3 diff --git a/fs/Kconfig b/fs/Kconfig
4 index c229f82..397b473 100644
7 @@ -212,6 +212,7 @@ source "fs/ufs/Kconfig"
8 source "fs/exofs/Kconfig"
9 source "fs/f2fs/Kconfig"
10 source "fs/efivarfs/Kconfig"
11 +source "fs/aufs/Kconfig"
13 endif # MISC_FILESYSTEMS
15 diff --git a/fs/Makefile b/fs/Makefile
16 index 4fe6df3..4a57676 100644
19 @@ -126,3 +126,4 @@ obj-y += exofs/ # Multiple modules
20 obj-$(CONFIG_CEPH_FS) += ceph/
21 obj-$(CONFIG_PSTORE) += pstore/
22 obj-$(CONFIG_EFIVAR_FS) += efivarfs/
23 +obj-$(CONFIG_AUFS_FS) += aufs/
24 diff --git a/include/uapi/linux/Kbuild b/include/uapi/linux/Kbuild
25 index 33d2b8f..b55eeb9 100644
26 --- a/include/uapi/linux/Kbuild
27 +++ b/include/uapi/linux/Kbuild
28 @@ -56,6 +56,7 @@ header-y += atmppp.h
32 +header-y += aufs_type.h
34 header-y += auto_fs4.h
38 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39 index c8dac73..2e229ac 100644
40 --- a/drivers/block/loop.c
41 +++ b/drivers/block/loop.c
42 @@ -691,6 +691,24 @@ static inline int is_loop_device(struct file *file)
43 return i && S_ISBLK(i->i_mode) && MAJOR(i->i_rdev) == LOOP_MAJOR;
48 + * no get/put for file.
50 +struct file *loop_backing_file(struct super_block *sb)
53 + struct loop_device *l;
56 + if (MAJOR(sb->s_dev) == LOOP_MAJOR) {
57 + l = sb->s_bdev->bd_disk->private_data;
58 + ret = l->lo_backing_file;
62 +EXPORT_SYMBOL(loop_backing_file);
64 /* loop sysfs attributes */
66 static ssize_t loop_attr_show(struct device *dev, char *page,
67 diff --git a/fs/inode.c b/fs/inode.c
68 index 4bcdad3..bc83168 100644
71 @@ -1497,7 +1497,7 @@ static int relatime_need_update(struct vfsmount *mnt, struct inode *inode,
72 * This does the actual work of updating an inodes time or version. Must have
73 * had called mnt_want_write() before calling this.
75 -static int update_time(struct inode *inode, struct timespec *time, int flags)
76 +int update_time(struct inode *inode, struct timespec *time, int flags)
78 if (inode->i_op->update_time)
79 return inode->i_op->update_time(inode, time, flags);
80 diff --git a/fs/splice.c b/fs/splice.c
81 index 46a08f7..719ca3e 100644
84 @@ -1093,8 +1093,8 @@ EXPORT_SYMBOL(generic_splice_sendpage);
86 * Attempt to initiate a splice from pipe to file.
88 -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
89 - loff_t *ppos, size_t len, unsigned int flags)
90 +long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
91 + loff_t *ppos, size_t len, unsigned int flags)
93 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
94 loff_t *, size_t, unsigned int);
95 @@ -1110,9 +1110,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
97 * Attempt to initiate a splice from a file to a pipe.
99 -static long do_splice_to(struct file *in, loff_t *ppos,
100 - struct pipe_inode_info *pipe, size_t len,
101 - unsigned int flags)
102 +long do_splice_to(struct file *in, loff_t *ppos,
103 + struct pipe_inode_info *pipe, size_t len,
104 + unsigned int flags)
106 ssize_t (*splice_read)(struct file *, loff_t *,
107 struct pipe_inode_info *, size_t, unsigned int);
108 diff --git a/include/linux/fs.h b/include/linux/fs.h
109 index 121f11f..39bf86d 100644
110 --- a/include/linux/fs.h
111 +++ b/include/linux/fs.h
112 @@ -2657,6 +2657,7 @@ extern int inode_change_ok(const struct inode *, struct iattr *);
113 extern int inode_newsize_ok(const struct inode *, loff_t offset);
114 extern void setattr_copy(struct inode *inode, const struct iattr *attr);
116 +extern int update_time(struct inode *, struct timespec *, int);
117 extern int file_update_time(struct file *file);
119 extern int generic_show_options(struct seq_file *m, struct dentry *root);
120 diff --git a/include/linux/splice.h b/include/linux/splice.h
121 index 74575cb..bfc6fb6 100644
122 --- a/include/linux/splice.h
123 +++ b/include/linux/splice.h
124 @@ -92,4 +92,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
125 extern void spd_release_page(struct splice_pipe_desc *, unsigned int);
127 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
129 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
130 + loff_t *ppos, size_t len, unsigned int flags);
131 +extern long do_splice_to(struct file *in, loff_t *ppos,
132 + struct pipe_inode_info *pipe, size_t len,
133 + unsigned int flags);
135 aufs3.13 standalone patch
137 diff --git a/fs/inode.c b/fs/inode.c
138 index bc83168..6dd1207 100644
141 @@ -57,6 +57,7 @@ static struct hlist_head *inode_hashtable __read_mostly;
142 static __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_hash_lock);
144 __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_sb_list_lock);
145 +EXPORT_SYMBOL(inode_sb_list_lock);
148 * Empty aops. Can be used for the cases where the user does not
149 @@ -1513,6 +1514,7 @@ int update_time(struct inode *inode, struct timespec *time, int flags)
150 mark_inode_dirty_sync(inode);
153 +EXPORT_SYMBOL(update_time);
156 * touch_atime - update the access time
157 diff --git a/fs/namespace.c b/fs/namespace.c
158 index be32ebc..d3f6f59 100644
161 @@ -425,6 +425,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
162 mnt_dec_writers(real_mount(mnt));
165 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
168 * mnt_drop_write - give up write access to a mount
169 @@ -1509,6 +1510,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
173 +EXPORT_SYMBOL(iterate_mounts);
175 static void cleanup_group_ids(struct mount *mnt, struct mount *end)
177 diff --git a/fs/notify/group.c b/fs/notify/group.c
178 index bd2625b..2ff2a0f 100644
179 --- a/fs/notify/group.c
180 +++ b/fs/notify/group.c
182 #include <linux/srcu.h>
183 #include <linux/rculist.h>
184 #include <linux/wait.h>
185 +#include <linux/module.h>
187 #include <linux/fsnotify_backend.h>
188 #include "fsnotify.h"
189 @@ -65,6 +66,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
191 atomic_inc(&group->refcnt);
193 +EXPORT_SYMBOL(fsnotify_get_group);
196 * Drop a reference to a group. Free it if it's through.
197 @@ -74,6 +76,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
198 if (atomic_dec_and_test(&group->refcnt))
199 fsnotify_final_destroy_group(group);
201 +EXPORT_SYMBOL(fsnotify_put_group);
204 * Create a new fsnotify_group and hold a reference for the group returned.
205 @@ -102,6 +105,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
209 +EXPORT_SYMBOL(fsnotify_alloc_group);
211 int fsnotify_fasync(int fd, struct file *file, int on)
213 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
214 index 923fe4a..176b435 100644
215 --- a/fs/notify/mark.c
216 +++ b/fs/notify/mark.c
217 @@ -109,6 +109,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
218 mark->free_mark(mark);
221 +EXPORT_SYMBOL(fsnotify_put_mark);
224 * Any time a mark is getting freed we end up here.
225 @@ -191,6 +192,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
226 fsnotify_destroy_mark_locked(mark, group);
227 mutex_unlock(&group->mark_mutex);
229 +EXPORT_SYMBOL(fsnotify_destroy_mark);
231 void fsnotify_set_mark_mask_locked(struct fsnotify_mark *mark, __u32 mask)
233 @@ -275,6 +277,7 @@ err:
237 +EXPORT_SYMBOL(fsnotify_add_mark);
239 int fsnotify_add_mark(struct fsnotify_mark *mark, struct fsnotify_group *group,
240 struct inode *inode, struct vfsmount *mnt, int allow_dups)
241 @@ -336,6 +339,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
242 atomic_set(&mark->refcnt, 1);
243 mark->free_mark = free_mark;
245 +EXPORT_SYMBOL(fsnotify_init_mark);
247 static int fsnotify_mark_destroy(void *ignored)
249 diff --git a/fs/open.c b/fs/open.c
250 index 4b3e1ed..ce49f2b 100644
253 @@ -62,6 +62,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
254 mutex_unlock(&dentry->d_inode->i_mutex);
257 +EXPORT_SYMBOL(do_truncate);
259 long vfs_truncate(struct path *path, loff_t length)
261 diff --git a/fs/splice.c b/fs/splice.c
262 index 719ca3e..6300dc8 100644
265 @@ -1106,6 +1106,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
267 return splice_write(pipe, out, ppos, len, flags);
269 +EXPORT_SYMBOL(do_splice_from);
272 * Attempt to initiate a splice from a file to a pipe.
273 @@ -1132,6 +1133,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
275 return splice_read(in, ppos, pipe, len, flags);
277 +EXPORT_SYMBOL(do_splice_to);
280 * splice_direct_to_actor - splices data directly between two non-pipes
281 diff --git a/security/commoncap.c b/security/commoncap.c
282 index b9d613e..ba3b618 100644
283 --- a/security/commoncap.c
284 +++ b/security/commoncap.c
285 @@ -988,9 +988,11 @@ int cap_mmap_addr(unsigned long addr)
289 +EXPORT_SYMBOL(cap_mmap_addr);
291 int cap_mmap_file(struct file *file, unsigned long reqprot,
292 unsigned long prot, unsigned long flags)
296 +EXPORT_SYMBOL(cap_mmap_file);
297 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
298 index 7c2a0a7..a37c054 100644
299 --- a/security/device_cgroup.c
300 +++ b/security/device_cgroup.c
302 #include <linux/device_cgroup.h>
303 #include <linux/cgroup.h>
304 #include <linux/ctype.h>
305 +#include <linux/export.h>
306 #include <linux/list.h>
307 #include <linux/uaccess.h>
308 #include <linux/seq_file.h>
309 @@ -745,6 +746,7 @@ int __devcgroup_inode_permission(struct inode *inode, int mask)
310 return __devcgroup_check_permission(type, imajor(inode), iminor(inode),
313 +EXPORT_SYMBOL(__devcgroup_inode_permission);
315 int devcgroup_inode_mknod(int mode, dev_t dev)
317 diff --git a/security/security.c b/security/security.c
318 index 15b6928..ae6eba6 100644
319 --- a/security/security.c
320 +++ b/security/security.c
321 @@ -407,6 +407,7 @@ int security_path_rmdir(struct path *dir, struct dentry *dentry)
323 return security_ops->path_rmdir(dir, dentry);
325 +EXPORT_SYMBOL(security_path_rmdir);
327 int security_path_unlink(struct path *dir, struct dentry *dentry)
329 @@ -423,6 +424,7 @@ int security_path_symlink(struct path *dir, struct dentry *dentry,
331 return security_ops->path_symlink(dir, dentry, old_name);
333 +EXPORT_SYMBOL(security_path_symlink);
335 int security_path_link(struct dentry *old_dentry, struct path *new_dir,
336 struct dentry *new_dentry)
337 @@ -431,6 +433,7 @@ int security_path_link(struct dentry *old_dentry, struct path *new_dir,
339 return security_ops->path_link(old_dentry, new_dir, new_dentry);
341 +EXPORT_SYMBOL(security_path_link);
343 int security_path_rename(struct path *old_dir, struct dentry *old_dentry,
344 struct path *new_dir, struct dentry *new_dentry)
345 @@ -449,6 +452,7 @@ int security_path_truncate(struct path *path)
347 return security_ops->path_truncate(path);
349 +EXPORT_SYMBOL(security_path_truncate);
351 int security_path_chmod(struct path *path, umode_t mode)
353 @@ -456,6 +460,7 @@ int security_path_chmod(struct path *path, umode_t mode)
355 return security_ops->path_chmod(path, mode);
357 +EXPORT_SYMBOL(security_path_chmod);
359 int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
361 @@ -463,6 +468,7 @@ int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
363 return security_ops->path_chown(path, uid, gid);
365 +EXPORT_SYMBOL(security_path_chown);
367 int security_path_chroot(struct path *path)
369 @@ -539,6 +545,7 @@ int security_inode_readlink(struct dentry *dentry)
371 return security_ops->inode_readlink(dentry);
373 +EXPORT_SYMBOL(security_inode_readlink);
375 int security_inode_follow_link(struct dentry *dentry, struct nameidata *nd)
377 @@ -553,6 +560,7 @@ int security_inode_permission(struct inode *inode, int mask)
379 return security_ops->inode_permission(inode, mask);
381 +EXPORT_SYMBOL(security_inode_permission);
383 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
385 @@ -675,6 +683,7 @@ int security_file_permission(struct file *file, int mask)
387 return fsnotify_perm(file, mask);
389 +EXPORT_SYMBOL(security_file_permission);
391 int security_file_alloc(struct file *file)
393 @@ -735,6 +744,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
395 return ima_file_mmap(file, prot);
397 +EXPORT_SYMBOL(security_mmap_file);
399 int security_mmap_addr(unsigned long addr)
401 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
402 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
403 +++ linux/Documentation/ABI/testing/debugfs-aufs 2014-01-27 23:16:52.651751827 +0100
405 +What: /debug/aufs/si_<id>/
407 +Contact: J. R. Okajima <hooanon05g@gmail.com>
409 + Under /debug/aufs, a directory named si_<id> is created
410 + per aufs mount, where <id> is a unique id generated
413 +What: /debug/aufs/si_<id>/plink
415 +Contact: J. R. Okajima <hooanon05g@gmail.com>
417 + It has three lines and shows the information about the
418 + pseudo-link. The first line is a single number
419 + representing a number of buckets. The second line is a
420 + number of pseudo-links per buckets (separated by a
421 + blank). The last line is a single number representing a
422 + total number of psedo-links.
423 + When the aufs mount option 'noplink' is specified, it
424 + will show "1\n0\n0\n".
426 +What: /debug/aufs/si_<id>/xib
428 +Contact: J. R. Okajima <hooanon05g@gmail.com>
430 + It shows the consumed blocks by xib (External Inode Number
431 + Bitmap), its block size and file size.
432 + When the aufs mount option 'noxino' is specified, it
433 + will be empty. About XINO files, see the aufs manual.
435 +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN
437 +Contact: J. R. Okajima <hooanon05g@gmail.com>
439 + It shows the consumed blocks by xino (External Inode Number
440 + Translation Table), its link count, block size and file
442 + When the aufs mount option 'noxino' is specified, it
443 + will be empty. About XINO files, see the aufs manual.
445 +What: /debug/aufs/si_<id>/xigen
447 +Contact: J. R. Okajima <hooanon05g@gmail.com>
449 + It shows the consumed blocks by xigen (External Inode
450 + Generation Table), its block size and file size.
451 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
453 + When the aufs mount option 'noxino' is specified, it
454 + will be empty. About XINO files, see the aufs manual.
455 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
456 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
457 +++ linux/Documentation/ABI/testing/sysfs-aufs 2014-01-27 23:16:52.651751827 +0100
459 +What: /sys/fs/aufs/si_<id>/
461 +Contact: J. R. Okajima <hooanon05g@gmail.com>
463 + Under /sys/fs/aufs, a directory named si_<id> is created
464 + per aufs mount, where <id> is a unique id generated
467 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
469 +Contact: J. R. Okajima <hooanon05g@gmail.com>
471 + It shows the abolute path of a member directory (which
472 + is called branch) in aufs, and its permission.
474 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
476 +Contact: J. R. Okajima <hooanon05g@gmail.com>
478 + It shows the id of a member directory (which is called
481 +What: /sys/fs/aufs/si_<id>/xi_path
483 +Contact: J. R. Okajima <hooanon05g@gmail.com>
485 + It shows the abolute path of XINO (External Inode Number
486 + Bitmap, Translation Table and Generation Table) file
487 + even if it is the default path.
488 + When the aufs mount option 'noxino' is specified, it
489 + will be empty. About XINO files, see the aufs manual.
490 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
491 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
492 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2014-01-20 20:16:14.729463171 +0100
495 +# Copyright (C) 2005-2014 Junjiro R. Okajima
497 +# This program is free software; you can redistribute it and/or modify
498 +# it under the terms of the GNU General Public License as published by
499 +# the Free Software Foundation; either version 2 of the License, or
500 +# (at your option) any later version.
502 +# This program is distributed in the hope that it will be useful,
503 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
504 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
505 +# GNU General Public License for more details.
507 +# You should have received a copy of the GNU General Public License
508 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
511 +----------------------------------------
513 +aufs [ei ju: ef es] | [a u f s]
514 +1. abbrev. for "advanced multi-layered unification filesystem".
515 +2. abbrev. for "another unionfs".
516 +3. abbrev. for "auf das" in German which means "on the" in English.
517 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
518 + But "Filesystem aufs Filesystem" is hard to understand.
520 +AUFS is a filesystem with features:
521 +- multi layered stackable unification filesystem, the member directory
522 + is called as a branch.
523 +- branch permission and attribute, 'readonly', 'real-readonly',
524 + 'readwrite', 'whiteout-able', 'link-able whiteout' and their
526 +- internal "file copy-on-write".
527 +- logical deletion, whiteout.
528 +- dynamic branch manipulation, adding, deleting and changing permission.
529 +- allow bypassing aufs, user's direct branch access.
530 +- external inode number translation table and bitmap which maintains the
531 + persistent aufs inode number.
532 +- seekable directory, including NFS readdir.
533 +- file mapping, mmap and sharing pages.
534 +- pseudo-link, hardlink over branches.
535 +- loopback mounted filesystem as a branch.
536 +- several policies to select one among multiple writable branches.
537 +- revert a single systemcall when an error occurs in aufs.
541 +Multi Layered Stackable Unification Filesystem
542 +----------------------------------------------------------------------
543 +Most people already knows what it is.
544 +It is a filesystem which unifies several directories and provides a
545 +merged single directory. When users access a file, the access will be
546 +passed/re-directed/converted (sorry, I am not sure which English word is
547 +correct) to the real file on the member filesystem. The member
548 +filesystem is called 'lower filesystem' or 'branch' and has a mode
549 +'readonly' and 'readwrite.' And the deletion for a file on the lower
550 +readonly branch is handled by creating 'whiteout' on the upper writable
553 +On LKML, there have been discussions about UnionMount (Jan Blunck,
554 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
555 +different approaches to implement the merged-view.
556 +The former tries putting it into VFS, and the latter implements as a
557 +separate filesystem.
558 +(If I misunderstand about these implementations, please let me know and
559 +I shall correct it. Because it is a long time ago when I read their
560 +source files last time).
562 +UnionMount's approach will be able to small, but may be hard to share
563 +branches between several UnionMount since the whiteout in it is
564 +implemented in the inode on branch filesystem and always
565 +shared. According to Bharata's post, readdir does not seems to be
567 +There are several missing features known in this implementations such as
568 +- for users, the inode number may change silently. eg. copy-up.
569 +- link(2) may break by copy-up.
570 +- read(2) may get an obsoleted filedata (fstat(2) too).
571 +- fcntl(F_SETLK) may be broken by copy-up.
572 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
575 +Unionfs has a longer history. When I started implementing a stacking filesystem
576 +(Aug 2005), it already existed. It has virtual super_block, inode,
577 +dentry and file objects and they have an array pointing lower same kind
578 +objects. After contributing many patches for Unionfs, I re-started my
579 +project AUFS (Jun 2006).
581 +In AUFS, the structure of filesystem resembles to Unionfs, but I
582 +implemented my own ideas, approaches and enhancements and it became
583 +totally different one.
585 +Comparing DM snapshot and fs based implementation
586 +- the number of bytes to be copied between devices is much smaller.
587 +- the type of filesystem must be one and only.
588 +- the fs must be writable, no readonly fs, even for the lower original
589 + device. so the compression fs will not be usable. but if we use
590 + loopback mount, we may address this issue.
592 + mount /cdrom/squashfs.img /sq
593 + losetup /sq/ext2.img
594 + losetup /somewhere/cow
595 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
596 +- it will be difficult (or needs more operations) to extract the
597 + difference between the original device and COW.
598 +- DM snapshot-merge may help a lot when users try merging. in the
599 + fs-layer union, users will use rsync(1).
602 +Several characters/aspects of aufs
603 +----------------------------------------------------------------------
605 +Aufs has several characters or aspects.
606 +1. a filesystem, callee of VFS helper
607 +2. sub-VFS, caller of VFS helper for branches
608 +3. a virtual filesystem which maintains persistent inode number
609 +4. reader/writer of files on branches such like an application
611 +1. Callee of VFS Helper
612 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
613 +unlink(2) from an application reaches sys_unlink() kernel function and
614 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
615 +calls filesystem specific unlink operation. Actually aufs implements the
616 +unlink operation but it behaves like a redirector.
618 +2. Caller of VFS Helper for Branches
619 +aufs_unlink() passes the unlink request to the branch filesystem as if
620 +it were called from VFS. So the called unlink operation of the branch
621 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
622 +every necessary pre/post operation for the branch filesystem.
623 +- acquire the lock for the parent dir on a branch
624 +- lookup in a branch
625 +- revalidate dentry on a branch
626 +- mnt_want_write() for a branch
627 +- vfs_unlink() for a branch
628 +- mnt_drop_write() for a branch
629 +- release the lock on a branch
631 +3. Persistent Inode Number
632 +One of the most important issue for a filesystem is to maintain inode
633 +numbers. This is particularly important to support exporting a
634 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
635 +backend block device for its own. But some storage is necessary to
636 +maintain inode number. It may be a large space and may not suit to keep
637 +in memory. Aufs rents some space from its first writable branch
638 +filesystem (by default) and creates file(s) on it. These files are
639 +created by aufs internally and removed soon (currently) keeping opened.
640 +Note: Because these files are removed, they are totally gone after
641 + unmounting aufs. It means the inode numbers are not persistent
642 + across unmount or reboot. I have a plan to make them really
643 + persistent which will be important for aufs on NFS server.
645 +4. Read/Write Files Internally (copy-on-write)
646 +Because a branch can be readonly, when you write a file on it, aufs will
647 +"copy-up" it to the upper writable branch internally. And then write the
648 +originally requested thing to the file. Generally kernel doesn't
649 +open/read/write file actively. In aufs, even a single write may cause a
650 +internal "file copy". This behaviour is very similar to cp(1) command.
652 +Some people may think it is better to pass such work to user space
653 +helper, instead of doing in kernel space. Actually I am still thinking
654 +about it. But currently I have implemented it in kernel space.
655 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
656 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
657 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2014-01-20 20:16:14.729463171 +0100
660 +# Copyright (C) 2005-2014 Junjiro R. Okajima
662 +# This program is free software; you can redistribute it and/or modify
663 +# it under the terms of the GNU General Public License as published by
664 +# the Free Software Foundation; either version 2 of the License, or
665 +# (at your option) any later version.
667 +# This program is distributed in the hope that it will be useful,
668 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
669 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
670 +# GNU General Public License for more details.
672 +# You should have received a copy of the GNU General Public License
673 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
675 +Basic Aufs Internal Structure
677 +Superblock/Inode/Dentry/File Objects
678 +----------------------------------------------------------------------
679 +As like an ordinary filesystem, aufs has its own
680 +superblock/inode/dentry/file objects. All these objects have a
681 +dynamically allocated array and store the same kind of pointers to the
682 +lower filesystem, branch.
683 +For example, when you build a union with one readwrite branch and one
684 +readonly, mounted /au, /rw and /ro respectively.
686 +- /ro/fileA exists but /rw/fileA
688 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
689 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
693 +This style of an array is essentially same to the aufs
694 +superblock/inode/dentry/file objects.
696 +Because aufs supports manipulating branches, ie. add/delete/change
697 +dynamically, these objects has its own generation. When branches are
698 +changed, the generation in aufs superblock is incremented. And a
699 +generation in other object are compared when it is accessed.
700 +When a generation in other objects are obsoleted, aufs refreshes the
705 +----------------------------------------------------------------------
706 +Additionally aufs superblock has some data for policies to select one
707 +among multiple writable branches, XIB files, pseudo-links and kobject.
708 +See below in detail.
709 +About the policies which supports copy-down a directory, see policy.txt
713 +Branch and XINO(External Inode Number Translation Table)
714 +----------------------------------------------------------------------
715 +Every branch has its own xino (external inode number translation table)
716 +file. The xino file is created and unlinked by aufs internally. When two
717 +members of a union exist on the same filesystem, they share the single
719 +The struct of a xino file is simple, just a sequence of aufs inode
720 +numbers which is indexed by the lower inode number.
721 +In the above sample, assume the inode number of /ro/fileA is i111 and
722 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
723 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
725 +When the inode numbers are not contiguous, the xino file will be sparse
726 +which has a hole in it and doesn't consume as much disk space as it
727 +might appear. If your branch filesystem consumes disk space for such
728 +holes, then you should specify 'xino=' option at mounting aufs.
730 +Also a writable branch has three kinds of "whiteout bases". All these
731 +are existed when the branch is joined to aufs and the names are
732 +whiteout-ed doubly, so that users will never see their names in aufs
734 +1. a regular file which will be linked to all whiteouts.
735 +2. a directory to store a pseudo-link.
736 +3. a directory to store an "orphan-ed" file temporary.
739 + When you remove a file on a readonly branch, aufs handles it as a
740 + logical deletion and creates a whiteout on the upper writable branch
741 + as a hardlink of this file in order not to consume inode on the
744 + See below, Pseudo-link.
746 + When "fileC" exists on the lower readonly branch only and it is
747 + opened and removed with its parent dir, and then user writes
748 + something into it, then aufs copies-up fileC to this
749 + directory. Because there is no other dir to store fileC. After
750 + creating a file under this dir, the file is unlinked.
752 +Because aufs supports manipulating branches, ie. add/delete/change
753 +dynamically, a branch has its own id. When the branch order changes, aufs
754 +finds the new index by searching the branch id.
758 +----------------------------------------------------------------------
759 +Assume "fileA" exists on the lower readonly branch only and it is
760 +hardlinked to "fileB" on the branch. When you write something to fileA,
761 +aufs copies-up it to the upper writable branch. Additionally aufs
762 +creates a hardlink under the Pseudo-link Directory of the writable
763 +branch. The inode of a pseudo-link is kept in aufs super_block as a
764 +simple list. If fileB is read after unlinking fileA, aufs returns
765 +filedata from the pseudo-link instead of the lower readonly
766 +branch. Because the pseudo-link is based upon the inode, to keep the
767 +inode number by xino (see above) is important.
769 +All the hardlinks under the Pseudo-link Directory of the writable branch
770 +should be restored in a proper location later. Aufs provides a utility
771 +to do this. The userspace helpers executed at remounting and unmounting
773 +During this utility is running, it puts aufs into the pseudo-link
774 +maintenance mode. In this mode, only the process which began the
775 +maintenance mode (and its child processes) is allowed to operate in
776 +aufs. Some other processes which are not related to the pseudo-link will
777 +be allowed to run too, but the rest have to return an error or wait
778 +until the maintenance mode ends. If a process already acquires an inode
779 +mutex (in VFS), it has to return an error.
782 +XIB(external inode number bitmap)
783 +----------------------------------------------------------------------
784 +Addition to the xino file per a branch, aufs has an external inode number
785 +bitmap in a superblock object. It is also a file such like a xino file.
786 +It is a simple bitmap to mark whether the aufs inode number is in-use or
788 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
790 +Aufs implements a feature to truncate/refresh both of xino and xib to
791 +reduce the number of consumed disk blocks for these files.
794 +Virtual or Vertical Dir, and Readdir in Userspace
795 +----------------------------------------------------------------------
796 +In order to support multiple layers (branches), aufs readdir operation
797 +constructs a virtual dir block on memory. For readdir, aufs calls
798 +vfs_readdir() internally for each dir on branches, merges their entries
799 +with eliminating the whiteout-ed ones, and sets it to file (dir)
800 +object. So the file object has its entry list until it is closed. The
801 +entry list will be updated when the file position is zero and becomes
802 +old. This decision is made in aufs automatically.
804 +The dynamically allocated memory block for the name of entries has a
805 +unit of 512 bytes (by default) and stores the names contiguously (no
806 +padding). Another block for each entry is handled by kmem_cache too.
807 +During building dir blocks, aufs creates hash list and judging whether
808 +the entry is whiteouted by its upper branch or already listed.
809 +The merged result is cached in the corresponding inode object and
810 +maintained by a customizable life-time option.
812 +Some people may call it can be a security hole or invite DoS attack
813 +since the opened and once readdir-ed dir (file object) holds its entry
814 +list and becomes a pressure for system memory. But I'd say it is similar
815 +to files under /proc or /sys. The virtual files in them also holds a
816 +memory page (generally) while they are opened. When an idea to reduce
817 +memory for them is introduced, it will be applied to aufs too.
818 +For those who really hate this situation, I've developed readdir(3)
819 +library which operates this merging in userspace. You just need to set
820 +LD_PRELOAD environment variable, and aufs will not consume no memory in
821 +kernel space for readdir(3).
825 +----------------------------------------------------------------------
826 +Aufs sometimes requires privilege access to a branch. For instance,
827 +in copy-up/down operation. When a user process is going to make changes
828 +to a file which exists in the lower readonly branch only, and the mode
829 +of one of ancestor directories may not be writable by a user
830 +process. Here aufs copy-up the file with its ancestors and they may
831 +require privilege to set its owner/group/mode/etc.
832 +This is a typical case of a application character of aufs (see
835 +Aufs uses workqueue synchronously for this case. It creates its own
836 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
837 +passes the request to call mkdir or write (for example), and wait for
838 +its completion. This approach solves a problem of a signal handler
840 +If aufs didn't adopt the workqueue and changed the privilege of the
841 +process, and if the mkdir/write call arises SIGXFSZ or other signal,
842 +then the user process might gain a privilege or the generated core file
843 +was owned by a superuser.
845 +Also aufs uses the system global workqueue ("events" kernel thread) too
846 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
847 +whiteout base and etc. This is unrelated to a privilege.
848 +Most of aufs operation tries acquiring a rw_semaphore for aufs
849 +superblock at the beginning, at the same time waits for the completion
850 +of all queued asynchronous tasks.
854 +----------------------------------------------------------------------
855 +The whiteout in aufs is very similar to Unionfs's. That is represented
856 +by its filename. UnionMount takes an approach of a file mode, but I am
857 +afraid several utilities (find(1) or something) will have to support it.
859 +Basically the whiteout represents "logical deletion" which stops aufs to
860 +lookup further, but also it represents "dir is opaque" which also stop
863 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
864 +In order to make several functions in a single systemcall to be
865 +revertible, aufs adopts an approach to rename a directory to a temporary
866 +unique whiteouted name.
867 +For example, in rename(2) dir where the target dir already existed, aufs
868 +renames the target dir to a temporary unique whiteouted name before the
869 +actual rename on a branch and then handles other actions (make it opaque,
870 +update the attributes, etc). If an error happens in these actions, aufs
871 +simply renames the whiteouted name back and returns an error. If all are
872 +succeeded, aufs registers a function to remove the whiteouted unique
873 +temporary name completely and asynchronously to the system global
878 +----------------------------------------------------------------------
879 +It is a well-known feature or concept.
880 +When user modifies a file on a readonly branch, aufs operate "copy-up"
881 +internally and makes change to the new file on the upper writable branch.
882 +When the trigger systemcall does not update the timestamps of the parent
883 +dir, aufs reverts it after copy-up.
886 +Move-down (aufs3.9 and later)
887 +----------------------------------------------------------------------
888 +"Copy-up" is one of the essential feature in aufs. It copies a file from
889 +the lower readonly branch to the upper writable branch when a user
890 +changes something about the file.
891 +"Move-down" is an opposite action of copy-up. Basically this action is
892 +ran manually instead of automatically and internally.
894 +Sometimes users want to move-down a file from the upper writable branch
895 +to the lower readonly or writable branch. For instance,
896 +- the free space of the upper writable branch is going to run out.
897 +- create a new intermediate branch between the upper and lower branch.
900 +For this purpose, use "aumvdown" command in aufs-util.git.
901 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
902 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
903 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2014-01-20 20:16:14.729463171 +0100
906 +# Copyright (C) 2005-2014 Junjiro R. Okajima
908 +# This program is free software; you can redistribute it and/or modify
909 +# it under the terms of the GNU General Public License as published by
910 +# the Free Software Foundation; either version 2 of the License, or
911 +# (at your option) any later version.
913 +# This program is distributed in the hope that it will be useful,
914 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
915 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
916 +# GNU General Public License for more details.
918 +# You should have received a copy of the GNU General Public License
919 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
922 +----------------------------------------------------------------------
923 +Since aufs has a character of sub-VFS (see Introduction), it operates
924 +lookup for branches as VFS does. It may be a heavy work. Generally
925 +speaking struct nameidata is a bigger structure and includes many
926 +information. But almost all lookup operation in aufs is the simplest
927 +case, ie. lookup only an entry directly connected to its parent. Digging
928 +down the directory hierarchy is unnecessary.
930 +VFS has a function lookup_one_len() for that use, but it is not usable
931 +for a branch filesystem which requires struct nameidata. So aufs
932 +implements a simple lookup wrapper function. When a branch filesystem
933 +allows NULL as nameidata, it calls lookup_one_len(). Otherwise it builds
934 +a simplest nameidata and calls lookup_hash().
935 +Here aufs applies "a principle in NFSD", ie. if the filesystem supports
936 +NFS-export, then it has to support NULL as a nameidata parameter for
937 +->create(), ->lookup() and ->d_revalidate(). So the lookup wrapper in
938 +aufs tests if ->s_export_op in the branch is NULL or not.
940 +When a branch is a remote filesystem, aufs basically trusts its
941 +->d_revalidate(), also aufs forces the hardest revalidate tests for
943 +For d_revalidate, aufs implements three levels of revalidate tests. See
944 +"Revalidate Dentry and UDBA" in detail.
948 +----------------------------------------------------------------------
949 +Basically aufs supports any type of filesystem and block device for a
950 +branch (actually there are some exceptions). But it is prohibited to add
951 +a loopback mounted one whose backend file exists in a filesystem which is
952 +already added to aufs. The reason is to protect aufs from a recursive
953 +lookup. If it was allowed, the aufs lookup operation might re-enter a
954 +lookup for the loopback mounted branch in the same context, and will
958 +Revalidate Dentry and UDBA (User's Direct Branch Access)
959 +----------------------------------------------------------------------
960 +Generally VFS helpers re-validate a dentry as a part of lookup.
961 +0. digging down the directory hierarchy.
962 +1. lock the parent dir by its i_mutex.
963 +2. lookup the final (child) entry.
965 +4. call the actual operation (create, unlink, etc.)
966 +5. unlock the parent dir
968 +If the filesystem implements its ->d_revalidate() (step 3), then it is
969 +called. Actually aufs implements it and checks the dentry on a branch is
971 +But it is not enough. Because aufs has to release the lock for the
972 +parent dir on a branch at the end of ->lookup() (step 2) and
973 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
975 +If the file on a branch is changed directly, eg. bypassing aufs, after
976 +aufs released the lock, then the subsequent operation may cause
977 +something unpleasant result.
979 +This situation is a result of VFS architecture, ->lookup() and
980 +->d_revalidate() is separated. But I never say it is wrong. It is a good
981 +design from VFS's point of view. It is just not suitable for sub-VFS
984 +Aufs supports such case by three level of revalidation which is
986 +1. Simple Revalidate
987 + Addition to the native flow in VFS's, confirm the child-parent
988 + relationship on the branch just after locking the parent dir on the
989 + branch in the "actual operation" (step 4). When this validation
990 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
991 + checks the validation of the dentry on branches.
992 +2. Monitor Changes Internally by Inotify/Fsnotify
993 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
994 + the dentry on the branch, and returns EBUSY if it finds different
996 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
997 + during it is in cache. When the event is notified, aufs registers a
998 + function to kernel 'events' thread by schedule_work(). And the
999 + function sets some special status to the cached aufs dentry and inode
1000 + private data. If they are not cached, then aufs has nothing to
1001 + do. When the same file is accessed through aufs (step 0-3) later,
1002 + aufs will detect the status and refresh all necessary data.
1003 + In this mode, aufs has to ignore the event which is fired by aufs
1005 +3. No Extra Validation
1006 + This is the simplest test and doesn't add any additional revalidation
1007 + test, and skip therevalidatin in step 4. It is useful and improves
1008 + aufs performance when system surely hide the aufs branches from user,
1009 + by over-mounting something (or another method).
1010 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1011 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1012 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2014-01-20 20:16:14.729463171 +0100
1015 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1017 +# This program is free software; you can redistribute it and/or modify
1018 +# it under the terms of the GNU General Public License as published by
1019 +# the Free Software Foundation; either version 2 of the License, or
1020 +# (at your option) any later version.
1022 +# This program is distributed in the hope that it will be useful,
1023 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1024 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1025 +# GNU General Public License for more details.
1027 +# You should have received a copy of the GNU General Public License
1028 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1030 +Branch Manipulation
1032 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1033 +and changing its permission/attribute, there are a lot of works to do.
1037 +----------------------------------------------------------------------
1038 +o Confirm the adding dir exists outside of aufs, including loopback
1040 +- and other various attributes...
1041 +o Initialize the xino file and whiteout bases if necessary.
1044 +o Check the owner/group/mode of the directory
1045 + When the owner/group/mode of the adding directory differs from the
1046 + existing branch, aufs issues a warning because it may impose a
1048 + For example, when a upper writable branch has a world writable empty
1049 + top directory, a malicious user can create any files on the writable
1050 + branch directly, like copy-up and modify manually. If something like
1051 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1052 + writable branch, and the writable branch is world-writable, then a
1053 + malicious guy may create /etc/passwd on the writable branch directly
1054 + and the infected file will be valid in aufs.
1055 + I am afraid it can be a security issue, but nothing to do except
1056 + producing a warning.
1060 +----------------------------------------------------------------------
1061 +o Confirm the deleting branch is not busy
1062 + To be general, there is one merit to adopt "remount" interface to
1063 + manipulate branches. It is to discard caches. At deleting a branch,
1064 + aufs checks the still cached (and connected) dentries and inodes. If
1065 + there are any, then they are all in-use. An inode without its
1066 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1068 + For the cached one, aufs checks whether the same named entry exists on
1070 + If the cached one is a directory, because aufs provides a merged view
1071 + to users, as long as one dir is left on any branch aufs can show the
1072 + dir to users. In this case, the branch can be removed from aufs.
1073 + Otherwise aufs rejects deleting the branch.
1075 + If any file on the deleting branch is opened by aufs, then aufs
1079 +Modify the Permission of a Branch
1080 +----------------------------------------------------------------------
1081 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1084 +o rw --> ro: Confirm the modifying branch is not busy
1085 + Aufs rejects the request if any of these conditions are true.
1086 + - a file on the branch is mmap-ed.
1087 + - a regular file on the branch is opened for write and there is no
1088 + same named entry on the upper branch.
1089 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1090 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1091 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2014-01-20 20:16:14.729463171 +0100
1094 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1096 +# This program is free software; you can redistribute it and/or modify
1097 +# it under the terms of the GNU General Public License as published by
1098 +# the Free Software Foundation; either version 2 of the License, or
1099 +# (at your option) any later version.
1101 +# This program is distributed in the hope that it will be useful,
1102 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1103 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1104 +# GNU General Public License for more details.
1106 +# You should have received a copy of the GNU General Public License
1107 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1109 +Policies to Select One among Multiple Writable Branches
1110 +----------------------------------------------------------------------
1111 +When the number of writable branch is more than one, aufs has to decide
1112 +the target branch for file creation or copy-up. By default, the highest
1113 +writable branch which has the parent (or ancestor) dir of the target
1114 +file is chosen (top-down-parent policy).
1115 +By user's request, aufs implements some other policies to select the
1116 +writable branch, for file creation two policies, round-robin and
1117 +most-free-space policies. For copy-up three policies, top-down-parent,
1118 +bottom-up-parent and bottom-up policies.
1120 +As expected, the round-robin policy selects the branch in circular. When
1121 +you have two writable branches and creates 10 new files, 5 files will be
1122 +created for each branch. mkdir(2) systemcall is an exception. When you
1123 +create 10 new directories, all will be created on the same branch.
1124 +And the most-free-space policy selects the one which has most free
1125 +space among the writable branches. The amount of free space will be
1126 +checked by aufs internally, and users can specify its time interval.
1128 +The policies for copy-up is more simple,
1129 +top-down-parent is equivalent to the same named on in create policy,
1130 +bottom-up-parent selects the writable branch where the parent dir
1131 +exists and the nearest upper one from the copyup-source,
1132 +bottom-up selects the nearest upper writable branch from the
1133 +copyup-source, regardless the existence of the parent dir.
1135 +There are some rules or exceptions to apply these policies.
1136 +- If there is a readonly branch above the policy-selected branch and
1137 + the parent dir is marked as opaque (a variation of whiteout), or the
1138 + target (creating) file is whiteout-ed on the upper readonly branch,
1139 + then the result of the policy is ignored and the target file will be
1140 + created on the nearest upper writable branch than the readonly branch.
1141 +- If there is a writable branch above the policy-selected branch and
1142 + the parent dir is marked as opaque or the target file is whiteouted
1143 + on the branch, then the result of the policy is ignored and the target
1144 + file will be created on the highest one among the upper writable
1145 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1147 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1148 + They try selecting the branch where the source exists as possible
1149 + since copyup a large file will take long time. If it can't be,
1150 + ie. the branch where the source exists is readonly, then they will
1151 + follow the copyup policy.
1152 +- There is an exception for rename(2) when the target exists.
1153 + If the rename target exists, aufs compares the index of the branches
1154 + where the source and the target exists and selects the higher
1155 + one. If the selected branch is readonly, then aufs follows the
1157 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
1158 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
1159 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2014-01-20 20:16:14.729463171 +0100
1162 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1164 +# This program is free software; you can redistribute it and/or modify
1165 +# it under the terms of the GNU General Public License as published by
1166 +# the Free Software Foundation; either version 2 of the License, or
1167 +# (at your option) any later version.
1169 +# This program is distributed in the hope that it will be useful,
1170 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1171 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1172 +# GNU General Public License for more details.
1174 +# You should have received a copy of the GNU General Public License
1175 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1177 +mmap(2) -- File Memory Mapping
1178 +----------------------------------------------------------------------
1179 +In aufs, the file-mapped pages are handled by a branch fs directly, no
1180 +interaction with aufs. It means aufs_mmap() calls the branch fs's
1182 +This approach is simple and good, but there is one problem.
1183 +Under /proc, several entries show the mmap-ped files by its path (with
1184 +device and inode number), and the printed path will be the path on the
1185 +branch fs's instead of virtual aufs's.
1186 +This is not a problem in most cases, but some utilities lsof(1) (and its
1187 +user) may expect the path on aufs.
1189 +To address this issue, aufs adds a new member called vm_prfile in struct
1190 +vm_area_struct (and struct vm_region). The original vm_file points to
1191 +the file on the branch fs in order to handle everything correctly as
1192 +usual. The new vm_prfile points to a virtual file in aufs, and the
1193 +show-functions in procfs refers to vm_prfile if it is set.
1194 +Also we need to maintain several other places where touching vm_file
1196 +- fork()/clone() copies vma and the reference count of vm_file is
1198 +- merging vma maintains the ref count too.
1200 +This is not a good approach. It just faking the printed path. But it
1201 +leaves all behaviour around f_mapping unchanged. This is surely an
1203 +Actually aufs had adopted another complicated approach which calls
1204 +generic_file_mmap() and handles struct vm_operations_struct. In this
1205 +approach, aufs met a hard problem and I could not solve it without
1206 +switching the approach.
1207 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
1208 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
1209 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2014-01-20 20:16:14.729463171 +0100
1212 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1214 +# This program is free software; you can redistribute it and/or modify
1215 +# it under the terms of the GNU General Public License as published by
1216 +# the Free Software Foundation; either version 2 of the License, or
1217 +# (at your option) any later version.
1219 +# This program is distributed in the hope that it will be useful,
1220 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1221 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1222 +# GNU General Public License for more details.
1224 +# You should have received a copy of the GNU General Public License
1225 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1227 +Export Aufs via NFS
1228 +----------------------------------------------------------------------
1229 +Here is an approach.
1230 +- like xino/xib, add a new file 'xigen' which stores aufs inode
1232 +- iget_locked(): initialize aufs inode generation for a new inode, and
1233 + store it in xigen file.
1234 +- destroy_inode(): increment aufs inode generation and store it in xigen
1235 + file. it is necessary even if it is not unlinked, because any data of
1236 + inode may be changed by UDBA.
1237 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
1238 + build file handle by
1239 + + branch id (4 bytes)
1240 + + superblock generation (4 bytes)
1241 + + inode number (4 or 8 bytes)
1242 + + parent dir inode number (4 or 8 bytes)
1243 + + inode generation (4 bytes))
1244 + + return value of exportfs_encode_fh() for the parent on a branch (4
1246 + + file handle for a branch (by exportfs_encode_fh())
1248 + + find the index of a branch from its id in handle, and check it is
1249 + still exist in aufs.
1250 + + 1st level: get the inode number from handle and search it in cache.
1251 + + 2nd level: if not found, get the parent inode number from handle and
1252 + search it in cache. and then open the parent dir, find the matching
1253 + inode number by vfs_readdir() and get its name, and call
1254 + lookup_one_len() for the target dentry.
1255 + + 3rd level: if the parent dir is not cached, call
1256 + exportfs_decode_fh() for a branch and get the parent on a branch,
1257 + build a pathname of it, convert it a pathname in aufs, call
1258 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
1260 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
1261 + for every branch, but not itself. to get this, (currently) aufs
1262 + searches in current->nsproxy->mnt_ns list. it may not be a good
1263 + idea, but I didn't get other approach.
1264 + + test the generation of the gotten inode.
1265 +- every inode operation: they may get EBUSY due to UDBA. in this case,
1266 + convert it into ESTALE for NFSD.
1267 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
1268 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
1269 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
1270 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
1271 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2014-01-20 20:16:14.729463171 +0100
1274 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1276 +# This program is free software; you can redistribute it and/or modify
1277 +# it under the terms of the GNU General Public License as published by
1278 +# the Free Software Foundation; either version 2 of the License, or
1279 +# (at your option) any later version.
1281 +# This program is distributed in the hope that it will be useful,
1282 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1283 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1284 +# GNU General Public License for more details.
1286 +# You should have received a copy of the GNU General Public License
1287 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1289 +Show Whiteout Mode (shwh)
1290 +----------------------------------------------------------------------
1291 +Generally aufs hides the name of whiteouts. But in some cases, to show
1292 +them is very useful for users. For instance, creating a new middle layer
1293 +(branch) by merging existing layers.
1295 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
1296 +When you have three branches,
1297 +- Bottom: 'system', squashfs (underlying base system), read-only
1298 +- Middle: 'mods', squashfs, read-only
1299 +- Top: 'overlay', ram (tmpfs), read-write
1301 +The top layer is loaded at boot time and saved at shutdown, to preserve
1302 +the changes made to the system during the session.
1303 +When larger changes have been made, or smaller changes have accumulated,
1304 +the size of the saved top layer data grows. At this point, it would be
1305 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
1306 +and rewrite the 'mods' squashfs, clearing the top layer and thus
1307 +restoring save and load speed.
1309 +This merging is simplified by the use of another aufs mount, of just the
1310 +two overlay branches using the 'shwh' option.
1311 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
1312 + aufs /livesys/merge_union
1314 +A merged view of these two branches is then available at
1315 +/livesys/merge_union, and the new feature is that the whiteouts are
1317 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
1318 +writing to all branches. Also the default mode for all branches is 'ro'.
1319 +It is now possible to save the combined contents of the two overlay
1320 +branches to a new squashfs, e.g.:
1321 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
1323 +This new squashfs archive can be stored on the boot device and the
1324 +initramfs will use it to replace the old one at the next boot.
1325 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
1326 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
1327 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2014-01-20 20:16:14.729463171 +0100
1330 +# Copyright (C) 2010-2014 Junjiro R. Okajima
1332 +# This program is free software; you can redistribute it and/or modify
1333 +# it under the terms of the GNU General Public License as published by
1334 +# the Free Software Foundation; either version 2 of the License, or
1335 +# (at your option) any later version.
1337 +# This program is distributed in the hope that it will be useful,
1338 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1339 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1340 +# GNU General Public License for more details.
1342 +# You should have received a copy of the GNU General Public License
1343 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1345 +Dynamically customizable FS operations
1346 +----------------------------------------------------------------------
1347 +Generally FS operations (struct inode_operations, struct
1348 +address_space_operations, struct file_operations, etc.) are defined as
1349 +"static const", but it never means that FS have only one set of
1350 +operation. Some FS have multiple sets of them. For instance, ext2 has
1351 +three sets, one for XIP, for NOBH, and for normal.
1352 +Since aufs overrides and redirects these operations, sometimes aufs has
1353 +to change its behaviour according to the branch FS type. More imporantly
1354 +VFS acts differently if a function (member in the struct) is set or
1355 +not. It means aufs should have several sets of operations and select one
1356 +among them according to the branch FS definition.
1358 +In order to solve this problem and not to affect the behavour of VFS,
1359 +aufs defines these operations dynamically. For instance, aufs defines
1360 +aio_read function for struct file_operations, but it may not be set to
1361 +the file_operations. When the branch FS doesn't have it, aufs doesn't
1362 +set it to its file_operations while the function definition itself is
1363 +still alive. So the behaviour of io_submit(2) will not change, and it
1364 +will return an error when aio_read is not defined.
1366 +The lifetime of these dynamically generated operation object is
1367 +maintained by aufs branch object. When the branch is removed from aufs,
1368 +the reference counter of the object is decremented. When it reaches
1369 +zero, the dynamically generated operation object will be freed.
1371 +This approach is designed to support AIO (io_submit), Direcit I/O and
1373 +Currently this approach is applied to file_operations and
1374 +vm_operations_struct for regular files only.
1375 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt linux/Documentation/filesystems/aufs/design/99plan.txt
1376 --- /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt 1970-01-01 01:00:00.000000000 +0100
1377 +++ linux/Documentation/filesystems/aufs/design/99plan.txt 2014-01-20 20:16:14.732796615 +0100
1380 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1382 +# This program is free software; you can redistribute it and/or modify
1383 +# it under the terms of the GNU General Public License as published by
1384 +# the Free Software Foundation; either version 2 of the License, or
1385 +# (at your option) any later version.
1387 +# This program is distributed in the hope that it will be useful,
1388 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1389 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1390 +# GNU General Public License for more details.
1392 +# You should have received a copy of the GNU General Public License
1393 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1397 +Restoring some features which was implemented in aufs1.
1398 +They were dropped in aufs2 in order to make source files simpler and
1399 +easier to be reviewed.
1402 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1403 +----------------------------------------------------------------------
1404 +Let's try case study.
1405 +- aufs has two branches, upper readwrite and lower readonly.
1407 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1408 +- user invoked "chmod a+rx /au/dirA"
1409 +- then "dirA" becomes world readable?
1411 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1412 +or it may be a natively readonly filesystem. If aufs respects the lower
1413 +branch, it should not respond readdir request from other users. But user
1414 +allowed it by chmod. Should really aufs rejects showing the entries
1417 +To be honest, I don't have a best solution for this case. So I
1418 +implemented 'dirperm1' and 'nodirperm1' option in aufs1, and leave it to
1420 +When dirperm1 is specified, aufs checks only the highest one for the
1421 +directory permission, and shows the entries. Otherwise, as usual, checks
1422 +every dir existing on all branches and rejects the request.
1424 +As a side effect, dirperm1 option improves the performance of aufs
1425 +because the number of permission check is reduced.
1428 +Being Another Aufs's Readonly Branch (robr)
1429 +----------------------------------------------------------------------
1430 +Aufs1 allows aufs to be another aufs's readonly branch.
1431 +This feature was developed by a user's request. But it may not be used
1435 +Copy-up on Open (coo=)
1436 +----------------------------------------------------------------------
1437 +By default the internal copy-up is executed when it is really necessary.
1438 +It is not done when a file is opened for writing, but when write(2) is
1439 +done. Users who have many (over 100) branches want to know and analyse
1440 +when and what file is copied-up. To insert a new upper branch which
1441 +contains such files only may improve the performance of aufs.
1443 +Aufs1 implemented "coo=none | leaf | all" option.
1446 +Refresh the Opened File (refrof)
1447 +----------------------------------------------------------------------
1448 +This option is implemented in aufs1 but incomplete.
1450 +When user reads from a file, he expects to get its latest filedata
1451 +generally. If the file is removed and a new same named file is created,
1452 +the content he gets is unchanged, ie. the unlinked filedata.
1454 +Let's try case study again.
1455 +- aufs has two branches.
1457 +- "fileA" exists under /ro, but /rw.
1458 +- user opened "/au/fileA".
1459 +- he or someone else inserts a branch (/new) between /rw and /ro.
1460 + /au = /rw + /new + /ro
1461 +- the new branch has "fileA".
1462 +- user reads from the opened "fileA"
1463 +- which filedata should aufs return, from /ro or /new?
1465 +Some people says it has to be "from /ro" and it is a semantics of Unix.
1466 +The others say it should be "from /new" because the file is not removed
1467 +and it is equivalent to the case of someone else modifies the file.
1469 +Here again I don't have a best and final answer. I got an idea to
1470 +implement 'refrof' and 'norefrof' option. When 'refrof' (REFResh the
1471 +Opened File) is specified (by default), aufs returns the filedata from
1473 +Otherwise from /new.
1474 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
1475 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
1476 +++ linux/Documentation/filesystems/aufs/README 2014-01-20 20:16:14.729463171 +0100
1479 +Aufs3 -- advanced multi layered unification filesystem version 3.x
1485 +----------------------------------------
1486 +In the early days, aufs was entirely re-designed and re-implemented
1487 +Unionfs Version 1.x series. After many original ideas, approaches,
1488 +improvements and implementations, it becomes totally different from
1489 +Unionfs while keeping the basic features.
1490 +Recently, Unionfs Version 2.x series begin taking some of the same
1491 +approaches to aufs1's.
1492 +Unionfs is being developed by Professor Erez Zadok at Stony Brook
1493 +University and his team.
1495 +Aufs3 supports linux-3.0 and later.
1496 +If you want older kernel version support, try aufs2-2.6.git or
1497 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
1499 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
1500 +According to Christoph Hellwig, linux rejects all union-type filesystems
1502 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
1506 +----------------------------------------
1507 +- unite several directories into a single virtual filesystem. The member
1508 + directory is called as a branch.
1509 +- you can specify the permission flags to the branch, which are 'readonly',
1510 + 'readwrite' and 'whiteout-able.'
1511 +- by upper writable branch, internal copyup and whiteout, files/dirs on
1512 + readonly branch are modifiable logically.
1513 +- dynamic branch manipulation, add, del.
1516 +Also there are many enhancements in aufs1, such as:
1517 +- readdir(3) in userspace.
1518 +- keep inode number by external inode number table
1519 +- keep the timestamps of file/dir in internal copyup operation
1520 +- seekable directory, supporting NFS readdir.
1521 +- whiteout is hardlinked in order to reduce the consumption of inodes
1523 +- do not copyup, nor create a whiteout when it is unnecessary
1524 +- revert a single systemcall when an error occurs in aufs
1525 +- remount interface instead of ioctl
1526 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
1527 +- loopback mounted filesystem as a branch
1528 +- kernel thread for removing the dir who has a plenty of whiteouts
1529 +- support copyup sparse file (a file which has a 'hole' in it)
1530 +- default permission flags for branches
1531 +- selectable permission flags for ro branch, whether whiteout can
1534 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
1535 +- support multiple writable branches, some policies to select one
1536 + among multiple writable branches.
1537 +- a new semantics for link(2) and rename(2) to support multiple
1538 + writable branches.
1539 +- no glibc changes are required.
1540 +- pseudo hardlink (hardlink over branches)
1541 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
1542 + including NFS or remote filesystem branch.
1543 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
1546 +Currently these features are dropped temporary from aufs3.
1547 +See design/08plan.txt in detail.
1548 +- test only the highest one for the directory permission (dirperm1)
1549 +- copyup on open (coo=)
1550 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
1552 +- statistics of aufs thread (/sys/fs/aufs/stat)
1553 +- delegation mode (dlgt)
1554 + a delegation of the internal branch access to support task I/O
1555 + accounting, which also supports Linux Security Modules (LSM) mainly
1556 + for Suse AppArmor.
1557 +- intent.open/create (file open in a single lookup)
1559 +Features or just an idea in the future (see also design/*.txt),
1560 +- reorder the branch index without del/re-add.
1561 +- permanent xino files for NFSD
1562 +- an option for refreshing the opened files after add/del branches
1563 +- 'move' policy for copy-up between two writable branches, after
1564 + checking free space.
1565 +- light version, without branch manipulation. (unnecessary?)
1566 +- copyup in userspace
1567 +- inotify in userspace
1573 +----------------------------------------
1574 +There were three GIT trees for aufs3, aufs3-linux.git,
1575 +aufs3-standalone.git, and aufs-util.git. Note that there is no "3" in
1577 +While the aufs-util is always necessary, you need either of aufs3-linux
1578 +or aufs3-standalone.
1580 +The aufs3-linux tree includes the whole linux mainline GIT tree,
1581 +git://git.kernel.org/.../torvalds/linux.git.
1582 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
1583 +build aufs3 as an external kernel module.
1585 +On the other hand, the aufs3-standalone tree has only aufs source files
1586 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
1588 +You will find GIT branches whose name is in form of "aufs3.x" where "x"
1589 +represents the linux kernel version, "linux-3.x". For instance,
1590 +"aufs3.0" is for linux-3.0. For latest "linux-3.x-rcN", use
1591 +"aufs3.x-rcN" branch.
1594 +$ git clone --reference /your/linux/git/tree \
1595 + git://git.code.sf.net/p/aufs/aufs3-linux aufs-aufs3-linux \
1597 +- if you don't have linux GIT tree, then remove "--reference ..."
1598 +$ cd aufs3-linux.git
1599 +$ git checkout origin/aufs3.0
1601 +o aufs3-standalone tree
1602 +$ git clone git://git.code.sf.net/p/aufs/aufs3-standalone \
1603 + aufs3-standalone.git
1604 +$ cd aufs3-standalone.git
1605 +$ git checkout origin/aufs3.0
1608 +$ git clone git://git.code.sf.net/p/aufs/aufs-util \
1611 +$ git checkout origin/aufs3.0
1613 +Note: The 3.x-rcN branch is to be used with `rc' kernel versions ONLY.
1614 +The minor version number, 'x' in '3.x', of aufs may not always
1615 +follow the minor version number of the kernel.
1616 +Because changes in the kernel that cause the use of a new
1617 +minor version number do not always require changes to aufs-util.
1619 +Since aufs-util has its own minor version number, you may not be
1620 +able to find a GIT branch in aufs-util for your kernel's
1621 +exact minor version number.
1622 +In this case, you should git-checkout the branch for the
1623 +nearest lower number.
1625 +For (an unreleased) example:
1626 +If you are using "linux-3.10" and the "aufs3.10" branch
1627 +does not exist in aufs-util repository, then "aufs3.9", "aufs3.8"
1628 +or something numerically smaller is the branch for your kernel.
1630 +Also you can view all branches by
1634 +3. Configuration and Compilation
1635 +----------------------------------------
1636 +Make sure you have git-checkout'ed the correct branch.
1638 +For aufs3-linux tree,
1639 +- enable CONFIG_AUFS_FS.
1640 +- set other aufs configurations if necessary.
1642 +For aufs3-standalone tree,
1643 +There are several ways to build.
1646 +- apply ./aufs3-kbuild.patch to your kernel source files.
1647 +- apply ./aufs3-base.patch too.
1648 +- apply ./aufs3-mmap.patch too.
1649 +- apply ./aufs3-standalone.patch too, if you have a plan to set
1650 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs3-standalone.patch.
1651 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
1652 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
1653 +- enable CONFIG_AUFS_FS, you can select either
1655 +- and build your kernel as usual.
1656 +- install the built kernel.
1657 + Note: Since linux-3.9, every filesystem module requires an alias
1658 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
1659 + modules.aliases file if you set CONFIG_AUFS_FS=m.
1660 +- install the header files too by "make headers_install" to the
1661 + directory where you specify. By default, it is $PWD/usr.
1662 + "make help" shows a brief note for headers_install.
1663 +- and reboot your system.
1666 +- module only (CONFIG_AUFS_FS=m).
1667 +- apply ./aufs3-base.patch to your kernel source files.
1668 +- apply ./aufs3-mmap.patch too.
1669 +- apply ./aufs3-standalone.patch too.
1670 +- build your kernel, don't forget "make headers_install", and reboot.
1671 +- edit ./config.mk and set other aufs configurations if necessary.
1672 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
1673 + every aufs configurations.
1674 +- build the module by simple "make".
1675 + Note: Since linux-3.9, every filesystem module requires an alias
1676 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
1677 + modules.aliases file.
1678 +- you can specify ${KDIR} make variable which points to your kernel
1680 +- install the files
1681 + + run "make install" to install the aufs module, or copy the built
1682 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
1683 + + run "make install_headers" (instead of headers_install) to install
1684 + the modified aufs header file (you can specify DESTDIR which is
1685 + available in aufs standalone version's Makefile only), or copy
1686 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
1687 + you like manually. By default, the target directory is $PWD/usr.
1688 +- no need to apply aufs3-kbuild.patch, nor copying source files to your
1689 + kernel source tree.
1691 +Note: The header file aufs_type.h is necessary to build aufs-util
1692 + as well as "make headers_install" in the kernel source tree.
1693 + headers_install is subject to be forgotten, but it is essentially
1694 + necessary, not only for building aufs-util.
1695 + You may not meet problems without headers_install in some older
1699 +- read README in aufs-util, build and install it
1700 +- note that your distribution may contain an obsoleted version of
1701 + aufs_type.h in /usr/include/linux or something. When you build aufs
1702 + utilities, make sure that your compiler refers the correct aufs header
1703 + file which is built by "make headers_install."
1704 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
1705 + then run "make install_ulib" too. And refer to the aufs manual in
1710 +----------------------------------------
1711 +At first, make sure aufs-util are installed, and please read the aufs
1712 +manual, aufs.5 in aufs-util.git tree.
1716 +$ mkdir /tmp/rw /tmp/aufs
1717 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
1719 +Here is another example. The result is equivalent.
1720 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
1722 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
1723 +# mount -o remount,append:${HOME} /tmp/aufs
1725 +Then, you can see whole tree of your home dir through /tmp/aufs. If
1726 +you modify a file under /tmp/aufs, the one on your home directory is
1727 +not affected, instead the same named file will be newly created under
1728 +/tmp/rw. And all of your modification to a file will be applied to
1729 +the one under /tmp/rw. This is called the file based Copy on Write
1731 +Aufs mount options are described in aufs.5.
1732 +If you run chroot or something and make your aufs as a root directory,
1733 +then you need to customize the shutdown script. See the aufs manual in
1736 +Additionally, there are some sample usages of aufs which are a
1737 +diskless system with network booting, and LiveCD over NFS.
1738 +See sample dir in CVS tree on SourceForge.
1742 +----------------------------------------
1743 +When you have any problems or strange behaviour in aufs, please let me
1745 +- /proc/mounts (instead of the output of mount(8))
1746 +- /sys/module/aufs/*
1747 +- /sys/fs/aufs/* (if you have them)
1748 +- /debug/aufs/* (if you have them)
1749 +- linux kernel version
1750 + if your kernel is not plain, for example modified by distributor,
1751 + the url where i can download its source is necessary too.
1752 +- aufs version which was printed at loading the module or booting the
1753 + system, instead of the date you downloaded.
1754 +- configuration (define/undefine CONFIG_AUFS_xxx)
1755 +- kernel configuration or /proc/config.gz (if you have it)
1756 +- behaviour which you think to be incorrect
1757 +- actual operation, reproducible one is better
1758 +- mailto: aufs-users at lists.sourceforge.net
1760 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
1761 +and Feature Requests) on SourceForge. Please join and write to
1765 +6. Acknowledgements
1766 +----------------------------------------
1767 +Thanks to everyone who have tried and are using aufs, whoever
1768 +have reported a bug or any feedback.
1770 +Especially donators:
1771 +Tomas Matejicek(slax.org) made a donation (much more than once).
1772 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
1773 + scripts) is making "doubling" donations.
1774 + Unfortunately I cannot list all of the donators, but I really
1776 + It ends Aug 2010, but the ordinary donation URL is still available.
1777 + <http://sourceforge.net/donate/index.php?group_id=167503>
1778 +Dai Itasaka made a donation (2007/8).
1779 +Chuck Smith made a donation (2008/4, 10 and 12).
1780 +Henk Schoneveld made a donation (2008/9).
1781 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
1782 +Francois Dupoux made a donation (2008/11).
1783 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
1784 + aufs2 GIT tree (2009/2).
1785 +William Grant made a donation (2009/3).
1786 +Patrick Lane made a donation (2009/4).
1787 +The Mail Archive (mail-archive.com) made donations (2009/5).
1788 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
1789 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
1790 +Pavel Pronskiy made a donation (2011/2).
1791 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
1792 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
1793 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
1795 +Sam Liddicott made a donation (2011/9).
1796 +Era Scarecrow made a donation (2013/4).
1797 +Bor Ratajc made a donation (2013/4).
1798 +Alessandro Gorreta made a donation (2013/4).
1799 +POIRETTE Marc made a donation (2013/4).
1800 +Alessandro Gorreta made a donation (2013/4).
1801 +lauri kasvandik made a donation (2013/5).
1802 +"pemasu from Finland" made a donation (2013/7).
1803 +The Parted Magic Project made a donation (2013/9 and 11).
1804 +Pavel Barta made a donation (2013/10).
1806 +Thank you very much.
1807 +Donations are always, including future donations, very important and
1808 +helpful for me to keep on developing aufs.
1812 +----------------------------------------
1813 +If you are an experienced user, no explanation is needed. Aufs is
1814 +just a linux filesystem.
1819 +# Local variables: ;
1822 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
1823 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
1824 +++ linux/fs/aufs/aufs.h 2014-01-20 20:16:14.732796615 +0100
1827 + * Copyright (C) 2005-2014 Junjiro R. Okajima
1829 + * This program, aufs is free software; you can redistribute it and/or modify
1830 + * it under the terms of the GNU General Public License as published by
1831 + * the Free Software Foundation; either version 2 of the License, or
1832 + * (at your option) any later version.
1834 + * This program is distributed in the hope that it will be useful,
1835 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1836 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1837 + * GNU General Public License for more details.
1839 + * You should have received a copy of the GNU General Public License
1840 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
1844 + * all header files
1852 +#define AuStub(type, name, body, ...) \
1853 + static inline type name(__VA_ARGS__) { body; }
1855 +#define AuStubVoid(name, ...) \
1856 + AuStub(void, name, , __VA_ARGS__)
1857 +#define AuStubInt0(name, ...) \
1858 + AuStub(int, name, return 0, __VA_ARGS__)
1862 +#include "branch.h"
1865 +#include "dbgaufs.h"
1866 +#include "dentry.h"
1870 +#include "fstype.h"
1873 +#include "module.h"
1878 +#include "sysaufs.h"
1883 +#endif /* __KERNEL__ */
1884 +#endif /* __AUFS_H__ */
1885 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
1886 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
1887 +++ linux/fs/aufs/branch.c 2014-01-20 20:16:14.732796615 +0100
1890 + * Copyright (C) 2005-2014 Junjiro R. Okajima
1892 + * This program, aufs is free software; you can redistribute it and/or modify
1893 + * it under the terms of the GNU General Public License as published by
1894 + * the Free Software Foundation; either version 2 of the License, or
1895 + * (at your option) any later version.
1897 + * This program is distributed in the hope that it will be useful,
1898 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1899 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1900 + * GNU General Public License for more details.
1902 + * You should have received a copy of the GNU General Public License
1903 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
1907 + * branch management
1910 +#include <linux/compat.h>
1911 +#include <linux/statfs.h>
1915 + * free a single branch
1918 +/* prohibit rmdir to the root of the branch */
1919 +/* todo: another new flag? */
1920 +static void au_br_dflags_force(struct au_branch *br)
1922 + struct dentry *h_dentry;
1924 + h_dentry = au_br_dentry(br);
1925 + spin_lock(&h_dentry->d_lock);
1926 + br->br_dflags = h_dentry->d_flags & DCACHE_MOUNTED;
1927 + h_dentry->d_flags |= DCACHE_MOUNTED;
1928 + spin_unlock(&h_dentry->d_lock);
1931 +/* restore its d_flags */
1932 +static void au_br_dflags_restore(struct au_branch *br)
1934 + struct dentry *h_dentry;
1936 + if (br->br_dflags)
1939 + h_dentry = au_br_dentry(br);
1940 + spin_lock(&h_dentry->d_lock);
1941 + h_dentry->d_flags &= ~DCACHE_MOUNTED;
1942 + spin_unlock(&h_dentry->d_lock);
1945 +static void au_br_do_free(struct au_branch *br)
1948 + struct au_wbr *wbr;
1949 + struct au_dykey **key;
1951 + au_hnotify_fin_br(br);
1953 + if (br->br_xino.xi_file)
1954 + fput(br->br_xino.xi_file);
1955 + mutex_destroy(&br->br_xino.xi_nondir_mtx);
1957 + AuDebugOn(atomic_read(&br->br_count));
1961 + for (i = 0; i < AuBrWh_Last; i++)
1962 + dput(wbr->wbr_wh[i]);
1963 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
1964 + AuRwDestroy(&wbr->wbr_wh_rwsem);
1967 + key = br->br_dykey;
1968 + for (i = 0; i < AuBrDynOp; i++, key++)
1974 + au_br_dflags_restore(br);
1976 + /* recursive lock, s_umount of branch's */
1978 + path_put(&br->br_path);
1985 + * frees all branches
1987 +void au_br_free(struct au_sbinfo *sbinfo)
1989 + aufs_bindex_t bmax;
1990 + struct au_branch **br;
1992 + AuRwMustWriteLock(&sbinfo->si_rwsem);
1994 + bmax = sbinfo->si_bend + 1;
1995 + br = sbinfo->si_branch;
1997 + au_br_do_free(*br++);
2001 + * find the index of a branch which is specified by @br_id.
2003 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
2005 + aufs_bindex_t bindex, bend;
2007 + bend = au_sbend(sb);
2008 + for (bindex = 0; bindex <= bend; bindex++)
2009 + if (au_sbr_id(sb, bindex) == br_id)
2014 +/* ---------------------------------------------------------------------- */
2020 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
2021 + struct dentry *h_root)
2023 + if (unlikely(h_adding == h_root
2024 + || au_test_loopback_overlap(sb, h_adding)))
2026 + if (h_adding->d_sb != h_root->d_sb)
2028 + return au_test_subdir(h_adding, h_root)
2029 + || au_test_subdir(h_root, h_adding);
2033 + * returns a newly allocated branch. @new_nbranch is a number of branches
2034 + * after adding a branch.
2036 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
2039 + struct au_branch *add_branch;
2040 + struct dentry *root;
2044 + root = sb->s_root;
2045 + add_branch = kmalloc(sizeof(*add_branch), GFP_NOFS);
2046 + if (unlikely(!add_branch))
2049 + err = au_hnotify_init_br(add_branch, perm);
2050 + if (unlikely(err))
2053 + add_branch->br_wbr = NULL;
2054 + if (au_br_writable(perm)) {
2055 + /* may be freed separately at changing the branch permission */
2056 + add_branch->br_wbr = kmalloc(sizeof(*add_branch->br_wbr),
2058 + if (unlikely(!add_branch->br_wbr))
2062 + err = au_sbr_realloc(au_sbi(sb), new_nbranch);
2064 + err = au_di_realloc(au_di(root), new_nbranch);
2066 + err = au_ii_realloc(au_ii(root->d_inode), new_nbranch);
2068 + return add_branch; /* success */
2070 + kfree(add_branch->br_wbr);
2073 + au_hnotify_fin_br(add_branch);
2075 + kfree(add_branch);
2077 + return ERR_PTR(err);
2081 + * test if the branch permission is legal or not.
2083 +static int test_br(struct inode *inode, int brperm, char *path)
2087 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
2092 + pr_err("write permission for readonly mount or inode, %s\n", path);
2100 + * 0: success, the caller will add it
2101 + * plus: success, it is already unified, the caller should ignore it
2104 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
2107 + aufs_bindex_t bend, bindex;
2108 + struct dentry *root;
2109 + struct inode *inode, *h_inode;
2111 + root = sb->s_root;
2112 + bend = au_sbend(sb);
2113 + if (unlikely(bend >= 0
2114 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
2118 + pr_err("%s duplicated\n", add->pathname);
2123 + err = -ENOSPC; /* -E2BIG; */
2124 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
2125 + || AUFS_BRANCH_MAX - 1 <= bend)) {
2126 + pr_err("number of branches exceeded %s\n", add->pathname);
2131 + if (unlikely(add->bindex < 0 || bend + 1 < add->bindex)) {
2132 + pr_err("bad index %d\n", add->bindex);
2136 + inode = add->path.dentry->d_inode;
2138 + if (unlikely(!inode->i_nlink)) {
2139 + pr_err("no existence %s\n", add->pathname);
2144 + if (unlikely(inode->i_sb == sb)) {
2145 + pr_err("%s must be outside\n", add->pathname);
2149 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
2150 + pr_err("unsupported filesystem, %s (%s)\n",
2151 + add->pathname, au_sbtype(inode->i_sb));
2155 + err = test_br(add->path.dentry->d_inode, add->perm, add->pathname);
2156 + if (unlikely(err))
2160 + return 0; /* success */
2163 + for (bindex = 0; bindex <= bend; bindex++)
2164 + if (unlikely(test_overlap(sb, add->path.dentry,
2165 + au_h_dptr(root, bindex)))) {
2166 + pr_err("%s is overlapped\n", add->pathname);
2171 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
2172 + h_inode = au_h_dptr(root, 0)->d_inode;
2173 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
2174 + || !uid_eq(h_inode->i_uid, inode->i_uid)
2175 + || !gid_eq(h_inode->i_gid, inode->i_gid))
2176 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
2178 + i_uid_read(inode), i_gid_read(inode),
2179 + (inode->i_mode & S_IALLUGO),
2180 + i_uid_read(h_inode), i_gid_read(h_inode),
2181 + (h_inode->i_mode & S_IALLUGO));
2189 + * initialize or clean the whiteouts for an adding branch
2191 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
2194 + int err, old_perm;
2195 + aufs_bindex_t bindex;
2196 + struct mutex *h_mtx;
2197 + struct au_wbr *wbr;
2198 + struct au_hinode *hdir;
2200 + err = vfsub_mnt_want_write(au_br_mnt(br));
2201 + if (unlikely(err))
2205 + old_perm = br->br_perm;
2206 + br->br_perm = new_perm;
2209 + bindex = au_br_index(sb, br->br_id);
2210 + if (0 <= bindex) {
2211 + hdir = au_hi(sb->s_root->d_inode, bindex);
2212 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
2214 + h_mtx = &au_br_dentry(br)->d_inode->i_mutex;
2215 + mutex_lock_nested(h_mtx, AuLsc_I_PARENT);
2218 + err = au_wh_init(br, sb);
2220 + wbr_wh_write_lock(wbr);
2221 + err = au_wh_init(br, sb);
2222 + wbr_wh_write_unlock(wbr);
2225 + au_hn_imtx_unlock(hdir);
2227 + mutex_unlock(h_mtx);
2228 + vfsub_mnt_drop_write(au_br_mnt(br));
2229 + br->br_perm = old_perm;
2231 + if (!err && wbr && !au_br_writable(new_perm)) {
2233 + br->br_wbr = NULL;
2240 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
2244 + struct kstatfs kst;
2245 + struct au_wbr *wbr;
2248 + au_rw_init(&wbr->wbr_wh_rwsem);
2249 + memset(wbr->wbr_wh, 0, sizeof(wbr->wbr_wh));
2250 + atomic_set(&wbr->wbr_wh_running, 0);
2251 + wbr->wbr_bytes = 0;
2254 + * a limit for rmdir/rename a dir
2255 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
2257 + err = vfs_statfs(&br->br_path, &kst);
2258 + if (unlikely(err))
2261 + if (kst.f_namelen >= NAME_MAX)
2262 + err = au_br_init_wh(sb, br, perm);
2264 + pr_err("%pd(%s), unsupported namelen %ld\n",
2266 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
2272 +/* intialize a new branch */
2273 +static int au_br_init(struct au_branch *br, struct super_block *sb,
2274 + struct au_opt_add *add)
2279 + memset(&br->br_xino, 0, sizeof(br->br_xino));
2280 + mutex_init(&br->br_xino.xi_nondir_mtx);
2281 + br->br_perm = add->perm;
2282 + BUILD_BUG_ON(sizeof(br->br_dflags)
2283 + != sizeof(br->br_path.dentry->d_flags));
2284 + br->br_dflags = DCACHE_MOUNTED;
2285 + br->br_path = add->path; /* set first, path_get() later */
2286 + spin_lock_init(&br->br_dykey_lock);
2287 + memset(br->br_dykey, 0, sizeof(br->br_dykey));
2288 + atomic_set(&br->br_count, 0);
2289 + atomic_set(&br->br_xino_running, 0);
2290 + br->br_id = au_new_br_id(sb);
2291 + AuDebugOn(br->br_id < 0);
2293 + if (au_br_writable(add->perm)) {
2294 + err = au_wbr_init(br, sb, add->perm);
2295 + if (unlikely(err))
2299 + if (au_opt_test(au_mntflags(sb), XINO)) {
2300 + err = au_xino_br(sb, br, add->path.dentry->d_inode->i_ino,
2301 + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1);
2302 + if (unlikely(err)) {
2303 + AuDebugOn(br->br_xino.xi_file);
2308 + sysaufs_br_init(br);
2309 + path_get(&br->br_path);
2310 + goto out; /* success */
2313 + memset(&br->br_path, 0, sizeof(br->br_path));
2318 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
2319 + struct au_branch *br, aufs_bindex_t bend,
2320 + aufs_bindex_t amount)
2322 + struct au_branch **brp;
2324 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2326 + brp = sbinfo->si_branch + bindex;
2327 + memmove(brp + 1, brp, sizeof(*brp) * amount);
2329 + sbinfo->si_bend++;
2330 + if (unlikely(bend < 0))
2331 + sbinfo->si_bend = 0;
2334 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
2335 + aufs_bindex_t bend, aufs_bindex_t amount)
2337 + struct au_hdentry *hdp;
2339 + AuRwMustWriteLock(&dinfo->di_rwsem);
2341 + hdp = dinfo->di_hdentry + bindex;
2342 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
2343 + au_h_dentry_init(hdp);
2345 + if (unlikely(bend < 0))
2346 + dinfo->di_bstart = 0;
2349 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
2350 + aufs_bindex_t bend, aufs_bindex_t amount)
2352 + struct au_hinode *hip;
2354 + AuRwMustWriteLock(&iinfo->ii_rwsem);
2356 + hip = iinfo->ii_hinode + bindex;
2357 + memmove(hip + 1, hip, sizeof(*hip) * amount);
2358 + hip->hi_inode = NULL;
2361 + if (unlikely(bend < 0))
2362 + iinfo->ii_bstart = 0;
2365 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
2366 + aufs_bindex_t bindex)
2368 + struct dentry *root, *h_dentry;
2369 + struct inode *root_inode;
2370 + aufs_bindex_t bend, amount;
2372 + au_br_dflags_force(br);
2374 + root = sb->s_root;
2375 + root_inode = root->d_inode;
2376 + bend = au_sbend(sb);
2377 + amount = bend + 1 - bindex;
2378 + h_dentry = au_br_dentry(br);
2379 + au_sbilist_lock();
2380 + au_br_do_add_brp(au_sbi(sb), bindex, br, bend, amount);
2381 + au_br_do_add_hdp(au_di(root), bindex, bend, amount);
2382 + au_br_do_add_hip(au_ii(root_inode), bindex, bend, amount);
2383 + au_set_h_dptr(root, bindex, dget(h_dentry));
2384 + au_set_h_iptr(root_inode, bindex, au_igrab(h_dentry->d_inode),
2386 + au_sbilist_unlock();
2389 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
2392 + aufs_bindex_t bend, add_bindex;
2393 + struct dentry *root, *h_dentry;
2394 + struct inode *root_inode;
2395 + struct au_branch *add_branch;
2397 + root = sb->s_root;
2398 + root_inode = root->d_inode;
2399 + IMustLock(root_inode);
2400 + err = test_add(sb, add, remount);
2401 + if (unlikely(err < 0))
2405 + goto out; /* success */
2408 + bend = au_sbend(sb);
2409 + add_branch = au_br_alloc(sb, bend + 2, add->perm);
2410 + err = PTR_ERR(add_branch);
2411 + if (IS_ERR(add_branch))
2414 + err = au_br_init(add_branch, sb, add);
2415 + if (unlikely(err)) {
2416 + au_br_do_free(add_branch);
2420 + add_bindex = add->bindex;
2422 + au_br_do_add(sb, add_branch, add_bindex);
2424 + sysaufs_brs_del(sb, add_bindex);
2425 + au_br_do_add(sb, add_branch, add_bindex);
2426 + sysaufs_brs_add(sb, add_bindex);
2429 + h_dentry = add->path.dentry;
2430 + if (!add_bindex) {
2431 + au_cpup_attr_all(root_inode, /*force*/1);
2432 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
2434 + au_add_nlink(root_inode, h_dentry->d_inode);
2437 + * this test/set prevents aufs from handling unnecesary notify events
2438 + * of xino files, in case of re-adding a writable branch which was
2439 + * once detached from aufs.
2441 + if (au_xino_brid(sb) < 0
2442 + && au_br_writable(add_branch->br_perm)
2443 + && !au_test_fs_bad_xino(h_dentry->d_sb)
2444 + && add_branch->br_xino.xi_file
2445 + && add_branch->br_xino.xi_file->f_dentry->d_parent == h_dentry)
2446 + au_xino_brid_set(sb, add_branch->br_id);
2452 +/* ---------------------------------------------------------------------- */
2458 +/* to show the line number, do not make it inlined function */
2459 +#define AuVerbose(do_info, fmt, ...) do { \
2461 + pr_info(fmt, ##__VA_ARGS__); \
2464 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t bstart,
2465 + aufs_bindex_t bend)
2467 + return (inode && !S_ISDIR(inode->i_mode)) || bstart == bend;
2470 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t bstart,
2471 + aufs_bindex_t bend)
2473 + return au_test_ibusy(dentry->d_inode, bstart, bend);
2477 + * test if the branch is deletable or not.
2479 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
2480 + unsigned int sigen, const unsigned int verbose)
2482 + int err, i, j, ndentry;
2483 + aufs_bindex_t bstart, bend;
2484 + struct au_dcsub_pages dpages;
2485 + struct au_dpage *dpage;
2488 + err = au_dpages_init(&dpages, GFP_NOFS);
2489 + if (unlikely(err))
2491 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
2492 + if (unlikely(err))
2495 + for (i = 0; !err && i < dpages.ndpage; i++) {
2496 + dpage = dpages.dpages + i;
2497 + ndentry = dpage->ndentry;
2498 + for (j = 0; !err && j < ndentry; j++) {
2499 + d = dpage->dentries[j];
2500 + AuDebugOn(!d_count(d));
2501 + if (!au_digen_test(d, sigen)) {
2502 + di_read_lock_child(d, AuLock_IR);
2503 + if (unlikely(au_dbrange_test(d))) {
2504 + di_read_unlock(d, AuLock_IR);
2508 + di_write_lock_child(d);
2509 + if (unlikely(au_dbrange_test(d))) {
2510 + di_write_unlock(d);
2513 + err = au_reval_dpath(d, sigen);
2515 + di_downgrade_lock(d, AuLock_IR);
2517 + di_write_unlock(d);
2522 + /* AuDbgDentry(d); */
2523 + bstart = au_dbstart(d);
2524 + bend = au_dbend(d);
2525 + if (bstart <= bindex
2527 + && au_h_dptr(d, bindex)
2528 + && au_test_dbusy(d, bstart, bend)) {
2530 + AuVerbose(verbose, "busy %pd\n", d);
2533 + di_read_unlock(d, AuLock_IR);
2538 + au_dpages_free(&dpages);
2543 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
2544 + unsigned int sigen, const unsigned int verbose)
2547 + unsigned long long max, ull;
2548 + struct inode *i, **array;
2549 + aufs_bindex_t bstart, bend;
2551 + array = au_iarray_alloc(sb, &max);
2552 + err = PTR_ERR(array);
2553 + if (IS_ERR(array))
2557 + AuDbg("b%d\n", bindex);
2558 + for (ull = 0; !err && ull < max; ull++) {
2560 + if (i->i_ino == AUFS_ROOT_INO)
2563 + /* AuDbgInode(i); */
2564 + if (au_iigen(i, NULL) == sigen)
2565 + ii_read_lock_child(i);
2567 + ii_write_lock_child(i);
2568 + err = au_refresh_hinode_self(i);
2571 + ii_downgrade_lock(i);
2573 + ii_write_unlock(i);
2578 + bstart = au_ibstart(i);
2579 + bend = au_ibend(i);
2580 + if (bstart <= bindex
2582 + && au_h_iptr(i, bindex)
2583 + && au_test_ibusy(i, bstart, bend)) {
2585 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
2588 + ii_read_unlock(i);
2590 + au_iarray_free(array, max);
2596 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
2597 + const unsigned int verbose)
2600 + unsigned int sigen;
2602 + sigen = au_sigen(root->d_sb);
2603 + DiMustNoWaiters(root);
2604 + IiMustNoWaiters(root->d_inode);
2605 + di_write_unlock(root);
2606 + err = test_dentry_busy(root, bindex, sigen, verbose);
2608 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
2609 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
2614 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
2615 + const aufs_bindex_t bindex,
2616 + const aufs_bindex_t bend)
2618 + struct au_branch **brp, **p;
2620 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2622 + brp = sbinfo->si_branch + bindex;
2623 + if (bindex < bend)
2624 + memmove(brp, brp + 1, sizeof(*brp) * (bend - bindex));
2625 + sbinfo->si_branch[0 + bend] = NULL;
2626 + sbinfo->si_bend--;
2628 + p = krealloc(sbinfo->si_branch, sizeof(*p) * bend, AuGFP_SBILIST);
2630 + sbinfo->si_branch = p;
2631 + /* harmless error */
2634 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
2635 + const aufs_bindex_t bend)
2637 + struct au_hdentry *hdp, *p;
2639 + AuRwMustWriteLock(&dinfo->di_rwsem);
2641 + hdp = dinfo->di_hdentry;
2642 + if (bindex < bend)
2643 + memmove(hdp + bindex, hdp + bindex + 1,
2644 + sizeof(*hdp) * (bend - bindex));
2645 + hdp[0 + bend].hd_dentry = NULL;
2648 + p = krealloc(hdp, sizeof(*p) * bend, AuGFP_SBILIST);
2650 + dinfo->di_hdentry = p;
2651 + /* harmless error */
2654 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
2655 + const aufs_bindex_t bend)
2657 + struct au_hinode *hip, *p;
2659 + AuRwMustWriteLock(&iinfo->ii_rwsem);
2661 + hip = iinfo->ii_hinode + bindex;
2662 + if (bindex < bend)
2663 + memmove(hip, hip + 1, sizeof(*hip) * (bend - bindex));
2664 + iinfo->ii_hinode[0 + bend].hi_inode = NULL;
2665 + au_hn_init(iinfo->ii_hinode + bend);
2668 + p = krealloc(iinfo->ii_hinode, sizeof(*p) * bend, AuGFP_SBILIST);
2670 + iinfo->ii_hinode = p;
2671 + /* harmless error */
2674 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
2675 + struct au_branch *br)
2677 + aufs_bindex_t bend;
2678 + struct au_sbinfo *sbinfo;
2679 + struct dentry *root, *h_root;
2680 + struct inode *inode, *h_inode;
2681 + struct au_hinode *hinode;
2683 + SiMustWriteLock(sb);
2685 + root = sb->s_root;
2686 + inode = root->d_inode;
2687 + sbinfo = au_sbi(sb);
2688 + bend = sbinfo->si_bend;
2690 + h_root = au_h_dptr(root, bindex);
2691 + hinode = au_hi(inode, bindex);
2692 + h_inode = au_igrab(hinode->hi_inode);
2695 + au_sbilist_lock();
2696 + au_br_do_del_brp(sbinfo, bindex, bend);
2697 + au_br_do_del_hdp(au_di(root), bindex, bend);
2698 + au_br_do_del_hip(au_ii(inode), bindex, bend);
2699 + au_sbilist_unlock();
2703 + au_br_do_free(br);
2706 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
2709 + unsigned int mnt_flags;
2710 + aufs_bindex_t bindex, bend, br_id;
2711 + unsigned char do_wh, verbose;
2712 + struct au_branch *br;
2713 + struct au_wbr *wbr;
2716 + bindex = au_find_dbindex(sb->s_root, del->h_path.dentry);
2719 + goto out; /* success */
2721 + pr_err("%s no such branch\n", del->pathname);
2724 + AuDbg("bindex b%d\n", bindex);
2727 + mnt_flags = au_mntflags(sb);
2728 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
2729 + bend = au_sbend(sb);
2730 + if (unlikely(!bend)) {
2731 + AuVerbose(verbose, "no more branches left\n");
2734 + br = au_sbr(sb, bindex);
2735 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
2736 + i = atomic_read(&br->br_count);
2737 + if (unlikely(i)) {
2738 + AuVerbose(verbose, "%d file(s) opened\n", i);
2743 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
2745 + /* instead of WbrWhMustWriteLock(wbr) */
2746 + SiMustWriteLock(sb);
2747 + for (i = 0; i < AuBrWh_Last; i++) {
2748 + dput(wbr->wbr_wh[i]);
2749 + wbr->wbr_wh[i] = NULL;
2753 + err = test_children_busy(sb->s_root, bindex, verbose);
2754 + if (unlikely(err)) {
2761 + br_id = br->br_id;
2763 + au_br_do_del(sb, bindex, br);
2765 + sysaufs_brs_del(sb, bindex);
2766 + au_br_do_del(sb, bindex, br);
2767 + sysaufs_brs_add(sb, bindex);
2771 + au_cpup_attr_all(sb->s_root->d_inode, /*force*/1);
2772 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
2774 + au_sub_nlink(sb->s_root->d_inode, del->h_path.dentry->d_inode);
2775 + if (au_opt_test(mnt_flags, PLINK))
2776 + au_plink_half_refresh(sb, br_id);
2778 + if (au_xino_brid(sb) == br_id)
2779 + au_xino_brid_set(sb, -1);
2780 + goto out; /* success */
2784 + rerr = au_br_init_wh(sb, br, br->br_perm);
2786 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
2787 + del->pathname, rerr);
2792 +/* ---------------------------------------------------------------------- */
2794 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
2797 + aufs_bindex_t bstart, bend;
2798 + struct aufs_ibusy ibusy;
2799 + struct inode *inode, *h_inode;
2802 + if (unlikely(!capable(CAP_SYS_ADMIN)))
2805 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
2807 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
2808 + if (unlikely(err)) {
2815 + si_read_lock(sb, AuLock_FLUSH);
2816 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbend(sb)))
2820 + ibusy.h_ino = 0; /* invalid */
2821 + inode = ilookup(sb, ibusy.ino);
2823 + || inode->i_ino == AUFS_ROOT_INO
2824 + || is_bad_inode(inode))
2827 + ii_read_lock_child(inode);
2828 + bstart = au_ibstart(inode);
2829 + bend = au_ibend(inode);
2830 + if (bstart <= ibusy.bindex && ibusy.bindex <= bend) {
2831 + h_inode = au_h_iptr(inode, ibusy.bindex);
2832 + if (h_inode && au_test_ibusy(inode, bstart, bend))
2833 + ibusy.h_ino = h_inode->i_ino;
2835 + ii_read_unlock(inode);
2839 + si_read_unlock(sb);
2841 + err = __put_user(ibusy.h_ino, &arg->h_ino);
2842 + if (unlikely(err)) {
2851 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
2853 + return au_ibusy(file->f_dentry->d_sb, (void __user *)arg);
2856 +#ifdef CONFIG_COMPAT
2857 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
2859 + return au_ibusy(file->f_dentry->d_sb, compat_ptr(arg));
2863 +/* ---------------------------------------------------------------------- */
2866 + * change a branch permission
2869 +static void au_warn_ima(void)
2872 + /* since it doesn't support mark_files_ro() */
2873 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
2877 +static int do_need_sigen_inc(int a, int b)
2879 + return au_br_whable(a) && !au_br_whable(b);
2882 +static int need_sigen_inc(int old, int new)
2884 + return do_need_sigen_inc(old, new)
2885 + || do_need_sigen_inc(new, old);
2888 +static unsigned long long au_farray_cb(void *a,
2889 + unsigned long long max __maybe_unused,
2892 + unsigned long long n;
2893 + struct file **p, *f;
2894 + struct au_sphlhead *files;
2895 + struct au_finfo *finfo;
2896 + struct super_block *sb = arg;
2900 + files = &au_sbi(sb)->si_files;
2901 + spin_lock(&files->spin);
2902 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
2903 + f = finfo->fi_file;
2905 + && !special_file(file_inode(f)->i_mode)) {
2909 + AuDebugOn(n > max);
2912 + spin_unlock(&files->spin);
2917 +static struct file **au_farray_alloc(struct super_block *sb,
2918 + unsigned long long *max)
2920 + *max = atomic_long_read(&au_sbi(sb)->si_nfiles);
2921 + return au_array_alloc(max, au_farray_cb, sb);
2924 +static void au_farray_free(struct file **a, unsigned long long max)
2926 + unsigned long long ull;
2928 + for (ull = 0; ull < max; ull++)
2934 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
2937 + unsigned int mnt_flags;
2938 + unsigned long long ull, max;
2939 + aufs_bindex_t br_id;
2940 + unsigned char verbose;
2941 + struct file *file, *hf, **array;
2942 + struct inode *inode;
2943 + struct au_hfile *hfile;
2945 + mnt_flags = au_mntflags(sb);
2946 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
2948 + array = au_farray_alloc(sb, &max);
2949 + err = PTR_ERR(array);
2950 + if (IS_ERR(array))
2954 + br_id = au_sbr_id(sb, bindex);
2955 + for (ull = 0; ull < max; ull++) {
2956 + file = array[ull];
2958 + /* AuDbg("%pD\n", file); */
2959 + fi_read_lock(file);
2960 + if (unlikely(au_test_mmapped(file))) {
2962 + AuVerbose(verbose, "mmapped %pD\n", file);
2964 + FiMustNoWaiters(file);
2965 + fi_read_unlock(file);
2969 + inode = file_inode(file);
2970 + hfile = &au_fi(file)->fi_htop;
2971 + hf = hfile->hf_file;
2972 + if (!S_ISREG(inode->i_mode)
2973 + || !(file->f_mode & FMODE_WRITE)
2974 + || hfile->hf_br->br_id != br_id
2975 + || !(hf->f_mode & FMODE_WRITE))
2976 + array[ull] = NULL;
2982 + FiMustNoWaiters(file);
2983 + fi_read_unlock(file);
2991 + for (ull = 0; ull < max; ull++) {
2992 + file = array[ull];
2996 + /* todo: already flushed? */
2998 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
2999 + * approach which resets f_mode and calls mnt_drop_write() and
3000 + * file_release_write() for each file, because the branch
3001 + * attribute in aufs world is totally different from the native
3004 + /* fi_read_lock(file); */
3005 + hfile = &au_fi(file)->fi_htop;
3006 + hf = hfile->hf_file;
3007 + /* fi_read_unlock(file); */
3008 + spin_lock(&hf->f_lock);
3009 + hf->f_mode &= ~FMODE_WRITE;
3010 + spin_unlock(&hf->f_lock);
3011 + if (!file_check_writeable(hf)) {
3012 + __mnt_drop_write(hf->f_path.mnt);
3013 + file_release_write(hf);
3018 + au_farray_free(array, max);
3024 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
3028 + aufs_bindex_t bindex;
3029 + struct dentry *root;
3030 + struct au_branch *br;
3032 + root = sb->s_root;
3033 + bindex = au_find_dbindex(root, mod->h_root);
3036 + return 0; /* success */
3038 + pr_err("%s no such branch\n", mod->path);
3041 + AuDbg("bindex b%d\n", bindex);
3043 + err = test_br(mod->h_root->d_inode, mod->perm, mod->path);
3044 + if (unlikely(err))
3047 + br = au_sbr(sb, bindex);
3048 + AuDebugOn(mod->h_root != au_br_dentry(br));
3049 + if (br->br_perm == mod->perm)
3050 + return 0; /* success */
3052 + if (au_br_writable(br->br_perm)) {
3053 + /* remove whiteout base */
3054 + err = au_br_init_wh(sb, br, mod->perm);
3055 + if (unlikely(err))
3058 + if (!au_br_writable(mod->perm)) {
3059 + /* rw --> ro, file might be mmapped */
3060 + DiMustNoWaiters(root);
3061 + IiMustNoWaiters(root->d_inode);
3062 + di_write_unlock(root);
3063 + err = au_br_mod_files_ro(sb, bindex);
3064 + /* aufs_write_lock() calls ..._child() */
3065 + di_write_lock_child(root);
3067 + if (unlikely(err)) {
3069 + br->br_wbr = kmalloc(sizeof(*br->br_wbr),
3072 + rerr = au_wbr_init(br, sb, br->br_perm);
3073 + if (unlikely(rerr)) {
3074 + AuIOErr("nested error %d (%d)\n",
3076 + br->br_perm = mod->perm;
3080 + } else if (au_br_writable(mod->perm)) {
3083 + br->br_wbr = kmalloc(sizeof(*br->br_wbr), GFP_NOFS);
3085 + err = au_wbr_init(br, sb, mod->perm);
3086 + if (unlikely(err)) {
3087 + kfree(br->br_wbr);
3088 + br->br_wbr = NULL;
3094 + if ((br->br_perm & AuBrAttr_UNPIN)
3095 + && !(mod->perm & AuBrAttr_UNPIN))
3096 + au_br_dflags_force(br);
3097 + else if (!(br->br_perm & AuBrAttr_UNPIN)
3098 + && (mod->perm & AuBrAttr_UNPIN))
3099 + au_br_dflags_restore(br);
3100 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
3101 + br->br_perm = mod->perm;
3108 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
3109 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
3110 +++ linux/fs/aufs/branch.h 2014-01-20 20:16:14.732796615 +0100
3113 + * Copyright (C) 2005-2014 Junjiro R. Okajima
3115 + * This program, aufs is free software; you can redistribute it and/or modify
3116 + * it under the terms of the GNU General Public License as published by
3117 + * the Free Software Foundation; either version 2 of the License, or
3118 + * (at your option) any later version.
3120 + * This program is distributed in the hope that it will be useful,
3121 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3122 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3123 + * GNU General Public License for more details.
3125 + * You should have received a copy of the GNU General Public License
3126 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3130 + * branch filesystems and xino for them
3133 +#ifndef __AUFS_BRANCH_H__
3134 +#define __AUFS_BRANCH_H__
3138 +#include <linux/mount.h>
3143 +/* ---------------------------------------------------------------------- */
3146 +struct au_xino_file {
3147 + struct file *xi_file;
3148 + struct mutex xi_nondir_mtx;
3150 + /* todo: make xino files an array to support huge inode number */
3152 +#ifdef CONFIG_DEBUG_FS
3153 + struct dentry *xi_dbgaufs;
3157 +/* members for writable branch only */
3158 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
3160 + struct au_rwsem wbr_wh_rwsem;
3161 + struct dentry *wbr_wh[AuBrWh_Last];
3162 + atomic_t wbr_wh_running;
3163 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
3164 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
3165 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
3168 + unsigned long long wbr_bytes;
3171 +/* ext2 has 3 types of operations at least, ext3 has 4 */
3172 +#define AuBrDynOp (AuDyLast * 4)
3174 +#ifdef CONFIG_AUFS_HFSNOTIFY
3175 +/* support for asynchronous destruction */
3176 +struct au_br_hfsnotify {
3177 + struct fsnotify_group *hfsn_group;
3181 +/* sysfs entries */
3182 +struct au_brsysfs {
3184 + struct attribute attr;
3193 +/* protected by superblock rwsem */
3195 + struct au_xino_file br_xino;
3197 + aufs_bindex_t br_id;
3200 + unsigned int br_dflags;
3201 + struct path br_path;
3202 + spinlock_t br_dykey_lock;
3203 + struct au_dykey *br_dykey[AuBrDynOp];
3204 + atomic_t br_count;
3206 + struct au_wbr *br_wbr;
3208 + /* xino truncation */
3209 + atomic_t br_xino_running;
3211 +#ifdef CONFIG_AUFS_HFSNOTIFY
3212 + struct au_br_hfsnotify *br_hfsn;
3215 +#ifdef CONFIG_SYSFS
3216 + /* entries under sysfs per mount-point */
3217 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
3221 +/* ---------------------------------------------------------------------- */
3223 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
3225 + return br->br_path.mnt;
3228 +static inline struct dentry *au_br_dentry(struct au_branch *br)
3230 + return br->br_path.dentry;
3233 +static inline struct super_block *au_br_sb(struct au_branch *br)
3235 + return au_br_mnt(br)->mnt_sb;
3238 +/* branch permissions and attributes */
3239 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
3240 +#define AuBrPerm_RO (1 << 1) /* readonly */
3241 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
3242 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
3244 +#define AuBrRAttr_WH (1 << 3) /* whiteout-able */
3246 +#define AuBrWAttr_NoLinkWH (1 << 4) /* un-hardlinkable whiteouts */
3248 +#define AuBrAttr_UNPIN (1 << 5) /* rename-able top dir of
3251 +static inline int au_br_writable(int brperm)
3253 + return brperm & AuBrPerm_RW;
3256 +static inline int au_br_whable(int brperm)
3258 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
3261 +static inline int au_br_wh_linkable(int brperm)
3263 + return !(brperm & AuBrWAttr_NoLinkWH);
3266 +static inline int au_br_rdonly(struct au_branch *br)
3268 + return ((au_br_sb(br)->s_flags & MS_RDONLY)
3269 + || !au_br_writable(br->br_perm))
3273 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
3275 +#ifdef CONFIG_AUFS_HNOTIFY
3276 + return !(brperm & AuBrPerm_RR);
3282 +/* ---------------------------------------------------------------------- */
3286 +void au_br_free(struct au_sbinfo *sinfo);
3287 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
3289 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
3291 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
3292 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
3293 +#ifdef CONFIG_COMPAT
3294 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
3297 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
3301 +static const loff_t au_loff_max = LLONG_MAX;
3303 +int au_xib_trunc(struct super_block *sb);
3304 +ssize_t xino_fread(au_readf_t func, struct file *file, void *buf, size_t size,
3306 +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size,
3308 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src);
3309 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent);
3310 +ino_t au_xino_new_ino(struct super_block *sb);
3311 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
3312 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
3314 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
3316 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino,
3317 + struct file *base_file, int do_test);
3318 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex);
3320 +struct au_opt_xino;
3321 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount);
3322 +void au_xino_clr(struct super_block *sb);
3323 +struct file *au_xino_def(struct super_block *sb);
3324 +int au_xino_path(struct seq_file *seq, struct file *file);
3326 +/* ---------------------------------------------------------------------- */
3328 +/* Superblock to branch */
3330 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
3332 + return au_sbr(sb, bindex)->br_id;
3336 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
3338 + return au_br_mnt(au_sbr(sb, bindex));
3342 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
3344 + return au_br_sb(au_sbr(sb, bindex));
3347 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
3349 + atomic_dec(&au_sbr(sb, bindex)->br_count);
3352 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
3354 + return au_sbr(sb, bindex)->br_perm;
3357 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
3359 + return au_br_whable(au_sbr_perm(sb, bindex));
3362 +/* ---------------------------------------------------------------------- */
3365 + * wbr_wh_read_lock, wbr_wh_write_lock
3366 + * wbr_wh_read_unlock, wbr_wh_write_unlock, wbr_wh_downgrade_lock
3368 +AuSimpleRwsemFuncs(wbr_wh, struct au_wbr *wbr, &wbr->wbr_wh_rwsem);
3370 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&wbr->wbr_wh_rwsem)
3371 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&wbr->wbr_wh_rwsem)
3372 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&wbr->wbr_wh_rwsem)
3374 +#endif /* __KERNEL__ */
3375 +#endif /* __AUFS_BRANCH_H__ */
3376 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
3377 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
3378 +++ linux/fs/aufs/conf.mk 2014-01-20 20:16:14.732796615 +0100
3381 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
3385 +AuConfStr += ${1}=${${1}}
3389 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
3391 + HNOTIFY HFSNOTIFY \
3401 +$(foreach i, ${AuConfAll}, \
3402 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
3404 +AuConfName = ${obj}/conf.str
3405 +${AuConfName}.tmp: FORCE
3406 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
3407 +${AuConfName}: ${AuConfName}.tmp
3408 + @diff -q $< $@ > /dev/null 2>&1 || { \
3409 + echo ' GEN ' $@; \
3413 +clean-files += ${AuConfName} ${AuConfName}.tmp
3414 +${obj}/sysfs.o: ${AuConfName}
3416 +-include ${srctree}/${src}/conf_priv.mk
3417 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
3418 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
3419 +++ linux/fs/aufs/cpup.c 2014-01-20 20:16:14.732796615 +0100
3422 + * Copyright (C) 2005-2014 Junjiro R. Okajima
3424 + * This program, aufs is free software; you can redistribute it and/or modify
3425 + * it under the terms of the GNU General Public License as published by
3426 + * the Free Software Foundation; either version 2 of the License, or
3427 + * (at your option) any later version.
3429 + * This program is distributed in the hope that it will be useful,
3430 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3431 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3432 + * GNU General Public License for more details.
3434 + * You should have received a copy of the GNU General Public License
3435 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3439 + * copy-up functions, see wbr_policy.c for copy-down
3442 +#include <linux/fs_stack.h>
3443 +#include <linux/mm.h>
3446 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
3448 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
3449 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
3451 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
3453 + dst->i_flags |= iflags & ~mask;
3454 + if (au_test_fs_notime(dst->i_sb))
3455 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
3458 +void au_cpup_attr_timesizes(struct inode *inode)
3460 + struct inode *h_inode;
3462 + h_inode = au_h_iptr(inode, au_ibstart(inode));
3463 + fsstack_copy_attr_times(inode, h_inode);
3464 + fsstack_copy_inode_size(inode, h_inode);
3467 +void au_cpup_attr_nlink(struct inode *inode, int force)
3469 + struct inode *h_inode;
3470 + struct super_block *sb;
3471 + aufs_bindex_t bindex, bend;
3474 + bindex = au_ibstart(inode);
3475 + h_inode = au_h_iptr(inode, bindex);
3477 + && !S_ISDIR(h_inode->i_mode)
3478 + && au_opt_test(au_mntflags(sb), PLINK)
3479 + && au_plink_test(inode))
3483 + * 0 can happen in revalidating.
3484 + * h_inode->i_mutex is not held, but it is harmless since once i_nlink
3485 + * reaches 0, it will never become positive.
3487 + set_nlink(inode, h_inode->i_nlink);
3490 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
3491 + * it may includes whplink directory.
3493 + if (S_ISDIR(h_inode->i_mode)) {
3494 + bend = au_ibend(inode);
3495 + for (bindex++; bindex <= bend; bindex++) {
3496 + h_inode = au_h_iptr(inode, bindex);
3498 + au_add_nlink(inode, h_inode);
3503 +void au_cpup_attr_changeable(struct inode *inode)
3505 + struct inode *h_inode;
3507 + h_inode = au_h_iptr(inode, au_ibstart(inode));
3508 + inode->i_mode = h_inode->i_mode;
3509 + inode->i_uid = h_inode->i_uid;
3510 + inode->i_gid = h_inode->i_gid;
3511 + au_cpup_attr_timesizes(inode);
3512 + au_cpup_attr_flags(inode, h_inode->i_flags);
3515 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
3517 + struct au_iinfo *iinfo = au_ii(inode);
3519 + IiMustWriteLock(inode);
3521 + iinfo->ii_higen = h_inode->i_generation;
3522 + iinfo->ii_hsb1 = h_inode->i_sb;
3525 +void au_cpup_attr_all(struct inode *inode, int force)
3527 + struct inode *h_inode;
3529 + h_inode = au_h_iptr(inode, au_ibstart(inode));
3530 + au_cpup_attr_changeable(inode);
3531 + if (inode->i_nlink > 0)
3532 + au_cpup_attr_nlink(inode, force);
3533 + inode->i_rdev = h_inode->i_rdev;
3534 + inode->i_blkbits = h_inode->i_blkbits;
3535 + au_cpup_igen(inode, h_inode);
3538 +/* ---------------------------------------------------------------------- */
3540 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
3542 +/* keep the timestamps of the parent dir when cpup */
3543 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
3544 + struct path *h_path)
3546 + struct inode *h_inode;
3548 + dt->dt_dentry = dentry;
3549 + dt->dt_h_path = *h_path;
3550 + h_inode = h_path->dentry->d_inode;
3551 + dt->dt_atime = h_inode->i_atime;
3552 + dt->dt_mtime = h_inode->i_mtime;
3556 +void au_dtime_revert(struct au_dtime *dt)
3558 + struct iattr attr;
3561 + attr.ia_atime = dt->dt_atime;
3562 + attr.ia_mtime = dt->dt_mtime;
3563 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
3564 + | ATTR_ATIME | ATTR_ATIME_SET;
3566 + /* no delegation since this is a directory */
3567 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
3568 + if (unlikely(err))
3569 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
3572 +/* ---------------------------------------------------------------------- */
3574 +/* internal use only */
3575 +struct au_cpup_reg_attr {
3578 + unsigned int iflags; /* inode->i_flags */
3581 +static noinline_for_stack
3582 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
3583 + struct au_cpup_reg_attr *h_src_attr)
3587 + struct path h_path;
3588 + struct inode *h_isrc, *h_idst;
3589 + struct kstat *h_st;
3591 + h_path.dentry = au_h_dptr(dst, bindex);
3592 + h_idst = h_path.dentry->d_inode;
3593 + h_path.mnt = au_sbr_mnt(dst->d_sb, bindex);
3594 + h_isrc = h_src->d_inode;
3595 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
3596 + | ATTR_ATIME | ATTR_MTIME
3597 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
3598 + if (h_src_attr && h_src_attr->valid) {
3599 + h_st = &h_src_attr->st;
3600 + ia.ia_uid = h_st->uid;
3601 + ia.ia_gid = h_st->gid;
3602 + ia.ia_atime = h_st->atime;
3603 + ia.ia_mtime = h_st->mtime;
3604 + if (h_idst->i_mode != h_st->mode
3605 + && !S_ISLNK(h_idst->i_mode)) {
3606 + ia.ia_valid |= ATTR_MODE;
3607 + ia.ia_mode = h_st->mode;
3609 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
3610 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
3612 + ia.ia_uid = h_isrc->i_uid;
3613 + ia.ia_gid = h_isrc->i_gid;
3614 + ia.ia_atime = h_isrc->i_atime;
3615 + ia.ia_mtime = h_isrc->i_mtime;
3616 + if (h_idst->i_mode != h_isrc->i_mode
3617 + && !S_ISLNK(h_idst->i_mode)) {
3618 + ia.ia_valid |= ATTR_MODE;
3619 + ia.ia_mode = h_isrc->i_mode;
3621 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
3622 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
3624 + /* no delegation since it is just created */
3625 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
3627 + /* is this nfs only? */
3628 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
3629 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
3630 + ia.ia_mode = h_isrc->i_mode;
3631 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
3637 +/* ---------------------------------------------------------------------- */
3639 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
3640 + char *buf, unsigned long blksize)
3643 + size_t sz, rbytes, wbytes;
3644 + unsigned char all_zero;
3646 + struct mutex *h_mtx;
3647 + /* reduce stack usage */
3650 + zp = page_address(ZERO_PAGE(0));
3651 + if (unlikely(!zp))
3652 + return -ENOMEM; /* possible? */
3657 + AuDbg("len %lld\n", len);
3659 + if (len < blksize)
3663 + /* todo: signal_pending? */
3664 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
3665 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
3668 + if (unlikely(err < 0))
3672 + if (len >= rbytes && rbytes == blksize)
3673 + all_zero = !memcmp(buf, zp, rbytes);
3680 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
3682 + /* todo: signal_pending? */
3683 + if (unlikely(err == -EAGAIN || err == -EINTR))
3685 + if (unlikely(err < 0))
3690 + if (unlikely(err < 0))
3696 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
3698 + if (unlikely(res < 0))
3705 + /* the last block may be a hole */
3706 + if (!err && all_zero) {
3707 + AuLabel(last hole);
3710 + if (au_test_nfs(dst->f_dentry->d_sb)) {
3711 + /* nfs requires this step to make last hole */
3712 + /* is this only nfs? */
3714 + /* todo: signal_pending? */
3715 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
3716 + } while (err == -EAGAIN || err == -EINTR);
3723 + ia->ia_size = dst->f_pos;
3724 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
3725 + ia->ia_file = dst;
3726 + h_mtx = &file_inode(dst)->i_mutex;
3727 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
3728 + /* no delegation since it is just created */
3729 + err = vfsub_notify_change(&dst->f_path, ia,
3730 + /*delegated*/NULL);
3731 + mutex_unlock(h_mtx);
3738 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
3741 + unsigned long blksize;
3742 + unsigned char do_kfree;
3746 + blksize = dst->f_dentry->d_sb->s_blocksize;
3747 + if (!blksize || PAGE_SIZE < blksize)
3748 + blksize = PAGE_SIZE;
3749 + AuDbg("blksize %lu\n", blksize);
3750 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
3752 + buf = kmalloc(blksize, GFP_NOFS);
3754 + buf = (void *)__get_free_page(GFP_NOFS);
3755 + if (unlikely(!buf))
3758 + if (len > (1 << 22))
3759 + AuDbg("copying a large file %lld\n", (long long)len);
3763 + err = au_do_copy_file(dst, src, len, buf, blksize);
3767 + free_page((unsigned long)buf);
3774 + * to support a sparse file which is opened with O_APPEND,
3775 + * we need to close the file.
3777 +static int au_cp_regular(struct au_cp_generic *cpg)
3780 + enum { SRC, DST };
3782 + aufs_bindex_t bindex;
3783 + unsigned int flags;
3784 + struct dentry *dentry;
3786 + struct file *file;
3790 + .bindex = cpg->bsrc,
3791 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
3795 + .bindex = cpg->bdst,
3796 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
3797 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
3798 + .label = &&out_src
3801 + struct super_block *sb;
3803 + /* bsrc branch can be ro/rw. */
3804 + sb = cpg->dentry->d_sb;
3806 + for (i = 0; i < 2; i++, f++) {
3807 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
3808 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
3809 + /*file*/NULL, f->force_wr);
3810 + err = PTR_ERR(f->file);
3811 + if (IS_ERR(f->file))
3815 + /* try stopping to update while we copyup */
3816 + IMustLock(file[SRC].dentry->d_inode);
3817 + err = au_copy_file(file[DST].file, file[SRC].file, cpg->len);
3819 + fput(file[DST].file);
3820 + au_sbr_put(sb, file[DST].bindex);
3823 + fput(file[SRC].file);
3824 + au_sbr_put(sb, file[SRC].bindex);
3829 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
3830 + struct au_cpup_reg_attr *h_src_attr)
3834 + struct path h_path;
3835 + struct inode *h_src_inode;
3838 + h_src_inode = au_h_iptr(cpg->dentry->d_inode, cpg->bsrc);
3839 + l = i_size_read(h_src_inode);
3840 + if (cpg->len == -1 || l < cpg->len)
3843 + /* try stopping to update while we are referencing */
3844 + mutex_lock_nested(&h_src_inode->i_mutex, AuLsc_I_CHILD);
3845 + au_pin_hdir_unlock(cpg->pin);
3847 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
3848 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
3849 + h_src_attr->iflags = h_src_inode->i_flags;
3850 + err = vfs_getattr(&h_path, &h_src_attr->st);
3851 + if (unlikely(err)) {
3852 + mutex_unlock(&h_src_inode->i_mutex);
3855 + h_src_attr->valid = 1;
3856 + err = au_cp_regular(cpg);
3857 + mutex_unlock(&h_src_inode->i_mutex);
3858 + rerr = au_pin_hdir_relock(cpg->pin);
3867 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
3868 + struct inode *h_dir)
3871 + mm_segment_t old_fs;
3878 + if (unlikely(!h_src->d_inode->i_op->readlink))
3882 + sym.k = (void *)__get_free_page(GFP_NOFS);
3883 + if (unlikely(!sym.k))
3886 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
3887 + old_fs = get_fs();
3888 + set_fs(KERNEL_DS);
3889 + symlen = h_src->d_inode->i_op->readlink(h_src, sym.u, PATH_MAX);
3894 + sym.k[symlen] = 0;
3895 + err = vfsub_symlink(h_dir, h_path, sym.k);
3897 + free_page((unsigned long)sym.k);
3903 +static noinline_for_stack
3904 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
3905 + struct au_cpup_reg_attr *h_src_attr)
3909 + unsigned int mnt_flags;
3910 + unsigned char isdir;
3911 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
3912 + struct au_dtime dt;
3913 + struct path h_path;
3914 + struct dentry *h_src, *h_dst, *h_parent;
3915 + struct inode *h_inode, *h_dir;
3916 + struct super_block *sb;
3918 + /* bsrc branch can be ro/rw. */
3919 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
3920 + h_inode = h_src->d_inode;
3921 + AuDebugOn(h_inode != au_h_iptr(cpg->dentry->d_inode, cpg->bsrc));
3923 + /* try stopping to be referenced while we are creating */
3924 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
3925 + if (au_ftest_cpup(cpg->flags, RENAME))
3926 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
3927 + AUFS_WH_PFX_LEN));
3928 + h_parent = h_dst->d_parent; /* dir inode is locked */
3929 + h_dir = h_parent->d_inode;
3931 + AuDebugOn(h_parent != h_dst->d_parent);
3933 + sb = cpg->dentry->d_sb;
3934 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
3936 + h_path.dentry = h_parent;
3937 + au_dtime_store(&dt, dst_parent, &h_path);
3939 + h_path.dentry = h_dst;
3942 + mode = h_inode->i_mode;
3943 + switch (mode & S_IFMT) {
3945 + err = vfsub_create(h_dir, &h_path, mode | S_IWUSR,
3946 + /*want_excl*/true);
3948 + err = au_do_cpup_regular(cpg, h_src_attr);
3952 + err = vfsub_mkdir(h_dir, &h_path, mode);
3955 + * strange behaviour from the users view,
3956 + * particularry setattr case
3958 + if (au_ibstart(dst_parent->d_inode) == cpg->bdst)
3959 + au_cpup_attr_nlink(dst_parent->d_inode,
3961 + au_cpup_attr_nlink(cpg->dentry->d_inode, /*force*/1);
3965 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
3969 + AuDebugOn(!capable(CAP_MKNOD));
3973 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
3976 + AuIOErr("Unknown inode type 0%o\n", mode);
3980 + mnt_flags = au_mntflags(sb);
3981 + if (!au_opt_test(mnt_flags, UDBA_NONE)
3983 + && au_opt_test(mnt_flags, XINO)
3984 + && h_inode->i_nlink == 1
3985 + /* todo: unnecessary? */
3986 + /* && cpg->dentry->d_inode->i_nlink == 1 */
3987 + && cpg->bdst < cpg->bsrc
3988 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
3989 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
3990 + /* ignore this error */
3993 + au_dtime_revert(&dt);
3997 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
4000 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
4001 + struct inode *h_dir;
4002 + aufs_bindex_t bdst;
4004 + dentry = cpg->dentry;
4006 + h_dentry = au_h_dptr(dentry, bdst);
4007 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
4009 + au_set_h_dptr(dentry, bdst, NULL);
4010 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
4012 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
4013 + au_set_h_dptr(dentry, bdst, h_dentry);
4016 + parent = dget_parent(dentry);
4017 + h_parent = au_h_dptr(parent, bdst);
4019 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
4020 + if (IS_ERR(h_path->dentry))
4021 + err = PTR_ERR(h_path->dentry);
4023 + if (unlikely(err))
4026 + h_parent = h_dentry->d_parent; /* dir inode is locked */
4027 + h_dir = h_parent->d_inode;
4029 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
4030 + /* no delegation since it is just created */
4031 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL);
4032 + dput(h_path->dentry);
4039 + * copyup the @dentry from @bsrc to @bdst.
4040 + * the caller must set the both of lower dentries.
4041 + * @len is for truncating when it is -1 copyup the entire file.
4042 + * in link/rename cases, @dst_parent may be different from the real one.
4043 + * basic->bsrc can be larger than basic->bdst.
4045 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
4048 + aufs_bindex_t old_ibstart;
4049 + unsigned char isdir, plink;
4050 + struct dentry *h_src, *h_dst, *h_parent;
4051 + struct inode *dst_inode, *h_dir, *inode, *delegated;
4052 + struct super_block *sb;
4053 + struct au_branch *br;
4054 + /* to reuduce stack size */
4056 + struct au_dtime dt;
4057 + struct path h_path;
4058 + struct au_cpup_reg_attr h_src_attr;
4062 + a = kmalloc(sizeof(*a), GFP_NOFS);
4065 + a->h_src_attr.valid = 0;
4067 + sb = cpg->dentry->d_sb;
4068 + br = au_sbr(sb, cpg->bdst);
4069 + a->h_path.mnt = au_br_mnt(br);
4070 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
4071 + h_parent = h_dst->d_parent; /* dir inode is locked */
4072 + h_dir = h_parent->d_inode;
4075 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
4076 + inode = cpg->dentry->d_inode;
4079 + dst_parent = dget_parent(cpg->dentry);
4083 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
4084 + dst_inode = au_h_iptr(inode, cpg->bdst);
4086 + if (unlikely(!plink)) {
4088 + AuIOErr("hi%lu(i%lu) exists on b%d "
4089 + "but plink is disabled\n",
4090 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
4094 + if (dst_inode->i_nlink) {
4095 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
4097 + h_src = au_plink_lkup(inode, cpg->bdst);
4098 + err = PTR_ERR(h_src);
4099 + if (IS_ERR(h_src))
4101 + if (unlikely(!h_src->d_inode)) {
4103 + AuIOErr("i%lu exists on a upper branch "
4104 + "but not pseudo-linked\n",
4111 + a->h_path.dentry = h_parent;
4112 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
4115 + a->h_path.dentry = h_dst;
4117 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
4118 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
4119 + err = au_do_ren_after_cpup(cpg, &a->h_path);
4121 + au_dtime_revert(&a->dt);
4122 + if (unlikely(err == -EWOULDBLOCK)) {
4123 + pr_warn("cannot retry for NFSv4 delegation"
4124 + " for an internal link\n");
4130 + /* todo: cpup_wh_file? */
4132 + au_update_ibrange(inode, /*do_put_zero*/1);
4135 + isdir = S_ISDIR(inode->i_mode);
4136 + old_ibstart = au_ibstart(inode);
4137 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
4138 + if (unlikely(err))
4140 + dst_inode = h_dst->d_inode;
4141 + mutex_lock_nested(&dst_inode->i_mutex, AuLsc_I_CHILD2);
4142 + /* todo: necessary? */
4143 + /* au_pin_hdir_unlock(cpg->pin); */
4145 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
4146 + if (unlikely(err)) {
4147 + /* todo: necessary? */
4148 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
4149 + mutex_unlock(&dst_inode->i_mutex);
4153 + if (cpg->bdst < old_ibstart) {
4154 + if (S_ISREG(inode->i_mode)) {
4155 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
4156 + if (unlikely(err)) {
4157 + /* ignore an error */
4158 + /* au_pin_hdir_relock(cpg->pin); */
4159 + mutex_unlock(&dst_inode->i_mutex);
4163 + au_set_ibstart(inode, cpg->bdst);
4165 + au_set_ibend(inode, cpg->bdst);
4166 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
4167 + au_hi_flags(inode, isdir));
4169 + /* todo: necessary? */
4170 + /* err = au_pin_hdir_relock(cpg->pin); */
4171 + mutex_unlock(&dst_inode->i_mutex);
4172 + if (unlikely(err))
4176 + && h_src->d_inode->i_nlink > 1
4178 + au_plink_append(inode, cpg->bdst, h_dst);
4180 + if (au_ftest_cpup(cpg->flags, RENAME)) {
4181 + a->h_path.dentry = h_dst;
4182 + err = au_do_ren_after_cpup(cpg, &a->h_path);
4185 + goto out_parent; /* success */
4189 + a->h_path.dentry = h_parent;
4190 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
4191 + a->h_path.dentry = h_dst;
4193 + if (h_dst->d_inode) {
4195 + /* no delegation since it is just created */
4196 + rerr = vfsub_unlink(h_dir, &a->h_path,
4197 + /*delegated*/NULL, /*force*/0);
4199 + rerr = vfsub_rmdir(h_dir, &a->h_path);
4201 + au_dtime_revert(&a->dt);
4203 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
4214 +struct au_cpup_single_args {
4216 + struct au_cp_generic *cpg;
4217 + struct dentry *dst_parent;
4220 +static void au_call_cpup_single(void *args)
4222 + struct au_cpup_single_args *a = args;
4224 + au_pin_hdir_acquire_nest(a->cpg->pin);
4225 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
4226 + au_pin_hdir_release(a->cpg->pin);
4231 + * prevent SIGXFSZ in copy-up.
4232 + * testing CAP_MKNOD is for generic fs,
4233 + * but CAP_FSETID is for xfs only, currently.
4235 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
4238 + struct super_block *sb;
4239 + struct inode *h_dir;
4242 + sb = au_pinned_parent(pin)->d_sb;
4243 + if (!au_wkq_test()
4244 + && (!au_sbi(sb)->si_plink_maint_pid
4245 + || au_plink_maint(sb, AuLock_NOPLM))) {
4246 + switch (mode & S_IFMT) {
4248 + /* no condition about RLIMIT_FSIZE and the file size */
4253 + do_sio = !capable(CAP_MKNOD);
4257 + do_sio = ((mode & (S_ISUID | S_ISGID))
4258 + && !capable(CAP_FSETID));
4259 + /* this workaround may be removed in the future */
4261 + h_dir = au_pinned_h_dir(pin);
4262 + do_sio = h_dir->i_mode & S_ISVTX;
4270 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
4273 + struct dentry *h_dentry;
4275 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
4276 + if (!au_cpup_sio_test(pin, h_dentry->d_inode->i_mode))
4277 + err = au_cpup_single(cpg, dst_parent);
4279 + struct au_cpup_single_args args = {
4282 + .dst_parent = dst_parent
4284 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
4285 + if (unlikely(wkq_err))
4294 + * copyup the @dentry from the first active lower branch to @bdst,
4295 + * using au_cpup_single().
4297 +static int au_cpup_simple(struct au_cp_generic *cpg)
4300 + unsigned int flags_orig;
4301 + struct dentry *dentry;
4303 + AuDebugOn(cpg->bsrc < 0);
4305 + dentry = cpg->dentry;
4306 + DiMustWriteLock(dentry);
4308 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
4310 + flags_orig = cpg->flags;
4311 + au_fset_cpup(cpg->flags, RENAME);
4312 + err = au_cpup_single(cpg, NULL);
4313 + cpg->flags = flags_orig;
4315 + return 0; /* success */
4318 + au_set_h_dptr(dentry, cpg->bdst, NULL);
4319 + au_set_dbstart(dentry, cpg->bsrc);
4325 +struct au_cpup_simple_args {
4327 + struct au_cp_generic *cpg;
4330 +static void au_call_cpup_simple(void *args)
4332 + struct au_cpup_simple_args *a = args;
4334 + au_pin_hdir_acquire_nest(a->cpg->pin);
4335 + *a->errp = au_cpup_simple(a->cpg);
4336 + au_pin_hdir_release(a->cpg->pin);
4339 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
4342 + struct dentry *dentry, *parent;
4343 + struct file *h_file;
4344 + struct inode *h_dir;
4346 + dentry = cpg->dentry;
4348 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
4349 + AuDebugOn(cpg->bsrc < 0);
4350 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
4351 + err = PTR_ERR(h_file);
4352 + if (IS_ERR(h_file))
4356 + parent = dget_parent(dentry);
4357 + h_dir = au_h_iptr(parent->d_inode, cpg->bdst);
4358 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
4359 + && !au_cpup_sio_test(cpg->pin, dentry->d_inode->i_mode))
4360 + err = au_cpup_simple(cpg);
4362 + struct au_cpup_simple_args args = {
4366 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
4367 + if (unlikely(wkq_err))
4373 + au_h_open_post(dentry, cpg->bsrc, h_file);
4379 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
4381 + aufs_bindex_t bsrc, bend;
4382 + struct dentry *dentry, *h_dentry;
4384 + if (cpg->bsrc < 0) {
4385 + dentry = cpg->dentry;
4386 + bend = au_dbend(dentry);
4387 + for (bsrc = cpg->bdst + 1; bsrc <= bend; bsrc++) {
4388 + h_dentry = au_h_dptr(dentry, bsrc);
4390 + AuDebugOn(!h_dentry->d_inode);
4394 + AuDebugOn(bsrc > bend);
4397 + AuDebugOn(cpg->bsrc <= cpg->bdst);
4398 + return au_do_sio_cpup_simple(cpg);
4401 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
4403 + AuDebugOn(cpg->bdst <= cpg->bsrc);
4404 + return au_do_sio_cpup_simple(cpg);
4407 +/* ---------------------------------------------------------------------- */
4410 + * copyup the deleted file for writing.
4412 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
4413 + struct file *file)
4416 + unsigned int flags_orig;
4417 + aufs_bindex_t bsrc_orig;
4418 + struct dentry *h_d_dst, *h_d_start;
4419 + struct au_dinfo *dinfo;
4420 + struct au_hdentry *hdp;
4422 + dinfo = au_di(cpg->dentry);
4423 + AuRwMustWriteLock(&dinfo->di_rwsem);
4425 + bsrc_orig = cpg->bsrc;
4426 + cpg->bsrc = dinfo->di_bstart;
4427 + hdp = dinfo->di_hdentry;
4428 + h_d_dst = hdp[0 + cpg->bdst].hd_dentry;
4429 + dinfo->di_bstart = cpg->bdst;
4430 + hdp[0 + cpg->bdst].hd_dentry = wh_dentry;
4433 + h_d_start = hdp[0 + cpg->bsrc].hd_dentry;
4434 + hdp[0 + cpg->bsrc].hd_dentry = au_hf_top(file)->f_dentry;
4436 + flags_orig = cpg->flags;
4437 + cpg->flags = !AuCpup_DTIME;
4438 + err = au_cpup_single(cpg, /*h_parent*/NULL);
4439 + cpg->flags = flags_orig;
4442 + err = au_reopen_nondir(file);
4443 + hdp[0 + cpg->bsrc].hd_dentry = h_d_start;
4445 + hdp[0 + cpg->bdst].hd_dentry = h_d_dst;
4446 + dinfo->di_bstart = cpg->bsrc;
4447 + cpg->bsrc = bsrc_orig;
4452 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
4455 + aufs_bindex_t bdst;
4456 + struct au_dtime dt;
4457 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
4458 + struct au_branch *br;
4459 + struct path h_path;
4461 + dentry = cpg->dentry;
4463 + br = au_sbr(dentry->d_sb, bdst);
4464 + parent = dget_parent(dentry);
4465 + h_parent = au_h_dptr(parent, bdst);
4466 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
4467 + err = PTR_ERR(wh_dentry);
4468 + if (IS_ERR(wh_dentry))
4471 + h_path.dentry = h_parent;
4472 + h_path.mnt = au_br_mnt(br);
4473 + au_dtime_store(&dt, parent, &h_path);
4474 + err = au_do_cpup_wh(cpg, wh_dentry, file);
4475 + if (unlikely(err))
4479 + h_path.dentry = wh_dentry;
4480 + if (!S_ISDIR(wh_dentry->d_inode->i_mode)) {
4481 + /* no delegation since it is just created */
4482 + err = vfsub_unlink(h_parent->d_inode, &h_path,
4483 + /*delegated*/NULL, /*force*/0);
4485 + err = vfsub_rmdir(h_parent->d_inode, &h_path);
4486 + if (unlikely(err)) {
4487 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
4491 + au_dtime_revert(&dt);
4492 + au_set_hi_wh(dentry->d_inode, bdst, wh_dentry);
4501 +struct au_cpup_wh_args {
4503 + struct au_cp_generic *cpg;
4504 + struct file *file;
4507 +static void au_call_cpup_wh(void *args)
4509 + struct au_cpup_wh_args *a = args;
4511 + au_pin_hdir_acquire_nest(a->cpg->pin);
4512 + *a->errp = au_cpup_wh(a->cpg, a->file);
4513 + au_pin_hdir_release(a->cpg->pin);
4516 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
4519 + aufs_bindex_t bdst;
4520 + struct dentry *dentry, *parent, *h_orph, *h_parent, *h_dentry;
4521 + struct inode *dir, *h_dir, *h_tmpdir;
4522 + struct au_wbr *wbr;
4523 + struct au_pin wh_pin, *pin_orig;
4525 + dentry = cpg->dentry;
4527 + parent = dget_parent(dentry);
4528 + dir = parent->d_inode;
4531 + h_dir = au_igrab(au_h_iptr(dir, bdst));
4534 + if (!h_dir->i_nlink) {
4535 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
4536 + h_orph = wbr->wbr_orph;
4538 + h_parent = dget(au_h_dptr(parent, bdst));
4539 + au_set_h_dptr(parent, bdst, dget(h_orph));
4540 + h_tmpdir = h_orph->d_inode;
4541 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
4544 + h_dentry = au_hf_top(file)->f_dentry;
4546 + h_dentry = au_h_dptr(dentry, au_dbstart(dentry));
4547 + mutex_lock_nested(&h_tmpdir->i_mutex, AuLsc_I_PARENT3);
4548 + /* todo: au_h_open_pre()? */
4550 + pin_orig = cpg->pin;
4551 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
4552 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
4553 + cpg->pin = &wh_pin;
4556 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
4557 + && !au_cpup_sio_test(cpg->pin, dentry->d_inode->i_mode))
4558 + err = au_cpup_wh(cpg, file);
4560 + struct au_cpup_wh_args args = {
4565 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
4566 + if (unlikely(wkq_err))
4571 + mutex_unlock(&h_tmpdir->i_mutex);
4572 + /* todo: au_h_open_post()? */
4573 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
4574 + au_set_h_dptr(parent, bdst, h_parent);
4575 + AuDebugOn(!pin_orig);
4576 + cpg->pin = pin_orig;
4584 +/* ---------------------------------------------------------------------- */
4587 + * generic routine for both of copy-up and copy-down.
4589 +/* cf. revalidate function in file.c */
4590 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
4591 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
4592 + struct au_pin *pin,
4593 + struct dentry *h_parent, void *arg),
4597 + struct au_pin pin;
4598 + struct dentry *d, *parent, *h_parent, *real_parent;
4601 + parent = dget_parent(dentry);
4602 + if (IS_ROOT(parent))
4605 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
4606 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
4608 + /* do not use au_dpage */
4609 + real_parent = parent;
4612 + parent = dget_parent(dentry);
4613 + h_parent = au_h_dptr(parent, bdst);
4615 + goto out; /* success */
4617 + /* find top dir which is necessary to cpup */
4621 + parent = dget_parent(d);
4622 + di_read_lock_parent3(parent, !AuLock_IR);
4623 + h_parent = au_h_dptr(parent, bdst);
4624 + di_read_unlock(parent, !AuLock_IR);
4625 + } while (!h_parent);
4627 + if (d != real_parent)
4628 + di_write_lock_child3(d);
4630 + /* somebody else might create while we were sleeping */
4631 + if (!au_h_dptr(d, bdst) || !au_h_dptr(d, bdst)->d_inode) {
4632 + if (au_h_dptr(d, bdst))
4633 + au_update_dbstart(d);
4635 + au_pin_set_dentry(&pin, d);
4636 + err = au_do_pin(&pin);
4638 + err = cp(d, bdst, &pin, h_parent, arg);
4643 + if (d != real_parent)
4644 + di_write_unlock(d);
4645 + if (unlikely(err))
4654 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
4655 + struct au_pin *pin,
4656 + struct dentry *h_parent __maybe_unused ,
4657 + void *arg __maybe_unused)
4659 + struct au_cp_generic cpg = {
4665 + .flags = AuCpup_DTIME
4667 + return au_sio_cpup_simple(&cpg);
4670 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
4672 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
4675 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
4678 + struct dentry *parent;
4679 + struct inode *dir;
4681 + parent = dget_parent(dentry);
4682 + dir = parent->d_inode;
4684 + if (au_h_iptr(dir, bdst))
4687 + di_read_unlock(parent, AuLock_IR);
4688 + di_write_lock_parent(parent);
4689 + /* someone else might change our inode while we were sleeping */
4690 + if (!au_h_iptr(dir, bdst))
4691 + err = au_cpup_dirs(dentry, bdst);
4692 + di_downgrade_lock(parent, AuLock_IR);
4698 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
4699 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
4700 +++ linux/fs/aufs/cpup.h 2014-01-20 20:16:14.732796615 +0100
4703 + * Copyright (C) 2005-2014 Junjiro R. Okajima
4705 + * This program, aufs is free software; you can redistribute it and/or modify
4706 + * it under the terms of the GNU General Public License as published by
4707 + * the Free Software Foundation; either version 2 of the License, or
4708 + * (at your option) any later version.
4710 + * This program is distributed in the hope that it will be useful,
4711 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4712 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4713 + * GNU General Public License for more details.
4715 + * You should have received a copy of the GNU General Public License
4716 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4720 + * copy-up/down functions
4723 +#ifndef __AUFS_CPUP_H__
4724 +#define __AUFS_CPUP_H__
4728 +#include <linux/path.h>
4734 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
4735 +void au_cpup_attr_timesizes(struct inode *inode);
4736 +void au_cpup_attr_nlink(struct inode *inode, int force);
4737 +void au_cpup_attr_changeable(struct inode *inode);
4738 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
4739 +void au_cpup_attr_all(struct inode *inode, int force);
4741 +/* ---------------------------------------------------------------------- */
4743 +struct au_cp_generic {
4744 + struct dentry *dentry;
4745 + aufs_bindex_t bdst, bsrc;
4747 + struct au_pin *pin;
4748 + unsigned int flags;
4752 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
4753 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
4755 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
4756 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
4758 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
4760 +#define AuCpup_RWDST (1 << 5) /* force write target even if
4761 + the branch is marked as RO */
4763 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
4764 +#define au_fset_cpup(flags, name) \
4765 + do { (flags) |= AuCpup_##name; } while (0)
4766 +#define au_fclr_cpup(flags, name) \
4767 + do { (flags) &= ~AuCpup_##name; } while (0)
4769 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
4770 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
4771 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
4772 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
4774 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
4775 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
4776 + struct au_pin *pin,
4777 + struct dentry *h_parent, void *arg),
4779 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
4780 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
4782 +/* ---------------------------------------------------------------------- */
4784 +/* keep timestamps when copyup */
4786 + struct dentry *dt_dentry;
4787 + struct path dt_h_path;
4788 + struct timespec dt_atime, dt_mtime;
4790 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4791 + struct path *h_path);
4792 +void au_dtime_revert(struct au_dtime *dt);
4794 +#endif /* __KERNEL__ */
4795 +#endif /* __AUFS_CPUP_H__ */
4796 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
4797 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
4798 +++ linux/fs/aufs/dbgaufs.c 2014-01-20 20:16:14.732796615 +0100
4801 + * Copyright (C) 2005-2014 Junjiro R. Okajima
4803 + * This program, aufs is free software; you can redistribute it and/or modify
4804 + * it under the terms of the GNU General Public License as published by
4805 + * the Free Software Foundation; either version 2 of the License, or
4806 + * (at your option) any later version.
4808 + * This program is distributed in the hope that it will be useful,
4809 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4810 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4811 + * GNU General Public License for more details.
4813 + * You should have received a copy of the GNU General Public License
4814 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4818 + * debugfs interface
4821 +#include <linux/debugfs.h>
4824 +#ifndef CONFIG_SYSFS
4825 +#error DEBUG_FS depends upon SYSFS
4828 +static struct dentry *dbgaufs;
4829 +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH;
4831 +/* 20 is max digits length of ulong 64 */
4832 +struct dbgaufs_arg {
4838 + * common function for all XINO files
4840 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
4841 + struct file *file)
4843 + kfree(file->private_data);
4847 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt)
4851 + struct dbgaufs_arg *p;
4854 + p = kmalloc(sizeof(*p), GFP_NOFS);
4860 + file->private_data = p;
4864 + err = vfs_getattr(&xf->f_path, &st);
4868 + (p->a, sizeof(p->a), "%ld, %llux%lu %lld\n",
4869 + (long)file_count(xf), st.blocks, st.blksize,
4870 + (long long)st.size);
4872 + p->n = snprintf(p->a, sizeof(p->a), "%llux%lu %lld\n",
4873 + st.blocks, st.blksize,
4874 + (long long)st.size);
4875 + AuDebugOn(p->n >= sizeof(p->a));
4877 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
4886 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
4887 + size_t count, loff_t *ppos)
4889 + struct dbgaufs_arg *p;
4891 + p = file->private_data;
4892 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
4895 +/* ---------------------------------------------------------------------- */
4897 +struct dbgaufs_plink_arg {
4902 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
4903 + struct file *file)
4905 + free_page((unsigned long)file->private_data);
4909 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
4911 + int err, i, limit;
4912 + unsigned long n, sum;
4913 + struct dbgaufs_plink_arg *p;
4914 + struct au_sbinfo *sbinfo;
4915 + struct super_block *sb;
4916 + struct au_sphlhead *sphl;
4919 + p = (void *)get_zeroed_page(GFP_NOFS);
4924 + sbinfo = inode->i_private;
4925 + sb = sbinfo->si_sb;
4926 + si_noflush_read_lock(sb);
4927 + if (au_opt_test(au_mntflags(sb), PLINK)) {
4928 + limit = PAGE_SIZE - sizeof(p->n);
4930 + /* the number of buckets */
4931 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
4936 + for (i = 0, sphl = sbinfo->si_plink;
4937 + i < AuPlink_NHASH;
4939 + n = au_sphl_count(sphl);
4942 + n = snprintf(p->a + p->n, limit, "%lu ", n);
4945 + if (unlikely(limit <= 0))
4948 + p->a[p->n - 1] = '\n';
4950 + /* the sum of plinks */
4951 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
4954 + if (unlikely(limit <= 0))
4957 +#define str "1\n0\n0\n"
4958 + p->n = sizeof(str) - 1;
4959 + strcpy(p->a, str);
4962 + si_read_unlock(sb);
4965 + file->private_data = p;
4966 + goto out; /* success */
4969 + free_page((unsigned long)p);
4974 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
4975 + size_t count, loff_t *ppos)
4977 + struct dbgaufs_plink_arg *p;
4979 + p = file->private_data;
4980 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
4983 +static const struct file_operations dbgaufs_plink_fop = {
4984 + .owner = THIS_MODULE,
4985 + .open = dbgaufs_plink_open,
4986 + .release = dbgaufs_plink_release,
4987 + .read = dbgaufs_plink_read
4990 +/* ---------------------------------------------------------------------- */
4992 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
4995 + struct au_sbinfo *sbinfo;
4996 + struct super_block *sb;
4998 + sbinfo = inode->i_private;
4999 + sb = sbinfo->si_sb;
5000 + si_noflush_read_lock(sb);
5001 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
5002 + si_read_unlock(sb);
5006 +static const struct file_operations dbgaufs_xib_fop = {
5007 + .owner = THIS_MODULE,
5008 + .open = dbgaufs_xib_open,
5009 + .release = dbgaufs_xi_release,
5010 + .read = dbgaufs_xi_read
5013 +/* ---------------------------------------------------------------------- */
5015 +#define DbgaufsXi_PREFIX "xi"
5017 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
5021 + struct au_sbinfo *sbinfo;
5022 + struct super_block *sb;
5024 + struct qstr *name;
5028 + name = &file->f_dentry->d_name;
5029 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
5030 + || memcmp(name->name, DbgaufsXi_PREFIX,
5031 + sizeof(DbgaufsXi_PREFIX) - 1)))
5033 + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
5034 + if (unlikely(err))
5037 + sbinfo = inode->i_private;
5038 + sb = sbinfo->si_sb;
5039 + si_noflush_read_lock(sb);
5040 + if (l <= au_sbend(sb)) {
5041 + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file;
5042 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1);
5045 + si_read_unlock(sb);
5051 +static const struct file_operations dbgaufs_xino_fop = {
5052 + .owner = THIS_MODULE,
5053 + .open = dbgaufs_xino_open,
5054 + .release = dbgaufs_xi_release,
5055 + .read = dbgaufs_xi_read
5058 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
5060 + aufs_bindex_t bend;
5061 + struct au_branch *br;
5062 + struct au_xino_file *xi;
5064 + if (!au_sbi(sb)->si_dbgaufs)
5067 + bend = au_sbend(sb);
5068 + for (; bindex <= bend; bindex++) {
5069 + br = au_sbr(sb, bindex);
5070 + xi = &br->br_xino;
5071 + debugfs_remove(xi->xi_dbgaufs);
5072 + xi->xi_dbgaufs = NULL;
5076 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
5078 + struct au_sbinfo *sbinfo;
5079 + struct dentry *parent;
5080 + struct au_branch *br;
5081 + struct au_xino_file *xi;
5082 + aufs_bindex_t bend;
5083 + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
5085 + sbinfo = au_sbi(sb);
5086 + parent = sbinfo->si_dbgaufs;
5090 + bend = au_sbend(sb);
5091 + for (; bindex <= bend; bindex++) {
5092 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
5093 + br = au_sbr(sb, bindex);
5094 + xi = &br->br_xino;
5095 + AuDebugOn(xi->xi_dbgaufs);
5096 + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
5097 + sbinfo, &dbgaufs_xino_fop);
5098 + /* ignore an error */
5099 + if (unlikely(!xi->xi_dbgaufs))
5100 + AuWarn1("failed %s under debugfs\n", name);
5104 +/* ---------------------------------------------------------------------- */
5106 +#ifdef CONFIG_AUFS_EXPORT
5107 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
5110 + struct au_sbinfo *sbinfo;
5111 + struct super_block *sb;
5113 + sbinfo = inode->i_private;
5114 + sb = sbinfo->si_sb;
5115 + si_noflush_read_lock(sb);
5116 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0);
5117 + si_read_unlock(sb);
5121 +static const struct file_operations dbgaufs_xigen_fop = {
5122 + .owner = THIS_MODULE,
5123 + .open = dbgaufs_xigen_open,
5124 + .release = dbgaufs_xi_release,
5125 + .read = dbgaufs_xi_read
5128 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
5133 + * This function is a dynamic '__init' fucntion actually,
5134 + * so the tiny check for si_rwsem is unnecessary.
5136 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
5139 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
5140 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
5141 + &dbgaufs_xigen_fop);
5142 + if (sbinfo->si_dbgaufs_xigen)
5148 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
5152 +#endif /* CONFIG_AUFS_EXPORT */
5154 +/* ---------------------------------------------------------------------- */
5156 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
5159 + * This function is a dynamic '__init' fucntion actually,
5160 + * so the tiny check for si_rwsem is unnecessary.
5162 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
5164 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
5165 + sbinfo->si_dbgaufs = NULL;
5166 + kobject_put(&sbinfo->si_kobj);
5169 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
5172 + char name[SysaufsSiNameLen];
5175 + * This function is a dynamic '__init' fucntion actually,
5176 + * so the tiny check for si_rwsem is unnecessary.
5178 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
5182 + AuErr1("/debug/aufs is uninitialized\n");
5187 + sysaufs_name(sbinfo, name);
5188 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
5189 + if (unlikely(!sbinfo->si_dbgaufs))
5191 + kobject_get(&sbinfo->si_kobj);
5193 + sbinfo->si_dbgaufs_xib = debugfs_create_file
5194 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
5195 + &dbgaufs_xib_fop);
5196 + if (unlikely(!sbinfo->si_dbgaufs_xib))
5199 + sbinfo->si_dbgaufs_plink = debugfs_create_file
5200 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
5201 + &dbgaufs_plink_fop);
5202 + if (unlikely(!sbinfo->si_dbgaufs_plink))
5205 + err = dbgaufs_xigen_init(sbinfo);
5207 + goto out; /* success */
5210 + dbgaufs_si_fin(sbinfo);
5215 +/* ---------------------------------------------------------------------- */
5217 +void dbgaufs_fin(void)
5219 + debugfs_remove(dbgaufs);
5222 +int __init dbgaufs_init(void)
5227 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
5232 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
5233 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
5234 +++ linux/fs/aufs/dbgaufs.h 2014-01-20 20:16:14.732796615 +0100
5237 + * Copyright (C) 2005-2014 Junjiro R. Okajima
5239 + * This program, aufs is free software; you can redistribute it and/or modify
5240 + * it under the terms of the GNU General Public License as published by
5241 + * the Free Software Foundation; either version 2 of the License, or
5242 + * (at your option) any later version.
5244 + * This program is distributed in the hope that it will be useful,
5245 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5246 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5247 + * GNU General Public License for more details.
5249 + * You should have received a copy of the GNU General Public License
5250 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5254 + * debugfs interface
5257 +#ifndef __DBGAUFS_H__
5258 +#define __DBGAUFS_H__
5262 +struct super_block;
5265 +#ifdef CONFIG_DEBUG_FS
5267 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
5268 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
5269 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
5270 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
5271 +void dbgaufs_fin(void);
5272 +int __init dbgaufs_init(void);
5274 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
5275 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
5276 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
5277 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
5278 +AuStubVoid(dbgaufs_fin, void)
5279 +AuStubInt0(__init dbgaufs_init, void)
5280 +#endif /* CONFIG_DEBUG_FS */
5282 +#endif /* __KERNEL__ */
5283 +#endif /* __DBGAUFS_H__ */
5284 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
5285 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
5286 +++ linux/fs/aufs/dcsub.c 2014-01-20 20:16:14.732796615 +0100
5289 + * Copyright (C) 2005-2014 Junjiro R. Okajima
5291 + * This program, aufs is free software; you can redistribute it and/or modify
5292 + * it under the terms of the GNU General Public License as published by
5293 + * the Free Software Foundation; either version 2 of the License, or
5294 + * (at your option) any later version.
5296 + * This program is distributed in the hope that it will be useful,
5297 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5298 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5299 + * GNU General Public License for more details.
5301 + * You should have received a copy of the GNU General Public License
5302 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5306 + * sub-routines for dentry cache
5311 +static void au_dpage_free(struct au_dpage *dpage)
5314 + struct dentry **p;
5316 + p = dpage->dentries;
5317 + for (i = 0; i < dpage->ndentry; i++)
5319 + free_page((unsigned long)dpage->dentries);
5322 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
5328 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
5329 + if (unlikely(!dpages->dpages))
5332 + p = (void *)__get_free_page(gfp);
5336 + dpages->dpages[0].ndentry = 0;
5337 + dpages->dpages[0].dentries = p;
5338 + dpages->ndpage = 1;
5339 + return 0; /* success */
5342 + kfree(dpages->dpages);
5347 +void au_dpages_free(struct au_dcsub_pages *dpages)
5350 + struct au_dpage *p;
5352 + p = dpages->dpages;
5353 + for (i = 0; i < dpages->ndpage; i++)
5354 + au_dpage_free(p++);
5355 + kfree(dpages->dpages);
5358 +static int au_dpages_append(struct au_dcsub_pages *dpages,
5359 + struct dentry *dentry, gfp_t gfp)
5362 + struct au_dpage *dpage;
5365 + dpage = dpages->dpages + dpages->ndpage - 1;
5366 + sz = PAGE_SIZE / sizeof(dentry);
5367 + if (unlikely(dpage->ndentry >= sz)) {
5368 + AuLabel(new dpage);
5370 + sz = dpages->ndpage * sizeof(*dpages->dpages);
5371 + p = au_kzrealloc(dpages->dpages, sz,
5372 + sz + sizeof(*dpages->dpages), gfp);
5376 + dpages->dpages = p;
5377 + dpage = dpages->dpages + dpages->ndpage;
5378 + p = (void *)__get_free_page(gfp);
5382 + dpage->ndentry = 0;
5383 + dpage->dentries = p;
5387 + AuDebugOn(!d_count(dentry));
5388 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
5389 + return 0; /* success */
5395 +/* try d_walk() in linux/fs/dcache.c */
5396 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
5397 + au_dpages_test test, void *arg)
5400 + struct dentry *this_parent;
5401 + struct list_head *next;
5402 + struct super_block *sb = root->d_sb;
5405 + write_seqlock(&rename_lock);
5406 + this_parent = root;
5407 + spin_lock(&this_parent->d_lock);
5409 + next = this_parent->d_subdirs.next;
5411 + if (this_parent->d_sb == sb
5412 + && !IS_ROOT(this_parent)
5413 + && au_di(this_parent)
5414 + && d_count(this_parent)
5415 + && (!test || test(this_parent, arg))) {
5416 + err = au_dpages_append(dpages, this_parent, GFP_ATOMIC);
5417 + if (unlikely(err))
5421 + while (next != &this_parent->d_subdirs) {
5422 + struct list_head *tmp = next;
5423 + struct dentry *dentry = list_entry(tmp, struct dentry,
5427 + spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED);
5428 + if (d_count(dentry)) {
5429 + if (!list_empty(&dentry->d_subdirs)) {
5430 + spin_unlock(&this_parent->d_lock);
5431 + spin_release(&dentry->d_lock.dep_map, 1,
5433 + this_parent = dentry;
5434 + spin_acquire(&this_parent->d_lock.dep_map, 0, 1,
5438 + if (dentry->d_sb == sb
5440 + && (!test || test(dentry, arg)))
5441 + err = au_dpages_append(dpages, dentry,
5444 + spin_unlock(&dentry->d_lock);
5445 + if (unlikely(err))
5449 + if (this_parent != root) {
5450 + struct dentry *tmp;
5451 + struct dentry *child;
5453 + tmp = this_parent->d_parent;
5455 + spin_unlock(&this_parent->d_lock);
5456 + child = this_parent;
5457 + this_parent = tmp;
5458 + spin_lock(&this_parent->d_lock);
5459 + rcu_read_unlock();
5460 + next = child->d_u.d_child.next;
5465 + spin_unlock(&this_parent->d_lock);
5466 + write_sequnlock(&rename_lock);
5470 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
5471 + int do_include, au_dpages_test test, void *arg)
5476 + write_seqlock(&rename_lock);
5477 + spin_lock(&dentry->d_lock);
5479 + && d_count(dentry)
5480 + && (!test || test(dentry, arg)))
5481 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
5482 + spin_unlock(&dentry->d_lock);
5483 + if (unlikely(err))
5487 + * RCU for vfsmount is unnecessary since this is a traverse in a single
5490 + while (!IS_ROOT(dentry)) {
5491 + dentry = dentry->d_parent; /* rename_lock is locked */
5492 + spin_lock(&dentry->d_lock);
5493 + if (d_count(dentry)
5494 + && (!test || test(dentry, arg)))
5495 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
5496 + spin_unlock(&dentry->d_lock);
5497 + if (unlikely(err))
5502 + write_sequnlock(&rename_lock);
5506 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
5508 + return au_di(dentry) && dentry->d_sb == arg;
5511 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
5512 + struct dentry *dentry, int do_include)
5514 + return au_dcsub_pages_rev(dpages, dentry, do_include,
5515 + au_dcsub_dpages_aufs, dentry->d_sb);
5518 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
5520 + struct path path[2] = {
5529 + return path_is_under(path + 0, path + 1);
5531 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
5532 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
5533 +++ linux/fs/aufs/dcsub.h 2014-01-20 20:16:14.736130059 +0100
5536 + * Copyright (C) 2005-2014 Junjiro R. Okajima
5538 + * This program, aufs is free software; you can redistribute it and/or modify
5539 + * it under the terms of the GNU General Public License as published by
5540 + * the Free Software Foundation; either version 2 of the License, or
5541 + * (at your option) any later version.
5543 + * This program is distributed in the hope that it will be useful,
5544 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5545 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5546 + * GNU General Public License for more details.
5548 + * You should have received a copy of the GNU General Public License
5549 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5553 + * sub-routines for dentry cache
5556 +#ifndef __AUFS_DCSUB_H__
5557 +#define __AUFS_DCSUB_H__
5561 +#include <linux/dcache.h>
5562 +#include <linux/fs.h>
5568 + struct dentry **dentries;
5571 +struct au_dcsub_pages {
5573 + struct au_dpage *dpages;
5576 +/* ---------------------------------------------------------------------- */
5579 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
5580 +void au_dpages_free(struct au_dcsub_pages *dpages);
5581 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
5582 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
5583 + au_dpages_test test, void *arg);
5584 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
5585 + int do_include, au_dpages_test test, void *arg);
5586 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
5587 + struct dentry *dentry, int do_include);
5588 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
5590 +/* ---------------------------------------------------------------------- */
5593 + * todo: in linux-3.13, several similar (but faster) helpers are added to
5594 + * include/linux/dcache.h. Try them (in the future).
5597 +static inline int au_d_hashed_positive(struct dentry *d)
5600 + struct inode *inode = d->d_inode;
5602 + if (unlikely(d_unhashed(d) || !inode || !inode->i_nlink))
5607 +static inline int au_d_alive(struct dentry *d)
5610 + struct inode *inode;
5613 + err = au_d_hashed_positive(d);
5615 + inode = d->d_inode;
5616 + if (unlikely(d_unlinked(d) || !inode || !inode->i_nlink))
5622 +static inline int au_alive_dir(struct dentry *d)
5625 + err = au_d_alive(d);
5626 + if (unlikely(err || IS_DEADDIR(d->d_inode)))
5631 +#endif /* __KERNEL__ */
5632 +#endif /* __AUFS_DCSUB_H__ */
5633 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
5634 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
5635 +++ linux/fs/aufs/debug.c 2014-01-20 20:16:14.736130059 +0100
5638 + * Copyright (C) 2005-2014 Junjiro R. Okajima
5640 + * This program, aufs is free software; you can redistribute it and/or modify
5641 + * it under the terms of the GNU General Public License as published by
5642 + * the Free Software Foundation; either version 2 of the License, or
5643 + * (at your option) any later version.
5645 + * This program is distributed in the hope that it will be useful,
5646 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5647 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5648 + * GNU General Public License for more details.
5650 + * You should have received a copy of the GNU General Public License
5651 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5655 + * debug print functions
5658 +#include <linux/vt_kern.h>
5661 +/* Returns 0, or -errno. arg is in kp->arg. */
5662 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
5666 + err = kstrtoint(val, 0, &n);
5676 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
5677 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
5682 + return sprintf(buffer, "%d", atomic_read(a));
5685 +static struct kernel_param_ops param_ops_atomic_t = {
5686 + .set = param_atomic_t_set,
5687 + .get = param_atomic_t_get
5688 + /* void (*free)(void *arg) */
5691 +atomic_t aufs_debug = ATOMIC_INIT(0);
5692 +MODULE_PARM_DESC(debug, "debug print");
5693 +module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP);
5695 +char *au_plevel = KERN_DEBUG;
5696 +#define dpri(fmt, ...) do { \
5698 + && strcmp(au_plevel, KERN_DEBUG)) \
5699 + || au_debug_test()) \
5700 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
5703 +/* ---------------------------------------------------------------------- */
5705 +void au_dpri_whlist(struct au_nhash *whlist)
5707 + unsigned long ul, n;
5708 + struct hlist_head *head;
5709 + struct au_vdir_wh *pos;
5711 + n = whlist->nh_num;
5712 + head = whlist->nh_head;
5713 + for (ul = 0; ul < n; ul++) {
5714 + hlist_for_each_entry(pos, head, wh_hash)
5715 + dpri("b%d, %.*s, %d\n",
5717 + pos->wh_str.len, pos->wh_str.name,
5723 +void au_dpri_vdir(struct au_vdir *vdir)
5726 + union au_vdir_deblk_p p;
5729 + if (!vdir || IS_ERR(vdir)) {
5730 + dpri("err %ld\n", PTR_ERR(vdir));
5734 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n",
5735 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
5736 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
5737 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
5738 + p.deblk = vdir->vd_deblk[ul];
5740 + dpri("[%lu]: %p\n", ul, o);
5744 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
5745 + struct dentry *wh)
5750 + if (!inode || IS_ERR(inode)) {
5751 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
5755 + /* the type of i_blocks depends upon CONFIG_LBDAF */
5756 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
5757 + && sizeof(inode->i_blocks) != sizeof(u64));
5759 + n = (void *)wh->d_name.name;
5760 + l = wh->d_name.len;
5763 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
5764 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
5766 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
5767 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
5768 + i_size_read(inode), (unsigned long long)inode->i_blocks,
5769 + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
5770 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
5771 + inode->i_state, inode->i_flags, inode->i_version,
5772 + inode->i_generation,
5773 + l ? ", wh " : "", l, n);
5777 +void au_dpri_inode(struct inode *inode)
5779 + struct au_iinfo *iinfo;
5780 + aufs_bindex_t bindex;
5783 + err = do_pri_inode(-1, inode, -1, NULL);
5784 + if (err || !au_test_aufs(inode->i_sb))
5787 + iinfo = au_ii(inode);
5790 + dpri("i-1: bstart %d, bend %d, gen %d\n",
5791 + iinfo->ii_bstart, iinfo->ii_bend, au_iigen(inode, NULL));
5792 + if (iinfo->ii_bstart < 0)
5795 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend; bindex++) {
5796 + hn = !!au_hn(iinfo->ii_hinode + bindex);
5797 + do_pri_inode(bindex, iinfo->ii_hinode[0 + bindex].hi_inode, hn,
5798 + iinfo->ii_hinode[0 + bindex].hi_whdentry);
5802 +void au_dpri_dalias(struct inode *inode)
5806 + spin_lock(&inode->i_lock);
5807 + hlist_for_each_entry(d, &inode->i_dentry, d_alias)
5808 + au_dpri_dentry(d);
5809 + spin_unlock(&inode->i_lock);
5812 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
5814 + struct dentry *wh = NULL;
5817 + if (!dentry || IS_ERR(dentry)) {
5818 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
5821 + /* do not call dget_parent() here */
5822 + /* note: access d_xxx without d_lock */
5823 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
5824 + bindex, dentry, dentry,
5825 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
5826 + d_count(dentry), dentry->d_flags,
5827 + d_unhashed(dentry) ? "un" : "");
5829 + if (bindex >= 0 && dentry->d_inode && au_test_aufs(dentry->d_sb)) {
5830 + struct au_iinfo *iinfo = au_ii(dentry->d_inode);
5832 + hn = !!au_hn(iinfo->ii_hinode + bindex);
5833 + wh = iinfo->ii_hinode[0 + bindex].hi_whdentry;
5836 + do_pri_inode(bindex, dentry->d_inode, hn, wh);
5840 +void au_dpri_dentry(struct dentry *dentry)
5842 + struct au_dinfo *dinfo;
5843 + aufs_bindex_t bindex;
5845 + struct au_hdentry *hdp;
5847 + err = do_pri_dentry(-1, dentry);
5848 + if (err || !au_test_aufs(dentry->d_sb))
5851 + dinfo = au_di(dentry);
5854 + dpri("d-1: bstart %d, bend %d, bwh %d, bdiropq %d, gen %d\n",
5855 + dinfo->di_bstart, dinfo->di_bend,
5856 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry));
5857 + if (dinfo->di_bstart < 0)
5859 + hdp = dinfo->di_hdentry;
5860 + for (bindex = dinfo->di_bstart; bindex <= dinfo->di_bend; bindex++)
5861 + do_pri_dentry(bindex, hdp[0 + bindex].hd_dentry);
5864 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
5868 + if (!file || IS_ERR(file)) {
5869 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
5875 + && au_test_aufs(file->f_dentry->d_sb)
5877 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
5878 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
5879 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
5880 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
5881 + file->f_version, file->f_pos, a);
5882 + if (file->f_dentry)
5883 + do_pri_dentry(bindex, file->f_dentry);
5887 +void au_dpri_file(struct file *file)
5889 + struct au_finfo *finfo;
5890 + struct au_fidir *fidir;
5891 + struct au_hfile *hfile;
5892 + aufs_bindex_t bindex;
5895 + err = do_pri_file(-1, file);
5896 + if (err || !file->f_dentry || !au_test_aufs(file->f_dentry->d_sb))
5899 + finfo = au_fi(file);
5902 + if (finfo->fi_btop < 0)
5904 + fidir = finfo->fi_hdir;
5906 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
5908 + for (bindex = finfo->fi_btop;
5909 + bindex >= 0 && bindex <= fidir->fd_bbot;
5911 + hfile = fidir->fd_hfile + bindex;
5912 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
5916 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
5918 + struct vfsmount *mnt;
5919 + struct super_block *sb;
5921 + if (!br || IS_ERR(br))
5923 + mnt = au_br_mnt(br);
5924 + if (!mnt || IS_ERR(mnt))
5927 + if (!sb || IS_ERR(sb))
5930 + dpri("s%d: {perm 0x%x, id %d, cnt %d, wbr %p}, "
5931 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
5933 + bindex, br->br_perm, br->br_id, atomic_read(&br->br_count),
5934 + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
5935 + sb->s_flags, sb->s_count,
5936 + atomic_read(&sb->s_active), !!br->br_xino.xi_file);
5940 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
5944 +void au_dpri_sb(struct super_block *sb)
5946 + struct au_sbinfo *sbinfo;
5947 + aufs_bindex_t bindex;
5949 + /* to reuduce stack size */
5951 + struct vfsmount mnt;
5952 + struct au_branch fake;
5955 + /* this function can be called from magic sysrq */
5956 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
5957 + if (unlikely(!a)) {
5958 + dpri("no memory\n");
5962 + a->mnt.mnt_sb = sb;
5963 + a->fake.br_perm = 0;
5964 + a->fake.br_path.mnt = &a->mnt;
5965 + a->fake.br_xino.xi_file = NULL;
5966 + atomic_set(&a->fake.br_count, 0);
5967 + smp_mb(); /* atomic_set */
5968 + err = do_pri_br(-1, &a->fake);
5970 + dpri("dev 0x%x\n", sb->s_dev);
5971 + if (err || !au_test_aufs(sb))
5974 + sbinfo = au_sbi(sb);
5977 + dpri("nw %d, gen %u, kobj %d\n",
5978 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
5979 + atomic_read(&sbinfo->si_kobj.kref.refcount));
5980 + for (bindex = 0; bindex <= sbinfo->si_bend; bindex++)
5981 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
5984 +/* ---------------------------------------------------------------------- */
5986 +void au_dbg_sleep_jiffy(int jiffy)
5989 + jiffy = schedule_timeout_uninterruptible(jiffy);
5992 +void au_dbg_iattr(struct iattr *ia)
5994 +#define AuBit(name) \
5996 + if (ia->ia_valid & ATTR_ ## name) \
5997 + dpri(#name "\n"); \
6017 + dpri("ia_file %p\n", ia->ia_file);
6020 +/* ---------------------------------------------------------------------- */
6022 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
6024 + struct inode *h_inode, *inode = dentry->d_inode;
6025 + struct dentry *h_dentry;
6026 + aufs_bindex_t bindex, bend, bi;
6028 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
6031 + bend = au_dbend(dentry);
6032 + bi = au_ibend(inode);
6035 + bindex = au_dbstart(dentry);
6036 + bi = au_ibstart(inode);
6040 + for (; bindex <= bend; bindex++) {
6041 + h_dentry = au_h_dptr(dentry, bindex);
6044 + h_inode = au_h_iptr(inode, bindex);
6045 + if (unlikely(h_inode != h_dentry->d_inode)) {
6047 + AuDbg("b%d, %s:%d\n", bindex, func, line);
6048 + AuDbgDentry(dentry);
6049 + AuDbgInode(inode);
6056 +void au_dbg_verify_dir_parent(struct dentry *dentry, unsigned int sigen)
6058 + struct dentry *parent;
6060 + parent = dget_parent(dentry);
6061 + AuDebugOn(!S_ISDIR(dentry->d_inode->i_mode));
6062 + AuDebugOn(IS_ROOT(dentry));
6063 + AuDebugOn(au_digen_test(parent, sigen));
6067 +void au_dbg_verify_nondir_parent(struct dentry *dentry, unsigned int sigen)
6069 + struct dentry *parent;
6070 + struct inode *inode;
6072 + parent = dget_parent(dentry);
6073 + inode = dentry->d_inode;
6074 + AuDebugOn(inode && S_ISDIR(dentry->d_inode->i_mode));
6075 + AuDebugOn(au_digen_test(parent, sigen));
6079 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
6082 + struct au_dcsub_pages dpages;
6083 + struct au_dpage *dpage;
6084 + struct dentry **dentries;
6086 + err = au_dpages_init(&dpages, GFP_NOFS);
6088 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
6090 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
6091 + dpage = dpages.dpages + i;
6092 + dentries = dpage->dentries;
6093 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
6094 + AuDebugOn(au_digen_test(dentries[j], sigen));
6096 + au_dpages_free(&dpages);
6099 +void au_dbg_verify_kthread(void)
6101 + if (au_wkq_test()) {
6104 + * It may be recursive, but udba=notify between two aufs mounts,
6105 + * where a single ro branch is shared, is not a problem.
6111 +/* ---------------------------------------------------------------------- */
6113 +void au_debug_sbinfo_init(struct au_sbinfo *sbinfo __maybe_unused)
6115 +#ifdef AuForceNoPlink
6116 + au_opt_clr(sbinfo->si_mntflags, PLINK);
6118 +#ifdef AuForceNoXino
6119 + au_opt_clr(sbinfo->si_mntflags, XINO);
6121 +#ifdef AuForceNoRefrof
6122 + au_opt_clr(sbinfo->si_mntflags, REFROF);
6124 +#ifdef AuForceHnotify
6125 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_HNOTIFY);
6128 + sbinfo->si_rdblk = 0;
6129 + sbinfo->si_rdhash = 0;
6133 +int __init au_debug_init(void)
6135 + aufs_bindex_t bindex;
6136 + struct au_vdir_destr destr;
6139 + AuDebugOn(bindex >= 0);
6142 + AuDebugOn(destr.len < NAME_MAX);
6144 +#ifdef CONFIG_4KSTACKS
6145 + pr_warn("CONFIG_4KSTACKS is defined.\n");
6148 +#ifdef AuForceNoBrs
6154 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
6155 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
6156 +++ linux/fs/aufs/debug.h 2014-01-20 20:16:14.736130059 +0100
6159 + * Copyright (C) 2005-2014 Junjiro R. Okajima
6161 + * This program, aufs is free software; you can redistribute it and/or modify
6162 + * it under the terms of the GNU General Public License as published by
6163 + * the Free Software Foundation; either version 2 of the License, or
6164 + * (at your option) any later version.
6166 + * This program is distributed in the hope that it will be useful,
6167 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6168 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6169 + * GNU General Public License for more details.
6171 + * You should have received a copy of the GNU General Public License
6172 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6176 + * debug print functions
6179 +#ifndef __AUFS_DEBUG_H__
6180 +#define __AUFS_DEBUG_H__
6184 +#include <linux/atomic.h>
6185 +#include <linux/module.h>
6186 +#include <linux/kallsyms.h>
6187 +#include <linux/sysrq.h>
6189 +#ifdef CONFIG_AUFS_DEBUG
6190 +#define AuDebugOn(a) BUG_ON(a)
6192 +/* module parameter */
6193 +extern atomic_t aufs_debug;
6194 +static inline void au_debug_on(void)
6196 + atomic_inc(&aufs_debug);
6198 +static inline void au_debug_off(void)
6200 + atomic_dec_if_positive(&aufs_debug);
6203 +static inline int au_debug_test(void)
6205 + return atomic_read(&aufs_debug) > 0;
6208 +#define AuDebugOn(a) do {} while (0)
6209 +AuStubVoid(au_debug_on, void)
6210 +AuStubVoid(au_debug_off, void)
6211 +AuStubInt0(au_debug_test, void)
6212 +#endif /* CONFIG_AUFS_DEBUG */
6214 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
6216 +/* ---------------------------------------------------------------------- */
6220 +#define AuDbg(fmt, ...) do { \
6221 + if (au_debug_test()) \
6222 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
6224 +#define AuLabel(l) AuDbg(#l "\n")
6225 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
6226 +#define AuWarn1(fmt, ...) do { \
6227 + static unsigned char _c; \
6229 + pr_warn(fmt, ##__VA_ARGS__); \
6232 +#define AuErr1(fmt, ...) do { \
6233 + static unsigned char _c; \
6235 + pr_err(fmt, ##__VA_ARGS__); \
6238 +#define AuIOErr1(fmt, ...) do { \
6239 + static unsigned char _c; \
6241 + AuIOErr(fmt, ##__VA_ARGS__); \
6244 +#define AuUnsupportMsg "This operation is not supported." \
6245 + " Please report this application to aufs-users ML."
6246 +#define AuUnsupport(fmt, ...) do { \
6247 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
6251 +#define AuTraceErr(e) do { \
6252 + if (unlikely((e) < 0)) \
6253 + AuDbg("err %d\n", (int)(e)); \
6256 +#define AuTraceErrPtr(p) do { \
6258 + AuDbg("err %ld\n", PTR_ERR(p)); \
6261 +/* dirty macros for debug print, use with "%.*s" and caution */
6262 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
6264 +/* ---------------------------------------------------------------------- */
6269 +#ifdef CONFIG_AUFS_DEBUG
6270 +extern char *au_plevel;
6272 +void au_dpri_whlist(struct au_nhash *whlist);
6274 +void au_dpri_vdir(struct au_vdir *vdir);
6276 +void au_dpri_inode(struct inode *inode);
6277 +void au_dpri_dalias(struct inode *inode);
6278 +void au_dpri_dentry(struct dentry *dentry);
6280 +void au_dpri_file(struct file *filp);
6281 +struct super_block;
6282 +void au_dpri_sb(struct super_block *sb);
6284 +void au_dbg_sleep_jiffy(int jiffy);
6286 +void au_dbg_iattr(struct iattr *ia);
6288 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
6289 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
6290 +void au_dbg_verify_dir_parent(struct dentry *dentry, unsigned int sigen);
6291 +void au_dbg_verify_nondir_parent(struct dentry *dentry, unsigned int sigen);
6292 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
6293 +void au_dbg_verify_kthread(void);
6295 +int __init au_debug_init(void);
6296 +void au_debug_sbinfo_init(struct au_sbinfo *sbinfo);
6297 +#define AuDbgWhlist(w) do { \
6299 + au_dpri_whlist(w); \
6302 +#define AuDbgVdir(v) do { \
6304 + au_dpri_vdir(v); \
6307 +#define AuDbgInode(i) do { \
6309 + au_dpri_inode(i); \
6312 +#define AuDbgDAlias(i) do { \
6314 + au_dpri_dalias(i); \
6317 +#define AuDbgDentry(d) do { \
6319 + au_dpri_dentry(d); \
6322 +#define AuDbgFile(f) do { \
6324 + au_dpri_file(f); \
6327 +#define AuDbgSb(sb) do { \
6328 + AuDbg(#sb "\n"); \
6332 +#define AuDbgSleep(sec) do { \
6333 + AuDbg("sleep %d sec\n", sec); \
6337 +#define AuDbgSleepJiffy(jiffy) do { \
6338 + AuDbg("sleep %d jiffies\n", jiffy); \
6339 + au_dbg_sleep_jiffy(jiffy); \
6342 +#define AuDbgIAttr(ia) do { \
6343 + AuDbg("ia_valid 0x%x\n", (ia)->ia_valid); \
6344 + au_dbg_iattr(ia); \
6347 +#define AuDbgSym(addr) do { \
6348 + char sym[KSYM_SYMBOL_LEN]; \
6349 + sprint_symbol(sym, (unsigned long)addr); \
6350 + AuDbg("%s\n", sym); \
6353 +#define AuInfoSym(addr) do { \
6354 + char sym[KSYM_SYMBOL_LEN]; \
6355 + sprint_symbol(sym, (unsigned long)addr); \
6356 + AuInfo("%s\n", sym); \
6359 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
6360 +AuStubVoid(au_dbg_verify_dir_parent, struct dentry *dentry, unsigned int sigen)
6361 +AuStubVoid(au_dbg_verify_nondir_parent, struct dentry *dentry,
6362 + unsigned int sigen)
6363 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
6364 +AuStubVoid(au_dbg_verify_kthread, void)
6365 +AuStubInt0(__init au_debug_init, void)
6366 +AuStubVoid(au_debug_sbinfo_init, struct au_sbinfo *sbinfo)
6368 +#define AuDbgWhlist(w) do {} while (0)
6369 +#define AuDbgVdir(v) do {} while (0)
6370 +#define AuDbgInode(i) do {} while (0)
6371 +#define AuDbgDAlias(i) do {} while (0)
6372 +#define AuDbgDentry(d) do {} while (0)
6373 +#define AuDbgFile(f) do {} while (0)
6374 +#define AuDbgSb(sb) do {} while (0)
6375 +#define AuDbgSleep(sec) do {} while (0)
6376 +#define AuDbgSleepJiffy(jiffy) do {} while (0)
6377 +#define AuDbgIAttr(ia) do {} while (0)
6378 +#define AuDbgSym(addr) do {} while (0)
6379 +#define AuInfoSym(addr) do {} while (0)
6380 +#endif /* CONFIG_AUFS_DEBUG */
6382 +/* ---------------------------------------------------------------------- */
6384 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
6385 +int __init au_sysrq_init(void);
6386 +void au_sysrq_fin(void);
6388 +#ifdef CONFIG_HW_CONSOLE
6389 +#define au_dbg_blocked() do { \
6391 + handle_sysrq('w'); \
6394 +AuStubVoid(au_dbg_blocked, void)
6398 +AuStubInt0(__init au_sysrq_init, void)
6399 +AuStubVoid(au_sysrq_fin, void)
6400 +AuStubVoid(au_dbg_blocked, void)
6401 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
6403 +#endif /* __KERNEL__ */
6404 +#endif /* __AUFS_DEBUG_H__ */
6405 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
6406 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
6407 +++ linux/fs/aufs/dentry.c 2014-01-27 23:16:52.701753487 +0100
6410 + * Copyright (C) 2005-2014 Junjiro R. Okajima
6412 + * This program, aufs is free software; you can redistribute it and/or modify
6413 + * it under the terms of the GNU General Public License as published by
6414 + * the Free Software Foundation; either version 2 of the License, or
6415 + * (at your option) any later version.
6417 + * This program is distributed in the hope that it will be useful,
6418 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6419 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6420 + * GNU General Public License for more details.
6422 + * You should have received a copy of the GNU General Public License
6423 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6427 + * lookup and dentry operations
6430 +#include <linux/namei.h>
6433 +#define AuLkup_ALLOW_NEG 1
6434 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
6435 +#define au_fset_lkup(flags, name) \
6436 + do { (flags) |= AuLkup_##name; } while (0)
6437 +#define au_fclr_lkup(flags, name) \
6438 + do { (flags) &= ~AuLkup_##name; } while (0)
6440 +struct au_do_lookup_args {
6441 + unsigned int flags;
6446 + * returns positive/negative dentry, NULL or an error.
6447 + * NULL means whiteout-ed or not-found.
6449 +static struct dentry*
6450 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
6451 + aufs_bindex_t bindex, struct qstr *wh_name,
6452 + struct au_do_lookup_args *args)
6454 + struct dentry *h_dentry;
6455 + struct inode *h_inode, *inode;
6456 + struct au_branch *br;
6457 + int wh_found, opq;
6458 + unsigned char wh_able;
6459 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
6462 + br = au_sbr(dentry->d_sb, bindex);
6463 + wh_able = !!au_br_whable(br->br_perm);
6465 + wh_found = au_wh_test(h_parent, wh_name, br, /*try_sio*/0);
6466 + h_dentry = ERR_PTR(wh_found);
6469 + if (unlikely(wh_found < 0))
6472 + /* We found a whiteout */
6473 + /* au_set_dbend(dentry, bindex); */
6474 + au_set_dbwh(dentry, bindex);
6476 + return NULL; /* success */
6479 + h_dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
6480 + if (IS_ERR(h_dentry))
6483 + h_inode = h_dentry->d_inode;
6487 + } else if (wh_found
6488 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
6491 + if (au_dbend(dentry) <= bindex)
6492 + au_set_dbend(dentry, bindex);
6493 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
6494 + au_set_dbstart(dentry, bindex);
6495 + au_set_h_dptr(dentry, bindex, h_dentry);
6497 + inode = dentry->d_inode;
6498 + if (!h_inode || !S_ISDIR(h_inode->i_mode) || !wh_able
6499 + || (inode && !S_ISDIR(inode->i_mode)))
6500 + goto out; /* success */
6502 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
6503 + opq = au_diropq_test(h_dentry, br);
6504 + mutex_unlock(&h_inode->i_mutex);
6506 + au_set_dbdiropq(dentry, bindex);
6507 + else if (unlikely(opq < 0)) {
6508 + au_set_h_dptr(dentry, bindex, NULL);
6509 + h_dentry = ERR_PTR(opq);
6520 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
6522 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
6523 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
6529 + * returns the number of lower positive dentries,
6530 + * otherwise an error.
6531 + * can be called at unlinking with @type is zero.
6533 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type)
6535 + int npositive, err;
6536 + aufs_bindex_t bindex, btail, bdiropq;
6537 + unsigned char isdir;
6538 + struct qstr whname;
6539 + struct au_do_lookup_args args = {
6543 + const struct qstr *name = &dentry->d_name;
6544 + struct dentry *parent;
6545 + struct inode *inode;
6547 + err = au_test_shwh(dentry->d_sb, name);
6548 + if (unlikely(err))
6551 + err = au_wh_name_alloc(&whname, name);
6552 + if (unlikely(err))
6555 + inode = dentry->d_inode;
6556 + isdir = !!(inode && S_ISDIR(inode->i_mode));
6558 + au_fset_lkup(args.flags, ALLOW_NEG);
6561 + parent = dget_parent(dentry);
6562 + btail = au_dbtaildir(parent);
6563 + for (bindex = bstart; bindex <= btail; bindex++) {
6564 + struct dentry *h_parent, *h_dentry;
6565 + struct inode *h_inode, *h_dir;
6567 + h_dentry = au_h_dptr(dentry, bindex);
6569 + if (h_dentry->d_inode)
6571 + if (type != S_IFDIR)
6575 + h_parent = au_h_dptr(parent, bindex);
6578 + h_dir = h_parent->d_inode;
6579 + if (!h_dir || !S_ISDIR(h_dir->i_mode))
6582 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
6583 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname,
6585 + mutex_unlock(&h_dir->i_mutex);
6586 + err = PTR_ERR(h_dentry);
6587 + if (IS_ERR(h_dentry))
6589 + au_fclr_lkup(args.flags, ALLOW_NEG);
6591 + if (au_dbwh(dentry) >= 0)
6595 + h_inode = h_dentry->d_inode;
6600 + args.type = h_inode->i_mode & S_IFMT;
6601 + if (args.type != S_IFDIR)
6604 + /* the type of lower may be different */
6605 + bdiropq = au_dbdiropq(dentry);
6606 + if (bdiropq >= 0 && bdiropq <= bindex)
6612 + AuLabel(positive);
6613 + au_update_dbstart(dentry);
6616 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
6617 + && au_dbstart(dentry) < 0)) {
6619 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
6625 + kfree(whname.name);
6630 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent,
6631 + struct au_branch *br)
6633 + struct dentry *dentry;
6636 + if (!au_test_h_perm_sio(parent->d_inode, MAY_EXEC))
6637 + dentry = vfsub_lkup_one(name, parent);
6639 + struct vfsub_lkup_one_args args = {
6645 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
6646 + if (unlikely(wkq_err))
6647 + dentry = ERR_PTR(wkq_err);
6654 + * lookup @dentry on @bindex which should be negative.
6656 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
6659 + struct dentry *parent, *h_parent, *h_dentry;
6660 + struct au_branch *br;
6662 + parent = dget_parent(dentry);
6663 + h_parent = au_h_dptr(parent, bindex);
6664 + br = au_sbr(dentry->d_sb, bindex);
6666 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
6668 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent, br);
6669 + err = PTR_ERR(h_dentry);
6670 + if (IS_ERR(h_dentry))
6672 + if (unlikely(h_dentry->d_inode)) {
6674 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
6680 + if (bindex < au_dbstart(dentry))
6681 + au_set_dbstart(dentry, bindex);
6682 + if (au_dbend(dentry) < bindex)
6683 + au_set_dbend(dentry, bindex);
6684 + au_set_h_dptr(dentry, bindex, h_dentry);
6691 +/* ---------------------------------------------------------------------- */
6693 +/* subset of struct inode */
6695 + unsigned long i_ino;
6696 + /* unsigned int i_nlink; */
6702 + blkcnt_t i_blocks;
6707 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
6709 + ia->i_ino = h_inode->i_ino;
6710 + /* ia->i_nlink = h_inode->i_nlink; */
6711 + ia->i_uid = h_inode->i_uid;
6712 + ia->i_gid = h_inode->i_gid;
6713 + ia->i_version = h_inode->i_version;
6715 + ia->i_size = h_inode->i_size;
6716 + ia->i_blocks = h_inode->i_blocks;
6718 + ia->i_mode = (h_inode->i_mode & S_IFMT);
6721 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
6723 + return ia->i_ino != h_inode->i_ino
6724 + /* || ia->i_nlink != h_inode->i_nlink */
6725 + || !uid_eq(ia->i_uid, h_inode->i_uid)
6726 + || !gid_eq(ia->i_gid, h_inode->i_gid)
6727 + || ia->i_version != h_inode->i_version
6729 + || ia->i_size != h_inode->i_size
6730 + || ia->i_blocks != h_inode->i_blocks
6732 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
6735 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
6736 + struct au_branch *br)
6739 + struct au_iattr ia;
6740 + struct inode *h_inode;
6741 + struct dentry *h_d;
6742 + struct super_block *h_sb;
6745 + memset(&ia, -1, sizeof(ia));
6746 + h_sb = h_dentry->d_sb;
6747 + h_inode = h_dentry->d_inode;
6749 + au_iattr_save(&ia, h_inode);
6750 + else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
6751 + /* nfs d_revalidate may return 0 for negative dentry */
6752 + /* fuse d_revalidate always return 0 for negative dentry */
6755 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
6756 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
6757 + err = PTR_ERR(h_d);
6762 + if (unlikely(h_d != h_dentry
6763 + || h_d->d_inode != h_inode
6764 + || (h_inode && au_iattr_test(&ia, h_inode))))
6765 + err = au_busy_or_stale();
6773 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
6774 + struct dentry *h_parent, struct au_branch *br)
6779 + if (udba == AuOpt_UDBA_REVAL
6780 + && !au_test_fs_remote(h_dentry->d_sb)) {
6782 + err = (h_dentry->d_parent->d_inode != h_dir);
6783 + } else if (udba != AuOpt_UDBA_NONE)
6784 + err = au_h_verify_dentry(h_dentry, h_parent, br);
6789 +/* ---------------------------------------------------------------------- */
6791 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
6794 + aufs_bindex_t new_bindex, bindex, bend, bwh, bdiropq;
6795 + struct au_hdentry tmp, *p, *q;
6796 + struct au_dinfo *dinfo;
6797 + struct super_block *sb;
6799 + DiMustWriteLock(dentry);
6801 + sb = dentry->d_sb;
6802 + dinfo = au_di(dentry);
6803 + bend = dinfo->di_bend;
6804 + bwh = dinfo->di_bwh;
6805 + bdiropq = dinfo->di_bdiropq;
6806 + p = dinfo->di_hdentry + dinfo->di_bstart;
6807 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++, p++) {
6808 + if (!p->hd_dentry)
6811 + new_bindex = au_br_index(sb, p->hd_id);
6812 + if (new_bindex == bindex)
6815 + if (dinfo->di_bwh == bindex)
6817 + if (dinfo->di_bdiropq == bindex)
6818 + bdiropq = new_bindex;
6819 + if (new_bindex < 0) {
6821 + p->hd_dentry = NULL;
6825 + /* swap two lower dentries, and loop again */
6826 + q = dinfo->di_hdentry + new_bindex;
6830 + if (tmp.hd_dentry) {
6836 + dinfo->di_bwh = -1;
6837 + if (bwh >= 0 && bwh <= au_sbend(sb) && au_sbr_whable(sb, bwh))
6838 + dinfo->di_bwh = bwh;
6840 + dinfo->di_bdiropq = -1;
6842 + && bdiropq <= au_sbend(sb)
6843 + && au_sbr_whable(sb, bdiropq))
6844 + dinfo->di_bdiropq = bdiropq;
6847 + dinfo->di_bstart = -1;
6848 + dinfo->di_bend = -1;
6849 + bend = au_dbend(parent);
6850 + p = dinfo->di_hdentry;
6851 + for (bindex = 0; bindex <= bend; bindex++, p++)
6852 + if (p->hd_dentry) {
6853 + dinfo->di_bstart = bindex;
6857 + if (dinfo->di_bstart >= 0) {
6858 + p = dinfo->di_hdentry + bend;
6859 + for (bindex = bend; bindex >= 0; bindex--, p--)
6860 + if (p->hd_dentry) {
6861 + dinfo->di_bend = bindex;
6870 +static void au_do_hide(struct dentry *dentry)
6872 + struct inode *inode;
6874 + inode = dentry->d_inode;
6876 + if (!S_ISDIR(inode->i_mode)) {
6877 + if (inode->i_nlink && !d_unhashed(dentry))
6878 + drop_nlink(inode);
6880 + clear_nlink(inode);
6881 + /* stop next lookup */
6882 + inode->i_flags |= S_DEAD;
6884 + smp_mb(); /* necessary? */
6889 +static int au_hide_children(struct dentry *parent)
6891 + int err, i, j, ndentry;
6892 + struct au_dcsub_pages dpages;
6893 + struct au_dpage *dpage;
6894 + struct dentry *dentry;
6896 + err = au_dpages_init(&dpages, GFP_NOFS);
6897 + if (unlikely(err))
6899 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
6900 + if (unlikely(err))
6903 + /* in reverse order */
6904 + for (i = dpages.ndpage - 1; i >= 0; i--) {
6905 + dpage = dpages.dpages + i;
6906 + ndentry = dpage->ndentry;
6907 + for (j = ndentry - 1; j >= 0; j--) {
6908 + dentry = dpage->dentries[j];
6909 + if (dentry != parent)
6910 + au_do_hide(dentry);
6915 + au_dpages_free(&dpages);
6920 +static void au_hide(struct dentry *dentry)
6923 + struct inode *inode;
6925 + AuDbgDentry(dentry);
6926 + inode = dentry->d_inode;
6927 + if (inode && S_ISDIR(inode->i_mode)) {
6928 + /* shrink_dcache_parent(dentry); */
6929 + err = au_hide_children(dentry);
6930 + if (unlikely(err))
6931 + AuIOErr("%pd, failed hiding children, ignored %d\n",
6934 + au_do_hide(dentry);
6938 + * By adding a dirty branch, a cached dentry may be affected in various ways.
6940 + * a dirty branch is added
6941 + * - on the top of layers
6942 + * - in the middle of layers
6943 + * - to the bottom of layers
6945 + * on the added branch there exists
6948 + * - a same named entry
6950 + * * negative --> positive
6951 + * * positive --> positive
6952 + * - type is unchanged
6953 + * - type is changed
6955 + * * negative --> negative
6956 + * * positive --> negative (rejected by au_br_del() for non-dir case)
6959 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
6960 + struct au_dinfo *tmp)
6963 + aufs_bindex_t bindex, bend;
6965 + struct dentry *dentry;
6966 + struct inode *inode;
6969 + struct au_hdentry *hd;
6970 + struct inode *inode, *h_inode;
6971 + struct dentry *h_dentry;
6974 + AuDebugOn(dinfo->di_bstart < 0);
6975 + orig_h.dentry = dinfo->di_hdentry[dinfo->di_bstart].hd_dentry;
6976 + orig_h.inode = orig_h.dentry->d_inode;
6979 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
6980 + memset(&tmp_h, 0, sizeof(tmp_h));
6981 + if (tmp->di_bstart >= 0) {
6982 + tmp_h.dentry = tmp->di_hdentry[tmp->di_bstart].hd_dentry;
6983 + tmp_h.inode = tmp_h.dentry->d_inode;
6985 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
6988 + inode = dentry->d_inode;
6989 + if (!orig_h.inode) {
6990 + AuDbg("nagative originally\n");
6996 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
6997 + AuDebugOn(dinfo->di_bdiropq != -1);
6999 + if (!tmp_h.inode) {
7000 + AuDbg("negative --> negative\n");
7001 + /* should have only one negative lower */
7002 + if (tmp->di_bstart >= 0
7003 + && tmp->di_bstart < dinfo->di_bstart) {
7004 + AuDebugOn(tmp->di_bstart != tmp->di_bend);
7005 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
7006 + au_set_h_dptr(dentry, dinfo->di_bstart, NULL);
7007 + au_di_cp(dinfo, tmp);
7008 + hd = tmp->di_hdentry + tmp->di_bstart;
7009 + au_set_h_dptr(dentry, tmp->di_bstart,
7010 + dget(hd->hd_dentry));
7012 + au_dbg_verify_dinode(dentry);
7014 + AuDbg("negative --> positive\n");
7016 + * similar to the behaviour of creating with bypassing
7018 + * unhash it in order to force an error in the
7019 + * succeeding create operation.
7020 + * we should not set S_DEAD here.
7023 + /* au_di_swap(tmp, dinfo); */
7024 + au_dbg_verify_dinode(dentry);
7027 + AuDbg("positive originally\n");
7028 + /* inode may be NULL */
7029 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
7030 + if (!tmp_h.inode) {
7031 + AuDbg("positive --> negative\n");
7032 + /* or bypassing aufs */
7034 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_bstart)
7035 + dinfo->di_bwh = tmp->di_bwh;
7037 + err = au_refresh_hinode_self(inode);
7038 + au_dbg_verify_dinode(dentry);
7039 + } else if (orig_h.mode == tmp_h.mode) {
7040 + AuDbg("positive --> positive, same type\n");
7041 + if (!S_ISDIR(orig_h.mode)
7042 + && dinfo->di_bstart > tmp->di_bstart) {
7044 + * similar to the behaviour of removing and
7049 + err = au_refresh_hinode_self(inode);
7050 + au_dbg_verify_dinode(dentry);
7052 + /* fill empty slots */
7053 + if (dinfo->di_bstart > tmp->di_bstart)
7054 + dinfo->di_bstart = tmp->di_bstart;
7055 + if (dinfo->di_bend < tmp->di_bend)
7056 + dinfo->di_bend = tmp->di_bend;
7057 + dinfo->di_bwh = tmp->di_bwh;
7058 + dinfo->di_bdiropq = tmp->di_bdiropq;
7059 + hd = tmp->di_hdentry;
7060 + bend = dinfo->di_bend;
7061 + for (bindex = tmp->di_bstart; bindex <= bend;
7063 + if (au_h_dptr(dentry, bindex))
7065 + h_dentry = hd[bindex].hd_dentry;
7068 + h_inode = h_dentry->d_inode;
7069 + AuDebugOn(!h_inode);
7070 + AuDebugOn(orig_h.mode
7071 + != (h_inode->i_mode
7073 + au_set_h_dptr(dentry, bindex,
7076 + err = au_refresh_hinode(inode, dentry);
7077 + au_dbg_verify_dinode(dentry);
7080 + AuDbg("positive --> positive, different type\n");
7081 + /* similar to the behaviour of removing and creating */
7084 + err = au_refresh_hinode_self(inode);
7085 + au_dbg_verify_dinode(dentry);
7093 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
7096 + unsigned int sigen;
7097 + struct au_dinfo *dinfo, *tmp;
7098 + struct super_block *sb;
7099 + struct inode *inode;
7101 + DiMustWriteLock(dentry);
7102 + AuDebugOn(IS_ROOT(dentry));
7103 + AuDebugOn(!parent->d_inode);
7105 + sb = dentry->d_sb;
7106 + inode = dentry->d_inode;
7107 + sigen = au_sigen(sb);
7108 + err = au_digen_test(parent, sigen);
7109 + if (unlikely(err))
7112 + dinfo = au_di(dentry);
7113 + err = au_di_realloc(dinfo, au_sbend(sb) + 1);
7114 + if (unlikely(err))
7116 + ebrange = au_dbrange_test(dentry);
7118 + ebrange = au_do_refresh_hdentry(dentry, parent);
7120 + if (d_unhashed(dentry) || ebrange) {
7121 + AuDebugOn(au_dbstart(dentry) < 0 && au_dbend(dentry) >= 0);
7123 + err = au_refresh_hinode_self(inode);
7124 + au_dbg_verify_dinode(dentry);
7126 + goto out_dgen; /* success */
7130 + /* temporary dinfo */
7131 + AuDbgDentry(dentry);
7133 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
7134 + if (unlikely(!tmp))
7136 + au_di_swap(tmp, dinfo);
7137 + /* returns the number of positive dentries */
7139 + * if current working dir is removed, it returns an error.
7140 + * but the dentry is legal.
7142 + err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0);
7143 + AuDbgDentry(dentry);
7144 + au_di_swap(tmp, dinfo);
7145 + if (err == -ENOENT)
7148 + /* compare/refresh by dinfo */
7149 + AuDbgDentry(dentry);
7150 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
7151 + au_dbg_verify_dinode(dentry);
7154 + au_rw_write_unlock(&tmp->di_rwsem);
7156 + if (unlikely(err))
7160 + au_update_digen(dentry);
7162 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
7163 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
7164 + AuDbgDentry(dentry);
7170 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
7171 + struct dentry *dentry, aufs_bindex_t bindex)
7176 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
7179 + AuDbg("b%d\n", bindex);
7181 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
7182 + * due to whiteout and branch permission.
7184 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
7185 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
7186 + /* it may return tri-state */
7187 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
7189 + if (unlikely(valid < 0))
7199 +/* todo: remove this */
7200 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
7201 + unsigned int flags, int do_udba)
7204 + umode_t mode, h_mode;
7205 + aufs_bindex_t bindex, btail, bstart, ibs, ibe;
7206 + unsigned char plus, unhashed, is_root, h_plus, h_nfs;
7207 + struct inode *h_inode, *h_cached_inode;
7208 + struct dentry *h_dentry;
7209 + struct qstr *name, *h_name;
7216 + unhashed = !!d_unhashed(dentry);
7217 + is_root = !!IS_ROOT(dentry);
7218 + name = &dentry->d_name;
7221 + * Theoretically, REVAL test should be unnecessary in case of
7223 + * But {fs,i}notify doesn't fire some necessary events,
7224 + * IN_ATTRIB for atime/nlink/pageio
7225 + * IN_DELETE for NFS dentry
7226 + * Let's do REVAL test too.
7228 + if (do_udba && inode) {
7229 + mode = (inode->i_mode & S_IFMT);
7230 + plus = (inode->i_nlink > 0);
7231 + ibs = au_ibstart(inode);
7232 + ibe = au_ibend(inode);
7235 + bstart = au_dbstart(dentry);
7237 + if (inode && S_ISDIR(inode->i_mode))
7238 + btail = au_dbtaildir(dentry);
7239 + for (bindex = bstart; bindex <= btail; bindex++) {
7240 + h_dentry = au_h_dptr(dentry, bindex);
7244 + AuDbg("b%d, %pd\n", bindex, h_dentry);
7245 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
7246 + spin_lock(&h_dentry->d_lock);
7247 + h_name = &h_dentry->d_name;
7248 + if (unlikely(do_udba
7251 + && (unhashed != !!d_unhashed(h_dentry)
7252 + || name->len != h_name->len
7253 + || memcmp(name->name, h_name->name,
7256 + && !(flags & LOOKUP_OPEN)
7257 + && (h_dentry->d_flags
7258 + & DCACHE_NFSFS_RENAMED)))
7260 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
7261 + unhashed, d_unhashed(h_dentry),
7262 + dentry, h_dentry);
7263 + spin_unlock(&h_dentry->d_lock);
7266 + spin_unlock(&h_dentry->d_lock);
7268 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
7269 + if (unlikely(err))
7270 + /* do not goto err, to keep the errno */
7273 + /* todo: plink too? */
7278 + h_inode = h_dentry->d_inode;
7279 + if (unlikely(!!inode != !!h_inode))
7284 + h_cached_inode = h_inode;
7286 + h_mode = (h_inode->i_mode & S_IFMT);
7287 + h_plus = (h_inode->i_nlink > 0);
7289 + if (inode && ibs <= bindex && bindex <= ibe)
7290 + h_cached_inode = au_h_iptr(inode, bindex);
7293 + if (unlikely(plus != h_plus))
7296 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
7298 + && !IS_ROOT(h_dentry)
7299 + && unhashed != d_unhashed(h_dentry)))
7302 + if (unlikely(mode != h_mode
7303 + || h_cached_inode != h_inode))
7316 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
7317 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
7320 + struct dentry *parent;
7322 + if (!au_digen_test(dentry, sigen))
7325 + parent = dget_parent(dentry);
7326 + di_read_lock_parent(parent, AuLock_IR);
7327 + AuDebugOn(au_digen_test(parent, sigen));
7328 + au_dbg_verify_gen(parent, sigen);
7329 + err = au_refresh_dentry(dentry, parent);
7330 + di_read_unlock(parent, AuLock_IR);
7336 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
7339 + struct dentry *d, *parent;
7340 + struct inode *inode;
7342 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
7343 + return simple_reval_dpath(dentry, sigen);
7345 + /* slow loop, keep it simple and stupid */
7346 + /* cf: au_cpup_dirs() */
7349 + while (au_digen_test(dentry, sigen)) {
7353 + parent = dget_parent(d);
7354 + if (!au_digen_test(parent, sigen))
7359 + inode = d->d_inode;
7361 + di_write_lock_child2(d);
7363 + /* someone might update our dentry while we were sleeping */
7364 + if (au_digen_test(d, sigen)) {
7366 + * todo: consolidate with simple_reval_dpath(),
7367 + * do_refresh() and au_reval_for_attr().
7369 + di_read_lock_parent(parent, AuLock_IR);
7370 + err = au_refresh_dentry(d, parent);
7371 + di_read_unlock(parent, AuLock_IR);
7375 + di_write_unlock(d);
7377 + if (unlikely(err))
7385 + * if valid returns 1, otherwise 0.
7387 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
7390 + unsigned int sigen;
7391 + unsigned char do_udba;
7392 + struct super_block *sb;
7393 + struct inode *inode;
7395 + /* todo: support rcu-walk? */
7396 + if (flags & LOOKUP_RCU)
7400 + if (unlikely(!au_di(dentry)))
7403 + inode = dentry->d_inode;
7404 + if (inode && is_bad_inode(inode))
7408 + sb = dentry->d_sb;
7411 + * i_mutex of parent dir may be held,
7412 + * but we should not return 'invalid' due to busy.
7414 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
7415 + if (unlikely(err)) {
7420 + if (unlikely(au_dbrange_test(dentry))) {
7426 + sigen = au_sigen(sb);
7427 + if (au_digen_test(dentry, sigen)) {
7428 + AuDebugOn(IS_ROOT(dentry));
7429 + err = au_reval_dpath(dentry, sigen);
7430 + if (unlikely(err)) {
7435 + di_downgrade_lock(dentry, AuLock_IR);
7438 + if (!(flags & LOOKUP_OPEN)
7440 + && (IS_DEADDIR(inode) || !inode->i_nlink))
7443 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
7444 + if (do_udba && inode) {
7445 + aufs_bindex_t bstart = au_ibstart(inode);
7446 + struct inode *h_inode;
7448 + if (bstart >= 0) {
7449 + h_inode = au_h_iptr(inode, bstart);
7450 + if (h_inode && au_test_higen(inode, h_inode))
7455 + err = h_d_revalidate(dentry, inode, flags, do_udba);
7456 + if (unlikely(!err && do_udba && au_dbstart(dentry) < 0)) {
7458 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
7464 + di_downgrade_lock(dentry, AuLock_IR);
7466 + aufs_read_unlock(dentry, AuLock_IR);
7471 + AuDbg("%pd invalid, %d\n", dentry, valid);
7477 +static void aufs_d_release(struct dentry *dentry)
7479 + if (au_di(dentry)) {
7480 + au_di_fin(dentry);
7481 + au_hn_di_reinit(dentry);
7485 +const struct dentry_operations aufs_dop = {
7486 + .d_revalidate = aufs_d_revalidate,
7487 + .d_weak_revalidate = aufs_d_revalidate,
7488 + .d_release = aufs_d_release
7490 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
7491 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
7492 +++ linux/fs/aufs/dentry.h 2014-01-20 20:16:14.736130059 +0100
7495 + * Copyright (C) 2005-2014 Junjiro R. Okajima
7497 + * This program, aufs is free software; you can redistribute it and/or modify
7498 + * it under the terms of the GNU General Public License as published by
7499 + * the Free Software Foundation; either version 2 of the License, or
7500 + * (at your option) any later version.
7502 + * This program is distributed in the hope that it will be useful,
7503 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7504 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7505 + * GNU General Public License for more details.
7507 + * You should have received a copy of the GNU General Public License
7508 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7512 + * lookup and dentry operations
7515 +#ifndef __AUFS_DENTRY_H__
7516 +#define __AUFS_DENTRY_H__
7520 +#include <linux/dcache.h>
7523 +struct au_hdentry {
7524 + struct dentry *hd_dentry;
7525 + aufs_bindex_t hd_id;
7529 + atomic_t di_generation;
7531 + struct au_rwsem di_rwsem;
7532 + aufs_bindex_t di_bstart, di_bend, di_bwh, di_bdiropq;
7533 + struct au_hdentry *di_hdentry;
7534 +} ____cacheline_aligned_in_smp;
7536 +/* ---------------------------------------------------------------------- */
7539 +extern const struct dentry_operations aufs_dop;
7541 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent,
7542 + struct au_branch *br);
7543 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
7544 + struct dentry *h_parent, struct au_branch *br);
7546 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type);
7547 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
7548 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
7549 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
7552 +void au_di_init_once(void *_di);
7553 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
7554 +void au_di_free(struct au_dinfo *dinfo);
7555 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
7556 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
7557 +int au_di_init(struct dentry *dentry);
7558 +void au_di_fin(struct dentry *dentry);
7559 +int au_di_realloc(struct au_dinfo *dinfo, int nbr);
7561 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
7562 +void di_read_unlock(struct dentry *d, int flags);
7563 +void di_downgrade_lock(struct dentry *d, int flags);
7564 +void di_write_lock(struct dentry *d, unsigned int lsc);
7565 +void di_write_unlock(struct dentry *d);
7566 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
7567 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
7568 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
7570 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
7571 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
7572 +aufs_bindex_t au_dbtail(struct dentry *dentry);
7573 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
7575 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
7576 + struct dentry *h_dentry);
7577 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
7578 +int au_dbrange_test(struct dentry *dentry);
7579 +void au_update_digen(struct dentry *dentry);
7580 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
7581 +void au_update_dbstart(struct dentry *dentry);
7582 +void au_update_dbend(struct dentry *dentry);
7583 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
7585 +/* ---------------------------------------------------------------------- */
7587 +static inline struct au_dinfo *au_di(struct dentry *dentry)
7589 + return dentry->d_fsdata;
7592 +/* ---------------------------------------------------------------------- */
7594 +/* lock subclass for dinfo */
7596 + AuLsc_DI_CHILD, /* child first */
7597 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
7598 + AuLsc_DI_CHILD3, /* copyup dirs */
7602 + AuLsc_DI_TMP /* temp for replacing dinfo */
7606 + * di_read_lock_child, di_write_lock_child,
7607 + * di_read_lock_child2, di_write_lock_child2,
7608 + * di_read_lock_child3, di_write_lock_child3,
7609 + * di_read_lock_parent, di_write_lock_parent,
7610 + * di_read_lock_parent2, di_write_lock_parent2,
7611 + * di_read_lock_parent3, di_write_lock_parent3,
7613 +#define AuReadLockFunc(name, lsc) \
7614 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
7615 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
7617 +#define AuWriteLockFunc(name, lsc) \
7618 +static inline void di_write_lock_##name(struct dentry *d) \
7619 +{ di_write_lock(d, AuLsc_DI_##lsc); }
7621 +#define AuRWLockFuncs(name, lsc) \
7622 + AuReadLockFunc(name, lsc) \
7623 + AuWriteLockFunc(name, lsc)
7625 +AuRWLockFuncs(child, CHILD);
7626 +AuRWLockFuncs(child2, CHILD2);
7627 +AuRWLockFuncs(child3, CHILD3);
7628 +AuRWLockFuncs(parent, PARENT);
7629 +AuRWLockFuncs(parent2, PARENT2);
7630 +AuRWLockFuncs(parent3, PARENT3);
7632 +#undef AuReadLockFunc
7633 +#undef AuWriteLockFunc
7634 +#undef AuRWLockFuncs
7636 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
7637 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
7638 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
7640 +/* ---------------------------------------------------------------------- */
7642 +/* todo: memory barrier? */
7643 +static inline unsigned int au_digen(struct dentry *d)
7645 + return atomic_read(&au_di(d)->di_generation);
7648 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
7650 + hdentry->hd_dentry = NULL;
7653 +static inline void au_hdput(struct au_hdentry *hd)
7656 + dput(hd->hd_dentry);
7659 +static inline aufs_bindex_t au_dbstart(struct dentry *dentry)
7661 + DiMustAnyLock(dentry);
7662 + return au_di(dentry)->di_bstart;
7665 +static inline aufs_bindex_t au_dbend(struct dentry *dentry)
7667 + DiMustAnyLock(dentry);
7668 + return au_di(dentry)->di_bend;
7671 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
7673 + DiMustAnyLock(dentry);
7674 + return au_di(dentry)->di_bwh;
7677 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
7679 + DiMustAnyLock(dentry);
7680 + return au_di(dentry)->di_bdiropq;
7683 +/* todo: hard/soft set? */
7684 +static inline void au_set_dbstart(struct dentry *dentry, aufs_bindex_t bindex)
7686 + DiMustWriteLock(dentry);
7687 + au_di(dentry)->di_bstart = bindex;
7690 +static inline void au_set_dbend(struct dentry *dentry, aufs_bindex_t bindex)
7692 + DiMustWriteLock(dentry);
7693 + au_di(dentry)->di_bend = bindex;
7696 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
7698 + DiMustWriteLock(dentry);
7699 + /* dbwh can be outside of bstart - bend range */
7700 + au_di(dentry)->di_bwh = bindex;
7703 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
7705 + DiMustWriteLock(dentry);
7706 + au_di(dentry)->di_bdiropq = bindex;
7709 +/* ---------------------------------------------------------------------- */
7711 +#ifdef CONFIG_AUFS_HNOTIFY
7712 +static inline void au_digen_dec(struct dentry *d)
7714 + atomic_dec(&au_di(d)->di_generation);
7717 +static inline void au_hn_di_reinit(struct dentry *dentry)
7719 + dentry->d_fsdata = NULL;
7722 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
7723 +#endif /* CONFIG_AUFS_HNOTIFY */
7725 +#endif /* __KERNEL__ */
7726 +#endif /* __AUFS_DENTRY_H__ */
7727 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
7728 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
7729 +++ linux/fs/aufs/dinfo.c 2014-01-20 20:16:14.736130059 +0100
7732 + * Copyright (C) 2005-2014 Junjiro R. Okajima
7734 + * This program, aufs is free software; you can redistribute it and/or modify
7735 + * it under the terms of the GNU General Public License as published by
7736 + * the Free Software Foundation; either version 2 of the License, or
7737 + * (at your option) any later version.
7739 + * This program is distributed in the hope that it will be useful,
7740 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7741 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7742 + * GNU General Public License for more details.
7744 + * You should have received a copy of the GNU General Public License
7745 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7749 + * dentry private data
7754 +void au_di_init_once(void *_dinfo)
7756 + struct au_dinfo *dinfo = _dinfo;
7757 + static struct lock_class_key aufs_di;
7759 + au_rw_init(&dinfo->di_rwsem);
7760 + au_rw_class(&dinfo->di_rwsem, &aufs_di);
7763 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
7765 + struct au_dinfo *dinfo;
7768 + dinfo = au_cache_alloc_dinfo();
7769 + if (unlikely(!dinfo))
7772 + nbr = au_sbend(sb) + 1;
7775 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
7776 + if (dinfo->di_hdentry) {
7777 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
7778 + dinfo->di_bstart = -1;
7779 + dinfo->di_bend = -1;
7780 + dinfo->di_bwh = -1;
7781 + dinfo->di_bdiropq = -1;
7782 + for (i = 0; i < nbr; i++)
7783 + dinfo->di_hdentry[i].hd_id = -1;
7787 + au_cache_free_dinfo(dinfo);
7794 +void au_di_free(struct au_dinfo *dinfo)
7796 + struct au_hdentry *p;
7797 + aufs_bindex_t bend, bindex;
7799 + /* dentry may not be revalidated */
7800 + bindex = dinfo->di_bstart;
7801 + if (bindex >= 0) {
7802 + bend = dinfo->di_bend;
7803 + p = dinfo->di_hdentry + bindex;
7804 + while (bindex++ <= bend)
7807 + kfree(dinfo->di_hdentry);
7808 + au_cache_free_dinfo(dinfo);
7811 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
7813 + struct au_hdentry *p;
7816 + AuRwMustWriteLock(&a->di_rwsem);
7817 + AuRwMustWriteLock(&b->di_rwsem);
7819 +#define DiSwap(v, name) \
7821 + v = a->di_##name; \
7822 + a->di_##name = b->di_##name; \
7823 + b->di_##name = v; \
7826 + DiSwap(p, hdentry);
7827 + DiSwap(bi, bstart);
7830 + DiSwap(bi, bdiropq);
7836 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
7838 + AuRwMustWriteLock(&dst->di_rwsem);
7839 + AuRwMustWriteLock(&src->di_rwsem);
7841 + dst->di_bstart = src->di_bstart;
7842 + dst->di_bend = src->di_bend;
7843 + dst->di_bwh = src->di_bwh;
7844 + dst->di_bdiropq = src->di_bdiropq;
7848 +int au_di_init(struct dentry *dentry)
7851 + struct super_block *sb;
7852 + struct au_dinfo *dinfo;
7855 + sb = dentry->d_sb;
7856 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
7858 + atomic_set(&dinfo->di_generation, au_sigen(sb));
7859 + /* smp_mb(); */ /* atomic_set */
7860 + dentry->d_fsdata = dinfo;
7867 +void au_di_fin(struct dentry *dentry)
7869 + struct au_dinfo *dinfo;
7871 + dinfo = au_di(dentry);
7872 + AuRwDestroy(&dinfo->di_rwsem);
7873 + au_di_free(dinfo);
7876 +int au_di_realloc(struct au_dinfo *dinfo, int nbr)
7879 + struct au_hdentry *hdp;
7881 + AuRwMustWriteLock(&dinfo->di_rwsem);
7884 + sz = sizeof(*hdp) * (dinfo->di_bend + 1);
7886 + sz = sizeof(*hdp);
7887 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS);
7889 + dinfo->di_hdentry = hdp;
7896 +/* ---------------------------------------------------------------------- */
7898 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
7901 + case AuLsc_DI_CHILD:
7902 + ii_write_lock_child(inode);
7904 + case AuLsc_DI_CHILD2:
7905 + ii_write_lock_child2(inode);
7907 + case AuLsc_DI_CHILD3:
7908 + ii_write_lock_child3(inode);
7910 + case AuLsc_DI_PARENT:
7911 + ii_write_lock_parent(inode);
7913 + case AuLsc_DI_PARENT2:
7914 + ii_write_lock_parent2(inode);
7916 + case AuLsc_DI_PARENT3:
7917 + ii_write_lock_parent3(inode);
7924 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
7927 + case AuLsc_DI_CHILD:
7928 + ii_read_lock_child(inode);
7930 + case AuLsc_DI_CHILD2:
7931 + ii_read_lock_child2(inode);
7933 + case AuLsc_DI_CHILD3:
7934 + ii_read_lock_child3(inode);
7936 + case AuLsc_DI_PARENT:
7937 + ii_read_lock_parent(inode);
7939 + case AuLsc_DI_PARENT2:
7940 + ii_read_lock_parent2(inode);
7942 + case AuLsc_DI_PARENT3:
7943 + ii_read_lock_parent3(inode);
7950 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
7952 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
7954 + if (au_ftest_lock(flags, IW))
7955 + do_ii_write_lock(d->d_inode, lsc);
7956 + else if (au_ftest_lock(flags, IR))
7957 + do_ii_read_lock(d->d_inode, lsc);
7961 +void di_read_unlock(struct dentry *d, int flags)
7964 + if (au_ftest_lock(flags, IW)) {
7965 + au_dbg_verify_dinode(d);
7966 + ii_write_unlock(d->d_inode);
7967 + } else if (au_ftest_lock(flags, IR)) {
7968 + au_dbg_verify_dinode(d);
7969 + ii_read_unlock(d->d_inode);
7972 + au_rw_read_unlock(&au_di(d)->di_rwsem);
7975 +void di_downgrade_lock(struct dentry *d, int flags)
7977 + if (d->d_inode && au_ftest_lock(flags, IR))
7978 + ii_downgrade_lock(d->d_inode);
7979 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
7982 +void di_write_lock(struct dentry *d, unsigned int lsc)
7984 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
7986 + do_ii_write_lock(d->d_inode, lsc);
7989 +void di_write_unlock(struct dentry *d)
7991 + au_dbg_verify_dinode(d);
7993 + ii_write_unlock(d->d_inode);
7994 + au_rw_write_unlock(&au_di(d)->di_rwsem);
7997 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
7999 + AuDebugOn(d1 == d2
8000 + || d1->d_inode == d2->d_inode
8001 + || d1->d_sb != d2->d_sb);
8003 + if (isdir && au_test_subdir(d1, d2)) {
8004 + di_write_lock_child(d1);
8005 + di_write_lock_child2(d2);
8007 + /* there should be no races */
8008 + di_write_lock_child(d2);
8009 + di_write_lock_child2(d1);
8013 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
8015 + AuDebugOn(d1 == d2
8016 + || d1->d_inode == d2->d_inode
8017 + || d1->d_sb != d2->d_sb);
8019 + if (isdir && au_test_subdir(d1, d2)) {
8020 + di_write_lock_parent(d1);
8021 + di_write_lock_parent2(d2);
8023 + /* there should be no races */
8024 + di_write_lock_parent(d2);
8025 + di_write_lock_parent2(d1);
8029 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
8031 + di_write_unlock(d1);
8032 + if (d1->d_inode == d2->d_inode)
8033 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
8035 + di_write_unlock(d2);
8038 +/* ---------------------------------------------------------------------- */
8040 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
8044 + DiMustAnyLock(dentry);
8046 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
8048 + AuDebugOn(bindex < 0);
8049 + d = au_di(dentry)->di_hdentry[0 + bindex].hd_dentry;
8050 + AuDebugOn(d && d_count(d) <= 0);
8055 + * extended version of au_h_dptr().
8056 + * returns a hashed and positive h_dentry in bindex, NULL, or error.
8058 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
8060 + struct dentry *h_dentry;
8061 + struct inode *inode, *h_inode;
8063 + inode = dentry->d_inode;
8064 + AuDebugOn(!inode);
8067 + if (au_dbstart(dentry) <= bindex
8068 + && bindex <= au_dbend(dentry))
8069 + h_dentry = au_h_dptr(dentry, bindex);
8070 + if (h_dentry && !au_d_hashed_positive(h_dentry)) {
8072 + goto out; /* success */
8075 + AuDebugOn(bindex < au_ibstart(inode));
8076 + AuDebugOn(au_ibend(inode) < bindex);
8077 + h_inode = au_h_iptr(inode, bindex);
8078 + h_dentry = d_find_alias(h_inode);
8080 + if (!IS_ERR(h_dentry)) {
8081 + if (!au_d_hashed_positive(h_dentry))
8082 + goto out; /* success */
8088 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
8089 + h_dentry = au_plink_lkup(inode, bindex);
8090 + AuDebugOn(!h_dentry);
8091 + if (!IS_ERR(h_dentry)) {
8092 + if (!au_d_hashed_positive(h_dentry))
8093 + goto out; /* success */
8100 + AuDbgDentry(h_dentry);
8104 +aufs_bindex_t au_dbtail(struct dentry *dentry)
8106 + aufs_bindex_t bend, bwh;
8108 + bend = au_dbend(dentry);
8110 + bwh = au_dbwh(dentry);
8113 + if (0 < bwh && bwh < bend)
8119 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
8121 + aufs_bindex_t bend, bopq;
8123 + bend = au_dbtail(dentry);
8125 + bopq = au_dbdiropq(dentry);
8126 + if (0 <= bopq && bopq < bend)
8132 +/* ---------------------------------------------------------------------- */
8134 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
8135 + struct dentry *h_dentry)
8137 + struct au_hdentry *hd = au_di(dentry)->di_hdentry + bindex;
8138 + struct au_branch *br;
8140 + DiMustWriteLock(dentry);
8143 + hd->hd_dentry = h_dentry;
8145 + br = au_sbr(dentry->d_sb, bindex);
8146 + hd->hd_id = br->br_id;
8150 +int au_dbrange_test(struct dentry *dentry)
8153 + aufs_bindex_t bstart, bend;
8156 + bstart = au_dbstart(dentry);
8157 + bend = au_dbend(dentry);
8159 + AuDebugOn(bend < 0 && bstart > bend);
8162 + AuDebugOn(bend >= 0);
8168 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
8173 + if (unlikely(au_digen(dentry) != sigen
8174 + || au_iigen_test(dentry->d_inode, sigen)))
8180 +void au_update_digen(struct dentry *dentry)
8182 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
8183 + /* smp_mb(); */ /* atomic_set */
8186 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
8188 + struct au_dinfo *dinfo;
8189 + struct dentry *h_d;
8190 + struct au_hdentry *hdp;
8192 + DiMustWriteLock(dentry);
8194 + dinfo = au_di(dentry);
8195 + if (!dinfo || dinfo->di_bstart < 0)
8198 + hdp = dinfo->di_hdentry;
8199 + if (do_put_zero) {
8200 + aufs_bindex_t bindex, bend;
8202 + bend = dinfo->di_bend;
8203 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++) {
8204 + h_d = hdp[0 + bindex].hd_dentry;
8205 + if (h_d && !h_d->d_inode)
8206 + au_set_h_dptr(dentry, bindex, NULL);
8210 + dinfo->di_bstart = -1;
8211 + while (++dinfo->di_bstart <= dinfo->di_bend)
8212 + if (hdp[0 + dinfo->di_bstart].hd_dentry)
8214 + if (dinfo->di_bstart > dinfo->di_bend) {
8215 + dinfo->di_bstart = -1;
8216 + dinfo->di_bend = -1;
8221 + while (0 <= --dinfo->di_bend)
8222 + if (hdp[0 + dinfo->di_bend].hd_dentry)
8224 + AuDebugOn(dinfo->di_bstart > dinfo->di_bend || dinfo->di_bend < 0);
8227 +void au_update_dbstart(struct dentry *dentry)
8229 + aufs_bindex_t bindex, bend;
8230 + struct dentry *h_dentry;
8232 + bend = au_dbend(dentry);
8233 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
8234 + h_dentry = au_h_dptr(dentry, bindex);
8237 + if (h_dentry->d_inode) {
8238 + au_set_dbstart(dentry, bindex);
8241 + au_set_h_dptr(dentry, bindex, NULL);
8245 +void au_update_dbend(struct dentry *dentry)
8247 + aufs_bindex_t bindex, bstart;
8248 + struct dentry *h_dentry;
8250 + bstart = au_dbstart(dentry);
8251 + for (bindex = au_dbend(dentry); bindex >= bstart; bindex--) {
8252 + h_dentry = au_h_dptr(dentry, bindex);
8255 + if (h_dentry->d_inode) {
8256 + au_set_dbend(dentry, bindex);
8259 + au_set_h_dptr(dentry, bindex, NULL);
8263 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
8265 + aufs_bindex_t bindex, bend;
8267 + bend = au_dbend(dentry);
8268 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++)
8269 + if (au_h_dptr(dentry, bindex) == h_dentry)
8273 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
8274 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
8275 +++ linux/fs/aufs/dir.c 2014-01-27 23:16:52.701753487 +0100
8278 + * Copyright (C) 2005-2014 Junjiro R. Okajima
8280 + * This program, aufs is free software; you can redistribute it and/or modify
8281 + * it under the terms of the GNU General Public License as published by
8282 + * the Free Software Foundation; either version 2 of the License, or
8283 + * (at your option) any later version.
8285 + * This program is distributed in the hope that it will be useful,
8286 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8287 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8288 + * GNU General Public License for more details.
8290 + * You should have received a copy of the GNU General Public License
8291 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8295 + * directory operations
8298 +#include <linux/fs_stack.h>
8301 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
8303 + unsigned int nlink;
8305 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
8307 + nlink = dir->i_nlink;
8308 + nlink += h_dir->i_nlink - 2;
8309 + if (h_dir->i_nlink < 2)
8311 + smp_mb(); /* for i_nlink */
8312 + /* 0 can happen in revaliding */
8313 + set_nlink(dir, nlink);
8316 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
8318 + unsigned int nlink;
8320 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
8322 + nlink = dir->i_nlink;
8323 + nlink -= h_dir->i_nlink - 2;
8324 + if (h_dir->i_nlink < 2)
8326 + smp_mb(); /* for i_nlink */
8327 + /* nlink == 0 means the branch-fs is broken */
8328 + set_nlink(dir, nlink);
8331 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
8334 + aufs_bindex_t bindex, bend;
8335 + struct file *h_file;
8336 + struct dentry *h_dentry;
8340 + AuDebugOn(!file_inode(file));
8341 + AuDebugOn(!S_ISDIR(file_inode(file)->i_mode));
8343 + bend = au_fbend_dir(file);
8344 + for (bindex = au_fbstart(file);
8345 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
8347 + h_file = au_hf_dir(file, bindex);
8348 + if (h_file && file_inode(h_file))
8349 + sz += vfsub_f_size_read(h_file);
8352 + AuDebugOn(!dentry);
8353 + AuDebugOn(!dentry->d_inode);
8354 + AuDebugOn(!S_ISDIR(dentry->d_inode->i_mode));
8356 + bend = au_dbtaildir(dentry);
8357 + for (bindex = au_dbstart(dentry);
8358 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
8360 + h_dentry = au_h_dptr(dentry, bindex);
8361 + if (h_dentry && h_dentry->d_inode)
8362 + sz += i_size_read(h_dentry->d_inode);
8365 + if (sz < KMALLOC_MAX_SIZE)
8366 + sz = roundup_pow_of_two(sz);
8367 + if (sz > KMALLOC_MAX_SIZE)
8368 + sz = KMALLOC_MAX_SIZE;
8369 + else if (sz < NAME_MAX) {
8370 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
8371 + sz = AUFS_RDBLK_DEF;
8376 +/* ---------------------------------------------------------------------- */
8378 +static int reopen_dir(struct file *file)
8381 + unsigned int flags;
8382 + aufs_bindex_t bindex, btail, bstart;
8383 + struct dentry *dentry, *h_dentry;
8384 + struct file *h_file;
8386 + /* open all lower dirs */
8387 + dentry = file->f_dentry;
8388 + bstart = au_dbstart(dentry);
8389 + for (bindex = au_fbstart(file); bindex < bstart; bindex++)
8390 + au_set_h_fptr(file, bindex, NULL);
8391 + au_set_fbstart(file, bstart);
8393 + btail = au_dbtaildir(dentry);
8394 + for (bindex = au_fbend_dir(file); btail < bindex; bindex--)
8395 + au_set_h_fptr(file, bindex, NULL);
8396 + au_set_fbend_dir(file, btail);
8398 + flags = vfsub_file_flags(file);
8399 + for (bindex = bstart; bindex <= btail; bindex++) {
8400 + h_dentry = au_h_dptr(dentry, bindex);
8403 + h_file = au_hf_dir(file, bindex);
8407 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
8408 + err = PTR_ERR(h_file);
8409 + if (IS_ERR(h_file))
8410 + goto out; /* close all? */
8411 + au_set_h_fptr(file, bindex, h_file);
8413 + au_update_figen(file);
8414 + /* todo: necessary? */
8415 + /* file->f_ra = h_file->f_ra; */
8422 +static int do_open_dir(struct file *file, int flags)
8425 + aufs_bindex_t bindex, btail;
8426 + struct dentry *dentry, *h_dentry;
8427 + struct file *h_file;
8429 + FiMustWriteLock(file);
8432 + dentry = file->f_dentry;
8433 + file->f_version = dentry->d_inode->i_version;
8434 + bindex = au_dbstart(dentry);
8435 + au_set_fbstart(file, bindex);
8436 + btail = au_dbtaildir(dentry);
8437 + au_set_fbend_dir(file, btail);
8438 + for (; !err && bindex <= btail; bindex++) {
8439 + h_dentry = au_h_dptr(dentry, bindex);
8443 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
8444 + if (IS_ERR(h_file)) {
8445 + err = PTR_ERR(h_file);
8448 + au_set_h_fptr(file, bindex, h_file);
8450 + au_update_figen(file);
8451 + /* todo: necessary? */
8452 + /* file->f_ra = h_file->f_ra; */
8454 + return 0; /* success */
8457 + for (bindex = au_fbstart(file); bindex <= btail; bindex++)
8458 + au_set_h_fptr(file, bindex, NULL);
8459 + au_set_fbstart(file, -1);
8460 + au_set_fbend_dir(file, -1);
8465 +static int aufs_open_dir(struct inode *inode __maybe_unused,
8466 + struct file *file)
8469 + struct super_block *sb;
8470 + struct au_fidir *fidir;
8473 + sb = file->f_dentry->d_sb;
8474 + si_read_lock(sb, AuLock_FLUSH);
8475 + fidir = au_fidir_alloc(sb);
8477 + err = au_do_open(file, do_open_dir, fidir);
8478 + if (unlikely(err))
8481 + si_read_unlock(sb);
8485 +static int aufs_release_dir(struct inode *inode __maybe_unused,
8486 + struct file *file)
8488 + struct au_vdir *vdir_cache;
8489 + struct au_finfo *finfo;
8490 + struct au_fidir *fidir;
8491 + aufs_bindex_t bindex, bend;
8493 + finfo = au_fi(file);
8494 + fidir = finfo->fi_hdir;
8496 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
8498 + au_vdir_free(vdir_cache);
8500 + bindex = finfo->fi_btop;
8501 + if (bindex >= 0) {
8503 + * calls fput() instead of filp_close(),
8504 + * since no dnotify or lock for the lower file.
8506 + bend = fidir->fd_bbot;
8507 + for (; bindex <= bend; bindex++)
8508 + au_set_h_fptr(file, bindex, NULL);
8511 + finfo->fi_hdir = NULL;
8513 + au_finfo_fin(file);
8517 +/* ---------------------------------------------------------------------- */
8519 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
8522 + aufs_bindex_t bindex, bend;
8523 + struct file *h_file;
8526 + bend = au_fbend_dir(file);
8527 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
8528 + h_file = au_hf_dir(file, bindex);
8530 + err = vfsub_flush(h_file, id);
8535 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
8537 + return au_do_flush(file, id, au_do_flush_dir);
8540 +/* ---------------------------------------------------------------------- */
8542 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
8545 + aufs_bindex_t bend, bindex;
8546 + struct inode *inode;
8547 + struct super_block *sb;
8550 + sb = dentry->d_sb;
8551 + inode = dentry->d_inode;
8553 + bend = au_dbend(dentry);
8554 + for (bindex = au_dbstart(dentry); !err && bindex <= bend; bindex++) {
8555 + struct path h_path;
8557 + if (au_test_ro(sb, bindex, inode))
8559 + h_path.dentry = au_h_dptr(dentry, bindex);
8560 + if (!h_path.dentry)
8563 + h_path.mnt = au_sbr_mnt(sb, bindex);
8564 + err = vfsub_fsync(NULL, &h_path, datasync);
8570 +static int au_do_fsync_dir(struct file *file, int datasync)
8573 + aufs_bindex_t bend, bindex;
8574 + struct file *h_file;
8575 + struct super_block *sb;
8576 + struct inode *inode;
8578 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
8579 + if (unlikely(err))
8582 + sb = file->f_dentry->d_sb;
8583 + inode = file_inode(file);
8584 + bend = au_fbend_dir(file);
8585 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
8586 + h_file = au_hf_dir(file, bindex);
8587 + if (!h_file || au_test_ro(sb, bindex, inode))
8590 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
8598 + * @file may be NULL
8600 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
8604 + struct dentry *dentry;
8605 + struct super_block *sb;
8606 + struct mutex *mtx;
8609 + dentry = file->f_dentry;
8610 + mtx = &dentry->d_inode->i_mutex;
8612 + sb = dentry->d_sb;
8613 + si_noflush_read_lock(sb);
8615 + err = au_do_fsync_dir(file, datasync);
8617 + di_write_lock_child(dentry);
8618 + err = au_do_fsync_dir_no_file(dentry, datasync);
8620 + au_cpup_attr_timesizes(dentry->d_inode);
8621 + di_write_unlock(dentry);
8623 + fi_write_unlock(file);
8625 + si_read_unlock(sb);
8626 + mutex_unlock(mtx);
8630 +/* ---------------------------------------------------------------------- */
8632 +static int aufs_iterate(struct file *file, struct dir_context *ctx)
8635 + struct dentry *dentry;
8636 + struct inode *inode, *h_inode;
8637 + struct super_block *sb;
8639 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
8641 + dentry = file->f_dentry;
8642 + inode = dentry->d_inode;
8645 + sb = dentry->d_sb;
8646 + si_read_lock(sb, AuLock_FLUSH);
8647 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
8648 + if (unlikely(err))
8650 + err = au_alive_dir(dentry);
8652 + err = au_vdir_init(file);
8653 + di_downgrade_lock(dentry, AuLock_IR);
8654 + if (unlikely(err))
8657 + h_inode = au_h_iptr(inode, au_ibstart(inode));
8658 + if (!au_test_nfsd()) {
8659 + err = au_vdir_fill_de(file, ctx);
8660 + fsstack_copy_attr_atime(inode, h_inode);
8663 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
8664 + * encode_fh() and others.
8666 + atomic_inc(&h_inode->i_count);
8667 + di_read_unlock(dentry, AuLock_IR);
8668 + si_read_unlock(sb);
8669 + err = au_vdir_fill_de(file, ctx);
8670 + fsstack_copy_attr_atime(inode, h_inode);
8671 + fi_write_unlock(file);
8679 + di_read_unlock(dentry, AuLock_IR);
8680 + fi_write_unlock(file);
8682 + si_read_unlock(sb);
8686 +/* ---------------------------------------------------------------------- */
8688 +#define AuTestEmpty_WHONLY 1
8689 +#define AuTestEmpty_CALLED (1 << 1)
8690 +#define AuTestEmpty_SHWH (1 << 2)
8691 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
8692 +#define au_fset_testempty(flags, name) \
8693 + do { (flags) |= AuTestEmpty_##name; } while (0)
8694 +#define au_fclr_testempty(flags, name) \
8695 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
8697 +#ifndef CONFIG_AUFS_SHWH
8698 +#undef AuTestEmpty_SHWH
8699 +#define AuTestEmpty_SHWH 0
8702 +struct test_empty_arg {
8703 + struct dir_context ctx;
8704 + struct au_nhash *whlist;
8705 + unsigned int flags;
8707 + aufs_bindex_t bindex;
8710 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
8711 + int namelen, loff_t offset __maybe_unused, u64 ino,
8712 + unsigned int d_type)
8714 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
8716 + char *name = (void *)__name;
8719 + au_fset_testempty(arg->flags, CALLED);
8721 + if (name[0] == '.'
8722 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
8723 + goto out; /* success */
8725 + if (namelen <= AUFS_WH_PFX_LEN
8726 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
8727 + if (au_ftest_testempty(arg->flags, WHONLY)
8728 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
8729 + arg->err = -ENOTEMPTY;
8733 + name += AUFS_WH_PFX_LEN;
8734 + namelen -= AUFS_WH_PFX_LEN;
8735 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
8736 + arg->err = au_nhash_append_wh
8737 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
8738 + au_ftest_testempty(arg->flags, SHWH));
8742 + AuTraceErr(arg->err);
8746 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
8749 + struct file *h_file;
8751 + h_file = au_h_open(dentry, arg->bindex,
8752 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
8753 + /*file*/NULL, /*force_wr*/0);
8754 + err = PTR_ERR(h_file);
8755 + if (IS_ERR(h_file))
8759 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
8760 + && !file_inode(h_file)->i_nlink)
8765 + au_fclr_testempty(arg->flags, CALLED);
8767 + err = vfsub_iterate_dir(h_file, &arg->ctx);
8770 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
8774 + au_sbr_put(dentry->d_sb, arg->bindex);
8779 +struct do_test_empty_args {
8781 + struct dentry *dentry;
8782 + struct test_empty_arg *arg;
8785 +static void call_do_test_empty(void *args)
8787 + struct do_test_empty_args *a = args;
8788 + *a->errp = do_test_empty(a->dentry, a->arg);
8791 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
8794 + struct dentry *h_dentry;
8795 + struct inode *h_inode;
8797 + h_dentry = au_h_dptr(dentry, arg->bindex);
8798 + h_inode = h_dentry->d_inode;
8799 + /* todo: i_mode changes anytime? */
8800 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
8801 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
8802 + mutex_unlock(&h_inode->i_mutex);
8804 + err = do_test_empty(dentry, arg);
8806 + struct do_test_empty_args args = {
8811 + unsigned int flags = arg->flags;
8813 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
8814 + if (unlikely(wkq_err))
8816 + arg->flags = flags;
8822 +int au_test_empty_lower(struct dentry *dentry)
8825 + unsigned int rdhash;
8826 + aufs_bindex_t bindex, bstart, btail;
8827 + struct au_nhash whlist;
8828 + struct test_empty_arg arg = {
8830 + .actor = au_diractor(test_empty_cb)
8834 + SiMustAnyLock(dentry->d_sb);
8836 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
8838 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
8839 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
8840 + if (unlikely(err))
8844 + arg.whlist = &whlist;
8845 + bstart = au_dbstart(dentry);
8846 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
8847 + au_fset_testempty(arg.flags, SHWH);
8848 + arg.bindex = bstart;
8849 + err = do_test_empty(dentry, &arg);
8850 + if (unlikely(err))
8853 + au_fset_testempty(arg.flags, WHONLY);
8854 + btail = au_dbtaildir(dentry);
8855 + for (bindex = bstart + 1; !err && bindex <= btail; bindex++) {
8856 + struct dentry *h_dentry;
8858 + h_dentry = au_h_dptr(dentry, bindex);
8859 + if (h_dentry && h_dentry->d_inode) {
8860 + arg.bindex = bindex;
8861 + err = do_test_empty(dentry, &arg);
8866 + au_nhash_wh_free(&whlist);
8871 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
8874 + struct test_empty_arg arg = {
8876 + .actor = au_diractor(test_empty_cb)
8879 + aufs_bindex_t bindex, btail;
8882 + arg.whlist = whlist;
8883 + arg.flags = AuTestEmpty_WHONLY;
8884 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
8885 + au_fset_testempty(arg.flags, SHWH);
8886 + btail = au_dbtaildir(dentry);
8887 + for (bindex = au_dbstart(dentry); !err && bindex <= btail; bindex++) {
8888 + struct dentry *h_dentry;
8890 + h_dentry = au_h_dptr(dentry, bindex);
8891 + if (h_dentry && h_dentry->d_inode) {
8892 + arg.bindex = bindex;
8893 + err = sio_test_empty(dentry, &arg);
8900 +/* ---------------------------------------------------------------------- */
8902 +const struct file_operations aufs_dir_fop = {
8903 + .owner = THIS_MODULE,
8904 + .llseek = default_llseek,
8905 + .read = generic_read_dir,
8906 + .iterate = aufs_iterate,
8907 + .unlocked_ioctl = aufs_ioctl_dir,
8908 +#ifdef CONFIG_COMPAT
8909 + .compat_ioctl = aufs_compat_ioctl_dir,
8911 + .open = aufs_open_dir,
8912 + .release = aufs_release_dir,
8913 + .flush = aufs_flush_dir,
8914 + .fsync = aufs_fsync_dir
8916 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
8917 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
8918 +++ linux/fs/aufs/dir.h 2014-01-20 20:16:14.736130059 +0100
8921 + * Copyright (C) 2005-2014 Junjiro R. Okajima
8923 + * This program, aufs is free software; you can redistribute it and/or modify
8924 + * it under the terms of the GNU General Public License as published by
8925 + * the Free Software Foundation; either version 2 of the License, or
8926 + * (at your option) any later version.
8928 + * This program is distributed in the hope that it will be useful,
8929 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8930 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8931 + * GNU General Public License for more details.
8933 + * You should have received a copy of the GNU General Public License
8934 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8938 + * directory operations
8941 +#ifndef __AUFS_DIR_H__
8942 +#define __AUFS_DIR_H__
8946 +#include <linux/fs.h>
8948 +/* ---------------------------------------------------------------------- */
8950 +/* need to be faster and smaller */
8953 + unsigned int nh_num;
8954 + struct hlist_head *nh_head;
8957 +struct au_vdir_destr {
8958 + unsigned char len;
8959 + unsigned char name[0];
8962 +struct au_vdir_dehstr {
8963 + struct hlist_node hash;
8964 + struct au_vdir_destr *str;
8965 +} ____cacheline_aligned_in_smp;
8967 +struct au_vdir_de {
8969 + unsigned char de_type;
8970 + /* caution: packed */
8971 + struct au_vdir_destr de_str;
8974 +struct au_vdir_wh {
8975 + struct hlist_node wh_hash;
8976 +#ifdef CONFIG_AUFS_SHWH
8978 + aufs_bindex_t wh_bindex;
8979 + unsigned char wh_type;
8981 + aufs_bindex_t wh_bindex;
8983 + /* caution: packed */
8984 + struct au_vdir_destr wh_str;
8987 +union au_vdir_deblk_p {
8988 + unsigned char *deblk;
8989 + struct au_vdir_de *de;
8993 + unsigned char **vd_deblk;
8994 + unsigned long vd_nblk;
8997 + union au_vdir_deblk_p p;
9000 + unsigned long vd_version;
9001 + unsigned int vd_deblk_sz;
9002 + unsigned long vd_jiffy;
9003 +} ____cacheline_aligned_in_smp;
9005 +/* ---------------------------------------------------------------------- */
9008 +extern const struct file_operations aufs_dir_fop;
9009 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
9010 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
9011 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
9012 +int au_test_empty_lower(struct dentry *dentry);
9013 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
9016 +unsigned int au_rdhash_est(loff_t sz);
9017 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
9018 +void au_nhash_wh_free(struct au_nhash *whlist);
9019 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
9021 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
9022 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
9023 + unsigned int d_type, aufs_bindex_t bindex,
9024 + unsigned char shwh);
9025 +void au_vdir_free(struct au_vdir *vdir);
9026 +int au_vdir_init(struct file *file);
9027 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
9030 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
9032 +#ifdef CONFIG_AUFS_RDU
9034 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
9035 +#ifdef CONFIG_COMPAT
9036 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
9037 + unsigned long arg);
9040 +static inline long au_rdu_ioctl(struct file *file, unsigned int cmd,
9041 + unsigned long arg)
9045 +#ifdef CONFIG_COMPAT
9046 +static inline long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
9047 + unsigned long arg)
9054 +#endif /* __KERNEL__ */
9055 +#endif /* __AUFS_DIR_H__ */
9056 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
9057 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
9058 +++ linux/fs/aufs/dynop.c 2014-01-20 20:16:14.736130059 +0100
9061 + * Copyright (C) 2010-2014 Junjiro R. Okajima
9063 + * This program, aufs is free software; you can redistribute it and/or modify
9064 + * it under the terms of the GNU General Public License as published by
9065 + * the Free Software Foundation; either version 2 of the License, or
9066 + * (at your option) any later version.
9068 + * This program is distributed in the hope that it will be useful,
9069 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9070 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9071 + * GNU General Public License for more details.
9073 + * You should have received a copy of the GNU General Public License
9074 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9078 + * dynamically customizable operations for regular files
9083 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
9086 + * How large will these lists be?
9087 + * Usually just a few elements, 20-30 at most for each, I guess.
9089 +static struct au_splhead dynop[AuDyLast];
9091 +static struct au_dykey *dy_gfind_get(struct au_splhead *spl, const void *h_op)
9093 + struct au_dykey *key, *tmp;
9094 + struct list_head *head;
9097 + head = &spl->head;
9099 + list_for_each_entry_rcu(tmp, head, dk_list)
9100 + if (tmp->dk_op.dy_hop == h_op) {
9102 + kref_get(&key->dk_kref);
9105 + rcu_read_unlock();
9110 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
9112 + struct au_dykey **k, *found;
9113 + const void *h_op = key->dk_op.dy_hop;
9118 + for (i = 0; i < AuBrDynOp; i++)
9120 + if (k[i]->dk_op.dy_hop == h_op) {
9127 + spin_lock(&br->br_dykey_lock);
9128 + for (; i < AuBrDynOp; i++)
9130 + if (k[i]->dk_op.dy_hop == h_op) {
9138 + spin_unlock(&br->br_dykey_lock);
9139 + BUG_ON(i == AuBrDynOp); /* expand the array */
9145 +/* kref_get() if @key is already added */
9146 +static struct au_dykey *dy_gadd(struct au_splhead *spl, struct au_dykey *key)
9148 + struct au_dykey *tmp, *found;
9149 + struct list_head *head;
9150 + const void *h_op = key->dk_op.dy_hop;
9153 + head = &spl->head;
9154 + spin_lock(&spl->spin);
9155 + list_for_each_entry(tmp, head, dk_list)
9156 + if (tmp->dk_op.dy_hop == h_op) {
9157 + kref_get(&tmp->dk_kref);
9162 + list_add_rcu(&key->dk_list, head);
9163 + spin_unlock(&spl->spin);
9170 +static void dy_free_rcu(struct rcu_head *rcu)
9172 + struct au_dykey *key;
9174 + key = container_of(rcu, struct au_dykey, dk_rcu);
9179 +static void dy_free(struct kref *kref)
9181 + struct au_dykey *key;
9182 + struct au_splhead *spl;
9184 + key = container_of(kref, struct au_dykey, dk_kref);
9185 + spl = dynop + key->dk_op.dy_type;
9186 + au_spl_del_rcu(&key->dk_list, spl);
9187 + call_rcu(&key->dk_rcu, dy_free_rcu);
9190 +void au_dy_put(struct au_dykey *key)
9192 + kref_put(&key->dk_kref, dy_free);
9195 +/* ---------------------------------------------------------------------- */
9197 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
9199 +#ifdef CONFIG_AUFS_DEBUG
9200 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
9201 +#define DyDbgInc(cnt) do { cnt++; } while (0)
9203 +#define DyDbgDeclare(cnt) do {} while (0)
9204 +#define DyDbgInc(cnt) do {} while (0)
9207 +#define DySet(func, dst, src, h_op, h_sb) do { \
9209 + if (h_op->func) { \
9211 + dst.func = src.func; \
9213 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
9217 +#define DySetForce(func, dst, src) do { \
9218 + AuDebugOn(!src.func); \
9220 + dst.func = src.func; \
9223 +#define DySetAop(func) \
9224 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
9225 +#define DySetAopForce(func) \
9226 + DySetForce(func, dyaop->da_op, aufs_aop)
9228 +static void dy_aop(struct au_dykey *key, const void *h_op,
9229 + struct super_block *h_sb __maybe_unused)
9231 + struct au_dyaop *dyaop = (void *)key;
9232 + const struct address_space_operations *h_aop = h_op;
9233 + DyDbgDeclare(cnt);
9235 + AuDbg("%s\n", au_sbtype(h_sb));
9237 + DySetAop(writepage);
9238 + DySetAopForce(readpage); /* force */
9239 + DySetAop(writepages);
9240 + DySetAop(set_page_dirty);
9241 + DySetAop(readpages);
9242 + DySetAop(write_begin);
9243 + DySetAop(write_end);
9245 + DySetAop(invalidatepage);
9246 + DySetAop(releasepage);
9247 + DySetAop(freepage);
9248 + /* these two will be changed according to an aufs mount option */
9249 + DySetAop(direct_IO);
9250 + DySetAop(get_xip_mem);
9251 + DySetAop(migratepage);
9252 + DySetAop(launder_page);
9253 + DySetAop(is_partially_uptodate);
9254 + DySetAop(is_dirty_writeback);
9255 + DySetAop(error_remove_page);
9256 + DySetAop(swap_activate);
9257 + DySetAop(swap_deactivate);
9259 + DyDbgSize(cnt, *h_aop);
9260 + dyaop->da_get_xip_mem = h_aop->get_xip_mem;
9263 +/* ---------------------------------------------------------------------- */
9265 +static void dy_bug(struct kref *kref)
9270 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
9272 + struct au_dykey *key, *old;
9273 + struct au_splhead *spl;
9276 + void (*set)(struct au_dykey *key, const void *h_op,
9277 + struct super_block *h_sb __maybe_unused);
9279 + static const struct op a[] = {
9281 + .sz = sizeof(struct au_dyaop),
9285 + const struct op *p;
9287 + spl = dynop + op->dy_type;
9288 + key = dy_gfind_get(spl, op->dy_hop);
9290 + goto out_add; /* success */
9292 + p = a + op->dy_type;
9293 + key = kzalloc(p->sz, GFP_NOFS);
9294 + if (unlikely(!key)) {
9295 + key = ERR_PTR(-ENOMEM);
9299 + key->dk_op.dy_hop = op->dy_hop;
9300 + kref_init(&key->dk_kref);
9301 + p->set(key, op->dy_hop, au_br_sb(br));
9302 + old = dy_gadd(spl, key);
9309 + old = dy_bradd(br, key);
9311 + /* its ref-count should never be zero here */
9312 + kref_put(&key->dk_kref, dy_bug);
9317 +/* ---------------------------------------------------------------------- */
9319 + * Aufs prohibits O_DIRECT by defaut even if the branch supports it.
9320 + * This behaviour is neccessary to return an error from open(O_DIRECT) instead
9321 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
9322 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
9323 + * See the aufs manual in detail.
9325 + * To keep this behaviour, aufs has to set NULL to ->get_xip_mem too, and the
9326 + * performance of fadvise() and madvise() may be affected.
9328 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
9331 + dyaop->da_op.direct_IO = NULL;
9332 + dyaop->da_op.get_xip_mem = NULL;
9334 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
9335 + dyaop->da_op.get_xip_mem = aufs_aop.get_xip_mem;
9336 + if (!dyaop->da_get_xip_mem)
9337 + dyaop->da_op.get_xip_mem = NULL;
9341 +static struct au_dyaop *dy_aget(struct au_branch *br,
9342 + const struct address_space_operations *h_aop,
9345 + struct au_dyaop *dyaop;
9346 + struct au_dynop op;
9348 + op.dy_type = AuDy_AOP;
9349 + op.dy_haop = h_aop;
9350 + dyaop = (void *)dy_get(&op, br);
9351 + if (IS_ERR(dyaop))
9353 + dy_adx(dyaop, do_dx);
9359 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
9360 + struct inode *h_inode)
9363 + struct super_block *sb;
9364 + struct au_branch *br;
9365 + struct au_dyaop *dyaop;
9367 + AuDebugOn(!S_ISREG(h_inode->i_mode));
9368 + IiMustWriteLock(inode);
9371 + br = au_sbr(sb, bindex);
9372 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
9373 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
9374 + err = PTR_ERR(dyaop);
9375 + if (IS_ERR(dyaop))
9376 + /* unnecessary to call dy_fput() */
9380 + inode->i_mapping->a_ops = &dyaop->da_op;
9387 + * Is it safe to replace a_ops during the inode/file is in operation?
9390 +int au_dy_irefresh(struct inode *inode)
9393 + aufs_bindex_t bstart;
9394 + struct inode *h_inode;
9397 + if (S_ISREG(inode->i_mode)) {
9398 + bstart = au_ibstart(inode);
9399 + h_inode = au_h_iptr(inode, bstart);
9400 + err = au_dy_iaop(inode, bstart, h_inode);
9405 +void au_dy_arefresh(int do_dx)
9407 + struct au_splhead *spl;
9408 + struct list_head *head;
9409 + struct au_dykey *key;
9411 + spl = dynop + AuDy_AOP;
9412 + head = &spl->head;
9413 + spin_lock(&spl->spin);
9414 + list_for_each_entry(key, head, dk_list)
9415 + dy_adx((void *)key, do_dx);
9416 + spin_unlock(&spl->spin);
9419 +/* ---------------------------------------------------------------------- */
9421 +void __init au_dy_init(void)
9425 + /* make sure that 'struct au_dykey *' can be any type */
9426 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
9428 + for (i = 0; i < AuDyLast; i++)
9429 + au_spl_init(dynop + i);
9432 +void au_dy_fin(void)
9436 + for (i = 0; i < AuDyLast; i++)
9437 + WARN_ON(!list_empty(&dynop[i].head));
9439 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
9440 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
9441 +++ linux/fs/aufs/dynop.h 2014-01-20 20:16:14.736130059 +0100
9444 + * Copyright (C) 2010-2014 Junjiro R. Okajima
9446 + * This program, aufs is free software; you can redistribute it and/or modify
9447 + * it under the terms of the GNU General Public License as published by
9448 + * the Free Software Foundation; either version 2 of the License, or
9449 + * (at your option) any later version.
9451 + * This program is distributed in the hope that it will be useful,
9452 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9453 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9454 + * GNU General Public License for more details.
9456 + * You should have received a copy of the GNU General Public License
9457 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9461 + * dynamically customizable operations (for regular files only)
9464 +#ifndef __AUFS_DYNOP_H__
9465 +#define __AUFS_DYNOP_H__
9471 +enum {AuDy_AOP, AuDyLast};
9476 + const void *dy_hop;
9477 + const struct address_space_operations *dy_haop;
9483 + struct list_head dk_list;
9484 + struct rcu_head dk_rcu;
9486 + struct au_dynop dk_op;
9489 + * during I am in the branch local array, kref is gotten. when the
9490 + * branch is removed, kref is put.
9492 + struct kref dk_kref;
9495 +/* stop unioning since their sizes are very different from each other */
9497 + struct au_dykey da_key;
9498 + struct address_space_operations da_op; /* not const */
9499 + int (*da_get_xip_mem)(struct address_space *, pgoff_t, int,
9500 + void **, unsigned long *);
9503 +/* ---------------------------------------------------------------------- */
9507 +void au_dy_put(struct au_dykey *key);
9508 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
9509 + struct inode *h_inode);
9510 +int au_dy_irefresh(struct inode *inode);
9511 +void au_dy_arefresh(int do_dio);
9513 +void __init au_dy_init(void);
9514 +void au_dy_fin(void);
9516 +#endif /* __KERNEL__ */
9517 +#endif /* __AUFS_DYNOP_H__ */
9518 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
9519 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
9520 +++ linux/fs/aufs/export.c 2014-01-20 20:16:14.736130059 +0100
9523 + * Copyright (C) 2005-2014 Junjiro R. Okajima
9525 + * This program, aufs is free software; you can redistribute it and/or modify
9526 + * it under the terms of the GNU General Public License as published by
9527 + * the Free Software Foundation; either version 2 of the License, or
9528 + * (at your option) any later version.
9530 + * This program is distributed in the hope that it will be useful,
9531 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9532 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9533 + * GNU General Public License for more details.
9535 + * You should have received a copy of the GNU General Public License
9536 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9543 +#include <linux/exportfs.h>
9544 +#include <linux/fs_struct.h>
9545 +#include <linux/namei.h>
9546 +#include <linux/nsproxy.h>
9547 +#include <linux/random.h>
9548 +#include <linux/writeback.h>
9549 +#include "../fs/mount.h"
9553 +#ifdef CONFIG_AUFS_INO_T_64
9561 +static ino_t decode_ino(__u32 *a)
9565 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
9567 +#ifdef CONFIG_AUFS_INO_T_64
9573 +static void encode_ino(__u32 *a, ino_t ino)
9579 +#ifdef CONFIG_AUFS_INO_T_64
9584 +/* NFS file handle */
9588 +#ifdef CONFIG_AUFS_INO_T_64
9589 + /* support 64bit inode number */
9603 + Fh_dir_ino = Fh_dir_ino1
9606 +static int au_test_anon(struct dentry *dentry)
9608 + /* note: read d_flags without d_lock */
9609 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
9612 +int au_test_nfsd(void)
9615 + struct task_struct *tsk = current;
9616 + char comm[sizeof(tsk->comm)];
9619 + if (tsk->flags & PF_KTHREAD) {
9620 + get_task_comm(comm, tsk);
9621 + ret = !strcmp(comm, "nfsd");
9627 +/* ---------------------------------------------------------------------- */
9628 +/* inode generation external table */
9630 +void au_xigen_inc(struct inode *inode)
9635 + struct super_block *sb;
9636 + struct au_sbinfo *sbinfo;
9639 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
9641 + sbinfo = au_sbi(sb);
9642 + pos = inode->i_ino;
9643 + pos *= sizeof(igen);
9644 + igen = inode->i_generation + 1;
9645 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
9646 + sizeof(igen), &pos);
9647 + if (sz == sizeof(igen))
9648 + return; /* success */
9650 + if (unlikely(sz >= 0))
9651 + AuIOErr("xigen error (%zd)\n", sz);
9654 +int au_xigen_new(struct inode *inode)
9659 + struct super_block *sb;
9660 + struct au_sbinfo *sbinfo;
9661 + struct file *file;
9664 + /* todo: dirty, at mount time */
9665 + if (inode->i_ino == AUFS_ROOT_INO)
9668 + SiMustAnyLock(sb);
9669 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
9673 + pos = inode->i_ino;
9674 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
9675 + AuIOErr1("too large i%lld\n", pos);
9678 + pos *= sizeof(inode->i_generation);
9681 + sbinfo = au_sbi(sb);
9682 + file = sbinfo->si_xigen;
9685 + if (vfsub_f_size_read(file)
9686 + < pos + sizeof(inode->i_generation)) {
9687 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
9688 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
9689 + sizeof(inode->i_generation), &pos);
9691 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
9692 + sizeof(inode->i_generation), &pos);
9693 + if (sz == sizeof(inode->i_generation))
9694 + goto out; /* success */
9697 + if (unlikely(sz >= 0)) {
9699 + AuIOErr("xigen error (%zd)\n", sz);
9706 +int au_xigen_set(struct super_block *sb, struct file *base)
9709 + struct au_sbinfo *sbinfo;
9710 + struct file *file;
9712 + SiMustWriteLock(sb);
9714 + sbinfo = au_sbi(sb);
9715 + file = au_xino_create2(base, sbinfo->si_xigen);
9716 + err = PTR_ERR(file);
9720 + if (sbinfo->si_xigen)
9721 + fput(sbinfo->si_xigen);
9722 + sbinfo->si_xigen = file;
9728 +void au_xigen_clr(struct super_block *sb)
9730 + struct au_sbinfo *sbinfo;
9732 + SiMustWriteLock(sb);
9734 + sbinfo = au_sbi(sb);
9735 + if (sbinfo->si_xigen) {
9736 + fput(sbinfo->si_xigen);
9737 + sbinfo->si_xigen = NULL;
9741 +/* ---------------------------------------------------------------------- */
9743 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
9746 + struct dentry *dentry, *d;
9747 + struct inode *inode;
9748 + unsigned int sigen;
9751 + inode = ilookup(sb, ino);
9755 + dentry = ERR_PTR(-ESTALE);
9756 + sigen = au_sigen(sb);
9757 + if (unlikely(is_bad_inode(inode)
9758 + || IS_DEADDIR(inode)
9759 + || sigen != au_iigen(inode, NULL)))
9763 + if (!dir_ino || S_ISDIR(inode->i_mode))
9764 + dentry = d_find_alias(inode);
9766 + spin_lock(&inode->i_lock);
9767 + hlist_for_each_entry(d, &inode->i_dentry, d_alias) {
9768 + spin_lock(&d->d_lock);
9769 + if (!au_test_anon(d)
9770 + && d->d_parent->d_inode->i_ino == dir_ino) {
9771 + dentry = dget_dlock(d);
9772 + spin_unlock(&d->d_lock);
9775 + spin_unlock(&d->d_lock);
9777 + spin_unlock(&inode->i_lock);
9779 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
9780 + /* need to refresh */
9788 + AuTraceErrPtr(dentry);
9792 +/* ---------------------------------------------------------------------- */
9795 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
9797 +struct au_compare_mnt_args {
9799 + struct super_block *sb;
9802 + struct vfsmount *mnt;
9805 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
9807 + struct au_compare_mnt_args *a = arg;
9809 + if (mnt->mnt_sb != a->sb)
9811 + a->mnt = mntget(mnt);
9815 +static struct vfsmount *au_mnt_get(struct super_block *sb)
9819 + struct au_compare_mnt_args args = {
9823 + get_fs_root(current->fs, &root);
9825 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
9826 + rcu_read_unlock();
9829 + AuDebugOn(!args.mnt);
9833 +struct au_nfsd_si_lock {
9834 + unsigned int sigen;
9835 + aufs_bindex_t bindex, br_id;
9836 + unsigned char force_lock;
9839 +static int si_nfsd_read_lock(struct super_block *sb,
9840 + struct au_nfsd_si_lock *nsi_lock)
9843 + aufs_bindex_t bindex;
9845 + si_read_lock(sb, AuLock_FLUSH);
9847 + /* branch id may be wrapped around */
9849 + bindex = au_br_index(sb, nsi_lock->br_id);
9850 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
9851 + goto out; /* success */
9855 + if (!nsi_lock->force_lock)
9856 + si_read_unlock(sb);
9859 + nsi_lock->bindex = bindex;
9863 +struct find_name_by_ino {
9864 + struct dir_context ctx;
9865 + int called, found;
9872 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
9873 + loff_t offset, u64 ino, unsigned int d_type)
9875 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
9879 + if (a->ino != ino)
9882 + memcpy(a->name, name, namelen);
9883 + a->namelen = namelen;
9888 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
9889 + struct au_nfsd_si_lock *nsi_lock)
9891 + struct dentry *dentry, *parent;
9892 + struct file *file;
9893 + struct inode *dir;
9894 + struct find_name_by_ino arg = {
9896 + .actor = au_diractor(find_name_by_ino)
9901 + parent = path->dentry;
9903 + si_read_unlock(parent->d_sb);
9904 + file = vfsub_dentry_open(path, au_dir_roflags);
9905 + dentry = (void *)file;
9909 + dentry = ERR_PTR(-ENOMEM);
9910 + arg.name = (void *)__get_free_page(GFP_NOFS);
9911 + if (unlikely(!arg.name))
9918 + err = vfsub_iterate_dir(file, &arg.ctx);
9919 + } while (!err && !arg.found && arg.called);
9920 + dentry = ERR_PTR(err);
9921 + if (unlikely(err))
9923 + /* instead of ENOENT */
9924 + dentry = ERR_PTR(-ESTALE);
9928 + /* do not call vfsub_lkup_one() */
9929 + dir = parent->d_inode;
9930 + mutex_lock(&dir->i_mutex);
9931 + dentry = vfsub_lookup_one_len(arg.name, parent, arg.namelen);
9932 + mutex_unlock(&dir->i_mutex);
9933 + AuTraceErrPtr(dentry);
9934 + if (IS_ERR(dentry))
9936 + AuDebugOn(au_test_anon(dentry));
9937 + if (unlikely(!dentry->d_inode)) {
9939 + dentry = ERR_PTR(-ENOENT);
9943 + free_page((unsigned long)arg.name);
9947 + if (unlikely(nsi_lock
9948 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
9949 + if (!IS_ERR(dentry)) {
9951 + dentry = ERR_PTR(-ESTALE);
9953 + AuTraceErrPtr(dentry);
9957 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
9959 + struct au_nfsd_si_lock *nsi_lock)
9961 + struct dentry *dentry;
9964 + if (dir_ino != AUFS_ROOT_INO) {
9965 + path.dentry = decode_by_ino(sb, dir_ino, 0);
9966 + dentry = path.dentry;
9967 + if (!path.dentry || IS_ERR(path.dentry))
9969 + AuDebugOn(au_test_anon(path.dentry));
9971 + path.dentry = dget(sb->s_root);
9973 + path.mnt = au_mnt_get(sb);
9974 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
9978 + AuTraceErrPtr(dentry);
9982 +/* ---------------------------------------------------------------------- */
9984 +static int h_acceptable(void *expv, struct dentry *dentry)
9989 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
9990 + char *buf, int len, struct super_block *sb)
9996 + p = d_path(h_rootpath, buf, len);
10001 + path.mnt = h_rootpath->mnt;
10002 + path.dentry = h_parent;
10003 + p = d_path(&path, buf, len);
10009 + path.mnt = au_mnt_get(sb);
10010 + path.dentry = sb->s_root;
10011 + p = d_path(&path, buf, len - strlen(p));
10012 + mntput(path.mnt);
10016 + p[strlen(p)] = '/';
10019 + AuTraceErrPtr(p);
10024 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
10025 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
10027 + struct dentry *dentry, *h_parent, *root;
10028 + struct super_block *h_sb;
10029 + char *pathname, *p;
10030 + struct vfsmount *h_mnt;
10031 + struct au_branch *br;
10033 + struct path path;
10035 + br = au_sbr(sb, nsi_lock->bindex);
10036 + h_mnt = au_br_mnt(br);
10037 + h_sb = h_mnt->mnt_sb;
10038 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
10039 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
10040 + fh_len - Fh_tail, fh[Fh_h_type],
10041 + h_acceptable, /*context*/NULL);
10042 + dentry = h_parent;
10043 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
10044 + AuWarn1("%s decode_fh failed, %ld\n",
10045 + au_sbtype(h_sb), PTR_ERR(h_parent));
10049 + if (unlikely(au_test_anon(h_parent))) {
10050 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
10051 + au_sbtype(h_sb));
10052 + goto out_h_parent;
10055 + dentry = ERR_PTR(-ENOMEM);
10056 + pathname = (void *)__get_free_page(GFP_NOFS);
10057 + if (unlikely(!pathname))
10058 + goto out_h_parent;
10060 + root = sb->s_root;
10061 + path.mnt = h_mnt;
10062 + di_read_lock_parent(root, !AuLock_IR);
10063 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
10064 + di_read_unlock(root, !AuLock_IR);
10065 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
10066 + dentry = (void *)p;
10068 + goto out_pathname;
10070 + si_read_unlock(sb);
10071 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
10072 + dentry = ERR_PTR(err);
10073 + if (unlikely(err))
10076 + dentry = ERR_PTR(-ENOENT);
10077 + AuDebugOn(au_test_anon(path.dentry));
10078 + if (unlikely(!path.dentry->d_inode))
10081 + if (ino != path.dentry->d_inode->i_ino)
10082 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
10084 + dentry = dget(path.dentry);
10089 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
10090 + if (!IS_ERR(dentry)) {
10092 + dentry = ERR_PTR(-ESTALE);
10095 + free_page((unsigned long)pathname);
10099 + AuTraceErrPtr(dentry);
10103 +/* ---------------------------------------------------------------------- */
10105 +static struct dentry *
10106 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
10109 + struct dentry *dentry;
10110 + __u32 *fh = fid->raw;
10111 + struct au_branch *br;
10112 + ino_t ino, dir_ino;
10113 + struct au_nfsd_si_lock nsi_lock = {
10117 + dentry = ERR_PTR(-ESTALE);
10118 + /* it should never happen, but the file handle is unreliable */
10119 + if (unlikely(fh_len < Fh_tail))
10121 + nsi_lock.sigen = fh[Fh_sigen];
10122 + nsi_lock.br_id = fh[Fh_br_id];
10124 + /* branch id may be wrapped around */
10126 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
10128 + nsi_lock.force_lock = 1;
10130 + /* is this inode still cached? */
10131 + ino = decode_ino(fh + Fh_ino);
10132 + /* it should never happen */
10133 + if (unlikely(ino == AUFS_ROOT_INO))
10136 + dir_ino = decode_ino(fh + Fh_dir_ino);
10137 + dentry = decode_by_ino(sb, ino, dir_ino);
10138 + if (IS_ERR(dentry))
10143 + /* is the parent dir cached? */
10144 + br = au_sbr(sb, nsi_lock.bindex);
10145 + atomic_inc(&br->br_count);
10146 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
10147 + if (IS_ERR(dentry))
10152 + /* lookup path */
10153 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
10154 + if (IS_ERR(dentry))
10156 + if (unlikely(!dentry))
10157 + /* todo?: make it ESTALE */
10161 + if (!au_digen_test(dentry, au_sigen(sb))
10162 + && dentry->d_inode->i_generation == fh[Fh_igen])
10163 + goto out_unlock; /* success */
10166 + dentry = ERR_PTR(-ESTALE);
10169 + atomic_dec(&br->br_count);
10170 + si_read_unlock(sb);
10172 + AuTraceErrPtr(dentry);
10176 +#if 0 /* reserved for future use */
10177 +/* support subtreecheck option */
10178 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
10179 + int fh_len, int fh_type)
10181 + struct dentry *parent;
10182 + __u32 *fh = fid->raw;
10185 + dir_ino = decode_ino(fh + Fh_dir_ino);
10186 + parent = decode_by_ino(sb, dir_ino, 0);
10187 + if (IS_ERR(parent))
10190 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
10191 + dir_ino, fh, fh_len);
10194 + AuTraceErrPtr(parent);
10199 +/* ---------------------------------------------------------------------- */
10201 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
10202 + struct inode *dir)
10205 + aufs_bindex_t bindex;
10206 + struct super_block *sb, *h_sb;
10207 + struct dentry *dentry, *parent, *h_parent;
10208 + struct inode *h_dir;
10209 + struct au_branch *br;
10212 + if (unlikely(*max_len <= Fh_tail)) {
10213 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
10217 + err = FILEID_ROOT;
10218 + if (inode->i_ino == AUFS_ROOT_INO) {
10219 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
10224 + sb = inode->i_sb;
10225 + err = si_read_lock(sb, AuLock_FLUSH);
10226 + if (unlikely(err))
10229 +#ifdef CONFIG_AUFS_DEBUG
10230 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
10231 + AuWarn1("NFS-exporting requires xino\n");
10235 + ii_read_lock_child(inode);
10236 + bindex = au_ibstart(inode);
10238 + dentry = d_find_alias(inode);
10239 + if (unlikely(!dentry))
10241 + AuDebugOn(au_test_anon(dentry));
10242 + parent = dget_parent(dentry);
10244 + if (unlikely(!parent))
10246 + dir = parent->d_inode;
10249 + ii_read_lock_parent(dir);
10250 + h_dir = au_h_iptr(dir, bindex);
10251 + ii_read_unlock(dir);
10252 + if (unlikely(!h_dir))
10254 + h_parent = d_find_alias(h_dir);
10255 + if (unlikely(!h_parent))
10256 + goto out_hparent;
10259 + br = au_sbr(sb, bindex);
10260 + h_sb = au_br_sb(br);
10261 + if (unlikely(!h_sb->s_export_op)) {
10262 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
10263 + goto out_hparent;
10266 + fh[Fh_br_id] = br->br_id;
10267 + fh[Fh_sigen] = au_sigen(sb);
10268 + encode_ino(fh + Fh_ino, inode->i_ino);
10269 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
10270 + fh[Fh_igen] = inode->i_generation;
10272 + *max_len -= Fh_tail;
10273 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
10275 + /*connectable or subtreecheck*/0);
10276 + err = fh[Fh_h_type];
10277 + *max_len += Fh_tail;
10278 + /* todo: macros? */
10279 + if (err != FILEID_INVALID)
10282 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
10289 + ii_read_unlock(inode);
10290 + si_read_unlock(sb);
10292 + if (unlikely(err < 0))
10293 + err = FILEID_INVALID;
10297 +/* ---------------------------------------------------------------------- */
10299 +static int aufs_commit_metadata(struct inode *inode)
10302 + aufs_bindex_t bindex;
10303 + struct super_block *sb;
10304 + struct inode *h_inode;
10305 + int (*f)(struct inode *inode);
10307 + sb = inode->i_sb;
10308 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
10309 + ii_write_lock_child(inode);
10310 + bindex = au_ibstart(inode);
10311 + AuDebugOn(bindex < 0);
10312 + h_inode = au_h_iptr(inode, bindex);
10314 + f = h_inode->i_sb->s_export_op->commit_metadata;
10316 + err = f(h_inode);
10318 + struct writeback_control wbc = {
10319 + .sync_mode = WB_SYNC_ALL,
10320 + .nr_to_write = 0 /* metadata only */
10323 + err = sync_inode(h_inode, &wbc);
10326 + au_cpup_attr_timesizes(inode);
10327 + ii_write_unlock(inode);
10328 + si_read_unlock(sb);
10332 +/* ---------------------------------------------------------------------- */
10334 +static struct export_operations aufs_export_op = {
10335 + .fh_to_dentry = aufs_fh_to_dentry,
10336 + /* .fh_to_parent = aufs_fh_to_parent, */
10337 + .encode_fh = aufs_encode_fh,
10338 + .commit_metadata = aufs_commit_metadata
10341 +void au_export_init(struct super_block *sb)
10343 + struct au_sbinfo *sbinfo;
10346 + sb->s_export_op = &aufs_export_op;
10347 + sbinfo = au_sbi(sb);
10348 + sbinfo->si_xigen = NULL;
10349 + get_random_bytes(&u, sizeof(u));
10350 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
10351 + atomic_set(&sbinfo->si_xigen_next, u);
10353 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
10354 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
10355 +++ linux/fs/aufs/file.c 2014-01-20 20:16:14.736130059 +0100
10358 + * Copyright (C) 2005-2014 Junjiro R. Okajima
10360 + * This program, aufs is free software; you can redistribute it and/or modify
10361 + * it under the terms of the GNU General Public License as published by
10362 + * the Free Software Foundation; either version 2 of the License, or
10363 + * (at your option) any later version.
10365 + * This program is distributed in the hope that it will be useful,
10366 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10367 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10368 + * GNU General Public License for more details.
10370 + * You should have received a copy of the GNU General Public License
10371 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10375 + * handling file/dir, and address_space operation
10378 +#ifdef CONFIG_AUFS_DEBUG
10379 +#include <linux/migrate.h>
10381 +#include <linux/pagemap.h>
10384 +/* drop flags for writing */
10385 +unsigned int au_file_roflags(unsigned int flags)
10387 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
10388 + flags |= O_RDONLY | O_NOATIME;
10392 +/* common functions to regular file and dir */
10393 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
10394 + struct file *file, int force_wr)
10396 + struct file *h_file;
10397 + struct dentry *h_dentry;
10398 + struct inode *h_inode;
10399 + struct super_block *sb;
10400 + struct au_branch *br;
10401 + struct path h_path;
10402 + int err, exec_flag;
10404 + /* a race condition can happen between open and unlink/rmdir */
10405 + h_file = ERR_PTR(-ENOENT);
10406 + h_dentry = au_h_dptr(dentry, bindex);
10407 + if (au_test_nfsd() && !h_dentry)
10409 + h_inode = h_dentry->d_inode;
10410 + if (au_test_nfsd() && !h_inode)
10412 + spin_lock(&h_dentry->d_lock);
10413 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
10415 + /* || !dentry->d_inode->i_nlink */
10417 + spin_unlock(&h_dentry->d_lock);
10418 + if (unlikely(err))
10421 + sb = dentry->d_sb;
10422 + br = au_sbr(sb, bindex);
10423 + h_file = ERR_PTR(-EACCES);
10424 + exec_flag = flags & __FMODE_EXEC;
10425 + if (exec_flag && (au_br_mnt(br)->mnt_flags & MNT_NOEXEC))
10428 + /* drop flags for writing */
10429 + if (au_test_ro(sb, bindex, dentry->d_inode)) {
10430 + if (force_wr && !(flags & O_WRONLY))
10432 + flags = au_file_roflags(flags);
10434 + h_file = ERR_PTR(-EROFS);
10435 + flags = au_file_roflags(flags);
10436 + if (unlikely(vfsub_native_ro(h_inode)
10437 + || IS_APPEND(h_inode)))
10439 + flags &= ~O_ACCMODE;
10440 + flags |= O_WRONLY;
10443 + flags &= ~O_CREAT;
10444 + atomic_inc(&br->br_count);
10445 + h_path.dentry = h_dentry;
10446 + h_path.mnt = au_br_mnt(br);
10447 + if (!au_special_file(h_inode->i_mode))
10448 + h_file = vfsub_dentry_open(&h_path, flags);
10450 + /* this block depends upon the configuration */
10451 + di_read_unlock(dentry, AuLock_IR);
10452 + fi_write_unlock(file);
10453 + si_read_unlock(sb);
10454 + h_file = vfsub_dentry_open(&h_path, flags);
10455 + si_noflush_read_lock(sb);
10456 + fi_write_lock(file);
10457 + di_read_lock_child(dentry, AuLock_IR);
10459 + if (IS_ERR(h_file))
10463 + err = deny_write_access(h_file);
10464 + if (unlikely(err)) {
10466 + h_file = ERR_PTR(err);
10470 + fsnotify_open(h_file);
10471 + goto out; /* success */
10474 + atomic_dec(&br->br_count);
10479 +int au_do_open(struct file *file, int (*open)(struct file *file, int flags),
10480 + struct au_fidir *fidir)
10483 + struct dentry *dentry;
10485 + err = au_finfo_init(file, fidir);
10486 + if (unlikely(err))
10489 + dentry = file->f_dentry;
10490 + di_read_lock_child(dentry, AuLock_IR);
10491 + err = open(file, vfsub_file_flags(file));
10492 + di_read_unlock(dentry, AuLock_IR);
10494 + fi_write_unlock(file);
10495 + if (unlikely(err)) {
10496 + au_fi(file)->fi_hdir = NULL;
10497 + au_finfo_fin(file);
10504 +int au_reopen_nondir(struct file *file)
10507 + aufs_bindex_t bstart;
10508 + struct dentry *dentry;
10509 + struct file *h_file, *h_file_tmp;
10511 + dentry = file->f_dentry;
10512 + AuDebugOn(au_special_file(dentry->d_inode->i_mode));
10513 + bstart = au_dbstart(dentry);
10514 + h_file_tmp = NULL;
10515 + if (au_fbstart(file) == bstart) {
10516 + h_file = au_hf_top(file);
10517 + if (file->f_mode == h_file->f_mode)
10518 + return 0; /* success */
10519 + h_file_tmp = h_file;
10520 + get_file(h_file_tmp);
10521 + au_set_h_fptr(file, bstart, NULL);
10523 + AuDebugOn(au_fi(file)->fi_hdir);
10526 + * file exists on both of rw and ro
10527 + * open --> dbstart and fbstart are both 0
10528 + * prepend a branch as rw, "rw" become ro
10530 + * delete the top branch, "rw" becomes rw again
10531 + * --> dbstart is 1, fbstart is still 0
10532 + * write --> fbstart is 0 but dbstart is 1
10534 + /* AuDebugOn(au_fbstart(file) < bstart); */
10536 + h_file = au_h_open(dentry, bstart, vfsub_file_flags(file) & ~O_TRUNC,
10537 + file, /*force_wr*/0);
10538 + err = PTR_ERR(h_file);
10539 + if (IS_ERR(h_file)) {
10540 + if (h_file_tmp) {
10541 + atomic_inc(&au_sbr(dentry->d_sb, bstart)->br_count);
10542 + au_set_h_fptr(file, bstart, h_file_tmp);
10543 + h_file_tmp = NULL;
10545 + goto out; /* todo: close all? */
10549 + au_set_fbstart(file, bstart);
10550 + au_set_h_fptr(file, bstart, h_file);
10551 + au_update_figen(file);
10552 + /* todo: necessary? */
10553 + /* file->f_ra = h_file->f_ra; */
10557 + fput(h_file_tmp);
10561 +/* ---------------------------------------------------------------------- */
10563 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
10564 + struct dentry *hi_wh)
10567 + aufs_bindex_t bstart;
10568 + struct au_dinfo *dinfo;
10569 + struct dentry *h_dentry;
10570 + struct au_hdentry *hdp;
10572 + dinfo = au_di(file->f_dentry);
10573 + AuRwMustWriteLock(&dinfo->di_rwsem);
10575 + bstart = dinfo->di_bstart;
10576 + dinfo->di_bstart = btgt;
10577 + hdp = dinfo->di_hdentry;
10578 + h_dentry = hdp[0 + btgt].hd_dentry;
10579 + hdp[0 + btgt].hd_dentry = hi_wh;
10580 + err = au_reopen_nondir(file);
10581 + hdp[0 + btgt].hd_dentry = h_dentry;
10582 + dinfo->di_bstart = bstart;
10587 +static int au_ready_to_write_wh(struct file *file, loff_t len,
10588 + aufs_bindex_t bcpup, struct au_pin *pin)
10591 + struct inode *inode, *h_inode;
10592 + struct dentry *h_dentry, *hi_wh;
10593 + struct au_cp_generic cpg = {
10594 + .dentry = file->f_dentry,
10601 + au_update_dbstart(cpg.dentry);
10602 + inode = cpg.dentry->d_inode;
10604 + if (au_dbstart(cpg.dentry) <= bcpup
10605 + && au_dbend(cpg.dentry) >= bcpup) {
10606 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
10608 + h_inode = h_dentry->d_inode;
10610 + hi_wh = au_hi_wh(inode, bcpup);
10611 + if (!hi_wh && !h_inode)
10612 + err = au_sio_cpup_wh(&cpg, file);
10614 + /* already copied-up after unlink */
10615 + err = au_reopen_wh(file, bcpup, hi_wh);
10618 + && inode->i_nlink > 1
10619 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
10620 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
10626 + * prepare the @file for writing.
10628 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
10631 + aufs_bindex_t dbstart;
10632 + struct dentry *parent, *h_dentry;
10633 + struct inode *inode;
10634 + struct super_block *sb;
10635 + struct file *h_file;
10636 + struct au_cp_generic cpg = {
10637 + .dentry = file->f_dentry,
10642 + .flags = AuCpup_DTIME
10645 + sb = cpg.dentry->d_sb;
10646 + inode = cpg.dentry->d_inode;
10647 + AuDebugOn(au_special_file(inode->i_mode));
10648 + cpg.bsrc = au_fbstart(file);
10649 + err = au_test_ro(sb, cpg.bsrc, inode);
10650 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
10651 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
10656 + /* need to cpup or reopen */
10657 + parent = dget_parent(cpg.dentry);
10658 + di_write_lock_parent(parent);
10659 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
10661 + if (unlikely(err < 0))
10665 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
10666 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
10667 + if (unlikely(err))
10671 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
10672 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
10673 + if (unlikely(err))
10676 + h_dentry = au_hf_top(file)->f_dentry;
10677 + dbstart = au_dbstart(cpg.dentry);
10678 + if (dbstart <= cpg.bdst) {
10679 + h_dentry = au_h_dptr(cpg.dentry, cpg.bdst);
10680 + AuDebugOn(!h_dentry);
10681 + cpg.bsrc = cpg.bdst;
10684 + if (dbstart <= cpg.bdst /* just reopen */
10685 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
10687 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
10688 + if (IS_ERR(h_file))
10689 + err = PTR_ERR(h_file);
10691 + di_downgrade_lock(parent, AuLock_IR);
10692 + if (dbstart > cpg.bdst)
10693 + err = au_sio_cpup_simple(&cpg);
10695 + err = au_reopen_nondir(file);
10696 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
10698 + } else { /* copyup as wh and reopen */
10700 + * since writable hfsplus branch is not supported,
10701 + * h_open_pre/post() are unnecessary.
10703 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
10704 + di_downgrade_lock(parent, AuLock_IR);
10708 + au_pin_set_parent_lflag(pin, /*lflag*/0);
10709 + goto out_dput; /* success */
10715 + di_downgrade_lock(parent, AuLock_IR);
10717 + di_read_unlock(parent, AuLock_IR);
10724 +/* ---------------------------------------------------------------------- */
10726 +int au_do_flush(struct file *file, fl_owner_t id,
10727 + int (*flush)(struct file *file, fl_owner_t id))
10730 + struct super_block *sb;
10731 + struct inode *inode;
10733 + inode = file_inode(file);
10734 + sb = inode->i_sb;
10735 + si_noflush_read_lock(sb);
10736 + fi_read_lock(file);
10737 + ii_read_lock_child(inode);
10739 + err = flush(file, id);
10740 + au_cpup_attr_timesizes(inode);
10742 + ii_read_unlock(inode);
10743 + fi_read_unlock(file);
10744 + si_read_unlock(sb);
10748 +/* ---------------------------------------------------------------------- */
10750 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
10753 + struct au_pin pin;
10754 + struct au_finfo *finfo;
10755 + struct dentry *parent, *hi_wh;
10756 + struct inode *inode;
10757 + struct super_block *sb;
10758 + struct au_cp_generic cpg = {
10759 + .dentry = file->f_dentry,
10764 + .flags = AuCpup_DTIME
10767 + FiMustWriteLock(file);
10770 + finfo = au_fi(file);
10771 + sb = cpg.dentry->d_sb;
10772 + inode = cpg.dentry->d_inode;
10773 + cpg.bdst = au_ibstart(inode);
10774 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
10777 + parent = dget_parent(cpg.dentry);
10778 + if (au_test_ro(sb, cpg.bdst, inode)) {
10779 + di_read_lock_parent(parent, !AuLock_IR);
10780 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
10782 + di_read_unlock(parent, !AuLock_IR);
10783 + if (unlikely(err < 0))
10788 + di_read_lock_parent(parent, AuLock_IR);
10789 + hi_wh = au_hi_wh(inode, cpg.bdst);
10790 + if (!S_ISDIR(inode->i_mode)
10791 + && au_opt_test(au_mntflags(sb), PLINK)
10792 + && au_plink_test(inode)
10793 + && !d_unhashed(cpg.dentry)
10794 + && cpg.bdst < au_dbstart(cpg.dentry)) {
10795 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
10796 + if (unlikely(err))
10799 + /* always superio. */
10800 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
10801 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
10803 + err = au_sio_cpup_simple(&cpg);
10806 + } else if (hi_wh) {
10807 + /* already copied-up after unlink */
10808 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
10809 + *need_reopen = 0;
10813 + di_read_unlock(parent, AuLock_IR);
10820 +static void au_do_refresh_dir(struct file *file)
10822 + aufs_bindex_t bindex, bend, new_bindex, brid;
10823 + struct au_hfile *p, tmp, *q;
10824 + struct au_finfo *finfo;
10825 + struct super_block *sb;
10826 + struct au_fidir *fidir;
10828 + FiMustWriteLock(file);
10830 + sb = file->f_dentry->d_sb;
10831 + finfo = au_fi(file);
10832 + fidir = finfo->fi_hdir;
10833 + AuDebugOn(!fidir);
10834 + p = fidir->fd_hfile + finfo->fi_btop;
10835 + brid = p->hf_br->br_id;
10836 + bend = fidir->fd_bbot;
10837 + for (bindex = finfo->fi_btop; bindex <= bend; bindex++, p++) {
10841 + new_bindex = au_br_index(sb, p->hf_br->br_id);
10842 + if (new_bindex == bindex)
10844 + if (new_bindex < 0) {
10845 + au_set_h_fptr(file, bindex, NULL);
10849 + /* swap two lower inode, and loop again */
10850 + q = fidir->fd_hfile + new_bindex;
10854 + if (tmp.hf_file) {
10860 + p = fidir->fd_hfile;
10861 + if (!au_test_mmapped(file) && !d_unlinked(file->f_dentry)) {
10862 + bend = au_sbend(sb);
10863 + for (finfo->fi_btop = 0; finfo->fi_btop <= bend;
10864 + finfo->fi_btop++, p++)
10865 + if (p->hf_file) {
10866 + if (file_inode(p->hf_file))
10869 + au_hfput(p, file);
10872 + bend = au_br_index(sb, brid);
10873 + for (finfo->fi_btop = 0; finfo->fi_btop < bend;
10874 + finfo->fi_btop++, p++)
10876 + au_hfput(p, file);
10877 + bend = au_sbend(sb);
10880 + p = fidir->fd_hfile + bend;
10881 + for (fidir->fd_bbot = bend; fidir->fd_bbot >= finfo->fi_btop;
10882 + fidir->fd_bbot--, p--)
10883 + if (p->hf_file) {
10884 + if (file_inode(p->hf_file))
10887 + au_hfput(p, file);
10889 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
10893 + * after branch manipulating, refresh the file.
10895 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
10897 + int err, need_reopen;
10898 + aufs_bindex_t bend, bindex;
10899 + struct dentry *dentry;
10900 + struct au_finfo *finfo;
10901 + struct au_hfile *hfile;
10903 + dentry = file->f_dentry;
10904 + finfo = au_fi(file);
10905 + if (!finfo->fi_hdir) {
10906 + hfile = &finfo->fi_htop;
10907 + AuDebugOn(!hfile->hf_file);
10908 + bindex = au_br_index(dentry->d_sb, hfile->hf_br->br_id);
10909 + AuDebugOn(bindex < 0);
10910 + if (bindex != finfo->fi_btop)
10911 + au_set_fbstart(file, bindex);
10913 + err = au_fidir_realloc(finfo, au_sbend(dentry->d_sb) + 1);
10914 + if (unlikely(err))
10916 + au_do_refresh_dir(file);
10921 + if (!au_test_mmapped(file))
10922 + err = au_file_refresh_by_inode(file, &need_reopen);
10923 + if (!err && need_reopen && !d_unlinked(dentry))
10924 + err = reopen(file);
10926 + au_update_figen(file);
10927 + goto out; /* success */
10930 + /* error, close all lower files */
10931 + if (finfo->fi_hdir) {
10932 + bend = au_fbend_dir(file);
10933 + for (bindex = au_fbstart(file); bindex <= bend; bindex++)
10934 + au_set_h_fptr(file, bindex, NULL);
10941 +/* common function to regular file and dir */
10942 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
10946 + unsigned int sigen, figen;
10947 + aufs_bindex_t bstart;
10948 + unsigned char pseudo_link;
10949 + struct dentry *dentry;
10950 + struct inode *inode;
10953 + dentry = file->f_dentry;
10954 + inode = dentry->d_inode;
10955 + AuDebugOn(au_special_file(inode->i_mode));
10956 + sigen = au_sigen(dentry->d_sb);
10957 + fi_write_lock(file);
10958 + figen = au_figen(file);
10959 + di_write_lock_child(dentry);
10960 + bstart = au_dbstart(dentry);
10961 + pseudo_link = (bstart != au_ibstart(inode));
10962 + if (sigen == figen && !pseudo_link && au_fbstart(file) == bstart) {
10964 + di_downgrade_lock(dentry, AuLock_IR);
10965 + fi_downgrade_lock(file);
10967 + goto out; /* success */
10970 + AuDbg("sigen %d, figen %d\n", sigen, figen);
10971 + if (au_digen_test(dentry, sigen)) {
10972 + err = au_reval_dpath(dentry, sigen);
10973 + AuDebugOn(!err && au_digen_test(dentry, sigen));
10977 + err = refresh_file(file, reopen);
10980 + di_downgrade_lock(dentry, AuLock_IR);
10981 + fi_downgrade_lock(file);
10984 + di_write_unlock(dentry);
10985 + fi_write_unlock(file);
10992 +/* ---------------------------------------------------------------------- */
10994 +/* cf. aufs_nopage() */
10995 +/* for madvise(2) */
10996 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
10998 + unlock_page(page);
11002 +/* it will never be called, but necessary to support O_DIRECT */
11003 +static ssize_t aufs_direct_IO(int rw, struct kiocb *iocb,
11004 + const struct iovec *iov, loff_t offset,
11005 + unsigned long nr_segs)
11006 +{ BUG(); return 0; }
11009 + * it will never be called, but madvise and fadvise behaves differently
11010 + * when get_xip_mem is defined
11012 +static int aufs_get_xip_mem(struct address_space *mapping, pgoff_t pgoff,
11013 + int create, void **kmem, unsigned long *pfn)
11014 +{ BUG(); return 0; }
11016 +/* they will never be called. */
11017 +#ifdef CONFIG_AUFS_DEBUG
11018 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
11019 + loff_t pos, unsigned len, unsigned flags,
11020 + struct page **pagep, void **fsdata)
11021 +{ AuUnsupport(); return 0; }
11022 +static int aufs_write_end(struct file *file, struct address_space *mapping,
11023 + loff_t pos, unsigned len, unsigned copied,
11024 + struct page *page, void *fsdata)
11025 +{ AuUnsupport(); return 0; }
11026 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
11027 +{ AuUnsupport(); return 0; }
11029 +static int aufs_set_page_dirty(struct page *page)
11030 +{ AuUnsupport(); return 0; }
11031 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
11032 + unsigned int length)
11033 +{ AuUnsupport(); }
11034 +static int aufs_releasepage(struct page *page, gfp_t gfp)
11035 +{ AuUnsupport(); return 0; }
11036 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
11037 + struct page *page, enum migrate_mode mode)
11038 +{ AuUnsupport(); return 0; }
11039 +static int aufs_launder_page(struct page *page)
11040 +{ AuUnsupport(); return 0; }
11041 +static int aufs_is_partially_uptodate(struct page *page,
11042 + read_descriptor_t *desc,
11043 + unsigned long from)
11044 +{ AuUnsupport(); return 0; }
11045 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
11047 +{ AuUnsupport(); }
11048 +static int aufs_error_remove_page(struct address_space *mapping,
11049 + struct page *page)
11050 +{ AuUnsupport(); return 0; }
11051 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
11053 +{ AuUnsupport(); return 0; }
11054 +static void aufs_swap_deactivate(struct file *file)
11055 +{ AuUnsupport(); }
11056 +#endif /* CONFIG_AUFS_DEBUG */
11058 +const struct address_space_operations aufs_aop = {
11059 + .readpage = aufs_readpage,
11060 + .direct_IO = aufs_direct_IO,
11061 + .get_xip_mem = aufs_get_xip_mem,
11062 +#ifdef CONFIG_AUFS_DEBUG
11063 + .writepage = aufs_writepage,
11064 + /* no writepages, because of writepage */
11065 + .set_page_dirty = aufs_set_page_dirty,
11066 + /* no readpages, because of readpage */
11067 + .write_begin = aufs_write_begin,
11068 + .write_end = aufs_write_end,
11069 + /* no bmap, no block device */
11070 + .invalidatepage = aufs_invalidatepage,
11071 + .releasepage = aufs_releasepage,
11072 + .migratepage = aufs_migratepage,
11073 + .launder_page = aufs_launder_page,
11074 + .is_partially_uptodate = aufs_is_partially_uptodate,
11075 + .is_dirty_writeback = aufs_is_dirty_writeback,
11076 + .error_remove_page = aufs_error_remove_page,
11077 + .swap_activate = aufs_swap_activate,
11078 + .swap_deactivate = aufs_swap_deactivate
11079 +#endif /* CONFIG_AUFS_DEBUG */
11081 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
11082 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
11083 +++ linux/fs/aufs/file.h 2014-01-20 20:16:14.736130059 +0100
11086 + * Copyright (C) 2005-2014 Junjiro R. Okajima
11088 + * This program, aufs is free software; you can redistribute it and/or modify
11089 + * it under the terms of the GNU General Public License as published by
11090 + * the Free Software Foundation; either version 2 of the License, or
11091 + * (at your option) any later version.
11093 + * This program is distributed in the hope that it will be useful,
11094 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11095 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11096 + * GNU General Public License for more details.
11098 + * You should have received a copy of the GNU General Public License
11099 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11103 + * file operations
11106 +#ifndef __AUFS_FILE_H__
11107 +#define __AUFS_FILE_H__
11111 +#include <linux/file.h>
11112 +#include <linux/fs.h>
11113 +#include <linux/poll.h>
11114 +#include "rwsem.h"
11118 + struct file *hf_file;
11119 + struct au_branch *hf_br;
11124 + aufs_bindex_t fd_bbot;
11125 + aufs_bindex_t fd_nent;
11126 + struct au_vdir *fd_vdir_cache;
11127 + struct au_hfile fd_hfile[];
11130 +static inline int au_fidir_sz(int nent)
11132 + AuDebugOn(nent < 0);
11133 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
11137 + atomic_t fi_generation;
11139 + struct au_rwsem fi_rwsem;
11140 + aufs_bindex_t fi_btop;
11142 + /* do not union them */
11143 + struct { /* for non-dir */
11144 + struct au_hfile fi_htop;
11145 + atomic_t fi_mmapped;
11147 + struct au_fidir *fi_hdir; /* for dir only */
11149 + struct hlist_node fi_hlist;
11150 + struct file *fi_file; /* very ugly */
11151 +} ____cacheline_aligned_in_smp;
11153 +/* ---------------------------------------------------------------------- */
11156 +extern const struct address_space_operations aufs_aop;
11157 +unsigned int au_file_roflags(unsigned int flags);
11158 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
11159 + struct file *file, int force_wr);
11160 +int au_do_open(struct file *file, int (*open)(struct file *file, int flags),
11161 + struct au_fidir *fidir);
11162 +int au_reopen_nondir(struct file *file);
11164 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
11165 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
11167 +int au_do_flush(struct file *file, fl_owner_t id,
11168 + int (*flush)(struct file *file, fl_owner_t id));
11171 +#ifdef CONFIG_AUFS_POLL
11172 +unsigned int aufs_poll(struct file *file, poll_table *wait);
11175 +#ifdef CONFIG_AUFS_BR_HFSPLUS
11177 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
11179 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
11180 + struct file *h_file);
11183 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
11189 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
11190 + struct file *h_file);
11194 +extern const struct file_operations aufs_file_fop;
11195 +int au_do_open_nondir(struct file *file, int flags);
11196 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
11198 +#ifdef CONFIG_AUFS_SP_IATTR
11200 +struct au_finfo *au_fi_sp(struct file *file);
11201 +int au_special_file(umode_t mode);
11202 +void au_init_special_fop(struct inode *inode, umode_t mode, dev_t rdev);
11204 +static inline struct au_finfo *au_fi_sp(struct file *file)
11208 +AuStubInt0(au_special_file, umode_t mode)
11209 +static inline void au_init_special_fop(struct inode *inode, umode_t mode,
11212 + init_special_inode(inode, mode, rdev);
11217 +void au_hfput(struct au_hfile *hf, struct file *file);
11218 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
11219 + struct file *h_file);
11221 +void au_update_figen(struct file *file);
11222 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
11223 +int au_fidir_realloc(struct au_finfo *finfo, int nbr);
11225 +void au_fi_init_once(void *_fi);
11226 +void au_finfo_fin(struct file *file);
11227 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
11230 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
11231 +#ifdef CONFIG_COMPAT
11232 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
11233 + unsigned long arg);
11234 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
11235 + unsigned long arg);
11238 +/* ---------------------------------------------------------------------- */
11240 +static inline struct au_finfo *au_fi(struct file *file)
11242 + struct au_finfo *finfo;
11244 + finfo = au_fi_sp(file);
11246 + finfo = file->private_data;
11250 +/* ---------------------------------------------------------------------- */
11253 + * fi_read_lock, fi_write_lock,
11254 + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock
11256 +AuSimpleRwsemFuncs(fi, struct file *f, &au_fi(f)->fi_rwsem);
11258 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
11259 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
11260 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
11262 +/* ---------------------------------------------------------------------- */
11264 +/* todo: hard/soft set? */
11265 +static inline aufs_bindex_t au_fbstart(struct file *file)
11267 + FiMustAnyLock(file);
11268 + return au_fi(file)->fi_btop;
11271 +static inline aufs_bindex_t au_fbend_dir(struct file *file)
11273 + FiMustAnyLock(file);
11274 + AuDebugOn(!au_fi(file)->fi_hdir);
11275 + return au_fi(file)->fi_hdir->fd_bbot;
11278 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
11280 + FiMustAnyLock(file);
11281 + AuDebugOn(!au_fi(file)->fi_hdir);
11282 + return au_fi(file)->fi_hdir->fd_vdir_cache;
11285 +static inline void au_set_fbstart(struct file *file, aufs_bindex_t bindex)
11287 + FiMustWriteLock(file);
11288 + au_fi(file)->fi_btop = bindex;
11291 +static inline void au_set_fbend_dir(struct file *file, aufs_bindex_t bindex)
11293 + FiMustWriteLock(file);
11294 + AuDebugOn(!au_fi(file)->fi_hdir);
11295 + au_fi(file)->fi_hdir->fd_bbot = bindex;
11298 +static inline void au_set_fvdir_cache(struct file *file,
11299 + struct au_vdir *vdir_cache)
11301 + FiMustWriteLock(file);
11302 + AuDebugOn(!au_fi(file)->fi_hdir);
11303 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
11306 +static inline struct file *au_hf_top(struct file *file)
11308 + FiMustAnyLock(file);
11309 + AuDebugOn(au_fi(file)->fi_hdir);
11310 + return au_fi(file)->fi_htop.hf_file;
11313 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
11315 + FiMustAnyLock(file);
11316 + AuDebugOn(!au_fi(file)->fi_hdir);
11317 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
11320 +/* todo: memory barrier? */
11321 +static inline unsigned int au_figen(struct file *f)
11323 + return atomic_read(&au_fi(f)->fi_generation);
11326 +static inline void au_set_mmapped(struct file *f)
11328 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
11330 + pr_warn("fi_mmapped wrapped around\n");
11331 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
11335 +static inline void au_unset_mmapped(struct file *f)
11337 + atomic_dec(&au_fi(f)->fi_mmapped);
11340 +static inline int au_test_mmapped(struct file *f)
11342 + return atomic_read(&au_fi(f)->fi_mmapped);
11345 +/* customize vma->vm_file */
11347 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
11348 + struct file *file)
11352 + f = vma->vm_file;
11354 + vma->vm_file = file;
11359 +#define AuDbgVmRegion(file, vma) do {} while (0)
11361 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
11362 + struct file *file)
11364 + au_do_vm_file_reset(vma, file);
11367 +#define AuDbgVmRegion(file, vma) \
11368 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
11370 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
11371 + struct file *file)
11375 + au_do_vm_file_reset(vma, file);
11376 + f = vma->vm_region->vm_file;
11378 + vma->vm_region->vm_file = file;
11381 +#endif /* CONFIG_MMU */
11383 +/* handle vma->vm_prfile */
11384 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
11385 + struct file *file)
11388 + vma->vm_prfile = file;
11389 +#ifndef CONFIG_MMU
11391 + vma->vm_region->vm_prfile = file;
11395 +#endif /* __KERNEL__ */
11396 +#endif /* __AUFS_FILE_H__ */
11397 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
11398 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
11399 +++ linux/fs/aufs/finfo.c 2014-01-20 20:16:14.736130059 +0100
11402 + * Copyright (C) 2005-2014 Junjiro R. Okajima
11404 + * This program, aufs is free software; you can redistribute it and/or modify
11405 + * it under the terms of the GNU General Public License as published by
11406 + * the Free Software Foundation; either version 2 of the License, or
11407 + * (at your option) any later version.
11409 + * This program is distributed in the hope that it will be useful,
11410 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11411 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11412 + * GNU General Public License for more details.
11414 + * You should have received a copy of the GNU General Public License
11415 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11419 + * file private data
11424 +void au_hfput(struct au_hfile *hf, struct file *file)
11426 + /* todo: direct access f_flags */
11427 + if (vfsub_file_flags(file) & __FMODE_EXEC)
11428 + allow_write_access(hf->hf_file);
11429 + fput(hf->hf_file);
11430 + hf->hf_file = NULL;
11431 + atomic_dec(&hf->hf_br->br_count);
11432 + hf->hf_br = NULL;
11435 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
11437 + struct au_finfo *finfo = au_fi(file);
11438 + struct au_hfile *hf;
11439 + struct au_fidir *fidir;
11441 + fidir = finfo->fi_hdir;
11443 + AuDebugOn(finfo->fi_btop != bindex);
11444 + hf = &finfo->fi_htop;
11446 + hf = fidir->fd_hfile + bindex;
11448 + if (hf && hf->hf_file)
11449 + au_hfput(hf, file);
11451 + FiMustWriteLock(file);
11452 + hf->hf_file = val;
11453 + hf->hf_br = au_sbr(file->f_dentry->d_sb, bindex);
11457 +void au_update_figen(struct file *file)
11459 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_dentry));
11460 + /* smp_mb(); */ /* atomic_set */
11463 +/* ---------------------------------------------------------------------- */
11465 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
11467 + struct au_fidir *fidir;
11470 + nbr = au_sbend(sb) + 1;
11472 + nbr = 2; /* initial allocate for 2 branches */
11473 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
11475 + fidir->fd_bbot = -1;
11476 + fidir->fd_nent = nbr;
11477 + fidir->fd_vdir_cache = NULL;
11483 +int au_fidir_realloc(struct au_finfo *finfo, int nbr)
11486 + struct au_fidir *fidir, *p;
11488 + AuRwMustWriteLock(&finfo->fi_rwsem);
11489 + fidir = finfo->fi_hdir;
11490 + AuDebugOn(!fidir);
11493 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
11496 + p->fd_nent = nbr;
11497 + finfo->fi_hdir = p;
11504 +/* ---------------------------------------------------------------------- */
11506 +void au_finfo_fin(struct file *file)
11508 + struct au_finfo *finfo;
11510 + au_nfiles_dec(file->f_dentry->d_sb);
11512 + finfo = au_fi(file);
11513 + AuDebugOn(finfo->fi_hdir);
11514 + AuRwDestroy(&finfo->fi_rwsem);
11515 + au_cache_free_finfo(finfo);
11518 +void au_fi_init_once(void *_finfo)
11520 + struct au_finfo *finfo = _finfo;
11521 + static struct lock_class_key aufs_fi;
11523 + au_rw_init(&finfo->fi_rwsem);
11524 + au_rw_class(&finfo->fi_rwsem, &aufs_fi);
11527 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
11530 + struct au_finfo *finfo;
11531 + struct dentry *dentry;
11534 + dentry = file->f_dentry;
11535 + finfo = au_cache_alloc_finfo();
11536 + if (unlikely(!finfo))
11540 + au_nfiles_inc(dentry->d_sb);
11541 + /* verbose coding for lock class name */
11543 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcNonDir_FIINFO);
11545 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcDir_FIINFO);
11546 + au_rw_write_lock(&finfo->fi_rwsem);
11547 + finfo->fi_btop = -1;
11548 + finfo->fi_hdir = fidir;
11549 + atomic_set(&finfo->fi_generation, au_digen(dentry));
11550 + /* smp_mb(); */ /* atomic_set */
11552 + file->private_data = finfo;
11557 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
11558 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
11559 +++ linux/fs/aufs/f_op.c 2014-01-20 20:16:14.736130059 +0100
11562 + * Copyright (C) 2005-2014 Junjiro R. Okajima
11564 + * This program, aufs is free software; you can redistribute it and/or modify
11565 + * it under the terms of the GNU General Public License as published by
11566 + * the Free Software Foundation; either version 2 of the License, or
11567 + * (at your option) any later version.
11569 + * This program is distributed in the hope that it will be useful,
11570 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11571 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11572 + * GNU General Public License for more details.
11574 + * You should have received a copy of the GNU General Public License
11575 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11579 + * file and vm operations
11582 +#include <linux/aio.h>
11583 +#include <linux/fs_stack.h>
11584 +#include <linux/mman.h>
11585 +#include <linux/security.h>
11588 +int au_do_open_nondir(struct file *file, int flags)
11591 + aufs_bindex_t bindex;
11592 + struct file *h_file;
11593 + struct dentry *dentry;
11594 + struct au_finfo *finfo;
11596 + FiMustWriteLock(file);
11599 + dentry = file->f_dentry;
11600 + finfo = au_fi(file);
11601 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
11602 + atomic_set(&finfo->fi_mmapped, 0);
11603 + bindex = au_dbstart(dentry);
11604 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
11605 + if (IS_ERR(h_file))
11606 + err = PTR_ERR(h_file);
11608 + au_set_fbstart(file, bindex);
11609 + au_set_h_fptr(file, bindex, h_file);
11610 + au_update_figen(file);
11611 + finfo->fi_file = file;
11612 + au_sphl_add(&finfo->fi_hlist, &au_sbi(dentry->d_sb)->si_files);
11613 + /* todo: necessary? */
11614 + /* file->f_ra = h_file->f_ra; */
11620 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
11621 + struct file *file)
11624 + struct super_block *sb;
11626 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
11627 + file, vfsub_file_flags(file), file->f_mode);
11629 + sb = file->f_dentry->d_sb;
11630 + si_read_lock(sb, AuLock_FLUSH);
11631 + err = au_do_open(file, au_do_open_nondir, /*fidir*/NULL);
11632 + si_read_unlock(sb);
11636 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
11638 + struct au_finfo *finfo;
11639 + aufs_bindex_t bindex;
11641 + finfo = au_fi(file);
11642 + au_sphl_del(&finfo->fi_hlist, &au_sbi(file->f_dentry->d_sb)->si_files);
11643 + bindex = finfo->fi_btop;
11645 + au_set_h_fptr(file, bindex, NULL);
11647 + au_finfo_fin(file);
11651 +/* ---------------------------------------------------------------------- */
11653 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
11656 + struct file *h_file;
11659 + h_file = au_hf_top(file);
11661 + err = vfsub_flush(h_file, id);
11665 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
11667 + return au_do_flush(file, id, au_do_flush_nondir);
11670 +/* ---------------------------------------------------------------------- */
11672 + * read and write functions acquire [fdi]_rwsem once, but release before
11673 + * mmap_sem. This is because to stop a race condition between mmap(2).
11674 + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping
11675 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
11676 + * read functions after [fdi]_rwsem are released, but it should be harmless.
11679 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
11683 + struct dentry *dentry;
11684 + struct file *h_file;
11685 + struct super_block *sb;
11687 + dentry = file->f_dentry;
11688 + sb = dentry->d_sb;
11689 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11690 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
11691 + if (unlikely(err))
11694 + h_file = au_hf_top(file);
11695 + get_file(h_file);
11696 + di_read_unlock(dentry, AuLock_IR);
11697 + fi_read_unlock(file);
11699 + /* filedata may be obsoleted by concurrent copyup, but no problem */
11700 + err = vfsub_read_u(h_file, buf, count, ppos);
11701 + /* todo: necessary? */
11702 + /* file->f_ra = h_file->f_ra; */
11703 + /* update without lock, I don't think it a problem */
11704 + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
11708 + si_read_unlock(sb);
11713 + * todo: very ugly
11714 + * it locks both of i_mutex and si_rwsem for read in safe.
11715 + * if the plink maintenance mode continues forever (that is the problem),
11716 + * may loop forever.
11718 +static void au_mtx_and_read_lock(struct inode *inode)
11721 + struct super_block *sb = inode->i_sb;
11724 + mutex_lock(&inode->i_mutex);
11725 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
11728 + mutex_unlock(&inode->i_mutex);
11729 + si_read_lock(sb, AuLock_NOPLMW);
11730 + si_read_unlock(sb);
11734 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
11735 + size_t count, loff_t *ppos)
11738 + struct au_pin pin;
11739 + struct dentry *dentry;
11740 + struct super_block *sb;
11741 + struct inode *inode;
11742 + struct file *h_file;
11743 + char __user *buf = (char __user *)ubuf;
11745 + dentry = file->f_dentry;
11746 + sb = dentry->d_sb;
11747 + inode = dentry->d_inode;
11748 + au_mtx_and_read_lock(inode);
11750 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
11751 + if (unlikely(err))
11754 + err = au_ready_to_write(file, -1, &pin);
11755 + di_downgrade_lock(dentry, AuLock_IR);
11756 + if (unlikely(err)) {
11757 + di_read_unlock(dentry, AuLock_IR);
11758 + fi_write_unlock(file);
11762 + h_file = au_hf_top(file);
11763 + get_file(h_file);
11765 + di_read_unlock(dentry, AuLock_IR);
11766 + fi_write_unlock(file);
11768 + err = vfsub_write_u(h_file, buf, count, ppos);
11769 + ii_write_lock_child(inode);
11770 + au_cpup_attr_timesizes(inode);
11771 + inode->i_mode = file_inode(h_file)->i_mode;
11772 + ii_write_unlock(inode);
11776 + si_read_unlock(sb);
11777 + mutex_unlock(&inode->i_mutex);
11781 +static ssize_t au_do_aio(struct file *h_file, int rw, struct kiocb *kio,
11782 + const struct iovec *iov, unsigned long nv, loff_t pos)
11785 + struct file *file;
11786 + ssize_t (*func)(struct kiocb *, const struct iovec *, unsigned long,
11789 + err = security_file_permission(h_file, rw);
11790 + if (unlikely(err))
11795 + if (rw == MAY_READ)
11796 + func = h_file->f_op->aio_read;
11797 + else if (rw == MAY_WRITE)
11798 + func = h_file->f_op->aio_write;
11800 + file = kio->ki_filp;
11801 + kio->ki_filp = h_file;
11803 + err = func(kio, iov, nv, pos);
11805 + kio->ki_filp = file;
11807 + /* currently there is no such fs */
11814 +static ssize_t aufs_aio_read(struct kiocb *kio, const struct iovec *iov,
11815 + unsigned long nv, loff_t pos)
11818 + struct file *file, *h_file;
11819 + struct dentry *dentry;
11820 + struct super_block *sb;
11822 + file = kio->ki_filp;
11823 + dentry = file->f_dentry;
11824 + sb = dentry->d_sb;
11825 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11826 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
11827 + if (unlikely(err))
11830 + h_file = au_hf_top(file);
11831 + get_file(h_file);
11832 + di_read_unlock(dentry, AuLock_IR);
11833 + fi_read_unlock(file);
11835 + err = au_do_aio(h_file, MAY_READ, kio, iov, nv, pos);
11836 + /* todo: necessary? */
11837 + /* file->f_ra = h_file->f_ra; */
11838 + /* update without lock, I don't think it a problem */
11839 + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
11843 + si_read_unlock(sb);
11847 +static ssize_t aufs_aio_write(struct kiocb *kio, const struct iovec *iov,
11848 + unsigned long nv, loff_t pos)
11851 + struct au_pin pin;
11852 + struct dentry *dentry;
11853 + struct inode *inode;
11854 + struct file *file, *h_file;
11855 + struct super_block *sb;
11857 + file = kio->ki_filp;
11858 + dentry = file->f_dentry;
11859 + sb = dentry->d_sb;
11860 + inode = dentry->d_inode;
11861 + au_mtx_and_read_lock(inode);
11863 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
11864 + if (unlikely(err))
11867 + err = au_ready_to_write(file, -1, &pin);
11868 + di_downgrade_lock(dentry, AuLock_IR);
11869 + if (unlikely(err)) {
11870 + di_read_unlock(dentry, AuLock_IR);
11871 + fi_write_unlock(file);
11875 + h_file = au_hf_top(file);
11876 + get_file(h_file);
11878 + di_read_unlock(dentry, AuLock_IR);
11879 + fi_write_unlock(file);
11881 + err = au_do_aio(h_file, MAY_WRITE, kio, iov, nv, pos);
11882 + ii_write_lock_child(inode);
11883 + au_cpup_attr_timesizes(inode);
11884 + inode->i_mode = file_inode(h_file)->i_mode;
11885 + ii_write_unlock(inode);
11889 + si_read_unlock(sb);
11890 + mutex_unlock(&inode->i_mutex);
11894 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
11895 + struct pipe_inode_info *pipe, size_t len,
11896 + unsigned int flags)
11899 + struct file *h_file;
11900 + struct dentry *dentry;
11901 + struct super_block *sb;
11903 + dentry = file->f_dentry;
11904 + sb = dentry->d_sb;
11905 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11906 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
11907 + if (unlikely(err))
11911 + h_file = au_hf_top(file);
11912 + get_file(h_file);
11913 + if (au_test_loopback_kthread()) {
11914 + au_warn_loopback(h_file->f_dentry->d_sb);
11915 + if (file->f_mapping != h_file->f_mapping) {
11916 + file->f_mapping = h_file->f_mapping;
11917 + smp_mb(); /* unnecessary? */
11920 + di_read_unlock(dentry, AuLock_IR);
11921 + fi_read_unlock(file);
11923 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
11924 + /* todo: necessasry? */
11925 + /* file->f_ra = h_file->f_ra; */
11926 + /* update without lock, I don't think it a problem */
11927 + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
11931 + si_read_unlock(sb);
11936 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
11937 + size_t len, unsigned int flags)
11940 + struct au_pin pin;
11941 + struct dentry *dentry;
11942 + struct inode *inode;
11943 + struct file *h_file;
11944 + struct super_block *sb;
11946 + dentry = file->f_dentry;
11947 + sb = dentry->d_sb;
11948 + inode = dentry->d_inode;
11949 + au_mtx_and_read_lock(inode);
11951 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
11952 + if (unlikely(err))
11955 + err = au_ready_to_write(file, -1, &pin);
11956 + di_downgrade_lock(dentry, AuLock_IR);
11957 + if (unlikely(err)) {
11958 + di_read_unlock(dentry, AuLock_IR);
11959 + fi_write_unlock(file);
11963 + h_file = au_hf_top(file);
11964 + get_file(h_file);
11966 + di_read_unlock(dentry, AuLock_IR);
11967 + fi_write_unlock(file);
11969 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
11970 + ii_write_lock_child(inode);
11971 + au_cpup_attr_timesizes(inode);
11972 + inode->i_mode = file_inode(h_file)->i_mode;
11973 + ii_write_unlock(inode);
11977 + si_read_unlock(sb);
11978 + mutex_unlock(&inode->i_mutex);
11982 +/* ---------------------------------------------------------------------- */
11985 + * The locking order around current->mmap_sem.
11986 + * - in most and regular cases
11987 + * file I/O syscall -- aufs_read() or something
11988 + * -- si_rwsem for read -- mmap_sem
11989 + * (Note that [fdi]i_rwsem are released before mmap_sem).
11991 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
11992 + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
11993 + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
11994 + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
11995 + * It means that when aufs acquires si_rwsem for write, the process should never
11996 + * acquire mmap_sem.
11998 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
11999 + * problem either since any directory is not able to be mmap-ed.
12000 + * The similar scenario is applied to aufs_readlink() too.
12003 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
12004 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
12006 +static unsigned long au_arch_prot_conv(unsigned long flags)
12008 + /* currently ppc64 only */
12009 +#ifdef CONFIG_PPC64
12010 + /* cf. linux/arch/powerpc/include/asm/mman.h */
12011 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
12012 + return AuConv_VM_PROT(flags, SAO);
12014 + AuDebugOn(arch_calc_vm_prot_bits(-1));
12019 +static unsigned long au_prot_conv(unsigned long flags)
12021 + return AuConv_VM_PROT(flags, READ)
12022 + | AuConv_VM_PROT(flags, WRITE)
12023 + | AuConv_VM_PROT(flags, EXEC)
12024 + | au_arch_prot_conv(flags);
12027 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
12028 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
12030 +static unsigned long au_flag_conv(unsigned long flags)
12032 + return AuConv_VM_MAP(flags, GROWSDOWN)
12033 + | AuConv_VM_MAP(flags, DENYWRITE)
12034 + | AuConv_VM_MAP(flags, LOCKED);
12037 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
12040 + aufs_bindex_t bstart;
12041 + const unsigned char wlock
12042 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
12043 + struct dentry *dentry;
12044 + struct super_block *sb;
12045 + struct file *h_file;
12046 + struct au_branch *br;
12047 + struct au_pin pin;
12049 + AuDbgVmRegion(file, vma);
12051 + dentry = file->f_dentry;
12052 + sb = dentry->d_sb;
12054 + si_read_lock(sb, AuLock_NOPLMW);
12055 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
12056 + if (unlikely(err))
12060 + err = au_ready_to_write(file, -1, &pin);
12061 + di_write_unlock(dentry);
12062 + if (unlikely(err)) {
12063 + fi_write_unlock(file);
12068 + di_write_unlock(dentry);
12070 + bstart = au_fbstart(file);
12071 + br = au_sbr(sb, bstart);
12072 + h_file = au_hf_top(file);
12073 + get_file(h_file);
12074 + au_set_mmapped(file);
12075 + fi_write_unlock(file);
12078 + au_vm_file_reset(vma, h_file);
12079 + err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
12080 + au_flag_conv(vma->vm_flags));
12082 + err = h_file->f_op->mmap(h_file, vma);
12083 + if (unlikely(err))
12086 + au_vm_prfile_set(vma, file);
12087 + /* update without lock, I don't think it a problem */
12088 + fsstack_copy_attr_atime(file_inode(file), file_inode(h_file));
12089 + goto out_fput; /* success */
12092 + au_unset_mmapped(file);
12093 + au_vm_file_reset(vma, file);
12098 + si_read_unlock(sb);
12104 +/* ---------------------------------------------------------------------- */
12106 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
12110 + struct au_pin pin;
12111 + struct dentry *dentry;
12112 + struct inode *inode;
12113 + struct file *h_file;
12114 + struct super_block *sb;
12116 + dentry = file->f_dentry;
12117 + inode = dentry->d_inode;
12118 + sb = dentry->d_sb;
12119 + mutex_lock(&inode->i_mutex);
12120 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
12121 + if (unlikely(err))
12124 + err = 0; /* -EBADF; */ /* posix? */
12125 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
12127 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
12128 + if (unlikely(err))
12131 + err = au_ready_to_write(file, -1, &pin);
12132 + di_downgrade_lock(dentry, AuLock_IR);
12133 + if (unlikely(err))
12138 + h_file = au_hf_top(file);
12139 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
12140 + au_cpup_attr_timesizes(inode);
12143 + di_read_unlock(dentry, AuLock_IR);
12144 + fi_write_unlock(file);
12146 + si_read_unlock(sb);
12148 + mutex_unlock(&inode->i_mutex);
12152 +/* no one supports this operation, currently */
12154 +static int aufs_aio_fsync_nondir(struct kiocb *kio, int datasync)
12157 + struct au_pin pin;
12158 + struct dentry *dentry;
12159 + struct inode *inode;
12160 + struct file *file, *h_file;
12162 + file = kio->ki_filp;
12163 + dentry = file->f_dentry;
12164 + inode = dentry->d_inode;
12165 + au_mtx_and_read_lock(inode);
12167 + err = 0; /* -EBADF; */ /* posix? */
12168 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
12170 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
12171 + if (unlikely(err))
12174 + err = au_ready_to_write(file, -1, &pin);
12175 + di_downgrade_lock(dentry, AuLock_IR);
12176 + if (unlikely(err))
12181 + h_file = au_hf_top(file);
12182 + if (h_file->f_op->aio_fsync) {
12183 + struct mutex *h_mtx;
12185 + h_mtx = &file_inode(h_file)->i_mutex;
12186 + if (!is_sync_kiocb(kio)) {
12187 + get_file(h_file);
12190 + kio->ki_filp = h_file;
12191 + err = h_file->f_op->aio_fsync(kio, datasync);
12192 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
12194 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL);
12196 + au_cpup_attr_timesizes(inode);
12197 + mutex_unlock(h_mtx);
12201 + di_read_unlock(dentry, AuLock_IR);
12202 + fi_write_unlock(file);
12204 + si_read_unlock(inode->sb);
12205 + mutex_unlock(&inode->i_mutex);
12210 +static int aufs_fasync(int fd, struct file *file, int flag)
12213 + struct file *h_file;
12214 + struct dentry *dentry;
12215 + struct super_block *sb;
12217 + dentry = file->f_dentry;
12218 + sb = dentry->d_sb;
12219 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
12220 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
12221 + if (unlikely(err))
12224 + h_file = au_hf_top(file);
12225 + if (h_file->f_op->fasync)
12226 + err = h_file->f_op->fasync(fd, h_file, flag);
12228 + di_read_unlock(dentry, AuLock_IR);
12229 + fi_read_unlock(file);
12232 + si_read_unlock(sb);
12236 +/* ---------------------------------------------------------------------- */
12238 +/* no one supports this operation, currently */
12240 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
12241 + size_t len, loff_t *pos , int more)
12246 +/* ---------------------------------------------------------------------- */
12248 +const struct file_operations aufs_file_fop = {
12249 + .owner = THIS_MODULE,
12251 + .llseek = default_llseek,
12253 + .read = aufs_read,
12254 + .write = aufs_write,
12255 + .aio_read = aufs_aio_read,
12256 + .aio_write = aufs_aio_write,
12257 +#ifdef CONFIG_AUFS_POLL
12258 + .poll = aufs_poll,
12260 + .unlocked_ioctl = aufs_ioctl_nondir,
12261 +#ifdef CONFIG_COMPAT
12262 + .compat_ioctl = aufs_compat_ioctl_nondir,
12264 + .mmap = aufs_mmap,
12265 + .open = aufs_open_nondir,
12266 + .flush = aufs_flush_nondir,
12267 + .release = aufs_release_nondir,
12268 + .fsync = aufs_fsync_nondir,
12269 + /* .aio_fsync = aufs_aio_fsync_nondir, */
12270 + .fasync = aufs_fasync,
12271 + /* .sendpage = aufs_sendpage, */
12272 + .splice_write = aufs_splice_write,
12273 + .splice_read = aufs_splice_read,
12275 + .aio_splice_write = aufs_aio_splice_write,
12276 + .aio_splice_read = aufs_aio_splice_read
12279 diff -urN /usr/share/empty/fs/aufs/f_op_sp.c linux/fs/aufs/f_op_sp.c
12280 --- /usr/share/empty/fs/aufs/f_op_sp.c 1970-01-01 01:00:00.000000000 +0100
12281 +++ linux/fs/aufs/f_op_sp.c 2014-01-20 20:16:14.736130059 +0100
12284 + * Copyright (C) 2005-2014 Junjiro R. Okajima
12286 + * This program, aufs is free software; you can redistribute it and/or modify
12287 + * it under the terms of the GNU General Public License as published by
12288 + * the Free Software Foundation; either version 2 of the License, or
12289 + * (at your option) any later version.
12291 + * This program is distributed in the hope that it will be useful,
12292 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12293 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12294 + * GNU General Public License for more details.
12296 + * You should have received a copy of the GNU General Public License
12297 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12301 + * file operations for special files.
12302 + * while they exist in aufs virtually,
12303 + * their file I/O is handled out of aufs.
12306 +#include <linux/aio.h>
12310 + * I don't think the size of this list grows much.
12311 + * so here is a very simple list implemented in order to find finfo matching a
12314 +static struct au_sphlhead au_finfo_sp = {
12315 + .spin = __SPIN_LOCK_INITIALIZER(au_finfo_sp.spin),
12316 + .head = HLIST_HEAD_INIT
12319 +struct au_finfo_sp {
12320 + struct hlist_node hlist;
12321 + struct file *file;
12322 + struct au_finfo *finfo;
12325 +struct au_finfo *au_fi_sp(struct file *file)
12327 + struct au_finfo *finfo;
12328 + struct au_finfo_sp *sp;
12331 + spin_lock(&au_finfo_sp.spin);
12332 + hlist_for_each_entry(sp, &au_finfo_sp.head, hlist) {
12333 + if (sp->file != file)
12335 + finfo = sp->finfo;
12338 + spin_unlock(&au_finfo_sp.spin);
12343 +static int au_fi_sp_add(struct file *file)
12346 + struct au_finfo_sp *sp;
12349 + sp = kmalloc(sizeof(*sp), GFP_NOFS);
12353 + sp->finfo = file->private_data;
12354 + spin_lock(&au_finfo_sp.spin);
12355 + hlist_add_head(&sp->hlist, &au_finfo_sp.head);
12356 + spin_unlock(&au_finfo_sp.spin);
12361 +static void au_fi_sp_del(struct file *file)
12363 + struct au_finfo_sp *sp, *do_free;
12366 + spin_lock(&au_finfo_sp.spin);
12367 + hlist_for_each_entry(sp, &au_finfo_sp.head, hlist) {
12368 + if (sp->file != file)
12370 + hlist_del(&sp->hlist);
12374 + spin_unlock(&au_finfo_sp.spin);
12378 +/* ---------------------------------------------------------------------- */
12380 +static ssize_t aufs_aio_read_sp(struct kiocb *kio, const struct iovec *iov,
12381 + unsigned long nv, loff_t pos)
12384 + aufs_bindex_t bstart;
12385 + unsigned char wbr;
12386 + struct file *file, *h_file;
12387 + struct super_block *sb;
12389 + file = kio->ki_filp;
12390 + sb = file->f_dentry->d_sb;
12391 + si_read_lock(sb, AuLock_FLUSH);
12392 + fi_read_lock(file);
12393 + bstart = au_fbstart(file);
12394 + h_file = au_hf_top(file);
12395 + fi_read_unlock(file);
12396 + wbr = !!au_br_writable(au_sbr(sb, bstart)->br_perm);
12397 + si_read_unlock(sb);
12399 + /* do not change the file in kio */
12400 + AuDebugOn(!h_file->f_op || !h_file->f_op->aio_read);
12401 + err = h_file->f_op->aio_read(kio, iov, nv, pos);
12402 + if (err > 0 && wbr)
12403 + file_accessed(h_file);
12408 +static ssize_t aufs_aio_write_sp(struct kiocb *kio, const struct iovec *iov,
12409 + unsigned long nv, loff_t pos)
12412 + aufs_bindex_t bstart;
12413 + unsigned char wbr;
12414 + struct super_block *sb;
12415 + struct file *file, *h_file;
12417 + file = kio->ki_filp;
12418 + sb = file->f_dentry->d_sb;
12419 + si_read_lock(sb, AuLock_FLUSH);
12420 + fi_read_lock(file);
12421 + bstart = au_fbstart(file);
12422 + h_file = au_hf_top(file);
12423 + fi_read_unlock(file);
12424 + wbr = !!au_br_writable(au_sbr(sb, bstart)->br_perm);
12425 + si_read_unlock(sb);
12427 + /* do not change the file in kio */
12428 + AuDebugOn(!h_file->f_op || !h_file->f_op->aio_write);
12429 + err = h_file->f_op->aio_write(kio, iov, nv, pos);
12433 +/* ---------------------------------------------------------------------- */
12435 +static int aufs_release_sp(struct inode *inode, struct file *file)
12438 + struct file *h_file;
12440 + fi_read_lock(file);
12441 + h_file = au_hf_top(file);
12442 + fi_read_unlock(file);
12443 + /* close this fifo in aufs */
12444 + err = h_file->f_op->release(inode, file); /* ignore */
12445 + aufs_release_nondir(inode, file); /* ignore */
12446 + au_fi_sp_del(file);
12450 +/* ---------------------------------------------------------------------- */
12452 +/* currently, support only FIFO */
12454 + AuSp_FIFO, AuSp_FIFO_R, AuSp_FIFO_W, AuSp_FIFO_RW,
12455 + /* AuSp_SOCK, AuSp_CHR, AuSp_BLK, */
12458 +static int aufs_open_sp(struct inode *inode, struct file *file);
12459 +static struct au_sp_fop {
12461 + struct file_operations fop; /* not 'const' */
12463 +} au_sp_fop[AuSp_Last] = {
12466 + .owner = THIS_MODULE,
12467 + .open = aufs_open_sp
12472 +static void au_init_fop_sp(struct file *file)
12474 + struct au_sp_fop *p;
12476 + struct file *h_file;
12479 + if (unlikely(!p->done)) {
12480 + /* initialize first time only */
12481 + static DEFINE_SPINLOCK(spin);
12483 + spin_lock(&spin);
12485 + BUILD_BUG_ON(sizeof(au_sp_fop)/sizeof(*au_sp_fop)
12487 + for (i = 0; i < AuSp_Last; i++)
12488 + spin_lock_init(&p[i].spin);
12491 + spin_unlock(&spin);
12494 + switch (file->f_mode & (FMODE_READ | FMODE_WRITE)) {
12498 + case FMODE_WRITE:
12501 + case FMODE_READ | FMODE_WRITE:
12502 + i = AuSp_FIFO_RW;
12509 + if (unlikely(!p->done)) {
12510 + /* initialize first time only */
12511 + h_file = au_hf_top(file);
12512 + spin_lock(&p->spin);
12514 + p->fop = *h_file->f_op;
12515 + p->fop.owner = THIS_MODULE;
12516 + if (p->fop.aio_read)
12517 + p->fop.aio_read = aufs_aio_read_sp;
12518 + if (p->fop.aio_write)
12519 + p->fop.aio_write = aufs_aio_write_sp;
12520 + p->fop.release = aufs_release_sp;
12523 + spin_unlock(&p->spin);
12525 + file->f_op = &p->fop;
12528 +static int au_cpup_sp(struct dentry *dentry)
12531 + struct au_pin pin;
12532 + struct au_wr_dir_args wr_dir_args = {
12533 + .force_btgt = -1,
12536 + struct au_cp_generic cpg = {
12537 + .dentry = dentry,
12542 + .flags = AuCpup_DTIME
12545 + AuDbg("%pd\n", dentry);
12547 + di_read_unlock(dentry, AuLock_IR);
12548 + di_write_lock_child(dentry);
12549 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
12550 + if (unlikely(err < 0))
12554 + if (cpg.bdst == au_dbstart(dentry))
12555 + goto out; /* success */
12557 + err = au_pin(&pin, dentry, cpg.bdst, au_opt_udba(dentry->d_sb),
12558 + AuPin_MNT_WRITE);
12560 + err = au_sio_cpup_simple(&cpg);
12565 + di_downgrade_lock(dentry, AuLock_IR);
12569 +static int au_do_open_sp(struct file *file, int flags)
12572 + struct dentry *dentry;
12573 + struct super_block *sb;
12574 + struct file *h_file;
12575 + struct inode *h_inode;
12577 + err = au_fi_sp_add(file);
12578 + if (unlikely(err))
12581 + dentry = file->f_dentry;
12582 + AuDbg("%pd\n", dentry);
12585 + * try copying-up.
12586 + * operate on the ro branch is not an error.
12588 + au_cpup_sp(dentry); /* ignore */
12590 + /* prepare h_file */
12591 + err = au_do_open_nondir(file, vfsub_file_flags(file));
12592 + if (unlikely(err))
12595 + sb = dentry->d_sb;
12596 + h_file = au_hf_top(file);
12597 + h_inode = file_inode(h_file);
12598 + di_read_unlock(dentry, AuLock_IR);
12599 + fi_write_unlock(file);
12600 + si_read_unlock(sb);
12601 + /* open this fifo in aufs */
12602 + err = h_inode->i_fop->open(file_inode(file), file);
12603 + si_noflush_read_lock(sb);
12604 + fi_write_lock(file);
12605 + di_read_lock_child(dentry, AuLock_IR);
12607 + au_init_fop_sp(file);
12608 + goto out; /* success */
12612 + au_fi_sp_del(file);
12617 +static int aufs_open_sp(struct inode *inode, struct file *file)
12620 + struct super_block *sb;
12622 + sb = file->f_dentry->d_sb;
12623 + si_read_lock(sb, AuLock_FLUSH);
12624 + err = au_do_open(file, au_do_open_sp, /*fidir*/NULL);
12625 + si_read_unlock(sb);
12629 +/* ---------------------------------------------------------------------- */
12631 +void au_init_special_fop(struct inode *inode, umode_t mode, dev_t rdev)
12633 + init_special_inode(inode, mode, rdev);
12635 + switch (mode & S_IFMT) {
12637 + inode->i_fop = &au_sp_fop[AuSp_FIFO].fop;
12648 +int au_special_file(umode_t mode)
12653 + switch (mode & S_IFMT) {
12665 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
12666 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
12667 +++ linux/fs/aufs/fstype.h 2014-01-20 20:16:14.739463504 +0100
12670 + * Copyright (C) 2005-2014 Junjiro R. Okajima
12672 + * This program, aufs is free software; you can redistribute it and/or modify
12673 + * it under the terms of the GNU General Public License as published by
12674 + * the Free Software Foundation; either version 2 of the License, or
12675 + * (at your option) any later version.
12677 + * This program is distributed in the hope that it will be useful,
12678 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12679 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12680 + * GNU General Public License for more details.
12682 + * You should have received a copy of the GNU General Public License
12683 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12687 + * judging filesystem type
12690 +#ifndef __AUFS_FSTYPE_H__
12691 +#define __AUFS_FSTYPE_H__
12695 +#include <linux/fs.h>
12696 +#include <linux/magic.h>
12697 +#include <linux/romfs_fs.h>
12699 +static inline int au_test_aufs(struct super_block *sb)
12701 + return sb->s_magic == AUFS_SUPER_MAGIC;
12704 +static inline const char *au_sbtype(struct super_block *sb)
12706 + return sb->s_type->name;
12709 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
12711 +#if defined(CONFIG_ROMFS_FS) || defined(CONFIG_ROMFS_FS_MODULE)
12712 + return sb->s_magic == ROMFS_MAGIC;
12718 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
12720 +#if defined(CONFIG_ISO9660_FS) || defined(CONFIG_ISO9660_FS_MODULE)
12721 + return sb->s_magic == ISOFS_SUPER_MAGIC;
12727 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
12729 +#if defined(CONFIG_CRAMFS) || defined(CONFIG_CRAMFS_MODULE)
12730 + return sb->s_magic == CRAMFS_MAGIC;
12735 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
12737 +#if defined(CONFIG_NFS_FS) || defined(CONFIG_NFS_FS_MODULE)
12738 + return sb->s_magic == NFS_SUPER_MAGIC;
12744 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
12746 +#if defined(CONFIG_FUSE_FS) || defined(CONFIG_FUSE_FS_MODULE)
12747 + return sb->s_magic == FUSE_SUPER_MAGIC;
12753 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
12755 +#if defined(CONFIG_XFS_FS) || defined(CONFIG_XFS_FS_MODULE)
12756 + return sb->s_magic == XFS_SB_MAGIC;
12762 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
12764 +#ifdef CONFIG_TMPFS
12765 + return sb->s_magic == TMPFS_MAGIC;
12771 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
12773 +#if defined(CONFIG_ECRYPT_FS) || defined(CONFIG_ECRYPT_FS_MODULE)
12774 + return !strcmp(au_sbtype(sb), "ecryptfs");
12780 +static inline int au_test_ocfs2(struct super_block *sb __maybe_unused)
12782 +#if defined(CONFIG_OCFS2_FS) || defined(CONFIG_OCFS2_FS_MODULE)
12783 + return sb->s_magic == OCFS2_SUPER_MAGIC;
12789 +static inline int au_test_ocfs2_dlmfs(struct super_block *sb __maybe_unused)
12791 +#if defined(CONFIG_OCFS2_FS_O2CB) || defined(CONFIG_OCFS2_FS_O2CB_MODULE)
12792 + return sb->s_magic == DLMFS_MAGIC;
12798 +static inline int au_test_coda(struct super_block *sb __maybe_unused)
12800 +#if defined(CONFIG_CODA_FS) || defined(CONFIG_CODA_FS_MODULE)
12801 + return sb->s_magic == CODA_SUPER_MAGIC;
12807 +static inline int au_test_v9fs(struct super_block *sb __maybe_unused)
12809 +#if defined(CONFIG_9P_FS) || defined(CONFIG_9P_FS_MODULE)
12810 + return sb->s_magic == V9FS_MAGIC;
12816 +static inline int au_test_ext4(struct super_block *sb __maybe_unused)
12818 +#if defined(CONFIG_EXT4_FS) || defined(CONFIG_EXT4_FS_MODULE)
12819 + return sb->s_magic == EXT4_SUPER_MAGIC;
12825 +static inline int au_test_sysv(struct super_block *sb __maybe_unused)
12827 +#if defined(CONFIG_SYSV_FS) || defined(CONFIG_SYSV_FS_MODULE)
12828 + return !strcmp(au_sbtype(sb), "sysv");
12834 +static inline int au_test_ramfs(struct super_block *sb)
12836 + return sb->s_magic == RAMFS_MAGIC;
12839 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
12841 +#if defined(CONFIG_UBIFS_FS) || defined(CONFIG_UBIFS_FS_MODULE)
12842 + return sb->s_magic == UBIFS_SUPER_MAGIC;
12848 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
12850 +#ifdef CONFIG_PROC_FS
12851 + return sb->s_magic == PROC_SUPER_MAGIC;
12857 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
12859 +#ifdef CONFIG_SYSFS
12860 + return sb->s_magic == SYSFS_MAGIC;
12866 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
12868 +#if defined(CONFIG_CONFIGFS_FS) || defined(CONFIG_CONFIGFS_FS_MODULE)
12869 + return sb->s_magic == CONFIGFS_MAGIC;
12875 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
12877 +#if defined(CONFIG_MINIX_FS) || defined(CONFIG_MINIX_FS_MODULE)
12878 + return sb->s_magic == MINIX3_SUPER_MAGIC
12879 + || sb->s_magic == MINIX2_SUPER_MAGIC
12880 + || sb->s_magic == MINIX2_SUPER_MAGIC2
12881 + || sb->s_magic == MINIX_SUPER_MAGIC
12882 + || sb->s_magic == MINIX_SUPER_MAGIC2;
12888 +static inline int au_test_cifs(struct super_block *sb __maybe_unused)
12890 +#if defined(CONFIG_CIFS_FS) || defined(CONFIGCIFS_FS_MODULE)
12891 + return sb->s_magic == CIFS_MAGIC_NUMBER;
12897 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
12899 +#if defined(CONFIG_FAT_FS) || defined(CONFIG_FAT_FS_MODULE)
12900 + return sb->s_magic == MSDOS_SUPER_MAGIC;
12906 +static inline int au_test_msdos(struct super_block *sb)
12908 + return au_test_fat(sb);
12911 +static inline int au_test_vfat(struct super_block *sb)
12913 + return au_test_fat(sb);
12916 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
12918 +#ifdef CONFIG_SECURITYFS
12919 + return sb->s_magic == SECURITYFS_MAGIC;
12925 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
12927 +#if defined(CONFIG_SQUASHFS) || defined(CONFIG_SQUASHFS_MODULE)
12928 + return sb->s_magic == SQUASHFS_MAGIC;
12934 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
12936 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
12937 + return sb->s_magic == BTRFS_SUPER_MAGIC;
12943 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
12945 +#if defined(CONFIG_XENFS) || defined(CONFIG_XENFS_MODULE)
12946 + return sb->s_magic == XENFS_SUPER_MAGIC;
12952 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
12954 +#ifdef CONFIG_DEBUG_FS
12955 + return sb->s_magic == DEBUGFS_MAGIC;
12961 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
12963 +#if defined(CONFIG_NILFS) || defined(CONFIG_NILFS_MODULE)
12964 + return sb->s_magic == NILFS_SUPER_MAGIC;
12970 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
12972 +#if defined(CONFIG_HFSPLUS_FS) || defined(CONFIG_HFSPLUS_FS_MODULE)
12973 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
12979 +/* ---------------------------------------------------------------------- */
12981 + * they can't be an aufs branch.
12983 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
12986 +#ifndef CONFIG_AUFS_BR_RAMFS
12987 + au_test_ramfs(sb) ||
12989 + au_test_procfs(sb)
12990 + || au_test_sysfs(sb)
12991 + || au_test_configfs(sb)
12992 + || au_test_debugfs(sb)
12993 + || au_test_securityfs(sb)
12994 + || au_test_xenfs(sb)
12995 + || au_test_ecryptfs(sb)
12996 + /* || !strcmp(au_sbtype(sb), "unionfs") */
12997 + || au_test_aufs(sb); /* will be supported in next version */
13000 +static inline int au_test_fs_remote(struct super_block *sb)
13002 + return !au_test_tmpfs(sb)
13003 +#ifdef CONFIG_AUFS_BR_RAMFS
13004 + && !au_test_ramfs(sb)
13006 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
13009 +/* ---------------------------------------------------------------------- */
13012 + * Note: these functions (below) are created after reading ->getattr() in all
13013 + * filesystems under linux/fs. it means we have to do so in every update...
13017 + * some filesystems require getattr to refresh the inode attributes before
13019 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
13020 + * and leave the work for d_revalidate()
13022 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
13024 + return au_test_nfs(sb)
13025 + || au_test_fuse(sb)
13026 + /* || au_test_ocfs2(sb) */ /* untested */
13027 + /* || au_test_btrfs(sb) */ /* untested */
13028 + /* || au_test_coda(sb) */ /* untested */
13029 + /* || au_test_v9fs(sb) */ /* untested */
13034 + * filesystems which don't maintain i_size or i_blocks.
13036 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
13038 + return au_test_xfs(sb)
13039 + || au_test_btrfs(sb)
13040 + || au_test_ubifs(sb)
13041 + || au_test_hfsplus(sb) /* maintained, but incorrect */
13042 + /* || au_test_ext4(sb) */ /* untested */
13043 + /* || au_test_ocfs2(sb) */ /* untested */
13044 + /* || au_test_ocfs2_dlmfs(sb) */ /* untested */
13045 + /* || au_test_sysv(sb) */ /* untested */
13046 + /* || au_test_minix(sb) */ /* untested */
13051 + * filesystems which don't store the correct value in some of their inode
13054 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
13056 + return au_test_fs_bad_iattr_size(sb)
13057 + /* || au_test_cifs(sb) */ /* untested */
13058 + || au_test_fat(sb)
13059 + || au_test_msdos(sb)
13060 + || au_test_vfat(sb);
13063 +/* they don't check i_nlink in link(2) */
13064 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
13066 + return au_test_tmpfs(sb)
13067 +#ifdef CONFIG_AUFS_BR_RAMFS
13068 + || au_test_ramfs(sb)
13070 + || au_test_ubifs(sb)
13071 + || au_test_hfsplus(sb);
13075 + * filesystems which sets S_NOATIME and S_NOCMTIME.
13077 +static inline int au_test_fs_notime(struct super_block *sb)
13079 + return au_test_nfs(sb)
13080 + || au_test_fuse(sb)
13081 + || au_test_ubifs(sb)
13082 + /* || au_test_cifs(sb) */ /* untested */
13087 + * filesystems which requires replacing i_mapping.
13089 +static inline int au_test_fs_bad_mapping(struct super_block *sb)
13091 + return au_test_fuse(sb)
13092 + || au_test_ubifs(sb);
13095 +/* temporary support for i#1 in cramfs */
13096 +static inline int au_test_fs_unique_ino(struct inode *inode)
13098 + if (au_test_cramfs(inode->i_sb))
13099 + return inode->i_ino != 1;
13103 +/* ---------------------------------------------------------------------- */
13106 + * the filesystem where the xino files placed must support i/o after unlink and
13107 + * maintain i_size and i_blocks.
13109 +static inline int au_test_fs_bad_xino(struct super_block *sb)
13111 + return au_test_fs_remote(sb)
13112 + || au_test_fs_bad_iattr_size(sb)
13113 + /* don't want unnecessary work for xino */
13114 + || au_test_aufs(sb)
13115 + || au_test_ecryptfs(sb)
13116 + || au_test_nilfs(sb);
13119 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
13121 + return au_test_tmpfs(sb)
13122 + || au_test_ramfs(sb);
13126 + * test if the @sb is real-readonly.
13128 +static inline int au_test_fs_rr(struct super_block *sb)
13130 + return au_test_squashfs(sb)
13131 + || au_test_iso9660(sb)
13132 + || au_test_cramfs(sb)
13133 + || au_test_romfs(sb);
13136 +#endif /* __KERNEL__ */
13137 +#endif /* __AUFS_FSTYPE_H__ */
13138 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
13139 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
13140 +++ linux/fs/aufs/hfsnotify.c 2014-01-20 20:16:14.739463504 +0100
13143 + * Copyright (C) 2005-2014 Junjiro R. Okajima
13145 + * This program, aufs is free software; you can redistribute it and/or modify
13146 + * it under the terms of the GNU General Public License as published by
13147 + * the Free Software Foundation; either version 2 of the License, or
13148 + * (at your option) any later version.
13150 + * This program is distributed in the hope that it will be useful,
13151 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13152 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13153 + * GNU General Public License for more details.
13155 + * You should have received a copy of the GNU General Public License
13156 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13160 + * fsnotify for the lower directories
13165 +/* FS_IN_IGNORED is unnecessary */
13166 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
13167 + | FS_CREATE | FS_EVENT_ON_CHILD);
13168 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
13169 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
13171 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
13173 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
13176 + au_cache_free_hnotify(hn);
13177 + smp_mb__before_atomic_dec();
13178 + if (atomic64_dec_and_test(&au_hfsn_ifree))
13179 + wake_up(&au_hfsn_wq);
13182 +static int au_hfsn_alloc(struct au_hinode *hinode)
13185 + struct au_hnotify *hn;
13186 + struct super_block *sb;
13187 + struct au_branch *br;
13188 + struct fsnotify_mark *mark;
13189 + aufs_bindex_t bindex;
13191 + hn = hinode->hi_notify;
13192 + sb = hn->hn_aufs_inode->i_sb;
13193 + bindex = au_br_index(sb, hinode->hi_id);
13194 + br = au_sbr(sb, bindex);
13195 + AuDebugOn(!br->br_hfsn);
13197 + mark = &hn->hn_mark;
13198 + fsnotify_init_mark(mark, au_hfsn_free_mark);
13199 + mark->mask = AuHfsnMask;
13201 + * by udba rename or rmdir, aufs assign a new inode to the known
13202 + * h_inode, so specify 1 to allow dups.
13204 + err = fsnotify_add_mark(mark, br->br_hfsn->hfsn_group, hinode->hi_inode,
13205 + /*mnt*/NULL, /*allow_dups*/1);
13206 + /* even if err */
13207 + fsnotify_put_mark(mark);
13212 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
13214 + struct fsnotify_mark *mark;
13215 + unsigned long long ull;
13216 + struct fsnotify_group *group;
13218 + ull = atomic64_inc_return(&au_hfsn_ifree);
13221 + mark = &hn->hn_mark;
13222 + spin_lock(&mark->lock);
13223 + group = mark->group;
13224 + fsnotify_get_group(group);
13225 + spin_unlock(&mark->lock);
13226 + fsnotify_destroy_mark(mark, group);
13227 + fsnotify_put_group(group);
13229 + /* free hn by myself */
13233 +/* ---------------------------------------------------------------------- */
13235 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
13237 + struct fsnotify_mark *mark;
13239 + mark = &hinode->hi_notify->hn_mark;
13240 + spin_lock(&mark->lock);
13242 + AuDebugOn(mark->mask & AuHfsnMask);
13243 + mark->mask |= AuHfsnMask;
13245 + AuDebugOn(!(mark->mask & AuHfsnMask));
13246 + mark->mask &= ~AuHfsnMask;
13248 + spin_unlock(&mark->lock);
13249 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
13252 +/* ---------------------------------------------------------------------- */
13254 +/* #define AuDbgHnotify */
13255 +#ifdef AuDbgHnotify
13256 +static char *au_hfsn_name(u32 mask)
13258 +#ifdef CONFIG_AUFS_DEBUG
13259 +#define test_ret(flag) \
13261 + if (mask & flag) \
13264 + test_ret(FS_ACCESS);
13265 + test_ret(FS_MODIFY);
13266 + test_ret(FS_ATTRIB);
13267 + test_ret(FS_CLOSE_WRITE);
13268 + test_ret(FS_CLOSE_NOWRITE);
13269 + test_ret(FS_OPEN);
13270 + test_ret(FS_MOVED_FROM);
13271 + test_ret(FS_MOVED_TO);
13272 + test_ret(FS_CREATE);
13273 + test_ret(FS_DELETE);
13274 + test_ret(FS_DELETE_SELF);
13275 + test_ret(FS_MOVE_SELF);
13276 + test_ret(FS_UNMOUNT);
13277 + test_ret(FS_Q_OVERFLOW);
13278 + test_ret(FS_IN_IGNORED);
13279 + test_ret(FS_IN_ISDIR);
13280 + test_ret(FS_IN_ONESHOT);
13281 + test_ret(FS_EVENT_ON_CHILD);
13290 +/* ---------------------------------------------------------------------- */
13292 +static void au_hfsn_free_group(struct fsnotify_group *group)
13294 + struct au_br_hfsnotify *hfsn = group->private;
13300 +static int au_hfsn_handle_event(struct fsnotify_group *group,
13301 + struct fsnotify_mark *inode_mark,
13302 + struct fsnotify_mark *vfsmount_mark,
13303 + struct fsnotify_event *event)
13306 + struct au_hnotify *hnotify;
13307 + struct inode *h_dir, *h_inode;
13309 + struct qstr h_child_qstr = QSTR_INIT(event->file_name, event->name_len);
13311 + AuDebugOn(event->data_type != FSNOTIFY_EVENT_INODE);
13314 + /* if FS_UNMOUNT happens, there must be another bug */
13315 + mask = event->mask;
13316 + AuDebugOn(mask & FS_UNMOUNT);
13317 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
13320 + h_dir = event->to_tell;
13321 + h_inode = event->inode;
13322 +#ifdef AuDbgHnotify
13324 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
13325 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
13326 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
13327 + h_dir->i_ino, mask, au_hfsn_name(mask),
13328 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
13329 + /* WARN_ON(1); */
13334 + AuDebugOn(!inode_mark);
13335 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
13336 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
13342 +/* isn't it waste to ask every registered 'group'? */
13343 +/* copied from linux/fs/notify/inotify/inotify_fsnotiry.c */
13344 +/* it should be exported to modules */
13345 +static bool au_hfsn_should_send_event(struct fsnotify_group *group,
13346 + struct inode *h_inode,
13347 + struct fsnotify_mark *inode_mark,
13348 + struct fsnotify_mark *vfsmount_mark,
13349 + __u32 mask, void *data, int data_type)
13351 + mask = (mask & ~FS_EVENT_ON_CHILD);
13352 + return inode_mark->mask & mask;
13355 +static struct fsnotify_ops au_hfsn_ops = {
13356 + .should_send_event = au_hfsn_should_send_event,
13357 + .handle_event = au_hfsn_handle_event,
13358 + .free_group_priv = au_hfsn_free_group
13361 +/* ---------------------------------------------------------------------- */
13363 +static void au_hfsn_fin_br(struct au_branch *br)
13365 + struct au_br_hfsnotify *hfsn;
13367 + hfsn = br->br_hfsn;
13369 + fsnotify_put_group(hfsn->hfsn_group);
13372 +static int au_hfsn_init_br(struct au_branch *br, int perm)
13375 + struct fsnotify_group *group;
13376 + struct au_br_hfsnotify *hfsn;
13379 + br->br_hfsn = NULL;
13380 + if (!au_br_hnotifyable(perm))
13384 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
13385 + if (unlikely(!hfsn))
13389 + group = fsnotify_alloc_group(&au_hfsn_ops);
13390 + if (IS_ERR(group)) {
13391 + err = PTR_ERR(group);
13392 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
13396 + group->private = hfsn;
13397 + hfsn->hfsn_group = group;
13398 + br->br_hfsn = hfsn;
13399 + goto out; /* success */
13407 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
13412 + if (!br->br_hfsn)
13413 + err = au_hfsn_init_br(br, perm);
13418 +/* ---------------------------------------------------------------------- */
13420 +static void au_hfsn_fin(void)
13422 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
13423 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
13426 +const struct au_hnotify_op au_hnotify_op = {
13427 + .ctl = au_hfsn_ctl,
13428 + .alloc = au_hfsn_alloc,
13429 + .free = au_hfsn_free,
13431 + .fin = au_hfsn_fin,
13433 + .reset_br = au_hfsn_reset_br,
13434 + .fin_br = au_hfsn_fin_br,
13435 + .init_br = au_hfsn_init_br
13437 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
13438 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
13439 +++ linux/fs/aufs/hfsplus.c 2014-01-20 20:16:14.739463504 +0100
13442 + * Copyright (C) 2010-2014 Junjiro R. Okajima
13444 + * This program, aufs is free software; you can redistribute it and/or modify
13445 + * it under the terms of the GNU General Public License as published by
13446 + * the Free Software Foundation; either version 2 of the License, or
13447 + * (at your option) any later version.
13449 + * This program is distributed in the hope that it will be useful,
13450 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13451 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13452 + * GNU General Public License for more details.
13454 + * You should have received a copy of the GNU General Public License
13455 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13459 + * special support for filesystems which aqucires an inode mutex
13460 + * at final closing a file, eg, hfsplus.
13462 + * This trick is very simple and stupid, just to open the file before really
13463 + * neceeary open to tell hfsplus that this is not the final closing.
13464 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
13465 + * and au_h_open_post() after releasing it.
13470 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
13473 + struct file *h_file;
13474 + struct dentry *h_dentry;
13476 + h_dentry = au_h_dptr(dentry, bindex);
13477 + AuDebugOn(!h_dentry);
13478 + AuDebugOn(!h_dentry->d_inode);
13481 + if (au_test_hfsplus(h_dentry->d_sb)
13482 + && S_ISREG(h_dentry->d_inode->i_mode))
13483 + h_file = au_h_open(dentry, bindex,
13484 + O_RDONLY | O_NOATIME | O_LARGEFILE,
13485 + /*file*/NULL, force_wr);
13489 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
13490 + struct file *h_file)
13494 + au_sbr_put(dentry->d_sb, bindex);
13497 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
13498 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
13499 +++ linux/fs/aufs/hnotify.c 2014-01-27 23:16:52.711753818 +0100
13502 + * Copyright (C) 2005-2014 Junjiro R. Okajima
13504 + * This program, aufs is free software; you can redistribute it and/or modify
13505 + * it under the terms of the GNU General Public License as published by
13506 + * the Free Software Foundation; either version 2 of the License, or
13507 + * (at your option) any later version.
13509 + * This program is distributed in the hope that it will be useful,
13510 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13511 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13512 + * GNU General Public License for more details.
13514 + * You should have received a copy of the GNU General Public License
13515 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13519 + * abstraction to notify the direct changes on lower directories
13524 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
13527 + struct au_hnotify *hn;
13530 + hn = au_cache_alloc_hnotify();
13532 + hn->hn_aufs_inode = inode;
13533 + hinode->hi_notify = hn;
13534 + err = au_hnotify_op.alloc(hinode);
13536 + if (unlikely(err)) {
13537 + hinode->hi_notify = NULL;
13538 + au_cache_free_hnotify(hn);
13540 + * The upper dir was removed by udba, but the same named
13541 + * dir left. In this case, aufs assignes a new inode
13542 + * number and set the monitor again.
13543 + * For the lower dir, the old monitnor is still left.
13545 + if (err == -EEXIST)
13554 +void au_hn_free(struct au_hinode *hinode)
13556 + struct au_hnotify *hn;
13558 + hn = hinode->hi_notify;
13560 + hinode->hi_notify = NULL;
13561 + if (au_hnotify_op.free(hinode, hn))
13562 + au_cache_free_hnotify(hn);
13566 +/* ---------------------------------------------------------------------- */
13568 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
13570 + if (hinode->hi_notify)
13571 + au_hnotify_op.ctl(hinode, do_set);
13574 +void au_hn_reset(struct inode *inode, unsigned int flags)
13576 + aufs_bindex_t bindex, bend;
13577 + struct inode *hi;
13578 + struct dentry *iwhdentry;
13580 + bend = au_ibend(inode);
13581 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
13582 + hi = au_h_iptr(inode, bindex);
13586 + /* mutex_lock_nested(&hi->i_mutex, AuLsc_I_CHILD); */
13587 + iwhdentry = au_hi_wh(inode, bindex);
13591 + au_set_h_iptr(inode, bindex, NULL, 0);
13592 + au_set_h_iptr(inode, bindex, au_igrab(hi),
13593 + flags & ~AuHi_XINO);
13596 + /* mutex_unlock(&hi->i_mutex); */
13600 +/* ---------------------------------------------------------------------- */
13602 +static int hn_xino(struct inode *inode, struct inode *h_inode)
13605 + aufs_bindex_t bindex, bend, bfound, bstart;
13606 + struct inode *h_i;
13609 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
13610 + pr_warn("branch root dir was changed\n");
13615 + bend = au_ibend(inode);
13616 + bstart = au_ibstart(inode);
13617 +#if 0 /* reserved for future use */
13618 + if (bindex == bend) {
13619 + /* keep this ino in rename case */
13623 + for (bindex = bstart; bindex <= bend; bindex++)
13624 + if (au_h_iptr(inode, bindex) == h_inode) {
13631 + for (bindex = bstart; bindex <= bend; bindex++) {
13632 + h_i = au_h_iptr(inode, bindex);
13636 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
13637 + /* ignore this error */
13638 + /* bad action? */
13641 + /* children inode number will be broken */
13648 +static int hn_gen_tree(struct dentry *dentry)
13650 + int err, i, j, ndentry;
13651 + struct au_dcsub_pages dpages;
13652 + struct au_dpage *dpage;
13653 + struct dentry **dentries;
13655 + err = au_dpages_init(&dpages, GFP_NOFS);
13656 + if (unlikely(err))
13658 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
13659 + if (unlikely(err))
13662 + for (i = 0; i < dpages.ndpage; i++) {
13663 + dpage = dpages.dpages + i;
13664 + dentries = dpage->dentries;
13665 + ndentry = dpage->ndentry;
13666 + for (j = 0; j < ndentry; j++) {
13667 + struct dentry *d;
13675 + /* todo: reset children xino?
13676 + cached children only? */
13677 + au_iigen_dec(d->d_inode);
13682 + au_dpages_free(&dpages);
13685 + /* discard children */
13686 + dentry_unhash(dentry);
13694 + * return 0 if processed.
13696 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
13697 + const unsigned int isdir)
13700 + struct dentry *d;
13701 + struct qstr *dname;
13704 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
13705 + pr_warn("branch root dir was changed\n");
13711 + AuDebugOn(!name);
13712 + au_iigen_dec(inode);
13713 + spin_lock(&inode->i_lock);
13714 + hlist_for_each_entry(d, &inode->i_dentry, d_alias) {
13715 + spin_lock(&d->d_lock);
13716 + dname = &d->d_name;
13717 + if (dname->len != nlen
13718 + && memcmp(dname->name, name, nlen)) {
13719 + spin_unlock(&d->d_lock);
13724 + spin_unlock(&d->d_lock);
13727 + spin_unlock(&inode->i_lock);
13729 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
13730 + d = d_find_alias(inode);
13732 + au_iigen_dec(inode);
13736 + spin_lock(&d->d_lock);
13737 + dname = &d->d_name;
13738 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
13739 + spin_unlock(&d->d_lock);
13740 + err = hn_gen_tree(d);
13741 + spin_lock(&d->d_lock);
13743 + spin_unlock(&d->d_lock);
13752 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
13755 + struct inode *inode;
13757 + inode = dentry->d_inode;
13758 + if (IS_ROOT(dentry)
13759 + /* || (inode && inode->i_ino == AUFS_ROOT_INO) */
13761 + pr_warn("branch root dir was changed\n");
13767 + au_digen_dec(dentry);
13769 + au_iigen_dec(inode);
13771 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
13773 + err = hn_gen_tree(dentry);
13780 +/* ---------------------------------------------------------------------- */
13782 +/* hnotify job flags */
13783 +#define AuHnJob_XINO0 1
13784 +#define AuHnJob_GEN (1 << 1)
13785 +#define AuHnJob_DIRENT (1 << 2)
13786 +#define AuHnJob_ISDIR (1 << 3)
13787 +#define AuHnJob_TRYXINO0 (1 << 4)
13788 +#define AuHnJob_MNTPNT (1 << 5)
13789 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
13790 +#define au_fset_hnjob(flags, name) \
13791 + do { (flags) |= AuHnJob_##name; } while (0)
13792 +#define au_fclr_hnjob(flags, name) \
13793 + do { (flags) &= ~AuHnJob_##name; } while (0)
13801 +struct au_hnotify_args {
13802 + struct inode *h_dir, *dir, *h_child_inode;
13804 + unsigned int flags[AuHnLast];
13805 + unsigned int h_child_nlen;
13806 + char h_child_name[];
13809 +struct hn_job_args {
13810 + unsigned int flags;
13811 + struct inode *inode, *h_inode, *dir, *h_dir;
13812 + struct dentry *dentry;
13817 +static int hn_job(struct hn_job_args *a)
13819 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
13822 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
13823 + hn_xino(a->inode, a->h_inode); /* ignore this error */
13825 + if (au_ftest_hnjob(a->flags, TRYXINO0)
13828 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
13829 + if (!a->h_inode->i_nlink)
13830 + hn_xino(a->inode, a->h_inode); /* ignore this error */
13831 + mutex_unlock(&a->h_inode->i_mutex);
13834 + /* make the generation obsolete */
13835 + if (au_ftest_hnjob(a->flags, GEN)) {
13838 + err = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
13840 + if (err && a->dentry)
13841 + hn_gen_by_name(a->dentry, isdir);
13842 + /* ignore this error */
13845 + /* make dir entries obsolete */
13846 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
13847 + struct au_vdir *vdir;
13849 + vdir = au_ivdir(a->inode);
13851 + vdir->vd_jiffy = 0;
13852 + /* IMustLock(a->inode); */
13853 + /* a->inode->i_version++; */
13856 + /* can do nothing but warn */
13857 + if (au_ftest_hnjob(a->flags, MNTPNT)
13859 + && d_mountpoint(a->dentry))
13860 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
13865 +/* ---------------------------------------------------------------------- */
13867 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
13868 + struct inode *dir)
13870 + struct dentry *dentry, *d, *parent;
13871 + struct qstr *dname;
13873 + parent = d_find_alias(dir);
13878 + spin_lock(&parent->d_lock);
13879 + list_for_each_entry(d, &parent->d_subdirs, d_u.d_child) {
13880 + /* AuDbg("%pd\n", d); */
13881 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
13882 + dname = &d->d_name;
13883 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
13884 + goto cont_unlock;
13888 + goto cont_unlock;
13889 + if (d_count(d)) {
13890 + dentry = dget_dlock(d);
13891 + spin_unlock(&d->d_lock);
13896 + spin_unlock(&d->d_lock);
13898 + spin_unlock(&parent->d_lock);
13902 + di_write_lock_child(dentry);
13907 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
13908 + aufs_bindex_t bindex, ino_t h_ino)
13910 + struct inode *inode;
13915 + err = au_xino_read(sb, bindex, h_ino, &ino);
13917 + inode = ilookup(sb, ino);
13921 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
13922 + pr_warn("wrong root branch\n");
13928 + ii_write_lock_child(inode);
13934 +static void au_hn_bh(void *_args)
13936 + struct au_hnotify_args *a = _args;
13937 + struct super_block *sb;
13938 + aufs_bindex_t bindex, bend, bfound;
13939 + unsigned char xino, try_iput;
13941 + struct inode *inode;
13943 + struct hn_job_args args;
13944 + struct dentry *dentry;
13945 + struct au_sbinfo *sbinfo;
13947 + AuDebugOn(!_args);
13948 + AuDebugOn(!a->h_dir);
13949 + AuDebugOn(!a->dir);
13950 + AuDebugOn(!a->mask);
13951 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
13952 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
13953 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
13958 + * do not lock a->dir->i_mutex here
13959 + * because of d_revalidate() may cause a deadlock.
13961 + sb = a->dir->i_sb;
13963 + sbinfo = au_sbi(sb);
13964 + AuDebugOn(!sbinfo);
13965 + si_write_lock(sb, AuLock_NOPLMW);
13967 + ii_read_lock_parent(a->dir);
13969 + bend = au_ibend(a->dir);
13970 + for (bindex = au_ibstart(a->dir); bindex <= bend; bindex++)
13971 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
13975 + ii_read_unlock(a->dir);
13976 + if (unlikely(bfound < 0))
13979 + xino = !!au_opt_test(au_mntflags(sb), XINO);
13981 + if (a->h_child_inode)
13982 + h_ino = a->h_child_inode->i_ino;
13984 + if (a->h_child_nlen
13985 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
13986 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
13987 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
13991 + inode = dentry->d_inode;
13992 + if (xino && !inode && h_ino
13993 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
13994 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
13995 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
13996 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
14000 + args.flags = a->flags[AuHn_CHILD];
14001 + args.dentry = dentry;
14002 + args.inode = inode;
14003 + args.h_inode = a->h_child_inode;
14004 + args.dir = a->dir;
14005 + args.h_dir = a->h_dir;
14006 + args.h_name = a->h_child_name;
14007 + args.h_nlen = a->h_child_nlen;
14008 + err = hn_job(&args);
14010 + if (au_di(dentry))
14011 + di_write_unlock(dentry);
14014 + if (inode && try_iput) {
14015 + ii_write_unlock(inode);
14019 + ii_write_lock_parent(a->dir);
14020 + args.flags = a->flags[AuHn_PARENT];
14021 + args.dentry = NULL;
14022 + args.inode = a->dir;
14023 + args.h_inode = a->h_dir;
14025 + args.h_dir = NULL;
14026 + args.h_name = NULL;
14028 + err = hn_job(&args);
14029 + ii_write_unlock(a->dir);
14032 + iput(a->h_child_inode);
14035 + si_write_unlock(sb);
14036 + au_nwt_done(&sbinfo->si_nowait);
14040 +/* ---------------------------------------------------------------------- */
14042 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
14043 + struct qstr *h_child_qstr, struct inode *h_child_inode)
14046 + unsigned int flags[AuHnLast], f;
14047 + unsigned char isdir, isroot, wh;
14048 + struct inode *dir;
14049 + struct au_hnotify_args *args;
14050 + char *p, *h_child_name;
14053 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
14054 + dir = igrab(hnotify->hn_aufs_inode);
14058 + isroot = (dir->i_ino == AUFS_ROOT_INO);
14060 + h_child_name = (void *)h_child_qstr->name;
14061 + len = h_child_qstr->len;
14062 + if (h_child_name) {
14063 + if (len > AUFS_WH_PFX_LEN
14064 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
14065 + h_child_name += AUFS_WH_PFX_LEN;
14066 + len -= AUFS_WH_PFX_LEN;
14072 + if (h_child_inode)
14073 + isdir = !!S_ISDIR(h_child_inode->i_mode);
14074 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
14075 + flags[AuHn_CHILD] = 0;
14077 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
14078 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
14079 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
14080 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
14081 + case FS_MOVED_FROM:
14082 + case FS_MOVED_TO:
14083 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
14084 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
14087 + AuDebugOn(!h_child_name || !h_child_inode);
14092 + * aufs never be able to get this child inode.
14093 + * revalidation should be in d_revalidate()
14094 + * by checking i_nlink, i_generation or d_unhashed().
14096 + AuDebugOn(!h_child_name);
14097 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
14098 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
14106 + h_child_inode = NULL;
14109 + /* iput() and kfree() will be called in au_hnotify() */
14110 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
14111 + if (unlikely(!args)) {
14112 + AuErr1("no memory\n");
14116 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
14117 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
14118 + args->mask = mask;
14120 + args->h_dir = igrab(h_dir);
14121 + if (h_child_inode)
14122 + h_child_inode = igrab(h_child_inode); /* can be NULL */
14123 + args->h_child_inode = h_child_inode;
14124 + args->h_child_nlen = len;
14126 + p = (void *)args;
14127 + p += sizeof(*args);
14128 + memcpy(p, h_child_name, len);
14133 + if (!dir->i_nlink)
14135 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
14136 + if (unlikely(err)) {
14137 + pr_err("wkq %d\n", err);
14138 + iput(args->h_child_inode);
14139 + iput(args->h_dir);
14148 +/* ---------------------------------------------------------------------- */
14150 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
14154 + AuDebugOn(!(udba & AuOptMask_UDBA));
14157 + if (au_hnotify_op.reset_br)
14158 + err = au_hnotify_op.reset_br(udba, br, perm);
14163 +int au_hnotify_init_br(struct au_branch *br, int perm)
14168 + if (au_hnotify_op.init_br)
14169 + err = au_hnotify_op.init_br(br, perm);
14174 +void au_hnotify_fin_br(struct au_branch *br)
14176 + if (au_hnotify_op.fin_br)
14177 + au_hnotify_op.fin_br(br);
14180 +static void au_hn_destroy_cache(void)
14182 + kmem_cache_destroy(au_cachep[AuCache_HNOTIFY]);
14183 + au_cachep[AuCache_HNOTIFY] = NULL;
14186 +int __init au_hnotify_init(void)
14191 + au_cachep[AuCache_HNOTIFY] = AuCache(au_hnotify);
14192 + if (au_cachep[AuCache_HNOTIFY]) {
14194 + if (au_hnotify_op.init)
14195 + err = au_hnotify_op.init();
14196 + if (unlikely(err))
14197 + au_hn_destroy_cache();
14203 +void au_hnotify_fin(void)
14205 + if (au_hnotify_op.fin)
14206 + au_hnotify_op.fin();
14207 + /* cf. au_cache_fin() */
14208 + if (au_cachep[AuCache_HNOTIFY])
14209 + au_hn_destroy_cache();
14211 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
14212 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
14213 +++ linux/fs/aufs/iinfo.c 2014-01-20 20:16:14.739463504 +0100
14216 + * Copyright (C) 2005-2014 Junjiro R. Okajima
14218 + * This program, aufs is free software; you can redistribute it and/or modify
14219 + * it under the terms of the GNU General Public License as published by
14220 + * the Free Software Foundation; either version 2 of the License, or
14221 + * (at your option) any later version.
14223 + * This program is distributed in the hope that it will be useful,
14224 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14225 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14226 + * GNU General Public License for more details.
14228 + * You should have received a copy of the GNU General Public License
14229 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14233 + * inode private data
14238 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
14240 + struct inode *h_inode;
14242 + IiMustAnyLock(inode);
14244 + h_inode = au_ii(inode)->ii_hinode[0 + bindex].hi_inode;
14245 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
14249 +/* todo: hard/soft set? */
14250 +void au_hiput(struct au_hinode *hinode)
14252 + au_hn_free(hinode);
14253 + dput(hinode->hi_whdentry);
14254 + iput(hinode->hi_inode);
14257 +unsigned int au_hi_flags(struct inode *inode, int isdir)
14259 + unsigned int flags;
14260 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
14263 + if (au_opt_test(mnt_flags, XINO))
14264 + au_fset_hi(flags, XINO);
14265 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
14266 + au_fset_hi(flags, HNOTIFY);
14270 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
14271 + struct inode *h_inode, unsigned int flags)
14273 + struct au_hinode *hinode;
14274 + struct inode *hi;
14275 + struct au_iinfo *iinfo = au_ii(inode);
14277 + IiMustWriteLock(inode);
14279 + hinode = iinfo->ii_hinode + bindex;
14280 + hi = hinode->hi_inode;
14281 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
14284 + au_hiput(hinode);
14285 + hinode->hi_inode = h_inode;
14288 + struct super_block *sb = inode->i_sb;
14289 + struct au_branch *br;
14291 + AuDebugOn(inode->i_mode
14292 + && (h_inode->i_mode & S_IFMT)
14293 + != (inode->i_mode & S_IFMT));
14294 + if (bindex == iinfo->ii_bstart)
14295 + au_cpup_igen(inode, h_inode);
14296 + br = au_sbr(sb, bindex);
14297 + hinode->hi_id = br->br_id;
14298 + if (au_ftest_hi(flags, XINO)) {
14299 + err = au_xino_write(sb, bindex, h_inode->i_ino,
14301 + if (unlikely(err))
14302 + AuIOErr1("failed au_xino_write() %d\n", err);
14305 + if (au_ftest_hi(flags, HNOTIFY)
14306 + && au_br_hnotifyable(br->br_perm)) {
14307 + err = au_hn_alloc(hinode, inode);
14308 + if (unlikely(err))
14309 + AuIOErr1("au_hn_alloc() %d\n", err);
14314 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
14315 + struct dentry *h_wh)
14317 + struct au_hinode *hinode;
14319 + IiMustWriteLock(inode);
14321 + hinode = au_ii(inode)->ii_hinode + bindex;
14322 + AuDebugOn(hinode->hi_whdentry);
14323 + hinode->hi_whdentry = h_wh;
14326 +void au_update_iigen(struct inode *inode, int half)
14328 + struct au_iinfo *iinfo;
14329 + struct au_iigen *iigen;
14330 + unsigned int sigen;
14332 + sigen = au_sigen(inode->i_sb);
14333 + iinfo = au_ii(inode);
14334 + iigen = &iinfo->ii_generation;
14335 + spin_lock(&iinfo->ii_genspin);
14336 + iigen->ig_generation = sigen;
14338 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
14340 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
14341 + spin_unlock(&iinfo->ii_genspin);
14344 +/* it may be called at remount time, too */
14345 +void au_update_ibrange(struct inode *inode, int do_put_zero)
14347 + struct au_iinfo *iinfo;
14348 + aufs_bindex_t bindex, bend;
14350 + iinfo = au_ii(inode);
14354 + IiMustWriteLock(inode);
14356 + if (do_put_zero && iinfo->ii_bstart >= 0) {
14357 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
14359 + struct inode *h_i;
14361 + h_i = iinfo->ii_hinode[0 + bindex].hi_inode;
14362 + if (h_i && !h_i->i_nlink)
14363 + au_set_h_iptr(inode, bindex, NULL, 0);
14367 + iinfo->ii_bstart = -1;
14368 + iinfo->ii_bend = -1;
14369 + bend = au_sbend(inode->i_sb);
14370 + for (bindex = 0; bindex <= bend; bindex++)
14371 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
14372 + iinfo->ii_bstart = bindex;
14375 + if (iinfo->ii_bstart >= 0)
14376 + for (bindex = bend; bindex >= iinfo->ii_bstart; bindex--)
14377 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
14378 + iinfo->ii_bend = bindex;
14381 + AuDebugOn(iinfo->ii_bstart > iinfo->ii_bend);
14384 +/* ---------------------------------------------------------------------- */
14386 +void au_icntnr_init_once(void *_c)
14388 + struct au_icntnr *c = _c;
14389 + struct au_iinfo *iinfo = &c->iinfo;
14390 + static struct lock_class_key aufs_ii;
14392 + spin_lock_init(&iinfo->ii_genspin);
14393 + au_rw_init(&iinfo->ii_rwsem);
14394 + au_rw_class(&iinfo->ii_rwsem, &aufs_ii);
14395 + inode_init_once(&c->vfs_inode);
14398 +int au_iinfo_init(struct inode *inode)
14400 + struct au_iinfo *iinfo;
14401 + struct super_block *sb;
14404 + sb = inode->i_sb;
14405 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
14406 + nbr = au_sbend(sb) + 1;
14407 + if (unlikely(nbr <= 0))
14409 + iinfo->ii_hinode = kcalloc(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
14410 + if (iinfo->ii_hinode) {
14411 + au_ninodes_inc(sb);
14412 + for (i = 0; i < nbr; i++)
14413 + iinfo->ii_hinode[i].hi_id = -1;
14415 + iinfo->ii_generation.ig_generation = au_sigen(sb);
14416 + iinfo->ii_bstart = -1;
14417 + iinfo->ii_bend = -1;
14418 + iinfo->ii_vdir = NULL;
14424 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr)
14427 + struct au_hinode *hip;
14429 + AuRwMustWriteLock(&iinfo->ii_rwsem);
14432 + sz = sizeof(*hip) * (iinfo->ii_bend + 1);
14434 + sz = sizeof(*hip);
14435 + hip = au_kzrealloc(iinfo->ii_hinode, sz, sizeof(*hip) * nbr, GFP_NOFS);
14437 + iinfo->ii_hinode = hip;
14444 +void au_iinfo_fin(struct inode *inode)
14446 + struct au_iinfo *iinfo;
14447 + struct au_hinode *hi;
14448 + struct super_block *sb;
14449 + aufs_bindex_t bindex, bend;
14450 + const unsigned char unlinked = !inode->i_nlink;
14452 + iinfo = au_ii(inode);
14453 + /* bad_inode case */
14457 + sb = inode->i_sb;
14458 + au_ninodes_dec(sb);
14459 + if (si_pid_test(sb))
14460 + au_xino_delete_inode(inode, unlinked);
14463 + * it is safe to hide the dependency between sbinfo and
14467 + si_noflush_read_lock(sb);
14468 + au_xino_delete_inode(inode, unlinked);
14469 + si_read_unlock(sb);
14473 + if (iinfo->ii_vdir)
14474 + au_vdir_free(iinfo->ii_vdir);
14476 + bindex = iinfo->ii_bstart;
14477 + if (bindex >= 0) {
14478 + hi = iinfo->ii_hinode + bindex;
14479 + bend = iinfo->ii_bend;
14480 + while (bindex++ <= bend) {
14481 + if (hi->hi_inode)
14486 + kfree(iinfo->ii_hinode);
14487 + iinfo->ii_hinode = NULL;
14488 + AuRwDestroy(&iinfo->ii_rwsem);
14490 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
14491 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
14492 +++ linux/fs/aufs/inode.c 2014-01-20 20:16:14.739463504 +0100
14495 + * Copyright (C) 2005-2014 Junjiro R. Okajima
14497 + * This program, aufs is free software; you can redistribute it and/or modify
14498 + * it under the terms of the GNU General Public License as published by
14499 + * the Free Software Foundation; either version 2 of the License, or
14500 + * (at your option) any later version.
14502 + * This program is distributed in the hope that it will be useful,
14503 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14504 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14505 + * GNU General Public License for more details.
14507 + * You should have received a copy of the GNU General Public License
14508 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14512 + * inode functions
14517 +struct inode *au_igrab(struct inode *inode)
14520 + AuDebugOn(!atomic_read(&inode->i_count));
14526 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
14528 + au_cpup_attr_all(inode, /*force*/0);
14529 + au_update_iigen(inode, /*half*/1);
14531 + inode->i_version++;
14534 +static int au_ii_refresh(struct inode *inode, int *update)
14538 + aufs_bindex_t bindex, new_bindex;
14539 + struct super_block *sb;
14540 + struct au_iinfo *iinfo;
14541 + struct au_hinode *p, *q, tmp;
14543 + IiMustWriteLock(inode);
14546 + sb = inode->i_sb;
14547 + type = inode->i_mode & S_IFMT;
14548 + iinfo = au_ii(inode);
14549 + err = au_ii_realloc(iinfo, au_sbend(sb) + 1);
14550 + if (unlikely(err))
14553 + AuDebugOn(iinfo->ii_bstart < 0);
14554 + p = iinfo->ii_hinode + iinfo->ii_bstart;
14555 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
14557 + if (!p->hi_inode)
14560 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
14561 + new_bindex = au_br_index(sb, p->hi_id);
14562 + if (new_bindex == bindex)
14565 + if (new_bindex < 0) {
14568 + p->hi_inode = NULL;
14572 + if (new_bindex < iinfo->ii_bstart)
14573 + iinfo->ii_bstart = new_bindex;
14574 + if (iinfo->ii_bend < new_bindex)
14575 + iinfo->ii_bend = new_bindex;
14576 + /* swap two lower inode, and loop again */
14577 + q = iinfo->ii_hinode + new_bindex;
14581 + if (tmp.hi_inode) {
14586 + au_update_ibrange(inode, /*do_put_zero*/0);
14587 + e = au_dy_irefresh(inode);
14588 + if (unlikely(e && !err))
14596 +int au_refresh_hinode_self(struct inode *inode)
14600 + err = au_ii_refresh(inode, &update);
14602 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
14608 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
14610 + int err, e, update;
14611 + unsigned int flags;
14613 + aufs_bindex_t bindex, bend;
14614 + unsigned char isdir;
14615 + struct au_hinode *p;
14616 + struct au_iinfo *iinfo;
14618 + err = au_ii_refresh(inode, &update);
14619 + if (unlikely(err))
14623 + iinfo = au_ii(inode);
14624 + p = iinfo->ii_hinode + iinfo->ii_bstart;
14625 + mode = (inode->i_mode & S_IFMT);
14626 + isdir = S_ISDIR(mode);
14627 + flags = au_hi_flags(inode, isdir);
14628 + bend = au_dbend(dentry);
14629 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
14630 + struct inode *h_i;
14631 + struct dentry *h_d;
14633 + h_d = au_h_dptr(dentry, bindex);
14634 + if (!h_d || !h_d->d_inode)
14637 + AuDebugOn(mode != (h_d->d_inode->i_mode & S_IFMT));
14638 + if (iinfo->ii_bstart <= bindex && bindex <= iinfo->ii_bend) {
14639 + h_i = au_h_iptr(inode, bindex);
14641 + if (h_i == h_d->d_inode)
14647 + if (bindex < iinfo->ii_bstart)
14648 + iinfo->ii_bstart = bindex;
14649 + if (iinfo->ii_bend < bindex)
14650 + iinfo->ii_bend = bindex;
14651 + au_set_h_iptr(inode, bindex, au_igrab(h_d->d_inode), flags);
14654 + au_update_ibrange(inode, /*do_put_zero*/0);
14655 + e = au_dy_irefresh(inode);
14656 + if (unlikely(e && !err))
14659 + au_refresh_hinode_attr(inode, update && isdir);
14666 +static int set_inode(struct inode *inode, struct dentry *dentry)
14669 + unsigned int flags;
14671 + aufs_bindex_t bindex, bstart, btail;
14672 + unsigned char isdir;
14673 + struct dentry *h_dentry;
14674 + struct inode *h_inode;
14675 + struct au_iinfo *iinfo;
14677 + IiMustWriteLock(inode);
14681 + bstart = au_dbstart(dentry);
14682 + h_inode = au_h_dptr(dentry, bstart)->d_inode;
14683 + mode = h_inode->i_mode;
14684 + switch (mode & S_IFMT) {
14686 + btail = au_dbtail(dentry);
14687 + inode->i_op = &aufs_iop;
14688 + inode->i_fop = &aufs_file_fop;
14689 + err = au_dy_iaop(inode, bstart, h_inode);
14690 + if (unlikely(err))
14695 + btail = au_dbtaildir(dentry);
14696 + inode->i_op = &aufs_dir_iop;
14697 + inode->i_fop = &aufs_dir_fop;
14700 + btail = au_dbtail(dentry);
14701 + inode->i_op = &aufs_symlink_iop;
14707 + btail = au_dbtail(dentry);
14708 + inode->i_op = &aufs_iop;
14709 + au_init_special_fop(inode, mode, h_inode->i_rdev);
14712 + AuIOErr("Unknown file type 0%o\n", mode);
14717 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
14718 + flags = au_hi_flags(inode, isdir);
14719 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
14720 + && au_ftest_hi(flags, HNOTIFY)
14721 + && dentry->d_name.len > AUFS_WH_PFX_LEN
14722 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
14723 + au_fclr_hi(flags, HNOTIFY);
14724 + iinfo = au_ii(inode);
14725 + iinfo->ii_bstart = bstart;
14726 + iinfo->ii_bend = btail;
14727 + for (bindex = bstart; bindex <= btail; bindex++) {
14728 + h_dentry = au_h_dptr(dentry, bindex);
14730 + au_set_h_iptr(inode, bindex,
14731 + au_igrab(h_dentry->d_inode), flags);
14733 + au_cpup_attr_all(inode, /*force*/1);
14740 + * successful returns with iinfo write_locked
14742 + * zero: success, matched
14743 + * plus: no error, but unmatched
14745 +static int reval_inode(struct inode *inode, struct dentry *dentry)
14748 + unsigned int gen;
14749 + struct au_iigen iigen;
14750 + aufs_bindex_t bindex, bend;
14751 + struct inode *h_inode, *h_dinode;
14754 + * before this function, if aufs got any iinfo lock, it must be only
14755 + * one, the parent dir.
14756 + * it can happen by UDBA and the obsoleted inode number.
14759 + if (unlikely(inode->i_ino == parent_ino(dentry)))
14763 + ii_write_lock_new_child(inode);
14764 + h_dinode = au_h_dptr(dentry, au_dbstart(dentry))->d_inode;
14765 + bend = au_ibend(inode);
14766 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
14767 + h_inode = au_h_iptr(inode, bindex);
14768 + if (!h_inode || h_inode != h_dinode)
14772 + gen = au_iigen(inode, &iigen);
14773 + if (gen == au_digen(dentry)
14774 + && !au_ig_ftest(iigen.ig_flags, HALF_REFRESHED))
14777 + /* fully refresh inode using dentry */
14778 + err = au_refresh_hinode(inode, dentry);
14780 + au_update_iigen(inode, /*half*/0);
14784 + if (unlikely(err))
14785 + ii_write_unlock(inode);
14790 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
14791 + unsigned int d_type, ino_t *ino)
14794 + struct mutex *mtx;
14796 + /* prevent hardlinked inode number from race condition */
14798 + if (d_type != DT_DIR) {
14799 + mtx = &au_sbr(sb, bindex)->br_xino.xi_nondir_mtx;
14802 + err = au_xino_read(sb, bindex, h_ino, ino);
14803 + if (unlikely(err))
14808 + *ino = au_xino_new_ino(sb);
14809 + if (unlikely(!*ino))
14811 + err = au_xino_write(sb, bindex, h_ino, *ino);
14812 + if (unlikely(err))
14818 + mutex_unlock(mtx);
14822 +/* successful returns with iinfo write_locked */
14823 +/* todo: return with unlocked? */
14824 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
14826 + struct inode *inode, *h_inode;
14827 + struct dentry *h_dentry;
14828 + struct super_block *sb;
14829 + struct mutex *mtx;
14830 + ino_t h_ino, ino;
14832 + aufs_bindex_t bstart;
14834 + sb = dentry->d_sb;
14835 + bstart = au_dbstart(dentry);
14836 + h_dentry = au_h_dptr(dentry, bstart);
14837 + h_inode = h_dentry->d_inode;
14838 + h_ino = h_inode->i_ino;
14841 + * stop 'race'-ing between hardlinks under different
14845 + if (!S_ISDIR(h_inode->i_mode))
14846 + mtx = &au_sbr(sb, bstart)->br_xino.xi_nondir_mtx;
14851 + err = au_xino_read(sb, bstart, h_ino, &ino);
14852 + inode = ERR_PTR(err);
14853 + if (unlikely(err))
14857 + ino = au_xino_new_ino(sb);
14858 + if (unlikely(!ino)) {
14859 + inode = ERR_PTR(-EIO);
14864 + AuDbg("i%lu\n", (unsigned long)ino);
14865 + inode = au_iget_locked(sb, ino);
14866 + err = PTR_ERR(inode);
14867 + if (IS_ERR(inode))
14870 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
14871 + if (inode->i_state & I_NEW) {
14872 + /* verbose coding for lock class name */
14873 + if (unlikely(S_ISLNK(h_inode->i_mode)))
14874 + au_rw_class(&au_ii(inode)->ii_rwsem,
14875 + au_lc_key + AuLcSymlink_IIINFO);
14876 + else if (unlikely(S_ISDIR(h_inode->i_mode)))
14877 + au_rw_class(&au_ii(inode)->ii_rwsem,
14878 + au_lc_key + AuLcDir_IIINFO);
14879 + else /* likely */
14880 + au_rw_class(&au_ii(inode)->ii_rwsem,
14881 + au_lc_key + AuLcNonDir_IIINFO);
14883 + ii_write_lock_new_child(inode);
14884 + err = set_inode(inode, dentry);
14886 + unlock_new_inode(inode);
14887 + goto out; /* success */
14891 + * iget_failed() calls iput(), but we need to call
14892 + * ii_write_unlock() after iget_failed(). so dirty hack for
14895 + atomic_inc(&inode->i_count);
14896 + iget_failed(inode);
14897 + ii_write_unlock(inode);
14898 + au_xino_write(sb, bstart, h_ino, /*ino*/0);
14899 + /* ignore this error */
14901 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
14903 + * horrible race condition between lookup, readdir and copyup
14904 + * (or something).
14907 + mutex_unlock(mtx);
14908 + err = reval_inode(inode, dentry);
14909 + if (unlikely(err < 0)) {
14916 + goto out; /* success */
14921 + if (unlikely(au_test_fs_unique_ino(h_dentry->d_inode)))
14922 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
14923 + " b%d, %s, %pd, hi%lu, i%lu.\n",
14924 + bstart, au_sbtype(h_dentry->d_sb), dentry,
14925 + (unsigned long)h_ino, (unsigned long)ino);
14927 + err = au_xino_write(sb, bstart, h_ino, /*ino*/0);
14931 + mutex_unlock(mtx);
14937 + inode = ERR_PTR(err);
14940 + mutex_unlock(mtx);
14944 +/* ---------------------------------------------------------------------- */
14946 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
14947 + struct inode *inode)
14951 + err = au_br_rdonly(au_sbr(sb, bindex));
14953 + /* pseudo-link after flushed may happen out of bounds */
14956 + && au_ibstart(inode) <= bindex
14957 + && bindex <= au_ibend(inode)) {
14959 + * permission check is unnecessary since vfsub routine
14960 + * will be called later
14962 + struct inode *hi = au_h_iptr(inode, bindex);
14964 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
14970 +int au_test_h_perm(struct inode *h_inode, int mask)
14972 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
14974 + return inode_permission(h_inode, mask);
14977 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
14979 + if (au_test_nfs(h_inode->i_sb)
14980 + && (mask & MAY_WRITE)
14981 + && S_ISDIR(h_inode->i_mode))
14982 + mask |= MAY_READ; /* force permission check */
14983 + return au_test_h_perm(h_inode, mask);
14985 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
14986 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
14987 +++ linux/fs/aufs/inode.h 2014-01-20 20:16:14.739463504 +0100
14990 + * Copyright (C) 2005-2014 Junjiro R. Okajima
14992 + * This program, aufs is free software; you can redistribute it and/or modify
14993 + * it under the terms of the GNU General Public License as published by
14994 + * the Free Software Foundation; either version 2 of the License, or
14995 + * (at your option) any later version.
14997 + * This program is distributed in the hope that it will be useful,
14998 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14999 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15000 + * GNU General Public License for more details.
15002 + * You should have received a copy of the GNU General Public License
15003 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15007 + * inode operations
15010 +#ifndef __AUFS_INODE_H__
15011 +#define __AUFS_INODE_H__
15015 +#include <linux/fsnotify.h>
15016 +#include "rwsem.h"
15020 +struct au_hnotify {
15021 +#ifdef CONFIG_AUFS_HNOTIFY
15022 +#ifdef CONFIG_AUFS_HFSNOTIFY
15023 + /* never use fsnotify_add_vfsmount_mark() */
15024 + struct fsnotify_mark hn_mark;
15026 + struct inode *hn_aufs_inode; /* no get/put */
15028 +} ____cacheline_aligned_in_smp;
15030 +struct au_hinode {
15031 + struct inode *hi_inode;
15032 + aufs_bindex_t hi_id;
15033 +#ifdef CONFIG_AUFS_HNOTIFY
15034 + struct au_hnotify *hi_notify;
15037 + /* reference to the copied-up whiteout with get/put */
15038 + struct dentry *hi_whdentry;
15042 +#define AuIG_HALF_REFRESHED 1
15043 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
15044 +#define au_ig_fset(flags, name) \
15045 + do { (flags) |= AuIG_##name; } while (0)
15046 +#define au_ig_fclr(flags, name) \
15047 + do { (flags) &= ~AuIG_##name; } while (0)
15050 + __u32 ig_generation, ig_flags;
15055 + spinlock_t ii_genspin;
15056 + struct au_iigen ii_generation;
15057 + struct super_block *ii_hsb1; /* no get/put */
15059 + struct au_rwsem ii_rwsem;
15060 + aufs_bindex_t ii_bstart, ii_bend;
15062 + struct au_hinode *ii_hinode;
15063 + struct au_vdir *ii_vdir;
15066 +struct au_icntnr {
15067 + struct au_iinfo iinfo;
15068 + struct inode vfs_inode;
15069 +} ____cacheline_aligned_in_smp;
15071 +/* au_pin flags */
15072 +#define AuPin_DI_LOCKED 1
15073 +#define AuPin_MNT_WRITE (1 << 1)
15074 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
15075 +#define au_fset_pin(flags, name) \
15076 + do { (flags) |= AuPin_##name; } while (0)
15077 +#define au_fclr_pin(flags, name) \
15078 + do { (flags) &= ~AuPin_##name; } while (0)
15082 + struct dentry *dentry;
15083 + unsigned int udba;
15084 + unsigned char lsc_di, lsc_hi, flags;
15085 + aufs_bindex_t bindex;
15088 + struct dentry *parent;
15089 + struct au_hinode *hdir;
15090 + struct vfsmount *h_mnt;
15092 + /* temporary unlock/relock for copyup */
15093 + struct dentry *h_dentry, *h_parent;
15094 + struct au_branch *br;
15095 + struct task_struct *task;
15098 +void au_pin_hdir_unlock(struct au_pin *p);
15099 +int au_pin_hdir_relock(struct au_pin *p);
15100 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task);
15101 +void au_pin_hdir_acquire_nest(struct au_pin *p);
15102 +void au_pin_hdir_release(struct au_pin *p);
15104 +/* ---------------------------------------------------------------------- */
15106 +static inline struct au_iinfo *au_ii(struct inode *inode)
15108 + struct au_iinfo *iinfo;
15110 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
15111 + if (iinfo->ii_hinode)
15113 + return NULL; /* debugging bad_inode case */
15116 +/* ---------------------------------------------------------------------- */
15119 +struct inode *au_igrab(struct inode *inode);
15120 +int au_refresh_hinode_self(struct inode *inode);
15121 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
15122 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
15123 + unsigned int d_type, ino_t *ino);
15124 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
15125 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
15126 + struct inode *inode);
15127 +int au_test_h_perm(struct inode *h_inode, int mask);
15128 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
15130 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
15131 + ino_t h_ino, unsigned int d_type, ino_t *ino)
15133 +#ifdef CONFIG_AUFS_SHWH
15134 + return au_ino(sb, bindex, h_ino, d_type, ino);
15141 +extern struct inode_operations aufs_iop, aufs_symlink_iop, aufs_dir_iop;
15143 +/* au_wr_dir flags */
15144 +#define AuWrDir_ADD_ENTRY 1
15145 +#define AuWrDir_TMP_WHENTRY (1 << 1)
15146 +#define AuWrDir_ISDIR (1 << 2)
15147 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
15148 +#define au_fset_wrdir(flags, name) \
15149 + do { (flags) |= AuWrDir_##name; } while (0)
15150 +#define au_fclr_wrdir(flags, name) \
15151 + do { (flags) &= ~AuWrDir_##name; } while (0)
15153 +struct au_wr_dir_args {
15154 + aufs_bindex_t force_btgt;
15155 + unsigned char flags;
15157 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
15158 + struct au_wr_dir_args *args);
15160 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
15161 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
15162 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
15163 + unsigned int udba, unsigned char flags);
15164 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
15165 + unsigned int udba, unsigned char flags) __must_check;
15166 +int au_do_pin(struct au_pin *pin) __must_check;
15167 +void au_unpin(struct au_pin *pin);
15170 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
15171 + struct dentry *h_parent, int isdir);
15172 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
15174 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
15175 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
15177 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
15178 + struct dentry *dentry);
15179 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
15182 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
15183 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
15184 + struct dentry *h_parent, int isdir);
15185 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
15186 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
15189 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
15190 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
15191 + struct inode *dir, struct dentry *dentry);
15194 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
15195 +void au_hiput(struct au_hinode *hinode);
15196 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
15197 + struct dentry *h_wh);
15198 +unsigned int au_hi_flags(struct inode *inode, int isdir);
15200 +/* hinode flags */
15201 +#define AuHi_XINO 1
15202 +#define AuHi_HNOTIFY (1 << 1)
15203 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
15204 +#define au_fset_hi(flags, name) \
15205 + do { (flags) |= AuHi_##name; } while (0)
15206 +#define au_fclr_hi(flags, name) \
15207 + do { (flags) &= ~AuHi_##name; } while (0)
15209 +#ifndef CONFIG_AUFS_HNOTIFY
15210 +#undef AuHi_HNOTIFY
15211 +#define AuHi_HNOTIFY 0
15214 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
15215 + struct inode *h_inode, unsigned int flags);
15217 +void au_update_iigen(struct inode *inode, int half);
15218 +void au_update_ibrange(struct inode *inode, int do_put_zero);
15220 +void au_icntnr_init_once(void *_c);
15221 +int au_iinfo_init(struct inode *inode);
15222 +void au_iinfo_fin(struct inode *inode);
15223 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr);
15225 +#ifdef CONFIG_PROC_FS
15227 +int au_plink_maint(struct super_block *sb, int flags);
15228 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
15229 +int au_plink_maint_enter(struct super_block *sb);
15230 +#ifdef CONFIG_AUFS_DEBUG
15231 +void au_plink_list(struct super_block *sb);
15233 +AuStubVoid(au_plink_list, struct super_block *sb)
15235 +int au_plink_test(struct inode *inode);
15236 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
15237 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
15238 + struct dentry *h_dentry);
15239 +void au_plink_put(struct super_block *sb, int verbose);
15240 +void au_plink_clean(struct super_block *sb, int verbose);
15241 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
15243 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
15244 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
15245 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
15246 +AuStubVoid(au_plink_list, struct super_block *sb);
15247 +AuStubInt0(au_plink_test, struct inode *inode);
15248 +AuStub(struct dentry *, au_plink_lkup, return NULL,
15249 + struct inode *inode, aufs_bindex_t bindex);
15250 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
15251 + struct dentry *h_dentry);
15252 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
15253 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
15254 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
15255 +#endif /* CONFIG_PROC_FS */
15257 +/* ---------------------------------------------------------------------- */
15259 +/* lock subclass for iinfo */
15261 + AuLsc_II_CHILD, /* child first */
15262 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
15263 + AuLsc_II_CHILD3, /* copyup dirs */
15264 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
15265 + AuLsc_II_PARENT2,
15266 + AuLsc_II_PARENT3, /* copyup dirs */
15267 + AuLsc_II_NEW_CHILD
15271 + * ii_read_lock_child, ii_write_lock_child,
15272 + * ii_read_lock_child2, ii_write_lock_child2,
15273 + * ii_read_lock_child3, ii_write_lock_child3,
15274 + * ii_read_lock_parent, ii_write_lock_parent,
15275 + * ii_read_lock_parent2, ii_write_lock_parent2,
15276 + * ii_read_lock_parent3, ii_write_lock_parent3,
15277 + * ii_read_lock_new_child, ii_write_lock_new_child,
15279 +#define AuReadLockFunc(name, lsc) \
15280 +static inline void ii_read_lock_##name(struct inode *i) \
15282 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
15285 +#define AuWriteLockFunc(name, lsc) \
15286 +static inline void ii_write_lock_##name(struct inode *i) \
15288 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
15291 +#define AuRWLockFuncs(name, lsc) \
15292 + AuReadLockFunc(name, lsc) \
15293 + AuWriteLockFunc(name, lsc)
15295 +AuRWLockFuncs(child, CHILD);
15296 +AuRWLockFuncs(child2, CHILD2);
15297 +AuRWLockFuncs(child3, CHILD3);
15298 +AuRWLockFuncs(parent, PARENT);
15299 +AuRWLockFuncs(parent2, PARENT2);
15300 +AuRWLockFuncs(parent3, PARENT3);
15301 +AuRWLockFuncs(new_child, NEW_CHILD);
15303 +#undef AuReadLockFunc
15304 +#undef AuWriteLockFunc
15305 +#undef AuRWLockFuncs
15308 + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock
15310 +AuSimpleUnlockRwsemFuncs(ii, struct inode *i, &au_ii(i)->ii_rwsem);
15312 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
15313 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
15314 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
15316 +/* ---------------------------------------------------------------------- */
15318 +static inline void au_icntnr_init(struct au_icntnr *c)
15320 +#ifdef CONFIG_AUFS_DEBUG
15321 + c->vfs_inode.i_mode = 0;
15325 +static inline unsigned int au_iigen(struct inode *inode, struct au_iigen *iigen)
15327 + unsigned int gen;
15328 + struct au_iinfo *iinfo;
15330 + iinfo = au_ii(inode);
15331 + spin_lock(&iinfo->ii_genspin);
15333 + *iigen = iinfo->ii_generation;
15334 + gen = iinfo->ii_generation.ig_generation;
15335 + spin_unlock(&iinfo->ii_genspin);
15340 +/* tiny test for inode number */
15341 +/* tmpfs generation is too rough */
15342 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
15344 + struct au_iinfo *iinfo;
15346 + iinfo = au_ii(inode);
15347 + AuRwMustAnyLock(&iinfo->ii_rwsem);
15348 + return !(iinfo->ii_hsb1 == h_inode->i_sb
15349 + && iinfo->ii_higen == h_inode->i_generation);
15352 +static inline void au_iigen_dec(struct inode *inode)
15354 + struct au_iinfo *iinfo;
15356 + iinfo = au_ii(inode);
15357 + spin_lock(&iinfo->ii_genspin);
15358 + iinfo->ii_generation.ig_generation--;
15359 + spin_unlock(&iinfo->ii_genspin);
15362 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
15367 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
15373 +/* ---------------------------------------------------------------------- */
15375 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
15376 + aufs_bindex_t bindex)
15378 + IiMustAnyLock(inode);
15379 + return au_ii(inode)->ii_hinode[0 + bindex].hi_id;
15382 +static inline aufs_bindex_t au_ibstart(struct inode *inode)
15384 + IiMustAnyLock(inode);
15385 + return au_ii(inode)->ii_bstart;
15388 +static inline aufs_bindex_t au_ibend(struct inode *inode)
15390 + IiMustAnyLock(inode);
15391 + return au_ii(inode)->ii_bend;
15394 +static inline struct au_vdir *au_ivdir(struct inode *inode)
15396 + IiMustAnyLock(inode);
15397 + return au_ii(inode)->ii_vdir;
15400 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
15402 + IiMustAnyLock(inode);
15403 + return au_ii(inode)->ii_hinode[0 + bindex].hi_whdentry;
15406 +static inline void au_set_ibstart(struct inode *inode, aufs_bindex_t bindex)
15408 + IiMustWriteLock(inode);
15409 + au_ii(inode)->ii_bstart = bindex;
15412 +static inline void au_set_ibend(struct inode *inode, aufs_bindex_t bindex)
15414 + IiMustWriteLock(inode);
15415 + au_ii(inode)->ii_bend = bindex;
15418 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
15420 + IiMustWriteLock(inode);
15421 + au_ii(inode)->ii_vdir = vdir;
15424 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
15426 + IiMustAnyLock(inode);
15427 + return au_ii(inode)->ii_hinode + bindex;
15430 +/* ---------------------------------------------------------------------- */
15432 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
15435 + return pin->parent;
15439 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
15441 + if (pin && pin->hdir)
15442 + return pin->hdir->hi_inode;
15446 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
15449 + return pin->hdir;
15453 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
15456 + pin->dentry = dentry;
15459 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
15460 + unsigned char lflag)
15464 + au_fset_pin(pin->flags, DI_LOCKED);
15466 + au_fclr_pin(pin->flags, DI_LOCKED);
15470 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
15473 + dput(pin->parent);
15474 + pin->parent = dget(parent);
15478 +/* ---------------------------------------------------------------------- */
15481 +#ifdef CONFIG_AUFS_HNOTIFY
15482 +struct au_hnotify_op {
15483 + void (*ctl)(struct au_hinode *hinode, int do_set);
15484 + int (*alloc)(struct au_hinode *hinode);
15487 + * if it returns true, the the caller should free hinode->hi_notify,
15488 + * otherwise ->free() frees it.
15490 + int (*free)(struct au_hinode *hinode,
15491 + struct au_hnotify *hn) __must_check;
15493 + void (*fin)(void);
15494 + int (*init)(void);
15496 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
15497 + void (*fin_br)(struct au_branch *br);
15498 + int (*init_br)(struct au_branch *br, int perm);
15502 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
15503 +void au_hn_free(struct au_hinode *hinode);
15504 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
15505 +void au_hn_reset(struct inode *inode, unsigned int flags);
15506 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
15507 + struct qstr *h_child_qstr, struct inode *h_child_inode);
15508 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
15509 +int au_hnotify_init_br(struct au_branch *br, int perm);
15510 +void au_hnotify_fin_br(struct au_branch *br);
15511 +int __init au_hnotify_init(void);
15512 +void au_hnotify_fin(void);
15515 +extern const struct au_hnotify_op au_hnotify_op;
15518 +void au_hn_init(struct au_hinode *hinode)
15520 + hinode->hi_notify = NULL;
15523 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
15525 + return hinode->hi_notify;
15530 +int au_hn_alloc(struct au_hinode *hinode __maybe_unused,
15531 + struct inode *inode __maybe_unused)
15533 + return -EOPNOTSUPP;
15536 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
15541 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
15542 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
15543 + int do_set __maybe_unused)
15544 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
15545 + unsigned int flags __maybe_unused)
15546 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
15547 + struct au_branch *br __maybe_unused,
15548 + int perm __maybe_unused)
15549 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
15550 + int perm __maybe_unused)
15551 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
15552 +AuStubInt0(__init au_hnotify_init, void)
15553 +AuStubVoid(au_hnotify_fin, void)
15554 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
15555 +#endif /* CONFIG_AUFS_HNOTIFY */
15557 +static inline void au_hn_suspend(struct au_hinode *hdir)
15559 + au_hn_ctl(hdir, /*do_set*/0);
15562 +static inline void au_hn_resume(struct au_hinode *hdir)
15564 + au_hn_ctl(hdir, /*do_set*/1);
15567 +static inline void au_hn_imtx_lock(struct au_hinode *hdir)
15569 + mutex_lock(&hdir->hi_inode->i_mutex);
15570 + au_hn_suspend(hdir);
15573 +static inline void au_hn_imtx_lock_nested(struct au_hinode *hdir,
15574 + unsigned int sc __maybe_unused)
15576 + mutex_lock_nested(&hdir->hi_inode->i_mutex, sc);
15577 + au_hn_suspend(hdir);
15580 +static inline void au_hn_imtx_unlock(struct au_hinode *hdir)
15582 + au_hn_resume(hdir);
15583 + mutex_unlock(&hdir->hi_inode->i_mutex);
15586 +#endif /* __KERNEL__ */
15587 +#endif /* __AUFS_INODE_H__ */
15588 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
15589 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
15590 +++ linux/fs/aufs/ioctl.c 2014-01-20 20:16:14.739463504 +0100
15593 + * Copyright (C) 2005-2014 Junjiro R. Okajima
15595 + * This program, aufs is free software; you can redistribute it and/or modify
15596 + * it under the terms of the GNU General Public License as published by
15597 + * the Free Software Foundation; either version 2 of the License, or
15598 + * (at your option) any later version.
15600 + * This program is distributed in the hope that it will be useful,
15601 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15602 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15603 + * GNU General Public License for more details.
15605 + * You should have received a copy of the GNU General Public License
15606 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15611 + * plink-management and readdir in userspace.
15612 + * assist the pathconf(3) wrapper library.
15616 +#include <linux/compat.h>
15617 +#include <linux/file.h>
15620 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
15623 + aufs_bindex_t wbi, bindex, bend;
15624 + struct file *h_file;
15625 + struct super_block *sb;
15626 + struct dentry *root;
15627 + struct au_branch *br;
15628 + struct aufs_wbr_fd wbrfd = {
15629 + .oflags = au_dir_roflags,
15632 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
15633 + | O_NOATIME | O_CLOEXEC;
15635 + AuDebugOn(wbrfd.oflags & ~valid);
15638 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
15639 + if (unlikely(err)) {
15645 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
15646 + wbrfd.oflags |= au_dir_roflags;
15647 + AuDbg("0%o\n", wbrfd.oflags);
15648 + if (unlikely(wbrfd.oflags & ~valid))
15652 + fd = get_unused_fd();
15654 + if (unlikely(fd < 0))
15657 + h_file = ERR_PTR(-EINVAL);
15660 + sb = path->dentry->d_sb;
15661 + root = sb->s_root;
15662 + aufs_read_lock(root, AuLock_IR);
15663 + bend = au_sbend(sb);
15664 + if (wbrfd.brid >= 0) {
15665 + wbi = au_br_index(sb, wbrfd.brid);
15666 + if (unlikely(wbi < 0 || wbi > bend))
15670 + h_file = ERR_PTR(-ENOENT);
15671 + br = au_sbr(sb, wbi);
15672 + if (!au_br_writable(br->br_perm)) {
15676 + bindex = wbi + 1;
15678 + for (; bindex <= bend; bindex++) {
15679 + br = au_sbr(sb, bindex);
15680 + if (au_br_writable(br->br_perm)) {
15682 + br = au_sbr(sb, wbi);
15687 + AuDbg("wbi %d\n", wbi);
15689 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
15693 + aufs_read_unlock(root, AuLock_IR);
15694 + err = PTR_ERR(h_file);
15695 + if (IS_ERR(h_file))
15698 + atomic_dec(&br->br_count); /* cf. au_h_open() */
15699 + fd_install(fd, h_file);
15701 + goto out; /* success */
15704 + put_unused_fd(fd);
15710 +/* ---------------------------------------------------------------------- */
15712 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
15717 + case AUFS_CTL_RDU:
15718 + case AUFS_CTL_RDU_INO:
15719 + err = au_rdu_ioctl(file, cmd, arg);
15722 + case AUFS_CTL_WBR_FD:
15723 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
15726 + case AUFS_CTL_IBUSY:
15727 + err = au_ibusy_ioctl(file, arg);
15731 + /* do not call the lower */
15732 + AuDbg("0x%x\n", cmd);
15740 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
15745 + case AUFS_CTL_MVDOWN:
15746 + err = au_mvdown(file->f_dentry, (void __user *)arg);
15749 + case AUFS_CTL_WBR_FD:
15750 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
15754 + /* do not call the lower */
15755 + AuDbg("0x%x\n", cmd);
15763 +#ifdef CONFIG_COMPAT
15764 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15765 + unsigned long arg)
15770 + case AUFS_CTL_RDU:
15771 + case AUFS_CTL_RDU_INO:
15772 + err = au_rdu_compat_ioctl(file, cmd, arg);
15775 + case AUFS_CTL_IBUSY:
15776 + err = au_ibusy_compat_ioctl(file, arg);
15780 + err = aufs_ioctl_dir(file, cmd, arg);
15787 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15788 + unsigned long arg)
15790 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
15793 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
15794 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
15795 +++ linux/fs/aufs/i_op_add.c 2014-01-20 20:16:14.739463504 +0100
15798 + * Copyright (C) 2005-2014 Junjiro R. Okajima
15800 + * This program, aufs is free software; you can redistribute it and/or modify
15801 + * it under the terms of the GNU General Public License as published by
15802 + * the Free Software Foundation; either version 2 of the License, or
15803 + * (at your option) any later version.
15805 + * This program is distributed in the hope that it will be useful,
15806 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15807 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15808 + * GNU General Public License for more details.
15810 + * You should have received a copy of the GNU General Public License
15811 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15815 + * inode operations (add entry)
15821 + * final procedure of adding a new entry, except link(2).
15822 + * remove whiteout, instantiate, copyup the parent dir's times and size
15823 + * and update version.
15824 + * if it failed, re-create the removed whiteout.
15826 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
15827 + struct dentry *wh_dentry, struct dentry *dentry)
15830 + aufs_bindex_t bwh;
15831 + struct path h_path;
15832 + struct inode *inode, *h_dir;
15833 + struct dentry *wh;
15837 + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
15838 + IMustLock(h_dir);
15839 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
15840 + bwh = au_dbwh(dentry);
15841 + h_path.dentry = wh_dentry;
15842 + h_path.mnt = au_sbr_mnt(dir->i_sb, bindex);
15843 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
15845 + if (unlikely(err))
15849 + inode = au_new_inode(dentry, /*must_new*/1);
15850 + if (!IS_ERR(inode)) {
15851 + d_instantiate(dentry, inode);
15852 + dir = dentry->d_parent->d_inode; /* dir inode is locked */
15854 + if (au_ibstart(dir) == au_dbstart(dentry))
15855 + au_cpup_attr_timesizes(dir);
15856 + dir->i_version++;
15857 + return 0; /* success */
15860 + err = PTR_ERR(inode);
15865 + /* dir inode is locked */
15866 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
15867 + rerr = PTR_ERR(wh);
15868 + if (IS_ERR(wh)) {
15869 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
15870 + dentry, err, rerr);
15879 +static int au_d_may_add(struct dentry *dentry)
15884 + if (unlikely(d_unhashed(dentry)))
15886 + if (unlikely(dentry->d_inode))
15892 + * simple tests for the adding inode operations.
15893 + * following the checks in vfs, plus the parent-child relationship.
15895 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
15896 + struct dentry *h_parent, int isdir)
15900 + struct dentry *h_dentry;
15901 + struct inode *h_inode;
15903 + err = -ENAMETOOLONG;
15904 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
15907 + h_dentry = au_h_dptr(dentry, bindex);
15908 + h_inode = h_dentry->d_inode;
15909 + if (!dentry->d_inode) {
15911 + if (unlikely(h_inode))
15914 + /* rename(2) case */
15916 + if (unlikely(!h_inode || !h_inode->i_nlink))
15919 + h_mode = h_inode->i_mode;
15922 + if (unlikely(S_ISDIR(h_mode)))
15924 + } else if (unlikely(!S_ISDIR(h_mode))) {
15931 + /* expected parent dir is locked */
15932 + if (unlikely(h_parent != h_dentry->d_parent))
15941 + * initial procedure of adding a new entry.
15942 + * prepare writable branch and the parent dir, lock it,
15943 + * and lookup whiteout for the new entry.
15945 +static struct dentry*
15946 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
15947 + struct dentry *src_dentry, struct au_pin *pin,
15948 + struct au_wr_dir_args *wr_dir_args)
15950 + struct dentry *wh_dentry, *h_parent;
15951 + struct super_block *sb;
15952 + struct au_branch *br;
15954 + unsigned int udba;
15955 + aufs_bindex_t bcpup;
15957 + AuDbg("%pd\n", dentry);
15959 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
15961 + wh_dentry = ERR_PTR(err);
15962 + if (unlikely(err < 0))
15965 + sb = dentry->d_sb;
15966 + udba = au_opt_udba(sb);
15967 + err = au_pin(pin, dentry, bcpup, udba,
15968 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
15969 + wh_dentry = ERR_PTR(err);
15970 + if (unlikely(err))
15973 + h_parent = au_pinned_h_parent(pin);
15974 + if (udba != AuOpt_UDBA_NONE
15975 + && au_dbstart(dentry) == bcpup)
15976 + err = au_may_add(dentry, bcpup, h_parent,
15977 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
15978 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
15979 + err = -ENAMETOOLONG;
15980 + wh_dentry = ERR_PTR(err);
15981 + if (unlikely(err))
15984 + br = au_sbr(sb, bcpup);
15986 + struct path tmp = {
15987 + .dentry = h_parent,
15988 + .mnt = au_br_mnt(br)
15990 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
15993 + wh_dentry = NULL;
15994 + if (bcpup != au_dbwh(dentry))
15995 + goto out; /* success */
15997 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
16000 + if (IS_ERR(wh_dentry))
16003 + return wh_dentry;
16006 +/* ---------------------------------------------------------------------- */
16008 +enum { Mknod, Symlink, Creat };
16009 +struct simple_arg {
16017 + const char *symname;
16026 +static int add_simple(struct inode *dir, struct dentry *dentry,
16027 + struct simple_arg *arg)
16030 + aufs_bindex_t bstart;
16031 + unsigned char created;
16032 + struct dentry *wh_dentry, *parent;
16033 + struct inode *h_dir;
16034 + /* to reuduce stack size */
16036 + struct au_dtime dt;
16037 + struct au_pin pin;
16038 + struct path h_path;
16039 + struct au_wr_dir_args wr_dir_args;
16042 + AuDbg("%pd\n", dentry);
16046 + a = kmalloc(sizeof(*a), GFP_NOFS);
16047 + if (unlikely(!a))
16049 + a->wr_dir_args.force_btgt = -1;
16050 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
16052 + parent = dentry->d_parent; /* dir inode is locked */
16053 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
16054 + if (unlikely(err))
16056 + err = au_d_may_add(dentry);
16057 + if (unlikely(err))
16059 + di_write_lock_parent(parent);
16060 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
16061 + &a->pin, &a->wr_dir_args);
16062 + err = PTR_ERR(wh_dentry);
16063 + if (IS_ERR(wh_dentry))
16066 + bstart = au_dbstart(dentry);
16067 + a->h_path.dentry = au_h_dptr(dentry, bstart);
16068 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
16069 + h_dir = au_pinned_h_dir(&a->pin);
16070 + switch (arg->type) {
16072 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
16073 + arg->u.c.want_excl);
16076 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
16079 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
16087 + err = epilog(dir, bstart, wh_dentry, dentry);
16090 + if (unlikely(created && err && a->h_path.dentry->d_inode)) {
16092 + /* no delegation since it is just created */
16093 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
16096 + AuIOErr("%pd revert failure(%d, %d)\n",
16097 + dentry, err, rerr);
16100 + au_dtime_revert(&a->dt);
16103 + au_unpin(&a->pin);
16107 + di_write_unlock(parent);
16109 + if (unlikely(err)) {
16110 + au_update_dbstart(dentry);
16113 + aufs_read_unlock(dentry, AuLock_DW);
16120 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
16123 + struct simple_arg arg = {
16130 + return add_simple(dir, dentry, &arg);
16133 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
16135 + struct simple_arg arg = {
16137 + .u.s.symname = symname
16139 + return add_simple(dir, dentry, &arg);
16142 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
16145 + struct simple_arg arg = {
16149 + .want_excl = want_excl
16152 + return add_simple(dir, dentry, &arg);
16155 +/* ---------------------------------------------------------------------- */
16157 +struct au_link_args {
16158 + aufs_bindex_t bdst, bsrc;
16159 + struct au_pin pin;
16160 + struct path h_path;
16161 + struct dentry *src_parent, *parent;
16164 +static int au_cpup_before_link(struct dentry *src_dentry,
16165 + struct au_link_args *a)
16168 + struct dentry *h_src_dentry;
16169 + struct au_cp_generic cpg = {
16170 + .dentry = src_dentry,
16175 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
16178 + di_read_lock_parent(a->src_parent, AuLock_IR);
16179 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
16180 + if (unlikely(err))
16183 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
16184 + err = au_pin(&a->pin, src_dentry, a->bdst,
16185 + au_opt_udba(src_dentry->d_sb),
16186 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
16187 + if (unlikely(err))
16190 + err = au_sio_cpup_simple(&cpg);
16191 + au_unpin(&a->pin);
16194 + di_read_unlock(a->src_parent, AuLock_IR);
16198 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
16199 + struct au_link_args *a)
16202 + unsigned char plink;
16203 + aufs_bindex_t bend;
16204 + struct dentry *h_src_dentry;
16205 + struct inode *h_inode, *inode, *delegated;
16206 + struct super_block *sb;
16207 + struct file *h_file;
16211 + sb = src_dentry->d_sb;
16212 + inode = src_dentry->d_inode;
16213 + if (au_ibstart(inode) <= a->bdst)
16214 + h_inode = au_h_iptr(inode, a->bdst);
16215 + if (!h_inode || !h_inode->i_nlink) {
16216 + /* copyup src_dentry as the name of dentry. */
16217 + bend = au_dbend(dentry);
16218 + if (bend < a->bsrc)
16219 + au_set_dbend(dentry, a->bsrc);
16220 + au_set_h_dptr(dentry, a->bsrc,
16221 + dget(au_h_dptr(src_dentry, a->bsrc)));
16222 + dget(a->h_path.dentry);
16223 + au_set_h_dptr(dentry, a->bdst, NULL);
16224 + dentry->d_inode = src_dentry->d_inode; /* tmp */
16225 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
16226 + if (IS_ERR(h_file))
16227 + err = PTR_ERR(h_file);
16229 + struct au_cp_generic cpg = {
16230 + .dentry = dentry,
16235 + .flags = AuCpup_KEEPLINO
16237 + err = au_sio_cpup_simple(&cpg);
16238 + au_h_open_post(dentry, a->bsrc, h_file);
16240 + dput(a->h_path.dentry);
16241 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
16243 + au_set_h_dptr(dentry, a->bdst,
16244 + a->h_path.dentry);
16246 + dentry->d_inode = NULL; /* restore */
16247 + au_set_h_dptr(dentry, a->bsrc, NULL);
16248 + au_set_dbend(dentry, bend);
16250 + /* the inode of src_dentry already exists on a.bdst branch */
16251 + h_src_dentry = d_find_alias(h_inode);
16252 + if (!h_src_dentry && au_plink_test(inode)) {
16254 + h_src_dentry = au_plink_lkup(inode, a->bdst);
16255 + err = PTR_ERR(h_src_dentry);
16256 + if (IS_ERR(h_src_dentry))
16259 + if (unlikely(!h_src_dentry->d_inode)) {
16260 + dput(h_src_dentry);
16261 + h_src_dentry = NULL;
16265 + if (h_src_dentry) {
16266 + delegated = NULL;
16267 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
16268 + &a->h_path, &delegated);
16269 + if (unlikely(err == -EWOULDBLOCK)) {
16270 + pr_warn("cannot retry for NFSv4 delegation"
16271 + " for an internal link\n");
16274 + dput(h_src_dentry);
16276 + AuIOErr("no dentry found for hi%lu on b%d\n",
16277 + h_inode->i_ino, a->bdst);
16282 + if (!err && !plink)
16283 + au_plink_append(inode, a->bdst, a->h_path.dentry);
16290 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
16291 + struct dentry *dentry)
16294 + struct au_dtime dt;
16295 + struct au_link_args *a;
16296 + struct dentry *wh_dentry, *h_src_dentry;
16297 + struct inode *inode, *delegated;
16298 + struct super_block *sb;
16299 + struct au_wr_dir_args wr_dir_args = {
16300 + /* .force_btgt = -1, */
16301 + .flags = AuWrDir_ADD_ENTRY
16305 + inode = src_dentry->d_inode;
16306 + IMustLock(inode);
16309 + a = kzalloc(sizeof(*a), GFP_NOFS);
16310 + if (unlikely(!a))
16313 + a->parent = dentry->d_parent; /* dir inode is locked */
16314 + err = aufs_read_and_write_lock2(dentry, src_dentry,
16315 + AuLock_NOPLM | AuLock_GEN);
16316 + if (unlikely(err))
16318 + err = au_d_hashed_positive(src_dentry);
16319 + if (unlikely(err))
16321 + err = au_d_may_add(dentry);
16322 + if (unlikely(err))
16325 + a->src_parent = dget_parent(src_dentry);
16326 + wr_dir_args.force_btgt = au_ibstart(inode);
16328 + di_write_lock_parent(a->parent);
16329 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
16330 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
16332 + err = PTR_ERR(wh_dentry);
16333 + if (IS_ERR(wh_dentry))
16337 + sb = dentry->d_sb;
16338 + a->bdst = au_dbstart(dentry);
16339 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
16340 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
16341 + a->bsrc = au_ibstart(inode);
16342 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
16343 + if (!h_src_dentry) {
16344 + a->bsrc = au_dbstart(src_dentry);
16345 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
16346 + AuDebugOn(!h_src_dentry);
16347 + } else if (IS_ERR(h_src_dentry))
16350 + if (au_opt_test(au_mntflags(sb), PLINK)) {
16351 + if (a->bdst < a->bsrc
16352 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
16353 + err = au_cpup_or_link(src_dentry, dentry, a);
16355 + delegated = NULL;
16356 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
16357 + &a->h_path, &delegated);
16358 + if (unlikely(err == -EWOULDBLOCK)) {
16359 + pr_warn("cannot retry for NFSv4 delegation"
16360 + " for an internal link\n");
16364 + dput(h_src_dentry);
16367 + * copyup src_dentry to the branch we process,
16368 + * and then link(2) to it.
16370 + dput(h_src_dentry);
16371 + if (a->bdst < a->bsrc
16372 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
16373 + au_unpin(&a->pin);
16374 + di_write_unlock(a->parent);
16375 + err = au_cpup_before_link(src_dentry, a);
16376 + di_write_lock_parent(a->parent);
16378 + err = au_pin(&a->pin, dentry, a->bdst,
16380 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
16381 + if (unlikely(err))
16385 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
16387 + if (h_src_dentry && h_src_dentry->d_inode) {
16388 + delegated = NULL;
16389 + err = vfsub_link(h_src_dentry,
16390 + au_pinned_h_dir(&a->pin),
16391 + &a->h_path, &delegated);
16392 + if (unlikely(err == -EWOULDBLOCK)) {
16393 + pr_warn("cannot retry"
16394 + " for NFSv4 delegation"
16395 + " for an internal link\n");
16401 + if (unlikely(err))
16405 + a->h_path.dentry = wh_dentry;
16406 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
16408 + if (unlikely(err))
16412 + dir->i_version++;
16413 + if (au_ibstart(dir) == au_dbstart(dentry))
16414 + au_cpup_attr_timesizes(dir);
16415 + inc_nlink(inode);
16416 + inode->i_ctime = dir->i_ctime;
16417 + d_instantiate(dentry, au_igrab(inode));
16418 + if (d_unhashed(a->h_path.dentry))
16419 + /* some filesystem calls d_drop() */
16421 + goto out_unpin; /* success */
16424 + /* no delegation since it is just created */
16425 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
16426 + /*delegated*/NULL, /*force*/0);
16427 + if (unlikely(rerr)) {
16428 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
16431 + au_dtime_revert(&dt);
16433 + au_unpin(&a->pin);
16437 + di_write_unlock(a->parent);
16438 + dput(a->src_parent);
16440 + if (unlikely(err)) {
16441 + au_update_dbstart(dentry);
16444 + aufs_read_and_write_unlock2(dentry, src_dentry);
16452 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
16455 + aufs_bindex_t bindex;
16456 + unsigned char diropq;
16457 + struct path h_path;
16458 + struct dentry *wh_dentry, *parent, *opq_dentry;
16459 + struct mutex *h_mtx;
16460 + struct super_block *sb;
16462 + struct au_pin pin;
16463 + struct au_dtime dt;
16464 + } *a; /* reduce the stack usage */
16465 + struct au_wr_dir_args wr_dir_args = {
16466 + .force_btgt = -1,
16467 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
16473 + a = kmalloc(sizeof(*a), GFP_NOFS);
16474 + if (unlikely(!a))
16477 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
16478 + if (unlikely(err))
16480 + err = au_d_may_add(dentry);
16481 + if (unlikely(err))
16484 + parent = dentry->d_parent; /* dir inode is locked */
16485 + di_write_lock_parent(parent);
16486 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
16487 + &a->pin, &wr_dir_args);
16488 + err = PTR_ERR(wh_dentry);
16489 + if (IS_ERR(wh_dentry))
16492 + sb = dentry->d_sb;
16493 + bindex = au_dbstart(dentry);
16494 + h_path.dentry = au_h_dptr(dentry, bindex);
16495 + h_path.mnt = au_sbr_mnt(sb, bindex);
16496 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
16497 + if (unlikely(err))
16500 + /* make the dir opaque */
16502 + h_mtx = &h_path.dentry->d_inode->i_mutex;
16504 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
16505 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
16506 + opq_dentry = au_diropq_create(dentry, bindex);
16507 + mutex_unlock(h_mtx);
16508 + err = PTR_ERR(opq_dentry);
16509 + if (IS_ERR(opq_dentry))
16511 + dput(opq_dentry);
16515 + err = epilog(dir, bindex, wh_dentry, dentry);
16518 + goto out_unpin; /* success */
16523 + AuLabel(revert opq);
16524 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
16525 + rerr = au_diropq_remove(dentry, bindex);
16526 + mutex_unlock(h_mtx);
16528 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
16529 + dentry, err, rerr);
16535 + AuLabel(revert dir);
16536 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
16538 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
16539 + dentry, err, rerr);
16542 + au_dtime_revert(&a->dt);
16544 + au_unpin(&a->pin);
16547 + di_write_unlock(parent);
16549 + if (unlikely(err)) {
16550 + au_update_dbstart(dentry);
16553 + aufs_read_unlock(dentry, AuLock_DW);
16559 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
16560 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
16561 +++ linux/fs/aufs/i_op.c 2014-01-27 23:16:52.715087263 +0100
16564 + * Copyright (C) 2005-2014 Junjiro R. Okajima
16566 + * This program, aufs is free software; you can redistribute it and/or modify
16567 + * it under the terms of the GNU General Public License as published by
16568 + * the Free Software Foundation; either version 2 of the License, or
16569 + * (at your option) any later version.
16571 + * This program is distributed in the hope that it will be useful,
16572 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16573 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16574 + * GNU General Public License for more details.
16576 + * You should have received a copy of the GNU General Public License
16577 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16581 + * inode operations (except add/del/rename)
16584 +#include <linux/device_cgroup.h>
16585 +#include <linux/fs_stack.h>
16586 +#include <linux/mm.h>
16587 +#include <linux/namei.h>
16588 +#include <linux/security.h>
16591 +static int h_permission(struct inode *h_inode, int mask,
16592 + struct vfsmount *h_mnt, int brperm)
16595 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
16598 + if ((write_mask && IS_IMMUTABLE(h_inode))
16599 + || ((mask & MAY_EXEC)
16600 + && S_ISREG(h_inode->i_mode)
16601 + && ((h_mnt->mnt_flags & MNT_NOEXEC)
16602 + || !(h_inode->i_mode & S_IXUGO))))
16606 + * - skip the lower fs test in the case of write to ro branch.
16607 + * - nfs dir permission write check is optimized, but a policy for
16608 + * link/rename requires a real check.
16610 + if ((write_mask && !au_br_writable(brperm))
16611 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
16612 + && write_mask && !(mask & MAY_READ))
16613 + || !h_inode->i_op->permission) {
16614 + /* AuLabel(generic_permission); */
16615 + err = generic_permission(h_inode, mask);
16617 + /* AuLabel(h_inode->permission); */
16618 + err = h_inode->i_op->permission(h_inode, mask);
16623 + err = devcgroup_inode_permission(h_inode, mask);
16625 + err = security_inode_permission(h_inode, mask);
16629 + /* todo: do we need to call ima_path_check()? */
16630 + struct path h_path = {
16634 + err = ima_path_check(&h_path,
16635 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
16636 + IMA_COUNT_LEAVE);
16644 +static int aufs_permission(struct inode *inode, int mask)
16647 + aufs_bindex_t bindex, bend;
16648 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
16649 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
16650 + struct inode *h_inode;
16651 + struct super_block *sb;
16652 + struct au_branch *br;
16654 + /* todo: support rcu-walk? */
16655 + if (mask & MAY_NOT_BLOCK)
16658 + sb = inode->i_sb;
16659 + si_read_lock(sb, AuLock_FLUSH);
16660 + ii_read_lock_child(inode);
16662 + err = au_iigen_test(inode, au_sigen(sb));
16663 + if (unlikely(err))
16667 + if (!isdir || write_mask) {
16668 + err = au_busy_or_stale();
16669 + h_inode = au_h_iptr(inode, au_ibstart(inode));
16670 + if (unlikely(!h_inode
16671 + || (h_inode->i_mode & S_IFMT)
16672 + != (inode->i_mode & S_IFMT)))
16676 + bindex = au_ibstart(inode);
16677 + br = au_sbr(sb, bindex);
16678 + err = h_permission(h_inode, mask, au_br_mnt(br), br->br_perm);
16681 + && !special_file(h_inode->i_mode)) {
16682 + /* test whether the upper writable branch exists */
16684 + for (; bindex >= 0; bindex--)
16685 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
16693 + /* non-write to dir */
16695 + bend = au_ibend(inode);
16696 + for (bindex = au_ibstart(inode); !err && bindex <= bend; bindex++) {
16697 + h_inode = au_h_iptr(inode, bindex);
16699 + err = au_busy_or_stale();
16700 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
16703 + br = au_sbr(sb, bindex);
16704 + err = h_permission(h_inode, mask, au_br_mnt(br),
16710 + ii_read_unlock(inode);
16711 + si_read_unlock(sb);
16715 +/* ---------------------------------------------------------------------- */
16717 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
16718 + unsigned int flags)
16720 + struct dentry *ret, *parent;
16721 + struct inode *inode;
16722 + struct super_block *sb;
16723 + int err, npositive;
16727 + /* todo: support rcu-walk? */
16728 + ret = ERR_PTR(-ECHILD);
16729 + if (flags & LOOKUP_RCU)
16732 + ret = ERR_PTR(-ENAMETOOLONG);
16733 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
16737 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16738 + ret = ERR_PTR(err);
16739 + if (unlikely(err))
16742 + err = au_di_init(dentry);
16743 + ret = ERR_PTR(err);
16744 + if (unlikely(err))
16748 + npositive = 0; /* suppress a warning */
16749 + parent = dentry->d_parent; /* dir inode is locked */
16750 + di_read_lock_parent(parent, AuLock_IR);
16751 + err = au_alive_dir(parent);
16753 + err = au_digen_test(parent, au_sigen(sb));
16755 + npositive = au_lkup_dentry(dentry, au_dbstart(parent),
16759 + di_read_unlock(parent, AuLock_IR);
16760 + ret = ERR_PTR(err);
16761 + if (unlikely(err < 0))
16765 + inode = au_new_inode(dentry, /*must_new*/0);
16766 + ret = (void *)inode;
16768 + if (IS_ERR(inode)) {
16773 + ret = d_splice_alias(inode, dentry);
16775 + if (unlikely(d_need_lookup(dentry))) {
16776 + spin_lock(&dentry->d_lock);
16777 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
16778 + spin_unlock(&dentry->d_lock);
16781 + if (unlikely(IS_ERR(ret) && inode)) {
16782 + ii_write_unlock(inode);
16788 + di_write_unlock(dentry);
16790 + /* verbose coding for lock class name */
16791 + if (unlikely(S_ISLNK(inode->i_mode)))
16792 + au_rw_class(&au_di(dentry)->di_rwsem,
16793 + au_lc_key + AuLcSymlink_DIINFO);
16794 + else if (unlikely(S_ISDIR(inode->i_mode)))
16795 + au_rw_class(&au_di(dentry)->di_rwsem,
16796 + au_lc_key + AuLcDir_DIINFO);
16797 + else /* likely */
16798 + au_rw_class(&au_di(dentry)->di_rwsem,
16799 + au_lc_key + AuLcNonDir_DIINFO);
16802 + si_read_unlock(sb);
16807 +/* ---------------------------------------------------------------------- */
16809 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
16810 + const unsigned char add_entry, aufs_bindex_t bcpup,
16811 + aufs_bindex_t bstart)
16814 + struct dentry *h_parent;
16815 + struct inode *h_dir;
16818 + IMustLock(parent->d_inode);
16820 + di_write_lock_parent(parent);
16823 + if (!au_h_dptr(parent, bcpup)) {
16824 + if (bstart > bcpup)
16825 + err = au_cpup_dirs(dentry, bcpup);
16826 + else if (bstart < bcpup)
16827 + err = au_cpdown_dirs(dentry, bcpup);
16831 + if (!err && add_entry) {
16832 + h_parent = au_h_dptr(parent, bcpup);
16833 + h_dir = h_parent->d_inode;
16834 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
16835 + err = au_lkup_neg(dentry, bcpup,
16836 + au_ftest_wrdir(add_entry, TMP_WHENTRY));
16837 + /* todo: no unlock here */
16838 + mutex_unlock(&h_dir->i_mutex);
16840 + AuDbg("bcpup %d\n", bcpup);
16842 + if (!dentry->d_inode)
16843 + au_set_h_dptr(dentry, bstart, NULL);
16844 + au_update_dbrange(dentry, /*do_put_zero*/0);
16849 + di_write_unlock(parent);
16851 + err = bcpup; /* success */
16858 + * decide the branch and the parent dir where we will create a new entry.
16859 + * returns new bindex or an error.
16860 + * copyup the parent dir if needed.
16862 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
16863 + struct au_wr_dir_args *args)
16866 + unsigned int flags;
16867 + aufs_bindex_t bcpup, bstart, src_bstart;
16868 + const unsigned char add_entry
16869 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
16870 + | au_ftest_wrdir(args->flags, TMP_WHENTRY);
16871 + struct super_block *sb;
16872 + struct dentry *parent;
16873 + struct au_sbinfo *sbinfo;
16875 + sb = dentry->d_sb;
16876 + sbinfo = au_sbi(sb);
16877 + parent = dget_parent(dentry);
16878 + bstart = au_dbstart(dentry);
16880 + if (args->force_btgt < 0) {
16881 + if (src_dentry) {
16882 + src_bstart = au_dbstart(src_dentry);
16883 + if (src_bstart < bstart)
16884 + bcpup = src_bstart;
16885 + } else if (add_entry) {
16887 + if (au_ftest_wrdir(args->flags, ISDIR))
16888 + au_fset_wbr(flags, DIR);
16889 + err = AuWbrCreate(sbinfo, dentry, flags);
16893 + if (bcpup < 0 || au_test_ro(sb, bcpup, dentry->d_inode)) {
16895 + err = AuWbrCopyup(sbinfo, dentry);
16897 + if (!IS_ROOT(dentry)) {
16898 + di_read_lock_parent(parent, !AuLock_IR);
16899 + err = AuWbrCopyup(sbinfo, dentry);
16900 + di_read_unlock(parent, !AuLock_IR);
16902 + err = AuWbrCopyup(sbinfo, dentry);
16905 + if (unlikely(err < 0))
16909 + bcpup = args->force_btgt;
16910 + AuDebugOn(au_test_ro(sb, bcpup, dentry->d_inode));
16913 + AuDbg("bstart %d, bcpup %d\n", bstart, bcpup);
16915 + if (bcpup == bstart)
16916 + goto out; /* success */
16918 + /* copyup the new parent into the branch we process */
16919 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, bstart);
16921 + if (!dentry->d_inode) {
16922 + au_set_h_dptr(dentry, bstart, NULL);
16923 + au_set_dbstart(dentry, bcpup);
16924 + au_set_dbend(dentry, bcpup);
16926 + AuDebugOn(add_entry && !au_h_dptr(dentry, bcpup));
16934 +/* ---------------------------------------------------------------------- */
16936 +void au_pin_hdir_unlock(struct au_pin *p)
16939 + au_hn_imtx_unlock(p->hdir);
16942 +static int au_pin_hdir_lock(struct au_pin *p)
16950 + /* even if an error happens later, keep this lock */
16951 + au_hn_imtx_lock_nested(p->hdir, p->lsc_hi);
16954 + if (unlikely(p->hdir->hi_inode != p->h_parent->d_inode))
16959 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
16960 + p->h_parent, p->br);
16966 +int au_pin_hdir_relock(struct au_pin *p)
16969 + struct inode *h_i;
16970 + struct dentry *h_d[] = {
16975 + err = au_pin_hdir_lock(p);
16976 + if (unlikely(err))
16979 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
16982 + h_i = h_d[i]->d_inode;
16984 + err = !h_i->i_nlink;
16991 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
16993 +#if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
16994 + p->hdir->hi_inode->i_mutex.owner = task;
16998 +void au_pin_hdir_acquire_nest(struct au_pin *p)
17001 + mutex_acquire_nest(&p->hdir->hi_inode->i_mutex.dep_map,
17002 + p->lsc_hi, 0, NULL, _RET_IP_);
17003 + au_pin_hdir_set_owner(p, current);
17007 +void au_pin_hdir_release(struct au_pin *p)
17010 + au_pin_hdir_set_owner(p, p->task);
17011 + mutex_release(&p->hdir->hi_inode->i_mutex.dep_map, 1, _RET_IP_);
17015 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
17017 + if (pin && pin->parent)
17018 + return au_h_dptr(pin->parent, pin->bindex);
17022 +void au_unpin(struct au_pin *p)
17025 + au_pin_hdir_unlock(p);
17026 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
17027 + vfsub_mnt_drop_write(p->h_mnt);
17031 + if (!au_ftest_pin(p->flags, DI_LOCKED))
17032 + di_read_unlock(p->parent, AuLock_IR);
17033 + iput(p->hdir->hi_inode);
17035 + p->parent = NULL;
17038 + /* do not clear p->task */
17041 +int au_do_pin(struct au_pin *p)
17044 + struct super_block *sb;
17045 + struct inode *h_dir;
17048 + sb = p->dentry->d_sb;
17049 + p->br = au_sbr(sb, p->bindex);
17050 + if (IS_ROOT(p->dentry)) {
17051 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
17052 + p->h_mnt = au_br_mnt(p->br);
17053 + err = vfsub_mnt_want_write(p->h_mnt);
17054 + if (unlikely(err)) {
17055 + au_fclr_pin(p->flags, MNT_WRITE);
17062 + p->h_dentry = NULL;
17063 + if (p->bindex <= au_dbend(p->dentry))
17064 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
17066 + p->parent = dget_parent(p->dentry);
17067 + if (!au_ftest_pin(p->flags, DI_LOCKED))
17068 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
17071 + p->h_parent = au_h_dptr(p->parent, p->bindex);
17072 + p->hdir = au_hi(p->parent->d_inode, p->bindex);
17074 + h_dir = p->hdir->hi_inode;
17078 + * if DI_LOCKED is not set, then p->parent may be different
17079 + * and h_parent can be NULL.
17081 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
17083 + if (!au_ftest_pin(p->flags, DI_LOCKED))
17084 + di_read_unlock(p->parent, AuLock_IR);
17086 + p->parent = NULL;
17090 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
17091 + p->h_mnt = au_br_mnt(p->br);
17092 + err = vfsub_mnt_want_write(p->h_mnt);
17093 + if (unlikely(err)) {
17094 + au_fclr_pin(p->flags, MNT_WRITE);
17095 + if (!au_ftest_pin(p->flags, DI_LOCKED))
17096 + di_read_unlock(p->parent, AuLock_IR);
17098 + p->parent = NULL;
17104 + err = au_pin_hdir_lock(p);
17106 + goto out; /* success */
17109 + pr_err("err %d\n", err);
17110 + err = au_busy_or_stale();
17115 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
17116 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
17117 + unsigned int udba, unsigned char flags)
17119 + p->dentry = dentry;
17121 + p->lsc_di = lsc_di;
17122 + p->lsc_hi = lsc_hi;
17123 + p->flags = flags;
17124 + p->bindex = bindex;
17126 + p->parent = NULL;
17130 + p->h_dentry = NULL;
17131 + p->h_parent = NULL;
17133 + p->task = current;
17136 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
17137 + unsigned int udba, unsigned char flags)
17139 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
17141 + return au_do_pin(pin);
17144 +/* ---------------------------------------------------------------------- */
17147 + * ->setattr() and ->getattr() are called in various cases.
17148 + * chmod, stat: dentry is revalidated.
17149 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
17151 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
17153 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
17154 +static int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
17157 + struct inode *inode;
17158 + struct dentry *parent;
17161 + inode = dentry->d_inode;
17162 + if (au_digen_test(dentry, sigen)) {
17163 + parent = dget_parent(dentry);
17164 + di_read_lock_parent(parent, AuLock_IR);
17165 + err = au_refresh_dentry(dentry, parent);
17166 + di_read_unlock(parent, AuLock_IR);
17174 +#define AuIcpup_DID_CPUP 1
17175 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
17176 +#define au_fset_icpup(flags, name) \
17177 + do { (flags) |= AuIcpup_##name; } while (0)
17178 +#define au_fclr_icpup(flags, name) \
17179 + do { (flags) &= ~AuIcpup_##name; } while (0)
17181 +struct au_icpup_args {
17182 + unsigned char flags;
17183 + unsigned char pin_flags;
17184 + aufs_bindex_t btgt;
17185 + unsigned int udba;
17186 + struct au_pin pin;
17187 + struct path h_path;
17188 + struct inode *h_inode;
17191 +static int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
17192 + struct au_icpup_args *a)
17196 + aufs_bindex_t bstart, ibstart;
17197 + struct dentry *hi_wh, *parent;
17198 + struct inode *inode;
17199 + struct au_wr_dir_args wr_dir_args = {
17200 + .force_btgt = -1,
17204 + bstart = au_dbstart(dentry);
17205 + inode = dentry->d_inode;
17206 + if (S_ISDIR(inode->i_mode))
17207 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
17208 + /* plink or hi_wh() case */
17209 + ibstart = au_ibstart(inode);
17210 + if (bstart != ibstart && !au_test_ro(inode->i_sb, ibstart, inode))
17211 + wr_dir_args.force_btgt = ibstart;
17212 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
17213 + if (unlikely(err < 0))
17216 + if (err != bstart)
17217 + au_fset_icpup(a->flags, DID_CPUP);
17220 + a->pin_flags = AuPin_MNT_WRITE;
17222 + if (!IS_ROOT(dentry)) {
17223 + au_fset_pin(a->pin_flags, DI_LOCKED);
17224 + parent = dget_parent(dentry);
17225 + di_write_lock_parent(parent);
17228 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
17229 + if (unlikely(err))
17232 + a->h_path.dentry = au_h_dptr(dentry, bstart);
17233 + a->h_inode = a->h_path.dentry->d_inode;
17234 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
17236 + if ((ia->ia_valid & ATTR_SIZE) && ia->ia_size < i_size_read(a->h_inode))
17237 + sz = ia->ia_size;
17238 + mutex_unlock(&a->h_inode->i_mutex);
17241 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
17242 + hi_wh = au_hi_wh(inode, a->btgt);
17244 + struct au_cp_generic cpg = {
17245 + .dentry = dentry,
17251 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
17252 + if (unlikely(err))
17254 + hi_wh = au_hi_wh(inode, a->btgt);
17255 + /* todo: revalidate hi_wh? */
17260 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
17261 + di_downgrade_lock(parent, AuLock_IR);
17265 + if (!au_ftest_icpup(a->flags, DID_CPUP))
17266 + goto out; /* success */
17268 + if (!d_unhashed(dentry)) {
17269 + struct au_cp_generic cpg = {
17270 + .dentry = dentry,
17275 + .flags = AuCpup_DTIME | AuCpup_HOPEN
17277 + err = au_sio_cpup_simple(&cpg);
17279 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
17280 + } else if (!hi_wh)
17281 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
17283 + a->h_path.dentry = hi_wh; /* do not dget here */
17286 + a->h_inode = a->h_path.dentry->d_inode;
17288 + goto out; /* success */
17289 + au_unpin(&a->pin);
17292 + di_write_unlock(parent);
17297 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
17301 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
17304 + struct inode *inode, *delegated;
17305 + struct super_block *sb;
17306 + struct file *file;
17307 + struct au_icpup_args *a;
17309 + inode = dentry->d_inode;
17310 + IMustLock(inode);
17313 + a = kzalloc(sizeof(*a), GFP_NOFS);
17314 + if (unlikely(!a))
17317 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
17318 + ia->ia_valid &= ~ATTR_MODE;
17321 + sb = dentry->d_sb;
17322 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
17323 + if (unlikely(err))
17326 + if (ia->ia_valid & ATTR_FILE) {
17327 + /* currently ftruncate(2) only */
17328 + AuDebugOn(!S_ISREG(inode->i_mode));
17329 + file = ia->ia_file;
17330 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
17331 + if (unlikely(err))
17333 + ia->ia_file = au_hf_top(file);
17334 + a->udba = AuOpt_UDBA_NONE;
17336 + /* fchmod() doesn't pass ia_file */
17337 + a->udba = au_opt_udba(sb);
17338 + di_write_lock_child(dentry);
17339 + /* no d_unlinked(), to set UDBA_NONE for root */
17340 + if (d_unhashed(dentry))
17341 + a->udba = AuOpt_UDBA_NONE;
17342 + if (a->udba != AuOpt_UDBA_NONE) {
17343 + AuDebugOn(IS_ROOT(dentry));
17344 + err = au_reval_for_attr(dentry, au_sigen(sb));
17345 + if (unlikely(err))
17350 + err = au_pin_and_icpup(dentry, ia, a);
17351 + if (unlikely(err < 0))
17353 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
17354 + ia->ia_file = NULL;
17355 + ia->ia_valid &= ~ATTR_FILE;
17358 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
17359 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
17360 + == (ATTR_MODE | ATTR_CTIME)) {
17361 + err = security_path_chmod(&a->h_path, ia->ia_mode);
17362 + if (unlikely(err))
17364 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
17365 + && (ia->ia_valid & ATTR_CTIME)) {
17366 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
17367 + if (unlikely(err))
17371 + if (ia->ia_valid & ATTR_SIZE) {
17374 + if (ia->ia_size < i_size_read(inode))
17376 + truncate_setsize(inode, ia->ia_size);
17379 + if (ia->ia_valid & ATTR_FILE)
17381 + mutex_unlock(&a->h_inode->i_mutex);
17382 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
17383 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
17385 + delegated = NULL;
17387 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
17389 + err = break_deleg_wait(&delegated);
17397 + au_cpup_attr_changeable(inode);
17400 + mutex_unlock(&a->h_inode->i_mutex);
17401 + au_unpin(&a->pin);
17402 + if (unlikely(err))
17403 + au_update_dbstart(dentry);
17405 + di_write_unlock(dentry);
17407 + fi_write_unlock(file);
17408 + ia->ia_file = file;
17409 + ia->ia_valid |= ATTR_FILE;
17412 + si_read_unlock(sb);
17420 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
17421 + unsigned int nlink)
17425 + inode->i_mode = st->mode;
17426 + /* don't i_[ug]id_write() here */
17427 + inode->i_uid = st->uid;
17428 + inode->i_gid = st->gid;
17429 + inode->i_atime = st->atime;
17430 + inode->i_mtime = st->mtime;
17431 + inode->i_ctime = st->ctime;
17433 + au_cpup_attr_nlink(inode, /*force*/0);
17434 + if (S_ISDIR(inode->i_mode)) {
17435 + n = inode->i_nlink;
17438 + smp_mb(); /* for i_nlink */
17439 + /* 0 can happen */
17440 + set_nlink(inode, n);
17443 + spin_lock(&inode->i_lock);
17444 + inode->i_blocks = st->blocks;
17445 + i_size_write(inode, st->size);
17446 + spin_unlock(&inode->i_lock);
17449 +static int aufs_getattr(struct vfsmount *mnt __maybe_unused,
17450 + struct dentry *dentry, struct kstat *st)
17453 + unsigned int mnt_flags;
17454 + aufs_bindex_t bindex;
17455 + unsigned char udba_none, positive;
17456 + struct super_block *sb, *h_sb;
17457 + struct inode *inode;
17458 + struct path h_path;
17460 + sb = dentry->d_sb;
17461 + inode = dentry->d_inode;
17462 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
17463 + if (unlikely(err))
17465 + mnt_flags = au_mntflags(sb);
17466 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
17468 + /* support fstat(2) */
17469 + if (!d_unlinked(dentry) && !udba_none) {
17470 + unsigned int sigen = au_sigen(sb);
17471 + err = au_digen_test(dentry, sigen);
17473 + di_read_lock_child(dentry, AuLock_IR);
17474 + err = au_dbrange_test(dentry);
17475 + if (unlikely(err))
17478 + AuDebugOn(IS_ROOT(dentry));
17479 + di_write_lock_child(dentry);
17480 + err = au_dbrange_test(dentry);
17482 + err = au_reval_for_attr(dentry, sigen);
17483 + di_downgrade_lock(dentry, AuLock_IR);
17484 + if (unlikely(err))
17488 + di_read_lock_child(dentry, AuLock_IR);
17490 + bindex = au_ibstart(inode);
17491 + h_path.mnt = au_sbr_mnt(sb, bindex);
17492 + h_sb = h_path.mnt->mnt_sb;
17493 + if (!au_test_fs_bad_iattr(h_sb) && udba_none)
17494 + goto out_fill; /* success */
17496 + h_path.dentry = NULL;
17497 + if (au_dbstart(dentry) == bindex)
17498 + h_path.dentry = dget(au_h_dptr(dentry, bindex));
17499 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
17500 + h_path.dentry = au_plink_lkup(inode, bindex);
17501 + if (IS_ERR(h_path.dentry))
17502 + goto out_fill; /* pretending success */
17504 + /* illegally overlapped or something */
17505 + if (unlikely(!h_path.dentry))
17506 + goto out_fill; /* pretending success */
17508 + positive = !!h_path.dentry->d_inode;
17510 + err = vfs_getattr(&h_path, st);
17511 + dput(h_path.dentry);
17514 + au_refresh_iattr(inode, st,
17515 + h_path.dentry->d_inode->i_nlink);
17516 + goto out_fill; /* success */
17522 + generic_fillattr(inode, st);
17524 + di_read_unlock(dentry, AuLock_IR);
17525 + si_read_unlock(sb);
17531 +/* ---------------------------------------------------------------------- */
17533 +static int h_readlink(struct dentry *dentry, int bindex, char __user *buf,
17537 + struct super_block *sb;
17538 + struct dentry *h_dentry;
17541 + h_dentry = au_h_dptr(dentry, bindex);
17542 + if (unlikely(!h_dentry->d_inode->i_op->readlink))
17545 + err = security_inode_readlink(h_dentry);
17546 + if (unlikely(err))
17549 + sb = dentry->d_sb;
17550 + if (!au_test_ro(sb, bindex, dentry->d_inode)) {
17551 + vfsub_touch_atime(au_sbr_mnt(sb, bindex), h_dentry);
17552 + fsstack_copy_attr_atime(dentry->d_inode, h_dentry->d_inode);
17554 + err = h_dentry->d_inode->i_op->readlink(h_dentry, buf, bufsiz);
17560 +static int aufs_readlink(struct dentry *dentry, char __user *buf, int bufsiz)
17564 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
17565 + if (unlikely(err))
17567 + err = au_d_hashed_positive(dentry);
17569 + err = h_readlink(dentry, au_dbstart(dentry), buf, bufsiz);
17570 + aufs_read_unlock(dentry, AuLock_IR);
17576 +static void *aufs_follow_link(struct dentry *dentry, struct nameidata *nd)
17579 + mm_segment_t old_fs;
17586 + buf.k = (void *)__get_free_page(GFP_NOFS);
17587 + if (unlikely(!buf.k))
17590 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
17591 + if (unlikely(err))
17594 + err = au_d_hashed_positive(dentry);
17596 + old_fs = get_fs();
17597 + set_fs(KERNEL_DS);
17598 + err = h_readlink(dentry, au_dbstart(dentry), buf.u, PATH_MAX);
17601 + aufs_read_unlock(dentry, AuLock_IR);
17605 + /* will be freed by put_link */
17606 + nd_set_link(nd, buf.k);
17607 + return NULL; /* success */
17611 + free_page((unsigned long)buf.k);
17614 + return ERR_PTR(err);
17617 +static void aufs_put_link(struct dentry *dentry __maybe_unused,
17618 + struct nameidata *nd, void *cookie __maybe_unused)
17622 + p = nd_get_link(nd);
17623 + if (!IS_ERR_OR_NULL(p))
17624 + free_page((unsigned long)p);
17627 +/* ---------------------------------------------------------------------- */
17629 +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags)
17632 + struct super_block *sb;
17633 + struct inode *h_inode;
17635 + sb = inode->i_sb;
17636 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
17638 + si_read_lock(sb, AuLock_FLUSH);
17639 + ii_write_lock_child(inode);
17641 + h_inode = au_h_iptr(inode, au_ibstart(inode));
17642 + err = vfsub_update_time(h_inode, ts, flags);
17644 + ii_write_unlock(inode);
17645 + si_read_unlock(sb);
17650 +/* ---------------------------------------------------------------------- */
17652 +struct inode_operations aufs_symlink_iop = {
17653 + .permission = aufs_permission,
17654 + .setattr = aufs_setattr,
17655 + .getattr = aufs_getattr,
17657 + .readlink = aufs_readlink,
17658 + .follow_link = aufs_follow_link,
17659 + .put_link = aufs_put_link,
17661 + /* .update_time = aufs_update_time */
17664 +struct inode_operations aufs_dir_iop = {
17665 + .create = aufs_create,
17666 + .lookup = aufs_lookup,
17667 + .link = aufs_link,
17668 + .unlink = aufs_unlink,
17669 + .symlink = aufs_symlink,
17670 + .mkdir = aufs_mkdir,
17671 + .rmdir = aufs_rmdir,
17672 + .mknod = aufs_mknod,
17673 + .rename = aufs_rename,
17675 + .permission = aufs_permission,
17676 + .setattr = aufs_setattr,
17677 + .getattr = aufs_getattr,
17679 + .update_time = aufs_update_time
17680 + /* no support for atomic_open() */
17683 +struct inode_operations aufs_iop = {
17684 + .permission = aufs_permission,
17685 + .setattr = aufs_setattr,
17686 + .getattr = aufs_getattr,
17688 + .update_time = aufs_update_time
17690 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
17691 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
17692 +++ linux/fs/aufs/i_op_del.c 2014-01-20 20:16:14.739463504 +0100
17695 + * Copyright (C) 2005-2014 Junjiro R. Okajima
17697 + * This program, aufs is free software; you can redistribute it and/or modify
17698 + * it under the terms of the GNU General Public License as published by
17699 + * the Free Software Foundation; either version 2 of the License, or
17700 + * (at your option) any later version.
17702 + * This program is distributed in the hope that it will be useful,
17703 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17704 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17705 + * GNU General Public License for more details.
17707 + * You should have received a copy of the GNU General Public License
17708 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17712 + * inode operations (del entry)
17718 + * decide if a new whiteout for @dentry is necessary or not.
17719 + * when it is necessary, prepare the parent dir for the upper branch whose
17720 + * branch index is @bcpup for creation. the actual creation of the whiteout will
17721 + * be done by caller.
17723 + * 0: wh is unnecessary
17724 + * plus: wh is necessary
17727 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
17729 + int need_wh, err;
17730 + aufs_bindex_t bstart;
17731 + struct super_block *sb;
17733 + sb = dentry->d_sb;
17734 + bstart = au_dbstart(dentry);
17735 + if (*bcpup < 0) {
17737 + if (au_test_ro(sb, bstart, dentry->d_inode)) {
17738 + err = AuWbrCopyup(au_sbi(sb), dentry);
17740 + if (unlikely(err < 0))
17744 + AuDebugOn(bstart < *bcpup
17745 + || au_test_ro(sb, *bcpup, dentry->d_inode));
17746 + AuDbg("bcpup %d, bstart %d\n", *bcpup, bstart);
17748 + if (*bcpup != bstart) {
17749 + err = au_cpup_dirs(dentry, *bcpup);
17750 + if (unlikely(err))
17754 + struct au_dinfo *dinfo, *tmp;
17756 + need_wh = -ENOMEM;
17757 + dinfo = au_di(dentry);
17758 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
17760 + au_di_cp(tmp, dinfo);
17761 + au_di_swap(tmp, dinfo);
17762 + /* returns the number of positive dentries */
17763 + need_wh = au_lkup_dentry(dentry, bstart + 1, /*type*/0);
17764 + au_di_swap(tmp, dinfo);
17765 + au_rw_write_unlock(&tmp->di_rwsem);
17769 + AuDbg("need_wh %d\n", need_wh);
17777 + * simple tests for the del-entry operations.
17778 + * following the checks in vfs, plus the parent-child relationship.
17780 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
17781 + struct dentry *h_parent, int isdir)
17785 + struct dentry *h_dentry, *h_latest;
17786 + struct inode *h_inode;
17788 + h_dentry = au_h_dptr(dentry, bindex);
17789 + h_inode = h_dentry->d_inode;
17790 + if (dentry->d_inode) {
17792 + if (unlikely(!h_inode || !h_inode->i_nlink))
17795 + h_mode = h_inode->i_mode;
17798 + if (unlikely(S_ISDIR(h_mode)))
17800 + } else if (unlikely(!S_ISDIR(h_mode))) {
17805 + /* rename(2) case */
17807 + if (unlikely(h_inode))
17812 + /* expected parent dir is locked */
17813 + if (unlikely(h_parent != h_dentry->d_parent))
17818 + * rmdir a dir may break the consistency on some filesystem.
17819 + * let's try heavy test.
17822 + if (unlikely(au_test_h_perm(h_parent->d_inode, MAY_EXEC | MAY_WRITE)))
17825 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent,
17826 + au_sbr(dentry->d_sb, bindex));
17828 + if (IS_ERR(h_latest))
17830 + if (h_latest == h_dentry)
17839 + * decide the branch where we operate for @dentry. the branch index will be set
17840 + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent
17841 + * dir for reverting.
17842 + * when a new whiteout is necessary, create it.
17844 +static struct dentry*
17845 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
17846 + struct au_dtime *dt, struct au_pin *pin)
17848 + struct dentry *wh_dentry;
17849 + struct super_block *sb;
17850 + struct path h_path;
17851 + int err, need_wh;
17852 + unsigned int udba;
17853 + aufs_bindex_t bcpup;
17855 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
17856 + wh_dentry = ERR_PTR(need_wh);
17857 + if (unlikely(need_wh < 0))
17860 + sb = dentry->d_sb;
17861 + udba = au_opt_udba(sb);
17863 + err = au_pin(pin, dentry, bcpup, udba,
17864 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17865 + wh_dentry = ERR_PTR(err);
17866 + if (unlikely(err))
17869 + h_path.dentry = au_pinned_h_parent(pin);
17870 + if (udba != AuOpt_UDBA_NONE
17871 + && au_dbstart(dentry) == bcpup) {
17872 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
17873 + wh_dentry = ERR_PTR(err);
17874 + if (unlikely(err))
17878 + h_path.mnt = au_sbr_mnt(sb, bcpup);
17879 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
17880 + wh_dentry = NULL;
17882 + goto out; /* success, no need to create whiteout */
17884 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
17885 + if (IS_ERR(wh_dentry))
17888 + /* returns with the parent is locked and wh_dentry is dget-ed */
17889 + goto out; /* success */
17894 + return wh_dentry;
17898 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
17899 + * in order to be revertible and save time for removing many child whiteouts
17901 + * returns 1 when there are too many child whiteout and caller should remove
17902 + * them asynchronously. returns 0 when the number of children is enough small to
17903 + * remove now or the branch fs is a remote fs.
17904 + * otherwise return an error.
17906 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
17907 + struct au_nhash *whlist, struct inode *dir)
17909 + int rmdir_later, err, dirwh;
17910 + struct dentry *h_dentry;
17911 + struct super_block *sb;
17913 + sb = dentry->d_sb;
17914 + SiMustAnyLock(sb);
17915 + h_dentry = au_h_dptr(dentry, bindex);
17916 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
17917 + if (unlikely(err))
17920 + /* stop monitoring */
17921 + au_hn_free(au_hi(dentry->d_inode, bindex));
17923 + if (!au_test_fs_remote(h_dentry->d_sb)) {
17924 + dirwh = au_sbi(sb)->si_dirwh;
17925 + rmdir_later = (dirwh <= 1);
17926 + if (!rmdir_later)
17927 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
17930 + return rmdir_later;
17933 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
17934 + if (unlikely(err)) {
17935 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
17936 + h_dentry, bindex, err);
17946 + * final procedure for deleting a entry.
17947 + * maintain dentry and iattr.
17949 +static void epilog(struct inode *dir, struct dentry *dentry,
17950 + aufs_bindex_t bindex)
17952 + struct inode *inode;
17954 + inode = dentry->d_inode;
17956 + inode->i_ctime = dir->i_ctime;
17958 + if (au_ibstart(dir) == bindex)
17959 + au_cpup_attr_timesizes(dir);
17960 + dir->i_version++;
17964 + * when an error happened, remove the created whiteout and revert everything.
17966 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
17967 + aufs_bindex_t bwh, struct dentry *wh_dentry,
17968 + struct dentry *dentry, struct au_dtime *dt)
17971 + struct path h_path = {
17972 + .dentry = wh_dentry,
17973 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
17976 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
17978 + au_set_dbwh(dentry, bwh);
17979 + au_dtime_revert(dt);
17983 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
17987 +/* ---------------------------------------------------------------------- */
17989 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
17992 + aufs_bindex_t bwh, bindex, bstart;
17993 + struct inode *inode, *h_dir, *delegated;
17994 + struct dentry *parent, *wh_dentry;
17995 + /* to reuduce stack size */
17997 + struct au_dtime dt;
17998 + struct au_pin pin;
17999 + struct path h_path;
18005 + a = kmalloc(sizeof(*a), GFP_NOFS);
18006 + if (unlikely(!a))
18009 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
18010 + if (unlikely(err))
18012 + err = au_d_hashed_positive(dentry);
18013 + if (unlikely(err))
18015 + inode = dentry->d_inode;
18016 + IMustLock(inode);
18018 + if (unlikely(S_ISDIR(inode->i_mode)))
18019 + goto out_unlock; /* possible? */
18021 + bstart = au_dbstart(dentry);
18022 + bwh = au_dbwh(dentry);
18024 + parent = dentry->d_parent; /* dir inode is locked */
18025 + di_write_lock_parent(parent);
18026 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
18028 + err = PTR_ERR(wh_dentry);
18029 + if (IS_ERR(wh_dentry))
18032 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
18033 + a->h_path.dentry = au_h_dptr(dentry, bstart);
18034 + dget(a->h_path.dentry);
18035 + if (bindex == bstart) {
18036 + h_dir = au_pinned_h_dir(&a->pin);
18037 + delegated = NULL;
18038 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
18039 + if (unlikely(err == -EWOULDBLOCK)) {
18040 + pr_warn("cannot retry for NFSv4 delegation"
18041 + " for an internal unlink\n");
18045 + /* dir inode is locked */
18046 + h_dir = wh_dentry->d_parent->d_inode;
18047 + IMustLock(h_dir);
18052 + vfsub_drop_nlink(inode);
18053 + epilog(dir, dentry, bindex);
18055 + /* update target timestamps */
18056 + if (bindex == bstart) {
18057 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
18059 + inode->i_ctime = a->h_path.dentry->d_inode->i_ctime;
18061 + /* todo: this timestamp may be reverted later */
18062 + inode->i_ctime = h_dir->i_ctime;
18063 + goto out_unpin; /* success */
18070 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
18077 + au_unpin(&a->pin);
18079 + dput(a->h_path.dentry);
18081 + di_write_unlock(parent);
18083 + aufs_read_unlock(dentry, AuLock_DW);
18090 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
18092 + int err, rmdir_later;
18093 + aufs_bindex_t bwh, bindex, bstart;
18094 + struct inode *inode;
18095 + struct dentry *parent, *wh_dentry, *h_dentry;
18096 + struct au_whtmp_rmdir *args;
18097 + /* to reuduce stack size */
18099 + struct au_dtime dt;
18100 + struct au_pin pin;
18106 + a = kmalloc(sizeof(*a), GFP_NOFS);
18107 + if (unlikely(!a))
18110 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
18111 + if (unlikely(err))
18113 + err = au_alive_dir(dentry);
18114 + if (unlikely(err))
18116 + inode = dentry->d_inode;
18117 + IMustLock(inode);
18119 + if (unlikely(!S_ISDIR(inode->i_mode)))
18120 + goto out_unlock; /* possible? */
18123 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
18124 + if (unlikely(!args))
18127 + parent = dentry->d_parent; /* dir inode is locked */
18128 + di_write_lock_parent(parent);
18129 + err = au_test_empty(dentry, &args->whlist);
18130 + if (unlikely(err))
18133 + bstart = au_dbstart(dentry);
18134 + bwh = au_dbwh(dentry);
18136 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
18138 + err = PTR_ERR(wh_dentry);
18139 + if (IS_ERR(wh_dentry))
18142 + h_dentry = au_h_dptr(dentry, bstart);
18145 + if (bindex == bstart) {
18146 + err = renwh_and_rmdir(dentry, bstart, &args->whlist, dir);
18148 + rmdir_later = err;
18152 + /* stop monitoring */
18153 + au_hn_free(au_hi(inode, bstart));
18155 + /* dir inode is locked */
18156 + IMustLock(wh_dentry->d_parent->d_inode);
18161 + vfsub_dead_dir(inode);
18162 + au_set_dbdiropq(dentry, -1);
18163 + epilog(dir, dentry, bindex);
18165 + if (rmdir_later) {
18166 + au_whtmp_kick_rmdir(dir, bstart, h_dentry, args);
18170 + goto out_unpin; /* success */
18178 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
18185 + au_unpin(&a->pin);
18189 + di_write_unlock(parent);
18191 + au_whtmp_rmdir_free(args);
18193 + aufs_read_unlock(dentry, AuLock_DW);
18200 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
18201 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
18202 +++ linux/fs/aufs/i_op_ren.c 2014-01-20 20:16:14.739463504 +0100
18205 + * Copyright (C) 2005-2014 Junjiro R. Okajima
18207 + * This program, aufs is free software; you can redistribute it and/or modify
18208 + * it under the terms of the GNU General Public License as published by
18209 + * the Free Software Foundation; either version 2 of the License, or
18210 + * (at your option) any later version.
18212 + * This program is distributed in the hope that it will be useful,
18213 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18214 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18215 + * GNU General Public License for more details.
18217 + * You should have received a copy of the GNU General Public License
18218 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18222 + * inode operation (rename entry)
18223 + * todo: this is crazy monster
18228 +enum { AuSRC, AuDST, AuSrcDst };
18229 +enum { AuPARENT, AuCHILD, AuParentChild };
18231 +#define AuRen_ISDIR 1
18232 +#define AuRen_ISSAMEDIR (1 << 1)
18233 +#define AuRen_WHSRC (1 << 2)
18234 +#define AuRen_WHDST (1 << 3)
18235 +#define AuRen_MNT_WRITE (1 << 4)
18236 +#define AuRen_DT_DSTDIR (1 << 5)
18237 +#define AuRen_DIROPQ (1 << 6)
18238 +#define AuRen_CPUP (1 << 7)
18239 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
18240 +#define au_fset_ren(flags, name) \
18241 + do { (flags) |= AuRen_##name; } while (0)
18242 +#define au_fclr_ren(flags, name) \
18243 + do { (flags) &= ~AuRen_##name; } while (0)
18245 +struct au_ren_args {
18247 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
18249 + struct inode *dir, *inode;
18250 + struct au_hinode *hdir;
18251 + struct au_dtime dt[AuParentChild];
18252 + aufs_bindex_t bstart;
18255 +#define src_dentry sd[AuSRC].dentry
18256 +#define src_dir sd[AuSRC].dir
18257 +#define src_inode sd[AuSRC].inode
18258 +#define src_h_dentry sd[AuSRC].h_dentry
18259 +#define src_parent sd[AuSRC].parent
18260 +#define src_h_parent sd[AuSRC].h_parent
18261 +#define src_wh_dentry sd[AuSRC].wh_dentry
18262 +#define src_hdir sd[AuSRC].hdir
18263 +#define src_h_dir sd[AuSRC].hdir->hi_inode
18264 +#define src_dt sd[AuSRC].dt
18265 +#define src_bstart sd[AuSRC].bstart
18267 +#define dst_dentry sd[AuDST].dentry
18268 +#define dst_dir sd[AuDST].dir
18269 +#define dst_inode sd[AuDST].inode
18270 +#define dst_h_dentry sd[AuDST].h_dentry
18271 +#define dst_parent sd[AuDST].parent
18272 +#define dst_h_parent sd[AuDST].h_parent
18273 +#define dst_wh_dentry sd[AuDST].wh_dentry
18274 +#define dst_hdir sd[AuDST].hdir
18275 +#define dst_h_dir sd[AuDST].hdir->hi_inode
18276 +#define dst_dt sd[AuDST].dt
18277 +#define dst_bstart sd[AuDST].bstart
18279 + struct dentry *h_trap;
18280 + struct au_branch *br;
18281 + struct au_hinode *src_hinode;
18282 + struct path h_path;
18283 + struct au_nhash whlist;
18284 + aufs_bindex_t btgt, src_bwh, src_bdiropq;
18286 + unsigned int flags;
18288 + struct au_whtmp_rmdir *thargs;
18289 + struct dentry *h_dst;
18292 +/* ---------------------------------------------------------------------- */
18295 + * functions for reverting.
18296 + * when an error happened in a single rename systemcall, we should revert
18297 + * everything as if nothing happend.
18298 + * we don't need to revert the copied-up/down the parent dir since they are
18302 +#define RevertFailure(fmt, ...) do { \
18303 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
18304 + ##__VA_ARGS__, err, rerr); \
18308 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
18312 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
18313 + rerr = au_diropq_remove(a->src_dentry, a->btgt);
18314 + au_hn_imtx_unlock(a->src_hinode);
18315 + au_set_dbdiropq(a->src_dentry, a->src_bdiropq);
18317 + RevertFailure("remove diropq %pd", a->src_dentry);
18320 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
18323 + struct inode *delegated;
18325 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
18326 + a->src_h_parent);
18327 + rerr = PTR_ERR(a->h_path.dentry);
18328 + if (IS_ERR(a->h_path.dentry)) {
18329 + RevertFailure("lkup one %pd", a->src_dentry);
18333 + delegated = NULL;
18334 + rerr = vfsub_rename(a->dst_h_dir,
18335 + au_h_dptr(a->src_dentry, a->btgt),
18336 + a->src_h_dir, &a->h_path, &delegated);
18337 + if (unlikely(rerr == -EWOULDBLOCK)) {
18338 + pr_warn("cannot retry for NFSv4 delegation"
18339 + " for an internal rename\n");
18342 + d_drop(a->h_path.dentry);
18343 + dput(a->h_path.dentry);
18344 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
18346 + RevertFailure("rename %pd", a->src_dentry);
18349 +static void au_ren_rev_cpup(int err, struct au_ren_args *a)
18353 + a->h_path.dentry = a->dst_h_dentry;
18354 + /* no delegation since it is just created */
18355 + rerr = vfsub_unlink(a->dst_h_dir, &a->h_path, /*delegated*/NULL,
18357 + au_set_h_dptr(a->src_dentry, a->btgt, NULL);
18358 + au_set_dbstart(a->src_dentry, a->src_bstart);
18360 + RevertFailure("unlink %pd", a->dst_h_dentry);
18363 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
18366 + struct inode *delegated;
18368 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
18369 + a->dst_h_parent);
18370 + rerr = PTR_ERR(a->h_path.dentry);
18371 + if (IS_ERR(a->h_path.dentry)) {
18372 + RevertFailure("lkup one %pd", a->dst_dentry);
18375 + if (a->h_path.dentry->d_inode) {
18376 + d_drop(a->h_path.dentry);
18377 + dput(a->h_path.dentry);
18381 + delegated = NULL;
18382 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
18384 + if (unlikely(rerr == -EWOULDBLOCK)) {
18385 + pr_warn("cannot retry for NFSv4 delegation"
18386 + " for an internal rename\n");
18389 + d_drop(a->h_path.dentry);
18390 + dput(a->h_path.dentry);
18392 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
18394 + RevertFailure("rename %pd", a->h_dst);
18397 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
18401 + a->h_path.dentry = a->src_wh_dentry;
18402 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
18403 + au_set_dbwh(a->src_dentry, a->src_bwh);
18405 + RevertFailure("unlink %pd", a->src_wh_dentry);
18407 +#undef RevertFailure
18409 +/* ---------------------------------------------------------------------- */
18412 + * when we have to copyup the renaming entry, do it with the rename-target name
18413 + * in order to minimize the cost (the later actual rename is unnecessary).
18414 + * otherwise rename it on the target branch.
18416 +static int au_ren_or_cpup(struct au_ren_args *a)
18419 + struct dentry *d;
18420 + struct inode *delegated;
18422 + d = a->src_dentry;
18423 + if (au_dbstart(d) == a->btgt) {
18424 + a->h_path.dentry = a->dst_h_dentry;
18425 + if (au_ftest_ren(a->flags, DIROPQ)
18426 + && au_dbdiropq(d) == a->btgt)
18427 + au_fclr_ren(a->flags, DIROPQ);
18428 + AuDebugOn(au_dbstart(d) != a->btgt);
18429 + delegated = NULL;
18430 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
18431 + a->dst_h_dir, &a->h_path, &delegated);
18432 + if (unlikely(err == -EWOULDBLOCK)) {
18433 + pr_warn("cannot retry for NFSv4 delegation"
18434 + " for an internal rename\n");
18440 + if (!err && a->h_dst)
18441 + /* it will be set to dinfo later */
18447 +/* cf. aufs_rmdir() */
18448 +static int au_ren_del_whtmp(struct au_ren_args *a)
18451 + struct inode *dir;
18453 + dir = a->dst_dir;
18454 + SiMustAnyLock(dir->i_sb);
18455 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
18456 + au_sbi(dir->i_sb)->si_dirwh)
18457 + || au_test_fs_remote(a->h_dst->d_sb)) {
18458 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
18459 + if (unlikely(err))
18460 + pr_warn("failed removing whtmp dir %pd (%d), "
18461 + "ignored.\n", a->h_dst, err);
18463 + au_nhash_wh_free(&a->thargs->whlist);
18464 + a->thargs->whlist = a->whlist;
18465 + a->whlist.nh_num = 0;
18466 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
18468 + a->thargs = NULL;
18474 +/* make it 'opaque' dir. */
18475 +static int au_ren_diropq(struct au_ren_args *a)
18478 + struct dentry *diropq;
18481 + a->src_bdiropq = au_dbdiropq(a->src_dentry);
18482 + a->src_hinode = au_hi(a->src_inode, a->btgt);
18483 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
18484 + diropq = au_diropq_create(a->src_dentry, a->btgt);
18485 + au_hn_imtx_unlock(a->src_hinode);
18486 + if (IS_ERR(diropq))
18487 + err = PTR_ERR(diropq);
18493 +static int do_rename(struct au_ren_args *a)
18496 + struct dentry *d, *h_d;
18498 + /* prepare workqueue args for asynchronous rmdir */
18499 + h_d = a->dst_h_dentry;
18500 + if (au_ftest_ren(a->flags, ISDIR) && h_d->d_inode) {
18502 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb, GFP_NOFS);
18503 + if (unlikely(!a->thargs))
18505 + a->h_dst = dget(h_d);
18508 + /* create whiteout for src_dentry */
18509 + if (au_ftest_ren(a->flags, WHSRC)) {
18510 + a->src_bwh = au_dbwh(a->src_dentry);
18511 + AuDebugOn(a->src_bwh >= 0);
18513 + = au_wh_create(a->src_dentry, a->btgt, a->src_h_parent);
18514 + err = PTR_ERR(a->src_wh_dentry);
18515 + if (IS_ERR(a->src_wh_dentry))
18519 + /* lookup whiteout for dentry */
18520 + if (au_ftest_ren(a->flags, WHDST)) {
18521 + h_d = au_wh_lkup(a->dst_h_parent, &a->dst_dentry->d_name,
18523 + err = PTR_ERR(h_d);
18526 + if (!h_d->d_inode)
18529 + a->dst_wh_dentry = h_d;
18532 + /* rename dentry to tmpwh */
18534 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
18535 + if (unlikely(err))
18538 + d = a->dst_dentry;
18539 + au_set_h_dptr(d, a->btgt, NULL);
18540 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
18541 + if (unlikely(err))
18543 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
18546 + BUG_ON(a->dst_h_dentry->d_inode && a->src_bstart != a->btgt);
18548 + /* rename by vfs_rename or cpup */
18549 + d = a->dst_dentry;
18550 + if (au_ftest_ren(a->flags, ISDIR)
18551 + && (a->dst_wh_dentry
18552 + || au_dbdiropq(d) == a->btgt
18553 + /* hide the lower to keep xino */
18554 + || a->btgt < au_dbend(d)
18555 + || au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ)))
18556 + au_fset_ren(a->flags, DIROPQ);
18557 + err = au_ren_or_cpup(a);
18558 + if (unlikely(err))
18559 + /* leave the copied-up one */
18562 + /* make dir opaque */
18563 + if (au_ftest_ren(a->flags, DIROPQ)) {
18564 + err = au_ren_diropq(a);
18565 + if (unlikely(err))
18569 + /* update target timestamps */
18570 + AuDebugOn(au_dbstart(a->src_dentry) != a->btgt);
18571 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
18572 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
18573 + a->src_inode->i_ctime = a->h_path.dentry->d_inode->i_ctime;
18575 + /* remove whiteout for dentry */
18576 + if (a->dst_wh_dentry) {
18577 + a->h_path.dentry = a->dst_wh_dentry;
18578 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
18580 + if (unlikely(err))
18584 + /* remove whtmp */
18586 + au_ren_del_whtmp(a); /* ignore this error */
18589 + goto out_success;
18592 + if (au_ftest_ren(a->flags, DIROPQ))
18593 + au_ren_rev_diropq(err, a);
18595 + if (!au_ftest_ren(a->flags, CPUP))
18596 + au_ren_rev_rename(err, a);
18598 + au_ren_rev_cpup(err, a);
18602 + au_ren_rev_whtmp(err, a);
18604 + dput(a->dst_wh_dentry);
18605 + a->dst_wh_dentry = NULL;
18607 + if (a->src_wh_dentry)
18608 + au_ren_rev_whsrc(err, a);
18610 + dput(a->src_wh_dentry);
18611 + dput(a->dst_wh_dentry);
18615 + au_whtmp_rmdir_free(a->thargs);
18616 + a->thargs = NULL;
18622 +/* ---------------------------------------------------------------------- */
18625 + * test if @dentry dir can be rename destination or not.
18626 + * success means, it is a logically empty dir.
18628 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
18630 + return au_test_empty(dentry, whlist);
18634 + * test if @dentry dir can be rename source or not.
18635 + * if it can, return 0 and @children is filled.
18637 + * - it is a logically empty dir.
18638 + * - or, it exists on writable branch and has no children including whiteouts
18639 + * on the lower branch.
18641 +static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt)
18644 + unsigned int rdhash;
18645 + aufs_bindex_t bstart;
18647 + bstart = au_dbstart(dentry);
18648 + if (bstart != btgt) {
18649 + struct au_nhash whlist;
18651 + SiMustAnyLock(dentry->d_sb);
18652 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
18654 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
18656 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
18657 + if (unlikely(err))
18659 + err = au_test_empty(dentry, &whlist);
18660 + au_nhash_wh_free(&whlist);
18664 + if (bstart == au_dbtaildir(dentry))
18665 + return 0; /* success */
18667 + err = au_test_empty_lower(dentry);
18670 + if (err == -ENOTEMPTY) {
18671 + AuWarn1("renaming dir who has child(ren) on multiple branches,"
18672 + " is not supported\n");
18678 +/* side effect: sets whlist and h_dentry */
18679 +static int au_ren_may_dir(struct au_ren_args *a)
18682 + unsigned int rdhash;
18683 + struct dentry *d;
18685 + d = a->dst_dentry;
18686 + SiMustAnyLock(d->d_sb);
18689 + if (au_ftest_ren(a->flags, ISDIR) && a->dst_inode) {
18690 + rdhash = au_sbi(d->d_sb)->si_rdhash;
18692 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
18693 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
18694 + if (unlikely(err))
18697 + au_set_dbstart(d, a->dst_bstart);
18698 + err = may_rename_dstdir(d, &a->whlist);
18699 + au_set_dbstart(d, a->btgt);
18701 + a->dst_h_dentry = au_h_dptr(d, au_dbstart(d));
18702 + if (unlikely(err))
18705 + d = a->src_dentry;
18706 + a->src_h_dentry = au_h_dptr(d, au_dbstart(d));
18707 + if (au_ftest_ren(a->flags, ISDIR)) {
18708 + err = may_rename_srcdir(d, a->btgt);
18709 + if (unlikely(err)) {
18710 + au_nhash_wh_free(&a->whlist);
18711 + a->whlist.nh_num = 0;
18718 +/* ---------------------------------------------------------------------- */
18721 + * simple tests for rename.
18722 + * following the checks in vfs, plus the parent-child relationship.
18724 +static int au_may_ren(struct au_ren_args *a)
18727 + struct inode *h_inode;
18729 + if (a->src_bstart == a->btgt) {
18730 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
18731 + au_ftest_ren(a->flags, ISDIR));
18732 + if (unlikely(err))
18735 + if (unlikely(a->src_h_dentry == a->h_trap))
18740 + if (a->dst_bstart != a->btgt)
18743 + err = -ENOTEMPTY;
18744 + if (unlikely(a->dst_h_dentry == a->h_trap))
18748 + h_inode = a->dst_h_dentry->d_inode;
18749 + isdir = !!au_ftest_ren(a->flags, ISDIR);
18750 + if (!a->dst_dentry->d_inode) {
18751 + if (unlikely(h_inode))
18753 + err = au_may_add(a->dst_dentry, a->btgt, a->dst_h_parent,
18756 + if (unlikely(!h_inode || !h_inode->i_nlink))
18758 + err = au_may_del(a->dst_dentry, a->btgt, a->dst_h_parent,
18760 + if (unlikely(err))
18765 + if (unlikely(err == -ENOENT || err == -EEXIST))
18771 +/* ---------------------------------------------------------------------- */
18776 + * - src_dir and dir by lock_rename()
18777 + * - inode if exitsts
18780 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
18782 + * + di_write_lock2_child()
18783 + * + di_write_lock_child()
18784 + * + ii_write_lock_child()
18785 + * + di_write_lock_child2()
18786 + * + ii_write_lock_child2()
18787 + * + src_parent and parent
18788 + * + di_write_lock_parent()
18789 + * + ii_write_lock_parent()
18790 + * + di_write_lock_parent2()
18791 + * + ii_write_lock_parent2()
18792 + * + lower src_dir and dir by vfsub_lock_rename()
18793 + * + verify the every relationships between child and parent. if any
18794 + * of them failed, unlock all and return -EBUSY.
18796 +static void au_ren_unlock(struct au_ren_args *a)
18798 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
18799 + a->dst_h_parent, a->dst_hdir);
18800 + if (au_ftest_ren(a->flags, MNT_WRITE))
18801 + vfsub_mnt_drop_write(au_br_mnt(a->br));
18804 +static int au_ren_lock(struct au_ren_args *a)
18807 + unsigned int udba;
18810 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
18811 + a->src_hdir = au_hi(a->src_dir, a->btgt);
18812 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
18813 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
18815 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
18816 + if (unlikely(err))
18818 + au_fset_ren(a->flags, MNT_WRITE);
18819 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
18820 + a->dst_h_parent, a->dst_hdir);
18821 + udba = au_opt_udba(a->src_dentry->d_sb);
18822 + if (unlikely(a->src_hdir->hi_inode != a->src_h_parent->d_inode
18823 + || a->dst_hdir->hi_inode != a->dst_h_parent->d_inode))
18824 + err = au_busy_or_stale();
18825 + if (!err && au_dbstart(a->src_dentry) == a->btgt)
18826 + err = au_h_verify(a->src_h_dentry, udba,
18827 + a->src_h_parent->d_inode, a->src_h_parent,
18829 + if (!err && au_dbstart(a->dst_dentry) == a->btgt)
18830 + err = au_h_verify(a->dst_h_dentry, udba,
18831 + a->dst_h_parent->d_inode, a->dst_h_parent,
18834 + goto out; /* success */
18836 + err = au_busy_or_stale();
18837 + au_ren_unlock(a);
18843 +/* ---------------------------------------------------------------------- */
18845 +static void au_ren_refresh_dir(struct au_ren_args *a)
18847 + struct inode *dir;
18849 + dir = a->dst_dir;
18850 + dir->i_version++;
18851 + if (au_ftest_ren(a->flags, ISDIR)) {
18852 + /* is this updating defined in POSIX? */
18853 + au_cpup_attr_timesizes(a->src_inode);
18854 + au_cpup_attr_nlink(dir, /*force*/1);
18857 + if (au_ibstart(dir) == a->btgt)
18858 + au_cpup_attr_timesizes(dir);
18860 + if (au_ftest_ren(a->flags, ISSAMEDIR))
18863 + dir = a->src_dir;
18864 + dir->i_version++;
18865 + if (au_ftest_ren(a->flags, ISDIR))
18866 + au_cpup_attr_nlink(dir, /*force*/1);
18867 + if (au_ibstart(dir) == a->btgt)
18868 + au_cpup_attr_timesizes(dir);
18871 +static void au_ren_refresh(struct au_ren_args *a)
18873 + aufs_bindex_t bend, bindex;
18874 + struct dentry *d, *h_d;
18875 + struct inode *i, *h_i;
18876 + struct super_block *sb;
18878 + d = a->dst_dentry;
18881 + /* already dget-ed by au_ren_or_cpup() */
18882 + au_set_h_dptr(d, a->btgt, a->h_dst);
18884 + i = a->dst_inode;
18886 + if (!au_ftest_ren(a->flags, ISDIR))
18887 + vfsub_drop_nlink(i);
18889 + vfsub_dead_dir(i);
18890 + au_cpup_attr_timesizes(i);
18892 + au_update_dbrange(d, /*do_put_zero*/1);
18895 + for (bindex = au_dbstart(d); bindex < bend; bindex++)
18896 + au_set_h_dptr(d, bindex, NULL);
18897 + bend = au_dbend(d);
18898 + for (bindex = a->btgt + 1; bindex <= bend; bindex++)
18899 + au_set_h_dptr(d, bindex, NULL);
18900 + au_update_dbrange(d, /*do_put_zero*/0);
18903 + d = a->src_dentry;
18904 + au_set_dbwh(d, -1);
18905 + bend = au_dbend(d);
18906 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
18907 + h_d = au_h_dptr(d, bindex);
18909 + au_set_h_dptr(d, bindex, NULL);
18911 + au_set_dbend(d, a->btgt);
18914 + i = a->src_inode;
18915 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
18916 + return; /* success */
18918 + bend = au_ibend(i);
18919 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
18920 + h_i = au_h_iptr(i, bindex);
18922 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
18923 + /* ignore this error */
18924 + au_set_h_iptr(i, bindex, NULL, 0);
18927 + au_set_ibend(i, a->btgt);
18930 +/* ---------------------------------------------------------------------- */
18932 +/* mainly for link(2) and rename(2) */
18933 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
18935 + aufs_bindex_t bdiropq, bwh;
18936 + struct dentry *parent;
18937 + struct au_branch *br;
18939 + parent = dentry->d_parent;
18940 + IMustLock(parent->d_inode); /* dir is locked */
18942 + bdiropq = au_dbdiropq(parent);
18943 + bwh = au_dbwh(dentry);
18944 + br = au_sbr(dentry->d_sb, btgt);
18945 + if (au_br_rdonly(br)
18946 + || (0 <= bdiropq && bdiropq < btgt)
18947 + || (0 <= bwh && bwh < btgt))
18950 + AuDbg("btgt %d\n", btgt);
18954 +/* sets src_bstart, dst_bstart and btgt */
18955 +static int au_ren_wbr(struct au_ren_args *a)
18958 + struct au_wr_dir_args wr_dir_args = {
18959 + /* .force_btgt = -1, */
18960 + .flags = AuWrDir_ADD_ENTRY
18963 + a->src_bstart = au_dbstart(a->src_dentry);
18964 + a->dst_bstart = au_dbstart(a->dst_dentry);
18965 + if (au_ftest_ren(a->flags, ISDIR))
18966 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
18967 + wr_dir_args.force_btgt = a->src_bstart;
18968 + if (a->dst_inode && a->dst_bstart < a->src_bstart)
18969 + wr_dir_args.force_btgt = a->dst_bstart;
18970 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
18971 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
18977 +static void au_ren_dt(struct au_ren_args *a)
18979 + a->h_path.dentry = a->src_h_parent;
18980 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
18981 + if (!au_ftest_ren(a->flags, ISSAMEDIR)) {
18982 + a->h_path.dentry = a->dst_h_parent;
18983 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
18986 + au_fclr_ren(a->flags, DT_DSTDIR);
18987 + if (!au_ftest_ren(a->flags, ISDIR))
18990 + a->h_path.dentry = a->src_h_dentry;
18991 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
18992 + if (a->dst_h_dentry->d_inode) {
18993 + au_fset_ren(a->flags, DT_DSTDIR);
18994 + a->h_path.dentry = a->dst_h_dentry;
18995 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
18999 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
19001 + struct dentry *h_d;
19002 + struct mutex *h_mtx;
19004 + au_dtime_revert(a->src_dt + AuPARENT);
19005 + if (!au_ftest_ren(a->flags, ISSAMEDIR))
19006 + au_dtime_revert(a->dst_dt + AuPARENT);
19008 + if (au_ftest_ren(a->flags, ISDIR) && err != -EIO) {
19009 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
19010 + h_mtx = &h_d->d_inode->i_mutex;
19011 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
19012 + au_dtime_revert(a->src_dt + AuCHILD);
19013 + mutex_unlock(h_mtx);
19015 + if (au_ftest_ren(a->flags, DT_DSTDIR)) {
19016 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
19017 + h_mtx = &h_d->d_inode->i_mutex;
19018 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
19019 + au_dtime_revert(a->dst_dt + AuCHILD);
19020 + mutex_unlock(h_mtx);
19025 +/* ---------------------------------------------------------------------- */
19027 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
19028 + struct inode *_dst_dir, struct dentry *_dst_dentry)
19031 + /* reduce stack space */
19032 + struct au_ren_args *a;
19034 + AuDbg("%pd, %pd\n", _src_dentry, _dst_dentry);
19035 + IMustLock(_src_dir);
19036 + IMustLock(_dst_dir);
19039 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
19040 + a = kzalloc(sizeof(*a), GFP_NOFS);
19041 + if (unlikely(!a))
19044 + a->src_dir = _src_dir;
19045 + a->src_dentry = _src_dentry;
19046 + a->src_inode = a->src_dentry->d_inode;
19047 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
19048 + a->dst_dir = _dst_dir;
19049 + a->dst_dentry = _dst_dentry;
19050 + a->dst_inode = a->dst_dentry->d_inode;
19051 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
19052 + if (a->dst_inode) {
19053 + IMustLock(a->dst_inode);
19054 + au_igrab(a->dst_inode);
19058 + flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
19059 + if (S_ISDIR(a->src_inode->i_mode)) {
19060 + au_fset_ren(a->flags, ISDIR);
19061 + if (unlikely(a->dst_inode && !S_ISDIR(a->dst_inode->i_mode)))
19063 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
19064 + AuLock_DIR | flags);
19066 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
19068 + if (unlikely(err))
19071 + err = au_d_hashed_positive(a->src_dentry);
19072 + if (unlikely(err))
19075 + if (a->dst_inode) {
19077 + * If it is a dir, VFS unhash dst_dentry before this
19078 + * function. It means we cannot rely upon d_unhashed().
19080 + if (unlikely(!a->dst_inode->i_nlink))
19082 + if (!S_ISDIR(a->dst_inode->i_mode)) {
19083 + err = au_d_hashed_positive(a->dst_dentry);
19084 + if (unlikely(err))
19086 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
19088 + } else if (unlikely(d_unhashed(a->dst_dentry)))
19092 + * is it possible?
19093 + * yes, it happend (in linux-3.3-rcN) but I don't know why.
19094 + * there may exist a problem somewhere else.
19097 + if (unlikely(a->dst_parent->d_inode == a->src_dentry->d_inode))
19100 + au_fset_ren(a->flags, ISSAMEDIR); /* temporary */
19101 + di_write_lock_parent(a->dst_parent);
19103 + /* which branch we process */
19104 + err = au_ren_wbr(a);
19105 + if (unlikely(err < 0))
19107 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
19108 + a->h_path.mnt = au_br_mnt(a->br);
19110 + /* are they available to be renamed */
19111 + err = au_ren_may_dir(a);
19112 + if (unlikely(err))
19113 + goto out_children;
19115 + /* prepare the writable parent dir on the same branch */
19116 + if (a->dst_bstart == a->btgt) {
19117 + au_fset_ren(a->flags, WHDST);
19119 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
19120 + if (unlikely(err))
19121 + goto out_children;
19124 + if (a->src_dir != a->dst_dir) {
19126 + * this temporary unlock is safe,
19127 + * because both dir->i_mutex are locked.
19129 + di_write_unlock(a->dst_parent);
19130 + di_write_lock_parent(a->src_parent);
19131 + err = au_wr_dir_need_wh(a->src_dentry,
19132 + au_ftest_ren(a->flags, ISDIR),
19134 + di_write_unlock(a->src_parent);
19135 + di_write_lock2_parent(a->src_parent, a->dst_parent, /*isdir*/1);
19136 + au_fclr_ren(a->flags, ISSAMEDIR);
19138 + err = au_wr_dir_need_wh(a->src_dentry,
19139 + au_ftest_ren(a->flags, ISDIR),
19141 + if (unlikely(err < 0))
19142 + goto out_children;
19144 + au_fset_ren(a->flags, WHSRC);
19147 + if (a->src_bstart != a->btgt) {
19148 + struct au_pin pin;
19150 + err = au_pin(&pin, a->src_dentry, a->btgt,
19151 + au_opt_udba(a->src_dentry->d_sb),
19152 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19154 + struct au_cp_generic cpg = {
19155 + .dentry = a->src_dentry,
19157 + .bsrc = a->src_bstart,
19160 + .flags = AuCpup_DTIME | AuCpup_HOPEN
19162 + AuDebugOn(au_dbstart(a->src_dentry) != a->src_bstart);
19163 + err = au_sio_cpup_simple(&cpg);
19166 + if (unlikely(err))
19167 + goto out_children;
19168 + a->src_bstart = a->btgt;
19169 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
19170 + au_fset_ren(a->flags, WHSRC);
19173 + /* lock them all */
19174 + err = au_ren_lock(a);
19175 + if (unlikely(err))
19176 + /* leave the copied-up one */
19177 + goto out_children;
19179 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
19180 + err = au_may_ren(a);
19181 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
19182 + err = -ENAMETOOLONG;
19183 + if (unlikely(err))
19186 + /* store timestamps to be revertible */
19190 + err = do_rename(a);
19191 + if (unlikely(err))
19194 + /* update dir attributes */
19195 + au_ren_refresh_dir(a);
19197 + /* dput/iput all lower dentries */
19198 + au_ren_refresh(a);
19200 + goto out_hdir; /* success */
19203 + au_ren_rev_dt(err, a);
19205 + au_ren_unlock(a);
19207 + au_nhash_wh_free(&a->whlist);
19208 + if (err && a->dst_inode && a->dst_bstart != a->btgt) {
19209 + AuDbg("bstart %d, btgt %d\n", a->dst_bstart, a->btgt);
19210 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
19211 + au_set_dbstart(a->dst_dentry, a->dst_bstart);
19215 + d_move(a->src_dentry, a->dst_dentry);
19217 + au_update_dbstart(a->dst_dentry);
19218 + if (!a->dst_inode)
19219 + d_drop(a->dst_dentry);
19221 + if (au_ftest_ren(a->flags, ISSAMEDIR))
19222 + di_write_unlock(a->dst_parent);
19224 + di_write_unlock2(a->src_parent, a->dst_parent);
19226 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
19228 + iput(a->dst_inode);
19230 + au_whtmp_rmdir_free(a->thargs);
19236 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
19237 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
19238 +++ linux/fs/aufs/Kconfig 2014-01-20 20:16:14.732796615 +0100
19241 + tristate "Aufs (Advanced multi layered unification filesystem) support"
19243 + Aufs is a stackable unification filesystem such as Unionfs,
19244 + which unifies several directories and provides a merged single
19246 + In the early days, aufs was entirely re-designed and
19247 + re-implemented Unionfs Version 1.x series. Introducing many
19248 + original ideas, approaches and improvements, it becomes totally
19249 + different from Unionfs while keeping the basic features.
19253 + prompt "Maximum number of branches"
19254 + default AUFS_BRANCH_MAX_127
19256 + Specifies the maximum number of branches (or member directories)
19257 + in a single aufs. The larger value consumes more system
19258 + resources and has a minor impact to performance.
19259 +config AUFS_BRANCH_MAX_127
19262 + Specifies the maximum number of branches (or member directories)
19263 + in a single aufs. The larger value consumes more system
19264 + resources and has a minor impact to performance.
19265 +config AUFS_BRANCH_MAX_511
19268 + Specifies the maximum number of branches (or member directories)
19269 + in a single aufs. The larger value consumes more system
19270 + resources and has a minor impact to performance.
19271 +config AUFS_BRANCH_MAX_1023
19274 + Specifies the maximum number of branches (or member directories)
19275 + in a single aufs. The larger value consumes more system
19276 + resources and has a minor impact to performance.
19277 +config AUFS_BRANCH_MAX_32767
19280 + Specifies the maximum number of branches (or member directories)
19281 + in a single aufs. The larger value consumes more system
19282 + resources and has a minor impact to performance.
19285 +config AUFS_SBILIST
19287 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
19290 + Automatic configuration for internal use.
19291 + When aufs supports Magic SysRq or /proc, enabled automatically.
19293 +config AUFS_HNOTIFY
19294 + bool "Detect direct branch access (bypassing aufs)"
19296 + If you want to modify files on branches directly, eg. bypassing aufs,
19297 + and want aufs to detect the changes of them fully, then enable this
19298 + option and use 'udba=notify' mount option.
19299 + Currently there is only one available configuration, "fsnotify".
19300 + It will have a negative impact to the performance.
19301 + See detail in aufs.5.
19304 + prompt "method" if AUFS_HNOTIFY
19305 + default AUFS_HFSNOTIFY
19306 +config AUFS_HFSNOTIFY
19311 +config AUFS_EXPORT
19312 + bool "NFS-exportable aufs"
19313 + depends on EXPORTFS
19315 + If you want to export your mounted aufs via NFS, then enable this
19316 + option. There are several requirements for this configuration.
19317 + See detail in aufs.5.
19319 +config AUFS_INO_T_64
19321 + depends on AUFS_EXPORT
19322 + depends on 64BIT && !(ALPHA || S390)
19325 + Automatic configuration for internal use.
19326 + /* typedef unsigned long/int __kernel_ino_t */
19327 + /* alpha and s390x are int */
19330 + bool "Readdir in userspace"
19332 + Aufs has two methods to provide a merged view for a directory,
19333 + by a user-space library and by kernel-space natively. The latter
19334 + is always enabled but sometimes large and slow.
19335 + If you enable this option, install the library in aufs2-util
19336 + package, and set some environment variables for your readdir(3),
19337 + then the work will be handled in user-space which generally
19338 + shows better performance in most cases.
19339 + See detail in aufs.5.
19341 +config AUFS_SP_IATTR
19342 + bool "Respect the attributes (mtime/ctime mainly) of special files"
19344 + When you write something to a special file, some attributes of it
19345 + (mtime/ctime mainly) may be updated. Generally such updates are
19346 + less important (actually some device drivers and NFS ignore
19347 + it). But some applications (such like test program) requires
19348 + such updates. If you need these updates, then enable this
19349 + configuration which introduces some overhead.
19350 + Currently this configuration handles FIFO only.
19353 + bool "Show whiteouts"
19355 + If you want to make the whiteouts in aufs visible, then enable
19356 + this option and specify 'shwh' mount option. Although it may
19357 + sounds like philosophy or something, but in technically it
19358 + simply shows the name of whiteout with keeping its behaviour.
19360 +config AUFS_BR_RAMFS
19361 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
19363 + If you want to use ramfs as an aufs branch fs, then enable this
19364 + option. Generally tmpfs is recommended.
19365 + Aufs prohibited them to be a branch fs by default, because
19366 + initramfs becomes unusable after switch_root or something
19367 + generally. If you sets initramfs as an aufs branch and boot your
19368 + system by switch_root, you will meet a problem easily since the
19369 + files in initramfs may be inaccessible.
19370 + Unless you are going to use ramfs as an aufs branch fs without
19371 + switch_root or something, leave it N.
19373 +config AUFS_BR_FUSE
19374 + bool "Fuse fs as an aufs branch"
19375 + depends on FUSE_FS
19378 + If you want to use fuse-based userspace filesystem as an aufs
19379 + branch fs, then enable this option.
19380 + It implements the internal poll(2) operation which is
19381 + implemented by fuse only (curretnly).
19386 + Automatic configuration for internal use.
19388 +config AUFS_BR_HFSPLUS
19389 + bool "Hfsplus as an aufs branch"
19390 + depends on HFSPLUS_FS
19393 + If you want to use hfsplus fs as an aufs branch fs, then enable
19394 + this option. This option introduces a small overhead at
19395 + copying-up a file on hfsplus.
19397 +config AUFS_BDEV_LOOP
19399 + depends on BLK_DEV_LOOP
19402 + Automatic configuration for internal use.
19403 + Convert =[ym] into =y.
19406 + bool "Debug aufs"
19408 + Enable this to compile aufs internal debug code.
19409 + It will have a negative impact to the performance.
19411 +config AUFS_MAGIC_SYSRQ
19413 + depends on AUFS_DEBUG && MAGIC_SYSRQ
19416 + Automatic configuration for internal use.
19417 + When aufs supports Magic SysRq, enabled automatically.
19419 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
19420 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
19421 +++ linux/fs/aufs/loop.c 2014-01-20 20:16:14.739463504 +0100
19424 + * Copyright (C) 2005-2014 Junjiro R. Okajima
19426 + * This program, aufs is free software; you can redistribute it and/or modify
19427 + * it under the terms of the GNU General Public License as published by
19428 + * the Free Software Foundation; either version 2 of the License, or
19429 + * (at your option) any later version.
19431 + * This program is distributed in the hope that it will be useful,
19432 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19433 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19434 + * GNU General Public License for more details.
19436 + * You should have received a copy of the GNU General Public License
19437 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19441 + * support for loopback block device as a branch
19446 +/* added into drivers/block/loop.c */
19447 +static struct file *(*backing_file_func)(struct super_block *sb);
19450 + * test if two lower dentries have overlapping branches.
19452 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
19454 + struct super_block *h_sb;
19455 + struct file *backing_file;
19457 + if (unlikely(!backing_file_func)) {
19458 + /* don't load "loop" module here */
19459 + backing_file_func = symbol_get(loop_backing_file);
19460 + if (unlikely(!backing_file_func))
19461 + /* "loop" module is not loaded */
19465 + h_sb = h_adding->d_sb;
19466 + backing_file = backing_file_func(h_sb);
19467 + if (!backing_file)
19470 + h_adding = backing_file->f_dentry;
19472 + * h_adding can be local NFS.
19473 + * in this case aufs cannot detect the loop.
19475 + if (unlikely(h_adding->d_sb == sb))
19477 + return !!au_test_subdir(h_adding, sb->s_root);
19480 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
19481 +int au_test_loopback_kthread(void)
19484 + struct task_struct *tsk = current;
19485 + char c, comm[sizeof(tsk->comm)];
19488 + if (tsk->flags & PF_KTHREAD) {
19489 + get_task_comm(comm, tsk);
19491 + ret = ('0' <= c && c <= '9'
19492 + && !strncmp(comm, "loop", 4));
19498 +/* ---------------------------------------------------------------------- */
19500 +#define au_warn_loopback_step 16
19501 +static int au_warn_loopback_nelem = au_warn_loopback_step;
19502 +static unsigned long *au_warn_loopback_array;
19504 +void au_warn_loopback(struct super_block *h_sb)
19506 + int i, new_nelem;
19507 + unsigned long *a, magic;
19508 + static DEFINE_SPINLOCK(spin);
19510 + magic = h_sb->s_magic;
19511 + spin_lock(&spin);
19512 + a = au_warn_loopback_array;
19513 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
19514 + if (a[i] == magic) {
19515 + spin_unlock(&spin);
19519 + /* h_sb is new to us, print it */
19520 + if (i < au_warn_loopback_nelem) {
19525 + /* expand the array */
19526 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
19527 + a = au_kzrealloc(au_warn_loopback_array,
19528 + au_warn_loopback_nelem * sizeof(unsigned long),
19529 + new_nelem * sizeof(unsigned long), GFP_ATOMIC);
19531 + au_warn_loopback_nelem = new_nelem;
19532 + au_warn_loopback_array = a;
19537 + spin_unlock(&spin);
19538 + AuWarn1("realloc failed, ignored\n");
19542 + spin_unlock(&spin);
19543 + pr_warn("you may want to try another patch for loopback file "
19544 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
19547 +int au_loopback_init(void)
19550 + struct super_block *sb __maybe_unused;
19552 + AuDebugOn(sizeof(sb->s_magic) != sizeof(unsigned long));
19555 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
19556 + sizeof(unsigned long), GFP_NOFS);
19557 + if (unlikely(!au_warn_loopback_array))
19563 +void au_loopback_fin(void)
19565 + symbol_put(loop_backing_file);
19566 + kfree(au_warn_loopback_array);
19568 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
19569 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
19570 +++ linux/fs/aufs/loop.h 2014-01-20 20:16:14.739463504 +0100
19573 + * Copyright (C) 2005-2014 Junjiro R. Okajima
19575 + * This program, aufs is free software; you can redistribute it and/or modify
19576 + * it under the terms of the GNU General Public License as published by
19577 + * the Free Software Foundation; either version 2 of the License, or
19578 + * (at your option) any later version.
19580 + * This program is distributed in the hope that it will be useful,
19581 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19582 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19583 + * GNU General Public License for more details.
19585 + * You should have received a copy of the GNU General Public License
19586 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19590 + * support for loopback mount as a branch
19593 +#ifndef __AUFS_LOOP_H__
19594 +#define __AUFS_LOOP_H__
19599 +struct super_block;
19601 +#ifdef CONFIG_AUFS_BDEV_LOOP
19602 +/* drivers/block/loop.c */
19603 +struct file *loop_backing_file(struct super_block *sb);
19606 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
19607 +int au_test_loopback_kthread(void);
19608 +void au_warn_loopback(struct super_block *h_sb);
19610 +int au_loopback_init(void);
19611 +void au_loopback_fin(void);
19613 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
19614 + struct dentry *h_adding)
19615 +AuStubInt0(au_test_loopback_kthread, void)
19616 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
19618 +AuStubInt0(au_loopback_init, void)
19619 +AuStubVoid(au_loopback_fin, void)
19620 +#endif /* BLK_DEV_LOOP */
19622 +#endif /* __KERNEL__ */
19623 +#endif /* __AUFS_LOOP_H__ */
19624 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
19625 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
19626 +++ linux/fs/aufs/magic.mk 2013-07-06 13:20:47.750198454 +0200
19629 +# defined in ${srctree}/fs/fuse/inode.c
19631 +ifdef CONFIG_FUSE_FS
19632 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
19635 +# defined in ${srctree}/fs/ocfs2/ocfs2_fs.h
19637 +ifdef CONFIG_OCFS2_FS
19638 +ccflags-y += -DOCFS2_SUPER_MAGIC=0x7461636f
19641 +# defined in ${srctree}/fs/ocfs2/dlm/userdlm.h
19643 +ifdef CONFIG_OCFS2_FS_O2CB
19644 +ccflags-y += -DDLMFS_MAGIC=0x76a9f425
19647 +# defined in ${srctree}/fs/cifs/cifsfs.c
19649 +ifdef CONFIG_CIFS_FS
19650 +ccflags-y += -DCIFS_MAGIC_NUMBER=0xFF534D42
19653 +# defined in ${srctree}/fs/xfs/xfs_sb.h
19655 +ifdef CONFIG_XFS_FS
19656 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
19659 +# defined in ${srctree}/fs/configfs/mount.c
19661 +ifdef CONFIG_CONFIGFS_FS
19662 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
19665 +# defined in ${srctree}/fs/9p/v9fs.h
19667 +ifdef CONFIG_9P_FS
19668 +ccflags-y += -DV9FS_MAGIC=0x01021997
19671 +# defined in ${srctree}/fs/ubifs/ubifs.h
19673 +ifdef CONFIG_UBIFS_FS
19674 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
19677 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
19679 +ifdef CONFIG_HFSPLUS_FS
19680 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
19682 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
19683 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
19684 +++ linux/fs/aufs/Makefile 2014-01-20 20:16:14.732796615 +0100
19687 +include ${src}/magic.mk
19688 +ifeq (${CONFIG_AUFS_FS},m)
19689 +include ${src}/conf.mk
19691 +-include ${src}/priv_def.mk
19693 +# cf. include/linux/kernel.h
19695 +ccflags-y += -DDEBUG
19696 +# sparse requires the full pathname
19698 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
19700 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
19703 +obj-$(CONFIG_AUFS_FS) += aufs.o
19704 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
19705 + wkq.o vfsub.o dcsub.o \
19706 + cpup.o whout.o wbr_policy.o \
19707 + dinfo.o dentry.o \
19709 + finfo.o file.o f_op.o \
19711 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
19715 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
19716 +aufs-$(CONFIG_SYSFS) += sysfs.o
19717 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
19718 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
19719 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
19720 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
19721 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
19722 +aufs-$(CONFIG_AUFS_POLL) += poll.o
19723 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
19724 +aufs-$(CONFIG_AUFS_SP_IATTR) += f_op_sp.o
19725 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
19726 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
19727 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
19728 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
19729 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
19730 +++ linux/fs/aufs/module.c 2014-01-20 20:16:14.739463504 +0100
19733 + * Copyright (C) 2005-2014 Junjiro R. Okajima
19735 + * This program, aufs is free software; you can redistribute it and/or modify
19736 + * it under the terms of the GNU General Public License as published by
19737 + * the Free Software Foundation; either version 2 of the License, or
19738 + * (at your option) any later version.
19740 + * This program is distributed in the hope that it will be useful,
19741 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19742 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19743 + * GNU General Public License for more details.
19745 + * You should have received a copy of the GNU General Public License
19746 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19750 + * module global variables and operations
19753 +#include <linux/module.h>
19754 +#include <linux/seq_file.h>
19757 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp)
19759 + if (new_sz <= nused)
19762 + p = krealloc(p, new_sz, gfp);
19764 + memset(p + nused, 0, new_sz - nused);
19768 +/* ---------------------------------------------------------------------- */
19773 +struct kmem_cache *au_cachep[AuCache_Last];
19774 +static int __init au_cache_init(void)
19776 + au_cachep[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
19777 + if (au_cachep[AuCache_DINFO])
19778 + /* SLAB_DESTROY_BY_RCU */
19779 + au_cachep[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
19780 + au_icntnr_init_once);
19781 + if (au_cachep[AuCache_ICNTNR])
19782 + au_cachep[AuCache_FINFO] = AuCacheCtor(au_finfo,
19783 + au_fi_init_once);
19784 + if (au_cachep[AuCache_FINFO])
19785 + au_cachep[AuCache_VDIR] = AuCache(au_vdir);
19786 + if (au_cachep[AuCache_VDIR])
19787 + au_cachep[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
19788 + if (au_cachep[AuCache_DEHSTR])
19794 +static void au_cache_fin(void)
19799 + * Make sure all delayed rcu free inodes are flushed before we
19804 + /* excluding AuCache_HNOTIFY */
19805 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
19806 + for (i = 0; i < AuCache_HNOTIFY; i++)
19807 + if (au_cachep[i]) {
19808 + kmem_cache_destroy(au_cachep[i]);
19809 + au_cachep[i] = NULL;
19813 +/* ---------------------------------------------------------------------- */
19815 +int au_dir_roflags;
19817 +#ifdef CONFIG_AUFS_SBILIST
19819 + * iterate_supers_type() doesn't protect us from
19820 + * remounting (branch management)
19822 +struct au_splhead au_sbilist;
19825 +struct lock_class_key au_lc_key[AuLcKey_Last];
19828 + * functions for module interface.
19830 +MODULE_LICENSE("GPL");
19831 +/* MODULE_LICENSE("GPL v2"); */
19832 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
19833 +MODULE_DESCRIPTION(AUFS_NAME
19834 + " -- Advanced multi layered unification filesystem");
19835 +MODULE_VERSION(AUFS_VERSION);
19836 +MODULE_ALIAS_FS(AUFS_NAME);
19838 +/* this module parameter has no meaning when SYSFS is disabled */
19839 +int sysaufs_brs = 1;
19840 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
19841 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
19843 +/* ---------------------------------------------------------------------- */
19845 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
19847 +int au_seq_path(struct seq_file *seq, struct path *path)
19849 + return seq_path(seq, path, au_esc_chars);
19852 +/* ---------------------------------------------------------------------- */
19854 +static int __init aufs_init(void)
19859 + p = au_esc_chars;
19860 + for (i = 1; i <= ' '; i++)
19866 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
19868 + au_sbilist_init();
19869 + sysaufs_brs_init();
19872 + err = sysaufs_init();
19873 + if (unlikely(err))
19875 + err = au_procfs_init();
19876 + if (unlikely(err))
19877 + goto out_sysaufs;
19878 + err = au_wkq_init();
19879 + if (unlikely(err))
19881 + err = au_loopback_init();
19882 + if (unlikely(err))
19884 + err = au_hnotify_init();
19885 + if (unlikely(err))
19886 + goto out_loopback;
19887 + err = au_sysrq_init();
19888 + if (unlikely(err))
19890 + err = au_cache_init();
19891 + if (unlikely(err))
19893 + err = register_filesystem(&aufs_fs_type);
19894 + if (unlikely(err))
19896 + /* since we define pr_fmt, call printk directly */
19897 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
19898 + goto out; /* success */
19905 + au_hnotify_fin();
19907 + au_loopback_fin();
19919 +static void __exit aufs_exit(void)
19921 + unregister_filesystem(&aufs_fs_type);
19924 + au_hnotify_fin();
19925 + au_loopback_fin();
19932 +module_init(aufs_init);
19933 +module_exit(aufs_exit);
19934 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
19935 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
19936 +++ linux/fs/aufs/module.h 2014-01-20 20:16:14.742796949 +0100
19939 + * Copyright (C) 2005-2014 Junjiro R. Okajima
19941 + * This program, aufs is free software; you can redistribute it and/or modify
19942 + * it under the terms of the GNU General Public License as published by
19943 + * the Free Software Foundation; either version 2 of the License, or
19944 + * (at your option) any later version.
19946 + * This program is distributed in the hope that it will be useful,
19947 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19948 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19949 + * GNU General Public License for more details.
19951 + * You should have received a copy of the GNU General Public License
19952 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19956 + * module initialization and module-global
19959 +#ifndef __AUFS_MODULE_H__
19960 +#define __AUFS_MODULE_H__
19964 +#include <linux/slab.h>
19969 +/* module parameters */
19970 +extern int sysaufs_brs;
19972 +/* ---------------------------------------------------------------------- */
19974 +extern int au_dir_roflags;
19977 + AuLcNonDir_FIINFO,
19978 + AuLcNonDir_DIINFO,
19979 + AuLcNonDir_IIINFO,
19985 + AuLcSymlink_DIINFO,
19986 + AuLcSymlink_IIINFO,
19990 +extern struct lock_class_key au_lc_key[AuLcKey_Last];
19992 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp);
19993 +int au_seq_path(struct seq_file *seq, struct path *path);
19995 +#ifdef CONFIG_PROC_FS
19997 +int __init au_procfs_init(void);
19998 +void au_procfs_fin(void);
20000 +AuStubInt0(au_procfs_init, void);
20001 +AuStubVoid(au_procfs_fin, void);
20004 +/* ---------------------------------------------------------------------- */
20013 + AuCache_HNOTIFY, /* must be last */
20017 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
20018 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
20019 +#define AuCacheCtor(type, ctor) \
20020 + kmem_cache_create(#type, sizeof(struct type), \
20021 + __alignof__(struct type), AuCacheFlags, ctor)
20023 +extern struct kmem_cache *au_cachep[];
20025 +#define AuCacheFuncs(name, index) \
20026 +static inline struct au_##name *au_cache_alloc_##name(void) \
20027 +{ return kmem_cache_alloc(au_cachep[AuCache_##index], GFP_NOFS); } \
20028 +static inline void au_cache_free_##name(struct au_##name *p) \
20029 +{ kmem_cache_free(au_cachep[AuCache_##index], p); }
20031 +AuCacheFuncs(dinfo, DINFO);
20032 +AuCacheFuncs(icntnr, ICNTNR);
20033 +AuCacheFuncs(finfo, FINFO);
20034 +AuCacheFuncs(vdir, VDIR);
20035 +AuCacheFuncs(vdir_dehstr, DEHSTR);
20036 +#ifdef CONFIG_AUFS_HNOTIFY
20037 +AuCacheFuncs(hnotify, HNOTIFY);
20040 +#endif /* __KERNEL__ */
20041 +#endif /* __AUFS_MODULE_H__ */
20042 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
20043 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
20044 +++ linux/fs/aufs/mvdown.c 2014-01-20 20:16:14.742796949 +0100
20047 + * Copyright (C) 2011-2014 Junjiro R. Okajima
20049 + * This program, aufs is free software; you can redistribute it and/or modify
20050 + * it under the terms of the GNU General Public License as published by
20051 + * the Free Software Foundation; either version 2 of the License, or
20052 + * (at your option) any later version.
20054 + * This program is distributed in the hope that it will be useful,
20055 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20056 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20057 + * GNU General Public License for more details.
20059 + * You should have received a copy of the GNU General Public License
20060 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20064 + * move-down, opposite of copy-up
20069 +struct au_mvd_args {
20071 + struct super_block *h_sb;
20072 + struct dentry *h_parent;
20073 + struct au_hinode *hdir;
20074 + struct inode *h_dir, *h_inode;
20075 + } info[AUFS_MVDOWN_NARRAY];
20077 + struct aufs_mvdown mvdown;
20078 + struct dentry *dentry, *parent;
20079 + struct inode *inode, *dir;
20080 + struct super_block *sb;
20081 + aufs_bindex_t bopq, bwh, bfound;
20082 + unsigned char rename_lock;
20083 + struct au_pin pin;
20086 +#define mvd_errno mvdown.au_errno
20087 +#define mvd_bsrc mvdown.a[AUFS_MVDOWN_UPPER].bindex
20088 +#define mvd_src_brid mvdown.a[AUFS_MVDOWN_UPPER].brid
20089 +#define mvd_bdst mvdown.a[AUFS_MVDOWN_LOWER].bindex
20090 +#define mvd_dst_brid mvdown.a[AUFS_MVDOWN_LOWER].brid
20092 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
20093 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
20094 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
20095 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
20096 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
20098 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
20099 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
20100 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
20101 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
20102 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
20104 +#define AU_MVD_PR(flag, ...) do { \
20106 + pr_err(__VA_ARGS__); \
20109 +/* make the parent dir on bdst */
20110 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
20115 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
20116 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
20117 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
20118 + a->mvd_h_dst_parent = NULL;
20119 + if (au_dbend(a->parent) >= a->mvd_bdst)
20120 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
20121 + if (!a->mvd_h_dst_parent) {
20122 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
20123 + if (unlikely(err)) {
20124 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
20127 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
20135 +/* lock them all */
20136 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
20139 + struct dentry *h_trap;
20141 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
20142 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
20143 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
20144 + a->rename_lock = 0;
20145 + err = au_pin(&a->pin, a->dentry, a->mvd_bdst,
20146 + au_opt_udba(a->sb),
20147 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
20149 + a->mvd_h_src_dir = a->mvd_h_src_parent->d_inode;
20150 + mutex_lock_nested(&a->mvd_h_src_dir->i_mutex,
20151 + AuLsc_I_PARENT3);
20153 + AU_MVD_PR(dmsg, "pin failed\n");
20158 + a->rename_lock = 1;
20159 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
20160 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
20162 + err = (h_trap != a->mvd_h_src_parent);
20164 + err = (h_trap != a->mvd_h_dst_parent);
20166 + BUG_ON(err); /* it should never happen */
20173 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
20175 + if (!a->rename_lock) {
20176 + mutex_unlock(&a->mvd_h_src_dir->i_mutex);
20177 + au_unpin(&a->pin);
20179 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
20180 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
20183 +/* copy-down the file */
20184 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
20187 + struct au_cp_generic cpg = {
20188 + .dentry = a->dentry,
20189 + .bdst = a->mvd_bdst,
20190 + .bsrc = a->mvd_bsrc,
20193 + .flags = AuCpup_DTIME | AuCpup_HOPEN
20196 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
20197 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
20198 + au_fset_cpup(cpg.flags, OVERWRITE);
20199 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
20200 + au_fset_cpup(cpg.flags, RWDST);
20201 + err = au_sio_cpdown_simple(&cpg);
20202 + if (unlikely(err))
20203 + AU_MVD_PR(dmsg, "cpdown failed\n");
20210 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
20213 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
20216 + struct path h_path;
20217 + struct au_branch *br;
20218 + struct inode *delegated;
20220 + br = au_sbr(a->sb, a->mvd_bdst);
20221 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
20222 + err = PTR_ERR(h_path.dentry);
20223 + if (IS_ERR(h_path.dentry)) {
20224 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
20229 + if (h_path.dentry->d_inode) {
20230 + h_path.mnt = au_br_mnt(br);
20231 + delegated = NULL;
20232 + err = vfsub_unlink(a->mvd_h_dst_parent->d_inode, &h_path,
20233 + &delegated, /*force*/0);
20234 + if (unlikely(err == -EWOULDBLOCK)) {
20235 + pr_warn("cannot retry for NFSv4 delegation"
20236 + " for an internal unlink\n");
20239 + if (unlikely(err))
20240 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
20242 + dput(h_path.dentry);
20250 + * unlink the topmost h_dentry
20251 + * Note: the target file MAY be modified by UDBA between this mutex_unlock() and
20252 + * mutex_lock() in vfs_unlink(). in this case, such changes may be lost.
20254 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
20257 + struct path h_path;
20258 + struct inode *delegated;
20260 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
20261 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
20262 + delegated = NULL;
20263 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
20264 + if (unlikely(err == -EWOULDBLOCK)) {
20265 + pr_warn("cannot retry for NFSv4 delegation"
20266 + " for an internal unlink\n");
20269 + if (unlikely(err))
20270 + AU_MVD_PR(dmsg, "unlink failed\n");
20277 + * copy-down the file and unlink the bsrc file.
20278 + * - unlink the bdst whout if exist
20279 + * - copy-down the file (with whtmp name and rename)
20280 + * - unlink the bsrc file
20282 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
20286 + err = au_do_mkdir(dmsg, a);
20288 + err = au_do_lock(dmsg, a);
20289 + if (unlikely(err))
20293 + * do not revert the activities we made on bdst since they should be
20294 + * harmless in aufs.
20297 + err = au_do_cpdown(dmsg, a);
20299 + err = au_do_unlink_wh(dmsg, a);
20300 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
20301 + err = au_do_unlink(dmsg, a);
20302 + if (unlikely(err))
20305 + /* maintain internal array */
20306 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
20307 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
20308 + au_set_dbstart(a->dentry, a->mvd_bdst);
20309 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
20310 + au_set_ibstart(a->inode, a->mvd_bdst);
20312 + if (au_dbend(a->dentry) < a->mvd_bdst)
20313 + au_set_dbend(a->dentry, a->mvd_bdst);
20314 + if (au_ibend(a->inode) < a->mvd_bdst)
20315 + au_set_ibend(a->inode, a->mvd_bdst);
20318 + au_do_unlock(dmsg, a);
20324 +/* ---------------------------------------------------------------------- */
20326 +static int find_lower_writable(struct au_mvd_args *a)
20328 + struct super_block *sb;
20329 + aufs_bindex_t bindex, bend;
20330 + struct au_branch *br;
20333 + bindex = a->mvd_bsrc;
20334 + bend = au_sbend(sb);
20335 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER)) {
20336 + for (bindex++; bindex <= bend; bindex++) {
20337 + br = au_sbr(sb, bindex);
20338 + if (!au_br_rdonly(br))
20342 + for (bindex++; bindex <= bend; bindex++) {
20343 + br = au_sbr(sb, bindex);
20344 + if (!(au_br_sb(br)->s_flags & MS_RDONLY)) {
20345 + if (au_br_rdonly(br))
20347 + |= AUFS_MVDOWN_ROLOWER_R;
20356 +/* make sure the file is idle */
20357 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
20359 + int err, plinked;
20362 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
20363 + if (au_dbstart(a->dentry) == a->mvd_bsrc
20364 + && d_count(a->dentry) == 1
20365 + && atomic_read(&a->inode->i_count) == 1
20366 + /* && a->mvd_h_src_inode->i_nlink == 1 */
20367 + && (!plinked || !au_plink_test(a->inode))
20368 + && a->inode->i_nlink == 1)
20373 + "b%d, d{b%d, c%u?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
20374 + a->mvd_bsrc, au_dbstart(a->dentry), d_count(a->dentry),
20375 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
20376 + a->mvd_h_src_inode->i_nlink,
20377 + plinked, plinked ? au_plink_test(a->inode) : 0);
20384 +/* make sure the parent dir is fine */
20385 +static int au_mvd_args_parent(const unsigned char dmsg,
20386 + struct au_mvd_args *a)
20389 + aufs_bindex_t bindex;
20392 + if (unlikely(au_alive_dir(a->parent))) {
20394 + AU_MVD_PR(dmsg, "parent dir is dead\n");
20398 + a->bopq = au_dbdiropq(a->parent);
20399 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
20400 + AuDbg("b%d\n", bindex);
20401 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
20402 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
20404 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
20405 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
20406 + a->bopq, a->mvd_bdst);
20414 +static int au_mvd_args_intermediate(const unsigned char dmsg,
20415 + struct au_mvd_args *a)
20418 + struct au_dinfo *dinfo, *tmp;
20420 + /* lookup the next lower positive entry */
20422 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
20423 + if (unlikely(!tmp))
20428 + dinfo = au_di(a->dentry);
20429 + au_di_cp(tmp, dinfo);
20430 + au_di_swap(tmp, dinfo);
20432 + /* returns the number of positive dentries */
20433 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1, /*type*/0);
20435 + a->bwh = au_dbwh(a->dentry);
20436 + else if (err > 0)
20437 + a->bfound = au_dbstart(a->dentry);
20439 + au_di_swap(tmp, dinfo);
20440 + au_rw_write_unlock(&tmp->di_rwsem);
20442 + if (unlikely(err < 0))
20443 + AU_MVD_PR(dmsg, "failed look-up lower\n");
20446 + * here, we have these cases.
20448 + * no positive dentry under bsrc. there are more sub-cases.
20450 + * there no whiteout, we can safely move-down.
20453 + * bsrc < bwh && bwh < bdst
20454 + * there is a whiteout on RO branch. cannot proceed.
20456 + * there is a whiteout on the RW target branch. it should
20459 + * there is a whiteout somewhere unrelated branch.
20460 + * -1 < bfound && bfound <= bsrc
20463 + * found, but it is on RO branch between bsrc and bdst. cannot
20466 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
20469 + * found, after we create the file on bdst, it will be hidden.
20472 + AuDebugOn(a->bfound == -1
20474 + && a->bwh <= a->mvd_bsrc);
20475 + AuDebugOn(-1 < a->bfound
20476 + && a->bfound <= a->mvd_bsrc);
20479 + if (a->bfound == -1
20480 + && a->mvd_bsrc < a->bwh
20482 + && a->bwh < a->mvd_bdst) {
20483 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
20484 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
20485 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
20487 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
20488 + a->mvd_errno = EAU_MVDOWN_UPPER;
20489 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
20490 + a->mvd_bdst, a->bfound);
20494 + err = 0; /* success */
20501 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
20506 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
20507 + && a->bfound == a->mvd_bdst)
20513 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
20516 + struct au_branch *br;
20519 + if (unlikely(S_ISDIR(a->inode->i_mode)))
20523 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
20524 + a->mvd_bsrc = au_ibstart(a->inode);
20526 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
20527 + if (unlikely(a->mvd_bsrc < 0
20528 + || (a->mvd_bsrc < au_dbstart(a->dentry)
20529 + || au_dbend(a->dentry) < a->mvd_bsrc
20530 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
20531 + || (a->mvd_bsrc < au_ibstart(a->inode)
20532 + || au_ibend(a->inode) < a->mvd_bsrc
20533 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
20534 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
20535 + AU_MVD_PR(dmsg, "no upper\n");
20539 + if (unlikely(a->mvd_bsrc == au_sbend(a->sb))) {
20540 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
20541 + AU_MVD_PR(dmsg, "on the bottom\n");
20544 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
20545 + br = au_sbr(a->sb, a->mvd_bsrc);
20546 + err = au_br_rdonly(br);
20547 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
20548 + if (unlikely(err))
20550 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
20551 + || IS_APPEND(a->mvd_h_src_inode))) {
20553 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
20559 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
20560 + a->mvd_bdst = find_lower_writable(a);
20561 + if (unlikely(a->mvd_bdst < 0)) {
20562 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
20563 + AU_MVD_PR(dmsg, "no writable lower branch\n");
20567 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
20568 + if (unlikely(a->mvd_bdst < 0
20569 + || au_sbend(a->sb) < a->mvd_bdst)) {
20570 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
20571 + AU_MVD_PR(dmsg, "no lower brid\n");
20576 + err = au_mvd_args_busy(dmsg, a);
20578 + err = au_mvd_args_parent(dmsg, a);
20580 + err = au_mvd_args_intermediate(dmsg, a);
20582 + err = au_mvd_args_exist(dmsg, a);
20584 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
20591 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
20594 + unsigned char dmsg;
20595 + struct au_mvd_args *args;
20598 + if (unlikely(!capable(CAP_SYS_ADMIN)))
20601 + WARN_ONCE(1, "move-down is still testing...\n");
20604 + args = kmalloc(sizeof(*args), GFP_NOFS);
20605 + if (unlikely(!args))
20608 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
20610 + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
20611 + if (unlikely(err)) {
20616 + AuDbg("flags 0x%x\n", args->mvdown.flags);
20617 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
20618 + args->mvdown.au_errno = 0;
20619 + args->dentry = dentry;
20620 + args->inode = dentry->d_inode;
20621 + args->sb = dentry->d_sb;
20624 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
20625 + args->parent = dget_parent(dentry);
20626 + args->dir = args->parent->d_inode;
20627 + mutex_lock_nested(&args->dir->i_mutex, I_MUTEX_PARENT);
20628 + dput(args->parent);
20629 + if (unlikely(args->parent != dentry->d_parent)) {
20630 + AU_MVD_PR(dmsg, "parent dir is moved\n");
20634 + mutex_lock_nested(&args->inode->i_mutex, I_MUTEX_CHILD);
20635 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH);
20636 + if (unlikely(err))
20639 + di_write_lock_parent(args->parent);
20640 + err = au_mvd_args(dmsg, args);
20641 + if (unlikely(err))
20644 + AuDbgDentry(dentry);
20645 + AuDbgInode(args->inode);
20646 + err = au_do_mvdown(dmsg, args);
20647 + if (unlikely(err))
20649 + AuDbgDentry(dentry);
20650 + AuDbgInode(args->inode);
20652 + au_cpup_attr_timesizes(args->dir);
20653 + au_cpup_attr_timesizes(args->inode);
20654 + au_cpup_igen(args->inode, au_h_iptr(args->inode, args->mvd_bdst));
20655 + /* au_digen_dec(dentry); */
20658 + di_write_unlock(args->parent);
20659 + aufs_read_unlock(dentry, AuLock_DW);
20661 + mutex_unlock(&args->inode->i_mutex);
20663 + mutex_unlock(&args->dir->i_mutex);
20665 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
20673 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
20674 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
20675 +++ linux/fs/aufs/opts.c 2014-01-27 23:16:52.715087263 +0100
20678 + * Copyright (C) 2005-2014 Junjiro R. Okajima
20680 + * This program, aufs is free software; you can redistribute it and/or modify
20681 + * it under the terms of the GNU General Public License as published by
20682 + * the Free Software Foundation; either version 2 of the License, or
20683 + * (at your option) any later version.
20685 + * This program is distributed in the hope that it will be useful,
20686 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20687 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20688 + * GNU General Public License for more details.
20690 + * You should have received a copy of the GNU General Public License
20691 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20695 + * mount options/flags
20698 +#include <linux/namei.h>
20699 +#include <linux/types.h> /* a distribution requires */
20700 +#include <linux/parser.h>
20703 +/* ---------------------------------------------------------------------- */
20707 + Opt_add, Opt_del, Opt_mod, Opt_reorder, Opt_append, Opt_prepend,
20708 + Opt_idel, Opt_imod, Opt_ireorder,
20709 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash, Opt_rendir,
20710 + Opt_rdblk_def, Opt_rdhash_def,
20711 + Opt_xino, Opt_zxino, Opt_noxino,
20712 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
20713 + Opt_trunc_xino_path, Opt_itrunc_xino,
20714 + Opt_trunc_xib, Opt_notrunc_xib,
20715 + Opt_shwh, Opt_noshwh,
20716 + Opt_plink, Opt_noplink, Opt_list_plink,
20718 + Opt_dio, Opt_nodio,
20719 + /* Opt_lock, Opt_unlock, */
20720 + Opt_cmd, Opt_cmd_args,
20721 + Opt_diropq_a, Opt_diropq_w,
20722 + Opt_warn_perm, Opt_nowarn_perm,
20723 + Opt_wbr_copyup, Opt_wbr_create,
20724 + Opt_refrof, Opt_norefrof,
20725 + Opt_verbose, Opt_noverbose,
20726 + Opt_sum, Opt_nosum, Opt_wsum,
20727 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
20730 +static match_table_t options = {
20731 + {Opt_br, "br=%s"},
20732 + {Opt_br, "br:%s"},
20734 + {Opt_add, "add=%d:%s"},
20735 + {Opt_add, "add:%d:%s"},
20736 + {Opt_add, "ins=%d:%s"},
20737 + {Opt_add, "ins:%d:%s"},
20738 + {Opt_append, "append=%s"},
20739 + {Opt_append, "append:%s"},
20740 + {Opt_prepend, "prepend=%s"},
20741 + {Opt_prepend, "prepend:%s"},
20743 + {Opt_del, "del=%s"},
20744 + {Opt_del, "del:%s"},
20745 + /* {Opt_idel, "idel:%d"}, */
20746 + {Opt_mod, "mod=%s"},
20747 + {Opt_mod, "mod:%s"},
20748 + /* {Opt_imod, "imod:%d:%s"}, */
20750 + {Opt_dirwh, "dirwh=%d"},
20752 + {Opt_xino, "xino=%s"},
20753 + {Opt_noxino, "noxino"},
20754 + {Opt_trunc_xino, "trunc_xino"},
20755 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
20756 + {Opt_notrunc_xino, "notrunc_xino"},
20757 + {Opt_trunc_xino_path, "trunc_xino=%s"},
20758 + {Opt_itrunc_xino, "itrunc_xino=%d"},
20759 + /* {Opt_zxino, "zxino=%s"}, */
20760 + {Opt_trunc_xib, "trunc_xib"},
20761 + {Opt_notrunc_xib, "notrunc_xib"},
20763 +#ifdef CONFIG_PROC_FS
20764 + {Opt_plink, "plink"},
20766 + {Opt_ignore_silent, "plink"},
20769 + {Opt_noplink, "noplink"},
20771 +#ifdef CONFIG_AUFS_DEBUG
20772 + {Opt_list_plink, "list_plink"},
20775 + {Opt_udba, "udba=%s"},
20777 + {Opt_dio, "dio"},
20778 + {Opt_nodio, "nodio"},
20780 + {Opt_diropq_a, "diropq=always"},
20781 + {Opt_diropq_a, "diropq=a"},
20782 + {Opt_diropq_w, "diropq=whiteouted"},
20783 + {Opt_diropq_w, "diropq=w"},
20785 + {Opt_warn_perm, "warn_perm"},
20786 + {Opt_nowarn_perm, "nowarn_perm"},
20788 + /* keep them temporary */
20789 + {Opt_ignore_silent, "coo=%s"},
20790 + {Opt_ignore_silent, "nodlgt"},
20791 + {Opt_ignore_silent, "nodirperm1"},
20792 + {Opt_ignore_silent, "clean_plink"},
20794 +#ifdef CONFIG_AUFS_SHWH
20795 + {Opt_shwh, "shwh"},
20797 + {Opt_noshwh, "noshwh"},
20799 + {Opt_rendir, "rendir=%d"},
20801 + {Opt_refrof, "refrof"},
20802 + {Opt_norefrof, "norefrof"},
20804 + {Opt_verbose, "verbose"},
20805 + {Opt_verbose, "v"},
20806 + {Opt_noverbose, "noverbose"},
20807 + {Opt_noverbose, "quiet"},
20808 + {Opt_noverbose, "q"},
20809 + {Opt_noverbose, "silent"},
20811 + {Opt_sum, "sum"},
20812 + {Opt_nosum, "nosum"},
20813 + {Opt_wsum, "wsum"},
20815 + {Opt_rdcache, "rdcache=%d"},
20816 + {Opt_rdblk, "rdblk=%d"},
20817 + {Opt_rdblk_def, "rdblk=def"},
20818 + {Opt_rdhash, "rdhash=%d"},
20819 + {Opt_rdhash_def, "rdhash=def"},
20821 + {Opt_wbr_create, "create=%s"},
20822 + {Opt_wbr_create, "create_policy=%s"},
20823 + {Opt_wbr_copyup, "cpup=%s"},
20824 + {Opt_wbr_copyup, "copyup=%s"},
20825 + {Opt_wbr_copyup, "copyup_policy=%s"},
20827 + /* internal use for the scripts */
20828 + {Opt_ignore_silent, "si=%s"},
20830 + {Opt_br, "dirs=%s"},
20831 + {Opt_ignore, "debug=%d"},
20832 + {Opt_ignore, "delete=whiteout"},
20833 + {Opt_ignore, "delete=all"},
20834 + {Opt_ignore, "imap=%s"},
20836 + /* temporary workaround, due to old mount(8)? */
20837 + {Opt_ignore_silent, "relatime"},
20842 +/* ---------------------------------------------------------------------- */
20844 +static const char *au_parser_pattern(int val, struct match_token *token)
20846 + while (token->pattern) {
20847 + if (token->token == val)
20848 + return token->pattern;
20855 +/* ---------------------------------------------------------------------- */
20857 +static match_table_t brperm = {
20858 + {AuBrPerm_RO, AUFS_BRPERM_RO},
20859 + {AuBrPerm_RR, AUFS_BRPERM_RR},
20860 + {AuBrPerm_RW, AUFS_BRPERM_RW},
20864 +static match_table_t brattr = {
20865 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
20866 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
20867 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
20871 +#define AuBrStr_LONGEST AUFS_BRPERM_RW \
20872 + "+" AUFS_BRATTR_UNPIN \
20873 + "+" AUFS_BRWATTR_NLWH
20875 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
20882 + p = strchr(str, '+');
20885 + v = match_token(str, table, args);
20891 + pr_warn("ignored branch attribute %s\n", str);
20901 +static int noinline_for_stack br_perm_val(char *perm)
20905 + substring_t args[MAX_OPT_ARGS];
20907 + p = strchr(perm, '+');
20910 + val = match_token(perm, brperm, args);
20914 + pr_warn("ignored branch permission %s\n", perm);
20915 + val = AuBrPerm_RO;
20923 + q = strchr(p, '+');
20926 + val |= br_attr_val(p, brattr, args);
20933 + switch (val & AuBrPerm_Mask) {
20934 + case AuBrPerm_RO:
20935 + case AuBrPerm_RR:
20936 + if (unlikely(val & AuBrWAttr_NoLinkWH)) {
20937 + pr_warn("ignored branch attribute %s\n",
20938 + AUFS_BRWATTR_NLWH);
20939 + val &= ~AuBrWAttr_NoLinkWH;
20942 + case AuBrPerm_RW:
20943 + if (unlikely(val & AuBrRAttr_WH)) {
20944 + pr_warn("ignored branch attribute %s\n",
20945 + AUFS_BRRATTR_WH);
20946 + val &= ~AuBrRAttr_WH;
20955 +/* Caller should free the return value */
20956 +char *au_optstr_br_perm(int brperm)
20958 + char *p, a[sizeof(AuBrStr_LONGEST)];
20961 +#define SetPerm(str) do { \
20962 + sz = sizeof(str); \
20963 + memcpy(a, str, sz); \
20964 + p = a + sz - 1; \
20967 +#define AppendAttr(flag, str) do { \
20968 + if (brperm & flag) { \
20969 + sz = sizeof(str); \
20971 + memcpy(p, str, sz); \
20976 + switch (brperm & AuBrPerm_Mask) {
20977 + case AuBrPerm_RO:
20978 + SetPerm(AUFS_BRPERM_RO);
20980 + case AuBrPerm_RR:
20981 + SetPerm(AUFS_BRPERM_RR);
20983 + case AuBrPerm_RW:
20984 + SetPerm(AUFS_BRPERM_RW);
20990 + AppendAttr(AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN);
20991 + AppendAttr(AuBrRAttr_WH, AUFS_BRRATTR_WH);
20992 + AppendAttr(AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH);
20994 + AuDebugOn(strlen(a) >= sizeof(a));
20995 + return kstrdup(a, GFP_NOFS);
21000 +/* ---------------------------------------------------------------------- */
21002 +static match_table_t udbalevel = {
21003 + {AuOpt_UDBA_REVAL, "reval"},
21004 + {AuOpt_UDBA_NONE, "none"},
21005 +#ifdef CONFIG_AUFS_HNOTIFY
21006 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
21007 +#ifdef CONFIG_AUFS_HFSNOTIFY
21008 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
21014 +static int noinline_for_stack udba_val(char *str)
21016 + substring_t args[MAX_OPT_ARGS];
21018 + return match_token(str, udbalevel, args);
21021 +const char *au_optstr_udba(int udba)
21023 + return au_parser_pattern(udba, (void *)udbalevel);
21026 +/* ---------------------------------------------------------------------- */
21028 +static match_table_t au_wbr_create_policy = {
21029 + {AuWbrCreate_TDP, "tdp"},
21030 + {AuWbrCreate_TDP, "top-down-parent"},
21031 + {AuWbrCreate_RR, "rr"},
21032 + {AuWbrCreate_RR, "round-robin"},
21033 + {AuWbrCreate_MFS, "mfs"},
21034 + {AuWbrCreate_MFS, "most-free-space"},
21035 + {AuWbrCreate_MFSV, "mfs:%d"},
21036 + {AuWbrCreate_MFSV, "most-free-space:%d"},
21038 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
21039 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
21040 + {AuWbrCreate_PMFS, "pmfs"},
21041 + {AuWbrCreate_PMFSV, "pmfs:%d"},
21042 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
21043 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
21049 + * cf. linux/lib/parser.c and cmdline.c
21050 + * gave up calling memparse() since it uses simple_strtoull() instead of
21053 +static int noinline_for_stack
21054 +au_match_ull(substring_t *s, unsigned long long *result)
21057 + unsigned int len;
21061 + len = s->to - s->from;
21062 + if (len + 1 <= sizeof(a)) {
21063 + memcpy(a, s->from, len);
21065 + err = kstrtoull(a, 0, result);
21070 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
21071 + struct au_opt_wbr_create *create)
21074 + unsigned long long ull;
21077 + if (!au_match_ull(arg, &ull))
21078 + create->mfsrr_watermark = ull;
21080 + pr_err("bad integer in %s\n", str);
21087 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
21088 + struct au_opt_wbr_create *create)
21093 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
21094 + create->mfs_second = n;
21096 + pr_err("bad integer in %s\n", str);
21103 +static int noinline_for_stack
21104 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
21107 + substring_t args[MAX_OPT_ARGS];
21109 + err = match_token(str, au_wbr_create_policy, args);
21110 + create->wbr_create = err;
21112 + case AuWbrCreate_MFSRRV:
21113 + case AuWbrCreate_PMFSRRV:
21114 + e = au_wbr_mfs_wmark(&args[0], str, create);
21116 + e = au_wbr_mfs_sec(&args[1], str, create);
21120 + case AuWbrCreate_MFSRR:
21121 + case AuWbrCreate_PMFSRR:
21122 + e = au_wbr_mfs_wmark(&args[0], str, create);
21123 + if (unlikely(e)) {
21128 + case AuWbrCreate_MFS:
21129 + case AuWbrCreate_PMFS:
21130 + create->mfs_second = AUFS_MFS_DEF_SEC;
21132 + case AuWbrCreate_MFSV:
21133 + case AuWbrCreate_PMFSV:
21134 + e = au_wbr_mfs_sec(&args[0], str, create);
21143 +const char *au_optstr_wbr_create(int wbr_create)
21145 + return au_parser_pattern(wbr_create, (void *)au_wbr_create_policy);
21148 +static match_table_t au_wbr_copyup_policy = {
21149 + {AuWbrCopyup_TDP, "tdp"},
21150 + {AuWbrCopyup_TDP, "top-down-parent"},
21151 + {AuWbrCopyup_BUP, "bup"},
21152 + {AuWbrCopyup_BUP, "bottom-up-parent"},
21153 + {AuWbrCopyup_BU, "bu"},
21154 + {AuWbrCopyup_BU, "bottom-up"},
21158 +static int noinline_for_stack au_wbr_copyup_val(char *str)
21160 + substring_t args[MAX_OPT_ARGS];
21162 + return match_token(str, au_wbr_copyup_policy, args);
21165 +const char *au_optstr_wbr_copyup(int wbr_copyup)
21167 + return au_parser_pattern(wbr_copyup, (void *)au_wbr_copyup_policy);
21170 +/* ---------------------------------------------------------------------- */
21172 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
21174 +static void dump_opts(struct au_opts *opts)
21176 +#ifdef CONFIG_AUFS_DEBUG
21177 + /* reduce stack space */
21179 + struct au_opt_add *add;
21180 + struct au_opt_del *del;
21181 + struct au_opt_mod *mod;
21182 + struct au_opt_xino *xino;
21183 + struct au_opt_xino_itrunc *xino_itrunc;
21184 + struct au_opt_wbr_create *create;
21186 + struct au_opt *opt;
21189 + while (opt->type != Opt_tail) {
21190 + switch (opt->type) {
21192 + u.add = &opt->add;
21193 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
21194 + u.add->bindex, u.add->pathname, u.add->perm,
21195 + u.add->path.dentry);
21199 + u.del = &opt->del;
21200 + AuDbg("del {%s, %p}\n",
21201 + u.del->pathname, u.del->h_path.dentry);
21205 + u.mod = &opt->mod;
21206 + AuDbg("mod {%s, 0x%x, %p}\n",
21207 + u.mod->path, u.mod->perm, u.mod->h_root);
21210 + u.add = &opt->add;
21211 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
21212 + u.add->bindex, u.add->pathname, u.add->perm,
21213 + u.add->path.dentry);
21215 + case Opt_prepend:
21216 + u.add = &opt->add;
21217 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
21218 + u.add->bindex, u.add->pathname, u.add->perm,
21219 + u.add->path.dentry);
21222 + AuDbg("dirwh %d\n", opt->dirwh);
21224 + case Opt_rdcache:
21225 + AuDbg("rdcache %d\n", opt->rdcache);
21228 + AuDbg("rdblk %u\n", opt->rdblk);
21230 + case Opt_rdblk_def:
21231 + AuDbg("rdblk_def\n");
21234 + AuDbg("rdhash %u\n", opt->rdhash);
21236 + case Opt_rdhash_def:
21237 + AuDbg("rdhash_def\n");
21240 + u.xino = &opt->xino;
21241 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
21243 + case Opt_trunc_xino:
21244 + AuLabel(trunc_xino);
21246 + case Opt_notrunc_xino:
21247 + AuLabel(notrunc_xino);
21249 + case Opt_trunc_xino_path:
21250 + case Opt_itrunc_xino:
21251 + u.xino_itrunc = &opt->xino_itrunc;
21252 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
21258 + case Opt_trunc_xib:
21259 + AuLabel(trunc_xib);
21261 + case Opt_notrunc_xib:
21262 + AuLabel(notrunc_xib);
21273 + case Opt_noplink:
21274 + AuLabel(noplink);
21276 + case Opt_list_plink:
21277 + AuLabel(list_plink);
21280 + AuDbg("udba %d, %s\n",
21281 + opt->udba, au_optstr_udba(opt->udba));
21289 + case Opt_diropq_a:
21290 + AuLabel(diropq_a);
21292 + case Opt_diropq_w:
21293 + AuLabel(diropq_w);
21295 + case Opt_warn_perm:
21296 + AuLabel(warn_perm);
21298 + case Opt_nowarn_perm:
21299 + AuLabel(nowarn_perm);
21304 + case Opt_norefrof:
21305 + AuLabel(norefrof);
21307 + case Opt_verbose:
21308 + AuLabel(verbose);
21310 + case Opt_noverbose:
21311 + AuLabel(noverbose);
21322 + case Opt_wbr_create:
21323 + u.create = &opt->wbr_create;
21324 + AuDbg("create %d, %s\n", u.create->wbr_create,
21325 + au_optstr_wbr_create(u.create->wbr_create));
21326 + switch (u.create->wbr_create) {
21327 + case AuWbrCreate_MFSV:
21328 + case AuWbrCreate_PMFSV:
21329 + AuDbg("%d sec\n", u.create->mfs_second);
21331 + case AuWbrCreate_MFSRR:
21332 + AuDbg("%llu watermark\n",
21333 + u.create->mfsrr_watermark);
21335 + case AuWbrCreate_MFSRRV:
21336 + case AuWbrCreate_PMFSRRV:
21337 + AuDbg("%llu watermark, %d sec\n",
21338 + u.create->mfsrr_watermark,
21339 + u.create->mfs_second);
21343 + case Opt_wbr_copyup:
21344 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
21345 + au_optstr_wbr_copyup(opt->wbr_copyup));
21355 +void au_opts_free(struct au_opts *opts)
21357 + struct au_opt *opt;
21360 + while (opt->type != Opt_tail) {
21361 + switch (opt->type) {
21364 + case Opt_prepend:
21365 + path_put(&opt->add.path);
21369 + path_put(&opt->del.h_path);
21373 + dput(opt->mod.h_root);
21376 + fput(opt->xino.file);
21383 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
21384 + aufs_bindex_t bindex)
21387 + struct au_opt_add *add = &opt->add;
21390 + add->bindex = bindex;
21391 + add->perm = AuBrPerm_RO;
21392 + add->pathname = opt_str;
21393 + p = strchr(opt_str, '=');
21397 + add->perm = br_perm_val(p);
21400 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
21403 + add->perm = AuBrPerm_RO;
21404 + if (au_test_fs_rr(add->path.dentry->d_sb))
21405 + add->perm = AuBrPerm_RR;
21406 + else if (!bindex && !(sb_flags & MS_RDONLY))
21407 + add->perm = AuBrPerm_RW;
21409 + opt->type = Opt_add;
21412 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
21419 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
21423 + del->pathname = args[0].from;
21424 + AuDbg("del path %s\n", del->pathname);
21426 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
21427 + if (unlikely(err))
21428 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
21433 +#if 0 /* reserved for future use */
21434 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
21435 + struct au_opt_del *del, substring_t args[])
21438 + struct dentry *root;
21441 + root = sb->s_root;
21442 + aufs_read_lock(root, AuLock_FLUSH);
21443 + if (bindex < 0 || au_sbend(sb) < bindex) {
21444 + pr_err("out of bounds, %d\n", bindex);
21449 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
21450 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
21453 + aufs_read_unlock(root, !AuLock_IR);
21458 +static int noinline_for_stack
21459 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
21462 + struct path path;
21466 + mod->path = args[0].from;
21467 + p = strchr(mod->path, '=');
21468 + if (unlikely(!p)) {
21469 + pr_err("no permssion %s\n", args[0].from);
21474 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
21475 + if (unlikely(err)) {
21476 + pr_err("lookup failed %s (%d)\n", mod->path, err);
21480 + mod->perm = br_perm_val(p);
21481 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
21482 + mod->h_root = dget(path.dentry);
21489 +#if 0 /* reserved for future use */
21490 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
21491 + struct au_opt_mod *mod, substring_t args[])
21494 + struct dentry *root;
21497 + root = sb->s_root;
21498 + aufs_read_lock(root, AuLock_FLUSH);
21499 + if (bindex < 0 || au_sbend(sb) < bindex) {
21500 + pr_err("out of bounds, %d\n", bindex);
21505 + mod->perm = br_perm_val(args[1].from);
21506 + AuDbg("mod path %s, perm 0x%x, %s\n",
21507 + mod->path, mod->perm, args[1].from);
21508 + mod->h_root = dget(au_h_dptr(root, bindex));
21511 + aufs_read_unlock(root, !AuLock_IR);
21516 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
21517 + substring_t args[])
21520 + struct file *file;
21522 + file = au_xino_create(sb, args[0].from, /*silent*/0);
21523 + err = PTR_ERR(file);
21524 + if (IS_ERR(file))
21528 + if (unlikely(file->f_dentry->d_sb == sb)) {
21530 + pr_err("%s must be outside\n", args[0].from);
21535 + xino->file = file;
21536 + xino->path = args[0].from;
21542 +static int noinline_for_stack
21543 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
21544 + struct au_opt_xino_itrunc *xino_itrunc,
21545 + substring_t args[])
21548 + aufs_bindex_t bend, bindex;
21549 + struct path path;
21550 + struct dentry *root;
21552 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
21553 + if (unlikely(err)) {
21554 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
21558 + xino_itrunc->bindex = -1;
21559 + root = sb->s_root;
21560 + aufs_read_lock(root, AuLock_FLUSH);
21561 + bend = au_sbend(sb);
21562 + for (bindex = 0; bindex <= bend; bindex++) {
21563 + if (au_h_dptr(root, bindex) == path.dentry) {
21564 + xino_itrunc->bindex = bindex;
21568 + aufs_read_unlock(root, !AuLock_IR);
21571 + if (unlikely(xino_itrunc->bindex < 0)) {
21572 + pr_err("no such branch %s\n", args[0].from);
21580 +/* called without aufs lock */
21581 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
21583 + int err, n, token;
21584 + aufs_bindex_t bindex;
21585 + unsigned char skipped;
21586 + struct dentry *root;
21587 + struct au_opt *opt, *opt_tail;
21589 + /* reduce the stack space */
21591 + struct au_opt_xino_itrunc *xino_itrunc;
21592 + struct au_opt_wbr_create *create;
21595 + substring_t args[MAX_OPT_ARGS];
21599 + a = kmalloc(sizeof(*a), GFP_NOFS);
21600 + if (unlikely(!a))
21603 + root = sb->s_root;
21607 + opt_tail = opt + opts->max_opt - 1;
21608 + opt->type = Opt_tail;
21609 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
21612 + token = match_token(opt_str, options, a->args);
21616 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
21618 + err = opt_add(opt, opt_str, opts->sb_flags,
21620 + if (unlikely(!err && ++opt > opt_tail)) {
21624 + opt->type = Opt_tail;
21629 + if (unlikely(match_int(&a->args[0], &n))) {
21630 + pr_err("bad integer in %s\n", opt_str);
21634 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
21637 + opt->type = token;
21640 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
21641 + /*dummy bindex*/1);
21643 + opt->type = token;
21645 + case Opt_prepend:
21646 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
21649 + opt->type = token;
21652 + err = au_opts_parse_del(&opt->del, a->args);
21654 + opt->type = token;
21656 +#if 0 /* reserved for future use */
21658 + del->pathname = "(indexed)";
21659 + if (unlikely(match_int(&args[0], &n))) {
21660 + pr_err("bad integer in %s\n", opt_str);
21663 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
21665 + opt->type = token;
21669 + err = au_opts_parse_mod(&opt->mod, a->args);
21671 + opt->type = token;
21673 +#ifdef IMOD /* reserved for future use */
21675 + u.mod->path = "(indexed)";
21676 + if (unlikely(match_int(&a->args[0], &n))) {
21677 + pr_err("bad integer in %s\n", opt_str);
21680 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
21682 + opt->type = token;
21686 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
21688 + opt->type = token;
21691 + case Opt_trunc_xino_path:
21692 + err = au_opts_parse_xino_itrunc_path
21693 + (sb, &opt->xino_itrunc, a->args);
21695 + opt->type = token;
21698 + case Opt_itrunc_xino:
21699 + u.xino_itrunc = &opt->xino_itrunc;
21700 + if (unlikely(match_int(&a->args[0], &n))) {
21701 + pr_err("bad integer in %s\n", opt_str);
21704 + u.xino_itrunc->bindex = n;
21705 + aufs_read_lock(root, AuLock_FLUSH);
21706 + if (n < 0 || au_sbend(sb) < n) {
21707 + pr_err("out of bounds, %d\n", n);
21708 + aufs_read_unlock(root, !AuLock_IR);
21711 + aufs_read_unlock(root, !AuLock_IR);
21713 + opt->type = token;
21717 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
21720 + opt->type = token;
21723 + case Opt_rdcache:
21724 + if (unlikely(match_int(&a->args[0], &n))) {
21725 + pr_err("bad integer in %s\n", opt_str);
21728 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
21729 + pr_err("rdcache must be smaller than %d\n",
21730 + AUFS_RDCACHE_MAX);
21733 + opt->rdcache = n;
21735 + opt->type = token;
21738 + if (unlikely(match_int(&a->args[0], &n)
21740 + || n > KMALLOC_MAX_SIZE)) {
21741 + pr_err("bad integer in %s\n", opt_str);
21744 + if (unlikely(n && n < NAME_MAX)) {
21745 + pr_err("rdblk must be larger than %d\n",
21751 + opt->type = token;
21754 + if (unlikely(match_int(&a->args[0], &n)
21756 + || n * sizeof(struct hlist_head)
21757 + > KMALLOC_MAX_SIZE)) {
21758 + pr_err("bad integer in %s\n", opt_str);
21763 + opt->type = token;
21766 + case Opt_trunc_xino:
21767 + case Opt_notrunc_xino:
21769 + case Opt_trunc_xib:
21770 + case Opt_notrunc_xib:
21774 + case Opt_noplink:
21775 + case Opt_list_plink:
21778 + case Opt_diropq_a:
21779 + case Opt_diropq_w:
21780 + case Opt_warn_perm:
21781 + case Opt_nowarn_perm:
21783 + case Opt_norefrof:
21784 + case Opt_verbose:
21785 + case Opt_noverbose:
21789 + case Opt_rdblk_def:
21790 + case Opt_rdhash_def:
21792 + opt->type = token;
21796 + opt->udba = udba_val(a->args[0].from);
21797 + if (opt->udba >= 0) {
21799 + opt->type = token;
21801 + pr_err("wrong value, %s\n", opt_str);
21804 + case Opt_wbr_create:
21805 + u.create = &opt->wbr_create;
21806 + u.create->wbr_create
21807 + = au_wbr_create_val(a->args[0].from, u.create);
21808 + if (u.create->wbr_create >= 0) {
21810 + opt->type = token;
21812 + pr_err("wrong value, %s\n", opt_str);
21814 + case Opt_wbr_copyup:
21815 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
21816 + if (opt->wbr_copyup >= 0) {
21818 + opt->type = token;
21820 + pr_err("wrong value, %s\n", opt_str);
21824 + pr_warn("ignored %s\n", opt_str);
21826 + case Opt_ignore_silent:
21831 + pr_err("unknown option %s\n", opt_str);
21835 + if (!err && !skipped) {
21836 + if (unlikely(++opt > opt_tail)) {
21839 + opt->type = Opt_tail;
21842 + opt->type = Opt_tail;
21848 + if (unlikely(err))
21849 + au_opts_free(opts);
21855 +static int au_opt_wbr_create(struct super_block *sb,
21856 + struct au_opt_wbr_create *create)
21859 + struct au_sbinfo *sbinfo;
21861 + SiMustWriteLock(sb);
21863 + err = 1; /* handled */
21864 + sbinfo = au_sbi(sb);
21865 + if (sbinfo->si_wbr_create_ops->fin) {
21866 + err = sbinfo->si_wbr_create_ops->fin(sb);
21871 + sbinfo->si_wbr_create = create->wbr_create;
21872 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
21873 + switch (create->wbr_create) {
21874 + case AuWbrCreate_MFSRRV:
21875 + case AuWbrCreate_MFSRR:
21876 + case AuWbrCreate_PMFSRR:
21877 + case AuWbrCreate_PMFSRRV:
21878 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
21880 + case AuWbrCreate_MFS:
21881 + case AuWbrCreate_MFSV:
21882 + case AuWbrCreate_PMFS:
21883 + case AuWbrCreate_PMFSV:
21884 + sbinfo->si_wbr_mfs.mfs_expire
21885 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
21889 + if (sbinfo->si_wbr_create_ops->init)
21890 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
21897 + * plus: processed without an error
21898 + * zero: unprocessed
21900 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
21901 + struct au_opts *opts)
21904 + struct au_sbinfo *sbinfo;
21906 + SiMustWriteLock(sb);
21908 + err = 1; /* handled */
21909 + sbinfo = au_sbi(sb);
21910 + switch (opt->type) {
21912 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
21913 + sbinfo->si_mntflags |= opt->udba;
21914 + opts->given_udba |= opt->udba;
21918 + au_opt_set(sbinfo->si_mntflags, PLINK);
21920 + case Opt_noplink:
21921 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
21922 + au_plink_put(sb, /*verbose*/1);
21923 + au_opt_clr(sbinfo->si_mntflags, PLINK);
21925 + case Opt_list_plink:
21926 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
21927 + au_plink_list(sb);
21931 + au_opt_set(sbinfo->si_mntflags, DIO);
21932 + au_fset_opts(opts->flags, REFRESH_DYAOP);
21935 + au_opt_clr(sbinfo->si_mntflags, DIO);
21936 + au_fset_opts(opts->flags, REFRESH_DYAOP);
21939 + case Opt_diropq_a:
21940 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
21942 + case Opt_diropq_w:
21943 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
21946 + case Opt_warn_perm:
21947 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
21949 + case Opt_nowarn_perm:
21950 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
21954 + au_opt_set(sbinfo->si_mntflags, REFROF);
21956 + case Opt_norefrof:
21957 + au_opt_clr(sbinfo->si_mntflags, REFROF);
21960 + case Opt_verbose:
21961 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
21963 + case Opt_noverbose:
21964 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
21968 + au_opt_set(sbinfo->si_mntflags, SUM);
21971 + au_opt_clr(sbinfo->si_mntflags, SUM);
21972 + au_opt_set(sbinfo->si_mntflags, SUM_W);
21974 + au_opt_clr(sbinfo->si_mntflags, SUM);
21975 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
21978 + case Opt_wbr_create:
21979 + err = au_opt_wbr_create(sb, &opt->wbr_create);
21981 + case Opt_wbr_copyup:
21982 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
21983 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
21987 + sbinfo->si_dirwh = opt->dirwh;
21990 + case Opt_rdcache:
21991 + sbinfo->si_rdcache
21992 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
21995 + sbinfo->si_rdblk = opt->rdblk;
21997 + case Opt_rdblk_def:
21998 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
22001 + sbinfo->si_rdhash = opt->rdhash;
22003 + case Opt_rdhash_def:
22004 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
22008 + au_opt_set(sbinfo->si_mntflags, SHWH);
22011 + au_opt_clr(sbinfo->si_mntflags, SHWH);
22014 + case Opt_trunc_xino:
22015 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
22017 + case Opt_notrunc_xino:
22018 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
22021 + case Opt_trunc_xino_path:
22022 + case Opt_itrunc_xino:
22023 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
22028 + case Opt_trunc_xib:
22029 + au_fset_opts(opts->flags, TRUNC_XIB);
22031 + case Opt_notrunc_xib:
22032 + au_fclr_opts(opts->flags, TRUNC_XIB);
22044 + * returns tri-state.
22045 + * plus: processed without an error
22046 + * zero: unprocessed
22049 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
22050 + struct au_opts *opts)
22052 + int err, do_refresh;
22055 + switch (opt->type) {
22057 + opt->add.bindex = au_sbend(sb) + 1;
22058 + if (opt->add.bindex < 0)
22059 + opt->add.bindex = 0;
22061 + case Opt_prepend:
22062 + opt->add.bindex = 0;
22063 + add: /* indented label */
22065 + err = au_br_add(sb, &opt->add,
22066 + au_ftest_opts(opts->flags, REMOUNT));
22069 + au_fset_opts(opts->flags, REFRESH);
22075 + err = au_br_del(sb, &opt->del,
22076 + au_ftest_opts(opts->flags, REMOUNT));
22079 + au_fset_opts(opts->flags, TRUNC_XIB);
22080 + au_fset_opts(opts->flags, REFRESH);
22086 + err = au_br_mod(sb, &opt->mod,
22087 + au_ftest_opts(opts->flags, REMOUNT),
22092 + au_fset_opts(opts->flags, REFRESH);
22100 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
22101 + struct au_opt_xino **opt_xino,
22102 + struct au_opts *opts)
22105 + aufs_bindex_t bend, bindex;
22106 + struct dentry *root, *parent, *h_root;
22109 + switch (opt->type) {
22111 + err = au_xino_set(sb, &opt->xino,
22112 + !!au_ftest_opts(opts->flags, REMOUNT));
22113 + if (unlikely(err))
22116 + *opt_xino = &opt->xino;
22117 + au_xino_brid_set(sb, -1);
22119 + /* safe d_parent access */
22120 + parent = opt->xino.file->f_dentry->d_parent;
22121 + root = sb->s_root;
22122 + bend = au_sbend(sb);
22123 + for (bindex = 0; bindex <= bend; bindex++) {
22124 + h_root = au_h_dptr(root, bindex);
22125 + if (h_root == parent) {
22126 + au_xino_brid_set(sb, au_sbr_id(sb, bindex));
22134 + au_xino_brid_set(sb, -1);
22135 + *opt_xino = (void *)-1;
22142 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
22143 + unsigned int pending)
22146 + aufs_bindex_t bindex, bend;
22147 + unsigned char do_plink, skip, do_free;
22148 + struct au_branch *br;
22149 + struct au_wbr *wbr;
22150 + struct dentry *root;
22151 + struct inode *dir, *h_dir;
22152 + struct au_sbinfo *sbinfo;
22153 + struct au_hinode *hdir;
22155 + SiMustAnyLock(sb);
22157 + sbinfo = au_sbi(sb);
22158 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
22160 + if (!(sb_flags & MS_RDONLY)) {
22161 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
22162 + pr_warn("first branch should be rw\n");
22163 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
22164 + pr_warn("shwh should be used with ro\n");
22167 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
22168 + && !au_opt_test(sbinfo->si_mntflags, XINO))
22169 + pr_warn("udba=*notify requires xino\n");
22172 + root = sb->s_root;
22173 + dir = root->d_inode;
22174 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
22175 + bend = au_sbend(sb);
22176 + for (bindex = 0; !err && bindex <= bend; bindex++) {
22178 + h_dir = au_h_iptr(dir, bindex);
22179 + br = au_sbr(sb, bindex);
22182 + wbr = br->br_wbr;
22184 + wbr_wh_read_lock(wbr);
22186 + if (!au_br_writable(br->br_perm)) {
22189 + || (!wbr->wbr_whbase
22190 + && !wbr->wbr_plink
22191 + && !wbr->wbr_orph));
22192 + } else if (!au_br_wh_linkable(br->br_perm)) {
22193 + /* skip = (!br->br_whbase && !br->br_orph); */
22194 + skip = (!wbr || !wbr->wbr_whbase);
22195 + if (skip && wbr) {
22197 + skip = !!wbr->wbr_plink;
22199 + skip = !wbr->wbr_plink;
22202 + /* skip = (br->br_whbase && br->br_ohph); */
22203 + skip = (wbr && wbr->wbr_whbase);
22206 + skip = !!wbr->wbr_plink;
22208 + skip = !wbr->wbr_plink;
22212 + wbr_wh_read_unlock(wbr);
22217 + hdir = au_hi(dir, bindex);
22218 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
22220 + wbr_wh_write_lock(wbr);
22221 + err = au_wh_init(br, sb);
22223 + wbr_wh_write_unlock(wbr);
22224 + au_hn_imtx_unlock(hdir);
22226 + if (!err && do_free) {
22228 + br->br_wbr = NULL;
22235 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
22238 + unsigned int tmp;
22239 + aufs_bindex_t bindex, bend;
22240 + struct au_opt *opt;
22241 + struct au_opt_xino *opt_xino, xino;
22242 + struct au_sbinfo *sbinfo;
22243 + struct au_branch *br;
22245 + SiMustWriteLock(sb);
22250 + while (err >= 0 && opt->type != Opt_tail)
22251 + err = au_opt_simple(sb, opt++, opts);
22254 + else if (unlikely(err < 0))
22257 + /* disable xino and udba temporary */
22258 + sbinfo = au_sbi(sb);
22259 + tmp = sbinfo->si_mntflags;
22260 + au_opt_clr(sbinfo->si_mntflags, XINO);
22261 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
22264 + while (err >= 0 && opt->type != Opt_tail)
22265 + err = au_opt_br(sb, opt++, opts);
22268 + else if (unlikely(err < 0))
22271 + bend = au_sbend(sb);
22272 + if (unlikely(bend < 0)) {
22274 + pr_err("no branches\n");
22278 + if (au_opt_test(tmp, XINO))
22279 + au_opt_set(sbinfo->si_mntflags, XINO);
22281 + while (!err && opt->type != Opt_tail)
22282 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
22283 + if (unlikely(err))
22286 + err = au_opts_verify(sb, sb->s_flags, tmp);
22287 + if (unlikely(err))
22290 + /* restore xino */
22291 + if (au_opt_test(tmp, XINO) && !opt_xino) {
22292 + xino.file = au_xino_def(sb);
22293 + err = PTR_ERR(xino.file);
22294 + if (IS_ERR(xino.file))
22297 + err = au_xino_set(sb, &xino, /*remount*/0);
22299 + if (unlikely(err))
22303 + /* restore udba */
22304 + tmp &= AuOptMask_UDBA;
22305 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
22306 + sbinfo->si_mntflags |= tmp;
22307 + bend = au_sbend(sb);
22308 + for (bindex = 0; bindex <= bend; bindex++) {
22309 + br = au_sbr(sb, bindex);
22310 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
22311 + if (unlikely(err))
22312 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
22314 + /* go on even if err */
22316 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
22317 + struct inode *dir = sb->s_root->d_inode;
22318 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
22325 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
22328 + struct inode *dir;
22329 + struct au_opt_xino *opt_xino;
22330 + struct au_opt *opt;
22331 + struct au_sbinfo *sbinfo;
22333 + SiMustWriteLock(sb);
22335 + dir = sb->s_root->d_inode;
22336 + sbinfo = au_sbi(sb);
22340 + while (err >= 0 && opt->type != Opt_tail) {
22341 + err = au_opt_simple(sb, opt, opts);
22343 + err = au_opt_br(sb, opt, opts);
22345 + err = au_opt_xino(sb, opt, &opt_xino, opts);
22351 + /* go on even err */
22353 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
22354 + if (unlikely(rerr && !err))
22357 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
22358 + rerr = au_xib_trunc(sb);
22359 + if (unlikely(rerr && !err))
22363 + /* will be handled by the caller */
22364 + if (!au_ftest_opts(opts->flags, REFRESH)
22365 + && (opts->given_udba || au_opt_test(sbinfo->si_mntflags, XINO)))
22366 + au_fset_opts(opts->flags, REFRESH);
22368 + AuDbg("status 0x%x\n", opts->flags);
22372 +/* ---------------------------------------------------------------------- */
22374 +unsigned int au_opt_udba(struct super_block *sb)
22376 + return au_mntflags(sb) & AuOptMask_UDBA;
22378 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
22379 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
22380 +++ linux/fs/aufs/opts.h 2014-01-20 20:16:14.742796949 +0100
22383 + * Copyright (C) 2005-2014 Junjiro R. Okajima
22385 + * This program, aufs is free software; you can redistribute it and/or modify
22386 + * it under the terms of the GNU General Public License as published by
22387 + * the Free Software Foundation; either version 2 of the License, or
22388 + * (at your option) any later version.
22390 + * This program is distributed in the hope that it will be useful,
22391 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22392 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22393 + * GNU General Public License for more details.
22395 + * You should have received a copy of the GNU General Public License
22396 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22400 + * mount options/flags
22403 +#ifndef __AUFS_OPTS_H__
22404 +#define __AUFS_OPTS_H__
22408 +#include <linux/path.h>
22411 +struct super_block;
22413 +/* ---------------------------------------------------------------------- */
22416 +#define AuOpt_XINO 1 /* external inode number bitmap
22417 + and translation table */
22418 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
22419 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
22420 +#define AuOpt_UDBA_REVAL (1 << 3)
22421 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
22422 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
22423 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
22424 +#define AuOpt_DIRPERM1 (1 << 7) /* unimplemented */
22425 +#define AuOpt_REFROF (1 << 8) /* unimplemented */
22426 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
22427 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
22428 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
22429 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
22430 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
22431 +#define AuOpt_DIO (1 << 14) /* direct io */
22433 +#ifndef CONFIG_AUFS_HNOTIFY
22434 +#undef AuOpt_UDBA_HNOTIFY
22435 +#define AuOpt_UDBA_HNOTIFY 0
22437 +#ifndef CONFIG_AUFS_SHWH
22439 +#define AuOpt_SHWH 0
22442 +#define AuOpt_Def (AuOpt_XINO \
22443 + | AuOpt_UDBA_REVAL \
22445 + /* | AuOpt_DIRPERM1 */ \
22446 + | AuOpt_WARN_PERM)
22447 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
22448 + | AuOpt_UDBA_REVAL \
22449 + | AuOpt_UDBA_HNOTIFY)
22451 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
22452 +#define au_opt_set(flags, name) do { \
22453 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
22454 + ((flags) |= AuOpt_##name); \
22456 +#define au_opt_set_udba(flags, name) do { \
22457 + (flags) &= ~AuOptMask_UDBA; \
22458 + ((flags) |= AuOpt_##name); \
22460 +#define au_opt_clr(flags, name) do { \
22461 + ((flags) &= ~AuOpt_##name); \
22464 +static inline unsigned int au_opts_plink(unsigned int mntflags)
22466 +#ifdef CONFIG_PROC_FS
22469 + return mntflags & ~AuOpt_PLINK;
22473 +/* ---------------------------------------------------------------------- */
22475 +/* policies to select one among multiple writable branches */
22477 + AuWbrCreate_TDP, /* top down parent */
22478 + AuWbrCreate_RR, /* round robin */
22479 + AuWbrCreate_MFS, /* most free space */
22480 + AuWbrCreate_MFSV, /* mfs with seconds */
22481 + AuWbrCreate_MFSRR, /* mfs then rr */
22482 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
22483 + AuWbrCreate_PMFS, /* parent and mfs */
22484 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
22485 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
22486 + AuWbrCreate_PMFSRRV, /* plus seconds */
22488 + AuWbrCreate_Def = AuWbrCreate_TDP
22492 + AuWbrCopyup_TDP, /* top down parent */
22493 + AuWbrCopyup_BUP, /* bottom up parent */
22494 + AuWbrCopyup_BU, /* bottom up */
22496 + AuWbrCopyup_Def = AuWbrCopyup_TDP
22499 +/* ---------------------------------------------------------------------- */
22501 +struct au_opt_add {
22502 + aufs_bindex_t bindex;
22505 + struct path path;
22508 +struct au_opt_del {
22510 + struct path h_path;
22513 +struct au_opt_mod {
22516 + struct dentry *h_root;
22519 +struct au_opt_xino {
22521 + struct file *file;
22524 +struct au_opt_xino_itrunc {
22525 + aufs_bindex_t bindex;
22528 +struct au_opt_wbr_create {
22531 + unsigned long long mfsrr_watermark;
22537 + struct au_opt_xino xino;
22538 + struct au_opt_xino_itrunc xino_itrunc;
22539 + struct au_opt_add add;
22540 + struct au_opt_del del;
22541 + struct au_opt_mod mod;
22544 + unsigned int rdblk;
22545 + unsigned int rdhash;
22547 + struct au_opt_wbr_create wbr_create;
22553 +#define AuOpts_REMOUNT 1
22554 +#define AuOpts_REFRESH (1 << 1)
22555 +#define AuOpts_TRUNC_XIB (1 << 2)
22556 +#define AuOpts_REFRESH_DYAOP (1 << 3)
22557 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
22558 +#define au_fset_opts(flags, name) \
22559 + do { (flags) |= AuOpts_##name; } while (0)
22560 +#define au_fclr_opts(flags, name) \
22561 + do { (flags) &= ~AuOpts_##name; } while (0)
22564 + struct au_opt *opt;
22567 + unsigned int given_udba;
22568 + unsigned int flags;
22569 + unsigned long sb_flags;
22572 +/* ---------------------------------------------------------------------- */
22574 +char *au_optstr_br_perm(int brperm);
22575 +const char *au_optstr_udba(int udba);
22576 +const char *au_optstr_wbr_copyup(int wbr_copyup);
22577 +const char *au_optstr_wbr_create(int wbr_create);
22579 +void au_opts_free(struct au_opts *opts);
22580 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
22581 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
22582 + unsigned int pending);
22583 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
22584 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
22586 +unsigned int au_opt_udba(struct super_block *sb);
22588 +/* ---------------------------------------------------------------------- */
22590 +#endif /* __KERNEL__ */
22591 +#endif /* __AUFS_OPTS_H__ */
22592 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
22593 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
22594 +++ linux/fs/aufs/plink.c 2014-01-20 20:16:14.742796949 +0100
22597 + * Copyright (C) 2005-2014 Junjiro R. Okajima
22599 + * This program, aufs is free software; you can redistribute it and/or modify
22600 + * it under the terms of the GNU General Public License as published by
22601 + * the Free Software Foundation; either version 2 of the License, or
22602 + * (at your option) any later version.
22604 + * This program is distributed in the hope that it will be useful,
22605 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22606 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22607 + * GNU General Public License for more details.
22609 + * You should have received a copy of the GNU General Public License
22610 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22620 + * the pseudo-link maintenance mode.
22621 + * during a user process maintains the pseudo-links,
22622 + * prohibit adding a new plink and branch manipulation.
22626 + * For entry functions which will handle plink, and i_mutex is already held
22628 + * They cannot wait and should return an error at once.
22629 + * Callers has to check the error.
22631 + * For entry functions which will handle plink, but i_mutex is not held
22633 + * They can wait the plink maintenance mode to finish.
22635 + * They behave like F_SETLK and F_SETLKW.
22636 + * If the caller never handle plink, then both flags are unnecessary.
22639 +int au_plink_maint(struct super_block *sb, int flags)
22643 + struct au_sbinfo *sbi;
22645 + SiMustAnyLock(sb);
22648 + if (!au_opt_test(au_mntflags(sb), PLINK))
22651 + sbi = au_sbi(sb);
22652 + pid = sbi->si_plink_maint_pid;
22653 + if (!pid || pid == current->pid)
22656 + /* todo: it highly depends upon /sbin/mount.aufs */
22658 + ppid = task_pid_vnr(rcu_dereference(current->real_parent));
22659 + rcu_read_unlock();
22663 + if (au_ftest_lock(flags, NOPLMW)) {
22664 + /* if there is no i_mutex lock in VFS, we don't need to wait */
22665 + /* AuDebugOn(!lockdep_depth(current)); */
22666 + while (sbi->si_plink_maint_pid) {
22667 + si_read_unlock(sb);
22668 + /* gave up wake_up_bit() */
22669 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
22671 + if (au_ftest_lock(flags, FLUSH))
22672 + au_nwt_flush(&sbi->si_nowait);
22673 + si_noflush_read_lock(sb);
22675 + } else if (au_ftest_lock(flags, NOPLM)) {
22676 + AuDbg("ppid %d, pid %d\n", ppid, pid);
22684 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
22686 + spin_lock(&sbinfo->si_plink_maint_lock);
22687 + sbinfo->si_plink_maint_pid = 0;
22688 + spin_unlock(&sbinfo->si_plink_maint_lock);
22689 + wake_up_all(&sbinfo->si_plink_wq);
22692 +int au_plink_maint_enter(struct super_block *sb)
22695 + struct au_sbinfo *sbinfo;
22698 + sbinfo = au_sbi(sb);
22699 + /* make sure i am the only one in this fs */
22700 + si_write_lock(sb, AuLock_FLUSH);
22701 + if (au_opt_test(au_mntflags(sb), PLINK)) {
22702 + spin_lock(&sbinfo->si_plink_maint_lock);
22703 + if (!sbinfo->si_plink_maint_pid)
22704 + sbinfo->si_plink_maint_pid = current->pid;
22707 + spin_unlock(&sbinfo->si_plink_maint_lock);
22709 + si_write_unlock(sb);
22714 +/* ---------------------------------------------------------------------- */
22716 +#ifdef CONFIG_AUFS_DEBUG
22717 +void au_plink_list(struct super_block *sb)
22720 + struct au_sbinfo *sbinfo;
22721 + struct hlist_head *plink_hlist;
22722 + struct pseudo_link *plink;
22724 + SiMustAnyLock(sb);
22726 + sbinfo = au_sbi(sb);
22727 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
22728 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
22730 + for (i = 0; i < AuPlink_NHASH; i++) {
22731 + plink_hlist = &sbinfo->si_plink[i].head;
22733 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
22734 + AuDbg("%lu\n", plink->inode->i_ino);
22735 + rcu_read_unlock();
22740 +/* is the inode pseudo-linked? */
22741 +int au_plink_test(struct inode *inode)
22744 + struct au_sbinfo *sbinfo;
22745 + struct hlist_head *plink_hlist;
22746 + struct pseudo_link *plink;
22748 + sbinfo = au_sbi(inode->i_sb);
22749 + AuRwMustAnyLock(&sbinfo->si_rwsem);
22750 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
22751 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
22754 + i = au_plink_hash(inode->i_ino);
22755 + plink_hlist = &sbinfo->si_plink[i].head;
22757 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
22758 + if (plink->inode == inode) {
22762 + rcu_read_unlock();
22766 +/* ---------------------------------------------------------------------- */
22769 + * generate a name for plink.
22770 + * the file will be stored under AUFS_WH_PLINKDIR.
22772 +/* 20 is max digits length of ulong 64 */
22773 +#define PLINK_NAME_LEN ((20 + 1) * 2)
22775 +static int plink_name(char *name, int len, struct inode *inode,
22776 + aufs_bindex_t bindex)
22779 + struct inode *h_inode;
22781 + h_inode = au_h_iptr(inode, bindex);
22782 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
22786 +struct au_do_plink_lkup_args {
22787 + struct dentry **errp;
22788 + struct qstr *tgtname;
22789 + struct dentry *h_parent;
22790 + struct au_branch *br;
22793 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
22794 + struct dentry *h_parent,
22795 + struct au_branch *br)
22797 + struct dentry *h_dentry;
22798 + struct mutex *h_mtx;
22800 + h_mtx = &h_parent->d_inode->i_mutex;
22801 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
22802 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
22803 + mutex_unlock(h_mtx);
22807 +static void au_call_do_plink_lkup(void *args)
22809 + struct au_do_plink_lkup_args *a = args;
22810 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
22813 +/* lookup the plink-ed @inode under the branch at @bindex */
22814 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
22816 + struct dentry *h_dentry, *h_parent;
22817 + struct au_branch *br;
22818 + struct inode *h_dir;
22820 + char a[PLINK_NAME_LEN];
22821 + struct qstr tgtname = QSTR_INIT(a, 0);
22823 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
22825 + br = au_sbr(inode->i_sb, bindex);
22826 + h_parent = br->br_wbr->wbr_plink;
22827 + h_dir = h_parent->d_inode;
22828 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
22830 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
22831 + struct au_do_plink_lkup_args args = {
22832 + .errp = &h_dentry,
22833 + .tgtname = &tgtname,
22834 + .h_parent = h_parent,
22838 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
22839 + if (unlikely(wkq_err))
22840 + h_dentry = ERR_PTR(wkq_err);
22842 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
22847 +/* create a pseudo-link */
22848 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
22849 + struct dentry *h_dentry, struct au_branch *br)
22852 + struct path h_path = {
22853 + .mnt = au_br_mnt(br)
22855 + struct inode *h_dir, *delegated;
22857 + h_dir = h_parent->d_inode;
22858 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_CHILD2);
22860 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
22861 + err = PTR_ERR(h_path.dentry);
22862 + if (IS_ERR(h_path.dentry))
22866 + /* wh.plink dir is not monitored */
22867 + /* todo: is it really safe? */
22868 + if (h_path.dentry->d_inode
22869 + && h_path.dentry->d_inode != h_dentry->d_inode) {
22870 + delegated = NULL;
22871 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
22872 + if (unlikely(err == -EWOULDBLOCK)) {
22873 + pr_warn("cannot retry for NFSv4 delegation"
22874 + " for an internal unlink\n");
22877 + dput(h_path.dentry);
22878 + h_path.dentry = NULL;
22882 + if (!err && !h_path.dentry->d_inode) {
22883 + delegated = NULL;
22884 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
22885 + if (unlikely(err == -EWOULDBLOCK)) {
22886 + pr_warn("cannot retry for NFSv4 delegation"
22887 + " for an internal link\n");
22891 + dput(h_path.dentry);
22894 + mutex_unlock(&h_dir->i_mutex);
22898 +struct do_whplink_args {
22900 + struct qstr *tgt;
22901 + struct dentry *h_parent;
22902 + struct dentry *h_dentry;
22903 + struct au_branch *br;
22906 +static void call_do_whplink(void *args)
22908 + struct do_whplink_args *a = args;
22909 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
22912 +static int whplink(struct dentry *h_dentry, struct inode *inode,
22913 + aufs_bindex_t bindex, struct au_branch *br)
22915 + int err, wkq_err;
22916 + struct au_wbr *wbr;
22917 + struct dentry *h_parent;
22918 + struct inode *h_dir;
22919 + char a[PLINK_NAME_LEN];
22920 + struct qstr tgtname = QSTR_INIT(a, 0);
22922 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
22923 + h_parent = wbr->wbr_plink;
22924 + h_dir = h_parent->d_inode;
22925 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
22927 + /* always superio. */
22928 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
22929 + struct do_whplink_args args = {
22932 + .h_parent = h_parent,
22933 + .h_dentry = h_dentry,
22936 + wkq_err = au_wkq_wait(call_do_whplink, &args);
22937 + if (unlikely(wkq_err))
22940 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
22945 +/* free a single plink */
22946 +static void do_put_plink(struct pseudo_link *plink, int do_del)
22949 + hlist_del(&plink->hlist);
22950 + iput(plink->inode);
22954 +static void do_put_plink_rcu(struct rcu_head *rcu)
22956 + struct pseudo_link *plink;
22958 + plink = container_of(rcu, struct pseudo_link, rcu);
22959 + iput(plink->inode);
22964 + * create a new pseudo-link for @h_dentry on @bindex.
22965 + * the linked inode is held in aufs @inode.
22967 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
22968 + struct dentry *h_dentry)
22970 + struct super_block *sb;
22971 + struct au_sbinfo *sbinfo;
22972 + struct hlist_head *plink_hlist;
22973 + struct pseudo_link *plink, *tmp;
22974 + struct au_sphlhead *sphl;
22975 + int found, err, cnt, i;
22977 + sb = inode->i_sb;
22978 + sbinfo = au_sbi(sb);
22979 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
22980 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
22982 + found = au_plink_test(inode);
22986 + i = au_plink_hash(inode->i_ino);
22987 + sphl = sbinfo->si_plink + i;
22988 + plink_hlist = &sphl->head;
22989 + tmp = kmalloc(sizeof(*plink), GFP_NOFS);
22991 + tmp->inode = au_igrab(inode);
22997 + spin_lock(&sphl->spin);
22998 + hlist_for_each_entry(plink, plink_hlist, hlist) {
22999 + if (plink->inode == inode) {
23005 + hlist_add_head_rcu(&tmp->hlist, plink_hlist);
23006 + spin_unlock(&sphl->spin);
23008 + cnt = au_sphl_count(sphl);
23009 +#define msg "unexpectedly unblanced or too many pseudo-links"
23010 + if (cnt > AUFS_PLINK_WARN)
23011 + AuWarn1(msg ", %d\n", cnt);
23013 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
23015 + do_put_plink(tmp, 0);
23020 + if (unlikely(err)) {
23021 + pr_warn("err %d, damaged pseudo link.\n", err);
23023 + au_sphl_del_rcu(&tmp->hlist, sphl);
23024 + call_rcu(&tmp->rcu, do_put_plink_rcu);
23029 +/* free all plinks */
23030 +void au_plink_put(struct super_block *sb, int verbose)
23033 + struct au_sbinfo *sbinfo;
23034 + struct hlist_head *plink_hlist;
23035 + struct hlist_node *tmp;
23036 + struct pseudo_link *plink;
23038 + SiMustWriteLock(sb);
23040 + sbinfo = au_sbi(sb);
23041 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
23042 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
23044 + /* no spin_lock since sbinfo is write-locked */
23046 + for (i = 0; i < AuPlink_NHASH; i++) {
23047 + plink_hlist = &sbinfo->si_plink[i].head;
23048 + if (!warned && verbose && !hlist_empty(plink_hlist)) {
23049 + pr_warn("pseudo-link is not flushed");
23052 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist)
23053 + do_put_plink(plink, 0);
23054 + INIT_HLIST_HEAD(plink_hlist);
23058 +void au_plink_clean(struct super_block *sb, int verbose)
23060 + struct dentry *root;
23062 + root = sb->s_root;
23063 + aufs_write_lock(root);
23064 + if (au_opt_test(au_mntflags(sb), PLINK))
23065 + au_plink_put(sb, verbose);
23066 + aufs_write_unlock(root);
23069 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
23072 + aufs_bindex_t bstart, bend, bindex;
23075 + bstart = au_ibstart(inode);
23076 + bend = au_ibend(inode);
23077 + if (bstart >= 0) {
23078 + for (bindex = bstart; bindex <= bend; bindex++) {
23079 + if (!au_h_iptr(inode, bindex)
23080 + || au_ii_br_id(inode, bindex) != br_id)
23082 + au_set_h_iptr(inode, bindex, NULL, 0);
23087 + for (bindex = bstart; bindex <= bend; bindex++)
23088 + if (au_h_iptr(inode, bindex)) {
23098 +/* free the plinks on a branch specified by @br_id */
23099 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
23101 + struct au_sbinfo *sbinfo;
23102 + struct hlist_head *plink_hlist;
23103 + struct hlist_node *tmp;
23104 + struct pseudo_link *plink;
23105 + struct inode *inode;
23108 + SiMustWriteLock(sb);
23110 + sbinfo = au_sbi(sb);
23111 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
23112 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
23114 + /* no spin_lock since sbinfo is write-locked */
23115 + for (i = 0; i < AuPlink_NHASH; i++) {
23116 + plink_hlist = &sbinfo->si_plink[i].head;
23117 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist) {
23118 + inode = au_igrab(plink->inode);
23119 + ii_write_lock_child(inode);
23120 + do_put = au_plink_do_half_refresh(inode, br_id);
23122 + do_put_plink(plink, 1);
23123 + ii_write_unlock(inode);
23128 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
23129 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
23130 +++ linux/fs/aufs/poll.c 2014-01-20 20:16:14.742796949 +0100
23133 + * Copyright (C) 2005-2014 Junjiro R. Okajima
23135 + * This program, aufs is free software; you can redistribute it and/or modify
23136 + * it under the terms of the GNU General Public License as published by
23137 + * the Free Software Foundation; either version 2 of the License, or
23138 + * (at your option) any later version.
23140 + * This program is distributed in the hope that it will be useful,
23141 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23142 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23143 + * GNU General Public License for more details.
23145 + * You should have received a copy of the GNU General Public License
23146 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23151 + * There is only one filesystem which implements ->poll operation, currently.
23156 +unsigned int aufs_poll(struct file *file, poll_table *wait)
23158 + unsigned int mask;
23160 + struct file *h_file;
23161 + struct dentry *dentry;
23162 + struct super_block *sb;
23164 + /* We should pretend an error happened. */
23165 + mask = POLLERR /* | POLLIN | POLLOUT */;
23166 + dentry = file->f_dentry;
23167 + sb = dentry->d_sb;
23168 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
23169 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
23170 + if (unlikely(err))
23173 + /* it is not an error if h_file has no operation */
23174 + mask = DEFAULT_POLLMASK;
23175 + h_file = au_hf_top(file);
23176 + if (h_file->f_op->poll)
23177 + mask = h_file->f_op->poll(h_file, wait);
23179 + di_read_unlock(dentry, AuLock_IR);
23180 + fi_read_unlock(file);
23183 + si_read_unlock(sb);
23184 + AuTraceErr((int)mask);
23187 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
23188 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
23189 +++ linux/fs/aufs/procfs.c 2014-01-20 20:16:14.742796949 +0100
23192 + * Copyright (C) 2010-2014 Junjiro R. Okajima
23194 + * This program, aufs is free software; you can redistribute it and/or modify
23195 + * it under the terms of the GNU General Public License as published by
23196 + * the Free Software Foundation; either version 2 of the License, or
23197 + * (at your option) any later version.
23199 + * This program is distributed in the hope that it will be useful,
23200 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23201 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23202 + * GNU General Public License for more details.
23204 + * You should have received a copy of the GNU General Public License
23205 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23209 + * procfs interfaces
23212 +#include <linux/proc_fs.h>
23215 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
23217 + struct au_sbinfo *sbinfo;
23219 + sbinfo = file->private_data;
23221 + au_plink_maint_leave(sbinfo);
23222 + kobject_put(&sbinfo->si_kobj);
23228 +static void au_procfs_plm_write_clean(struct file *file)
23230 + struct au_sbinfo *sbinfo;
23232 + sbinfo = file->private_data;
23234 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
23237 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
23240 + struct super_block *sb;
23241 + struct au_sbinfo *sbinfo;
23244 + if (unlikely(file->private_data))
23248 + /* don't use au_sbilist_lock() here */
23249 + spin_lock(&au_sbilist.spin);
23250 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
23251 + if (id == sysaufs_si_id(sbinfo)) {
23252 + kobject_get(&sbinfo->si_kobj);
23253 + sb = sbinfo->si_sb;
23256 + spin_unlock(&au_sbilist.spin);
23259 + if (unlikely(!sb))
23262 + err = au_plink_maint_enter(sb);
23264 + /* keep kobject_get() */
23265 + file->private_data = sbinfo;
23267 + kobject_put(&sbinfo->si_kobj);
23273 + * Accept a valid "si=xxxx" only.
23274 + * Once it is accepted successfully, accept "clean" too.
23276 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
23277 + size_t count, loff_t *ppos)
23280 + unsigned long id;
23281 + /* last newline is allowed */
23282 + char buf[3 + sizeof(unsigned long) * 2 + 1];
23285 + if (unlikely(!capable(CAP_SYS_ADMIN)))
23289 + if (unlikely(count > sizeof(buf)))
23292 + err = copy_from_user(buf, ubuf, count);
23293 + if (unlikely(err)) {
23300 + if (!strcmp("clean", buf)) {
23301 + au_procfs_plm_write_clean(file);
23302 + goto out_success;
23303 + } else if (unlikely(strncmp("si=", buf, 3)))
23306 + err = kstrtoul(buf + 3, 16, &id);
23307 + if (unlikely(err))
23310 + err = au_procfs_plm_write_si(file, id);
23311 + if (unlikely(err))
23315 + err = count; /* success */
23320 +static const struct file_operations au_procfs_plm_fop = {
23321 + .write = au_procfs_plm_write,
23322 + .release = au_procfs_plm_release,
23323 + .owner = THIS_MODULE
23326 +/* ---------------------------------------------------------------------- */
23328 +static struct proc_dir_entry *au_procfs_dir;
23330 +void au_procfs_fin(void)
23332 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
23333 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
23336 +int __init au_procfs_init(void)
23339 + struct proc_dir_entry *entry;
23342 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
23343 + if (unlikely(!au_procfs_dir))
23346 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR,
23347 + au_procfs_dir, &au_procfs_plm_fop);
23348 + if (unlikely(!entry))
23352 + goto out; /* success */
23356 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
23360 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
23361 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
23362 +++ linux/fs/aufs/rdu.c 2014-01-20 20:16:14.742796949 +0100
23365 + * Copyright (C) 2005-2014 Junjiro R. Okajima
23367 + * This program, aufs is free software; you can redistribute it and/or modify
23368 + * it under the terms of the GNU General Public License as published by
23369 + * the Free Software Foundation; either version 2 of the License, or
23370 + * (at your option) any later version.
23372 + * This program is distributed in the hope that it will be useful,
23373 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23374 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23375 + * GNU General Public License for more details.
23377 + * You should have received a copy of the GNU General Public License
23378 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23382 + * readdir in userspace.
23385 +#include <linux/compat.h>
23386 +#include <linux/fs_stack.h>
23387 +#include <linux/security.h>
23390 +/* bits for struct aufs_rdu.flags */
23391 +#define AuRdu_CALLED 1
23392 +#define AuRdu_CONT (1 << 1)
23393 +#define AuRdu_FULL (1 << 2)
23394 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
23395 +#define au_fset_rdu(flags, name) \
23396 + do { (flags) |= AuRdu_##name; } while (0)
23397 +#define au_fclr_rdu(flags, name) \
23398 + do { (flags) &= ~AuRdu_##name; } while (0)
23400 +struct au_rdu_arg {
23401 + struct dir_context ctx;
23402 + struct aufs_rdu *rdu;
23403 + union au_rdu_ent_ul ent;
23404 + unsigned long end;
23406 + struct super_block *sb;
23410 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
23411 + loff_t offset, u64 h_ino, unsigned int d_type)
23414 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
23415 + struct aufs_rdu *rdu = arg->rdu;
23416 + struct au_rdu_ent ent;
23420 + au_fset_rdu(rdu->cookie.flags, CALLED);
23421 + len = au_rdu_len(nlen);
23422 + if (arg->ent.ul + len < arg->end) {
23424 + ent.bindex = rdu->cookie.bindex;
23425 + ent.type = d_type;
23427 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
23428 + ent.type = DT_UNKNOWN;
23430 + /* unnecessary to support mmap_sem since this is a dir */
23432 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
23434 + if (copy_to_user(arg->ent.e->name, name, nlen))
23436 + /* the terminating NULL */
23437 + if (__put_user(0, arg->ent.e->name + nlen))
23440 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
23441 + arg->ent.ul += len;
23445 + au_fset_rdu(rdu->cookie.flags, FULL);
23447 + rdu->tail = arg->ent;
23451 + /* AuTraceErr(err); */
23455 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
23459 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
23461 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
23462 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
23464 + if (unlikely(offset != cookie->h_pos))
23470 + au_fclr_rdu(cookie->flags, CALLED);
23472 + err = vfsub_iterate_dir(h_file, &arg->ctx);
23476 + && au_ftest_rdu(cookie->flags, CALLED)
23477 + && !au_ftest_rdu(cookie->flags, FULL));
23478 + cookie->h_pos = h_file->f_pos;
23485 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
23488 + aufs_bindex_t bend;
23489 + struct au_rdu_arg arg = {
23491 + .actor = au_diractor(au_rdu_fill)
23494 + struct dentry *dentry;
23495 + struct inode *inode;
23496 + struct file *h_file;
23497 + struct au_rdu_cookie *cookie = &rdu->cookie;
23499 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
23500 + if (unlikely(err)) {
23506 + rdu->tail = rdu->ent;
23509 + arg.ent = rdu->ent;
23510 + arg.end = arg.ent.ul;
23511 + arg.end += rdu->sz;
23514 + if (unlikely(!file->f_op->iterate))
23517 + err = security_file_permission(file, MAY_READ);
23519 + if (unlikely(err))
23522 + dentry = file->f_dentry;
23523 + inode = dentry->d_inode;
23525 + mutex_lock(&inode->i_mutex);
23527 + err = mutex_lock_killable(&inode->i_mutex);
23529 + if (unlikely(err))
23533 + arg.sb = inode->i_sb;
23534 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
23535 + if (unlikely(err))
23537 + err = au_alive_dir(dentry);
23538 + if (unlikely(err))
23540 + /* todo: reval? */
23541 + fi_read_lock(file);
23544 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
23545 + && cookie->generation != au_figen(file)))
23550 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
23552 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
23554 + bend = au_fbstart(file);
23555 + if (cookie->bindex < bend)
23556 + cookie->bindex = bend;
23557 + bend = au_fbend_dir(file);
23558 + /* AuDbg("b%d, b%d\n", cookie->bindex, bend); */
23559 + for (; !err && cookie->bindex <= bend;
23560 + cookie->bindex++, cookie->h_pos = 0) {
23561 + h_file = au_hf_dir(file, cookie->bindex);
23565 + au_fclr_rdu(cookie->flags, FULL);
23566 + err = au_rdu_do(h_file, &arg);
23568 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
23571 + AuDbg("rent %llu\n", rdu->rent);
23573 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
23574 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
23575 + au_fset_rdu(cookie->flags, CONT);
23576 + cookie->generation = au_figen(file);
23579 + ii_read_lock_child(inode);
23580 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibstart(inode)));
23581 + ii_read_unlock(inode);
23584 + fi_read_unlock(file);
23586 + si_read_unlock(arg.sb);
23588 + mutex_unlock(&inode->i_mutex);
23594 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
23598 + unsigned long long nent;
23599 + union au_rdu_ent_ul *u;
23600 + struct au_rdu_ent ent;
23601 + struct super_block *sb;
23604 + nent = rdu->nent;
23606 + sb = file->f_dentry->d_sb;
23607 + si_read_lock(sb, AuLock_FLUSH);
23608 + while (nent-- > 0) {
23609 + /* unnecessary to support mmap_sem since this is a dir */
23610 + err = copy_from_user(&ent, u->e, sizeof(ent));
23612 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
23613 + if (unlikely(err)) {
23619 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
23621 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
23623 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
23625 + if (unlikely(err)) {
23630 + err = __put_user(ino, &u->e->ino);
23631 + if (unlikely(err)) {
23636 + u->ul += au_rdu_len(ent.nlen);
23638 + si_read_unlock(sb);
23643 +/* ---------------------------------------------------------------------- */
23645 +static int au_rdu_verify(struct aufs_rdu *rdu)
23647 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
23648 + "%llu, b%d, 0x%x, g%u}\n",
23649 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
23651 + rdu->rent, rdu->shwh, rdu->full,
23652 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
23653 + rdu->cookie.generation);
23655 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
23659 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
23663 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
23666 + struct aufs_rdu rdu;
23667 + void __user *p = (void __user *)arg;
23669 + err = copy_from_user(&rdu, p, sizeof(rdu));
23670 + if (unlikely(err)) {
23675 + err = au_rdu_verify(&rdu);
23676 + if (unlikely(err))
23680 + case AUFS_CTL_RDU:
23681 + err = au_rdu(file, &rdu);
23682 + if (unlikely(err))
23685 + e = copy_to_user(p, &rdu, sizeof(rdu));
23686 + if (unlikely(e)) {
23691 + case AUFS_CTL_RDU_INO:
23692 + err = au_rdu_ino(file, &rdu);
23696 + /* err = -ENOTTY; */
23705 +#ifdef CONFIG_COMPAT
23706 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
23709 + struct aufs_rdu rdu;
23710 + void __user *p = compat_ptr(arg);
23712 + /* todo: get_user()? */
23713 + err = copy_from_user(&rdu, p, sizeof(rdu));
23714 + if (unlikely(err)) {
23719 + rdu.ent.e = compat_ptr(rdu.ent.ul);
23720 + err = au_rdu_verify(&rdu);
23721 + if (unlikely(err))
23725 + case AUFS_CTL_RDU:
23726 + err = au_rdu(file, &rdu);
23727 + if (unlikely(err))
23730 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
23731 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
23732 + e = copy_to_user(p, &rdu, sizeof(rdu));
23733 + if (unlikely(e)) {
23738 + case AUFS_CTL_RDU_INO:
23739 + err = au_rdu_ino(file, &rdu);
23743 + /* err = -ENOTTY; */
23752 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
23753 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
23754 +++ linux/fs/aufs/rwsem.h 2014-01-20 20:16:14.742796949 +0100
23757 + * Copyright (C) 2005-2014 Junjiro R. Okajima
23759 + * This program, aufs is free software; you can redistribute it and/or modify
23760 + * it under the terms of the GNU General Public License as published by
23761 + * the Free Software Foundation; either version 2 of the License, or
23762 + * (at your option) any later version.
23764 + * This program is distributed in the hope that it will be useful,
23765 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23766 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23767 + * GNU General Public License for more details.
23769 + * You should have received a copy of the GNU General Public License
23770 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23774 + * simple read-write semaphore wrappers
23777 +#ifndef __AUFS_RWSEM_H__
23778 +#define __AUFS_RWSEM_H__
23782 +#include "debug.h"
23785 + struct rw_semaphore rwsem;
23786 +#ifdef CONFIG_AUFS_DEBUG
23787 + /* just for debugging, not almighty counter */
23788 + atomic_t rcnt, wcnt;
23792 +#ifdef CONFIG_AUFS_DEBUG
23793 +#define AuDbgCntInit(rw) do { \
23794 + atomic_set(&(rw)->rcnt, 0); \
23795 + atomic_set(&(rw)->wcnt, 0); \
23796 + smp_mb(); /* atomic set */ \
23799 +#define AuDbgRcntInc(rw) atomic_inc(&(rw)->rcnt)
23800 +#define AuDbgRcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->rcnt) < 0)
23801 +#define AuDbgWcntInc(rw) atomic_inc(&(rw)->wcnt)
23802 +#define AuDbgWcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->wcnt) < 0)
23804 +#define AuDbgCntInit(rw) do {} while (0)
23805 +#define AuDbgRcntInc(rw) do {} while (0)
23806 +#define AuDbgRcntDec(rw) do {} while (0)
23807 +#define AuDbgWcntInc(rw) do {} while (0)
23808 +#define AuDbgWcntDec(rw) do {} while (0)
23809 +#endif /* CONFIG_AUFS_DEBUG */
23811 +/* to debug easier, do not make them inlined functions */
23812 +#define AuRwMustNoWaiters(rw) AuDebugOn(!list_empty(&(rw)->rwsem.wait_list))
23813 +/* rwsem_is_locked() is unusable */
23814 +#define AuRwMustReadLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0)
23815 +#define AuRwMustWriteLock(rw) AuDebugOn(atomic_read(&(rw)->wcnt) <= 0)
23816 +#define AuRwMustAnyLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0 \
23817 + && atomic_read(&(rw)->wcnt) <= 0)
23818 +#define AuRwDestroy(rw) AuDebugOn(atomic_read(&(rw)->rcnt) \
23819 + || atomic_read(&(rw)->wcnt))
23821 +#define au_rw_class(rw, key) lockdep_set_class(&(rw)->rwsem, key)
23823 +static inline void au_rw_init(struct au_rwsem *rw)
23825 + AuDbgCntInit(rw);
23826 + init_rwsem(&rw->rwsem);
23829 +static inline void au_rw_init_wlock(struct au_rwsem *rw)
23832 + down_write(&rw->rwsem);
23833 + AuDbgWcntInc(rw);
23836 +static inline void au_rw_init_wlock_nested(struct au_rwsem *rw,
23837 + unsigned int lsc)
23840 + down_write_nested(&rw->rwsem, lsc);
23841 + AuDbgWcntInc(rw);
23844 +static inline void au_rw_read_lock(struct au_rwsem *rw)
23846 + down_read(&rw->rwsem);
23847 + AuDbgRcntInc(rw);
23850 +static inline void au_rw_read_lock_nested(struct au_rwsem *rw, unsigned int lsc)
23852 + down_read_nested(&rw->rwsem, lsc);
23853 + AuDbgRcntInc(rw);
23856 +static inline void au_rw_read_unlock(struct au_rwsem *rw)
23858 + AuRwMustReadLock(rw);
23859 + AuDbgRcntDec(rw);
23860 + up_read(&rw->rwsem);
23863 +static inline void au_rw_dgrade_lock(struct au_rwsem *rw)
23865 + AuRwMustWriteLock(rw);
23866 + AuDbgRcntInc(rw);
23867 + AuDbgWcntDec(rw);
23868 + downgrade_write(&rw->rwsem);
23871 +static inline void au_rw_write_lock(struct au_rwsem *rw)
23873 + down_write(&rw->rwsem);
23874 + AuDbgWcntInc(rw);
23877 +static inline void au_rw_write_lock_nested(struct au_rwsem *rw,
23878 + unsigned int lsc)
23880 + down_write_nested(&rw->rwsem, lsc);
23881 + AuDbgWcntInc(rw);
23884 +static inline void au_rw_write_unlock(struct au_rwsem *rw)
23886 + AuRwMustWriteLock(rw);
23887 + AuDbgWcntDec(rw);
23888 + up_write(&rw->rwsem);
23891 +/* why is not _nested version defined */
23892 +static inline int au_rw_read_trylock(struct au_rwsem *rw)
23894 + int ret = down_read_trylock(&rw->rwsem);
23896 + AuDbgRcntInc(rw);
23900 +static inline int au_rw_write_trylock(struct au_rwsem *rw)
23902 + int ret = down_write_trylock(&rw->rwsem);
23904 + AuDbgWcntInc(rw);
23908 +#undef AuDbgCntInit
23909 +#undef AuDbgRcntInc
23910 +#undef AuDbgRcntDec
23911 +#undef AuDbgWcntInc
23912 +#undef AuDbgWcntDec
23914 +#define AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
23915 +static inline void prefix##_read_lock(param) \
23916 +{ au_rw_read_lock(rwsem); } \
23917 +static inline void prefix##_write_lock(param) \
23918 +{ au_rw_write_lock(rwsem); } \
23919 +static inline int prefix##_read_trylock(param) \
23920 +{ return au_rw_read_trylock(rwsem); } \
23921 +static inline int prefix##_write_trylock(param) \
23922 +{ return au_rw_write_trylock(rwsem); }
23923 +/* why is not _nested version defined */
23924 +/* static inline void prefix##_read_trylock_nested(param, lsc)
23925 +{ au_rw_read_trylock_nested(rwsem, lsc)); }
23926 +static inline void prefix##_write_trylock_nestd(param, lsc)
23927 +{ au_rw_write_trylock_nested(rwsem, lsc); } */
23929 +#define AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) \
23930 +static inline void prefix##_read_unlock(param) \
23931 +{ au_rw_read_unlock(rwsem); } \
23932 +static inline void prefix##_write_unlock(param) \
23933 +{ au_rw_write_unlock(rwsem); } \
23934 +static inline void prefix##_downgrade_lock(param) \
23935 +{ au_rw_dgrade_lock(rwsem); }
23937 +#define AuSimpleRwsemFuncs(prefix, param, rwsem) \
23938 + AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
23939 + AuSimpleUnlockRwsemFuncs(prefix, param, rwsem)
23941 +#endif /* __KERNEL__ */
23942 +#endif /* __AUFS_RWSEM_H__ */
23943 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
23944 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
23945 +++ linux/fs/aufs/sbinfo.c 2014-01-20 20:16:14.742796949 +0100
23948 + * Copyright (C) 2005-2014 Junjiro R. Okajima
23950 + * This program, aufs is free software; you can redistribute it and/or modify
23951 + * it under the terms of the GNU General Public License as published by
23952 + * the Free Software Foundation; either version 2 of the License, or
23953 + * (at your option) any later version.
23955 + * This program is distributed in the hope that it will be useful,
23956 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23957 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23958 + * GNU General Public License for more details.
23960 + * You should have received a copy of the GNU General Public License
23961 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23965 + * superblock private data
23971 + * they are necessary regardless sysfs is disabled.
23973 +void au_si_free(struct kobject *kobj)
23976 + struct au_sbinfo *sbinfo;
23977 + char *locked __maybe_unused; /* debug only */
23979 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
23980 + for (i = 0; i < AuPlink_NHASH; i++)
23981 + AuDebugOn(!hlist_empty(&sbinfo->si_plink[i].head));
23982 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
23984 + au_rw_write_lock(&sbinfo->si_rwsem);
23985 + au_br_free(sbinfo);
23986 + au_rw_write_unlock(&sbinfo->si_rwsem);
23988 + AuDebugOn(radix_tree_gang_lookup
23989 + (&sbinfo->au_si_pid.tree, (void **)&locked,
23990 + /*first_index*/PID_MAX_DEFAULT - 1,
23991 + /*max_items*/sizeof(locked)/sizeof(*locked)));
23993 + kfree(sbinfo->si_branch);
23994 + kfree(sbinfo->au_si_pid.bitmap);
23995 + mutex_destroy(&sbinfo->si_xib_mtx);
23996 + AuRwDestroy(&sbinfo->si_rwsem);
24001 +int au_si_alloc(struct super_block *sb)
24004 + struct au_sbinfo *sbinfo;
24005 + static struct lock_class_key aufs_si;
24008 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
24009 + if (unlikely(!sbinfo))
24012 + BUILD_BUG_ON(sizeof(unsigned long) !=
24013 + sizeof(*sbinfo->au_si_pid.bitmap));
24014 + sbinfo->au_si_pid.bitmap = kcalloc(BITS_TO_LONGS(PID_MAX_DEFAULT),
24015 + sizeof(*sbinfo->au_si_pid.bitmap),
24017 + if (unlikely(!sbinfo->au_si_pid.bitmap))
24020 + /* will be reallocated separately */
24021 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
24022 + if (unlikely(!sbinfo->si_branch))
24025 + err = sysaufs_si_init(sbinfo);
24026 + if (unlikely(err))
24029 + au_nwt_init(&sbinfo->si_nowait);
24030 + au_rw_init_wlock(&sbinfo->si_rwsem);
24031 + au_rw_class(&sbinfo->si_rwsem, &aufs_si);
24032 + spin_lock_init(&sbinfo->au_si_pid.tree_lock);
24033 + INIT_RADIX_TREE(&sbinfo->au_si_pid.tree, GFP_ATOMIC | __GFP_NOFAIL);
24035 + atomic_long_set(&sbinfo->si_ninodes, 0);
24036 + atomic_long_set(&sbinfo->si_nfiles, 0);
24038 + sbinfo->si_bend = -1;
24039 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
24041 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
24042 + sbinfo->si_wbr_create = AuWbrCreate_Def;
24043 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
24044 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
24046 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
24048 + sbinfo->si_xino_jiffy = jiffies;
24049 + sbinfo->si_xino_expire
24050 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
24051 + mutex_init(&sbinfo->si_xib_mtx);
24052 + sbinfo->si_xino_brid = -1;
24053 + /* leave si_xib_last_pindex and si_xib_next_bit */
24055 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
24056 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
24057 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
24058 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
24060 + for (i = 0; i < AuPlink_NHASH; i++)
24061 + au_sphl_init(sbinfo->si_plink + i);
24062 + init_waitqueue_head(&sbinfo->si_plink_wq);
24063 + spin_lock_init(&sbinfo->si_plink_maint_lock);
24065 + au_sphl_init(&sbinfo->si_files);
24067 + /* leave other members for sysaufs and si_mnt. */
24068 + sbinfo->si_sb = sb;
24069 + sb->s_fs_info = sbinfo;
24071 + au_debug_sbinfo_init(sbinfo);
24072 + return 0; /* success */
24075 + kfree(sbinfo->si_branch);
24077 + kfree(sbinfo->au_si_pid.bitmap);
24084 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr)
24087 + struct au_branch **brp;
24089 + AuRwMustWriteLock(&sbinfo->si_rwsem);
24092 + sz = sizeof(*brp) * (sbinfo->si_bend + 1);
24093 + if (unlikely(!sz))
24094 + sz = sizeof(*brp);
24095 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS);
24097 + sbinfo->si_branch = brp;
24104 +/* ---------------------------------------------------------------------- */
24106 +unsigned int au_sigen_inc(struct super_block *sb)
24108 + unsigned int gen;
24110 + SiMustWriteLock(sb);
24112 + gen = ++au_sbi(sb)->si_generation;
24113 + au_update_digen(sb->s_root);
24114 + au_update_iigen(sb->s_root->d_inode, /*half*/0);
24115 + sb->s_root->d_inode->i_version++;
24119 +aufs_bindex_t au_new_br_id(struct super_block *sb)
24121 + aufs_bindex_t br_id;
24123 + struct au_sbinfo *sbinfo;
24125 + SiMustWriteLock(sb);
24127 + sbinfo = au_sbi(sb);
24128 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
24129 + br_id = ++sbinfo->si_last_br_id;
24130 + AuDebugOn(br_id < 0);
24131 + if (br_id && au_br_index(sb, br_id) < 0)
24138 +/* ---------------------------------------------------------------------- */
24140 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
24141 +int si_read_lock(struct super_block *sb, int flags)
24146 + if (au_ftest_lock(flags, FLUSH))
24147 + au_nwt_flush(&au_sbi(sb)->si_nowait);
24149 + si_noflush_read_lock(sb);
24150 + err = au_plink_maint(sb, flags);
24151 + if (unlikely(err))
24152 + si_read_unlock(sb);
24157 +int si_write_lock(struct super_block *sb, int flags)
24161 + if (au_ftest_lock(flags, FLUSH))
24162 + au_nwt_flush(&au_sbi(sb)->si_nowait);
24164 + si_noflush_write_lock(sb);
24165 + err = au_plink_maint(sb, flags);
24166 + if (unlikely(err))
24167 + si_write_unlock(sb);
24172 +/* dentry and super_block lock. call at entry point */
24173 +int aufs_read_lock(struct dentry *dentry, int flags)
24176 + struct super_block *sb;
24178 + sb = dentry->d_sb;
24179 + err = si_read_lock(sb, flags);
24180 + if (unlikely(err))
24183 + if (au_ftest_lock(flags, DW))
24184 + di_write_lock_child(dentry);
24186 + di_read_lock_child(dentry, flags);
24188 + if (au_ftest_lock(flags, GEN)) {
24189 + err = au_digen_test(dentry, au_sigen(sb));
24190 + AuDebugOn(!err && au_dbrange_test(dentry));
24191 + if (unlikely(err))
24192 + aufs_read_unlock(dentry, flags);
24199 +void aufs_read_unlock(struct dentry *dentry, int flags)
24201 + if (au_ftest_lock(flags, DW))
24202 + di_write_unlock(dentry);
24204 + di_read_unlock(dentry, flags);
24205 + si_read_unlock(dentry->d_sb);
24208 +void aufs_write_lock(struct dentry *dentry)
24210 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
24211 + di_write_lock_child(dentry);
24214 +void aufs_write_unlock(struct dentry *dentry)
24216 + di_write_unlock(dentry);
24217 + si_write_unlock(dentry->d_sb);
24220 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
24223 + unsigned int sigen;
24224 + struct super_block *sb;
24227 + err = si_read_lock(sb, flags);
24228 + if (unlikely(err))
24231 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIR));
24233 + if (au_ftest_lock(flags, GEN)) {
24234 + sigen = au_sigen(sb);
24235 + err = au_digen_test(d1, sigen);
24236 + AuDebugOn(!err && au_dbrange_test(d1));
24238 + err = au_digen_test(d2, sigen);
24239 + AuDebugOn(!err && au_dbrange_test(d2));
24241 + if (unlikely(err))
24242 + aufs_read_and_write_unlock2(d1, d2);
24249 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
24251 + di_write_unlock2(d1, d2);
24252 + si_read_unlock(d1->d_sb);
24255 +/* ---------------------------------------------------------------------- */
24257 +int si_pid_test_slow(struct super_block *sb)
24262 + p = radix_tree_lookup(&au_sbi(sb)->au_si_pid.tree, current->pid);
24263 + rcu_read_unlock();
24265 + return (long)!!p;
24268 +void si_pid_set_slow(struct super_block *sb)
24271 + struct au_sbinfo *sbinfo;
24273 + AuDebugOn(si_pid_test_slow(sb));
24275 + sbinfo = au_sbi(sb);
24276 + err = radix_tree_preload(GFP_NOFS | __GFP_NOFAIL);
24278 + spin_lock(&sbinfo->au_si_pid.tree_lock);
24279 + err = radix_tree_insert(&sbinfo->au_si_pid.tree, current->pid,
24280 + /*any valid ptr*/sb);
24281 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
24283 + radix_tree_preload_end();
24286 +void si_pid_clr_slow(struct super_block *sb)
24289 + struct au_sbinfo *sbinfo;
24291 + AuDebugOn(!si_pid_test_slow(sb));
24293 + sbinfo = au_sbi(sb);
24294 + spin_lock(&sbinfo->au_si_pid.tree_lock);
24295 + p = radix_tree_delete(&sbinfo->au_si_pid.tree, current->pid);
24296 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
24298 diff -urN /usr/share/empty/fs/aufs/spl.h linux/fs/aufs/spl.h
24299 --- /usr/share/empty/fs/aufs/spl.h 1970-01-01 01:00:00.000000000 +0100
24300 +++ linux/fs/aufs/spl.h 2014-01-20 20:16:14.742796949 +0100
24303 + * Copyright (C) 2005-2014 Junjiro R. Okajima
24305 + * This program, aufs is free software; you can redistribute it and/or modify
24306 + * it under the terms of the GNU General Public License as published by
24307 + * the Free Software Foundation; either version 2 of the License, or
24308 + * (at your option) any later version.
24310 + * This program is distributed in the hope that it will be useful,
24311 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24312 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24313 + * GNU General Public License for more details.
24315 + * You should have received a copy of the GNU General Public License
24316 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24320 + * simple list protected by a spinlock
24323 +#ifndef __AUFS_SPL_H__
24324 +#define __AUFS_SPL_H__
24328 +struct au_splhead {
24330 + struct list_head head;
24333 +static inline void au_spl_init(struct au_splhead *spl)
24335 + spin_lock_init(&spl->spin);
24336 + INIT_LIST_HEAD(&spl->head);
24339 +static inline void au_spl_add(struct list_head *list, struct au_splhead *spl)
24341 + spin_lock(&spl->spin);
24342 + list_add(list, &spl->head);
24343 + spin_unlock(&spl->spin);
24346 +static inline void au_spl_del(struct list_head *list, struct au_splhead *spl)
24348 + spin_lock(&spl->spin);
24350 + spin_unlock(&spl->spin);
24353 +static inline void au_spl_del_rcu(struct list_head *list,
24354 + struct au_splhead *spl)
24356 + spin_lock(&spl->spin);
24357 + list_del_rcu(list);
24358 + spin_unlock(&spl->spin);
24361 +/* ---------------------------------------------------------------------- */
24363 +struct au_sphlhead {
24365 + struct hlist_head head;
24368 +static inline void au_sphl_init(struct au_sphlhead *sphl)
24370 + spin_lock_init(&sphl->spin);
24371 + INIT_HLIST_HEAD(&sphl->head);
24374 +static inline void au_sphl_add(struct hlist_node *hlist,
24375 + struct au_sphlhead *sphl)
24377 + spin_lock(&sphl->spin);
24378 + hlist_add_head(hlist, &sphl->head);
24379 + spin_unlock(&sphl->spin);
24382 +static inline void au_sphl_del(struct hlist_node *hlist,
24383 + struct au_sphlhead *sphl)
24385 + spin_lock(&sphl->spin);
24386 + hlist_del(hlist);
24387 + spin_unlock(&sphl->spin);
24390 +static inline void au_sphl_del_rcu(struct hlist_node *hlist,
24391 + struct au_sphlhead *sphl)
24393 + spin_lock(&sphl->spin);
24394 + hlist_del_rcu(hlist);
24395 + spin_unlock(&sphl->spin);
24398 +static inline unsigned long au_sphl_count(struct au_sphlhead *sphl)
24400 + unsigned long cnt;
24401 + struct hlist_node *pos;
24404 + spin_lock(&sphl->spin);
24405 + hlist_for_each(pos, &sphl->head)
24407 + spin_unlock(&sphl->spin);
24411 +#endif /* __KERNEL__ */
24412 +#endif /* __AUFS_SPL_H__ */
24413 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
24414 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
24415 +++ linux/fs/aufs/super.c 2014-01-20 20:16:14.742796949 +0100
24418 + * Copyright (C) 2005-2014 Junjiro R. Okajima
24420 + * This program, aufs is free software; you can redistribute it and/or modify
24421 + * it under the terms of the GNU General Public License as published by
24422 + * the Free Software Foundation; either version 2 of the License, or
24423 + * (at your option) any later version.
24425 + * This program is distributed in the hope that it will be useful,
24426 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24427 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24428 + * GNU General Public License for more details.
24430 + * You should have received a copy of the GNU General Public License
24431 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24435 + * mount and super_block operations
24438 +#include <linux/mm.h>
24439 +#include <linux/module.h>
24440 +#include <linux/seq_file.h>
24441 +#include <linux/statfs.h>
24442 +#include <linux/vmalloc.h>
24443 +#include <linux/writeback.h>
24447 + * super_operations
24449 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
24451 + struct au_icntnr *c;
24453 + c = au_cache_alloc_icntnr();
24455 + au_icntnr_init(c);
24456 + c->vfs_inode.i_version = 1; /* sigen(sb); */
24457 + c->iinfo.ii_hinode = NULL;
24458 + return &c->vfs_inode;
24463 +static void aufs_destroy_inode_cb(struct rcu_head *head)
24465 + struct inode *inode = container_of(head, struct inode, i_rcu);
24467 + INIT_HLIST_HEAD(&inode->i_dentry);
24468 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
24471 +static void aufs_destroy_inode(struct inode *inode)
24473 + au_iinfo_fin(inode);
24474 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
24477 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
24479 + struct inode *inode;
24482 + inode = iget_locked(sb, ino);
24483 + if (unlikely(!inode)) {
24484 + inode = ERR_PTR(-ENOMEM);
24487 + if (!(inode->i_state & I_NEW))
24490 + err = au_xigen_new(inode);
24492 + err = au_iinfo_init(inode);
24494 + inode->i_version++;
24496 + iget_failed(inode);
24497 + inode = ERR_PTR(err);
24501 + /* never return NULL */
24502 + AuDebugOn(!inode);
24503 + AuTraceErrPtr(inode);
24507 +/* lock free root dinfo */
24508 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
24511 + aufs_bindex_t bindex, bend;
24512 + struct path path;
24513 + struct au_hdentry *hdp;
24514 + struct au_branch *br;
24518 + bend = au_sbend(sb);
24519 + hdp = au_di(sb->s_root)->di_hdentry;
24520 + for (bindex = 0; !err && bindex <= bend; bindex++) {
24521 + br = au_sbr(sb, bindex);
24522 + path.mnt = au_br_mnt(br);
24523 + path.dentry = hdp[bindex].hd_dentry;
24524 + err = au_seq_path(seq, &path);
24526 + perm = au_optstr_br_perm(br->br_perm);
24528 + err = seq_printf(seq, "=%s", perm);
24535 + if (!err && bindex != bend)
24536 + err = seq_putc(seq, ':');
24542 +static void au_show_wbr_create(struct seq_file *m, int v,
24543 + struct au_sbinfo *sbinfo)
24547 + AuRwMustAnyLock(&sbinfo->si_rwsem);
24549 + seq_puts(m, ",create=");
24550 + pat = au_optstr_wbr_create(v);
24552 + case AuWbrCreate_TDP:
24553 + case AuWbrCreate_RR:
24554 + case AuWbrCreate_MFS:
24555 + case AuWbrCreate_PMFS:
24556 + seq_puts(m, pat);
24558 + case AuWbrCreate_MFSV:
24559 + seq_printf(m, /*pat*/"mfs:%lu",
24560 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
24563 + case AuWbrCreate_PMFSV:
24564 + seq_printf(m, /*pat*/"pmfs:%lu",
24565 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
24568 + case AuWbrCreate_MFSRR:
24569 + seq_printf(m, /*pat*/"mfsrr:%llu",
24570 + sbinfo->si_wbr_mfs.mfsrr_watermark);
24572 + case AuWbrCreate_MFSRRV:
24573 + seq_printf(m, /*pat*/"mfsrr:%llu:%lu",
24574 + sbinfo->si_wbr_mfs.mfsrr_watermark,
24575 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
24578 + case AuWbrCreate_PMFSRR:
24579 + seq_printf(m, /*pat*/"pmfsrr:%llu",
24580 + sbinfo->si_wbr_mfs.mfsrr_watermark);
24582 + case AuWbrCreate_PMFSRRV:
24583 + seq_printf(m, /*pat*/"pmfsrr:%llu:%lu",
24584 + sbinfo->si_wbr_mfs.mfsrr_watermark,
24585 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
24591 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
24593 +#ifdef CONFIG_SYSFS
24597 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
24598 + aufs_bindex_t bindex, brid;
24599 + struct qstr *name;
24601 + struct dentry *d, *h_root;
24602 + struct au_hdentry *hdp;
24604 + AuRwMustAnyLock(&sbinfo->si_rwsem);
24607 + f = au_sbi(sb)->si_xib;
24611 + /* stop printing the default xino path on the first writable branch */
24613 + brid = au_xino_brid(sb);
24615 + bindex = au_br_index(sb, brid);
24616 + hdp = au_di(sb->s_root)->di_hdentry;
24617 + h_root = hdp[0 + bindex].hd_dentry;
24620 + name = &d->d_name;
24621 + /* safe ->d_parent because the file is unlinked */
24622 + if (d->d_parent == h_root
24623 + && name->len == len
24624 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
24627 + seq_puts(seq, ",xino=");
24628 + err = au_xino_path(seq, f);
24635 +/* seq_file will re-call me in case of too long string */
24636 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
24639 + unsigned int mnt_flags, v;
24640 + struct super_block *sb;
24641 + struct au_sbinfo *sbinfo;
24643 +#define AuBool(name, str) do { \
24644 + v = au_opt_test(mnt_flags, name); \
24645 + if (v != au_opt_test(AuOpt_Def, name)) \
24646 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
24649 +#define AuStr(name, str) do { \
24650 + v = mnt_flags & AuOptMask_##name; \
24651 + if (v != (AuOpt_Def & AuOptMask_##name)) \
24652 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
24655 +#define AuUInt(name, str, val) do { \
24656 + if (val != AUFS_##name##_DEF) \
24657 + seq_printf(m, "," #str "=%u", val); \
24660 + /* lock free root dinfo */
24661 + sb = dentry->d_sb;
24662 + si_noflush_read_lock(sb);
24663 + sbinfo = au_sbi(sb);
24664 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
24666 + mnt_flags = au_mntflags(sb);
24667 + if (au_opt_test(mnt_flags, XINO)) {
24668 + err = au_show_xino(m, sb);
24669 + if (unlikely(err))
24672 + seq_puts(m, ",noxino");
24674 + AuBool(TRUNC_XINO, trunc_xino);
24675 + AuStr(UDBA, udba);
24676 + AuBool(SHWH, shwh);
24677 + AuBool(PLINK, plink);
24678 + AuBool(DIO, dio);
24679 + /* AuBool(DIRPERM1, dirperm1); */
24680 + /* AuBool(REFROF, refrof); */
24682 + v = sbinfo->si_wbr_create;
24683 + if (v != AuWbrCreate_Def)
24684 + au_show_wbr_create(m, v, sbinfo);
24686 + v = sbinfo->si_wbr_copyup;
24687 + if (v != AuWbrCopyup_Def)
24688 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
24690 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
24691 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
24692 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
24694 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
24696 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
24697 + AuUInt(RDCACHE, rdcache, v);
24699 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
24700 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
24702 + AuBool(SUM, sum);
24703 + /* AuBool(SUM_W, wsum); */
24704 + AuBool(WARN_PERM, warn_perm);
24705 + AuBool(VERBOSE, verbose);
24708 + /* be sure to print "br:" last */
24709 + if (!sysaufs_brs) {
24710 + seq_puts(m, ",br:");
24711 + au_show_brs(m, sb);
24713 + si_read_unlock(sb);
24721 +/* ---------------------------------------------------------------------- */
24723 +/* sum mode which returns the summation for statfs(2) */
24725 +static u64 au_add_till_max(u64 a, u64 b)
24733 + return ULLONG_MAX;
24736 +static u64 au_mul_till_max(u64 a, long mul)
24744 + return ULLONG_MAX;
24747 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
24750 + long bsize, factor;
24751 + u64 blocks, bfree, bavail, files, ffree;
24752 + aufs_bindex_t bend, bindex, i;
24753 + unsigned char shared;
24754 + struct path h_path;
24755 + struct super_block *h_sb;
24758 + bsize = LONG_MAX;
24764 + bend = au_sbend(sb);
24765 + for (bindex = 0; bindex <= bend; bindex++) {
24766 + h_path.mnt = au_sbr_mnt(sb, bindex);
24767 + h_sb = h_path.mnt->mnt_sb;
24769 + for (i = 0; !shared && i < bindex; i++)
24770 + shared = (au_sbr_sb(sb, i) == h_sb);
24774 + /* sb->s_root for NFS is unreliable */
24775 + h_path.dentry = h_path.mnt->mnt_root;
24776 + err = vfs_statfs(&h_path, buf);
24777 + if (unlikely(err))
24780 + if (bsize > buf->f_bsize) {
24782 + * we will reduce bsize, so we have to expand blocks
24783 + * etc. to match them again
24785 + factor = (bsize / buf->f_bsize);
24786 + blocks = au_mul_till_max(blocks, factor);
24787 + bfree = au_mul_till_max(bfree, factor);
24788 + bavail = au_mul_till_max(bavail, factor);
24789 + bsize = buf->f_bsize;
24792 + factor = (buf->f_bsize / bsize);
24793 + blocks = au_add_till_max(blocks,
24794 + au_mul_till_max(buf->f_blocks, factor));
24795 + bfree = au_add_till_max(bfree,
24796 + au_mul_till_max(buf->f_bfree, factor));
24797 + bavail = au_add_till_max(bavail,
24798 + au_mul_till_max(buf->f_bavail, factor));
24799 + files = au_add_till_max(files, buf->f_files);
24800 + ffree = au_add_till_max(ffree, buf->f_ffree);
24803 + buf->f_bsize = bsize;
24804 + buf->f_blocks = blocks;
24805 + buf->f_bfree = bfree;
24806 + buf->f_bavail = bavail;
24807 + buf->f_files = files;
24808 + buf->f_ffree = ffree;
24809 + buf->f_frsize = 0;
24815 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
24818 + struct path h_path;
24819 + struct super_block *sb;
24821 + /* lock free root dinfo */
24822 + sb = dentry->d_sb;
24823 + si_noflush_read_lock(sb);
24824 + if (!au_opt_test(au_mntflags(sb), SUM)) {
24825 + /* sb->s_root for NFS is unreliable */
24826 + h_path.mnt = au_sbr_mnt(sb, 0);
24827 + h_path.dentry = h_path.mnt->mnt_root;
24828 + err = vfs_statfs(&h_path, buf);
24830 + err = au_statfs_sum(sb, buf);
24831 + si_read_unlock(sb);
24834 + buf->f_type = AUFS_SUPER_MAGIC;
24835 + buf->f_namelen = AUFS_MAX_NAMELEN;
24836 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
24838 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
24843 +/* ---------------------------------------------------------------------- */
24845 +static int aufs_sync_fs(struct super_block *sb, int wait)
24848 + aufs_bindex_t bend, bindex;
24849 + struct au_branch *br;
24850 + struct super_block *h_sb;
24853 + si_noflush_read_lock(sb);
24854 + bend = au_sbend(sb);
24855 + for (bindex = 0; bindex <= bend; bindex++) {
24856 + br = au_sbr(sb, bindex);
24857 + if (!au_br_writable(br->br_perm))
24860 + h_sb = au_sbr_sb(sb, bindex);
24861 + if (h_sb->s_op->sync_fs) {
24862 + e = h_sb->s_op->sync_fs(h_sb, wait);
24863 + if (unlikely(e && !err))
24865 + /* go on even if an error happens */
24868 + si_read_unlock(sb);
24873 +/* ---------------------------------------------------------------------- */
24875 +/* final actions when unmounting a file system */
24876 +static void aufs_put_super(struct super_block *sb)
24878 + struct au_sbinfo *sbinfo;
24880 + sbinfo = au_sbi(sb);
24884 + dbgaufs_si_fin(sbinfo);
24885 + kobject_put(&sbinfo->si_kobj);
24888 +/* ---------------------------------------------------------------------- */
24890 +void au_array_free(void *array)
24893 + if (!is_vmalloc_addr(array))
24900 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg)
24903 + unsigned long long n;
24910 + if (*hint > ULLONG_MAX / sizeof(array)) {
24911 + array = ERR_PTR(-EMFILE);
24912 + pr_err("hint %llu\n", *hint);
24916 + array = kmalloc(sizeof(array) * *hint, GFP_NOFS);
24917 + if (unlikely(!array))
24918 + array = vmalloc(sizeof(array) * *hint);
24919 + if (unlikely(!array)) {
24920 + array = ERR_PTR(-ENOMEM);
24924 + n = cb(array, *hint, arg);
24925 + AuDebugOn(n > *hint);
24932 +static unsigned long long au_iarray_cb(void *a,
24933 + unsigned long long max __maybe_unused,
24936 + unsigned long long n;
24937 + struct inode **p, *inode;
24938 + struct list_head *head;
24943 + spin_lock(&inode_sb_list_lock);
24944 + list_for_each_entry(inode, head, i_sb_list) {
24945 + if (!is_bad_inode(inode)
24946 + && au_ii(inode)->ii_bstart >= 0) {
24947 + spin_lock(&inode->i_lock);
24948 + if (atomic_read(&inode->i_count)) {
24952 + AuDebugOn(n > max);
24954 + spin_unlock(&inode->i_lock);
24957 + spin_unlock(&inode_sb_list_lock);
24962 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
24964 + *max = atomic_long_read(&au_sbi(sb)->si_ninodes);
24965 + return au_array_alloc(max, au_iarray_cb, &sb->s_inodes);
24968 +void au_iarray_free(struct inode **a, unsigned long long max)
24970 + unsigned long long ull;
24972 + for (ull = 0; ull < max; ull++)
24974 + au_array_free(a);
24977 +/* ---------------------------------------------------------------------- */
24980 + * refresh dentry and inode at remount time.
24982 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
24983 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
24984 + struct dentry *parent)
24988 + di_write_lock_child(dentry);
24989 + di_read_lock_parent(parent, AuLock_IR);
24990 + err = au_refresh_dentry(dentry, parent);
24991 + if (!err && dir_flags)
24992 + au_hn_reset(dentry->d_inode, dir_flags);
24993 + di_read_unlock(parent, AuLock_IR);
24994 + di_write_unlock(dentry);
24999 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
25000 + struct au_sbinfo *sbinfo,
25001 + const unsigned int dir_flags)
25004 + struct dentry *parent;
25005 + struct inode *inode;
25008 + parent = dget_parent(dentry);
25009 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
25010 + inode = dentry->d_inode;
25012 + if (!S_ISDIR(inode->i_mode))
25013 + err = au_do_refresh(dentry, /*dir_flags*/0,
25016 + err = au_do_refresh(dentry, dir_flags, parent);
25017 + if (unlikely(err))
25018 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
25021 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
25022 + AuDbgDentry(dentry);
25030 +static int au_refresh_d(struct super_block *sb)
25032 + int err, i, j, ndentry, e;
25033 + unsigned int sigen;
25034 + struct au_dcsub_pages dpages;
25035 + struct au_dpage *dpage;
25036 + struct dentry **dentries, *d;
25037 + struct au_sbinfo *sbinfo;
25038 + struct dentry *root = sb->s_root;
25039 + const unsigned int dir_flags = au_hi_flags(root->d_inode, /*isdir*/1);
25041 + err = au_dpages_init(&dpages, GFP_NOFS);
25042 + if (unlikely(err))
25044 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
25045 + if (unlikely(err))
25048 + sigen = au_sigen(sb);
25049 + sbinfo = au_sbi(sb);
25050 + for (i = 0; i < dpages.ndpage; i++) {
25051 + dpage = dpages.dpages + i;
25052 + dentries = dpage->dentries;
25053 + ndentry = dpage->ndentry;
25054 + for (j = 0; j < ndentry; j++) {
25056 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags);
25057 + if (unlikely(e && !err))
25059 + /* go on even err */
25064 + au_dpages_free(&dpages);
25069 +static int au_refresh_i(struct super_block *sb)
25072 + unsigned int sigen;
25073 + unsigned long long max, ull;
25074 + struct inode *inode, **array;
25076 + array = au_iarray_alloc(sb, &max);
25077 + err = PTR_ERR(array);
25078 + if (IS_ERR(array))
25082 + sigen = au_sigen(sb);
25083 + for (ull = 0; ull < max; ull++) {
25084 + inode = array[ull];
25085 + if (au_iigen(inode, NULL) != sigen) {
25086 + ii_write_lock_child(inode);
25087 + e = au_refresh_hinode_self(inode);
25088 + ii_write_unlock(inode);
25089 + if (unlikely(e)) {
25090 + pr_err("error %d, i%lu\n", e, inode->i_ino);
25093 + /* go on even if err */
25098 + au_iarray_free(array, max);
25104 +static void au_remount_refresh(struct super_block *sb)
25107 + unsigned int udba;
25108 + aufs_bindex_t bindex, bend;
25109 + struct dentry *root;
25110 + struct inode *inode;
25111 + struct au_branch *br;
25113 + au_sigen_inc(sb);
25114 + au_fclr_si(au_sbi(sb), FAILED_REFRESH_DIR);
25116 + root = sb->s_root;
25117 + DiMustNoWaiters(root);
25118 + inode = root->d_inode;
25119 + IiMustNoWaiters(inode);
25121 + udba = au_opt_udba(sb);
25122 + bend = au_sbend(sb);
25123 + for (bindex = 0; bindex <= bend; bindex++) {
25124 + br = au_sbr(sb, bindex);
25125 + err = au_hnotify_reset_br(udba, br, br->br_perm);
25126 + if (unlikely(err))
25127 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
25129 + /* go on even if err */
25131 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
25133 + di_write_unlock(root);
25134 + err = au_refresh_d(sb);
25135 + e = au_refresh_i(sb);
25136 + if (unlikely(e && !err))
25138 + /* aufs_write_lock() calls ..._child() */
25139 + di_write_lock_child(root);
25141 + au_cpup_attr_all(inode, /*force*/1);
25143 + if (unlikely(err))
25144 + AuIOErr("refresh failed, ignored, %d\n", err);
25147 +/* stop extra interpretation of errno in mount(8), and strange error messages */
25148 +static int cvt_err(int err)
25162 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
25165 + unsigned int mntflags;
25166 + struct au_opts opts;
25167 + struct dentry *root;
25168 + struct inode *inode;
25169 + struct au_sbinfo *sbinfo;
25172 + root = sb->s_root;
25173 + if (!data || !*data) {
25174 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
25176 + di_write_lock_child(root);
25177 + err = au_opts_verify(sb, *flags, /*pending*/0);
25178 + aufs_write_unlock(root);
25184 + memset(&opts, 0, sizeof(opts));
25185 + opts.opt = (void *)__get_free_page(GFP_NOFS);
25186 + if (unlikely(!opts.opt))
25188 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
25189 + opts.flags = AuOpts_REMOUNT;
25190 + opts.sb_flags = *flags;
25192 + /* parse it before aufs lock */
25193 + err = au_opts_parse(sb, data, &opts);
25194 + if (unlikely(err))
25197 + sbinfo = au_sbi(sb);
25198 + inode = root->d_inode;
25199 + mutex_lock(&inode->i_mutex);
25200 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
25201 + if (unlikely(err))
25203 + di_write_lock_child(root);
25205 + /* au_opts_remount() may return an error */
25206 + err = au_opts_remount(sb, &opts);
25207 + au_opts_free(&opts);
25209 + if (au_ftest_opts(opts.flags, REFRESH))
25210 + au_remount_refresh(sb);
25212 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
25213 + mntflags = au_mntflags(sb);
25214 + do_dx = !!au_opt_test(mntflags, DIO);
25215 + au_dy_arefresh(do_dx);
25218 + aufs_write_unlock(root);
25221 + mutex_unlock(&inode->i_mutex);
25223 + free_page((unsigned long)opts.opt);
25225 + err = cvt_err(err);
25230 +static const struct super_operations aufs_sop = {
25231 + .alloc_inode = aufs_alloc_inode,
25232 + .destroy_inode = aufs_destroy_inode,
25233 + /* always deleting, no clearing */
25234 + .drop_inode = generic_delete_inode,
25235 + .show_options = aufs_show_options,
25236 + .statfs = aufs_statfs,
25237 + .put_super = aufs_put_super,
25238 + .sync_fs = aufs_sync_fs,
25239 + .remount_fs = aufs_remount_fs
25242 +/* ---------------------------------------------------------------------- */
25244 +static int alloc_root(struct super_block *sb)
25247 + struct inode *inode;
25248 + struct dentry *root;
25251 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
25252 + err = PTR_ERR(inode);
25253 + if (IS_ERR(inode))
25256 + inode->i_op = &aufs_dir_iop;
25257 + inode->i_fop = &aufs_dir_fop;
25258 + inode->i_mode = S_IFDIR;
25259 + set_nlink(inode, 2);
25260 + unlock_new_inode(inode);
25262 + root = d_make_root(inode);
25263 + if (unlikely(!root))
25265 + err = PTR_ERR(root);
25266 + if (IS_ERR(root))
25269 + err = au_di_init(root);
25271 + sb->s_root = root;
25272 + return 0; /* success */
25280 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
25281 + int silent __maybe_unused)
25284 + struct au_opts opts;
25285 + struct dentry *root;
25286 + struct inode *inode;
25287 + char *arg = raw_data;
25289 + if (unlikely(!arg || !*arg)) {
25291 + pr_err("no arg\n");
25296 + memset(&opts, 0, sizeof(opts));
25297 + opts.opt = (void *)__get_free_page(GFP_NOFS);
25298 + if (unlikely(!opts.opt))
25300 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
25301 + opts.sb_flags = sb->s_flags;
25303 + err = au_si_alloc(sb);
25304 + if (unlikely(err))
25307 + /* all timestamps always follow the ones on the branch */
25308 + sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
25309 + sb->s_op = &aufs_sop;
25310 + sb->s_d_op = &aufs_dop;
25311 + sb->s_magic = AUFS_SUPER_MAGIC;
25312 + sb->s_maxbytes = 0;
25313 + au_export_init(sb);
25315 + err = alloc_root(sb);
25316 + if (unlikely(err)) {
25317 + si_write_unlock(sb);
25320 + root = sb->s_root;
25321 + inode = root->d_inode;
25324 + * actually we can parse options regardless aufs lock here.
25325 + * but at remount time, parsing must be done before aufs lock.
25326 + * so we follow the same rule.
25328 + ii_write_lock_parent(inode);
25329 + aufs_write_unlock(root);
25330 + err = au_opts_parse(sb, arg, &opts);
25331 + if (unlikely(err))
25334 + /* lock vfs_inode first, then aufs. */
25335 + mutex_lock(&inode->i_mutex);
25336 + aufs_write_lock(root);
25337 + err = au_opts_mount(sb, &opts);
25338 + au_opts_free(&opts);
25339 + aufs_write_unlock(root);
25340 + mutex_unlock(&inode->i_mutex);
25342 + goto out_opts; /* success */
25346 + sb->s_root = NULL;
25348 + dbgaufs_si_fin(au_sbi(sb));
25349 + kobject_put(&au_sbi(sb)->si_kobj);
25350 + sb->s_fs_info = NULL;
25352 + free_page((unsigned long)opts.opt);
25355 + err = cvt_err(err);
25360 +/* ---------------------------------------------------------------------- */
25362 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
25363 + const char *dev_name __maybe_unused,
25366 + struct dentry *root;
25367 + struct super_block *sb;
25369 + /* all timestamps always follow the ones on the branch */
25370 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
25371 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
25372 + if (IS_ERR(root))
25376 + si_write_lock(sb, !AuLock_FLUSH);
25377 + sysaufs_brs_add(sb, 0);
25378 + si_write_unlock(sb);
25379 + au_sbilist_add(sb);
25385 +static void aufs_kill_sb(struct super_block *sb)
25387 + struct au_sbinfo *sbinfo;
25389 + sbinfo = au_sbi(sb);
25391 + au_sbilist_del(sb);
25392 + aufs_write_lock(sb->s_root);
25393 + if (sbinfo->si_wbr_create_ops->fin)
25394 + sbinfo->si_wbr_create_ops->fin(sb);
25395 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
25396 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
25397 + au_remount_refresh(sb);
25399 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
25400 + au_plink_put(sb, /*verbose*/1);
25402 + sbinfo->si_sb = NULL;
25403 + aufs_write_unlock(sb->s_root);
25404 + au_nwt_flush(&sbinfo->si_nowait);
25406 + generic_shutdown_super(sb);
25409 +struct file_system_type aufs_fs_type = {
25410 + .name = AUFS_FSTYPE,
25411 + /* a race between rename and others */
25412 + .fs_flags = FS_RENAME_DOES_D_MOVE,
25413 + .mount = aufs_mount,
25414 + .kill_sb = aufs_kill_sb,
25415 + /* no need to __module_get() and module_put(). */
25416 + .owner = THIS_MODULE,
25418 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
25419 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
25420 +++ linux/fs/aufs/super.h 2014-01-20 20:16:14.742796949 +0100
25423 + * Copyright (C) 2005-2014 Junjiro R. Okajima
25425 + * This program, aufs is free software; you can redistribute it and/or modify
25426 + * it under the terms of the GNU General Public License as published by
25427 + * the Free Software Foundation; either version 2 of the License, or
25428 + * (at your option) any later version.
25430 + * This program is distributed in the hope that it will be useful,
25431 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25432 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25433 + * GNU General Public License for more details.
25435 + * You should have received a copy of the GNU General Public License
25436 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25440 + * super_block operations
25443 +#ifndef __AUFS_SUPER_H__
25444 +#define __AUFS_SUPER_H__
25448 +#include <linux/fs.h>
25449 +#include "rwsem.h"
25453 +typedef ssize_t (*au_readf_t)(struct file *, char __user *, size_t, loff_t *);
25454 +typedef ssize_t (*au_writef_t)(struct file *, const char __user *, size_t,
25457 +/* policies to select one among multiple writable branches */
25458 +struct au_wbr_copyup_operations {
25459 + int (*copyup)(struct dentry *dentry);
25462 +#define AuWbr_DIR 1 /* target is a dir */
25463 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
25465 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
25466 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
25467 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
25469 +struct au_wbr_create_operations {
25470 + int (*create)(struct dentry *dentry, unsigned int flags);
25471 + int (*init)(struct super_block *sb);
25472 + int (*fin)(struct super_block *sb);
25475 +struct au_wbr_mfs {
25476 + struct mutex mfs_lock; /* protect this structure */
25477 + unsigned long mfs_jiffy;
25478 + unsigned long mfs_expire;
25479 + aufs_bindex_t mfs_bindex;
25481 + unsigned long long mfsrr_bytes;
25482 + unsigned long long mfsrr_watermark;
25485 +struct pseudo_link {
25487 + struct hlist_node hlist;
25488 + struct rcu_head rcu;
25490 + struct inode *inode;
25493 +#define AuPlink_NHASH 100
25494 +static inline int au_plink_hash(ino_t ino)
25496 + return ino % AuPlink_NHASH;
25500 +struct au_sbinfo {
25501 + /* nowait tasks in the system-wide workqueue */
25502 + struct au_nowait_tasks si_nowait;
25505 + * tried sb->s_umount, but failed due to the dependecy between i_mutex.
25506 + * rwsem for au_sbinfo is necessary.
25508 + struct au_rwsem si_rwsem;
25510 + /* prevent recursive locking in deleting inode */
25512 + unsigned long *bitmap;
25513 + spinlock_t tree_lock;
25514 + struct radix_tree_root tree;
25518 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
25521 + atomic_long_t si_ninodes, si_nfiles;
25523 + /* branch management */
25524 + unsigned int si_generation;
25526 + /* see above flags */
25527 + unsigned char au_si_status;
25529 + aufs_bindex_t si_bend;
25531 + /* dirty trick to keep br_id plus */
25532 + unsigned int si_last_br_id :
25533 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
25534 + struct au_branch **si_branch;
25536 + /* policy to select a writable branch */
25537 + unsigned char si_wbr_copyup;
25538 + unsigned char si_wbr_create;
25539 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
25540 + struct au_wbr_create_operations *si_wbr_create_ops;
25542 + /* round robin */
25543 + atomic_t si_wbr_rr_next;
25545 + /* most free space */
25546 + struct au_wbr_mfs si_wbr_mfs;
25548 + /* mount flags */
25549 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
25550 + unsigned int si_mntflags;
25552 + /* external inode number (bitmap and translation table) */
25553 + au_readf_t si_xread;
25554 + au_writef_t si_xwrite;
25555 + struct file *si_xib;
25556 + struct mutex si_xib_mtx; /* protect xib members */
25557 + unsigned long *si_xib_buf;
25558 + unsigned long si_xib_last_pindex;
25559 + int si_xib_next_bit;
25560 + aufs_bindex_t si_xino_brid;
25561 + unsigned long si_xino_jiffy;
25562 + unsigned long si_xino_expire;
25563 + /* reserved for future use */
25564 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
25566 +#ifdef CONFIG_AUFS_EXPORT
25567 + /* i_generation */
25568 + struct file *si_xigen;
25569 + atomic_t si_xigen_next;
25572 + /* vdir parameters */
25573 + unsigned long si_rdcache; /* max cache time in jiffies */
25574 + unsigned int si_rdblk; /* deblk size */
25575 + unsigned int si_rdhash; /* hash size */
25578 + * If the number of whiteouts are larger than si_dirwh, leave all of
25579 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
25580 + * future fsck.aufs or kernel thread will remove them later.
25581 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
25583 + unsigned int si_dirwh;
25586 + * rename(2) a directory with all children.
25588 + /* reserved for future use */
25589 + /* int si_rendir; */
25591 + /* pseudo_link list */
25592 + struct au_sphlhead si_plink[AuPlink_NHASH];
25593 + wait_queue_head_t si_plink_wq;
25594 + spinlock_t si_plink_maint_lock;
25595 + pid_t si_plink_maint_pid;
25598 + struct au_sphlhead si_files;
25601 + * sysfs and lifetime management.
25602 + * this is not a small structure and it may be a waste of memory in case
25603 + * of sysfs is disabled, particulary when many aufs-es are mounted.
25604 + * but using sysfs is majority.
25606 + struct kobject si_kobj;
25607 +#ifdef CONFIG_DEBUG_FS
25608 + struct dentry *si_dbgaufs;
25609 + struct dentry *si_dbgaufs_plink;
25610 + struct dentry *si_dbgaufs_xib;
25611 +#ifdef CONFIG_AUFS_EXPORT
25612 + struct dentry *si_dbgaufs_xigen;
25616 +#ifdef CONFIG_AUFS_SBILIST
25617 + struct list_head si_list;
25620 + /* dirty, necessary for unmounting, sysfs and sysrq */
25621 + struct super_block *si_sb;
25624 +/* sbinfo status flags */
25626 + * set true when refresh_dirs() failed at remount time.
25627 + * then try refreshing dirs at access time again.
25628 + * if it is false, refreshing dirs at access time is unnecesary
25630 +#define AuSi_FAILED_REFRESH_DIR 1
25631 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
25632 + unsigned int flag)
25634 + AuRwMustAnyLock(&sbi->si_rwsem);
25635 + return sbi->au_si_status & flag;
25637 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
25638 +#define au_fset_si(sbinfo, name) do { \
25639 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
25640 + (sbinfo)->au_si_status |= AuSi_##name; \
25642 +#define au_fclr_si(sbinfo, name) do { \
25643 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
25644 + (sbinfo)->au_si_status &= ~AuSi_##name; \
25647 +/* ---------------------------------------------------------------------- */
25649 +/* policy to select one among writable branches */
25650 +#define AuWbrCopyup(sbinfo, ...) \
25651 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
25652 +#define AuWbrCreate(sbinfo, ...) \
25653 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
25655 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
25656 +#define AuLock_DW 1 /* write-lock dentry */
25657 +#define AuLock_IR (1 << 1) /* read-lock inode */
25658 +#define AuLock_IW (1 << 2) /* write-lock inode */
25659 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
25660 +#define AuLock_DIR (1 << 4) /* target is a dir */
25661 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
25662 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
25663 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
25664 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
25665 +#define au_fset_lock(flags, name) \
25666 + do { (flags) |= AuLock_##name; } while (0)
25667 +#define au_fclr_lock(flags, name) \
25668 + do { (flags) &= ~AuLock_##name; } while (0)
25670 +/* ---------------------------------------------------------------------- */
25673 +extern struct file_system_type aufs_fs_type;
25674 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
25675 +typedef unsigned long long (*au_arraycb_t)(void *array, unsigned long long max,
25677 +void au_array_free(void *array);
25678 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg);
25679 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
25680 +void au_iarray_free(struct inode **a, unsigned long long max);
25683 +void au_si_free(struct kobject *kobj);
25684 +int au_si_alloc(struct super_block *sb);
25685 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr);
25687 +unsigned int au_sigen_inc(struct super_block *sb);
25688 +aufs_bindex_t au_new_br_id(struct super_block *sb);
25690 +int si_read_lock(struct super_block *sb, int flags);
25691 +int si_write_lock(struct super_block *sb, int flags);
25692 +int aufs_read_lock(struct dentry *dentry, int flags);
25693 +void aufs_read_unlock(struct dentry *dentry, int flags);
25694 +void aufs_write_lock(struct dentry *dentry);
25695 +void aufs_write_unlock(struct dentry *dentry);
25696 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
25697 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
25699 +int si_pid_test_slow(struct super_block *sb);
25700 +void si_pid_set_slow(struct super_block *sb);
25701 +void si_pid_clr_slow(struct super_block *sb);
25703 +/* wbr_policy.c */
25704 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
25705 +extern struct au_wbr_create_operations au_wbr_create_ops[];
25706 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
25707 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
25710 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
25712 +/* ---------------------------------------------------------------------- */
25714 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
25716 + return sb->s_fs_info;
25719 +/* ---------------------------------------------------------------------- */
25721 +#ifdef CONFIG_AUFS_EXPORT
25722 +int au_test_nfsd(void);
25723 +void au_export_init(struct super_block *sb);
25724 +void au_xigen_inc(struct inode *inode);
25725 +int au_xigen_new(struct inode *inode);
25726 +int au_xigen_set(struct super_block *sb, struct file *base);
25727 +void au_xigen_clr(struct super_block *sb);
25729 +static inline int au_busy_or_stale(void)
25731 + if (!au_test_nfsd())
25736 +AuStubInt0(au_test_nfsd, void)
25737 +AuStubVoid(au_export_init, struct super_block *sb)
25738 +AuStubVoid(au_xigen_inc, struct inode *inode)
25739 +AuStubInt0(au_xigen_new, struct inode *inode)
25740 +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base)
25741 +AuStubVoid(au_xigen_clr, struct super_block *sb)
25742 +static inline int au_busy_or_stale(void)
25746 +#endif /* CONFIG_AUFS_EXPORT */
25748 +/* ---------------------------------------------------------------------- */
25750 +#ifdef CONFIG_AUFS_SBILIST
25752 +extern struct au_splhead au_sbilist;
25754 +static inline void au_sbilist_init(void)
25756 + au_spl_init(&au_sbilist);
25759 +static inline void au_sbilist_add(struct super_block *sb)
25761 + au_spl_add(&au_sbi(sb)->si_list, &au_sbilist);
25764 +static inline void au_sbilist_del(struct super_block *sb)
25766 + au_spl_del(&au_sbi(sb)->si_list, &au_sbilist);
25769 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
25770 +static inline void au_sbilist_lock(void)
25772 + spin_lock(&au_sbilist.spin);
25775 +static inline void au_sbilist_unlock(void)
25777 + spin_unlock(&au_sbilist.spin);
25779 +#define AuGFP_SBILIST GFP_ATOMIC
25781 +AuStubVoid(au_sbilist_lock, void)
25782 +AuStubVoid(au_sbilist_unlock, void)
25783 +#define AuGFP_SBILIST GFP_NOFS
25784 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
25786 +AuStubVoid(au_sbilist_init, void)
25787 +AuStubVoid(au_sbilist_add, struct super_block*)
25788 +AuStubVoid(au_sbilist_del, struct super_block*)
25789 +AuStubVoid(au_sbilist_lock, void)
25790 +AuStubVoid(au_sbilist_unlock, void)
25791 +#define AuGFP_SBILIST GFP_NOFS
25794 +/* ---------------------------------------------------------------------- */
25796 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
25799 + * This function is a dynamic '__init' fucntion actually,
25800 + * so the tiny check for si_rwsem is unnecessary.
25802 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
25803 +#ifdef CONFIG_DEBUG_FS
25804 + sbinfo->si_dbgaufs = NULL;
25805 + sbinfo->si_dbgaufs_plink = NULL;
25806 + sbinfo->si_dbgaufs_xib = NULL;
25807 +#ifdef CONFIG_AUFS_EXPORT
25808 + sbinfo->si_dbgaufs_xigen = NULL;
25813 +/* ---------------------------------------------------------------------- */
25815 +static inline pid_t si_pid_bit(void)
25817 + /* the origin of pid is 1, but the bitmap's is 0 */
25818 + return current->pid - 1;
25821 +static inline int si_pid_test(struct super_block *sb)
25823 + pid_t bit = si_pid_bit();
25824 + if (bit < PID_MAX_DEFAULT)
25825 + return test_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
25827 + return si_pid_test_slow(sb);
25830 +static inline void si_pid_set(struct super_block *sb)
25832 + pid_t bit = si_pid_bit();
25833 + if (bit < PID_MAX_DEFAULT) {
25834 + AuDebugOn(test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
25835 + set_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
25838 + si_pid_set_slow(sb);
25841 +static inline void si_pid_clr(struct super_block *sb)
25843 + pid_t bit = si_pid_bit();
25844 + if (bit < PID_MAX_DEFAULT) {
25845 + AuDebugOn(!test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
25846 + clear_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
25849 + si_pid_clr_slow(sb);
25852 +/* ---------------------------------------------------------------------- */
25854 +/* lock superblock. mainly for entry point functions */
25856 + * __si_read_lock, __si_write_lock,
25857 + * __si_read_unlock, __si_write_unlock, __si_downgrade_lock
25859 +AuSimpleRwsemFuncs(__si, struct super_block *sb, &au_sbi(sb)->si_rwsem);
25861 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
25862 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
25863 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
25865 +static inline void si_noflush_read_lock(struct super_block *sb)
25867 + __si_read_lock(sb);
25871 +static inline int si_noflush_read_trylock(struct super_block *sb)
25873 + int locked = __si_read_trylock(sb);
25879 +static inline void si_noflush_write_lock(struct super_block *sb)
25881 + __si_write_lock(sb);
25885 +static inline int si_noflush_write_trylock(struct super_block *sb)
25887 + int locked = __si_write_trylock(sb);
25893 +#if 0 /* unused */
25894 +static inline int si_read_trylock(struct super_block *sb, int flags)
25896 + if (au_ftest_lock(flags, FLUSH))
25897 + au_nwt_flush(&au_sbi(sb)->si_nowait);
25898 + return si_noflush_read_trylock(sb);
25902 +static inline void si_read_unlock(struct super_block *sb)
25905 + __si_read_unlock(sb);
25908 +#if 0 /* unused */
25909 +static inline int si_write_trylock(struct super_block *sb, int flags)
25911 + if (au_ftest_lock(flags, FLUSH))
25912 + au_nwt_flush(&au_sbi(sb)->si_nowait);
25913 + return si_noflush_write_trylock(sb);
25917 +static inline void si_write_unlock(struct super_block *sb)
25920 + __si_write_unlock(sb);
25923 +#if 0 /* unused */
25924 +static inline void si_downgrade_lock(struct super_block *sb)
25926 + __si_downgrade_lock(sb);
25930 +/* ---------------------------------------------------------------------- */
25932 +static inline aufs_bindex_t au_sbend(struct super_block *sb)
25934 + SiMustAnyLock(sb);
25935 + return au_sbi(sb)->si_bend;
25938 +static inline unsigned int au_mntflags(struct super_block *sb)
25940 + SiMustAnyLock(sb);
25941 + return au_sbi(sb)->si_mntflags;
25944 +static inline unsigned int au_sigen(struct super_block *sb)
25946 + SiMustAnyLock(sb);
25947 + return au_sbi(sb)->si_generation;
25950 +static inline void au_ninodes_inc(struct super_block *sb)
25952 + atomic_long_inc(&au_sbi(sb)->si_ninodes);
25955 +static inline void au_ninodes_dec(struct super_block *sb)
25957 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_ninodes));
25958 + atomic_long_dec(&au_sbi(sb)->si_ninodes);
25961 +static inline void au_nfiles_inc(struct super_block *sb)
25963 + atomic_long_inc(&au_sbi(sb)->si_nfiles);
25966 +static inline void au_nfiles_dec(struct super_block *sb)
25968 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_nfiles));
25969 + atomic_long_dec(&au_sbi(sb)->si_nfiles);
25972 +static inline struct au_branch *au_sbr(struct super_block *sb,
25973 + aufs_bindex_t bindex)
25975 + SiMustAnyLock(sb);
25976 + return au_sbi(sb)->si_branch[0 + bindex];
25979 +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid)
25981 + SiMustWriteLock(sb);
25982 + au_sbi(sb)->si_xino_brid = brid;
25985 +static inline aufs_bindex_t au_xino_brid(struct super_block *sb)
25987 + SiMustAnyLock(sb);
25988 + return au_sbi(sb)->si_xino_brid;
25991 +#endif /* __KERNEL__ */
25992 +#endif /* __AUFS_SUPER_H__ */
25993 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
25994 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
25995 +++ linux/fs/aufs/sysaufs.c 2014-01-20 20:16:14.749463838 +0100
25998 + * Copyright (C) 2005-2014 Junjiro R. Okajima
26000 + * This program, aufs is free software; you can redistribute it and/or modify
26001 + * it under the terms of the GNU General Public License as published by
26002 + * the Free Software Foundation; either version 2 of the License, or
26003 + * (at your option) any later version.
26005 + * This program is distributed in the hope that it will be useful,
26006 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26007 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26008 + * GNU General Public License for more details.
26010 + * You should have received a copy of the GNU General Public License
26011 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26015 + * sysfs interface and lifetime management
26016 + * they are necessary regardless sysfs is disabled.
26019 +#include <linux/random.h>
26022 +unsigned long sysaufs_si_mask;
26023 +struct kset *sysaufs_kset;
26025 +#define AuSiAttr(_name) { \
26026 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
26027 + .show = sysaufs_si_##_name, \
26030 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
26031 +struct attribute *sysaufs_si_attrs[] = {
26032 + &sysaufs_si_attr_xi_path.attr,
26036 +static const struct sysfs_ops au_sbi_ops = {
26037 + .show = sysaufs_si_show
26040 +static struct kobj_type au_sbi_ktype = {
26041 + .release = au_si_free,
26042 + .sysfs_ops = &au_sbi_ops,
26043 + .default_attrs = sysaufs_si_attrs
26046 +/* ---------------------------------------------------------------------- */
26048 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
26052 + sbinfo->si_kobj.kset = sysaufs_kset;
26053 + /* cf. sysaufs_name() */
26054 + err = kobject_init_and_add
26055 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
26056 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
26058 + dbgaufs_si_null(sbinfo);
26060 + err = dbgaufs_si_init(sbinfo);
26061 + if (unlikely(err))
26062 + kobject_put(&sbinfo->si_kobj);
26067 +void sysaufs_fin(void)
26070 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
26071 + kset_unregister(sysaufs_kset);
26074 +int __init sysaufs_init(void)
26079 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
26080 + } while (!sysaufs_si_mask);
26083 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
26084 + if (unlikely(!sysaufs_kset))
26086 + err = PTR_ERR(sysaufs_kset);
26087 + if (IS_ERR(sysaufs_kset))
26089 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
26090 + if (unlikely(err)) {
26091 + kset_unregister(sysaufs_kset);
26095 + err = dbgaufs_init();
26096 + if (unlikely(err))
26101 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
26102 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
26103 +++ linux/fs/aufs/sysaufs.h 2014-01-20 20:16:14.749463838 +0100
26106 + * Copyright (C) 2005-2014 Junjiro R. Okajima
26108 + * This program, aufs is free software; you can redistribute it and/or modify
26109 + * it under the terms of the GNU General Public License as published by
26110 + * the Free Software Foundation; either version 2 of the License, or
26111 + * (at your option) any later version.
26113 + * This program is distributed in the hope that it will be useful,
26114 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26115 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26116 + * GNU General Public License for more details.
26118 + * You should have received a copy of the GNU General Public License
26119 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26123 + * sysfs interface and mount lifetime management
26126 +#ifndef __SYSAUFS_H__
26127 +#define __SYSAUFS_H__
26131 +#include <linux/sysfs.h>
26132 +#include "module.h"
26134 +struct super_block;
26137 +struct sysaufs_si_attr {
26138 + struct attribute attr;
26139 + int (*show)(struct seq_file *seq, struct super_block *sb);
26142 +/* ---------------------------------------------------------------------- */
26145 +extern unsigned long sysaufs_si_mask;
26146 +extern struct kset *sysaufs_kset;
26147 +extern struct attribute *sysaufs_si_attrs[];
26148 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
26149 +int __init sysaufs_init(void);
26150 +void sysaufs_fin(void);
26152 +/* ---------------------------------------------------------------------- */
26154 +/* some people doesn't like to show a pointer in kernel */
26155 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
26157 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
26160 +#define SysaufsSiNamePrefix "si_"
26161 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
26162 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
26164 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
26165 + sysaufs_si_id(sbinfo));
26169 +#ifdef CONFIG_SYSFS
26171 +extern struct attribute_group *sysaufs_attr_group;
26173 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
26174 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
26177 +void sysaufs_br_init(struct au_branch *br);
26178 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
26179 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
26181 +#define sysaufs_brs_init() do {} while (0)
26184 +#define sysaufs_attr_group NULL
26186 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
26189 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
26195 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
26196 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
26197 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
26199 +static inline void sysaufs_brs_init(void)
26204 +#endif /* CONFIG_SYSFS */
26206 +#endif /* __KERNEL__ */
26207 +#endif /* __SYSAUFS_H__ */
26208 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
26209 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
26210 +++ linux/fs/aufs/sysfs.c 2014-01-20 20:16:14.749463838 +0100
26213 + * Copyright (C) 2005-2014 Junjiro R. Okajima
26215 + * This program, aufs is free software; you can redistribute it and/or modify
26216 + * it under the terms of the GNU General Public License as published by
26217 + * the Free Software Foundation; either version 2 of the License, or
26218 + * (at your option) any later version.
26220 + * This program is distributed in the hope that it will be useful,
26221 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26222 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26223 + * GNU General Public License for more details.
26225 + * You should have received a copy of the GNU General Public License
26226 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26230 + * sysfs interface
26233 +#include <linux/seq_file.h>
26236 +#ifdef CONFIG_AUFS_FS_MODULE
26237 +/* this entry violates the "one line per file" policy of sysfs */
26238 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
26242 + static char *conf =
26243 +/* this file is generated at compiling */
26244 +#include "conf.str"
26247 + err = snprintf(buf, PAGE_SIZE, conf);
26248 + if (unlikely(err >= PAGE_SIZE))
26253 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
26256 +static struct attribute *au_attr[] = {
26257 +#ifdef CONFIG_AUFS_FS_MODULE
26258 + &au_config_attr.attr,
26260 + NULL, /* need to NULL terminate the list of attributes */
26263 +static struct attribute_group sysaufs_attr_group_body = {
26267 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
26269 +/* ---------------------------------------------------------------------- */
26271 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
26275 + SiMustAnyLock(sb);
26278 + if (au_opt_test(au_mntflags(sb), XINO)) {
26279 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
26280 + seq_putc(seq, '\n');
26286 + * the lifetime of branch is independent from the entry under sysfs.
26287 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
26290 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
26291 + aufs_bindex_t bindex, int idx)
26294 + struct path path;
26295 + struct dentry *root;
26296 + struct au_branch *br;
26299 + AuDbg("b%d\n", bindex);
26302 + root = sb->s_root;
26303 + di_read_lock_parent(root, !AuLock_IR);
26304 + br = au_sbr(sb, bindex);
26307 + case AuBrSysfs_BR:
26308 + path.mnt = au_br_mnt(br);
26309 + path.dentry = au_h_dptr(root, bindex);
26310 + au_seq_path(seq, &path);
26311 + di_read_unlock(root, !AuLock_IR);
26312 + perm = au_optstr_br_perm(br->br_perm);
26314 + err = seq_printf(seq, "=%s\n", perm);
26321 + case AuBrSysfs_BRID:
26322 + err = seq_printf(seq, "%d\n", br->br_id);
26323 + di_read_unlock(root, !AuLock_IR);
26332 +/* ---------------------------------------------------------------------- */
26334 +static struct seq_file *au_seq(char *p, ssize_t len)
26336 + struct seq_file *seq;
26338 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
26340 + /* mutex_init(&seq.lock); */
26343 + return seq; /* success */
26346 + seq = ERR_PTR(-ENOMEM);
26350 +#define SysaufsBr_PREFIX "br"
26351 +#define SysaufsBrid_PREFIX "brid"
26353 +/* todo: file size may exceed PAGE_SIZE */
26354 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
26360 + aufs_bindex_t bend;
26361 + struct au_sbinfo *sbinfo;
26362 + struct super_block *sb;
26363 + struct seq_file *seq;
26365 + struct attribute **cattr;
26367 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
26368 + sb = sbinfo->si_sb;
26371 + * prevent a race condition between sysfs and aufs.
26372 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
26373 + * prohibits maintaining the sysfs entries.
26374 + * hew we acquire read lock after sysfs_get_active_two().
26375 + * on the other hand, the remount process may maintain the sysfs/aufs
26376 + * entries after acquiring write lock.
26377 + * it can cause a deadlock.
26378 + * simply we gave up processing read here.
26381 + if (unlikely(!si_noflush_read_trylock(sb)))
26384 + seq = au_seq(buf, PAGE_SIZE);
26385 + err = PTR_ERR(seq);
26389 + name = (void *)attr->name;
26390 + cattr = sysaufs_si_attrs;
26392 + if (!strcmp(name, (*cattr)->name)) {
26393 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
26400 + if (!strncmp(name, SysaufsBrid_PREFIX,
26401 + sizeof(SysaufsBrid_PREFIX) - 1)) {
26402 + idx = AuBrSysfs_BRID;
26403 + name += sizeof(SysaufsBrid_PREFIX) - 1;
26404 + } else if (!strncmp(name, SysaufsBr_PREFIX,
26405 + sizeof(SysaufsBr_PREFIX) - 1)) {
26406 + idx = AuBrSysfs_BR;
26407 + name += sizeof(SysaufsBr_PREFIX) - 1;
26411 + err = kstrtol(name, 10, &l);
26413 + bend = au_sbend(sb);
26415 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
26422 + err = seq->count;
26423 + /* sysfs limit */
26424 + if (unlikely(err == PAGE_SIZE))
26429 + si_read_unlock(sb);
26434 +/* ---------------------------------------------------------------------- */
26436 +void sysaufs_br_init(struct au_branch *br)
26439 + struct au_brsysfs *br_sysfs;
26440 + struct attribute *attr;
26442 + br_sysfs = br->br_sysfs;
26443 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
26444 + attr = &br_sysfs->attr;
26445 + sysfs_attr_init(attr);
26446 + attr->name = br_sysfs->name;
26447 + attr->mode = S_IRUGO;
26452 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
26454 + struct au_branch *br;
26455 + struct kobject *kobj;
26456 + struct au_brsysfs *br_sysfs;
26458 + aufs_bindex_t bend;
26460 + dbgaufs_brs_del(sb, bindex);
26462 + if (!sysaufs_brs)
26465 + kobj = &au_sbi(sb)->si_kobj;
26466 + bend = au_sbend(sb);
26467 + for (; bindex <= bend; bindex++) {
26468 + br = au_sbr(sb, bindex);
26469 + br_sysfs = br->br_sysfs;
26470 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
26471 + sysfs_remove_file(kobj, &br_sysfs->attr);
26477 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
26480 + aufs_bindex_t bend;
26481 + struct kobject *kobj;
26482 + struct au_branch *br;
26483 + struct au_brsysfs *br_sysfs;
26485 + dbgaufs_brs_add(sb, bindex);
26487 + if (!sysaufs_brs)
26490 + kobj = &au_sbi(sb)->si_kobj;
26491 + bend = au_sbend(sb);
26492 + for (; bindex <= bend; bindex++) {
26493 + br = au_sbr(sb, bindex);
26494 + br_sysfs = br->br_sysfs;
26495 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
26496 + SysaufsBr_PREFIX "%d", bindex);
26497 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
26498 + SysaufsBrid_PREFIX "%d", bindex);
26499 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
26500 + err = sysfs_create_file(kobj, &br_sysfs->attr);
26501 + if (unlikely(err))
26502 + pr_warn("failed %s under sysfs(%d)\n",
26503 + br_sysfs->name, err);
26508 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
26509 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
26510 +++ linux/fs/aufs/sysrq.c 2014-01-20 20:16:14.749463838 +0100
26513 + * Copyright (C) 2005-2014 Junjiro R. Okajima
26515 + * This program, aufs is free software; you can redistribute it and/or modify
26516 + * it under the terms of the GNU General Public License as published by
26517 + * the Free Software Foundation; either version 2 of the License, or
26518 + * (at your option) any later version.
26520 + * This program is distributed in the hope that it will be useful,
26521 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26522 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26523 + * GNU General Public License for more details.
26525 + * You should have received a copy of the GNU General Public License
26526 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26530 + * magic sysrq hanlder
26533 +/* #include <linux/sysrq.h> */
26534 +#include <linux/writeback.h>
26537 +/* ---------------------------------------------------------------------- */
26539 +static void sysrq_sb(struct super_block *sb)
26542 + struct au_sbinfo *sbinfo;
26543 + struct file *file;
26544 + struct au_sphlhead *files;
26545 + struct au_finfo *finfo;
26547 + plevel = au_plevel;
26548 + au_plevel = KERN_WARNING;
26550 + /* since we define pr_fmt, call printk directly */
26551 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
26553 + sbinfo = au_sbi(sb);
26554 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
26555 + pr("superblock\n");
26559 + pr("root dentry\n");
26560 + au_dpri_dentry(sb->s_root);
26561 + pr("root inode\n");
26562 + au_dpri_inode(sb->s_root->d_inode);
26567 + int err, i, j, ndentry;
26568 + struct au_dcsub_pages dpages;
26569 + struct au_dpage *dpage;
26571 + err = au_dpages_init(&dpages, GFP_ATOMIC);
26572 + if (unlikely(err))
26574 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
26576 + for (i = 0; i < dpages.ndpage; i++) {
26577 + dpage = dpages.dpages + i;
26578 + ndentry = dpage->ndentry;
26579 + for (j = 0; j < ndentry; j++)
26580 + au_dpri_dentry(dpage->dentries[j]);
26582 + au_dpages_free(&dpages);
26589 + pr("isolated inode\n");
26590 + spin_lock(&inode_sb_list_lock);
26591 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
26592 + spin_lock(&i->i_lock);
26593 + if (1 || hlist_empty(&i->i_dentry))
26594 + au_dpri_inode(i);
26595 + spin_unlock(&i->i_lock);
26597 + spin_unlock(&inode_sb_list_lock);
26601 + files = &au_sbi(sb)->si_files;
26602 + spin_lock(&files->spin);
26603 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
26605 + file = finfo->fi_file;
26606 + mode = file_inode(file)->i_mode;
26607 + if (!special_file(mode) || au_special_file(mode))
26608 + au_dpri_file(file);
26610 + spin_unlock(&files->spin);
26614 + au_plevel = plevel;
26617 +/* ---------------------------------------------------------------------- */
26619 +/* module parameter */
26620 +static char *aufs_sysrq_key = "a";
26621 +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO);
26622 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
26624 +static void au_sysrq(int key __maybe_unused)
26626 + struct au_sbinfo *sbinfo;
26629 + au_sbilist_lock();
26630 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
26631 + sysrq_sb(sbinfo->si_sb);
26632 + au_sbilist_unlock();
26636 +static struct sysrq_key_op au_sysrq_op = {
26637 + .handler = au_sysrq,
26638 + .help_msg = "Aufs",
26639 + .action_msg = "Aufs",
26640 + .enable_mask = SYSRQ_ENABLE_DUMP
26643 +/* ---------------------------------------------------------------------- */
26645 +int __init au_sysrq_init(void)
26651 + key = *aufs_sysrq_key;
26652 + if ('a' <= key && key <= 'z')
26653 + err = register_sysrq_key(key, &au_sysrq_op);
26654 + if (unlikely(err))
26655 + pr_err("err %d, sysrq=%c\n", err, key);
26659 +void au_sysrq_fin(void)
26662 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
26663 + if (unlikely(err))
26664 + pr_err("err %d (ignored)\n", err);
26666 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
26667 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
26668 +++ linux/fs/aufs/vdir.c 2014-01-20 20:16:14.749463838 +0100
26671 + * Copyright (C) 2005-2014 Junjiro R. Okajima
26673 + * This program, aufs is free software; you can redistribute it and/or modify
26674 + * it under the terms of the GNU General Public License as published by
26675 + * the Free Software Foundation; either version 2 of the License, or
26676 + * (at your option) any later version.
26678 + * This program is distributed in the hope that it will be useful,
26679 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26680 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26681 + * GNU General Public License for more details.
26683 + * You should have received a copy of the GNU General Public License
26684 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26688 + * virtual or vertical directory
26693 +static unsigned int calc_size(int nlen)
26695 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
26698 +static int set_deblk_end(union au_vdir_deblk_p *p,
26699 + union au_vdir_deblk_p *deblk_end)
26701 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
26702 + p->de->de_str.len = 0;
26706 + return -1; /* error */
26709 +/* returns true or false */
26710 +static int is_deblk_end(union au_vdir_deblk_p *p,
26711 + union au_vdir_deblk_p *deblk_end)
26713 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
26714 + return !p->de->de_str.len;
26718 +static unsigned char *last_deblk(struct au_vdir *vdir)
26720 + return vdir->vd_deblk[vdir->vd_nblk - 1];
26723 +/* ---------------------------------------------------------------------- */
26725 +/* estimate the apropriate size for name hash table */
26726 +unsigned int au_rdhash_est(loff_t sz)
26734 + if (sz < AUFS_RDHASH_DEF)
26735 + n = AUFS_RDHASH_DEF;
26736 + /* pr_info("n %u\n", n); */
26741 + * the allocated memory has to be freed by
26742 + * au_nhash_wh_free() or au_nhash_de_free().
26744 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
26746 + struct hlist_head *head;
26749 + head = kmalloc(sizeof(*nhash->nh_head) * num_hash, gfp);
26751 + nhash->nh_num = num_hash;
26752 + nhash->nh_head = head;
26753 + for (u = 0; u < num_hash; u++)
26754 + INIT_HLIST_HEAD(head++);
26755 + return 0; /* success */
26761 +static void nhash_count(struct hlist_head *head)
26765 + struct hlist_node *pos;
26768 + hlist_for_each(pos, head)
26770 + pr_info("%lu\n", n);
26774 +static void au_nhash_wh_do_free(struct hlist_head *head)
26776 + struct au_vdir_wh *pos;
26777 + struct hlist_node *node;
26779 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
26783 +static void au_nhash_de_do_free(struct hlist_head *head)
26785 + struct au_vdir_dehstr *pos;
26786 + struct hlist_node *node;
26788 + hlist_for_each_entry_safe(pos, node, head, hash)
26789 + au_cache_free_vdir_dehstr(pos);
26792 +static void au_nhash_do_free(struct au_nhash *nhash,
26793 + void (*free)(struct hlist_head *head))
26796 + struct hlist_head *head;
26798 + n = nhash->nh_num;
26802 + head = nhash->nh_head;
26803 + while (n-- > 0) {
26804 + nhash_count(head);
26807 + kfree(nhash->nh_head);
26810 +void au_nhash_wh_free(struct au_nhash *whlist)
26812 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
26815 +static void au_nhash_de_free(struct au_nhash *delist)
26817 + au_nhash_do_free(delist, au_nhash_de_do_free);
26820 +/* ---------------------------------------------------------------------- */
26822 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
26826 + unsigned int u, n;
26827 + struct hlist_head *head;
26828 + struct au_vdir_wh *pos;
26831 + n = whlist->nh_num;
26832 + head = whlist->nh_head;
26833 + for (u = 0; u < n; u++, head++)
26834 + hlist_for_each_entry(pos, head, wh_hash)
26835 + if (pos->wh_bindex == btgt && ++num > limit)
26840 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
26841 + unsigned char *name,
26842 + unsigned int len)
26845 + /* const unsigned int magic_bit = 12; */
26847 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
26852 + /* v = hash_long(v, magic_bit); */
26853 + v %= nhash->nh_num;
26854 + return nhash->nh_head + v;
26857 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
26860 + return str->len == nlen && !memcmp(str->name, name, nlen);
26863 +/* returns found or not */
26864 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
26866 + struct hlist_head *head;
26867 + struct au_vdir_wh *pos;
26868 + struct au_vdir_destr *str;
26870 + head = au_name_hash(whlist, name, nlen);
26871 + hlist_for_each_entry(pos, head, wh_hash) {
26872 + str = &pos->wh_str;
26873 + AuDbg("%.*s\n", str->len, str->name);
26874 + if (au_nhash_test_name(str, name, nlen))
26880 +/* returns found(true) or not */
26881 +static int test_known(struct au_nhash *delist, char *name, int nlen)
26883 + struct hlist_head *head;
26884 + struct au_vdir_dehstr *pos;
26885 + struct au_vdir_destr *str;
26887 + head = au_name_hash(delist, name, nlen);
26888 + hlist_for_each_entry(pos, head, hash) {
26890 + AuDbg("%.*s\n", str->len, str->name);
26891 + if (au_nhash_test_name(str, name, nlen))
26897 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
26898 + unsigned char d_type)
26900 +#ifdef CONFIG_AUFS_SHWH
26901 + wh->wh_ino = ino;
26902 + wh->wh_type = d_type;
26906 +/* ---------------------------------------------------------------------- */
26908 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
26909 + unsigned int d_type, aufs_bindex_t bindex,
26910 + unsigned char shwh)
26913 + struct au_vdir_destr *str;
26914 + struct au_vdir_wh *wh;
26916 + AuDbg("%.*s\n", nlen, name);
26917 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
26920 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
26921 + if (unlikely(!wh))
26925 + wh->wh_bindex = bindex;
26927 + au_shwh_init_wh(wh, ino, d_type);
26928 + str = &wh->wh_str;
26930 + memcpy(str->name, name, nlen);
26931 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
26938 +static int append_deblk(struct au_vdir *vdir)
26941 + unsigned long ul;
26942 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
26943 + union au_vdir_deblk_p p, deblk_end;
26944 + unsigned char **o;
26947 + o = krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
26949 + if (unlikely(!o))
26952 + vdir->vd_deblk = o;
26953 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
26955 + ul = vdir->vd_nblk++;
26956 + vdir->vd_deblk[ul] = p.deblk;
26957 + vdir->vd_last.ul = ul;
26958 + vdir->vd_last.p.deblk = p.deblk;
26959 + deblk_end.deblk = p.deblk + deblk_sz;
26960 + err = set_deblk_end(&p, &deblk_end);
26967 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
26968 + unsigned int d_type, struct au_nhash *delist)
26972 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
26973 + union au_vdir_deblk_p p, *room, deblk_end;
26974 + struct au_vdir_dehstr *dehstr;
26976 + p.deblk = last_deblk(vdir);
26977 + deblk_end.deblk = p.deblk + deblk_sz;
26978 + room = &vdir->vd_last.p;
26979 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
26980 + || !is_deblk_end(room, &deblk_end));
26982 + sz = calc_size(nlen);
26983 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
26984 + err = append_deblk(vdir);
26985 + if (unlikely(err))
26988 + p.deblk = last_deblk(vdir);
26989 + deblk_end.deblk = p.deblk + deblk_sz;
26991 + AuDebugOn(room->deblk != p.deblk);
26995 + dehstr = au_cache_alloc_vdir_dehstr();
26996 + if (unlikely(!dehstr))
26999 + dehstr->str = &room->de->de_str;
27000 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
27001 + room->de->de_ino = ino;
27002 + room->de->de_type = d_type;
27003 + room->de->de_str.len = nlen;
27004 + memcpy(room->de->de_str.name, name, nlen);
27007 + room->deblk += sz;
27008 + if (unlikely(set_deblk_end(room, &deblk_end)))
27009 + err = append_deblk(vdir);
27016 +/* ---------------------------------------------------------------------- */
27018 +void au_vdir_free(struct au_vdir *vdir)
27020 + unsigned char **deblk;
27022 + deblk = vdir->vd_deblk;
27023 + while (vdir->vd_nblk--)
27025 + kfree(vdir->vd_deblk);
27026 + au_cache_free_vdir(vdir);
27029 +static struct au_vdir *alloc_vdir(struct file *file)
27031 + struct au_vdir *vdir;
27032 + struct super_block *sb;
27035 + sb = file->f_dentry->d_sb;
27036 + SiMustAnyLock(sb);
27039 + vdir = au_cache_alloc_vdir();
27040 + if (unlikely(!vdir))
27043 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
27044 + if (unlikely(!vdir->vd_deblk))
27047 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
27048 + if (!vdir->vd_deblk_sz) {
27049 + /* estimate the apropriate size for deblk */
27050 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
27051 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
27053 + vdir->vd_nblk = 0;
27054 + vdir->vd_version = 0;
27055 + vdir->vd_jiffy = 0;
27056 + err = append_deblk(vdir);
27058 + return vdir; /* success */
27060 + kfree(vdir->vd_deblk);
27063 + au_cache_free_vdir(vdir);
27065 + vdir = ERR_PTR(err);
27069 +static int reinit_vdir(struct au_vdir *vdir)
27072 + union au_vdir_deblk_p p, deblk_end;
27074 + while (vdir->vd_nblk > 1) {
27075 + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
27076 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
27079 + p.deblk = vdir->vd_deblk[0];
27080 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
27081 + err = set_deblk_end(&p, &deblk_end);
27082 + /* keep vd_dblk_sz */
27083 + vdir->vd_last.ul = 0;
27084 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
27085 + vdir->vd_version = 0;
27086 + vdir->vd_jiffy = 0;
27091 +/* ---------------------------------------------------------------------- */
27093 +#define AuFillVdir_CALLED 1
27094 +#define AuFillVdir_WHABLE (1 << 1)
27095 +#define AuFillVdir_SHWH (1 << 2)
27096 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
27097 +#define au_fset_fillvdir(flags, name) \
27098 + do { (flags) |= AuFillVdir_##name; } while (0)
27099 +#define au_fclr_fillvdir(flags, name) \
27100 + do { (flags) &= ~AuFillVdir_##name; } while (0)
27102 +#ifndef CONFIG_AUFS_SHWH
27103 +#undef AuFillVdir_SHWH
27104 +#define AuFillVdir_SHWH 0
27107 +struct fillvdir_arg {
27108 + struct dir_context ctx;
27109 + struct file *file;
27110 + struct au_vdir *vdir;
27111 + struct au_nhash delist;
27112 + struct au_nhash whlist;
27113 + aufs_bindex_t bindex;
27114 + unsigned int flags;
27118 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
27119 + loff_t offset __maybe_unused, u64 h_ino,
27120 + unsigned int d_type)
27122 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
27123 + char *name = (void *)__name;
27124 + struct super_block *sb;
27126 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
27129 + sb = arg->file->f_dentry->d_sb;
27130 + au_fset_fillvdir(arg->flags, CALLED);
27132 + if (nlen <= AUFS_WH_PFX_LEN
27133 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
27134 + if (test_known(&arg->delist, name, nlen)
27135 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
27136 + goto out; /* already exists or whiteouted */
27138 + sb = arg->file->f_dentry->d_sb;
27139 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
27141 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
27142 + d_type = DT_UNKNOWN;
27143 + arg->err = append_de(arg->vdir, name, nlen, ino,
27144 + d_type, &arg->delist);
27146 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
27147 + name += AUFS_WH_PFX_LEN;
27148 + nlen -= AUFS_WH_PFX_LEN;
27149 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
27150 + goto out; /* already whiteouted */
27153 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
27156 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
27157 + d_type = DT_UNKNOWN;
27158 + arg->err = au_nhash_append_wh
27159 + (&arg->whlist, name, nlen, ino, d_type,
27160 + arg->bindex, shwh);
27166 + arg->vdir->vd_jiffy = jiffies;
27168 + AuTraceErr(arg->err);
27172 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
27173 + struct au_nhash *whlist, struct au_nhash *delist)
27175 +#ifdef CONFIG_AUFS_SHWH
27177 + unsigned int nh, u;
27178 + struct hlist_head *head;
27179 + struct au_vdir_wh *pos;
27180 + struct hlist_node *n;
27182 + struct au_vdir_destr *destr;
27184 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
27187 + o = p = (void *)__get_free_page(GFP_NOFS);
27188 + if (unlikely(!p))
27192 + nh = whlist->nh_num;
27193 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
27194 + p += AUFS_WH_PFX_LEN;
27195 + for (u = 0; u < nh; u++) {
27196 + head = whlist->nh_head + u;
27197 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
27198 + destr = &pos->wh_str;
27199 + memcpy(p, destr->name, destr->len);
27200 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
27201 + pos->wh_ino, pos->wh_type, delist);
27202 + if (unlikely(err))
27207 + free_page((unsigned long)o);
27217 +static int au_do_read_vdir(struct fillvdir_arg *arg)
27220 + unsigned int rdhash;
27222 + aufs_bindex_t bend, bindex, bstart;
27223 + unsigned char shwh;
27224 + struct file *hf, *file;
27225 + struct super_block *sb;
27227 + file = arg->file;
27228 + sb = file->f_dentry->d_sb;
27229 + SiMustAnyLock(sb);
27231 + rdhash = au_sbi(sb)->si_rdhash;
27233 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
27234 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
27235 + if (unlikely(err))
27237 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
27238 + if (unlikely(err))
27244 + if (au_opt_test(au_mntflags(sb), SHWH)) {
27246 + au_fset_fillvdir(arg->flags, SHWH);
27248 + bstart = au_fbstart(file);
27249 + bend = au_fbend_dir(file);
27250 + for (bindex = bstart; !err && bindex <= bend; bindex++) {
27251 + hf = au_hf_dir(file, bindex);
27255 + offset = vfsub_llseek(hf, 0, SEEK_SET);
27257 + if (unlikely(offset))
27260 + arg->bindex = bindex;
27261 + au_fclr_fillvdir(arg->flags, WHABLE);
27263 + || (bindex != bend
27264 + && au_br_whable(au_sbr_perm(sb, bindex))))
27265 + au_fset_fillvdir(arg->flags, WHABLE);
27268 + au_fclr_fillvdir(arg->flags, CALLED);
27270 + err = vfsub_iterate_dir(hf, &arg->ctx);
27273 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
27276 + * dir_relax() may be good for concurrency, but aufs should not
27277 + * use it since it will cause a lockdep problem.
27281 + if (!err && shwh)
27282 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
27284 + au_nhash_wh_free(&arg->whlist);
27287 + au_nhash_de_free(&arg->delist);
27292 +static int read_vdir(struct file *file, int may_read)
27295 + unsigned long expire;
27296 + unsigned char do_read;
27297 + struct fillvdir_arg arg = {
27299 + .actor = au_diractor(fillvdir)
27302 + struct inode *inode;
27303 + struct au_vdir *vdir, *allocated;
27306 + inode = file_inode(file);
27307 + IMustLock(inode);
27308 + SiMustAnyLock(inode->i_sb);
27310 + allocated = NULL;
27312 + expire = au_sbi(inode->i_sb)->si_rdcache;
27313 + vdir = au_ivdir(inode);
27316 + vdir = alloc_vdir(file);
27317 + err = PTR_ERR(vdir);
27318 + if (IS_ERR(vdir))
27321 + allocated = vdir;
27322 + } else if (may_read
27323 + && (inode->i_version != vdir->vd_version
27324 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
27326 + err = reinit_vdir(vdir);
27327 + if (unlikely(err))
27332 + return 0; /* success */
27336 + err = au_do_read_vdir(&arg);
27338 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
27339 + vdir->vd_version = inode->i_version;
27340 + vdir->vd_last.ul = 0;
27341 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
27343 + au_set_ivdir(inode, allocated);
27344 + } else if (allocated)
27345 + au_vdir_free(allocated);
27351 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
27354 + unsigned long ul, n;
27355 + const unsigned int deblk_sz = src->vd_deblk_sz;
27357 + AuDebugOn(tgt->vd_nblk != 1);
27360 + if (tgt->vd_nblk < src->vd_nblk) {
27361 + unsigned char **p;
27363 + p = krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
27365 + if (unlikely(!p))
27367 + tgt->vd_deblk = p;
27370 + if (tgt->vd_deblk_sz != deblk_sz) {
27371 + unsigned char *p;
27373 + tgt->vd_deblk_sz = deblk_sz;
27374 + p = krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS);
27375 + if (unlikely(!p))
27377 + tgt->vd_deblk[0] = p;
27379 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
27380 + tgt->vd_version = src->vd_version;
27381 + tgt->vd_jiffy = src->vd_jiffy;
27383 + n = src->vd_nblk;
27384 + for (ul = 1; ul < n; ul++) {
27385 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
27387 + if (unlikely(!tgt->vd_deblk[ul]))
27391 + tgt->vd_nblk = n;
27392 + tgt->vd_last.ul = tgt->vd_last.ul;
27393 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
27394 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
27395 + - src->vd_deblk[src->vd_last.ul];
27397 + return 0; /* success */
27400 + rerr = reinit_vdir(tgt);
27405 +int au_vdir_init(struct file *file)
27408 + struct inode *inode;
27409 + struct au_vdir *vdir_cache, *allocated;
27411 + /* test file->f_pos here instead of ctx->pos */
27412 + err = read_vdir(file, !file->f_pos);
27413 + if (unlikely(err))
27416 + allocated = NULL;
27417 + vdir_cache = au_fvdir_cache(file);
27418 + if (!vdir_cache) {
27419 + vdir_cache = alloc_vdir(file);
27420 + err = PTR_ERR(vdir_cache);
27421 + if (IS_ERR(vdir_cache))
27423 + allocated = vdir_cache;
27424 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
27425 + /* test file->f_pos here instead of ctx->pos */
27426 + err = reinit_vdir(vdir_cache);
27427 + if (unlikely(err))
27430 + return 0; /* success */
27432 + inode = file_inode(file);
27433 + err = copy_vdir(vdir_cache, au_ivdir(inode));
27435 + file->f_version = inode->i_version;
27437 + au_set_fvdir_cache(file, allocated);
27438 + } else if (allocated)
27439 + au_vdir_free(allocated);
27445 +static loff_t calc_offset(struct au_vdir *vdir)
27448 + union au_vdir_deblk_p p;
27450 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
27451 + offset = vdir->vd_last.p.deblk - p.deblk;
27452 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
27456 +/* returns true or false */
27457 +static int seek_vdir(struct file *file, struct dir_context *ctx)
27460 + unsigned int deblk_sz;
27461 + unsigned long ul, n;
27463 + union au_vdir_deblk_p p, deblk_end;
27464 + struct au_vdir *vdir_cache;
27467 + vdir_cache = au_fvdir_cache(file);
27468 + offset = calc_offset(vdir_cache);
27469 + AuDbg("offset %lld\n", offset);
27470 + if (ctx->pos == offset)
27473 + vdir_cache->vd_last.ul = 0;
27474 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
27479 + deblk_sz = vdir_cache->vd_deblk_sz;
27480 + ul = div64_u64(ctx->pos, deblk_sz);
27481 + AuDbg("ul %lu\n", ul);
27482 + if (ul >= vdir_cache->vd_nblk)
27485 + n = vdir_cache->vd_nblk;
27486 + for (; ul < n; ul++) {
27487 + p.deblk = vdir_cache->vd_deblk[ul];
27488 + deblk_end.deblk = p.deblk + deblk_sz;
27490 + offset *= deblk_sz;
27491 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
27494 + l = calc_size(p.de->de_str.len);
27498 + if (!is_deblk_end(&p, &deblk_end)) {
27500 + vdir_cache->vd_last.ul = ul;
27501 + vdir_cache->vd_last.p = p;
27508 + AuTraceErr(!valid);
27512 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
27514 + unsigned int l, deblk_sz;
27515 + union au_vdir_deblk_p deblk_end;
27516 + struct au_vdir *vdir_cache;
27517 + struct au_vdir_de *de;
27519 + vdir_cache = au_fvdir_cache(file);
27520 + if (!seek_vdir(file, ctx))
27523 + deblk_sz = vdir_cache->vd_deblk_sz;
27525 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
27526 + deblk_end.deblk += deblk_sz;
27527 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
27528 + de = vdir_cache->vd_last.p.de;
27529 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
27530 + de->de_str.len, de->de_str.name, ctx->pos,
27531 + (unsigned long)de->de_ino, de->de_type);
27532 + if (unlikely(!dir_emit(ctx, de->de_str.name,
27533 + de->de_str.len, de->de_ino,
27535 + /* todo: ignore the error caused by udba? */
27536 + /* return err; */
27540 + l = calc_size(de->de_str.len);
27541 + vdir_cache->vd_last.p.deblk += l;
27544 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
27545 + vdir_cache->vd_last.ul++;
27546 + vdir_cache->vd_last.p.deblk
27547 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
27548 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
27557 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
27558 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
27559 +++ linux/fs/aufs/vfsub.c 2014-01-20 20:16:14.749463838 +0100
27562 + * Copyright (C) 2005-2014 Junjiro R. Okajima
27564 + * This program, aufs is free software; you can redistribute it and/or modify
27565 + * it under the terms of the GNU General Public License as published by
27566 + * the Free Software Foundation; either version 2 of the License, or
27567 + * (at your option) any later version.
27569 + * This program is distributed in the hope that it will be useful,
27570 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27571 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27572 + * GNU General Public License for more details.
27574 + * You should have received a copy of the GNU General Public License
27575 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27579 + * sub-routines for VFS
27582 +#include <linux/ima.h>
27583 +#include <linux/namei.h>
27584 +#include <linux/security.h>
27585 +#include <linux/splice.h>
27588 +int vfsub_update_h_iattr(struct path *h_path, int *did)
27592 + struct super_block *h_sb;
27594 + /* for remote fs, leave work for its getattr or d_revalidate */
27595 + /* for bad i_attr fs, handle them in aufs_getattr() */
27596 + /* still some fs may acquire i_mutex. we need to skip them */
27600 + h_sb = h_path->dentry->d_sb;
27601 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
27603 + err = vfs_getattr(h_path, &st);
27608 +/* ---------------------------------------------------------------------- */
27610 +struct file *vfsub_dentry_open(struct path *path, int flags)
27612 + struct file *file;
27614 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
27616 + if (!IS_ERR_OR_NULL(file)
27617 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
27618 + i_readcount_inc(path->dentry->d_inode);
27623 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
27625 + struct file *file;
27628 + file = filp_open(path,
27629 + oflags /* | __FMODE_NONOTIFY */,
27632 + if (IS_ERR(file))
27634 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
27640 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
27644 + err = kern_path(name, flags, path);
27645 + if (!err && path->dentry->d_inode)
27646 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
27650 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
27653 + struct path path = {
27657 + /* VFS checks it too, but by WARN_ON_ONCE() */
27658 + IMustLock(parent->d_inode);
27660 + path.dentry = lookup_one_len(name, parent, len);
27661 + if (IS_ERR(path.dentry))
27663 + if (path.dentry->d_inode)
27664 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
27667 + AuTraceErrPtr(path.dentry);
27668 + return path.dentry;
27671 +void vfsub_call_lkup_one(void *args)
27673 + struct vfsub_lkup_one_args *a = args;
27674 + *a->errp = vfsub_lkup_one(a->name, a->parent);
27677 +/* ---------------------------------------------------------------------- */
27679 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
27680 + struct dentry *d2, struct au_hinode *hdir2)
27682 + struct dentry *d;
27685 + d = lock_rename(d1, d2);
27687 + au_hn_suspend(hdir1);
27688 + if (hdir1 != hdir2)
27689 + au_hn_suspend(hdir2);
27694 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
27695 + struct dentry *d2, struct au_hinode *hdir2)
27697 + au_hn_resume(hdir1);
27698 + if (hdir1 != hdir2)
27699 + au_hn_resume(hdir2);
27701 + unlock_rename(d1, d2);
27705 +/* ---------------------------------------------------------------------- */
27707 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
27710 + struct dentry *d;
27714 + d = path->dentry;
27715 + path->dentry = d->d_parent;
27716 + err = security_path_mknod(path, d, mode, 0);
27717 + path->dentry = d;
27718 + if (unlikely(err))
27721 + err = vfs_create(dir, path->dentry, mode, want_excl);
27723 + struct path tmp = *path;
27726 + vfsub_update_h_iattr(&tmp, &did);
27728 + tmp.dentry = path->dentry->d_parent;
27729 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27738 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
27741 + struct dentry *d;
27745 + d = path->dentry;
27746 + path->dentry = d->d_parent;
27747 + err = security_path_symlink(path, d, symname);
27748 + path->dentry = d;
27749 + if (unlikely(err))
27752 + err = vfs_symlink(dir, path->dentry, symname);
27754 + struct path tmp = *path;
27757 + vfsub_update_h_iattr(&tmp, &did);
27759 + tmp.dentry = path->dentry->d_parent;
27760 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27769 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
27772 + struct dentry *d;
27776 + d = path->dentry;
27777 + path->dentry = d->d_parent;
27778 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
27779 + path->dentry = d;
27780 + if (unlikely(err))
27783 + err = vfs_mknod(dir, path->dentry, mode, dev);
27785 + struct path tmp = *path;
27788 + vfsub_update_h_iattr(&tmp, &did);
27790 + tmp.dentry = path->dentry->d_parent;
27791 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27800 +static int au_test_nlink(struct inode *inode)
27802 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
27804 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
27805 + || inode->i_nlink < link_max)
27810 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
27811 + struct inode **delegated_inode)
27814 + struct dentry *d;
27818 + err = au_test_nlink(src_dentry->d_inode);
27819 + if (unlikely(err))
27822 + /* we don't call may_linkat() */
27823 + d = path->dentry;
27824 + path->dentry = d->d_parent;
27825 + err = security_path_link(src_dentry, path, d);
27826 + path->dentry = d;
27827 + if (unlikely(err))
27831 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
27834 + struct path tmp = *path;
27837 + /* fuse has different memory inode for the same inumber */
27838 + vfsub_update_h_iattr(&tmp, &did);
27840 + tmp.dentry = path->dentry->d_parent;
27841 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27842 + tmp.dentry = src_dentry;
27843 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27852 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
27853 + struct inode *dir, struct path *path,
27854 + struct inode **delegated_inode)
27857 + struct path tmp = {
27860 + struct dentry *d;
27863 + IMustLock(src_dir);
27865 + d = path->dentry;
27866 + path->dentry = d->d_parent;
27867 + tmp.dentry = src_dentry->d_parent;
27868 + err = security_path_rename(&tmp, src_dentry, path, d);
27869 + path->dentry = d;
27870 + if (unlikely(err))
27874 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
27875 + delegated_inode);
27880 + tmp.dentry = d->d_parent;
27881 + vfsub_update_h_iattr(&tmp, &did);
27883 + tmp.dentry = src_dentry;
27884 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27885 + tmp.dentry = src_dentry->d_parent;
27886 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27895 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
27898 + struct dentry *d;
27902 + d = path->dentry;
27903 + path->dentry = d->d_parent;
27904 + err = security_path_mkdir(path, d, mode);
27905 + path->dentry = d;
27906 + if (unlikely(err))
27909 + err = vfs_mkdir(dir, path->dentry, mode);
27911 + struct path tmp = *path;
27914 + vfsub_update_h_iattr(&tmp, &did);
27916 + tmp.dentry = path->dentry->d_parent;
27917 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27926 +int vfsub_rmdir(struct inode *dir, struct path *path)
27929 + struct dentry *d;
27933 + d = path->dentry;
27934 + path->dentry = d->d_parent;
27935 + err = security_path_rmdir(path, d);
27936 + path->dentry = d;
27937 + if (unlikely(err))
27941 + err = vfs_rmdir(dir, path->dentry);
27944 + struct path tmp = {
27945 + .dentry = path->dentry->d_parent,
27949 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
27956 +/* ---------------------------------------------------------------------- */
27958 +/* todo: support mmap_sem? */
27959 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
27965 + err = vfs_read(file, ubuf, count, ppos);
27968 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
27972 +/* todo: kernel_read()? */
27973 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
27977 + mm_segment_t oldfs;
27984 + oldfs = get_fs();
27985 + set_fs(KERNEL_DS);
27986 + err = vfsub_read_u(file, buf.u, count, ppos);
27991 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
27997 + err = vfs_write(file, ubuf, count, ppos);
28000 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
28004 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
28007 + mm_segment_t oldfs;
28010 + const char __user *u;
28014 + oldfs = get_fs();
28015 + set_fs(KERNEL_DS);
28016 + err = vfsub_write_u(file, buf.u, count, ppos);
28021 +int vfsub_flush(struct file *file, fl_owner_t id)
28026 + if (file->f_op->flush) {
28027 + if (!au_test_nfs(file->f_dentry->d_sb))
28028 + err = file->f_op->flush(file, id);
28031 + err = file->f_op->flush(file, id);
28035 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
28041 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
28045 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
28048 + err = iterate_dir(file, ctx);
28051 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
28055 +long vfsub_splice_to(struct file *in, loff_t *ppos,
28056 + struct pipe_inode_info *pipe, size_t len,
28057 + unsigned int flags)
28062 + err = do_splice_to(in, ppos, pipe, len, flags);
28064 + file_accessed(in);
28066 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
28070 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
28071 + loff_t *ppos, size_t len, unsigned int flags)
28076 + err = do_splice_from(pipe, out, ppos, len, flags);
28079 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
28083 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
28087 + /* file can be NULL */
28089 + err = vfs_fsync(file, datasync);
28093 + AuDebugOn(!file);
28094 + path = &file->f_path;
28096 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
28101 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
28102 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
28103 + struct file *h_file)
28106 + struct inode *h_inode;
28107 + struct super_block *h_sb;
28110 + err = vfsub_truncate(h_path, length);
28114 + h_inode = h_path->dentry->d_inode;
28115 + h_sb = h_inode->i_sb;
28117 + sb_start_write(h_sb);
28119 + err = locks_verify_truncate(h_inode, h_file, length);
28121 + err = security_path_truncate(h_path);
28124 + err = do_truncate(h_path->dentry, length, attr, h_file);
28128 + sb_end_write(h_sb);
28135 +/* ---------------------------------------------------------------------- */
28137 +struct au_vfsub_mkdir_args {
28139 + struct inode *dir;
28140 + struct path *path;
28144 +static void au_call_vfsub_mkdir(void *args)
28146 + struct au_vfsub_mkdir_args *a = args;
28147 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
28150 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
28152 + int err, do_sio, wkq_err;
28154 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
28156 + err = vfsub_mkdir(dir, path, mode);
28158 + struct au_vfsub_mkdir_args args = {
28164 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
28165 + if (unlikely(wkq_err))
28172 +struct au_vfsub_rmdir_args {
28174 + struct inode *dir;
28175 + struct path *path;
28178 +static void au_call_vfsub_rmdir(void *args)
28180 + struct au_vfsub_rmdir_args *a = args;
28181 + *a->errp = vfsub_rmdir(a->dir, a->path);
28184 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
28186 + int err, do_sio, wkq_err;
28188 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
28190 + err = vfsub_rmdir(dir, path);
28192 + struct au_vfsub_rmdir_args args = {
28197 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
28198 + if (unlikely(wkq_err))
28205 +/* ---------------------------------------------------------------------- */
28207 +struct notify_change_args {
28209 + struct path *path;
28210 + struct iattr *ia;
28211 + struct inode **delegated_inode;
28214 +static void call_notify_change(void *args)
28216 + struct notify_change_args *a = args;
28217 + struct inode *h_inode;
28219 + h_inode = a->path->dentry->d_inode;
28220 + IMustLock(h_inode);
28222 + *a->errp = -EPERM;
28223 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
28224 + *a->errp = notify_change(a->path->dentry, a->ia,
28225 + a->delegated_inode);
28227 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
28229 + AuTraceErr(*a->errp);
28232 +int vfsub_notify_change(struct path *path, struct iattr *ia,
28233 + struct inode **delegated_inode)
28236 + struct notify_change_args args = {
28240 + .delegated_inode = delegated_inode
28243 + call_notify_change(&args);
28248 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
28249 + struct inode **delegated_inode)
28251 + int err, wkq_err;
28252 + struct notify_change_args args = {
28256 + .delegated_inode = delegated_inode
28259 + wkq_err = au_wkq_wait(call_notify_change, &args);
28260 + if (unlikely(wkq_err))
28266 +/* ---------------------------------------------------------------------- */
28268 +struct unlink_args {
28270 + struct inode *dir;
28271 + struct path *path;
28272 + struct inode **delegated_inode;
28275 +static void call_unlink(void *args)
28277 + struct unlink_args *a = args;
28278 + struct dentry *d = a->path->dentry;
28279 + struct inode *h_inode;
28280 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
28281 + && d_count(d) == 1);
28283 + IMustLock(a->dir);
28285 + a->path->dentry = d->d_parent;
28286 + *a->errp = security_path_unlink(a->path, d);
28287 + a->path->dentry = d;
28288 + if (unlikely(*a->errp))
28291 + if (!stop_sillyrename)
28293 + h_inode = d->d_inode;
28298 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
28301 + struct path tmp = {
28302 + .dentry = d->d_parent,
28303 + .mnt = a->path->mnt
28305 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
28308 + if (!stop_sillyrename)
28313 + AuTraceErr(*a->errp);
28317 + * @dir: must be locked.
28318 + * @dentry: target dentry.
28320 +int vfsub_unlink(struct inode *dir, struct path *path,
28321 + struct inode **delegated_inode, int force)
28324 + struct unlink_args args = {
28328 + .delegated_inode = delegated_inode
28332 + call_unlink(&args);
28336 + wkq_err = au_wkq_wait(call_unlink, &args);
28337 + if (unlikely(wkq_err))
28343 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
28344 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
28345 +++ linux/fs/aufs/vfsub.h 2014-01-20 20:16:14.749463838 +0100
28348 + * Copyright (C) 2005-2014 Junjiro R. Okajima
28350 + * This program, aufs is free software; you can redistribute it and/or modify
28351 + * it under the terms of the GNU General Public License as published by
28352 + * the Free Software Foundation; either version 2 of the License, or
28353 + * (at your option) any later version.
28355 + * This program is distributed in the hope that it will be useful,
28356 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28357 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28358 + * GNU General Public License for more details.
28360 + * You should have received a copy of the GNU General Public License
28361 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28365 + * sub-routines for VFS
28368 +#ifndef __AUFS_VFSUB_H__
28369 +#define __AUFS_VFSUB_H__
28373 +#include <linux/fs.h>
28374 +#include <linux/lglock.h>
28375 +#include <linux/mount.h>
28376 +#include "debug.h"
28378 +/* copied from linux/fs/internal.h */
28379 +/* todo: BAD approach!! */
28380 +extern void __mnt_drop_write(struct vfsmount *);
28381 +extern spinlock_t inode_sb_list_lock;
28383 +/* ---------------------------------------------------------------------- */
28385 +/* lock subclass for lower inode */
28386 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
28387 +/* reduce? gave up. */
28389 + AuLsc_I_Begin = I_MUTEX_NONDIR2, /* 4 */
28390 + AuLsc_I_PARENT, /* lower inode, parent first */
28391 + AuLsc_I_PARENT2, /* copyup dirs */
28392 + AuLsc_I_PARENT3, /* copyup wh */
28398 +/* to debug easier, do not make them inlined functions */
28399 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
28400 +#define IMustLock(i) MtxMustLock(&(i)->i_mutex)
28402 +/* ---------------------------------------------------------------------- */
28404 +static inline void vfsub_drop_nlink(struct inode *inode)
28406 + AuDebugOn(!inode->i_nlink);
28407 + drop_nlink(inode);
28410 +static inline void vfsub_dead_dir(struct inode *inode)
28412 + AuDebugOn(!S_ISDIR(inode->i_mode));
28413 + inode->i_flags |= S_DEAD;
28414 + clear_nlink(inode);
28417 +static inline int vfsub_native_ro(struct inode *inode)
28419 + return (inode->i_sb->s_flags & MS_RDONLY)
28420 + || IS_RDONLY(inode)
28421 + /* || IS_APPEND(inode) */
28422 + || IS_IMMUTABLE(inode);
28425 +/* ---------------------------------------------------------------------- */
28427 +int vfsub_update_h_iattr(struct path *h_path, int *did);
28428 +struct file *vfsub_dentry_open(struct path *path, int flags);
28429 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
28430 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
28432 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
28435 +struct vfsub_lkup_one_args {
28436 + struct dentry **errp;
28437 + struct qstr *name;
28438 + struct dentry *parent;
28441 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
28442 + struct dentry *parent)
28444 + return vfsub_lookup_one_len(name->name, parent, name->len);
28447 +void vfsub_call_lkup_one(void *args);
28449 +/* ---------------------------------------------------------------------- */
28451 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
28455 + err = mnt_want_write(mnt);
28460 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
28463 + mnt_drop_write(mnt);
28467 +static inline void vfsub_mnt_drop_write_file(struct file *file)
28470 + mnt_drop_write_file(file);
28474 +/* ---------------------------------------------------------------------- */
28477 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
28478 + struct dentry *d2, struct au_hinode *hdir2);
28479 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
28480 + struct dentry *d2, struct au_hinode *hdir2);
28482 +int vfsub_create(struct inode *dir, struct path *path, int mode,
28484 +int vfsub_symlink(struct inode *dir, struct path *path,
28485 + const char *symname);
28486 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
28487 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
28488 + struct path *path, struct inode **delegated_inode);
28489 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
28490 + struct inode *hdir, struct path *path,
28491 + struct inode **delegated_inode);
28492 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
28493 +int vfsub_rmdir(struct inode *dir, struct path *path);
28495 +/* ---------------------------------------------------------------------- */
28497 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
28499 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
28501 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
28503 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
28505 +int vfsub_flush(struct file *file, fl_owner_t id);
28506 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
28508 +/* just for type-check */
28509 +static inline filldir_t au_diractor(int (*func)(struct dir_context *,
28510 + const char *, int, loff_t, u64,
28513 + return (filldir_t)func;
28517 +static inline loff_t vfsub_f_size_read(struct file *file)
28519 + return i_size_read(file_inode(file));
28522 +static inline unsigned int vfsub_file_flags(struct file *file)
28524 + unsigned int flags;
28526 + spin_lock(&file->f_lock);
28527 + flags = file->f_flags;
28528 + spin_unlock(&file->f_lock);
28533 +static inline void vfsub_file_accessed(struct file *h_file)
28535 + file_accessed(h_file);
28536 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
28539 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
28540 + struct dentry *h_dentry)
28542 + struct path h_path = {
28543 + .dentry = h_dentry,
28546 + touch_atime(&h_path);
28547 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
28550 +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts,
28553 + return update_time(h_inode, ts, flags);
28554 + /* no vfsub_update_h_iattr() since we don't have struct path */
28557 +long vfsub_splice_to(struct file *in, loff_t *ppos,
28558 + struct pipe_inode_info *pipe, size_t len,
28559 + unsigned int flags);
28560 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
28561 + loff_t *ppos, size_t len, unsigned int flags);
28563 +static inline long vfsub_truncate(struct path *path, loff_t length)
28567 + err = vfs_truncate(path, length);
28572 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
28573 + struct file *h_file);
28574 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
28576 +/* ---------------------------------------------------------------------- */
28578 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
28583 + err = vfs_llseek(file, offset, origin);
28588 +/* ---------------------------------------------------------------------- */
28590 +/* dirty workaround for strict type of fmode_t */
28596 +static inline unsigned int vfsub_fmode_to_uint(fmode_t fm)
28598 + union vfsub_fmu u = {
28602 + BUILD_BUG_ON(sizeof(u.fm) != sizeof(u.ui));
28607 +static inline fmode_t vfsub_uint_to_fmode(unsigned int ui)
28609 + union vfsub_fmu u = {
28616 +/* ---------------------------------------------------------------------- */
28618 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
28619 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
28620 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
28621 + struct inode **delegated_inode);
28622 +int vfsub_notify_change(struct path *path, struct iattr *ia,
28623 + struct inode **delegated_inode);
28624 +int vfsub_unlink(struct inode *dir, struct path *path,
28625 + struct inode **delegated_inode, int force);
28627 +#endif /* __KERNEL__ */
28628 +#endif /* __AUFS_VFSUB_H__ */
28629 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
28630 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
28631 +++ linux/fs/aufs/wbr_policy.c 2014-01-20 20:16:14.749463838 +0100
28634 + * Copyright (C) 2005-2014 Junjiro R. Okajima
28636 + * This program, aufs is free software; you can redistribute it and/or modify
28637 + * it under the terms of the GNU General Public License as published by
28638 + * the Free Software Foundation; either version 2 of the License, or
28639 + * (at your option) any later version.
28641 + * This program is distributed in the hope that it will be useful,
28642 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28643 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28644 + * GNU General Public License for more details.
28646 + * You should have received a copy of the GNU General Public License
28647 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28651 + * policies for selecting one among multiple writable branches
28654 +#include <linux/statfs.h>
28657 +/* subset of cpup_attr() */
28658 +static noinline_for_stack
28659 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
28663 + struct inode *h_isrc;
28665 + h_isrc = h_src->d_inode;
28666 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
28667 + ia.ia_mode = h_isrc->i_mode;
28668 + ia.ia_uid = h_isrc->i_uid;
28669 + ia.ia_gid = h_isrc->i_gid;
28670 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
28671 + au_cpup_attr_flags(h_path->dentry->d_inode, h_isrc->i_flags);
28672 + /* no delegation since it is just created */
28673 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
28675 + /* is this nfs only? */
28676 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
28677 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
28678 + ia.ia_mode = h_isrc->i_mode;
28679 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
28685 +#define AuCpdown_PARENT_OPQ 1
28686 +#define AuCpdown_WHED (1 << 1)
28687 +#define AuCpdown_MADE_DIR (1 << 2)
28688 +#define AuCpdown_DIROPQ (1 << 3)
28689 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
28690 +#define au_fset_cpdown(flags, name) \
28691 + do { (flags) |= AuCpdown_##name; } while (0)
28692 +#define au_fclr_cpdown(flags, name) \
28693 + do { (flags) &= ~AuCpdown_##name; } while (0)
28695 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
28696 + unsigned int *flags)
28699 + struct dentry *opq_dentry;
28701 + opq_dentry = au_diropq_create(dentry, bdst);
28702 + err = PTR_ERR(opq_dentry);
28703 + if (IS_ERR(opq_dentry))
28705 + dput(opq_dentry);
28706 + au_fset_cpdown(*flags, DIROPQ);
28712 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
28713 + struct inode *dir, aufs_bindex_t bdst)
28716 + struct path h_path;
28717 + struct au_branch *br;
28719 + br = au_sbr(dentry->d_sb, bdst);
28720 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
28721 + err = PTR_ERR(h_path.dentry);
28722 + if (IS_ERR(h_path.dentry))
28726 + if (h_path.dentry->d_inode) {
28727 + h_path.mnt = au_br_mnt(br);
28728 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
28731 + dput(h_path.dentry);
28737 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
28738 + struct au_pin *pin,
28739 + struct dentry *h_parent, void *arg)
28742 + aufs_bindex_t bopq, bstart;
28743 + struct path h_path;
28744 + struct dentry *parent;
28745 + struct inode *h_dir, *h_inode, *inode, *dir;
28746 + unsigned int *flags = arg;
28748 + bstart = au_dbstart(dentry);
28749 + /* dentry is di-locked */
28750 + parent = dget_parent(dentry);
28751 + dir = parent->d_inode;
28752 + h_dir = h_parent->d_inode;
28753 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
28754 + IMustLock(h_dir);
28756 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
28757 + if (unlikely(err < 0))
28759 + h_path.dentry = au_h_dptr(dentry, bdst);
28760 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
28761 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path,
28762 + S_IRWXU | S_IRUGO | S_IXUGO);
28763 + if (unlikely(err))
28765 + au_fset_cpdown(*flags, MADE_DIR);
28767 + bopq = au_dbdiropq(dentry);
28768 + au_fclr_cpdown(*flags, WHED);
28769 + au_fclr_cpdown(*flags, DIROPQ);
28770 + if (au_dbwh(dentry) == bdst)
28771 + au_fset_cpdown(*flags, WHED);
28772 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
28773 + au_fset_cpdown(*flags, PARENT_OPQ);
28774 + h_inode = h_path.dentry->d_inode;
28775 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
28776 + if (au_ftest_cpdown(*flags, WHED)) {
28777 + err = au_cpdown_dir_opq(dentry, bdst, flags);
28778 + if (unlikely(err)) {
28779 + mutex_unlock(&h_inode->i_mutex);
28784 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, bstart));
28785 + mutex_unlock(&h_inode->i_mutex);
28786 + if (unlikely(err))
28789 + if (au_ftest_cpdown(*flags, WHED)) {
28790 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
28791 + if (unlikely(err))
28795 + inode = dentry->d_inode;
28796 + if (au_ibend(inode) < bdst)
28797 + au_set_ibend(inode, bdst);
28798 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
28799 + au_hi_flags(inode, /*isdir*/1));
28800 + goto out; /* success */
28804 + if (au_ftest_cpdown(*flags, DIROPQ)) {
28805 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
28806 + rerr = au_diropq_remove(dentry, bdst);
28807 + mutex_unlock(&h_inode->i_mutex);
28808 + if (unlikely(rerr)) {
28809 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
28810 + dentry, bdst, rerr);
28816 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
28817 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
28818 + if (unlikely(rerr)) {
28819 + AuIOErr("failed removing %pd b%d (%d)\n",
28820 + dentry, bdst, rerr);
28825 + au_set_h_dptr(dentry, bdst, NULL);
28826 + if (au_dbend(dentry) == bdst)
28827 + au_update_dbend(dentry);
28833 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
28836 + unsigned int flags;
28839 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
28844 +/* ---------------------------------------------------------------------- */
28846 +/* policies for create */
28848 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
28850 + int err, i, j, ndentry;
28851 + aufs_bindex_t bopq;
28852 + struct au_dcsub_pages dpages;
28853 + struct au_dpage *dpage;
28854 + struct dentry **dentries, *parent, *d;
28856 + err = au_dpages_init(&dpages, GFP_NOFS);
28857 + if (unlikely(err))
28859 + parent = dget_parent(dentry);
28860 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
28861 + if (unlikely(err))
28865 + for (i = 0; i < dpages.ndpage; i++) {
28866 + dpage = dpages.dpages + i;
28867 + dentries = dpage->dentries;
28868 + ndentry = dpage->ndentry;
28869 + for (j = 0; j < ndentry; j++) {
28871 + di_read_lock_parent2(d, !AuLock_IR);
28872 + bopq = au_dbdiropq(d);
28873 + di_read_unlock(d, !AuLock_IR);
28874 + if (bopq >= 0 && bopq < err)
28881 + au_dpages_free(&dpages);
28886 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
28888 + for (; bindex >= 0; bindex--)
28889 + if (!au_br_rdonly(au_sbr(sb, bindex)))
28894 +/* top down parent */
28895 +static int au_wbr_create_tdp(struct dentry *dentry,
28896 + unsigned int flags __maybe_unused)
28899 + aufs_bindex_t bstart, bindex;
28900 + struct super_block *sb;
28901 + struct dentry *parent, *h_parent;
28903 + sb = dentry->d_sb;
28904 + bstart = au_dbstart(dentry);
28906 + if (!au_br_rdonly(au_sbr(sb, bstart)))
28910 + parent = dget_parent(dentry);
28911 + for (bindex = au_dbstart(parent); bindex < bstart; bindex++) {
28912 + h_parent = au_h_dptr(parent, bindex);
28913 + if (!h_parent || !h_parent->d_inode)
28916 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
28923 + /* bottom up here */
28924 + if (unlikely(err < 0)) {
28925 + err = au_wbr_bu(sb, bstart - 1);
28927 + err = au_wbr_nonopq(dentry, err);
28931 + AuDbg("b%d\n", err);
28935 +/* ---------------------------------------------------------------------- */
28937 +/* an exception for the policy other than tdp */
28938 +static int au_wbr_create_exp(struct dentry *dentry)
28941 + aufs_bindex_t bwh, bdiropq;
28942 + struct dentry *parent;
28945 + bwh = au_dbwh(dentry);
28946 + parent = dget_parent(dentry);
28947 + bdiropq = au_dbdiropq(parent);
28949 + if (bdiropq >= 0)
28950 + err = min(bdiropq, bwh);
28953 + AuDbg("%d\n", err);
28954 + } else if (bdiropq >= 0) {
28956 + AuDbg("%d\n", err);
28961 + err = au_wbr_nonopq(dentry, err);
28963 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
28966 + AuDbg("%d\n", err);
28970 +/* ---------------------------------------------------------------------- */
28973 +static int au_wbr_create_init_rr(struct super_block *sb)
28977 + err = au_wbr_bu(sb, au_sbend(sb));
28978 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
28981 + AuDbg("b%d\n", err);
28985 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
28989 + aufs_bindex_t bindex, bend;
28990 + struct super_block *sb;
28993 + err = au_wbr_create_exp(dentry);
28997 + sb = dentry->d_sb;
28998 + next = &au_sbi(sb)->si_wbr_rr_next;
28999 + bend = au_sbend(sb);
29001 + for (bindex = 0; bindex <= bend; bindex++) {
29002 + if (!au_ftest_wbr(flags, DIR)) {
29003 + err = atomic_dec_return(next) + 1;
29004 + /* modulo for 0 is meaningless */
29005 + if (unlikely(!err))
29006 + err = atomic_dec_return(next) + 1;
29008 + err = atomic_read(next);
29009 + AuDbg("%d\n", err);
29012 + AuDbg("%d\n", err);
29013 + if (!au_br_rdonly(au_sbr(sb, err)))
29019 + err = au_wbr_nonopq(dentry, err);
29022 + AuDbg("%d\n", err);
29026 +/* ---------------------------------------------------------------------- */
29028 +/* most free space */
29029 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
29031 + struct super_block *sb;
29032 + struct au_branch *br;
29033 + struct au_wbr_mfs *mfs;
29034 + struct dentry *h_parent;
29035 + aufs_bindex_t bindex, bend;
29037 + unsigned long long b, bavail;
29038 + struct path h_path;
29039 + /* reduce the stack usage */
29040 + struct kstatfs *st;
29042 + st = kmalloc(sizeof(*st), GFP_NOFS);
29043 + if (unlikely(!st)) {
29044 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
29049 + sb = dentry->d_sb;
29050 + mfs = &au_sbi(sb)->si_wbr_mfs;
29051 + MtxMustLock(&mfs->mfs_lock);
29052 + mfs->mfs_bindex = -EROFS;
29053 + mfs->mfsrr_bytes = 0;
29056 + bend = au_sbend(sb);
29058 + bindex = au_dbstart(parent);
29059 + bend = au_dbtaildir(parent);
29062 + for (; bindex <= bend; bindex++) {
29064 + h_parent = au_h_dptr(parent, bindex);
29065 + if (!h_parent || !h_parent->d_inode)
29068 + br = au_sbr(sb, bindex);
29069 + if (au_br_rdonly(br))
29072 + /* sb->s_root for NFS is unreliable */
29073 + h_path.mnt = au_br_mnt(br);
29074 + h_path.dentry = h_path.mnt->mnt_root;
29075 + err = vfs_statfs(&h_path, st);
29076 + if (unlikely(err)) {
29077 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
29081 + /* when the available size is equal, select the lower one */
29082 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
29083 + || sizeof(b) < sizeof(st->f_bsize));
29084 + b = st->f_bavail * st->f_bsize;
29085 + br->br_wbr->wbr_bytes = b;
29086 + if (b >= bavail) {
29088 + mfs->mfs_bindex = bindex;
29089 + mfs->mfs_jiffy = jiffies;
29093 + mfs->mfsrr_bytes = bavail;
29094 + AuDbg("b%d\n", mfs->mfs_bindex);
29098 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
29101 + struct dentry *parent;
29102 + struct super_block *sb;
29103 + struct au_wbr_mfs *mfs;
29105 + err = au_wbr_create_exp(dentry);
29109 + sb = dentry->d_sb;
29111 + if (au_ftest_wbr(flags, PARENT))
29112 + parent = dget_parent(dentry);
29113 + mfs = &au_sbi(sb)->si_wbr_mfs;
29114 + mutex_lock(&mfs->mfs_lock);
29115 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
29116 + || mfs->mfs_bindex < 0
29117 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
29118 + au_mfs(dentry, parent);
29119 + mutex_unlock(&mfs->mfs_lock);
29120 + err = mfs->mfs_bindex;
29124 + err = au_wbr_nonopq(dentry, err);
29127 + AuDbg("b%d\n", err);
29131 +static int au_wbr_create_init_mfs(struct super_block *sb)
29133 + struct au_wbr_mfs *mfs;
29135 + mfs = &au_sbi(sb)->si_wbr_mfs;
29136 + mutex_init(&mfs->mfs_lock);
29137 + mfs->mfs_jiffy = 0;
29138 + mfs->mfs_bindex = -EROFS;
29143 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
29145 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
29149 +/* ---------------------------------------------------------------------- */
29151 +/* most free space and then round robin */
29152 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
29155 + struct au_wbr_mfs *mfs;
29157 + err = au_wbr_create_mfs(dentry, flags);
29159 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
29160 + mutex_lock(&mfs->mfs_lock);
29161 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
29162 + err = au_wbr_create_rr(dentry, flags);
29163 + mutex_unlock(&mfs->mfs_lock);
29166 + AuDbg("b%d\n", err);
29170 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
29174 + au_wbr_create_init_mfs(sb); /* ignore */
29175 + err = au_wbr_create_init_rr(sb);
29180 +/* ---------------------------------------------------------------------- */
29182 +/* top down parent and most free space */
29183 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
29186 + unsigned long long b;
29187 + aufs_bindex_t bindex, bstart, bend;
29188 + struct super_block *sb;
29189 + struct dentry *parent, *h_parent;
29190 + struct au_branch *br;
29192 + err = au_wbr_create_tdp(dentry, flags);
29193 + if (unlikely(err < 0))
29195 + parent = dget_parent(dentry);
29196 + bstart = au_dbstart(parent);
29197 + bend = au_dbtaildir(parent);
29198 + if (bstart == bend)
29199 + goto out_parent; /* success */
29201 + e2 = au_wbr_create_mfs(dentry, flags);
29203 + goto out_parent; /* success */
29205 + /* when the available size is equal, select upper one */
29206 + sb = dentry->d_sb;
29207 + br = au_sbr(sb, err);
29208 + b = br->br_wbr->wbr_bytes;
29209 + AuDbg("b%d, %llu\n", err, b);
29211 + for (bindex = bstart; bindex <= bend; bindex++) {
29212 + h_parent = au_h_dptr(parent, bindex);
29213 + if (!h_parent || !h_parent->d_inode)
29216 + br = au_sbr(sb, bindex);
29217 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
29218 + b = br->br_wbr->wbr_bytes;
29220 + AuDbg("b%d, %llu\n", err, b);
29225 + err = au_wbr_nonopq(dentry, err);
29230 + AuDbg("b%d\n", err);
29234 +/* ---------------------------------------------------------------------- */
29237 + * - top down parent
29238 + * - most free space with parent
29239 + * - most free space round-robin regardless parent
29241 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
29244 + unsigned long long watermark;
29245 + struct super_block *sb;
29246 + struct au_branch *br;
29247 + struct au_wbr_mfs *mfs;
29249 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
29250 + if (unlikely(err < 0))
29253 + sb = dentry->d_sb;
29254 + br = au_sbr(sb, err);
29255 + mfs = &au_sbi(sb)->si_wbr_mfs;
29256 + mutex_lock(&mfs->mfs_lock);
29257 + watermark = mfs->mfsrr_watermark;
29258 + mutex_unlock(&mfs->mfs_lock);
29259 + if (br->br_wbr->wbr_bytes < watermark)
29260 + /* regardless the parent dir */
29261 + err = au_wbr_create_mfsrr(dentry, flags);
29264 + AuDbg("b%d\n", err);
29268 +/* ---------------------------------------------------------------------- */
29270 +/* policies for copyup */
29272 +/* top down parent */
29273 +static int au_wbr_copyup_tdp(struct dentry *dentry)
29275 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
29278 +/* bottom up parent */
29279 +static int au_wbr_copyup_bup(struct dentry *dentry)
29282 + aufs_bindex_t bindex, bstart;
29283 + struct dentry *parent, *h_parent;
29284 + struct super_block *sb;
29287 + sb = dentry->d_sb;
29288 + parent = dget_parent(dentry);
29289 + bstart = au_dbstart(parent);
29290 + for (bindex = au_dbstart(dentry); bindex >= bstart; bindex--) {
29291 + h_parent = au_h_dptr(parent, bindex);
29292 + if (!h_parent || !h_parent->d_inode)
29295 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
29302 + /* bottom up here */
29303 + if (unlikely(err < 0))
29304 + err = au_wbr_bu(sb, bstart - 1);
29306 + AuDbg("b%d\n", err);
29311 +static int au_wbr_copyup_bu(struct dentry *dentry)
29314 + aufs_bindex_t bstart;
29316 + bstart = au_dbstart(dentry);
29317 + err = au_wbr_bu(dentry->d_sb, bstart);
29318 + AuDbg("b%d\n", err);
29319 + if (err > bstart)
29320 + err = au_wbr_nonopq(dentry, err);
29322 + AuDbg("b%d\n", err);
29326 +/* ---------------------------------------------------------------------- */
29328 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
29329 + [AuWbrCopyup_TDP] = {
29330 + .copyup = au_wbr_copyup_tdp
29332 + [AuWbrCopyup_BUP] = {
29333 + .copyup = au_wbr_copyup_bup
29335 + [AuWbrCopyup_BU] = {
29336 + .copyup = au_wbr_copyup_bu
29340 +struct au_wbr_create_operations au_wbr_create_ops[] = {
29341 + [AuWbrCreate_TDP] = {
29342 + .create = au_wbr_create_tdp
29344 + [AuWbrCreate_RR] = {
29345 + .create = au_wbr_create_rr,
29346 + .init = au_wbr_create_init_rr
29348 + [AuWbrCreate_MFS] = {
29349 + .create = au_wbr_create_mfs,
29350 + .init = au_wbr_create_init_mfs,
29351 + .fin = au_wbr_create_fin_mfs
29353 + [AuWbrCreate_MFSV] = {
29354 + .create = au_wbr_create_mfs,
29355 + .init = au_wbr_create_init_mfs,
29356 + .fin = au_wbr_create_fin_mfs
29358 + [AuWbrCreate_MFSRR] = {
29359 + .create = au_wbr_create_mfsrr,
29360 + .init = au_wbr_create_init_mfsrr,
29361 + .fin = au_wbr_create_fin_mfs
29363 + [AuWbrCreate_MFSRRV] = {
29364 + .create = au_wbr_create_mfsrr,
29365 + .init = au_wbr_create_init_mfsrr,
29366 + .fin = au_wbr_create_fin_mfs
29368 + [AuWbrCreate_PMFS] = {
29369 + .create = au_wbr_create_pmfs,
29370 + .init = au_wbr_create_init_mfs,
29371 + .fin = au_wbr_create_fin_mfs
29373 + [AuWbrCreate_PMFSV] = {
29374 + .create = au_wbr_create_pmfs,
29375 + .init = au_wbr_create_init_mfs,
29376 + .fin = au_wbr_create_fin_mfs
29378 + [AuWbrCreate_PMFSRR] = {
29379 + .create = au_wbr_create_pmfsrr,
29380 + .init = au_wbr_create_init_mfsrr,
29381 + .fin = au_wbr_create_fin_mfs
29383 + [AuWbrCreate_PMFSRRV] = {
29384 + .create = au_wbr_create_pmfsrr,
29385 + .init = au_wbr_create_init_mfsrr,
29386 + .fin = au_wbr_create_fin_mfs
29389 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
29390 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
29391 +++ linux/fs/aufs/whout.c 2014-01-20 20:16:14.749463838 +0100
29394 + * Copyright (C) 2005-2014 Junjiro R. Okajima
29396 + * This program, aufs is free software; you can redistribute it and/or modify
29397 + * it under the terms of the GNU General Public License as published by
29398 + * the Free Software Foundation; either version 2 of the License, or
29399 + * (at your option) any later version.
29401 + * This program is distributed in the hope that it will be useful,
29402 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29403 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29404 + * GNU General Public License for more details.
29406 + * You should have received a copy of the GNU General Public License
29407 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29411 + * whiteout for logical deletion and opaque directory
29416 +#define WH_MASK S_IRUGO
29419 + * If a directory contains this file, then it is opaque. We start with the
29420 + * .wh. flag so that it is blocked by lookup.
29422 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
29423 + sizeof(AUFS_WH_DIROPQ) - 1);
29426 + * generate whiteout name, which is NOT terminated by NULL.
29427 + * @name: original d_name.name
29428 + * @len: original d_name.len
29429 + * @wh: whiteout qstr
29430 + * returns zero when succeeds, otherwise error.
29431 + * succeeded value as wh->name should be freed by kfree().
29433 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
29437 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
29438 + return -ENAMETOOLONG;
29440 + wh->len = name->len + AUFS_WH_PFX_LEN;
29441 + p = kmalloc(wh->len, GFP_NOFS);
29444 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
29445 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
29452 +/* ---------------------------------------------------------------------- */
29455 + * test if the @wh_name exists under @h_parent.
29456 + * @try_sio specifies the necessary of super-io.
29458 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name,
29459 + struct au_branch *br, int try_sio)
29462 + struct dentry *wh_dentry;
29465 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
29467 + wh_dentry = au_sio_lkup_one(wh_name, h_parent, br);
29468 + err = PTR_ERR(wh_dentry);
29469 + if (IS_ERR(wh_dentry))
29473 + if (!wh_dentry->d_inode)
29474 + goto out_wh; /* success */
29477 + if (S_ISREG(wh_dentry->d_inode->i_mode))
29478 + goto out_wh; /* success */
29481 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
29482 + wh_dentry, wh_dentry->d_inode->i_mode);
29491 + * test if the @h_dentry sets opaque or not.
29493 +int au_diropq_test(struct dentry *h_dentry, struct au_branch *br)
29496 + struct inode *h_dir;
29498 + h_dir = h_dentry->d_inode;
29499 + err = au_wh_test(h_dentry, &diropq_name, br,
29500 + au_test_h_perm_sio(h_dir, MAY_EXEC));
29505 + * returns a negative dentry whose name is unique and temporary.
29507 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
29508 + struct qstr *prefix)
29510 + struct dentry *dentry;
29512 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
29514 + /* strict atomic_t is unnecessary here */
29515 + static unsigned short cnt;
29518 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
29521 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
29522 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
29523 + dentry = ERR_PTR(-ENAMETOOLONG);
29524 + if (unlikely(qs.len > NAME_MAX))
29526 + dentry = ERR_PTR(-ENOMEM);
29527 + name = kmalloc(qs.len + 1, GFP_NOFS);
29528 + if (unlikely(!name))
29532 + /* doubly whiteout-ed */
29533 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
29534 + p = name + AUFS_WH_PFX_LEN * 2;
29535 + memcpy(p, prefix->name, prefix->len);
29536 + p += prefix->len;
29538 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
29541 + for (i = 0; i < 3; i++) {
29542 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
29543 + dentry = au_sio_lkup_one(&qs, h_parent, br);
29544 + if (IS_ERR(dentry) || !dentry->d_inode)
29548 + /* pr_warn("could not get random name\n"); */
29549 + dentry = ERR_PTR(-EEXIST);
29550 + AuDbg("%.*s\n", AuLNPair(&qs));
29554 + if (name != defname)
29557 + AuTraceErrPtr(dentry);
29562 + * rename the @h_dentry on @br to the whiteouted temporary name.
29564 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
29567 + struct path h_path = {
29568 + .mnt = au_br_mnt(br)
29570 + struct inode *h_dir, *delegated;
29571 + struct dentry *h_parent;
29573 + h_parent = h_dentry->d_parent; /* dir inode is locked */
29574 + h_dir = h_parent->d_inode;
29575 + IMustLock(h_dir);
29577 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
29578 + err = PTR_ERR(h_path.dentry);
29579 + if (IS_ERR(h_path.dentry))
29582 + /* under the same dir, no need to lock_rename() */
29583 + delegated = NULL;
29584 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated);
29586 + if (unlikely(err == -EWOULDBLOCK)) {
29587 + pr_warn("cannot retry for NFSv4 delegation"
29588 + " for an internal rename\n");
29591 + dput(h_path.dentry);
29598 +/* ---------------------------------------------------------------------- */
29600 + * functions for removing a whiteout
29603 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
29606 + struct inode *delegated;
29609 + * forces superio when the dir has a sticky bit.
29610 + * this may be a violation of unix fs semantics.
29612 + force = (h_dir->i_mode & S_ISVTX)
29613 + && !uid_eq(current_fsuid(), h_path->dentry->d_inode->i_uid);
29614 + delegated = NULL;
29615 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
29616 + if (unlikely(err == -EWOULDBLOCK)) {
29617 + pr_warn("cannot retry for NFSv4 delegation"
29618 + " for an internal unlink\n");
29624 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
29625 + struct dentry *dentry)
29629 + err = do_unlink_wh(h_dir, h_path);
29630 + if (!err && dentry)
29631 + au_set_dbwh(dentry, -1);
29636 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
29637 + struct au_branch *br)
29640 + struct path h_path = {
29641 + .mnt = au_br_mnt(br)
29645 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
29646 + if (IS_ERR(h_path.dentry))
29647 + err = PTR_ERR(h_path.dentry);
29649 + if (h_path.dentry->d_inode
29650 + && S_ISREG(h_path.dentry->d_inode->i_mode))
29651 + err = do_unlink_wh(h_parent->d_inode, &h_path);
29652 + dput(h_path.dentry);
29658 +/* ---------------------------------------------------------------------- */
29660 + * initialize/clean whiteout for a branch
29663 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
29667 + struct inode *delegated;
29669 + if (!whpath->dentry->d_inode)
29673 + err = vfsub_rmdir(h_dir, whpath);
29675 + delegated = NULL;
29676 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
29677 + if (unlikely(err == -EWOULDBLOCK)) {
29678 + pr_warn("cannot retry for NFSv4 delegation"
29679 + " for an internal unlink\n");
29683 + if (unlikely(err))
29684 + pr_warn("failed removing %pd (%d), ignored.\n",
29685 + whpath->dentry, err);
29688 +static int test_linkable(struct dentry *h_root)
29690 + struct inode *h_dir = h_root->d_inode;
29692 + if (h_dir->i_op->link)
29695 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
29696 + h_root, au_sbtype(h_root->d_sb));
29700 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
29701 +static int au_whdir(struct inode *h_dir, struct path *path)
29706 + if (!path->dentry->d_inode) {
29707 + int mode = S_IRWXU;
29709 + if (au_test_nfs(path->dentry->d_sb))
29711 + err = vfsub_mkdir(h_dir, path, mode);
29712 + } else if (S_ISDIR(path->dentry->d_inode->i_mode))
29715 + pr_err("unknown %pd exists\n", path->dentry);
29720 +struct au_wh_base {
29721 + const struct qstr *name;
29722 + struct dentry *dentry;
29725 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
29726 + struct path *h_path)
29728 + h_path->dentry = base[AuBrWh_BASE].dentry;
29729 + au_wh_clean(h_dir, h_path, /*isdir*/0);
29730 + h_path->dentry = base[AuBrWh_PLINK].dentry;
29731 + au_wh_clean(h_dir, h_path, /*isdir*/1);
29732 + h_path->dentry = base[AuBrWh_ORPH].dentry;
29733 + au_wh_clean(h_dir, h_path, /*isdir*/1);
29737 + * returns tri-state,
29738 + * minus: error, caller should print the mesage
29740 + * plus: error, caller should NOT print the mesage
29742 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
29743 + int do_plink, struct au_wh_base base[],
29744 + struct path *h_path)
29747 + struct inode *h_dir;
29749 + h_dir = h_root->d_inode;
29750 + h_path->dentry = base[AuBrWh_BASE].dentry;
29751 + au_wh_clean(h_dir, h_path, /*isdir*/0);
29752 + h_path->dentry = base[AuBrWh_PLINK].dentry;
29754 + err = test_linkable(h_root);
29755 + if (unlikely(err)) {
29760 + err = au_whdir(h_dir, h_path);
29761 + if (unlikely(err))
29763 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
29765 + au_wh_clean(h_dir, h_path, /*isdir*/1);
29766 + h_path->dentry = base[AuBrWh_ORPH].dentry;
29767 + err = au_whdir(h_dir, h_path);
29768 + if (unlikely(err))
29770 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
29777 + * for the moment, aufs supports the branch filesystem which does not support
29778 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
29779 + * copyup failed. finally, such filesystem will not be used as the writable
29782 + * returns tri-state, see above.
29784 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
29785 + int do_plink, struct au_wh_base base[],
29786 + struct path *h_path)
29789 + struct inode *h_dir;
29791 + WbrWhMustWriteLock(wbr);
29793 + err = test_linkable(h_root);
29794 + if (unlikely(err)) {
29800 + * todo: should this create be done in /sbin/mount.aufs helper?
29803 + h_dir = h_root->d_inode;
29804 + if (!base[AuBrWh_BASE].dentry->d_inode) {
29805 + h_path->dentry = base[AuBrWh_BASE].dentry;
29806 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
29807 + } else if (S_ISREG(base[AuBrWh_BASE].dentry->d_inode->i_mode))
29810 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
29811 + if (unlikely(err))
29814 + h_path->dentry = base[AuBrWh_PLINK].dentry;
29816 + err = au_whdir(h_dir, h_path);
29817 + if (unlikely(err))
29819 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
29821 + au_wh_clean(h_dir, h_path, /*isdir*/1);
29822 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
29824 + h_path->dentry = base[AuBrWh_ORPH].dentry;
29825 + err = au_whdir(h_dir, h_path);
29826 + if (unlikely(err))
29828 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
29835 + * initialize the whiteout base file/dir for @br.
29837 +int au_wh_init(struct au_branch *br, struct super_block *sb)
29840 + const unsigned char do_plink
29841 + = !!au_opt_test(au_mntflags(sb), PLINK);
29842 + struct inode *h_dir;
29843 + struct path path = br->br_path;
29844 + struct dentry *h_root = path.dentry;
29845 + struct au_wbr *wbr = br->br_wbr;
29846 + static const struct qstr base_name[] = {
29847 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
29848 + sizeof(AUFS_BASE_NAME) - 1),
29849 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
29850 + sizeof(AUFS_PLINKDIR_NAME) - 1),
29851 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
29852 + sizeof(AUFS_ORPHDIR_NAME) - 1)
29854 + struct au_wh_base base[] = {
29855 + [AuBrWh_BASE] = {
29856 + .name = base_name + AuBrWh_BASE,
29859 + [AuBrWh_PLINK] = {
29860 + .name = base_name + AuBrWh_PLINK,
29863 + [AuBrWh_ORPH] = {
29864 + .name = base_name + AuBrWh_ORPH,
29870 + WbrWhMustWriteLock(wbr);
29872 + for (i = 0; i < AuBrWh_Last; i++) {
29873 + /* doubly whiteouted */
29874 + struct dentry *d;
29876 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
29877 + err = PTR_ERR(d);
29881 + base[i].dentry = d;
29883 + && wbr->wbr_wh[i]
29884 + && wbr->wbr_wh[i] != base[i].dentry);
29888 + for (i = 0; i < AuBrWh_Last; i++) {
29889 + dput(wbr->wbr_wh[i]);
29890 + wbr->wbr_wh[i] = NULL;
29894 + if (!au_br_writable(br->br_perm)) {
29895 + h_dir = h_root->d_inode;
29896 + au_wh_init_ro(h_dir, base, &path);
29897 + } else if (!au_br_wh_linkable(br->br_perm)) {
29898 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
29904 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
29910 + goto out; /* success */
29913 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
29914 + err, h_root, au_sbtype(h_root->d_sb));
29916 + for (i = 0; i < AuBrWh_Last; i++)
29917 + dput(base[i].dentry);
29921 +/* ---------------------------------------------------------------------- */
29923 + * whiteouts are all hard-linked usually.
29924 + * when its link count reaches a ceiling, we create a new whiteout base
29925 + * asynchronously.
29928 +struct reinit_br_wh {
29929 + struct super_block *sb;
29930 + struct au_branch *br;
29933 +static void reinit_br_wh(void *arg)
29936 + aufs_bindex_t bindex;
29937 + struct path h_path;
29938 + struct reinit_br_wh *a = arg;
29939 + struct au_wbr *wbr;
29940 + struct inode *dir, *delegated;
29941 + struct dentry *h_root;
29942 + struct au_hinode *hdir;
29945 + wbr = a->br->br_wbr;
29946 + /* big aufs lock */
29947 + si_noflush_write_lock(a->sb);
29948 + if (!au_br_writable(a->br->br_perm))
29950 + bindex = au_br_index(a->sb, a->br->br_id);
29951 + if (unlikely(bindex < 0))
29954 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
29955 + dir = a->sb->s_root->d_inode;
29956 + hdir = au_hi(dir, bindex);
29957 + h_root = au_h_dptr(a->sb->s_root, bindex);
29958 + AuDebugOn(h_root != au_br_dentry(a->br));
29960 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
29961 + wbr_wh_write_lock(wbr);
29962 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
29965 + h_path.dentry = wbr->wbr_whbase;
29966 + h_path.mnt = au_br_mnt(a->br);
29967 + delegated = NULL;
29968 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
29970 + if (unlikely(err == -EWOULDBLOCK)) {
29971 + pr_warn("cannot retry for NFSv4 delegation"
29972 + " for an internal unlink\n");
29976 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
29979 + dput(wbr->wbr_whbase);
29980 + wbr->wbr_whbase = NULL;
29982 + err = au_wh_init(a->br, a->sb);
29983 + wbr_wh_write_unlock(wbr);
29984 + au_hn_imtx_unlock(hdir);
29985 + di_read_unlock(a->sb->s_root, AuLock_IR);
29989 + atomic_dec(&wbr->wbr_wh_running);
29990 + atomic_dec(&a->br->br_count);
29991 + si_write_unlock(a->sb);
29992 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
29994 + if (unlikely(err))
29995 + AuIOErr("err %d\n", err);
29998 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
30000 + int do_dec, wkq_err;
30001 + struct reinit_br_wh *arg;
30004 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
30007 + /* ignore ENOMEM */
30008 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
30011 + * dec(wh_running), kfree(arg) and dec(br_count)
30012 + * in reinit function
30016 + atomic_inc(&br->br_count);
30017 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
30018 + if (unlikely(wkq_err)) {
30019 + atomic_dec(&br->br_wbr->wbr_wh_running);
30020 + atomic_dec(&br->br_count);
30028 + atomic_dec(&br->br_wbr->wbr_wh_running);
30031 +/* ---------------------------------------------------------------------- */
30034 + * create the whiteout @wh.
30036 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
30037 + struct dentry *wh)
30040 + struct path h_path = {
30043 + struct au_branch *br;
30044 + struct au_wbr *wbr;
30045 + struct dentry *h_parent;
30046 + struct inode *h_dir, *delegated;
30048 + h_parent = wh->d_parent; /* dir inode is locked */
30049 + h_dir = h_parent->d_inode;
30050 + IMustLock(h_dir);
30052 + br = au_sbr(sb, bindex);
30053 + h_path.mnt = au_br_mnt(br);
30054 + wbr = br->br_wbr;
30055 + wbr_wh_read_lock(wbr);
30056 + if (wbr->wbr_whbase) {
30057 + delegated = NULL;
30058 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
30059 + if (unlikely(err == -EWOULDBLOCK)) {
30060 + pr_warn("cannot retry for NFSv4 delegation"
30061 + " for an internal link\n");
30064 + if (!err || err != -EMLINK)
30067 + /* link count full. re-initialize br_whbase. */
30068 + kick_reinit_br_wh(sb, br);
30071 + /* return this error in this context */
30072 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
30075 + wbr_wh_read_unlock(wbr);
30079 +/* ---------------------------------------------------------------------- */
30082 + * create or remove the diropq.
30084 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
30085 + unsigned int flags)
30087 + struct dentry *opq_dentry, *h_dentry;
30088 + struct super_block *sb;
30089 + struct au_branch *br;
30092 + sb = dentry->d_sb;
30093 + br = au_sbr(sb, bindex);
30094 + h_dentry = au_h_dptr(dentry, bindex);
30095 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
30096 + if (IS_ERR(opq_dentry))
30099 + if (au_ftest_diropq(flags, CREATE)) {
30100 + err = link_or_create_wh(sb, bindex, opq_dentry);
30102 + au_set_dbdiropq(dentry, bindex);
30103 + goto out; /* success */
30106 + struct path tmp = {
30107 + .dentry = opq_dentry,
30108 + .mnt = au_br_mnt(br)
30110 + err = do_unlink_wh(au_h_iptr(dentry->d_inode, bindex), &tmp);
30112 + au_set_dbdiropq(dentry, -1);
30114 + dput(opq_dentry);
30115 + opq_dentry = ERR_PTR(err);
30118 + return opq_dentry;
30121 +struct do_diropq_args {
30122 + struct dentry **errp;
30123 + struct dentry *dentry;
30124 + aufs_bindex_t bindex;
30125 + unsigned int flags;
30128 +static void call_do_diropq(void *args)
30130 + struct do_diropq_args *a = args;
30131 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
30134 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
30135 + unsigned int flags)
30137 + struct dentry *diropq, *h_dentry;
30139 + h_dentry = au_h_dptr(dentry, bindex);
30140 + if (!au_test_h_perm_sio(h_dentry->d_inode, MAY_EXEC | MAY_WRITE))
30141 + diropq = do_diropq(dentry, bindex, flags);
30144 + struct do_diropq_args args = {
30146 + .dentry = dentry,
30147 + .bindex = bindex,
30151 + wkq_err = au_wkq_wait(call_do_diropq, &args);
30152 + if (unlikely(wkq_err))
30153 + diropq = ERR_PTR(wkq_err);
30159 +/* ---------------------------------------------------------------------- */
30162 + * lookup whiteout dentry.
30163 + * @h_parent: lower parent dentry which must exist and be locked
30164 + * @base_name: name of dentry which will be whiteouted
30165 + * returns dentry for whiteout.
30167 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
30168 + struct au_branch *br)
30171 + struct qstr wh_name;
30172 + struct dentry *wh_dentry;
30174 + err = au_wh_name_alloc(&wh_name, base_name);
30175 + wh_dentry = ERR_PTR(err);
30177 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
30178 + kfree(wh_name.name);
30180 + return wh_dentry;
30184 + * link/create a whiteout for @dentry on @bindex.
30186 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
30187 + struct dentry *h_parent)
30189 + struct dentry *wh_dentry;
30190 + struct super_block *sb;
30193 + sb = dentry->d_sb;
30194 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
30195 + if (!IS_ERR(wh_dentry) && !wh_dentry->d_inode) {
30196 + err = link_or_create_wh(sb, bindex, wh_dentry);
30198 + au_set_dbwh(dentry, bindex);
30201 + wh_dentry = ERR_PTR(err);
30205 + return wh_dentry;
30208 +/* ---------------------------------------------------------------------- */
30210 +/* Delete all whiteouts in this directory on branch bindex. */
30211 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
30212 + aufs_bindex_t bindex, struct au_branch *br)
30215 + unsigned long ul, n;
30216 + struct qstr wh_name;
30218 + struct hlist_head *head;
30219 + struct au_vdir_wh *pos;
30220 + struct au_vdir_destr *str;
30223 + p = (void *)__get_free_page(GFP_NOFS);
30224 + wh_name.name = p;
30225 + if (unlikely(!wh_name.name))
30229 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
30230 + p += AUFS_WH_PFX_LEN;
30231 + n = whlist->nh_num;
30232 + head = whlist->nh_head;
30233 + for (ul = 0; !err && ul < n; ul++, head++) {
30234 + hlist_for_each_entry(pos, head, wh_hash) {
30235 + if (pos->wh_bindex != bindex)
30238 + str = &pos->wh_str;
30239 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
30240 + memcpy(p, str->name, str->len);
30241 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
30242 + err = unlink_wh_name(h_dentry, &wh_name, br);
30247 + AuIOErr("whiteout name too long %.*s\n",
30248 + str->len, str->name);
30253 + free_page((unsigned long)wh_name.name);
30259 +struct del_wh_children_args {
30261 + struct dentry *h_dentry;
30262 + struct au_nhash *whlist;
30263 + aufs_bindex_t bindex;
30264 + struct au_branch *br;
30267 +static void call_del_wh_children(void *args)
30269 + struct del_wh_children_args *a = args;
30270 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
30273 +/* ---------------------------------------------------------------------- */
30275 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
30277 + struct au_whtmp_rmdir *whtmp;
30279 + unsigned int rdhash;
30281 + SiMustAnyLock(sb);
30283 + whtmp = kmalloc(sizeof(*whtmp), gfp);
30284 + if (unlikely(!whtmp)) {
30285 + whtmp = ERR_PTR(-ENOMEM);
30289 + whtmp->dir = NULL;
30290 + whtmp->br = NULL;
30291 + whtmp->wh_dentry = NULL;
30292 + /* no estimation for dir size */
30293 + rdhash = au_sbi(sb)->si_rdhash;
30295 + rdhash = AUFS_RDHASH_DEF;
30296 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
30297 + if (unlikely(err)) {
30299 + whtmp = ERR_PTR(err);
30306 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
30309 + atomic_dec(&whtmp->br->br_count);
30310 + dput(whtmp->wh_dentry);
30311 + iput(whtmp->dir);
30312 + au_nhash_wh_free(&whtmp->whlist);
30317 + * rmdir the whiteouted temporary named dir @h_dentry.
30318 + * @whlist: whiteouted children.
30320 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
30321 + struct dentry *wh_dentry, struct au_nhash *whlist)
30324 + struct path h_tmp;
30325 + struct inode *wh_inode, *h_dir;
30326 + struct au_branch *br;
30328 + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
30329 + IMustLock(h_dir);
30331 + br = au_sbr(dir->i_sb, bindex);
30332 + wh_inode = wh_dentry->d_inode;
30333 + mutex_lock_nested(&wh_inode->i_mutex, AuLsc_I_CHILD);
30336 + * someone else might change some whiteouts while we were sleeping.
30337 + * it means this whlist may have an obsoleted entry.
30339 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
30340 + err = del_wh_children(wh_dentry, whlist, bindex, br);
30343 + struct del_wh_children_args args = {
30345 + .h_dentry = wh_dentry,
30346 + .whlist = whlist,
30347 + .bindex = bindex,
30351 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
30352 + if (unlikely(wkq_err))
30355 + mutex_unlock(&wh_inode->i_mutex);
30358 + h_tmp.dentry = wh_dentry;
30359 + h_tmp.mnt = au_br_mnt(br);
30360 + err = vfsub_rmdir(h_dir, &h_tmp);
30364 + if (au_ibstart(dir) == bindex) {
30365 + /* todo: dir->i_mutex is necessary */
30366 + au_cpup_attr_timesizes(dir);
30367 + vfsub_drop_nlink(dir);
30369 + return 0; /* success */
30372 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
30376 +static void call_rmdir_whtmp(void *args)
30379 + aufs_bindex_t bindex;
30380 + struct au_whtmp_rmdir *a = args;
30381 + struct super_block *sb;
30382 + struct dentry *h_parent;
30383 + struct inode *h_dir;
30384 + struct au_hinode *hdir;
30386 + /* rmdir by nfsd may cause deadlock with this i_mutex */
30387 + /* mutex_lock(&a->dir->i_mutex); */
30389 + sb = a->dir->i_sb;
30390 + si_read_lock(sb, !AuLock_FLUSH);
30391 + if (!au_br_writable(a->br->br_perm))
30393 + bindex = au_br_index(sb, a->br->br_id);
30394 + if (unlikely(bindex < 0))
30398 + ii_write_lock_parent(a->dir);
30399 + h_parent = dget_parent(a->wh_dentry);
30400 + h_dir = h_parent->d_inode;
30401 + hdir = au_hi(a->dir, bindex);
30402 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
30403 + if (unlikely(err))
30405 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
30406 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
30409 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
30410 + au_hn_imtx_unlock(hdir);
30411 + vfsub_mnt_drop_write(au_br_mnt(a->br));
30415 + ii_write_unlock(a->dir);
30417 + /* mutex_unlock(&a->dir->i_mutex); */
30418 + au_whtmp_rmdir_free(a);
30419 + si_read_unlock(sb);
30420 + au_nwt_done(&au_sbi(sb)->si_nowait);
30421 + if (unlikely(err))
30422 + AuIOErr("err %d\n", err);
30425 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
30426 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
30429 + struct super_block *sb;
30433 + /* all post-process will be done in do_rmdir_whtmp(). */
30435 + args->dir = au_igrab(dir);
30436 + args->br = au_sbr(sb, bindex);
30437 + atomic_inc(&args->br->br_count);
30438 + args->wh_dentry = dget(wh_dentry);
30439 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
30440 + if (unlikely(wkq_err)) {
30441 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
30442 + au_whtmp_rmdir_free(args);
30445 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
30446 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
30447 +++ linux/fs/aufs/whout.h 2014-01-20 20:16:14.749463838 +0100
30450 + * Copyright (C) 2005-2014 Junjiro R. Okajima
30452 + * This program, aufs is free software; you can redistribute it and/or modify
30453 + * it under the terms of the GNU General Public License as published by
30454 + * the Free Software Foundation; either version 2 of the License, or
30455 + * (at your option) any later version.
30457 + * This program is distributed in the hope that it will be useful,
30458 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30459 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30460 + * GNU General Public License for more details.
30462 + * You should have received a copy of the GNU General Public License
30463 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30467 + * whiteout for logical deletion and opaque directory
30470 +#ifndef __AUFS_WHOUT_H__
30471 +#define __AUFS_WHOUT_H__
30478 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
30480 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name,
30481 + struct au_branch *br, int try_sio);
30482 +int au_diropq_test(struct dentry *h_dentry, struct au_branch *br);
30483 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
30484 + struct qstr *prefix);
30485 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
30486 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
30487 + struct dentry *dentry);
30488 +int au_wh_init(struct au_branch *br, struct super_block *sb);
30490 +/* diropq flags */
30491 +#define AuDiropq_CREATE 1
30492 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
30493 +#define au_fset_diropq(flags, name) \
30494 + do { (flags) |= AuDiropq_##name; } while (0)
30495 +#define au_fclr_diropq(flags, name) \
30496 + do { (flags) &= ~AuDiropq_##name; } while (0)
30498 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
30499 + unsigned int flags);
30500 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
30501 + struct au_branch *br);
30502 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
30503 + struct dentry *h_parent);
30505 +/* real rmdir for the whiteout-ed dir */
30506 +struct au_whtmp_rmdir {
30507 + struct inode *dir;
30508 + struct au_branch *br;
30509 + struct dentry *wh_dentry;
30510 + struct au_nhash whlist;
30513 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
30514 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
30515 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
30516 + struct dentry *wh_dentry, struct au_nhash *whlist);
30517 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
30518 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
30520 +/* ---------------------------------------------------------------------- */
30522 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
30523 + aufs_bindex_t bindex)
30525 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
30528 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
30530 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
30533 +#endif /* __KERNEL__ */
30534 +#endif /* __AUFS_WHOUT_H__ */
30535 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
30536 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
30537 +++ linux/fs/aufs/wkq.c 2014-01-20 20:16:14.749463838 +0100
30540 + * Copyright (C) 2005-2014 Junjiro R. Okajima
30542 + * This program, aufs is free software; you can redistribute it and/or modify
30543 + * it under the terms of the GNU General Public License as published by
30544 + * the Free Software Foundation; either version 2 of the License, or
30545 + * (at your option) any later version.
30547 + * This program is distributed in the hope that it will be useful,
30548 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30549 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30550 + * GNU General Public License for more details.
30552 + * You should have received a copy of the GNU General Public License
30553 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30557 + * workqueue for asynchronous/super-io operations
30558 + * todo: try new dredential scheme
30561 +#include <linux/module.h>
30564 +/* internal workqueue named AUFS_WKQ_NAME */
30566 +static struct workqueue_struct *au_wkq;
30568 +struct au_wkinfo {
30569 + struct work_struct wk;
30570 + struct kobject *kobj;
30572 + unsigned int flags; /* see wkq.h */
30574 + au_wkq_func_t func;
30577 + struct completion *comp;
30580 +/* ---------------------------------------------------------------------- */
30582 +static void wkq_func(struct work_struct *wk)
30584 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
30586 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
30587 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
30589 + wkinfo->func(wkinfo->args);
30590 + if (au_ftest_wkq(wkinfo->flags, WAIT))
30591 + complete(wkinfo->comp);
30593 + kobject_put(wkinfo->kobj);
30594 + module_put(THIS_MODULE); /* todo: ?? */
30600 + * Since struct completion is large, try allocating it dynamically.
30602 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
30603 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
30605 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
30607 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
30609 + init_completion(*comp);
30610 + wkinfo->comp = *comp;
30616 +static void au_wkq_comp_free(struct completion *comp)
30624 +#define AuWkqCompDeclare(name) \
30625 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
30626 + struct completion *comp = &_ ## name
30628 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
30630 + wkinfo->comp = *comp;
30634 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
30638 +#endif /* 4KSTACKS */
30640 +static void au_wkq_run(struct au_wkinfo *wkinfo)
30642 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
30643 + if (au_wkq_test()) {
30644 + AuWarn1("wkq from wkq, due to a dead dir by UDBA?\n");
30645 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
30648 + au_dbg_verify_kthread();
30650 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
30651 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
30652 + queue_work(au_wkq, &wkinfo->wk);
30654 + INIT_WORK(&wkinfo->wk, wkq_func);
30655 + schedule_work(&wkinfo->wk);
30660 + * Be careful. It is easy to make deadlock happen.
30661 + * processA: lock, wkq and wait
30662 + * processB: wkq and wait, lock in wkq
30665 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
30668 + AuWkqCompDeclare(comp);
30669 + struct au_wkinfo wkinfo = {
30675 + err = au_wkq_comp_alloc(&wkinfo, &comp);
30677 + au_wkq_run(&wkinfo);
30678 + /* no timeout, no interrupt */
30679 + wait_for_completion(wkinfo.comp);
30680 + au_wkq_comp_free(comp);
30681 + destroy_work_on_stack(&wkinfo.wk);
30689 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
30690 + * problem in a concurrent umounting.
30692 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
30693 + unsigned int flags)
30696 + struct au_wkinfo *wkinfo;
30698 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
30701 + * wkq_func() must free this wkinfo.
30702 + * it highly depends upon the implementation of workqueue.
30705 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
30707 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
30708 + wkinfo->flags = flags & ~AuWkq_WAIT;
30709 + wkinfo->func = func;
30710 + wkinfo->args = args;
30711 + wkinfo->comp = NULL;
30712 + kobject_get(wkinfo->kobj);
30713 + __module_get(THIS_MODULE); /* todo: ?? */
30715 + au_wkq_run(wkinfo);
30718 + au_nwt_done(&au_sbi(sb)->si_nowait);
30724 +/* ---------------------------------------------------------------------- */
30726 +void au_nwt_init(struct au_nowait_tasks *nwt)
30728 + atomic_set(&nwt->nw_len, 0);
30729 + /* smp_mb(); */ /* atomic_set */
30730 + init_waitqueue_head(&nwt->nw_wq);
30733 +void au_wkq_fin(void)
30735 + destroy_workqueue(au_wkq);
30738 +int __init au_wkq_init(void)
30743 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
30744 + if (IS_ERR(au_wkq))
30745 + err = PTR_ERR(au_wkq);
30746 + else if (!au_wkq)
30751 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
30752 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
30753 +++ linux/fs/aufs/wkq.h 2014-01-20 20:16:14.752797282 +0100
30756 + * Copyright (C) 2005-2014 Junjiro R. Okajima
30758 + * This program, aufs is free software; you can redistribute it and/or modify
30759 + * it under the terms of the GNU General Public License as published by
30760 + * the Free Software Foundation; either version 2 of the License, or
30761 + * (at your option) any later version.
30763 + * This program is distributed in the hope that it will be useful,
30764 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30765 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30766 + * GNU General Public License for more details.
30768 + * You should have received a copy of the GNU General Public License
30769 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30773 + * workqueue for asynchronous/super-io operations
30774 + * todo: try new credentials management scheme
30777 +#ifndef __AUFS_WKQ_H__
30778 +#define __AUFS_WKQ_H__
30782 +struct super_block;
30784 +/* ---------------------------------------------------------------------- */
30787 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
30789 +struct au_nowait_tasks {
30791 + wait_queue_head_t nw_wq;
30794 +/* ---------------------------------------------------------------------- */
30796 +typedef void (*au_wkq_func_t)(void *args);
30799 +#define AuWkq_WAIT 1
30800 +#define AuWkq_NEST (1 << 1)
30801 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
30802 +#define au_fset_wkq(flags, name) \
30803 + do { (flags) |= AuWkq_##name; } while (0)
30804 +#define au_fclr_wkq(flags, name) \
30805 + do { (flags) &= ~AuWkq_##name; } while (0)
30807 +#ifndef CONFIG_AUFS_HNOTIFY
30809 +#define AuWkq_NEST 0
30813 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
30814 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
30815 + unsigned int flags);
30816 +void au_nwt_init(struct au_nowait_tasks *nwt);
30817 +int __init au_wkq_init(void);
30818 +void au_wkq_fin(void);
30820 +/* ---------------------------------------------------------------------- */
30822 +static inline int au_wkq_test(void)
30824 + return current->flags & PF_WQ_WORKER;
30827 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
30829 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
30832 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
30834 + if (atomic_dec_and_test(&nwt->nw_len))
30835 + wake_up_all(&nwt->nw_wq);
30838 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
30840 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
30844 +#endif /* __KERNEL__ */
30845 +#endif /* __AUFS_WKQ_H__ */
30846 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
30847 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
30848 +++ linux/fs/aufs/xino.c 2014-01-20 20:16:14.752797282 +0100
30851 + * Copyright (C) 2005-2014 Junjiro R. Okajima
30853 + * This program, aufs is free software; you can redistribute it and/or modify
30854 + * it under the terms of the GNU General Public License as published by
30855 + * the Free Software Foundation; either version 2 of the License, or
30856 + * (at your option) any later version.
30858 + * This program is distributed in the hope that it will be useful,
30859 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30860 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30861 + * GNU General Public License for more details.
30863 + * You should have received a copy of the GNU General Public License
30864 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30868 + * external inode number translation table and bitmap
30871 +#include <linux/seq_file.h>
30872 +#include <linux/statfs.h>
30875 +/* todo: unnecessary to support mmap_sem since kernel-space? */
30876 +ssize_t xino_fread(au_readf_t func, struct file *file, void *kbuf, size_t size,
30880 + mm_segment_t oldfs;
30887 + oldfs = get_fs();
30888 + set_fs(KERNEL_DS);
30890 + /* todo: signal_pending? */
30891 + err = func(file, buf.u, size, pos);
30892 + } while (err == -EAGAIN || err == -EINTR);
30895 +#if 0 /* reserved for future use */
30897 + fsnotify_access(file->f_dentry);
30903 +/* ---------------------------------------------------------------------- */
30905 +static ssize_t do_xino_fwrite(au_writef_t func, struct file *file, void *kbuf,
30906 + size_t size, loff_t *pos)
30909 + mm_segment_t oldfs;
30912 + const char __user *u;
30916 + oldfs = get_fs();
30917 + set_fs(KERNEL_DS);
30919 + /* todo: signal_pending? */
30920 + err = func(file, buf.u, size, pos);
30921 + } while (err == -EAGAIN || err == -EINTR);
30924 +#if 0 /* reserved for future use */
30926 + fsnotify_modify(file->f_dentry);
30932 +struct do_xino_fwrite_args {
30934 + au_writef_t func;
30935 + struct file *file;
30941 +static void call_do_xino_fwrite(void *args)
30943 + struct do_xino_fwrite_args *a = args;
30944 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
30947 +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size,
30952 + /* todo: signal block and no wkq? */
30953 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
30955 + err = do_xino_fwrite(func, file, buf, size, pos);
30959 + * it breaks RLIMIT_FSIZE and normal user's limit,
30960 + * users should care about quota and real 'filesystem full.'
30963 + struct do_xino_fwrite_args args = {
30972 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
30973 + if (unlikely(wkq_err))
30980 +/* ---------------------------------------------------------------------- */
30983 + * create a new xinofile at the same place/path as @base_file.
30985 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src)
30987 + struct file *file;
30988 + struct dentry *base, *parent;
30989 + struct inode *dir, *delegated;
30990 + struct qstr *name;
30991 + struct path path;
30994 + base = base_file->f_dentry;
30995 + parent = base->d_parent; /* dir inode is locked */
30996 + dir = parent->d_inode;
30999 + file = ERR_PTR(-EINVAL);
31000 + name = &base->d_name;
31001 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
31002 + if (IS_ERR(path.dentry)) {
31003 + file = (void *)path.dentry;
31004 + pr_err("%pd lookup err %ld\n",
31005 + base, PTR_ERR(path.dentry));
31009 + /* no need to mnt_want_write() since we call dentry_open() later */
31010 + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL);
31011 + if (unlikely(err)) {
31012 + file = ERR_PTR(err);
31013 + pr_err("%pd create err %d\n", base, err);
31017 + path.mnt = base_file->f_path.mnt;
31018 + file = vfsub_dentry_open(&path,
31019 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
31020 + /* | __FMODE_NONOTIFY */);
31021 + if (IS_ERR(file)) {
31022 + pr_err("%pd open err %ld\n", base, PTR_ERR(file));
31026 + delegated = NULL;
31027 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
31028 + if (unlikely(err == -EWOULDBLOCK)) {
31029 + pr_warn("cannot retry for NFSv4 delegation"
31030 + " for an internal unlink\n");
31033 + if (unlikely(err)) {
31034 + pr_err("%pd unlink err %d\n", base, err);
31039 + /* no one can touch copy_src xino */
31040 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
31041 + if (unlikely(err)) {
31042 + pr_err("%pd copy err %d\n", base, err);
31046 + goto out_dput; /* success */
31050 + file = ERR_PTR(err);
31052 + dput(path.dentry);
31057 +struct au_xino_lock_dir {
31058 + struct au_hinode *hdir;
31059 + struct dentry *parent;
31060 + struct mutex *mtx;
31063 +static void au_xino_lock_dir(struct super_block *sb, struct file *xino,
31064 + struct au_xino_lock_dir *ldir)
31066 + aufs_bindex_t brid, bindex;
31068 + ldir->hdir = NULL;
31070 + brid = au_xino_brid(sb);
31072 + bindex = au_br_index(sb, brid);
31073 + if (bindex >= 0) {
31074 + ldir->hdir = au_hi(sb->s_root->d_inode, bindex);
31075 + au_hn_imtx_lock_nested(ldir->hdir, AuLsc_I_PARENT);
31077 + ldir->parent = dget_parent(xino->f_dentry);
31078 + ldir->mtx = &ldir->parent->d_inode->i_mutex;
31079 + mutex_lock_nested(ldir->mtx, AuLsc_I_PARENT);
31083 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
31086 + au_hn_imtx_unlock(ldir->hdir);
31088 + mutex_unlock(ldir->mtx);
31089 + dput(ldir->parent);
31093 +/* ---------------------------------------------------------------------- */
31095 +/* trucate xino files asynchronously */
31097 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
31100 + unsigned long jiffy;
31102 + aufs_bindex_t bi, bend;
31103 + struct kstatfs *st;
31104 + struct au_branch *br;
31105 + struct file *new_xino, *file;
31106 + struct super_block *h_sb;
31107 + struct au_xino_lock_dir ldir;
31110 + st = kzalloc(sizeof(*st), GFP_NOFS);
31111 + if (unlikely(!st))
31115 + bend = au_sbend(sb);
31116 + if (unlikely(bindex < 0 || bend < bindex))
31118 + br = au_sbr(sb, bindex);
31119 + file = br->br_xino.xi_file;
31123 + err = vfs_statfs(&file->f_path, st);
31124 + if (unlikely(err))
31125 + AuErr1("statfs err %d, ignored\n", err);
31127 + blocks = file_inode(file)->i_blocks;
31128 + pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
31129 + bindex, (u64)blocks, st->f_bfree, st->f_blocks);
31131 + au_xino_lock_dir(sb, file, &ldir);
31132 + /* mnt_want_write() is unnecessary here */
31133 + new_xino = au_xino_create2(file, file);
31134 + au_xino_unlock_dir(&ldir);
31135 + err = PTR_ERR(new_xino);
31136 + if (IS_ERR(new_xino)) {
31137 + pr_err("err %d, ignored\n", err);
31142 + br->br_xino.xi_file = new_xino;
31144 + h_sb = au_br_sb(br);
31145 + for (bi = 0; bi <= bend; bi++) {
31146 + if (unlikely(bi == bindex))
31148 + br = au_sbr(sb, bi);
31149 + if (au_br_sb(br) != h_sb)
31152 + fput(br->br_xino.xi_file);
31153 + br->br_xino.xi_file = new_xino;
31154 + get_file(new_xino);
31157 + err = vfs_statfs(&new_xino->f_path, st);
31159 + pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
31160 + bindex, (u64)file_inode(new_xino)->i_blocks,
31161 + st->f_bfree, st->f_blocks);
31162 + if (file_inode(new_xino)->i_blocks < blocks)
31163 + au_sbi(sb)->si_xino_jiffy = jiffy;
31165 + AuErr1("statfs err %d, ignored\n", err);
31173 +struct xino_do_trunc_args {
31174 + struct super_block *sb;
31175 + struct au_branch *br;
31178 +static void xino_do_trunc(void *_args)
31180 + struct xino_do_trunc_args *args = _args;
31181 + struct super_block *sb;
31182 + struct au_branch *br;
31183 + struct inode *dir;
31185 + aufs_bindex_t bindex;
31189 + dir = sb->s_root->d_inode;
31192 + si_noflush_write_lock(sb);
31193 + ii_read_lock_parent(dir);
31194 + bindex = au_br_index(sb, br->br_id);
31195 + err = au_xino_trunc(sb, bindex);
31196 + ii_read_unlock(dir);
31197 + if (unlikely(err))
31198 + pr_warn("err b%d, (%d)\n", bindex, err);
31199 + atomic_dec(&br->br_xino_running);
31200 + atomic_dec(&br->br_count);
31201 + si_write_unlock(sb);
31202 + au_nwt_done(&au_sbi(sb)->si_nowait);
31206 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
31209 + struct kstatfs st;
31210 + struct au_sbinfo *sbinfo;
31212 + /* todo: si_xino_expire and the ratio should be customizable */
31213 + sbinfo = au_sbi(sb);
31214 + if (time_before(jiffies,
31215 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
31218 + /* truncation border */
31219 + err = vfs_statfs(&br->br_xino.xi_file->f_path, &st);
31220 + if (unlikely(err)) {
31221 + AuErr1("statfs err %d, ignored\n", err);
31224 + if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC)
31230 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
31232 + struct xino_do_trunc_args *args;
31235 + if (!xino_trunc_test(sb, br))
31238 + if (atomic_inc_return(&br->br_xino_running) > 1)
31241 + /* lock and kfree() will be called in trunc_xino() */
31242 + args = kmalloc(sizeof(*args), GFP_NOFS);
31243 + if (unlikely(!args)) {
31244 + AuErr1("no memory\n");
31248 + atomic_inc(&br->br_count);
31251 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
31253 + return; /* success */
31255 + pr_err("wkq %d\n", wkq_err);
31256 + atomic_dec(&br->br_count);
31261 + atomic_dec(&br->br_xino_running);
31264 +/* ---------------------------------------------------------------------- */
31266 +static int au_xino_do_write(au_writef_t write, struct file *file,
31267 + ino_t h_ino, ino_t ino)
31273 + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) {
31274 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
31277 + pos *= sizeof(ino);
31278 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos);
31279 + if (sz == sizeof(ino))
31280 + return 0; /* success */
31282 + AuIOErr("write failed (%zd)\n", sz);
31287 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
31288 + * at the position of @h_ino.
31289 + * even if @ino is zero, it is written to the xinofile and means no entry.
31290 + * if the size of the xino file on a specific filesystem exceeds the watermark,
31291 + * try truncating it.
31293 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
31297 + unsigned int mnt_flags;
31298 + struct au_branch *br;
31300 + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max)
31301 + || ((loff_t)-1) > 0);
31302 + SiMustAnyLock(sb);
31304 + mnt_flags = au_mntflags(sb);
31305 + if (!au_opt_test(mnt_flags, XINO))
31308 + br = au_sbr(sb, bindex);
31309 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
31312 + if (au_opt_test(mnt_flags, TRUNC_XINO)
31313 + && au_test_fs_trunc_xino(au_br_sb(br)))
31314 + xino_try_trunc(sb, br);
31315 + return 0; /* success */
31318 + AuIOErr("write failed (%d)\n", err);
31322 +/* ---------------------------------------------------------------------- */
31324 +/* aufs inode number bitmap */
31326 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
31327 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
31331 + AuDebugOn(bit < 0 || page_bits <= bit);
31332 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
31336 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
31338 + AuDebugOn(ino < AUFS_FIRST_INO);
31339 + ino -= AUFS_FIRST_INO;
31340 + *pindex = ino / page_bits;
31341 + *bit = ino % page_bits;
31344 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
31349 + struct au_sbinfo *sbinfo;
31350 + struct file *xib;
31351 + unsigned long *p;
31353 + sbinfo = au_sbi(sb);
31354 + MtxMustLock(&sbinfo->si_xib_mtx);
31355 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
31356 + || !au_opt_test(sbinfo->si_mntflags, XINO));
31358 + if (pindex == sbinfo->si_xib_last_pindex)
31361 + xib = sbinfo->si_xib;
31362 + p = sbinfo->si_xib_buf;
31363 + pos = sbinfo->si_xib_last_pindex;
31364 + pos *= PAGE_SIZE;
31365 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
31366 + if (unlikely(sz != PAGE_SIZE))
31370 + pos *= PAGE_SIZE;
31371 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
31372 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
31374 + memset(p, 0, PAGE_SIZE);
31375 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
31377 + if (sz == PAGE_SIZE) {
31378 + sbinfo->si_xib_last_pindex = pindex;
31379 + return 0; /* success */
31383 + AuIOErr1("write failed (%zd)\n", sz);
31390 +/* ---------------------------------------------------------------------- */
31392 +static void au_xib_clear_bit(struct inode *inode)
31395 + unsigned long pindex;
31396 + struct super_block *sb;
31397 + struct au_sbinfo *sbinfo;
31399 + AuDebugOn(inode->i_nlink);
31401 + sb = inode->i_sb;
31402 + xib_calc_bit(inode->i_ino, &pindex, &bit);
31403 + AuDebugOn(page_bits <= bit);
31404 + sbinfo = au_sbi(sb);
31405 + mutex_lock(&sbinfo->si_xib_mtx);
31406 + err = xib_pindex(sb, pindex);
31408 + clear_bit(bit, sbinfo->si_xib_buf);
31409 + sbinfo->si_xib_next_bit = bit;
31411 + mutex_unlock(&sbinfo->si_xib_mtx);
31414 +/* for s_op->delete_inode() */
31415 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
31418 + unsigned int mnt_flags;
31419 + aufs_bindex_t bindex, bend, bi;
31420 + unsigned char try_trunc;
31421 + struct au_iinfo *iinfo;
31422 + struct super_block *sb;
31423 + struct au_hinode *hi;
31424 + struct inode *h_inode;
31425 + struct au_branch *br;
31426 + au_writef_t xwrite;
31428 + sb = inode->i_sb;
31429 + mnt_flags = au_mntflags(sb);
31430 + if (!au_opt_test(mnt_flags, XINO)
31431 + || inode->i_ino == AUFS_ROOT_INO)
31435 + au_xigen_inc(inode);
31436 + au_xib_clear_bit(inode);
31439 + iinfo = au_ii(inode);
31443 + bindex = iinfo->ii_bstart;
31447 + xwrite = au_sbi(sb)->si_xwrite;
31448 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
31449 + hi = iinfo->ii_hinode + bindex;
31450 + bend = iinfo->ii_bend;
31451 + for (; bindex <= bend; bindex++, hi++) {
31452 + h_inode = hi->hi_inode;
31454 + || (!unlinked && h_inode->i_nlink))
31457 + /* inode may not be revalidated */
31458 + bi = au_br_index(sb, hi->hi_id);
31462 + br = au_sbr(sb, bi);
31463 + err = au_xino_do_write(xwrite, br->br_xino.xi_file,
31464 + h_inode->i_ino, /*ino*/0);
31465 + if (!err && try_trunc
31466 + && au_test_fs_trunc_xino(au_br_sb(br)))
31467 + xino_try_trunc(sb, br);
31471 +/* get an unused inode number from bitmap */
31472 +ino_t au_xino_new_ino(struct super_block *sb)
31475 + unsigned long *p, pindex, ul, pend;
31476 + struct au_sbinfo *sbinfo;
31477 + struct file *file;
31478 + int free_bit, err;
31480 + if (!au_opt_test(au_mntflags(sb), XINO))
31481 + return iunique(sb, AUFS_FIRST_INO);
31483 + sbinfo = au_sbi(sb);
31484 + mutex_lock(&sbinfo->si_xib_mtx);
31485 + p = sbinfo->si_xib_buf;
31486 + free_bit = sbinfo->si_xib_next_bit;
31487 + if (free_bit < page_bits && !test_bit(free_bit, p))
31488 + goto out; /* success */
31489 + free_bit = find_first_zero_bit(p, page_bits);
31490 + if (free_bit < page_bits)
31491 + goto out; /* success */
31493 + pindex = sbinfo->si_xib_last_pindex;
31494 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
31495 + err = xib_pindex(sb, ul);
31496 + if (unlikely(err))
31498 + free_bit = find_first_zero_bit(p, page_bits);
31499 + if (free_bit < page_bits)
31500 + goto out; /* success */
31503 + file = sbinfo->si_xib;
31504 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
31505 + for (ul = pindex + 1; ul <= pend; ul++) {
31506 + err = xib_pindex(sb, ul);
31507 + if (unlikely(err))
31509 + free_bit = find_first_zero_bit(p, page_bits);
31510 + if (free_bit < page_bits)
31511 + goto out; /* success */
31516 + set_bit(free_bit, p);
31517 + sbinfo->si_xib_next_bit = free_bit + 1;
31518 + pindex = sbinfo->si_xib_last_pindex;
31519 + mutex_unlock(&sbinfo->si_xib_mtx);
31520 + ino = xib_calc_ino(pindex, free_bit);
31521 + AuDbg("i%lu\n", (unsigned long)ino);
31524 + mutex_unlock(&sbinfo->si_xib_mtx);
31530 + * read @ino from xinofile for the specified branch{@sb, @bindex}
31531 + * at the position of @h_ino.
31532 + * if @ino does not exist and @do_new is true, get new one.
31534 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
31540 + struct file *file;
31541 + struct au_sbinfo *sbinfo;
31544 + if (!au_opt_test(au_mntflags(sb), XINO))
31545 + return 0; /* no xino */
31548 + sbinfo = au_sbi(sb);
31550 + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) {
31551 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
31554 + pos *= sizeof(*ino);
31556 + file = au_sbr(sb, bindex)->br_xino.xi_file;
31557 + if (vfsub_f_size_read(file) < pos + sizeof(*ino))
31558 + return 0; /* no ino */
31560 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
31561 + if (sz == sizeof(*ino))
31562 + return 0; /* success */
31565 + if (unlikely(sz >= 0)) {
31567 + AuIOErr("xino read error (%zd)\n", sz);
31573 +/* ---------------------------------------------------------------------- */
31575 +/* create and set a new xino file */
31577 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent)
31579 + struct file *file;
31580 + struct dentry *h_parent, *d;
31581 + struct inode *h_dir;
31585 + * at mount-time, and the xino file is the default path,
31586 + * hnotify is disabled so we have no notify events to ignore.
31587 + * when a user specified the xino, we cannot get au_hdir to be ignored.
31589 + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
31590 + /* | __FMODE_NONOTIFY */,
31591 + S_IRUGO | S_IWUGO);
31592 + if (IS_ERR(file)) {
31594 + pr_err("open %s(%ld)\n", fname, PTR_ERR(file));
31598 + /* keep file count */
31599 + h_parent = dget_parent(file->f_dentry);
31600 + h_dir = h_parent->d_inode;
31601 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
31602 + /* mnt_want_write() is unnecessary here */
31603 + /* no delegation since it is just created */
31604 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL, /*force*/0);
31605 + mutex_unlock(&h_dir->i_mutex);
31607 + if (unlikely(err)) {
31609 + pr_err("unlink %s(%d)\n", fname, err);
31614 + d = file->f_dentry;
31615 + if (unlikely(sb == d->d_sb)) {
31617 + pr_err("%s must be outside\n", fname);
31620 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
31622 + pr_err("xino doesn't support %s(%s)\n",
31623 + fname, au_sbtype(d->d_sb));
31626 + return file; /* success */
31630 + file = ERR_PTR(err);
31635 + * find another branch who is on the same filesystem of the specified
31636 + * branch{@btgt}. search until @bend.
31638 +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
31639 + aufs_bindex_t bend)
31641 + aufs_bindex_t bindex;
31642 + struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
31644 + for (bindex = 0; bindex < btgt; bindex++)
31645 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
31647 + for (bindex++; bindex <= bend; bindex++)
31648 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
31653 +/* ---------------------------------------------------------------------- */
31656 + * initialize the xinofile for the specified branch @br
31657 + * at the place/path where @base_file indicates.
31658 + * test whether another branch is on the same filesystem or not,
31659 + * if @do_test is true.
31661 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
31662 + struct file *base_file, int do_test)
31666 + aufs_bindex_t bend, bindex;
31667 + struct au_branch *shared_br, *b;
31668 + struct file *file;
31669 + struct super_block *tgt_sb;
31671 + shared_br = NULL;
31672 + bend = au_sbend(sb);
31674 + tgt_sb = au_br_sb(br);
31675 + for (bindex = 0; bindex <= bend; bindex++) {
31676 + b = au_sbr(sb, bindex);
31677 + if (tgt_sb == au_br_sb(b)) {
31684 + if (!shared_br || !shared_br->br_xino.xi_file) {
31685 + struct au_xino_lock_dir ldir;
31687 + au_xino_lock_dir(sb, base_file, &ldir);
31688 + /* mnt_want_write() is unnecessary here */
31689 + file = au_xino_create2(base_file, NULL);
31690 + au_xino_unlock_dir(&ldir);
31691 + err = PTR_ERR(file);
31692 + if (IS_ERR(file))
31694 + br->br_xino.xi_file = file;
31696 + br->br_xino.xi_file = shared_br->br_xino.xi_file;
31697 + get_file(br->br_xino.xi_file);
31700 + ino = AUFS_ROOT_INO;
31701 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
31703 + if (unlikely(err)) {
31704 + fput(br->br_xino.xi_file);
31705 + br->br_xino.xi_file = NULL;
31712 +/* ---------------------------------------------------------------------- */
31714 +/* trucate a xino bitmap file */
31717 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
31721 + unsigned long pindex;
31722 + loff_t pos, pend;
31723 + struct au_sbinfo *sbinfo;
31726 + unsigned long *p;
31729 + sbinfo = au_sbi(sb);
31730 + MtxMustLock(&sbinfo->si_xib_mtx);
31731 + p = sbinfo->si_xib_buf;
31732 + func = sbinfo->si_xread;
31733 + pend = vfsub_f_size_read(file);
31735 + while (pos < pend) {
31736 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
31738 + if (unlikely(sz <= 0))
31742 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
31743 + if (unlikely(*ino < AUFS_FIRST_INO))
31746 + xib_calc_bit(*ino, &pindex, &bit);
31747 + AuDebugOn(page_bits <= bit);
31748 + err = xib_pindex(sb, pindex);
31760 +static int xib_restore(struct super_block *sb)
31763 + aufs_bindex_t bindex, bend;
31767 + page = (void *)__get_free_page(GFP_NOFS);
31768 + if (unlikely(!page))
31772 + bend = au_sbend(sb);
31773 + for (bindex = 0; !err && bindex <= bend; bindex++)
31774 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
31775 + err = do_xib_restore
31776 + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page);
31778 + AuDbg("b%d\n", bindex);
31779 + free_page((unsigned long)page);
31785 +int au_xib_trunc(struct super_block *sb)
31790 + struct au_xino_lock_dir ldir;
31791 + struct au_sbinfo *sbinfo;
31792 + unsigned long *p;
31793 + struct file *file;
31795 + SiMustWriteLock(sb);
31798 + sbinfo = au_sbi(sb);
31799 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
31802 + file = sbinfo->si_xib;
31803 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
31806 + au_xino_lock_dir(sb, file, &ldir);
31807 + /* mnt_want_write() is unnecessary here */
31808 + file = au_xino_create2(sbinfo->si_xib, NULL);
31809 + au_xino_unlock_dir(&ldir);
31810 + err = PTR_ERR(file);
31811 + if (IS_ERR(file))
31813 + fput(sbinfo->si_xib);
31814 + sbinfo->si_xib = file;
31816 + p = sbinfo->si_xib_buf;
31817 + memset(p, 0, PAGE_SIZE);
31819 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
31820 + if (unlikely(sz != PAGE_SIZE)) {
31822 + AuIOErr("err %d\n", err);
31828 + mutex_lock(&sbinfo->si_xib_mtx);
31829 + /* mnt_want_write() is unnecessary here */
31830 + err = xib_restore(sb);
31831 + mutex_unlock(&sbinfo->si_xib_mtx);
31837 +/* ---------------------------------------------------------------------- */
31840 + * xino mount option handlers
31842 +static au_readf_t find_readf(struct file *h_file)
31844 + const struct file_operations *fop = h_file->f_op;
31847 + return fop->read;
31848 + if (fop->aio_read)
31849 + return do_sync_read;
31850 + return ERR_PTR(-ENOSYS);
31853 +static au_writef_t find_writef(struct file *h_file)
31855 + const struct file_operations *fop = h_file->f_op;
31858 + return fop->write;
31859 + if (fop->aio_write)
31860 + return do_sync_write;
31861 + return ERR_PTR(-ENOSYS);
31865 +static void xino_clear_xib(struct super_block *sb)
31867 + struct au_sbinfo *sbinfo;
31869 + SiMustWriteLock(sb);
31871 + sbinfo = au_sbi(sb);
31872 + sbinfo->si_xread = NULL;
31873 + sbinfo->si_xwrite = NULL;
31874 + if (sbinfo->si_xib)
31875 + fput(sbinfo->si_xib);
31876 + sbinfo->si_xib = NULL;
31877 + free_page((unsigned long)sbinfo->si_xib_buf);
31878 + sbinfo->si_xib_buf = NULL;
31881 +static int au_xino_set_xib(struct super_block *sb, struct file *base)
31885 + struct au_sbinfo *sbinfo;
31886 + struct file *file;
31888 + SiMustWriteLock(sb);
31890 + sbinfo = au_sbi(sb);
31891 + file = au_xino_create2(base, sbinfo->si_xib);
31892 + err = PTR_ERR(file);
31893 + if (IS_ERR(file))
31895 + if (sbinfo->si_xib)
31896 + fput(sbinfo->si_xib);
31897 + sbinfo->si_xib = file;
31898 + sbinfo->si_xread = find_readf(file);
31899 + sbinfo->si_xwrite = find_writef(file);
31902 + if (!sbinfo->si_xib_buf)
31903 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
31904 + if (unlikely(!sbinfo->si_xib_buf))
31907 + sbinfo->si_xib_last_pindex = 0;
31908 + sbinfo->si_xib_next_bit = 0;
31909 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
31911 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
31912 + PAGE_SIZE, &pos);
31913 + if (unlikely(err != PAGE_SIZE))
31917 + goto out; /* success */
31920 + free_page((unsigned long)sbinfo->si_xib_buf);
31921 + sbinfo->si_xib_buf = NULL;
31925 + fput(sbinfo->si_xib);
31926 + sbinfo->si_xib = NULL;
31927 + sbinfo->si_xread = NULL;
31928 + sbinfo->si_xwrite = NULL;
31933 +/* xino for each branch */
31934 +static void xino_clear_br(struct super_block *sb)
31936 + aufs_bindex_t bindex, bend;
31937 + struct au_branch *br;
31939 + bend = au_sbend(sb);
31940 + for (bindex = 0; bindex <= bend; bindex++) {
31941 + br = au_sbr(sb, bindex);
31942 + if (!br || !br->br_xino.xi_file)
31945 + fput(br->br_xino.xi_file);
31946 + br->br_xino.xi_file = NULL;
31950 +static int au_xino_set_br(struct super_block *sb, struct file *base)
31954 + aufs_bindex_t bindex, bend, bshared;
31956 + struct file *old, *new;
31958 + struct au_branch *br;
31959 + struct inode *inode;
31960 + au_writef_t writef;
31962 + SiMustWriteLock(sb);
31965 + bend = au_sbend(sb);
31966 + fpair = kcalloc(bend + 1, sizeof(*fpair), GFP_NOFS);
31967 + if (unlikely(!fpair))
31970 + inode = sb->s_root->d_inode;
31971 + ino = AUFS_ROOT_INO;
31972 + writef = au_sbi(sb)->si_xwrite;
31973 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
31974 + br = au_sbr(sb, bindex);
31975 + bshared = is_sb_shared(sb, bindex, bindex - 1);
31976 + if (bshared >= 0) {
31977 + /* shared xino */
31978 + *p = fpair[bshared];
31979 + get_file(p->new);
31984 + p->old = br->br_xino.xi_file;
31985 + p->new = au_xino_create2(base, br->br_xino.xi_file);
31986 + err = PTR_ERR(p->new);
31987 + if (IS_ERR(p->new)) {
31993 + err = au_xino_do_write(writef, p->new,
31994 + au_h_iptr(inode, bindex)->i_ino, ino);
31995 + if (unlikely(err))
31999 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
32000 + br = au_sbr(sb, bindex);
32001 + if (br->br_xino.xi_file)
32002 + fput(br->br_xino.xi_file);
32003 + get_file(p->new);
32004 + br->br_xino.xi_file = p->new;
32008 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++)
32018 +void au_xino_clr(struct super_block *sb)
32020 + struct au_sbinfo *sbinfo;
32022 + au_xigen_clr(sb);
32023 + xino_clear_xib(sb);
32024 + xino_clear_br(sb);
32025 + sbinfo = au_sbi(sb);
32026 + /* lvalue, do not call au_mntflags() */
32027 + au_opt_clr(sbinfo->si_mntflags, XINO);
32030 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
32033 + struct dentry *parent, *cur_parent;
32034 + struct qstr *dname, *cur_name;
32035 + struct file *cur_xino;
32036 + struct inode *dir;
32037 + struct au_sbinfo *sbinfo;
32039 + SiMustWriteLock(sb);
32042 + sbinfo = au_sbi(sb);
32043 + parent = dget_parent(xino->file->f_dentry);
32046 + dname = &xino->file->f_dentry->d_name;
32047 + cur_xino = sbinfo->si_xib;
32049 + cur_parent = dget_parent(cur_xino->f_dentry);
32050 + cur_name = &cur_xino->f_dentry->d_name;
32051 + skip = (cur_parent == parent
32052 + && dname->len == cur_name->len
32053 + && !memcmp(dname->name, cur_name->name,
32055 + dput(cur_parent);
32061 + au_opt_set(sbinfo->si_mntflags, XINO);
32062 + dir = parent->d_inode;
32063 + mutex_lock_nested(&dir->i_mutex, AuLsc_I_PARENT);
32064 + /* mnt_want_write() is unnecessary here */
32065 + err = au_xino_set_xib(sb, xino->file);
32067 + err = au_xigen_set(sb, xino->file);
32069 + err = au_xino_set_br(sb, xino->file);
32070 + mutex_unlock(&dir->i_mutex);
32072 + goto out; /* success */
32075 + AuIOErr("failed creating xino(%d).\n", err);
32082 +/* ---------------------------------------------------------------------- */
32085 + * create a xinofile at the default place/path.
32087 +struct file *au_xino_def(struct super_block *sb)
32089 + struct file *file;
32091 + struct au_branch *br;
32092 + struct super_block *h_sb;
32093 + struct path path;
32094 + aufs_bindex_t bend, bindex, bwr;
32097 + bend = au_sbend(sb);
32099 + for (bindex = 0; bindex <= bend; bindex++) {
32100 + br = au_sbr(sb, bindex);
32101 + if (au_br_writable(br->br_perm)
32102 + && !au_test_fs_bad_xino(au_br_sb(br))) {
32109 + file = ERR_PTR(-ENOMEM);
32110 + page = (void *)__get_free_page(GFP_NOFS);
32111 + if (unlikely(!page))
32113 + path.mnt = au_br_mnt(br);
32114 + path.dentry = au_h_dptr(sb->s_root, bwr);
32115 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
32116 + file = (void *)p;
32117 + if (!IS_ERR(p)) {
32118 + strcat(p, "/" AUFS_XINO_FNAME);
32119 + AuDbg("%s\n", p);
32120 + file = au_xino_create(sb, p, /*silent*/0);
32121 + if (!IS_ERR(file))
32122 + au_xino_brid_set(sb, br->br_id);
32124 + free_page((unsigned long)page);
32126 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
32127 + if (IS_ERR(file))
32129 + h_sb = file->f_dentry->d_sb;
32130 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
32131 + pr_err("xino doesn't support %s(%s)\n",
32132 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
32134 + file = ERR_PTR(-EINVAL);
32136 + if (!IS_ERR(file))
32137 + au_xino_brid_set(sb, -1);
32144 +/* ---------------------------------------------------------------------- */
32146 +int au_xino_path(struct seq_file *seq, struct file *file)
32150 + err = au_seq_path(seq, &file->f_path);
32151 + if (unlikely(err < 0))
32155 +#define Deleted "\\040(deleted)"
32156 + seq->count -= sizeof(Deleted) - 1;
32157 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
32158 + sizeof(Deleted) - 1));
32164 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
32165 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
32166 +++ linux/include/uapi/linux/aufs_type.h 2014-01-27 23:17:06.205534916 +0100
32169 + * Copyright (C) 2005-2014 Junjiro R. Okajima
32171 + * This program, aufs is free software; you can redistribute it and/or modify
32172 + * it under the terms of the GNU General Public License as published by
32173 + * the Free Software Foundation; either version 2 of the License, or
32174 + * (at your option) any later version.
32176 + * This program is distributed in the hope that it will be useful,
32177 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32178 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32179 + * GNU General Public License for more details.
32181 + * You should have received a copy of the GNU General Public License
32182 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32185 +#ifndef __AUFS_TYPE_H__
32186 +#define __AUFS_TYPE_H__
32188 +#define AUFS_NAME "aufs"
32192 + * define it before including all other headers.
32193 + * sched.h may use pr_* macros before defining "current", so define the
32194 + * no-current version first, and re-define later.
32196 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
32197 +#include <linux/sched.h>
32199 +#define pr_fmt(fmt) \
32200 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
32201 + (int)sizeof(current->comm), current->comm, current->pid
32203 +#include <stdint.h>
32204 +#include <sys/types.h>
32205 +#endif /* __KERNEL__ */
32207 +#include <linux/limits.h>
32209 +#define AUFS_VERSION "3.13-20140127"
32211 +/* todo? move this to linux-2.6.19/include/magic.h */
32212 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
32214 +/* ---------------------------------------------------------------------- */
32216 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
32217 +typedef int8_t aufs_bindex_t;
32218 +#define AUFS_BRANCH_MAX 127
32220 +typedef int16_t aufs_bindex_t;
32221 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
32222 +#define AUFS_BRANCH_MAX 511
32223 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
32224 +#define AUFS_BRANCH_MAX 1023
32225 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
32226 +#define AUFS_BRANCH_MAX 32767
32231 +#ifndef AUFS_BRANCH_MAX
32232 +#error unknown CONFIG_AUFS_BRANCH_MAX value
32234 +#endif /* __KERNEL__ */
32236 +/* ---------------------------------------------------------------------- */
32238 +#define AUFS_FSTYPE AUFS_NAME
32240 +#define AUFS_ROOT_INO 2
32241 +#define AUFS_FIRST_INO 11
32243 +#define AUFS_WH_PFX ".wh."
32244 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
32245 +#define AUFS_WH_TMP_LEN 4
32246 +/* a limit for rmdir/rename a dir and copyup */
32247 +#define AUFS_MAX_NAMELEN (NAME_MAX \
32248 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
32250 + - AUFS_WH_TMP_LEN) /* hex */
32251 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
32252 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
32253 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
32254 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
32255 +#define AUFS_DIRWH_DEF 3
32256 +#define AUFS_RDCACHE_DEF 10 /* seconds */
32257 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
32258 +#define AUFS_RDBLK_DEF 512 /* bytes */
32259 +#define AUFS_RDHASH_DEF 32
32260 +#define AUFS_WKQ_NAME AUFS_NAME "d"
32261 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
32262 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
32263 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
32265 +/* pseudo-link maintenace under /proc */
32266 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
32267 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
32268 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
32270 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
32271 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
32273 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
32274 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
32275 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
32277 +/* doubly whiteouted */
32278 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
32279 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
32280 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
32282 +/* branch permissions and attributes */
32283 +#define AUFS_BRPERM_RW "rw"
32284 +#define AUFS_BRPERM_RO "ro"
32285 +#define AUFS_BRPERM_RR "rr"
32286 +#define AUFS_BRRATTR_WH "wh"
32287 +#define AUFS_BRWATTR_NLWH "nolwh"
32288 +#define AUFS_BRATTR_UNPIN "unpin"
32290 +/* ---------------------------------------------------------------------- */
32294 + /* readdir in userspace */
32298 + /* pathconf wrapper */
32308 +/* borrowed from linux/include/linux/kernel.h */
32310 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
32311 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
32314 +/* borrowed from linux/include/linux/compiler-gcc3.h */
32316 +#define __aligned(x) __attribute__((aligned(x)))
32321 +#define __packed __attribute__((packed))
32325 +struct au_rdu_cookie {
32330 + uint32_t generation;
32333 +struct au_rdu_ent {
32342 +static inline int au_rdu_len(int nlen)
32344 + /* include the terminating NULL */
32345 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
32346 + sizeof(uint64_t));
32349 +union au_rdu_ent_ul {
32350 + struct au_rdu_ent __user *e;
32362 + uint64_t sz; /* AuCtl_RDU */
32363 + uint64_t nent; /* AuCtl_RDU_INO */
32365 + union au_rdu_ent_ul ent;
32366 + uint16_t verify[AufsCtlRduV_End];
32368 + /* input/output */
32372 + union au_rdu_ent_ul tail;
32373 + /* number of entries which were added in a single call */
32378 + struct au_rdu_cookie cookie;
32381 +/* ---------------------------------------------------------------------- */
32383 +struct aufs_wbr_fd {
32388 +/* ---------------------------------------------------------------------- */
32390 +struct aufs_ibusy {
32391 + uint64_t ino, h_ino;
32395 +/* ---------------------------------------------------------------------- */
32397 +/* error code for move-down */
32398 +/* the actual message strings are implemented in aufs-util.git */
32400 + EAU_MVDOWN_OPAQUE = 1,
32401 + EAU_MVDOWN_WHITEOUT,
32402 + EAU_MVDOWN_UPPER,
32403 + EAU_MVDOWN_BOTTOM,
32404 + EAU_MVDOWN_NOUPPER,
32405 + EAU_MVDOWN_NOLOWERBR,
32409 +/* flags for move-down */
32410 +#define AUFS_MVDOWN_DMSG 1
32411 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
32412 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
32413 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
32414 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
32415 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
32416 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
32417 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
32418 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
32419 +/* will be added more */
32422 + AUFS_MVDOWN_UPPER,
32423 + AUFS_MVDOWN_LOWER,
32424 + AUFS_MVDOWN_NARRAY
32427 +struct aufs_mvdown {
32432 + } a[AUFS_MVDOWN_NARRAY];
32434 + /* will be added more */
32437 +/* ---------------------------------------------------------------------- */
32439 +#define AuCtlType 'A'
32440 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
32441 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
32442 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
32443 + struct aufs_wbr_fd)
32444 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
32445 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
32446 + struct aufs_mvdown)
32448 +#endif /* __AUFS_TYPE_H__ */