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 bdc6e87..349600c 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/fs/file_table.c b/fs/file_table.c
39 index 485dc0e..8db8096 100644
42 @@ -36,7 +36,7 @@ struct files_stat_struct files_stat = {
46 -DEFINE_STATIC_LGLOCK(files_lglock);
47 +DEFINE_LGLOCK(files_lglock);
49 /* SLAB cache for file structures */
50 static struct kmem_cache *filp_cachep __read_mostly;
51 diff --git a/fs/inode.c b/fs/inode.c
52 index 00d5fc3..f324521 100644
55 @@ -1498,7 +1498,7 @@ static int relatime_need_update(struct vfsmount *mnt, struct inode *inode,
56 * This does the actual work of updating an inodes time or version. Must have
57 * had called mnt_want_write() before calling this.
59 -static int update_time(struct inode *inode, struct timespec *time, int flags)
60 +int update_time(struct inode *inode, struct timespec *time, int flags)
62 if (inode->i_op->update_time)
63 return inode->i_op->update_time(inode, time, flags);
64 diff --git a/fs/splice.c b/fs/splice.c
65 index d37431d..987346f 100644
68 @@ -1093,8 +1093,8 @@ EXPORT_SYMBOL(generic_splice_sendpage);
70 * Attempt to initiate a splice from pipe to file.
72 -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
73 - loff_t *ppos, size_t len, unsigned int flags)
74 +long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
75 + loff_t *ppos, size_t len, unsigned int flags)
77 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
78 loff_t *, size_t, unsigned int);
79 @@ -1124,9 +1124,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
81 * Attempt to initiate a splice from a file to a pipe.
83 -static long do_splice_to(struct file *in, loff_t *ppos,
84 - struct pipe_inode_info *pipe, size_t len,
86 +long do_splice_to(struct file *in, loff_t *ppos,
87 + struct pipe_inode_info *pipe, size_t len,
90 ssize_t (*splice_read)(struct file *, loff_t *,
91 struct pipe_inode_info *, size_t, unsigned int);
92 diff --git a/include/linux/fs.h b/include/linux/fs.h
93 index 65c2be2..0148214 100644
94 --- a/include/linux/fs.h
95 +++ b/include/linux/fs.h
96 @@ -2574,6 +2574,7 @@ extern int inode_change_ok(const struct inode *, struct iattr *);
97 extern int inode_newsize_ok(const struct inode *, loff_t offset);
98 extern void setattr_copy(struct inode *inode, const struct iattr *attr);
100 +extern int update_time(struct inode *, struct timespec *, int);
101 extern int file_update_time(struct file *file);
103 extern int generic_show_options(struct seq_file *m, struct dentry *root);
104 diff --git a/include/linux/splice.h b/include/linux/splice.h
105 index 74575cb..bfc6fb6 100644
106 --- a/include/linux/splice.h
107 +++ b/include/linux/splice.h
108 @@ -92,4 +92,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
109 extern void spd_release_page(struct splice_pipe_desc *, unsigned int);
111 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
113 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
114 + loff_t *ppos, size_t len, unsigned int flags);
115 +extern long do_splice_to(struct file *in, loff_t *ppos,
116 + struct pipe_inode_info *pipe, size_t len,
117 + unsigned int flags);
119 aufs3.10 standalone patch
121 diff --git a/fs/file_table.c b/fs/file_table.c
122 index 8db8096..e271e28 100644
123 --- a/fs/file_table.c
124 +++ b/fs/file_table.c
125 @@ -37,6 +37,7 @@ struct files_stat_struct files_stat = {
128 DEFINE_LGLOCK(files_lglock);
129 +EXPORT_SYMBOL(files_lglock);
131 /* SLAB cache for file structures */
132 static struct kmem_cache *filp_cachep __read_mostly;
133 @@ -405,6 +406,8 @@ void file_sb_list_del(struct file *file)
137 +EXPORT_SYMBOL(file_sb_list_del);
142 diff --git a/fs/inode.c b/fs/inode.c
143 index f324521..bff7670 100644
146 @@ -56,6 +56,7 @@ static struct hlist_head *inode_hashtable __read_mostly;
147 static __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_hash_lock);
149 __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_sb_list_lock);
150 +EXPORT_SYMBOL(inode_sb_list_lock);
153 * Empty aops. Can be used for the cases where the user does not
154 @@ -1514,6 +1515,7 @@ int update_time(struct inode *inode, struct timespec *time, int flags)
155 mark_inode_dirty_sync(inode);
158 +EXPORT_SYMBOL(update_time);
161 * touch_atime - update the access time
162 diff --git a/fs/namespace.c b/fs/namespace.c
163 index 7b1ca9b..51db6ad 100644
166 @@ -54,6 +54,7 @@ EXPORT_SYMBOL_GPL(fs_kobj);
167 * tree or hash is modified or when a vfsmount structure is modified.
169 DEFINE_BRLOCK(vfsmount_lock);
170 +EXPORT_SYMBOL(vfsmount_lock);
172 static inline unsigned long hash(struct vfsmount *mnt, struct dentry *dentry)
174 @@ -427,6 +428,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
175 mnt_dec_writers(real_mount(mnt));
178 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
181 * mnt_drop_write - give up write access to a mount
182 @@ -1456,6 +1458,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
186 +EXPORT_SYMBOL(iterate_mounts);
188 static void cleanup_group_ids(struct mount *mnt, struct mount *end)
190 diff --git a/fs/notify/group.c b/fs/notify/group.c
191 index bd2625b..2ff2a0f 100644
192 --- a/fs/notify/group.c
193 +++ b/fs/notify/group.c
195 #include <linux/srcu.h>
196 #include <linux/rculist.h>
197 #include <linux/wait.h>
198 +#include <linux/module.h>
200 #include <linux/fsnotify_backend.h>
201 #include "fsnotify.h"
202 @@ -65,6 +66,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
204 atomic_inc(&group->refcnt);
206 +EXPORT_SYMBOL(fsnotify_get_group);
209 * Drop a reference to a group. Free it if it's through.
210 @@ -74,6 +76,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
211 if (atomic_dec_and_test(&group->refcnt))
212 fsnotify_final_destroy_group(group);
214 +EXPORT_SYMBOL(fsnotify_put_group);
217 * Create a new fsnotify_group and hold a reference for the group returned.
218 @@ -102,6 +105,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
222 +EXPORT_SYMBOL(fsnotify_alloc_group);
224 int fsnotify_fasync(int fd, struct file *file, int on)
226 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
227 index fc6b49b..a6bb87d 100644
228 --- a/fs/notify/mark.c
229 +++ b/fs/notify/mark.c
230 @@ -115,6 +115,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
231 mark->free_mark(mark);
234 +EXPORT_SYMBOL(fsnotify_put_mark);
237 * Any time a mark is getting freed we end up here.
238 @@ -197,6 +198,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
239 fsnotify_destroy_mark_locked(mark, group);
240 mutex_unlock(&group->mark_mutex);
242 +EXPORT_SYMBOL(fsnotify_destroy_mark);
244 void fsnotify_set_mark_mask_locked(struct fsnotify_mark *mark, __u32 mask)
246 @@ -281,6 +283,7 @@ err:
250 +EXPORT_SYMBOL(fsnotify_add_mark);
252 int fsnotify_add_mark(struct fsnotify_mark *mark, struct fsnotify_group *group,
253 struct inode *inode, struct vfsmount *mnt, int allow_dups)
254 @@ -342,6 +345,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
255 atomic_set(&mark->refcnt, 1);
256 mark->free_mark = free_mark;
258 +EXPORT_SYMBOL(fsnotify_init_mark);
260 static int fsnotify_mark_destroy(void *ignored)
262 diff --git a/fs/open.c b/fs/open.c
263 index 8c74100..be563cd 100644
266 @@ -61,6 +61,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
267 mutex_unlock(&dentry->d_inode->i_mutex);
270 +EXPORT_SYMBOL(do_truncate);
272 long vfs_truncate(struct path *path, loff_t length)
274 diff --git a/fs/splice.c b/fs/splice.c
275 index 987346f..8d6a045 100644
278 @@ -1120,6 +1120,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
282 +EXPORT_SYMBOL(do_splice_from);
285 * Attempt to initiate a splice from a file to a pipe.
286 @@ -1146,6 +1147,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
288 return splice_read(in, ppos, pipe, len, flags);
290 +EXPORT_SYMBOL(do_splice_to);
293 * splice_direct_to_actor - splices data directly between two non-pipes
294 diff --git a/security/commoncap.c b/security/commoncap.c
295 index c44b6fe..d78b003 100644
296 --- a/security/commoncap.c
297 +++ b/security/commoncap.c
298 @@ -988,9 +988,11 @@ int cap_mmap_addr(unsigned long addr)
302 +EXPORT_SYMBOL(cap_mmap_addr);
304 int cap_mmap_file(struct file *file, unsigned long reqprot,
305 unsigned long prot, unsigned long flags)
309 +EXPORT_SYMBOL(cap_mmap_file);
310 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
311 index dd0dc57..9760ecb6 100644
312 --- a/security/device_cgroup.c
313 +++ b/security/device_cgroup.c
315 #include <linux/device_cgroup.h>
316 #include <linux/cgroup.h>
317 #include <linux/ctype.h>
318 +#include <linux/export.h>
319 #include <linux/list.h>
320 #include <linux/uaccess.h>
321 #include <linux/seq_file.h>
322 @@ -789,6 +790,7 @@ int __devcgroup_inode_permission(struct inode *inode, int mask)
323 return __devcgroup_check_permission(type, imajor(inode), iminor(inode),
326 +EXPORT_SYMBOL(__devcgroup_inode_permission);
328 int devcgroup_inode_mknod(int mode, dev_t dev)
330 diff --git a/security/security.c b/security/security.c
331 index a3dce87..06a6ea6 100644
332 --- a/security/security.c
333 +++ b/security/security.c
334 @@ -396,6 +396,7 @@ int security_path_rmdir(struct path *dir, struct dentry *dentry)
336 return security_ops->path_rmdir(dir, dentry);
338 +EXPORT_SYMBOL(security_path_rmdir);
340 int security_path_unlink(struct path *dir, struct dentry *dentry)
342 @@ -412,6 +413,7 @@ int security_path_symlink(struct path *dir, struct dentry *dentry,
344 return security_ops->path_symlink(dir, dentry, old_name);
346 +EXPORT_SYMBOL(security_path_symlink);
348 int security_path_link(struct dentry *old_dentry, struct path *new_dir,
349 struct dentry *new_dentry)
350 @@ -420,6 +422,7 @@ int security_path_link(struct dentry *old_dentry, struct path *new_dir,
352 return security_ops->path_link(old_dentry, new_dir, new_dentry);
354 +EXPORT_SYMBOL(security_path_link);
356 int security_path_rename(struct path *old_dir, struct dentry *old_dentry,
357 struct path *new_dir, struct dentry *new_dentry)
358 @@ -438,6 +441,7 @@ int security_path_truncate(struct path *path)
360 return security_ops->path_truncate(path);
362 +EXPORT_SYMBOL(security_path_truncate);
364 int security_path_chmod(struct path *path, umode_t mode)
366 @@ -445,6 +449,7 @@ int security_path_chmod(struct path *path, umode_t mode)
368 return security_ops->path_chmod(path, mode);
370 +EXPORT_SYMBOL(security_path_chmod);
372 int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
374 @@ -452,6 +457,7 @@ int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
376 return security_ops->path_chown(path, uid, gid);
378 +EXPORT_SYMBOL(security_path_chown);
380 int security_path_chroot(struct path *path)
382 @@ -528,6 +534,7 @@ int security_inode_readlink(struct dentry *dentry)
384 return security_ops->inode_readlink(dentry);
386 +EXPORT_SYMBOL(security_inode_readlink);
388 int security_inode_follow_link(struct dentry *dentry, struct nameidata *nd)
390 @@ -542,6 +549,7 @@ int security_inode_permission(struct inode *inode, int mask)
392 return security_ops->inode_permission(inode, mask);
394 +EXPORT_SYMBOL(security_inode_permission);
396 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
398 @@ -663,6 +671,7 @@ int security_file_permission(struct file *file, int mask)
400 return fsnotify_perm(file, mask);
402 +EXPORT_SYMBOL(security_file_permission);
404 int security_file_alloc(struct file *file)
406 @@ -723,6 +732,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
408 return ima_file_mmap(file, prot);
410 +EXPORT_SYMBOL(security_mmap_file);
412 int security_mmap_addr(unsigned long addr)
414 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
415 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
416 +++ linux/Documentation/ABI/testing/debugfs-aufs 2013-07-06 13:20:47.716863966 +0200
418 +What: /debug/aufs/si_<id>/
420 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
422 + Under /debug/aufs, a directory named si_<id> is created
423 + per aufs mount, where <id> is a unique id generated
426 +What: /debug/aufs/si_<id>/plink
428 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
430 + It has three lines and shows the information about the
431 + pseudo-link. The first line is a single number
432 + representing a number of buckets. The second line is a
433 + number of pseudo-links per buckets (separated by a
434 + blank). The last line is a single number representing a
435 + total number of psedo-links.
436 + When the aufs mount option 'noplink' is specified, it
437 + will show "1\n0\n0\n".
439 +What: /debug/aufs/si_<id>/xib
441 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
443 + It shows the consumed blocks by xib (External Inode Number
444 + Bitmap), its block size and file size.
445 + When the aufs mount option 'noxino' is specified, it
446 + will be empty. About XINO files, see the aufs manual.
448 +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN
450 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
452 + It shows the consumed blocks by xino (External Inode Number
453 + Translation Table), its link count, block size and file
455 + When the aufs mount option 'noxino' is specified, it
456 + will be empty. About XINO files, see the aufs manual.
458 +What: /debug/aufs/si_<id>/xigen
460 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
462 + It shows the consumed blocks by xigen (External Inode
463 + Generation Table), its block size and file size.
464 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
466 + When the aufs mount option 'noxino' is specified, it
467 + will be empty. About XINO files, see the aufs manual.
468 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
469 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
470 +++ linux/Documentation/ABI/testing/sysfs-aufs 2013-07-06 13:20:47.730197761 +0200
472 +What: /sys/fs/aufs/si_<id>/
474 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
476 + Under /sys/fs/aufs, a directory named si_<id> is created
477 + per aufs mount, where <id> is a unique id generated
480 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
482 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
484 + It shows the abolute path of a member directory (which
485 + is called branch) in aufs, and its permission.
487 +What: /sys/fs/aufs/si_<id>/xi_path
489 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
491 + It shows the abolute path of XINO (External Inode Number
492 + Bitmap, Translation Table and Generation Table) file
493 + even if it is the default path.
494 + When the aufs mount option 'noxino' is specified, it
495 + will be empty. About XINO files, see the aufs manual.
496 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
497 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
498 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2013-07-06 13:20:47.730197761 +0200
501 +# Copyright (C) 2005-2013 Junjiro R. Okajima
503 +# This program is free software; you can redistribute it and/or modify
504 +# it under the terms of the GNU General Public License as published by
505 +# the Free Software Foundation; either version 2 of the License, or
506 +# (at your option) any later version.
508 +# This program is distributed in the hope that it will be useful,
509 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
510 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
511 +# GNU General Public License for more details.
513 +# You should have received a copy of the GNU General Public License
514 +# along with this program; if not, write to the Free Software
515 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
518 +----------------------------------------
520 +aufs [ei ju: ef es] | [a u f s]
521 +1. abbrev. for "advanced multi-layered unification filesystem".
522 +2. abbrev. for "another unionfs".
523 +3. abbrev. for "auf das" in German which means "on the" in English.
524 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
525 + But "Filesystem aufs Filesystem" is hard to understand.
527 +AUFS is a filesystem with features:
528 +- multi layered stackable unification filesystem, the member directory
529 + is called as a branch.
530 +- branch permission and attribute, 'readonly', 'real-readonly',
531 + 'readwrite', 'whiteout-able', 'link-able whiteout' and their
533 +- internal "file copy-on-write".
534 +- logical deletion, whiteout.
535 +- dynamic branch manipulation, adding, deleting and changing permission.
536 +- allow bypassing aufs, user's direct branch access.
537 +- external inode number translation table and bitmap which maintains the
538 + persistent aufs inode number.
539 +- seekable directory, including NFS readdir.
540 +- file mapping, mmap and sharing pages.
541 +- pseudo-link, hardlink over branches.
542 +- loopback mounted filesystem as a branch.
543 +- several policies to select one among multiple writable branches.
544 +- revert a single systemcall when an error occurs in aufs.
548 +Multi Layered Stackable Unification Filesystem
549 +----------------------------------------------------------------------
550 +Most people already knows what it is.
551 +It is a filesystem which unifies several directories and provides a
552 +merged single directory. When users access a file, the access will be
553 +passed/re-directed/converted (sorry, I am not sure which English word is
554 +correct) to the real file on the member filesystem. The member
555 +filesystem is called 'lower filesystem' or 'branch' and has a mode
556 +'readonly' and 'readwrite.' And the deletion for a file on the lower
557 +readonly branch is handled by creating 'whiteout' on the upper writable
560 +On LKML, there have been discussions about UnionMount (Jan Blunck,
561 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
562 +different approaches to implement the merged-view.
563 +The former tries putting it into VFS, and the latter implements as a
564 +separate filesystem.
565 +(If I misunderstand about these implementations, please let me know and
566 +I shall correct it. Because it is a long time ago when I read their
567 +source files last time).
569 +UnionMount's approach will be able to small, but may be hard to share
570 +branches between several UnionMount since the whiteout in it is
571 +implemented in the inode on branch filesystem and always
572 +shared. According to Bharata's post, readdir does not seems to be
574 +There are several missing features known in this implementations such as
575 +- for users, the inode number may change silently. eg. copy-up.
576 +- link(2) may break by copy-up.
577 +- read(2) may get an obsoleted filedata (fstat(2) too).
578 +- fcntl(F_SETLK) may be broken by copy-up.
579 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
582 +Unionfs has a longer history. When I started implementing a stacking filesystem
583 +(Aug 2005), it already existed. It has virtual super_block, inode,
584 +dentry and file objects and they have an array pointing lower same kind
585 +objects. After contributing many patches for Unionfs, I re-started my
586 +project AUFS (Jun 2006).
588 +In AUFS, the structure of filesystem resembles to Unionfs, but I
589 +implemented my own ideas, approaches and enhancements and it became
590 +totally different one.
592 +Comparing DM snapshot and fs based implementation
593 +- the number of bytes to be copied between devices is much smaller.
594 +- the type of filesystem must be one and only.
595 +- the fs must be writable, no readonly fs, even for the lower original
596 + device. so the compression fs will not be usable. but if we use
597 + loopback mount, we may address this issue.
599 + mount /cdrom/squashfs.img /sq
600 + losetup /sq/ext2.img
601 + losetup /somewhere/cow
602 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
603 +- it will be difficult (or needs more operations) to extract the
604 + difference between the original device and COW.
605 +- DM snapshot-merge may help a lot when users try merging. in the
606 + fs-layer union, users will use rsync(1).
609 +Several characters/aspects of aufs
610 +----------------------------------------------------------------------
612 +Aufs has several characters or aspects.
613 +1. a filesystem, callee of VFS helper
614 +2. sub-VFS, caller of VFS helper for branches
615 +3. a virtual filesystem which maintains persistent inode number
616 +4. reader/writer of files on branches such like an application
618 +1. Callee of VFS Helper
619 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
620 +unlink(2) from an application reaches sys_unlink() kernel function and
621 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
622 +calls filesystem specific unlink operation. Actually aufs implements the
623 +unlink operation but it behaves like a redirector.
625 +2. Caller of VFS Helper for Branches
626 +aufs_unlink() passes the unlink request to the branch filesystem as if
627 +it were called from VFS. So the called unlink operation of the branch
628 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
629 +every necessary pre/post operation for the branch filesystem.
630 +- acquire the lock for the parent dir on a branch
631 +- lookup in a branch
632 +- revalidate dentry on a branch
633 +- mnt_want_write() for a branch
634 +- vfs_unlink() for a branch
635 +- mnt_drop_write() for a branch
636 +- release the lock on a branch
638 +3. Persistent Inode Number
639 +One of the most important issue for a filesystem is to maintain inode
640 +numbers. This is particularly important to support exporting a
641 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
642 +backend block device for its own. But some storage is necessary to
643 +maintain inode number. It may be a large space and may not suit to keep
644 +in memory. Aufs rents some space from its first writable branch
645 +filesystem (by default) and creates file(s) on it. These files are
646 +created by aufs internally and removed soon (currently) keeping opened.
647 +Note: Because these files are removed, they are totally gone after
648 + unmounting aufs. It means the inode numbers are not persistent
649 + across unmount or reboot. I have a plan to make them really
650 + persistent which will be important for aufs on NFS server.
652 +4. Read/Write Files Internally (copy-on-write)
653 +Because a branch can be readonly, when you write a file on it, aufs will
654 +"copy-up" it to the upper writable branch internally. And then write the
655 +originally requested thing to the file. Generally kernel doesn't
656 +open/read/write file actively. In aufs, even a single write may cause a
657 +internal "file copy". This behaviour is very similar to cp(1) command.
659 +Some people may think it is better to pass such work to user space
660 +helper, instead of doing in kernel space. Actually I am still thinking
661 +about it. But currently I have implemented it in kernel space.
662 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
663 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
664 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2013-08-23 23:59:39.631583456 +0200
667 +# Copyright (C) 2005-2013 Junjiro R. Okajima
669 +# This program is free software; you can redistribute it and/or modify
670 +# it under the terms of the GNU General Public License as published by
671 +# the Free Software Foundation; either version 2 of the License, or
672 +# (at your option) any later version.
674 +# This program is distributed in the hope that it will be useful,
675 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
676 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
677 +# GNU General Public License for more details.
679 +# You should have received a copy of the GNU General Public License
680 +# along with this program; if not, write to the Free Software
681 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
683 +Basic Aufs Internal Structure
685 +Superblock/Inode/Dentry/File Objects
686 +----------------------------------------------------------------------
687 +As like an ordinary filesystem, aufs has its own
688 +superblock/inode/dentry/file objects. All these objects have a
689 +dynamically allocated array and store the same kind of pointers to the
690 +lower filesystem, branch.
691 +For example, when you build a union with one readwrite branch and one
692 +readonly, mounted /au, /rw and /ro respectively.
694 +- /ro/fileA exists but /rw/fileA
696 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
697 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
701 +This style of an array is essentially same to the aufs
702 +superblock/inode/dentry/file objects.
704 +Because aufs supports manipulating branches, ie. add/delete/change
705 +dynamically, these objects has its own generation. When branches are
706 +changed, the generation in aufs superblock is incremented. And a
707 +generation in other object are compared when it is accessed.
708 +When a generation in other objects are obsoleted, aufs refreshes the
713 +----------------------------------------------------------------------
714 +Additionally aufs superblock has some data for policies to select one
715 +among multiple writable branches, XIB files, pseudo-links and kobject.
716 +See below in detail.
717 +About the policies which supports copy-down a directory, see policy.txt
721 +Branch and XINO(External Inode Number Translation Table)
722 +----------------------------------------------------------------------
723 +Every branch has its own xino (external inode number translation table)
724 +file. The xino file is created and unlinked by aufs internally. When two
725 +members of a union exist on the same filesystem, they share the single
727 +The struct of a xino file is simple, just a sequence of aufs inode
728 +numbers which is indexed by the lower inode number.
729 +In the above sample, assume the inode number of /ro/fileA is i111 and
730 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
731 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
733 +When the inode numbers are not contiguous, the xino file will be sparse
734 +which has a hole in it and doesn't consume as much disk space as it
735 +might appear. If your branch filesystem consumes disk space for such
736 +holes, then you should specify 'xino=' option at mounting aufs.
738 +Also a writable branch has three kinds of "whiteout bases". All these
739 +are existed when the branch is joined to aufs and the names are
740 +whiteout-ed doubly, so that users will never see their names in aufs
742 +1. a regular file which will be linked to all whiteouts.
743 +2. a directory to store a pseudo-link.
744 +3. a directory to store an "orphan-ed" file temporary.
747 + When you remove a file on a readonly branch, aufs handles it as a
748 + logical deletion and creates a whiteout on the upper writable branch
749 + as a hardlink of this file in order not to consume inode on the
752 + See below, Pseudo-link.
754 + When "fileC" exists on the lower readonly branch only and it is
755 + opened and removed with its parent dir, and then user writes
756 + something into it, then aufs copies-up fileC to this
757 + directory. Because there is no other dir to store fileC. After
758 + creating a file under this dir, the file is unlinked.
760 +Because aufs supports manipulating branches, ie. add/delete/change
761 +dynamically, a branch has its own id. When the branch order changes, aufs
762 +finds the new index by searching the branch id.
766 +----------------------------------------------------------------------
767 +Assume "fileA" exists on the lower readonly branch only and it is
768 +hardlinked to "fileB" on the branch. When you write something to fileA,
769 +aufs copies-up it to the upper writable branch. Additionally aufs
770 +creates a hardlink under the Pseudo-link Directory of the writable
771 +branch. The inode of a pseudo-link is kept in aufs super_block as a
772 +simple list. If fileB is read after unlinking fileA, aufs returns
773 +filedata from the pseudo-link instead of the lower readonly
774 +branch. Because the pseudo-link is based upon the inode, to keep the
775 +inode number by xino (see above) is important.
777 +All the hardlinks under the Pseudo-link Directory of the writable branch
778 +should be restored in a proper location later. Aufs provides a utility
779 +to do this. The userspace helpers executed at remounting and unmounting
781 +During this utility is running, it puts aufs into the pseudo-link
782 +maintenance mode. In this mode, only the process which began the
783 +maintenance mode (and its child processes) is allowed to operate in
784 +aufs. Some other processes which are not related to the pseudo-link will
785 +be allowed to run too, but the rest have to return an error or wait
786 +until the maintenance mode ends. If a process already acquires an inode
787 +mutex (in VFS), it has to return an error.
790 +XIB(external inode number bitmap)
791 +----------------------------------------------------------------------
792 +Addition to the xino file per a branch, aufs has an external inode number
793 +bitmap in a superblock object. It is also a file such like a xino file.
794 +It is a simple bitmap to mark whether the aufs inode number is in-use or
796 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
798 +Aufs implements a feature to truncate/refresh both of xino and xib to
799 +reduce the number of consumed disk blocks for these files.
802 +Virtual or Vertical Dir, and Readdir in Userspace
803 +----------------------------------------------------------------------
804 +In order to support multiple layers (branches), aufs readdir operation
805 +constructs a virtual dir block on memory. For readdir, aufs calls
806 +vfs_readdir() internally for each dir on branches, merges their entries
807 +with eliminating the whiteout-ed ones, and sets it to file (dir)
808 +object. So the file object has its entry list until it is closed. The
809 +entry list will be updated when the file position is zero and becomes
810 +old. This decision is made in aufs automatically.
812 +The dynamically allocated memory block for the name of entries has a
813 +unit of 512 bytes (by default) and stores the names contiguously (no
814 +padding). Another block for each entry is handled by kmem_cache too.
815 +During building dir blocks, aufs creates hash list and judging whether
816 +the entry is whiteouted by its upper branch or already listed.
817 +The merged result is cached in the corresponding inode object and
818 +maintained by a customizable life-time option.
820 +Some people may call it can be a security hole or invite DoS attack
821 +since the opened and once readdir-ed dir (file object) holds its entry
822 +list and becomes a pressure for system memory. But I'd say it is similar
823 +to files under /proc or /sys. The virtual files in them also holds a
824 +memory page (generally) while they are opened. When an idea to reduce
825 +memory for them is introduced, it will be applied to aufs too.
826 +For those who really hate this situation, I've developed readdir(3)
827 +library which operates this merging in userspace. You just need to set
828 +LD_PRELOAD environment variable, and aufs will not consume no memory in
829 +kernel space for readdir(3).
833 +----------------------------------------------------------------------
834 +Aufs sometimes requires privilege access to a branch. For instance,
835 +in copy-up/down operation. When a user process is going to make changes
836 +to a file which exists in the lower readonly branch only, and the mode
837 +of one of ancestor directories may not be writable by a user
838 +process. Here aufs copy-up the file with its ancestors and they may
839 +require privilege to set its owner/group/mode/etc.
840 +This is a typical case of a application character of aufs (see
843 +Aufs uses workqueue synchronously for this case. It creates its own
844 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
845 +passes the request to call mkdir or write (for example), and wait for
846 +its completion. This approach solves a problem of a signal handler
848 +If aufs didn't adopt the workqueue and changed the privilege of the
849 +process, and if the mkdir/write call arises SIGXFSZ or other signal,
850 +then the user process might gain a privilege or the generated core file
851 +was owned by a superuser.
853 +Also aufs uses the system global workqueue ("events" kernel thread) too
854 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
855 +whiteout base and etc. This is unrelated to a privilege.
856 +Most of aufs operation tries acquiring a rw_semaphore for aufs
857 +superblock at the beginning, at the same time waits for the completion
858 +of all queued asynchronous tasks.
862 +----------------------------------------------------------------------
863 +The whiteout in aufs is very similar to Unionfs's. That is represented
864 +by its filename. UnionMount takes an approach of a file mode, but I am
865 +afraid several utilities (find(1) or something) will have to support it.
867 +Basically the whiteout represents "logical deletion" which stops aufs to
868 +lookup further, but also it represents "dir is opaque" which also stop
871 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
872 +In order to make several functions in a single systemcall to be
873 +revertible, aufs adopts an approach to rename a directory to a temporary
874 +unique whiteouted name.
875 +For example, in rename(2) dir where the target dir already existed, aufs
876 +renames the target dir to a temporary unique whiteouted name before the
877 +actual rename on a branch and then handles other actions (make it opaque,
878 +update the attributes, etc). If an error happens in these actions, aufs
879 +simply renames the whiteouted name back and returns an error. If all are
880 +succeeded, aufs registers a function to remove the whiteouted unique
881 +temporary name completely and asynchronously to the system global
886 +----------------------------------------------------------------------
887 +It is a well-known feature or concept.
888 +When user modifies a file on a readonly branch, aufs operate "copy-up"
889 +internally and makes change to the new file on the upper writable branch.
890 +When the trigger systemcall does not update the timestamps of the parent
891 +dir, aufs reverts it after copy-up.
894 +Move-down (aufs3.9 and later)
895 +----------------------------------------------------------------------
896 +"Copy-up" is one of the essential feature in aufs. It copies a file from
897 +the lower readonly branch to the upper writable branch when a user
898 +changes something about the file.
899 +"Move-down" is an opposite action of copy-up. Basically this action is
900 +ran manually instead of automatically and internally.
902 +Sometimes users want to move-down a file from the upper writable branch
903 +to the lower readonly or writable branch. For instance,
904 +- the free space of the upper writable branch is going to run out.
905 +- create a new intermediate branch between the upper and lower branch.
908 +For this purpose, use "aumvdown" command in aufs-util.git.
909 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
910 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
911 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2013-07-06 13:20:47.730197761 +0200
914 +# Copyright (C) 2005-2013 Junjiro R. Okajima
916 +# This program is free software; you can redistribute it and/or modify
917 +# it under the terms of the GNU General Public License as published by
918 +# the Free Software Foundation; either version 2 of the License, or
919 +# (at your option) any later version.
921 +# This program is distributed in the hope that it will be useful,
922 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
923 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
924 +# GNU General Public License for more details.
926 +# You should have received a copy of the GNU General Public License
927 +# along with this program; if not, write to the Free Software
928 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
931 +----------------------------------------------------------------------
932 +Since aufs has a character of sub-VFS (see Introduction), it operates
933 +lookup for branches as VFS does. It may be a heavy work. Generally
934 +speaking struct nameidata is a bigger structure and includes many
935 +information. But almost all lookup operation in aufs is the simplest
936 +case, ie. lookup only an entry directly connected to its parent. Digging
937 +down the directory hierarchy is unnecessary.
939 +VFS has a function lookup_one_len() for that use, but it is not usable
940 +for a branch filesystem which requires struct nameidata. So aufs
941 +implements a simple lookup wrapper function. When a branch filesystem
942 +allows NULL as nameidata, it calls lookup_one_len(). Otherwise it builds
943 +a simplest nameidata and calls lookup_hash().
944 +Here aufs applies "a principle in NFSD", ie. if the filesystem supports
945 +NFS-export, then it has to support NULL as a nameidata parameter for
946 +->create(), ->lookup() and ->d_revalidate(). So the lookup wrapper in
947 +aufs tests if ->s_export_op in the branch is NULL or not.
949 +When a branch is a remote filesystem, aufs basically trusts its
950 +->d_revalidate(), also aufs forces the hardest revalidate tests for
952 +For d_revalidate, aufs implements three levels of revalidate tests. See
953 +"Revalidate Dentry and UDBA" in detail.
957 +----------------------------------------------------------------------
958 +Basically aufs supports any type of filesystem and block device for a
959 +branch (actually there are some exceptions). But it is prohibited to add
960 +a loopback mounted one whose backend file exists in a filesystem which is
961 +already added to aufs. The reason is to protect aufs from a recursive
962 +lookup. If it was allowed, the aufs lookup operation might re-enter a
963 +lookup for the loopback mounted branch in the same context, and will
967 +Revalidate Dentry and UDBA (User's Direct Branch Access)
968 +----------------------------------------------------------------------
969 +Generally VFS helpers re-validate a dentry as a part of lookup.
970 +0. digging down the directory hierarchy.
971 +1. lock the parent dir by its i_mutex.
972 +2. lookup the final (child) entry.
974 +4. call the actual operation (create, unlink, etc.)
975 +5. unlock the parent dir
977 +If the filesystem implements its ->d_revalidate() (step 3), then it is
978 +called. Actually aufs implements it and checks the dentry on a branch is
980 +But it is not enough. Because aufs has to release the lock for the
981 +parent dir on a branch at the end of ->lookup() (step 2) and
982 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
984 +If the file on a branch is changed directly, eg. bypassing aufs, after
985 +aufs released the lock, then the subsequent operation may cause
986 +something unpleasant result.
988 +This situation is a result of VFS architecture, ->lookup() and
989 +->d_revalidate() is separated. But I never say it is wrong. It is a good
990 +design from VFS's point of view. It is just not suitable for sub-VFS
993 +Aufs supports such case by three level of revalidation which is
995 +1. Simple Revalidate
996 + Addition to the native flow in VFS's, confirm the child-parent
997 + relationship on the branch just after locking the parent dir on the
998 + branch in the "actual operation" (step 4). When this validation
999 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1000 + checks the validation of the dentry on branches.
1001 +2. Monitor Changes Internally by Inotify/Fsnotify
1002 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1003 + the dentry on the branch, and returns EBUSY if it finds different
1005 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1006 + during it is in cache. When the event is notified, aufs registers a
1007 + function to kernel 'events' thread by schedule_work(). And the
1008 + function sets some special status to the cached aufs dentry and inode
1009 + private data. If they are not cached, then aufs has nothing to
1010 + do. When the same file is accessed through aufs (step 0-3) later,
1011 + aufs will detect the status and refresh all necessary data.
1012 + In this mode, aufs has to ignore the event which is fired by aufs
1014 +3. No Extra Validation
1015 + This is the simplest test and doesn't add any additional revalidation
1016 + test, and skip therevalidatin in step 4. It is useful and improves
1017 + aufs performance when system surely hide the aufs branches from user,
1018 + by over-mounting something (or another method).
1019 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1020 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1021 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2013-07-06 13:20:47.730197761 +0200
1024 +# Copyright (C) 2005-2013 Junjiro R. Okajima
1026 +# This program is free software; you can redistribute it and/or modify
1027 +# it under the terms of the GNU General Public License as published by
1028 +# the Free Software Foundation; either version 2 of the License, or
1029 +# (at your option) any later version.
1031 +# This program is distributed in the hope that it will be useful,
1032 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1033 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1034 +# GNU General Public License for more details.
1036 +# You should have received a copy of the GNU General Public License
1037 +# along with this program; if not, write to the Free Software
1038 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1040 +Branch Manipulation
1042 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1043 +and changing its permission/attribute, there are a lot of works to do.
1047 +----------------------------------------------------------------------
1048 +o Confirm the adding dir exists outside of aufs, including loopback
1050 +- and other various attributes...
1051 +o Initialize the xino file and whiteout bases if necessary.
1054 +o Check the owner/group/mode of the directory
1055 + When the owner/group/mode of the adding directory differs from the
1056 + existing branch, aufs issues a warning because it may impose a
1058 + For example, when a upper writable branch has a world writable empty
1059 + top directory, a malicious user can create any files on the writable
1060 + branch directly, like copy-up and modify manually. If something like
1061 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1062 + writable branch, and the writable branch is world-writable, then a
1063 + malicious guy may create /etc/passwd on the writable branch directly
1064 + and the infected file will be valid in aufs.
1065 + I am afraid it can be a security issue, but nothing to do except
1066 + producing a warning.
1070 +----------------------------------------------------------------------
1071 +o Confirm the deleting branch is not busy
1072 + To be general, there is one merit to adopt "remount" interface to
1073 + manipulate branches. It is to discard caches. At deleting a branch,
1074 + aufs checks the still cached (and connected) dentries and inodes. If
1075 + there are any, then they are all in-use. An inode without its
1076 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1078 + For the cached one, aufs checks whether the same named entry exists on
1080 + If the cached one is a directory, because aufs provides a merged view
1081 + to users, as long as one dir is left on any branch aufs can show the
1082 + dir to users. In this case, the branch can be removed from aufs.
1083 + Otherwise aufs rejects deleting the branch.
1085 + If any file on the deleting branch is opened by aufs, then aufs
1089 +Modify the Permission of a Branch
1090 +----------------------------------------------------------------------
1091 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1094 +o rw --> ro: Confirm the modifying branch is not busy
1095 + Aufs rejects the request if any of these conditions are true.
1096 + - a file on the branch is mmap-ed.
1097 + - a regular file on the branch is opened for write and there is no
1098 + same named entry on the upper branch.
1099 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1100 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1101 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2013-07-06 13:20:47.730197761 +0200
1104 +# Copyright (C) 2005-2013 Junjiro R. Okajima
1106 +# This program is free software; you can redistribute it and/or modify
1107 +# it under the terms of the GNU General Public License as published by
1108 +# the Free Software Foundation; either version 2 of the License, or
1109 +# (at your option) any later version.
1111 +# This program is distributed in the hope that it will be useful,
1112 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1113 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1114 +# GNU General Public License for more details.
1116 +# You should have received a copy of the GNU General Public License
1117 +# along with this program; if not, write to the Free Software
1118 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1120 +Policies to Select One among Multiple Writable Branches
1121 +----------------------------------------------------------------------
1122 +When the number of writable branch is more than one, aufs has to decide
1123 +the target branch for file creation or copy-up. By default, the highest
1124 +writable branch which has the parent (or ancestor) dir of the target
1125 +file is chosen (top-down-parent policy).
1126 +By user's request, aufs implements some other policies to select the
1127 +writable branch, for file creation two policies, round-robin and
1128 +most-free-space policies. For copy-up three policies, top-down-parent,
1129 +bottom-up-parent and bottom-up policies.
1131 +As expected, the round-robin policy selects the branch in circular. When
1132 +you have two writable branches and creates 10 new files, 5 files will be
1133 +created for each branch. mkdir(2) systemcall is an exception. When you
1134 +create 10 new directories, all will be created on the same branch.
1135 +And the most-free-space policy selects the one which has most free
1136 +space among the writable branches. The amount of free space will be
1137 +checked by aufs internally, and users can specify its time interval.
1139 +The policies for copy-up is more simple,
1140 +top-down-parent is equivalent to the same named on in create policy,
1141 +bottom-up-parent selects the writable branch where the parent dir
1142 +exists and the nearest upper one from the copyup-source,
1143 +bottom-up selects the nearest upper writable branch from the
1144 +copyup-source, regardless the existence of the parent dir.
1146 +There are some rules or exceptions to apply these policies.
1147 +- If there is a readonly branch above the policy-selected branch and
1148 + the parent dir is marked as opaque (a variation of whiteout), or the
1149 + target (creating) file is whiteout-ed on the upper readonly branch,
1150 + then the result of the policy is ignored and the target file will be
1151 + created on the nearest upper writable branch than the readonly branch.
1152 +- If there is a writable branch above the policy-selected branch and
1153 + the parent dir is marked as opaque or the target file is whiteouted
1154 + on the branch, then the result of the policy is ignored and the target
1155 + file will be created on the highest one among the upper writable
1156 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1158 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1159 + They try selecting the branch where the source exists as possible
1160 + since copyup a large file will take long time. If it can't be,
1161 + ie. the branch where the source exists is readonly, then they will
1162 + follow the copyup policy.
1163 +- There is an exception for rename(2) when the target exists.
1164 + If the rename target exists, aufs compares the index of the branches
1165 + where the source and the target exists and selects the higher
1166 + one. If the selected branch is readonly, then aufs follows the
1168 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
1169 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
1170 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2013-07-06 13:20:47.730197761 +0200
1173 +# Copyright (C) 2005-2013 Junjiro R. Okajima
1175 +# This program is free software; you can redistribute it and/or modify
1176 +# it under the terms of the GNU General Public License as published by
1177 +# the Free Software Foundation; either version 2 of the License, or
1178 +# (at your option) any later version.
1180 +# This program is distributed in the hope that it will be useful,
1181 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1182 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1183 +# GNU General Public License for more details.
1185 +# You should have received a copy of the GNU General Public License
1186 +# along with this program; if not, write to the Free Software
1187 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1189 +mmap(2) -- File Memory Mapping
1190 +----------------------------------------------------------------------
1191 +In aufs, the file-mapped pages are handled by a branch fs directly, no
1192 +interaction with aufs. It means aufs_mmap() calls the branch fs's
1194 +This approach is simple and good, but there is one problem.
1195 +Under /proc, several entries show the mmap-ped files by its path (with
1196 +device and inode number), and the printed path will be the path on the
1197 +branch fs's instead of virtual aufs's.
1198 +This is not a problem in most cases, but some utilities lsof(1) (and its
1199 +user) may expect the path on aufs.
1201 +To address this issue, aufs adds a new member called vm_prfile in struct
1202 +vm_area_struct (and struct vm_region). The original vm_file points to
1203 +the file on the branch fs in order to handle everything correctly as
1204 +usual. The new vm_prfile points to a virtual file in aufs, and the
1205 +show-functions in procfs refers to vm_prfile if it is set.
1206 +Also we need to maintain several other places where touching vm_file
1208 +- fork()/clone() copies vma and the reference count of vm_file is
1210 +- merging vma maintains the ref count too.
1212 +This is not a good approach. It just faking the printed path. But it
1213 +leaves all behaviour around f_mapping unchanged. This is surely an
1215 +Actually aufs had adopted another complicated approach which calls
1216 +generic_file_mmap() and handles struct vm_operations_struct. In this
1217 +approach, aufs met a hard problem and I could not solve it without
1218 +switching the approach.
1219 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
1220 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
1221 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2013-07-06 13:20:47.736864659 +0200
1224 +# Copyright (C) 2005-2013 Junjiro R. Okajima
1226 +# This program is free software; you can redistribute it and/or modify
1227 +# it under the terms of the GNU General Public License as published by
1228 +# the Free Software Foundation; either version 2 of the License, or
1229 +# (at your option) any later version.
1231 +# This program is distributed in the hope that it will be useful,
1232 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1233 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1234 +# GNU General Public License for more details.
1236 +# You should have received a copy of the GNU General Public License
1237 +# along with this program; if not, write to the Free Software
1238 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1240 +Export Aufs via NFS
1241 +----------------------------------------------------------------------
1242 +Here is an approach.
1243 +- like xino/xib, add a new file 'xigen' which stores aufs inode
1245 +- iget_locked(): initialize aufs inode generation for a new inode, and
1246 + store it in xigen file.
1247 +- destroy_inode(): increment aufs inode generation and store it in xigen
1248 + file. it is necessary even if it is not unlinked, because any data of
1249 + inode may be changed by UDBA.
1250 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
1251 + build file handle by
1252 + + branch id (4 bytes)
1253 + + superblock generation (4 bytes)
1254 + + inode number (4 or 8 bytes)
1255 + + parent dir inode number (4 or 8 bytes)
1256 + + inode generation (4 bytes))
1257 + + return value of exportfs_encode_fh() for the parent on a branch (4
1259 + + file handle for a branch (by exportfs_encode_fh())
1261 + + find the index of a branch from its id in handle, and check it is
1262 + still exist in aufs.
1263 + + 1st level: get the inode number from handle and search it in cache.
1264 + + 2nd level: if not found, get the parent inode number from handle and
1265 + search it in cache. and then open the parent dir, find the matching
1266 + inode number by vfs_readdir() and get its name, and call
1267 + lookup_one_len() for the target dentry.
1268 + + 3rd level: if the parent dir is not cached, call
1269 + exportfs_decode_fh() for a branch and get the parent on a branch,
1270 + build a pathname of it, convert it a pathname in aufs, call
1271 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
1273 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
1274 + for every branch, but not itself. to get this, (currently) aufs
1275 + searches in current->nsproxy->mnt_ns list. it may not be a good
1276 + idea, but I didn't get other approach.
1277 + + test the generation of the gotten inode.
1278 +- every inode operation: they may get EBUSY due to UDBA. in this case,
1279 + convert it into ESTALE for NFSD.
1280 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
1281 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
1282 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
1283 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
1284 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2013-07-06 13:20:47.736864659 +0200
1287 +# Copyright (C) 2005-2013 Junjiro R. Okajima
1289 +# This program is free software; you can redistribute it and/or modify
1290 +# it under the terms of the GNU General Public License as published by
1291 +# the Free Software Foundation; either version 2 of the License, or
1292 +# (at your option) any later version.
1294 +# This program is distributed in the hope that it will be useful,
1295 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1296 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1297 +# GNU General Public License for more details.
1299 +# You should have received a copy of the GNU General Public License
1300 +# along with this program; if not, write to the Free Software
1301 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1303 +Show Whiteout Mode (shwh)
1304 +----------------------------------------------------------------------
1305 +Generally aufs hides the name of whiteouts. But in some cases, to show
1306 +them is very useful for users. For instance, creating a new middle layer
1307 +(branch) by merging existing layers.
1309 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
1310 +When you have three branches,
1311 +- Bottom: 'system', squashfs (underlying base system), read-only
1312 +- Middle: 'mods', squashfs, read-only
1313 +- Top: 'overlay', ram (tmpfs), read-write
1315 +The top layer is loaded at boot time and saved at shutdown, to preserve
1316 +the changes made to the system during the session.
1317 +When larger changes have been made, or smaller changes have accumulated,
1318 +the size of the saved top layer data grows. At this point, it would be
1319 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
1320 +and rewrite the 'mods' squashfs, clearing the top layer and thus
1321 +restoring save and load speed.
1323 +This merging is simplified by the use of another aufs mount, of just the
1324 +two overlay branches using the 'shwh' option.
1325 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
1326 + aufs /livesys/merge_union
1328 +A merged view of these two branches is then available at
1329 +/livesys/merge_union, and the new feature is that the whiteouts are
1331 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
1332 +writing to all branches. Also the default mode for all branches is 'ro'.
1333 +It is now possible to save the combined contents of the two overlay
1334 +branches to a new squashfs, e.g.:
1335 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
1337 +This new squashfs archive can be stored on the boot device and the
1338 +initramfs will use it to replace the old one at the next boot.
1339 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
1340 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
1341 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2013-07-06 13:20:47.736864659 +0200
1344 +# Copyright (C) 2010-2013 Junjiro R. Okajima
1346 +# This program is free software; you can redistribute it and/or modify
1347 +# it under the terms of the GNU General Public License as published by
1348 +# the Free Software Foundation; either version 2 of the License, or
1349 +# (at your option) any later version.
1351 +# This program is distributed in the hope that it will be useful,
1352 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1353 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1354 +# GNU General Public License for more details.
1356 +# You should have received a copy of the GNU General Public License
1357 +# along with this program; if not, write to the Free Software
1358 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1360 +Dynamically customizable FS operations
1361 +----------------------------------------------------------------------
1362 +Generally FS operations (struct inode_operations, struct
1363 +address_space_operations, struct file_operations, etc.) are defined as
1364 +"static const", but it never means that FS have only one set of
1365 +operation. Some FS have multiple sets of them. For instance, ext2 has
1366 +three sets, one for XIP, for NOBH, and for normal.
1367 +Since aufs overrides and redirects these operations, sometimes aufs has
1368 +to change its behaviour according to the branch FS type. More imporantly
1369 +VFS acts differently if a function (member in the struct) is set or
1370 +not. It means aufs should have several sets of operations and select one
1371 +among them according to the branch FS definition.
1373 +In order to solve this problem and not to affect the behavour of VFS,
1374 +aufs defines these operations dynamically. For instance, aufs defines
1375 +aio_read function for struct file_operations, but it may not be set to
1376 +the file_operations. When the branch FS doesn't have it, aufs doesn't
1377 +set it to its file_operations while the function definition itself is
1378 +still alive. So the behaviour of io_submit(2) will not change, and it
1379 +will return an error when aio_read is not defined.
1381 +The lifetime of these dynamically generated operation object is
1382 +maintained by aufs branch object. When the branch is removed from aufs,
1383 +the reference counter of the object is decremented. When it reaches
1384 +zero, the dynamically generated operation object will be freed.
1386 +This approach is designed to support AIO (io_submit), Direcit I/O and
1388 +Currently this approach is applied to file_operations and
1389 +vm_operations_struct for regular files only.
1390 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt linux/Documentation/filesystems/aufs/design/99plan.txt
1391 --- /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt 1970-01-01 01:00:00.000000000 +0100
1392 +++ linux/Documentation/filesystems/aufs/design/99plan.txt 2013-07-06 13:20:47.736864659 +0200
1395 +# Copyright (C) 2005-2013 Junjiro R. Okajima
1397 +# This program is free software; you can redistribute it and/or modify
1398 +# it under the terms of the GNU General Public License as published by
1399 +# the Free Software Foundation; either version 2 of the License, or
1400 +# (at your option) any later version.
1402 +# This program is distributed in the hope that it will be useful,
1403 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1404 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1405 +# GNU General Public License for more details.
1407 +# You should have received a copy of the GNU General Public License
1408 +# along with this program; if not, write to the Free Software
1409 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1413 +Restoring some features which was implemented in aufs1.
1414 +They were dropped in aufs2 in order to make source files simpler and
1415 +easier to be reviewed.
1418 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1419 +----------------------------------------------------------------------
1420 +Let's try case study.
1421 +- aufs has two branches, upper readwrite and lower readonly.
1423 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1424 +- user invoked "chmod a+rx /au/dirA"
1425 +- then "dirA" becomes world readable?
1427 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1428 +or it may be a natively readonly filesystem. If aufs respects the lower
1429 +branch, it should not respond readdir request from other users. But user
1430 +allowed it by chmod. Should really aufs rejects showing the entries
1433 +To be honest, I don't have a best solution for this case. So I
1434 +implemented 'dirperm1' and 'nodirperm1' option in aufs1, and leave it to
1436 +When dirperm1 is specified, aufs checks only the highest one for the
1437 +directory permission, and shows the entries. Otherwise, as usual, checks
1438 +every dir existing on all branches and rejects the request.
1440 +As a side effect, dirperm1 option improves the performance of aufs
1441 +because the number of permission check is reduced.
1444 +Being Another Aufs's Readonly Branch (robr)
1445 +----------------------------------------------------------------------
1446 +Aufs1 allows aufs to be another aufs's readonly branch.
1447 +This feature was developed by a user's request. But it may not be used
1451 +Copy-up on Open (coo=)
1452 +----------------------------------------------------------------------
1453 +By default the internal copy-up is executed when it is really necessary.
1454 +It is not done when a file is opened for writing, but when write(2) is
1455 +done. Users who have many (over 100) branches want to know and analyse
1456 +when and what file is copied-up. To insert a new upper branch which
1457 +contains such files only may improve the performance of aufs.
1459 +Aufs1 implemented "coo=none | leaf | all" option.
1462 +Refresh the Opened File (refrof)
1463 +----------------------------------------------------------------------
1464 +This option is implemented in aufs1 but incomplete.
1466 +When user reads from a file, he expects to get its latest filedata
1467 +generally. If the file is removed and a new same named file is created,
1468 +the content he gets is unchanged, ie. the unlinked filedata.
1470 +Let's try case study again.
1471 +- aufs has two branches.
1473 +- "fileA" exists under /ro, but /rw.
1474 +- user opened "/au/fileA".
1475 +- he or someone else inserts a branch (/new) between /rw and /ro.
1476 + /au = /rw + /new + /ro
1477 +- the new branch has "fileA".
1478 +- user reads from the opened "fileA"
1479 +- which filedata should aufs return, from /ro or /new?
1481 +Some people says it has to be "from /ro" and it is a semantics of Unix.
1482 +The others say it should be "from /new" because the file is not removed
1483 +and it is equivalent to the case of someone else modifies the file.
1485 +Here again I don't have a best and final answer. I got an idea to
1486 +implement 'refrof' and 'norefrof' option. When 'refrof' (REFResh the
1487 +Opened File) is specified (by default), aufs returns the filedata from
1489 +Otherwise from /new.
1490 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
1491 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
1492 +++ linux/Documentation/filesystems/aufs/README 2013-07-30 22:42:46.229279157 +0200
1495 +Aufs3 -- advanced multi layered unification filesystem version 3.x
1501 +----------------------------------------
1502 +In the early days, aufs was entirely re-designed and re-implemented
1503 +Unionfs Version 1.x series. After many original ideas, approaches,
1504 +improvements and implementations, it becomes totally different from
1505 +Unionfs while keeping the basic features.
1506 +Recently, Unionfs Version 2.x series begin taking some of the same
1507 +approaches to aufs1's.
1508 +Unionfs is being developed by Professor Erez Zadok at Stony Brook
1509 +University and his team.
1511 +Aufs3 supports linux-3.0 and later.
1512 +If you want older kernel version support, try aufs2-2.6.git or
1513 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
1515 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
1516 +According to Christoph Hellwig, linux rejects all union-type filesystems
1518 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
1522 +----------------------------------------
1523 +- unite several directories into a single virtual filesystem. The member
1524 + directory is called as a branch.
1525 +- you can specify the permission flags to the branch, which are 'readonly',
1526 + 'readwrite' and 'whiteout-able.'
1527 +- by upper writable branch, internal copyup and whiteout, files/dirs on
1528 + readonly branch are modifiable logically.
1529 +- dynamic branch manipulation, add, del.
1532 +Also there are many enhancements in aufs1, such as:
1533 +- readdir(3) in userspace.
1534 +- keep inode number by external inode number table
1535 +- keep the timestamps of file/dir in internal copyup operation
1536 +- seekable directory, supporting NFS readdir.
1537 +- whiteout is hardlinked in order to reduce the consumption of inodes
1539 +- do not copyup, nor create a whiteout when it is unnecessary
1540 +- revert a single systemcall when an error occurs in aufs
1541 +- remount interface instead of ioctl
1542 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
1543 +- loopback mounted filesystem as a branch
1544 +- kernel thread for removing the dir who has a plenty of whiteouts
1545 +- support copyup sparse file (a file which has a 'hole' in it)
1546 +- default permission flags for branches
1547 +- selectable permission flags for ro branch, whether whiteout can
1550 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
1551 +- support multiple writable branches, some policies to select one
1552 + among multiple writable branches.
1553 +- a new semantics for link(2) and rename(2) to support multiple
1554 + writable branches.
1555 +- no glibc changes are required.
1556 +- pseudo hardlink (hardlink over branches)
1557 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
1558 + including NFS or remote filesystem branch.
1559 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
1562 +Currently these features are dropped temporary from aufs3.
1563 +See design/08plan.txt in detail.
1564 +- test only the highest one for the directory permission (dirperm1)
1565 +- copyup on open (coo=)
1566 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
1568 +- statistics of aufs thread (/sys/fs/aufs/stat)
1569 +- delegation mode (dlgt)
1570 + a delegation of the internal branch access to support task I/O
1571 + accounting, which also supports Linux Security Modules (LSM) mainly
1572 + for Suse AppArmor.
1573 +- intent.open/create (file open in a single lookup)
1575 +Features or just an idea in the future (see also design/*.txt),
1576 +- reorder the branch index without del/re-add.
1577 +- permanent xino files for NFSD
1578 +- an option for refreshing the opened files after add/del branches
1579 +- 'move' policy for copy-up between two writable branches, after
1580 + checking free space.
1581 +- light version, without branch manipulation. (unnecessary?)
1582 +- copyup in userspace
1583 +- inotify in userspace
1589 +----------------------------------------
1590 +There were three GIT trees for aufs3, aufs3-linux.git,
1591 +aufs3-standalone.git, and aufs-util.git. Note that there is no "3" in
1593 +While the aufs-util is always necessary, you need either of aufs3-linux
1594 +or aufs3-standalone.
1596 +The aufs3-linux tree includes the whole linux mainline GIT tree,
1597 +git://git.kernel.org/.../torvalds/linux.git.
1598 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
1599 +build aufs3 as an external kernel module.
1601 +On the other hand, the aufs3-standalone tree has only aufs source files
1602 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
1604 +You will find GIT branches whose name is in form of "aufs3.x" where "x"
1605 +represents the linux kernel version, "linux-3.x". For instance,
1606 +"aufs3.0" is for linux-3.0. For latest "linux-3.x-rcN", use
1607 +"aufs3.x-rcN" branch.
1610 +$ git clone --reference /your/linux/git/tree \
1611 + git://git.code.sf.net/p/aufs/aufs3-linux aufs-aufs3-linux \
1613 +- if you don't have linux GIT tree, then remove "--reference ..."
1614 +$ cd aufs3-linux.git
1615 +$ git checkout origin/aufs3.0
1617 +o aufs3-standalone tree
1618 +$ git clone git://git.code.sf.net/p/aufs/aufs3-standalone \
1619 + aufs3-standalone.git
1620 +$ cd aufs3-standalone.git
1621 +$ git checkout origin/aufs3.0
1624 +$ git clone git://git.code.sf.net/p/aufs/aufs-util \
1627 +$ git checkout origin/aufs3.0
1629 +Note: The 3.x-rcN branch is to be used with `rc' kernel versions ONLY.
1630 +The minor version number, 'x' in '3.x', of aufs may not always
1631 +follow the minor version number of the kernel.
1632 +Because changes in the kernel that cause the use of a new
1633 +minor version number do not always require changes to aufs-util.
1635 +Since aufs-util has its own minor version number, you may not be
1636 +able to find a GIT branch in aufs-util for your kernel's
1637 +exact minor version number.
1638 +In this case, you should git-checkout the branch for the
1639 +nearest lower number.
1641 +For (an unreleased) example:
1642 +If you are using "linux-3.10" and the "aufs3.10" branch
1643 +does not exist in aufs-util repository, then "aufs3.9", "aufs3.8"
1644 +or something numerically smaller is the branch for your kernel.
1646 +Also you can view all branches by
1650 +3. Configuration and Compilation
1651 +----------------------------------------
1652 +Make sure you have git-checkout'ed the correct branch.
1654 +For aufs3-linux tree,
1655 +- enable CONFIG_AUFS_FS.
1656 +- set other aufs configurations if necessary.
1658 +For aufs3-standalone tree,
1659 +There are several ways to build.
1662 +- apply ./aufs3-kbuild.patch to your kernel source files.
1663 +- apply ./aufs3-base.patch too.
1664 +- apply ./aufs3-proc_map.patch too, if you want to make /proc/PID/maps (and
1665 + others including lsof(1)) show the file path on aufs instead of the
1666 + path on the branch fs.
1667 +- apply ./aufs3-standalone.patch too, if you have a plan to set
1668 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs3-standalone.patch.
1669 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
1670 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
1671 +- enable CONFIG_AUFS_FS, you can select either
1673 +- and build your kernel as usual.
1674 +- install the built kernel.
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 if you set CONFIG_AUFS_FS=m.
1678 +- install the header files too by "make headers_install" to the
1679 + directory where you specify. By default, it is $PWD/usr.
1680 + "make help" shows a brief note for headers_install.
1681 +- and reboot your system.
1684 +- module only (CONFIG_AUFS_FS=m).
1685 +- apply ./aufs3-base.patch to your kernel source files.
1686 +- apply ./aufs3-proc_map.patch too to your kernel source files,
1687 + if you want to make /proc/PID/maps (and others including lsof(1)) show
1688 + the file path on aufs instead of the path on the branch fs.
1689 +- apply ./aufs3-standalone.patch too.
1690 +- build your kernel, don't forget "make headers_install", and reboot.
1691 +- edit ./config.mk and set other aufs configurations if necessary.
1692 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
1693 + every aufs configurations.
1694 +- build the module by simple "make".
1695 + Note: Since linux-3.9, every filesystem module requires an alias
1696 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
1697 + modules.aliases file.
1698 +- you can specify ${KDIR} make variable which points to your kernel
1700 +- install the files
1701 + + run "make install" to install the aufs module, or copy the built
1702 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
1703 + + run "make install_headers" (instead of headers_install) to install
1704 + the modified aufs header file (you can specify DESTDIR which is
1705 + available in aufs standalone version's Makefile only), or copy
1706 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
1707 + you like manually. By default, the target directory is $PWD/usr.
1708 +- no need to apply aufs3-kbuild.patch, nor copying source files to your
1709 + kernel source tree.
1711 +Note: The header file aufs_type.h is necessary to build aufs-util
1712 + as well as "make headers_install" in the kernel source tree.
1713 + headers_install is subject to be forgotten, but it is essentially
1714 + necessary, not only for building aufs-util.
1715 + You may not meet problems without headers_install in some older
1719 +- read README in aufs-util, build and install it
1720 +- note that your distribution may contain an obsoleted version of
1721 + aufs_type.h in /usr/include/linux or something. When you build aufs
1722 + utilities, make sure that your compiler refers the correct aufs header
1723 + file which is built by "make headers_install."
1724 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
1725 + then run "make install_ulib" too. And refer to the aufs manual in
1730 +----------------------------------------
1731 +At first, make sure aufs-util are installed, and please read the aufs
1732 +manual, aufs.5 in aufs-util.git tree.
1736 +$ mkdir /tmp/rw /tmp/aufs
1737 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
1739 +Here is another example. The result is equivalent.
1740 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
1742 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
1743 +# mount -o remount,append:${HOME} /tmp/aufs
1745 +Then, you can see whole tree of your home dir through /tmp/aufs. If
1746 +you modify a file under /tmp/aufs, the one on your home directory is
1747 +not affected, instead the same named file will be newly created under
1748 +/tmp/rw. And all of your modification to a file will be applied to
1749 +the one under /tmp/rw. This is called the file based Copy on Write
1751 +Aufs mount options are described in aufs.5.
1752 +If you run chroot or something and make your aufs as a root directory,
1753 +then you need to customize the shutdown script. See the aufs manual in
1756 +Additionally, there are some sample usages of aufs which are a
1757 +diskless system with network booting, and LiveCD over NFS.
1758 +See sample dir in CVS tree on SourceForge.
1762 +----------------------------------------
1763 +When you have any problems or strange behaviour in aufs, please let me
1765 +- /proc/mounts (instead of the output of mount(8))
1766 +- /sys/module/aufs/*
1767 +- /sys/fs/aufs/* (if you have them)
1768 +- /debug/aufs/* (if you have them)
1769 +- linux kernel version
1770 + if your kernel is not plain, for example modified by distributor,
1771 + the url where i can download its source is necessary too.
1772 +- aufs version which was printed at loading the module or booting the
1773 + system, instead of the date you downloaded.
1774 +- configuration (define/undefine CONFIG_AUFS_xxx)
1775 +- kernel configuration or /proc/config.gz (if you have it)
1776 +- behaviour which you think to be incorrect
1777 +- actual operation, reproducible one is better
1778 +- mailto: aufs-users at lists.sourceforge.net
1780 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
1781 +and Feature Requests) on SourceForge. Please join and write to
1785 +6. Acknowledgements
1786 +----------------------------------------
1787 +Thanks to everyone who have tried and are using aufs, whoever
1788 +have reported a bug or any feedback.
1790 +Especially donators:
1791 +Tomas Matejicek(slax.org) made a donation (much more than once).
1792 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
1793 + scripts) is making "doubling" donations.
1794 + Unfortunately I cannot list all of the donators, but I really
1796 + It ends Aug 2010, but the ordinary donation URL is still available.
1797 + <http://sourceforge.net/donate/index.php?group_id=167503>
1798 +Dai Itasaka made a donation (2007/8).
1799 +Chuck Smith made a donation (2008/4, 10 and 12).
1800 +Henk Schoneveld made a donation (2008/9).
1801 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
1802 +Francois Dupoux made a donation (2008/11).
1803 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
1804 + aufs2 GIT tree (2009/2).
1805 +William Grant made a donation (2009/3).
1806 +Patrick Lane made a donation (2009/4).
1807 +The Mail Archive (mail-archive.com) made donations (2009/5).
1808 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
1809 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
1810 +Pavel Pronskiy made a donation (2011/2).
1811 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
1812 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
1813 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
1815 +Sam Liddicott made a donation (2011/9).
1816 +Era Scarecrow made a donation (2013/4).
1817 +Bor Ratajc made a donation (2013/4).
1818 +Alessandro Gorreta made a donation (2013/4).
1819 +POIRETTE Marc made a donation (2013/4).
1820 +Alessandro Gorreta made a donation (2013/4).
1821 +lauri kasvandik made a donation (2013/5).
1822 +pemasu from Finland made a donation (2013/7).
1824 +Thank you very much.
1825 +Donations are always, including future donations, very important and
1826 +helpful for me to keep on developing aufs.
1830 +----------------------------------------
1831 +If you are an experienced user, no explanation is needed. Aufs is
1832 +just a linux filesystem.
1837 +# Local variables: ;
1840 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
1841 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
1842 +++ linux/fs/aufs/aufs.h 2013-07-06 13:20:47.736864659 +0200
1845 + * Copyright (C) 2005-2013 Junjiro R. Okajima
1847 + * This program, aufs is free software; you can redistribute it and/or modify
1848 + * it under the terms of the GNU General Public License as published by
1849 + * the Free Software Foundation; either version 2 of the License, or
1850 + * (at your option) any later version.
1852 + * This program is distributed in the hope that it will be useful,
1853 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1854 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1855 + * GNU General Public License for more details.
1857 + * You should have received a copy of the GNU General Public License
1858 + * along with this program; if not, write to the Free Software
1859 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1863 + * all header files
1871 +#define AuStub(type, name, body, ...) \
1872 + static inline type name(__VA_ARGS__) { body; }
1874 +#define AuStubVoid(name, ...) \
1875 + AuStub(void, name, , __VA_ARGS__)
1876 +#define AuStubInt0(name, ...) \
1877 + AuStub(int, name, return 0, __VA_ARGS__)
1881 +#include "branch.h"
1884 +#include "dbgaufs.h"
1885 +#include "dentry.h"
1889 +#include "fstype.h"
1892 +#include "module.h"
1897 +#include "sysaufs.h"
1902 +#endif /* __KERNEL__ */
1903 +#endif /* __AUFS_H__ */
1904 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
1905 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
1906 +++ linux/fs/aufs/branch.c 2013-07-30 22:42:55.839613269 +0200
1909 + * Copyright (C) 2005-2013 Junjiro R. Okajima
1911 + * This program, aufs is free software; you can redistribute it and/or modify
1912 + * it under the terms of the GNU General Public License as published by
1913 + * the Free Software Foundation; either version 2 of the License, or
1914 + * (at your option) any later version.
1916 + * This program is distributed in the hope that it will be useful,
1917 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1918 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1919 + * GNU General Public License for more details.
1921 + * You should have received a copy of the GNU General Public License
1922 + * along with this program; if not, write to the Free Software
1923 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1927 + * branch management
1930 +#include <linux/compat.h>
1931 +#include <linux/statfs.h>
1935 + * free a single branch
1938 +/* prohibit rmdir to the root of the branch */
1939 +/* todo: another new flag? */
1940 +static void au_br_dflags_force(struct au_branch *br)
1942 + struct dentry *h_dentry;
1944 + h_dentry = au_br_dentry(br);
1945 + spin_lock(&h_dentry->d_lock);
1946 + br->br_dflags = h_dentry->d_flags & DCACHE_MOUNTED;
1947 + h_dentry->d_flags |= DCACHE_MOUNTED;
1948 + spin_unlock(&h_dentry->d_lock);
1951 +/* restore its d_flags */
1952 +static void au_br_dflags_restore(struct au_branch *br)
1954 + struct dentry *h_dentry;
1956 + if (br->br_dflags)
1959 + h_dentry = au_br_dentry(br);
1960 + spin_lock(&h_dentry->d_lock);
1961 + h_dentry->d_flags &= ~DCACHE_MOUNTED;
1962 + spin_unlock(&h_dentry->d_lock);
1965 +static void au_br_do_free(struct au_branch *br)
1968 + struct au_wbr *wbr;
1969 + struct au_dykey **key;
1971 + au_hnotify_fin_br(br);
1973 + if (br->br_xino.xi_file)
1974 + fput(br->br_xino.xi_file);
1975 + mutex_destroy(&br->br_xino.xi_nondir_mtx);
1977 + AuDebugOn(atomic_read(&br->br_count));
1981 + for (i = 0; i < AuBrWh_Last; i++)
1982 + dput(wbr->wbr_wh[i]);
1983 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
1984 + AuRwDestroy(&wbr->wbr_wh_rwsem);
1987 + key = br->br_dykey;
1988 + for (i = 0; i < AuBrDynOp; i++, key++)
1994 + au_br_dflags_restore(br);
1996 + /* recursive lock, s_umount of branch's */
1998 + path_put(&br->br_path);
2005 + * frees all branches
2007 +void au_br_free(struct au_sbinfo *sbinfo)
2009 + aufs_bindex_t bmax;
2010 + struct au_branch **br;
2012 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2014 + bmax = sbinfo->si_bend + 1;
2015 + br = sbinfo->si_branch;
2017 + au_br_do_free(*br++);
2021 + * find the index of a branch which is specified by @br_id.
2023 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
2025 + aufs_bindex_t bindex, bend;
2027 + bend = au_sbend(sb);
2028 + for (bindex = 0; bindex <= bend; bindex++)
2029 + if (au_sbr_id(sb, bindex) == br_id)
2034 +/* ---------------------------------------------------------------------- */
2040 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
2041 + struct dentry *h_root)
2043 + if (unlikely(h_adding == h_root
2044 + || au_test_loopback_overlap(sb, h_adding)))
2046 + if (h_adding->d_sb != h_root->d_sb)
2048 + return au_test_subdir(h_adding, h_root)
2049 + || au_test_subdir(h_root, h_adding);
2053 + * returns a newly allocated branch. @new_nbranch is a number of branches
2054 + * after adding a branch.
2056 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
2059 + struct au_branch *add_branch;
2060 + struct dentry *root;
2064 + root = sb->s_root;
2065 + add_branch = kmalloc(sizeof(*add_branch), GFP_NOFS);
2066 + if (unlikely(!add_branch))
2069 + err = au_hnotify_init_br(add_branch, perm);
2070 + if (unlikely(err))
2073 + add_branch->br_wbr = NULL;
2074 + if (au_br_writable(perm)) {
2075 + /* may be freed separately at changing the branch permission */
2076 + add_branch->br_wbr = kmalloc(sizeof(*add_branch->br_wbr),
2078 + if (unlikely(!add_branch->br_wbr))
2082 + err = au_sbr_realloc(au_sbi(sb), new_nbranch);
2084 + err = au_di_realloc(au_di(root), new_nbranch);
2086 + err = au_ii_realloc(au_ii(root->d_inode), new_nbranch);
2088 + return add_branch; /* success */
2090 + kfree(add_branch->br_wbr);
2093 + au_hnotify_fin_br(add_branch);
2095 + kfree(add_branch);
2097 + return ERR_PTR(err);
2101 + * test if the branch permission is legal or not.
2103 +static int test_br(struct inode *inode, int brperm, char *path)
2107 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
2112 + pr_err("write permission for readonly mount or inode, %s\n", path);
2120 + * 0: success, the caller will add it
2121 + * plus: success, it is already unified, the caller should ignore it
2124 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
2127 + aufs_bindex_t bend, bindex;
2128 + struct dentry *root;
2129 + struct inode *inode, *h_inode;
2131 + root = sb->s_root;
2132 + bend = au_sbend(sb);
2133 + if (unlikely(bend >= 0
2134 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
2138 + pr_err("%s duplicated\n", add->pathname);
2143 + err = -ENOSPC; /* -E2BIG; */
2144 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
2145 + || AUFS_BRANCH_MAX - 1 <= bend)) {
2146 + pr_err("number of branches exceeded %s\n", add->pathname);
2151 + if (unlikely(add->bindex < 0 || bend + 1 < add->bindex)) {
2152 + pr_err("bad index %d\n", add->bindex);
2156 + inode = add->path.dentry->d_inode;
2158 + if (unlikely(!inode->i_nlink)) {
2159 + pr_err("no existence %s\n", add->pathname);
2164 + if (unlikely(inode->i_sb == sb)) {
2165 + pr_err("%s must be outside\n", add->pathname);
2169 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
2170 + pr_err("unsupported filesystem, %s (%s)\n",
2171 + add->pathname, au_sbtype(inode->i_sb));
2175 + err = test_br(add->path.dentry->d_inode, add->perm, add->pathname);
2176 + if (unlikely(err))
2180 + return 0; /* success */
2183 + for (bindex = 0; bindex <= bend; bindex++)
2184 + if (unlikely(test_overlap(sb, add->path.dentry,
2185 + au_h_dptr(root, bindex)))) {
2186 + pr_err("%s is overlapped\n", add->pathname);
2191 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
2192 + h_inode = au_h_dptr(root, 0)->d_inode;
2193 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
2194 + || !uid_eq(h_inode->i_uid, inode->i_uid)
2195 + || !gid_eq(h_inode->i_gid, inode->i_gid))
2196 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
2198 + i_uid_read(inode), i_gid_read(inode),
2199 + (inode->i_mode & S_IALLUGO),
2200 + i_uid_read(h_inode), i_gid_read(h_inode),
2201 + (h_inode->i_mode & S_IALLUGO));
2209 + * initialize or clean the whiteouts for an adding branch
2211 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
2214 + int err, old_perm;
2215 + aufs_bindex_t bindex;
2216 + struct mutex *h_mtx;
2217 + struct au_wbr *wbr;
2218 + struct au_hinode *hdir;
2220 + err = vfsub_mnt_want_write(au_br_mnt(br));
2221 + if (unlikely(err))
2225 + old_perm = br->br_perm;
2226 + br->br_perm = new_perm;
2229 + bindex = au_br_index(sb, br->br_id);
2230 + if (0 <= bindex) {
2231 + hdir = au_hi(sb->s_root->d_inode, bindex);
2232 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
2234 + h_mtx = &au_br_dentry(br)->d_inode->i_mutex;
2235 + mutex_lock_nested(h_mtx, AuLsc_I_PARENT);
2238 + err = au_wh_init(br, sb);
2240 + wbr_wh_write_lock(wbr);
2241 + err = au_wh_init(br, sb);
2242 + wbr_wh_write_unlock(wbr);
2245 + au_hn_imtx_unlock(hdir);
2247 + mutex_unlock(h_mtx);
2248 + vfsub_mnt_drop_write(au_br_mnt(br));
2249 + br->br_perm = old_perm;
2251 + if (!err && wbr && !au_br_writable(new_perm)) {
2253 + br->br_wbr = NULL;
2260 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
2264 + struct kstatfs kst;
2265 + struct au_wbr *wbr;
2268 + au_rw_init(&wbr->wbr_wh_rwsem);
2269 + memset(wbr->wbr_wh, 0, sizeof(wbr->wbr_wh));
2270 + atomic_set(&wbr->wbr_wh_running, 0);
2271 + wbr->wbr_bytes = 0;
2274 + * a limit for rmdir/rename a dir
2275 + * cf. AUFS_MAX_NAMELEN in include/linux/aufs_type.h
2277 + err = vfs_statfs(&br->br_path, &kst);
2278 + if (unlikely(err))
2281 + if (kst.f_namelen >= NAME_MAX)
2282 + err = au_br_init_wh(sb, br, perm);
2284 + pr_err("%.*s(%s), unsupported namelen %ld\n",
2285 + AuDLNPair(au_br_dentry(br)),
2286 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
2292 +/* intialize a new branch */
2293 +static int au_br_init(struct au_branch *br, struct super_block *sb,
2294 + struct au_opt_add *add)
2299 + memset(&br->br_xino, 0, sizeof(br->br_xino));
2300 + mutex_init(&br->br_xino.xi_nondir_mtx);
2301 + br->br_perm = add->perm;
2302 + BUILD_BUG_ON(sizeof(br->br_dflags)
2303 + != sizeof(br->br_path.dentry->d_flags));
2304 + br->br_dflags = DCACHE_MOUNTED;
2305 + br->br_path = add->path; /* set first, path_get() later */
2306 + spin_lock_init(&br->br_dykey_lock);
2307 + memset(br->br_dykey, 0, sizeof(br->br_dykey));
2308 + atomic_set(&br->br_count, 0);
2309 + br->br_xino_upper = AUFS_XINO_TRUNC_INIT;
2310 + atomic_set(&br->br_xino_running, 0);
2311 + br->br_id = au_new_br_id(sb);
2312 + AuDebugOn(br->br_id < 0);
2314 + if (au_br_writable(add->perm)) {
2315 + err = au_wbr_init(br, sb, add->perm);
2316 + if (unlikely(err))
2320 + if (au_opt_test(au_mntflags(sb), XINO)) {
2321 + err = au_xino_br(sb, br, add->path.dentry->d_inode->i_ino,
2322 + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1);
2323 + if (unlikely(err)) {
2324 + AuDebugOn(br->br_xino.xi_file);
2329 + sysaufs_br_init(br);
2330 + path_get(&br->br_path);
2331 + goto out; /* success */
2334 + memset(&br->br_path, 0, sizeof(br->br_path));
2339 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
2340 + struct au_branch *br, aufs_bindex_t bend,
2341 + aufs_bindex_t amount)
2343 + struct au_branch **brp;
2345 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2347 + brp = sbinfo->si_branch + bindex;
2348 + memmove(brp + 1, brp, sizeof(*brp) * amount);
2350 + sbinfo->si_bend++;
2351 + if (unlikely(bend < 0))
2352 + sbinfo->si_bend = 0;
2355 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
2356 + aufs_bindex_t bend, aufs_bindex_t amount)
2358 + struct au_hdentry *hdp;
2360 + AuRwMustWriteLock(&dinfo->di_rwsem);
2362 + hdp = dinfo->di_hdentry + bindex;
2363 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
2364 + au_h_dentry_init(hdp);
2366 + if (unlikely(bend < 0))
2367 + dinfo->di_bstart = 0;
2370 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
2371 + aufs_bindex_t bend, aufs_bindex_t amount)
2373 + struct au_hinode *hip;
2375 + AuRwMustWriteLock(&iinfo->ii_rwsem);
2377 + hip = iinfo->ii_hinode + bindex;
2378 + memmove(hip + 1, hip, sizeof(*hip) * amount);
2379 + hip->hi_inode = NULL;
2382 + if (unlikely(bend < 0))
2383 + iinfo->ii_bstart = 0;
2386 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
2387 + aufs_bindex_t bindex)
2389 + struct dentry *root, *h_dentry;
2390 + struct inode *root_inode;
2391 + aufs_bindex_t bend, amount;
2393 + au_br_dflags_force(br);
2395 + root = sb->s_root;
2396 + root_inode = root->d_inode;
2397 + bend = au_sbend(sb);
2398 + amount = bend + 1 - bindex;
2399 + h_dentry = au_br_dentry(br);
2400 + au_sbilist_lock();
2401 + au_br_do_add_brp(au_sbi(sb), bindex, br, bend, amount);
2402 + au_br_do_add_hdp(au_di(root), bindex, bend, amount);
2403 + au_br_do_add_hip(au_ii(root_inode), bindex, bend, amount);
2404 + au_set_h_dptr(root, bindex, dget(h_dentry));
2405 + au_set_h_iptr(root_inode, bindex, au_igrab(h_dentry->d_inode),
2407 + au_sbilist_unlock();
2410 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
2413 + aufs_bindex_t bend, add_bindex;
2414 + struct dentry *root, *h_dentry;
2415 + struct inode *root_inode;
2416 + struct au_branch *add_branch;
2418 + root = sb->s_root;
2419 + root_inode = root->d_inode;
2420 + IMustLock(root_inode);
2421 + err = test_add(sb, add, remount);
2422 + if (unlikely(err < 0))
2426 + goto out; /* success */
2429 + bend = au_sbend(sb);
2430 + add_branch = au_br_alloc(sb, bend + 2, add->perm);
2431 + err = PTR_ERR(add_branch);
2432 + if (IS_ERR(add_branch))
2435 + err = au_br_init(add_branch, sb, add);
2436 + if (unlikely(err)) {
2437 + au_br_do_free(add_branch);
2441 + add_bindex = add->bindex;
2443 + au_br_do_add(sb, add_branch, add_bindex);
2445 + sysaufs_brs_del(sb, add_bindex);
2446 + au_br_do_add(sb, add_branch, add_bindex);
2447 + sysaufs_brs_add(sb, add_bindex);
2450 + h_dentry = add->path.dentry;
2451 + if (!add_bindex) {
2452 + au_cpup_attr_all(root_inode, /*force*/1);
2453 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
2455 + au_add_nlink(root_inode, h_dentry->d_inode);
2458 + * this test/set prevents aufs from handling unnecesary notify events
2459 + * of xino files, in case of re-adding a writable branch which was
2460 + * once detached from aufs.
2462 + if (au_xino_brid(sb) < 0
2463 + && au_br_writable(add_branch->br_perm)
2464 + && !au_test_fs_bad_xino(h_dentry->d_sb)
2465 + && add_branch->br_xino.xi_file
2466 + && add_branch->br_xino.xi_file->f_dentry->d_parent == h_dentry)
2467 + au_xino_brid_set(sb, add_branch->br_id);
2473 +/* ---------------------------------------------------------------------- */
2479 +/* to show the line number, do not make it inlined function */
2480 +#define AuVerbose(do_info, fmt, ...) do { \
2482 + pr_info(fmt, ##__VA_ARGS__); \
2485 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t bstart,
2486 + aufs_bindex_t bend)
2488 + return (inode && !S_ISDIR(inode->i_mode)) || bstart == bend;
2491 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t bstart,
2492 + aufs_bindex_t bend)
2494 + return au_test_ibusy(dentry->d_inode, bstart, bend);
2498 + * test if the branch is deletable or not.
2500 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
2501 + unsigned int sigen, const unsigned int verbose)
2503 + int err, i, j, ndentry;
2504 + aufs_bindex_t bstart, bend;
2505 + struct au_dcsub_pages dpages;
2506 + struct au_dpage *dpage;
2509 + err = au_dpages_init(&dpages, GFP_NOFS);
2510 + if (unlikely(err))
2512 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
2513 + if (unlikely(err))
2516 + for (i = 0; !err && i < dpages.ndpage; i++) {
2517 + dpage = dpages.dpages + i;
2518 + ndentry = dpage->ndentry;
2519 + for (j = 0; !err && j < ndentry; j++) {
2520 + d = dpage->dentries[j];
2521 + AuDebugOn(!d->d_count);
2522 + if (!au_digen_test(d, sigen)) {
2523 + di_read_lock_child(d, AuLock_IR);
2524 + if (unlikely(au_dbrange_test(d))) {
2525 + di_read_unlock(d, AuLock_IR);
2529 + di_write_lock_child(d);
2530 + if (unlikely(au_dbrange_test(d))) {
2531 + di_write_unlock(d);
2534 + err = au_reval_dpath(d, sigen);
2536 + di_downgrade_lock(d, AuLock_IR);
2538 + di_write_unlock(d);
2543 + /* AuDbgDentry(d); */
2544 + bstart = au_dbstart(d);
2545 + bend = au_dbend(d);
2546 + if (bstart <= bindex
2548 + && au_h_dptr(d, bindex)
2549 + && au_test_dbusy(d, bstart, bend)) {
2551 + AuVerbose(verbose, "busy %.*s\n", AuDLNPair(d));
2554 + di_read_unlock(d, AuLock_IR);
2559 + au_dpages_free(&dpages);
2564 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
2565 + unsigned int sigen, const unsigned int verbose)
2568 + unsigned long long max, ull;
2569 + struct inode *i, **array;
2570 + aufs_bindex_t bstart, bend;
2572 + array = au_iarray_alloc(sb, &max);
2573 + err = PTR_ERR(array);
2574 + if (IS_ERR(array))
2578 + AuDbg("b%d\n", bindex);
2579 + for (ull = 0; !err && ull < max; ull++) {
2581 + if (i->i_ino == AUFS_ROOT_INO)
2584 + /* AuDbgInode(i); */
2585 + if (au_iigen(i, NULL) == sigen)
2586 + ii_read_lock_child(i);
2588 + ii_write_lock_child(i);
2589 + err = au_refresh_hinode_self(i);
2592 + ii_downgrade_lock(i);
2594 + ii_write_unlock(i);
2599 + bstart = au_ibstart(i);
2600 + bend = au_ibend(i);
2601 + if (bstart <= bindex
2603 + && au_h_iptr(i, bindex)
2604 + && au_test_ibusy(i, bstart, bend)) {
2606 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
2609 + ii_read_unlock(i);
2611 + au_iarray_free(array, max);
2617 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
2618 + const unsigned int verbose)
2621 + unsigned int sigen;
2623 + sigen = au_sigen(root->d_sb);
2624 + DiMustNoWaiters(root);
2625 + IiMustNoWaiters(root->d_inode);
2626 + di_write_unlock(root);
2627 + err = test_dentry_busy(root, bindex, sigen, verbose);
2629 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
2630 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
2635 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
2636 + const aufs_bindex_t bindex,
2637 + const aufs_bindex_t bend)
2639 + struct au_branch **brp, **p;
2641 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2643 + brp = sbinfo->si_branch + bindex;
2644 + if (bindex < bend)
2645 + memmove(brp, brp + 1, sizeof(*brp) * (bend - bindex));
2646 + sbinfo->si_branch[0 + bend] = NULL;
2647 + sbinfo->si_bend--;
2649 + p = krealloc(sbinfo->si_branch, sizeof(*p) * bend, AuGFP_SBILIST);
2651 + sbinfo->si_branch = p;
2652 + /* harmless error */
2655 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
2656 + const aufs_bindex_t bend)
2658 + struct au_hdentry *hdp, *p;
2660 + AuRwMustWriteLock(&dinfo->di_rwsem);
2662 + hdp = dinfo->di_hdentry;
2663 + if (bindex < bend)
2664 + memmove(hdp + bindex, hdp + bindex + 1,
2665 + sizeof(*hdp) * (bend - bindex));
2666 + hdp[0 + bend].hd_dentry = NULL;
2669 + p = krealloc(hdp, sizeof(*p) * bend, AuGFP_SBILIST);
2671 + dinfo->di_hdentry = p;
2672 + /* harmless error */
2675 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
2676 + const aufs_bindex_t bend)
2678 + struct au_hinode *hip, *p;
2680 + AuRwMustWriteLock(&iinfo->ii_rwsem);
2682 + hip = iinfo->ii_hinode + bindex;
2683 + if (bindex < bend)
2684 + memmove(hip, hip + 1, sizeof(*hip) * (bend - bindex));
2685 + iinfo->ii_hinode[0 + bend].hi_inode = NULL;
2686 + au_hn_init(iinfo->ii_hinode + bend);
2689 + p = krealloc(iinfo->ii_hinode, sizeof(*p) * bend, AuGFP_SBILIST);
2691 + iinfo->ii_hinode = p;
2692 + /* harmless error */
2695 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
2696 + struct au_branch *br)
2698 + aufs_bindex_t bend;
2699 + struct au_sbinfo *sbinfo;
2700 + struct dentry *root, *h_root;
2701 + struct inode *inode, *h_inode;
2702 + struct au_hinode *hinode;
2704 + SiMustWriteLock(sb);
2706 + root = sb->s_root;
2707 + inode = root->d_inode;
2708 + sbinfo = au_sbi(sb);
2709 + bend = sbinfo->si_bend;
2711 + h_root = au_h_dptr(root, bindex);
2712 + hinode = au_hi(inode, bindex);
2713 + h_inode = au_igrab(hinode->hi_inode);
2716 + au_sbilist_lock();
2717 + au_br_do_del_brp(sbinfo, bindex, bend);
2718 + au_br_do_del_hdp(au_di(root), bindex, bend);
2719 + au_br_do_del_hip(au_ii(inode), bindex, bend);
2720 + au_sbilist_unlock();
2724 + au_br_do_free(br);
2727 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
2730 + unsigned int mnt_flags;
2731 + aufs_bindex_t bindex, bend, br_id;
2732 + unsigned char do_wh, verbose;
2733 + struct au_branch *br;
2734 + struct au_wbr *wbr;
2737 + bindex = au_find_dbindex(sb->s_root, del->h_path.dentry);
2740 + goto out; /* success */
2742 + pr_err("%s no such branch\n", del->pathname);
2745 + AuDbg("bindex b%d\n", bindex);
2748 + mnt_flags = au_mntflags(sb);
2749 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
2750 + bend = au_sbend(sb);
2751 + if (unlikely(!bend)) {
2752 + AuVerbose(verbose, "no more branches left\n");
2755 + br = au_sbr(sb, bindex);
2756 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
2757 + i = atomic_read(&br->br_count);
2758 + if (unlikely(i)) {
2759 + AuVerbose(verbose, "%d file(s) opened\n", i);
2764 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
2766 + /* instead of WbrWhMustWriteLock(wbr) */
2767 + SiMustWriteLock(sb);
2768 + for (i = 0; i < AuBrWh_Last; i++) {
2769 + dput(wbr->wbr_wh[i]);
2770 + wbr->wbr_wh[i] = NULL;
2774 + err = test_children_busy(sb->s_root, bindex, verbose);
2775 + if (unlikely(err)) {
2782 + br_id = br->br_id;
2784 + au_br_do_del(sb, bindex, br);
2786 + sysaufs_brs_del(sb, bindex);
2787 + au_br_do_del(sb, bindex, br);
2788 + sysaufs_brs_add(sb, bindex);
2792 + au_cpup_attr_all(sb->s_root->d_inode, /*force*/1);
2793 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
2795 + au_sub_nlink(sb->s_root->d_inode, del->h_path.dentry->d_inode);
2796 + if (au_opt_test(mnt_flags, PLINK))
2797 + au_plink_half_refresh(sb, br_id);
2799 + if (au_xino_brid(sb) == br_id)
2800 + au_xino_brid_set(sb, -1);
2801 + goto out; /* success */
2805 + rerr = au_br_init_wh(sb, br, br->br_perm);
2807 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
2808 + del->pathname, rerr);
2813 +/* ---------------------------------------------------------------------- */
2815 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
2818 + aufs_bindex_t bstart, bend;
2819 + struct aufs_ibusy ibusy;
2820 + struct inode *inode, *h_inode;
2823 + if (unlikely(!capable(CAP_SYS_ADMIN)))
2826 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
2828 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
2829 + if (unlikely(err)) {
2836 + si_read_lock(sb, AuLock_FLUSH);
2837 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbend(sb)))
2841 + ibusy.h_ino = 0; /* invalid */
2842 + inode = ilookup(sb, ibusy.ino);
2844 + || inode->i_ino == AUFS_ROOT_INO
2845 + || is_bad_inode(inode))
2848 + ii_read_lock_child(inode);
2849 + bstart = au_ibstart(inode);
2850 + bend = au_ibend(inode);
2851 + if (bstart <= ibusy.bindex && ibusy.bindex <= bend) {
2852 + h_inode = au_h_iptr(inode, ibusy.bindex);
2853 + if (h_inode && au_test_ibusy(inode, bstart, bend))
2854 + ibusy.h_ino = h_inode->i_ino;
2856 + ii_read_unlock(inode);
2860 + si_read_unlock(sb);
2862 + err = __put_user(ibusy.h_ino, &arg->h_ino);
2863 + if (unlikely(err)) {
2872 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
2874 + return au_ibusy(file->f_dentry->d_sb, (void __user *)arg);
2877 +#ifdef CONFIG_COMPAT
2878 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
2880 + return au_ibusy(file->f_dentry->d_sb, compat_ptr(arg));
2884 +/* ---------------------------------------------------------------------- */
2887 + * change a branch permission
2890 +static void au_warn_ima(void)
2893 + /* since it doesn't support mark_files_ro() */
2894 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
2898 +static int do_need_sigen_inc(int a, int b)
2900 + return au_br_whable(a) && !au_br_whable(b);
2903 +static int need_sigen_inc(int old, int new)
2905 + return do_need_sigen_inc(old, new)
2906 + || do_need_sigen_inc(new, old);
2909 +static unsigned long long au_farray_cb(void *a,
2910 + unsigned long long max __maybe_unused,
2913 + unsigned long long n;
2914 + struct file **p, *f;
2915 + struct super_block *sb = arg;
2919 + lg_global_lock(&files_lglock);
2920 + do_file_list_for_each_entry(sb, f) {
2923 + && !special_file(file_inode(f)->i_mode)) {
2927 + AuDebugOn(n > max);
2929 + } while_file_list_for_each_entry;
2930 + lg_global_unlock(&files_lglock);
2935 +static struct file **au_farray_alloc(struct super_block *sb,
2936 + unsigned long long *max)
2938 + *max = atomic_long_read(&au_sbi(sb)->si_nfiles);
2939 + return au_array_alloc(max, au_farray_cb, sb);
2942 +static void au_farray_free(struct file **a, unsigned long long max)
2944 + unsigned long long ull;
2946 + for (ull = 0; ull < max; ull++)
2952 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
2955 + unsigned int mnt_flags;
2956 + unsigned long long ull, max;
2957 + aufs_bindex_t br_id;
2958 + unsigned char verbose;
2959 + struct file *file, *hf, **array;
2960 + struct inode *inode;
2961 + struct au_hfile *hfile;
2963 + mnt_flags = au_mntflags(sb);
2964 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
2966 + array = au_farray_alloc(sb, &max);
2967 + err = PTR_ERR(array);
2968 + if (IS_ERR(array))
2972 + br_id = au_sbr_id(sb, bindex);
2973 + for (ull = 0; ull < max; ull++) {
2974 + file = array[ull];
2976 + /* AuDbg("%.*s\n", AuDLNPair(file->f_dentry)); */
2977 + fi_read_lock(file);
2978 + if (unlikely(au_test_mmapped(file))) {
2980 + AuVerbose(verbose, "mmapped %.*s\n",
2981 + AuDLNPair(file->f_dentry));
2983 + FiMustNoWaiters(file);
2984 + fi_read_unlock(file);
2988 + inode = file_inode(file);
2989 + hfile = &au_fi(file)->fi_htop;
2990 + hf = hfile->hf_file;
2991 + if (!S_ISREG(inode->i_mode)
2992 + || !(file->f_mode & FMODE_WRITE)
2993 + || hfile->hf_br->br_id != br_id
2994 + || !(hf->f_mode & FMODE_WRITE))
2995 + array[ull] = NULL;
3001 + FiMustNoWaiters(file);
3002 + fi_read_unlock(file);
3010 + for (ull = 0; ull < max; ull++) {
3011 + file = array[ull];
3015 + /* todo: already flushed? */
3016 + /* cf. fs/super.c:mark_files_ro() */
3017 + /* fi_read_lock(file); */
3018 + hfile = &au_fi(file)->fi_htop;
3019 + hf = hfile->hf_file;
3020 + /* fi_read_unlock(file); */
3021 + spin_lock(&hf->f_lock);
3022 + hf->f_mode &= ~FMODE_WRITE;
3023 + spin_unlock(&hf->f_lock);
3024 + if (!file_check_writeable(hf)) {
3025 + __mnt_drop_write(hf->f_path.mnt);
3026 + file_release_write(hf);
3031 + au_farray_free(array, max);
3037 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
3041 + aufs_bindex_t bindex;
3042 + struct dentry *root;
3043 + struct au_branch *br;
3045 + root = sb->s_root;
3046 + bindex = au_find_dbindex(root, mod->h_root);
3049 + return 0; /* success */
3051 + pr_err("%s no such branch\n", mod->path);
3054 + AuDbg("bindex b%d\n", bindex);
3056 + err = test_br(mod->h_root->d_inode, mod->perm, mod->path);
3057 + if (unlikely(err))
3060 + br = au_sbr(sb, bindex);
3061 + AuDebugOn(mod->h_root != au_br_dentry(br));
3062 + if (br->br_perm == mod->perm)
3063 + return 0; /* success */
3065 + if (au_br_writable(br->br_perm)) {
3066 + /* remove whiteout base */
3067 + err = au_br_init_wh(sb, br, mod->perm);
3068 + if (unlikely(err))
3071 + if (!au_br_writable(mod->perm)) {
3072 + /* rw --> ro, file might be mmapped */
3073 + DiMustNoWaiters(root);
3074 + IiMustNoWaiters(root->d_inode);
3075 + di_write_unlock(root);
3076 + err = au_br_mod_files_ro(sb, bindex);
3077 + /* aufs_write_lock() calls ..._child() */
3078 + di_write_lock_child(root);
3080 + if (unlikely(err)) {
3082 + br->br_wbr = kmalloc(sizeof(*br->br_wbr),
3085 + rerr = au_wbr_init(br, sb, br->br_perm);
3086 + if (unlikely(rerr)) {
3087 + AuIOErr("nested error %d (%d)\n",
3089 + br->br_perm = mod->perm;
3093 + } else if (au_br_writable(mod->perm)) {
3096 + br->br_wbr = kmalloc(sizeof(*br->br_wbr), GFP_NOFS);
3098 + err = au_wbr_init(br, sb, mod->perm);
3099 + if (unlikely(err)) {
3100 + kfree(br->br_wbr);
3101 + br->br_wbr = NULL;
3107 + if ((br->br_perm & AuBrAttr_UNPIN)
3108 + && !(mod->perm & AuBrAttr_UNPIN))
3109 + au_br_dflags_force(br);
3110 + else if (!(br->br_perm & AuBrAttr_UNPIN)
3111 + && (mod->perm & AuBrAttr_UNPIN))
3112 + au_br_dflags_restore(br);
3113 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
3114 + br->br_perm = mod->perm;
3121 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
3122 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
3123 +++ linux/fs/aufs/branch.h 2013-07-06 13:20:47.740198107 +0200
3126 + * Copyright (C) 2005-2013 Junjiro R. Okajima
3128 + * This program, aufs is free software; you can redistribute it and/or modify
3129 + * it under the terms of the GNU General Public License as published by
3130 + * the Free Software Foundation; either version 2 of the License, or
3131 + * (at your option) any later version.
3133 + * This program is distributed in the hope that it will be useful,
3134 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3135 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3136 + * GNU General Public License for more details.
3138 + * You should have received a copy of the GNU General Public License
3139 + * along with this program; if not, write to the Free Software
3140 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3144 + * branch filesystems and xino for them
3147 +#ifndef __AUFS_BRANCH_H__
3148 +#define __AUFS_BRANCH_H__
3152 +#include <linux/mount.h>
3157 +/* ---------------------------------------------------------------------- */
3160 +struct au_xino_file {
3161 + struct file *xi_file;
3162 + struct mutex xi_nondir_mtx;
3164 + /* todo: make xino files an array to support huge inode number */
3166 +#ifdef CONFIG_DEBUG_FS
3167 + struct dentry *xi_dbgaufs;
3171 +/* members for writable branch only */
3172 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
3174 + struct au_rwsem wbr_wh_rwsem;
3175 + struct dentry *wbr_wh[AuBrWh_Last];
3176 + atomic_t wbr_wh_running;
3177 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
3178 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
3179 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
3182 + unsigned long long wbr_bytes;
3185 +/* ext2 has 3 types of operations at least, ext3 has 4 */
3186 +#define AuBrDynOp (AuDyLast * 4)
3188 +#ifdef CONFIG_AUFS_HFSNOTIFY
3189 +/* support for asynchronous destruction */
3190 +struct au_br_hfsnotify {
3191 + struct fsnotify_group *hfsn_group;
3195 +/* protected by superblock rwsem */
3197 + struct au_xino_file br_xino;
3199 + aufs_bindex_t br_id;
3202 + unsigned int br_dflags;
3203 + struct path br_path;
3204 + spinlock_t br_dykey_lock;
3205 + struct au_dykey *br_dykey[AuBrDynOp];
3206 + atomic_t br_count;
3208 + struct au_wbr *br_wbr;
3210 + /* xino truncation */
3211 + blkcnt_t br_xino_upper; /* watermark in blocks */
3212 + atomic_t br_xino_running;
3214 +#ifdef CONFIG_AUFS_HFSNOTIFY
3215 + struct au_br_hfsnotify *br_hfsn;
3218 +#ifdef CONFIG_SYSFS
3219 + /* an entry under sysfs per mount-point */
3221 + struct attribute br_attr;
3225 +/* ---------------------------------------------------------------------- */
3227 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
3229 + return br->br_path.mnt;
3232 +static inline struct dentry *au_br_dentry(struct au_branch *br)
3234 + return br->br_path.dentry;
3237 +static inline struct super_block *au_br_sb(struct au_branch *br)
3239 + return au_br_mnt(br)->mnt_sb;
3242 +/* branch permissions and attributes */
3243 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
3244 +#define AuBrPerm_RO (1 << 1) /* readonly */
3245 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
3246 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
3248 +#define AuBrRAttr_WH (1 << 3) /* whiteout-able */
3250 +#define AuBrWAttr_NoLinkWH (1 << 4) /* un-hardlinkable whiteouts */
3252 +#define AuBrAttr_UNPIN (1 << 5) /* rename-able top dir of
3255 +static inline int au_br_writable(int brperm)
3257 + return brperm & AuBrPerm_RW;
3260 +static inline int au_br_whable(int brperm)
3262 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
3265 +static inline int au_br_wh_linkable(int brperm)
3267 + return !(brperm & AuBrWAttr_NoLinkWH);
3270 +static inline int au_br_rdonly(struct au_branch *br)
3272 + return ((au_br_sb(br)->s_flags & MS_RDONLY)
3273 + || !au_br_writable(br->br_perm))
3277 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
3279 +#ifdef CONFIG_AUFS_HNOTIFY
3280 + return !(brperm & AuBrPerm_RR);
3286 +/* ---------------------------------------------------------------------- */
3290 +void au_br_free(struct au_sbinfo *sinfo);
3291 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
3293 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
3295 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
3296 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
3297 +#ifdef CONFIG_COMPAT
3298 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
3301 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
3305 +static const loff_t au_loff_max = LLONG_MAX;
3307 +int au_xib_trunc(struct super_block *sb);
3308 +ssize_t xino_fread(au_readf_t func, struct file *file, void *buf, size_t size,
3310 +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size,
3312 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src);
3313 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent);
3314 +ino_t au_xino_new_ino(struct super_block *sb);
3315 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
3316 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
3318 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
3320 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino,
3321 + struct file *base_file, int do_test);
3322 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex);
3324 +struct au_opt_xino;
3325 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount);
3326 +void au_xino_clr(struct super_block *sb);
3327 +struct file *au_xino_def(struct super_block *sb);
3328 +int au_xino_path(struct seq_file *seq, struct file *file);
3330 +/* ---------------------------------------------------------------------- */
3332 +/* Superblock to branch */
3334 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
3336 + return au_sbr(sb, bindex)->br_id;
3340 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
3342 + return au_br_mnt(au_sbr(sb, bindex));
3346 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
3348 + return au_br_sb(au_sbr(sb, bindex));
3351 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
3353 + atomic_dec(&au_sbr(sb, bindex)->br_count);
3356 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
3358 + return au_sbr(sb, bindex)->br_perm;
3361 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
3363 + return au_br_whable(au_sbr_perm(sb, bindex));
3366 +/* ---------------------------------------------------------------------- */
3369 + * wbr_wh_read_lock, wbr_wh_write_lock
3370 + * wbr_wh_read_unlock, wbr_wh_write_unlock, wbr_wh_downgrade_lock
3372 +AuSimpleRwsemFuncs(wbr_wh, struct au_wbr *wbr, &wbr->wbr_wh_rwsem);
3374 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&wbr->wbr_wh_rwsem)
3375 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&wbr->wbr_wh_rwsem)
3376 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&wbr->wbr_wh_rwsem)
3378 +#endif /* __KERNEL__ */
3379 +#endif /* __AUFS_BRANCH_H__ */
3380 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
3381 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
3382 +++ linux/fs/aufs/conf.mk 2013-07-06 13:20:47.740198107 +0200
3385 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
3389 +AuConfStr += ${1}=${${1}}
3393 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
3395 + HNOTIFY HFSNOTIFY \
3406 +$(foreach i, ${AuConfAll}, \
3407 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
3409 +AuConfName = ${obj}/conf.str
3410 +${AuConfName}.tmp: FORCE
3411 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
3412 +${AuConfName}: ${AuConfName}.tmp
3413 + @diff -q $< $@ > /dev/null 2>&1 || { \
3414 + echo ' GEN ' $@; \
3418 +clean-files += ${AuConfName} ${AuConfName}.tmp
3419 +${obj}/sysfs.o: ${AuConfName}
3421 +-include ${srctree}/${src}/conf_priv.mk
3422 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
3423 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
3424 +++ linux/fs/aufs/cpup.c 2013-08-23 23:59:39.631583456 +0200
3427 + * Copyright (C) 2005-2013 Junjiro R. Okajima
3429 + * This program, aufs is free software; you can redistribute it and/or modify
3430 + * it under the terms of the GNU General Public License as published by
3431 + * the Free Software Foundation; either version 2 of the License, or
3432 + * (at your option) any later version.
3434 + * This program is distributed in the hope that it will be useful,
3435 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3436 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3437 + * GNU General Public License for more details.
3439 + * You should have received a copy of the GNU General Public License
3440 + * along with this program; if not, write to the Free Software
3441 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3445 + * copy-up functions, see wbr_policy.c for copy-down
3448 +#include <linux/fs_stack.h>
3449 +#include <linux/mm.h>
3452 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
3454 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
3455 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
3457 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
3459 + dst->i_flags |= iflags & ~mask;
3460 + if (au_test_fs_notime(dst->i_sb))
3461 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
3464 +void au_cpup_attr_timesizes(struct inode *inode)
3466 + struct inode *h_inode;
3468 + h_inode = au_h_iptr(inode, au_ibstart(inode));
3469 + fsstack_copy_attr_times(inode, h_inode);
3470 + fsstack_copy_inode_size(inode, h_inode);
3473 +void au_cpup_attr_nlink(struct inode *inode, int force)
3475 + struct inode *h_inode;
3476 + struct super_block *sb;
3477 + aufs_bindex_t bindex, bend;
3480 + bindex = au_ibstart(inode);
3481 + h_inode = au_h_iptr(inode, bindex);
3483 + && !S_ISDIR(h_inode->i_mode)
3484 + && au_opt_test(au_mntflags(sb), PLINK)
3485 + && au_plink_test(inode))
3489 + * 0 can happen in revalidating.
3490 + * h_inode->i_mutex is not held, but it is harmless since once i_nlink
3491 + * reaches 0, it will never become positive.
3493 + set_nlink(inode, h_inode->i_nlink);
3496 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
3497 + * it may includes whplink directory.
3499 + if (S_ISDIR(h_inode->i_mode)) {
3500 + bend = au_ibend(inode);
3501 + for (bindex++; bindex <= bend; bindex++) {
3502 + h_inode = au_h_iptr(inode, bindex);
3504 + au_add_nlink(inode, h_inode);
3509 +void au_cpup_attr_changeable(struct inode *inode)
3511 + struct inode *h_inode;
3513 + h_inode = au_h_iptr(inode, au_ibstart(inode));
3514 + inode->i_mode = h_inode->i_mode;
3515 + inode->i_uid = h_inode->i_uid;
3516 + inode->i_gid = h_inode->i_gid;
3517 + au_cpup_attr_timesizes(inode);
3518 + au_cpup_attr_flags(inode, h_inode->i_flags);
3521 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
3523 + struct au_iinfo *iinfo = au_ii(inode);
3525 + IiMustWriteLock(inode);
3527 + iinfo->ii_higen = h_inode->i_generation;
3528 + iinfo->ii_hsb1 = h_inode->i_sb;
3531 +void au_cpup_attr_all(struct inode *inode, int force)
3533 + struct inode *h_inode;
3535 + h_inode = au_h_iptr(inode, au_ibstart(inode));
3536 + au_cpup_attr_changeable(inode);
3537 + if (inode->i_nlink > 0)
3538 + au_cpup_attr_nlink(inode, force);
3539 + inode->i_rdev = h_inode->i_rdev;
3540 + inode->i_blkbits = h_inode->i_blkbits;
3541 + au_cpup_igen(inode, h_inode);
3544 +/* ---------------------------------------------------------------------- */
3546 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
3548 +/* keep the timestamps of the parent dir when cpup */
3549 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
3550 + struct path *h_path)
3552 + struct inode *h_inode;
3554 + dt->dt_dentry = dentry;
3555 + dt->dt_h_path = *h_path;
3556 + h_inode = h_path->dentry->d_inode;
3557 + dt->dt_atime = h_inode->i_atime;
3558 + dt->dt_mtime = h_inode->i_mtime;
3562 +void au_dtime_revert(struct au_dtime *dt)
3564 + struct iattr attr;
3567 + attr.ia_atime = dt->dt_atime;
3568 + attr.ia_mtime = dt->dt_mtime;
3569 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
3570 + | ATTR_ATIME | ATTR_ATIME_SET;
3572 + err = vfsub_notify_change(&dt->dt_h_path, &attr);
3573 + if (unlikely(err))
3574 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
3577 +/* ---------------------------------------------------------------------- */
3579 +/* internal use only */
3580 +struct au_cpup_reg_attr {
3583 + unsigned int iflags; /* inode->i_flags */
3586 +static noinline_for_stack
3587 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
3588 + struct au_cpup_reg_attr *h_src_attr)
3592 + struct path h_path;
3593 + struct inode *h_isrc, *h_idst;
3594 + struct kstat *h_st;
3596 + h_path.dentry = au_h_dptr(dst, bindex);
3597 + h_idst = h_path.dentry->d_inode;
3598 + h_path.mnt = au_sbr_mnt(dst->d_sb, bindex);
3599 + h_isrc = h_src->d_inode;
3600 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
3601 + | ATTR_ATIME | ATTR_MTIME
3602 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
3603 + if (h_src_attr && h_src_attr->valid) {
3604 + h_st = &h_src_attr->st;
3605 + ia.ia_uid = h_st->uid;
3606 + ia.ia_gid = h_st->gid;
3607 + ia.ia_atime = h_st->atime;
3608 + ia.ia_mtime = h_st->mtime;
3609 + if (h_idst->i_mode != h_st->mode
3610 + && !S_ISLNK(h_idst->i_mode)) {
3611 + ia.ia_valid |= ATTR_MODE;
3612 + ia.ia_mode = h_st->mode;
3614 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
3615 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
3617 + ia.ia_uid = h_isrc->i_uid;
3618 + ia.ia_gid = h_isrc->i_gid;
3619 + ia.ia_atime = h_isrc->i_atime;
3620 + ia.ia_mtime = h_isrc->i_mtime;
3621 + if (h_idst->i_mode != h_isrc->i_mode
3622 + && !S_ISLNK(h_idst->i_mode)) {
3623 + ia.ia_valid |= ATTR_MODE;
3624 + ia.ia_mode = h_isrc->i_mode;
3626 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
3627 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
3629 + err = vfsub_notify_change(&h_path, &ia);
3631 + /* is this nfs only? */
3632 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
3633 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
3634 + ia.ia_mode = h_isrc->i_mode;
3635 + err = vfsub_notify_change(&h_path, &ia);
3641 +/* ---------------------------------------------------------------------- */
3643 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
3644 + char *buf, unsigned long blksize)
3647 + size_t sz, rbytes, wbytes;
3648 + unsigned char all_zero;
3650 + struct mutex *h_mtx;
3651 + /* reduce stack usage */
3654 + zp = page_address(ZERO_PAGE(0));
3655 + if (unlikely(!zp))
3656 + return -ENOMEM; /* possible? */
3661 + AuDbg("len %lld\n", len);
3663 + if (len < blksize)
3667 + /* todo: signal_pending? */
3668 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
3669 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
3672 + if (unlikely(err < 0))
3676 + if (len >= rbytes && rbytes == blksize)
3677 + all_zero = !memcmp(buf, zp, rbytes);
3684 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
3686 + /* todo: signal_pending? */
3687 + if (unlikely(err == -EAGAIN || err == -EINTR))
3689 + if (unlikely(err < 0))
3698 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
3700 + if (unlikely(res < 0))
3707 + /* the last block may be a hole */
3708 + if (!err && all_zero) {
3709 + AuLabel(last hole);
3712 + if (au_test_nfs(dst->f_dentry->d_sb)) {
3713 + /* nfs requires this step to make last hole */
3714 + /* is this only nfs? */
3716 + /* todo: signal_pending? */
3717 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
3718 + } while (err == -EAGAIN || err == -EINTR);
3725 + ia->ia_size = dst->f_pos;
3726 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
3727 + ia->ia_file = dst;
3728 + h_mtx = &file_inode(dst)->i_mutex;
3729 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
3730 + err = vfsub_notify_change(&dst->f_path, ia);
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;
3785 + struct file *file;
3786 + void *label, *label_file;
3789 + .bindex = cpg->bsrc,
3790 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
3793 + .label_file = &&out_src
3796 + .bindex = cpg->bdst,
3797 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
3799 + .label = &&out_src,
3800 + .label_file = &&out_dst
3803 + struct super_block *sb;
3805 + /* bsrc branch can be ro/rw. */
3806 + sb = cpg->dentry->d_sb;
3808 + for (i = 0; i < 2; i++, f++) {
3809 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
3810 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
3812 + err = PTR_ERR(f->file);
3813 + if (IS_ERR(f->file))
3816 + if (unlikely(!f->file->f_op))
3817 + goto *f->label_file;
3820 + /* try stopping to update while we copyup */
3821 + IMustLock(file[SRC].dentry->d_inode);
3822 + err = au_copy_file(file[DST].file, file[SRC].file, cpg->len);
3825 + fput(file[DST].file);
3826 + au_sbr_put(sb, file[DST].bindex);
3828 + fput(file[SRC].file);
3829 + au_sbr_put(sb, file[SRC].bindex);
3834 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
3835 + struct au_cpup_reg_attr *h_src_attr)
3839 + struct path h_path;
3840 + struct inode *h_src_inode;
3843 + h_src_inode = au_h_iptr(cpg->dentry->d_inode, cpg->bsrc);
3844 + l = i_size_read(h_src_inode);
3845 + if (cpg->len == -1 || l < cpg->len)
3848 + /* try stopping to update while we are referencing */
3849 + mutex_lock_nested(&h_src_inode->i_mutex, AuLsc_I_CHILD);
3850 + au_pin_hdir_unlock(cpg->pin);
3852 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
3853 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
3854 + h_src_attr->iflags = h_src_inode->i_flags;
3855 + err = vfs_getattr(&h_path, &h_src_attr->st);
3856 + if (unlikely(err)) {
3857 + mutex_unlock(&h_src_inode->i_mutex);
3860 + h_src_attr->valid = 1;
3861 + err = au_cp_regular(cpg);
3862 + mutex_unlock(&h_src_inode->i_mutex);
3863 + rerr = au_pin_hdir_relock(cpg->pin);
3872 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
3873 + struct inode *h_dir)
3876 + mm_segment_t old_fs;
3883 + if (unlikely(!h_src->d_inode->i_op->readlink))
3887 + sym.k = (void *)__get_free_page(GFP_NOFS);
3888 + if (unlikely(!sym.k))
3891 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
3892 + old_fs = get_fs();
3893 + set_fs(KERNEL_DS);
3894 + symlen = h_src->d_inode->i_op->readlink(h_src, sym.u, PATH_MAX);
3899 + sym.k[symlen] = 0;
3900 + err = vfsub_symlink(h_dir, h_path, sym.k);
3902 + free_page((unsigned long)sym.k);
3908 +static noinline_for_stack
3909 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
3910 + struct au_cpup_reg_attr *h_src_attr)
3914 + unsigned int mnt_flags;
3915 + unsigned char isdir;
3916 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
3917 + struct au_dtime dt;
3918 + struct path h_path;
3919 + struct dentry *h_src, *h_dst, *h_parent;
3920 + struct inode *h_inode, *h_dir;
3921 + struct super_block *sb;
3923 + /* bsrc branch can be ro/rw. */
3924 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
3925 + h_inode = h_src->d_inode;
3926 + AuDebugOn(h_inode != au_h_iptr(cpg->dentry->d_inode, cpg->bsrc));
3928 + /* try stopping to be referenced while we are creating */
3929 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
3930 + if (au_ftest_cpup(cpg->flags, RENAME))
3931 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
3932 + AUFS_WH_PFX_LEN));
3933 + h_parent = h_dst->d_parent; /* dir inode is locked */
3934 + h_dir = h_parent->d_inode;
3936 + AuDebugOn(h_parent != h_dst->d_parent);
3938 + sb = cpg->dentry->d_sb;
3939 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
3941 + h_path.dentry = h_parent;
3942 + au_dtime_store(&dt, dst_parent, &h_path);
3944 + h_path.dentry = h_dst;
3947 + mode = h_inode->i_mode;
3948 + switch (mode & S_IFMT) {
3950 + err = vfsub_create(h_dir, &h_path, mode | S_IWUSR,
3951 + /*want_excl*/true);
3953 + err = au_do_cpup_regular(cpg, h_src_attr);
3957 + err = vfsub_mkdir(h_dir, &h_path, mode);
3960 + * strange behaviour from the users view,
3961 + * particularry setattr case
3963 + if (au_ibstart(dst_parent->d_inode) == cpg->bdst)
3964 + au_cpup_attr_nlink(dst_parent->d_inode,
3966 + au_cpup_attr_nlink(cpg->dentry->d_inode, /*force*/1);
3970 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
3974 + AuDebugOn(!capable(CAP_MKNOD));
3978 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
3981 + AuIOErr("Unknown inode type 0%o\n", mode);
3985 + mnt_flags = au_mntflags(sb);
3986 + if (!au_opt_test(mnt_flags, UDBA_NONE)
3988 + && au_opt_test(mnt_flags, XINO)
3989 + && h_inode->i_nlink == 1
3990 + /* todo: unnecessary? */
3991 + /* && cpg->dentry->d_inode->i_nlink == 1 */
3992 + && cpg->bdst < cpg->bsrc
3993 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
3994 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
3995 + /* ignore this error */
3998 + au_dtime_revert(&dt);
4002 +static int au_do_ren_after_cpup(struct dentry *dentry, aufs_bindex_t bdst,
4003 + struct path *h_path)
4006 + struct dentry *h_dentry, *h_parent;
4007 + struct inode *h_dir;
4009 + h_dentry = dget(au_h_dptr(dentry, bdst));
4010 + au_set_h_dptr(dentry, bdst, NULL);
4011 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
4012 + if (unlikely(err)) {
4013 + au_set_h_dptr(dentry, bdst, h_dentry);
4017 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
4018 + au_set_h_dptr(dentry, bdst, h_dentry);
4019 + h_parent = h_dentry->d_parent; /* dir inode is locked */
4020 + h_dir = h_parent->d_inode;
4022 + AuDbg("%.*s %.*s\n", AuDLNPair(h_dentry), AuDLNPair(h_path->dentry));
4023 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path);
4024 + dput(h_path->dentry);
4031 + * copyup the @dentry from @bsrc to @bdst.
4032 + * the caller must set the both of lower dentries.
4033 + * @len is for truncating when it is -1 copyup the entire file.
4034 + * in link/rename cases, @dst_parent may be different from the real one.
4035 + * basic->bsrc can be larger than basic->bdst.
4037 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
4040 + aufs_bindex_t old_ibstart;
4041 + unsigned char isdir, plink;
4042 + struct dentry *h_src, *h_dst, *h_parent;
4043 + struct inode *dst_inode, *h_dir, *inode;
4044 + struct super_block *sb;
4045 + struct au_branch *br;
4046 + /* to reuduce stack size */
4048 + struct au_dtime dt;
4049 + struct path h_path;
4050 + struct au_cpup_reg_attr h_src_attr;
4054 + a = kmalloc(sizeof(*a), GFP_NOFS);
4057 + a->h_src_attr.valid = 0;
4059 + sb = cpg->dentry->d_sb;
4060 + br = au_sbr(sb, cpg->bdst);
4061 + a->h_path.mnt = au_br_mnt(br);
4062 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
4063 + h_parent = h_dst->d_parent; /* dir inode is locked */
4064 + h_dir = h_parent->d_inode;
4067 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
4068 + inode = cpg->dentry->d_inode;
4071 + dst_parent = dget_parent(cpg->dentry);
4075 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
4076 + dst_inode = au_h_iptr(inode, cpg->bdst);
4078 + if (unlikely(!plink)) {
4080 + AuIOErr("hi%lu(i%lu) exists on b%d "
4081 + "but plink is disabled\n",
4082 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
4086 + if (dst_inode->i_nlink) {
4087 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
4089 + h_src = au_plink_lkup(inode, cpg->bdst);
4090 + err = PTR_ERR(h_src);
4091 + if (IS_ERR(h_src))
4093 + if (unlikely(!h_src->d_inode)) {
4095 + AuIOErr("i%lu exists on a upper branch "
4096 + "but not pseudo-linked\n",
4103 + a->h_path.dentry = h_parent;
4104 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
4107 + a->h_path.dentry = h_dst;
4108 + err = vfsub_link(h_src, h_dir, &a->h_path);
4109 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
4110 + err = au_do_ren_after_cpup
4111 + (cpg->dentry, cpg->bdst, &a->h_path);
4113 + au_dtime_revert(&a->dt);
4117 + /* todo: cpup_wh_file? */
4119 + au_update_ibrange(inode, /*do_put_zero*/1);
4122 + isdir = S_ISDIR(inode->i_mode);
4123 + old_ibstart = au_ibstart(inode);
4124 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
4125 + if (unlikely(err))
4127 + dst_inode = h_dst->d_inode;
4128 + mutex_lock_nested(&dst_inode->i_mutex, AuLsc_I_CHILD2);
4129 + /* todo: necessary? */
4130 + /* au_pin_hdir_unlock(cpg->pin); */
4132 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
4133 + if (unlikely(err)) {
4134 + /* todo: necessary? */
4135 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
4136 + mutex_unlock(&dst_inode->i_mutex);
4140 + if (cpg->bdst < old_ibstart) {
4141 + if (S_ISREG(inode->i_mode)) {
4142 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
4143 + if (unlikely(err)) {
4144 + /* ignore an error */
4145 + /* au_pin_hdir_relock(cpg->pin); */
4146 + mutex_unlock(&dst_inode->i_mutex);
4150 + au_set_ibstart(inode, cpg->bdst);
4152 + au_set_ibend(inode, cpg->bdst);
4153 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
4154 + au_hi_flags(inode, isdir));
4156 + /* todo: necessary? */
4157 + /* err = au_pin_hdir_relock(cpg->pin); */
4158 + mutex_unlock(&dst_inode->i_mutex);
4159 + if (unlikely(err))
4163 + && h_src->d_inode->i_nlink > 1
4165 + au_plink_append(inode, cpg->bdst, h_dst);
4167 + if (au_ftest_cpup(cpg->flags, RENAME)) {
4168 + a->h_path.dentry = h_dst;
4169 + err = au_do_ren_after_cpup(cpg->dentry, cpg->bdst, &a->h_path);
4172 + goto out_parent; /* success */
4176 + a->h_path.dentry = h_parent;
4177 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
4178 + a->h_path.dentry = h_dst;
4180 + if (h_dst->d_inode) {
4182 + rerr = vfsub_unlink(h_dir, &a->h_path, /*force*/0);
4184 + rerr = vfsub_rmdir(h_dir, &a->h_path);
4186 + au_dtime_revert(&a->dt);
4188 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
4199 +struct au_cpup_single_args {
4201 + struct au_cp_generic *cpg;
4202 + struct dentry *dst_parent;
4205 +static void au_call_cpup_single(void *args)
4207 + struct au_cpup_single_args *a = args;
4209 + au_pin_hdir_acquire_nest(a->cpg->pin);
4210 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
4211 + au_pin_hdir_release(a->cpg->pin);
4216 + * prevent SIGXFSZ in copy-up.
4217 + * testing CAP_MKNOD is for generic fs,
4218 + * but CAP_FSETID is for xfs only, currently.
4220 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
4223 + struct super_block *sb;
4224 + struct inode *h_dir;
4227 + sb = au_pinned_parent(pin)->d_sb;
4228 + if (!au_wkq_test()
4229 + && (!au_sbi(sb)->si_plink_maint_pid
4230 + || au_plink_maint(sb, AuLock_NOPLM))) {
4231 + switch (mode & S_IFMT) {
4233 + /* no condition about RLIMIT_FSIZE and the file size */
4238 + do_sio = !capable(CAP_MKNOD);
4242 + do_sio = ((mode & (S_ISUID | S_ISGID))
4243 + && !capable(CAP_FSETID));
4244 + /* this workaround may be removed in the future */
4246 + h_dir = au_pinned_h_dir(pin);
4247 + do_sio = h_dir->i_mode & S_ISVTX;
4255 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
4258 + struct dentry *h_dentry;
4260 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
4261 + if (!au_cpup_sio_test(pin, h_dentry->d_inode->i_mode))
4262 + err = au_cpup_single(cpg, dst_parent);
4264 + struct au_cpup_single_args args = {
4267 + .dst_parent = dst_parent
4269 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
4270 + if (unlikely(wkq_err))
4279 + * copyup the @dentry from the first active lower branch to @bdst,
4280 + * using au_cpup_single().
4282 +static int au_cpup_simple(struct au_cp_generic *cpg)
4285 + unsigned int flags_orig;
4286 + struct dentry *dentry;
4288 + AuDebugOn(cpg->bsrc < 0);
4290 + dentry = cpg->dentry;
4291 + DiMustWriteLock(dentry);
4293 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
4295 + flags_orig = cpg->flags;
4296 + au_fset_cpup(cpg->flags, RENAME);
4297 + err = au_cpup_single(cpg, NULL);
4298 + cpg->flags = flags_orig;
4300 + return 0; /* success */
4303 + au_set_h_dptr(dentry, cpg->bdst, NULL);
4304 + au_set_dbstart(dentry, cpg->bsrc);
4310 +struct au_cpup_simple_args {
4312 + struct au_cp_generic *cpg;
4315 +static void au_call_cpup_simple(void *args)
4317 + struct au_cpup_simple_args *a = args;
4319 + au_pin_hdir_acquire_nest(a->cpg->pin);
4320 + *a->errp = au_cpup_simple(a->cpg);
4321 + au_pin_hdir_release(a->cpg->pin);
4324 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
4327 + struct dentry *dentry, *parent;
4328 + struct file *h_file;
4329 + struct inode *h_dir;
4331 + dentry = cpg->dentry;
4333 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
4334 + AuDebugOn(cpg->bsrc < 0);
4335 + h_file = au_h_open_pre(dentry, cpg->bsrc);
4336 + err = PTR_ERR(h_file);
4337 + if (IS_ERR(h_file))
4341 + parent = dget_parent(dentry);
4342 + h_dir = au_h_iptr(parent->d_inode, cpg->bdst);
4343 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
4344 + && !au_cpup_sio_test(cpg->pin, dentry->d_inode->i_mode))
4345 + err = au_cpup_simple(cpg);
4347 + struct au_cpup_simple_args args = {
4351 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
4352 + if (unlikely(wkq_err))
4358 + au_h_open_post(dentry, cpg->bsrc, h_file);
4364 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
4366 + aufs_bindex_t bsrc, bend;
4367 + struct dentry *dentry, *h_dentry;
4369 + if (cpg->bsrc < 0) {
4370 + dentry = cpg->dentry;
4371 + bend = au_dbend(dentry);
4372 + for (bsrc = cpg->bdst + 1; bsrc <= bend; bsrc++) {
4373 + h_dentry = au_h_dptr(dentry, bsrc);
4375 + AuDebugOn(!h_dentry->d_inode);
4379 + AuDebugOn(bsrc > bend);
4382 + AuDebugOn(cpg->bsrc <= cpg->bdst);
4383 + return au_do_sio_cpup_simple(cpg);
4386 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
4388 + AuDebugOn(cpg->bdst <= cpg->bsrc);
4389 + return au_do_sio_cpup_simple(cpg);
4392 +/* ---------------------------------------------------------------------- */
4395 + * copyup the deleted file for writing.
4397 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
4398 + struct file *file)
4401 + unsigned int flags_orig;
4402 + aufs_bindex_t bsrc_orig;
4403 + struct dentry *h_d_dst, *h_d_start;
4404 + struct au_dinfo *dinfo;
4405 + struct au_hdentry *hdp;
4407 + dinfo = au_di(cpg->dentry);
4408 + AuRwMustWriteLock(&dinfo->di_rwsem);
4410 + bsrc_orig = cpg->bsrc;
4411 + cpg->bsrc = dinfo->di_bstart;
4412 + hdp = dinfo->di_hdentry;
4413 + h_d_dst = hdp[0 + cpg->bdst].hd_dentry;
4414 + dinfo->di_bstart = cpg->bdst;
4415 + hdp[0 + cpg->bdst].hd_dentry = wh_dentry;
4418 + h_d_start = hdp[0 + cpg->bsrc].hd_dentry;
4419 + hdp[0 + cpg->bsrc].hd_dentry = au_hf_top(file)->f_dentry;
4421 + flags_orig = cpg->flags;
4422 + cpg->flags = !AuCpup_DTIME;
4423 + err = au_cpup_single(cpg, /*h_parent*/NULL);
4424 + cpg->flags = flags_orig;
4427 + err = au_reopen_nondir(file);
4428 + hdp[0 + cpg->bsrc].hd_dentry = h_d_start;
4430 + hdp[0 + cpg->bdst].hd_dentry = h_d_dst;
4431 + dinfo->di_bstart = cpg->bsrc;
4432 + cpg->bsrc = bsrc_orig;
4437 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
4440 + aufs_bindex_t bdst;
4441 + struct au_dtime dt;
4442 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
4443 + struct au_branch *br;
4444 + struct path h_path;
4446 + dentry = cpg->dentry;
4448 + br = au_sbr(dentry->d_sb, bdst);
4449 + parent = dget_parent(dentry);
4450 + h_parent = au_h_dptr(parent, bdst);
4451 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
4452 + err = PTR_ERR(wh_dentry);
4453 + if (IS_ERR(wh_dentry))
4456 + h_path.dentry = h_parent;
4457 + h_path.mnt = au_br_mnt(br);
4458 + au_dtime_store(&dt, parent, &h_path);
4459 + err = au_do_cpup_wh(cpg, wh_dentry, file);
4460 + if (unlikely(err))
4464 + h_path.dentry = wh_dentry;
4465 + if (!S_ISDIR(wh_dentry->d_inode->i_mode))
4466 + err = vfsub_unlink(h_parent->d_inode, &h_path, /*force*/0);
4468 + err = vfsub_rmdir(h_parent->d_inode, &h_path);
4469 + if (unlikely(err)) {
4470 + AuIOErr("failed remove copied-up tmp file %.*s(%d)\n",
4471 + AuDLNPair(wh_dentry), err);
4474 + au_dtime_revert(&dt);
4475 + au_set_hi_wh(dentry->d_inode, bdst, wh_dentry);
4484 +struct au_cpup_wh_args {
4486 + struct au_cp_generic *cpg;
4487 + struct file *file;
4490 +static void au_call_cpup_wh(void *args)
4492 + struct au_cpup_wh_args *a = args;
4494 + au_pin_hdir_acquire_nest(a->cpg->pin);
4495 + *a->errp = au_cpup_wh(a->cpg, a->file);
4496 + au_pin_hdir_release(a->cpg->pin);
4499 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
4502 + aufs_bindex_t bdst;
4503 + struct dentry *dentry, *parent, *h_orph, *h_parent, *h_dentry;
4504 + struct inode *dir, *h_dir, *h_tmpdir;
4505 + struct au_wbr *wbr;
4506 + struct au_pin wh_pin, *pin_orig;
4508 + dentry = cpg->dentry;
4510 + parent = dget_parent(dentry);
4511 + dir = parent->d_inode;
4514 + h_dir = au_igrab(au_h_iptr(dir, bdst));
4517 + if (!h_dir->i_nlink) {
4518 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
4519 + h_orph = wbr->wbr_orph;
4521 + h_parent = dget(au_h_dptr(parent, bdst));
4522 + au_set_h_dptr(parent, bdst, dget(h_orph));
4523 + h_tmpdir = h_orph->d_inode;
4524 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
4527 + h_dentry = au_hf_top(file)->f_dentry;
4529 + h_dentry = au_h_dptr(dentry, au_dbstart(dentry));
4530 + mutex_lock_nested(&h_tmpdir->i_mutex, AuLsc_I_PARENT3);
4531 + /* todo: au_h_open_pre()? */
4533 + pin_orig = cpg->pin;
4534 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
4535 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
4536 + cpg->pin = &wh_pin;
4539 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
4540 + && !au_cpup_sio_test(cpg->pin, dentry->d_inode->i_mode))
4541 + err = au_cpup_wh(cpg, file);
4543 + struct au_cpup_wh_args args = {
4548 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
4549 + if (unlikely(wkq_err))
4554 + mutex_unlock(&h_tmpdir->i_mutex);
4555 + /* todo: au_h_open_post()? */
4556 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
4557 + au_set_h_dptr(parent, bdst, h_parent);
4558 + AuDebugOn(!pin_orig);
4559 + cpg->pin = pin_orig;
4567 +/* ---------------------------------------------------------------------- */
4570 + * generic routine for both of copy-up and copy-down.
4572 +/* cf. revalidate function in file.c */
4573 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
4574 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
4575 + struct au_pin *pin,
4576 + struct dentry *h_parent, void *arg),
4580 + struct au_pin pin;
4581 + struct dentry *d, *parent, *h_parent, *real_parent;
4584 + parent = dget_parent(dentry);
4585 + if (IS_ROOT(parent))
4588 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
4589 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
4591 + /* do not use au_dpage */
4592 + real_parent = parent;
4595 + parent = dget_parent(dentry);
4596 + h_parent = au_h_dptr(parent, bdst);
4598 + goto out; /* success */
4600 + /* find top dir which is necessary to cpup */
4604 + parent = dget_parent(d);
4605 + di_read_lock_parent3(parent, !AuLock_IR);
4606 + h_parent = au_h_dptr(parent, bdst);
4607 + di_read_unlock(parent, !AuLock_IR);
4608 + } while (!h_parent);
4610 + if (d != real_parent)
4611 + di_write_lock_child3(d);
4613 + /* somebody else might create while we were sleeping */
4614 + if (!au_h_dptr(d, bdst) || !au_h_dptr(d, bdst)->d_inode) {
4615 + if (au_h_dptr(d, bdst))
4616 + au_update_dbstart(d);
4618 + au_pin_set_dentry(&pin, d);
4619 + err = au_do_pin(&pin);
4621 + err = cp(d, bdst, &pin, h_parent, arg);
4626 + if (d != real_parent)
4627 + di_write_unlock(d);
4628 + if (unlikely(err))
4637 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
4638 + struct au_pin *pin,
4639 + struct dentry *h_parent __maybe_unused ,
4640 + void *arg __maybe_unused)
4642 + struct au_cp_generic cpg = {
4648 + .flags = AuCpup_DTIME
4650 + return au_sio_cpup_simple(&cpg);
4653 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
4655 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
4658 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
4661 + struct dentry *parent;
4662 + struct inode *dir;
4664 + parent = dget_parent(dentry);
4665 + dir = parent->d_inode;
4667 + if (au_h_iptr(dir, bdst))
4670 + di_read_unlock(parent, AuLock_IR);
4671 + di_write_lock_parent(parent);
4672 + /* someone else might change our inode while we were sleeping */
4673 + if (!au_h_iptr(dir, bdst))
4674 + err = au_cpup_dirs(dentry, bdst);
4675 + di_downgrade_lock(parent, AuLock_IR);
4681 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
4682 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
4683 +++ linux/fs/aufs/cpup.h 2013-08-23 23:59:39.634916914 +0200
4686 + * Copyright (C) 2005-2013 Junjiro R. Okajima
4688 + * This program, aufs is free software; you can redistribute it and/or modify
4689 + * it under the terms of the GNU General Public License as published by
4690 + * the Free Software Foundation; either version 2 of the License, or
4691 + * (at your option) any later version.
4693 + * This program is distributed in the hope that it will be useful,
4694 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4695 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4696 + * GNU General Public License for more details.
4698 + * You should have received a copy of the GNU General Public License
4699 + * along with this program; if not, write to the Free Software
4700 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
4704 + * copy-up/down functions
4707 +#ifndef __AUFS_CPUP_H__
4708 +#define __AUFS_CPUP_H__
4712 +#include <linux/path.h>
4718 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
4719 +void au_cpup_attr_timesizes(struct inode *inode);
4720 +void au_cpup_attr_nlink(struct inode *inode, int force);
4721 +void au_cpup_attr_changeable(struct inode *inode);
4722 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
4723 +void au_cpup_attr_all(struct inode *inode, int force);
4725 +/* ---------------------------------------------------------------------- */
4727 +struct au_cp_generic {
4728 + struct dentry *dentry;
4729 + aufs_bindex_t bdst, bsrc;
4731 + struct au_pin *pin;
4732 + unsigned int flags;
4736 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
4737 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
4739 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
4740 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in cpup */
4742 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
4743 +#define au_fset_cpup(flags, name) \
4744 + do { (flags) |= AuCpup_##name; } while (0)
4745 +#define au_fclr_cpup(flags, name) \
4746 + do { (flags) &= ~AuCpup_##name; } while (0)
4748 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
4749 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
4750 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
4751 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
4753 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
4754 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
4755 + struct au_pin *pin,
4756 + struct dentry *h_parent, void *arg),
4758 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
4759 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
4761 +/* ---------------------------------------------------------------------- */
4763 +/* keep timestamps when copyup */
4765 + struct dentry *dt_dentry;
4766 + struct path dt_h_path;
4767 + struct timespec dt_atime, dt_mtime;
4769 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4770 + struct path *h_path);
4771 +void au_dtime_revert(struct au_dtime *dt);
4773 +#endif /* __KERNEL__ */
4774 +#endif /* __AUFS_CPUP_H__ */
4775 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
4776 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
4777 +++ linux/fs/aufs/dbgaufs.c 2013-07-06 13:20:47.740198107 +0200
4780 + * Copyright (C) 2005-2013 Junjiro R. Okajima
4782 + * This program, aufs is free software; you can redistribute it and/or modify
4783 + * it under the terms of the GNU General Public License as published by
4784 + * the Free Software Foundation; either version 2 of the License, or
4785 + * (at your option) any later version.
4787 + * This program is distributed in the hope that it will be useful,
4788 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4789 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4790 + * GNU General Public License for more details.
4792 + * You should have received a copy of the GNU General Public License
4793 + * along with this program; if not, write to the Free Software
4794 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
4798 + * debugfs interface
4801 +#include <linux/debugfs.h>
4804 +#ifndef CONFIG_SYSFS
4805 +#error DEBUG_FS depends upon SYSFS
4808 +static struct dentry *dbgaufs;
4809 +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH;
4811 +/* 20 is max digits length of ulong 64 */
4812 +struct dbgaufs_arg {
4818 + * common function for all XINO files
4820 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
4821 + struct file *file)
4823 + kfree(file->private_data);
4827 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt)
4831 + struct dbgaufs_arg *p;
4834 + p = kmalloc(sizeof(*p), GFP_NOFS);
4840 + file->private_data = p;
4844 + err = vfs_getattr(&xf->f_path, &st);
4848 + (p->a, sizeof(p->a), "%ld, %llux%lu %lld\n",
4849 + (long)file_count(xf), st.blocks, st.blksize,
4850 + (long long)st.size);
4852 + p->n = snprintf(p->a, sizeof(p->a), "%llux%lu %lld\n",
4853 + st.blocks, st.blksize,
4854 + (long long)st.size);
4855 + AuDebugOn(p->n >= sizeof(p->a));
4857 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
4866 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
4867 + size_t count, loff_t *ppos)
4869 + struct dbgaufs_arg *p;
4871 + p = file->private_data;
4872 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
4875 +/* ---------------------------------------------------------------------- */
4877 +struct dbgaufs_plink_arg {
4882 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
4883 + struct file *file)
4885 + free_page((unsigned long)file->private_data);
4889 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
4891 + int err, i, limit;
4892 + unsigned long n, sum;
4893 + struct dbgaufs_plink_arg *p;
4894 + struct au_sbinfo *sbinfo;
4895 + struct super_block *sb;
4896 + struct au_sphlhead *sphl;
4899 + p = (void *)get_zeroed_page(GFP_NOFS);
4904 + sbinfo = inode->i_private;
4905 + sb = sbinfo->si_sb;
4906 + si_noflush_read_lock(sb);
4907 + if (au_opt_test(au_mntflags(sb), PLINK)) {
4908 + limit = PAGE_SIZE - sizeof(p->n);
4910 + /* the number of buckets */
4911 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
4916 + for (i = 0, sphl = sbinfo->si_plink;
4917 + i < AuPlink_NHASH;
4919 + n = au_sphl_count(sphl);
4922 + n = snprintf(p->a + p->n, limit, "%lu ", n);
4925 + if (unlikely(limit <= 0))
4928 + p->a[p->n - 1] = '\n';
4930 + /* the sum of plinks */
4931 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
4934 + if (unlikely(limit <= 0))
4937 +#define str "1\n0\n0\n"
4938 + p->n = sizeof(str) - 1;
4939 + strcpy(p->a, str);
4942 + si_read_unlock(sb);
4945 + file->private_data = p;
4946 + goto out; /* success */
4949 + free_page((unsigned long)p);
4954 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
4955 + size_t count, loff_t *ppos)
4957 + struct dbgaufs_plink_arg *p;
4959 + p = file->private_data;
4960 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
4963 +static const struct file_operations dbgaufs_plink_fop = {
4964 + .owner = THIS_MODULE,
4965 + .open = dbgaufs_plink_open,
4966 + .release = dbgaufs_plink_release,
4967 + .read = dbgaufs_plink_read
4970 +/* ---------------------------------------------------------------------- */
4972 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
4975 + struct au_sbinfo *sbinfo;
4976 + struct super_block *sb;
4978 + sbinfo = inode->i_private;
4979 + sb = sbinfo->si_sb;
4980 + si_noflush_read_lock(sb);
4981 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
4982 + si_read_unlock(sb);
4986 +static const struct file_operations dbgaufs_xib_fop = {
4987 + .owner = THIS_MODULE,
4988 + .open = dbgaufs_xib_open,
4989 + .release = dbgaufs_xi_release,
4990 + .read = dbgaufs_xi_read
4993 +/* ---------------------------------------------------------------------- */
4995 +#define DbgaufsXi_PREFIX "xi"
4997 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
5001 + struct au_sbinfo *sbinfo;
5002 + struct super_block *sb;
5004 + struct qstr *name;
5008 + name = &file->f_dentry->d_name;
5009 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
5010 + || memcmp(name->name, DbgaufsXi_PREFIX,
5011 + sizeof(DbgaufsXi_PREFIX) - 1)))
5013 + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
5014 + if (unlikely(err))
5017 + sbinfo = inode->i_private;
5018 + sb = sbinfo->si_sb;
5019 + si_noflush_read_lock(sb);
5020 + if (l <= au_sbend(sb)) {
5021 + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file;
5022 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1);
5025 + si_read_unlock(sb);
5031 +static const struct file_operations dbgaufs_xino_fop = {
5032 + .owner = THIS_MODULE,
5033 + .open = dbgaufs_xino_open,
5034 + .release = dbgaufs_xi_release,
5035 + .read = dbgaufs_xi_read
5038 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
5040 + aufs_bindex_t bend;
5041 + struct au_branch *br;
5042 + struct au_xino_file *xi;
5044 + if (!au_sbi(sb)->si_dbgaufs)
5047 + bend = au_sbend(sb);
5048 + for (; bindex <= bend; bindex++) {
5049 + br = au_sbr(sb, bindex);
5050 + xi = &br->br_xino;
5051 + debugfs_remove(xi->xi_dbgaufs);
5052 + xi->xi_dbgaufs = NULL;
5056 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
5058 + struct au_sbinfo *sbinfo;
5059 + struct dentry *parent;
5060 + struct au_branch *br;
5061 + struct au_xino_file *xi;
5062 + aufs_bindex_t bend;
5063 + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
5065 + sbinfo = au_sbi(sb);
5066 + parent = sbinfo->si_dbgaufs;
5070 + bend = au_sbend(sb);
5071 + for (; bindex <= bend; bindex++) {
5072 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
5073 + br = au_sbr(sb, bindex);
5074 + xi = &br->br_xino;
5075 + AuDebugOn(xi->xi_dbgaufs);
5076 + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
5077 + sbinfo, &dbgaufs_xino_fop);
5078 + /* ignore an error */
5079 + if (unlikely(!xi->xi_dbgaufs))
5080 + AuWarn1("failed %s under debugfs\n", name);
5084 +/* ---------------------------------------------------------------------- */
5086 +#ifdef CONFIG_AUFS_EXPORT
5087 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
5090 + struct au_sbinfo *sbinfo;
5091 + struct super_block *sb;
5093 + sbinfo = inode->i_private;
5094 + sb = sbinfo->si_sb;
5095 + si_noflush_read_lock(sb);
5096 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0);
5097 + si_read_unlock(sb);
5101 +static const struct file_operations dbgaufs_xigen_fop = {
5102 + .owner = THIS_MODULE,
5103 + .open = dbgaufs_xigen_open,
5104 + .release = dbgaufs_xi_release,
5105 + .read = dbgaufs_xi_read
5108 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
5113 + * This function is a dynamic '__init' fucntion actually,
5114 + * so the tiny check for si_rwsem is unnecessary.
5116 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
5119 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
5120 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
5121 + &dbgaufs_xigen_fop);
5122 + if (sbinfo->si_dbgaufs_xigen)
5128 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
5132 +#endif /* CONFIG_AUFS_EXPORT */
5134 +/* ---------------------------------------------------------------------- */
5136 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
5139 + * This function is a dynamic '__init' fucntion actually,
5140 + * so the tiny check for si_rwsem is unnecessary.
5142 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
5144 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
5145 + sbinfo->si_dbgaufs = NULL;
5146 + kobject_put(&sbinfo->si_kobj);
5149 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
5152 + char name[SysaufsSiNameLen];
5155 + * This function is a dynamic '__init' fucntion actually,
5156 + * so the tiny check for si_rwsem is unnecessary.
5158 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
5162 + AuErr1("/debug/aufs is uninitialized\n");
5167 + sysaufs_name(sbinfo, name);
5168 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
5169 + if (unlikely(!sbinfo->si_dbgaufs))
5171 + kobject_get(&sbinfo->si_kobj);
5173 + sbinfo->si_dbgaufs_xib = debugfs_create_file
5174 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
5175 + &dbgaufs_xib_fop);
5176 + if (unlikely(!sbinfo->si_dbgaufs_xib))
5179 + sbinfo->si_dbgaufs_plink = debugfs_create_file
5180 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
5181 + &dbgaufs_plink_fop);
5182 + if (unlikely(!sbinfo->si_dbgaufs_plink))
5185 + err = dbgaufs_xigen_init(sbinfo);
5187 + goto out; /* success */
5190 + dbgaufs_si_fin(sbinfo);
5195 +/* ---------------------------------------------------------------------- */
5197 +void dbgaufs_fin(void)
5199 + debugfs_remove(dbgaufs);
5202 +int __init dbgaufs_init(void)
5207 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
5212 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
5213 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
5214 +++ linux/fs/aufs/dbgaufs.h 2013-07-06 13:20:47.740198107 +0200
5217 + * Copyright (C) 2005-2013 Junjiro R. Okajima
5219 + * This program, aufs is free software; you can redistribute it and/or modify
5220 + * it under the terms of the GNU General Public License as published by
5221 + * the Free Software Foundation; either version 2 of the License, or
5222 + * (at your option) any later version.
5224 + * This program is distributed in the hope that it will be useful,
5225 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5226 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5227 + * GNU General Public License for more details.
5229 + * You should have received a copy of the GNU General Public License
5230 + * along with this program; if not, write to the Free Software
5231 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
5235 + * debugfs interface
5238 +#ifndef __DBGAUFS_H__
5239 +#define __DBGAUFS_H__
5243 +struct super_block;
5246 +#ifdef CONFIG_DEBUG_FS
5248 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
5249 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
5250 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
5251 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
5252 +void dbgaufs_fin(void);
5253 +int __init dbgaufs_init(void);
5255 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
5256 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
5257 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
5258 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
5259 +AuStubVoid(dbgaufs_fin, void)
5260 +AuStubInt0(__init dbgaufs_init, void)
5261 +#endif /* CONFIG_DEBUG_FS */
5263 +#endif /* __KERNEL__ */
5264 +#endif /* __DBGAUFS_H__ */
5265 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
5266 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
5267 +++ linux/fs/aufs/dcsub.c 2013-07-30 22:42:55.839613269 +0200
5270 + * Copyright (C) 2005-2013 Junjiro R. Okajima
5272 + * This program, aufs is free software; you can redistribute it and/or modify
5273 + * it under the terms of the GNU General Public License as published by
5274 + * the Free Software Foundation; either version 2 of the License, or
5275 + * (at your option) any later version.
5277 + * This program is distributed in the hope that it will be useful,
5278 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5279 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5280 + * GNU General Public License for more details.
5282 + * You should have received a copy of the GNU General Public License
5283 + * along with this program; if not, write to the Free Software
5284 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
5288 + * sub-routines for dentry cache
5293 +static void au_dpage_free(struct au_dpage *dpage)
5296 + struct dentry **p;
5298 + p = dpage->dentries;
5299 + for (i = 0; i < dpage->ndentry; i++)
5301 + free_page((unsigned long)dpage->dentries);
5304 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
5310 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
5311 + if (unlikely(!dpages->dpages))
5314 + p = (void *)__get_free_page(gfp);
5318 + dpages->dpages[0].ndentry = 0;
5319 + dpages->dpages[0].dentries = p;
5320 + dpages->ndpage = 1;
5321 + return 0; /* success */
5324 + kfree(dpages->dpages);
5329 +void au_dpages_free(struct au_dcsub_pages *dpages)
5332 + struct au_dpage *p;
5334 + p = dpages->dpages;
5335 + for (i = 0; i < dpages->ndpage; i++)
5336 + au_dpage_free(p++);
5337 + kfree(dpages->dpages);
5340 +static int au_dpages_append(struct au_dcsub_pages *dpages,
5341 + struct dentry *dentry, gfp_t gfp)
5344 + struct au_dpage *dpage;
5347 + dpage = dpages->dpages + dpages->ndpage - 1;
5348 + sz = PAGE_SIZE / sizeof(dentry);
5349 + if (unlikely(dpage->ndentry >= sz)) {
5350 + AuLabel(new dpage);
5352 + sz = dpages->ndpage * sizeof(*dpages->dpages);
5353 + p = au_kzrealloc(dpages->dpages, sz,
5354 + sz + sizeof(*dpages->dpages), gfp);
5358 + dpages->dpages = p;
5359 + dpage = dpages->dpages + dpages->ndpage;
5360 + p = (void *)__get_free_page(gfp);
5364 + dpage->ndentry = 0;
5365 + dpage->dentries = p;
5369 + AuDebugOn(!dentry->d_count);
5370 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
5371 + return 0; /* success */
5377 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
5378 + au_dpages_test test, void *arg)
5381 + struct dentry *this_parent;
5382 + struct list_head *next;
5383 + struct super_block *sb = root->d_sb;
5386 + write_seqlock(&rename_lock);
5387 + this_parent = root;
5388 + spin_lock(&this_parent->d_lock);
5390 + next = this_parent->d_subdirs.next;
5392 + if (this_parent->d_sb == sb
5393 + && !IS_ROOT(this_parent)
5394 + && au_di(this_parent)
5395 + && this_parent->d_count
5396 + && (!test || test(this_parent, arg))) {
5397 + err = au_dpages_append(dpages, this_parent, GFP_ATOMIC);
5398 + if (unlikely(err))
5402 + while (next != &this_parent->d_subdirs) {
5403 + struct list_head *tmp = next;
5404 + struct dentry *dentry = list_entry(tmp, struct dentry,
5408 + spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED);
5409 + if (dentry->d_count) {
5410 + if (!list_empty(&dentry->d_subdirs)) {
5411 + spin_unlock(&this_parent->d_lock);
5412 + spin_release(&dentry->d_lock.dep_map, 1,
5414 + this_parent = dentry;
5415 + spin_acquire(&this_parent->d_lock.dep_map, 0, 1,
5419 + if (dentry->d_sb == sb
5421 + && (!test || test(dentry, arg)))
5422 + err = au_dpages_append(dpages, dentry,
5425 + spin_unlock(&dentry->d_lock);
5426 + if (unlikely(err))
5430 + if (this_parent != root) {
5431 + struct dentry *tmp;
5432 + struct dentry *child;
5434 + tmp = this_parent->d_parent;
5436 + spin_unlock(&this_parent->d_lock);
5437 + child = this_parent;
5438 + this_parent = tmp;
5439 + spin_lock(&this_parent->d_lock);
5440 + rcu_read_unlock();
5441 + next = child->d_u.d_child.next;
5446 + spin_unlock(&this_parent->d_lock);
5447 + write_sequnlock(&rename_lock);
5451 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
5452 + int do_include, au_dpages_test test, void *arg)
5457 + write_seqlock(&rename_lock);
5458 + spin_lock(&dentry->d_lock);
5460 + && dentry->d_count
5461 + && (!test || test(dentry, arg)))
5462 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
5463 + spin_unlock(&dentry->d_lock);
5464 + if (unlikely(err))
5468 + * vfsmount_lock is unnecessary since this is a traverse in a single
5471 + while (!IS_ROOT(dentry)) {
5472 + dentry = dentry->d_parent; /* rename_lock is locked */
5473 + spin_lock(&dentry->d_lock);
5474 + if (dentry->d_count
5475 + && (!test || test(dentry, arg)))
5476 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
5477 + spin_unlock(&dentry->d_lock);
5478 + if (unlikely(err))
5483 + write_sequnlock(&rename_lock);
5487 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
5489 + return au_di(dentry) && dentry->d_sb == arg;
5492 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
5493 + struct dentry *dentry, int do_include)
5495 + return au_dcsub_pages_rev(dpages, dentry, do_include,
5496 + au_dcsub_dpages_aufs, dentry->d_sb);
5499 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
5501 + struct path path[2] = {
5510 + return path_is_under(path + 0, path + 1);
5512 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
5513 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
5514 +++ linux/fs/aufs/dcsub.h 2013-07-06 13:20:47.740198107 +0200
5517 + * Copyright (C) 2005-2013 Junjiro R. Okajima
5519 + * This program, aufs is free software; you can redistribute it and/or modify
5520 + * it under the terms of the GNU General Public License as published by
5521 + * the Free Software Foundation; either version 2 of the License, or
5522 + * (at your option) any later version.
5524 + * This program is distributed in the hope that it will be useful,
5525 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5526 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5527 + * GNU General Public License for more details.
5529 + * You should have received a copy of the GNU General Public License
5530 + * along with this program; if not, write to the Free Software
5531 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
5535 + * sub-routines for dentry cache
5538 +#ifndef __AUFS_DCSUB_H__
5539 +#define __AUFS_DCSUB_H__
5543 +#include <linux/dcache.h>
5544 +#include <linux/fs.h>
5550 + struct dentry **dentries;
5553 +struct au_dcsub_pages {
5555 + struct au_dpage *dpages;
5558 +/* ---------------------------------------------------------------------- */
5561 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
5562 +void au_dpages_free(struct au_dcsub_pages *dpages);
5563 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
5564 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
5565 + au_dpages_test test, void *arg);
5566 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
5567 + int do_include, au_dpages_test test, void *arg);
5568 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
5569 + struct dentry *dentry, int do_include);
5570 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
5572 +/* ---------------------------------------------------------------------- */
5574 +static inline int au_d_hashed_positive(struct dentry *d)
5577 + struct inode *inode = d->d_inode;
5579 + if (unlikely(d_unhashed(d) || !inode || !inode->i_nlink))
5584 +static inline int au_d_alive(struct dentry *d)
5587 + struct inode *inode;
5590 + err = au_d_hashed_positive(d);
5592 + inode = d->d_inode;
5593 + if (unlikely(d_unlinked(d) || !inode || !inode->i_nlink))
5599 +static inline int au_alive_dir(struct dentry *d)
5602 + err = au_d_alive(d);
5603 + if (unlikely(err || IS_DEADDIR(d->d_inode)))
5608 +#endif /* __KERNEL__ */
5609 +#endif /* __AUFS_DCSUB_H__ */
5610 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
5611 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
5612 +++ linux/fs/aufs/debug.c 2013-08-23 23:59:39.634916914 +0200
5615 + * Copyright (C) 2005-2013 Junjiro R. Okajima
5617 + * This program, aufs is free software; you can redistribute it and/or modify
5618 + * it under the terms of the GNU General Public License as published by
5619 + * the Free Software Foundation; either version 2 of the License, or
5620 + * (at your option) any later version.
5622 + * This program is distributed in the hope that it will be useful,
5623 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5624 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5625 + * GNU General Public License for more details.
5627 + * You should have received a copy of the GNU General Public License
5628 + * along with this program; if not, write to the Free Software
5629 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
5633 + * debug print functions
5636 +#include <linux/vt_kern.h>
5640 +MODULE_PARM_DESC(debug, "debug print");
5641 +module_param_named(debug, aufs_debug, int, S_IRUGO | S_IWUSR | S_IWGRP);
5643 +char *au_plevel = KERN_DEBUG;
5644 +#define dpri(fmt, ...) do { \
5646 + && strcmp(au_plevel, KERN_DEBUG)) \
5647 + || au_debug_test()) \
5648 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
5651 +/* ---------------------------------------------------------------------- */
5653 +void au_dpri_whlist(struct au_nhash *whlist)
5655 + unsigned long ul, n;
5656 + struct hlist_head *head;
5657 + struct au_vdir_wh *pos;
5659 + n = whlist->nh_num;
5660 + head = whlist->nh_head;
5661 + for (ul = 0; ul < n; ul++) {
5662 + hlist_for_each_entry(pos, head, wh_hash)
5663 + dpri("b%d, %.*s, %d\n",
5665 + pos->wh_str.len, pos->wh_str.name,
5671 +void au_dpri_vdir(struct au_vdir *vdir)
5674 + union au_vdir_deblk_p p;
5677 + if (!vdir || IS_ERR(vdir)) {
5678 + dpri("err %ld\n", PTR_ERR(vdir));
5682 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n",
5683 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
5684 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
5685 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
5686 + p.deblk = vdir->vd_deblk[ul];
5688 + dpri("[%lu]: %p\n", ul, o);
5692 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
5693 + struct dentry *wh)
5698 + if (!inode || IS_ERR(inode)) {
5699 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
5703 + /* the type of i_blocks depends upon CONFIG_LBDAF */
5704 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
5705 + && sizeof(inode->i_blocks) != sizeof(u64));
5707 + n = (void *)wh->d_name.name;
5708 + l = wh->d_name.len;
5711 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
5712 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
5714 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
5715 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
5716 + i_size_read(inode), (unsigned long long)inode->i_blocks,
5717 + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
5718 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
5719 + inode->i_state, inode->i_flags, inode->i_version,
5720 + inode->i_generation,
5721 + l ? ", wh " : "", l, n);
5725 +void au_dpri_inode(struct inode *inode)
5727 + struct au_iinfo *iinfo;
5728 + aufs_bindex_t bindex;
5731 + err = do_pri_inode(-1, inode, -1, NULL);
5732 + if (err || !au_test_aufs(inode->i_sb))
5735 + iinfo = au_ii(inode);
5738 + dpri("i-1: bstart %d, bend %d, gen %d\n",
5739 + iinfo->ii_bstart, iinfo->ii_bend, au_iigen(inode, NULL));
5740 + if (iinfo->ii_bstart < 0)
5743 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend; bindex++) {
5744 + hn = !!au_hn(iinfo->ii_hinode + bindex);
5745 + do_pri_inode(bindex, iinfo->ii_hinode[0 + bindex].hi_inode, hn,
5746 + iinfo->ii_hinode[0 + bindex].hi_whdentry);
5750 +void au_dpri_dalias(struct inode *inode)
5754 + spin_lock(&inode->i_lock);
5755 + hlist_for_each_entry(d, &inode->i_dentry, d_alias)
5756 + au_dpri_dentry(d);
5757 + spin_unlock(&inode->i_lock);
5760 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
5762 + struct dentry *wh = NULL;
5765 + if (!dentry || IS_ERR(dentry)) {
5766 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
5769 + /* do not call dget_parent() here */
5770 + /* note: access d_xxx without d_lock */
5771 + dpri("d%d: %.*s?/%.*s, %s, cnt %d, flags 0x%x\n",
5773 + AuDLNPair(dentry->d_parent), AuDLNPair(dentry),
5774 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
5775 + dentry->d_count, dentry->d_flags);
5777 + if (bindex >= 0 && dentry->d_inode && au_test_aufs(dentry->d_sb)) {
5778 + struct au_iinfo *iinfo = au_ii(dentry->d_inode);
5780 + hn = !!au_hn(iinfo->ii_hinode + bindex);
5781 + wh = iinfo->ii_hinode[0 + bindex].hi_whdentry;
5784 + do_pri_inode(bindex, dentry->d_inode, hn, wh);
5788 +void au_dpri_dentry(struct dentry *dentry)
5790 + struct au_dinfo *dinfo;
5791 + aufs_bindex_t bindex;
5793 + struct au_hdentry *hdp;
5795 + err = do_pri_dentry(-1, dentry);
5796 + if (err || !au_test_aufs(dentry->d_sb))
5799 + dinfo = au_di(dentry);
5802 + dpri("d-1: bstart %d, bend %d, bwh %d, bdiropq %d, gen %d\n",
5803 + dinfo->di_bstart, dinfo->di_bend,
5804 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry));
5805 + if (dinfo->di_bstart < 0)
5807 + hdp = dinfo->di_hdentry;
5808 + for (bindex = dinfo->di_bstart; bindex <= dinfo->di_bend; bindex++)
5809 + do_pri_dentry(bindex, hdp[0 + bindex].hd_dentry);
5812 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
5816 + if (!file || IS_ERR(file)) {
5817 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
5823 + && au_test_aufs(file->f_dentry->d_sb)
5825 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
5826 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
5827 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
5828 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
5829 + file->f_version, file->f_pos, a);
5830 + if (file->f_dentry)
5831 + do_pri_dentry(bindex, file->f_dentry);
5835 +void au_dpri_file(struct file *file)
5837 + struct au_finfo *finfo;
5838 + struct au_fidir *fidir;
5839 + struct au_hfile *hfile;
5840 + aufs_bindex_t bindex;
5843 + err = do_pri_file(-1, file);
5844 + if (err || !file->f_dentry || !au_test_aufs(file->f_dentry->d_sb))
5847 + finfo = au_fi(file);
5850 + if (finfo->fi_btop < 0)
5852 + fidir = finfo->fi_hdir;
5854 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
5856 + for (bindex = finfo->fi_btop;
5857 + bindex >= 0 && bindex <= fidir->fd_bbot;
5859 + hfile = fidir->fd_hfile + bindex;
5860 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
5864 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
5866 + struct vfsmount *mnt;
5867 + struct super_block *sb;
5869 + if (!br || IS_ERR(br))
5871 + mnt = au_br_mnt(br);
5872 + if (!mnt || IS_ERR(mnt))
5875 + if (!sb || IS_ERR(sb))
5878 + dpri("s%d: {perm 0x%x, id %d, cnt %d, wbr %p}, "
5879 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
5881 + bindex, br->br_perm, br->br_id, atomic_read(&br->br_count),
5882 + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
5883 + sb->s_flags, sb->s_count,
5884 + atomic_read(&sb->s_active), !!br->br_xino.xi_file);
5888 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
5892 +void au_dpri_sb(struct super_block *sb)
5894 + struct au_sbinfo *sbinfo;
5895 + aufs_bindex_t bindex;
5897 + /* to reuduce stack size */
5899 + struct vfsmount mnt;
5900 + struct au_branch fake;
5903 + /* this function can be called from magic sysrq */
5904 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
5905 + if (unlikely(!a)) {
5906 + dpri("no memory\n");
5910 + a->mnt.mnt_sb = sb;
5911 + a->fake.br_perm = 0;
5912 + a->fake.br_path.mnt = &a->mnt;
5913 + a->fake.br_xino.xi_file = NULL;
5914 + atomic_set(&a->fake.br_count, 0);
5915 + smp_mb(); /* atomic_set */
5916 + err = do_pri_br(-1, &a->fake);
5918 + dpri("dev 0x%x\n", sb->s_dev);
5919 + if (err || !au_test_aufs(sb))
5922 + sbinfo = au_sbi(sb);
5925 + dpri("nw %d, gen %u, kobj %d\n",
5926 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
5927 + atomic_read(&sbinfo->si_kobj.kref.refcount));
5928 + for (bindex = 0; bindex <= sbinfo->si_bend; bindex++)
5929 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
5932 +/* ---------------------------------------------------------------------- */
5934 +void au_dbg_sleep_jiffy(int jiffy)
5937 + jiffy = schedule_timeout_uninterruptible(jiffy);
5940 +void au_dbg_iattr(struct iattr *ia)
5942 +#define AuBit(name) \
5944 + if (ia->ia_valid & ATTR_ ## name) \
5945 + dpri(#name "\n"); \
5965 + dpri("ia_file %p\n", ia->ia_file);
5968 +/* ---------------------------------------------------------------------- */
5970 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
5972 + struct inode *h_inode, *inode = dentry->d_inode;
5973 + struct dentry *h_dentry;
5974 + aufs_bindex_t bindex, bend, bi;
5976 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
5979 + bend = au_dbend(dentry);
5980 + bi = au_ibend(inode);
5983 + bindex = au_dbstart(dentry);
5984 + bi = au_ibstart(inode);
5988 + for (; bindex <= bend; bindex++) {
5989 + h_dentry = au_h_dptr(dentry, bindex);
5992 + h_inode = au_h_iptr(inode, bindex);
5993 + if (unlikely(h_inode != h_dentry->d_inode)) {
5994 + int old = au_debug_test();
5997 + AuDbg("b%d, %s:%d\n", bindex, func, line);
5998 + AuDbgDentry(dentry);
5999 + AuDbgInode(inode);
6007 +void au_dbg_verify_dir_parent(struct dentry *dentry, unsigned int sigen)
6009 + struct dentry *parent;
6011 + parent = dget_parent(dentry);
6012 + AuDebugOn(!S_ISDIR(dentry->d_inode->i_mode));
6013 + AuDebugOn(IS_ROOT(dentry));
6014 + AuDebugOn(au_digen_test(parent, sigen));
6018 +void au_dbg_verify_nondir_parent(struct dentry *dentry, unsigned int sigen)
6020 + struct dentry *parent;
6021 + struct inode *inode;
6023 + parent = dget_parent(dentry);
6024 + inode = dentry->d_inode;
6025 + AuDebugOn(inode && S_ISDIR(dentry->d_inode->i_mode));
6026 + AuDebugOn(au_digen_test(parent, sigen));
6030 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
6033 + struct au_dcsub_pages dpages;
6034 + struct au_dpage *dpage;
6035 + struct dentry **dentries;
6037 + err = au_dpages_init(&dpages, GFP_NOFS);
6039 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
6041 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
6042 + dpage = dpages.dpages + i;
6043 + dentries = dpage->dentries;
6044 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
6045 + AuDebugOn(au_digen_test(dentries[j], sigen));
6047 + au_dpages_free(&dpages);
6050 +void au_dbg_verify_kthread(void)
6052 + if (au_wkq_test()) {
6055 + * It may be recursive, but udba=notify between two aufs mounts,
6056 + * where a single ro branch is shared, is not a problem.
6062 +/* ---------------------------------------------------------------------- */
6064 +void au_debug_sbinfo_init(struct au_sbinfo *sbinfo __maybe_unused)
6066 +#ifdef AuForceNoPlink
6067 + au_opt_clr(sbinfo->si_mntflags, PLINK);
6069 +#ifdef AuForceNoXino
6070 + au_opt_clr(sbinfo->si_mntflags, XINO);
6072 +#ifdef AuForceNoRefrof
6073 + au_opt_clr(sbinfo->si_mntflags, REFROF);
6075 +#ifdef AuForceHnotify
6076 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_HNOTIFY);
6079 + sbinfo->si_rdblk = 0;
6080 + sbinfo->si_rdhash = 0;
6084 +int __init au_debug_init(void)
6086 + aufs_bindex_t bindex;
6087 + struct au_vdir_destr destr;
6090 + AuDebugOn(bindex >= 0);
6093 + AuDebugOn(destr.len < NAME_MAX);
6095 +#ifdef CONFIG_4KSTACKS
6096 + pr_warn("CONFIG_4KSTACKS is defined.\n");
6099 +#ifdef AuForceNoBrs
6105 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
6106 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
6107 +++ linux/fs/aufs/debug.h 2013-07-06 13:20:47.740198107 +0200
6110 + * Copyright (C) 2005-2013 Junjiro R. Okajima
6112 + * This program, aufs is free software; you can redistribute it and/or modify
6113 + * it under the terms of the GNU General Public License as published by
6114 + * the Free Software Foundation; either version 2 of the License, or
6115 + * (at your option) any later version.
6117 + * This program is distributed in the hope that it will be useful,
6118 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6119 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6120 + * GNU General Public License for more details.
6122 + * You should have received a copy of the GNU General Public License
6123 + * along with this program; if not, write to the Free Software
6124 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
6128 + * debug print functions
6131 +#ifndef __AUFS_DEBUG_H__
6132 +#define __AUFS_DEBUG_H__
6136 +#include <linux/module.h>
6137 +#include <linux/kallsyms.h>
6138 +#include <linux/sysrq.h>
6140 +#ifdef CONFIG_AUFS_DEBUG
6141 +#define AuDebugOn(a) BUG_ON(a)
6143 +/* module parameter */
6144 +extern int aufs_debug;
6145 +static inline void au_debug(int n)
6151 +static inline int au_debug_test(void)
6153 + return aufs_debug;
6156 +#define AuDebugOn(a) do {} while (0)
6157 +AuStubVoid(au_debug, int n)
6158 +AuStubInt0(au_debug_test, void)
6159 +#endif /* CONFIG_AUFS_DEBUG */
6161 +/* ---------------------------------------------------------------------- */
6165 +#define AuDbg(fmt, ...) do { \
6166 + if (au_debug_test()) \
6167 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
6169 +#define AuLabel(l) AuDbg(#l "\n")
6170 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
6171 +#define AuWarn1(fmt, ...) do { \
6172 + static unsigned char _c; \
6174 + pr_warn(fmt, ##__VA_ARGS__); \
6177 +#define AuErr1(fmt, ...) do { \
6178 + static unsigned char _c; \
6180 + pr_err(fmt, ##__VA_ARGS__); \
6183 +#define AuIOErr1(fmt, ...) do { \
6184 + static unsigned char _c; \
6186 + AuIOErr(fmt, ##__VA_ARGS__); \
6189 +#define AuUnsupportMsg "This operation is not supported." \
6190 + " Please report this application to aufs-users ML."
6191 +#define AuUnsupport(fmt, ...) do { \
6192 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
6196 +#define AuTraceErr(e) do { \
6197 + if (unlikely((e) < 0)) \
6198 + AuDbg("err %d\n", (int)(e)); \
6201 +#define AuTraceErrPtr(p) do { \
6203 + AuDbg("err %ld\n", PTR_ERR(p)); \
6206 +/* dirty macros for debug print, use with "%.*s" and caution */
6207 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
6208 +#define AuDLNPair(d) AuLNPair(&(d)->d_name)
6210 +/* ---------------------------------------------------------------------- */
6215 +#ifdef CONFIG_AUFS_DEBUG
6216 +extern char *au_plevel;
6218 +void au_dpri_whlist(struct au_nhash *whlist);
6220 +void au_dpri_vdir(struct au_vdir *vdir);
6222 +void au_dpri_inode(struct inode *inode);
6223 +void au_dpri_dalias(struct inode *inode);
6224 +void au_dpri_dentry(struct dentry *dentry);
6226 +void au_dpri_file(struct file *filp);
6227 +struct super_block;
6228 +void au_dpri_sb(struct super_block *sb);
6230 +void au_dbg_sleep_jiffy(int jiffy);
6232 +void au_dbg_iattr(struct iattr *ia);
6234 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
6235 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
6236 +void au_dbg_verify_dir_parent(struct dentry *dentry, unsigned int sigen);
6237 +void au_dbg_verify_nondir_parent(struct dentry *dentry, unsigned int sigen);
6238 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
6239 +void au_dbg_verify_kthread(void);
6241 +int __init au_debug_init(void);
6242 +void au_debug_sbinfo_init(struct au_sbinfo *sbinfo);
6243 +#define AuDbgWhlist(w) do { \
6245 + au_dpri_whlist(w); \
6248 +#define AuDbgVdir(v) do { \
6250 + au_dpri_vdir(v); \
6253 +#define AuDbgInode(i) do { \
6255 + au_dpri_inode(i); \
6258 +#define AuDbgDAlias(i) do { \
6260 + au_dpri_dalias(i); \
6263 +#define AuDbgDentry(d) do { \
6265 + au_dpri_dentry(d); \
6268 +#define AuDbgFile(f) do { \
6270 + au_dpri_file(f); \
6273 +#define AuDbgSb(sb) do { \
6274 + AuDbg(#sb "\n"); \
6278 +#define AuDbgSleep(sec) do { \
6279 + AuDbg("sleep %d sec\n", sec); \
6283 +#define AuDbgSleepJiffy(jiffy) do { \
6284 + AuDbg("sleep %d jiffies\n", jiffy); \
6285 + au_dbg_sleep_jiffy(jiffy); \
6288 +#define AuDbgIAttr(ia) do { \
6289 + AuDbg("ia_valid 0x%x\n", (ia)->ia_valid); \
6290 + au_dbg_iattr(ia); \
6293 +#define AuDbgSym(addr) do { \
6294 + char sym[KSYM_SYMBOL_LEN]; \
6295 + sprint_symbol(sym, (unsigned long)addr); \
6296 + AuDbg("%s\n", sym); \
6299 +#define AuInfoSym(addr) do { \
6300 + char sym[KSYM_SYMBOL_LEN]; \
6301 + sprint_symbol(sym, (unsigned long)addr); \
6302 + AuInfo("%s\n", sym); \
6305 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
6306 +AuStubVoid(au_dbg_verify_dir_parent, struct dentry *dentry, unsigned int sigen)
6307 +AuStubVoid(au_dbg_verify_nondir_parent, struct dentry *dentry,
6308 + unsigned int sigen)
6309 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
6310 +AuStubVoid(au_dbg_verify_kthread, void)
6311 +AuStubInt0(__init au_debug_init, void)
6312 +AuStubVoid(au_debug_sbinfo_init, struct au_sbinfo *sbinfo)
6314 +#define AuDbgWhlist(w) do {} while (0)
6315 +#define AuDbgVdir(v) do {} while (0)
6316 +#define AuDbgInode(i) do {} while (0)
6317 +#define AuDbgDAlias(i) do {} while (0)
6318 +#define AuDbgDentry(d) do {} while (0)
6319 +#define AuDbgFile(f) do {} while (0)
6320 +#define AuDbgSb(sb) do {} while (0)
6321 +#define AuDbgSleep(sec) do {} while (0)
6322 +#define AuDbgSleepJiffy(jiffy) do {} while (0)
6323 +#define AuDbgIAttr(ia) do {} while (0)
6324 +#define AuDbgSym(addr) do {} while (0)
6325 +#define AuInfoSym(addr) do {} while (0)
6326 +#endif /* CONFIG_AUFS_DEBUG */
6328 +/* ---------------------------------------------------------------------- */
6330 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
6331 +int __init au_sysrq_init(void);
6332 +void au_sysrq_fin(void);
6334 +#ifdef CONFIG_HW_CONSOLE
6335 +#define au_dbg_blocked() do { \
6337 + handle_sysrq('w'); \
6340 +AuStubVoid(au_dbg_blocked, void)
6344 +AuStubInt0(__init au_sysrq_init, void)
6345 +AuStubVoid(au_sysrq_fin, void)
6346 +AuStubVoid(au_dbg_blocked, void)
6347 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
6349 +#endif /* __KERNEL__ */
6350 +#endif /* __AUFS_DEBUG_H__ */
6351 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
6352 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
6353 +++ linux/fs/aufs/dentry.c 2013-07-06 13:20:47.740198107 +0200
6356 + * Copyright (C) 2005-2013 Junjiro R. Okajima
6358 + * This program, aufs is free software; you can redistribute it and/or modify
6359 + * it under the terms of the GNU General Public License as published by
6360 + * the Free Software Foundation; either version 2 of the License, or
6361 + * (at your option) any later version.
6363 + * This program is distributed in the hope that it will be useful,
6364 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6365 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6366 + * GNU General Public License for more details.
6368 + * You should have received a copy of the GNU General Public License
6369 + * along with this program; if not, write to the Free Software
6370 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
6374 + * lookup and dentry operations
6377 +#include <linux/namei.h>
6380 +#define AuLkup_ALLOW_NEG 1
6381 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
6382 +#define au_fset_lkup(flags, name) \
6383 + do { (flags) |= AuLkup_##name; } while (0)
6384 +#define au_fclr_lkup(flags, name) \
6385 + do { (flags) &= ~AuLkup_##name; } while (0)
6387 +struct au_do_lookup_args {
6388 + unsigned int flags;
6393 + * returns positive/negative dentry, NULL or an error.
6394 + * NULL means whiteout-ed or not-found.
6396 +static struct dentry*
6397 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
6398 + aufs_bindex_t bindex, struct qstr *wh_name,
6399 + struct au_do_lookup_args *args)
6401 + struct dentry *h_dentry;
6402 + struct inode *h_inode, *inode;
6403 + struct au_branch *br;
6404 + int wh_found, opq;
6405 + unsigned char wh_able;
6406 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
6409 + br = au_sbr(dentry->d_sb, bindex);
6410 + wh_able = !!au_br_whable(br->br_perm);
6412 + wh_found = au_wh_test(h_parent, wh_name, br, /*try_sio*/0);
6413 + h_dentry = ERR_PTR(wh_found);
6416 + if (unlikely(wh_found < 0))
6419 + /* We found a whiteout */
6420 + /* au_set_dbend(dentry, bindex); */
6421 + au_set_dbwh(dentry, bindex);
6423 + return NULL; /* success */
6426 + h_dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
6427 + if (IS_ERR(h_dentry))
6430 + h_inode = h_dentry->d_inode;
6434 + } else if (wh_found
6435 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
6438 + if (au_dbend(dentry) <= bindex)
6439 + au_set_dbend(dentry, bindex);
6440 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
6441 + au_set_dbstart(dentry, bindex);
6442 + au_set_h_dptr(dentry, bindex, h_dentry);
6444 + inode = dentry->d_inode;
6445 + if (!h_inode || !S_ISDIR(h_inode->i_mode) || !wh_able
6446 + || (inode && !S_ISDIR(inode->i_mode)))
6447 + goto out; /* success */
6449 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
6450 + opq = au_diropq_test(h_dentry, br);
6451 + mutex_unlock(&h_inode->i_mutex);
6453 + au_set_dbdiropq(dentry, bindex);
6454 + else if (unlikely(opq < 0)) {
6455 + au_set_h_dptr(dentry, bindex, NULL);
6456 + h_dentry = ERR_PTR(opq);
6467 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
6469 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
6470 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
6476 + * returns the number of lower positive dentries,
6477 + * otherwise an error.
6478 + * can be called at unlinking with @type is zero.
6480 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type)
6482 + int npositive, err;
6483 + aufs_bindex_t bindex, btail, bdiropq;
6484 + unsigned char isdir;
6485 + struct qstr whname;
6486 + struct au_do_lookup_args args = {
6490 + const struct qstr *name = &dentry->d_name;
6491 + struct dentry *parent;
6492 + struct inode *inode;
6494 + err = au_test_shwh(dentry->d_sb, name);
6495 + if (unlikely(err))
6498 + err = au_wh_name_alloc(&whname, name);
6499 + if (unlikely(err))
6502 + inode = dentry->d_inode;
6503 + isdir = !!(inode && S_ISDIR(inode->i_mode));
6505 + au_fset_lkup(args.flags, ALLOW_NEG);
6508 + parent = dget_parent(dentry);
6509 + btail = au_dbtaildir(parent);
6510 + for (bindex = bstart; bindex <= btail; bindex++) {
6511 + struct dentry *h_parent, *h_dentry;
6512 + struct inode *h_inode, *h_dir;
6514 + h_dentry = au_h_dptr(dentry, bindex);
6516 + if (h_dentry->d_inode)
6518 + if (type != S_IFDIR)
6522 + h_parent = au_h_dptr(parent, bindex);
6525 + h_dir = h_parent->d_inode;
6526 + if (!h_dir || !S_ISDIR(h_dir->i_mode))
6529 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
6530 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname,
6532 + mutex_unlock(&h_dir->i_mutex);
6533 + err = PTR_ERR(h_dentry);
6534 + if (IS_ERR(h_dentry))
6536 + au_fclr_lkup(args.flags, ALLOW_NEG);
6538 + if (au_dbwh(dentry) >= 0)
6542 + h_inode = h_dentry->d_inode;
6547 + args.type = h_inode->i_mode & S_IFMT;
6548 + if (args.type != S_IFDIR)
6551 + /* the type of lower may be different */
6552 + bdiropq = au_dbdiropq(dentry);
6553 + if (bdiropq >= 0 && bdiropq <= bindex)
6559 + AuLabel(positive);
6560 + au_update_dbstart(dentry);
6563 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
6564 + && au_dbstart(dentry) < 0)) {
6566 + AuIOErr("both of real entry and whiteout found, %.*s, err %d\n",
6567 + AuDLNPair(dentry), err);
6572 + kfree(whname.name);
6577 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent,
6578 + struct au_branch *br)
6580 + struct dentry *dentry;
6583 + if (!au_test_h_perm_sio(parent->d_inode, MAY_EXEC))
6584 + dentry = vfsub_lkup_one(name, parent);
6586 + struct vfsub_lkup_one_args args = {
6592 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
6593 + if (unlikely(wkq_err))
6594 + dentry = ERR_PTR(wkq_err);
6601 + * lookup @dentry on @bindex which should be negative.
6603 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
6606 + struct dentry *parent, *h_parent, *h_dentry;
6607 + struct au_branch *br;
6609 + parent = dget_parent(dentry);
6610 + h_parent = au_h_dptr(parent, bindex);
6611 + br = au_sbr(dentry->d_sb, bindex);
6613 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
6615 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent, br);
6616 + err = PTR_ERR(h_dentry);
6617 + if (IS_ERR(h_dentry))
6619 + if (unlikely(h_dentry->d_inode)) {
6621 + AuIOErr("%.*s should be negative on b%d.\n",
6622 + AuDLNPair(h_dentry), bindex);
6628 + if (bindex < au_dbstart(dentry))
6629 + au_set_dbstart(dentry, bindex);
6630 + if (au_dbend(dentry) < bindex)
6631 + au_set_dbend(dentry, bindex);
6632 + au_set_h_dptr(dentry, bindex, h_dentry);
6639 +/* ---------------------------------------------------------------------- */
6641 +/* subset of struct inode */
6643 + unsigned long i_ino;
6644 + /* unsigned int i_nlink; */
6650 + blkcnt_t i_blocks;
6655 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
6657 + ia->i_ino = h_inode->i_ino;
6658 + /* ia->i_nlink = h_inode->i_nlink; */
6659 + ia->i_uid = h_inode->i_uid;
6660 + ia->i_gid = h_inode->i_gid;
6661 + ia->i_version = h_inode->i_version;
6663 + ia->i_size = h_inode->i_size;
6664 + ia->i_blocks = h_inode->i_blocks;
6666 + ia->i_mode = (h_inode->i_mode & S_IFMT);
6669 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
6671 + return ia->i_ino != h_inode->i_ino
6672 + /* || ia->i_nlink != h_inode->i_nlink */
6673 + || !uid_eq(ia->i_uid, h_inode->i_uid)
6674 + || !gid_eq(ia->i_gid, h_inode->i_gid)
6675 + || ia->i_version != h_inode->i_version
6677 + || ia->i_size != h_inode->i_size
6678 + || ia->i_blocks != h_inode->i_blocks
6680 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
6683 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
6684 + struct au_branch *br)
6687 + struct au_iattr ia;
6688 + struct inode *h_inode;
6689 + struct dentry *h_d;
6690 + struct super_block *h_sb;
6693 + memset(&ia, -1, sizeof(ia));
6694 + h_sb = h_dentry->d_sb;
6695 + h_inode = h_dentry->d_inode;
6697 + au_iattr_save(&ia, h_inode);
6698 + else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
6699 + /* nfs d_revalidate may return 0 for negative dentry */
6700 + /* fuse d_revalidate always return 0 for negative dentry */
6703 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
6704 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
6705 + err = PTR_ERR(h_d);
6710 + if (unlikely(h_d != h_dentry
6711 + || h_d->d_inode != h_inode
6712 + || (h_inode && au_iattr_test(&ia, h_inode))))
6713 + err = au_busy_or_stale();
6721 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
6722 + struct dentry *h_parent, struct au_branch *br)
6727 + if (udba == AuOpt_UDBA_REVAL
6728 + && !au_test_fs_remote(h_dentry->d_sb)) {
6730 + err = (h_dentry->d_parent->d_inode != h_dir);
6731 + } else if (udba != AuOpt_UDBA_NONE)
6732 + err = au_h_verify_dentry(h_dentry, h_parent, br);
6737 +/* ---------------------------------------------------------------------- */
6739 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
6742 + aufs_bindex_t new_bindex, bindex, bend, bwh, bdiropq;
6743 + struct au_hdentry tmp, *p, *q;
6744 + struct au_dinfo *dinfo;
6745 + struct super_block *sb;
6747 + DiMustWriteLock(dentry);
6749 + sb = dentry->d_sb;
6750 + dinfo = au_di(dentry);
6751 + bend = dinfo->di_bend;
6752 + bwh = dinfo->di_bwh;
6753 + bdiropq = dinfo->di_bdiropq;
6754 + p = dinfo->di_hdentry + dinfo->di_bstart;
6755 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++, p++) {
6756 + if (!p->hd_dentry)
6759 + new_bindex = au_br_index(sb, p->hd_id);
6760 + if (new_bindex == bindex)
6763 + if (dinfo->di_bwh == bindex)
6765 + if (dinfo->di_bdiropq == bindex)
6766 + bdiropq = new_bindex;
6767 + if (new_bindex < 0) {
6769 + p->hd_dentry = NULL;
6773 + /* swap two lower dentries, and loop again */
6774 + q = dinfo->di_hdentry + new_bindex;
6778 + if (tmp.hd_dentry) {
6784 + dinfo->di_bwh = -1;
6785 + if (bwh >= 0 && bwh <= au_sbend(sb) && au_sbr_whable(sb, bwh))
6786 + dinfo->di_bwh = bwh;
6788 + dinfo->di_bdiropq = -1;
6790 + && bdiropq <= au_sbend(sb)
6791 + && au_sbr_whable(sb, bdiropq))
6792 + dinfo->di_bdiropq = bdiropq;
6795 + dinfo->di_bstart = -1;
6796 + dinfo->di_bend = -1;
6797 + bend = au_dbend(parent);
6798 + p = dinfo->di_hdentry;
6799 + for (bindex = 0; bindex <= bend; bindex++, p++)
6800 + if (p->hd_dentry) {
6801 + dinfo->di_bstart = bindex;
6805 + if (dinfo->di_bstart >= 0) {
6806 + p = dinfo->di_hdentry + bend;
6807 + for (bindex = bend; bindex >= 0; bindex--, p--)
6808 + if (p->hd_dentry) {
6809 + dinfo->di_bend = bindex;
6818 +static void au_do_hide(struct dentry *dentry)
6820 + struct inode *inode;
6822 + inode = dentry->d_inode;
6824 + if (!S_ISDIR(inode->i_mode)) {
6825 + if (inode->i_nlink && !d_unhashed(dentry))
6826 + drop_nlink(inode);
6828 + clear_nlink(inode);
6829 + /* stop next lookup */
6830 + inode->i_flags |= S_DEAD;
6832 + smp_mb(); /* necessary? */
6837 +static int au_hide_children(struct dentry *parent)
6839 + int err, i, j, ndentry;
6840 + struct au_dcsub_pages dpages;
6841 + struct au_dpage *dpage;
6842 + struct dentry *dentry;
6844 + err = au_dpages_init(&dpages, GFP_NOFS);
6845 + if (unlikely(err))
6847 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
6848 + if (unlikely(err))
6851 + /* in reverse order */
6852 + for (i = dpages.ndpage - 1; i >= 0; i--) {
6853 + dpage = dpages.dpages + i;
6854 + ndentry = dpage->ndentry;
6855 + for (j = ndentry - 1; j >= 0; j--) {
6856 + dentry = dpage->dentries[j];
6857 + if (dentry != parent)
6858 + au_do_hide(dentry);
6863 + au_dpages_free(&dpages);
6868 +static void au_hide(struct dentry *dentry)
6871 + struct inode *inode;
6873 + AuDbgDentry(dentry);
6874 + inode = dentry->d_inode;
6875 + if (inode && S_ISDIR(inode->i_mode)) {
6876 + /* shrink_dcache_parent(dentry); */
6877 + err = au_hide_children(dentry);
6878 + if (unlikely(err))
6879 + AuIOErr("%.*s, failed hiding children, ignored %d\n",
6880 + AuDLNPair(dentry), err);
6882 + au_do_hide(dentry);
6886 + * By adding a dirty branch, a cached dentry may be affected in various ways.
6888 + * a dirty branch is added
6889 + * - on the top of layers
6890 + * - in the middle of layers
6891 + * - to the bottom of layers
6893 + * on the added branch there exists
6896 + * - a same named entry
6898 + * * negative --> positive
6899 + * * positive --> positive
6900 + * - type is unchanged
6901 + * - type is changed
6903 + * * negative --> negative
6904 + * * positive --> negative (rejected by au_br_del() for non-dir case)
6907 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
6908 + struct au_dinfo *tmp)
6911 + aufs_bindex_t bindex, bend;
6913 + struct dentry *dentry;
6914 + struct inode *inode;
6917 + struct au_hdentry *hd;
6918 + struct inode *inode, *h_inode;
6919 + struct dentry *h_dentry;
6922 + AuDebugOn(dinfo->di_bstart < 0);
6923 + orig_h.dentry = dinfo->di_hdentry[dinfo->di_bstart].hd_dentry;
6924 + orig_h.inode = orig_h.dentry->d_inode;
6927 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
6928 + memset(&tmp_h, 0, sizeof(tmp_h));
6929 + if (tmp->di_bstart >= 0) {
6930 + tmp_h.dentry = tmp->di_hdentry[tmp->di_bstart].hd_dentry;
6931 + tmp_h.inode = tmp_h.dentry->d_inode;
6933 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
6936 + inode = dentry->d_inode;
6937 + if (!orig_h.inode) {
6938 + AuDbg("nagative originally\n");
6944 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
6945 + AuDebugOn(dinfo->di_bdiropq != -1);
6947 + if (!tmp_h.inode) {
6948 + AuDbg("negative --> negative\n");
6949 + /* should have only one negative lower */
6950 + if (tmp->di_bstart >= 0
6951 + && tmp->di_bstart < dinfo->di_bstart) {
6952 + AuDebugOn(tmp->di_bstart != tmp->di_bend);
6953 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
6954 + au_set_h_dptr(dentry, dinfo->di_bstart, NULL);
6955 + au_di_cp(dinfo, tmp);
6956 + hd = tmp->di_hdentry + tmp->di_bstart;
6957 + au_set_h_dptr(dentry, tmp->di_bstart,
6958 + dget(hd->hd_dentry));
6960 + au_dbg_verify_dinode(dentry);
6962 + AuDbg("negative --> positive\n");
6964 + * similar to the behaviour of creating with bypassing
6966 + * unhash it in order to force an error in the
6967 + * succeeding create operation.
6968 + * we should not set S_DEAD here.
6971 + /* au_di_swap(tmp, dinfo); */
6972 + au_dbg_verify_dinode(dentry);
6975 + AuDbg("positive originally\n");
6976 + /* inode may be NULL */
6977 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
6978 + if (!tmp_h.inode) {
6979 + AuDbg("positive --> negative\n");
6980 + /* or bypassing aufs */
6982 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_bstart)
6983 + dinfo->di_bwh = tmp->di_bwh;
6985 + err = au_refresh_hinode_self(inode);
6986 + au_dbg_verify_dinode(dentry);
6987 + } else if (orig_h.mode == tmp_h.mode) {
6988 + AuDbg("positive --> positive, same type\n");
6989 + if (!S_ISDIR(orig_h.mode)
6990 + && dinfo->di_bstart > tmp->di_bstart) {
6992 + * similar to the behaviour of removing and
6997 + err = au_refresh_hinode_self(inode);
6998 + au_dbg_verify_dinode(dentry);
7000 + /* fill empty slots */
7001 + if (dinfo->di_bstart > tmp->di_bstart)
7002 + dinfo->di_bstart = tmp->di_bstart;
7003 + if (dinfo->di_bend < tmp->di_bend)
7004 + dinfo->di_bend = tmp->di_bend;
7005 + dinfo->di_bwh = tmp->di_bwh;
7006 + dinfo->di_bdiropq = tmp->di_bdiropq;
7007 + hd = tmp->di_hdentry;
7008 + bend = dinfo->di_bend;
7009 + for (bindex = tmp->di_bstart; bindex <= bend;
7011 + if (au_h_dptr(dentry, bindex))
7013 + h_dentry = hd[bindex].hd_dentry;
7016 + h_inode = h_dentry->d_inode;
7017 + AuDebugOn(!h_inode);
7018 + AuDebugOn(orig_h.mode
7019 + != (h_inode->i_mode
7021 + au_set_h_dptr(dentry, bindex,
7024 + err = au_refresh_hinode(inode, dentry);
7025 + au_dbg_verify_dinode(dentry);
7028 + AuDbg("positive --> positive, different type\n");
7029 + /* similar to the behaviour of removing and creating */
7032 + err = au_refresh_hinode_self(inode);
7033 + au_dbg_verify_dinode(dentry);
7041 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
7044 + unsigned int sigen;
7045 + struct au_dinfo *dinfo, *tmp;
7046 + struct super_block *sb;
7047 + struct inode *inode;
7049 + DiMustWriteLock(dentry);
7050 + AuDebugOn(IS_ROOT(dentry));
7051 + AuDebugOn(!parent->d_inode);
7053 + sb = dentry->d_sb;
7054 + inode = dentry->d_inode;
7055 + sigen = au_sigen(sb);
7056 + err = au_digen_test(parent, sigen);
7057 + if (unlikely(err))
7060 + dinfo = au_di(dentry);
7061 + err = au_di_realloc(dinfo, au_sbend(sb) + 1);
7062 + if (unlikely(err))
7064 + ebrange = au_dbrange_test(dentry);
7066 + ebrange = au_do_refresh_hdentry(dentry, parent);
7068 + if (d_unhashed(dentry) || ebrange) {
7069 + AuDebugOn(au_dbstart(dentry) < 0 && au_dbend(dentry) >= 0);
7071 + err = au_refresh_hinode_self(inode);
7072 + au_dbg_verify_dinode(dentry);
7074 + goto out_dgen; /* success */
7078 + /* temporary dinfo */
7079 + AuDbgDentry(dentry);
7081 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
7082 + if (unlikely(!tmp))
7084 + au_di_swap(tmp, dinfo);
7085 + /* returns the number of positive dentries */
7087 + * if current working dir is removed, it returns an error.
7088 + * but the dentry is legal.
7090 + err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0);
7091 + AuDbgDentry(dentry);
7092 + au_di_swap(tmp, dinfo);
7093 + if (err == -ENOENT)
7096 + /* compare/refresh by dinfo */
7097 + AuDbgDentry(dentry);
7098 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
7099 + au_dbg_verify_dinode(dentry);
7102 + au_rw_write_unlock(&tmp->di_rwsem);
7104 + if (unlikely(err))
7108 + au_update_digen(dentry);
7110 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
7111 + AuIOErr("failed refreshing %.*s, %d\n",
7112 + AuDLNPair(dentry), err);
7113 + AuDbgDentry(dentry);
7119 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
7120 + struct dentry *dentry, aufs_bindex_t bindex)
7125 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
7128 + AuDbg("b%d\n", bindex);
7130 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
7131 + * due to whiteout and branch permission.
7133 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
7134 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
7135 + /* it may return tri-state */
7136 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
7138 + if (unlikely(valid < 0))
7148 +/* todo: remove this */
7149 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
7150 + unsigned int flags, int do_udba)
7153 + umode_t mode, h_mode;
7154 + aufs_bindex_t bindex, btail, bstart, ibs, ibe;
7155 + unsigned char plus, unhashed, is_root, h_plus;
7156 + struct inode *h_inode, *h_cached_inode;
7157 + struct dentry *h_dentry;
7158 + struct qstr *name, *h_name;
7165 + unhashed = !!d_unhashed(dentry);
7166 + is_root = !!IS_ROOT(dentry);
7167 + name = &dentry->d_name;
7170 + * Theoretically, REVAL test should be unnecessary in case of
7172 + * But {fs,i}notify doesn't fire some necessary events,
7173 + * IN_ATTRIB for atime/nlink/pageio
7174 + * IN_DELETE for NFS dentry
7175 + * Let's do REVAL test too.
7177 + if (do_udba && inode) {
7178 + mode = (inode->i_mode & S_IFMT);
7179 + plus = (inode->i_nlink > 0);
7180 + ibs = au_ibstart(inode);
7181 + ibe = au_ibend(inode);
7184 + bstart = au_dbstart(dentry);
7186 + if (inode && S_ISDIR(inode->i_mode))
7187 + btail = au_dbtaildir(dentry);
7188 + for (bindex = bstart; bindex <= btail; bindex++) {
7189 + h_dentry = au_h_dptr(dentry, bindex);
7193 + AuDbg("b%d, %.*s\n", bindex, AuDLNPair(h_dentry));
7194 + spin_lock(&h_dentry->d_lock);
7195 + h_name = &h_dentry->d_name;
7196 + if (unlikely(do_udba
7198 + && (unhashed != !!d_unhashed(h_dentry)
7199 + || name->len != h_name->len
7200 + || memcmp(name->name, h_name->name, name->len))
7202 + AuDbg("unhash 0x%x 0x%x, %.*s %.*s\n",
7203 + unhashed, d_unhashed(h_dentry),
7204 + AuDLNPair(dentry), AuDLNPair(h_dentry));
7205 + spin_unlock(&h_dentry->d_lock);
7208 + spin_unlock(&h_dentry->d_lock);
7210 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
7211 + if (unlikely(err))
7212 + /* do not goto err, to keep the errno */
7215 + /* todo: plink too? */
7220 + h_inode = h_dentry->d_inode;
7221 + if (unlikely(!!inode != !!h_inode))
7226 + h_cached_inode = h_inode;
7228 + h_mode = (h_inode->i_mode & S_IFMT);
7229 + h_plus = (h_inode->i_nlink > 0);
7231 + if (inode && ibs <= bindex && bindex <= ibe)
7232 + h_cached_inode = au_h_iptr(inode, bindex);
7234 + if (unlikely(plus != h_plus
7236 + || h_cached_inode != h_inode))
7248 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
7249 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
7252 + struct dentry *parent;
7254 + if (!au_digen_test(dentry, sigen))
7257 + parent = dget_parent(dentry);
7258 + di_read_lock_parent(parent, AuLock_IR);
7259 + AuDebugOn(au_digen_test(parent, sigen));
7260 + au_dbg_verify_gen(parent, sigen);
7261 + err = au_refresh_dentry(dentry, parent);
7262 + di_read_unlock(parent, AuLock_IR);
7268 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
7271 + struct dentry *d, *parent;
7272 + struct inode *inode;
7274 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
7275 + return simple_reval_dpath(dentry, sigen);
7277 + /* slow loop, keep it simple and stupid */
7278 + /* cf: au_cpup_dirs() */
7281 + while (au_digen_test(dentry, sigen)) {
7285 + parent = dget_parent(d);
7286 + if (!au_digen_test(parent, sigen))
7291 + inode = d->d_inode;
7293 + di_write_lock_child2(d);
7295 + /* someone might update our dentry while we were sleeping */
7296 + if (au_digen_test(d, sigen)) {
7298 + * todo: consolidate with simple_reval_dpath(),
7299 + * do_refresh() and au_reval_for_attr().
7301 + di_read_lock_parent(parent, AuLock_IR);
7302 + err = au_refresh_dentry(d, parent);
7303 + di_read_unlock(parent, AuLock_IR);
7307 + di_write_unlock(d);
7309 + if (unlikely(err))
7317 + * if valid returns 1, otherwise 0.
7319 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
7322 + unsigned int sigen;
7323 + unsigned char do_udba;
7324 + struct super_block *sb;
7325 + struct inode *inode;
7327 + /* todo: support rcu-walk? */
7328 + if (flags & LOOKUP_RCU)
7332 + if (unlikely(!au_di(dentry)))
7335 + inode = dentry->d_inode;
7336 + if (inode && is_bad_inode(inode))
7340 + sb = dentry->d_sb;
7343 + * i_mutex of parent dir may be held,
7344 + * but we should not return 'invalid' due to busy.
7346 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
7347 + if (unlikely(err)) {
7352 + if (unlikely(au_dbrange_test(dentry))) {
7358 + sigen = au_sigen(sb);
7359 + if (au_digen_test(dentry, sigen)) {
7360 + AuDebugOn(IS_ROOT(dentry));
7361 + err = au_reval_dpath(dentry, sigen);
7362 + if (unlikely(err)) {
7367 + di_downgrade_lock(dentry, AuLock_IR);
7370 + if (inode && (IS_DEADDIR(inode) || !inode->i_nlink))
7373 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
7374 + if (do_udba && inode) {
7375 + aufs_bindex_t bstart = au_ibstart(inode);
7376 + struct inode *h_inode;
7378 + if (bstart >= 0) {
7379 + h_inode = au_h_iptr(inode, bstart);
7380 + if (h_inode && au_test_higen(inode, h_inode))
7385 + err = h_d_revalidate(dentry, inode, flags, do_udba);
7386 + if (unlikely(!err && do_udba && au_dbstart(dentry) < 0)) {
7388 + AuDbg("both of real entry and whiteout found, %.*s, err %d\n",
7389 + AuDLNPair(dentry), err);
7394 + di_downgrade_lock(dentry, AuLock_IR);
7396 + aufs_read_unlock(dentry, AuLock_IR);
7401 + AuDbg("%.*s invalid, %d\n", AuDLNPair(dentry), valid);
7407 +static void aufs_d_release(struct dentry *dentry)
7409 + if (au_di(dentry)) {
7410 + au_di_fin(dentry);
7411 + au_hn_di_reinit(dentry);
7415 +const struct dentry_operations aufs_dop = {
7416 + .d_revalidate = aufs_d_revalidate,
7417 + .d_weak_revalidate = aufs_d_revalidate,
7418 + .d_release = aufs_d_release
7420 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
7421 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
7422 +++ linux/fs/aufs/dentry.h 2013-07-06 13:20:47.740198107 +0200
7425 + * Copyright (C) 2005-2013 Junjiro R. Okajima
7427 + * This program, aufs is free software; you can redistribute it and/or modify
7428 + * it under the terms of the GNU General Public License as published by
7429 + * the Free Software Foundation; either version 2 of the License, or
7430 + * (at your option) any later version.
7432 + * This program is distributed in the hope that it will be useful,
7433 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7434 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7435 + * GNU General Public License for more details.
7437 + * You should have received a copy of the GNU General Public License
7438 + * along with this program; if not, write to the Free Software
7439 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
7443 + * lookup and dentry operations
7446 +#ifndef __AUFS_DENTRY_H__
7447 +#define __AUFS_DENTRY_H__
7451 +#include <linux/dcache.h>
7454 +struct au_hdentry {
7455 + struct dentry *hd_dentry;
7456 + aufs_bindex_t hd_id;
7460 + atomic_t di_generation;
7462 + struct au_rwsem di_rwsem;
7463 + aufs_bindex_t di_bstart, di_bend, di_bwh, di_bdiropq;
7464 + struct au_hdentry *di_hdentry;
7465 +} ____cacheline_aligned_in_smp;
7467 +/* ---------------------------------------------------------------------- */
7470 +extern const struct dentry_operations aufs_dop;
7472 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent,
7473 + struct au_branch *br);
7474 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
7475 + struct dentry *h_parent, struct au_branch *br);
7477 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type);
7478 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
7479 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
7480 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
7483 +void au_di_init_once(void *_di);
7484 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
7485 +void au_di_free(struct au_dinfo *dinfo);
7486 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
7487 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
7488 +int au_di_init(struct dentry *dentry);
7489 +void au_di_fin(struct dentry *dentry);
7490 +int au_di_realloc(struct au_dinfo *dinfo, int nbr);
7492 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
7493 +void di_read_unlock(struct dentry *d, int flags);
7494 +void di_downgrade_lock(struct dentry *d, int flags);
7495 +void di_write_lock(struct dentry *d, unsigned int lsc);
7496 +void di_write_unlock(struct dentry *d);
7497 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
7498 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
7499 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
7501 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
7502 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
7503 +aufs_bindex_t au_dbtail(struct dentry *dentry);
7504 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
7506 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
7507 + struct dentry *h_dentry);
7508 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
7509 +int au_dbrange_test(struct dentry *dentry);
7510 +void au_update_digen(struct dentry *dentry);
7511 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
7512 +void au_update_dbstart(struct dentry *dentry);
7513 +void au_update_dbend(struct dentry *dentry);
7514 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
7516 +/* ---------------------------------------------------------------------- */
7518 +static inline struct au_dinfo *au_di(struct dentry *dentry)
7520 + return dentry->d_fsdata;
7523 +/* ---------------------------------------------------------------------- */
7525 +/* lock subclass for dinfo */
7527 + AuLsc_DI_CHILD, /* child first */
7528 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
7529 + AuLsc_DI_CHILD3, /* copyup dirs */
7533 + AuLsc_DI_TMP /* temp for replacing dinfo */
7537 + * di_read_lock_child, di_write_lock_child,
7538 + * di_read_lock_child2, di_write_lock_child2,
7539 + * di_read_lock_child3, di_write_lock_child3,
7540 + * di_read_lock_parent, di_write_lock_parent,
7541 + * di_read_lock_parent2, di_write_lock_parent2,
7542 + * di_read_lock_parent3, di_write_lock_parent3,
7544 +#define AuReadLockFunc(name, lsc) \
7545 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
7546 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
7548 +#define AuWriteLockFunc(name, lsc) \
7549 +static inline void di_write_lock_##name(struct dentry *d) \
7550 +{ di_write_lock(d, AuLsc_DI_##lsc); }
7552 +#define AuRWLockFuncs(name, lsc) \
7553 + AuReadLockFunc(name, lsc) \
7554 + AuWriteLockFunc(name, lsc)
7556 +AuRWLockFuncs(child, CHILD);
7557 +AuRWLockFuncs(child2, CHILD2);
7558 +AuRWLockFuncs(child3, CHILD3);
7559 +AuRWLockFuncs(parent, PARENT);
7560 +AuRWLockFuncs(parent2, PARENT2);
7561 +AuRWLockFuncs(parent3, PARENT3);
7563 +#undef AuReadLockFunc
7564 +#undef AuWriteLockFunc
7565 +#undef AuRWLockFuncs
7567 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
7568 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
7569 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
7571 +/* ---------------------------------------------------------------------- */
7573 +/* todo: memory barrier? */
7574 +static inline unsigned int au_digen(struct dentry *d)
7576 + return atomic_read(&au_di(d)->di_generation);
7579 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
7581 + hdentry->hd_dentry = NULL;
7584 +static inline void au_hdput(struct au_hdentry *hd)
7587 + dput(hd->hd_dentry);
7590 +static inline aufs_bindex_t au_dbstart(struct dentry *dentry)
7592 + DiMustAnyLock(dentry);
7593 + return au_di(dentry)->di_bstart;
7596 +static inline aufs_bindex_t au_dbend(struct dentry *dentry)
7598 + DiMustAnyLock(dentry);
7599 + return au_di(dentry)->di_bend;
7602 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
7604 + DiMustAnyLock(dentry);
7605 + return au_di(dentry)->di_bwh;
7608 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
7610 + DiMustAnyLock(dentry);
7611 + return au_di(dentry)->di_bdiropq;
7614 +/* todo: hard/soft set? */
7615 +static inline void au_set_dbstart(struct dentry *dentry, aufs_bindex_t bindex)
7617 + DiMustWriteLock(dentry);
7618 + au_di(dentry)->di_bstart = bindex;
7621 +static inline void au_set_dbend(struct dentry *dentry, aufs_bindex_t bindex)
7623 + DiMustWriteLock(dentry);
7624 + au_di(dentry)->di_bend = bindex;
7627 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
7629 + DiMustWriteLock(dentry);
7630 + /* dbwh can be outside of bstart - bend range */
7631 + au_di(dentry)->di_bwh = bindex;
7634 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
7636 + DiMustWriteLock(dentry);
7637 + au_di(dentry)->di_bdiropq = bindex;
7640 +/* ---------------------------------------------------------------------- */
7642 +#ifdef CONFIG_AUFS_HNOTIFY
7643 +static inline void au_digen_dec(struct dentry *d)
7645 + atomic_dec(&au_di(d)->di_generation);
7648 +static inline void au_hn_di_reinit(struct dentry *dentry)
7650 + dentry->d_fsdata = NULL;
7653 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
7654 +#endif /* CONFIG_AUFS_HNOTIFY */
7656 +#endif /* __KERNEL__ */
7657 +#endif /* __AUFS_DENTRY_H__ */
7658 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
7659 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
7660 +++ linux/fs/aufs/dinfo.c 2013-07-30 22:42:55.839613269 +0200
7663 + * Copyright (C) 2005-2013 Junjiro R. Okajima
7665 + * This program, aufs is free software; you can redistribute it and/or modify
7666 + * it under the terms of the GNU General Public License as published by
7667 + * the Free Software Foundation; either version 2 of the License, or
7668 + * (at your option) any later version.
7670 + * This program is distributed in the hope that it will be useful,
7671 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7672 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7673 + * GNU General Public License for more details.
7675 + * You should have received a copy of the GNU General Public License
7676 + * along with this program; if not, write to the Free Software
7677 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
7681 + * dentry private data
7686 +void au_di_init_once(void *_dinfo)
7688 + struct au_dinfo *dinfo = _dinfo;
7689 + static struct lock_class_key aufs_di;
7691 + au_rw_init(&dinfo->di_rwsem);
7692 + au_rw_class(&dinfo->di_rwsem, &aufs_di);
7695 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
7697 + struct au_dinfo *dinfo;
7700 + dinfo = au_cache_alloc_dinfo();
7701 + if (unlikely(!dinfo))
7704 + nbr = au_sbend(sb) + 1;
7707 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
7708 + if (dinfo->di_hdentry) {
7709 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
7710 + dinfo->di_bstart = -1;
7711 + dinfo->di_bend = -1;
7712 + dinfo->di_bwh = -1;
7713 + dinfo->di_bdiropq = -1;
7714 + for (i = 0; i < nbr; i++)
7715 + dinfo->di_hdentry[i].hd_id = -1;
7719 + au_cache_free_dinfo(dinfo);
7726 +void au_di_free(struct au_dinfo *dinfo)
7728 + struct au_hdentry *p;
7729 + aufs_bindex_t bend, bindex;
7731 + /* dentry may not be revalidated */
7732 + bindex = dinfo->di_bstart;
7733 + if (bindex >= 0) {
7734 + bend = dinfo->di_bend;
7735 + p = dinfo->di_hdentry + bindex;
7736 + while (bindex++ <= bend)
7739 + kfree(dinfo->di_hdentry);
7740 + au_cache_free_dinfo(dinfo);
7743 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
7745 + struct au_hdentry *p;
7748 + AuRwMustWriteLock(&a->di_rwsem);
7749 + AuRwMustWriteLock(&b->di_rwsem);
7751 +#define DiSwap(v, name) \
7753 + v = a->di_##name; \
7754 + a->di_##name = b->di_##name; \
7755 + b->di_##name = v; \
7758 + DiSwap(p, hdentry);
7759 + DiSwap(bi, bstart);
7762 + DiSwap(bi, bdiropq);
7768 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
7770 + AuRwMustWriteLock(&dst->di_rwsem);
7771 + AuRwMustWriteLock(&src->di_rwsem);
7773 + dst->di_bstart = src->di_bstart;
7774 + dst->di_bend = src->di_bend;
7775 + dst->di_bwh = src->di_bwh;
7776 + dst->di_bdiropq = src->di_bdiropq;
7780 +int au_di_init(struct dentry *dentry)
7783 + struct super_block *sb;
7784 + struct au_dinfo *dinfo;
7787 + sb = dentry->d_sb;
7788 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
7790 + atomic_set(&dinfo->di_generation, au_sigen(sb));
7791 + /* smp_mb(); */ /* atomic_set */
7792 + dentry->d_fsdata = dinfo;
7799 +void au_di_fin(struct dentry *dentry)
7801 + struct au_dinfo *dinfo;
7803 + dinfo = au_di(dentry);
7804 + AuRwDestroy(&dinfo->di_rwsem);
7805 + au_di_free(dinfo);
7808 +int au_di_realloc(struct au_dinfo *dinfo, int nbr)
7811 + struct au_hdentry *hdp;
7813 + AuRwMustWriteLock(&dinfo->di_rwsem);
7816 + sz = sizeof(*hdp) * (dinfo->di_bend + 1);
7818 + sz = sizeof(*hdp);
7819 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS);
7821 + dinfo->di_hdentry = hdp;
7828 +/* ---------------------------------------------------------------------- */
7830 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
7833 + case AuLsc_DI_CHILD:
7834 + ii_write_lock_child(inode);
7836 + case AuLsc_DI_CHILD2:
7837 + ii_write_lock_child2(inode);
7839 + case AuLsc_DI_CHILD3:
7840 + ii_write_lock_child3(inode);
7842 + case AuLsc_DI_PARENT:
7843 + ii_write_lock_parent(inode);
7845 + case AuLsc_DI_PARENT2:
7846 + ii_write_lock_parent2(inode);
7848 + case AuLsc_DI_PARENT3:
7849 + ii_write_lock_parent3(inode);
7856 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
7859 + case AuLsc_DI_CHILD:
7860 + ii_read_lock_child(inode);
7862 + case AuLsc_DI_CHILD2:
7863 + ii_read_lock_child2(inode);
7865 + case AuLsc_DI_CHILD3:
7866 + ii_read_lock_child3(inode);
7868 + case AuLsc_DI_PARENT:
7869 + ii_read_lock_parent(inode);
7871 + case AuLsc_DI_PARENT2:
7872 + ii_read_lock_parent2(inode);
7874 + case AuLsc_DI_PARENT3:
7875 + ii_read_lock_parent3(inode);
7882 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
7884 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
7886 + if (au_ftest_lock(flags, IW))
7887 + do_ii_write_lock(d->d_inode, lsc);
7888 + else if (au_ftest_lock(flags, IR))
7889 + do_ii_read_lock(d->d_inode, lsc);
7893 +void di_read_unlock(struct dentry *d, int flags)
7896 + if (au_ftest_lock(flags, IW)) {
7897 + au_dbg_verify_dinode(d);
7898 + ii_write_unlock(d->d_inode);
7899 + } else if (au_ftest_lock(flags, IR)) {
7900 + au_dbg_verify_dinode(d);
7901 + ii_read_unlock(d->d_inode);
7904 + au_rw_read_unlock(&au_di(d)->di_rwsem);
7907 +void di_downgrade_lock(struct dentry *d, int flags)
7909 + if (d->d_inode && au_ftest_lock(flags, IR))
7910 + ii_downgrade_lock(d->d_inode);
7911 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
7914 +void di_write_lock(struct dentry *d, unsigned int lsc)
7916 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
7918 + do_ii_write_lock(d->d_inode, lsc);
7921 +void di_write_unlock(struct dentry *d)
7923 + au_dbg_verify_dinode(d);
7925 + ii_write_unlock(d->d_inode);
7926 + au_rw_write_unlock(&au_di(d)->di_rwsem);
7929 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
7931 + AuDebugOn(d1 == d2
7932 + || d1->d_inode == d2->d_inode
7933 + || d1->d_sb != d2->d_sb);
7935 + if (isdir && au_test_subdir(d1, d2)) {
7936 + di_write_lock_child(d1);
7937 + di_write_lock_child2(d2);
7939 + /* there should be no races */
7940 + di_write_lock_child(d2);
7941 + di_write_lock_child2(d1);
7945 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
7947 + AuDebugOn(d1 == d2
7948 + || d1->d_inode == d2->d_inode
7949 + || d1->d_sb != d2->d_sb);
7951 + if (isdir && au_test_subdir(d1, d2)) {
7952 + di_write_lock_parent(d1);
7953 + di_write_lock_parent2(d2);
7955 + /* there should be no races */
7956 + di_write_lock_parent(d2);
7957 + di_write_lock_parent2(d1);
7961 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
7963 + di_write_unlock(d1);
7964 + if (d1->d_inode == d2->d_inode)
7965 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
7967 + di_write_unlock(d2);
7970 +/* ---------------------------------------------------------------------- */
7972 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
7976 + DiMustAnyLock(dentry);
7978 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
7980 + AuDebugOn(bindex < 0);
7981 + d = au_di(dentry)->di_hdentry[0 + bindex].hd_dentry;
7982 + AuDebugOn(d && d->d_count <= 0);
7987 + * extended version of au_h_dptr().
7988 + * returns a hashed and positive h_dentry in bindex, NULL, or error.
7990 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
7992 + struct dentry *h_dentry;
7993 + struct inode *inode, *h_inode;
7995 + inode = dentry->d_inode;
7996 + AuDebugOn(!inode);
7999 + if (au_dbstart(dentry) <= bindex
8000 + && bindex <= au_dbend(dentry))
8001 + h_dentry = au_h_dptr(dentry, bindex);
8002 + if (h_dentry && !au_d_hashed_positive(h_dentry)) {
8004 + goto out; /* success */
8007 + AuDebugOn(bindex < au_ibstart(inode));
8008 + AuDebugOn(au_ibend(inode) < bindex);
8009 + h_inode = au_h_iptr(inode, bindex);
8010 + h_dentry = d_find_alias(h_inode);
8012 + if (!IS_ERR(h_dentry)) {
8013 + if (!au_d_hashed_positive(h_dentry))
8014 + goto out; /* success */
8020 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
8021 + h_dentry = au_plink_lkup(inode, bindex);
8022 + AuDebugOn(!h_dentry);
8023 + if (!IS_ERR(h_dentry)) {
8024 + if (!au_d_hashed_positive(h_dentry))
8025 + goto out; /* success */
8032 + AuDbgDentry(h_dentry);
8036 +aufs_bindex_t au_dbtail(struct dentry *dentry)
8038 + aufs_bindex_t bend, bwh;
8040 + bend = au_dbend(dentry);
8042 + bwh = au_dbwh(dentry);
8045 + if (0 < bwh && bwh < bend)
8051 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
8053 + aufs_bindex_t bend, bopq;
8055 + bend = au_dbtail(dentry);
8057 + bopq = au_dbdiropq(dentry);
8058 + if (0 <= bopq && bopq < bend)
8064 +/* ---------------------------------------------------------------------- */
8066 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
8067 + struct dentry *h_dentry)
8069 + struct au_hdentry *hd = au_di(dentry)->di_hdentry + bindex;
8070 + struct au_branch *br;
8072 + DiMustWriteLock(dentry);
8075 + hd->hd_dentry = h_dentry;
8077 + br = au_sbr(dentry->d_sb, bindex);
8078 + hd->hd_id = br->br_id;
8082 +int au_dbrange_test(struct dentry *dentry)
8085 + aufs_bindex_t bstart, bend;
8088 + bstart = au_dbstart(dentry);
8089 + bend = au_dbend(dentry);
8091 + AuDebugOn(bend < 0 && bstart > bend);
8094 + AuDebugOn(bend >= 0);
8100 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
8105 + if (unlikely(au_digen(dentry) != sigen
8106 + || au_iigen_test(dentry->d_inode, sigen)))
8112 +void au_update_digen(struct dentry *dentry)
8114 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
8115 + /* smp_mb(); */ /* atomic_set */
8118 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
8120 + struct au_dinfo *dinfo;
8121 + struct dentry *h_d;
8122 + struct au_hdentry *hdp;
8124 + DiMustWriteLock(dentry);
8126 + dinfo = au_di(dentry);
8127 + if (!dinfo || dinfo->di_bstart < 0)
8130 + hdp = dinfo->di_hdentry;
8131 + if (do_put_zero) {
8132 + aufs_bindex_t bindex, bend;
8134 + bend = dinfo->di_bend;
8135 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++) {
8136 + h_d = hdp[0 + bindex].hd_dentry;
8137 + if (h_d && !h_d->d_inode)
8138 + au_set_h_dptr(dentry, bindex, NULL);
8142 + dinfo->di_bstart = -1;
8143 + while (++dinfo->di_bstart <= dinfo->di_bend)
8144 + if (hdp[0 + dinfo->di_bstart].hd_dentry)
8146 + if (dinfo->di_bstart > dinfo->di_bend) {
8147 + dinfo->di_bstart = -1;
8148 + dinfo->di_bend = -1;
8153 + while (0 <= --dinfo->di_bend)
8154 + if (hdp[0 + dinfo->di_bend].hd_dentry)
8156 + AuDebugOn(dinfo->di_bstart > dinfo->di_bend || dinfo->di_bend < 0);
8159 +void au_update_dbstart(struct dentry *dentry)
8161 + aufs_bindex_t bindex, bend;
8162 + struct dentry *h_dentry;
8164 + bend = au_dbend(dentry);
8165 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
8166 + h_dentry = au_h_dptr(dentry, bindex);
8169 + if (h_dentry->d_inode) {
8170 + au_set_dbstart(dentry, bindex);
8173 + au_set_h_dptr(dentry, bindex, NULL);
8177 +void au_update_dbend(struct dentry *dentry)
8179 + aufs_bindex_t bindex, bstart;
8180 + struct dentry *h_dentry;
8182 + bstart = au_dbstart(dentry);
8183 + for (bindex = au_dbend(dentry); bindex >= bstart; bindex--) {
8184 + h_dentry = au_h_dptr(dentry, bindex);
8187 + if (h_dentry->d_inode) {
8188 + au_set_dbend(dentry, bindex);
8191 + au_set_h_dptr(dentry, bindex, NULL);
8195 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
8197 + aufs_bindex_t bindex, bend;
8199 + bend = au_dbend(dentry);
8200 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++)
8201 + if (au_h_dptr(dentry, bindex) == h_dentry)
8205 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
8206 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
8207 +++ linux/fs/aufs/dir.c 2013-07-30 22:42:55.839613269 +0200
8210 + * Copyright (C) 2005-2013 Junjiro R. Okajima
8212 + * This program, aufs is free software; you can redistribute it and/or modify
8213 + * it under the terms of the GNU General Public License as published by
8214 + * the Free Software Foundation; either version 2 of the License, or
8215 + * (at your option) any later version.
8217 + * This program is distributed in the hope that it will be useful,
8218 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8219 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8220 + * GNU General Public License for more details.
8222 + * You should have received a copy of the GNU General Public License
8223 + * along with this program; if not, write to the Free Software
8224 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
8228 + * directory operations
8231 +#include <linux/fs_stack.h>
8234 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
8236 + unsigned int nlink;
8238 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
8240 + nlink = dir->i_nlink;
8241 + nlink += h_dir->i_nlink - 2;
8242 + if (h_dir->i_nlink < 2)
8245 + /* 0 can happen in revaliding */
8246 + set_nlink(dir, nlink);
8249 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
8251 + unsigned int nlink;
8253 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
8255 + nlink = dir->i_nlink;
8256 + nlink -= h_dir->i_nlink - 2;
8257 + if (h_dir->i_nlink < 2)
8260 + /* nlink == 0 means the branch-fs is broken */
8261 + set_nlink(dir, nlink);
8264 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
8267 + aufs_bindex_t bindex, bend;
8268 + struct file *h_file;
8269 + struct dentry *h_dentry;
8273 + AuDebugOn(!file_inode(file));
8274 + AuDebugOn(!S_ISDIR(file_inode(file)->i_mode));
8276 + bend = au_fbend_dir(file);
8277 + for (bindex = au_fbstart(file);
8278 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
8280 + h_file = au_hf_dir(file, bindex);
8281 + if (h_file && file_inode(h_file))
8282 + sz += vfsub_f_size_read(h_file);
8285 + AuDebugOn(!dentry);
8286 + AuDebugOn(!dentry->d_inode);
8287 + AuDebugOn(!S_ISDIR(dentry->d_inode->i_mode));
8289 + bend = au_dbtaildir(dentry);
8290 + for (bindex = au_dbstart(dentry);
8291 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
8293 + h_dentry = au_h_dptr(dentry, bindex);
8294 + if (h_dentry && h_dentry->d_inode)
8295 + sz += i_size_read(h_dentry->d_inode);
8298 + if (sz < KMALLOC_MAX_SIZE)
8299 + sz = roundup_pow_of_two(sz);
8300 + if (sz > KMALLOC_MAX_SIZE)
8301 + sz = KMALLOC_MAX_SIZE;
8302 + else if (sz < NAME_MAX) {
8303 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
8304 + sz = AUFS_RDBLK_DEF;
8309 +/* ---------------------------------------------------------------------- */
8311 +static int reopen_dir(struct file *file)
8314 + unsigned int flags;
8315 + aufs_bindex_t bindex, btail, bstart;
8316 + struct dentry *dentry, *h_dentry;
8317 + struct file *h_file;
8319 + /* open all lower dirs */
8320 + dentry = file->f_dentry;
8321 + bstart = au_dbstart(dentry);
8322 + for (bindex = au_fbstart(file); bindex < bstart; bindex++)
8323 + au_set_h_fptr(file, bindex, NULL);
8324 + au_set_fbstart(file, bstart);
8326 + btail = au_dbtaildir(dentry);
8327 + for (bindex = au_fbend_dir(file); btail < bindex; bindex--)
8328 + au_set_h_fptr(file, bindex, NULL);
8329 + au_set_fbend_dir(file, btail);
8331 + flags = vfsub_file_flags(file);
8332 + for (bindex = bstart; bindex <= btail; bindex++) {
8333 + h_dentry = au_h_dptr(dentry, bindex);
8336 + h_file = au_hf_dir(file, bindex);
8340 + h_file = au_h_open(dentry, bindex, flags, file);
8341 + err = PTR_ERR(h_file);
8342 + if (IS_ERR(h_file))
8343 + goto out; /* close all? */
8344 + au_set_h_fptr(file, bindex, h_file);
8346 + au_update_figen(file);
8347 + /* todo: necessary? */
8348 + /* file->f_ra = h_file->f_ra; */
8355 +static int do_open_dir(struct file *file, int flags)
8358 + aufs_bindex_t bindex, btail;
8359 + struct dentry *dentry, *h_dentry;
8360 + struct file *h_file;
8362 + FiMustWriteLock(file);
8364 + dentry = file->f_dentry;
8365 + err = au_alive_dir(dentry);
8366 + if (unlikely(err))
8369 + file->f_version = dentry->d_inode->i_version;
8370 + bindex = au_dbstart(dentry);
8371 + au_set_fbstart(file, bindex);
8372 + btail = au_dbtaildir(dentry);
8373 + au_set_fbend_dir(file, btail);
8374 + for (; !err && bindex <= btail; bindex++) {
8375 + h_dentry = au_h_dptr(dentry, bindex);
8379 + h_file = au_h_open(dentry, bindex, flags, file);
8380 + if (IS_ERR(h_file)) {
8381 + err = PTR_ERR(h_file);
8384 + au_set_h_fptr(file, bindex, h_file);
8386 + au_update_figen(file);
8387 + /* todo: necessary? */
8388 + /* file->f_ra = h_file->f_ra; */
8390 + return 0; /* success */
8393 + for (bindex = au_fbstart(file); bindex <= btail; bindex++)
8394 + au_set_h_fptr(file, bindex, NULL);
8395 + au_set_fbstart(file, -1);
8396 + au_set_fbend_dir(file, -1);
8402 +static int aufs_open_dir(struct inode *inode __maybe_unused,
8403 + struct file *file)
8406 + struct super_block *sb;
8407 + struct au_fidir *fidir;
8410 + sb = file->f_dentry->d_sb;
8411 + si_read_lock(sb, AuLock_FLUSH);
8412 + fidir = au_fidir_alloc(sb);
8414 + err = au_do_open(file, do_open_dir, fidir);
8415 + if (unlikely(err))
8418 + si_read_unlock(sb);
8422 +static int aufs_release_dir(struct inode *inode __maybe_unused,
8423 + struct file *file)
8425 + struct au_vdir *vdir_cache;
8426 + struct au_finfo *finfo;
8427 + struct au_fidir *fidir;
8428 + aufs_bindex_t bindex, bend;
8430 + finfo = au_fi(file);
8431 + fidir = finfo->fi_hdir;
8433 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
8435 + au_vdir_free(vdir_cache);
8437 + bindex = finfo->fi_btop;
8438 + if (bindex >= 0) {
8440 + * calls fput() instead of filp_close(),
8441 + * since no dnotify or lock for the lower file.
8443 + bend = fidir->fd_bbot;
8444 + for (; bindex <= bend; bindex++)
8445 + au_set_h_fptr(file, bindex, NULL);
8448 + finfo->fi_hdir = NULL;
8450 + au_finfo_fin(file);
8454 +/* ---------------------------------------------------------------------- */
8456 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
8459 + aufs_bindex_t bindex, bend;
8460 + struct file *h_file;
8463 + bend = au_fbend_dir(file);
8464 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
8465 + h_file = au_hf_dir(file, bindex);
8467 + err = vfsub_flush(h_file, id);
8472 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
8474 + return au_do_flush(file, id, au_do_flush_dir);
8477 +/* ---------------------------------------------------------------------- */
8479 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
8482 + aufs_bindex_t bend, bindex;
8483 + struct inode *inode;
8484 + struct super_block *sb;
8487 + sb = dentry->d_sb;
8488 + inode = dentry->d_inode;
8490 + bend = au_dbend(dentry);
8491 + for (bindex = au_dbstart(dentry); !err && bindex <= bend; bindex++) {
8492 + struct path h_path;
8494 + if (au_test_ro(sb, bindex, inode))
8496 + h_path.dentry = au_h_dptr(dentry, bindex);
8497 + if (!h_path.dentry)
8500 + h_path.mnt = au_sbr_mnt(sb, bindex);
8501 + err = vfsub_fsync(NULL, &h_path, datasync);
8507 +static int au_do_fsync_dir(struct file *file, int datasync)
8510 + aufs_bindex_t bend, bindex;
8511 + struct file *h_file;
8512 + struct super_block *sb;
8513 + struct inode *inode;
8515 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
8516 + if (unlikely(err))
8519 + sb = file->f_dentry->d_sb;
8520 + inode = file_inode(file);
8521 + bend = au_fbend_dir(file);
8522 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
8523 + h_file = au_hf_dir(file, bindex);
8524 + if (!h_file || au_test_ro(sb, bindex, inode))
8527 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
8535 + * @file may be NULL
8537 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
8541 + struct dentry *dentry;
8542 + struct super_block *sb;
8543 + struct mutex *mtx;
8546 + dentry = file->f_dentry;
8547 + mtx = &dentry->d_inode->i_mutex;
8549 + sb = dentry->d_sb;
8550 + si_noflush_read_lock(sb);
8552 + err = au_do_fsync_dir(file, datasync);
8554 + di_write_lock_child(dentry);
8555 + err = au_do_fsync_dir_no_file(dentry, datasync);
8557 + au_cpup_attr_timesizes(dentry->d_inode);
8558 + di_write_unlock(dentry);
8560 + fi_write_unlock(file);
8562 + si_read_unlock(sb);
8563 + mutex_unlock(mtx);
8567 +/* ---------------------------------------------------------------------- */
8569 +static int aufs_readdir(struct file *file, void *dirent, filldir_t filldir)
8572 + struct dentry *dentry;
8573 + struct inode *inode, *h_inode;
8574 + struct super_block *sb;
8576 + dentry = file->f_dentry;
8577 + inode = dentry->d_inode;
8580 + sb = dentry->d_sb;
8581 + si_read_lock(sb, AuLock_FLUSH);
8582 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
8583 + if (unlikely(err))
8585 + err = au_alive_dir(dentry);
8587 + err = au_vdir_init(file);
8588 + di_downgrade_lock(dentry, AuLock_IR);
8589 + if (unlikely(err))
8592 + h_inode = au_h_iptr(inode, au_ibstart(inode));
8593 + if (!au_test_nfsd()) {
8594 + err = au_vdir_fill_de(file, dirent, filldir);
8595 + fsstack_copy_attr_atime(inode, h_inode);
8598 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
8599 + * encode_fh() and others.
8601 + atomic_inc(&h_inode->i_count);
8602 + di_read_unlock(dentry, AuLock_IR);
8603 + si_read_unlock(sb);
8604 + err = au_vdir_fill_de(file, dirent, filldir);
8605 + fsstack_copy_attr_atime(inode, h_inode);
8606 + fi_write_unlock(file);
8614 + di_read_unlock(dentry, AuLock_IR);
8615 + fi_write_unlock(file);
8617 + si_read_unlock(sb);
8621 +/* ---------------------------------------------------------------------- */
8623 +#define AuTestEmpty_WHONLY 1
8624 +#define AuTestEmpty_CALLED (1 << 1)
8625 +#define AuTestEmpty_SHWH (1 << 2)
8626 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
8627 +#define au_fset_testempty(flags, name) \
8628 + do { (flags) |= AuTestEmpty_##name; } while (0)
8629 +#define au_fclr_testempty(flags, name) \
8630 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
8632 +#ifndef CONFIG_AUFS_SHWH
8633 +#undef AuTestEmpty_SHWH
8634 +#define AuTestEmpty_SHWH 0
8637 +struct test_empty_arg {
8638 + struct au_nhash *whlist;
8639 + unsigned int flags;
8641 + aufs_bindex_t bindex;
8644 +static int test_empty_cb(void *__arg, const char *__name, int namelen,
8645 + loff_t offset __maybe_unused, u64 ino,
8646 + unsigned int d_type)
8648 + struct test_empty_arg *arg = __arg;
8649 + char *name = (void *)__name;
8652 + au_fset_testempty(arg->flags, CALLED);
8654 + if (name[0] == '.'
8655 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
8656 + goto out; /* success */
8658 + if (namelen <= AUFS_WH_PFX_LEN
8659 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
8660 + if (au_ftest_testempty(arg->flags, WHONLY)
8661 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
8662 + arg->err = -ENOTEMPTY;
8666 + name += AUFS_WH_PFX_LEN;
8667 + namelen -= AUFS_WH_PFX_LEN;
8668 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
8669 + arg->err = au_nhash_append_wh
8670 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
8671 + au_ftest_testempty(arg->flags, SHWH));
8675 + AuTraceErr(arg->err);
8679 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
8682 + struct file *h_file;
8684 + h_file = au_h_open(dentry, arg->bindex,
8685 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
8687 + err = PTR_ERR(h_file);
8688 + if (IS_ERR(h_file))
8692 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
8693 + && !file_inode(h_file)->i_nlink)
8698 + au_fclr_testempty(arg->flags, CALLED);
8700 + err = vfsub_readdir(h_file, test_empty_cb, arg);
8703 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
8707 + au_sbr_put(dentry->d_sb, arg->bindex);
8712 +struct do_test_empty_args {
8714 + struct dentry *dentry;
8715 + struct test_empty_arg *arg;
8718 +static void call_do_test_empty(void *args)
8720 + struct do_test_empty_args *a = args;
8721 + *a->errp = do_test_empty(a->dentry, a->arg);
8724 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
8727 + struct dentry *h_dentry;
8728 + struct inode *h_inode;
8730 + h_dentry = au_h_dptr(dentry, arg->bindex);
8731 + h_inode = h_dentry->d_inode;
8732 + /* todo: i_mode changes anytime? */
8733 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
8734 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
8735 + mutex_unlock(&h_inode->i_mutex);
8737 + err = do_test_empty(dentry, arg);
8739 + struct do_test_empty_args args = {
8744 + unsigned int flags = arg->flags;
8746 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
8747 + if (unlikely(wkq_err))
8749 + arg->flags = flags;
8755 +int au_test_empty_lower(struct dentry *dentry)
8758 + unsigned int rdhash;
8759 + aufs_bindex_t bindex, bstart, btail;
8760 + struct au_nhash whlist;
8761 + struct test_empty_arg arg;
8763 + SiMustAnyLock(dentry->d_sb);
8765 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
8767 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
8768 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
8769 + if (unlikely(err))
8773 + arg.whlist = &whlist;
8774 + bstart = au_dbstart(dentry);
8775 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
8776 + au_fset_testempty(arg.flags, SHWH);
8777 + arg.bindex = bstart;
8778 + err = do_test_empty(dentry, &arg);
8779 + if (unlikely(err))
8782 + au_fset_testempty(arg.flags, WHONLY);
8783 + btail = au_dbtaildir(dentry);
8784 + for (bindex = bstart + 1; !err && bindex <= btail; bindex++) {
8785 + struct dentry *h_dentry;
8787 + h_dentry = au_h_dptr(dentry, bindex);
8788 + if (h_dentry && h_dentry->d_inode) {
8789 + arg.bindex = bindex;
8790 + err = do_test_empty(dentry, &arg);
8795 + au_nhash_wh_free(&whlist);
8800 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
8803 + struct test_empty_arg arg;
8804 + aufs_bindex_t bindex, btail;
8807 + arg.whlist = whlist;
8808 + arg.flags = AuTestEmpty_WHONLY;
8809 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
8810 + au_fset_testempty(arg.flags, SHWH);
8811 + btail = au_dbtaildir(dentry);
8812 + for (bindex = au_dbstart(dentry); !err && bindex <= btail; bindex++) {
8813 + struct dentry *h_dentry;
8815 + h_dentry = au_h_dptr(dentry, bindex);
8816 + if (h_dentry && h_dentry->d_inode) {
8817 + arg.bindex = bindex;
8818 + err = sio_test_empty(dentry, &arg);
8825 +/* ---------------------------------------------------------------------- */
8827 +const struct file_operations aufs_dir_fop = {
8828 + .owner = THIS_MODULE,
8829 + .llseek = default_llseek,
8830 + .read = generic_read_dir,
8831 + .readdir = aufs_readdir,
8832 + .unlocked_ioctl = aufs_ioctl_dir,
8833 +#ifdef CONFIG_COMPAT
8834 + .compat_ioctl = aufs_compat_ioctl_dir,
8836 + .open = aufs_open_dir,
8837 + .release = aufs_release_dir,
8838 + .flush = aufs_flush_dir,
8839 + .fsync = aufs_fsync_dir
8841 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
8842 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
8843 +++ linux/fs/aufs/dir.h 2013-07-30 22:42:55.839613269 +0200
8846 + * Copyright (C) 2005-2013 Junjiro R. Okajima
8848 + * This program, aufs is free software; you can redistribute it and/or modify
8849 + * it under the terms of the GNU General Public License as published by
8850 + * the Free Software Foundation; either version 2 of the License, or
8851 + * (at your option) any later version.
8853 + * This program is distributed in the hope that it will be useful,
8854 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8855 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8856 + * GNU General Public License for more details.
8858 + * You should have received a copy of the GNU General Public License
8859 + * along with this program; if not, write to the Free Software
8860 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
8864 + * directory operations
8867 +#ifndef __AUFS_DIR_H__
8868 +#define __AUFS_DIR_H__
8872 +#include <linux/fs.h>
8874 +/* ---------------------------------------------------------------------- */
8876 +/* need to be faster and smaller */
8879 + unsigned int nh_num;
8880 + struct hlist_head *nh_head;
8883 +struct au_vdir_destr {
8884 + unsigned char len;
8885 + unsigned char name[0];
8888 +struct au_vdir_dehstr {
8889 + struct hlist_node hash;
8890 + struct au_vdir_destr *str;
8891 +} ____cacheline_aligned_in_smp;
8893 +struct au_vdir_de {
8895 + unsigned char de_type;
8896 + /* caution: packed */
8897 + struct au_vdir_destr de_str;
8900 +struct au_vdir_wh {
8901 + struct hlist_node wh_hash;
8902 +#ifdef CONFIG_AUFS_SHWH
8904 + aufs_bindex_t wh_bindex;
8905 + unsigned char wh_type;
8907 + aufs_bindex_t wh_bindex;
8909 + /* caution: packed */
8910 + struct au_vdir_destr wh_str;
8913 +union au_vdir_deblk_p {
8914 + unsigned char *deblk;
8915 + struct au_vdir_de *de;
8919 + unsigned char **vd_deblk;
8920 + unsigned long vd_nblk;
8923 + union au_vdir_deblk_p p;
8926 + unsigned long vd_version;
8927 + unsigned int vd_deblk_sz;
8928 + unsigned long vd_jiffy;
8929 +} ____cacheline_aligned_in_smp;
8931 +/* ---------------------------------------------------------------------- */
8934 +extern const struct file_operations aufs_dir_fop;
8935 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
8936 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
8937 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
8938 +int au_test_empty_lower(struct dentry *dentry);
8939 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
8942 +unsigned int au_rdhash_est(loff_t sz);
8943 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
8944 +void au_nhash_wh_free(struct au_nhash *whlist);
8945 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
8947 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
8948 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
8949 + unsigned int d_type, aufs_bindex_t bindex,
8950 + unsigned char shwh);
8951 +void au_vdir_free(struct au_vdir *vdir);
8952 +int au_vdir_init(struct file *file);
8953 +int au_vdir_fill_de(struct file *file, void *dirent, filldir_t filldir);
8956 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
8958 +#ifdef CONFIG_AUFS_RDU
8960 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
8961 +#ifdef CONFIG_COMPAT
8962 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
8963 + unsigned long arg);
8966 +static inline long au_rdu_ioctl(struct file *file, unsigned int cmd,
8967 + unsigned long arg)
8971 +#ifdef CONFIG_COMPAT
8972 +static inline long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
8973 + unsigned long arg)
8980 +#endif /* __KERNEL__ */
8981 +#endif /* __AUFS_DIR_H__ */
8982 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
8983 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
8984 +++ linux/fs/aufs/dynop.c 2013-07-30 22:42:55.839613269 +0200
8987 + * Copyright (C) 2010-2013 Junjiro R. Okajima
8989 + * This program, aufs is free software; you can redistribute it and/or modify
8990 + * it under the terms of the GNU General Public License as published by
8991 + * the Free Software Foundation; either version 2 of the License, or
8992 + * (at your option) any later version.
8994 + * This program is distributed in the hope that it will be useful,
8995 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8996 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8997 + * GNU General Public License for more details.
8999 + * You should have received a copy of the GNU General Public License
9000 + * along with this program; if not, write to the Free Software
9001 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
9005 + * dynamically customizable operations for regular files
9010 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
9013 + * How large will these lists be?
9014 + * Usually just a few elements, 20-30 at most for each, I guess.
9016 +static struct au_splhead dynop[AuDyLast];
9018 +static struct au_dykey *dy_gfind_get(struct au_splhead *spl, const void *h_op)
9020 + struct au_dykey *key, *tmp;
9021 + struct list_head *head;
9024 + head = &spl->head;
9026 + list_for_each_entry_rcu(tmp, head, dk_list)
9027 + if (tmp->dk_op.dy_hop == h_op) {
9029 + kref_get(&key->dk_kref);
9032 + rcu_read_unlock();
9037 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
9039 + struct au_dykey **k, *found;
9040 + const void *h_op = key->dk_op.dy_hop;
9045 + for (i = 0; i < AuBrDynOp; i++)
9047 + if (k[i]->dk_op.dy_hop == h_op) {
9054 + spin_lock(&br->br_dykey_lock);
9055 + for (; i < AuBrDynOp; i++)
9057 + if (k[i]->dk_op.dy_hop == h_op) {
9065 + spin_unlock(&br->br_dykey_lock);
9066 + BUG_ON(i == AuBrDynOp); /* expand the array */
9072 +/* kref_get() if @key is already added */
9073 +static struct au_dykey *dy_gadd(struct au_splhead *spl, struct au_dykey *key)
9075 + struct au_dykey *tmp, *found;
9076 + struct list_head *head;
9077 + const void *h_op = key->dk_op.dy_hop;
9080 + head = &spl->head;
9081 + spin_lock(&spl->spin);
9082 + list_for_each_entry(tmp, head, dk_list)
9083 + if (tmp->dk_op.dy_hop == h_op) {
9084 + kref_get(&tmp->dk_kref);
9089 + list_add_rcu(&key->dk_list, head);
9090 + spin_unlock(&spl->spin);
9097 +static void dy_free_rcu(struct rcu_head *rcu)
9099 + struct au_dykey *key;
9101 + key = container_of(rcu, struct au_dykey, dk_rcu);
9106 +static void dy_free(struct kref *kref)
9108 + struct au_dykey *key;
9109 + struct au_splhead *spl;
9111 + key = container_of(kref, struct au_dykey, dk_kref);
9112 + spl = dynop + key->dk_op.dy_type;
9113 + au_spl_del_rcu(&key->dk_list, spl);
9114 + call_rcu(&key->dk_rcu, dy_free_rcu);
9117 +void au_dy_put(struct au_dykey *key)
9119 + kref_put(&key->dk_kref, dy_free);
9122 +/* ---------------------------------------------------------------------- */
9124 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
9126 +#ifdef CONFIG_AUFS_DEBUG
9127 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
9128 +#define DyDbgInc(cnt) do { cnt++; } while (0)
9130 +#define DyDbgDeclare(cnt) do {} while (0)
9131 +#define DyDbgInc(cnt) do {} while (0)
9134 +#define DySet(func, dst, src, h_op, h_sb) do { \
9136 + if (h_op->func) { \
9138 + dst.func = src.func; \
9140 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
9144 +#define DySetForce(func, dst, src) do { \
9145 + AuDebugOn(!src.func); \
9147 + dst.func = src.func; \
9150 +#define DySetAop(func) \
9151 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
9152 +#define DySetAopForce(func) \
9153 + DySetForce(func, dyaop->da_op, aufs_aop)
9155 +static void dy_aop(struct au_dykey *key, const void *h_op,
9156 + struct super_block *h_sb __maybe_unused)
9158 + struct au_dyaop *dyaop = (void *)key;
9159 + const struct address_space_operations *h_aop = h_op;
9160 + DyDbgDeclare(cnt);
9162 + AuDbg("%s\n", au_sbtype(h_sb));
9164 + DySetAop(writepage);
9165 + DySetAopForce(readpage); /* force */
9166 + DySetAop(writepages);
9167 + DySetAop(set_page_dirty);
9168 + DySetAop(readpages);
9169 + DySetAop(write_begin);
9170 + DySetAop(write_end);
9172 + DySetAop(invalidatepage);
9173 + DySetAop(releasepage);
9174 + DySetAop(freepage);
9175 + /* these two will be changed according to an aufs mount option */
9176 + DySetAop(direct_IO);
9177 + DySetAop(get_xip_mem);
9178 + DySetAop(migratepage);
9179 + DySetAop(launder_page);
9180 + DySetAop(is_partially_uptodate);
9181 + DySetAop(error_remove_page);
9182 + DySetAop(swap_activate);
9183 + DySetAop(swap_deactivate);
9185 + DyDbgSize(cnt, *h_aop);
9186 + dyaop->da_get_xip_mem = h_aop->get_xip_mem;
9189 +/* ---------------------------------------------------------------------- */
9191 +static void dy_bug(struct kref *kref)
9196 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
9198 + struct au_dykey *key, *old;
9199 + struct au_splhead *spl;
9202 + void (*set)(struct au_dykey *key, const void *h_op,
9203 + struct super_block *h_sb __maybe_unused);
9205 + static const struct op a[] = {
9207 + .sz = sizeof(struct au_dyaop),
9211 + const struct op *p;
9213 + spl = dynop + op->dy_type;
9214 + key = dy_gfind_get(spl, op->dy_hop);
9216 + goto out_add; /* success */
9218 + p = a + op->dy_type;
9219 + key = kzalloc(p->sz, GFP_NOFS);
9220 + if (unlikely(!key)) {
9221 + key = ERR_PTR(-ENOMEM);
9225 + key->dk_op.dy_hop = op->dy_hop;
9226 + kref_init(&key->dk_kref);
9227 + p->set(key, op->dy_hop, au_br_sb(br));
9228 + old = dy_gadd(spl, key);
9235 + old = dy_bradd(br, key);
9237 + /* its ref-count should never be zero here */
9238 + kref_put(&key->dk_kref, dy_bug);
9243 +/* ---------------------------------------------------------------------- */
9245 + * Aufs prohibits O_DIRECT by defaut even if the branch supports it.
9246 + * This behaviour is neccessary to return an error from open(O_DIRECT) instead
9247 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
9248 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
9249 + * See the aufs manual in detail.
9251 + * To keep this behaviour, aufs has to set NULL to ->get_xip_mem too, and the
9252 + * performance of fadvise() and madvise() may be affected.
9254 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
9257 + dyaop->da_op.direct_IO = NULL;
9258 + dyaop->da_op.get_xip_mem = NULL;
9260 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
9261 + dyaop->da_op.get_xip_mem = aufs_aop.get_xip_mem;
9262 + if (!dyaop->da_get_xip_mem)
9263 + dyaop->da_op.get_xip_mem = NULL;
9267 +static struct au_dyaop *dy_aget(struct au_branch *br,
9268 + const struct address_space_operations *h_aop,
9271 + struct au_dyaop *dyaop;
9272 + struct au_dynop op;
9274 + op.dy_type = AuDy_AOP;
9275 + op.dy_haop = h_aop;
9276 + dyaop = (void *)dy_get(&op, br);
9277 + if (IS_ERR(dyaop))
9279 + dy_adx(dyaop, do_dx);
9285 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
9286 + struct inode *h_inode)
9289 + struct super_block *sb;
9290 + struct au_branch *br;
9291 + struct au_dyaop *dyaop;
9293 + AuDebugOn(!S_ISREG(h_inode->i_mode));
9294 + IiMustWriteLock(inode);
9297 + br = au_sbr(sb, bindex);
9298 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
9299 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
9300 + err = PTR_ERR(dyaop);
9301 + if (IS_ERR(dyaop))
9302 + /* unnecessary to call dy_fput() */
9306 + inode->i_mapping->a_ops = &dyaop->da_op;
9313 + * Is it safe to replace a_ops during the inode/file is in operation?
9316 +int au_dy_irefresh(struct inode *inode)
9319 + aufs_bindex_t bstart;
9320 + struct inode *h_inode;
9323 + if (S_ISREG(inode->i_mode)) {
9324 + bstart = au_ibstart(inode);
9325 + h_inode = au_h_iptr(inode, bstart);
9326 + err = au_dy_iaop(inode, bstart, h_inode);
9331 +void au_dy_arefresh(int do_dx)
9333 + struct au_splhead *spl;
9334 + struct list_head *head;
9335 + struct au_dykey *key;
9337 + spl = dynop + AuDy_AOP;
9338 + head = &spl->head;
9339 + spin_lock(&spl->spin);
9340 + list_for_each_entry(key, head, dk_list)
9341 + dy_adx((void *)key, do_dx);
9342 + spin_unlock(&spl->spin);
9345 +/* ---------------------------------------------------------------------- */
9347 +void __init au_dy_init(void)
9351 + /* make sure that 'struct au_dykey *' can be any type */
9352 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
9354 + for (i = 0; i < AuDyLast; i++)
9355 + au_spl_init(dynop + i);
9358 +void au_dy_fin(void)
9362 + for (i = 0; i < AuDyLast; i++)
9363 + WARN_ON(!list_empty(&dynop[i].head));
9365 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
9366 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
9367 +++ linux/fs/aufs/dynop.h 2013-07-06 13:20:47.740198107 +0200
9370 + * Copyright (C) 2010-2013 Junjiro R. Okajima
9372 + * This program, aufs is free software; you can redistribute it and/or modify
9373 + * it under the terms of the GNU General Public License as published by
9374 + * the Free Software Foundation; either version 2 of the License, or
9375 + * (at your option) any later version.
9377 + * This program is distributed in the hope that it will be useful,
9378 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9379 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9380 + * GNU General Public License for more details.
9382 + * You should have received a copy of the GNU General Public License
9383 + * along with this program; if not, write to the Free Software
9384 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
9388 + * dynamically customizable operations (for regular files only)
9391 +#ifndef __AUFS_DYNOP_H__
9392 +#define __AUFS_DYNOP_H__
9398 +enum {AuDy_AOP, AuDyLast};
9403 + const void *dy_hop;
9404 + const struct address_space_operations *dy_haop;
9410 + struct list_head dk_list;
9411 + struct rcu_head dk_rcu;
9413 + struct au_dynop dk_op;
9416 + * during I am in the branch local array, kref is gotten. when the
9417 + * branch is removed, kref is put.
9419 + struct kref dk_kref;
9422 +/* stop unioning since their sizes are very different from each other */
9424 + struct au_dykey da_key;
9425 + struct address_space_operations da_op; /* not const */
9426 + int (*da_get_xip_mem)(struct address_space *, pgoff_t, int,
9427 + void **, unsigned long *);
9430 +/* ---------------------------------------------------------------------- */
9434 +void au_dy_put(struct au_dykey *key);
9435 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
9436 + struct inode *h_inode);
9437 +int au_dy_irefresh(struct inode *inode);
9438 +void au_dy_arefresh(int do_dio);
9440 +void __init au_dy_init(void);
9441 +void au_dy_fin(void);
9443 +#endif /* __KERNEL__ */
9444 +#endif /* __AUFS_DYNOP_H__ */
9445 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
9446 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
9447 +++ linux/fs/aufs/export.c 2013-07-30 22:42:55.839613269 +0200
9450 + * Copyright (C) 2005-2013 Junjiro R. Okajima
9452 + * This program, aufs is free software; you can redistribute it and/or modify
9453 + * it under the terms of the GNU General Public License as published by
9454 + * the Free Software Foundation; either version 2 of the License, or
9455 + * (at your option) any later version.
9457 + * This program is distributed in the hope that it will be useful,
9458 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9459 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9460 + * GNU General Public License for more details.
9462 + * You should have received a copy of the GNU General Public License
9463 + * along with this program; if not, write to the Free Software
9464 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
9471 +#include <linux/exportfs.h>
9472 +#include <linux/fs_struct.h>
9473 +#include <linux/namei.h>
9474 +#include <linux/nsproxy.h>
9475 +#include <linux/random.h>
9476 +#include <linux/writeback.h>
9477 +#include "../fs/mount.h"
9481 +#ifdef CONFIG_AUFS_INO_T_64
9489 +static ino_t decode_ino(__u32 *a)
9493 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
9495 +#ifdef CONFIG_AUFS_INO_T_64
9501 +static void encode_ino(__u32 *a, ino_t ino)
9507 +#ifdef CONFIG_AUFS_INO_T_64
9512 +/* NFS file handle */
9516 +#ifdef CONFIG_AUFS_INO_T_64
9517 + /* support 64bit inode number */
9531 + Fh_dir_ino = Fh_dir_ino1
9534 +static int au_test_anon(struct dentry *dentry)
9536 + /* note: read d_flags without d_lock */
9537 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
9540 +int au_test_nfsd(void)
9543 + struct task_struct *tsk = current;
9544 + char comm[sizeof(tsk->comm)];
9547 + if (tsk->flags & PF_KTHREAD) {
9548 + get_task_comm(comm, tsk);
9549 + ret = !strcmp(comm, "nfsd");
9555 +/* ---------------------------------------------------------------------- */
9556 +/* inode generation external table */
9558 +void au_xigen_inc(struct inode *inode)
9563 + struct super_block *sb;
9564 + struct au_sbinfo *sbinfo;
9567 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
9569 + sbinfo = au_sbi(sb);
9570 + pos = inode->i_ino;
9571 + pos *= sizeof(igen);
9572 + igen = inode->i_generation + 1;
9573 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
9574 + sizeof(igen), &pos);
9575 + if (sz == sizeof(igen))
9576 + return; /* success */
9578 + if (unlikely(sz >= 0))
9579 + AuIOErr("xigen error (%zd)\n", sz);
9582 +int au_xigen_new(struct inode *inode)
9587 + struct super_block *sb;
9588 + struct au_sbinfo *sbinfo;
9589 + struct file *file;
9592 + /* todo: dirty, at mount time */
9593 + if (inode->i_ino == AUFS_ROOT_INO)
9596 + SiMustAnyLock(sb);
9597 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
9601 + pos = inode->i_ino;
9602 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
9603 + AuIOErr1("too large i%lld\n", pos);
9606 + pos *= sizeof(inode->i_generation);
9609 + sbinfo = au_sbi(sb);
9610 + file = sbinfo->si_xigen;
9613 + if (vfsub_f_size_read(file)
9614 + < pos + sizeof(inode->i_generation)) {
9615 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
9616 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
9617 + sizeof(inode->i_generation), &pos);
9619 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
9620 + sizeof(inode->i_generation), &pos);
9621 + if (sz == sizeof(inode->i_generation))
9622 + goto out; /* success */
9625 + if (unlikely(sz >= 0)) {
9627 + AuIOErr("xigen error (%zd)\n", sz);
9634 +int au_xigen_set(struct super_block *sb, struct file *base)
9637 + struct au_sbinfo *sbinfo;
9638 + struct file *file;
9640 + SiMustWriteLock(sb);
9642 + sbinfo = au_sbi(sb);
9643 + file = au_xino_create2(base, sbinfo->si_xigen);
9644 + err = PTR_ERR(file);
9648 + if (sbinfo->si_xigen)
9649 + fput(sbinfo->si_xigen);
9650 + sbinfo->si_xigen = file;
9656 +void au_xigen_clr(struct super_block *sb)
9658 + struct au_sbinfo *sbinfo;
9660 + SiMustWriteLock(sb);
9662 + sbinfo = au_sbi(sb);
9663 + if (sbinfo->si_xigen) {
9664 + fput(sbinfo->si_xigen);
9665 + sbinfo->si_xigen = NULL;
9669 +/* ---------------------------------------------------------------------- */
9671 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
9674 + struct dentry *dentry, *d;
9675 + struct inode *inode;
9676 + unsigned int sigen;
9679 + inode = ilookup(sb, ino);
9683 + dentry = ERR_PTR(-ESTALE);
9684 + sigen = au_sigen(sb);
9685 + if (unlikely(is_bad_inode(inode)
9686 + || IS_DEADDIR(inode)
9687 + || sigen != au_iigen(inode, NULL)))
9691 + if (!dir_ino || S_ISDIR(inode->i_mode))
9692 + dentry = d_find_alias(inode);
9694 + spin_lock(&inode->i_lock);
9695 + hlist_for_each_entry(d, &inode->i_dentry, d_alias) {
9696 + spin_lock(&d->d_lock);
9697 + if (!au_test_anon(d)
9698 + && d->d_parent->d_inode->i_ino == dir_ino) {
9699 + dentry = dget_dlock(d);
9700 + spin_unlock(&d->d_lock);
9703 + spin_unlock(&d->d_lock);
9705 + spin_unlock(&inode->i_lock);
9707 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
9708 + /* need to refresh */
9716 + AuTraceErrPtr(dentry);
9720 +/* ---------------------------------------------------------------------- */
9723 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
9725 +struct au_compare_mnt_args {
9727 + struct super_block *sb;
9730 + struct vfsmount *mnt;
9733 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
9735 + struct au_compare_mnt_args *a = arg;
9737 + if (mnt->mnt_sb != a->sb)
9739 + a->mnt = mntget(mnt);
9743 +static struct vfsmount *au_mnt_get(struct super_block *sb)
9747 + struct au_compare_mnt_args args = {
9751 + get_fs_root(current->fs, &root);
9752 + br_read_lock(&vfsmount_lock);
9753 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
9754 + br_read_unlock(&vfsmount_lock);
9757 + AuDebugOn(!args.mnt);
9761 +struct au_nfsd_si_lock {
9762 + unsigned int sigen;
9763 + aufs_bindex_t bindex, br_id;
9764 + unsigned char force_lock;
9767 +static int si_nfsd_read_lock(struct super_block *sb,
9768 + struct au_nfsd_si_lock *nsi_lock)
9771 + aufs_bindex_t bindex;
9773 + si_read_lock(sb, AuLock_FLUSH);
9775 + /* branch id may be wrapped around */
9777 + bindex = au_br_index(sb, nsi_lock->br_id);
9778 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
9779 + goto out; /* success */
9783 + if (!nsi_lock->force_lock)
9784 + si_read_unlock(sb);
9787 + nsi_lock->bindex = bindex;
9791 +struct find_name_by_ino {
9792 + int called, found;
9799 +find_name_by_ino(void *arg, const char *name, int namelen, loff_t offset,
9800 + u64 ino, unsigned int d_type)
9802 + struct find_name_by_ino *a = arg;
9805 + if (a->ino != ino)
9808 + memcpy(a->name, name, namelen);
9809 + a->namelen = namelen;
9814 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
9815 + struct au_nfsd_si_lock *nsi_lock)
9817 + struct dentry *dentry, *parent;
9818 + struct file *file;
9819 + struct inode *dir;
9820 + struct find_name_by_ino arg;
9823 + parent = path->dentry;
9825 + si_read_unlock(parent->d_sb);
9826 + file = vfsub_dentry_open(path, au_dir_roflags);
9827 + dentry = (void *)file;
9831 + dentry = ERR_PTR(-ENOMEM);
9832 + arg.name = (void *)__get_free_page(GFP_NOFS);
9833 + if (unlikely(!arg.name))
9840 + err = vfsub_readdir(file, find_name_by_ino, &arg);
9841 + } while (!err && !arg.found && arg.called);
9842 + dentry = ERR_PTR(err);
9843 + if (unlikely(err))
9845 + /* instead of ENOENT */
9846 + dentry = ERR_PTR(-ESTALE);
9850 + /* do not call vfsub_lkup_one() */
9851 + dir = parent->d_inode;
9852 + mutex_lock(&dir->i_mutex);
9853 + dentry = vfsub_lookup_one_len(arg.name, parent, arg.namelen);
9854 + mutex_unlock(&dir->i_mutex);
9855 + AuTraceErrPtr(dentry);
9856 + if (IS_ERR(dentry))
9858 + AuDebugOn(au_test_anon(dentry));
9859 + if (unlikely(!dentry->d_inode)) {
9861 + dentry = ERR_PTR(-ENOENT);
9865 + free_page((unsigned long)arg.name);
9869 + if (unlikely(nsi_lock
9870 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
9871 + if (!IS_ERR(dentry)) {
9873 + dentry = ERR_PTR(-ESTALE);
9875 + AuTraceErrPtr(dentry);
9879 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
9881 + struct au_nfsd_si_lock *nsi_lock)
9883 + struct dentry *dentry;
9886 + if (dir_ino != AUFS_ROOT_INO) {
9887 + path.dentry = decode_by_ino(sb, dir_ino, 0);
9888 + dentry = path.dentry;
9889 + if (!path.dentry || IS_ERR(path.dentry))
9891 + AuDebugOn(au_test_anon(path.dentry));
9893 + path.dentry = dget(sb->s_root);
9895 + path.mnt = au_mnt_get(sb);
9896 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
9900 + AuTraceErrPtr(dentry);
9904 +/* ---------------------------------------------------------------------- */
9906 +static int h_acceptable(void *expv, struct dentry *dentry)
9911 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
9912 + char *buf, int len, struct super_block *sb)
9918 + p = d_path(h_rootpath, buf, len);
9923 + path.mnt = h_rootpath->mnt;
9924 + path.dentry = h_parent;
9925 + p = d_path(&path, buf, len);
9931 + path.mnt = au_mnt_get(sb);
9932 + path.dentry = sb->s_root;
9933 + p = d_path(&path, buf, len - strlen(p));
9938 + p[strlen(p)] = '/';
9946 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
9947 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
9949 + struct dentry *dentry, *h_parent, *root;
9950 + struct super_block *h_sb;
9951 + char *pathname, *p;
9952 + struct vfsmount *h_mnt;
9953 + struct au_branch *br;
9957 + br = au_sbr(sb, nsi_lock->bindex);
9958 + h_mnt = au_br_mnt(br);
9959 + h_sb = h_mnt->mnt_sb;
9960 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
9961 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
9962 + fh_len - Fh_tail, fh[Fh_h_type],
9963 + h_acceptable, /*context*/NULL);
9964 + dentry = h_parent;
9965 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
9966 + AuWarn1("%s decode_fh failed, %ld\n",
9967 + au_sbtype(h_sb), PTR_ERR(h_parent));
9971 + if (unlikely(au_test_anon(h_parent))) {
9972 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
9974 + goto out_h_parent;
9977 + dentry = ERR_PTR(-ENOMEM);
9978 + pathname = (void *)__get_free_page(GFP_NOFS);
9979 + if (unlikely(!pathname))
9980 + goto out_h_parent;
9982 + root = sb->s_root;
9984 + di_read_lock_parent(root, !AuLock_IR);
9985 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
9986 + di_read_unlock(root, !AuLock_IR);
9987 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
9988 + dentry = (void *)p;
9990 + goto out_pathname;
9992 + si_read_unlock(sb);
9993 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
9994 + dentry = ERR_PTR(err);
9995 + if (unlikely(err))
9998 + dentry = ERR_PTR(-ENOENT);
9999 + AuDebugOn(au_test_anon(path.dentry));
10000 + if (unlikely(!path.dentry->d_inode))
10003 + if (ino != path.dentry->d_inode->i_ino)
10004 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
10006 + dentry = dget(path.dentry);
10011 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
10012 + if (!IS_ERR(dentry)) {
10014 + dentry = ERR_PTR(-ESTALE);
10017 + free_page((unsigned long)pathname);
10021 + AuTraceErrPtr(dentry);
10025 +/* ---------------------------------------------------------------------- */
10027 +static struct dentry *
10028 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
10031 + struct dentry *dentry;
10032 + __u32 *fh = fid->raw;
10033 + struct au_branch *br;
10034 + ino_t ino, dir_ino;
10035 + struct au_nfsd_si_lock nsi_lock = {
10039 + dentry = ERR_PTR(-ESTALE);
10040 + /* it should never happen, but the file handle is unreliable */
10041 + if (unlikely(fh_len < Fh_tail))
10043 + nsi_lock.sigen = fh[Fh_sigen];
10044 + nsi_lock.br_id = fh[Fh_br_id];
10046 + /* branch id may be wrapped around */
10048 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
10050 + nsi_lock.force_lock = 1;
10052 + /* is this inode still cached? */
10053 + ino = decode_ino(fh + Fh_ino);
10054 + /* it should never happen */
10055 + if (unlikely(ino == AUFS_ROOT_INO))
10058 + dir_ino = decode_ino(fh + Fh_dir_ino);
10059 + dentry = decode_by_ino(sb, ino, dir_ino);
10060 + if (IS_ERR(dentry))
10065 + /* is the parent dir cached? */
10066 + br = au_sbr(sb, nsi_lock.bindex);
10067 + atomic_inc(&br->br_count);
10068 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
10069 + if (IS_ERR(dentry))
10074 + /* lookup path */
10075 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
10076 + if (IS_ERR(dentry))
10078 + if (unlikely(!dentry))
10079 + /* todo?: make it ESTALE */
10083 + if (!au_digen_test(dentry, au_sigen(sb))
10084 + && dentry->d_inode->i_generation == fh[Fh_igen])
10085 + goto out_unlock; /* success */
10088 + dentry = ERR_PTR(-ESTALE);
10091 + atomic_dec(&br->br_count);
10092 + si_read_unlock(sb);
10094 + AuTraceErrPtr(dentry);
10098 +#if 0 /* reserved for future use */
10099 +/* support subtreecheck option */
10100 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
10101 + int fh_len, int fh_type)
10103 + struct dentry *parent;
10104 + __u32 *fh = fid->raw;
10107 + dir_ino = decode_ino(fh + Fh_dir_ino);
10108 + parent = decode_by_ino(sb, dir_ino, 0);
10109 + if (IS_ERR(parent))
10112 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
10113 + dir_ino, fh, fh_len);
10116 + AuTraceErrPtr(parent);
10121 +/* ---------------------------------------------------------------------- */
10123 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
10124 + struct inode *dir)
10127 + aufs_bindex_t bindex;
10128 + struct super_block *sb, *h_sb;
10129 + struct dentry *dentry, *parent, *h_parent;
10130 + struct inode *h_dir;
10131 + struct au_branch *br;
10134 + if (unlikely(*max_len <= Fh_tail)) {
10135 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
10139 + err = FILEID_ROOT;
10140 + if (inode->i_ino == AUFS_ROOT_INO) {
10141 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
10146 + sb = inode->i_sb;
10147 + err = si_read_lock(sb, AuLock_FLUSH);
10148 + if (unlikely(err))
10151 +#ifdef CONFIG_AUFS_DEBUG
10152 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
10153 + AuWarn1("NFS-exporting requires xino\n");
10157 + ii_read_lock_child(inode);
10158 + bindex = au_ibstart(inode);
10160 + dentry = d_find_alias(inode);
10161 + if (unlikely(!dentry))
10163 + AuDebugOn(au_test_anon(dentry));
10164 + parent = dget_parent(dentry);
10166 + if (unlikely(!parent))
10168 + dir = parent->d_inode;
10171 + ii_read_lock_parent(dir);
10172 + h_dir = au_h_iptr(dir, bindex);
10173 + ii_read_unlock(dir);
10174 + if (unlikely(!h_dir))
10176 + h_parent = d_find_alias(h_dir);
10177 + if (unlikely(!h_parent))
10178 + goto out_hparent;
10181 + br = au_sbr(sb, bindex);
10182 + h_sb = au_br_sb(br);
10183 + if (unlikely(!h_sb->s_export_op)) {
10184 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
10185 + goto out_hparent;
10188 + fh[Fh_br_id] = br->br_id;
10189 + fh[Fh_sigen] = au_sigen(sb);
10190 + encode_ino(fh + Fh_ino, inode->i_ino);
10191 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
10192 + fh[Fh_igen] = inode->i_generation;
10194 + *max_len -= Fh_tail;
10195 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
10197 + /*connectable or subtreecheck*/0);
10198 + err = fh[Fh_h_type];
10199 + *max_len += Fh_tail;
10200 + /* todo: macros? */
10201 + if (err != FILEID_INVALID)
10204 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
10211 + ii_read_unlock(inode);
10212 + si_read_unlock(sb);
10214 + if (unlikely(err < 0))
10215 + err = FILEID_INVALID;
10219 +/* ---------------------------------------------------------------------- */
10221 +static int aufs_commit_metadata(struct inode *inode)
10224 + aufs_bindex_t bindex;
10225 + struct super_block *sb;
10226 + struct inode *h_inode;
10227 + int (*f)(struct inode *inode);
10229 + sb = inode->i_sb;
10230 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
10231 + ii_write_lock_child(inode);
10232 + bindex = au_ibstart(inode);
10233 + AuDebugOn(bindex < 0);
10234 + h_inode = au_h_iptr(inode, bindex);
10236 + f = h_inode->i_sb->s_export_op->commit_metadata;
10238 + err = f(h_inode);
10240 + struct writeback_control wbc = {
10241 + .sync_mode = WB_SYNC_ALL,
10242 + .nr_to_write = 0 /* metadata only */
10245 + err = sync_inode(h_inode, &wbc);
10248 + au_cpup_attr_timesizes(inode);
10249 + ii_write_unlock(inode);
10250 + si_read_unlock(sb);
10254 +/* ---------------------------------------------------------------------- */
10256 +static struct export_operations aufs_export_op = {
10257 + .fh_to_dentry = aufs_fh_to_dentry,
10258 + /* .fh_to_parent = aufs_fh_to_parent, */
10259 + .encode_fh = aufs_encode_fh,
10260 + .commit_metadata = aufs_commit_metadata
10263 +void au_export_init(struct super_block *sb)
10265 + struct au_sbinfo *sbinfo;
10268 + sb->s_export_op = &aufs_export_op;
10269 + sbinfo = au_sbi(sb);
10270 + sbinfo->si_xigen = NULL;
10271 + get_random_bytes(&u, sizeof(u));
10272 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
10273 + atomic_set(&sbinfo->si_xigen_next, u);
10275 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
10276 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
10277 +++ linux/fs/aufs/file.c 2013-08-23 23:59:39.634916914 +0200
10280 + * Copyright (C) 2005-2013 Junjiro R. Okajima
10282 + * This program, aufs is free software; you can redistribute it and/or modify
10283 + * it under the terms of the GNU General Public License as published by
10284 + * the Free Software Foundation; either version 2 of the License, or
10285 + * (at your option) any later version.
10287 + * This program is distributed in the hope that it will be useful,
10288 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10289 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10290 + * GNU General Public License for more details.
10292 + * You should have received a copy of the GNU General Public License
10293 + * along with this program; if not, write to the Free Software
10294 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
10298 + * handling file/dir, and address_space operation
10301 +#ifdef CONFIG_AUFS_DEBUG
10302 +#include <linux/migrate.h>
10304 +#include <linux/pagemap.h>
10307 +/* drop flags for writing */
10308 +unsigned int au_file_roflags(unsigned int flags)
10310 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
10311 + flags |= O_RDONLY | O_NOATIME;
10315 +/* common functions to regular file and dir */
10316 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
10317 + struct file *file)
10319 + struct file *h_file;
10320 + struct dentry *h_dentry;
10321 + struct inode *h_inode;
10322 + struct super_block *sb;
10323 + struct au_branch *br;
10324 + struct path h_path;
10325 + int err, exec_flag;
10327 + /* a race condition can happen between open and unlink/rmdir */
10328 + h_file = ERR_PTR(-ENOENT);
10329 + h_dentry = au_h_dptr(dentry, bindex);
10330 + if (au_test_nfsd() && !h_dentry)
10332 + h_inode = h_dentry->d_inode;
10333 + if (au_test_nfsd() && !h_inode)
10335 + spin_lock(&h_dentry->d_lock);
10336 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
10338 + /* || !dentry->d_inode->i_nlink */
10340 + spin_unlock(&h_dentry->d_lock);
10341 + if (unlikely(err))
10344 + sb = dentry->d_sb;
10345 + br = au_sbr(sb, bindex);
10346 + h_file = ERR_PTR(-EACCES);
10347 + exec_flag = flags & __FMODE_EXEC;
10348 + if (exec_flag && (au_br_mnt(br)->mnt_flags & MNT_NOEXEC))
10351 + /* drop flags for writing */
10352 + if (au_test_ro(sb, bindex, dentry->d_inode))
10353 + flags = au_file_roflags(flags);
10354 + flags &= ~O_CREAT;
10355 + atomic_inc(&br->br_count);
10356 + h_path.dentry = h_dentry;
10357 + h_path.mnt = au_br_mnt(br);
10358 + if (!au_special_file(h_inode->i_mode))
10359 + h_file = vfsub_dentry_open(&h_path, flags);
10361 + /* this block depends upon the configuration */
10362 + di_read_unlock(dentry, AuLock_IR);
10363 + fi_write_unlock(file);
10364 + si_read_unlock(sb);
10365 + h_file = vfsub_dentry_open(&h_path, flags);
10366 + si_noflush_read_lock(sb);
10367 + fi_write_lock(file);
10368 + di_read_lock_child(dentry, AuLock_IR);
10370 + if (IS_ERR(h_file))
10374 + err = deny_write_access(h_file);
10375 + if (unlikely(err)) {
10377 + h_file = ERR_PTR(err);
10381 + fsnotify_open(h_file);
10382 + goto out; /* success */
10385 + atomic_dec(&br->br_count);
10390 +int au_do_open(struct file *file, int (*open)(struct file *file, int flags),
10391 + struct au_fidir *fidir)
10394 + struct dentry *dentry;
10396 + err = au_finfo_init(file, fidir);
10397 + if (unlikely(err))
10400 + dentry = file->f_dentry;
10401 + di_read_lock_child(dentry, AuLock_IR);
10402 + err = open(file, vfsub_file_flags(file));
10403 + di_read_unlock(dentry, AuLock_IR);
10405 + fi_write_unlock(file);
10406 + if (unlikely(err)) {
10407 + au_fi(file)->fi_hdir = NULL;
10408 + au_finfo_fin(file);
10415 +int au_reopen_nondir(struct file *file)
10418 + aufs_bindex_t bstart;
10419 + struct dentry *dentry;
10420 + struct file *h_file, *h_file_tmp;
10422 + dentry = file->f_dentry;
10423 + AuDebugOn(au_special_file(dentry->d_inode->i_mode));
10424 + bstart = au_dbstart(dentry);
10425 + h_file_tmp = NULL;
10426 + if (au_fbstart(file) == bstart) {
10427 + h_file = au_hf_top(file);
10428 + if (file->f_mode == h_file->f_mode)
10429 + return 0; /* success */
10430 + h_file_tmp = h_file;
10431 + get_file(h_file_tmp);
10432 + au_set_h_fptr(file, bstart, NULL);
10434 + AuDebugOn(au_fi(file)->fi_hdir);
10437 + * file exists on both of rw and ro
10438 + * open --> dbstart and fbstart are both 0
10439 + * prepend a branch as rw, "rw" become ro
10441 + * delete the top branch, "rw" becomes rw again
10442 + * --> dbstart is 1, fbstart is still 0
10443 + * write --> fbstart is 0 but dbstart is 1
10445 + /* AuDebugOn(au_fbstart(file) < bstart); */
10447 + h_file = au_h_open(dentry, bstart, vfsub_file_flags(file) & ~O_TRUNC,
10449 + err = PTR_ERR(h_file);
10450 + if (IS_ERR(h_file)) {
10451 + if (h_file_tmp) {
10452 + atomic_inc(&au_sbr(dentry->d_sb, bstart)->br_count);
10453 + au_set_h_fptr(file, bstart, h_file_tmp);
10454 + h_file_tmp = NULL;
10456 + goto out; /* todo: close all? */
10460 + au_set_fbstart(file, bstart);
10461 + au_set_h_fptr(file, bstart, h_file);
10462 + au_update_figen(file);
10463 + /* todo: necessary? */
10464 + /* file->f_ra = h_file->f_ra; */
10468 + fput(h_file_tmp);
10472 +/* ---------------------------------------------------------------------- */
10474 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
10475 + struct dentry *hi_wh)
10478 + aufs_bindex_t bstart;
10479 + struct au_dinfo *dinfo;
10480 + struct dentry *h_dentry;
10481 + struct au_hdentry *hdp;
10483 + dinfo = au_di(file->f_dentry);
10484 + AuRwMustWriteLock(&dinfo->di_rwsem);
10486 + bstart = dinfo->di_bstart;
10487 + dinfo->di_bstart = btgt;
10488 + hdp = dinfo->di_hdentry;
10489 + h_dentry = hdp[0 + btgt].hd_dentry;
10490 + hdp[0 + btgt].hd_dentry = hi_wh;
10491 + err = au_reopen_nondir(file);
10492 + hdp[0 + btgt].hd_dentry = h_dentry;
10493 + dinfo->di_bstart = bstart;
10498 +static int au_ready_to_write_wh(struct file *file, loff_t len,
10499 + aufs_bindex_t bcpup, struct au_pin *pin)
10502 + struct inode *inode, *h_inode;
10503 + struct dentry *h_dentry, *hi_wh;
10504 + struct au_cp_generic cpg = {
10505 + .dentry = file->f_dentry,
10512 + au_update_dbstart(cpg.dentry);
10513 + inode = cpg.dentry->d_inode;
10515 + if (au_dbstart(cpg.dentry) <= bcpup
10516 + && au_dbend(cpg.dentry) >= bcpup) {
10517 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
10519 + h_inode = h_dentry->d_inode;
10521 + hi_wh = au_hi_wh(inode, bcpup);
10522 + if (!hi_wh && !h_inode)
10523 + err = au_sio_cpup_wh(&cpg, file);
10525 + /* already copied-up after unlink */
10526 + err = au_reopen_wh(file, bcpup, hi_wh);
10529 + && inode->i_nlink > 1
10530 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
10531 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
10537 + * prepare the @file for writing.
10539 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
10542 + aufs_bindex_t dbstart;
10543 + struct dentry *parent, *h_dentry;
10544 + struct inode *inode;
10545 + struct super_block *sb;
10546 + struct file *h_file;
10547 + struct au_cp_generic cpg = {
10548 + .dentry = file->f_dentry,
10553 + .flags = AuCpup_DTIME
10556 + sb = cpg.dentry->d_sb;
10557 + inode = cpg.dentry->d_inode;
10558 + AuDebugOn(au_special_file(inode->i_mode));
10559 + cpg.bsrc = au_fbstart(file);
10560 + err = au_test_ro(sb, cpg.bsrc, inode);
10561 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
10562 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
10567 + /* need to cpup or reopen */
10568 + parent = dget_parent(cpg.dentry);
10569 + di_write_lock_parent(parent);
10570 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
10572 + if (unlikely(err < 0))
10576 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
10577 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
10578 + if (unlikely(err))
10582 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
10583 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
10584 + if (unlikely(err))
10587 + h_dentry = au_hf_top(file)->f_dentry;
10588 + dbstart = au_dbstart(cpg.dentry);
10589 + if (dbstart <= cpg.bdst) {
10590 + h_dentry = au_h_dptr(cpg.dentry, cpg.bdst);
10591 + AuDebugOn(!h_dentry);
10592 + cpg.bsrc = cpg.bdst;
10595 + if (dbstart <= cpg.bdst /* just reopen */
10596 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
10598 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc);
10599 + if (IS_ERR(h_file))
10600 + err = PTR_ERR(h_file);
10602 + di_downgrade_lock(parent, AuLock_IR);
10603 + if (dbstart > cpg.bdst)
10604 + err = au_sio_cpup_simple(&cpg);
10606 + err = au_reopen_nondir(file);
10607 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
10609 + } else { /* copyup as wh and reopen */
10611 + * since writable hfsplus branch is not supported,
10612 + * h_open_pre/post() are unnecessary.
10614 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
10615 + di_downgrade_lock(parent, AuLock_IR);
10619 + au_pin_set_parent_lflag(pin, /*lflag*/0);
10620 + goto out_dput; /* success */
10626 + di_downgrade_lock(parent, AuLock_IR);
10628 + di_read_unlock(parent, AuLock_IR);
10635 +/* ---------------------------------------------------------------------- */
10637 +int au_do_flush(struct file *file, fl_owner_t id,
10638 + int (*flush)(struct file *file, fl_owner_t id))
10641 + struct super_block *sb;
10642 + struct inode *inode;
10644 + inode = file_inode(file);
10645 + sb = inode->i_sb;
10646 + si_noflush_read_lock(sb);
10647 + fi_read_lock(file);
10648 + ii_read_lock_child(inode);
10650 + err = flush(file, id);
10651 + au_cpup_attr_timesizes(inode);
10653 + ii_read_unlock(inode);
10654 + fi_read_unlock(file);
10655 + si_read_unlock(sb);
10659 +/* ---------------------------------------------------------------------- */
10661 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
10664 + struct au_pin pin;
10665 + struct au_finfo *finfo;
10666 + struct dentry *parent, *hi_wh;
10667 + struct inode *inode;
10668 + struct super_block *sb;
10669 + struct au_cp_generic cpg = {
10670 + .dentry = file->f_dentry,
10675 + .flags = AuCpup_DTIME
10678 + FiMustWriteLock(file);
10681 + finfo = au_fi(file);
10682 + sb = cpg.dentry->d_sb;
10683 + inode = cpg.dentry->d_inode;
10684 + cpg.bdst = au_ibstart(inode);
10685 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
10688 + parent = dget_parent(cpg.dentry);
10689 + if (au_test_ro(sb, cpg.bdst, inode)) {
10690 + di_read_lock_parent(parent, !AuLock_IR);
10691 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
10693 + di_read_unlock(parent, !AuLock_IR);
10694 + if (unlikely(err < 0))
10699 + di_read_lock_parent(parent, AuLock_IR);
10700 + hi_wh = au_hi_wh(inode, cpg.bdst);
10701 + if (!S_ISDIR(inode->i_mode)
10702 + && au_opt_test(au_mntflags(sb), PLINK)
10703 + && au_plink_test(inode)
10704 + && !d_unhashed(cpg.dentry)
10705 + && cpg.bdst < au_dbstart(cpg.dentry)) {
10706 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
10707 + if (unlikely(err))
10710 + /* always superio. */
10711 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
10712 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
10714 + err = au_sio_cpup_simple(&cpg);
10717 + } else if (hi_wh) {
10718 + /* already copied-up after unlink */
10719 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
10720 + *need_reopen = 0;
10724 + di_read_unlock(parent, AuLock_IR);
10731 +static void au_do_refresh_dir(struct file *file)
10733 + aufs_bindex_t bindex, bend, new_bindex, brid;
10734 + struct au_hfile *p, tmp, *q;
10735 + struct au_finfo *finfo;
10736 + struct super_block *sb;
10737 + struct au_fidir *fidir;
10739 + FiMustWriteLock(file);
10741 + sb = file->f_dentry->d_sb;
10742 + finfo = au_fi(file);
10743 + fidir = finfo->fi_hdir;
10744 + AuDebugOn(!fidir);
10745 + p = fidir->fd_hfile + finfo->fi_btop;
10746 + brid = p->hf_br->br_id;
10747 + bend = fidir->fd_bbot;
10748 + for (bindex = finfo->fi_btop; bindex <= bend; bindex++, p++) {
10752 + new_bindex = au_br_index(sb, p->hf_br->br_id);
10753 + if (new_bindex == bindex)
10755 + if (new_bindex < 0) {
10756 + au_set_h_fptr(file, bindex, NULL);
10760 + /* swap two lower inode, and loop again */
10761 + q = fidir->fd_hfile + new_bindex;
10765 + if (tmp.hf_file) {
10771 + p = fidir->fd_hfile;
10772 + if (!au_test_mmapped(file) && !d_unlinked(file->f_dentry)) {
10773 + bend = au_sbend(sb);
10774 + for (finfo->fi_btop = 0; finfo->fi_btop <= bend;
10775 + finfo->fi_btop++, p++)
10776 + if (p->hf_file) {
10777 + if (file_inode(p->hf_file))
10780 + au_hfput(p, file);
10783 + bend = au_br_index(sb, brid);
10784 + for (finfo->fi_btop = 0; finfo->fi_btop < bend;
10785 + finfo->fi_btop++, p++)
10787 + au_hfput(p, file);
10788 + bend = au_sbend(sb);
10791 + p = fidir->fd_hfile + bend;
10792 + for (fidir->fd_bbot = bend; fidir->fd_bbot >= finfo->fi_btop;
10793 + fidir->fd_bbot--, p--)
10794 + if (p->hf_file) {
10795 + if (file_inode(p->hf_file))
10798 + au_hfput(p, file);
10800 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
10804 + * after branch manipulating, refresh the file.
10806 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
10808 + int err, need_reopen;
10809 + aufs_bindex_t bend, bindex;
10810 + struct dentry *dentry;
10811 + struct au_finfo *finfo;
10812 + struct au_hfile *hfile;
10814 + dentry = file->f_dentry;
10815 + finfo = au_fi(file);
10816 + if (!finfo->fi_hdir) {
10817 + hfile = &finfo->fi_htop;
10818 + AuDebugOn(!hfile->hf_file);
10819 + bindex = au_br_index(dentry->d_sb, hfile->hf_br->br_id);
10820 + AuDebugOn(bindex < 0);
10821 + if (bindex != finfo->fi_btop)
10822 + au_set_fbstart(file, bindex);
10824 + err = au_fidir_realloc(finfo, au_sbend(dentry->d_sb) + 1);
10825 + if (unlikely(err))
10827 + au_do_refresh_dir(file);
10832 + if (!au_test_mmapped(file))
10833 + err = au_file_refresh_by_inode(file, &need_reopen);
10834 + if (!err && need_reopen && !d_unlinked(dentry))
10835 + err = reopen(file);
10837 + au_update_figen(file);
10838 + goto out; /* success */
10841 + /* error, close all lower files */
10842 + if (finfo->fi_hdir) {
10843 + bend = au_fbend_dir(file);
10844 + for (bindex = au_fbstart(file); bindex <= bend; bindex++)
10845 + au_set_h_fptr(file, bindex, NULL);
10852 +/* common function to regular file and dir */
10853 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
10857 + unsigned int sigen, figen;
10858 + aufs_bindex_t bstart;
10859 + unsigned char pseudo_link;
10860 + struct dentry *dentry;
10861 + struct inode *inode;
10864 + dentry = file->f_dentry;
10865 + inode = dentry->d_inode;
10866 + AuDebugOn(au_special_file(inode->i_mode));
10867 + sigen = au_sigen(dentry->d_sb);
10868 + fi_write_lock(file);
10869 + figen = au_figen(file);
10870 + di_write_lock_child(dentry);
10871 + bstart = au_dbstart(dentry);
10872 + pseudo_link = (bstart != au_ibstart(inode));
10873 + if (sigen == figen && !pseudo_link && au_fbstart(file) == bstart) {
10875 + di_downgrade_lock(dentry, AuLock_IR);
10876 + fi_downgrade_lock(file);
10878 + goto out; /* success */
10881 + AuDbg("sigen %d, figen %d\n", sigen, figen);
10882 + if (au_digen_test(dentry, sigen)) {
10883 + err = au_reval_dpath(dentry, sigen);
10884 + AuDebugOn(!err && au_digen_test(dentry, sigen));
10888 + err = refresh_file(file, reopen);
10891 + di_downgrade_lock(dentry, AuLock_IR);
10892 + fi_downgrade_lock(file);
10895 + di_write_unlock(dentry);
10896 + fi_write_unlock(file);
10903 +/* ---------------------------------------------------------------------- */
10905 +/* cf. aufs_nopage() */
10906 +/* for madvise(2) */
10907 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
10909 + unlock_page(page);
10913 +/* it will never be called, but necessary to support O_DIRECT */
10914 +static ssize_t aufs_direct_IO(int rw, struct kiocb *iocb,
10915 + const struct iovec *iov, loff_t offset,
10916 + unsigned long nr_segs)
10917 +{ BUG(); return 0; }
10920 + * it will never be called, but madvise and fadvise behaves differently
10921 + * when get_xip_mem is defined
10923 +static int aufs_get_xip_mem(struct address_space *mapping, pgoff_t pgoff,
10924 + int create, void **kmem, unsigned long *pfn)
10925 +{ BUG(); return 0; }
10927 +/* they will never be called. */
10928 +#ifdef CONFIG_AUFS_DEBUG
10929 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
10930 + loff_t pos, unsigned len, unsigned flags,
10931 + struct page **pagep, void **fsdata)
10932 +{ AuUnsupport(); return 0; }
10933 +static int aufs_write_end(struct file *file, struct address_space *mapping,
10934 + loff_t pos, unsigned len, unsigned copied,
10935 + struct page *page, void *fsdata)
10936 +{ AuUnsupport(); return 0; }
10937 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
10938 +{ AuUnsupport(); return 0; }
10940 +static int aufs_set_page_dirty(struct page *page)
10941 +{ AuUnsupport(); return 0; }
10942 +static void aufs_invalidatepage(struct page *page, unsigned long offset)
10943 +{ AuUnsupport(); }
10944 +static int aufs_releasepage(struct page *page, gfp_t gfp)
10945 +{ AuUnsupport(); return 0; }
10946 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
10947 + struct page *page, enum migrate_mode mode)
10948 +{ AuUnsupport(); return 0; }
10949 +static int aufs_launder_page(struct page *page)
10950 +{ AuUnsupport(); return 0; }
10951 +static int aufs_is_partially_uptodate(struct page *page,
10952 + read_descriptor_t *desc,
10953 + unsigned long from)
10954 +{ AuUnsupport(); return 0; }
10955 +static int aufs_error_remove_page(struct address_space *mapping,
10956 + struct page *page)
10957 +{ AuUnsupport(); return 0; }
10958 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
10960 +{ AuUnsupport(); return 0; }
10961 +static void aufs_swap_deactivate(struct file *file)
10962 +{ AuUnsupport(); }
10963 +#endif /* CONFIG_AUFS_DEBUG */
10965 +const struct address_space_operations aufs_aop = {
10966 + .readpage = aufs_readpage,
10967 + .direct_IO = aufs_direct_IO,
10968 + .get_xip_mem = aufs_get_xip_mem,
10969 +#ifdef CONFIG_AUFS_DEBUG
10970 + .writepage = aufs_writepage,
10971 + /* no writepages, because of writepage */
10972 + .set_page_dirty = aufs_set_page_dirty,
10973 + /* no readpages, because of readpage */
10974 + .write_begin = aufs_write_begin,
10975 + .write_end = aufs_write_end,
10976 + /* no bmap, no block device */
10977 + .invalidatepage = aufs_invalidatepage,
10978 + .releasepage = aufs_releasepage,
10979 + .migratepage = aufs_migratepage,
10980 + .launder_page = aufs_launder_page,
10981 + .is_partially_uptodate = aufs_is_partially_uptodate,
10982 + .error_remove_page = aufs_error_remove_page,
10983 + .swap_activate = aufs_swap_activate,
10984 + .swap_deactivate = aufs_swap_deactivate
10985 +#endif /* CONFIG_AUFS_DEBUG */
10987 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
10988 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
10989 +++ linux/fs/aufs/file.h 2013-08-23 23:59:39.634916914 +0200
10992 + * Copyright (C) 2005-2013 Junjiro R. Okajima
10994 + * This program, aufs is free software; you can redistribute it and/or modify
10995 + * it under the terms of the GNU General Public License as published by
10996 + * the Free Software Foundation; either version 2 of the License, or
10997 + * (at your option) any later version.
10999 + * This program is distributed in the hope that it will be useful,
11000 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11001 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11002 + * GNU General Public License for more details.
11004 + * You should have received a copy of the GNU General Public License
11005 + * along with this program; if not, write to the Free Software
11006 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11010 + * file operations
11013 +#ifndef __AUFS_FILE_H__
11014 +#define __AUFS_FILE_H__
11018 +#include <linux/file.h>
11019 +#include <linux/fs.h>
11020 +#include <linux/poll.h>
11021 +#include "rwsem.h"
11025 + struct file *hf_file;
11026 + struct au_branch *hf_br;
11031 + aufs_bindex_t fd_bbot;
11032 + aufs_bindex_t fd_nent;
11033 + struct au_vdir *fd_vdir_cache;
11034 + struct au_hfile fd_hfile[];
11037 +static inline int au_fidir_sz(int nent)
11039 + AuDebugOn(nent < 0);
11040 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
11044 + atomic_t fi_generation;
11046 + struct au_rwsem fi_rwsem;
11047 + aufs_bindex_t fi_btop;
11049 + /* do not union them */
11050 + struct { /* for non-dir */
11051 + struct au_hfile fi_htop;
11052 + atomic_t fi_mmapped;
11054 + struct au_fidir *fi_hdir; /* for dir only */
11055 +} ____cacheline_aligned_in_smp;
11057 +/* ---------------------------------------------------------------------- */
11060 +extern const struct address_space_operations aufs_aop;
11061 +unsigned int au_file_roflags(unsigned int flags);
11062 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
11063 + struct file *file);
11064 +int au_do_open(struct file *file, int (*open)(struct file *file, int flags),
11065 + struct au_fidir *fidir);
11066 +int au_reopen_nondir(struct file *file);
11068 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
11069 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
11071 +int au_do_flush(struct file *file, fl_owner_t id,
11072 + int (*flush)(struct file *file, fl_owner_t id));
11075 +#ifdef CONFIG_AUFS_POLL
11076 +unsigned int aufs_poll(struct file *file, poll_table *wait);
11079 +#ifdef CONFIG_AUFS_BR_HFSPLUS
11081 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex);
11082 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
11083 + struct file *h_file);
11086 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex)
11091 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
11092 + struct file *h_file);
11096 +extern const struct file_operations aufs_file_fop;
11097 +int au_do_open_nondir(struct file *file, int flags);
11098 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
11100 +#ifdef CONFIG_AUFS_SP_IATTR
11102 +struct au_finfo *au_fi_sp(struct file *file);
11103 +int au_special_file(umode_t mode);
11104 +void au_init_special_fop(struct inode *inode, umode_t mode, dev_t rdev);
11106 +static inline struct au_finfo *au_fi_sp(struct file *file)
11110 +AuStubInt0(au_special_file, umode_t mode)
11111 +static inline void au_init_special_fop(struct inode *inode, umode_t mode,
11114 + init_special_inode(inode, mode, rdev);
11119 +void au_hfput(struct au_hfile *hf, struct file *file);
11120 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
11121 + struct file *h_file);
11123 +void au_update_figen(struct file *file);
11124 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
11125 +int au_fidir_realloc(struct au_finfo *finfo, int nbr);
11127 +void au_fi_init_once(void *_fi);
11128 +void au_finfo_fin(struct file *file);
11129 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
11132 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
11133 +#ifdef CONFIG_COMPAT
11134 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
11135 + unsigned long arg);
11136 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
11137 + unsigned long arg);
11140 +/* ---------------------------------------------------------------------- */
11142 +static inline struct au_finfo *au_fi(struct file *file)
11144 + struct au_finfo *finfo;
11146 + finfo = au_fi_sp(file);
11148 + finfo = file->private_data;
11152 +/* ---------------------------------------------------------------------- */
11155 + * fi_read_lock, fi_write_lock,
11156 + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock
11158 +AuSimpleRwsemFuncs(fi, struct file *f, &au_fi(f)->fi_rwsem);
11160 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
11161 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
11162 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
11164 +/* ---------------------------------------------------------------------- */
11166 +/* todo: hard/soft set? */
11167 +static inline aufs_bindex_t au_fbstart(struct file *file)
11169 + FiMustAnyLock(file);
11170 + return au_fi(file)->fi_btop;
11173 +static inline aufs_bindex_t au_fbend_dir(struct file *file)
11175 + FiMustAnyLock(file);
11176 + AuDebugOn(!au_fi(file)->fi_hdir);
11177 + return au_fi(file)->fi_hdir->fd_bbot;
11180 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
11182 + FiMustAnyLock(file);
11183 + AuDebugOn(!au_fi(file)->fi_hdir);
11184 + return au_fi(file)->fi_hdir->fd_vdir_cache;
11187 +static inline void au_set_fbstart(struct file *file, aufs_bindex_t bindex)
11189 + FiMustWriteLock(file);
11190 + au_fi(file)->fi_btop = bindex;
11193 +static inline void au_set_fbend_dir(struct file *file, aufs_bindex_t bindex)
11195 + FiMustWriteLock(file);
11196 + AuDebugOn(!au_fi(file)->fi_hdir);
11197 + au_fi(file)->fi_hdir->fd_bbot = bindex;
11200 +static inline void au_set_fvdir_cache(struct file *file,
11201 + struct au_vdir *vdir_cache)
11203 + FiMustWriteLock(file);
11204 + AuDebugOn(!au_fi(file)->fi_hdir);
11205 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
11208 +static inline struct file *au_hf_top(struct file *file)
11210 + FiMustAnyLock(file);
11211 + AuDebugOn(au_fi(file)->fi_hdir);
11212 + return au_fi(file)->fi_htop.hf_file;
11215 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
11217 + FiMustAnyLock(file);
11218 + AuDebugOn(!au_fi(file)->fi_hdir);
11219 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
11222 +/* todo: memory barrier? */
11223 +static inline unsigned int au_figen(struct file *f)
11225 + return atomic_read(&au_fi(f)->fi_generation);
11228 +static inline void au_set_mmapped(struct file *f)
11230 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
11232 + pr_warn("fi_mmapped wrapped around\n");
11233 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
11237 +static inline void au_unset_mmapped(struct file *f)
11239 + atomic_dec(&au_fi(f)->fi_mmapped);
11242 +static inline int au_test_mmapped(struct file *f)
11244 + return atomic_read(&au_fi(f)->fi_mmapped);
11247 +/* customize vma->vm_file */
11249 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
11250 + struct file *file)
11254 + f = vma->vm_file;
11256 + vma->vm_file = file;
11261 +#define AuDbgVmRegion(file, vma) do {} while (0)
11263 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
11264 + struct file *file)
11266 + au_do_vm_file_reset(vma, file);
11269 +#define AuDbgVmRegion(file, vma) \
11270 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
11272 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
11273 + struct file *file)
11277 + au_do_vm_file_reset(vma, file);
11278 + f = vma->vm_region->vm_file;
11280 + vma->vm_region->vm_file = file;
11283 +#endif /* CONFIG_MMU */
11285 +/* handle vma->vm_prfile */
11286 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
11287 + struct file *file)
11289 +#ifdef CONFIG_AUFS_PROC_MAP
11291 + vma->vm_prfile = file;
11292 +#ifndef CONFIG_MMU
11294 + vma->vm_region->vm_prfile = file;
11299 +#endif /* __KERNEL__ */
11300 +#endif /* __AUFS_FILE_H__ */
11301 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
11302 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
11303 +++ linux/fs/aufs/finfo.c 2013-07-06 13:20:47.750198454 +0200
11306 + * Copyright (C) 2005-2013 Junjiro R. Okajima
11308 + * This program, aufs is free software; you can redistribute it and/or modify
11309 + * it under the terms of the GNU General Public License as published by
11310 + * the Free Software Foundation; either version 2 of the License, or
11311 + * (at your option) any later version.
11313 + * This program is distributed in the hope that it will be useful,
11314 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11315 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11316 + * GNU General Public License for more details.
11318 + * You should have received a copy of the GNU General Public License
11319 + * along with this program; if not, write to the Free Software
11320 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11324 + * file private data
11329 +void au_hfput(struct au_hfile *hf, struct file *file)
11331 + /* todo: direct access f_flags */
11332 + if (vfsub_file_flags(file) & __FMODE_EXEC)
11333 + allow_write_access(hf->hf_file);
11334 + fput(hf->hf_file);
11335 + hf->hf_file = NULL;
11336 + atomic_dec(&hf->hf_br->br_count);
11337 + hf->hf_br = NULL;
11340 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
11342 + struct au_finfo *finfo = au_fi(file);
11343 + struct au_hfile *hf;
11344 + struct au_fidir *fidir;
11346 + fidir = finfo->fi_hdir;
11348 + AuDebugOn(finfo->fi_btop != bindex);
11349 + hf = &finfo->fi_htop;
11351 + hf = fidir->fd_hfile + bindex;
11353 + if (hf && hf->hf_file)
11354 + au_hfput(hf, file);
11356 + FiMustWriteLock(file);
11357 + hf->hf_file = val;
11358 + hf->hf_br = au_sbr(file->f_dentry->d_sb, bindex);
11362 +void au_update_figen(struct file *file)
11364 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_dentry));
11365 + /* smp_mb(); */ /* atomic_set */
11368 +/* ---------------------------------------------------------------------- */
11370 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
11372 + struct au_fidir *fidir;
11375 + nbr = au_sbend(sb) + 1;
11377 + nbr = 2; /* initial allocate for 2 branches */
11378 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
11380 + fidir->fd_bbot = -1;
11381 + fidir->fd_nent = nbr;
11382 + fidir->fd_vdir_cache = NULL;
11388 +int au_fidir_realloc(struct au_finfo *finfo, int nbr)
11391 + struct au_fidir *fidir, *p;
11393 + AuRwMustWriteLock(&finfo->fi_rwsem);
11394 + fidir = finfo->fi_hdir;
11395 + AuDebugOn(!fidir);
11398 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
11401 + p->fd_nent = nbr;
11402 + finfo->fi_hdir = p;
11409 +/* ---------------------------------------------------------------------- */
11411 +void au_finfo_fin(struct file *file)
11413 + struct au_finfo *finfo;
11415 + au_nfiles_dec(file->f_dentry->d_sb);
11417 + finfo = au_fi(file);
11418 + AuDebugOn(finfo->fi_hdir);
11419 + AuRwDestroy(&finfo->fi_rwsem);
11420 + au_cache_free_finfo(finfo);
11423 +void au_fi_init_once(void *_finfo)
11425 + struct au_finfo *finfo = _finfo;
11426 + static struct lock_class_key aufs_fi;
11428 + au_rw_init(&finfo->fi_rwsem);
11429 + au_rw_class(&finfo->fi_rwsem, &aufs_fi);
11432 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
11435 + struct au_finfo *finfo;
11436 + struct dentry *dentry;
11439 + dentry = file->f_dentry;
11440 + finfo = au_cache_alloc_finfo();
11441 + if (unlikely(!finfo))
11445 + au_nfiles_inc(dentry->d_sb);
11446 + /* verbose coding for lock class name */
11448 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcNonDir_FIINFO);
11450 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcDir_FIINFO);
11451 + au_rw_write_lock(&finfo->fi_rwsem);
11452 + finfo->fi_btop = -1;
11453 + finfo->fi_hdir = fidir;
11454 + atomic_set(&finfo->fi_generation, au_digen(dentry));
11455 + /* smp_mb(); */ /* atomic_set */
11457 + file->private_data = finfo;
11462 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
11463 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
11464 +++ linux/fs/aufs/f_op.c 2013-08-23 23:59:39.634916914 +0200
11467 + * Copyright (C) 2005-2013 Junjiro R. Okajima
11469 + * This program, aufs is free software; you can redistribute it and/or modify
11470 + * it under the terms of the GNU General Public License as published by
11471 + * the Free Software Foundation; either version 2 of the License, or
11472 + * (at your option) any later version.
11474 + * This program is distributed in the hope that it will be useful,
11475 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11476 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11477 + * GNU General Public License for more details.
11479 + * You should have received a copy of the GNU General Public License
11480 + * along with this program; if not, write to the Free Software
11481 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11485 + * file and vm operations
11488 +#include <linux/aio.h>
11489 +#include <linux/fs_stack.h>
11490 +#include <linux/mman.h>
11491 +#include <linux/security.h>
11494 +int au_do_open_nondir(struct file *file, int flags)
11497 + aufs_bindex_t bindex;
11498 + struct file *h_file;
11499 + struct dentry *dentry;
11500 + struct au_finfo *finfo;
11502 + FiMustWriteLock(file);
11504 + dentry = file->f_dentry;
11505 + err = au_d_alive(dentry);
11506 + if (unlikely(err))
11509 + finfo = au_fi(file);
11510 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
11511 + atomic_set(&finfo->fi_mmapped, 0);
11512 + bindex = au_dbstart(dentry);
11513 + h_file = au_h_open(dentry, bindex, flags, file);
11514 + if (IS_ERR(h_file))
11515 + err = PTR_ERR(h_file);
11517 + au_set_fbstart(file, bindex);
11518 + au_set_h_fptr(file, bindex, h_file);
11519 + au_update_figen(file);
11520 + /* todo: necessary? */
11521 + /* file->f_ra = h_file->f_ra; */
11528 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
11529 + struct file *file)
11532 + struct super_block *sb;
11534 + AuDbg("%.*s, f_flags 0x%x, f_mode 0x%x\n",
11535 + AuDLNPair(file->f_dentry), vfsub_file_flags(file),
11538 + sb = file->f_dentry->d_sb;
11539 + si_read_lock(sb, AuLock_FLUSH);
11540 + err = au_do_open(file, au_do_open_nondir, /*fidir*/NULL);
11541 + si_read_unlock(sb);
11545 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
11547 + struct au_finfo *finfo;
11548 + aufs_bindex_t bindex;
11550 + finfo = au_fi(file);
11551 + bindex = finfo->fi_btop;
11553 + au_set_h_fptr(file, bindex, NULL);
11555 + au_finfo_fin(file);
11559 +/* ---------------------------------------------------------------------- */
11561 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
11564 + struct file *h_file;
11567 + h_file = au_hf_top(file);
11569 + err = vfsub_flush(h_file, id);
11573 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
11575 + return au_do_flush(file, id, au_do_flush_nondir);
11578 +/* ---------------------------------------------------------------------- */
11580 + * read and write functions acquire [fdi]_rwsem once, but release before
11581 + * mmap_sem. This is because to stop a race condition between mmap(2).
11582 + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping
11583 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
11584 + * read functions after [fdi]_rwsem are released, but it should be harmless.
11587 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
11591 + struct dentry *dentry;
11592 + struct file *h_file;
11593 + struct super_block *sb;
11595 + dentry = file->f_dentry;
11596 + sb = dentry->d_sb;
11597 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11598 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
11599 + if (unlikely(err))
11602 + h_file = au_hf_top(file);
11603 + get_file(h_file);
11604 + di_read_unlock(dentry, AuLock_IR);
11605 + fi_read_unlock(file);
11607 + /* filedata may be obsoleted by concurrent copyup, but no problem */
11608 + err = vfsub_read_u(h_file, buf, count, ppos);
11609 + /* todo: necessary? */
11610 + /* file->f_ra = h_file->f_ra; */
11611 + /* update without lock, I don't think it a problem */
11612 + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
11616 + si_read_unlock(sb);
11621 + * todo: very ugly
11622 + * it locks both of i_mutex and si_rwsem for read in safe.
11623 + * if the plink maintenance mode continues forever (that is the problem),
11624 + * may loop forever.
11626 +static void au_mtx_and_read_lock(struct inode *inode)
11629 + struct super_block *sb = inode->i_sb;
11632 + mutex_lock(&inode->i_mutex);
11633 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
11636 + mutex_unlock(&inode->i_mutex);
11637 + si_read_lock(sb, AuLock_NOPLMW);
11638 + si_read_unlock(sb);
11642 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
11643 + size_t count, loff_t *ppos)
11646 + struct au_pin pin;
11647 + struct dentry *dentry;
11648 + struct super_block *sb;
11649 + struct inode *inode;
11650 + struct file *h_file;
11651 + char __user *buf = (char __user *)ubuf;
11653 + dentry = file->f_dentry;
11654 + sb = dentry->d_sb;
11655 + inode = dentry->d_inode;
11656 + au_mtx_and_read_lock(inode);
11658 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
11659 + if (unlikely(err))
11662 + err = au_ready_to_write(file, -1, &pin);
11663 + di_downgrade_lock(dentry, AuLock_IR);
11664 + if (unlikely(err)) {
11665 + di_read_unlock(dentry, AuLock_IR);
11666 + fi_write_unlock(file);
11670 + h_file = au_hf_top(file);
11671 + get_file(h_file);
11673 + di_read_unlock(dentry, AuLock_IR);
11674 + fi_write_unlock(file);
11676 + err = vfsub_write_u(h_file, buf, count, ppos);
11677 + ii_write_lock_child(inode);
11678 + au_cpup_attr_timesizes(inode);
11679 + inode->i_mode = file_inode(h_file)->i_mode;
11680 + ii_write_unlock(inode);
11684 + si_read_unlock(sb);
11685 + mutex_unlock(&inode->i_mutex);
11689 +static ssize_t au_do_aio(struct file *h_file, int rw, struct kiocb *kio,
11690 + const struct iovec *iov, unsigned long nv, loff_t pos)
11693 + struct file *file;
11694 + ssize_t (*func)(struct kiocb *, const struct iovec *, unsigned long,
11697 + err = security_file_permission(h_file, rw);
11698 + if (unlikely(err))
11703 + if (rw == MAY_READ)
11704 + func = h_file->f_op->aio_read;
11705 + else if (rw == MAY_WRITE)
11706 + func = h_file->f_op->aio_write;
11708 + file = kio->ki_filp;
11709 + kio->ki_filp = h_file;
11711 + err = func(kio, iov, nv, pos);
11713 + kio->ki_filp = file;
11715 + /* currently there is no such fs */
11722 +static ssize_t aufs_aio_read(struct kiocb *kio, const struct iovec *iov,
11723 + unsigned long nv, loff_t pos)
11726 + struct file *file, *h_file;
11727 + struct dentry *dentry;
11728 + struct super_block *sb;
11730 + file = kio->ki_filp;
11731 + dentry = file->f_dentry;
11732 + sb = dentry->d_sb;
11733 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11734 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
11735 + if (unlikely(err))
11738 + h_file = au_hf_top(file);
11739 + get_file(h_file);
11740 + di_read_unlock(dentry, AuLock_IR);
11741 + fi_read_unlock(file);
11743 + err = au_do_aio(h_file, MAY_READ, kio, iov, nv, pos);
11744 + /* todo: necessary? */
11745 + /* file->f_ra = h_file->f_ra; */
11746 + /* update without lock, I don't think it a problem */
11747 + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
11751 + si_read_unlock(sb);
11755 +static ssize_t aufs_aio_write(struct kiocb *kio, const struct iovec *iov,
11756 + unsigned long nv, loff_t pos)
11759 + struct au_pin pin;
11760 + struct dentry *dentry;
11761 + struct inode *inode;
11762 + struct file *file, *h_file;
11763 + struct super_block *sb;
11765 + file = kio->ki_filp;
11766 + dentry = file->f_dentry;
11767 + sb = dentry->d_sb;
11768 + inode = dentry->d_inode;
11769 + au_mtx_and_read_lock(inode);
11771 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
11772 + if (unlikely(err))
11775 + err = au_ready_to_write(file, -1, &pin);
11776 + di_downgrade_lock(dentry, AuLock_IR);
11777 + if (unlikely(err)) {
11778 + di_read_unlock(dentry, AuLock_IR);
11779 + fi_write_unlock(file);
11783 + h_file = au_hf_top(file);
11784 + get_file(h_file);
11786 + di_read_unlock(dentry, AuLock_IR);
11787 + fi_write_unlock(file);
11789 + err = au_do_aio(h_file, MAY_WRITE, kio, iov, nv, pos);
11790 + ii_write_lock_child(inode);
11791 + au_cpup_attr_timesizes(inode);
11792 + inode->i_mode = file_inode(h_file)->i_mode;
11793 + ii_write_unlock(inode);
11797 + si_read_unlock(sb);
11798 + mutex_unlock(&inode->i_mutex);
11802 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
11803 + struct pipe_inode_info *pipe, size_t len,
11804 + unsigned int flags)
11807 + struct file *h_file;
11808 + struct dentry *dentry;
11809 + struct super_block *sb;
11811 + dentry = file->f_dentry;
11812 + sb = dentry->d_sb;
11813 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11814 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
11815 + if (unlikely(err))
11819 + h_file = au_hf_top(file);
11820 + get_file(h_file);
11821 + if (au_test_loopback_kthread()) {
11822 + au_warn_loopback(h_file->f_dentry->d_sb);
11823 + if (file->f_mapping != h_file->f_mapping) {
11824 + file->f_mapping = h_file->f_mapping;
11825 + smp_mb(); /* unnecessary? */
11828 + di_read_unlock(dentry, AuLock_IR);
11829 + fi_read_unlock(file);
11831 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
11832 + /* todo: necessasry? */
11833 + /* file->f_ra = h_file->f_ra; */
11834 + /* update without lock, I don't think it a problem */
11835 + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
11839 + si_read_unlock(sb);
11844 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
11845 + size_t len, unsigned int flags)
11848 + struct au_pin pin;
11849 + struct dentry *dentry;
11850 + struct inode *inode;
11851 + struct file *h_file;
11852 + struct super_block *sb;
11854 + dentry = file->f_dentry;
11855 + sb = dentry->d_sb;
11856 + inode = dentry->d_inode;
11857 + au_mtx_and_read_lock(inode);
11859 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
11860 + if (unlikely(err))
11863 + err = au_ready_to_write(file, -1, &pin);
11864 + di_downgrade_lock(dentry, AuLock_IR);
11865 + if (unlikely(err)) {
11866 + di_read_unlock(dentry, AuLock_IR);
11867 + fi_write_unlock(file);
11871 + h_file = au_hf_top(file);
11872 + get_file(h_file);
11874 + di_read_unlock(dentry, AuLock_IR);
11875 + fi_write_unlock(file);
11877 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
11878 + ii_write_lock_child(inode);
11879 + au_cpup_attr_timesizes(inode);
11880 + inode->i_mode = file_inode(h_file)->i_mode;
11881 + ii_write_unlock(inode);
11885 + si_read_unlock(sb);
11886 + mutex_unlock(&inode->i_mutex);
11890 +/* ---------------------------------------------------------------------- */
11893 + * The locking order around current->mmap_sem.
11894 + * - in most and regular cases
11895 + * file I/O syscall -- aufs_read() or something
11896 + * -- si_rwsem for read -- mmap_sem
11897 + * (Note that [fdi]i_rwsem are released before mmap_sem).
11899 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
11900 + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
11901 + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
11902 + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
11903 + * It means that when aufs acquires si_rwsem for write, the process should never
11904 + * acquire mmap_sem.
11906 + * Actually aufs_readdir() holds [fdi]i_rwsem before mmap_sem, but this is not a
11907 + * problem either since any directory is not able to be mmap-ed.
11908 + * The similar scenario is applied to aufs_readlink() too.
11911 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
11912 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
11914 +static unsigned long au_arch_prot_conv(unsigned long flags)
11916 + /* currently ppc64 only */
11917 +#ifdef CONFIG_PPC64
11918 + /* cf. linux/arch/powerpc/include/asm/mman.h */
11919 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
11920 + return AuConv_VM_PROT(flags, SAO);
11922 + AuDebugOn(arch_calc_vm_prot_bits(-1));
11927 +static unsigned long au_prot_conv(unsigned long flags)
11929 + return AuConv_VM_PROT(flags, READ)
11930 + | AuConv_VM_PROT(flags, WRITE)
11931 + | AuConv_VM_PROT(flags, EXEC)
11932 + | au_arch_prot_conv(flags);
11935 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
11936 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
11938 +static unsigned long au_flag_conv(unsigned long flags)
11940 + return AuConv_VM_MAP(flags, GROWSDOWN)
11941 + | AuConv_VM_MAP(flags, DENYWRITE)
11942 + | AuConv_VM_MAP(flags, LOCKED);
11945 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
11948 + aufs_bindex_t bstart;
11949 + const unsigned char wlock
11950 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
11951 + struct dentry *dentry;
11952 + struct super_block *sb;
11953 + struct file *h_file;
11954 + struct au_branch *br;
11955 + struct au_pin pin;
11957 + AuDbgVmRegion(file, vma);
11959 + dentry = file->f_dentry;
11960 + sb = dentry->d_sb;
11962 + si_read_lock(sb, AuLock_NOPLMW);
11963 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
11964 + if (unlikely(err))
11968 + err = au_ready_to_write(file, -1, &pin);
11969 + di_write_unlock(dentry);
11970 + if (unlikely(err)) {
11971 + fi_write_unlock(file);
11976 + di_write_unlock(dentry);
11978 + bstart = au_fbstart(file);
11979 + br = au_sbr(sb, bstart);
11980 + h_file = au_hf_top(file);
11981 + get_file(h_file);
11982 + au_set_mmapped(file);
11983 + fi_write_unlock(file);
11986 + au_vm_file_reset(vma, h_file);
11987 + err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
11988 + au_flag_conv(vma->vm_flags));
11990 + err = h_file->f_op->mmap(h_file, vma);
11991 + if (unlikely(err))
11994 + au_vm_prfile_set(vma, file);
11995 + /* update without lock, I don't think it a problem */
11996 + fsstack_copy_attr_atime(file_inode(file), file_inode(h_file));
11997 + goto out_fput; /* success */
12000 + au_unset_mmapped(file);
12001 + au_vm_file_reset(vma, file);
12006 + si_read_unlock(sb);
12012 +/* ---------------------------------------------------------------------- */
12014 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
12018 + struct au_pin pin;
12019 + struct dentry *dentry;
12020 + struct inode *inode;
12021 + struct file *h_file;
12022 + struct super_block *sb;
12024 + dentry = file->f_dentry;
12025 + inode = dentry->d_inode;
12026 + sb = dentry->d_sb;
12027 + mutex_lock(&inode->i_mutex);
12028 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
12029 + if (unlikely(err))
12032 + err = 0; /* -EBADF; */ /* posix? */
12033 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
12035 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
12036 + if (unlikely(err))
12039 + err = au_ready_to_write(file, -1, &pin);
12040 + di_downgrade_lock(dentry, AuLock_IR);
12041 + if (unlikely(err))
12046 + h_file = au_hf_top(file);
12047 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
12048 + au_cpup_attr_timesizes(inode);
12051 + di_read_unlock(dentry, AuLock_IR);
12052 + fi_write_unlock(file);
12054 + si_read_unlock(sb);
12056 + mutex_unlock(&inode->i_mutex);
12060 +/* no one supports this operation, currently */
12062 +static int aufs_aio_fsync_nondir(struct kiocb *kio, int datasync)
12065 + struct au_pin pin;
12066 + struct dentry *dentry;
12067 + struct inode *inode;
12068 + struct file *file, *h_file;
12070 + file = kio->ki_filp;
12071 + dentry = file->f_dentry;
12072 + inode = dentry->d_inode;
12073 + au_mtx_and_read_lock(inode);
12075 + err = 0; /* -EBADF; */ /* posix? */
12076 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
12078 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
12079 + if (unlikely(err))
12082 + err = au_ready_to_write(file, -1, &pin);
12083 + di_downgrade_lock(dentry, AuLock_IR);
12084 + if (unlikely(err))
12089 + h_file = au_hf_top(file);
12090 + if (h_file->f_op && h_file->f_op->aio_fsync) {
12091 + struct mutex *h_mtx;
12093 + h_mtx = &file_inode(h_file)->i_mutex;
12094 + if (!is_sync_kiocb(kio)) {
12095 + get_file(h_file);
12098 + kio->ki_filp = h_file;
12099 + err = h_file->f_op->aio_fsync(kio, datasync);
12100 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
12102 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL);
12104 + au_cpup_attr_timesizes(inode);
12105 + mutex_unlock(h_mtx);
12109 + di_read_unlock(dentry, AuLock_IR);
12110 + fi_write_unlock(file);
12112 + si_read_unlock(inode->sb);
12113 + mutex_unlock(&inode->i_mutex);
12118 +static int aufs_fasync(int fd, struct file *file, int flag)
12121 + struct file *h_file;
12122 + struct dentry *dentry;
12123 + struct super_block *sb;
12125 + dentry = file->f_dentry;
12126 + sb = dentry->d_sb;
12127 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
12128 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
12129 + if (unlikely(err))
12132 + h_file = au_hf_top(file);
12133 + if (h_file->f_op && h_file->f_op->fasync)
12134 + err = h_file->f_op->fasync(fd, h_file, flag);
12136 + di_read_unlock(dentry, AuLock_IR);
12137 + fi_read_unlock(file);
12140 + si_read_unlock(sb);
12144 +/* ---------------------------------------------------------------------- */
12146 +/* no one supports this operation, currently */
12148 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
12149 + size_t len, loff_t *pos , int more)
12154 +/* ---------------------------------------------------------------------- */
12156 +const struct file_operations aufs_file_fop = {
12157 + .owner = THIS_MODULE,
12159 + .llseek = default_llseek,
12161 + .read = aufs_read,
12162 + .write = aufs_write,
12163 + .aio_read = aufs_aio_read,
12164 + .aio_write = aufs_aio_write,
12165 +#ifdef CONFIG_AUFS_POLL
12166 + .poll = aufs_poll,
12168 + .unlocked_ioctl = aufs_ioctl_nondir,
12169 +#ifdef CONFIG_COMPAT
12170 + .compat_ioctl = aufs_compat_ioctl_nondir,
12172 + .mmap = aufs_mmap,
12173 + .open = aufs_open_nondir,
12174 + .flush = aufs_flush_nondir,
12175 + .release = aufs_release_nondir,
12176 + .fsync = aufs_fsync_nondir,
12177 + /* .aio_fsync = aufs_aio_fsync_nondir, */
12178 + .fasync = aufs_fasync,
12179 + /* .sendpage = aufs_sendpage, */
12180 + .splice_write = aufs_splice_write,
12181 + .splice_read = aufs_splice_read,
12183 + .aio_splice_write = aufs_aio_splice_write,
12184 + .aio_splice_read = aufs_aio_splice_read
12187 diff -urN /usr/share/empty/fs/aufs/f_op_sp.c linux/fs/aufs/f_op_sp.c
12188 --- /usr/share/empty/fs/aufs/f_op_sp.c 1970-01-01 01:00:00.000000000 +0100
12189 +++ linux/fs/aufs/f_op_sp.c 2013-08-23 23:59:39.634916914 +0200
12192 + * Copyright (C) 2005-2013 Junjiro R. Okajima
12194 + * This program, aufs is free software; you can redistribute it and/or modify
12195 + * it under the terms of the GNU General Public License as published by
12196 + * the Free Software Foundation; either version 2 of the License, or
12197 + * (at your option) any later version.
12199 + * This program is distributed in the hope that it will be useful,
12200 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12201 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12202 + * GNU General Public License for more details.
12204 + * You should have received a copy of the GNU General Public License
12205 + * along with this program; if not, write to the Free Software
12206 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
12210 + * file operations for special files.
12211 + * while they exist in aufs virtually,
12212 + * their file I/O is handled out of aufs.
12215 +#include <linux/aio.h>
12219 + * I don't think the size of this list grows much.
12220 + * so here is a very simple list implemented in order to find finfo matching a
12223 +static struct au_sphlhead au_finfo_sp = {
12224 + .spin = __SPIN_LOCK_INITIALIZER(au_finfo_sp.spin),
12225 + .head = HLIST_HEAD_INIT
12228 +struct au_finfo_sp {
12229 + struct hlist_node hlist;
12230 + struct file *file;
12231 + struct au_finfo *finfo;
12234 +struct au_finfo *au_fi_sp(struct file *file)
12236 + struct au_finfo *finfo;
12237 + struct au_finfo_sp *sp;
12240 + spin_lock(&au_finfo_sp.spin);
12241 + hlist_for_each_entry(sp, &au_finfo_sp.head, hlist) {
12242 + if (sp->file != file)
12244 + finfo = sp->finfo;
12247 + spin_unlock(&au_finfo_sp.spin);
12252 +static int au_fi_sp_add(struct file *file)
12255 + struct au_finfo_sp *sp;
12258 + sp = kmalloc(sizeof(*sp), GFP_NOFS);
12262 + sp->finfo = file->private_data;
12263 + spin_lock(&au_finfo_sp.spin);
12264 + hlist_add_head(&sp->hlist, &au_finfo_sp.head);
12265 + spin_unlock(&au_finfo_sp.spin);
12270 +static void au_fi_sp_del(struct file *file)
12272 + struct au_finfo_sp *sp, *do_free;
12275 + spin_lock(&au_finfo_sp.spin);
12276 + hlist_for_each_entry(sp, &au_finfo_sp.head, hlist) {
12277 + if (sp->file != file)
12279 + hlist_del(&sp->hlist);
12283 + spin_unlock(&au_finfo_sp.spin);
12287 +/* ---------------------------------------------------------------------- */
12289 +static ssize_t aufs_aio_read_sp(struct kiocb *kio, const struct iovec *iov,
12290 + unsigned long nv, loff_t pos)
12293 + aufs_bindex_t bstart;
12294 + unsigned char wbr;
12295 + struct file *file, *h_file;
12296 + struct super_block *sb;
12298 + file = kio->ki_filp;
12299 + sb = file->f_dentry->d_sb;
12300 + si_read_lock(sb, AuLock_FLUSH);
12301 + fi_read_lock(file);
12302 + bstart = au_fbstart(file);
12303 + h_file = au_hf_top(file);
12304 + fi_read_unlock(file);
12305 + wbr = !!au_br_writable(au_sbr(sb, bstart)->br_perm);
12306 + si_read_unlock(sb);
12308 + /* do not change the file in kio */
12309 + AuDebugOn(!h_file->f_op || !h_file->f_op->aio_read);
12310 + err = h_file->f_op->aio_read(kio, iov, nv, pos);
12311 + if (err > 0 && wbr)
12312 + file_accessed(h_file);
12317 +static ssize_t aufs_aio_write_sp(struct kiocb *kio, const struct iovec *iov,
12318 + unsigned long nv, loff_t pos)
12321 + aufs_bindex_t bstart;
12322 + unsigned char wbr;
12323 + struct super_block *sb;
12324 + struct file *file, *h_file;
12326 + file = kio->ki_filp;
12327 + sb = file->f_dentry->d_sb;
12328 + si_read_lock(sb, AuLock_FLUSH);
12329 + fi_read_lock(file);
12330 + bstart = au_fbstart(file);
12331 + h_file = au_hf_top(file);
12332 + fi_read_unlock(file);
12333 + wbr = !!au_br_writable(au_sbr(sb, bstart)->br_perm);
12334 + si_read_unlock(sb);
12336 + /* do not change the file in kio */
12337 + AuDebugOn(!h_file->f_op || !h_file->f_op->aio_write);
12338 + err = h_file->f_op->aio_write(kio, iov, nv, pos);
12342 +/* ---------------------------------------------------------------------- */
12344 +static int aufs_release_sp(struct inode *inode, struct file *file)
12347 + struct file *h_file;
12349 + fi_read_lock(file);
12350 + h_file = au_hf_top(file);
12351 + fi_read_unlock(file);
12352 + /* close this fifo in aufs */
12353 + err = h_file->f_op->release(inode, file); /* ignore */
12354 + aufs_release_nondir(inode, file); /* ignore */
12355 + au_fi_sp_del(file);
12359 +/* ---------------------------------------------------------------------- */
12361 +/* currently, support only FIFO */
12363 + AuSp_FIFO, AuSp_FIFO_R, AuSp_FIFO_W, AuSp_FIFO_RW,
12364 + /* AuSp_SOCK, AuSp_CHR, AuSp_BLK, */
12367 +static int aufs_open_sp(struct inode *inode, struct file *file);
12368 +static struct au_sp_fop {
12370 + struct file_operations fop; /* not 'const' */
12372 +} au_sp_fop[AuSp_Last] = {
12375 + .owner = THIS_MODULE,
12376 + .open = aufs_open_sp
12381 +static void au_init_fop_sp(struct file *file)
12383 + struct au_sp_fop *p;
12385 + struct file *h_file;
12388 + if (unlikely(!p->done)) {
12389 + /* initialize first time only */
12390 + static DEFINE_SPINLOCK(spin);
12392 + spin_lock(&spin);
12394 + BUILD_BUG_ON(sizeof(au_sp_fop)/sizeof(*au_sp_fop)
12396 + for (i = 0; i < AuSp_Last; i++)
12397 + spin_lock_init(&p[i].spin);
12400 + spin_unlock(&spin);
12403 + switch (file->f_mode & (FMODE_READ | FMODE_WRITE)) {
12407 + case FMODE_WRITE:
12410 + case FMODE_READ | FMODE_WRITE:
12411 + i = AuSp_FIFO_RW;
12418 + if (unlikely(!p->done)) {
12419 + /* initialize first time only */
12420 + h_file = au_hf_top(file);
12421 + spin_lock(&p->spin);
12423 + p->fop = *h_file->f_op;
12424 + p->fop.owner = THIS_MODULE;
12425 + if (p->fop.aio_read)
12426 + p->fop.aio_read = aufs_aio_read_sp;
12427 + if (p->fop.aio_write)
12428 + p->fop.aio_write = aufs_aio_write_sp;
12429 + p->fop.release = aufs_release_sp;
12432 + spin_unlock(&p->spin);
12434 + file->f_op = &p->fop;
12437 +static int au_cpup_sp(struct dentry *dentry)
12440 + struct au_pin pin;
12441 + struct au_wr_dir_args wr_dir_args = {
12442 + .force_btgt = -1,
12445 + struct au_cp_generic cpg = {
12446 + .dentry = dentry,
12451 + .flags = AuCpup_DTIME
12454 + AuDbg("%.*s\n", AuDLNPair(dentry));
12456 + di_read_unlock(dentry, AuLock_IR);
12457 + di_write_lock_child(dentry);
12458 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
12459 + if (unlikely(err < 0))
12463 + if (cpg.bdst == au_dbstart(dentry))
12464 + goto out; /* success */
12466 + err = au_pin(&pin, dentry, cpg.bdst, au_opt_udba(dentry->d_sb),
12467 + AuPin_MNT_WRITE);
12469 + err = au_sio_cpup_simple(&cpg);
12474 + di_downgrade_lock(dentry, AuLock_IR);
12478 +static int au_do_open_sp(struct file *file, int flags)
12481 + struct dentry *dentry;
12482 + struct super_block *sb;
12483 + struct file *h_file;
12484 + struct inode *h_inode;
12486 + err = au_fi_sp_add(file);
12487 + if (unlikely(err))
12490 + dentry = file->f_dentry;
12491 + AuDbg("%.*s\n", AuDLNPair(dentry));
12494 + * try copying-up.
12495 + * operate on the ro branch is not an error.
12497 + au_cpup_sp(dentry); /* ignore */
12499 + /* prepare h_file */
12500 + err = au_do_open_nondir(file, vfsub_file_flags(file));
12501 + if (unlikely(err))
12504 + sb = dentry->d_sb;
12505 + h_file = au_hf_top(file);
12506 + h_inode = file_inode(h_file);
12507 + di_read_unlock(dentry, AuLock_IR);
12508 + fi_write_unlock(file);
12509 + si_read_unlock(sb);
12510 + /* open this fifo in aufs */
12511 + err = h_inode->i_fop->open(file_inode(file), file);
12512 + si_noflush_read_lock(sb);
12513 + fi_write_lock(file);
12514 + di_read_lock_child(dentry, AuLock_IR);
12516 + au_init_fop_sp(file);
12517 + goto out; /* success */
12521 + au_fi_sp_del(file);
12526 +static int aufs_open_sp(struct inode *inode, struct file *file)
12529 + struct super_block *sb;
12531 + sb = file->f_dentry->d_sb;
12532 + si_read_lock(sb, AuLock_FLUSH);
12533 + err = au_do_open(file, au_do_open_sp, /*fidir*/NULL);
12534 + si_read_unlock(sb);
12538 +/* ---------------------------------------------------------------------- */
12540 +void au_init_special_fop(struct inode *inode, umode_t mode, dev_t rdev)
12542 + init_special_inode(inode, mode, rdev);
12544 + switch (mode & S_IFMT) {
12546 + inode->i_fop = &au_sp_fop[AuSp_FIFO].fop;
12557 +int au_special_file(umode_t mode)
12562 + switch (mode & S_IFMT) {
12574 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
12575 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
12576 +++ linux/fs/aufs/fstype.h 2013-08-23 23:59:39.634916914 +0200
12579 + * Copyright (C) 2005-2013 Junjiro R. Okajima
12581 + * This program, aufs is free software; you can redistribute it and/or modify
12582 + * it under the terms of the GNU General Public License as published by
12583 + * the Free Software Foundation; either version 2 of the License, or
12584 + * (at your option) any later version.
12586 + * This program is distributed in the hope that it will be useful,
12587 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12588 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12589 + * GNU General Public License for more details.
12591 + * You should have received a copy of the GNU General Public License
12592 + * along with this program; if not, write to the Free Software
12593 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
12597 + * judging filesystem type
12600 +#ifndef __AUFS_FSTYPE_H__
12601 +#define __AUFS_FSTYPE_H__
12605 +#include <linux/fs.h>
12606 +#include <linux/magic.h>
12607 +#include <linux/romfs_fs.h>
12609 +static inline int au_test_aufs(struct super_block *sb)
12611 + return sb->s_magic == AUFS_SUPER_MAGIC;
12614 +static inline const char *au_sbtype(struct super_block *sb)
12616 + return sb->s_type->name;
12619 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
12621 +#if defined(CONFIG_ROMFS_FS) || defined(CONFIG_ROMFS_FS_MODULE)
12622 + return sb->s_magic == ROMFS_MAGIC;
12628 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
12630 +#if defined(CONFIG_ISO9660_FS) || defined(CONFIG_ISO9660_FS_MODULE)
12631 + return sb->s_magic == ISOFS_SUPER_MAGIC;
12637 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
12639 +#if defined(CONFIG_CRAMFS) || defined(CONFIG_CRAMFS_MODULE)
12640 + return sb->s_magic == CRAMFS_MAGIC;
12645 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
12647 +#if defined(CONFIG_NFS_FS) || defined(CONFIG_NFS_FS_MODULE)
12648 + return sb->s_magic == NFS_SUPER_MAGIC;
12654 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
12656 +#if defined(CONFIG_FUSE_FS) || defined(CONFIG_FUSE_FS_MODULE)
12657 + return sb->s_magic == FUSE_SUPER_MAGIC;
12663 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
12665 +#if defined(CONFIG_XFS_FS) || defined(CONFIG_XFS_FS_MODULE)
12666 + return sb->s_magic == XFS_SB_MAGIC;
12672 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
12674 +#ifdef CONFIG_TMPFS
12675 + return sb->s_magic == TMPFS_MAGIC;
12681 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
12683 +#if defined(CONFIG_ECRYPT_FS) || defined(CONFIG_ECRYPT_FS_MODULE)
12684 + return !strcmp(au_sbtype(sb), "ecryptfs");
12690 +static inline int au_test_ocfs2(struct super_block *sb __maybe_unused)
12692 +#if defined(CONFIG_OCFS2_FS) || defined(CONFIG_OCFS2_FS_MODULE)
12693 + return sb->s_magic == OCFS2_SUPER_MAGIC;
12699 +static inline int au_test_ocfs2_dlmfs(struct super_block *sb __maybe_unused)
12701 +#if defined(CONFIG_OCFS2_FS_O2CB) || defined(CONFIG_OCFS2_FS_O2CB_MODULE)
12702 + return sb->s_magic == DLMFS_MAGIC;
12708 +static inline int au_test_coda(struct super_block *sb __maybe_unused)
12710 +#if defined(CONFIG_CODA_FS) || defined(CONFIG_CODA_FS_MODULE)
12711 + return sb->s_magic == CODA_SUPER_MAGIC;
12717 +static inline int au_test_v9fs(struct super_block *sb __maybe_unused)
12719 +#if defined(CONFIG_9P_FS) || defined(CONFIG_9P_FS_MODULE)
12720 + return sb->s_magic == V9FS_MAGIC;
12726 +static inline int au_test_ext4(struct super_block *sb __maybe_unused)
12728 +#if defined(CONFIG_EXT4_FS) || defined(CONFIG_EXT4_FS_MODULE)
12729 + return sb->s_magic == EXT4_SUPER_MAGIC;
12735 +static inline int au_test_sysv(struct super_block *sb __maybe_unused)
12737 +#if defined(CONFIG_SYSV_FS) || defined(CONFIG_SYSV_FS_MODULE)
12738 + return !strcmp(au_sbtype(sb), "sysv");
12744 +static inline int au_test_ramfs(struct super_block *sb)
12746 + return sb->s_magic == RAMFS_MAGIC;
12749 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
12751 +#if defined(CONFIG_UBIFS_FS) || defined(CONFIG_UBIFS_FS_MODULE)
12752 + return sb->s_magic == UBIFS_SUPER_MAGIC;
12758 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
12760 +#ifdef CONFIG_PROC_FS
12761 + return sb->s_magic == PROC_SUPER_MAGIC;
12767 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
12769 +#ifdef CONFIG_SYSFS
12770 + return sb->s_magic == SYSFS_MAGIC;
12776 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
12778 +#if defined(CONFIG_CONFIGFS_FS) || defined(CONFIG_CONFIGFS_FS_MODULE)
12779 + return sb->s_magic == CONFIGFS_MAGIC;
12785 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
12787 +#if defined(CONFIG_MINIX_FS) || defined(CONFIG_MINIX_FS_MODULE)
12788 + return sb->s_magic == MINIX3_SUPER_MAGIC
12789 + || sb->s_magic == MINIX2_SUPER_MAGIC
12790 + || sb->s_magic == MINIX2_SUPER_MAGIC2
12791 + || sb->s_magic == MINIX_SUPER_MAGIC
12792 + || sb->s_magic == MINIX_SUPER_MAGIC2;
12798 +static inline int au_test_cifs(struct super_block *sb __maybe_unused)
12800 +#if defined(CONFIG_CIFS_FS) || defined(CONFIGCIFS_FS_MODULE)
12801 + return sb->s_magic == CIFS_MAGIC_NUMBER;
12807 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
12809 +#if defined(CONFIG_FAT_FS) || defined(CONFIG_FAT_FS_MODULE)
12810 + return sb->s_magic == MSDOS_SUPER_MAGIC;
12816 +static inline int au_test_msdos(struct super_block *sb)
12818 + return au_test_fat(sb);
12821 +static inline int au_test_vfat(struct super_block *sb)
12823 + return au_test_fat(sb);
12826 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
12828 +#ifdef CONFIG_SECURITYFS
12829 + return sb->s_magic == SECURITYFS_MAGIC;
12835 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
12837 +#if defined(CONFIG_SQUASHFS) || defined(CONFIG_SQUASHFS_MODULE)
12838 + return sb->s_magic == SQUASHFS_MAGIC;
12844 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
12846 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
12847 + return sb->s_magic == BTRFS_SUPER_MAGIC;
12853 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
12855 +#if defined(CONFIG_XENFS) || defined(CONFIG_XENFS_MODULE)
12856 + return sb->s_magic == XENFS_SUPER_MAGIC;
12862 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
12864 +#ifdef CONFIG_DEBUG_FS
12865 + return sb->s_magic == DEBUGFS_MAGIC;
12871 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
12873 +#if defined(CONFIG_NILFS) || defined(CONFIG_NILFS_MODULE)
12874 + return sb->s_magic == NILFS_SUPER_MAGIC;
12880 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
12882 +#if defined(CONFIG_HFSPLUS_FS) || defined(CONFIG_HFSPLUS_FS_MODULE)
12883 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
12889 +/* ---------------------------------------------------------------------- */
12891 + * they can't be an aufs branch.
12893 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
12896 +#ifndef CONFIG_AUFS_BR_RAMFS
12897 + au_test_ramfs(sb) ||
12899 + au_test_procfs(sb)
12900 + || au_test_sysfs(sb)
12901 + || au_test_configfs(sb)
12902 + || au_test_debugfs(sb)
12903 + || au_test_securityfs(sb)
12904 + || au_test_xenfs(sb)
12905 + || au_test_ecryptfs(sb)
12906 + /* || !strcmp(au_sbtype(sb), "unionfs") */
12907 + || au_test_aufs(sb); /* will be supported in next version */
12910 +static inline int au_test_fs_remote(struct super_block *sb)
12912 + return !au_test_tmpfs(sb)
12913 +#ifdef CONFIG_AUFS_BR_RAMFS
12914 + && !au_test_ramfs(sb)
12916 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
12919 +/* ---------------------------------------------------------------------- */
12922 + * Note: these functions (below) are created after reading ->getattr() in all
12923 + * filesystems under linux/fs. it means we have to do so in every update...
12927 + * some filesystems require getattr to refresh the inode attributes before
12929 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
12930 + * and leave the work for d_revalidate()
12932 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
12934 + return au_test_nfs(sb)
12935 + || au_test_fuse(sb)
12936 + /* || au_test_ocfs2(sb) */ /* untested */
12937 + /* || au_test_btrfs(sb) */ /* untested */
12938 + /* || au_test_coda(sb) */ /* untested */
12939 + /* || au_test_v9fs(sb) */ /* untested */
12944 + * filesystems which don't maintain i_size or i_blocks.
12946 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
12948 + return au_test_xfs(sb)
12949 + || au_test_btrfs(sb)
12950 + || au_test_ubifs(sb)
12951 + || au_test_hfsplus(sb) /* maintained, but incorrect */
12952 + /* || au_test_ext4(sb) */ /* untested */
12953 + /* || au_test_ocfs2(sb) */ /* untested */
12954 + /* || au_test_ocfs2_dlmfs(sb) */ /* untested */
12955 + /* || au_test_sysv(sb) */ /* untested */
12956 + /* || au_test_minix(sb) */ /* untested */
12961 + * filesystems which don't store the correct value in some of their inode
12964 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
12966 + return au_test_fs_bad_iattr_size(sb)
12967 + /* || au_test_cifs(sb) */ /* untested */
12968 + || au_test_fat(sb)
12969 + || au_test_msdos(sb)
12970 + || au_test_vfat(sb);
12973 +/* they don't check i_nlink in link(2) */
12974 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
12976 + return au_test_tmpfs(sb)
12977 +#ifdef CONFIG_AUFS_BR_RAMFS
12978 + || au_test_ramfs(sb)
12980 + || au_test_ubifs(sb)
12981 + || au_test_hfsplus(sb);
12985 + * filesystems which sets S_NOATIME and S_NOCMTIME.
12987 +static inline int au_test_fs_notime(struct super_block *sb)
12989 + return au_test_nfs(sb)
12990 + || au_test_fuse(sb)
12991 + || au_test_ubifs(sb)
12992 + /* || au_test_cifs(sb) */ /* untested */
12997 + * filesystems which requires replacing i_mapping.
12999 +static inline int au_test_fs_bad_mapping(struct super_block *sb)
13001 + return au_test_fuse(sb)
13002 + || au_test_ubifs(sb);
13005 +/* temporary support for i#1 in cramfs */
13006 +static inline int au_test_fs_unique_ino(struct inode *inode)
13008 + if (au_test_cramfs(inode->i_sb))
13009 + return inode->i_ino != 1;
13013 +/* ---------------------------------------------------------------------- */
13016 + * the filesystem where the xino files placed must support i/o after unlink and
13017 + * maintain i_size and i_blocks.
13019 +static inline int au_test_fs_bad_xino(struct super_block *sb)
13021 + return au_test_fs_remote(sb)
13022 + || au_test_fs_bad_iattr_size(sb)
13023 + /* don't want unnecessary work for xino */
13024 + || au_test_aufs(sb)
13025 + || au_test_ecryptfs(sb)
13026 + || au_test_nilfs(sb);
13029 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
13031 + return au_test_tmpfs(sb)
13032 + || au_test_ramfs(sb);
13036 + * test if the @sb is real-readonly.
13038 +static inline int au_test_fs_rr(struct super_block *sb)
13040 + return au_test_squashfs(sb)
13041 + || au_test_iso9660(sb)
13042 + || au_test_cramfs(sb)
13043 + || au_test_romfs(sb);
13046 +#endif /* __KERNEL__ */
13047 +#endif /* __AUFS_FSTYPE_H__ */
13048 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
13049 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
13050 +++ linux/fs/aufs/hfsnotify.c 2013-07-06 13:20:47.750198454 +0200
13053 + * Copyright (C) 2005-2013 Junjiro R. Okajima
13055 + * This program, aufs is free software; you can redistribute it and/or modify
13056 + * it under the terms of the GNU General Public License as published by
13057 + * the Free Software Foundation; either version 2 of the License, or
13058 + * (at your option) any later version.
13060 + * This program is distributed in the hope that it will be useful,
13061 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13062 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13063 + * GNU General Public License for more details.
13065 + * You should have received a copy of the GNU General Public License
13066 + * along with this program; if not, write to the Free Software
13067 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13071 + * fsnotify for the lower directories
13076 +/* FS_IN_IGNORED is unnecessary */
13077 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
13078 + | FS_CREATE | FS_EVENT_ON_CHILD);
13079 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
13080 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
13082 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
13084 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
13087 + au_cache_free_hnotify(hn);
13088 + smp_mb__before_atomic_dec();
13089 + if (atomic64_dec_and_test(&au_hfsn_ifree))
13090 + wake_up(&au_hfsn_wq);
13093 +static int au_hfsn_alloc(struct au_hinode *hinode)
13096 + struct au_hnotify *hn;
13097 + struct super_block *sb;
13098 + struct au_branch *br;
13099 + struct fsnotify_mark *mark;
13100 + aufs_bindex_t bindex;
13102 + hn = hinode->hi_notify;
13103 + sb = hn->hn_aufs_inode->i_sb;
13104 + bindex = au_br_index(sb, hinode->hi_id);
13105 + br = au_sbr(sb, bindex);
13106 + AuDebugOn(!br->br_hfsn);
13108 + mark = &hn->hn_mark;
13109 + fsnotify_init_mark(mark, au_hfsn_free_mark);
13110 + mark->mask = AuHfsnMask;
13112 + * by udba rename or rmdir, aufs assign a new inode to the known
13113 + * h_inode, so specify 1 to allow dups.
13115 + err = fsnotify_add_mark(mark, br->br_hfsn->hfsn_group, hinode->hi_inode,
13116 + /*mnt*/NULL, /*allow_dups*/1);
13117 + /* even if err */
13118 + fsnotify_put_mark(mark);
13123 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
13125 + struct fsnotify_mark *mark;
13126 + unsigned long long ull;
13127 + struct fsnotify_group *group;
13129 + ull = atomic64_inc_return(&au_hfsn_ifree);
13132 + mark = &hn->hn_mark;
13133 + spin_lock(&mark->lock);
13134 + group = mark->group;
13135 + fsnotify_get_group(group);
13136 + spin_unlock(&mark->lock);
13137 + fsnotify_destroy_mark(mark, group);
13138 + fsnotify_put_group(group);
13140 + /* free hn by myself */
13144 +/* ---------------------------------------------------------------------- */
13146 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
13148 + struct fsnotify_mark *mark;
13150 + mark = &hinode->hi_notify->hn_mark;
13151 + spin_lock(&mark->lock);
13153 + AuDebugOn(mark->mask & AuHfsnMask);
13154 + mark->mask |= AuHfsnMask;
13156 + AuDebugOn(!(mark->mask & AuHfsnMask));
13157 + mark->mask &= ~AuHfsnMask;
13159 + spin_unlock(&mark->lock);
13160 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
13163 +/* ---------------------------------------------------------------------- */
13165 +/* #define AuDbgHnotify */
13166 +#ifdef AuDbgHnotify
13167 +static char *au_hfsn_name(u32 mask)
13169 +#ifdef CONFIG_AUFS_DEBUG
13170 +#define test_ret(flag) \
13172 + if (mask & flag) \
13175 + test_ret(FS_ACCESS);
13176 + test_ret(FS_MODIFY);
13177 + test_ret(FS_ATTRIB);
13178 + test_ret(FS_CLOSE_WRITE);
13179 + test_ret(FS_CLOSE_NOWRITE);
13180 + test_ret(FS_OPEN);
13181 + test_ret(FS_MOVED_FROM);
13182 + test_ret(FS_MOVED_TO);
13183 + test_ret(FS_CREATE);
13184 + test_ret(FS_DELETE);
13185 + test_ret(FS_DELETE_SELF);
13186 + test_ret(FS_MOVE_SELF);
13187 + test_ret(FS_UNMOUNT);
13188 + test_ret(FS_Q_OVERFLOW);
13189 + test_ret(FS_IN_IGNORED);
13190 + test_ret(FS_IN_ISDIR);
13191 + test_ret(FS_IN_ONESHOT);
13192 + test_ret(FS_EVENT_ON_CHILD);
13201 +/* ---------------------------------------------------------------------- */
13203 +static void au_hfsn_free_group(struct fsnotify_group *group)
13205 + struct au_br_hfsnotify *hfsn = group->private;
13211 +static int au_hfsn_handle_event(struct fsnotify_group *group,
13212 + struct fsnotify_mark *inode_mark,
13213 + struct fsnotify_mark *vfsmount_mark,
13214 + struct fsnotify_event *event)
13217 + struct au_hnotify *hnotify;
13218 + struct inode *h_dir, *h_inode;
13220 + struct qstr h_child_qstr = QSTR_INIT(event->file_name, event->name_len);
13222 + AuDebugOn(event->data_type != FSNOTIFY_EVENT_INODE);
13225 + /* if FS_UNMOUNT happens, there must be another bug */
13226 + mask = event->mask;
13227 + AuDebugOn(mask & FS_UNMOUNT);
13228 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
13231 + h_dir = event->to_tell;
13232 + h_inode = event->inode;
13233 +#ifdef AuDbgHnotify
13235 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
13236 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
13237 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
13238 + h_dir->i_ino, mask, au_hfsn_name(mask),
13239 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
13240 + /* WARN_ON(1); */
13245 + AuDebugOn(!inode_mark);
13246 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
13247 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
13253 +/* isn't it waste to ask every registered 'group'? */
13254 +/* copied from linux/fs/notify/inotify/inotify_fsnotiry.c */
13255 +/* it should be exported to modules */
13256 +static bool au_hfsn_should_send_event(struct fsnotify_group *group,
13257 + struct inode *h_inode,
13258 + struct fsnotify_mark *inode_mark,
13259 + struct fsnotify_mark *vfsmount_mark,
13260 + __u32 mask, void *data, int data_type)
13262 + mask = (mask & ~FS_EVENT_ON_CHILD);
13263 + return inode_mark->mask & mask;
13266 +static struct fsnotify_ops au_hfsn_ops = {
13267 + .should_send_event = au_hfsn_should_send_event,
13268 + .handle_event = au_hfsn_handle_event,
13269 + .free_group_priv = au_hfsn_free_group
13272 +/* ---------------------------------------------------------------------- */
13274 +static void au_hfsn_fin_br(struct au_branch *br)
13276 + struct au_br_hfsnotify *hfsn;
13278 + hfsn = br->br_hfsn;
13280 + fsnotify_put_group(hfsn->hfsn_group);
13283 +static int au_hfsn_init_br(struct au_branch *br, int perm)
13286 + struct fsnotify_group *group;
13287 + struct au_br_hfsnotify *hfsn;
13290 + br->br_hfsn = NULL;
13291 + if (!au_br_hnotifyable(perm))
13295 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
13296 + if (unlikely(!hfsn))
13300 + group = fsnotify_alloc_group(&au_hfsn_ops);
13301 + if (IS_ERR(group)) {
13302 + err = PTR_ERR(group);
13303 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
13307 + group->private = hfsn;
13308 + hfsn->hfsn_group = group;
13309 + br->br_hfsn = hfsn;
13310 + goto out; /* success */
13318 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
13323 + if (!br->br_hfsn)
13324 + err = au_hfsn_init_br(br, perm);
13329 +/* ---------------------------------------------------------------------- */
13331 +static void au_hfsn_fin(void)
13333 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
13334 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
13337 +const struct au_hnotify_op au_hnotify_op = {
13338 + .ctl = au_hfsn_ctl,
13339 + .alloc = au_hfsn_alloc,
13340 + .free = au_hfsn_free,
13342 + .fin = au_hfsn_fin,
13344 + .reset_br = au_hfsn_reset_br,
13345 + .fin_br = au_hfsn_fin_br,
13346 + .init_br = au_hfsn_init_br
13348 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
13349 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
13350 +++ linux/fs/aufs/hfsplus.c 2013-07-06 13:20:47.750198454 +0200
13353 + * Copyright (C) 2010-2013 Junjiro R. Okajima
13355 + * This program, aufs is free software; you can redistribute it and/or modify
13356 + * it under the terms of the GNU General Public License as published by
13357 + * the Free Software Foundation; either version 2 of the License, or
13358 + * (at your option) any later version.
13360 + * This program is distributed in the hope that it will be useful,
13361 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13362 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13363 + * GNU General Public License for more details.
13365 + * You should have received a copy of the GNU General Public License
13366 + * along with this program; if not, write to the Free Software
13367 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13371 + * special support for filesystems which aqucires an inode mutex
13372 + * at final closing a file, eg, hfsplus.
13374 + * This trick is very simple and stupid, just to open the file before really
13375 + * neceeary open to tell hfsplus that this is not the final closing.
13376 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
13377 + * and au_h_open_post() after releasing it.
13382 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex)
13384 + struct file *h_file;
13385 + struct dentry *h_dentry;
13387 + h_dentry = au_h_dptr(dentry, bindex);
13388 + AuDebugOn(!h_dentry);
13389 + AuDebugOn(!h_dentry->d_inode);
13392 + if (au_test_hfsplus(h_dentry->d_sb)
13393 + && S_ISREG(h_dentry->d_inode->i_mode))
13394 + h_file = au_h_open(dentry, bindex,
13395 + O_RDONLY | O_NOATIME | O_LARGEFILE,
13400 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
13401 + struct file *h_file)
13405 + au_sbr_put(dentry->d_sb, bindex);
13408 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
13409 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
13410 +++ linux/fs/aufs/hnotify.c 2013-07-30 22:42:55.842946719 +0200
13413 + * Copyright (C) 2005-2013 Junjiro R. Okajima
13415 + * This program, aufs is free software; you can redistribute it and/or modify
13416 + * it under the terms of the GNU General Public License as published by
13417 + * the Free Software Foundation; either version 2 of the License, or
13418 + * (at your option) any later version.
13420 + * This program is distributed in the hope that it will be useful,
13421 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13422 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13423 + * GNU General Public License for more details.
13425 + * You should have received a copy of the GNU General Public License
13426 + * along with this program; if not, write to the Free Software
13427 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13431 + * abstraction to notify the direct changes on lower directories
13436 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
13439 + struct au_hnotify *hn;
13442 + hn = au_cache_alloc_hnotify();
13444 + hn->hn_aufs_inode = inode;
13445 + hinode->hi_notify = hn;
13446 + err = au_hnotify_op.alloc(hinode);
13448 + if (unlikely(err)) {
13449 + hinode->hi_notify = NULL;
13450 + au_cache_free_hnotify(hn);
13452 + * The upper dir was removed by udba, but the same named
13453 + * dir left. In this case, aufs assignes a new inode
13454 + * number and set the monitor again.
13455 + * For the lower dir, the old monitnor is still left.
13457 + if (err == -EEXIST)
13466 +void au_hn_free(struct au_hinode *hinode)
13468 + struct au_hnotify *hn;
13470 + hn = hinode->hi_notify;
13472 + hinode->hi_notify = NULL;
13473 + if (au_hnotify_op.free(hinode, hn))
13474 + au_cache_free_hnotify(hn);
13478 +/* ---------------------------------------------------------------------- */
13480 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
13482 + if (hinode->hi_notify)
13483 + au_hnotify_op.ctl(hinode, do_set);
13486 +void au_hn_reset(struct inode *inode, unsigned int flags)
13488 + aufs_bindex_t bindex, bend;
13489 + struct inode *hi;
13490 + struct dentry *iwhdentry;
13492 + bend = au_ibend(inode);
13493 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
13494 + hi = au_h_iptr(inode, bindex);
13498 + /* mutex_lock_nested(&hi->i_mutex, AuLsc_I_CHILD); */
13499 + iwhdentry = au_hi_wh(inode, bindex);
13503 + au_set_h_iptr(inode, bindex, NULL, 0);
13504 + au_set_h_iptr(inode, bindex, au_igrab(hi),
13505 + flags & ~AuHi_XINO);
13508 + /* mutex_unlock(&hi->i_mutex); */
13512 +/* ---------------------------------------------------------------------- */
13514 +static int hn_xino(struct inode *inode, struct inode *h_inode)
13517 + aufs_bindex_t bindex, bend, bfound, bstart;
13518 + struct inode *h_i;
13521 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
13522 + pr_warn("branch root dir was changed\n");
13527 + bend = au_ibend(inode);
13528 + bstart = au_ibstart(inode);
13529 +#if 0 /* reserved for future use */
13530 + if (bindex == bend) {
13531 + /* keep this ino in rename case */
13535 + for (bindex = bstart; bindex <= bend; bindex++)
13536 + if (au_h_iptr(inode, bindex) == h_inode) {
13543 + for (bindex = bstart; bindex <= bend; bindex++) {
13544 + h_i = au_h_iptr(inode, bindex);
13548 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
13549 + /* ignore this error */
13550 + /* bad action? */
13553 + /* children inode number will be broken */
13560 +static int hn_gen_tree(struct dentry *dentry)
13562 + int err, i, j, ndentry;
13563 + struct au_dcsub_pages dpages;
13564 + struct au_dpage *dpage;
13565 + struct dentry **dentries;
13567 + err = au_dpages_init(&dpages, GFP_NOFS);
13568 + if (unlikely(err))
13570 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
13571 + if (unlikely(err))
13574 + for (i = 0; i < dpages.ndpage; i++) {
13575 + dpage = dpages.dpages + i;
13576 + dentries = dpage->dentries;
13577 + ndentry = dpage->ndentry;
13578 + for (j = 0; j < ndentry; j++) {
13579 + struct dentry *d;
13587 + /* todo: reset children xino?
13588 + cached children only? */
13589 + au_iigen_dec(d->d_inode);
13594 + au_dpages_free(&dpages);
13597 + /* discard children */
13598 + dentry_unhash(dentry);
13606 + * return 0 if processed.
13608 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
13609 + const unsigned int isdir)
13612 + struct dentry *d;
13613 + struct qstr *dname;
13616 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
13617 + pr_warn("branch root dir was changed\n");
13623 + AuDebugOn(!name);
13624 + au_iigen_dec(inode);
13625 + spin_lock(&inode->i_lock);
13626 + hlist_for_each_entry(d, &inode->i_dentry, d_alias) {
13627 + spin_lock(&d->d_lock);
13628 + dname = &d->d_name;
13629 + if (dname->len != nlen
13630 + && memcmp(dname->name, name, nlen)) {
13631 + spin_unlock(&d->d_lock);
13636 + spin_unlock(&d->d_lock);
13639 + spin_unlock(&inode->i_lock);
13641 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
13642 + d = d_find_alias(inode);
13644 + au_iigen_dec(inode);
13648 + spin_lock(&d->d_lock);
13649 + dname = &d->d_name;
13650 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
13651 + spin_unlock(&d->d_lock);
13652 + err = hn_gen_tree(d);
13653 + spin_lock(&d->d_lock);
13655 + spin_unlock(&d->d_lock);
13664 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
13667 + struct inode *inode;
13669 + inode = dentry->d_inode;
13670 + if (IS_ROOT(dentry)
13671 + /* || (inode && inode->i_ino == AUFS_ROOT_INO) */
13673 + pr_warn("branch root dir was changed\n");
13679 + au_digen_dec(dentry);
13681 + au_iigen_dec(inode);
13683 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
13685 + err = hn_gen_tree(dentry);
13692 +/* ---------------------------------------------------------------------- */
13694 +/* hnotify job flags */
13695 +#define AuHnJob_XINO0 1
13696 +#define AuHnJob_GEN (1 << 1)
13697 +#define AuHnJob_DIRENT (1 << 2)
13698 +#define AuHnJob_ISDIR (1 << 3)
13699 +#define AuHnJob_TRYXINO0 (1 << 4)
13700 +#define AuHnJob_MNTPNT (1 << 5)
13701 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
13702 +#define au_fset_hnjob(flags, name) \
13703 + do { (flags) |= AuHnJob_##name; } while (0)
13704 +#define au_fclr_hnjob(flags, name) \
13705 + do { (flags) &= ~AuHnJob_##name; } while (0)
13713 +struct au_hnotify_args {
13714 + struct inode *h_dir, *dir, *h_child_inode;
13716 + unsigned int flags[AuHnLast];
13717 + unsigned int h_child_nlen;
13718 + char h_child_name[];
13721 +struct hn_job_args {
13722 + unsigned int flags;
13723 + struct inode *inode, *h_inode, *dir, *h_dir;
13724 + struct dentry *dentry;
13729 +static int hn_job(struct hn_job_args *a)
13731 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
13734 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
13735 + hn_xino(a->inode, a->h_inode); /* ignore this error */
13737 + if (au_ftest_hnjob(a->flags, TRYXINO0)
13740 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
13741 + if (!a->h_inode->i_nlink)
13742 + hn_xino(a->inode, a->h_inode); /* ignore this error */
13743 + mutex_unlock(&a->h_inode->i_mutex);
13746 + /* make the generation obsolete */
13747 + if (au_ftest_hnjob(a->flags, GEN)) {
13750 + err = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
13752 + if (err && a->dentry)
13753 + hn_gen_by_name(a->dentry, isdir);
13754 + /* ignore this error */
13757 + /* make dir entries obsolete */
13758 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
13759 + struct au_vdir *vdir;
13761 + vdir = au_ivdir(a->inode);
13763 + vdir->vd_jiffy = 0;
13764 + /* IMustLock(a->inode); */
13765 + /* a->inode->i_version++; */
13768 + /* can do nothing but warn */
13769 + if (au_ftest_hnjob(a->flags, MNTPNT)
13771 + && d_mountpoint(a->dentry))
13772 + pr_warn("mount-point %.*s is removed or renamed\n",
13773 + AuDLNPair(a->dentry));
13778 +/* ---------------------------------------------------------------------- */
13780 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
13781 + struct inode *dir)
13783 + struct dentry *dentry, *d, *parent;
13784 + struct qstr *dname;
13786 + parent = d_find_alias(dir);
13791 + spin_lock(&parent->d_lock);
13792 + list_for_each_entry(d, &parent->d_subdirs, d_u.d_child) {
13793 + /* AuDbg("%.*s\n", AuDLNPair(d)); */
13794 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
13795 + dname = &d->d_name;
13796 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
13797 + goto cont_unlock;
13801 + goto cont_unlock;
13802 + if (d->d_count) {
13803 + dentry = dget_dlock(d);
13804 + spin_unlock(&d->d_lock);
13809 + spin_unlock(&d->d_lock);
13811 + spin_unlock(&parent->d_lock);
13815 + di_write_lock_child(dentry);
13820 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
13821 + aufs_bindex_t bindex, ino_t h_ino)
13823 + struct inode *inode;
13828 + err = au_xino_read(sb, bindex, h_ino, &ino);
13830 + inode = ilookup(sb, ino);
13834 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
13835 + pr_warn("wrong root branch\n");
13841 + ii_write_lock_child(inode);
13847 +static void au_hn_bh(void *_args)
13849 + struct au_hnotify_args *a = _args;
13850 + struct super_block *sb;
13851 + aufs_bindex_t bindex, bend, bfound;
13852 + unsigned char xino, try_iput;
13854 + struct inode *inode;
13856 + struct hn_job_args args;
13857 + struct dentry *dentry;
13858 + struct au_sbinfo *sbinfo;
13860 + AuDebugOn(!_args);
13861 + AuDebugOn(!a->h_dir);
13862 + AuDebugOn(!a->dir);
13863 + AuDebugOn(!a->mask);
13864 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
13865 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
13866 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
13871 + * do not lock a->dir->i_mutex here
13872 + * because of d_revalidate() may cause a deadlock.
13874 + sb = a->dir->i_sb;
13876 + sbinfo = au_sbi(sb);
13877 + AuDebugOn(!sbinfo);
13878 + si_write_lock(sb, AuLock_NOPLMW);
13880 + ii_read_lock_parent(a->dir);
13882 + bend = au_ibend(a->dir);
13883 + for (bindex = au_ibstart(a->dir); bindex <= bend; bindex++)
13884 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
13888 + ii_read_unlock(a->dir);
13889 + if (unlikely(bfound < 0))
13892 + xino = !!au_opt_test(au_mntflags(sb), XINO);
13894 + if (a->h_child_inode)
13895 + h_ino = a->h_child_inode->i_ino;
13897 + if (a->h_child_nlen
13898 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
13899 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
13900 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
13904 + inode = dentry->d_inode;
13905 + if (xino && !inode && h_ino
13906 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
13907 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
13908 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
13909 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
13913 + args.flags = a->flags[AuHn_CHILD];
13914 + args.dentry = dentry;
13915 + args.inode = inode;
13916 + args.h_inode = a->h_child_inode;
13917 + args.dir = a->dir;
13918 + args.h_dir = a->h_dir;
13919 + args.h_name = a->h_child_name;
13920 + args.h_nlen = a->h_child_nlen;
13921 + err = hn_job(&args);
13923 + if (au_di(dentry))
13924 + di_write_unlock(dentry);
13927 + if (inode && try_iput) {
13928 + ii_write_unlock(inode);
13932 + ii_write_lock_parent(a->dir);
13933 + args.flags = a->flags[AuHn_PARENT];
13934 + args.dentry = NULL;
13935 + args.inode = a->dir;
13936 + args.h_inode = a->h_dir;
13938 + args.h_dir = NULL;
13939 + args.h_name = NULL;
13941 + err = hn_job(&args);
13942 + ii_write_unlock(a->dir);
13945 + iput(a->h_child_inode);
13948 + si_write_unlock(sb);
13949 + au_nwt_done(&sbinfo->si_nowait);
13953 +/* ---------------------------------------------------------------------- */
13955 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
13956 + struct qstr *h_child_qstr, struct inode *h_child_inode)
13959 + unsigned int flags[AuHnLast], f;
13960 + unsigned char isdir, isroot, wh;
13961 + struct inode *dir;
13962 + struct au_hnotify_args *args;
13963 + char *p, *h_child_name;
13966 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
13967 + dir = igrab(hnotify->hn_aufs_inode);
13971 + isroot = (dir->i_ino == AUFS_ROOT_INO);
13973 + h_child_name = (void *)h_child_qstr->name;
13974 + len = h_child_qstr->len;
13975 + if (h_child_name) {
13976 + if (len > AUFS_WH_PFX_LEN
13977 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
13978 + h_child_name += AUFS_WH_PFX_LEN;
13979 + len -= AUFS_WH_PFX_LEN;
13985 + if (h_child_inode)
13986 + isdir = !!S_ISDIR(h_child_inode->i_mode);
13987 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
13988 + flags[AuHn_CHILD] = 0;
13990 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
13991 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
13992 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
13993 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
13994 + case FS_MOVED_FROM:
13995 + case FS_MOVED_TO:
13996 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
13997 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
14000 + AuDebugOn(!h_child_name || !h_child_inode);
14005 + * aufs never be able to get this child inode.
14006 + * revalidation should be in d_revalidate()
14007 + * by checking i_nlink, i_generation or d_unhashed().
14009 + AuDebugOn(!h_child_name);
14010 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
14011 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
14019 + h_child_inode = NULL;
14022 + /* iput() and kfree() will be called in au_hnotify() */
14023 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
14024 + if (unlikely(!args)) {
14025 + AuErr1("no memory\n");
14029 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
14030 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
14031 + args->mask = mask;
14033 + args->h_dir = igrab(h_dir);
14034 + if (h_child_inode)
14035 + h_child_inode = igrab(h_child_inode); /* can be NULL */
14036 + args->h_child_inode = h_child_inode;
14037 + args->h_child_nlen = len;
14039 + p = (void *)args;
14040 + p += sizeof(*args);
14041 + memcpy(p, h_child_name, len);
14046 + if (!dir->i_nlink)
14048 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
14049 + if (unlikely(err)) {
14050 + pr_err("wkq %d\n", err);
14051 + iput(args->h_child_inode);
14052 + iput(args->h_dir);
14061 +/* ---------------------------------------------------------------------- */
14063 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
14067 + AuDebugOn(!(udba & AuOptMask_UDBA));
14070 + if (au_hnotify_op.reset_br)
14071 + err = au_hnotify_op.reset_br(udba, br, perm);
14076 +int au_hnotify_init_br(struct au_branch *br, int perm)
14081 + if (au_hnotify_op.init_br)
14082 + err = au_hnotify_op.init_br(br, perm);
14087 +void au_hnotify_fin_br(struct au_branch *br)
14089 + if (au_hnotify_op.fin_br)
14090 + au_hnotify_op.fin_br(br);
14093 +static void au_hn_destroy_cache(void)
14095 + kmem_cache_destroy(au_cachep[AuCache_HNOTIFY]);
14096 + au_cachep[AuCache_HNOTIFY] = NULL;
14099 +int __init au_hnotify_init(void)
14104 + au_cachep[AuCache_HNOTIFY] = AuCache(au_hnotify);
14105 + if (au_cachep[AuCache_HNOTIFY]) {
14107 + if (au_hnotify_op.init)
14108 + err = au_hnotify_op.init();
14109 + if (unlikely(err))
14110 + au_hn_destroy_cache();
14116 +void au_hnotify_fin(void)
14118 + if (au_hnotify_op.fin)
14119 + au_hnotify_op.fin();
14120 + /* cf. au_cache_fin() */
14121 + if (au_cachep[AuCache_HNOTIFY])
14122 + au_hn_destroy_cache();
14124 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
14125 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
14126 +++ linux/fs/aufs/iinfo.c 2013-07-06 13:20:47.750198454 +0200
14129 + * Copyright (C) 2005-2013 Junjiro R. Okajima
14131 + * This program, aufs is free software; you can redistribute it and/or modify
14132 + * it under the terms of the GNU General Public License as published by
14133 + * the Free Software Foundation; either version 2 of the License, or
14134 + * (at your option) any later version.
14136 + * This program is distributed in the hope that it will be useful,
14137 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14138 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14139 + * GNU General Public License for more details.
14141 + * You should have received a copy of the GNU General Public License
14142 + * along with this program; if not, write to the Free Software
14143 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14147 + * inode private data
14152 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
14154 + struct inode *h_inode;
14156 + IiMustAnyLock(inode);
14158 + h_inode = au_ii(inode)->ii_hinode[0 + bindex].hi_inode;
14159 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
14163 +/* todo: hard/soft set? */
14164 +void au_hiput(struct au_hinode *hinode)
14166 + au_hn_free(hinode);
14167 + dput(hinode->hi_whdentry);
14168 + iput(hinode->hi_inode);
14171 +unsigned int au_hi_flags(struct inode *inode, int isdir)
14173 + unsigned int flags;
14174 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
14177 + if (au_opt_test(mnt_flags, XINO))
14178 + au_fset_hi(flags, XINO);
14179 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
14180 + au_fset_hi(flags, HNOTIFY);
14184 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
14185 + struct inode *h_inode, unsigned int flags)
14187 + struct au_hinode *hinode;
14188 + struct inode *hi;
14189 + struct au_iinfo *iinfo = au_ii(inode);
14191 + IiMustWriteLock(inode);
14193 + hinode = iinfo->ii_hinode + bindex;
14194 + hi = hinode->hi_inode;
14195 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
14198 + au_hiput(hinode);
14199 + hinode->hi_inode = h_inode;
14202 + struct super_block *sb = inode->i_sb;
14203 + struct au_branch *br;
14205 + AuDebugOn(inode->i_mode
14206 + && (h_inode->i_mode & S_IFMT)
14207 + != (inode->i_mode & S_IFMT));
14208 + if (bindex == iinfo->ii_bstart)
14209 + au_cpup_igen(inode, h_inode);
14210 + br = au_sbr(sb, bindex);
14211 + hinode->hi_id = br->br_id;
14212 + if (au_ftest_hi(flags, XINO)) {
14213 + err = au_xino_write(sb, bindex, h_inode->i_ino,
14215 + if (unlikely(err))
14216 + AuIOErr1("failed au_xino_write() %d\n", err);
14219 + if (au_ftest_hi(flags, HNOTIFY)
14220 + && au_br_hnotifyable(br->br_perm)) {
14221 + err = au_hn_alloc(hinode, inode);
14222 + if (unlikely(err))
14223 + AuIOErr1("au_hn_alloc() %d\n", err);
14228 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
14229 + struct dentry *h_wh)
14231 + struct au_hinode *hinode;
14233 + IiMustWriteLock(inode);
14235 + hinode = au_ii(inode)->ii_hinode + bindex;
14236 + AuDebugOn(hinode->hi_whdentry);
14237 + hinode->hi_whdentry = h_wh;
14240 +void au_update_iigen(struct inode *inode, int half)
14242 + struct au_iinfo *iinfo;
14243 + struct au_iigen *iigen;
14244 + unsigned int sigen;
14246 + sigen = au_sigen(inode->i_sb);
14247 + iinfo = au_ii(inode);
14248 + iigen = &iinfo->ii_generation;
14249 + spin_lock(&iinfo->ii_genspin);
14250 + iigen->ig_generation = sigen;
14252 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
14254 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
14255 + spin_unlock(&iinfo->ii_genspin);
14258 +/* it may be called at remount time, too */
14259 +void au_update_ibrange(struct inode *inode, int do_put_zero)
14261 + struct au_iinfo *iinfo;
14262 + aufs_bindex_t bindex, bend;
14264 + iinfo = au_ii(inode);
14268 + IiMustWriteLock(inode);
14270 + if (do_put_zero && iinfo->ii_bstart >= 0) {
14271 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
14273 + struct inode *h_i;
14275 + h_i = iinfo->ii_hinode[0 + bindex].hi_inode;
14276 + if (h_i && !h_i->i_nlink)
14277 + au_set_h_iptr(inode, bindex, NULL, 0);
14281 + iinfo->ii_bstart = -1;
14282 + iinfo->ii_bend = -1;
14283 + bend = au_sbend(inode->i_sb);
14284 + for (bindex = 0; bindex <= bend; bindex++)
14285 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
14286 + iinfo->ii_bstart = bindex;
14289 + if (iinfo->ii_bstart >= 0)
14290 + for (bindex = bend; bindex >= iinfo->ii_bstart; bindex--)
14291 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
14292 + iinfo->ii_bend = bindex;
14295 + AuDebugOn(iinfo->ii_bstart > iinfo->ii_bend);
14298 +/* ---------------------------------------------------------------------- */
14300 +void au_icntnr_init_once(void *_c)
14302 + struct au_icntnr *c = _c;
14303 + struct au_iinfo *iinfo = &c->iinfo;
14304 + static struct lock_class_key aufs_ii;
14306 + spin_lock_init(&iinfo->ii_genspin);
14307 + au_rw_init(&iinfo->ii_rwsem);
14308 + au_rw_class(&iinfo->ii_rwsem, &aufs_ii);
14309 + inode_init_once(&c->vfs_inode);
14312 +int au_iinfo_init(struct inode *inode)
14314 + struct au_iinfo *iinfo;
14315 + struct super_block *sb;
14318 + sb = inode->i_sb;
14319 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
14320 + nbr = au_sbend(sb) + 1;
14321 + if (unlikely(nbr <= 0))
14323 + iinfo->ii_hinode = kcalloc(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
14324 + if (iinfo->ii_hinode) {
14325 + au_ninodes_inc(sb);
14326 + for (i = 0; i < nbr; i++)
14327 + iinfo->ii_hinode[i].hi_id = -1;
14329 + iinfo->ii_generation.ig_generation = au_sigen(sb);
14330 + iinfo->ii_bstart = -1;
14331 + iinfo->ii_bend = -1;
14332 + iinfo->ii_vdir = NULL;
14338 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr)
14341 + struct au_hinode *hip;
14343 + AuRwMustWriteLock(&iinfo->ii_rwsem);
14346 + sz = sizeof(*hip) * (iinfo->ii_bend + 1);
14348 + sz = sizeof(*hip);
14349 + hip = au_kzrealloc(iinfo->ii_hinode, sz, sizeof(*hip) * nbr, GFP_NOFS);
14351 + iinfo->ii_hinode = hip;
14358 +void au_iinfo_fin(struct inode *inode)
14360 + struct au_iinfo *iinfo;
14361 + struct au_hinode *hi;
14362 + struct super_block *sb;
14363 + aufs_bindex_t bindex, bend;
14364 + const unsigned char unlinked = !inode->i_nlink;
14366 + iinfo = au_ii(inode);
14367 + /* bad_inode case */
14371 + sb = inode->i_sb;
14372 + au_ninodes_dec(sb);
14373 + if (si_pid_test(sb))
14374 + au_xino_delete_inode(inode, unlinked);
14377 + * it is safe to hide the dependency between sbinfo and
14381 + si_noflush_read_lock(sb);
14382 + au_xino_delete_inode(inode, unlinked);
14383 + si_read_unlock(sb);
14387 + if (iinfo->ii_vdir)
14388 + au_vdir_free(iinfo->ii_vdir);
14390 + bindex = iinfo->ii_bstart;
14391 + if (bindex >= 0) {
14392 + hi = iinfo->ii_hinode + bindex;
14393 + bend = iinfo->ii_bend;
14394 + while (bindex++ <= bend) {
14395 + if (hi->hi_inode)
14400 + kfree(iinfo->ii_hinode);
14401 + iinfo->ii_hinode = NULL;
14402 + AuRwDestroy(&iinfo->ii_rwsem);
14404 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
14405 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
14406 +++ linux/fs/aufs/inode.c 2013-07-06 13:20:47.750198454 +0200
14409 + * Copyright (C) 2005-2013 Junjiro R. Okajima
14411 + * This program, aufs is free software; you can redistribute it and/or modify
14412 + * it under the terms of the GNU General Public License as published by
14413 + * the Free Software Foundation; either version 2 of the License, or
14414 + * (at your option) any later version.
14416 + * This program is distributed in the hope that it will be useful,
14417 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14418 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14419 + * GNU General Public License for more details.
14421 + * You should have received a copy of the GNU General Public License
14422 + * along with this program; if not, write to the Free Software
14423 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14427 + * inode functions
14432 +struct inode *au_igrab(struct inode *inode)
14435 + AuDebugOn(!atomic_read(&inode->i_count));
14441 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
14443 + au_cpup_attr_all(inode, /*force*/0);
14444 + au_update_iigen(inode, /*half*/1);
14446 + inode->i_version++;
14449 +static int au_ii_refresh(struct inode *inode, int *update)
14453 + aufs_bindex_t bindex, new_bindex;
14454 + struct super_block *sb;
14455 + struct au_iinfo *iinfo;
14456 + struct au_hinode *p, *q, tmp;
14458 + IiMustWriteLock(inode);
14461 + sb = inode->i_sb;
14462 + type = inode->i_mode & S_IFMT;
14463 + iinfo = au_ii(inode);
14464 + err = au_ii_realloc(iinfo, au_sbend(sb) + 1);
14465 + if (unlikely(err))
14468 + AuDebugOn(iinfo->ii_bstart < 0);
14469 + p = iinfo->ii_hinode + iinfo->ii_bstart;
14470 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
14472 + if (!p->hi_inode)
14475 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
14476 + new_bindex = au_br_index(sb, p->hi_id);
14477 + if (new_bindex == bindex)
14480 + if (new_bindex < 0) {
14483 + p->hi_inode = NULL;
14487 + if (new_bindex < iinfo->ii_bstart)
14488 + iinfo->ii_bstart = new_bindex;
14489 + if (iinfo->ii_bend < new_bindex)
14490 + iinfo->ii_bend = new_bindex;
14491 + /* swap two lower inode, and loop again */
14492 + q = iinfo->ii_hinode + new_bindex;
14496 + if (tmp.hi_inode) {
14501 + au_update_ibrange(inode, /*do_put_zero*/0);
14502 + e = au_dy_irefresh(inode);
14503 + if (unlikely(e && !err))
14511 +int au_refresh_hinode_self(struct inode *inode)
14515 + err = au_ii_refresh(inode, &update);
14517 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
14523 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
14525 + int err, e, update;
14526 + unsigned int flags;
14528 + aufs_bindex_t bindex, bend;
14529 + unsigned char isdir;
14530 + struct au_hinode *p;
14531 + struct au_iinfo *iinfo;
14533 + err = au_ii_refresh(inode, &update);
14534 + if (unlikely(err))
14538 + iinfo = au_ii(inode);
14539 + p = iinfo->ii_hinode + iinfo->ii_bstart;
14540 + mode = (inode->i_mode & S_IFMT);
14541 + isdir = S_ISDIR(mode);
14542 + flags = au_hi_flags(inode, isdir);
14543 + bend = au_dbend(dentry);
14544 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
14545 + struct inode *h_i;
14546 + struct dentry *h_d;
14548 + h_d = au_h_dptr(dentry, bindex);
14549 + if (!h_d || !h_d->d_inode)
14552 + AuDebugOn(mode != (h_d->d_inode->i_mode & S_IFMT));
14553 + if (iinfo->ii_bstart <= bindex && bindex <= iinfo->ii_bend) {
14554 + h_i = au_h_iptr(inode, bindex);
14556 + if (h_i == h_d->d_inode)
14562 + if (bindex < iinfo->ii_bstart)
14563 + iinfo->ii_bstart = bindex;
14564 + if (iinfo->ii_bend < bindex)
14565 + iinfo->ii_bend = bindex;
14566 + au_set_h_iptr(inode, bindex, au_igrab(h_d->d_inode), flags);
14569 + au_update_ibrange(inode, /*do_put_zero*/0);
14570 + e = au_dy_irefresh(inode);
14571 + if (unlikely(e && !err))
14574 + au_refresh_hinode_attr(inode, update && isdir);
14581 +static int set_inode(struct inode *inode, struct dentry *dentry)
14584 + unsigned int flags;
14586 + aufs_bindex_t bindex, bstart, btail;
14587 + unsigned char isdir;
14588 + struct dentry *h_dentry;
14589 + struct inode *h_inode;
14590 + struct au_iinfo *iinfo;
14592 + IiMustWriteLock(inode);
14596 + bstart = au_dbstart(dentry);
14597 + h_inode = au_h_dptr(dentry, bstart)->d_inode;
14598 + mode = h_inode->i_mode;
14599 + switch (mode & S_IFMT) {
14601 + btail = au_dbtail(dentry);
14602 + inode->i_op = &aufs_iop;
14603 + inode->i_fop = &aufs_file_fop;
14604 + err = au_dy_iaop(inode, bstart, h_inode);
14605 + if (unlikely(err))
14610 + btail = au_dbtaildir(dentry);
14611 + inode->i_op = &aufs_dir_iop;
14612 + inode->i_fop = &aufs_dir_fop;
14615 + btail = au_dbtail(dentry);
14616 + inode->i_op = &aufs_symlink_iop;
14622 + btail = au_dbtail(dentry);
14623 + inode->i_op = &aufs_iop;
14624 + au_init_special_fop(inode, mode, h_inode->i_rdev);
14627 + AuIOErr("Unknown file type 0%o\n", mode);
14632 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
14633 + flags = au_hi_flags(inode, isdir);
14634 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
14635 + && au_ftest_hi(flags, HNOTIFY)
14636 + && dentry->d_name.len > AUFS_WH_PFX_LEN
14637 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
14638 + au_fclr_hi(flags, HNOTIFY);
14639 + iinfo = au_ii(inode);
14640 + iinfo->ii_bstart = bstart;
14641 + iinfo->ii_bend = btail;
14642 + for (bindex = bstart; bindex <= btail; bindex++) {
14643 + h_dentry = au_h_dptr(dentry, bindex);
14645 + au_set_h_iptr(inode, bindex,
14646 + au_igrab(h_dentry->d_inode), flags);
14648 + au_cpup_attr_all(inode, /*force*/1);
14655 + * successful returns with iinfo write_locked
14657 + * zero: success, matched
14658 + * plus: no error, but unmatched
14660 +static int reval_inode(struct inode *inode, struct dentry *dentry)
14663 + unsigned int gen;
14664 + struct au_iigen iigen;
14665 + aufs_bindex_t bindex, bend;
14666 + struct inode *h_inode, *h_dinode;
14669 + * before this function, if aufs got any iinfo lock, it must be only
14670 + * one, the parent dir.
14671 + * it can happen by UDBA and the obsoleted inode number.
14674 + if (unlikely(inode->i_ino == parent_ino(dentry)))
14678 + ii_write_lock_new_child(inode);
14679 + h_dinode = au_h_dptr(dentry, au_dbstart(dentry))->d_inode;
14680 + bend = au_ibend(inode);
14681 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
14682 + h_inode = au_h_iptr(inode, bindex);
14683 + if (!h_inode || h_inode != h_dinode)
14687 + gen = au_iigen(inode, &iigen);
14688 + if (gen == au_digen(dentry)
14689 + && !au_ig_ftest(iigen.ig_flags, HALF_REFRESHED))
14692 + /* fully refresh inode using dentry */
14693 + err = au_refresh_hinode(inode, dentry);
14695 + au_update_iigen(inode, /*half*/0);
14699 + if (unlikely(err))
14700 + ii_write_unlock(inode);
14705 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
14706 + unsigned int d_type, ino_t *ino)
14709 + struct mutex *mtx;
14711 + /* prevent hardlinked inode number from race condition */
14713 + if (d_type != DT_DIR) {
14714 + mtx = &au_sbr(sb, bindex)->br_xino.xi_nondir_mtx;
14717 + err = au_xino_read(sb, bindex, h_ino, ino);
14718 + if (unlikely(err))
14723 + *ino = au_xino_new_ino(sb);
14724 + if (unlikely(!*ino))
14726 + err = au_xino_write(sb, bindex, h_ino, *ino);
14727 + if (unlikely(err))
14733 + mutex_unlock(mtx);
14737 +/* successful returns with iinfo write_locked */
14738 +/* todo: return with unlocked? */
14739 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
14741 + struct inode *inode, *h_inode;
14742 + struct dentry *h_dentry;
14743 + struct super_block *sb;
14744 + struct mutex *mtx;
14745 + ino_t h_ino, ino;
14747 + aufs_bindex_t bstart;
14749 + sb = dentry->d_sb;
14750 + bstart = au_dbstart(dentry);
14751 + h_dentry = au_h_dptr(dentry, bstart);
14752 + h_inode = h_dentry->d_inode;
14753 + h_ino = h_inode->i_ino;
14756 + * stop 'race'-ing between hardlinks under different
14760 + if (!S_ISDIR(h_inode->i_mode))
14761 + mtx = &au_sbr(sb, bstart)->br_xino.xi_nondir_mtx;
14766 + err = au_xino_read(sb, bstart, h_ino, &ino);
14767 + inode = ERR_PTR(err);
14768 + if (unlikely(err))
14772 + ino = au_xino_new_ino(sb);
14773 + if (unlikely(!ino)) {
14774 + inode = ERR_PTR(-EIO);
14779 + AuDbg("i%lu\n", (unsigned long)ino);
14780 + inode = au_iget_locked(sb, ino);
14781 + err = PTR_ERR(inode);
14782 + if (IS_ERR(inode))
14785 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
14786 + if (inode->i_state & I_NEW) {
14787 + /* verbose coding for lock class name */
14788 + if (unlikely(S_ISLNK(h_inode->i_mode)))
14789 + au_rw_class(&au_ii(inode)->ii_rwsem,
14790 + au_lc_key + AuLcSymlink_IIINFO);
14791 + else if (unlikely(S_ISDIR(h_inode->i_mode)))
14792 + au_rw_class(&au_ii(inode)->ii_rwsem,
14793 + au_lc_key + AuLcDir_IIINFO);
14794 + else /* likely */
14795 + au_rw_class(&au_ii(inode)->ii_rwsem,
14796 + au_lc_key + AuLcNonDir_IIINFO);
14798 + ii_write_lock_new_child(inode);
14799 + err = set_inode(inode, dentry);
14801 + unlock_new_inode(inode);
14802 + goto out; /* success */
14806 + * iget_failed() calls iput(), but we need to call
14807 + * ii_write_unlock() after iget_failed(). so dirty hack for
14810 + atomic_inc(&inode->i_count);
14811 + iget_failed(inode);
14812 + ii_write_unlock(inode);
14813 + au_xino_write(sb, bstart, h_ino, /*ino*/0);
14814 + /* ignore this error */
14816 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
14818 + * horrible race condition between lookup, readdir and copyup
14819 + * (or something).
14822 + mutex_unlock(mtx);
14823 + err = reval_inode(inode, dentry);
14824 + if (unlikely(err < 0)) {
14831 + goto out; /* success */
14836 + if (unlikely(au_test_fs_unique_ino(h_dentry->d_inode)))
14837 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
14838 + " b%d, %s, %.*s, hi%lu, i%lu.\n",
14839 + bstart, au_sbtype(h_dentry->d_sb), AuDLNPair(dentry),
14840 + (unsigned long)h_ino, (unsigned long)ino);
14842 + err = au_xino_write(sb, bstart, h_ino, /*ino*/0);
14846 + mutex_unlock(mtx);
14852 + inode = ERR_PTR(err);
14855 + mutex_unlock(mtx);
14859 +/* ---------------------------------------------------------------------- */
14861 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
14862 + struct inode *inode)
14866 + err = au_br_rdonly(au_sbr(sb, bindex));
14868 + /* pseudo-link after flushed may happen out of bounds */
14871 + && au_ibstart(inode) <= bindex
14872 + && bindex <= au_ibend(inode)) {
14874 + * permission check is unnecessary since vfsub routine
14875 + * will be called later
14877 + struct inode *hi = au_h_iptr(inode, bindex);
14879 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
14885 +int au_test_h_perm(struct inode *h_inode, int mask)
14887 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
14889 + return inode_permission(h_inode, mask);
14892 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
14894 + if (au_test_nfs(h_inode->i_sb)
14895 + && (mask & MAY_WRITE)
14896 + && S_ISDIR(h_inode->i_mode))
14897 + mask |= MAY_READ; /* force permission check */
14898 + return au_test_h_perm(h_inode, mask);
14900 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
14901 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
14902 +++ linux/fs/aufs/inode.h 2013-07-06 13:20:47.750198454 +0200
14905 + * Copyright (C) 2005-2013 Junjiro R. Okajima
14907 + * This program, aufs is free software; you can redistribute it and/or modify
14908 + * it under the terms of the GNU General Public License as published by
14909 + * the Free Software Foundation; either version 2 of the License, or
14910 + * (at your option) any later version.
14912 + * This program is distributed in the hope that it will be useful,
14913 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14914 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14915 + * GNU General Public License for more details.
14917 + * You should have received a copy of the GNU General Public License
14918 + * along with this program; if not, write to the Free Software
14919 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14923 + * inode operations
14926 +#ifndef __AUFS_INODE_H__
14927 +#define __AUFS_INODE_H__
14931 +#include <linux/fsnotify.h>
14932 +#include "rwsem.h"
14936 +struct au_hnotify {
14937 +#ifdef CONFIG_AUFS_HNOTIFY
14938 +#ifdef CONFIG_AUFS_HFSNOTIFY
14939 + /* never use fsnotify_add_vfsmount_mark() */
14940 + struct fsnotify_mark hn_mark;
14942 + struct inode *hn_aufs_inode; /* no get/put */
14944 +} ____cacheline_aligned_in_smp;
14946 +struct au_hinode {
14947 + struct inode *hi_inode;
14948 + aufs_bindex_t hi_id;
14949 +#ifdef CONFIG_AUFS_HNOTIFY
14950 + struct au_hnotify *hi_notify;
14953 + /* reference to the copied-up whiteout with get/put */
14954 + struct dentry *hi_whdentry;
14958 +#define AuIG_HALF_REFRESHED 1
14959 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
14960 +#define au_ig_fset(flags, name) \
14961 + do { (flags) |= AuIG_##name; } while (0)
14962 +#define au_ig_fclr(flags, name) \
14963 + do { (flags) &= ~AuIG_##name; } while (0)
14966 + __u32 ig_generation, ig_flags;
14971 + spinlock_t ii_genspin;
14972 + struct au_iigen ii_generation;
14973 + struct super_block *ii_hsb1; /* no get/put */
14975 + struct au_rwsem ii_rwsem;
14976 + aufs_bindex_t ii_bstart, ii_bend;
14978 + struct au_hinode *ii_hinode;
14979 + struct au_vdir *ii_vdir;
14982 +struct au_icntnr {
14983 + struct au_iinfo iinfo;
14984 + struct inode vfs_inode;
14985 +} ____cacheline_aligned_in_smp;
14987 +/* au_pin flags */
14988 +#define AuPin_DI_LOCKED 1
14989 +#define AuPin_MNT_WRITE (1 << 1)
14990 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
14991 +#define au_fset_pin(flags, name) \
14992 + do { (flags) |= AuPin_##name; } while (0)
14993 +#define au_fclr_pin(flags, name) \
14994 + do { (flags) &= ~AuPin_##name; } while (0)
14998 + struct dentry *dentry;
14999 + unsigned int udba;
15000 + unsigned char lsc_di, lsc_hi, flags;
15001 + aufs_bindex_t bindex;
15004 + struct dentry *parent;
15005 + struct au_hinode *hdir;
15006 + struct vfsmount *h_mnt;
15008 + /* temporary unlock/relock for copyup */
15009 + struct dentry *h_dentry, *h_parent;
15010 + struct au_branch *br;
15011 + struct task_struct *task;
15014 +void au_pin_hdir_unlock(struct au_pin *p);
15015 +int au_pin_hdir_relock(struct au_pin *p);
15016 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task);
15017 +void au_pin_hdir_acquire_nest(struct au_pin *p);
15018 +void au_pin_hdir_release(struct au_pin *p);
15020 +/* ---------------------------------------------------------------------- */
15022 +static inline struct au_iinfo *au_ii(struct inode *inode)
15024 + struct au_iinfo *iinfo;
15026 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
15027 + if (iinfo->ii_hinode)
15029 + return NULL; /* debugging bad_inode case */
15032 +/* ---------------------------------------------------------------------- */
15035 +struct inode *au_igrab(struct inode *inode);
15036 +int au_refresh_hinode_self(struct inode *inode);
15037 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
15038 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
15039 + unsigned int d_type, ino_t *ino);
15040 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
15041 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
15042 + struct inode *inode);
15043 +int au_test_h_perm(struct inode *h_inode, int mask);
15044 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
15046 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
15047 + ino_t h_ino, unsigned int d_type, ino_t *ino)
15049 +#ifdef CONFIG_AUFS_SHWH
15050 + return au_ino(sb, bindex, h_ino, d_type, ino);
15057 +extern struct inode_operations aufs_iop, aufs_symlink_iop, aufs_dir_iop;
15059 +/* au_wr_dir flags */
15060 +#define AuWrDir_ADD_ENTRY 1
15061 +#define AuWrDir_TMP_WHENTRY (1 << 1)
15062 +#define AuWrDir_ISDIR (1 << 2)
15063 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
15064 +#define au_fset_wrdir(flags, name) \
15065 + do { (flags) |= AuWrDir_##name; } while (0)
15066 +#define au_fclr_wrdir(flags, name) \
15067 + do { (flags) &= ~AuWrDir_##name; } while (0)
15069 +struct au_wr_dir_args {
15070 + aufs_bindex_t force_btgt;
15071 + unsigned char flags;
15073 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
15074 + struct au_wr_dir_args *args);
15076 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
15077 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
15078 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
15079 + unsigned int udba, unsigned char flags);
15080 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
15081 + unsigned int udba, unsigned char flags) __must_check;
15082 +int au_do_pin(struct au_pin *pin) __must_check;
15083 +void au_unpin(struct au_pin *pin);
15086 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
15087 + struct dentry *h_parent, int isdir);
15088 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
15090 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
15091 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
15093 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
15094 + struct dentry *dentry);
15095 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
15098 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
15099 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
15100 + struct dentry *h_parent, int isdir);
15101 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
15102 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
15105 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
15106 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
15107 + struct inode *dir, struct dentry *dentry);
15110 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
15111 +void au_hiput(struct au_hinode *hinode);
15112 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
15113 + struct dentry *h_wh);
15114 +unsigned int au_hi_flags(struct inode *inode, int isdir);
15116 +/* hinode flags */
15117 +#define AuHi_XINO 1
15118 +#define AuHi_HNOTIFY (1 << 1)
15119 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
15120 +#define au_fset_hi(flags, name) \
15121 + do { (flags) |= AuHi_##name; } while (0)
15122 +#define au_fclr_hi(flags, name) \
15123 + do { (flags) &= ~AuHi_##name; } while (0)
15125 +#ifndef CONFIG_AUFS_HNOTIFY
15126 +#undef AuHi_HNOTIFY
15127 +#define AuHi_HNOTIFY 0
15130 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
15131 + struct inode *h_inode, unsigned int flags);
15133 +void au_update_iigen(struct inode *inode, int half);
15134 +void au_update_ibrange(struct inode *inode, int do_put_zero);
15136 +void au_icntnr_init_once(void *_c);
15137 +int au_iinfo_init(struct inode *inode);
15138 +void au_iinfo_fin(struct inode *inode);
15139 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr);
15141 +#ifdef CONFIG_PROC_FS
15143 +int au_plink_maint(struct super_block *sb, int flags);
15144 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
15145 +int au_plink_maint_enter(struct super_block *sb);
15146 +#ifdef CONFIG_AUFS_DEBUG
15147 +void au_plink_list(struct super_block *sb);
15149 +AuStubVoid(au_plink_list, struct super_block *sb)
15151 +int au_plink_test(struct inode *inode);
15152 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
15153 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
15154 + struct dentry *h_dentry);
15155 +void au_plink_put(struct super_block *sb, int verbose);
15156 +void au_plink_clean(struct super_block *sb, int verbose);
15157 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
15159 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
15160 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
15161 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
15162 +AuStubVoid(au_plink_list, struct super_block *sb);
15163 +AuStubInt0(au_plink_test, struct inode *inode);
15164 +AuStub(struct dentry *, au_plink_lkup, return NULL,
15165 + struct inode *inode, aufs_bindex_t bindex);
15166 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
15167 + struct dentry *h_dentry);
15168 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
15169 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
15170 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
15171 +#endif /* CONFIG_PROC_FS */
15173 +/* ---------------------------------------------------------------------- */
15175 +/* lock subclass for iinfo */
15177 + AuLsc_II_CHILD, /* child first */
15178 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
15179 + AuLsc_II_CHILD3, /* copyup dirs */
15180 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
15181 + AuLsc_II_PARENT2,
15182 + AuLsc_II_PARENT3, /* copyup dirs */
15183 + AuLsc_II_NEW_CHILD
15187 + * ii_read_lock_child, ii_write_lock_child,
15188 + * ii_read_lock_child2, ii_write_lock_child2,
15189 + * ii_read_lock_child3, ii_write_lock_child3,
15190 + * ii_read_lock_parent, ii_write_lock_parent,
15191 + * ii_read_lock_parent2, ii_write_lock_parent2,
15192 + * ii_read_lock_parent3, ii_write_lock_parent3,
15193 + * ii_read_lock_new_child, ii_write_lock_new_child,
15195 +#define AuReadLockFunc(name, lsc) \
15196 +static inline void ii_read_lock_##name(struct inode *i) \
15198 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
15201 +#define AuWriteLockFunc(name, lsc) \
15202 +static inline void ii_write_lock_##name(struct inode *i) \
15204 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
15207 +#define AuRWLockFuncs(name, lsc) \
15208 + AuReadLockFunc(name, lsc) \
15209 + AuWriteLockFunc(name, lsc)
15211 +AuRWLockFuncs(child, CHILD);
15212 +AuRWLockFuncs(child2, CHILD2);
15213 +AuRWLockFuncs(child3, CHILD3);
15214 +AuRWLockFuncs(parent, PARENT);
15215 +AuRWLockFuncs(parent2, PARENT2);
15216 +AuRWLockFuncs(parent3, PARENT3);
15217 +AuRWLockFuncs(new_child, NEW_CHILD);
15219 +#undef AuReadLockFunc
15220 +#undef AuWriteLockFunc
15221 +#undef AuRWLockFuncs
15224 + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock
15226 +AuSimpleUnlockRwsemFuncs(ii, struct inode *i, &au_ii(i)->ii_rwsem);
15228 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
15229 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
15230 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
15232 +/* ---------------------------------------------------------------------- */
15234 +static inline void au_icntnr_init(struct au_icntnr *c)
15236 +#ifdef CONFIG_AUFS_DEBUG
15237 + c->vfs_inode.i_mode = 0;
15241 +static inline unsigned int au_iigen(struct inode *inode, struct au_iigen *iigen)
15243 + unsigned int gen;
15244 + struct au_iinfo *iinfo;
15246 + iinfo = au_ii(inode);
15247 + spin_lock(&iinfo->ii_genspin);
15249 + *iigen = iinfo->ii_generation;
15250 + gen = iinfo->ii_generation.ig_generation;
15251 + spin_unlock(&iinfo->ii_genspin);
15256 +/* tiny test for inode number */
15257 +/* tmpfs generation is too rough */
15258 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
15260 + struct au_iinfo *iinfo;
15262 + iinfo = au_ii(inode);
15263 + AuRwMustAnyLock(&iinfo->ii_rwsem);
15264 + return !(iinfo->ii_hsb1 == h_inode->i_sb
15265 + && iinfo->ii_higen == h_inode->i_generation);
15268 +static inline void au_iigen_dec(struct inode *inode)
15270 + struct au_iinfo *iinfo;
15272 + iinfo = au_ii(inode);
15273 + spin_lock(&iinfo->ii_genspin);
15274 + iinfo->ii_generation.ig_generation--;
15275 + spin_unlock(&iinfo->ii_genspin);
15278 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
15283 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
15289 +/* ---------------------------------------------------------------------- */
15291 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
15292 + aufs_bindex_t bindex)
15294 + IiMustAnyLock(inode);
15295 + return au_ii(inode)->ii_hinode[0 + bindex].hi_id;
15298 +static inline aufs_bindex_t au_ibstart(struct inode *inode)
15300 + IiMustAnyLock(inode);
15301 + return au_ii(inode)->ii_bstart;
15304 +static inline aufs_bindex_t au_ibend(struct inode *inode)
15306 + IiMustAnyLock(inode);
15307 + return au_ii(inode)->ii_bend;
15310 +static inline struct au_vdir *au_ivdir(struct inode *inode)
15312 + IiMustAnyLock(inode);
15313 + return au_ii(inode)->ii_vdir;
15316 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
15318 + IiMustAnyLock(inode);
15319 + return au_ii(inode)->ii_hinode[0 + bindex].hi_whdentry;
15322 +static inline void au_set_ibstart(struct inode *inode, aufs_bindex_t bindex)
15324 + IiMustWriteLock(inode);
15325 + au_ii(inode)->ii_bstart = bindex;
15328 +static inline void au_set_ibend(struct inode *inode, aufs_bindex_t bindex)
15330 + IiMustWriteLock(inode);
15331 + au_ii(inode)->ii_bend = bindex;
15334 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
15336 + IiMustWriteLock(inode);
15337 + au_ii(inode)->ii_vdir = vdir;
15340 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
15342 + IiMustAnyLock(inode);
15343 + return au_ii(inode)->ii_hinode + bindex;
15346 +/* ---------------------------------------------------------------------- */
15348 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
15351 + return pin->parent;
15355 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
15357 + if (pin && pin->hdir)
15358 + return pin->hdir->hi_inode;
15362 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
15365 + return pin->hdir;
15369 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
15372 + pin->dentry = dentry;
15375 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
15376 + unsigned char lflag)
15380 + au_fset_pin(pin->flags, DI_LOCKED);
15382 + au_fclr_pin(pin->flags, DI_LOCKED);
15386 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
15389 + dput(pin->parent);
15390 + pin->parent = dget(parent);
15394 +/* ---------------------------------------------------------------------- */
15397 +#ifdef CONFIG_AUFS_HNOTIFY
15398 +struct au_hnotify_op {
15399 + void (*ctl)(struct au_hinode *hinode, int do_set);
15400 + int (*alloc)(struct au_hinode *hinode);
15403 + * if it returns true, the the caller should free hinode->hi_notify,
15404 + * otherwise ->free() frees it.
15406 + int (*free)(struct au_hinode *hinode,
15407 + struct au_hnotify *hn) __must_check;
15409 + void (*fin)(void);
15410 + int (*init)(void);
15412 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
15413 + void (*fin_br)(struct au_branch *br);
15414 + int (*init_br)(struct au_branch *br, int perm);
15418 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
15419 +void au_hn_free(struct au_hinode *hinode);
15420 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
15421 +void au_hn_reset(struct inode *inode, unsigned int flags);
15422 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
15423 + struct qstr *h_child_qstr, struct inode *h_child_inode);
15424 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
15425 +int au_hnotify_init_br(struct au_branch *br, int perm);
15426 +void au_hnotify_fin_br(struct au_branch *br);
15427 +int __init au_hnotify_init(void);
15428 +void au_hnotify_fin(void);
15431 +extern const struct au_hnotify_op au_hnotify_op;
15434 +void au_hn_init(struct au_hinode *hinode)
15436 + hinode->hi_notify = NULL;
15439 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
15441 + return hinode->hi_notify;
15446 +int au_hn_alloc(struct au_hinode *hinode __maybe_unused,
15447 + struct inode *inode __maybe_unused)
15449 + return -EOPNOTSUPP;
15452 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
15457 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
15458 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
15459 + int do_set __maybe_unused)
15460 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
15461 + unsigned int flags __maybe_unused)
15462 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
15463 + struct au_branch *br __maybe_unused,
15464 + int perm __maybe_unused)
15465 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
15466 + int perm __maybe_unused)
15467 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
15468 +AuStubInt0(__init au_hnotify_init, void)
15469 +AuStubVoid(au_hnotify_fin, void)
15470 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
15471 +#endif /* CONFIG_AUFS_HNOTIFY */
15473 +static inline void au_hn_suspend(struct au_hinode *hdir)
15475 + au_hn_ctl(hdir, /*do_set*/0);
15478 +static inline void au_hn_resume(struct au_hinode *hdir)
15480 + au_hn_ctl(hdir, /*do_set*/1);
15483 +static inline void au_hn_imtx_lock(struct au_hinode *hdir)
15485 + mutex_lock(&hdir->hi_inode->i_mutex);
15486 + au_hn_suspend(hdir);
15489 +static inline void au_hn_imtx_lock_nested(struct au_hinode *hdir,
15490 + unsigned int sc __maybe_unused)
15492 + mutex_lock_nested(&hdir->hi_inode->i_mutex, sc);
15493 + au_hn_suspend(hdir);
15496 +static inline void au_hn_imtx_unlock(struct au_hinode *hdir)
15498 + au_hn_resume(hdir);
15499 + mutex_unlock(&hdir->hi_inode->i_mutex);
15502 +#endif /* __KERNEL__ */
15503 +#endif /* __AUFS_INODE_H__ */
15504 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
15505 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
15506 +++ linux/fs/aufs/ioctl.c 2013-08-23 23:59:39.634916914 +0200
15509 + * Copyright (C) 2005-2013 Junjiro R. Okajima
15511 + * This program, aufs is free software; you can redistribute it and/or modify
15512 + * it under the terms of the GNU General Public License as published by
15513 + * the Free Software Foundation; either version 2 of the License, or
15514 + * (at your option) any later version.
15516 + * This program is distributed in the hope that it will be useful,
15517 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15518 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15519 + * GNU General Public License for more details.
15521 + * You should have received a copy of the GNU General Public License
15522 + * along with this program; if not, write to the Free Software
15523 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15528 + * plink-management and readdir in userspace.
15529 + * assist the pathconf(3) wrapper library.
15533 +#include <linux/compat.h>
15534 +#include <linux/file.h>
15537 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
15540 + aufs_bindex_t wbi, bindex, bend;
15541 + struct file *h_file;
15542 + struct super_block *sb;
15543 + struct dentry *root;
15544 + struct au_branch *br;
15545 + struct aufs_wbr_fd wbrfd = {
15546 + .oflags = au_dir_roflags,
15549 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
15550 + | O_NOATIME | O_CLOEXEC;
15552 + AuDebugOn(wbrfd.oflags & ~valid);
15555 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
15556 + if (unlikely(err)) {
15562 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
15563 + wbrfd.oflags |= au_dir_roflags;
15564 + AuDbg("0%o\n", wbrfd.oflags);
15565 + if (unlikely(wbrfd.oflags & ~valid))
15569 + fd = get_unused_fd();
15571 + if (unlikely(fd < 0))
15574 + h_file = ERR_PTR(-EINVAL);
15577 + sb = path->dentry->d_sb;
15578 + root = sb->s_root;
15579 + aufs_read_lock(root, AuLock_IR);
15580 + bend = au_sbend(sb);
15581 + if (wbrfd.brid >= 0) {
15582 + wbi = au_br_index(sb, wbrfd.brid);
15583 + if (unlikely(wbi < 0 || wbi > bend))
15587 + h_file = ERR_PTR(-ENOENT);
15588 + br = au_sbr(sb, wbi);
15589 + if (!au_br_writable(br->br_perm)) {
15593 + bindex = wbi + 1;
15595 + for (; bindex <= bend; bindex++) {
15596 + br = au_sbr(sb, bindex);
15597 + if (au_br_writable(br->br_perm)) {
15599 + br = au_sbr(sb, wbi);
15604 + AuDbg("wbi %d\n", wbi);
15606 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL);
15609 + aufs_read_unlock(root, AuLock_IR);
15610 + err = PTR_ERR(h_file);
15611 + if (IS_ERR(h_file))
15614 + atomic_dec(&br->br_count); /* cf. au_h_open() */
15615 + fd_install(fd, h_file);
15617 + goto out; /* success */
15620 + put_unused_fd(fd);
15626 +/* ---------------------------------------------------------------------- */
15628 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
15633 + case AUFS_CTL_RDU:
15634 + case AUFS_CTL_RDU_INO:
15635 + err = au_rdu_ioctl(file, cmd, arg);
15638 + case AUFS_CTL_WBR_FD:
15639 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
15642 + case AUFS_CTL_IBUSY:
15643 + err = au_ibusy_ioctl(file, arg);
15647 + /* do not call the lower */
15648 + AuDbg("0x%x\n", cmd);
15656 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
15661 + case AUFS_CTL_MVDOWN:
15662 + WARN_ONCE(1, "move-down is still testing...\n");
15663 + err = au_mvdown(file->f_dentry, (void __user *)arg);
15666 + case AUFS_CTL_WBR_FD:
15667 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
15671 + /* do not call the lower */
15672 + AuDbg("0x%x\n", cmd);
15680 +#ifdef CONFIG_COMPAT
15681 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15682 + unsigned long arg)
15687 + case AUFS_CTL_RDU:
15688 + case AUFS_CTL_RDU_INO:
15689 + err = au_rdu_compat_ioctl(file, cmd, arg);
15692 + case AUFS_CTL_IBUSY:
15693 + err = au_ibusy_compat_ioctl(file, arg);
15697 + err = aufs_ioctl_dir(file, cmd, arg);
15704 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15705 + unsigned long arg)
15707 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
15710 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
15711 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
15712 +++ linux/fs/aufs/i_op_add.c 2013-08-23 23:59:39.634916914 +0200
15715 + * Copyright (C) 2005-2013 Junjiro R. Okajima
15717 + * This program, aufs is free software; you can redistribute it and/or modify
15718 + * it under the terms of the GNU General Public License as published by
15719 + * the Free Software Foundation; either version 2 of the License, or
15720 + * (at your option) any later version.
15722 + * This program is distributed in the hope that it will be useful,
15723 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15724 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15725 + * GNU General Public License for more details.
15727 + * You should have received a copy of the GNU General Public License
15728 + * along with this program; if not, write to the Free Software
15729 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15733 + * inode operations (add entry)
15739 + * final procedure of adding a new entry, except link(2).
15740 + * remove whiteout, instantiate, copyup the parent dir's times and size
15741 + * and update version.
15742 + * if it failed, re-create the removed whiteout.
15744 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
15745 + struct dentry *wh_dentry, struct dentry *dentry)
15748 + aufs_bindex_t bwh;
15749 + struct path h_path;
15750 + struct inode *inode, *h_dir;
15751 + struct dentry *wh;
15755 + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
15756 + IMustLock(h_dir);
15757 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
15758 + bwh = au_dbwh(dentry);
15759 + h_path.dentry = wh_dentry;
15760 + h_path.mnt = au_sbr_mnt(dir->i_sb, bindex);
15761 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
15763 + if (unlikely(err))
15767 + inode = au_new_inode(dentry, /*must_new*/1);
15768 + if (!IS_ERR(inode)) {
15769 + d_instantiate(dentry, inode);
15770 + dir = dentry->d_parent->d_inode; /* dir inode is locked */
15772 + if (au_ibstart(dir) == au_dbstart(dentry))
15773 + au_cpup_attr_timesizes(dir);
15774 + dir->i_version++;
15775 + return 0; /* success */
15778 + err = PTR_ERR(inode);
15783 + /* dir inode is locked */
15784 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
15785 + rerr = PTR_ERR(wh);
15786 + if (IS_ERR(wh)) {
15787 + AuIOErr("%.*s reverting whiteout failed(%d, %d)\n",
15788 + AuDLNPair(dentry), err, rerr);
15797 +static int au_d_may_add(struct dentry *dentry)
15802 + if (unlikely(d_unhashed(dentry)))
15804 + if (unlikely(dentry->d_inode))
15810 + * simple tests for the adding inode operations.
15811 + * following the checks in vfs, plus the parent-child relationship.
15813 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
15814 + struct dentry *h_parent, int isdir)
15818 + struct dentry *h_dentry;
15819 + struct inode *h_inode;
15821 + err = -ENAMETOOLONG;
15822 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
15825 + h_dentry = au_h_dptr(dentry, bindex);
15826 + h_inode = h_dentry->d_inode;
15827 + if (!dentry->d_inode) {
15829 + if (unlikely(h_inode))
15832 + /* rename(2) case */
15834 + if (unlikely(!h_inode || !h_inode->i_nlink))
15837 + h_mode = h_inode->i_mode;
15840 + if (unlikely(S_ISDIR(h_mode)))
15842 + } else if (unlikely(!S_ISDIR(h_mode))) {
15849 + /* expected parent dir is locked */
15850 + if (unlikely(h_parent != h_dentry->d_parent))
15859 + * initial procedure of adding a new entry.
15860 + * prepare writable branch and the parent dir, lock it,
15861 + * and lookup whiteout for the new entry.
15863 +static struct dentry*
15864 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
15865 + struct dentry *src_dentry, struct au_pin *pin,
15866 + struct au_wr_dir_args *wr_dir_args)
15868 + struct dentry *wh_dentry, *h_parent;
15869 + struct super_block *sb;
15870 + struct au_branch *br;
15872 + unsigned int udba;
15873 + aufs_bindex_t bcpup;
15875 + AuDbg("%.*s\n", AuDLNPair(dentry));
15877 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
15879 + wh_dentry = ERR_PTR(err);
15880 + if (unlikely(err < 0))
15883 + sb = dentry->d_sb;
15884 + udba = au_opt_udba(sb);
15885 + err = au_pin(pin, dentry, bcpup, udba,
15886 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
15887 + wh_dentry = ERR_PTR(err);
15888 + if (unlikely(err))
15891 + h_parent = au_pinned_h_parent(pin);
15892 + if (udba != AuOpt_UDBA_NONE
15893 + && au_dbstart(dentry) == bcpup)
15894 + err = au_may_add(dentry, bcpup, h_parent,
15895 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
15896 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
15897 + err = -ENAMETOOLONG;
15898 + wh_dentry = ERR_PTR(err);
15899 + if (unlikely(err))
15902 + br = au_sbr(sb, bcpup);
15904 + struct path tmp = {
15905 + .dentry = h_parent,
15906 + .mnt = au_br_mnt(br)
15908 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
15911 + wh_dentry = NULL;
15912 + if (bcpup != au_dbwh(dentry))
15913 + goto out; /* success */
15915 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
15918 + if (IS_ERR(wh_dentry))
15921 + return wh_dentry;
15924 +/* ---------------------------------------------------------------------- */
15926 +enum { Mknod, Symlink, Creat };
15927 +struct simple_arg {
15935 + const char *symname;
15944 +static int add_simple(struct inode *dir, struct dentry *dentry,
15945 + struct simple_arg *arg)
15948 + aufs_bindex_t bstart;
15949 + unsigned char created;
15950 + struct dentry *wh_dentry, *parent;
15951 + struct inode *h_dir;
15952 + /* to reuduce stack size */
15954 + struct au_dtime dt;
15955 + struct au_pin pin;
15956 + struct path h_path;
15957 + struct au_wr_dir_args wr_dir_args;
15960 + AuDbg("%.*s\n", AuDLNPair(dentry));
15964 + a = kmalloc(sizeof(*a), GFP_NOFS);
15965 + if (unlikely(!a))
15967 + a->wr_dir_args.force_btgt = -1;
15968 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
15970 + parent = dentry->d_parent; /* dir inode is locked */
15971 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
15972 + if (unlikely(err))
15974 + err = au_d_may_add(dentry);
15975 + if (unlikely(err))
15977 + di_write_lock_parent(parent);
15978 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
15979 + &a->pin, &a->wr_dir_args);
15980 + err = PTR_ERR(wh_dentry);
15981 + if (IS_ERR(wh_dentry))
15984 + bstart = au_dbstart(dentry);
15985 + a->h_path.dentry = au_h_dptr(dentry, bstart);
15986 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
15987 + h_dir = au_pinned_h_dir(&a->pin);
15988 + switch (arg->type) {
15990 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
15991 + arg->u.c.want_excl);
15994 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
15997 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
16005 + err = epilog(dir, bstart, wh_dentry, dentry);
16008 + if (unlikely(created && err && a->h_path.dentry->d_inode)) {
16010 + rerr = vfsub_unlink(h_dir, &a->h_path, /*force*/0);
16012 + AuIOErr("%.*s revert failure(%d, %d)\n",
16013 + AuDLNPair(dentry), err, rerr);
16016 + au_dtime_revert(&a->dt);
16019 + au_unpin(&a->pin);
16023 + di_write_unlock(parent);
16025 + if (unlikely(err)) {
16026 + au_update_dbstart(dentry);
16029 + aufs_read_unlock(dentry, AuLock_DW);
16036 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
16039 + struct simple_arg arg = {
16046 + return add_simple(dir, dentry, &arg);
16049 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
16051 + struct simple_arg arg = {
16053 + .u.s.symname = symname
16055 + return add_simple(dir, dentry, &arg);
16058 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
16061 + struct simple_arg arg = {
16065 + .want_excl = want_excl
16068 + return add_simple(dir, dentry, &arg);
16071 +/* ---------------------------------------------------------------------- */
16073 +struct au_link_args {
16074 + aufs_bindex_t bdst, bsrc;
16075 + struct au_pin pin;
16076 + struct path h_path;
16077 + struct dentry *src_parent, *parent;
16080 +static int au_cpup_before_link(struct dentry *src_dentry,
16081 + struct au_link_args *a)
16084 + struct dentry *h_src_dentry;
16085 + struct au_cp_generic cpg = {
16086 + .dentry = src_dentry,
16091 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
16094 + di_read_lock_parent(a->src_parent, AuLock_IR);
16095 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
16096 + if (unlikely(err))
16099 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
16100 + err = au_pin(&a->pin, src_dentry, a->bdst,
16101 + au_opt_udba(src_dentry->d_sb),
16102 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
16103 + if (unlikely(err))
16106 + err = au_sio_cpup_simple(&cpg);
16107 + au_unpin(&a->pin);
16110 + di_read_unlock(a->src_parent, AuLock_IR);
16114 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
16115 + struct au_link_args *a)
16118 + unsigned char plink;
16119 + aufs_bindex_t bend;
16120 + struct dentry *h_src_dentry;
16121 + struct inode *h_inode, *inode;
16122 + struct super_block *sb;
16123 + struct file *h_file;
16127 + sb = src_dentry->d_sb;
16128 + inode = src_dentry->d_inode;
16129 + if (au_ibstart(inode) <= a->bdst)
16130 + h_inode = au_h_iptr(inode, a->bdst);
16131 + if (!h_inode || !h_inode->i_nlink) {
16132 + /* copyup src_dentry as the name of dentry. */
16133 + bend = au_dbend(dentry);
16134 + if (bend < a->bsrc)
16135 + au_set_dbend(dentry, a->bsrc);
16136 + au_set_h_dptr(dentry, a->bsrc,
16137 + dget(au_h_dptr(src_dentry, a->bsrc)));
16138 + dget(a->h_path.dentry);
16139 + au_set_h_dptr(dentry, a->bdst, NULL);
16140 + dentry->d_inode = src_dentry->d_inode; /* tmp */
16141 + h_file = au_h_open_pre(dentry, a->bsrc);
16142 + if (IS_ERR(h_file))
16143 + err = PTR_ERR(h_file);
16145 + struct au_cp_generic cpg = {
16146 + .dentry = dentry,
16151 + .flags = AuCpup_KEEPLINO
16153 + err = au_sio_cpup_simple(&cpg);
16154 + au_h_open_post(dentry, a->bsrc, h_file);
16156 + dput(a->h_path.dentry);
16157 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
16159 + au_set_h_dptr(dentry, a->bdst,
16160 + a->h_path.dentry);
16162 + dentry->d_inode = NULL; /* restore */
16163 + au_set_h_dptr(dentry, a->bsrc, NULL);
16164 + au_set_dbend(dentry, bend);
16166 + /* the inode of src_dentry already exists on a.bdst branch */
16167 + h_src_dentry = d_find_alias(h_inode);
16168 + if (!h_src_dentry && au_plink_test(inode)) {
16170 + h_src_dentry = au_plink_lkup(inode, a->bdst);
16171 + err = PTR_ERR(h_src_dentry);
16172 + if (IS_ERR(h_src_dentry))
16175 + if (unlikely(!h_src_dentry->d_inode)) {
16176 + dput(h_src_dentry);
16177 + h_src_dentry = NULL;
16181 + if (h_src_dentry) {
16182 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
16184 + dput(h_src_dentry);
16186 + AuIOErr("no dentry found for hi%lu on b%d\n",
16187 + h_inode->i_ino, a->bdst);
16192 + if (!err && !plink)
16193 + au_plink_append(inode, a->bdst, a->h_path.dentry);
16200 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
16201 + struct dentry *dentry)
16204 + struct au_dtime dt;
16205 + struct au_link_args *a;
16206 + struct dentry *wh_dentry, *h_src_dentry;
16207 + struct inode *inode;
16208 + struct super_block *sb;
16209 + struct au_wr_dir_args wr_dir_args = {
16210 + /* .force_btgt = -1, */
16211 + .flags = AuWrDir_ADD_ENTRY
16215 + inode = src_dentry->d_inode;
16216 + IMustLock(inode);
16219 + a = kzalloc(sizeof(*a), GFP_NOFS);
16220 + if (unlikely(!a))
16223 + a->parent = dentry->d_parent; /* dir inode is locked */
16224 + err = aufs_read_and_write_lock2(dentry, src_dentry,
16225 + AuLock_NOPLM | AuLock_GEN);
16226 + if (unlikely(err))
16228 + err = au_d_hashed_positive(src_dentry);
16229 + if (unlikely(err))
16231 + err = au_d_may_add(dentry);
16232 + if (unlikely(err))
16235 + a->src_parent = dget_parent(src_dentry);
16236 + wr_dir_args.force_btgt = au_ibstart(inode);
16238 + di_write_lock_parent(a->parent);
16239 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
16240 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
16242 + err = PTR_ERR(wh_dentry);
16243 + if (IS_ERR(wh_dentry))
16247 + sb = dentry->d_sb;
16248 + a->bdst = au_dbstart(dentry);
16249 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
16250 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
16251 + a->bsrc = au_ibstart(inode);
16252 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
16253 + if (!h_src_dentry) {
16254 + a->bsrc = au_dbstart(src_dentry);
16255 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
16256 + AuDebugOn(!h_src_dentry);
16257 + } else if (IS_ERR(h_src_dentry))
16260 + if (au_opt_test(au_mntflags(sb), PLINK)) {
16261 + if (a->bdst < a->bsrc
16262 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
16263 + err = au_cpup_or_link(src_dentry, dentry, a);
16265 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
16267 + dput(h_src_dentry);
16270 + * copyup src_dentry to the branch we process,
16271 + * and then link(2) to it.
16273 + dput(h_src_dentry);
16274 + if (a->bdst < a->bsrc
16275 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
16276 + au_unpin(&a->pin);
16277 + di_write_unlock(a->parent);
16278 + err = au_cpup_before_link(src_dentry, a);
16279 + di_write_lock_parent(a->parent);
16281 + err = au_pin(&a->pin, dentry, a->bdst,
16283 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
16284 + if (unlikely(err))
16288 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
16290 + if (h_src_dentry && h_src_dentry->d_inode)
16291 + err = vfsub_link(h_src_dentry,
16292 + au_pinned_h_dir(&a->pin),
16296 + if (unlikely(err))
16300 + a->h_path.dentry = wh_dentry;
16301 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
16303 + if (unlikely(err))
16307 + dir->i_version++;
16308 + if (au_ibstart(dir) == au_dbstart(dentry))
16309 + au_cpup_attr_timesizes(dir);
16310 + inc_nlink(inode);
16311 + inode->i_ctime = dir->i_ctime;
16312 + d_instantiate(dentry, au_igrab(inode));
16313 + if (d_unhashed(a->h_path.dentry))
16314 + /* some filesystem calls d_drop() */
16316 + goto out_unpin; /* success */
16319 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path, /*force*/0);
16320 + if (unlikely(rerr)) {
16321 + AuIOErr("%.*s reverting failed(%d, %d)\n",
16322 + AuDLNPair(dentry), err, rerr);
16325 + au_dtime_revert(&dt);
16327 + au_unpin(&a->pin);
16331 + di_write_unlock(a->parent);
16332 + dput(a->src_parent);
16334 + if (unlikely(err)) {
16335 + au_update_dbstart(dentry);
16338 + aufs_read_and_write_unlock2(dentry, src_dentry);
16346 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
16349 + aufs_bindex_t bindex;
16350 + unsigned char diropq;
16351 + struct path h_path;
16352 + struct dentry *wh_dentry, *parent, *opq_dentry;
16353 + struct mutex *h_mtx;
16354 + struct super_block *sb;
16356 + struct au_pin pin;
16357 + struct au_dtime dt;
16358 + } *a; /* reduce the stack usage */
16359 + struct au_wr_dir_args wr_dir_args = {
16360 + .force_btgt = -1,
16361 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
16367 + a = kmalloc(sizeof(*a), GFP_NOFS);
16368 + if (unlikely(!a))
16371 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
16372 + if (unlikely(err))
16374 + err = au_d_may_add(dentry);
16375 + if (unlikely(err))
16378 + parent = dentry->d_parent; /* dir inode is locked */
16379 + di_write_lock_parent(parent);
16380 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
16381 + &a->pin, &wr_dir_args);
16382 + err = PTR_ERR(wh_dentry);
16383 + if (IS_ERR(wh_dentry))
16386 + sb = dentry->d_sb;
16387 + bindex = au_dbstart(dentry);
16388 + h_path.dentry = au_h_dptr(dentry, bindex);
16389 + h_path.mnt = au_sbr_mnt(sb, bindex);
16390 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
16391 + if (unlikely(err))
16394 + /* make the dir opaque */
16396 + h_mtx = &h_path.dentry->d_inode->i_mutex;
16398 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
16399 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
16400 + opq_dentry = au_diropq_create(dentry, bindex);
16401 + mutex_unlock(h_mtx);
16402 + err = PTR_ERR(opq_dentry);
16403 + if (IS_ERR(opq_dentry))
16405 + dput(opq_dentry);
16409 + err = epilog(dir, bindex, wh_dentry, dentry);
16412 + goto out_unpin; /* success */
16417 + AuLabel(revert opq);
16418 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
16419 + rerr = au_diropq_remove(dentry, bindex);
16420 + mutex_unlock(h_mtx);
16422 + AuIOErr("%.*s reverting diropq failed(%d, %d)\n",
16423 + AuDLNPair(dentry), err, rerr);
16429 + AuLabel(revert dir);
16430 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
16432 + AuIOErr("%.*s reverting dir failed(%d, %d)\n",
16433 + AuDLNPair(dentry), err, rerr);
16436 + au_dtime_revert(&a->dt);
16438 + au_unpin(&a->pin);
16441 + di_write_unlock(parent);
16443 + if (unlikely(err)) {
16444 + au_update_dbstart(dentry);
16447 + aufs_read_unlock(dentry, AuLock_DW);
16453 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
16454 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
16455 +++ linux/fs/aufs/i_op.c 2013-08-23 23:59:39.634916914 +0200
16458 + * Copyright (C) 2005-2013 Junjiro R. Okajima
16460 + * This program, aufs is free software; you can redistribute it and/or modify
16461 + * it under the terms of the GNU General Public License as published by
16462 + * the Free Software Foundation; either version 2 of the License, or
16463 + * (at your option) any later version.
16465 + * This program is distributed in the hope that it will be useful,
16466 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16467 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16468 + * GNU General Public License for more details.
16470 + * You should have received a copy of the GNU General Public License
16471 + * along with this program; if not, write to the Free Software
16472 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16476 + * inode operations (except add/del/rename)
16479 +#include <linux/device_cgroup.h>
16480 +#include <linux/fs_stack.h>
16481 +#include <linux/mm.h>
16482 +#include <linux/namei.h>
16483 +#include <linux/security.h>
16486 +static int h_permission(struct inode *h_inode, int mask,
16487 + struct vfsmount *h_mnt, int brperm)
16490 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
16493 + if ((write_mask && IS_IMMUTABLE(h_inode))
16494 + || ((mask & MAY_EXEC)
16495 + && S_ISREG(h_inode->i_mode)
16496 + && ((h_mnt->mnt_flags & MNT_NOEXEC)
16497 + || !(h_inode->i_mode & S_IXUGO))))
16501 + * - skip the lower fs test in the case of write to ro branch.
16502 + * - nfs dir permission write check is optimized, but a policy for
16503 + * link/rename requires a real check.
16505 + if ((write_mask && !au_br_writable(brperm))
16506 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
16507 + && write_mask && !(mask & MAY_READ))
16508 + || !h_inode->i_op->permission) {
16509 + /* AuLabel(generic_permission); */
16510 + err = generic_permission(h_inode, mask);
16512 + /* AuLabel(h_inode->permission); */
16513 + err = h_inode->i_op->permission(h_inode, mask);
16518 + err = devcgroup_inode_permission(h_inode, mask);
16520 + err = security_inode_permission(h_inode, mask);
16524 + /* todo: do we need to call ima_path_check()? */
16525 + struct path h_path = {
16529 + err = ima_path_check(&h_path,
16530 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
16531 + IMA_COUNT_LEAVE);
16539 +static int aufs_permission(struct inode *inode, int mask)
16542 + aufs_bindex_t bindex, bend;
16543 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
16544 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
16545 + struct inode *h_inode;
16546 + struct super_block *sb;
16547 + struct au_branch *br;
16549 + /* todo: support rcu-walk? */
16550 + if (mask & MAY_NOT_BLOCK)
16553 + sb = inode->i_sb;
16554 + si_read_lock(sb, AuLock_FLUSH);
16555 + ii_read_lock_child(inode);
16557 + err = au_iigen_test(inode, au_sigen(sb));
16558 + if (unlikely(err))
16562 + if (!isdir || write_mask) {
16563 + err = au_busy_or_stale();
16564 + h_inode = au_h_iptr(inode, au_ibstart(inode));
16565 + if (unlikely(!h_inode
16566 + || (h_inode->i_mode & S_IFMT)
16567 + != (inode->i_mode & S_IFMT)))
16571 + bindex = au_ibstart(inode);
16572 + br = au_sbr(sb, bindex);
16573 + err = h_permission(h_inode, mask, au_br_mnt(br), br->br_perm);
16576 + && !special_file(h_inode->i_mode)) {
16577 + /* test whether the upper writable branch exists */
16579 + for (; bindex >= 0; bindex--)
16580 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
16588 + /* non-write to dir */
16590 + bend = au_ibend(inode);
16591 + for (bindex = au_ibstart(inode); !err && bindex <= bend; bindex++) {
16592 + h_inode = au_h_iptr(inode, bindex);
16594 + err = au_busy_or_stale();
16595 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
16598 + br = au_sbr(sb, bindex);
16599 + err = h_permission(h_inode, mask, au_br_mnt(br),
16605 + ii_read_unlock(inode);
16606 + si_read_unlock(sb);
16610 +/* ---------------------------------------------------------------------- */
16612 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
16613 + unsigned int flags)
16615 + struct dentry *ret, *parent;
16616 + struct inode *inode;
16617 + struct super_block *sb;
16618 + int err, npositive;
16622 + /* todo: support rcu-walk? */
16623 + ret = ERR_PTR(-ECHILD);
16624 + if (flags & LOOKUP_RCU)
16627 + ret = ERR_PTR(-ENAMETOOLONG);
16628 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
16632 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16633 + ret = ERR_PTR(err);
16634 + if (unlikely(err))
16637 + err = au_di_init(dentry);
16638 + ret = ERR_PTR(err);
16639 + if (unlikely(err))
16643 + npositive = 0; /* suppress a warning */
16644 + parent = dentry->d_parent; /* dir inode is locked */
16645 + di_read_lock_parent(parent, AuLock_IR);
16646 + err = au_alive_dir(parent);
16648 + err = au_digen_test(parent, au_sigen(sb));
16650 + npositive = au_lkup_dentry(dentry, au_dbstart(parent),
16654 + di_read_unlock(parent, AuLock_IR);
16655 + ret = ERR_PTR(err);
16656 + if (unlikely(err < 0))
16660 + inode = au_new_inode(dentry, /*must_new*/0);
16661 + ret = (void *)inode;
16663 + if (IS_ERR(inode)) {
16668 + ret = d_splice_alias(inode, dentry);
16670 + if (unlikely(d_need_lookup(dentry))) {
16671 + spin_lock(&dentry->d_lock);
16672 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
16673 + spin_unlock(&dentry->d_lock);
16676 + if (unlikely(IS_ERR(ret) && inode)) {
16677 + ii_write_unlock(inode);
16683 + di_write_unlock(dentry);
16685 + /* verbose coding for lock class name */
16686 + if (unlikely(S_ISLNK(inode->i_mode)))
16687 + au_rw_class(&au_di(dentry)->di_rwsem,
16688 + au_lc_key + AuLcSymlink_DIINFO);
16689 + else if (unlikely(S_ISDIR(inode->i_mode)))
16690 + au_rw_class(&au_di(dentry)->di_rwsem,
16691 + au_lc_key + AuLcDir_DIINFO);
16692 + else /* likely */
16693 + au_rw_class(&au_di(dentry)->di_rwsem,
16694 + au_lc_key + AuLcNonDir_DIINFO);
16697 + si_read_unlock(sb);
16702 +/* ---------------------------------------------------------------------- */
16704 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
16705 + const unsigned char add_entry, aufs_bindex_t bcpup,
16706 + aufs_bindex_t bstart)
16709 + struct dentry *h_parent;
16710 + struct inode *h_dir;
16713 + IMustLock(parent->d_inode);
16715 + di_write_lock_parent(parent);
16718 + if (!au_h_dptr(parent, bcpup)) {
16719 + if (bstart > bcpup)
16720 + err = au_cpup_dirs(dentry, bcpup);
16721 + else if (bstart < bcpup)
16722 + err = au_cpdown_dirs(dentry, bcpup);
16726 + if (!err && add_entry) {
16727 + h_parent = au_h_dptr(parent, bcpup);
16728 + h_dir = h_parent->d_inode;
16729 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
16730 + err = au_lkup_neg(dentry, bcpup,
16731 + au_ftest_wrdir(add_entry, TMP_WHENTRY));
16732 + /* todo: no unlock here */
16733 + mutex_unlock(&h_dir->i_mutex);
16735 + AuDbg("bcpup %d\n", bcpup);
16737 + if (!dentry->d_inode)
16738 + au_set_h_dptr(dentry, bstart, NULL);
16739 + au_update_dbrange(dentry, /*do_put_zero*/0);
16744 + di_write_unlock(parent);
16746 + err = bcpup; /* success */
16753 + * decide the branch and the parent dir where we will create a new entry.
16754 + * returns new bindex or an error.
16755 + * copyup the parent dir if needed.
16757 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
16758 + struct au_wr_dir_args *args)
16761 + aufs_bindex_t bcpup, bstart, src_bstart;
16762 + const unsigned char add_entry
16763 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
16764 + | au_ftest_wrdir(args->flags, TMP_WHENTRY);
16765 + struct super_block *sb;
16766 + struct dentry *parent;
16767 + struct au_sbinfo *sbinfo;
16769 + sb = dentry->d_sb;
16770 + sbinfo = au_sbi(sb);
16771 + parent = dget_parent(dentry);
16772 + bstart = au_dbstart(dentry);
16774 + if (args->force_btgt < 0) {
16775 + if (src_dentry) {
16776 + src_bstart = au_dbstart(src_dentry);
16777 + if (src_bstart < bstart)
16778 + bcpup = src_bstart;
16779 + } else if (add_entry) {
16780 + err = AuWbrCreate(sbinfo, dentry,
16781 + au_ftest_wrdir(args->flags, ISDIR));
16785 + if (bcpup < 0 || au_test_ro(sb, bcpup, dentry->d_inode)) {
16787 + err = AuWbrCopyup(sbinfo, dentry);
16789 + if (!IS_ROOT(dentry)) {
16790 + di_read_lock_parent(parent, !AuLock_IR);
16791 + err = AuWbrCopyup(sbinfo, dentry);
16792 + di_read_unlock(parent, !AuLock_IR);
16794 + err = AuWbrCopyup(sbinfo, dentry);
16797 + if (unlikely(err < 0))
16801 + bcpup = args->force_btgt;
16802 + AuDebugOn(au_test_ro(sb, bcpup, dentry->d_inode));
16805 + AuDbg("bstart %d, bcpup %d\n", bstart, bcpup);
16807 + if (bcpup == bstart)
16808 + goto out; /* success */
16810 + /* copyup the new parent into the branch we process */
16811 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, bstart);
16813 + if (!dentry->d_inode) {
16814 + au_set_h_dptr(dentry, bstart, NULL);
16815 + au_set_dbstart(dentry, bcpup);
16816 + au_set_dbend(dentry, bcpup);
16818 + AuDebugOn(add_entry && !au_h_dptr(dentry, bcpup));
16826 +/* ---------------------------------------------------------------------- */
16828 +void au_pin_hdir_unlock(struct au_pin *p)
16831 + au_hn_imtx_unlock(p->hdir);
16834 +static int au_pin_hdir_lock(struct au_pin *p)
16842 + /* even if an error happens later, keep this lock */
16843 + au_hn_imtx_lock_nested(p->hdir, p->lsc_hi);
16846 + if (unlikely(p->hdir->hi_inode != p->h_parent->d_inode))
16851 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
16852 + p->h_parent, p->br);
16858 +int au_pin_hdir_relock(struct au_pin *p)
16861 + struct inode *h_i;
16862 + struct dentry *h_d[] = {
16867 + err = au_pin_hdir_lock(p);
16868 + if (unlikely(err))
16871 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
16874 + h_i = h_d[i]->d_inode;
16876 + err = !h_i->i_nlink;
16883 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
16885 +#if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
16886 + p->hdir->hi_inode->i_mutex.owner = task;
16890 +void au_pin_hdir_acquire_nest(struct au_pin *p)
16893 + mutex_acquire_nest(&p->hdir->hi_inode->i_mutex.dep_map,
16894 + p->lsc_hi, 0, NULL, _RET_IP_);
16895 + au_pin_hdir_set_owner(p, current);
16899 +void au_pin_hdir_release(struct au_pin *p)
16902 + au_pin_hdir_set_owner(p, p->task);
16903 + mutex_release(&p->hdir->hi_inode->i_mutex.dep_map, 1, _RET_IP_);
16907 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
16909 + if (pin && pin->parent)
16910 + return au_h_dptr(pin->parent, pin->bindex);
16914 +void au_unpin(struct au_pin *p)
16917 + au_pin_hdir_unlock(p);
16918 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
16919 + vfsub_mnt_drop_write(p->h_mnt);
16923 + if (!au_ftest_pin(p->flags, DI_LOCKED))
16924 + di_read_unlock(p->parent, AuLock_IR);
16925 + iput(p->hdir->hi_inode);
16927 + p->parent = NULL;
16930 + /* do not clear p->task */
16933 +int au_do_pin(struct au_pin *p)
16936 + struct super_block *sb;
16937 + struct inode *h_dir;
16940 + sb = p->dentry->d_sb;
16941 + p->br = au_sbr(sb, p->bindex);
16942 + if (IS_ROOT(p->dentry)) {
16943 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
16944 + p->h_mnt = au_br_mnt(p->br);
16945 + err = vfsub_mnt_want_write(p->h_mnt);
16946 + if (unlikely(err)) {
16947 + au_fclr_pin(p->flags, MNT_WRITE);
16954 + p->h_dentry = NULL;
16955 + if (p->bindex <= au_dbend(p->dentry))
16956 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
16958 + p->parent = dget_parent(p->dentry);
16959 + if (!au_ftest_pin(p->flags, DI_LOCKED))
16960 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
16963 + p->h_parent = au_h_dptr(p->parent, p->bindex);
16964 + p->hdir = au_hi(p->parent->d_inode, p->bindex);
16966 + h_dir = p->hdir->hi_inode;
16970 + * if DI_LOCKED is not set, then p->parent may be different
16971 + * and h_parent can be NULL.
16973 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
16975 + if (!au_ftest_pin(p->flags, DI_LOCKED))
16976 + di_read_unlock(p->parent, AuLock_IR);
16978 + p->parent = NULL;
16982 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
16983 + p->h_mnt = au_br_mnt(p->br);
16984 + err = vfsub_mnt_want_write(p->h_mnt);
16985 + if (unlikely(err)) {
16986 + au_fclr_pin(p->flags, MNT_WRITE);
16987 + if (!au_ftest_pin(p->flags, DI_LOCKED))
16988 + di_read_unlock(p->parent, AuLock_IR);
16990 + p->parent = NULL;
16996 + err = au_pin_hdir_lock(p);
16998 + goto out; /* success */
17001 + pr_err("err %d\n", err);
17002 + err = au_busy_or_stale();
17007 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
17008 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
17009 + unsigned int udba, unsigned char flags)
17011 + p->dentry = dentry;
17013 + p->lsc_di = lsc_di;
17014 + p->lsc_hi = lsc_hi;
17015 + p->flags = flags;
17016 + p->bindex = bindex;
17018 + p->parent = NULL;
17022 + p->h_dentry = NULL;
17023 + p->h_parent = NULL;
17025 + p->task = current;
17028 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
17029 + unsigned int udba, unsigned char flags)
17031 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
17033 + return au_do_pin(pin);
17036 +/* ---------------------------------------------------------------------- */
17039 + * ->setattr() and ->getattr() are called in various cases.
17040 + * chmod, stat: dentry is revalidated.
17041 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
17043 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
17045 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
17046 +static int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
17049 + struct inode *inode;
17050 + struct dentry *parent;
17053 + inode = dentry->d_inode;
17054 + if (au_digen_test(dentry, sigen)) {
17055 + parent = dget_parent(dentry);
17056 + di_read_lock_parent(parent, AuLock_IR);
17057 + err = au_refresh_dentry(dentry, parent);
17058 + di_read_unlock(parent, AuLock_IR);
17066 +#define AuIcpup_DID_CPUP 1
17067 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
17068 +#define au_fset_icpup(flags, name) \
17069 + do { (flags) |= AuIcpup_##name; } while (0)
17070 +#define au_fclr_icpup(flags, name) \
17071 + do { (flags) &= ~AuIcpup_##name; } while (0)
17073 +struct au_icpup_args {
17074 + unsigned char flags;
17075 + unsigned char pin_flags;
17076 + aufs_bindex_t btgt;
17077 + unsigned int udba;
17078 + struct au_pin pin;
17079 + struct path h_path;
17080 + struct inode *h_inode;
17083 +static int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
17084 + struct au_icpup_args *a)
17088 + aufs_bindex_t bstart, ibstart;
17089 + struct dentry *hi_wh, *parent;
17090 + struct inode *inode;
17091 + struct au_wr_dir_args wr_dir_args = {
17092 + .force_btgt = -1,
17096 + bstart = au_dbstart(dentry);
17097 + inode = dentry->d_inode;
17098 + if (S_ISDIR(inode->i_mode))
17099 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
17100 + /* plink or hi_wh() case */
17101 + ibstart = au_ibstart(inode);
17102 + if (bstart != ibstart && !au_test_ro(inode->i_sb, ibstart, inode))
17103 + wr_dir_args.force_btgt = ibstart;
17104 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
17105 + if (unlikely(err < 0))
17108 + if (err != bstart)
17109 + au_fset_icpup(a->flags, DID_CPUP);
17112 + a->pin_flags = AuPin_MNT_WRITE;
17114 + if (!IS_ROOT(dentry)) {
17115 + au_fset_pin(a->pin_flags, DI_LOCKED);
17116 + parent = dget_parent(dentry);
17117 + di_write_lock_parent(parent);
17120 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
17121 + if (unlikely(err))
17124 + a->h_path.dentry = au_h_dptr(dentry, bstart);
17125 + a->h_inode = a->h_path.dentry->d_inode;
17126 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
17128 + if ((ia->ia_valid & ATTR_SIZE) && ia->ia_size < i_size_read(a->h_inode))
17129 + sz = ia->ia_size;
17130 + mutex_unlock(&a->h_inode->i_mutex);
17133 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
17134 + hi_wh = au_hi_wh(inode, a->btgt);
17136 + struct au_cp_generic cpg = {
17137 + .dentry = dentry,
17143 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
17144 + if (unlikely(err))
17146 + hi_wh = au_hi_wh(inode, a->btgt);
17147 + /* todo: revalidate hi_wh? */
17152 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
17153 + di_downgrade_lock(parent, AuLock_IR);
17157 + if (!au_ftest_icpup(a->flags, DID_CPUP))
17158 + goto out; /* success */
17160 + if (!d_unhashed(dentry)) {
17161 + struct au_cp_generic cpg = {
17162 + .dentry = dentry,
17167 + .flags = AuCpup_DTIME | AuCpup_HOPEN
17169 + err = au_sio_cpup_simple(&cpg);
17171 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
17172 + } else if (!hi_wh)
17173 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
17175 + a->h_path.dentry = hi_wh; /* do not dget here */
17178 + a->h_inode = a->h_path.dentry->d_inode;
17180 + goto out; /* success */
17181 + au_unpin(&a->pin);
17184 + di_write_unlock(parent);
17189 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
17193 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
17196 + struct inode *inode;
17197 + struct super_block *sb;
17198 + struct file *file;
17199 + struct au_icpup_args *a;
17201 + inode = dentry->d_inode;
17202 + IMustLock(inode);
17205 + a = kzalloc(sizeof(*a), GFP_NOFS);
17206 + if (unlikely(!a))
17209 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
17210 + ia->ia_valid &= ~ATTR_MODE;
17213 + sb = dentry->d_sb;
17214 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
17215 + if (unlikely(err))
17218 + if (ia->ia_valid & ATTR_FILE) {
17219 + /* currently ftruncate(2) only */
17220 + AuDebugOn(!S_ISREG(inode->i_mode));
17221 + file = ia->ia_file;
17222 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
17223 + if (unlikely(err))
17225 + ia->ia_file = au_hf_top(file);
17226 + a->udba = AuOpt_UDBA_NONE;
17228 + /* fchmod() doesn't pass ia_file */
17229 + a->udba = au_opt_udba(sb);
17230 + di_write_lock_child(dentry);
17231 + /* no d_unlinked(), to set UDBA_NONE for root */
17232 + if (d_unhashed(dentry))
17233 + a->udba = AuOpt_UDBA_NONE;
17234 + if (a->udba != AuOpt_UDBA_NONE) {
17235 + AuDebugOn(IS_ROOT(dentry));
17236 + err = au_reval_for_attr(dentry, au_sigen(sb));
17237 + if (unlikely(err))
17242 + err = au_pin_and_icpup(dentry, ia, a);
17243 + if (unlikely(err < 0))
17245 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
17246 + ia->ia_file = NULL;
17247 + ia->ia_valid &= ~ATTR_FILE;
17250 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
17251 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
17252 + == (ATTR_MODE | ATTR_CTIME)) {
17253 + err = security_path_chmod(&a->h_path, ia->ia_mode);
17254 + if (unlikely(err))
17256 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
17257 + && (ia->ia_valid & ATTR_CTIME)) {
17258 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
17259 + if (unlikely(err))
17263 + if (ia->ia_valid & ATTR_SIZE) {
17266 + if (ia->ia_size < i_size_read(inode))
17268 + truncate_setsize(inode, ia->ia_size);
17271 + if (ia->ia_valid & ATTR_FILE)
17273 + mutex_unlock(&a->h_inode->i_mutex);
17274 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
17275 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
17277 + err = vfsub_notify_change(&a->h_path, ia);
17279 + au_cpup_attr_changeable(inode);
17282 + mutex_unlock(&a->h_inode->i_mutex);
17283 + au_unpin(&a->pin);
17284 + if (unlikely(err))
17285 + au_update_dbstart(dentry);
17287 + di_write_unlock(dentry);
17289 + fi_write_unlock(file);
17290 + ia->ia_file = file;
17291 + ia->ia_valid |= ATTR_FILE;
17294 + si_read_unlock(sb);
17302 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
17303 + unsigned int nlink)
17307 + inode->i_mode = st->mode;
17308 + /* don't i_[ug]id_write() here */
17309 + inode->i_uid = st->uid;
17310 + inode->i_gid = st->gid;
17311 + inode->i_atime = st->atime;
17312 + inode->i_mtime = st->mtime;
17313 + inode->i_ctime = st->ctime;
17315 + au_cpup_attr_nlink(inode, /*force*/0);
17316 + if (S_ISDIR(inode->i_mode)) {
17317 + n = inode->i_nlink;
17321 + /* 0 can happen */
17322 + set_nlink(inode, n);
17325 + spin_lock(&inode->i_lock);
17326 + inode->i_blocks = st->blocks;
17327 + i_size_write(inode, st->size);
17328 + spin_unlock(&inode->i_lock);
17331 +static int aufs_getattr(struct vfsmount *mnt __maybe_unused,
17332 + struct dentry *dentry, struct kstat *st)
17335 + unsigned int mnt_flags;
17336 + aufs_bindex_t bindex;
17337 + unsigned char udba_none, positive;
17338 + struct super_block *sb, *h_sb;
17339 + struct inode *inode;
17340 + struct path h_path;
17342 + sb = dentry->d_sb;
17343 + inode = dentry->d_inode;
17344 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
17345 + if (unlikely(err))
17347 + mnt_flags = au_mntflags(sb);
17348 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
17350 + /* support fstat(2) */
17351 + if (!d_unlinked(dentry) && !udba_none) {
17352 + unsigned int sigen = au_sigen(sb);
17353 + err = au_digen_test(dentry, sigen);
17355 + di_read_lock_child(dentry, AuLock_IR);
17356 + err = au_dbrange_test(dentry);
17357 + if (unlikely(err))
17360 + AuDebugOn(IS_ROOT(dentry));
17361 + di_write_lock_child(dentry);
17362 + err = au_dbrange_test(dentry);
17364 + err = au_reval_for_attr(dentry, sigen);
17365 + di_downgrade_lock(dentry, AuLock_IR);
17366 + if (unlikely(err))
17370 + di_read_lock_child(dentry, AuLock_IR);
17372 + bindex = au_ibstart(inode);
17373 + h_path.mnt = au_sbr_mnt(sb, bindex);
17374 + h_sb = h_path.mnt->mnt_sb;
17375 + if (!au_test_fs_bad_iattr(h_sb) && udba_none)
17376 + goto out_fill; /* success */
17378 + h_path.dentry = NULL;
17379 + if (au_dbstart(dentry) == bindex)
17380 + h_path.dentry = dget(au_h_dptr(dentry, bindex));
17381 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
17382 + h_path.dentry = au_plink_lkup(inode, bindex);
17383 + if (IS_ERR(h_path.dentry))
17384 + goto out_fill; /* pretending success */
17386 + /* illegally overlapped or something */
17387 + if (unlikely(!h_path.dentry))
17388 + goto out_fill; /* pretending success */
17390 + positive = !!h_path.dentry->d_inode;
17392 + err = vfs_getattr(&h_path, st);
17393 + dput(h_path.dentry);
17396 + au_refresh_iattr(inode, st,
17397 + h_path.dentry->d_inode->i_nlink);
17398 + goto out_fill; /* success */
17404 + generic_fillattr(inode, st);
17406 + di_read_unlock(dentry, AuLock_IR);
17407 + si_read_unlock(sb);
17413 +/* ---------------------------------------------------------------------- */
17415 +static int h_readlink(struct dentry *dentry, int bindex, char __user *buf,
17419 + struct super_block *sb;
17420 + struct dentry *h_dentry;
17423 + h_dentry = au_h_dptr(dentry, bindex);
17424 + if (unlikely(!h_dentry->d_inode->i_op->readlink))
17427 + err = security_inode_readlink(h_dentry);
17428 + if (unlikely(err))
17431 + sb = dentry->d_sb;
17432 + if (!au_test_ro(sb, bindex, dentry->d_inode)) {
17433 + vfsub_touch_atime(au_sbr_mnt(sb, bindex), h_dentry);
17434 + fsstack_copy_attr_atime(dentry->d_inode, h_dentry->d_inode);
17436 + err = h_dentry->d_inode->i_op->readlink(h_dentry, buf, bufsiz);
17442 +static int aufs_readlink(struct dentry *dentry, char __user *buf, int bufsiz)
17446 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
17447 + if (unlikely(err))
17449 + err = au_d_hashed_positive(dentry);
17451 + err = h_readlink(dentry, au_dbstart(dentry), buf, bufsiz);
17452 + aufs_read_unlock(dentry, AuLock_IR);
17458 +static void *aufs_follow_link(struct dentry *dentry, struct nameidata *nd)
17461 + mm_segment_t old_fs;
17468 + buf.k = (void *)__get_free_page(GFP_NOFS);
17469 + if (unlikely(!buf.k))
17472 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
17473 + if (unlikely(err))
17476 + err = au_d_hashed_positive(dentry);
17478 + old_fs = get_fs();
17479 + set_fs(KERNEL_DS);
17480 + err = h_readlink(dentry, au_dbstart(dentry), buf.u, PATH_MAX);
17483 + aufs_read_unlock(dentry, AuLock_IR);
17487 + /* will be freed by put_link */
17488 + nd_set_link(nd, buf.k);
17489 + return NULL; /* success */
17493 + free_page((unsigned long)buf.k);
17496 + return ERR_PTR(err);
17499 +static void aufs_put_link(struct dentry *dentry __maybe_unused,
17500 + struct nameidata *nd, void *cookie __maybe_unused)
17504 + p = nd_get_link(nd);
17505 + if (!IS_ERR_OR_NULL(p))
17506 + free_page((unsigned long)p);
17509 +/* ---------------------------------------------------------------------- */
17511 +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags)
17514 + struct super_block *sb;
17515 + struct inode *h_inode;
17517 + sb = inode->i_sb;
17518 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
17520 + si_read_lock(sb, AuLock_FLUSH);
17521 + ii_write_lock_child(inode);
17523 + h_inode = au_h_iptr(inode, au_ibstart(inode));
17524 + err = vfsub_update_time(h_inode, ts, flags);
17526 + ii_write_unlock(inode);
17527 + si_read_unlock(sb);
17532 +/* ---------------------------------------------------------------------- */
17534 +struct inode_operations aufs_symlink_iop = {
17535 + .permission = aufs_permission,
17536 + .setattr = aufs_setattr,
17537 + .getattr = aufs_getattr,
17539 + .readlink = aufs_readlink,
17540 + .follow_link = aufs_follow_link,
17541 + .put_link = aufs_put_link,
17543 + /* .update_time = aufs_update_time */
17546 +struct inode_operations aufs_dir_iop = {
17547 + .create = aufs_create,
17548 + .lookup = aufs_lookup,
17549 + .link = aufs_link,
17550 + .unlink = aufs_unlink,
17551 + .symlink = aufs_symlink,
17552 + .mkdir = aufs_mkdir,
17553 + .rmdir = aufs_rmdir,
17554 + .mknod = aufs_mknod,
17555 + .rename = aufs_rename,
17557 + .permission = aufs_permission,
17558 + .setattr = aufs_setattr,
17559 + .getattr = aufs_getattr,
17561 + .update_time = aufs_update_time
17562 + /* no support for atomic_open() */
17565 +struct inode_operations aufs_iop = {
17566 + .permission = aufs_permission,
17567 + .setattr = aufs_setattr,
17568 + .getattr = aufs_getattr,
17570 + .update_time = aufs_update_time
17572 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
17573 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
17574 +++ linux/fs/aufs/i_op_del.c 2013-08-23 23:59:39.634916914 +0200
17577 + * Copyright (C) 2005-2013 Junjiro R. Okajima
17579 + * This program, aufs is free software; you can redistribute it and/or modify
17580 + * it under the terms of the GNU General Public License as published by
17581 + * the Free Software Foundation; either version 2 of the License, or
17582 + * (at your option) any later version.
17584 + * This program is distributed in the hope that it will be useful,
17585 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17586 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17587 + * GNU General Public License for more details.
17589 + * You should have received a copy of the GNU General Public License
17590 + * along with this program; if not, write to the Free Software
17591 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17595 + * inode operations (del entry)
17601 + * decide if a new whiteout for @dentry is necessary or not.
17602 + * when it is necessary, prepare the parent dir for the upper branch whose
17603 + * branch index is @bcpup for creation. the actual creation of the whiteout will
17604 + * be done by caller.
17606 + * 0: wh is unnecessary
17607 + * plus: wh is necessary
17610 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
17612 + int need_wh, err;
17613 + aufs_bindex_t bstart;
17614 + struct super_block *sb;
17616 + sb = dentry->d_sb;
17617 + bstart = au_dbstart(dentry);
17618 + if (*bcpup < 0) {
17620 + if (au_test_ro(sb, bstart, dentry->d_inode)) {
17621 + err = AuWbrCopyup(au_sbi(sb), dentry);
17623 + if (unlikely(err < 0))
17627 + AuDebugOn(bstart < *bcpup
17628 + || au_test_ro(sb, *bcpup, dentry->d_inode));
17629 + AuDbg("bcpup %d, bstart %d\n", *bcpup, bstart);
17631 + if (*bcpup != bstart) {
17632 + err = au_cpup_dirs(dentry, *bcpup);
17633 + if (unlikely(err))
17637 + struct au_dinfo *dinfo, *tmp;
17639 + need_wh = -ENOMEM;
17640 + dinfo = au_di(dentry);
17641 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
17643 + au_di_cp(tmp, dinfo);
17644 + au_di_swap(tmp, dinfo);
17645 + /* returns the number of positive dentries */
17646 + need_wh = au_lkup_dentry(dentry, bstart + 1, /*type*/0);
17647 + au_di_swap(tmp, dinfo);
17648 + au_rw_write_unlock(&tmp->di_rwsem);
17652 + AuDbg("need_wh %d\n", need_wh);
17660 + * simple tests for the del-entry operations.
17661 + * following the checks in vfs, plus the parent-child relationship.
17663 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
17664 + struct dentry *h_parent, int isdir)
17668 + struct dentry *h_dentry, *h_latest;
17669 + struct inode *h_inode;
17671 + h_dentry = au_h_dptr(dentry, bindex);
17672 + h_inode = h_dentry->d_inode;
17673 + if (dentry->d_inode) {
17675 + if (unlikely(!h_inode || !h_inode->i_nlink))
17678 + h_mode = h_inode->i_mode;
17681 + if (unlikely(S_ISDIR(h_mode)))
17683 + } else if (unlikely(!S_ISDIR(h_mode))) {
17688 + /* rename(2) case */
17690 + if (unlikely(h_inode))
17695 + /* expected parent dir is locked */
17696 + if (unlikely(h_parent != h_dentry->d_parent))
17701 + * rmdir a dir may break the consistency on some filesystem.
17702 + * let's try heavy test.
17705 + if (unlikely(au_test_h_perm(h_parent->d_inode, MAY_EXEC | MAY_WRITE)))
17708 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent,
17709 + au_sbr(dentry->d_sb, bindex));
17711 + if (IS_ERR(h_latest))
17713 + if (h_latest == h_dentry)
17722 + * decide the branch where we operate for @dentry. the branch index will be set
17723 + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent
17724 + * dir for reverting.
17725 + * when a new whiteout is necessary, create it.
17727 +static struct dentry*
17728 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
17729 + struct au_dtime *dt, struct au_pin *pin)
17731 + struct dentry *wh_dentry;
17732 + struct super_block *sb;
17733 + struct path h_path;
17734 + int err, need_wh;
17735 + unsigned int udba;
17736 + aufs_bindex_t bcpup;
17738 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
17739 + wh_dentry = ERR_PTR(need_wh);
17740 + if (unlikely(need_wh < 0))
17743 + sb = dentry->d_sb;
17744 + udba = au_opt_udba(sb);
17746 + err = au_pin(pin, dentry, bcpup, udba,
17747 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17748 + wh_dentry = ERR_PTR(err);
17749 + if (unlikely(err))
17752 + h_path.dentry = au_pinned_h_parent(pin);
17753 + if (udba != AuOpt_UDBA_NONE
17754 + && au_dbstart(dentry) == bcpup) {
17755 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
17756 + wh_dentry = ERR_PTR(err);
17757 + if (unlikely(err))
17761 + h_path.mnt = au_sbr_mnt(sb, bcpup);
17762 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
17763 + wh_dentry = NULL;
17765 + goto out; /* success, no need to create whiteout */
17767 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
17768 + if (IS_ERR(wh_dentry))
17771 + /* returns with the parent is locked and wh_dentry is dget-ed */
17772 + goto out; /* success */
17777 + return wh_dentry;
17781 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
17782 + * in order to be revertible and save time for removing many child whiteouts
17784 + * returns 1 when there are too many child whiteout and caller should remove
17785 + * them asynchronously. returns 0 when the number of children is enough small to
17786 + * remove now or the branch fs is a remote fs.
17787 + * otherwise return an error.
17789 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
17790 + struct au_nhash *whlist, struct inode *dir)
17792 + int rmdir_later, err, dirwh;
17793 + struct dentry *h_dentry;
17794 + struct super_block *sb;
17796 + sb = dentry->d_sb;
17797 + SiMustAnyLock(sb);
17798 + h_dentry = au_h_dptr(dentry, bindex);
17799 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
17800 + if (unlikely(err))
17803 + /* stop monitoring */
17804 + au_hn_free(au_hi(dentry->d_inode, bindex));
17806 + if (!au_test_fs_remote(h_dentry->d_sb)) {
17807 + dirwh = au_sbi(sb)->si_dirwh;
17808 + rmdir_later = (dirwh <= 1);
17809 + if (!rmdir_later)
17810 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
17813 + return rmdir_later;
17816 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
17817 + if (unlikely(err)) {
17818 + AuIOErr("rmdir %.*s, b%d failed, %d. ignored\n",
17819 + AuDLNPair(h_dentry), bindex, err);
17829 + * final procedure for deleting a entry.
17830 + * maintain dentry and iattr.
17832 +static void epilog(struct inode *dir, struct dentry *dentry,
17833 + aufs_bindex_t bindex)
17835 + struct inode *inode;
17837 + inode = dentry->d_inode;
17839 + inode->i_ctime = dir->i_ctime;
17841 + if (au_ibstart(dir) == bindex)
17842 + au_cpup_attr_timesizes(dir);
17843 + dir->i_version++;
17847 + * when an error happened, remove the created whiteout and revert everything.
17849 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
17850 + aufs_bindex_t bwh, struct dentry *wh_dentry,
17851 + struct dentry *dentry, struct au_dtime *dt)
17854 + struct path h_path = {
17855 + .dentry = wh_dentry,
17856 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
17859 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
17861 + au_set_dbwh(dentry, bwh);
17862 + au_dtime_revert(dt);
17866 + AuIOErr("%.*s reverting whiteout failed(%d, %d)\n",
17867 + AuDLNPair(dentry), err, rerr);
17871 +/* ---------------------------------------------------------------------- */
17873 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
17876 + aufs_bindex_t bwh, bindex, bstart;
17877 + struct inode *inode, *h_dir;
17878 + struct dentry *parent, *wh_dentry;
17879 + /* to reuduce stack size */
17881 + struct au_dtime dt;
17882 + struct au_pin pin;
17883 + struct path h_path;
17889 + a = kmalloc(sizeof(*a), GFP_NOFS);
17890 + if (unlikely(!a))
17893 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
17894 + if (unlikely(err))
17896 + err = au_d_hashed_positive(dentry);
17897 + if (unlikely(err))
17899 + inode = dentry->d_inode;
17900 + IMustLock(inode);
17902 + if (unlikely(S_ISDIR(inode->i_mode)))
17903 + goto out_unlock; /* possible? */
17905 + bstart = au_dbstart(dentry);
17906 + bwh = au_dbwh(dentry);
17908 + parent = dentry->d_parent; /* dir inode is locked */
17909 + di_write_lock_parent(parent);
17910 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
17912 + err = PTR_ERR(wh_dentry);
17913 + if (IS_ERR(wh_dentry))
17916 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
17917 + a->h_path.dentry = au_h_dptr(dentry, bstart);
17918 + dget(a->h_path.dentry);
17919 + if (bindex == bstart) {
17920 + h_dir = au_pinned_h_dir(&a->pin);
17921 + err = vfsub_unlink(h_dir, &a->h_path, /*force*/0);
17923 + /* dir inode is locked */
17924 + h_dir = wh_dentry->d_parent->d_inode;
17925 + IMustLock(h_dir);
17930 + vfsub_drop_nlink(inode);
17931 + epilog(dir, dentry, bindex);
17933 + /* update target timestamps */
17934 + if (bindex == bstart) {
17935 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
17937 + inode->i_ctime = a->h_path.dentry->d_inode->i_ctime;
17939 + /* todo: this timestamp may be reverted later */
17940 + inode->i_ctime = h_dir->i_ctime;
17941 + goto out_unpin; /* success */
17948 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
17955 + au_unpin(&a->pin);
17957 + dput(a->h_path.dentry);
17959 + di_write_unlock(parent);
17961 + aufs_read_unlock(dentry, AuLock_DW);
17968 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
17970 + int err, rmdir_later;
17971 + aufs_bindex_t bwh, bindex, bstart;
17972 + struct inode *inode;
17973 + struct dentry *parent, *wh_dentry, *h_dentry;
17974 + struct au_whtmp_rmdir *args;
17975 + /* to reuduce stack size */
17977 + struct au_dtime dt;
17978 + struct au_pin pin;
17984 + a = kmalloc(sizeof(*a), GFP_NOFS);
17985 + if (unlikely(!a))
17988 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
17989 + if (unlikely(err))
17991 + err = au_alive_dir(dentry);
17992 + if (unlikely(err))
17994 + inode = dentry->d_inode;
17995 + IMustLock(inode);
17997 + if (unlikely(!S_ISDIR(inode->i_mode)))
17998 + goto out_unlock; /* possible? */
18001 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
18002 + if (unlikely(!args))
18005 + parent = dentry->d_parent; /* dir inode is locked */
18006 + di_write_lock_parent(parent);
18007 + err = au_test_empty(dentry, &args->whlist);
18008 + if (unlikely(err))
18011 + bstart = au_dbstart(dentry);
18012 + bwh = au_dbwh(dentry);
18014 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
18016 + err = PTR_ERR(wh_dentry);
18017 + if (IS_ERR(wh_dentry))
18020 + h_dentry = au_h_dptr(dentry, bstart);
18023 + if (bindex == bstart) {
18024 + err = renwh_and_rmdir(dentry, bstart, &args->whlist, dir);
18026 + rmdir_later = err;
18030 + /* stop monitoring */
18031 + au_hn_free(au_hi(inode, bstart));
18033 + /* dir inode is locked */
18034 + IMustLock(wh_dentry->d_parent->d_inode);
18039 + vfsub_dead_dir(inode);
18040 + au_set_dbdiropq(dentry, -1);
18041 + epilog(dir, dentry, bindex);
18043 + if (rmdir_later) {
18044 + au_whtmp_kick_rmdir(dir, bstart, h_dentry, args);
18048 + goto out_unpin; /* success */
18056 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
18063 + au_unpin(&a->pin);
18067 + di_write_unlock(parent);
18069 + au_whtmp_rmdir_free(args);
18071 + aufs_read_unlock(dentry, AuLock_DW);
18078 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
18079 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
18080 +++ linux/fs/aufs/i_op_ren.c 2013-08-23 23:59:39.634916914 +0200
18083 + * Copyright (C) 2005-2013 Junjiro R. Okajima
18085 + * This program, aufs is free software; you can redistribute it and/or modify
18086 + * it under the terms of the GNU General Public License as published by
18087 + * the Free Software Foundation; either version 2 of the License, or
18088 + * (at your option) any later version.
18090 + * This program is distributed in the hope that it will be useful,
18091 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18092 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18093 + * GNU General Public License for more details.
18095 + * You should have received a copy of the GNU General Public License
18096 + * along with this program; if not, write to the Free Software
18097 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18101 + * inode operation (rename entry)
18102 + * todo: this is crazy monster
18107 +enum { AuSRC, AuDST, AuSrcDst };
18108 +enum { AuPARENT, AuCHILD, AuParentChild };
18110 +#define AuRen_ISDIR 1
18111 +#define AuRen_ISSAMEDIR (1 << 1)
18112 +#define AuRen_WHSRC (1 << 2)
18113 +#define AuRen_WHDST (1 << 3)
18114 +#define AuRen_MNT_WRITE (1 << 4)
18115 +#define AuRen_DT_DSTDIR (1 << 5)
18116 +#define AuRen_DIROPQ (1 << 6)
18117 +#define AuRen_CPUP (1 << 7)
18118 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
18119 +#define au_fset_ren(flags, name) \
18120 + do { (flags) |= AuRen_##name; } while (0)
18121 +#define au_fclr_ren(flags, name) \
18122 + do { (flags) &= ~AuRen_##name; } while (0)
18124 +struct au_ren_args {
18126 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
18128 + struct inode *dir, *inode;
18129 + struct au_hinode *hdir;
18130 + struct au_dtime dt[AuParentChild];
18131 + aufs_bindex_t bstart;
18134 +#define src_dentry sd[AuSRC].dentry
18135 +#define src_dir sd[AuSRC].dir
18136 +#define src_inode sd[AuSRC].inode
18137 +#define src_h_dentry sd[AuSRC].h_dentry
18138 +#define src_parent sd[AuSRC].parent
18139 +#define src_h_parent sd[AuSRC].h_parent
18140 +#define src_wh_dentry sd[AuSRC].wh_dentry
18141 +#define src_hdir sd[AuSRC].hdir
18142 +#define src_h_dir sd[AuSRC].hdir->hi_inode
18143 +#define src_dt sd[AuSRC].dt
18144 +#define src_bstart sd[AuSRC].bstart
18146 +#define dst_dentry sd[AuDST].dentry
18147 +#define dst_dir sd[AuDST].dir
18148 +#define dst_inode sd[AuDST].inode
18149 +#define dst_h_dentry sd[AuDST].h_dentry
18150 +#define dst_parent sd[AuDST].parent
18151 +#define dst_h_parent sd[AuDST].h_parent
18152 +#define dst_wh_dentry sd[AuDST].wh_dentry
18153 +#define dst_hdir sd[AuDST].hdir
18154 +#define dst_h_dir sd[AuDST].hdir->hi_inode
18155 +#define dst_dt sd[AuDST].dt
18156 +#define dst_bstart sd[AuDST].bstart
18158 + struct dentry *h_trap;
18159 + struct au_branch *br;
18160 + struct au_hinode *src_hinode;
18161 + struct path h_path;
18162 + struct au_nhash whlist;
18163 + aufs_bindex_t btgt, src_bwh, src_bdiropq;
18165 + unsigned int flags;
18167 + struct au_whtmp_rmdir *thargs;
18168 + struct dentry *h_dst;
18171 +/* ---------------------------------------------------------------------- */
18174 + * functions for reverting.
18175 + * when an error happened in a single rename systemcall, we should revert
18176 + * everything as if nothing happend.
18177 + * we don't need to revert the copied-up/down the parent dir since they are
18181 +#define RevertFailure(fmt, ...) do { \
18182 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
18183 + ##__VA_ARGS__, err, rerr); \
18187 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
18191 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
18192 + rerr = au_diropq_remove(a->src_dentry, a->btgt);
18193 + au_hn_imtx_unlock(a->src_hinode);
18194 + au_set_dbdiropq(a->src_dentry, a->src_bdiropq);
18196 + RevertFailure("remove diropq %.*s", AuDLNPair(a->src_dentry));
18199 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
18203 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
18204 + a->src_h_parent);
18205 + rerr = PTR_ERR(a->h_path.dentry);
18206 + if (IS_ERR(a->h_path.dentry)) {
18207 + RevertFailure("lkup one %.*s", AuDLNPair(a->src_dentry));
18211 + rerr = vfsub_rename(a->dst_h_dir,
18212 + au_h_dptr(a->src_dentry, a->btgt),
18213 + a->src_h_dir, &a->h_path);
18214 + d_drop(a->h_path.dentry);
18215 + dput(a->h_path.dentry);
18216 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
18218 + RevertFailure("rename %.*s", AuDLNPair(a->src_dentry));
18221 +static void au_ren_rev_cpup(int err, struct au_ren_args *a)
18225 + a->h_path.dentry = a->dst_h_dentry;
18226 + rerr = vfsub_unlink(a->dst_h_dir, &a->h_path, /*force*/0);
18227 + au_set_h_dptr(a->src_dentry, a->btgt, NULL);
18228 + au_set_dbstart(a->src_dentry, a->src_bstart);
18230 + RevertFailure("unlink %.*s", AuDLNPair(a->dst_h_dentry));
18233 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
18237 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
18238 + a->dst_h_parent);
18239 + rerr = PTR_ERR(a->h_path.dentry);
18240 + if (IS_ERR(a->h_path.dentry)) {
18241 + RevertFailure("lkup one %.*s", AuDLNPair(a->dst_dentry));
18244 + if (a->h_path.dentry->d_inode) {
18245 + d_drop(a->h_path.dentry);
18246 + dput(a->h_path.dentry);
18250 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path);
18251 + d_drop(a->h_path.dentry);
18252 + dput(a->h_path.dentry);
18254 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
18256 + RevertFailure("rename %.*s", AuDLNPair(a->h_dst));
18259 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
18263 + a->h_path.dentry = a->src_wh_dentry;
18264 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
18265 + au_set_dbwh(a->src_dentry, a->src_bwh);
18267 + RevertFailure("unlink %.*s", AuDLNPair(a->src_wh_dentry));
18269 +#undef RevertFailure
18271 +/* ---------------------------------------------------------------------- */
18274 + * when we have to copyup the renaming entry, do it with the rename-target name
18275 + * in order to minimize the cost (the later actual rename is unnecessary).
18276 + * otherwise rename it on the target branch.
18278 +static int au_ren_or_cpup(struct au_ren_args *a)
18281 + struct dentry *d;
18283 + d = a->src_dentry;
18284 + if (au_dbstart(d) == a->btgt) {
18285 + a->h_path.dentry = a->dst_h_dentry;
18286 + if (au_ftest_ren(a->flags, DIROPQ)
18287 + && au_dbdiropq(d) == a->btgt)
18288 + au_fclr_ren(a->flags, DIROPQ);
18289 + AuDebugOn(au_dbstart(d) != a->btgt);
18290 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
18291 + a->dst_h_dir, &a->h_path);
18295 + if (!err && a->h_dst)
18296 + /* it will be set to dinfo later */
18302 +/* cf. aufs_rmdir() */
18303 +static int au_ren_del_whtmp(struct au_ren_args *a)
18306 + struct inode *dir;
18308 + dir = a->dst_dir;
18309 + SiMustAnyLock(dir->i_sb);
18310 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
18311 + au_sbi(dir->i_sb)->si_dirwh)
18312 + || au_test_fs_remote(a->h_dst->d_sb)) {
18313 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
18314 + if (unlikely(err))
18315 + pr_warn("failed removing whtmp dir %.*s (%d), "
18316 + "ignored.\n", AuDLNPair(a->h_dst), err);
18318 + au_nhash_wh_free(&a->thargs->whlist);
18319 + a->thargs->whlist = a->whlist;
18320 + a->whlist.nh_num = 0;
18321 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
18323 + a->thargs = NULL;
18329 +/* make it 'opaque' dir. */
18330 +static int au_ren_diropq(struct au_ren_args *a)
18333 + struct dentry *diropq;
18336 + a->src_bdiropq = au_dbdiropq(a->src_dentry);
18337 + a->src_hinode = au_hi(a->src_inode, a->btgt);
18338 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
18339 + diropq = au_diropq_create(a->src_dentry, a->btgt);
18340 + au_hn_imtx_unlock(a->src_hinode);
18341 + if (IS_ERR(diropq))
18342 + err = PTR_ERR(diropq);
18348 +static int do_rename(struct au_ren_args *a)
18351 + struct dentry *d, *h_d;
18353 + /* prepare workqueue args for asynchronous rmdir */
18354 + h_d = a->dst_h_dentry;
18355 + if (au_ftest_ren(a->flags, ISDIR) && h_d->d_inode) {
18357 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb, GFP_NOFS);
18358 + if (unlikely(!a->thargs))
18360 + a->h_dst = dget(h_d);
18363 + /* create whiteout for src_dentry */
18364 + if (au_ftest_ren(a->flags, WHSRC)) {
18365 + a->src_bwh = au_dbwh(a->src_dentry);
18366 + AuDebugOn(a->src_bwh >= 0);
18368 + = au_wh_create(a->src_dentry, a->btgt, a->src_h_parent);
18369 + err = PTR_ERR(a->src_wh_dentry);
18370 + if (IS_ERR(a->src_wh_dentry))
18374 + /* lookup whiteout for dentry */
18375 + if (au_ftest_ren(a->flags, WHDST)) {
18376 + h_d = au_wh_lkup(a->dst_h_parent, &a->dst_dentry->d_name,
18378 + err = PTR_ERR(h_d);
18381 + if (!h_d->d_inode)
18384 + a->dst_wh_dentry = h_d;
18387 + /* rename dentry to tmpwh */
18389 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
18390 + if (unlikely(err))
18393 + d = a->dst_dentry;
18394 + au_set_h_dptr(d, a->btgt, NULL);
18395 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
18396 + if (unlikely(err))
18398 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
18401 + BUG_ON(a->dst_h_dentry->d_inode && a->src_bstart != a->btgt);
18403 + /* rename by vfs_rename or cpup */
18404 + d = a->dst_dentry;
18405 + if (au_ftest_ren(a->flags, ISDIR)
18406 + && (a->dst_wh_dentry
18407 + || au_dbdiropq(d) == a->btgt
18408 + /* hide the lower to keep xino */
18409 + || a->btgt < au_dbend(d)
18410 + || au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ)))
18411 + au_fset_ren(a->flags, DIROPQ);
18412 + err = au_ren_or_cpup(a);
18413 + if (unlikely(err))
18414 + /* leave the copied-up one */
18417 + /* make dir opaque */
18418 + if (au_ftest_ren(a->flags, DIROPQ)) {
18419 + err = au_ren_diropq(a);
18420 + if (unlikely(err))
18424 + /* update target timestamps */
18425 + AuDebugOn(au_dbstart(a->src_dentry) != a->btgt);
18426 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
18427 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
18428 + a->src_inode->i_ctime = a->h_path.dentry->d_inode->i_ctime;
18430 + /* remove whiteout for dentry */
18431 + if (a->dst_wh_dentry) {
18432 + a->h_path.dentry = a->dst_wh_dentry;
18433 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
18435 + if (unlikely(err))
18439 + /* remove whtmp */
18441 + au_ren_del_whtmp(a); /* ignore this error */
18444 + goto out_success;
18447 + if (au_ftest_ren(a->flags, DIROPQ))
18448 + au_ren_rev_diropq(err, a);
18450 + if (!au_ftest_ren(a->flags, CPUP))
18451 + au_ren_rev_rename(err, a);
18453 + au_ren_rev_cpup(err, a);
18457 + au_ren_rev_whtmp(err, a);
18459 + dput(a->dst_wh_dentry);
18460 + a->dst_wh_dentry = NULL;
18462 + if (a->src_wh_dentry)
18463 + au_ren_rev_whsrc(err, a);
18465 + dput(a->src_wh_dentry);
18466 + dput(a->dst_wh_dentry);
18470 + au_whtmp_rmdir_free(a->thargs);
18471 + a->thargs = NULL;
18477 +/* ---------------------------------------------------------------------- */
18480 + * test if @dentry dir can be rename destination or not.
18481 + * success means, it is a logically empty dir.
18483 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
18485 + return au_test_empty(dentry, whlist);
18489 + * test if @dentry dir can be rename source or not.
18490 + * if it can, return 0 and @children is filled.
18492 + * - it is a logically empty dir.
18493 + * - or, it exists on writable branch and has no children including whiteouts
18494 + * on the lower branch.
18496 +static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt)
18499 + unsigned int rdhash;
18500 + aufs_bindex_t bstart;
18502 + bstart = au_dbstart(dentry);
18503 + if (bstart != btgt) {
18504 + struct au_nhash whlist;
18506 + SiMustAnyLock(dentry->d_sb);
18507 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
18509 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
18511 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
18512 + if (unlikely(err))
18514 + err = au_test_empty(dentry, &whlist);
18515 + au_nhash_wh_free(&whlist);
18519 + if (bstart == au_dbtaildir(dentry))
18520 + return 0; /* success */
18522 + err = au_test_empty_lower(dentry);
18525 + if (err == -ENOTEMPTY) {
18526 + AuWarn1("renaming dir who has child(ren) on multiple branches,"
18527 + " is not supported\n");
18533 +/* side effect: sets whlist and h_dentry */
18534 +static int au_ren_may_dir(struct au_ren_args *a)
18537 + unsigned int rdhash;
18538 + struct dentry *d;
18540 + d = a->dst_dentry;
18541 + SiMustAnyLock(d->d_sb);
18544 + if (au_ftest_ren(a->flags, ISDIR) && a->dst_inode) {
18545 + rdhash = au_sbi(d->d_sb)->si_rdhash;
18547 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
18548 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
18549 + if (unlikely(err))
18552 + au_set_dbstart(d, a->dst_bstart);
18553 + err = may_rename_dstdir(d, &a->whlist);
18554 + au_set_dbstart(d, a->btgt);
18556 + a->dst_h_dentry = au_h_dptr(d, au_dbstart(d));
18557 + if (unlikely(err))
18560 + d = a->src_dentry;
18561 + a->src_h_dentry = au_h_dptr(d, au_dbstart(d));
18562 + if (au_ftest_ren(a->flags, ISDIR)) {
18563 + err = may_rename_srcdir(d, a->btgt);
18564 + if (unlikely(err)) {
18565 + au_nhash_wh_free(&a->whlist);
18566 + a->whlist.nh_num = 0;
18573 +/* ---------------------------------------------------------------------- */
18576 + * simple tests for rename.
18577 + * following the checks in vfs, plus the parent-child relationship.
18579 +static int au_may_ren(struct au_ren_args *a)
18582 + struct inode *h_inode;
18584 + if (a->src_bstart == a->btgt) {
18585 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
18586 + au_ftest_ren(a->flags, ISDIR));
18587 + if (unlikely(err))
18590 + if (unlikely(a->src_h_dentry == a->h_trap))
18595 + if (a->dst_bstart != a->btgt)
18598 + err = -ENOTEMPTY;
18599 + if (unlikely(a->dst_h_dentry == a->h_trap))
18603 + h_inode = a->dst_h_dentry->d_inode;
18604 + isdir = !!au_ftest_ren(a->flags, ISDIR);
18605 + if (!a->dst_dentry->d_inode) {
18606 + if (unlikely(h_inode))
18608 + err = au_may_add(a->dst_dentry, a->btgt, a->dst_h_parent,
18611 + if (unlikely(!h_inode || !h_inode->i_nlink))
18613 + err = au_may_del(a->dst_dentry, a->btgt, a->dst_h_parent,
18615 + if (unlikely(err))
18620 + if (unlikely(err == -ENOENT || err == -EEXIST))
18626 +/* ---------------------------------------------------------------------- */
18631 + * - src_dir and dir by lock_rename()
18632 + * - inode if exitsts
18635 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
18637 + * + di_write_lock2_child()
18638 + * + di_write_lock_child()
18639 + * + ii_write_lock_child()
18640 + * + di_write_lock_child2()
18641 + * + ii_write_lock_child2()
18642 + * + src_parent and parent
18643 + * + di_write_lock_parent()
18644 + * + ii_write_lock_parent()
18645 + * + di_write_lock_parent2()
18646 + * + ii_write_lock_parent2()
18647 + * + lower src_dir and dir by vfsub_lock_rename()
18648 + * + verify the every relationships between child and parent. if any
18649 + * of them failed, unlock all and return -EBUSY.
18651 +static void au_ren_unlock(struct au_ren_args *a)
18653 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
18654 + a->dst_h_parent, a->dst_hdir);
18655 + if (au_ftest_ren(a->flags, MNT_WRITE))
18656 + vfsub_mnt_drop_write(au_br_mnt(a->br));
18659 +static int au_ren_lock(struct au_ren_args *a)
18662 + unsigned int udba;
18665 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
18666 + a->src_hdir = au_hi(a->src_dir, a->btgt);
18667 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
18668 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
18670 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
18671 + if (unlikely(err))
18673 + au_fset_ren(a->flags, MNT_WRITE);
18674 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
18675 + a->dst_h_parent, a->dst_hdir);
18676 + udba = au_opt_udba(a->src_dentry->d_sb);
18677 + if (unlikely(a->src_hdir->hi_inode != a->src_h_parent->d_inode
18678 + || a->dst_hdir->hi_inode != a->dst_h_parent->d_inode))
18679 + err = au_busy_or_stale();
18680 + if (!err && au_dbstart(a->src_dentry) == a->btgt)
18681 + err = au_h_verify(a->src_h_dentry, udba,
18682 + a->src_h_parent->d_inode, a->src_h_parent,
18684 + if (!err && au_dbstart(a->dst_dentry) == a->btgt)
18685 + err = au_h_verify(a->dst_h_dentry, udba,
18686 + a->dst_h_parent->d_inode, a->dst_h_parent,
18689 + goto out; /* success */
18691 + err = au_busy_or_stale();
18692 + au_ren_unlock(a);
18698 +/* ---------------------------------------------------------------------- */
18700 +static void au_ren_refresh_dir(struct au_ren_args *a)
18702 + struct inode *dir;
18704 + dir = a->dst_dir;
18705 + dir->i_version++;
18706 + if (au_ftest_ren(a->flags, ISDIR)) {
18707 + /* is this updating defined in POSIX? */
18708 + au_cpup_attr_timesizes(a->src_inode);
18709 + au_cpup_attr_nlink(dir, /*force*/1);
18712 + if (au_ibstart(dir) == a->btgt)
18713 + au_cpup_attr_timesizes(dir);
18715 + if (au_ftest_ren(a->flags, ISSAMEDIR))
18718 + dir = a->src_dir;
18719 + dir->i_version++;
18720 + if (au_ftest_ren(a->flags, ISDIR))
18721 + au_cpup_attr_nlink(dir, /*force*/1);
18722 + if (au_ibstart(dir) == a->btgt)
18723 + au_cpup_attr_timesizes(dir);
18726 +static void au_ren_refresh(struct au_ren_args *a)
18728 + aufs_bindex_t bend, bindex;
18729 + struct dentry *d, *h_d;
18730 + struct inode *i, *h_i;
18731 + struct super_block *sb;
18733 + d = a->dst_dentry;
18736 + /* already dget-ed by au_ren_or_cpup() */
18737 + au_set_h_dptr(d, a->btgt, a->h_dst);
18739 + i = a->dst_inode;
18741 + if (!au_ftest_ren(a->flags, ISDIR))
18742 + vfsub_drop_nlink(i);
18744 + vfsub_dead_dir(i);
18745 + au_cpup_attr_timesizes(i);
18747 + au_update_dbrange(d, /*do_put_zero*/1);
18750 + for (bindex = au_dbstart(d); bindex < bend; bindex++)
18751 + au_set_h_dptr(d, bindex, NULL);
18752 + bend = au_dbend(d);
18753 + for (bindex = a->btgt + 1; bindex <= bend; bindex++)
18754 + au_set_h_dptr(d, bindex, NULL);
18755 + au_update_dbrange(d, /*do_put_zero*/0);
18758 + d = a->src_dentry;
18759 + au_set_dbwh(d, -1);
18760 + bend = au_dbend(d);
18761 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
18762 + h_d = au_h_dptr(d, bindex);
18764 + au_set_h_dptr(d, bindex, NULL);
18766 + au_set_dbend(d, a->btgt);
18769 + i = a->src_inode;
18770 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
18771 + return; /* success */
18773 + bend = au_ibend(i);
18774 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
18775 + h_i = au_h_iptr(i, bindex);
18777 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
18778 + /* ignore this error */
18779 + au_set_h_iptr(i, bindex, NULL, 0);
18782 + au_set_ibend(i, a->btgt);
18785 +/* ---------------------------------------------------------------------- */
18787 +/* mainly for link(2) and rename(2) */
18788 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
18790 + aufs_bindex_t bdiropq, bwh;
18791 + struct dentry *parent;
18792 + struct au_branch *br;
18794 + parent = dentry->d_parent;
18795 + IMustLock(parent->d_inode); /* dir is locked */
18797 + bdiropq = au_dbdiropq(parent);
18798 + bwh = au_dbwh(dentry);
18799 + br = au_sbr(dentry->d_sb, btgt);
18800 + if (au_br_rdonly(br)
18801 + || (0 <= bdiropq && bdiropq < btgt)
18802 + || (0 <= bwh && bwh < btgt))
18805 + AuDbg("btgt %d\n", btgt);
18809 +/* sets src_bstart, dst_bstart and btgt */
18810 +static int au_ren_wbr(struct au_ren_args *a)
18813 + struct au_wr_dir_args wr_dir_args = {
18814 + /* .force_btgt = -1, */
18815 + .flags = AuWrDir_ADD_ENTRY
18818 + a->src_bstart = au_dbstart(a->src_dentry);
18819 + a->dst_bstart = au_dbstart(a->dst_dentry);
18820 + if (au_ftest_ren(a->flags, ISDIR))
18821 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
18822 + wr_dir_args.force_btgt = a->src_bstart;
18823 + if (a->dst_inode && a->dst_bstart < a->src_bstart)
18824 + wr_dir_args.force_btgt = a->dst_bstart;
18825 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
18826 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
18832 +static void au_ren_dt(struct au_ren_args *a)
18834 + a->h_path.dentry = a->src_h_parent;
18835 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
18836 + if (!au_ftest_ren(a->flags, ISSAMEDIR)) {
18837 + a->h_path.dentry = a->dst_h_parent;
18838 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
18841 + au_fclr_ren(a->flags, DT_DSTDIR);
18842 + if (!au_ftest_ren(a->flags, ISDIR))
18845 + a->h_path.dentry = a->src_h_dentry;
18846 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
18847 + if (a->dst_h_dentry->d_inode) {
18848 + au_fset_ren(a->flags, DT_DSTDIR);
18849 + a->h_path.dentry = a->dst_h_dentry;
18850 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
18854 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
18856 + struct dentry *h_d;
18857 + struct mutex *h_mtx;
18859 + au_dtime_revert(a->src_dt + AuPARENT);
18860 + if (!au_ftest_ren(a->flags, ISSAMEDIR))
18861 + au_dtime_revert(a->dst_dt + AuPARENT);
18863 + if (au_ftest_ren(a->flags, ISDIR) && err != -EIO) {
18864 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
18865 + h_mtx = &h_d->d_inode->i_mutex;
18866 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
18867 + au_dtime_revert(a->src_dt + AuCHILD);
18868 + mutex_unlock(h_mtx);
18870 + if (au_ftest_ren(a->flags, DT_DSTDIR)) {
18871 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
18872 + h_mtx = &h_d->d_inode->i_mutex;
18873 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
18874 + au_dtime_revert(a->dst_dt + AuCHILD);
18875 + mutex_unlock(h_mtx);
18880 +/* ---------------------------------------------------------------------- */
18882 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
18883 + struct inode *_dst_dir, struct dentry *_dst_dentry)
18886 + /* reduce stack space */
18887 + struct au_ren_args *a;
18889 + AuDbg("%.*s, %.*s\n", AuDLNPair(_src_dentry), AuDLNPair(_dst_dentry));
18890 + IMustLock(_src_dir);
18891 + IMustLock(_dst_dir);
18894 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
18895 + a = kzalloc(sizeof(*a), GFP_NOFS);
18896 + if (unlikely(!a))
18899 + a->src_dir = _src_dir;
18900 + a->src_dentry = _src_dentry;
18901 + a->src_inode = a->src_dentry->d_inode;
18902 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
18903 + a->dst_dir = _dst_dir;
18904 + a->dst_dentry = _dst_dentry;
18905 + a->dst_inode = a->dst_dentry->d_inode;
18906 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
18907 + if (a->dst_inode) {
18908 + IMustLock(a->dst_inode);
18909 + au_igrab(a->dst_inode);
18913 + flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
18914 + if (S_ISDIR(a->src_inode->i_mode)) {
18915 + au_fset_ren(a->flags, ISDIR);
18916 + if (unlikely(a->dst_inode && !S_ISDIR(a->dst_inode->i_mode)))
18918 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
18919 + AuLock_DIR | flags);
18921 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
18923 + if (unlikely(err))
18926 + err = au_d_hashed_positive(a->src_dentry);
18927 + if (unlikely(err))
18930 + if (a->dst_inode) {
18932 + * If it is a dir, VFS unhash dst_dentry before this
18933 + * function. It means we cannot rely upon d_unhashed().
18935 + if (unlikely(!a->dst_inode->i_nlink))
18937 + if (!S_ISDIR(a->dst_inode->i_mode)) {
18938 + err = au_d_hashed_positive(a->dst_dentry);
18939 + if (unlikely(err))
18941 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
18943 + } else if (unlikely(d_unhashed(a->dst_dentry)))
18947 + * is it possible?
18948 + * yes, it happend (in linux-3.3-rcN) but I don't know why.
18949 + * there may exist a problem somewhere else.
18952 + if (unlikely(a->dst_parent->d_inode == a->src_dentry->d_inode))
18955 + au_fset_ren(a->flags, ISSAMEDIR); /* temporary */
18956 + di_write_lock_parent(a->dst_parent);
18958 + /* which branch we process */
18959 + err = au_ren_wbr(a);
18960 + if (unlikely(err < 0))
18962 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
18963 + a->h_path.mnt = au_br_mnt(a->br);
18965 + /* are they available to be renamed */
18966 + err = au_ren_may_dir(a);
18967 + if (unlikely(err))
18968 + goto out_children;
18970 + /* prepare the writable parent dir on the same branch */
18971 + if (a->dst_bstart == a->btgt) {
18972 + au_fset_ren(a->flags, WHDST);
18974 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
18975 + if (unlikely(err))
18976 + goto out_children;
18979 + if (a->src_dir != a->dst_dir) {
18981 + * this temporary unlock is safe,
18982 + * because both dir->i_mutex are locked.
18984 + di_write_unlock(a->dst_parent);
18985 + di_write_lock_parent(a->src_parent);
18986 + err = au_wr_dir_need_wh(a->src_dentry,
18987 + au_ftest_ren(a->flags, ISDIR),
18989 + di_write_unlock(a->src_parent);
18990 + di_write_lock2_parent(a->src_parent, a->dst_parent, /*isdir*/1);
18991 + au_fclr_ren(a->flags, ISSAMEDIR);
18993 + err = au_wr_dir_need_wh(a->src_dentry,
18994 + au_ftest_ren(a->flags, ISDIR),
18996 + if (unlikely(err < 0))
18997 + goto out_children;
18999 + au_fset_ren(a->flags, WHSRC);
19002 + if (a->src_bstart != a->btgt) {
19003 + struct au_pin pin;
19005 + err = au_pin(&pin, a->src_dentry, a->btgt,
19006 + au_opt_udba(a->src_dentry->d_sb),
19007 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19009 + struct au_cp_generic cpg = {
19010 + .dentry = a->src_dentry,
19012 + .bsrc = a->src_bstart,
19015 + .flags = AuCpup_DTIME | AuCpup_HOPEN
19017 + AuDebugOn(au_dbstart(a->src_dentry) != a->src_bstart);
19018 + err = au_sio_cpup_simple(&cpg);
19021 + if (unlikely(err))
19022 + goto out_children;
19023 + a->src_bstart = a->btgt;
19024 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
19025 + au_fset_ren(a->flags, WHSRC);
19028 + /* lock them all */
19029 + err = au_ren_lock(a);
19030 + if (unlikely(err))
19031 + /* leave the copied-up one */
19032 + goto out_children;
19034 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
19035 + err = au_may_ren(a);
19036 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
19037 + err = -ENAMETOOLONG;
19038 + if (unlikely(err))
19041 + /* store timestamps to be revertible */
19045 + err = do_rename(a);
19046 + if (unlikely(err))
19049 + /* update dir attributes */
19050 + au_ren_refresh_dir(a);
19052 + /* dput/iput all lower dentries */
19053 + au_ren_refresh(a);
19055 + goto out_hdir; /* success */
19058 + au_ren_rev_dt(err, a);
19060 + au_ren_unlock(a);
19062 + au_nhash_wh_free(&a->whlist);
19063 + if (err && a->dst_inode && a->dst_bstart != a->btgt) {
19064 + AuDbg("bstart %d, btgt %d\n", a->dst_bstart, a->btgt);
19065 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
19066 + au_set_dbstart(a->dst_dentry, a->dst_bstart);
19070 + d_move(a->src_dentry, a->dst_dentry);
19072 + au_update_dbstart(a->dst_dentry);
19073 + if (!a->dst_inode)
19074 + d_drop(a->dst_dentry);
19076 + if (au_ftest_ren(a->flags, ISSAMEDIR))
19077 + di_write_unlock(a->dst_parent);
19079 + di_write_unlock2(a->src_parent, a->dst_parent);
19081 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
19083 + iput(a->dst_inode);
19085 + au_whtmp_rmdir_free(a->thargs);
19091 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
19092 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
19093 +++ linux/fs/aufs/Kconfig 2013-07-06 13:20:47.736864659 +0200
19096 + tristate "Aufs (Advanced multi layered unification filesystem) support"
19098 + Aufs is a stackable unification filesystem such as Unionfs,
19099 + which unifies several directories and provides a merged single
19101 + In the early days, aufs was entirely re-designed and
19102 + re-implemented Unionfs Version 1.x series. Introducing many
19103 + original ideas, approaches and improvements, it becomes totally
19104 + different from Unionfs while keeping the basic features.
19108 + prompt "Maximum number of branches"
19109 + default AUFS_BRANCH_MAX_127
19111 + Specifies the maximum number of branches (or member directories)
19112 + in a single aufs. The larger value consumes more system
19113 + resources and has a minor impact to performance.
19114 +config AUFS_BRANCH_MAX_127
19117 + Specifies the maximum number of branches (or member directories)
19118 + in a single aufs. The larger value consumes more system
19119 + resources and has a minor impact to performance.
19120 +config AUFS_BRANCH_MAX_511
19123 + Specifies the maximum number of branches (or member directories)
19124 + in a single aufs. The larger value consumes more system
19125 + resources and has a minor impact to performance.
19126 +config AUFS_BRANCH_MAX_1023
19129 + Specifies the maximum number of branches (or member directories)
19130 + in a single aufs. The larger value consumes more system
19131 + resources and has a minor impact to performance.
19132 +config AUFS_BRANCH_MAX_32767
19135 + Specifies the maximum number of branches (or member directories)
19136 + in a single aufs. The larger value consumes more system
19137 + resources and has a minor impact to performance.
19140 +config AUFS_SBILIST
19142 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
19145 + Automatic configuration for internal use.
19146 + When aufs supports Magic SysRq or /proc, enabled automatically.
19148 +config AUFS_HNOTIFY
19149 + bool "Detect direct branch access (bypassing aufs)"
19151 + If you want to modify files on branches directly, eg. bypassing aufs,
19152 + and want aufs to detect the changes of them fully, then enable this
19153 + option and use 'udba=notify' mount option.
19154 + Currently there is only one available configuration, "fsnotify".
19155 + It will have a negative impact to the performance.
19156 + See detail in aufs.5.
19159 + prompt "method" if AUFS_HNOTIFY
19160 + default AUFS_HFSNOTIFY
19161 +config AUFS_HFSNOTIFY
19166 +config AUFS_EXPORT
19167 + bool "NFS-exportable aufs"
19168 + depends on EXPORTFS
19170 + If you want to export your mounted aufs via NFS, then enable this
19171 + option. There are several requirements for this configuration.
19172 + See detail in aufs.5.
19174 +config AUFS_INO_T_64
19176 + depends on AUFS_EXPORT
19177 + depends on 64BIT && !(ALPHA || S390)
19180 + Automatic configuration for internal use.
19181 + /* typedef unsigned long/int __kernel_ino_t */
19182 + /* alpha and s390x are int */
19185 + bool "Readdir in userspace"
19187 + Aufs has two methods to provide a merged view for a directory,
19188 + by a user-space library and by kernel-space natively. The latter
19189 + is always enabled but sometimes large and slow.
19190 + If you enable this option, install the library in aufs2-util
19191 + package, and set some environment variables for your readdir(3),
19192 + then the work will be handled in user-space which generally
19193 + shows better performance in most cases.
19194 + See detail in aufs.5.
19196 +config AUFS_PROC_MAP
19197 + bool "support for /proc/maps and lsof(1)"
19198 + depends on PROC_FS
19200 + When you issue mmap(2) in aufs, it is actually a direct mmap(2)
19201 + call to the file on the branch fs since the file in aufs is
19202 + purely virtual. And the file path printed in /proc/maps (and
19203 + others) will be the path on the branch fs. In most cases, it
19204 + does no harm. But some utilities like lsof(1) may confuse since
19205 + the utility or user may expect the file path in aufs to be
19207 + To address this issue, aufs provides a patch which introduces a
19208 + new member called vm_prfile into struct vm_are_struct. The patch
19209 + is meaningless without enabling this configuration since nobody
19210 + sets the new vm_prfile member.
19211 + If you don't apply the patch, then enabling this configuration
19212 + will cause a compile error.
19213 + This approach is fragile since if someone else make some changes
19214 + around vm_file, then vm_prfile may not work anymore. As a
19215 + workaround such case, aufs provides this configuration. If you
19216 + disable it, then lsof(1) may produce incorrect result but the
19217 + problem will be gone even if the aufs patch is applied (I hope).
19219 +config AUFS_SP_IATTR
19220 + bool "Respect the attributes (mtime/ctime mainly) of special files"
19222 + When you write something to a special file, some attributes of it
19223 + (mtime/ctime mainly) may be updated. Generally such updates are
19224 + less important (actually some device drivers and NFS ignore
19225 + it). But some applications (such like test program) requires
19226 + such updates. If you need these updates, then enable this
19227 + configuration which introduces some overhead.
19228 + Currently this configuration handles FIFO only.
19231 + bool "Show whiteouts"
19233 + If you want to make the whiteouts in aufs visible, then enable
19234 + this option and specify 'shwh' mount option. Although it may
19235 + sounds like philosophy or something, but in technically it
19236 + simply shows the name of whiteout with keeping its behaviour.
19238 +config AUFS_BR_RAMFS
19239 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
19241 + If you want to use ramfs as an aufs branch fs, then enable this
19242 + option. Generally tmpfs is recommended.
19243 + Aufs prohibited them to be a branch fs by default, because
19244 + initramfs becomes unusable after switch_root or something
19245 + generally. If you sets initramfs as an aufs branch and boot your
19246 + system by switch_root, you will meet a problem easily since the
19247 + files in initramfs may be inaccessible.
19248 + Unless you are going to use ramfs as an aufs branch fs without
19249 + switch_root or something, leave it N.
19251 +config AUFS_BR_FUSE
19252 + bool "Fuse fs as an aufs branch"
19253 + depends on FUSE_FS
19256 + If you want to use fuse-based userspace filesystem as an aufs
19257 + branch fs, then enable this option.
19258 + It implements the internal poll(2) operation which is
19259 + implemented by fuse only (curretnly).
19264 + Automatic configuration for internal use.
19266 +config AUFS_BR_HFSPLUS
19267 + bool "Hfsplus as an aufs branch"
19268 + depends on HFSPLUS_FS
19271 + If you want to use hfsplus fs as an aufs branch fs, then enable
19272 + this option. This option introduces a small overhead at
19273 + copying-up a file on hfsplus.
19275 +config AUFS_BDEV_LOOP
19277 + depends on BLK_DEV_LOOP
19280 + Automatic configuration for internal use.
19281 + Convert =[ym] into =y.
19284 + bool "Debug aufs"
19286 + Enable this to compile aufs internal debug code.
19287 + It will have a negative impact to the performance.
19289 +config AUFS_MAGIC_SYSRQ
19291 + depends on AUFS_DEBUG && MAGIC_SYSRQ
19294 + Automatic configuration for internal use.
19295 + When aufs supports Magic SysRq, enabled automatically.
19297 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
19298 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
19299 +++ linux/fs/aufs/loop.c 2013-07-30 22:42:55.842946719 +0200
19302 + * Copyright (C) 2005-2013 Junjiro R. Okajima
19304 + * This program, aufs is free software; you can redistribute it and/or modify
19305 + * it under the terms of the GNU General Public License as published by
19306 + * the Free Software Foundation; either version 2 of the License, or
19307 + * (at your option) any later version.
19309 + * This program is distributed in the hope that it will be useful,
19310 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19311 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19312 + * GNU General Public License for more details.
19314 + * You should have received a copy of the GNU General Public License
19315 + * along with this program; if not, write to the Free Software
19316 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19320 + * support for loopback block device as a branch
19323 +#include <linux/loop.h>
19327 + * test if two lower dentries have overlapping branches.
19329 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
19331 + struct super_block *h_sb;
19332 + struct loop_device *l;
19334 + h_sb = h_adding->d_sb;
19335 + if (MAJOR(h_sb->s_dev) != LOOP_MAJOR)
19338 + l = h_sb->s_bdev->bd_disk->private_data;
19339 + h_adding = l->lo_backing_file->f_dentry;
19341 + * h_adding can be local NFS.
19342 + * in this case aufs cannot detect the loop.
19344 + if (unlikely(h_adding->d_sb == sb))
19346 + return !!au_test_subdir(h_adding, sb->s_root);
19349 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
19350 +int au_test_loopback_kthread(void)
19353 + struct task_struct *tsk = current;
19354 + char c, comm[sizeof(tsk->comm)];
19357 + if (tsk->flags & PF_KTHREAD) {
19358 + get_task_comm(comm, tsk);
19360 + ret = ('0' <= c && c <= '9'
19361 + && !strncmp(comm, "loop", 4));
19367 +/* ---------------------------------------------------------------------- */
19369 +#define au_warn_loopback_step 16
19370 +static int au_warn_loopback_nelem = au_warn_loopback_step;
19371 +static unsigned long *au_warn_loopback_array;
19373 +void au_warn_loopback(struct super_block *h_sb)
19375 + int i, new_nelem;
19376 + unsigned long *a, magic;
19377 + static DEFINE_SPINLOCK(spin);
19379 + magic = h_sb->s_magic;
19380 + spin_lock(&spin);
19381 + a = au_warn_loopback_array;
19382 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
19383 + if (a[i] == magic) {
19384 + spin_unlock(&spin);
19388 + /* h_sb is new to us, print it */
19389 + if (i < au_warn_loopback_nelem) {
19394 + /* expand the array */
19395 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
19396 + a = au_kzrealloc(au_warn_loopback_array,
19397 + au_warn_loopback_nelem * sizeof(unsigned long),
19398 + new_nelem * sizeof(unsigned long), GFP_ATOMIC);
19400 + au_warn_loopback_nelem = new_nelem;
19401 + au_warn_loopback_array = a;
19406 + spin_unlock(&spin);
19407 + AuWarn1("realloc failed, ignored\n");
19411 + spin_unlock(&spin);
19412 + pr_warn("you may want to try another patch for loopback file "
19413 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
19416 +int au_loopback_init(void)
19419 + struct super_block *sb __maybe_unused;
19421 + AuDebugOn(sizeof(sb->s_magic) != sizeof(unsigned long));
19424 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
19425 + sizeof(unsigned long), GFP_NOFS);
19426 + if (unlikely(!au_warn_loopback_array))
19432 +void au_loopback_fin(void)
19434 + kfree(au_warn_loopback_array);
19436 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
19437 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
19438 +++ linux/fs/aufs/loop.h 2013-07-30 22:42:55.842946719 +0200
19441 + * Copyright (C) 2005-2013 Junjiro R. Okajima
19443 + * This program, aufs is free software; you can redistribute it and/or modify
19444 + * it under the terms of the GNU General Public License as published by
19445 + * the Free Software Foundation; either version 2 of the License, or
19446 + * (at your option) any later version.
19448 + * This program is distributed in the hope that it will be useful,
19449 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19450 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19451 + * GNU General Public License for more details.
19453 + * You should have received a copy of the GNU General Public License
19454 + * along with this program; if not, write to the Free Software
19455 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19459 + * support for loopback mount as a branch
19462 +#ifndef __AUFS_LOOP_H__
19463 +#define __AUFS_LOOP_H__
19468 +struct super_block;
19470 +#ifdef CONFIG_AUFS_BDEV_LOOP
19472 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
19473 +int au_test_loopback_kthread(void);
19474 +void au_warn_loopback(struct super_block *h_sb);
19476 +int au_loopback_init(void);
19477 +void au_loopback_fin(void);
19479 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
19480 + struct dentry *h_adding)
19481 +AuStubInt0(au_test_loopback_kthread, void)
19482 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
19484 +AuStubInt0(au_loopback_init, void)
19485 +AuStubVoid(au_loopback_fin, void)
19486 +#endif /* BLK_DEV_LOOP */
19488 +#endif /* __KERNEL__ */
19489 +#endif /* __AUFS_LOOP_H__ */
19490 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
19491 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
19492 +++ linux/fs/aufs/magic.mk 2013-07-06 13:20:47.750198454 +0200
19495 +# defined in ${srctree}/fs/fuse/inode.c
19497 +ifdef CONFIG_FUSE_FS
19498 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
19501 +# defined in ${srctree}/fs/ocfs2/ocfs2_fs.h
19503 +ifdef CONFIG_OCFS2_FS
19504 +ccflags-y += -DOCFS2_SUPER_MAGIC=0x7461636f
19507 +# defined in ${srctree}/fs/ocfs2/dlm/userdlm.h
19509 +ifdef CONFIG_OCFS2_FS_O2CB
19510 +ccflags-y += -DDLMFS_MAGIC=0x76a9f425
19513 +# defined in ${srctree}/fs/cifs/cifsfs.c
19515 +ifdef CONFIG_CIFS_FS
19516 +ccflags-y += -DCIFS_MAGIC_NUMBER=0xFF534D42
19519 +# defined in ${srctree}/fs/xfs/xfs_sb.h
19521 +ifdef CONFIG_XFS_FS
19522 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
19525 +# defined in ${srctree}/fs/configfs/mount.c
19527 +ifdef CONFIG_CONFIGFS_FS
19528 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
19531 +# defined in ${srctree}/fs/9p/v9fs.h
19533 +ifdef CONFIG_9P_FS
19534 +ccflags-y += -DV9FS_MAGIC=0x01021997
19537 +# defined in ${srctree}/fs/ubifs/ubifs.h
19539 +ifdef CONFIG_UBIFS_FS
19540 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
19543 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
19545 +ifdef CONFIG_HFSPLUS_FS
19546 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
19548 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
19549 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
19550 +++ linux/fs/aufs/Makefile 2013-08-23 23:59:39.631583456 +0200
19553 +include ${src}/magic.mk
19554 +ifeq (${CONFIG_AUFS_FS},m)
19555 +include ${src}/conf.mk
19557 +-include ${src}/priv_def.mk
19559 +# cf. include/linux/kernel.h
19561 +ccflags-y += -DDEBUG
19562 +# sparse requires the full pathname
19564 +ccflags-y += -include ${M}/../../include/linux/aufs_type.h
19566 +ccflags-y += -include ${srctree}/include/linux/aufs_type.h
19569 +obj-$(CONFIG_AUFS_FS) += aufs.o
19570 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
19571 + wkq.o vfsub.o dcsub.o \
19572 + cpup.o whout.o wbr_policy.o \
19573 + dinfo.o dentry.o \
19575 + finfo.o file.o f_op.o \
19577 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
19581 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
19582 +aufs-$(CONFIG_SYSFS) += sysfs.o
19583 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
19584 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
19585 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
19586 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
19587 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
19588 +aufs-$(CONFIG_AUFS_POLL) += poll.o
19589 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
19590 +aufs-$(CONFIG_AUFS_SP_IATTR) += f_op_sp.o
19591 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
19592 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
19593 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
19594 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
19595 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
19596 +++ linux/fs/aufs/module.c 2013-07-06 13:20:47.750198454 +0200
19599 + * Copyright (C) 2005-2013 Junjiro R. Okajima
19601 + * This program, aufs is free software; you can redistribute it and/or modify
19602 + * it under the terms of the GNU General Public License as published by
19603 + * the Free Software Foundation; either version 2 of the License, or
19604 + * (at your option) any later version.
19606 + * This program is distributed in the hope that it will be useful,
19607 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19608 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19609 + * GNU General Public License for more details.
19611 + * You should have received a copy of the GNU General Public License
19612 + * along with this program; if not, write to the Free Software
19613 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19617 + * module global variables and operations
19620 +#include <linux/module.h>
19621 +#include <linux/seq_file.h>
19624 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp)
19626 + if (new_sz <= nused)
19629 + p = krealloc(p, new_sz, gfp);
19631 + memset(p + nused, 0, new_sz - nused);
19635 +/* ---------------------------------------------------------------------- */
19640 +struct kmem_cache *au_cachep[AuCache_Last];
19641 +static int __init au_cache_init(void)
19643 + au_cachep[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
19644 + if (au_cachep[AuCache_DINFO])
19645 + /* SLAB_DESTROY_BY_RCU */
19646 + au_cachep[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
19647 + au_icntnr_init_once);
19648 + if (au_cachep[AuCache_ICNTNR])
19649 + au_cachep[AuCache_FINFO] = AuCacheCtor(au_finfo,
19650 + au_fi_init_once);
19651 + if (au_cachep[AuCache_FINFO])
19652 + au_cachep[AuCache_VDIR] = AuCache(au_vdir);
19653 + if (au_cachep[AuCache_VDIR])
19654 + au_cachep[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
19655 + if (au_cachep[AuCache_DEHSTR])
19661 +static void au_cache_fin(void)
19666 + * Make sure all delayed rcu free inodes are flushed before we
19671 + /* excluding AuCache_HNOTIFY */
19672 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
19673 + for (i = 0; i < AuCache_HNOTIFY; i++)
19674 + if (au_cachep[i]) {
19675 + kmem_cache_destroy(au_cachep[i]);
19676 + au_cachep[i] = NULL;
19680 +/* ---------------------------------------------------------------------- */
19682 +int au_dir_roflags;
19684 +#ifdef CONFIG_AUFS_SBILIST
19686 + * iterate_supers_type() doesn't protect us from
19687 + * remounting (branch management)
19689 +struct au_splhead au_sbilist;
19692 +struct lock_class_key au_lc_key[AuLcKey_Last];
19695 + * functions for module interface.
19697 +MODULE_LICENSE("GPL");
19698 +/* MODULE_LICENSE("GPL v2"); */
19699 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
19700 +MODULE_DESCRIPTION(AUFS_NAME
19701 + " -- Advanced multi layered unification filesystem");
19702 +MODULE_VERSION(AUFS_VERSION);
19703 +MODULE_ALIAS_FS(AUFS_NAME);
19705 +/* this module parameter has no meaning when SYSFS is disabled */
19706 +int sysaufs_brs = 1;
19707 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
19708 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
19710 +/* ---------------------------------------------------------------------- */
19712 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
19714 +int au_seq_path(struct seq_file *seq, struct path *path)
19716 + return seq_path(seq, path, au_esc_chars);
19719 +/* ---------------------------------------------------------------------- */
19721 +static int __init aufs_init(void)
19726 + p = au_esc_chars;
19727 + for (i = 1; i <= ' '; i++)
19733 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
19735 + au_sbilist_init();
19736 + sysaufs_brs_init();
19739 + err = sysaufs_init();
19740 + if (unlikely(err))
19742 + err = au_procfs_init();
19743 + if (unlikely(err))
19744 + goto out_sysaufs;
19745 + err = au_wkq_init();
19746 + if (unlikely(err))
19748 + err = au_loopback_init();
19749 + if (unlikely(err))
19751 + err = au_hnotify_init();
19752 + if (unlikely(err))
19753 + goto out_loopback;
19754 + err = au_sysrq_init();
19755 + if (unlikely(err))
19757 + err = au_cache_init();
19758 + if (unlikely(err))
19760 + err = register_filesystem(&aufs_fs_type);
19761 + if (unlikely(err))
19763 + /* since we define pr_fmt, call printk directly */
19764 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
19765 + goto out; /* success */
19772 + au_hnotify_fin();
19774 + au_loopback_fin();
19786 +static void __exit aufs_exit(void)
19788 + unregister_filesystem(&aufs_fs_type);
19791 + au_hnotify_fin();
19792 + au_loopback_fin();
19799 +module_init(aufs_init);
19800 +module_exit(aufs_exit);
19801 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
19802 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
19803 +++ linux/fs/aufs/module.h 2013-07-06 13:20:47.750198454 +0200
19806 + * Copyright (C) 2005-2013 Junjiro R. Okajima
19808 + * This program, aufs is free software; you can redistribute it and/or modify
19809 + * it under the terms of the GNU General Public License as published by
19810 + * the Free Software Foundation; either version 2 of the License, or
19811 + * (at your option) any later version.
19813 + * This program is distributed in the hope that it will be useful,
19814 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19815 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19816 + * GNU General Public License for more details.
19818 + * You should have received a copy of the GNU General Public License
19819 + * along with this program; if not, write to the Free Software
19820 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19824 + * module initialization and module-global
19827 +#ifndef __AUFS_MODULE_H__
19828 +#define __AUFS_MODULE_H__
19832 +#include <linux/slab.h>
19837 +/* module parameters */
19838 +extern int sysaufs_brs;
19840 +/* ---------------------------------------------------------------------- */
19842 +extern int au_dir_roflags;
19845 + AuLcNonDir_FIINFO,
19846 + AuLcNonDir_DIINFO,
19847 + AuLcNonDir_IIINFO,
19853 + AuLcSymlink_DIINFO,
19854 + AuLcSymlink_IIINFO,
19858 +extern struct lock_class_key au_lc_key[AuLcKey_Last];
19860 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp);
19861 +int au_seq_path(struct seq_file *seq, struct path *path);
19863 +#ifdef CONFIG_PROC_FS
19865 +int __init au_procfs_init(void);
19866 +void au_procfs_fin(void);
19868 +AuStubInt0(au_procfs_init, void);
19869 +AuStubVoid(au_procfs_fin, void);
19872 +/* ---------------------------------------------------------------------- */
19881 + AuCache_HNOTIFY, /* must be last */
19885 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
19886 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
19887 +#define AuCacheCtor(type, ctor) \
19888 + kmem_cache_create(#type, sizeof(struct type), \
19889 + __alignof__(struct type), AuCacheFlags, ctor)
19891 +extern struct kmem_cache *au_cachep[];
19893 +#define AuCacheFuncs(name, index) \
19894 +static inline struct au_##name *au_cache_alloc_##name(void) \
19895 +{ return kmem_cache_alloc(au_cachep[AuCache_##index], GFP_NOFS); } \
19896 +static inline void au_cache_free_##name(struct au_##name *p) \
19897 +{ kmem_cache_free(au_cachep[AuCache_##index], p); }
19899 +AuCacheFuncs(dinfo, DINFO);
19900 +AuCacheFuncs(icntnr, ICNTNR);
19901 +AuCacheFuncs(finfo, FINFO);
19902 +AuCacheFuncs(vdir, VDIR);
19903 +AuCacheFuncs(vdir_dehstr, DEHSTR);
19904 +#ifdef CONFIG_AUFS_HNOTIFY
19905 +AuCacheFuncs(hnotify, HNOTIFY);
19908 +#endif /* __KERNEL__ */
19909 +#endif /* __AUFS_MODULE_H__ */
19910 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
19911 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
19912 +++ linux/fs/aufs/mvdown.c 2013-08-23 23:59:39.634916914 +0200
19915 + * Copyright (C) 2011-2013 Junjiro R. Okajima
19917 + * This program, aufs is free software; you can redistribute it and/or modify
19918 + * it under the terms of the GNU General Public License as published by
19919 + * the Free Software Foundation; either version 2 of the License, or
19920 + * (at your option) any later version.
19922 + * This program is distributed in the hope that it will be useful,
19923 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19924 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19925 + * GNU General Public License for more details.
19927 + * You should have received a copy of the GNU General Public License
19928 + * along with this program; if not, write to the Free Software
19929 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19937 + AUFS_MVDOWN_NARRAY
19940 +struct au_mvd_args {
19942 + aufs_bindex_t bindex;
19943 + struct super_block *h_sb;
19944 + struct dentry *h_parent;
19945 + struct au_hinode *hdir;
19946 + struct inode *h_dir;
19947 + } info[AUFS_MVDOWN_NARRAY];
19949 + struct aufs_mvdown mvdown;
19950 + struct dentry *dentry, *parent;
19951 + struct inode *inode, *dir;
19952 + struct super_block *sb;
19953 + aufs_bindex_t bopq, bwh, bfound;
19954 + unsigned char rename_lock;
19955 + struct au_pin pin;
19958 +#define mvd_bsrc info[AUFS_MVDOWN_SRC].bindex
19959 +#define mvd_h_src_sb info[AUFS_MVDOWN_SRC].h_sb
19960 +#define mvd_h_src_parent info[AUFS_MVDOWN_SRC].h_parent
19961 +#define mvd_hdir_src info[AUFS_MVDOWN_SRC].hdir
19962 +#define mvd_h_src_dir info[AUFS_MVDOWN_SRC].h_dir
19964 +#define mvd_bdst info[AUFS_MVDOWN_DST].bindex
19965 +#define mvd_h_dst_sb info[AUFS_MVDOWN_DST].h_sb
19966 +#define mvd_h_dst_parent info[AUFS_MVDOWN_DST].h_parent
19967 +#define mvd_hdir_dst info[AUFS_MVDOWN_DST].hdir
19968 +#define mvd_h_dst_dir info[AUFS_MVDOWN_DST].h_dir
19970 +#define AU_MVD_PR(flag, ...) do { \
19972 + pr_err(__VA_ARGS__); \
19975 +/* make the parent dir on bdst */
19976 +static int au_do_mkdir(const unsigned char verbose, struct au_mvd_args *a)
19981 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
19982 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
19983 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
19984 + a->mvd_h_dst_parent = NULL;
19985 + if (au_dbend(a->parent) >= a->mvd_bdst)
19986 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
19987 + if (!a->mvd_h_dst_parent) {
19988 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
19989 + if (unlikely(err)) {
19990 + AU_MVD_PR(verbose, "cpdown_dirs failed\n");
19993 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
20001 +/* lock them all */
20002 +static int au_do_lock(const unsigned char verbose, struct au_mvd_args *a)
20005 + struct dentry *h_trap;
20007 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
20008 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
20009 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
20010 + a->rename_lock = 0;
20011 + err = au_pin(&a->pin, a->dentry, a->mvd_bdst, au_opt_udba(a->sb),
20012 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
20014 + a->mvd_h_src_dir = a->mvd_h_src_parent->d_inode;
20015 + mutex_lock_nested(&a->mvd_h_src_dir->i_mutex,
20016 + AuLsc_I_PARENT3);
20018 + AU_MVD_PR(verbose, "pin failed\n");
20023 + a->rename_lock = 1;
20024 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
20025 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
20027 + err = (h_trap != a->mvd_h_src_parent);
20029 + err = (h_trap != a->mvd_h_dst_parent);
20031 + BUG_ON(err); /* it should never happen */
20038 +static void au_do_unlock(const unsigned char verbose, struct au_mvd_args *a)
20040 + if (!a->rename_lock) {
20041 + mutex_unlock(&a->mvd_h_src_dir->i_mutex);
20042 + au_unpin(&a->pin);
20044 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
20045 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
20048 +/* copy-down the file */
20049 +static int au_do_cpdown(const unsigned char verbose, struct au_mvd_args *a)
20052 + struct au_cp_generic cpg = {
20053 + .dentry = a->dentry,
20054 + .bdst = a->mvd_bdst,
20055 + .bsrc = a->mvd_bsrc,
20058 + .flags = AuCpup_DTIME | AuCpup_HOPEN
20061 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
20062 + err = au_sio_cpdown_simple(&cpg);
20063 + if (unlikely(err))
20064 + AU_MVD_PR(verbose, "cpdown failed\n");
20071 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
20074 +static int au_do_unlink_wh(const unsigned char verbose, struct au_mvd_args *a)
20077 + struct path h_path;
20078 + struct au_branch *br;
20080 + br = au_sbr(a->sb, a->mvd_bdst);
20081 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
20082 + err = PTR_ERR(h_path.dentry);
20083 + if (IS_ERR(h_path.dentry)) {
20084 + AU_MVD_PR(verbose, "wh_lkup failed\n");
20089 + if (h_path.dentry->d_inode) {
20090 + h_path.mnt = au_br_mnt(br);
20091 + err = vfsub_unlink(a->mvd_h_dst_parent->d_inode, &h_path,
20093 + if (unlikely(err))
20094 + AU_MVD_PR(verbose, "wh_unlink failed\n");
20096 + dput(h_path.dentry);
20104 + * unlink the topmost h_dentry
20105 + * Note: the target file MAY be modified by UDBA between this mutex_unlock() and
20106 + * mutex_lock() in vfs_unlink(). in this case, such changes may be lost.
20108 +static int au_do_unlink(const unsigned char verbose, struct au_mvd_args *a)
20111 + struct path h_path;
20113 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
20114 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
20115 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, /*force*/0);
20116 + if (unlikely(err))
20117 + AU_MVD_PR(verbose, "unlink failed\n");
20124 + * copy-down the file and unlink the bsrc file.
20125 + * - unlink the bdst whout if exist
20126 + * - copy-down the file (with whtmp name and rename)
20127 + * - unlink the bsrc file
20129 +static int au_do_mvdown(const unsigned char verbose, struct au_mvd_args *a)
20133 + err = au_do_mkdir(verbose, a);
20135 + err = au_do_lock(verbose, a);
20136 + if (unlikely(err))
20140 + * do not revert the activities we made on bdst since they should be
20141 + * harmless in aufs.
20144 + err = au_do_cpdown(verbose, a);
20146 + err = au_do_unlink_wh(verbose, a);
20148 + err = au_do_unlink(verbose, a);
20149 + if (unlikely(err))
20152 + /* maintain internal array */
20153 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
20154 + au_set_dbstart(a->dentry, a->mvd_bdst);
20155 + if (au_dbend(a->dentry) < a->mvd_bdst)
20156 + au_set_dbend(a->dentry, a->mvd_bdst);
20157 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
20158 + au_set_ibstart(a->inode, a->mvd_bdst);
20159 + if (au_ibend(a->inode) < a->mvd_bdst)
20160 + au_set_ibend(a->inode, a->mvd_bdst);
20163 + au_do_unlock(verbose, a);
20169 +/* ---------------------------------------------------------------------- */
20171 +static int find_lower_writable(struct super_block *sb, aufs_bindex_t bindex)
20173 + aufs_bindex_t bend;
20174 + struct au_branch *br;
20176 + bend = au_sbend(sb);
20177 + for (bindex++; bindex <= bend; bindex++) {
20178 + br = au_sbr(sb, bindex);
20179 + if (!au_br_rdonly(br))
20186 +/* make sure the file is idle */
20187 +static int au_mvd_args_busy(const unsigned char verbose, struct au_mvd_args *a)
20189 + int err, plinked;
20190 + struct inode *h_src_inode;
20193 + h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
20194 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
20195 + if (au_dbstart(a->dentry) == a->mvd_bsrc
20196 + && a->dentry->d_count == 1
20197 + && atomic_read(&a->inode->i_count) == 1
20198 + /* && h_src_inode->i_nlink == 1 */
20199 + && (!plinked || !au_plink_test(a->inode))
20200 + && a->inode->i_nlink == 1)
20204 + AU_MVD_PR(verbose,
20205 + "b%d, d{b%d, c%u?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
20206 + a->mvd_bsrc, au_dbstart(a->dentry), a->dentry->d_count,
20207 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
20208 + h_src_inode->i_nlink,
20209 + plinked, plinked ? au_plink_test(a->inode) : 0);
20216 +/* make sure the parent dir is fine */
20217 +static int au_mvd_args_parent(const unsigned char verbose,
20218 + struct au_mvd_args *a)
20221 + aufs_bindex_t bindex;
20224 + if (unlikely(au_alive_dir(a->parent))) {
20226 + AU_MVD_PR(verbose, "parent dir is dead\n");
20230 + a->bopq = au_dbdiropq(a->parent);
20231 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
20232 + AuDbg("b%d\n", bindex);
20233 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
20234 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
20236 + AU_MVD_PR(verbose, "parent dir is opaque b%d, b%d\n",
20237 + a->bopq, a->mvd_bdst);
20245 +static int au_mvd_args_intermediate(const unsigned char verbose,
20246 + struct au_mvd_args *a)
20249 + struct au_dinfo *dinfo, *tmp;
20251 + /* lookup the next lower positive entry */
20253 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
20254 + if (unlikely(!tmp))
20259 + dinfo = au_di(a->dentry);
20260 + au_di_cp(tmp, dinfo);
20261 + au_di_swap(tmp, dinfo);
20263 + /* returns the number of positive dentries */
20264 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1, /*type*/0);
20266 + a->bwh = au_dbwh(a->dentry);
20267 + else if (err > 0)
20268 + a->bfound = au_dbstart(a->dentry);
20270 + au_di_swap(tmp, dinfo);
20271 + au_rw_write_unlock(&tmp->di_rwsem);
20273 + if (unlikely(err < 0))
20274 + AU_MVD_PR(verbose, "failed look-up lower\n");
20277 + * here, we have these cases.
20279 + * no positive dentry under bsrc. there are more sub-cases.
20281 + * there no whiteout, we can safely move-down.
20284 + * bsrc < bwh && bwh < bdst
20285 + * there is a whiteout on RO branch. cannot proceed.
20287 + * there is a whiteout on the RW target branch. it should
20290 + * there is a whiteout somewhere unrelated branch.
20291 + * -1 < bfound && bfound <= bsrc
20294 + * found, but it is on RO branch between bsrc and bdst. cannot
20297 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
20300 + * found, after we create the file on bdst, it will be hidden.
20303 + AuDebugOn(a->bfound == -1
20305 + && a->bwh <= a->mvd_bsrc);
20306 + AuDebugOn(-1 < a->bfound
20307 + && a->bfound <= a->mvd_bsrc);
20310 + if (a->bfound == -1
20311 + && a->mvd_bsrc < a->bwh
20313 + && a->bwh < a->mvd_bdst) {
20314 + AU_MVD_PR(verbose, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
20315 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
20317 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
20318 + AU_MVD_PR(verbose, "bdst %d, bfound %d\n",
20319 + a->mvd_bdst, a->bfound);
20323 + err = 0; /* success */
20330 +static int au_mvd_args_exist(const unsigned char verbose, struct au_mvd_args *a)
20334 + err = (a->bfound != a->mvd_bdst) ? 0 : -EEXIST;
20339 +static int au_mvd_args(const unsigned char verbose, struct au_mvd_args *a)
20342 + struct au_branch *br;
20345 + if (unlikely(S_ISDIR(a->inode->i_mode)))
20349 + a->mvd_bsrc = au_ibstart(a->inode);
20350 + if (unlikely(a->mvd_bsrc == au_sbend(a->sb))) {
20351 + AU_MVD_PR(verbose, "on the bottom\n");
20354 + br = au_sbr(a->sb, a->mvd_bsrc);
20355 + err = au_br_rdonly(br);
20356 + if (unlikely(err))
20360 + a->mvd_bdst = find_lower_writable(a->sb, a->mvd_bsrc);
20361 + if (unlikely(a->mvd_bdst < 0)) {
20362 + AU_MVD_PR(verbose, "no writable lower branch\n");
20366 + err = au_mvd_args_busy(verbose, a);
20368 + err = au_mvd_args_parent(verbose, a);
20370 + err = au_mvd_args_intermediate(verbose, a);
20372 + err = au_mvd_args_exist(verbose, a);
20374 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
20381 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
20384 + unsigned char verbose;
20385 + struct au_mvd_args args = {
20386 + .dentry = dentry,
20387 + .inode = dentry->d_inode,
20388 + .sb = dentry->d_sb
20392 + if (unlikely(!capable(CAP_SYS_ADMIN)))
20395 + err = copy_from_user(&args.mvdown, uarg, sizeof(args.mvdown));
20396 + if (unlikely(err)) {
20400 + AuDbg("flags 0x%x\n", args.mvdown.flags);
20403 + verbose = !!(args.mvdown.flags & AUFS_MVDOWN_VERBOSE);
20404 + args.parent = dget_parent(dentry);
20405 + args.dir = args.parent->d_inode;
20406 + mutex_lock_nested(&args.dir->i_mutex, I_MUTEX_PARENT);
20407 + dput(args.parent);
20408 + if (unlikely(args.parent != dentry->d_parent)) {
20409 + AU_MVD_PR(verbose, "parent dir is moved\n");
20413 + mutex_lock_nested(&args.inode->i_mutex, I_MUTEX_CHILD);
20414 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH);
20415 + if (unlikely(err))
20418 + di_write_lock_parent(args.parent);
20419 + err = au_mvd_args(verbose, &args);
20420 + if (unlikely(err))
20423 + AuDbgDentry(dentry);
20424 + AuDbgInode(args.inode);
20425 + err = au_do_mvdown(verbose, &args);
20426 + if (unlikely(err))
20428 + AuDbgDentry(dentry);
20429 + AuDbgInode(args.inode);
20431 + au_cpup_attr_timesizes(args.dir);
20432 + au_cpup_attr_timesizes(args.inode);
20433 + au_cpup_igen(args.inode, au_h_iptr(args.inode, args.mvd_bdst));
20434 + /* au_digen_dec(dentry); */
20437 + di_write_unlock(args.parent);
20438 + aufs_read_unlock(dentry, AuLock_DW);
20440 + mutex_unlock(&args.inode->i_mutex);
20442 + mutex_unlock(&args.dir->i_mutex);
20447 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
20448 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
20449 +++ linux/fs/aufs/opts.c 2013-07-06 13:20:47.753531903 +0200
20452 + * Copyright (C) 2005-2013 Junjiro R. Okajima
20454 + * This program, aufs is free software; you can redistribute it and/or modify
20455 + * it under the terms of the GNU General Public License as published by
20456 + * the Free Software Foundation; either version 2 of the License, or
20457 + * (at your option) any later version.
20459 + * This program is distributed in the hope that it will be useful,
20460 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20461 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20462 + * GNU General Public License for more details.
20464 + * You should have received a copy of the GNU General Public License
20465 + * along with this program; if not, write to the Free Software
20466 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20470 + * mount options/flags
20473 +#include <linux/namei.h>
20474 +#include <linux/types.h> /* a distribution requires */
20475 +#include <linux/parser.h>
20478 +/* ---------------------------------------------------------------------- */
20482 + Opt_add, Opt_del, Opt_mod, Opt_reorder, Opt_append, Opt_prepend,
20483 + Opt_idel, Opt_imod, Opt_ireorder,
20484 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash, Opt_rendir,
20485 + Opt_rdblk_def, Opt_rdhash_def,
20486 + Opt_xino, Opt_zxino, Opt_noxino,
20487 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
20488 + Opt_trunc_xino_path, Opt_itrunc_xino,
20489 + Opt_trunc_xib, Opt_notrunc_xib,
20490 + Opt_shwh, Opt_noshwh,
20491 + Opt_plink, Opt_noplink, Opt_list_plink,
20493 + Opt_dio, Opt_nodio,
20494 + /* Opt_lock, Opt_unlock, */
20495 + Opt_cmd, Opt_cmd_args,
20496 + Opt_diropq_a, Opt_diropq_w,
20497 + Opt_warn_perm, Opt_nowarn_perm,
20498 + Opt_wbr_copyup, Opt_wbr_create,
20499 + Opt_refrof, Opt_norefrof,
20500 + Opt_verbose, Opt_noverbose,
20501 + Opt_sum, Opt_nosum, Opt_wsum,
20502 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
20505 +static match_table_t options = {
20506 + {Opt_br, "br=%s"},
20507 + {Opt_br, "br:%s"},
20509 + {Opt_add, "add=%d:%s"},
20510 + {Opt_add, "add:%d:%s"},
20511 + {Opt_add, "ins=%d:%s"},
20512 + {Opt_add, "ins:%d:%s"},
20513 + {Opt_append, "append=%s"},
20514 + {Opt_append, "append:%s"},
20515 + {Opt_prepend, "prepend=%s"},
20516 + {Opt_prepend, "prepend:%s"},
20518 + {Opt_del, "del=%s"},
20519 + {Opt_del, "del:%s"},
20520 + /* {Opt_idel, "idel:%d"}, */
20521 + {Opt_mod, "mod=%s"},
20522 + {Opt_mod, "mod:%s"},
20523 + /* {Opt_imod, "imod:%d:%s"}, */
20525 + {Opt_dirwh, "dirwh=%d"},
20527 + {Opt_xino, "xino=%s"},
20528 + {Opt_noxino, "noxino"},
20529 + {Opt_trunc_xino, "trunc_xino"},
20530 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
20531 + {Opt_notrunc_xino, "notrunc_xino"},
20532 + {Opt_trunc_xino_path, "trunc_xino=%s"},
20533 + {Opt_itrunc_xino, "itrunc_xino=%d"},
20534 + /* {Opt_zxino, "zxino=%s"}, */
20535 + {Opt_trunc_xib, "trunc_xib"},
20536 + {Opt_notrunc_xib, "notrunc_xib"},
20538 +#ifdef CONFIG_PROC_FS
20539 + {Opt_plink, "plink"},
20541 + {Opt_ignore_silent, "plink"},
20544 + {Opt_noplink, "noplink"},
20546 +#ifdef CONFIG_AUFS_DEBUG
20547 + {Opt_list_plink, "list_plink"},
20550 + {Opt_udba, "udba=%s"},
20552 + {Opt_dio, "dio"},
20553 + {Opt_nodio, "nodio"},
20555 + {Opt_diropq_a, "diropq=always"},
20556 + {Opt_diropq_a, "diropq=a"},
20557 + {Opt_diropq_w, "diropq=whiteouted"},
20558 + {Opt_diropq_w, "diropq=w"},
20560 + {Opt_warn_perm, "warn_perm"},
20561 + {Opt_nowarn_perm, "nowarn_perm"},
20563 + /* keep them temporary */
20564 + {Opt_ignore_silent, "coo=%s"},
20565 + {Opt_ignore_silent, "nodlgt"},
20566 + {Opt_ignore_silent, "nodirperm1"},
20567 + {Opt_ignore_silent, "clean_plink"},
20569 +#ifdef CONFIG_AUFS_SHWH
20570 + {Opt_shwh, "shwh"},
20572 + {Opt_noshwh, "noshwh"},
20574 + {Opt_rendir, "rendir=%d"},
20576 + {Opt_refrof, "refrof"},
20577 + {Opt_norefrof, "norefrof"},
20579 + {Opt_verbose, "verbose"},
20580 + {Opt_verbose, "v"},
20581 + {Opt_noverbose, "noverbose"},
20582 + {Opt_noverbose, "quiet"},
20583 + {Opt_noverbose, "q"},
20584 + {Opt_noverbose, "silent"},
20586 + {Opt_sum, "sum"},
20587 + {Opt_nosum, "nosum"},
20588 + {Opt_wsum, "wsum"},
20590 + {Opt_rdcache, "rdcache=%d"},
20591 + {Opt_rdblk, "rdblk=%d"},
20592 + {Opt_rdblk_def, "rdblk=def"},
20593 + {Opt_rdhash, "rdhash=%d"},
20594 + {Opt_rdhash_def, "rdhash=def"},
20596 + {Opt_wbr_create, "create=%s"},
20597 + {Opt_wbr_create, "create_policy=%s"},
20598 + {Opt_wbr_copyup, "cpup=%s"},
20599 + {Opt_wbr_copyup, "copyup=%s"},
20600 + {Opt_wbr_copyup, "copyup_policy=%s"},
20602 + /* internal use for the scripts */
20603 + {Opt_ignore_silent, "si=%s"},
20605 + {Opt_br, "dirs=%s"},
20606 + {Opt_ignore, "debug=%d"},
20607 + {Opt_ignore, "delete=whiteout"},
20608 + {Opt_ignore, "delete=all"},
20609 + {Opt_ignore, "imap=%s"},
20611 + /* temporary workaround, due to old mount(8)? */
20612 + {Opt_ignore_silent, "relatime"},
20617 +/* ---------------------------------------------------------------------- */
20619 +static const char *au_parser_pattern(int val, struct match_token *token)
20621 + while (token->pattern) {
20622 + if (token->token == val)
20623 + return token->pattern;
20630 +/* ---------------------------------------------------------------------- */
20632 +static match_table_t brperm = {
20633 + {AuBrPerm_RO, AUFS_BRPERM_RO},
20634 + {AuBrPerm_RR, AUFS_BRPERM_RR},
20635 + {AuBrPerm_RW, AUFS_BRPERM_RW},
20639 +static match_table_t brattr = {
20640 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
20641 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
20642 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
20646 +#define AuBrStr_LONGEST AUFS_BRPERM_RW \
20647 + "+" AUFS_BRATTR_UNPIN \
20648 + "+" AUFS_BRWATTR_NLWH
20650 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
20657 + p = strchr(str, '+');
20660 + v = match_token(str, table, args);
20666 + pr_warn("ignored branch attribute %s\n", str);
20676 +static int noinline_for_stack br_perm_val(char *perm)
20680 + substring_t args[MAX_OPT_ARGS];
20682 + p = strchr(perm, '+');
20685 + val = match_token(perm, brperm, args);
20689 + pr_warn("ignored branch permission %s\n", perm);
20690 + val = AuBrPerm_RO;
20698 + q = strchr(p, '+');
20701 + val |= br_attr_val(p, brattr, args);
20708 + switch (val & AuBrPerm_Mask) {
20709 + case AuBrPerm_RO:
20710 + case AuBrPerm_RR:
20711 + if (unlikely(val & AuBrWAttr_NoLinkWH)) {
20712 + pr_warn("ignored branch attribute %s\n",
20713 + AUFS_BRWATTR_NLWH);
20714 + val &= ~AuBrWAttr_NoLinkWH;
20717 + case AuBrPerm_RW:
20718 + if (unlikely(val & AuBrRAttr_WH)) {
20719 + pr_warn("ignored branch attribute %s\n",
20720 + AUFS_BRRATTR_WH);
20721 + val &= ~AuBrRAttr_WH;
20730 +/* Caller should free the return value */
20731 +char *au_optstr_br_perm(int brperm)
20733 + char *p, a[sizeof(AuBrStr_LONGEST)];
20736 +#define SetPerm(str) do { \
20737 + sz = sizeof(str); \
20738 + memcpy(a, str, sz); \
20739 + p = a + sz - 1; \
20742 +#define AppendAttr(flag, str) do { \
20743 + if (brperm & flag) { \
20744 + sz = sizeof(str); \
20746 + memcpy(p, str, sz); \
20751 + switch (brperm & AuBrPerm_Mask) {
20752 + case AuBrPerm_RO:
20753 + SetPerm(AUFS_BRPERM_RO);
20755 + case AuBrPerm_RR:
20756 + SetPerm(AUFS_BRPERM_RR);
20758 + case AuBrPerm_RW:
20759 + SetPerm(AUFS_BRPERM_RW);
20765 + AppendAttr(AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN);
20766 + AppendAttr(AuBrRAttr_WH, AUFS_BRRATTR_WH);
20767 + AppendAttr(AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH);
20769 + AuDebugOn(strlen(a) >= sizeof(a));
20770 + return kstrdup(a, GFP_NOFS);
20775 +/* ---------------------------------------------------------------------- */
20777 +static match_table_t udbalevel = {
20778 + {AuOpt_UDBA_REVAL, "reval"},
20779 + {AuOpt_UDBA_NONE, "none"},
20780 +#ifdef CONFIG_AUFS_HNOTIFY
20781 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
20782 +#ifdef CONFIG_AUFS_HFSNOTIFY
20783 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
20789 +static int noinline_for_stack udba_val(char *str)
20791 + substring_t args[MAX_OPT_ARGS];
20793 + return match_token(str, udbalevel, args);
20796 +const char *au_optstr_udba(int udba)
20798 + return au_parser_pattern(udba, (void *)udbalevel);
20801 +/* ---------------------------------------------------------------------- */
20803 +static match_table_t au_wbr_create_policy = {
20804 + {AuWbrCreate_TDP, "tdp"},
20805 + {AuWbrCreate_TDP, "top-down-parent"},
20806 + {AuWbrCreate_RR, "rr"},
20807 + {AuWbrCreate_RR, "round-robin"},
20808 + {AuWbrCreate_MFS, "mfs"},
20809 + {AuWbrCreate_MFS, "most-free-space"},
20810 + {AuWbrCreate_MFSV, "mfs:%d"},
20811 + {AuWbrCreate_MFSV, "most-free-space:%d"},
20813 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
20814 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
20815 + {AuWbrCreate_PMFS, "pmfs"},
20816 + {AuWbrCreate_PMFSV, "pmfs:%d"},
20822 + * cf. linux/lib/parser.c and cmdline.c
20823 + * gave up calling memparse() since it uses simple_strtoull() instead of
20826 +static int noinline_for_stack
20827 +au_match_ull(substring_t *s, unsigned long long *result)
20830 + unsigned int len;
20834 + len = s->to - s->from;
20835 + if (len + 1 <= sizeof(a)) {
20836 + memcpy(a, s->from, len);
20838 + err = kstrtoull(a, 0, result);
20843 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
20844 + struct au_opt_wbr_create *create)
20847 + unsigned long long ull;
20850 + if (!au_match_ull(arg, &ull))
20851 + create->mfsrr_watermark = ull;
20853 + pr_err("bad integer in %s\n", str);
20860 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
20861 + struct au_opt_wbr_create *create)
20866 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
20867 + create->mfs_second = n;
20869 + pr_err("bad integer in %s\n", str);
20876 +static int noinline_for_stack
20877 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
20880 + substring_t args[MAX_OPT_ARGS];
20882 + err = match_token(str, au_wbr_create_policy, args);
20883 + create->wbr_create = err;
20885 + case AuWbrCreate_MFSRRV:
20886 + e = au_wbr_mfs_wmark(&args[0], str, create);
20888 + e = au_wbr_mfs_sec(&args[1], str, create);
20892 + case AuWbrCreate_MFSRR:
20893 + e = au_wbr_mfs_wmark(&args[0], str, create);
20894 + if (unlikely(e)) {
20899 + case AuWbrCreate_MFS:
20900 + case AuWbrCreate_PMFS:
20901 + create->mfs_second = AUFS_MFS_DEF_SEC;
20903 + case AuWbrCreate_MFSV:
20904 + case AuWbrCreate_PMFSV:
20905 + e = au_wbr_mfs_sec(&args[0], str, create);
20914 +const char *au_optstr_wbr_create(int wbr_create)
20916 + return au_parser_pattern(wbr_create, (void *)au_wbr_create_policy);
20919 +static match_table_t au_wbr_copyup_policy = {
20920 + {AuWbrCopyup_TDP, "tdp"},
20921 + {AuWbrCopyup_TDP, "top-down-parent"},
20922 + {AuWbrCopyup_BUP, "bup"},
20923 + {AuWbrCopyup_BUP, "bottom-up-parent"},
20924 + {AuWbrCopyup_BU, "bu"},
20925 + {AuWbrCopyup_BU, "bottom-up"},
20929 +static int noinline_for_stack au_wbr_copyup_val(char *str)
20931 + substring_t args[MAX_OPT_ARGS];
20933 + return match_token(str, au_wbr_copyup_policy, args);
20936 +const char *au_optstr_wbr_copyup(int wbr_copyup)
20938 + return au_parser_pattern(wbr_copyup, (void *)au_wbr_copyup_policy);
20941 +/* ---------------------------------------------------------------------- */
20943 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
20945 +static void dump_opts(struct au_opts *opts)
20947 +#ifdef CONFIG_AUFS_DEBUG
20948 + /* reduce stack space */
20950 + struct au_opt_add *add;
20951 + struct au_opt_del *del;
20952 + struct au_opt_mod *mod;
20953 + struct au_opt_xino *xino;
20954 + struct au_opt_xino_itrunc *xino_itrunc;
20955 + struct au_opt_wbr_create *create;
20957 + struct au_opt *opt;
20960 + while (opt->type != Opt_tail) {
20961 + switch (opt->type) {
20963 + u.add = &opt->add;
20964 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
20965 + u.add->bindex, u.add->pathname, u.add->perm,
20966 + u.add->path.dentry);
20970 + u.del = &opt->del;
20971 + AuDbg("del {%s, %p}\n",
20972 + u.del->pathname, u.del->h_path.dentry);
20976 + u.mod = &opt->mod;
20977 + AuDbg("mod {%s, 0x%x, %p}\n",
20978 + u.mod->path, u.mod->perm, u.mod->h_root);
20981 + u.add = &opt->add;
20982 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
20983 + u.add->bindex, u.add->pathname, u.add->perm,
20984 + u.add->path.dentry);
20986 + case Opt_prepend:
20987 + u.add = &opt->add;
20988 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
20989 + u.add->bindex, u.add->pathname, u.add->perm,
20990 + u.add->path.dentry);
20993 + AuDbg("dirwh %d\n", opt->dirwh);
20995 + case Opt_rdcache:
20996 + AuDbg("rdcache %d\n", opt->rdcache);
20999 + AuDbg("rdblk %u\n", opt->rdblk);
21001 + case Opt_rdblk_def:
21002 + AuDbg("rdblk_def\n");
21005 + AuDbg("rdhash %u\n", opt->rdhash);
21007 + case Opt_rdhash_def:
21008 + AuDbg("rdhash_def\n");
21011 + u.xino = &opt->xino;
21012 + AuDbg("xino {%s %.*s}\n",
21014 + AuDLNPair(u.xino->file->f_dentry));
21016 + case Opt_trunc_xino:
21017 + AuLabel(trunc_xino);
21019 + case Opt_notrunc_xino:
21020 + AuLabel(notrunc_xino);
21022 + case Opt_trunc_xino_path:
21023 + case Opt_itrunc_xino:
21024 + u.xino_itrunc = &opt->xino_itrunc;
21025 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
21031 + case Opt_trunc_xib:
21032 + AuLabel(trunc_xib);
21034 + case Opt_notrunc_xib:
21035 + AuLabel(notrunc_xib);
21046 + case Opt_noplink:
21047 + AuLabel(noplink);
21049 + case Opt_list_plink:
21050 + AuLabel(list_plink);
21053 + AuDbg("udba %d, %s\n",
21054 + opt->udba, au_optstr_udba(opt->udba));
21062 + case Opt_diropq_a:
21063 + AuLabel(diropq_a);
21065 + case Opt_diropq_w:
21066 + AuLabel(diropq_w);
21068 + case Opt_warn_perm:
21069 + AuLabel(warn_perm);
21071 + case Opt_nowarn_perm:
21072 + AuLabel(nowarn_perm);
21077 + case Opt_norefrof:
21078 + AuLabel(norefrof);
21080 + case Opt_verbose:
21081 + AuLabel(verbose);
21083 + case Opt_noverbose:
21084 + AuLabel(noverbose);
21095 + case Opt_wbr_create:
21096 + u.create = &opt->wbr_create;
21097 + AuDbg("create %d, %s\n", u.create->wbr_create,
21098 + au_optstr_wbr_create(u.create->wbr_create));
21099 + switch (u.create->wbr_create) {
21100 + case AuWbrCreate_MFSV:
21101 + case AuWbrCreate_PMFSV:
21102 + AuDbg("%d sec\n", u.create->mfs_second);
21104 + case AuWbrCreate_MFSRR:
21105 + AuDbg("%llu watermark\n",
21106 + u.create->mfsrr_watermark);
21108 + case AuWbrCreate_MFSRRV:
21109 + AuDbg("%llu watermark, %d sec\n",
21110 + u.create->mfsrr_watermark,
21111 + u.create->mfs_second);
21115 + case Opt_wbr_copyup:
21116 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
21117 + au_optstr_wbr_copyup(opt->wbr_copyup));
21127 +void au_opts_free(struct au_opts *opts)
21129 + struct au_opt *opt;
21132 + while (opt->type != Opt_tail) {
21133 + switch (opt->type) {
21136 + case Opt_prepend:
21137 + path_put(&opt->add.path);
21141 + path_put(&opt->del.h_path);
21145 + dput(opt->mod.h_root);
21148 + fput(opt->xino.file);
21155 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
21156 + aufs_bindex_t bindex)
21159 + struct au_opt_add *add = &opt->add;
21162 + add->bindex = bindex;
21163 + add->perm = AuBrPerm_RO;
21164 + add->pathname = opt_str;
21165 + p = strchr(opt_str, '=');
21169 + add->perm = br_perm_val(p);
21172 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
21175 + add->perm = AuBrPerm_RO;
21176 + if (au_test_fs_rr(add->path.dentry->d_sb))
21177 + add->perm = AuBrPerm_RR;
21178 + else if (!bindex && !(sb_flags & MS_RDONLY))
21179 + add->perm = AuBrPerm_RW;
21181 + opt->type = Opt_add;
21184 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
21191 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
21195 + del->pathname = args[0].from;
21196 + AuDbg("del path %s\n", del->pathname);
21198 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
21199 + if (unlikely(err))
21200 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
21205 +#if 0 /* reserved for future use */
21206 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
21207 + struct au_opt_del *del, substring_t args[])
21210 + struct dentry *root;
21213 + root = sb->s_root;
21214 + aufs_read_lock(root, AuLock_FLUSH);
21215 + if (bindex < 0 || au_sbend(sb) < bindex) {
21216 + pr_err("out of bounds, %d\n", bindex);
21221 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
21222 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
21225 + aufs_read_unlock(root, !AuLock_IR);
21230 +static int noinline_for_stack
21231 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
21234 + struct path path;
21238 + mod->path = args[0].from;
21239 + p = strchr(mod->path, '=');
21240 + if (unlikely(!p)) {
21241 + pr_err("no permssion %s\n", args[0].from);
21246 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
21247 + if (unlikely(err)) {
21248 + pr_err("lookup failed %s (%d)\n", mod->path, err);
21252 + mod->perm = br_perm_val(p);
21253 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
21254 + mod->h_root = dget(path.dentry);
21261 +#if 0 /* reserved for future use */
21262 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
21263 + struct au_opt_mod *mod, substring_t args[])
21266 + struct dentry *root;
21269 + root = sb->s_root;
21270 + aufs_read_lock(root, AuLock_FLUSH);
21271 + if (bindex < 0 || au_sbend(sb) < bindex) {
21272 + pr_err("out of bounds, %d\n", bindex);
21277 + mod->perm = br_perm_val(args[1].from);
21278 + AuDbg("mod path %s, perm 0x%x, %s\n",
21279 + mod->path, mod->perm, args[1].from);
21280 + mod->h_root = dget(au_h_dptr(root, bindex));
21283 + aufs_read_unlock(root, !AuLock_IR);
21288 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
21289 + substring_t args[])
21292 + struct file *file;
21294 + file = au_xino_create(sb, args[0].from, /*silent*/0);
21295 + err = PTR_ERR(file);
21296 + if (IS_ERR(file))
21300 + if (unlikely(file->f_dentry->d_sb == sb)) {
21302 + pr_err("%s must be outside\n", args[0].from);
21307 + xino->file = file;
21308 + xino->path = args[0].from;
21314 +static int noinline_for_stack
21315 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
21316 + struct au_opt_xino_itrunc *xino_itrunc,
21317 + substring_t args[])
21320 + aufs_bindex_t bend, bindex;
21321 + struct path path;
21322 + struct dentry *root;
21324 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
21325 + if (unlikely(err)) {
21326 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
21330 + xino_itrunc->bindex = -1;
21331 + root = sb->s_root;
21332 + aufs_read_lock(root, AuLock_FLUSH);
21333 + bend = au_sbend(sb);
21334 + for (bindex = 0; bindex <= bend; bindex++) {
21335 + if (au_h_dptr(root, bindex) == path.dentry) {
21336 + xino_itrunc->bindex = bindex;
21340 + aufs_read_unlock(root, !AuLock_IR);
21343 + if (unlikely(xino_itrunc->bindex < 0)) {
21344 + pr_err("no such branch %s\n", args[0].from);
21352 +/* called without aufs lock */
21353 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
21355 + int err, n, token;
21356 + aufs_bindex_t bindex;
21357 + unsigned char skipped;
21358 + struct dentry *root;
21359 + struct au_opt *opt, *opt_tail;
21361 + /* reduce the stack space */
21363 + struct au_opt_xino_itrunc *xino_itrunc;
21364 + struct au_opt_wbr_create *create;
21367 + substring_t args[MAX_OPT_ARGS];
21371 + a = kmalloc(sizeof(*a), GFP_NOFS);
21372 + if (unlikely(!a))
21375 + root = sb->s_root;
21379 + opt_tail = opt + opts->max_opt - 1;
21380 + opt->type = Opt_tail;
21381 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
21384 + token = match_token(opt_str, options, a->args);
21388 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
21390 + err = opt_add(opt, opt_str, opts->sb_flags,
21392 + if (unlikely(!err && ++opt > opt_tail)) {
21396 + opt->type = Opt_tail;
21401 + if (unlikely(match_int(&a->args[0], &n))) {
21402 + pr_err("bad integer in %s\n", opt_str);
21406 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
21409 + opt->type = token;
21412 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
21413 + /*dummy bindex*/1);
21415 + opt->type = token;
21417 + case Opt_prepend:
21418 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
21421 + opt->type = token;
21424 + err = au_opts_parse_del(&opt->del, a->args);
21426 + opt->type = token;
21428 +#if 0 /* reserved for future use */
21430 + del->pathname = "(indexed)";
21431 + if (unlikely(match_int(&args[0], &n))) {
21432 + pr_err("bad integer in %s\n", opt_str);
21435 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
21437 + opt->type = token;
21441 + err = au_opts_parse_mod(&opt->mod, a->args);
21443 + opt->type = token;
21445 +#ifdef IMOD /* reserved for future use */
21447 + u.mod->path = "(indexed)";
21448 + if (unlikely(match_int(&a->args[0], &n))) {
21449 + pr_err("bad integer in %s\n", opt_str);
21452 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
21454 + opt->type = token;
21458 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
21460 + opt->type = token;
21463 + case Opt_trunc_xino_path:
21464 + err = au_opts_parse_xino_itrunc_path
21465 + (sb, &opt->xino_itrunc, a->args);
21467 + opt->type = token;
21470 + case Opt_itrunc_xino:
21471 + u.xino_itrunc = &opt->xino_itrunc;
21472 + if (unlikely(match_int(&a->args[0], &n))) {
21473 + pr_err("bad integer in %s\n", opt_str);
21476 + u.xino_itrunc->bindex = n;
21477 + aufs_read_lock(root, AuLock_FLUSH);
21478 + if (n < 0 || au_sbend(sb) < n) {
21479 + pr_err("out of bounds, %d\n", n);
21480 + aufs_read_unlock(root, !AuLock_IR);
21483 + aufs_read_unlock(root, !AuLock_IR);
21485 + opt->type = token;
21489 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
21492 + opt->type = token;
21495 + case Opt_rdcache:
21496 + if (unlikely(match_int(&a->args[0], &n))) {
21497 + pr_err("bad integer in %s\n", opt_str);
21500 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
21501 + pr_err("rdcache must be smaller than %d\n",
21502 + AUFS_RDCACHE_MAX);
21505 + opt->rdcache = n;
21507 + opt->type = token;
21510 + if (unlikely(match_int(&a->args[0], &n)
21512 + || n > KMALLOC_MAX_SIZE)) {
21513 + pr_err("bad integer in %s\n", opt_str);
21516 + if (unlikely(n && n < NAME_MAX)) {
21517 + pr_err("rdblk must be larger than %d\n",
21523 + opt->type = token;
21526 + if (unlikely(match_int(&a->args[0], &n)
21528 + || n * sizeof(struct hlist_head)
21529 + > KMALLOC_MAX_SIZE)) {
21530 + pr_err("bad integer in %s\n", opt_str);
21535 + opt->type = token;
21538 + case Opt_trunc_xino:
21539 + case Opt_notrunc_xino:
21541 + case Opt_trunc_xib:
21542 + case Opt_notrunc_xib:
21546 + case Opt_noplink:
21547 + case Opt_list_plink:
21550 + case Opt_diropq_a:
21551 + case Opt_diropq_w:
21552 + case Opt_warn_perm:
21553 + case Opt_nowarn_perm:
21555 + case Opt_norefrof:
21556 + case Opt_verbose:
21557 + case Opt_noverbose:
21561 + case Opt_rdblk_def:
21562 + case Opt_rdhash_def:
21564 + opt->type = token;
21568 + opt->udba = udba_val(a->args[0].from);
21569 + if (opt->udba >= 0) {
21571 + opt->type = token;
21573 + pr_err("wrong value, %s\n", opt_str);
21576 + case Opt_wbr_create:
21577 + u.create = &opt->wbr_create;
21578 + u.create->wbr_create
21579 + = au_wbr_create_val(a->args[0].from, u.create);
21580 + if (u.create->wbr_create >= 0) {
21582 + opt->type = token;
21584 + pr_err("wrong value, %s\n", opt_str);
21586 + case Opt_wbr_copyup:
21587 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
21588 + if (opt->wbr_copyup >= 0) {
21590 + opt->type = token;
21592 + pr_err("wrong value, %s\n", opt_str);
21596 + pr_warn("ignored %s\n", opt_str);
21598 + case Opt_ignore_silent:
21603 + pr_err("unknown option %s\n", opt_str);
21607 + if (!err && !skipped) {
21608 + if (unlikely(++opt > opt_tail)) {
21611 + opt->type = Opt_tail;
21614 + opt->type = Opt_tail;
21620 + if (unlikely(err))
21621 + au_opts_free(opts);
21627 +static int au_opt_wbr_create(struct super_block *sb,
21628 + struct au_opt_wbr_create *create)
21631 + struct au_sbinfo *sbinfo;
21633 + SiMustWriteLock(sb);
21635 + err = 1; /* handled */
21636 + sbinfo = au_sbi(sb);
21637 + if (sbinfo->si_wbr_create_ops->fin) {
21638 + err = sbinfo->si_wbr_create_ops->fin(sb);
21643 + sbinfo->si_wbr_create = create->wbr_create;
21644 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
21645 + switch (create->wbr_create) {
21646 + case AuWbrCreate_MFSRRV:
21647 + case AuWbrCreate_MFSRR:
21648 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
21650 + case AuWbrCreate_MFS:
21651 + case AuWbrCreate_MFSV:
21652 + case AuWbrCreate_PMFS:
21653 + case AuWbrCreate_PMFSV:
21654 + sbinfo->si_wbr_mfs.mfs_expire
21655 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
21659 + if (sbinfo->si_wbr_create_ops->init)
21660 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
21667 + * plus: processed without an error
21668 + * zero: unprocessed
21670 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
21671 + struct au_opts *opts)
21674 + struct au_sbinfo *sbinfo;
21676 + SiMustWriteLock(sb);
21678 + err = 1; /* handled */
21679 + sbinfo = au_sbi(sb);
21680 + switch (opt->type) {
21682 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
21683 + sbinfo->si_mntflags |= opt->udba;
21684 + opts->given_udba |= opt->udba;
21688 + au_opt_set(sbinfo->si_mntflags, PLINK);
21690 + case Opt_noplink:
21691 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
21692 + au_plink_put(sb, /*verbose*/1);
21693 + au_opt_clr(sbinfo->si_mntflags, PLINK);
21695 + case Opt_list_plink:
21696 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
21697 + au_plink_list(sb);
21701 + au_opt_set(sbinfo->si_mntflags, DIO);
21702 + au_fset_opts(opts->flags, REFRESH_DYAOP);
21705 + au_opt_clr(sbinfo->si_mntflags, DIO);
21706 + au_fset_opts(opts->flags, REFRESH_DYAOP);
21709 + case Opt_diropq_a:
21710 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
21712 + case Opt_diropq_w:
21713 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
21716 + case Opt_warn_perm:
21717 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
21719 + case Opt_nowarn_perm:
21720 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
21724 + au_opt_set(sbinfo->si_mntflags, REFROF);
21726 + case Opt_norefrof:
21727 + au_opt_clr(sbinfo->si_mntflags, REFROF);
21730 + case Opt_verbose:
21731 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
21733 + case Opt_noverbose:
21734 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
21738 + au_opt_set(sbinfo->si_mntflags, SUM);
21741 + au_opt_clr(sbinfo->si_mntflags, SUM);
21742 + au_opt_set(sbinfo->si_mntflags, SUM_W);
21744 + au_opt_clr(sbinfo->si_mntflags, SUM);
21745 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
21748 + case Opt_wbr_create:
21749 + err = au_opt_wbr_create(sb, &opt->wbr_create);
21751 + case Opt_wbr_copyup:
21752 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
21753 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
21757 + sbinfo->si_dirwh = opt->dirwh;
21760 + case Opt_rdcache:
21761 + sbinfo->si_rdcache
21762 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
21765 + sbinfo->si_rdblk = opt->rdblk;
21767 + case Opt_rdblk_def:
21768 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
21771 + sbinfo->si_rdhash = opt->rdhash;
21773 + case Opt_rdhash_def:
21774 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
21778 + au_opt_set(sbinfo->si_mntflags, SHWH);
21781 + au_opt_clr(sbinfo->si_mntflags, SHWH);
21784 + case Opt_trunc_xino:
21785 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
21787 + case Opt_notrunc_xino:
21788 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
21791 + case Opt_trunc_xino_path:
21792 + case Opt_itrunc_xino:
21793 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
21798 + case Opt_trunc_xib:
21799 + au_fset_opts(opts->flags, TRUNC_XIB);
21801 + case Opt_notrunc_xib:
21802 + au_fclr_opts(opts->flags, TRUNC_XIB);
21814 + * returns tri-state.
21815 + * plus: processed without an error
21816 + * zero: unprocessed
21819 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
21820 + struct au_opts *opts)
21822 + int err, do_refresh;
21825 + switch (opt->type) {
21827 + opt->add.bindex = au_sbend(sb) + 1;
21828 + if (opt->add.bindex < 0)
21829 + opt->add.bindex = 0;
21831 + case Opt_prepend:
21832 + opt->add.bindex = 0;
21835 + err = au_br_add(sb, &opt->add,
21836 + au_ftest_opts(opts->flags, REMOUNT));
21839 + au_fset_opts(opts->flags, REFRESH);
21845 + err = au_br_del(sb, &opt->del,
21846 + au_ftest_opts(opts->flags, REMOUNT));
21849 + au_fset_opts(opts->flags, TRUNC_XIB);
21850 + au_fset_opts(opts->flags, REFRESH);
21856 + err = au_br_mod(sb, &opt->mod,
21857 + au_ftest_opts(opts->flags, REMOUNT),
21862 + au_fset_opts(opts->flags, REFRESH);
21870 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
21871 + struct au_opt_xino **opt_xino,
21872 + struct au_opts *opts)
21875 + aufs_bindex_t bend, bindex;
21876 + struct dentry *root, *parent, *h_root;
21879 + switch (opt->type) {
21881 + err = au_xino_set(sb, &opt->xino,
21882 + !!au_ftest_opts(opts->flags, REMOUNT));
21883 + if (unlikely(err))
21886 + *opt_xino = &opt->xino;
21887 + au_xino_brid_set(sb, -1);
21889 + /* safe d_parent access */
21890 + parent = opt->xino.file->f_dentry->d_parent;
21891 + root = sb->s_root;
21892 + bend = au_sbend(sb);
21893 + for (bindex = 0; bindex <= bend; bindex++) {
21894 + h_root = au_h_dptr(root, bindex);
21895 + if (h_root == parent) {
21896 + au_xino_brid_set(sb, au_sbr_id(sb, bindex));
21904 + au_xino_brid_set(sb, -1);
21905 + *opt_xino = (void *)-1;
21912 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
21913 + unsigned int pending)
21916 + aufs_bindex_t bindex, bend;
21917 + unsigned char do_plink, skip, do_free;
21918 + struct au_branch *br;
21919 + struct au_wbr *wbr;
21920 + struct dentry *root;
21921 + struct inode *dir, *h_dir;
21922 + struct au_sbinfo *sbinfo;
21923 + struct au_hinode *hdir;
21925 + SiMustAnyLock(sb);
21927 + sbinfo = au_sbi(sb);
21928 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
21930 + if (!(sb_flags & MS_RDONLY)) {
21931 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
21932 + pr_warn("first branch should be rw\n");
21933 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
21934 + pr_warn("shwh should be used with ro\n");
21937 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
21938 + && !au_opt_test(sbinfo->si_mntflags, XINO))
21939 + pr_warn("udba=*notify requires xino\n");
21942 + root = sb->s_root;
21943 + dir = root->d_inode;
21944 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
21945 + bend = au_sbend(sb);
21946 + for (bindex = 0; !err && bindex <= bend; bindex++) {
21948 + h_dir = au_h_iptr(dir, bindex);
21949 + br = au_sbr(sb, bindex);
21952 + wbr = br->br_wbr;
21954 + wbr_wh_read_lock(wbr);
21956 + if (!au_br_writable(br->br_perm)) {
21959 + || (!wbr->wbr_whbase
21960 + && !wbr->wbr_plink
21961 + && !wbr->wbr_orph));
21962 + } else if (!au_br_wh_linkable(br->br_perm)) {
21963 + /* skip = (!br->br_whbase && !br->br_orph); */
21964 + skip = (!wbr || !wbr->wbr_whbase);
21965 + if (skip && wbr) {
21967 + skip = !!wbr->wbr_plink;
21969 + skip = !wbr->wbr_plink;
21972 + /* skip = (br->br_whbase && br->br_ohph); */
21973 + skip = (wbr && wbr->wbr_whbase);
21976 + skip = !!wbr->wbr_plink;
21978 + skip = !wbr->wbr_plink;
21982 + wbr_wh_read_unlock(wbr);
21987 + hdir = au_hi(dir, bindex);
21988 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
21990 + wbr_wh_write_lock(wbr);
21991 + err = au_wh_init(br, sb);
21993 + wbr_wh_write_unlock(wbr);
21994 + au_hn_imtx_unlock(hdir);
21996 + if (!err && do_free) {
21998 + br->br_wbr = NULL;
22005 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
22008 + unsigned int tmp;
22009 + aufs_bindex_t bindex, bend;
22010 + struct au_opt *opt;
22011 + struct au_opt_xino *opt_xino, xino;
22012 + struct au_sbinfo *sbinfo;
22013 + struct au_branch *br;
22015 + SiMustWriteLock(sb);
22020 + while (err >= 0 && opt->type != Opt_tail)
22021 + err = au_opt_simple(sb, opt++, opts);
22024 + else if (unlikely(err < 0))
22027 + /* disable xino and udba temporary */
22028 + sbinfo = au_sbi(sb);
22029 + tmp = sbinfo->si_mntflags;
22030 + au_opt_clr(sbinfo->si_mntflags, XINO);
22031 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
22034 + while (err >= 0 && opt->type != Opt_tail)
22035 + err = au_opt_br(sb, opt++, opts);
22038 + else if (unlikely(err < 0))
22041 + bend = au_sbend(sb);
22042 + if (unlikely(bend < 0)) {
22044 + pr_err("no branches\n");
22048 + if (au_opt_test(tmp, XINO))
22049 + au_opt_set(sbinfo->si_mntflags, XINO);
22051 + while (!err && opt->type != Opt_tail)
22052 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
22053 + if (unlikely(err))
22056 + err = au_opts_verify(sb, sb->s_flags, tmp);
22057 + if (unlikely(err))
22060 + /* restore xino */
22061 + if (au_opt_test(tmp, XINO) && !opt_xino) {
22062 + xino.file = au_xino_def(sb);
22063 + err = PTR_ERR(xino.file);
22064 + if (IS_ERR(xino.file))
22067 + err = au_xino_set(sb, &xino, /*remount*/0);
22069 + if (unlikely(err))
22073 + /* restore udba */
22074 + tmp &= AuOptMask_UDBA;
22075 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
22076 + sbinfo->si_mntflags |= tmp;
22077 + bend = au_sbend(sb);
22078 + for (bindex = 0; bindex <= bend; bindex++) {
22079 + br = au_sbr(sb, bindex);
22080 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
22081 + if (unlikely(err))
22082 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
22084 + /* go on even if err */
22086 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
22087 + struct inode *dir = sb->s_root->d_inode;
22088 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
22095 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
22098 + struct inode *dir;
22099 + struct au_opt_xino *opt_xino;
22100 + struct au_opt *opt;
22101 + struct au_sbinfo *sbinfo;
22103 + SiMustWriteLock(sb);
22105 + dir = sb->s_root->d_inode;
22106 + sbinfo = au_sbi(sb);
22110 + while (err >= 0 && opt->type != Opt_tail) {
22111 + err = au_opt_simple(sb, opt, opts);
22113 + err = au_opt_br(sb, opt, opts);
22115 + err = au_opt_xino(sb, opt, &opt_xino, opts);
22121 + /* go on even err */
22123 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
22124 + if (unlikely(rerr && !err))
22127 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
22128 + rerr = au_xib_trunc(sb);
22129 + if (unlikely(rerr && !err))
22133 + /* will be handled by the caller */
22134 + if (!au_ftest_opts(opts->flags, REFRESH)
22135 + && (opts->given_udba || au_opt_test(sbinfo->si_mntflags, XINO)))
22136 + au_fset_opts(opts->flags, REFRESH);
22138 + AuDbg("status 0x%x\n", opts->flags);
22142 +/* ---------------------------------------------------------------------- */
22144 +unsigned int au_opt_udba(struct super_block *sb)
22146 + return au_mntflags(sb) & AuOptMask_UDBA;
22148 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
22149 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
22150 +++ linux/fs/aufs/opts.h 2013-07-06 13:20:47.753531903 +0200
22153 + * Copyright (C) 2005-2013 Junjiro R. Okajima
22155 + * This program, aufs is free software; you can redistribute it and/or modify
22156 + * it under the terms of the GNU General Public License as published by
22157 + * the Free Software Foundation; either version 2 of the License, or
22158 + * (at your option) any later version.
22160 + * This program is distributed in the hope that it will be useful,
22161 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22162 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22163 + * GNU General Public License for more details.
22165 + * You should have received a copy of the GNU General Public License
22166 + * along with this program; if not, write to the Free Software
22167 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22171 + * mount options/flags
22174 +#ifndef __AUFS_OPTS_H__
22175 +#define __AUFS_OPTS_H__
22179 +#include <linux/path.h>
22182 +struct super_block;
22184 +/* ---------------------------------------------------------------------- */
22187 +#define AuOpt_XINO 1 /* external inode number bitmap
22188 + and translation table */
22189 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
22190 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
22191 +#define AuOpt_UDBA_REVAL (1 << 3)
22192 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
22193 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
22194 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
22195 +#define AuOpt_DIRPERM1 (1 << 7) /* unimplemented */
22196 +#define AuOpt_REFROF (1 << 8) /* unimplemented */
22197 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
22198 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
22199 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
22200 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
22201 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
22202 +#define AuOpt_DIO (1 << 14) /* direct io */
22204 +#ifndef CONFIG_AUFS_HNOTIFY
22205 +#undef AuOpt_UDBA_HNOTIFY
22206 +#define AuOpt_UDBA_HNOTIFY 0
22208 +#ifndef CONFIG_AUFS_SHWH
22210 +#define AuOpt_SHWH 0
22213 +#define AuOpt_Def (AuOpt_XINO \
22214 + | AuOpt_UDBA_REVAL \
22216 + /* | AuOpt_DIRPERM1 */ \
22217 + | AuOpt_WARN_PERM)
22218 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
22219 + | AuOpt_UDBA_REVAL \
22220 + | AuOpt_UDBA_HNOTIFY)
22222 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
22223 +#define au_opt_set(flags, name) do { \
22224 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
22225 + ((flags) |= AuOpt_##name); \
22227 +#define au_opt_set_udba(flags, name) do { \
22228 + (flags) &= ~AuOptMask_UDBA; \
22229 + ((flags) |= AuOpt_##name); \
22231 +#define au_opt_clr(flags, name) do { \
22232 + ((flags) &= ~AuOpt_##name); \
22235 +static inline unsigned int au_opts_plink(unsigned int mntflags)
22237 +#ifdef CONFIG_PROC_FS
22240 + return mntflags & ~AuOpt_PLINK;
22244 +/* ---------------------------------------------------------------------- */
22246 +/* policies to select one among multiple writable branches */
22248 + AuWbrCreate_TDP, /* top down parent */
22249 + AuWbrCreate_RR, /* round robin */
22250 + AuWbrCreate_MFS, /* most free space */
22251 + AuWbrCreate_MFSV, /* mfs with seconds */
22252 + AuWbrCreate_MFSRR, /* mfs then rr */
22253 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
22254 + AuWbrCreate_PMFS, /* parent and mfs */
22255 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
22257 + AuWbrCreate_Def = AuWbrCreate_TDP
22261 + AuWbrCopyup_TDP, /* top down parent */
22262 + AuWbrCopyup_BUP, /* bottom up parent */
22263 + AuWbrCopyup_BU, /* bottom up */
22265 + AuWbrCopyup_Def = AuWbrCopyup_TDP
22268 +/* ---------------------------------------------------------------------- */
22270 +struct au_opt_add {
22271 + aufs_bindex_t bindex;
22274 + struct path path;
22277 +struct au_opt_del {
22279 + struct path h_path;
22282 +struct au_opt_mod {
22285 + struct dentry *h_root;
22288 +struct au_opt_xino {
22290 + struct file *file;
22293 +struct au_opt_xino_itrunc {
22294 + aufs_bindex_t bindex;
22297 +struct au_opt_wbr_create {
22300 + unsigned long long mfsrr_watermark;
22306 + struct au_opt_xino xino;
22307 + struct au_opt_xino_itrunc xino_itrunc;
22308 + struct au_opt_add add;
22309 + struct au_opt_del del;
22310 + struct au_opt_mod mod;
22313 + unsigned int rdblk;
22314 + unsigned int rdhash;
22316 + struct au_opt_wbr_create wbr_create;
22322 +#define AuOpts_REMOUNT 1
22323 +#define AuOpts_REFRESH (1 << 1)
22324 +#define AuOpts_TRUNC_XIB (1 << 2)
22325 +#define AuOpts_REFRESH_DYAOP (1 << 3)
22326 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
22327 +#define au_fset_opts(flags, name) \
22328 + do { (flags) |= AuOpts_##name; } while (0)
22329 +#define au_fclr_opts(flags, name) \
22330 + do { (flags) &= ~AuOpts_##name; } while (0)
22333 + struct au_opt *opt;
22336 + unsigned int given_udba;
22337 + unsigned int flags;
22338 + unsigned long sb_flags;
22341 +/* ---------------------------------------------------------------------- */
22343 +char *au_optstr_br_perm(int brperm);
22344 +const char *au_optstr_udba(int udba);
22345 +const char *au_optstr_wbr_copyup(int wbr_copyup);
22346 +const char *au_optstr_wbr_create(int wbr_create);
22348 +void au_opts_free(struct au_opts *opts);
22349 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
22350 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
22351 + unsigned int pending);
22352 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
22353 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
22355 +unsigned int au_opt_udba(struct super_block *sb);
22357 +/* ---------------------------------------------------------------------- */
22359 +#endif /* __KERNEL__ */
22360 +#endif /* __AUFS_OPTS_H__ */
22361 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
22362 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
22363 +++ linux/fs/aufs/plink.c 2013-07-06 13:20:47.753531903 +0200
22366 + * Copyright (C) 2005-2013 Junjiro R. Okajima
22368 + * This program, aufs is free software; you can redistribute it and/or modify
22369 + * it under the terms of the GNU General Public License as published by
22370 + * the Free Software Foundation; either version 2 of the License, or
22371 + * (at your option) any later version.
22373 + * This program is distributed in the hope that it will be useful,
22374 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22375 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22376 + * GNU General Public License for more details.
22378 + * You should have received a copy of the GNU General Public License
22379 + * along with this program; if not, write to the Free Software
22380 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22390 + * the pseudo-link maintenance mode.
22391 + * during a user process maintains the pseudo-links,
22392 + * prohibit adding a new plink and branch manipulation.
22396 + * For entry functions which will handle plink, and i_mutex is already held
22398 + * They cannot wait and should return an error at once.
22399 + * Callers has to check the error.
22401 + * For entry functions which will handle plink, but i_mutex is not held
22403 + * They can wait the plink maintenance mode to finish.
22405 + * They behave like F_SETLK and F_SETLKW.
22406 + * If the caller never handle plink, then both flags are unnecessary.
22409 +int au_plink_maint(struct super_block *sb, int flags)
22413 + struct au_sbinfo *sbi;
22415 + SiMustAnyLock(sb);
22418 + if (!au_opt_test(au_mntflags(sb), PLINK))
22421 + sbi = au_sbi(sb);
22422 + pid = sbi->si_plink_maint_pid;
22423 + if (!pid || pid == current->pid)
22426 + /* todo: it highly depends upon /sbin/mount.aufs */
22428 + ppid = task_pid_vnr(rcu_dereference(current->real_parent));
22429 + rcu_read_unlock();
22433 + if (au_ftest_lock(flags, NOPLMW)) {
22434 + /* if there is no i_mutex lock in VFS, we don't need to wait */
22435 + /* AuDebugOn(!lockdep_depth(current)); */
22436 + while (sbi->si_plink_maint_pid) {
22437 + si_read_unlock(sb);
22438 + /* gave up wake_up_bit() */
22439 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
22441 + if (au_ftest_lock(flags, FLUSH))
22442 + au_nwt_flush(&sbi->si_nowait);
22443 + si_noflush_read_lock(sb);
22445 + } else if (au_ftest_lock(flags, NOPLM)) {
22446 + AuDbg("ppid %d, pid %d\n", ppid, pid);
22454 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
22456 + spin_lock(&sbinfo->si_plink_maint_lock);
22457 + sbinfo->si_plink_maint_pid = 0;
22458 + spin_unlock(&sbinfo->si_plink_maint_lock);
22459 + wake_up_all(&sbinfo->si_plink_wq);
22462 +int au_plink_maint_enter(struct super_block *sb)
22465 + struct au_sbinfo *sbinfo;
22468 + sbinfo = au_sbi(sb);
22469 + /* make sure i am the only one in this fs */
22470 + si_write_lock(sb, AuLock_FLUSH);
22471 + if (au_opt_test(au_mntflags(sb), PLINK)) {
22472 + spin_lock(&sbinfo->si_plink_maint_lock);
22473 + if (!sbinfo->si_plink_maint_pid)
22474 + sbinfo->si_plink_maint_pid = current->pid;
22477 + spin_unlock(&sbinfo->si_plink_maint_lock);
22479 + si_write_unlock(sb);
22484 +/* ---------------------------------------------------------------------- */
22486 +#ifdef CONFIG_AUFS_DEBUG
22487 +void au_plink_list(struct super_block *sb)
22490 + struct au_sbinfo *sbinfo;
22491 + struct hlist_head *plink_hlist;
22492 + struct pseudo_link *plink;
22494 + SiMustAnyLock(sb);
22496 + sbinfo = au_sbi(sb);
22497 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
22498 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
22500 + for (i = 0; i < AuPlink_NHASH; i++) {
22501 + plink_hlist = &sbinfo->si_plink[i].head;
22503 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
22504 + AuDbg("%lu\n", plink->inode->i_ino);
22505 + rcu_read_unlock();
22510 +/* is the inode pseudo-linked? */
22511 +int au_plink_test(struct inode *inode)
22514 + struct au_sbinfo *sbinfo;
22515 + struct hlist_head *plink_hlist;
22516 + struct pseudo_link *plink;
22518 + sbinfo = au_sbi(inode->i_sb);
22519 + AuRwMustAnyLock(&sbinfo->si_rwsem);
22520 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
22521 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
22524 + i = au_plink_hash(inode->i_ino);
22525 + plink_hlist = &sbinfo->si_plink[i].head;
22527 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
22528 + if (plink->inode == inode) {
22532 + rcu_read_unlock();
22536 +/* ---------------------------------------------------------------------- */
22539 + * generate a name for plink.
22540 + * the file will be stored under AUFS_WH_PLINKDIR.
22542 +/* 20 is max digits length of ulong 64 */
22543 +#define PLINK_NAME_LEN ((20 + 1) * 2)
22545 +static int plink_name(char *name, int len, struct inode *inode,
22546 + aufs_bindex_t bindex)
22549 + struct inode *h_inode;
22551 + h_inode = au_h_iptr(inode, bindex);
22552 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
22556 +struct au_do_plink_lkup_args {
22557 + struct dentry **errp;
22558 + struct qstr *tgtname;
22559 + struct dentry *h_parent;
22560 + struct au_branch *br;
22563 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
22564 + struct dentry *h_parent,
22565 + struct au_branch *br)
22567 + struct dentry *h_dentry;
22568 + struct mutex *h_mtx;
22570 + h_mtx = &h_parent->d_inode->i_mutex;
22571 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
22572 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
22573 + mutex_unlock(h_mtx);
22577 +static void au_call_do_plink_lkup(void *args)
22579 + struct au_do_plink_lkup_args *a = args;
22580 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
22583 +/* lookup the plink-ed @inode under the branch at @bindex */
22584 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
22586 + struct dentry *h_dentry, *h_parent;
22587 + struct au_branch *br;
22588 + struct inode *h_dir;
22590 + char a[PLINK_NAME_LEN];
22591 + struct qstr tgtname = QSTR_INIT(a, 0);
22593 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
22595 + br = au_sbr(inode->i_sb, bindex);
22596 + h_parent = br->br_wbr->wbr_plink;
22597 + h_dir = h_parent->d_inode;
22598 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
22600 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
22601 + struct au_do_plink_lkup_args args = {
22602 + .errp = &h_dentry,
22603 + .tgtname = &tgtname,
22604 + .h_parent = h_parent,
22608 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
22609 + if (unlikely(wkq_err))
22610 + h_dentry = ERR_PTR(wkq_err);
22612 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
22617 +/* create a pseudo-link */
22618 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
22619 + struct dentry *h_dentry, struct au_branch *br)
22622 + struct path h_path = {
22623 + .mnt = au_br_mnt(br)
22625 + struct inode *h_dir;
22627 + h_dir = h_parent->d_inode;
22628 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_CHILD2);
22630 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
22631 + err = PTR_ERR(h_path.dentry);
22632 + if (IS_ERR(h_path.dentry))
22636 + /* wh.plink dir is not monitored */
22637 + /* todo: is it really safe? */
22638 + if (h_path.dentry->d_inode
22639 + && h_path.dentry->d_inode != h_dentry->d_inode) {
22640 + err = vfsub_unlink(h_dir, &h_path, /*force*/0);
22641 + dput(h_path.dentry);
22642 + h_path.dentry = NULL;
22646 + if (!err && !h_path.dentry->d_inode)
22647 + err = vfsub_link(h_dentry, h_dir, &h_path);
22648 + dput(h_path.dentry);
22651 + mutex_unlock(&h_dir->i_mutex);
22655 +struct do_whplink_args {
22657 + struct qstr *tgt;
22658 + struct dentry *h_parent;
22659 + struct dentry *h_dentry;
22660 + struct au_branch *br;
22663 +static void call_do_whplink(void *args)
22665 + struct do_whplink_args *a = args;
22666 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
22669 +static int whplink(struct dentry *h_dentry, struct inode *inode,
22670 + aufs_bindex_t bindex, struct au_branch *br)
22672 + int err, wkq_err;
22673 + struct au_wbr *wbr;
22674 + struct dentry *h_parent;
22675 + struct inode *h_dir;
22676 + char a[PLINK_NAME_LEN];
22677 + struct qstr tgtname = QSTR_INIT(a, 0);
22679 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
22680 + h_parent = wbr->wbr_plink;
22681 + h_dir = h_parent->d_inode;
22682 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
22684 + /* always superio. */
22685 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
22686 + struct do_whplink_args args = {
22689 + .h_parent = h_parent,
22690 + .h_dentry = h_dentry,
22693 + wkq_err = au_wkq_wait(call_do_whplink, &args);
22694 + if (unlikely(wkq_err))
22697 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
22702 +/* free a single plink */
22703 +static void do_put_plink(struct pseudo_link *plink, int do_del)
22706 + hlist_del(&plink->hlist);
22707 + iput(plink->inode);
22711 +static void do_put_plink_rcu(struct rcu_head *rcu)
22713 + struct pseudo_link *plink;
22715 + plink = container_of(rcu, struct pseudo_link, rcu);
22716 + iput(plink->inode);
22721 + * create a new pseudo-link for @h_dentry on @bindex.
22722 + * the linked inode is held in aufs @inode.
22724 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
22725 + struct dentry *h_dentry)
22727 + struct super_block *sb;
22728 + struct au_sbinfo *sbinfo;
22729 + struct hlist_head *plink_hlist;
22730 + struct pseudo_link *plink, *tmp;
22731 + struct au_sphlhead *sphl;
22732 + int found, err, cnt, i;
22734 + sb = inode->i_sb;
22735 + sbinfo = au_sbi(sb);
22736 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
22737 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
22739 + found = au_plink_test(inode);
22743 + i = au_plink_hash(inode->i_ino);
22744 + sphl = sbinfo->si_plink + i;
22745 + plink_hlist = &sphl->head;
22746 + tmp = kmalloc(sizeof(*plink), GFP_NOFS);
22748 + tmp->inode = au_igrab(inode);
22754 + spin_lock(&sphl->spin);
22755 + hlist_for_each_entry(plink, plink_hlist, hlist) {
22756 + if (plink->inode == inode) {
22762 + hlist_add_head_rcu(&tmp->hlist, plink_hlist);
22763 + spin_unlock(&sphl->spin);
22765 + cnt = au_sphl_count(sphl);
22766 +#define msg "unexpectedly unblanced or too many pseudo-links"
22767 + if (cnt > AUFS_PLINK_WARN)
22768 + AuWarn1(msg ", %d\n", cnt);
22770 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
22772 + do_put_plink(tmp, 0);
22777 + if (unlikely(err)) {
22778 + pr_warn("err %d, damaged pseudo link.\n", err);
22780 + au_sphl_del_rcu(&tmp->hlist, sphl);
22781 + call_rcu(&tmp->rcu, do_put_plink_rcu);
22786 +/* free all plinks */
22787 +void au_plink_put(struct super_block *sb, int verbose)
22790 + struct au_sbinfo *sbinfo;
22791 + struct hlist_head *plink_hlist;
22792 + struct hlist_node *tmp;
22793 + struct pseudo_link *plink;
22795 + SiMustWriteLock(sb);
22797 + sbinfo = au_sbi(sb);
22798 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
22799 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
22801 + /* no spin_lock since sbinfo is write-locked */
22803 + for (i = 0; i < AuPlink_NHASH; i++) {
22804 + plink_hlist = &sbinfo->si_plink[i].head;
22805 + if (!warned && verbose && !hlist_empty(plink_hlist)) {
22806 + pr_warn("pseudo-link is not flushed");
22809 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist)
22810 + do_put_plink(plink, 0);
22811 + INIT_HLIST_HEAD(plink_hlist);
22815 +void au_plink_clean(struct super_block *sb, int verbose)
22817 + struct dentry *root;
22819 + root = sb->s_root;
22820 + aufs_write_lock(root);
22821 + if (au_opt_test(au_mntflags(sb), PLINK))
22822 + au_plink_put(sb, verbose);
22823 + aufs_write_unlock(root);
22826 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
22829 + aufs_bindex_t bstart, bend, bindex;
22832 + bstart = au_ibstart(inode);
22833 + bend = au_ibend(inode);
22834 + if (bstart >= 0) {
22835 + for (bindex = bstart; bindex <= bend; bindex++) {
22836 + if (!au_h_iptr(inode, bindex)
22837 + || au_ii_br_id(inode, bindex) != br_id)
22839 + au_set_h_iptr(inode, bindex, NULL, 0);
22844 + for (bindex = bstart; bindex <= bend; bindex++)
22845 + if (au_h_iptr(inode, bindex)) {
22855 +/* free the plinks on a branch specified by @br_id */
22856 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
22858 + struct au_sbinfo *sbinfo;
22859 + struct hlist_head *plink_hlist;
22860 + struct hlist_node *tmp;
22861 + struct pseudo_link *plink;
22862 + struct inode *inode;
22865 + SiMustWriteLock(sb);
22867 + sbinfo = au_sbi(sb);
22868 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
22869 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
22871 + /* no spin_lock since sbinfo is write-locked */
22872 + for (i = 0; i < AuPlink_NHASH; i++) {
22873 + plink_hlist = &sbinfo->si_plink[i].head;
22874 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist) {
22875 + inode = au_igrab(plink->inode);
22876 + ii_write_lock_child(inode);
22877 + do_put = au_plink_do_half_refresh(inode, br_id);
22879 + do_put_plink(plink, 1);
22880 + ii_write_unlock(inode);
22885 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
22886 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
22887 +++ linux/fs/aufs/poll.c 2013-07-06 13:20:47.753531903 +0200
22890 + * Copyright (C) 2005-2013 Junjiro R. Okajima
22892 + * This program, aufs is free software; you can redistribute it and/or modify
22893 + * it under the terms of the GNU General Public License as published by
22894 + * the Free Software Foundation; either version 2 of the License, or
22895 + * (at your option) any later version.
22897 + * This program is distributed in the hope that it will be useful,
22898 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22899 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22900 + * GNU General Public License for more details.
22902 + * You should have received a copy of the GNU General Public License
22903 + * along with this program; if not, write to the Free Software
22904 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22909 + * There is only one filesystem which implements ->poll operation, currently.
22914 +unsigned int aufs_poll(struct file *file, poll_table *wait)
22916 + unsigned int mask;
22918 + struct file *h_file;
22919 + struct dentry *dentry;
22920 + struct super_block *sb;
22922 + /* We should pretend an error happened. */
22923 + mask = POLLERR /* | POLLIN | POLLOUT */;
22924 + dentry = file->f_dentry;
22925 + sb = dentry->d_sb;
22926 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
22927 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
22928 + if (unlikely(err))
22931 + /* it is not an error if h_file has no operation */
22932 + mask = DEFAULT_POLLMASK;
22933 + h_file = au_hf_top(file);
22934 + if (h_file->f_op && h_file->f_op->poll)
22935 + mask = h_file->f_op->poll(h_file, wait);
22937 + di_read_unlock(dentry, AuLock_IR);
22938 + fi_read_unlock(file);
22941 + si_read_unlock(sb);
22942 + AuTraceErr((int)mask);
22945 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
22946 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
22947 +++ linux/fs/aufs/procfs.c 2013-07-06 13:20:47.753531903 +0200
22950 + * Copyright (C) 2010-2013 Junjiro R. Okajima
22952 + * This program, aufs is free software; you can redistribute it and/or modify
22953 + * it under the terms of the GNU General Public License as published by
22954 + * the Free Software Foundation; either version 2 of the License, or
22955 + * (at your option) any later version.
22957 + * This program is distributed in the hope that it will be useful,
22958 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22959 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22960 + * GNU General Public License for more details.
22962 + * You should have received a copy of the GNU General Public License
22963 + * along with this program; if not, write to the Free Software
22964 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22968 + * procfs interfaces
22971 +#include <linux/proc_fs.h>
22974 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
22976 + struct au_sbinfo *sbinfo;
22978 + sbinfo = file->private_data;
22980 + au_plink_maint_leave(sbinfo);
22981 + kobject_put(&sbinfo->si_kobj);
22987 +static void au_procfs_plm_write_clean(struct file *file)
22989 + struct au_sbinfo *sbinfo;
22991 + sbinfo = file->private_data;
22993 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
22996 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
22999 + struct super_block *sb;
23000 + struct au_sbinfo *sbinfo;
23003 + if (unlikely(file->private_data))
23007 + /* don't use au_sbilist_lock() here */
23008 + spin_lock(&au_sbilist.spin);
23009 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
23010 + if (id == sysaufs_si_id(sbinfo)) {
23011 + kobject_get(&sbinfo->si_kobj);
23012 + sb = sbinfo->si_sb;
23015 + spin_unlock(&au_sbilist.spin);
23018 + if (unlikely(!sb))
23021 + err = au_plink_maint_enter(sb);
23023 + /* keep kobject_get() */
23024 + file->private_data = sbinfo;
23026 + kobject_put(&sbinfo->si_kobj);
23032 + * Accept a valid "si=xxxx" only.
23033 + * Once it is accepted successfully, accept "clean" too.
23035 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
23036 + size_t count, loff_t *ppos)
23039 + unsigned long id;
23040 + /* last newline is allowed */
23041 + char buf[3 + sizeof(unsigned long) * 2 + 1];
23044 + if (unlikely(!capable(CAP_SYS_ADMIN)))
23048 + if (unlikely(count > sizeof(buf)))
23051 + err = copy_from_user(buf, ubuf, count);
23052 + if (unlikely(err)) {
23059 + if (!strcmp("clean", buf)) {
23060 + au_procfs_plm_write_clean(file);
23061 + goto out_success;
23062 + } else if (unlikely(strncmp("si=", buf, 3)))
23065 + err = kstrtoul(buf + 3, 16, &id);
23066 + if (unlikely(err))
23069 + err = au_procfs_plm_write_si(file, id);
23070 + if (unlikely(err))
23074 + err = count; /* success */
23079 +static const struct file_operations au_procfs_plm_fop = {
23080 + .write = au_procfs_plm_write,
23081 + .release = au_procfs_plm_release,
23082 + .owner = THIS_MODULE
23085 +/* ---------------------------------------------------------------------- */
23087 +static struct proc_dir_entry *au_procfs_dir;
23089 +void au_procfs_fin(void)
23091 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
23092 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
23095 +int __init au_procfs_init(void)
23098 + struct proc_dir_entry *entry;
23101 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
23102 + if (unlikely(!au_procfs_dir))
23105 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR,
23106 + au_procfs_dir, &au_procfs_plm_fop);
23107 + if (unlikely(!entry))
23111 + goto out; /* success */
23115 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
23119 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
23120 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
23121 +++ linux/fs/aufs/rdu.c 2013-07-30 22:42:55.842946719 +0200
23124 + * Copyright (C) 2005-2013 Junjiro R. Okajima
23126 + * This program, aufs is free software; you can redistribute it and/or modify
23127 + * it under the terms of the GNU General Public License as published by
23128 + * the Free Software Foundation; either version 2 of the License, or
23129 + * (at your option) any later version.
23131 + * This program is distributed in the hope that it will be useful,
23132 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23133 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23134 + * GNU General Public License for more details.
23136 + * You should have received a copy of the GNU General Public License
23137 + * along with this program; if not, write to the Free Software
23138 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23142 + * readdir in userspace.
23145 +#include <linux/compat.h>
23146 +#include <linux/fs_stack.h>
23147 +#include <linux/security.h>
23150 +/* bits for struct aufs_rdu.flags */
23151 +#define AuRdu_CALLED 1
23152 +#define AuRdu_CONT (1 << 1)
23153 +#define AuRdu_FULL (1 << 2)
23154 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
23155 +#define au_fset_rdu(flags, name) \
23156 + do { (flags) |= AuRdu_##name; } while (0)
23157 +#define au_fclr_rdu(flags, name) \
23158 + do { (flags) &= ~AuRdu_##name; } while (0)
23160 +struct au_rdu_arg {
23161 + struct aufs_rdu *rdu;
23162 + union au_rdu_ent_ul ent;
23163 + unsigned long end;
23165 + struct super_block *sb;
23169 +static int au_rdu_fill(void *__arg, const char *name, int nlen,
23170 + loff_t offset, u64 h_ino, unsigned int d_type)
23173 + struct au_rdu_arg *arg = __arg;
23174 + struct aufs_rdu *rdu = arg->rdu;
23175 + struct au_rdu_ent ent;
23179 + au_fset_rdu(rdu->cookie.flags, CALLED);
23180 + len = au_rdu_len(nlen);
23181 + if (arg->ent.ul + len < arg->end) {
23183 + ent.bindex = rdu->cookie.bindex;
23184 + ent.type = d_type;
23186 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
23187 + ent.type = DT_UNKNOWN;
23189 + /* unnecessary to support mmap_sem since this is a dir */
23191 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
23193 + if (copy_to_user(arg->ent.e->name, name, nlen))
23195 + /* the terminating NULL */
23196 + if (__put_user(0, arg->ent.e->name + nlen))
23199 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
23200 + arg->ent.ul += len;
23204 + au_fset_rdu(rdu->cookie.flags, FULL);
23206 + rdu->tail = arg->ent;
23210 + /* AuTraceErr(err); */
23214 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
23218 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
23220 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
23221 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
23223 + if (unlikely(offset != cookie->h_pos))
23229 + au_fclr_rdu(cookie->flags, CALLED);
23231 + err = vfsub_readdir(h_file, au_rdu_fill, arg);
23235 + && au_ftest_rdu(cookie->flags, CALLED)
23236 + && !au_ftest_rdu(cookie->flags, FULL));
23237 + cookie->h_pos = h_file->f_pos;
23244 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
23247 + aufs_bindex_t bend;
23248 + struct au_rdu_arg arg;
23249 + struct dentry *dentry;
23250 + struct inode *inode;
23251 + struct file *h_file;
23252 + struct au_rdu_cookie *cookie = &rdu->cookie;
23254 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
23255 + if (unlikely(err)) {
23261 + rdu->tail = rdu->ent;
23264 + arg.ent = rdu->ent;
23265 + arg.end = arg.ent.ul;
23266 + arg.end += rdu->sz;
23269 + if (unlikely(!file->f_op || !file->f_op->readdir))
23272 + err = security_file_permission(file, MAY_READ);
23274 + if (unlikely(err))
23277 + dentry = file->f_dentry;
23278 + inode = dentry->d_inode;
23280 + mutex_lock(&inode->i_mutex);
23282 + err = mutex_lock_killable(&inode->i_mutex);
23284 + if (unlikely(err))
23288 + arg.sb = inode->i_sb;
23289 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
23290 + if (unlikely(err))
23292 + err = au_alive_dir(dentry);
23293 + if (unlikely(err))
23295 + /* todo: reval? */
23296 + fi_read_lock(file);
23299 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
23300 + && cookie->generation != au_figen(file)))
23305 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
23307 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
23309 + bend = au_fbstart(file);
23310 + if (cookie->bindex < bend)
23311 + cookie->bindex = bend;
23312 + bend = au_fbend_dir(file);
23313 + /* AuDbg("b%d, b%d\n", cookie->bindex, bend); */
23314 + for (; !err && cookie->bindex <= bend;
23315 + cookie->bindex++, cookie->h_pos = 0) {
23316 + h_file = au_hf_dir(file, cookie->bindex);
23320 + au_fclr_rdu(cookie->flags, FULL);
23321 + err = au_rdu_do(h_file, &arg);
23323 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
23326 + AuDbg("rent %llu\n", rdu->rent);
23328 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
23329 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
23330 + au_fset_rdu(cookie->flags, CONT);
23331 + cookie->generation = au_figen(file);
23334 + ii_read_lock_child(inode);
23335 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibstart(inode)));
23336 + ii_read_unlock(inode);
23339 + fi_read_unlock(file);
23341 + si_read_unlock(arg.sb);
23343 + mutex_unlock(&inode->i_mutex);
23349 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
23353 + unsigned long long nent;
23354 + union au_rdu_ent_ul *u;
23355 + struct au_rdu_ent ent;
23356 + struct super_block *sb;
23359 + nent = rdu->nent;
23361 + sb = file->f_dentry->d_sb;
23362 + si_read_lock(sb, AuLock_FLUSH);
23363 + while (nent-- > 0) {
23364 + /* unnecessary to support mmap_sem since this is a dir */
23365 + err = copy_from_user(&ent, u->e, sizeof(ent));
23367 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
23368 + if (unlikely(err)) {
23374 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
23376 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
23378 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
23380 + if (unlikely(err)) {
23385 + err = __put_user(ino, &u->e->ino);
23386 + if (unlikely(err)) {
23391 + u->ul += au_rdu_len(ent.nlen);
23393 + si_read_unlock(sb);
23398 +/* ---------------------------------------------------------------------- */
23400 +static int au_rdu_verify(struct aufs_rdu *rdu)
23402 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
23403 + "%llu, b%d, 0x%x, g%u}\n",
23404 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
23406 + rdu->rent, rdu->shwh, rdu->full,
23407 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
23408 + rdu->cookie.generation);
23410 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
23414 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
23418 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
23421 + struct aufs_rdu rdu;
23422 + void __user *p = (void __user *)arg;
23424 + err = copy_from_user(&rdu, p, sizeof(rdu));
23425 + if (unlikely(err)) {
23430 + err = au_rdu_verify(&rdu);
23431 + if (unlikely(err))
23435 + case AUFS_CTL_RDU:
23436 + err = au_rdu(file, &rdu);
23437 + if (unlikely(err))
23440 + e = copy_to_user(p, &rdu, sizeof(rdu));
23441 + if (unlikely(e)) {
23446 + case AUFS_CTL_RDU_INO:
23447 + err = au_rdu_ino(file, &rdu);
23451 + /* err = -ENOTTY; */
23460 +#ifdef CONFIG_COMPAT
23461 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
23464 + struct aufs_rdu rdu;
23465 + void __user *p = compat_ptr(arg);
23467 + /* todo: get_user()? */
23468 + err = copy_from_user(&rdu, p, sizeof(rdu));
23469 + if (unlikely(err)) {
23474 + rdu.ent.e = compat_ptr(rdu.ent.ul);
23475 + err = au_rdu_verify(&rdu);
23476 + if (unlikely(err))
23480 + case AUFS_CTL_RDU:
23481 + err = au_rdu(file, &rdu);
23482 + if (unlikely(err))
23485 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
23486 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
23487 + e = copy_to_user(p, &rdu, sizeof(rdu));
23488 + if (unlikely(e)) {
23493 + case AUFS_CTL_RDU_INO:
23494 + err = au_rdu_ino(file, &rdu);
23498 + /* err = -ENOTTY; */
23507 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
23508 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
23509 +++ linux/fs/aufs/rwsem.h 2013-07-06 13:20:47.753531903 +0200
23512 + * Copyright (C) 2005-2013 Junjiro R. Okajima
23514 + * This program, aufs is free software; you can redistribute it and/or modify
23515 + * it under the terms of the GNU General Public License as published by
23516 + * the Free Software Foundation; either version 2 of the License, or
23517 + * (at your option) any later version.
23519 + * This program is distributed in the hope that it will be useful,
23520 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23521 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23522 + * GNU General Public License for more details.
23524 + * You should have received a copy of the GNU General Public License
23525 + * along with this program; if not, write to the Free Software
23526 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23530 + * simple read-write semaphore wrappers
23533 +#ifndef __AUFS_RWSEM_H__
23534 +#define __AUFS_RWSEM_H__
23538 +#include "debug.h"
23541 + struct rw_semaphore rwsem;
23542 +#ifdef CONFIG_AUFS_DEBUG
23543 + /* just for debugging, not almighty counter */
23544 + atomic_t rcnt, wcnt;
23548 +#ifdef CONFIG_AUFS_DEBUG
23549 +#define AuDbgCntInit(rw) do { \
23550 + atomic_set(&(rw)->rcnt, 0); \
23551 + atomic_set(&(rw)->wcnt, 0); \
23552 + smp_mb(); /* atomic set */ \
23555 +#define AuDbgRcntInc(rw) atomic_inc(&(rw)->rcnt)
23556 +#define AuDbgRcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->rcnt) < 0)
23557 +#define AuDbgWcntInc(rw) atomic_inc(&(rw)->wcnt)
23558 +#define AuDbgWcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->wcnt) < 0)
23560 +#define AuDbgCntInit(rw) do {} while (0)
23561 +#define AuDbgRcntInc(rw) do {} while (0)
23562 +#define AuDbgRcntDec(rw) do {} while (0)
23563 +#define AuDbgWcntInc(rw) do {} while (0)
23564 +#define AuDbgWcntDec(rw) do {} while (0)
23565 +#endif /* CONFIG_AUFS_DEBUG */
23567 +/* to debug easier, do not make them inlined functions */
23568 +#define AuRwMustNoWaiters(rw) AuDebugOn(!list_empty(&(rw)->rwsem.wait_list))
23569 +/* rwsem_is_locked() is unusable */
23570 +#define AuRwMustReadLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0)
23571 +#define AuRwMustWriteLock(rw) AuDebugOn(atomic_read(&(rw)->wcnt) <= 0)
23572 +#define AuRwMustAnyLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0 \
23573 + && atomic_read(&(rw)->wcnt) <= 0)
23574 +#define AuRwDestroy(rw) AuDebugOn(atomic_read(&(rw)->rcnt) \
23575 + || atomic_read(&(rw)->wcnt))
23577 +#define au_rw_class(rw, key) lockdep_set_class(&(rw)->rwsem, key)
23579 +static inline void au_rw_init(struct au_rwsem *rw)
23581 + AuDbgCntInit(rw);
23582 + init_rwsem(&rw->rwsem);
23585 +static inline void au_rw_init_wlock(struct au_rwsem *rw)
23588 + down_write(&rw->rwsem);
23589 + AuDbgWcntInc(rw);
23592 +static inline void au_rw_init_wlock_nested(struct au_rwsem *rw,
23593 + unsigned int lsc)
23596 + down_write_nested(&rw->rwsem, lsc);
23597 + AuDbgWcntInc(rw);
23600 +static inline void au_rw_read_lock(struct au_rwsem *rw)
23602 + down_read(&rw->rwsem);
23603 + AuDbgRcntInc(rw);
23606 +static inline void au_rw_read_lock_nested(struct au_rwsem *rw, unsigned int lsc)
23608 + down_read_nested(&rw->rwsem, lsc);
23609 + AuDbgRcntInc(rw);
23612 +static inline void au_rw_read_unlock(struct au_rwsem *rw)
23614 + AuRwMustReadLock(rw);
23615 + AuDbgRcntDec(rw);
23616 + up_read(&rw->rwsem);
23619 +static inline void au_rw_dgrade_lock(struct au_rwsem *rw)
23621 + AuRwMustWriteLock(rw);
23622 + AuDbgRcntInc(rw);
23623 + AuDbgWcntDec(rw);
23624 + downgrade_write(&rw->rwsem);
23627 +static inline void au_rw_write_lock(struct au_rwsem *rw)
23629 + down_write(&rw->rwsem);
23630 + AuDbgWcntInc(rw);
23633 +static inline void au_rw_write_lock_nested(struct au_rwsem *rw,
23634 + unsigned int lsc)
23636 + down_write_nested(&rw->rwsem, lsc);
23637 + AuDbgWcntInc(rw);
23640 +static inline void au_rw_write_unlock(struct au_rwsem *rw)
23642 + AuRwMustWriteLock(rw);
23643 + AuDbgWcntDec(rw);
23644 + up_write(&rw->rwsem);
23647 +/* why is not _nested version defined */
23648 +static inline int au_rw_read_trylock(struct au_rwsem *rw)
23650 + int ret = down_read_trylock(&rw->rwsem);
23652 + AuDbgRcntInc(rw);
23656 +static inline int au_rw_write_trylock(struct au_rwsem *rw)
23658 + int ret = down_write_trylock(&rw->rwsem);
23660 + AuDbgWcntInc(rw);
23664 +#undef AuDbgCntInit
23665 +#undef AuDbgRcntInc
23666 +#undef AuDbgRcntDec
23667 +#undef AuDbgWcntInc
23668 +#undef AuDbgWcntDec
23670 +#define AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
23671 +static inline void prefix##_read_lock(param) \
23672 +{ au_rw_read_lock(rwsem); } \
23673 +static inline void prefix##_write_lock(param) \
23674 +{ au_rw_write_lock(rwsem); } \
23675 +static inline int prefix##_read_trylock(param) \
23676 +{ return au_rw_read_trylock(rwsem); } \
23677 +static inline int prefix##_write_trylock(param) \
23678 +{ return au_rw_write_trylock(rwsem); }
23679 +/* why is not _nested version defined */
23680 +/* static inline void prefix##_read_trylock_nested(param, lsc)
23681 +{ au_rw_read_trylock_nested(rwsem, lsc)); }
23682 +static inline void prefix##_write_trylock_nestd(param, lsc)
23683 +{ au_rw_write_trylock_nested(rwsem, lsc); } */
23685 +#define AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) \
23686 +static inline void prefix##_read_unlock(param) \
23687 +{ au_rw_read_unlock(rwsem); } \
23688 +static inline void prefix##_write_unlock(param) \
23689 +{ au_rw_write_unlock(rwsem); } \
23690 +static inline void prefix##_downgrade_lock(param) \
23691 +{ au_rw_dgrade_lock(rwsem); }
23693 +#define AuSimpleRwsemFuncs(prefix, param, rwsem) \
23694 + AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
23695 + AuSimpleUnlockRwsemFuncs(prefix, param, rwsem)
23697 +#endif /* __KERNEL__ */
23698 +#endif /* __AUFS_RWSEM_H__ */
23699 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
23700 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
23701 +++ linux/fs/aufs/sbinfo.c 2013-07-06 13:20:47.753531903 +0200
23704 + * Copyright (C) 2005-2013 Junjiro R. Okajima
23706 + * This program, aufs is free software; you can redistribute it and/or modify
23707 + * it under the terms of the GNU General Public License as published by
23708 + * the Free Software Foundation; either version 2 of the License, or
23709 + * (at your option) any later version.
23711 + * This program is distributed in the hope that it will be useful,
23712 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23713 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23714 + * GNU General Public License for more details.
23716 + * You should have received a copy of the GNU General Public License
23717 + * along with this program; if not, write to the Free Software
23718 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23722 + * superblock private data
23728 + * they are necessary regardless sysfs is disabled.
23730 +void au_si_free(struct kobject *kobj)
23733 + struct au_sbinfo *sbinfo;
23734 + char *locked __maybe_unused; /* debug only */
23736 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
23737 + for (i = 0; i < AuPlink_NHASH; i++)
23738 + AuDebugOn(!hlist_empty(&sbinfo->si_plink[i].head));
23739 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
23741 + au_rw_write_lock(&sbinfo->si_rwsem);
23742 + au_br_free(sbinfo);
23743 + au_rw_write_unlock(&sbinfo->si_rwsem);
23745 + AuDebugOn(radix_tree_gang_lookup
23746 + (&sbinfo->au_si_pid.tree, (void **)&locked,
23747 + /*first_index*/PID_MAX_DEFAULT - 1,
23748 + /*max_items*/sizeof(locked)/sizeof(*locked)));
23750 + kfree(sbinfo->si_branch);
23751 + kfree(sbinfo->au_si_pid.bitmap);
23752 + mutex_destroy(&sbinfo->si_xib_mtx);
23753 + AuRwDestroy(&sbinfo->si_rwsem);
23758 +int au_si_alloc(struct super_block *sb)
23761 + struct au_sbinfo *sbinfo;
23762 + static struct lock_class_key aufs_si;
23765 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
23766 + if (unlikely(!sbinfo))
23769 + BUILD_BUG_ON(sizeof(unsigned long) !=
23770 + sizeof(*sbinfo->au_si_pid.bitmap));
23771 + sbinfo->au_si_pid.bitmap = kcalloc(BITS_TO_LONGS(PID_MAX_DEFAULT),
23772 + sizeof(*sbinfo->au_si_pid.bitmap),
23774 + if (unlikely(!sbinfo->au_si_pid.bitmap))
23777 + /* will be reallocated separately */
23778 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
23779 + if (unlikely(!sbinfo->si_branch))
23782 + err = sysaufs_si_init(sbinfo);
23783 + if (unlikely(err))
23786 + au_nwt_init(&sbinfo->si_nowait);
23787 + au_rw_init_wlock(&sbinfo->si_rwsem);
23788 + au_rw_class(&sbinfo->si_rwsem, &aufs_si);
23789 + spin_lock_init(&sbinfo->au_si_pid.tree_lock);
23790 + INIT_RADIX_TREE(&sbinfo->au_si_pid.tree, GFP_ATOMIC | __GFP_NOFAIL);
23792 + atomic_long_set(&sbinfo->si_ninodes, 0);
23793 + atomic_long_set(&sbinfo->si_nfiles, 0);
23795 + sbinfo->si_bend = -1;
23797 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
23798 + sbinfo->si_wbr_create = AuWbrCreate_Def;
23799 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
23800 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
23802 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
23804 + mutex_init(&sbinfo->si_xib_mtx);
23805 + sbinfo->si_xino_brid = -1;
23806 + /* leave si_xib_last_pindex and si_xib_next_bit */
23808 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
23809 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
23810 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
23811 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
23813 + for (i = 0; i < AuPlink_NHASH; i++)
23814 + au_sphl_init(sbinfo->si_plink + i);
23815 + init_waitqueue_head(&sbinfo->si_plink_wq);
23816 + spin_lock_init(&sbinfo->si_plink_maint_lock);
23818 + /* leave other members for sysaufs and si_mnt. */
23819 + sbinfo->si_sb = sb;
23820 + sb->s_fs_info = sbinfo;
23822 + au_debug_sbinfo_init(sbinfo);
23823 + return 0; /* success */
23826 + kfree(sbinfo->si_branch);
23828 + kfree(sbinfo->au_si_pid.bitmap);
23835 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr)
23838 + struct au_branch **brp;
23840 + AuRwMustWriteLock(&sbinfo->si_rwsem);
23843 + sz = sizeof(*brp) * (sbinfo->si_bend + 1);
23844 + if (unlikely(!sz))
23845 + sz = sizeof(*brp);
23846 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS);
23848 + sbinfo->si_branch = brp;
23855 +/* ---------------------------------------------------------------------- */
23857 +unsigned int au_sigen_inc(struct super_block *sb)
23859 + unsigned int gen;
23861 + SiMustWriteLock(sb);
23863 + gen = ++au_sbi(sb)->si_generation;
23864 + au_update_digen(sb->s_root);
23865 + au_update_iigen(sb->s_root->d_inode, /*half*/0);
23866 + sb->s_root->d_inode->i_version++;
23870 +aufs_bindex_t au_new_br_id(struct super_block *sb)
23872 + aufs_bindex_t br_id;
23874 + struct au_sbinfo *sbinfo;
23876 + SiMustWriteLock(sb);
23878 + sbinfo = au_sbi(sb);
23879 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
23880 + br_id = ++sbinfo->si_last_br_id;
23881 + AuDebugOn(br_id < 0);
23882 + if (br_id && au_br_index(sb, br_id) < 0)
23889 +/* ---------------------------------------------------------------------- */
23891 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
23892 +int si_read_lock(struct super_block *sb, int flags)
23897 + if (au_ftest_lock(flags, FLUSH))
23898 + au_nwt_flush(&au_sbi(sb)->si_nowait);
23900 + si_noflush_read_lock(sb);
23901 + err = au_plink_maint(sb, flags);
23902 + if (unlikely(err))
23903 + si_read_unlock(sb);
23908 +int si_write_lock(struct super_block *sb, int flags)
23912 + if (au_ftest_lock(flags, FLUSH))
23913 + au_nwt_flush(&au_sbi(sb)->si_nowait);
23915 + si_noflush_write_lock(sb);
23916 + err = au_plink_maint(sb, flags);
23917 + if (unlikely(err))
23918 + si_write_unlock(sb);
23923 +/* dentry and super_block lock. call at entry point */
23924 +int aufs_read_lock(struct dentry *dentry, int flags)
23927 + struct super_block *sb;
23929 + sb = dentry->d_sb;
23930 + err = si_read_lock(sb, flags);
23931 + if (unlikely(err))
23934 + if (au_ftest_lock(flags, DW))
23935 + di_write_lock_child(dentry);
23937 + di_read_lock_child(dentry, flags);
23939 + if (au_ftest_lock(flags, GEN)) {
23940 + err = au_digen_test(dentry, au_sigen(sb));
23941 + AuDebugOn(!err && au_dbrange_test(dentry));
23942 + if (unlikely(err))
23943 + aufs_read_unlock(dentry, flags);
23950 +void aufs_read_unlock(struct dentry *dentry, int flags)
23952 + if (au_ftest_lock(flags, DW))
23953 + di_write_unlock(dentry);
23955 + di_read_unlock(dentry, flags);
23956 + si_read_unlock(dentry->d_sb);
23959 +void aufs_write_lock(struct dentry *dentry)
23961 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
23962 + di_write_lock_child(dentry);
23965 +void aufs_write_unlock(struct dentry *dentry)
23967 + di_write_unlock(dentry);
23968 + si_write_unlock(dentry->d_sb);
23971 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
23974 + unsigned int sigen;
23975 + struct super_block *sb;
23978 + err = si_read_lock(sb, flags);
23979 + if (unlikely(err))
23982 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIR));
23984 + if (au_ftest_lock(flags, GEN)) {
23985 + sigen = au_sigen(sb);
23986 + err = au_digen_test(d1, sigen);
23987 + AuDebugOn(!err && au_dbrange_test(d1));
23989 + err = au_digen_test(d2, sigen);
23990 + AuDebugOn(!err && au_dbrange_test(d2));
23992 + if (unlikely(err))
23993 + aufs_read_and_write_unlock2(d1, d2);
24000 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
24002 + di_write_unlock2(d1, d2);
24003 + si_read_unlock(d1->d_sb);
24006 +/* ---------------------------------------------------------------------- */
24008 +int si_pid_test_slow(struct super_block *sb)
24013 + p = radix_tree_lookup(&au_sbi(sb)->au_si_pid.tree, current->pid);
24014 + rcu_read_unlock();
24016 + return (long)!!p;
24019 +void si_pid_set_slow(struct super_block *sb)
24022 + struct au_sbinfo *sbinfo;
24024 + AuDebugOn(si_pid_test_slow(sb));
24026 + sbinfo = au_sbi(sb);
24027 + err = radix_tree_preload(GFP_NOFS | __GFP_NOFAIL);
24029 + spin_lock(&sbinfo->au_si_pid.tree_lock);
24030 + err = radix_tree_insert(&sbinfo->au_si_pid.tree, current->pid,
24031 + /*any valid ptr*/sb);
24032 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
24034 + radix_tree_preload_end();
24037 +void si_pid_clr_slow(struct super_block *sb)
24040 + struct au_sbinfo *sbinfo;
24042 + AuDebugOn(!si_pid_test_slow(sb));
24044 + sbinfo = au_sbi(sb);
24045 + spin_lock(&sbinfo->au_si_pid.tree_lock);
24046 + p = radix_tree_delete(&sbinfo->au_si_pid.tree, current->pid);
24047 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
24049 diff -urN /usr/share/empty/fs/aufs/spl.h linux/fs/aufs/spl.h
24050 --- /usr/share/empty/fs/aufs/spl.h 1970-01-01 01:00:00.000000000 +0100
24051 +++ linux/fs/aufs/spl.h 2013-07-06 13:20:47.753531903 +0200
24054 + * Copyright (C) 2005-2013 Junjiro R. Okajima
24056 + * This program, aufs is free software; you can redistribute it and/or modify
24057 + * it under the terms of the GNU General Public License as published by
24058 + * the Free Software Foundation; either version 2 of the License, or
24059 + * (at your option) any later version.
24061 + * This program is distributed in the hope that it will be useful,
24062 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24063 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24064 + * GNU General Public License for more details.
24066 + * You should have received a copy of the GNU General Public License
24067 + * along with this program; if not, write to the Free Software
24068 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24072 + * simple list protected by a spinlock
24075 +#ifndef __AUFS_SPL_H__
24076 +#define __AUFS_SPL_H__
24080 +struct au_splhead {
24082 + struct list_head head;
24085 +static inline void au_spl_init(struct au_splhead *spl)
24087 + spin_lock_init(&spl->spin);
24088 + INIT_LIST_HEAD(&spl->head);
24091 +static inline void au_spl_add(struct list_head *list, struct au_splhead *spl)
24093 + spin_lock(&spl->spin);
24094 + list_add(list, &spl->head);
24095 + spin_unlock(&spl->spin);
24098 +static inline void au_spl_del(struct list_head *list, struct au_splhead *spl)
24100 + spin_lock(&spl->spin);
24102 + spin_unlock(&spl->spin);
24105 +static inline void au_spl_del_rcu(struct list_head *list,
24106 + struct au_splhead *spl)
24108 + spin_lock(&spl->spin);
24109 + list_del_rcu(list);
24110 + spin_unlock(&spl->spin);
24113 +/* ---------------------------------------------------------------------- */
24115 +struct au_sphlhead {
24117 + struct hlist_head head;
24120 +static inline void au_sphl_init(struct au_sphlhead *sphl)
24122 + spin_lock_init(&sphl->spin);
24123 + INIT_HLIST_HEAD(&sphl->head);
24126 +static inline void au_sphl_add(struct hlist_node *hlist,
24127 + struct au_sphlhead *sphl)
24129 + spin_lock(&sphl->spin);
24130 + hlist_add_head(hlist, &sphl->head);
24131 + spin_unlock(&sphl->spin);
24134 +static inline void au_sphl_del(struct hlist_node *hlist,
24135 + struct au_sphlhead *sphl)
24137 + spin_lock(&sphl->spin);
24138 + hlist_del(hlist);
24139 + spin_unlock(&sphl->spin);
24142 +static inline void au_sphl_del_rcu(struct hlist_node *hlist,
24143 + struct au_sphlhead *sphl)
24145 + spin_lock(&sphl->spin);
24146 + hlist_del_rcu(hlist);
24147 + spin_unlock(&sphl->spin);
24150 +static inline unsigned long au_sphl_count(struct au_sphlhead *sphl)
24152 + unsigned long cnt;
24153 + struct hlist_node *pos;
24156 + spin_lock(&sphl->spin);
24157 + hlist_for_each(pos, &sphl->head)
24159 + spin_unlock(&sphl->spin);
24163 +#endif /* __KERNEL__ */
24164 +#endif /* __AUFS_SPL_H__ */
24165 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
24166 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
24167 +++ linux/fs/aufs/super.c 2013-08-23 23:59:39.634916914 +0200
24170 + * Copyright (C) 2005-2013 Junjiro R. Okajima
24172 + * This program, aufs is free software; you can redistribute it and/or modify
24173 + * it under the terms of the GNU General Public License as published by
24174 + * the Free Software Foundation; either version 2 of the License, or
24175 + * (at your option) any later version.
24177 + * This program is distributed in the hope that it will be useful,
24178 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24179 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24180 + * GNU General Public License for more details.
24182 + * You should have received a copy of the GNU General Public License
24183 + * along with this program; if not, write to the Free Software
24184 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24188 + * mount and super_block operations
24191 +#include <linux/mm.h>
24192 +#include <linux/module.h>
24193 +#include <linux/seq_file.h>
24194 +#include <linux/statfs.h>
24195 +#include <linux/vmalloc.h>
24196 +#include <linux/writeback.h>
24200 + * super_operations
24202 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
24204 + struct au_icntnr *c;
24206 + c = au_cache_alloc_icntnr();
24208 + au_icntnr_init(c);
24209 + c->vfs_inode.i_version = 1; /* sigen(sb); */
24210 + c->iinfo.ii_hinode = NULL;
24211 + return &c->vfs_inode;
24216 +static void aufs_destroy_inode_cb(struct rcu_head *head)
24218 + struct inode *inode = container_of(head, struct inode, i_rcu);
24220 + INIT_HLIST_HEAD(&inode->i_dentry);
24221 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
24224 +static void aufs_destroy_inode(struct inode *inode)
24226 + au_iinfo_fin(inode);
24227 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
24230 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
24232 + struct inode *inode;
24235 + inode = iget_locked(sb, ino);
24236 + if (unlikely(!inode)) {
24237 + inode = ERR_PTR(-ENOMEM);
24240 + if (!(inode->i_state & I_NEW))
24243 + err = au_xigen_new(inode);
24245 + err = au_iinfo_init(inode);
24247 + inode->i_version++;
24249 + iget_failed(inode);
24250 + inode = ERR_PTR(err);
24254 + /* never return NULL */
24255 + AuDebugOn(!inode);
24256 + AuTraceErrPtr(inode);
24260 +/* lock free root dinfo */
24261 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
24264 + aufs_bindex_t bindex, bend;
24265 + struct path path;
24266 + struct au_hdentry *hdp;
24267 + struct au_branch *br;
24271 + bend = au_sbend(sb);
24272 + hdp = au_di(sb->s_root)->di_hdentry;
24273 + for (bindex = 0; !err && bindex <= bend; bindex++) {
24274 + br = au_sbr(sb, bindex);
24275 + path.mnt = au_br_mnt(br);
24276 + path.dentry = hdp[bindex].hd_dentry;
24277 + err = au_seq_path(seq, &path);
24279 + perm = au_optstr_br_perm(br->br_perm);
24281 + err = seq_printf(seq, "=%s", perm);
24288 + if (!err && bindex != bend)
24289 + err = seq_putc(seq, ':');
24295 +static void au_show_wbr_create(struct seq_file *m, int v,
24296 + struct au_sbinfo *sbinfo)
24300 + AuRwMustAnyLock(&sbinfo->si_rwsem);
24302 + seq_puts(m, ",create=");
24303 + pat = au_optstr_wbr_create(v);
24305 + case AuWbrCreate_TDP:
24306 + case AuWbrCreate_RR:
24307 + case AuWbrCreate_MFS:
24308 + case AuWbrCreate_PMFS:
24309 + seq_puts(m, pat);
24311 + case AuWbrCreate_MFSV:
24312 + seq_printf(m, /*pat*/"mfs:%lu",
24313 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
24316 + case AuWbrCreate_PMFSV:
24317 + seq_printf(m, /*pat*/"pmfs:%lu",
24318 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
24321 + case AuWbrCreate_MFSRR:
24322 + seq_printf(m, /*pat*/"mfsrr:%llu",
24323 + sbinfo->si_wbr_mfs.mfsrr_watermark);
24325 + case AuWbrCreate_MFSRRV:
24326 + seq_printf(m, /*pat*/"mfsrr:%llu:%lu",
24327 + sbinfo->si_wbr_mfs.mfsrr_watermark,
24328 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
24334 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
24336 +#ifdef CONFIG_SYSFS
24340 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
24341 + aufs_bindex_t bindex, brid;
24342 + struct qstr *name;
24344 + struct dentry *d, *h_root;
24345 + struct au_hdentry *hdp;
24347 + AuRwMustAnyLock(&sbinfo->si_rwsem);
24350 + f = au_sbi(sb)->si_xib;
24354 + /* stop printing the default xino path on the first writable branch */
24356 + brid = au_xino_brid(sb);
24358 + bindex = au_br_index(sb, brid);
24359 + hdp = au_di(sb->s_root)->di_hdentry;
24360 + h_root = hdp[0 + bindex].hd_dentry;
24363 + name = &d->d_name;
24364 + /* safe ->d_parent because the file is unlinked */
24365 + if (d->d_parent == h_root
24366 + && name->len == len
24367 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
24370 + seq_puts(seq, ",xino=");
24371 + err = au_xino_path(seq, f);
24378 +/* seq_file will re-call me in case of too long string */
24379 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
24382 + unsigned int mnt_flags, v;
24383 + struct super_block *sb;
24384 + struct au_sbinfo *sbinfo;
24386 +#define AuBool(name, str) do { \
24387 + v = au_opt_test(mnt_flags, name); \
24388 + if (v != au_opt_test(AuOpt_Def, name)) \
24389 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
24392 +#define AuStr(name, str) do { \
24393 + v = mnt_flags & AuOptMask_##name; \
24394 + if (v != (AuOpt_Def & AuOptMask_##name)) \
24395 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
24398 +#define AuUInt(name, str, val) do { \
24399 + if (val != AUFS_##name##_DEF) \
24400 + seq_printf(m, "," #str "=%u", val); \
24403 + /* lock free root dinfo */
24404 + sb = dentry->d_sb;
24405 + si_noflush_read_lock(sb);
24406 + sbinfo = au_sbi(sb);
24407 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
24409 + mnt_flags = au_mntflags(sb);
24410 + if (au_opt_test(mnt_flags, XINO)) {
24411 + err = au_show_xino(m, sb);
24412 + if (unlikely(err))
24415 + seq_puts(m, ",noxino");
24417 + AuBool(TRUNC_XINO, trunc_xino);
24418 + AuStr(UDBA, udba);
24419 + AuBool(SHWH, shwh);
24420 + AuBool(PLINK, plink);
24421 + AuBool(DIO, dio);
24422 + /* AuBool(DIRPERM1, dirperm1); */
24423 + /* AuBool(REFROF, refrof); */
24425 + v = sbinfo->si_wbr_create;
24426 + if (v != AuWbrCreate_Def)
24427 + au_show_wbr_create(m, v, sbinfo);
24429 + v = sbinfo->si_wbr_copyup;
24430 + if (v != AuWbrCopyup_Def)
24431 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
24433 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
24434 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
24435 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
24437 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
24439 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
24440 + AuUInt(RDCACHE, rdcache, v);
24442 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
24443 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
24445 + AuBool(SUM, sum);
24446 + /* AuBool(SUM_W, wsum); */
24447 + AuBool(WARN_PERM, warn_perm);
24448 + AuBool(VERBOSE, verbose);
24451 + /* be sure to print "br:" last */
24452 + if (!sysaufs_brs) {
24453 + seq_puts(m, ",br:");
24454 + au_show_brs(m, sb);
24456 + si_read_unlock(sb);
24464 +/* ---------------------------------------------------------------------- */
24466 +/* sum mode which returns the summation for statfs(2) */
24468 +static u64 au_add_till_max(u64 a, u64 b)
24476 + return ULLONG_MAX;
24479 +static u64 au_mul_till_max(u64 a, long mul)
24487 + return ULLONG_MAX;
24490 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
24493 + long bsize, factor;
24494 + u64 blocks, bfree, bavail, files, ffree;
24495 + aufs_bindex_t bend, bindex, i;
24496 + unsigned char shared;
24497 + struct path h_path;
24498 + struct super_block *h_sb;
24501 + bsize = LONG_MAX;
24507 + bend = au_sbend(sb);
24508 + for (bindex = 0; bindex <= bend; bindex++) {
24509 + h_path.mnt = au_sbr_mnt(sb, bindex);
24510 + h_sb = h_path.mnt->mnt_sb;
24512 + for (i = 0; !shared && i < bindex; i++)
24513 + shared = (au_sbr_sb(sb, i) == h_sb);
24517 + /* sb->s_root for NFS is unreliable */
24518 + h_path.dentry = h_path.mnt->mnt_root;
24519 + err = vfs_statfs(&h_path, buf);
24520 + if (unlikely(err))
24523 + if (bsize > buf->f_bsize) {
24525 + * we will reduce bsize, so we have to expand blocks
24526 + * etc. to match them again
24528 + factor = (bsize / buf->f_bsize);
24529 + blocks = au_mul_till_max(blocks, factor);
24530 + bfree = au_mul_till_max(bfree, factor);
24531 + bavail = au_mul_till_max(bavail, factor);
24532 + bsize = buf->f_bsize;
24535 + factor = (buf->f_bsize / bsize);
24536 + blocks = au_add_till_max(blocks,
24537 + au_mul_till_max(buf->f_blocks, factor));
24538 + bfree = au_add_till_max(bfree,
24539 + au_mul_till_max(buf->f_bfree, factor));
24540 + bavail = au_add_till_max(bavail,
24541 + au_mul_till_max(buf->f_bavail, factor));
24542 + files = au_add_till_max(files, buf->f_files);
24543 + ffree = au_add_till_max(ffree, buf->f_ffree);
24546 + buf->f_bsize = bsize;
24547 + buf->f_blocks = blocks;
24548 + buf->f_bfree = bfree;
24549 + buf->f_bavail = bavail;
24550 + buf->f_files = files;
24551 + buf->f_ffree = ffree;
24552 + buf->f_frsize = 0;
24558 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
24561 + struct path h_path;
24562 + struct super_block *sb;
24564 + /* lock free root dinfo */
24565 + sb = dentry->d_sb;
24566 + si_noflush_read_lock(sb);
24567 + if (!au_opt_test(au_mntflags(sb), SUM)) {
24568 + /* sb->s_root for NFS is unreliable */
24569 + h_path.mnt = au_sbr_mnt(sb, 0);
24570 + h_path.dentry = h_path.mnt->mnt_root;
24571 + err = vfs_statfs(&h_path, buf);
24573 + err = au_statfs_sum(sb, buf);
24574 + si_read_unlock(sb);
24577 + buf->f_type = AUFS_SUPER_MAGIC;
24578 + buf->f_namelen = AUFS_MAX_NAMELEN;
24579 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
24581 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
24586 +/* ---------------------------------------------------------------------- */
24588 +static int aufs_sync_fs(struct super_block *sb, int wait)
24591 + aufs_bindex_t bend, bindex;
24592 + struct au_branch *br;
24593 + struct super_block *h_sb;
24596 + si_noflush_read_lock(sb);
24597 + bend = au_sbend(sb);
24598 + for (bindex = 0; bindex <= bend; bindex++) {
24599 + br = au_sbr(sb, bindex);
24600 + if (!au_br_writable(br->br_perm))
24603 + h_sb = au_sbr_sb(sb, bindex);
24604 + if (h_sb->s_op->sync_fs) {
24605 + e = h_sb->s_op->sync_fs(h_sb, wait);
24606 + if (unlikely(e && !err))
24608 + /* go on even if an error happens */
24611 + si_read_unlock(sb);
24616 +/* ---------------------------------------------------------------------- */
24618 +/* final actions when unmounting a file system */
24619 +static void aufs_put_super(struct super_block *sb)
24621 + struct au_sbinfo *sbinfo;
24623 + sbinfo = au_sbi(sb);
24627 + dbgaufs_si_fin(sbinfo);
24628 + kobject_put(&sbinfo->si_kobj);
24631 +/* ---------------------------------------------------------------------- */
24633 +void au_array_free(void *array)
24636 + if (!is_vmalloc_addr(array))
24643 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg)
24646 + unsigned long long n;
24653 + if (*hint > ULLONG_MAX / sizeof(array)) {
24654 + array = ERR_PTR(-EMFILE);
24655 + pr_err("hint %llu\n", *hint);
24659 + array = kmalloc(sizeof(array) * *hint, GFP_NOFS);
24660 + if (unlikely(!array))
24661 + array = vmalloc(sizeof(array) * *hint);
24662 + if (unlikely(!array)) {
24663 + array = ERR_PTR(-ENOMEM);
24667 + n = cb(array, *hint, arg);
24668 + AuDebugOn(n > *hint);
24675 +static unsigned long long au_iarray_cb(void *a,
24676 + unsigned long long max __maybe_unused,
24679 + unsigned long long n;
24680 + struct inode **p, *inode;
24681 + struct list_head *head;
24686 + spin_lock(&inode_sb_list_lock);
24687 + list_for_each_entry(inode, head, i_sb_list) {
24688 + if (!is_bad_inode(inode)
24689 + && au_ii(inode)->ii_bstart >= 0) {
24690 + spin_lock(&inode->i_lock);
24691 + if (atomic_read(&inode->i_count)) {
24695 + AuDebugOn(n > max);
24697 + spin_unlock(&inode->i_lock);
24700 + spin_unlock(&inode_sb_list_lock);
24705 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
24707 + *max = atomic_long_read(&au_sbi(sb)->si_ninodes);
24708 + return au_array_alloc(max, au_iarray_cb, &sb->s_inodes);
24711 +void au_iarray_free(struct inode **a, unsigned long long max)
24713 + unsigned long long ull;
24715 + for (ull = 0; ull < max; ull++)
24717 + au_array_free(a);
24720 +/* ---------------------------------------------------------------------- */
24723 + * refresh dentry and inode at remount time.
24725 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
24726 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
24727 + struct dentry *parent)
24731 + di_write_lock_child(dentry);
24732 + di_read_lock_parent(parent, AuLock_IR);
24733 + err = au_refresh_dentry(dentry, parent);
24734 + if (!err && dir_flags)
24735 + au_hn_reset(dentry->d_inode, dir_flags);
24736 + di_read_unlock(parent, AuLock_IR);
24737 + di_write_unlock(dentry);
24742 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
24743 + struct au_sbinfo *sbinfo,
24744 + const unsigned int dir_flags)
24747 + struct dentry *parent;
24748 + struct inode *inode;
24751 + parent = dget_parent(dentry);
24752 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
24753 + inode = dentry->d_inode;
24755 + if (!S_ISDIR(inode->i_mode))
24756 + err = au_do_refresh(dentry, /*dir_flags*/0,
24759 + err = au_do_refresh(dentry, dir_flags, parent);
24760 + if (unlikely(err))
24761 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
24764 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
24765 + AuDbgDentry(dentry);
24773 +static int au_refresh_d(struct super_block *sb)
24775 + int err, i, j, ndentry, e;
24776 + unsigned int sigen;
24777 + struct au_dcsub_pages dpages;
24778 + struct au_dpage *dpage;
24779 + struct dentry **dentries, *d;
24780 + struct au_sbinfo *sbinfo;
24781 + struct dentry *root = sb->s_root;
24782 + const unsigned int dir_flags = au_hi_flags(root->d_inode, /*isdir*/1);
24784 + err = au_dpages_init(&dpages, GFP_NOFS);
24785 + if (unlikely(err))
24787 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
24788 + if (unlikely(err))
24791 + sigen = au_sigen(sb);
24792 + sbinfo = au_sbi(sb);
24793 + for (i = 0; i < dpages.ndpage; i++) {
24794 + dpage = dpages.dpages + i;
24795 + dentries = dpage->dentries;
24796 + ndentry = dpage->ndentry;
24797 + for (j = 0; j < ndentry; j++) {
24799 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags);
24800 + if (unlikely(e && !err))
24802 + /* go on even err */
24807 + au_dpages_free(&dpages);
24812 +static int au_refresh_i(struct super_block *sb)
24815 + unsigned int sigen;
24816 + unsigned long long max, ull;
24817 + struct inode *inode, **array;
24819 + array = au_iarray_alloc(sb, &max);
24820 + err = PTR_ERR(array);
24821 + if (IS_ERR(array))
24825 + sigen = au_sigen(sb);
24826 + for (ull = 0; ull < max; ull++) {
24827 + inode = array[ull];
24828 + if (au_iigen(inode, NULL) != sigen) {
24829 + ii_write_lock_child(inode);
24830 + e = au_refresh_hinode_self(inode);
24831 + ii_write_unlock(inode);
24832 + if (unlikely(e)) {
24833 + pr_err("error %d, i%lu\n", e, inode->i_ino);
24836 + /* go on even if err */
24841 + au_iarray_free(array, max);
24847 +static void au_remount_refresh(struct super_block *sb)
24850 + unsigned int udba;
24851 + aufs_bindex_t bindex, bend;
24852 + struct dentry *root;
24853 + struct inode *inode;
24854 + struct au_branch *br;
24856 + au_sigen_inc(sb);
24857 + au_fclr_si(au_sbi(sb), FAILED_REFRESH_DIR);
24859 + root = sb->s_root;
24860 + DiMustNoWaiters(root);
24861 + inode = root->d_inode;
24862 + IiMustNoWaiters(inode);
24864 + udba = au_opt_udba(sb);
24865 + bend = au_sbend(sb);
24866 + for (bindex = 0; bindex <= bend; bindex++) {
24867 + br = au_sbr(sb, bindex);
24868 + err = au_hnotify_reset_br(udba, br, br->br_perm);
24869 + if (unlikely(err))
24870 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
24872 + /* go on even if err */
24874 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
24876 + di_write_unlock(root);
24877 + err = au_refresh_d(sb);
24878 + e = au_refresh_i(sb);
24879 + if (unlikely(e && !err))
24881 + /* aufs_write_lock() calls ..._child() */
24882 + di_write_lock_child(root);
24884 + au_cpup_attr_all(inode, /*force*/1);
24886 + if (unlikely(err))
24887 + AuIOErr("refresh failed, ignored, %d\n", err);
24890 +/* stop extra interpretation of errno in mount(8), and strange error messages */
24891 +static int cvt_err(int err)
24905 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
24908 + unsigned int mntflags;
24909 + struct au_opts opts;
24910 + struct dentry *root;
24911 + struct inode *inode;
24912 + struct au_sbinfo *sbinfo;
24915 + root = sb->s_root;
24916 + if (!data || !*data) {
24917 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
24919 + di_write_lock_child(root);
24920 + err = au_opts_verify(sb, *flags, /*pending*/0);
24921 + aufs_write_unlock(root);
24927 + memset(&opts, 0, sizeof(opts));
24928 + opts.opt = (void *)__get_free_page(GFP_NOFS);
24929 + if (unlikely(!opts.opt))
24931 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
24932 + opts.flags = AuOpts_REMOUNT;
24933 + opts.sb_flags = *flags;
24935 + /* parse it before aufs lock */
24936 + err = au_opts_parse(sb, data, &opts);
24937 + if (unlikely(err))
24940 + sbinfo = au_sbi(sb);
24941 + inode = root->d_inode;
24942 + mutex_lock(&inode->i_mutex);
24943 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
24944 + if (unlikely(err))
24946 + di_write_lock_child(root);
24948 + /* au_opts_remount() may return an error */
24949 + err = au_opts_remount(sb, &opts);
24950 + au_opts_free(&opts);
24952 + if (au_ftest_opts(opts.flags, REFRESH))
24953 + au_remount_refresh(sb);
24955 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
24956 + mntflags = au_mntflags(sb);
24957 + do_dx = !!au_opt_test(mntflags, DIO);
24958 + au_dy_arefresh(do_dx);
24961 + aufs_write_unlock(root);
24964 + mutex_unlock(&inode->i_mutex);
24966 + free_page((unsigned long)opts.opt);
24968 + err = cvt_err(err);
24973 +static const struct super_operations aufs_sop = {
24974 + .alloc_inode = aufs_alloc_inode,
24975 + .destroy_inode = aufs_destroy_inode,
24976 + /* always deleting, no clearing */
24977 + .drop_inode = generic_delete_inode,
24978 + .show_options = aufs_show_options,
24979 + .statfs = aufs_statfs,
24980 + .put_super = aufs_put_super,
24981 + .sync_fs = aufs_sync_fs,
24982 + .remount_fs = aufs_remount_fs
24985 +/* ---------------------------------------------------------------------- */
24987 +static int alloc_root(struct super_block *sb)
24990 + struct inode *inode;
24991 + struct dentry *root;
24994 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
24995 + err = PTR_ERR(inode);
24996 + if (IS_ERR(inode))
24999 + inode->i_op = &aufs_dir_iop;
25000 + inode->i_fop = &aufs_dir_fop;
25001 + inode->i_mode = S_IFDIR;
25002 + set_nlink(inode, 2);
25003 + unlock_new_inode(inode);
25005 + root = d_make_root(inode);
25006 + if (unlikely(!root))
25008 + err = PTR_ERR(root);
25009 + if (IS_ERR(root))
25012 + err = au_di_init(root);
25014 + sb->s_root = root;
25015 + return 0; /* success */
25023 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
25024 + int silent __maybe_unused)
25027 + struct au_opts opts;
25028 + struct dentry *root;
25029 + struct inode *inode;
25030 + char *arg = raw_data;
25032 + if (unlikely(!arg || !*arg)) {
25034 + pr_err("no arg\n");
25039 + memset(&opts, 0, sizeof(opts));
25040 + opts.opt = (void *)__get_free_page(GFP_NOFS);
25041 + if (unlikely(!opts.opt))
25043 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
25044 + opts.sb_flags = sb->s_flags;
25046 + err = au_si_alloc(sb);
25047 + if (unlikely(err))
25050 + /* all timestamps always follow the ones on the branch */
25051 + sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
25052 + sb->s_op = &aufs_sop;
25053 + sb->s_d_op = &aufs_dop;
25054 + sb->s_magic = AUFS_SUPER_MAGIC;
25055 + sb->s_maxbytes = 0;
25056 + au_export_init(sb);
25058 + err = alloc_root(sb);
25059 + if (unlikely(err)) {
25060 + si_write_unlock(sb);
25063 + root = sb->s_root;
25064 + inode = root->d_inode;
25067 + * actually we can parse options regardless aufs lock here.
25068 + * but at remount time, parsing must be done before aufs lock.
25069 + * so we follow the same rule.
25071 + ii_write_lock_parent(inode);
25072 + aufs_write_unlock(root);
25073 + err = au_opts_parse(sb, arg, &opts);
25074 + if (unlikely(err))
25077 + /* lock vfs_inode first, then aufs. */
25078 + mutex_lock(&inode->i_mutex);
25079 + aufs_write_lock(root);
25080 + err = au_opts_mount(sb, &opts);
25081 + au_opts_free(&opts);
25082 + aufs_write_unlock(root);
25083 + mutex_unlock(&inode->i_mutex);
25085 + goto out_opts; /* success */
25089 + sb->s_root = NULL;
25091 + dbgaufs_si_fin(au_sbi(sb));
25092 + kobject_put(&au_sbi(sb)->si_kobj);
25093 + sb->s_fs_info = NULL;
25095 + free_page((unsigned long)opts.opt);
25098 + err = cvt_err(err);
25103 +/* ---------------------------------------------------------------------- */
25105 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
25106 + const char *dev_name __maybe_unused,
25109 + struct dentry *root;
25110 + struct super_block *sb;
25112 + /* all timestamps always follow the ones on the branch */
25113 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
25114 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
25115 + if (IS_ERR(root))
25119 + si_write_lock(sb, !AuLock_FLUSH);
25120 + sysaufs_brs_add(sb, 0);
25121 + si_write_unlock(sb);
25122 + au_sbilist_add(sb);
25128 +static void aufs_kill_sb(struct super_block *sb)
25130 + struct au_sbinfo *sbinfo;
25132 + sbinfo = au_sbi(sb);
25134 + au_sbilist_del(sb);
25135 + aufs_write_lock(sb->s_root);
25136 + if (sbinfo->si_wbr_create_ops->fin)
25137 + sbinfo->si_wbr_create_ops->fin(sb);
25138 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
25139 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
25140 + au_remount_refresh(sb);
25142 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
25143 + au_plink_put(sb, /*verbose*/1);
25145 + sbinfo->si_sb = NULL;
25146 + aufs_write_unlock(sb->s_root);
25147 + au_nwt_flush(&sbinfo->si_nowait);
25149 + generic_shutdown_super(sb);
25152 +struct file_system_type aufs_fs_type = {
25153 + .name = AUFS_FSTYPE,
25154 + /* a race between rename and others */
25155 + .fs_flags = FS_RENAME_DOES_D_MOVE,
25156 + .mount = aufs_mount,
25157 + .kill_sb = aufs_kill_sb,
25158 + /* no need to __module_get() and module_put(). */
25159 + .owner = THIS_MODULE,
25161 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
25162 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
25163 +++ linux/fs/aufs/super.h 2013-08-23 23:59:39.638250372 +0200
25166 + * Copyright (C) 2005-2013 Junjiro R. Okajima
25168 + * This program, aufs is free software; you can redistribute it and/or modify
25169 + * it under the terms of the GNU General Public License as published by
25170 + * the Free Software Foundation; either version 2 of the License, or
25171 + * (at your option) any later version.
25173 + * This program is distributed in the hope that it will be useful,
25174 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25175 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25176 + * GNU General Public License for more details.
25178 + * You should have received a copy of the GNU General Public License
25179 + * along with this program; if not, write to the Free Software
25180 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25184 + * super_block operations
25187 +#ifndef __AUFS_SUPER_H__
25188 +#define __AUFS_SUPER_H__
25192 +#include <linux/fs.h>
25193 +#include "rwsem.h"
25197 +typedef ssize_t (*au_readf_t)(struct file *, char __user *, size_t, loff_t *);
25198 +typedef ssize_t (*au_writef_t)(struct file *, const char __user *, size_t,
25201 +/* policies to select one among multiple writable branches */
25202 +struct au_wbr_copyup_operations {
25203 + int (*copyup)(struct dentry *dentry);
25206 +struct au_wbr_create_operations {
25207 + int (*create)(struct dentry *dentry, int isdir);
25208 + int (*init)(struct super_block *sb);
25209 + int (*fin)(struct super_block *sb);
25212 +struct au_wbr_mfs {
25213 + struct mutex mfs_lock; /* protect this structure */
25214 + unsigned long mfs_jiffy;
25215 + unsigned long mfs_expire;
25216 + aufs_bindex_t mfs_bindex;
25218 + unsigned long long mfsrr_bytes;
25219 + unsigned long long mfsrr_watermark;
25222 +struct pseudo_link {
25224 + struct hlist_node hlist;
25225 + struct rcu_head rcu;
25227 + struct inode *inode;
25230 +#define AuPlink_NHASH 100
25231 +static inline int au_plink_hash(ino_t ino)
25233 + return ino % AuPlink_NHASH;
25237 +struct au_sbinfo {
25238 + /* nowait tasks in the system-wide workqueue */
25239 + struct au_nowait_tasks si_nowait;
25242 + * tried sb->s_umount, but failed due to the dependecy between i_mutex.
25243 + * rwsem for au_sbinfo is necessary.
25245 + struct au_rwsem si_rwsem;
25247 + /* prevent recursive locking in deleting inode */
25249 + unsigned long *bitmap;
25250 + spinlock_t tree_lock;
25251 + struct radix_tree_root tree;
25255 + * dirty approach to protect sb->sb_inodes and ->s_files from remount.
25257 + atomic_long_t si_ninodes, si_nfiles;
25259 + /* branch management */
25260 + unsigned int si_generation;
25262 + /* see above flags */
25263 + unsigned char au_si_status;
25265 + aufs_bindex_t si_bend;
25267 + /* dirty trick to keep br_id plus */
25268 + unsigned int si_last_br_id :
25269 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
25270 + struct au_branch **si_branch;
25272 + /* policy to select a writable branch */
25273 + unsigned char si_wbr_copyup;
25274 + unsigned char si_wbr_create;
25275 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
25276 + struct au_wbr_create_operations *si_wbr_create_ops;
25278 + /* round robin */
25279 + atomic_t si_wbr_rr_next;
25281 + /* most free space */
25282 + struct au_wbr_mfs si_wbr_mfs;
25284 + /* mount flags */
25285 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
25286 + unsigned int si_mntflags;
25288 + /* external inode number (bitmap and translation table) */
25289 + au_readf_t si_xread;
25290 + au_writef_t si_xwrite;
25291 + struct file *si_xib;
25292 + struct mutex si_xib_mtx; /* protect xib members */
25293 + unsigned long *si_xib_buf;
25294 + unsigned long si_xib_last_pindex;
25295 + int si_xib_next_bit;
25296 + aufs_bindex_t si_xino_brid;
25297 + /* reserved for future use */
25298 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
25300 +#ifdef CONFIG_AUFS_EXPORT
25301 + /* i_generation */
25302 + struct file *si_xigen;
25303 + atomic_t si_xigen_next;
25306 + /* vdir parameters */
25307 + unsigned long si_rdcache; /* max cache time in jiffies */
25308 + unsigned int si_rdblk; /* deblk size */
25309 + unsigned int si_rdhash; /* hash size */
25312 + * If the number of whiteouts are larger than si_dirwh, leave all of
25313 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
25314 + * future fsck.aufs or kernel thread will remove them later.
25315 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
25317 + unsigned int si_dirwh;
25320 + * rename(2) a directory with all children.
25322 + /* reserved for future use */
25323 + /* int si_rendir; */
25325 + /* pseudo_link list */
25326 + struct au_sphlhead si_plink[AuPlink_NHASH];
25327 + wait_queue_head_t si_plink_wq;
25328 + spinlock_t si_plink_maint_lock;
25329 + pid_t si_plink_maint_pid;
25332 + * sysfs and lifetime management.
25333 + * this is not a small structure and it may be a waste of memory in case
25334 + * of sysfs is disabled, particulary when many aufs-es are mounted.
25335 + * but using sysfs is majority.
25337 + struct kobject si_kobj;
25338 +#ifdef CONFIG_DEBUG_FS
25339 + struct dentry *si_dbgaufs;
25340 + struct dentry *si_dbgaufs_plink;
25341 + struct dentry *si_dbgaufs_xib;
25342 +#ifdef CONFIG_AUFS_EXPORT
25343 + struct dentry *si_dbgaufs_xigen;
25347 +#ifdef CONFIG_AUFS_SBILIST
25348 + struct list_head si_list;
25351 + /* dirty, necessary for unmounting, sysfs and sysrq */
25352 + struct super_block *si_sb;
25355 +/* sbinfo status flags */
25357 + * set true when refresh_dirs() failed at remount time.
25358 + * then try refreshing dirs at access time again.
25359 + * if it is false, refreshing dirs at access time is unnecesary
25361 +#define AuSi_FAILED_REFRESH_DIR 1
25362 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
25363 + unsigned int flag)
25365 + AuRwMustAnyLock(&sbi->si_rwsem);
25366 + return sbi->au_si_status & flag;
25368 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
25369 +#define au_fset_si(sbinfo, name) do { \
25370 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
25371 + (sbinfo)->au_si_status |= AuSi_##name; \
25373 +#define au_fclr_si(sbinfo, name) do { \
25374 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
25375 + (sbinfo)->au_si_status &= ~AuSi_##name; \
25378 +/* ---------------------------------------------------------------------- */
25380 +/* policy to select one among writable branches */
25381 +#define AuWbrCopyup(sbinfo, ...) \
25382 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
25383 +#define AuWbrCreate(sbinfo, ...) \
25384 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
25386 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
25387 +#define AuLock_DW 1 /* write-lock dentry */
25388 +#define AuLock_IR (1 << 1) /* read-lock inode */
25389 +#define AuLock_IW (1 << 2) /* write-lock inode */
25390 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
25391 +#define AuLock_DIR (1 << 4) /* target is a dir */
25392 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
25393 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
25394 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
25395 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
25396 +#define au_fset_lock(flags, name) \
25397 + do { (flags) |= AuLock_##name; } while (0)
25398 +#define au_fclr_lock(flags, name) \
25399 + do { (flags) &= ~AuLock_##name; } while (0)
25401 +/* ---------------------------------------------------------------------- */
25404 +extern struct file_system_type aufs_fs_type;
25405 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
25406 +typedef unsigned long long (*au_arraycb_t)(void *array, unsigned long long max,
25408 +void au_array_free(void *array);
25409 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg);
25410 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
25411 +void au_iarray_free(struct inode **a, unsigned long long max);
25414 +void au_si_free(struct kobject *kobj);
25415 +int au_si_alloc(struct super_block *sb);
25416 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr);
25418 +unsigned int au_sigen_inc(struct super_block *sb);
25419 +aufs_bindex_t au_new_br_id(struct super_block *sb);
25421 +int si_read_lock(struct super_block *sb, int flags);
25422 +int si_write_lock(struct super_block *sb, int flags);
25423 +int aufs_read_lock(struct dentry *dentry, int flags);
25424 +void aufs_read_unlock(struct dentry *dentry, int flags);
25425 +void aufs_write_lock(struct dentry *dentry);
25426 +void aufs_write_unlock(struct dentry *dentry);
25427 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
25428 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
25430 +int si_pid_test_slow(struct super_block *sb);
25431 +void si_pid_set_slow(struct super_block *sb);
25432 +void si_pid_clr_slow(struct super_block *sb);
25434 +/* wbr_policy.c */
25435 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
25436 +extern struct au_wbr_create_operations au_wbr_create_ops[];
25437 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
25438 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
25441 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
25443 +/* ---------------------------------------------------------------------- */
25445 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
25447 + return sb->s_fs_info;
25450 +/* ---------------------------------------------------------------------- */
25452 +#ifdef CONFIG_AUFS_EXPORT
25453 +int au_test_nfsd(void);
25454 +void au_export_init(struct super_block *sb);
25455 +void au_xigen_inc(struct inode *inode);
25456 +int au_xigen_new(struct inode *inode);
25457 +int au_xigen_set(struct super_block *sb, struct file *base);
25458 +void au_xigen_clr(struct super_block *sb);
25460 +static inline int au_busy_or_stale(void)
25462 + if (!au_test_nfsd())
25467 +AuStubInt0(au_test_nfsd, void)
25468 +AuStubVoid(au_export_init, struct super_block *sb)
25469 +AuStubVoid(au_xigen_inc, struct inode *inode)
25470 +AuStubInt0(au_xigen_new, struct inode *inode)
25471 +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base)
25472 +AuStubVoid(au_xigen_clr, struct super_block *sb)
25473 +static inline int au_busy_or_stale(void)
25477 +#endif /* CONFIG_AUFS_EXPORT */
25479 +/* ---------------------------------------------------------------------- */
25481 +#ifdef CONFIG_AUFS_SBILIST
25483 +extern struct au_splhead au_sbilist;
25485 +static inline void au_sbilist_init(void)
25487 + au_spl_init(&au_sbilist);
25490 +static inline void au_sbilist_add(struct super_block *sb)
25492 + au_spl_add(&au_sbi(sb)->si_list, &au_sbilist);
25495 +static inline void au_sbilist_del(struct super_block *sb)
25497 + au_spl_del(&au_sbi(sb)->si_list, &au_sbilist);
25500 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
25501 +static inline void au_sbilist_lock(void)
25503 + spin_lock(&au_sbilist.spin);
25506 +static inline void au_sbilist_unlock(void)
25508 + spin_unlock(&au_sbilist.spin);
25510 +#define AuGFP_SBILIST GFP_ATOMIC
25512 +AuStubVoid(au_sbilist_lock, void)
25513 +AuStubVoid(au_sbilist_unlock, void)
25514 +#define AuGFP_SBILIST GFP_NOFS
25515 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
25517 +AuStubVoid(au_sbilist_init, void)
25518 +AuStubVoid(au_sbilist_add, struct super_block*)
25519 +AuStubVoid(au_sbilist_del, struct super_block*)
25520 +AuStubVoid(au_sbilist_lock, void)
25521 +AuStubVoid(au_sbilist_unlock, void)
25522 +#define AuGFP_SBILIST GFP_NOFS
25525 +/* ---------------------------------------------------------------------- */
25527 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
25530 + * This function is a dynamic '__init' fucntion actually,
25531 + * so the tiny check for si_rwsem is unnecessary.
25533 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
25534 +#ifdef CONFIG_DEBUG_FS
25535 + sbinfo->si_dbgaufs = NULL;
25536 + sbinfo->si_dbgaufs_plink = NULL;
25537 + sbinfo->si_dbgaufs_xib = NULL;
25538 +#ifdef CONFIG_AUFS_EXPORT
25539 + sbinfo->si_dbgaufs_xigen = NULL;
25544 +/* ---------------------------------------------------------------------- */
25546 +static inline pid_t si_pid_bit(void)
25548 + /* the origin of pid is 1, but the bitmap's is 0 */
25549 + return current->pid - 1;
25552 +static inline int si_pid_test(struct super_block *sb)
25554 + pid_t bit = si_pid_bit();
25555 + if (bit < PID_MAX_DEFAULT)
25556 + return test_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
25558 + return si_pid_test_slow(sb);
25561 +static inline void si_pid_set(struct super_block *sb)
25563 + pid_t bit = si_pid_bit();
25564 + if (bit < PID_MAX_DEFAULT) {
25565 + AuDebugOn(test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
25566 + set_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
25569 + si_pid_set_slow(sb);
25572 +static inline void si_pid_clr(struct super_block *sb)
25574 + pid_t bit = si_pid_bit();
25575 + if (bit < PID_MAX_DEFAULT) {
25576 + AuDebugOn(!test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
25577 + clear_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
25580 + si_pid_clr_slow(sb);
25583 +/* ---------------------------------------------------------------------- */
25585 +/* lock superblock. mainly for entry point functions */
25587 + * __si_read_lock, __si_write_lock,
25588 + * __si_read_unlock, __si_write_unlock, __si_downgrade_lock
25590 +AuSimpleRwsemFuncs(__si, struct super_block *sb, &au_sbi(sb)->si_rwsem);
25592 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
25593 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
25594 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
25596 +static inline void si_noflush_read_lock(struct super_block *sb)
25598 + __si_read_lock(sb);
25602 +static inline int si_noflush_read_trylock(struct super_block *sb)
25604 + int locked = __si_read_trylock(sb);
25610 +static inline void si_noflush_write_lock(struct super_block *sb)
25612 + __si_write_lock(sb);
25616 +static inline int si_noflush_write_trylock(struct super_block *sb)
25618 + int locked = __si_write_trylock(sb);
25624 +#if 0 /* unused */
25625 +static inline int si_read_trylock(struct super_block *sb, int flags)
25627 + if (au_ftest_lock(flags, FLUSH))
25628 + au_nwt_flush(&au_sbi(sb)->si_nowait);
25629 + return si_noflush_read_trylock(sb);
25633 +static inline void si_read_unlock(struct super_block *sb)
25636 + __si_read_unlock(sb);
25639 +#if 0 /* unused */
25640 +static inline int si_write_trylock(struct super_block *sb, int flags)
25642 + if (au_ftest_lock(flags, FLUSH))
25643 + au_nwt_flush(&au_sbi(sb)->si_nowait);
25644 + return si_noflush_write_trylock(sb);
25648 +static inline void si_write_unlock(struct super_block *sb)
25651 + __si_write_unlock(sb);
25654 +#if 0 /* unused */
25655 +static inline void si_downgrade_lock(struct super_block *sb)
25657 + __si_downgrade_lock(sb);
25661 +/* ---------------------------------------------------------------------- */
25663 +static inline aufs_bindex_t au_sbend(struct super_block *sb)
25665 + SiMustAnyLock(sb);
25666 + return au_sbi(sb)->si_bend;
25669 +static inline unsigned int au_mntflags(struct super_block *sb)
25671 + SiMustAnyLock(sb);
25672 + return au_sbi(sb)->si_mntflags;
25675 +static inline unsigned int au_sigen(struct super_block *sb)
25677 + SiMustAnyLock(sb);
25678 + return au_sbi(sb)->si_generation;
25681 +static inline void au_ninodes_inc(struct super_block *sb)
25683 + atomic_long_inc(&au_sbi(sb)->si_ninodes);
25686 +static inline void au_ninodes_dec(struct super_block *sb)
25688 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_ninodes));
25689 + atomic_long_dec(&au_sbi(sb)->si_ninodes);
25692 +static inline void au_nfiles_inc(struct super_block *sb)
25694 + atomic_long_inc(&au_sbi(sb)->si_nfiles);
25697 +static inline void au_nfiles_dec(struct super_block *sb)
25699 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_nfiles));
25700 + atomic_long_dec(&au_sbi(sb)->si_nfiles);
25703 +static inline struct au_branch *au_sbr(struct super_block *sb,
25704 + aufs_bindex_t bindex)
25706 + SiMustAnyLock(sb);
25707 + return au_sbi(sb)->si_branch[0 + bindex];
25710 +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid)
25712 + SiMustWriteLock(sb);
25713 + au_sbi(sb)->si_xino_brid = brid;
25716 +static inline aufs_bindex_t au_xino_brid(struct super_block *sb)
25718 + SiMustAnyLock(sb);
25719 + return au_sbi(sb)->si_xino_brid;
25722 +#endif /* __KERNEL__ */
25723 +#endif /* __AUFS_SUPER_H__ */
25724 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
25725 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
25726 +++ linux/fs/aufs/sysaufs.c 2013-07-06 13:20:47.753531903 +0200
25729 + * Copyright (C) 2005-2013 Junjiro R. Okajima
25731 + * This program, aufs is free software; you can redistribute it and/or modify
25732 + * it under the terms of the GNU General Public License as published by
25733 + * the Free Software Foundation; either version 2 of the License, or
25734 + * (at your option) any later version.
25736 + * This program is distributed in the hope that it will be useful,
25737 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25738 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25739 + * GNU General Public License for more details.
25741 + * You should have received a copy of the GNU General Public License
25742 + * along with this program; if not, write to the Free Software
25743 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25747 + * sysfs interface and lifetime management
25748 + * they are necessary regardless sysfs is disabled.
25751 +#include <linux/random.h>
25754 +unsigned long sysaufs_si_mask;
25755 +struct kset *sysaufs_kset;
25757 +#define AuSiAttr(_name) { \
25758 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
25759 + .show = sysaufs_si_##_name, \
25762 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
25763 +struct attribute *sysaufs_si_attrs[] = {
25764 + &sysaufs_si_attr_xi_path.attr,
25768 +static const struct sysfs_ops au_sbi_ops = {
25769 + .show = sysaufs_si_show
25772 +static struct kobj_type au_sbi_ktype = {
25773 + .release = au_si_free,
25774 + .sysfs_ops = &au_sbi_ops,
25775 + .default_attrs = sysaufs_si_attrs
25778 +/* ---------------------------------------------------------------------- */
25780 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
25784 + sbinfo->si_kobj.kset = sysaufs_kset;
25785 + /* cf. sysaufs_name() */
25786 + err = kobject_init_and_add
25787 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
25788 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
25790 + dbgaufs_si_null(sbinfo);
25792 + err = dbgaufs_si_init(sbinfo);
25793 + if (unlikely(err))
25794 + kobject_put(&sbinfo->si_kobj);
25799 +void sysaufs_fin(void)
25802 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
25803 + kset_unregister(sysaufs_kset);
25806 +int __init sysaufs_init(void)
25811 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
25812 + } while (!sysaufs_si_mask);
25815 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
25816 + if (unlikely(!sysaufs_kset))
25818 + err = PTR_ERR(sysaufs_kset);
25819 + if (IS_ERR(sysaufs_kset))
25821 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
25822 + if (unlikely(err)) {
25823 + kset_unregister(sysaufs_kset);
25827 + err = dbgaufs_init();
25828 + if (unlikely(err))
25833 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
25834 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
25835 +++ linux/fs/aufs/sysaufs.h 2013-07-06 13:20:47.753531903 +0200
25838 + * Copyright (C) 2005-2013 Junjiro R. Okajima
25840 + * This program, aufs is free software; you can redistribute it and/or modify
25841 + * it under the terms of the GNU General Public License as published by
25842 + * the Free Software Foundation; either version 2 of the License, or
25843 + * (at your option) any later version.
25845 + * This program is distributed in the hope that it will be useful,
25846 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25847 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25848 + * GNU General Public License for more details.
25850 + * You should have received a copy of the GNU General Public License
25851 + * along with this program; if not, write to the Free Software
25852 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25856 + * sysfs interface and mount lifetime management
25859 +#ifndef __SYSAUFS_H__
25860 +#define __SYSAUFS_H__
25864 +#include <linux/sysfs.h>
25865 +#include "module.h"
25867 +struct super_block;
25870 +struct sysaufs_si_attr {
25871 + struct attribute attr;
25872 + int (*show)(struct seq_file *seq, struct super_block *sb);
25875 +/* ---------------------------------------------------------------------- */
25878 +extern unsigned long sysaufs_si_mask;
25879 +extern struct kset *sysaufs_kset;
25880 +extern struct attribute *sysaufs_si_attrs[];
25881 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
25882 +int __init sysaufs_init(void);
25883 +void sysaufs_fin(void);
25885 +/* ---------------------------------------------------------------------- */
25887 +/* some people doesn't like to show a pointer in kernel */
25888 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
25890 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
25893 +#define SysaufsSiNamePrefix "si_"
25894 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
25895 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
25897 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
25898 + sysaufs_si_id(sbinfo));
25902 +#ifdef CONFIG_SYSFS
25904 +extern struct attribute_group *sysaufs_attr_group;
25906 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
25907 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
25910 +void sysaufs_br_init(struct au_branch *br);
25911 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
25912 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
25914 +#define sysaufs_brs_init() do {} while (0)
25917 +#define sysaufs_attr_group NULL
25919 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
25922 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
25928 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
25929 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
25930 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
25932 +static inline void sysaufs_brs_init(void)
25937 +#endif /* CONFIG_SYSFS */
25939 +#endif /* __KERNEL__ */
25940 +#endif /* __SYSAUFS_H__ */
25941 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
25942 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
25943 +++ linux/fs/aufs/sysfs.c 2013-07-06 13:20:47.753531903 +0200
25946 + * Copyright (C) 2005-2013 Junjiro R. Okajima
25948 + * This program, aufs is free software; you can redistribute it and/or modify
25949 + * it under the terms of the GNU General Public License as published by
25950 + * the Free Software Foundation; either version 2 of the License, or
25951 + * (at your option) any later version.
25953 + * This program is distributed in the hope that it will be useful,
25954 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25955 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25956 + * GNU General Public License for more details.
25958 + * You should have received a copy of the GNU General Public License
25959 + * along with this program; if not, write to the Free Software
25960 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25964 + * sysfs interface
25967 +#include <linux/seq_file.h>
25970 +#ifdef CONFIG_AUFS_FS_MODULE
25971 +/* this entry violates the "one line per file" policy of sysfs */
25972 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
25976 + static char *conf =
25977 +/* this file is generated at compiling */
25978 +#include "conf.str"
25981 + err = snprintf(buf, PAGE_SIZE, conf);
25982 + if (unlikely(err >= PAGE_SIZE))
25987 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
25990 +static struct attribute *au_attr[] = {
25991 +#ifdef CONFIG_AUFS_FS_MODULE
25992 + &au_config_attr.attr,
25994 + NULL, /* need to NULL terminate the list of attributes */
25997 +static struct attribute_group sysaufs_attr_group_body = {
26001 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
26003 +/* ---------------------------------------------------------------------- */
26005 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
26009 + SiMustAnyLock(sb);
26012 + if (au_opt_test(au_mntflags(sb), XINO)) {
26013 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
26014 + seq_putc(seq, '\n');
26020 + * the lifetime of branch is independent from the entry under sysfs.
26021 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
26024 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
26025 + aufs_bindex_t bindex)
26028 + struct path path;
26029 + struct dentry *root;
26030 + struct au_branch *br;
26033 + AuDbg("b%d\n", bindex);
26036 + root = sb->s_root;
26037 + di_read_lock_parent(root, !AuLock_IR);
26038 + br = au_sbr(sb, bindex);
26039 + path.mnt = au_br_mnt(br);
26040 + path.dentry = au_h_dptr(root, bindex);
26041 + au_seq_path(seq, &path);
26042 + di_read_unlock(root, !AuLock_IR);
26043 + perm = au_optstr_br_perm(br->br_perm);
26045 + err = seq_printf(seq, "=%s\n", perm);
26054 +/* ---------------------------------------------------------------------- */
26056 +static struct seq_file *au_seq(char *p, ssize_t len)
26058 + struct seq_file *seq;
26060 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
26062 + /* mutex_init(&seq.lock); */
26065 + return seq; /* success */
26068 + seq = ERR_PTR(-ENOMEM);
26072 +#define SysaufsBr_PREFIX "br"
26074 +/* todo: file size may exceed PAGE_SIZE */
26075 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
26080 + aufs_bindex_t bend;
26081 + struct au_sbinfo *sbinfo;
26082 + struct super_block *sb;
26083 + struct seq_file *seq;
26085 + struct attribute **cattr;
26087 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
26088 + sb = sbinfo->si_sb;
26091 + * prevent a race condition between sysfs and aufs.
26092 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
26093 + * prohibits maintaining the sysfs entries.
26094 + * hew we acquire read lock after sysfs_get_active_two().
26095 + * on the other hand, the remount process may maintain the sysfs/aufs
26096 + * entries after acquiring write lock.
26097 + * it can cause a deadlock.
26098 + * simply we gave up processing read here.
26101 + if (unlikely(!si_noflush_read_trylock(sb)))
26104 + seq = au_seq(buf, PAGE_SIZE);
26105 + err = PTR_ERR(seq);
26109 + name = (void *)attr->name;
26110 + cattr = sysaufs_si_attrs;
26112 + if (!strcmp(name, (*cattr)->name)) {
26113 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
26120 + bend = au_sbend(sb);
26121 + if (!strncmp(name, SysaufsBr_PREFIX, sizeof(SysaufsBr_PREFIX) - 1)) {
26122 + name += sizeof(SysaufsBr_PREFIX) - 1;
26123 + err = kstrtol(name, 10, &l);
26126 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l);
26136 + err = seq->count;
26137 + /* sysfs limit */
26138 + if (unlikely(err == PAGE_SIZE))
26143 + si_read_unlock(sb);
26148 +/* ---------------------------------------------------------------------- */
26150 +void sysaufs_br_init(struct au_branch *br)
26152 + struct attribute *attr = &br->br_attr;
26154 + sysfs_attr_init(attr);
26155 + attr->name = br->br_name;
26156 + attr->mode = S_IRUGO;
26159 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
26161 + struct au_branch *br;
26162 + struct kobject *kobj;
26163 + aufs_bindex_t bend;
26165 + dbgaufs_brs_del(sb, bindex);
26167 + if (!sysaufs_brs)
26170 + kobj = &au_sbi(sb)->si_kobj;
26171 + bend = au_sbend(sb);
26172 + for (; bindex <= bend; bindex++) {
26173 + br = au_sbr(sb, bindex);
26174 + sysfs_remove_file(kobj, &br->br_attr);
26178 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
26181 + aufs_bindex_t bend;
26182 + struct kobject *kobj;
26183 + struct au_branch *br;
26185 + dbgaufs_brs_add(sb, bindex);
26187 + if (!sysaufs_brs)
26190 + kobj = &au_sbi(sb)->si_kobj;
26191 + bend = au_sbend(sb);
26192 + for (; bindex <= bend; bindex++) {
26193 + br = au_sbr(sb, bindex);
26194 + snprintf(br->br_name, sizeof(br->br_name), SysaufsBr_PREFIX
26196 + err = sysfs_create_file(kobj, &br->br_attr);
26197 + if (unlikely(err))
26198 + pr_warn("failed %s under sysfs(%d)\n",
26199 + br->br_name, err);
26202 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
26203 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
26204 +++ linux/fs/aufs/sysrq.c 2013-07-06 13:20:47.753531903 +0200
26207 + * Copyright (C) 2005-2013 Junjiro R. Okajima
26209 + * This program, aufs is free software; you can redistribute it and/or modify
26210 + * it under the terms of the GNU General Public License as published by
26211 + * the Free Software Foundation; either version 2 of the License, or
26212 + * (at your option) any later version.
26214 + * This program is distributed in the hope that it will be useful,
26215 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26216 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26217 + * GNU General Public License for more details.
26219 + * You should have received a copy of the GNU General Public License
26220 + * along with this program; if not, write to the Free Software
26221 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26225 + * magic sysrq hanlder
26228 +/* #include <linux/sysrq.h> */
26229 +#include <linux/writeback.h>
26232 +/* ---------------------------------------------------------------------- */
26234 +static void sysrq_sb(struct super_block *sb)
26237 + struct au_sbinfo *sbinfo;
26238 + struct file *file;
26240 + plevel = au_plevel;
26241 + au_plevel = KERN_WARNING;
26243 + /* since we define pr_fmt, call printk directly */
26244 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
26246 + sbinfo = au_sbi(sb);
26247 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
26248 + pr("superblock\n");
26252 + pr("root dentry\n");
26253 + au_dpri_dentry(sb->s_root);
26254 + pr("root inode\n");
26255 + au_dpri_inode(sb->s_root->d_inode);
26260 + int err, i, j, ndentry;
26261 + struct au_dcsub_pages dpages;
26262 + struct au_dpage *dpage;
26264 + err = au_dpages_init(&dpages, GFP_ATOMIC);
26265 + if (unlikely(err))
26267 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
26269 + for (i = 0; i < dpages.ndpage; i++) {
26270 + dpage = dpages.dpages + i;
26271 + ndentry = dpage->ndentry;
26272 + for (j = 0; j < ndentry; j++)
26273 + au_dpri_dentry(dpage->dentries[j]);
26275 + au_dpages_free(&dpages);
26282 + pr("isolated inode\n");
26283 + spin_lock(&inode_sb_list_lock);
26284 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
26285 + spin_lock(&i->i_lock);
26286 + if (1 || hlist_empty(&i->i_dentry))
26287 + au_dpri_inode(i);
26288 + spin_unlock(&i->i_lock);
26290 + spin_unlock(&inode_sb_list_lock);
26294 + lg_global_lock(&files_lglock);
26295 + do_file_list_for_each_entry(sb, file) {
26297 + mode = file_inode(file)->i_mode;
26298 + if (!special_file(mode) || au_special_file(mode))
26299 + au_dpri_file(file);
26300 + } while_file_list_for_each_entry;
26301 + lg_global_unlock(&files_lglock);
26305 + au_plevel = plevel;
26308 +/* ---------------------------------------------------------------------- */
26310 +/* module parameter */
26311 +static char *aufs_sysrq_key = "a";
26312 +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO);
26313 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
26315 +static void au_sysrq(int key __maybe_unused)
26317 + struct au_sbinfo *sbinfo;
26320 + au_sbilist_lock();
26321 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
26322 + sysrq_sb(sbinfo->si_sb);
26323 + au_sbilist_unlock();
26327 +static struct sysrq_key_op au_sysrq_op = {
26328 + .handler = au_sysrq,
26329 + .help_msg = "Aufs",
26330 + .action_msg = "Aufs",
26331 + .enable_mask = SYSRQ_ENABLE_DUMP
26334 +/* ---------------------------------------------------------------------- */
26336 +int __init au_sysrq_init(void)
26342 + key = *aufs_sysrq_key;
26343 + if ('a' <= key && key <= 'z')
26344 + err = register_sysrq_key(key, &au_sysrq_op);
26345 + if (unlikely(err))
26346 + pr_err("err %d, sysrq=%c\n", err, key);
26350 +void au_sysrq_fin(void)
26353 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
26354 + if (unlikely(err))
26355 + pr_err("err %d (ignored)\n", err);
26357 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
26358 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
26359 +++ linux/fs/aufs/vdir.c 2013-07-30 22:42:55.842946719 +0200
26362 + * Copyright (C) 2005-2013 Junjiro R. Okajima
26364 + * This program, aufs is free software; you can redistribute it and/or modify
26365 + * it under the terms of the GNU General Public License as published by
26366 + * the Free Software Foundation; either version 2 of the License, or
26367 + * (at your option) any later version.
26369 + * This program is distributed in the hope that it will be useful,
26370 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26371 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26372 + * GNU General Public License for more details.
26374 + * You should have received a copy of the GNU General Public License
26375 + * along with this program; if not, write to the Free Software
26376 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26380 + * virtual or vertical directory
26385 +static unsigned int calc_size(int nlen)
26387 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
26390 +static int set_deblk_end(union au_vdir_deblk_p *p,
26391 + union au_vdir_deblk_p *deblk_end)
26393 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
26394 + p->de->de_str.len = 0;
26398 + return -1; /* error */
26401 +/* returns true or false */
26402 +static int is_deblk_end(union au_vdir_deblk_p *p,
26403 + union au_vdir_deblk_p *deblk_end)
26405 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
26406 + return !p->de->de_str.len;
26410 +static unsigned char *last_deblk(struct au_vdir *vdir)
26412 + return vdir->vd_deblk[vdir->vd_nblk - 1];
26415 +/* ---------------------------------------------------------------------- */
26417 +/* estimate the apropriate size for name hash table */
26418 +unsigned int au_rdhash_est(loff_t sz)
26426 + if (sz < AUFS_RDHASH_DEF)
26427 + n = AUFS_RDHASH_DEF;
26428 + /* pr_info("n %u\n", n); */
26433 + * the allocated memory has to be freed by
26434 + * au_nhash_wh_free() or au_nhash_de_free().
26436 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
26438 + struct hlist_head *head;
26441 + head = kmalloc(sizeof(*nhash->nh_head) * num_hash, gfp);
26443 + nhash->nh_num = num_hash;
26444 + nhash->nh_head = head;
26445 + for (u = 0; u < num_hash; u++)
26446 + INIT_HLIST_HEAD(head++);
26447 + return 0; /* success */
26453 +static void nhash_count(struct hlist_head *head)
26457 + struct hlist_node *pos;
26460 + hlist_for_each(pos, head)
26462 + pr_info("%lu\n", n);
26466 +static void au_nhash_wh_do_free(struct hlist_head *head)
26468 + struct au_vdir_wh *pos;
26469 + struct hlist_node *node;
26471 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
26475 +static void au_nhash_de_do_free(struct hlist_head *head)
26477 + struct au_vdir_dehstr *pos;
26478 + struct hlist_node *node;
26480 + hlist_for_each_entry_safe(pos, node, head, hash)
26481 + au_cache_free_vdir_dehstr(pos);
26484 +static void au_nhash_do_free(struct au_nhash *nhash,
26485 + void (*free)(struct hlist_head *head))
26488 + struct hlist_head *head;
26490 + n = nhash->nh_num;
26494 + head = nhash->nh_head;
26495 + while (n-- > 0) {
26496 + nhash_count(head);
26499 + kfree(nhash->nh_head);
26502 +void au_nhash_wh_free(struct au_nhash *whlist)
26504 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
26507 +static void au_nhash_de_free(struct au_nhash *delist)
26509 + au_nhash_do_free(delist, au_nhash_de_do_free);
26512 +/* ---------------------------------------------------------------------- */
26514 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
26518 + unsigned int u, n;
26519 + struct hlist_head *head;
26520 + struct au_vdir_wh *pos;
26523 + n = whlist->nh_num;
26524 + head = whlist->nh_head;
26525 + for (u = 0; u < n; u++, head++)
26526 + hlist_for_each_entry(pos, head, wh_hash)
26527 + if (pos->wh_bindex == btgt && ++num > limit)
26532 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
26533 + unsigned char *name,
26534 + unsigned int len)
26537 + /* const unsigned int magic_bit = 12; */
26539 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
26544 + /* v = hash_long(v, magic_bit); */
26545 + v %= nhash->nh_num;
26546 + return nhash->nh_head + v;
26549 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
26552 + return str->len == nlen && !memcmp(str->name, name, nlen);
26555 +/* returns found or not */
26556 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
26558 + struct hlist_head *head;
26559 + struct au_vdir_wh *pos;
26560 + struct au_vdir_destr *str;
26562 + head = au_name_hash(whlist, name, nlen);
26563 + hlist_for_each_entry(pos, head, wh_hash) {
26564 + str = &pos->wh_str;
26565 + AuDbg("%.*s\n", str->len, str->name);
26566 + if (au_nhash_test_name(str, name, nlen))
26572 +/* returns found(true) or not */
26573 +static int test_known(struct au_nhash *delist, char *name, int nlen)
26575 + struct hlist_head *head;
26576 + struct au_vdir_dehstr *pos;
26577 + struct au_vdir_destr *str;
26579 + head = au_name_hash(delist, name, nlen);
26580 + hlist_for_each_entry(pos, head, hash) {
26582 + AuDbg("%.*s\n", str->len, str->name);
26583 + if (au_nhash_test_name(str, name, nlen))
26589 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
26590 + unsigned char d_type)
26592 +#ifdef CONFIG_AUFS_SHWH
26593 + wh->wh_ino = ino;
26594 + wh->wh_type = d_type;
26598 +/* ---------------------------------------------------------------------- */
26600 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
26601 + unsigned int d_type, aufs_bindex_t bindex,
26602 + unsigned char shwh)
26605 + struct au_vdir_destr *str;
26606 + struct au_vdir_wh *wh;
26608 + AuDbg("%.*s\n", nlen, name);
26609 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
26612 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
26613 + if (unlikely(!wh))
26617 + wh->wh_bindex = bindex;
26619 + au_shwh_init_wh(wh, ino, d_type);
26620 + str = &wh->wh_str;
26622 + memcpy(str->name, name, nlen);
26623 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
26630 +static int append_deblk(struct au_vdir *vdir)
26633 + unsigned long ul;
26634 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
26635 + union au_vdir_deblk_p p, deblk_end;
26636 + unsigned char **o;
26639 + o = krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
26641 + if (unlikely(!o))
26644 + vdir->vd_deblk = o;
26645 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
26647 + ul = vdir->vd_nblk++;
26648 + vdir->vd_deblk[ul] = p.deblk;
26649 + vdir->vd_last.ul = ul;
26650 + vdir->vd_last.p.deblk = p.deblk;
26651 + deblk_end.deblk = p.deblk + deblk_sz;
26652 + err = set_deblk_end(&p, &deblk_end);
26659 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
26660 + unsigned int d_type, struct au_nhash *delist)
26664 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
26665 + union au_vdir_deblk_p p, *room, deblk_end;
26666 + struct au_vdir_dehstr *dehstr;
26668 + p.deblk = last_deblk(vdir);
26669 + deblk_end.deblk = p.deblk + deblk_sz;
26670 + room = &vdir->vd_last.p;
26671 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
26672 + || !is_deblk_end(room, &deblk_end));
26674 + sz = calc_size(nlen);
26675 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
26676 + err = append_deblk(vdir);
26677 + if (unlikely(err))
26680 + p.deblk = last_deblk(vdir);
26681 + deblk_end.deblk = p.deblk + deblk_sz;
26683 + AuDebugOn(room->deblk != p.deblk);
26687 + dehstr = au_cache_alloc_vdir_dehstr();
26688 + if (unlikely(!dehstr))
26691 + dehstr->str = &room->de->de_str;
26692 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
26693 + room->de->de_ino = ino;
26694 + room->de->de_type = d_type;
26695 + room->de->de_str.len = nlen;
26696 + memcpy(room->de->de_str.name, name, nlen);
26699 + room->deblk += sz;
26700 + if (unlikely(set_deblk_end(room, &deblk_end)))
26701 + err = append_deblk(vdir);
26708 +/* ---------------------------------------------------------------------- */
26710 +void au_vdir_free(struct au_vdir *vdir)
26712 + unsigned char **deblk;
26714 + deblk = vdir->vd_deblk;
26715 + while (vdir->vd_nblk--)
26717 + kfree(vdir->vd_deblk);
26718 + au_cache_free_vdir(vdir);
26721 +static struct au_vdir *alloc_vdir(struct file *file)
26723 + struct au_vdir *vdir;
26724 + struct super_block *sb;
26727 + sb = file->f_dentry->d_sb;
26728 + SiMustAnyLock(sb);
26731 + vdir = au_cache_alloc_vdir();
26732 + if (unlikely(!vdir))
26735 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
26736 + if (unlikely(!vdir->vd_deblk))
26739 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
26740 + if (!vdir->vd_deblk_sz) {
26741 + /* estimate the apropriate size for deblk */
26742 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
26743 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
26745 + vdir->vd_nblk = 0;
26746 + vdir->vd_version = 0;
26747 + vdir->vd_jiffy = 0;
26748 + err = append_deblk(vdir);
26750 + return vdir; /* success */
26752 + kfree(vdir->vd_deblk);
26755 + au_cache_free_vdir(vdir);
26757 + vdir = ERR_PTR(err);
26761 +static int reinit_vdir(struct au_vdir *vdir)
26764 + union au_vdir_deblk_p p, deblk_end;
26766 + while (vdir->vd_nblk > 1) {
26767 + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
26768 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
26771 + p.deblk = vdir->vd_deblk[0];
26772 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
26773 + err = set_deblk_end(&p, &deblk_end);
26774 + /* keep vd_dblk_sz */
26775 + vdir->vd_last.ul = 0;
26776 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
26777 + vdir->vd_version = 0;
26778 + vdir->vd_jiffy = 0;
26783 +/* ---------------------------------------------------------------------- */
26785 +#define AuFillVdir_CALLED 1
26786 +#define AuFillVdir_WHABLE (1 << 1)
26787 +#define AuFillVdir_SHWH (1 << 2)
26788 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
26789 +#define au_fset_fillvdir(flags, name) \
26790 + do { (flags) |= AuFillVdir_##name; } while (0)
26791 +#define au_fclr_fillvdir(flags, name) \
26792 + do { (flags) &= ~AuFillVdir_##name; } while (0)
26794 +#ifndef CONFIG_AUFS_SHWH
26795 +#undef AuFillVdir_SHWH
26796 +#define AuFillVdir_SHWH 0
26799 +struct fillvdir_arg {
26800 + struct file *file;
26801 + struct au_vdir *vdir;
26802 + struct au_nhash delist;
26803 + struct au_nhash whlist;
26804 + aufs_bindex_t bindex;
26805 + unsigned int flags;
26809 +static int fillvdir(void *__arg, const char *__name, int nlen,
26810 + loff_t offset __maybe_unused, u64 h_ino,
26811 + unsigned int d_type)
26813 + struct fillvdir_arg *arg = __arg;
26814 + char *name = (void *)__name;
26815 + struct super_block *sb;
26817 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
26820 + sb = arg->file->f_dentry->d_sb;
26821 + au_fset_fillvdir(arg->flags, CALLED);
26823 + if (nlen <= AUFS_WH_PFX_LEN
26824 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
26825 + if (test_known(&arg->delist, name, nlen)
26826 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
26827 + goto out; /* already exists or whiteouted */
26829 + sb = arg->file->f_dentry->d_sb;
26830 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
26832 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
26833 + d_type = DT_UNKNOWN;
26834 + arg->err = append_de(arg->vdir, name, nlen, ino,
26835 + d_type, &arg->delist);
26837 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
26838 + name += AUFS_WH_PFX_LEN;
26839 + nlen -= AUFS_WH_PFX_LEN;
26840 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
26841 + goto out; /* already whiteouted */
26844 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
26847 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
26848 + d_type = DT_UNKNOWN;
26849 + arg->err = au_nhash_append_wh
26850 + (&arg->whlist, name, nlen, ino, d_type,
26851 + arg->bindex, shwh);
26857 + arg->vdir->vd_jiffy = jiffies;
26859 + AuTraceErr(arg->err);
26863 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
26864 + struct au_nhash *whlist, struct au_nhash *delist)
26866 +#ifdef CONFIG_AUFS_SHWH
26868 + unsigned int nh, u;
26869 + struct hlist_head *head;
26870 + struct au_vdir_wh *pos;
26871 + struct hlist_node *n;
26873 + struct au_vdir_destr *destr;
26875 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
26878 + o = p = (void *)__get_free_page(GFP_NOFS);
26879 + if (unlikely(!p))
26883 + nh = whlist->nh_num;
26884 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
26885 + p += AUFS_WH_PFX_LEN;
26886 + for (u = 0; u < nh; u++) {
26887 + head = whlist->nh_head + u;
26888 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
26889 + destr = &pos->wh_str;
26890 + memcpy(p, destr->name, destr->len);
26891 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
26892 + pos->wh_ino, pos->wh_type, delist);
26893 + if (unlikely(err))
26898 + free_page((unsigned long)o);
26908 +static int au_do_read_vdir(struct fillvdir_arg *arg)
26911 + unsigned int rdhash;
26913 + aufs_bindex_t bend, bindex, bstart;
26914 + unsigned char shwh;
26915 + struct file *hf, *file;
26916 + struct super_block *sb;
26918 + file = arg->file;
26919 + sb = file->f_dentry->d_sb;
26920 + SiMustAnyLock(sb);
26922 + rdhash = au_sbi(sb)->si_rdhash;
26924 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
26925 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
26926 + if (unlikely(err))
26928 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
26929 + if (unlikely(err))
26935 + if (au_opt_test(au_mntflags(sb), SHWH)) {
26937 + au_fset_fillvdir(arg->flags, SHWH);
26939 + bstart = au_fbstart(file);
26940 + bend = au_fbend_dir(file);
26941 + for (bindex = bstart; !err && bindex <= bend; bindex++) {
26942 + hf = au_hf_dir(file, bindex);
26946 + offset = vfsub_llseek(hf, 0, SEEK_SET);
26948 + if (unlikely(offset))
26951 + arg->bindex = bindex;
26952 + au_fclr_fillvdir(arg->flags, WHABLE);
26954 + || (bindex != bend
26955 + && au_br_whable(au_sbr_perm(sb, bindex))))
26956 + au_fset_fillvdir(arg->flags, WHABLE);
26959 + au_fclr_fillvdir(arg->flags, CALLED);
26961 + err = vfsub_readdir(hf, fillvdir, arg);
26964 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
26967 + if (!err && shwh)
26968 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
26970 + au_nhash_wh_free(&arg->whlist);
26973 + au_nhash_de_free(&arg->delist);
26978 +static int read_vdir(struct file *file, int may_read)
26981 + unsigned long expire;
26982 + unsigned char do_read;
26983 + struct fillvdir_arg arg;
26984 + struct inode *inode;
26985 + struct au_vdir *vdir, *allocated;
26988 + inode = file_inode(file);
26989 + IMustLock(inode);
26990 + SiMustAnyLock(inode->i_sb);
26992 + allocated = NULL;
26994 + expire = au_sbi(inode->i_sb)->si_rdcache;
26995 + vdir = au_ivdir(inode);
26998 + vdir = alloc_vdir(file);
26999 + err = PTR_ERR(vdir);
27000 + if (IS_ERR(vdir))
27003 + allocated = vdir;
27004 + } else if (may_read
27005 + && (inode->i_version != vdir->vd_version
27006 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
27008 + err = reinit_vdir(vdir);
27009 + if (unlikely(err))
27014 + return 0; /* success */
27018 + err = au_do_read_vdir(&arg);
27020 + /* file->f_pos = 0; */
27021 + vdir->vd_version = inode->i_version;
27022 + vdir->vd_last.ul = 0;
27023 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
27025 + au_set_ivdir(inode, allocated);
27026 + } else if (allocated)
27027 + au_vdir_free(allocated);
27033 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
27036 + unsigned long ul, n;
27037 + const unsigned int deblk_sz = src->vd_deblk_sz;
27039 + AuDebugOn(tgt->vd_nblk != 1);
27042 + if (tgt->vd_nblk < src->vd_nblk) {
27043 + unsigned char **p;
27045 + p = krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
27047 + if (unlikely(!p))
27049 + tgt->vd_deblk = p;
27052 + if (tgt->vd_deblk_sz != deblk_sz) {
27053 + unsigned char *p;
27055 + tgt->vd_deblk_sz = deblk_sz;
27056 + p = krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS);
27057 + if (unlikely(!p))
27059 + tgt->vd_deblk[0] = p;
27061 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
27062 + tgt->vd_version = src->vd_version;
27063 + tgt->vd_jiffy = src->vd_jiffy;
27065 + n = src->vd_nblk;
27066 + for (ul = 1; ul < n; ul++) {
27067 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
27069 + if (unlikely(!tgt->vd_deblk[ul]))
27073 + tgt->vd_nblk = n;
27074 + tgt->vd_last.ul = tgt->vd_last.ul;
27075 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
27076 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
27077 + - src->vd_deblk[src->vd_last.ul];
27079 + return 0; /* success */
27082 + rerr = reinit_vdir(tgt);
27087 +int au_vdir_init(struct file *file)
27090 + struct inode *inode;
27091 + struct au_vdir *vdir_cache, *allocated;
27093 + err = read_vdir(file, !file->f_pos);
27094 + if (unlikely(err))
27097 + allocated = NULL;
27098 + vdir_cache = au_fvdir_cache(file);
27099 + if (!vdir_cache) {
27100 + vdir_cache = alloc_vdir(file);
27101 + err = PTR_ERR(vdir_cache);
27102 + if (IS_ERR(vdir_cache))
27104 + allocated = vdir_cache;
27105 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
27106 + err = reinit_vdir(vdir_cache);
27107 + if (unlikely(err))
27110 + return 0; /* success */
27112 + inode = file_inode(file);
27113 + err = copy_vdir(vdir_cache, au_ivdir(inode));
27115 + file->f_version = inode->i_version;
27117 + au_set_fvdir_cache(file, allocated);
27118 + } else if (allocated)
27119 + au_vdir_free(allocated);
27125 +static loff_t calc_offset(struct au_vdir *vdir)
27128 + union au_vdir_deblk_p p;
27130 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
27131 + offset = vdir->vd_last.p.deblk - p.deblk;
27132 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
27136 +/* returns true or false */
27137 +static int seek_vdir(struct file *file)
27140 + unsigned int deblk_sz;
27141 + unsigned long ul, n;
27143 + union au_vdir_deblk_p p, deblk_end;
27144 + struct au_vdir *vdir_cache;
27147 + vdir_cache = au_fvdir_cache(file);
27148 + offset = calc_offset(vdir_cache);
27149 + AuDbg("offset %lld\n", offset);
27150 + if (file->f_pos == offset)
27153 + vdir_cache->vd_last.ul = 0;
27154 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
27155 + if (!file->f_pos)
27159 + deblk_sz = vdir_cache->vd_deblk_sz;
27160 + ul = div64_u64(file->f_pos, deblk_sz);
27161 + AuDbg("ul %lu\n", ul);
27162 + if (ul >= vdir_cache->vd_nblk)
27165 + n = vdir_cache->vd_nblk;
27166 + for (; ul < n; ul++) {
27167 + p.deblk = vdir_cache->vd_deblk[ul];
27168 + deblk_end.deblk = p.deblk + deblk_sz;
27170 + offset *= deblk_sz;
27171 + while (!is_deblk_end(&p, &deblk_end) && offset < file->f_pos) {
27174 + l = calc_size(p.de->de_str.len);
27178 + if (!is_deblk_end(&p, &deblk_end)) {
27180 + vdir_cache->vd_last.ul = ul;
27181 + vdir_cache->vd_last.p = p;
27188 + AuTraceErr(!valid);
27192 +int au_vdir_fill_de(struct file *file, void *dirent, filldir_t filldir)
27195 + unsigned int l, deblk_sz;
27196 + union au_vdir_deblk_p deblk_end;
27197 + struct au_vdir *vdir_cache;
27198 + struct au_vdir_de *de;
27200 + vdir_cache = au_fvdir_cache(file);
27201 + if (!seek_vdir(file))
27204 + deblk_sz = vdir_cache->vd_deblk_sz;
27206 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
27207 + deblk_end.deblk += deblk_sz;
27208 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
27209 + de = vdir_cache->vd_last.p.de;
27210 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
27211 + de->de_str.len, de->de_str.name, file->f_pos,
27212 + (unsigned long)de->de_ino, de->de_type);
27213 + err = filldir(dirent, de->de_str.name, de->de_str.len,
27214 + file->f_pos, de->de_ino, de->de_type);
27215 + if (unlikely(err)) {
27217 + /* todo: ignore the error caused by udba? */
27218 + /* return err; */
27222 + l = calc_size(de->de_str.len);
27223 + vdir_cache->vd_last.p.deblk += l;
27224 + file->f_pos += l;
27226 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
27227 + vdir_cache->vd_last.ul++;
27228 + vdir_cache->vd_last.p.deblk
27229 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
27230 + file->f_pos = deblk_sz * vdir_cache->vd_last.ul;
27239 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
27240 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
27241 +++ linux/fs/aufs/vfsub.c 2013-07-30 22:42:55.842946719 +0200
27244 + * Copyright (C) 2005-2013 Junjiro R. Okajima
27246 + * This program, aufs is free software; you can redistribute it and/or modify
27247 + * it under the terms of the GNU General Public License as published by
27248 + * the Free Software Foundation; either version 2 of the License, or
27249 + * (at your option) any later version.
27251 + * This program is distributed in the hope that it will be useful,
27252 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27253 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27254 + * GNU General Public License for more details.
27256 + * You should have received a copy of the GNU General Public License
27257 + * along with this program; if not, write to the Free Software
27258 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27262 + * sub-routines for VFS
27265 +#include <linux/ima.h>
27266 +#include <linux/namei.h>
27267 +#include <linux/security.h>
27268 +#include <linux/splice.h>
27271 +int vfsub_update_h_iattr(struct path *h_path, int *did)
27275 + struct super_block *h_sb;
27277 + /* for remote fs, leave work for its getattr or d_revalidate */
27278 + /* for bad i_attr fs, handle them in aufs_getattr() */
27279 + /* still some fs may acquire i_mutex. we need to skip them */
27283 + h_sb = h_path->dentry->d_sb;
27284 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
27286 + err = vfs_getattr(h_path, &st);
27291 +/* ---------------------------------------------------------------------- */
27293 +struct file *vfsub_dentry_open(struct path *path, int flags)
27295 + struct file *file;
27297 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
27299 + if (!IS_ERR_OR_NULL(file)
27300 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
27301 + i_readcount_inc(path->dentry->d_inode);
27306 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
27308 + struct file *file;
27311 + file = filp_open(path,
27312 + oflags /* | __FMODE_NONOTIFY */,
27315 + if (IS_ERR(file))
27317 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
27323 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
27327 + err = kern_path(name, flags, path);
27328 + if (!err && path->dentry->d_inode)
27329 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
27333 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
27336 + struct path path = {
27340 + /* VFS checks it too, but by WARN_ON_ONCE() */
27341 + IMustLock(parent->d_inode);
27343 + path.dentry = lookup_one_len(name, parent, len);
27344 + if (IS_ERR(path.dentry))
27346 + if (path.dentry->d_inode)
27347 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
27350 + AuTraceErrPtr(path.dentry);
27351 + return path.dentry;
27354 +void vfsub_call_lkup_one(void *args)
27356 + struct vfsub_lkup_one_args *a = args;
27357 + *a->errp = vfsub_lkup_one(a->name, a->parent);
27360 +/* ---------------------------------------------------------------------- */
27362 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
27363 + struct dentry *d2, struct au_hinode *hdir2)
27365 + struct dentry *d;
27368 + d = lock_rename(d1, d2);
27370 + au_hn_suspend(hdir1);
27371 + if (hdir1 != hdir2)
27372 + au_hn_suspend(hdir2);
27377 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
27378 + struct dentry *d2, struct au_hinode *hdir2)
27380 + au_hn_resume(hdir1);
27381 + if (hdir1 != hdir2)
27382 + au_hn_resume(hdir2);
27384 + unlock_rename(d1, d2);
27388 +/* ---------------------------------------------------------------------- */
27390 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
27393 + struct dentry *d;
27397 + d = path->dentry;
27398 + path->dentry = d->d_parent;
27399 + err = security_path_mknod(path, d, mode, 0);
27400 + path->dentry = d;
27401 + if (unlikely(err))
27404 + err = vfs_create(dir, path->dentry, mode, want_excl);
27406 + struct path tmp = *path;
27409 + vfsub_update_h_iattr(&tmp, &did);
27411 + tmp.dentry = path->dentry->d_parent;
27412 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27421 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
27424 + struct dentry *d;
27428 + d = path->dentry;
27429 + path->dentry = d->d_parent;
27430 + err = security_path_symlink(path, d, symname);
27431 + path->dentry = d;
27432 + if (unlikely(err))
27435 + err = vfs_symlink(dir, path->dentry, symname);
27437 + struct path tmp = *path;
27440 + vfsub_update_h_iattr(&tmp, &did);
27442 + tmp.dentry = path->dentry->d_parent;
27443 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27452 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
27455 + struct dentry *d;
27459 + d = path->dentry;
27460 + path->dentry = d->d_parent;
27461 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
27462 + path->dentry = d;
27463 + if (unlikely(err))
27466 + err = vfs_mknod(dir, path->dentry, mode, dev);
27468 + struct path tmp = *path;
27471 + vfsub_update_h_iattr(&tmp, &did);
27473 + tmp.dentry = path->dentry->d_parent;
27474 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27483 +static int au_test_nlink(struct inode *inode)
27485 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
27487 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
27488 + || inode->i_nlink < link_max)
27493 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path)
27496 + struct dentry *d;
27500 + err = au_test_nlink(src_dentry->d_inode);
27501 + if (unlikely(err))
27504 + /* we don't call may_linkat() */
27505 + d = path->dentry;
27506 + path->dentry = d->d_parent;
27507 + err = security_path_link(src_dentry, path, d);
27508 + path->dentry = d;
27509 + if (unlikely(err))
27513 + err = vfs_link(src_dentry, dir, path->dentry);
27516 + struct path tmp = *path;
27519 + /* fuse has different memory inode for the same inumber */
27520 + vfsub_update_h_iattr(&tmp, &did);
27522 + tmp.dentry = path->dentry->d_parent;
27523 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27524 + tmp.dentry = src_dentry;
27525 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27534 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
27535 + struct inode *dir, struct path *path)
27538 + struct path tmp = {
27541 + struct dentry *d;
27544 + IMustLock(src_dir);
27546 + d = path->dentry;
27547 + path->dentry = d->d_parent;
27548 + tmp.dentry = src_dentry->d_parent;
27549 + err = security_path_rename(&tmp, src_dentry, path, d);
27550 + path->dentry = d;
27551 + if (unlikely(err))
27555 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry);
27560 + tmp.dentry = d->d_parent;
27561 + vfsub_update_h_iattr(&tmp, &did);
27563 + tmp.dentry = src_dentry;
27564 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27565 + tmp.dentry = src_dentry->d_parent;
27566 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27575 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
27578 + struct dentry *d;
27582 + d = path->dentry;
27583 + path->dentry = d->d_parent;
27584 + err = security_path_mkdir(path, d, mode);
27585 + path->dentry = d;
27586 + if (unlikely(err))
27589 + err = vfs_mkdir(dir, path->dentry, mode);
27591 + struct path tmp = *path;
27594 + vfsub_update_h_iattr(&tmp, &did);
27596 + tmp.dentry = path->dentry->d_parent;
27597 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27606 +int vfsub_rmdir(struct inode *dir, struct path *path)
27609 + struct dentry *d;
27613 + d = path->dentry;
27614 + path->dentry = d->d_parent;
27615 + err = security_path_rmdir(path, d);
27616 + path->dentry = d;
27617 + if (unlikely(err))
27621 + err = vfs_rmdir(dir, path->dentry);
27624 + struct path tmp = {
27625 + .dentry = path->dentry->d_parent,
27629 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
27636 +/* ---------------------------------------------------------------------- */
27638 +/* todo: support mmap_sem? */
27639 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
27645 + err = vfs_read(file, ubuf, count, ppos);
27648 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
27652 +/* todo: kernel_read()? */
27653 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
27657 + mm_segment_t oldfs;
27664 + oldfs = get_fs();
27665 + set_fs(KERNEL_DS);
27666 + err = vfsub_read_u(file, buf.u, count, ppos);
27671 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
27677 + err = vfs_write(file, ubuf, count, ppos);
27680 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
27684 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
27687 + mm_segment_t oldfs;
27690 + const char __user *u;
27694 + oldfs = get_fs();
27695 + set_fs(KERNEL_DS);
27696 + err = vfsub_write_u(file, buf.u, count, ppos);
27701 +int vfsub_flush(struct file *file, fl_owner_t id)
27706 + if (file->f_op && file->f_op->flush) {
27707 + if (!au_test_nfs(file->f_dentry->d_sb))
27708 + err = file->f_op->flush(file, id);
27711 + err = file->f_op->flush(file, id);
27715 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
27721 +int vfsub_readdir(struct file *file, filldir_t filldir, void *arg)
27726 + err = vfs_readdir(file, filldir, arg);
27729 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
27733 +long vfsub_splice_to(struct file *in, loff_t *ppos,
27734 + struct pipe_inode_info *pipe, size_t len,
27735 + unsigned int flags)
27740 + err = do_splice_to(in, ppos, pipe, len, flags);
27742 + file_accessed(in);
27744 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
27748 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
27749 + loff_t *ppos, size_t len, unsigned int flags)
27754 + err = do_splice_from(pipe, out, ppos, len, flags);
27757 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
27761 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
27765 + /* file can be NULL */
27767 + err = vfs_fsync(file, datasync);
27771 + AuDebugOn(!file);
27772 + path = &file->f_path;
27774 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
27779 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
27780 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
27781 + struct file *h_file)
27784 + struct inode *h_inode;
27785 + struct super_block *h_sb;
27788 + err = vfsub_truncate(h_path, length);
27792 + h_inode = h_path->dentry->d_inode;
27793 + h_sb = h_inode->i_sb;
27795 + sb_start_write(h_sb);
27797 + err = locks_verify_truncate(h_inode, h_file, length);
27799 + err = security_path_truncate(h_path);
27802 + err = do_truncate(h_path->dentry, length, attr, h_file);
27806 + sb_end_write(h_sb);
27813 +/* ---------------------------------------------------------------------- */
27815 +struct au_vfsub_mkdir_args {
27817 + struct inode *dir;
27818 + struct path *path;
27822 +static void au_call_vfsub_mkdir(void *args)
27824 + struct au_vfsub_mkdir_args *a = args;
27825 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
27828 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
27830 + int err, do_sio, wkq_err;
27832 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
27834 + err = vfsub_mkdir(dir, path, mode);
27836 + struct au_vfsub_mkdir_args args = {
27842 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
27843 + if (unlikely(wkq_err))
27850 +struct au_vfsub_rmdir_args {
27852 + struct inode *dir;
27853 + struct path *path;
27856 +static void au_call_vfsub_rmdir(void *args)
27858 + struct au_vfsub_rmdir_args *a = args;
27859 + *a->errp = vfsub_rmdir(a->dir, a->path);
27862 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
27864 + int err, do_sio, wkq_err;
27866 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
27868 + err = vfsub_rmdir(dir, path);
27870 + struct au_vfsub_rmdir_args args = {
27875 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
27876 + if (unlikely(wkq_err))
27883 +/* ---------------------------------------------------------------------- */
27885 +struct notify_change_args {
27887 + struct path *path;
27888 + struct iattr *ia;
27891 +static void call_notify_change(void *args)
27893 + struct notify_change_args *a = args;
27894 + struct inode *h_inode;
27896 + h_inode = a->path->dentry->d_inode;
27897 + IMustLock(h_inode);
27899 + *a->errp = -EPERM;
27900 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
27901 + *a->errp = notify_change(a->path->dentry, a->ia);
27903 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
27905 + AuTraceErr(*a->errp);
27908 +int vfsub_notify_change(struct path *path, struct iattr *ia)
27911 + struct notify_change_args args = {
27917 + call_notify_change(&args);
27922 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia)
27924 + int err, wkq_err;
27925 + struct notify_change_args args = {
27931 + wkq_err = au_wkq_wait(call_notify_change, &args);
27932 + if (unlikely(wkq_err))
27938 +/* ---------------------------------------------------------------------- */
27940 +struct unlink_args {
27942 + struct inode *dir;
27943 + struct path *path;
27946 +static void call_unlink(void *args)
27948 + struct unlink_args *a = args;
27949 + struct dentry *d = a->path->dentry;
27950 + struct inode *h_inode;
27951 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
27952 + && d->d_count == 1);
27954 + IMustLock(a->dir);
27956 + a->path->dentry = d->d_parent;
27957 + *a->errp = security_path_unlink(a->path, d);
27958 + a->path->dentry = d;
27959 + if (unlikely(*a->errp))
27962 + if (!stop_sillyrename)
27964 + h_inode = d->d_inode;
27969 + *a->errp = vfs_unlink(a->dir, d);
27972 + struct path tmp = {
27973 + .dentry = d->d_parent,
27974 + .mnt = a->path->mnt
27976 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
27979 + if (!stop_sillyrename)
27984 + AuTraceErr(*a->errp);
27988 + * @dir: must be locked.
27989 + * @dentry: target dentry.
27991 +int vfsub_unlink(struct inode *dir, struct path *path, int force)
27994 + struct unlink_args args = {
28001 + call_unlink(&args);
28005 + wkq_err = au_wkq_wait(call_unlink, &args);
28006 + if (unlikely(wkq_err))
28012 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
28013 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
28014 +++ linux/fs/aufs/vfsub.h 2013-07-30 22:42:55.842946719 +0200
28017 + * Copyright (C) 2005-2013 Junjiro R. Okajima
28019 + * This program, aufs is free software; you can redistribute it and/or modify
28020 + * it under the terms of the GNU General Public License as published by
28021 + * the Free Software Foundation; either version 2 of the License, or
28022 + * (at your option) any later version.
28024 + * This program is distributed in the hope that it will be useful,
28025 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28026 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28027 + * GNU General Public License for more details.
28029 + * You should have received a copy of the GNU General Public License
28030 + * along with this program; if not, write to the Free Software
28031 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28035 + * sub-routines for VFS
28038 +#ifndef __AUFS_VFSUB_H__
28039 +#define __AUFS_VFSUB_H__
28043 +#include <linux/fs.h>
28044 +#include <linux/lglock.h>
28045 +#include <linux/mount.h>
28046 +#include "debug.h"
28048 +/* copied from linux/fs/internal.h */
28049 +/* todo: BAD approach!! */
28050 +extern struct lglock vfsmount_lock;
28051 +extern void __mnt_drop_write(struct vfsmount *);
28052 +extern spinlock_t inode_sb_list_lock;
28054 +/* copied from linux/fs/file_table.c */
28055 +extern struct lglock files_lglock;
28058 + * These macros iterate all files on all CPUs for a given superblock.
28059 + * files_lglock must be held globally.
28061 +#define do_file_list_for_each_entry(__sb, __file) \
28064 + for_each_possible_cpu(i) { \
28065 + struct list_head *list; \
28066 + list = per_cpu_ptr((__sb)->s_files, i); \
28067 + list_for_each_entry((__file), list, f_u.fu_list)
28069 +#define while_file_list_for_each_entry \
28075 +#define do_file_list_for_each_entry(__sb, __file) \
28077 + struct list_head *list; \
28078 + list = &(sb)->s_files; \
28079 + list_for_each_entry((__file), list, f_u.fu_list)
28081 +#define while_file_list_for_each_entry \
28085 +/* ---------------------------------------------------------------------- */
28087 +/* lock subclass for lower inode */
28088 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
28089 +/* reduce? gave up. */
28091 + AuLsc_I_Begin = I_MUTEX_QUOTA, /* 4 */
28092 + AuLsc_I_PARENT, /* lower inode, parent first */
28093 + AuLsc_I_PARENT2, /* copyup dirs */
28094 + AuLsc_I_PARENT3, /* copyup wh */
28100 +/* to debug easier, do not make them inlined functions */
28101 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
28102 +#define IMustLock(i) MtxMustLock(&(i)->i_mutex)
28104 +/* ---------------------------------------------------------------------- */
28106 +static inline void vfsub_drop_nlink(struct inode *inode)
28108 + AuDebugOn(!inode->i_nlink);
28109 + drop_nlink(inode);
28112 +static inline void vfsub_dead_dir(struct inode *inode)
28114 + AuDebugOn(!S_ISDIR(inode->i_mode));
28115 + inode->i_flags |= S_DEAD;
28116 + clear_nlink(inode);
28119 +/* ---------------------------------------------------------------------- */
28121 +int vfsub_update_h_iattr(struct path *h_path, int *did);
28122 +struct file *vfsub_dentry_open(struct path *path, int flags);
28123 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
28124 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
28126 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
28129 +struct vfsub_lkup_one_args {
28130 + struct dentry **errp;
28131 + struct qstr *name;
28132 + struct dentry *parent;
28135 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
28136 + struct dentry *parent)
28138 + return vfsub_lookup_one_len(name->name, parent, name->len);
28141 +void vfsub_call_lkup_one(void *args);
28143 +/* ---------------------------------------------------------------------- */
28145 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
28149 + err = mnt_want_write(mnt);
28154 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
28157 + mnt_drop_write(mnt);
28161 +static inline void vfsub_mnt_drop_write_file(struct file *file)
28164 + mnt_drop_write_file(file);
28168 +/* ---------------------------------------------------------------------- */
28171 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
28172 + struct dentry *d2, struct au_hinode *hdir2);
28173 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
28174 + struct dentry *d2, struct au_hinode *hdir2);
28176 +int vfsub_create(struct inode *dir, struct path *path, int mode,
28178 +int vfsub_symlink(struct inode *dir, struct path *path,
28179 + const char *symname);
28180 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
28181 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
28182 + struct path *path);
28183 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
28184 + struct inode *hdir, struct path *path);
28185 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
28186 +int vfsub_rmdir(struct inode *dir, struct path *path);
28188 +/* ---------------------------------------------------------------------- */
28190 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
28192 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
28194 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
28196 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
28198 +int vfsub_flush(struct file *file, fl_owner_t id);
28199 +int vfsub_readdir(struct file *file, filldir_t filldir, void *arg);
28201 +static inline loff_t vfsub_f_size_read(struct file *file)
28203 + return i_size_read(file_inode(file));
28206 +static inline unsigned int vfsub_file_flags(struct file *file)
28208 + unsigned int flags;
28210 + spin_lock(&file->f_lock);
28211 + flags = file->f_flags;
28212 + spin_unlock(&file->f_lock);
28217 +static inline void vfsub_file_accessed(struct file *h_file)
28219 + file_accessed(h_file);
28220 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
28223 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
28224 + struct dentry *h_dentry)
28226 + struct path h_path = {
28227 + .dentry = h_dentry,
28230 + touch_atime(&h_path);
28231 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
28234 +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts,
28237 + return update_time(h_inode, ts, flags);
28238 + /* no vfsub_update_h_iattr() since we don't have struct path */
28241 +long vfsub_splice_to(struct file *in, loff_t *ppos,
28242 + struct pipe_inode_info *pipe, size_t len,
28243 + unsigned int flags);
28244 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
28245 + loff_t *ppos, size_t len, unsigned int flags);
28247 +static inline long vfsub_truncate(struct path *path, loff_t length)
28251 + err = vfs_truncate(path, length);
28256 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
28257 + struct file *h_file);
28258 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
28260 +/* ---------------------------------------------------------------------- */
28262 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
28267 + err = vfs_llseek(file, offset, origin);
28272 +/* ---------------------------------------------------------------------- */
28274 +/* dirty workaround for strict type of fmode_t */
28280 +static inline unsigned int vfsub_fmode_to_uint(fmode_t fm)
28282 + union vfsub_fmu u = {
28286 + BUILD_BUG_ON(sizeof(u.fm) != sizeof(u.ui));
28291 +static inline fmode_t vfsub_uint_to_fmode(unsigned int ui)
28293 + union vfsub_fmu u = {
28300 +/* ---------------------------------------------------------------------- */
28302 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
28303 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
28304 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia);
28305 +int vfsub_notify_change(struct path *path, struct iattr *ia);
28306 +int vfsub_unlink(struct inode *dir, struct path *path, int force);
28308 +#endif /* __KERNEL__ */
28309 +#endif /* __AUFS_VFSUB_H__ */
28310 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
28311 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
28312 +++ linux/fs/aufs/wbr_policy.c 2013-08-23 23:59:39.638250372 +0200
28315 + * Copyright (C) 2005-2013 Junjiro R. Okajima
28317 + * This program, aufs is free software; you can redistribute it and/or modify
28318 + * it under the terms of the GNU General Public License as published by
28319 + * the Free Software Foundation; either version 2 of the License, or
28320 + * (at your option) any later version.
28322 + * This program is distributed in the hope that it will be useful,
28323 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28324 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28325 + * GNU General Public License for more details.
28327 + * You should have received a copy of the GNU General Public License
28328 + * along with this program; if not, write to the Free Software
28329 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28333 + * policies for selecting one among multiple writable branches
28336 +#include <linux/statfs.h>
28339 +/* subset of cpup_attr() */
28340 +static noinline_for_stack
28341 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
28345 + struct inode *h_isrc;
28347 + h_isrc = h_src->d_inode;
28348 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
28349 + ia.ia_mode = h_isrc->i_mode;
28350 + ia.ia_uid = h_isrc->i_uid;
28351 + ia.ia_gid = h_isrc->i_gid;
28352 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
28353 + au_cpup_attr_flags(h_path->dentry->d_inode, h_isrc->i_flags);
28354 + err = vfsub_sio_notify_change(h_path, &ia);
28356 + /* is this nfs only? */
28357 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
28358 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
28359 + ia.ia_mode = h_isrc->i_mode;
28360 + err = vfsub_sio_notify_change(h_path, &ia);
28366 +#define AuCpdown_PARENT_OPQ 1
28367 +#define AuCpdown_WHED (1 << 1)
28368 +#define AuCpdown_MADE_DIR (1 << 2)
28369 +#define AuCpdown_DIROPQ (1 << 3)
28370 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
28371 +#define au_fset_cpdown(flags, name) \
28372 + do { (flags) |= AuCpdown_##name; } while (0)
28373 +#define au_fclr_cpdown(flags, name) \
28374 + do { (flags) &= ~AuCpdown_##name; } while (0)
28376 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
28377 + unsigned int *flags)
28380 + struct dentry *opq_dentry;
28382 + opq_dentry = au_diropq_create(dentry, bdst);
28383 + err = PTR_ERR(opq_dentry);
28384 + if (IS_ERR(opq_dentry))
28386 + dput(opq_dentry);
28387 + au_fset_cpdown(*flags, DIROPQ);
28393 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
28394 + struct inode *dir, aufs_bindex_t bdst)
28397 + struct path h_path;
28398 + struct au_branch *br;
28400 + br = au_sbr(dentry->d_sb, bdst);
28401 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
28402 + err = PTR_ERR(h_path.dentry);
28403 + if (IS_ERR(h_path.dentry))
28407 + if (h_path.dentry->d_inode) {
28408 + h_path.mnt = au_br_mnt(br);
28409 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
28412 + dput(h_path.dentry);
28418 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
28419 + struct au_pin *pin,
28420 + struct dentry *h_parent, void *arg)
28423 + aufs_bindex_t bopq, bstart;
28424 + struct path h_path;
28425 + struct dentry *parent;
28426 + struct inode *h_dir, *h_inode, *inode, *dir;
28427 + unsigned int *flags = arg;
28429 + bstart = au_dbstart(dentry);
28430 + /* dentry is di-locked */
28431 + parent = dget_parent(dentry);
28432 + dir = parent->d_inode;
28433 + h_dir = h_parent->d_inode;
28434 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
28435 + IMustLock(h_dir);
28437 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
28438 + if (unlikely(err < 0))
28440 + h_path.dentry = au_h_dptr(dentry, bdst);
28441 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
28442 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path,
28443 + S_IRWXU | S_IRUGO | S_IXUGO);
28444 + if (unlikely(err))
28446 + au_fset_cpdown(*flags, MADE_DIR);
28448 + bopq = au_dbdiropq(dentry);
28449 + au_fclr_cpdown(*flags, WHED);
28450 + au_fclr_cpdown(*flags, DIROPQ);
28451 + if (au_dbwh(dentry) == bdst)
28452 + au_fset_cpdown(*flags, WHED);
28453 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
28454 + au_fset_cpdown(*flags, PARENT_OPQ);
28455 + h_inode = h_path.dentry->d_inode;
28456 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
28457 + if (au_ftest_cpdown(*flags, WHED)) {
28458 + err = au_cpdown_dir_opq(dentry, bdst, flags);
28459 + if (unlikely(err)) {
28460 + mutex_unlock(&h_inode->i_mutex);
28465 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, bstart));
28466 + mutex_unlock(&h_inode->i_mutex);
28467 + if (unlikely(err))
28470 + if (au_ftest_cpdown(*flags, WHED)) {
28471 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
28472 + if (unlikely(err))
28476 + inode = dentry->d_inode;
28477 + if (au_ibend(inode) < bdst)
28478 + au_set_ibend(inode, bdst);
28479 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
28480 + au_hi_flags(inode, /*isdir*/1));
28481 + goto out; /* success */
28485 + if (au_ftest_cpdown(*flags, DIROPQ)) {
28486 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
28487 + rerr = au_diropq_remove(dentry, bdst);
28488 + mutex_unlock(&h_inode->i_mutex);
28489 + if (unlikely(rerr)) {
28490 + AuIOErr("failed removing diropq for %.*s b%d (%d)\n",
28491 + AuDLNPair(dentry), bdst, rerr);
28497 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
28498 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
28499 + if (unlikely(rerr)) {
28500 + AuIOErr("failed removing %.*s b%d (%d)\n",
28501 + AuDLNPair(dentry), bdst, rerr);
28506 + au_set_h_dptr(dentry, bdst, NULL);
28507 + if (au_dbend(dentry) == bdst)
28508 + au_update_dbend(dentry);
28514 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
28517 + unsigned int flags;
28520 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
28525 +/* ---------------------------------------------------------------------- */
28527 +/* policies for create */
28529 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
28531 + int err, i, j, ndentry;
28532 + aufs_bindex_t bopq;
28533 + struct au_dcsub_pages dpages;
28534 + struct au_dpage *dpage;
28535 + struct dentry **dentries, *parent, *d;
28537 + err = au_dpages_init(&dpages, GFP_NOFS);
28538 + if (unlikely(err))
28540 + parent = dget_parent(dentry);
28541 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
28542 + if (unlikely(err))
28546 + for (i = 0; i < dpages.ndpage; i++) {
28547 + dpage = dpages.dpages + i;
28548 + dentries = dpage->dentries;
28549 + ndentry = dpage->ndentry;
28550 + for (j = 0; j < ndentry; j++) {
28552 + di_read_lock_parent2(d, !AuLock_IR);
28553 + bopq = au_dbdiropq(d);
28554 + di_read_unlock(d, !AuLock_IR);
28555 + if (bopq >= 0 && bopq < err)
28562 + au_dpages_free(&dpages);
28567 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
28569 + for (; bindex >= 0; bindex--)
28570 + if (!au_br_rdonly(au_sbr(sb, bindex)))
28575 +/* top down parent */
28576 +static int au_wbr_create_tdp(struct dentry *dentry, int isdir __maybe_unused)
28579 + aufs_bindex_t bstart, bindex;
28580 + struct super_block *sb;
28581 + struct dentry *parent, *h_parent;
28583 + sb = dentry->d_sb;
28584 + bstart = au_dbstart(dentry);
28586 + if (!au_br_rdonly(au_sbr(sb, bstart)))
28590 + parent = dget_parent(dentry);
28591 + for (bindex = au_dbstart(parent); bindex < bstart; bindex++) {
28592 + h_parent = au_h_dptr(parent, bindex);
28593 + if (!h_parent || !h_parent->d_inode)
28596 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
28603 + /* bottom up here */
28604 + if (unlikely(err < 0)) {
28605 + err = au_wbr_bu(sb, bstart - 1);
28607 + err = au_wbr_nonopq(dentry, err);
28611 + AuDbg("b%d\n", err);
28615 +/* ---------------------------------------------------------------------- */
28617 +/* an exception for the policy other than tdp */
28618 +static int au_wbr_create_exp(struct dentry *dentry)
28621 + aufs_bindex_t bwh, bdiropq;
28622 + struct dentry *parent;
28625 + bwh = au_dbwh(dentry);
28626 + parent = dget_parent(dentry);
28627 + bdiropq = au_dbdiropq(parent);
28629 + if (bdiropq >= 0)
28630 + err = min(bdiropq, bwh);
28633 + AuDbg("%d\n", err);
28634 + } else if (bdiropq >= 0) {
28636 + AuDbg("%d\n", err);
28641 + err = au_wbr_nonopq(dentry, err);
28643 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
28646 + AuDbg("%d\n", err);
28650 +/* ---------------------------------------------------------------------- */
28653 +static int au_wbr_create_init_rr(struct super_block *sb)
28657 + err = au_wbr_bu(sb, au_sbend(sb));
28658 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
28661 + AuDbg("b%d\n", err);
28665 +static int au_wbr_create_rr(struct dentry *dentry, int isdir)
28669 + aufs_bindex_t bindex, bend;
28670 + struct super_block *sb;
28673 + err = au_wbr_create_exp(dentry);
28677 + sb = dentry->d_sb;
28678 + next = &au_sbi(sb)->si_wbr_rr_next;
28679 + bend = au_sbend(sb);
28681 + for (bindex = 0; bindex <= bend; bindex++) {
28683 + err = atomic_dec_return(next) + 1;
28684 + /* modulo for 0 is meaningless */
28685 + if (unlikely(!err))
28686 + err = atomic_dec_return(next) + 1;
28688 + err = atomic_read(next);
28689 + AuDbg("%d\n", err);
28692 + AuDbg("%d\n", err);
28693 + if (!au_br_rdonly(au_sbr(sb, err)))
28699 + err = au_wbr_nonopq(dentry, err);
28702 + AuDbg("%d\n", err);
28706 +/* ---------------------------------------------------------------------- */
28708 +/* most free space */
28709 +static void au_mfs(struct dentry *dentry)
28711 + struct super_block *sb;
28712 + struct au_branch *br;
28713 + struct au_wbr_mfs *mfs;
28714 + aufs_bindex_t bindex, bend;
28716 + unsigned long long b, bavail;
28717 + struct path h_path;
28718 + /* reduce the stack usage */
28719 + struct kstatfs *st;
28721 + st = kmalloc(sizeof(*st), GFP_NOFS);
28722 + if (unlikely(!st)) {
28723 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
28728 + sb = dentry->d_sb;
28729 + mfs = &au_sbi(sb)->si_wbr_mfs;
28730 + MtxMustLock(&mfs->mfs_lock);
28731 + mfs->mfs_bindex = -EROFS;
28732 + mfs->mfsrr_bytes = 0;
28733 + bend = au_sbend(sb);
28734 + for (bindex = 0; bindex <= bend; bindex++) {
28735 + br = au_sbr(sb, bindex);
28736 + if (au_br_rdonly(br))
28739 + /* sb->s_root for NFS is unreliable */
28740 + h_path.mnt = au_br_mnt(br);
28741 + h_path.dentry = h_path.mnt->mnt_root;
28742 + err = vfs_statfs(&h_path, st);
28743 + if (unlikely(err)) {
28744 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
28748 + /* when the available size is equal, select the lower one */
28749 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
28750 + || sizeof(b) < sizeof(st->f_bsize));
28751 + b = st->f_bavail * st->f_bsize;
28752 + br->br_wbr->wbr_bytes = b;
28753 + if (b >= bavail) {
28755 + mfs->mfs_bindex = bindex;
28756 + mfs->mfs_jiffy = jiffies;
28760 + mfs->mfsrr_bytes = bavail;
28761 + AuDbg("b%d\n", mfs->mfs_bindex);
28765 +static int au_wbr_create_mfs(struct dentry *dentry, int isdir __maybe_unused)
28768 + struct super_block *sb;
28769 + struct au_wbr_mfs *mfs;
28771 + err = au_wbr_create_exp(dentry);
28775 + sb = dentry->d_sb;
28776 + mfs = &au_sbi(sb)->si_wbr_mfs;
28777 + mutex_lock(&mfs->mfs_lock);
28778 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
28779 + || mfs->mfs_bindex < 0
28780 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
28782 + mutex_unlock(&mfs->mfs_lock);
28783 + err = mfs->mfs_bindex;
28786 + err = au_wbr_nonopq(dentry, err);
28789 + AuDbg("b%d\n", err);
28793 +static int au_wbr_create_init_mfs(struct super_block *sb)
28795 + struct au_wbr_mfs *mfs;
28797 + mfs = &au_sbi(sb)->si_wbr_mfs;
28798 + mutex_init(&mfs->mfs_lock);
28799 + mfs->mfs_jiffy = 0;
28800 + mfs->mfs_bindex = -EROFS;
28805 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
28807 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
28811 +/* ---------------------------------------------------------------------- */
28813 +/* most free space and then round robin */
28814 +static int au_wbr_create_mfsrr(struct dentry *dentry, int isdir)
28817 + struct au_wbr_mfs *mfs;
28819 + err = au_wbr_create_mfs(dentry, isdir);
28821 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
28822 + mutex_lock(&mfs->mfs_lock);
28823 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
28824 + err = au_wbr_create_rr(dentry, isdir);
28825 + mutex_unlock(&mfs->mfs_lock);
28828 + AuDbg("b%d\n", err);
28832 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
28836 + au_wbr_create_init_mfs(sb); /* ignore */
28837 + err = au_wbr_create_init_rr(sb);
28842 +/* ---------------------------------------------------------------------- */
28844 +/* top down parent and most free space */
28845 +static int au_wbr_create_pmfs(struct dentry *dentry, int isdir)
28848 + unsigned long long b;
28849 + aufs_bindex_t bindex, bstart, bend;
28850 + struct super_block *sb;
28851 + struct dentry *parent, *h_parent;
28852 + struct au_branch *br;
28854 + err = au_wbr_create_tdp(dentry, isdir);
28855 + if (unlikely(err < 0))
28857 + parent = dget_parent(dentry);
28858 + bstart = au_dbstart(parent);
28859 + bend = au_dbtaildir(parent);
28860 + if (bstart == bend)
28861 + goto out_parent; /* success */
28863 + e2 = au_wbr_create_mfs(dentry, isdir);
28865 + goto out_parent; /* success */
28867 + /* when the available size is equal, select upper one */
28868 + sb = dentry->d_sb;
28869 + br = au_sbr(sb, err);
28870 + b = br->br_wbr->wbr_bytes;
28871 + AuDbg("b%d, %llu\n", err, b);
28873 + for (bindex = bstart; bindex <= bend; bindex++) {
28874 + h_parent = au_h_dptr(parent, bindex);
28875 + if (!h_parent || !h_parent->d_inode)
28878 + br = au_sbr(sb, bindex);
28879 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
28880 + b = br->br_wbr->wbr_bytes;
28882 + AuDbg("b%d, %llu\n", err, b);
28887 + err = au_wbr_nonopq(dentry, err);
28892 + AuDbg("b%d\n", err);
28896 +/* ---------------------------------------------------------------------- */
28898 +/* policies for copyup */
28900 +/* top down parent */
28901 +static int au_wbr_copyup_tdp(struct dentry *dentry)
28903 + return au_wbr_create_tdp(dentry, /*isdir, anything is ok*/0);
28906 +/* bottom up parent */
28907 +static int au_wbr_copyup_bup(struct dentry *dentry)
28910 + aufs_bindex_t bindex, bstart;
28911 + struct dentry *parent, *h_parent;
28912 + struct super_block *sb;
28915 + sb = dentry->d_sb;
28916 + parent = dget_parent(dentry);
28917 + bstart = au_dbstart(parent);
28918 + for (bindex = au_dbstart(dentry); bindex >= bstart; bindex--) {
28919 + h_parent = au_h_dptr(parent, bindex);
28920 + if (!h_parent || !h_parent->d_inode)
28923 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
28930 + /* bottom up here */
28931 + if (unlikely(err < 0))
28932 + err = au_wbr_bu(sb, bstart - 1);
28934 + AuDbg("b%d\n", err);
28939 +static int au_wbr_copyup_bu(struct dentry *dentry)
28942 + aufs_bindex_t bstart;
28944 + bstart = au_dbstart(dentry);
28945 + err = au_wbr_bu(dentry->d_sb, bstart);
28946 + AuDbg("b%d\n", err);
28947 + if (err > bstart)
28948 + err = au_wbr_nonopq(dentry, err);
28950 + AuDbg("b%d\n", err);
28954 +/* ---------------------------------------------------------------------- */
28956 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
28957 + [AuWbrCopyup_TDP] = {
28958 + .copyup = au_wbr_copyup_tdp
28960 + [AuWbrCopyup_BUP] = {
28961 + .copyup = au_wbr_copyup_bup
28963 + [AuWbrCopyup_BU] = {
28964 + .copyup = au_wbr_copyup_bu
28968 +struct au_wbr_create_operations au_wbr_create_ops[] = {
28969 + [AuWbrCreate_TDP] = {
28970 + .create = au_wbr_create_tdp
28972 + [AuWbrCreate_RR] = {
28973 + .create = au_wbr_create_rr,
28974 + .init = au_wbr_create_init_rr
28976 + [AuWbrCreate_MFS] = {
28977 + .create = au_wbr_create_mfs,
28978 + .init = au_wbr_create_init_mfs,
28979 + .fin = au_wbr_create_fin_mfs
28981 + [AuWbrCreate_MFSV] = {
28982 + .create = au_wbr_create_mfs,
28983 + .init = au_wbr_create_init_mfs,
28984 + .fin = au_wbr_create_fin_mfs
28986 + [AuWbrCreate_MFSRR] = {
28987 + .create = au_wbr_create_mfsrr,
28988 + .init = au_wbr_create_init_mfsrr,
28989 + .fin = au_wbr_create_fin_mfs
28991 + [AuWbrCreate_MFSRRV] = {
28992 + .create = au_wbr_create_mfsrr,
28993 + .init = au_wbr_create_init_mfsrr,
28994 + .fin = au_wbr_create_fin_mfs
28996 + [AuWbrCreate_PMFS] = {
28997 + .create = au_wbr_create_pmfs,
28998 + .init = au_wbr_create_init_mfs,
28999 + .fin = au_wbr_create_fin_mfs
29001 + [AuWbrCreate_PMFSV] = {
29002 + .create = au_wbr_create_pmfs,
29003 + .init = au_wbr_create_init_mfs,
29004 + .fin = au_wbr_create_fin_mfs
29007 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
29008 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
29009 +++ linux/fs/aufs/whout.c 2013-07-06 13:20:47.760198800 +0200
29012 + * Copyright (C) 2005-2013 Junjiro R. Okajima
29014 + * This program, aufs is free software; you can redistribute it and/or modify
29015 + * it under the terms of the GNU General Public License as published by
29016 + * the Free Software Foundation; either version 2 of the License, or
29017 + * (at your option) any later version.
29019 + * This program is distributed in the hope that it will be useful,
29020 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29021 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29022 + * GNU General Public License for more details.
29024 + * You should have received a copy of the GNU General Public License
29025 + * along with this program; if not, write to the Free Software
29026 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29030 + * whiteout for logical deletion and opaque directory
29035 +#define WH_MASK S_IRUGO
29038 + * If a directory contains this file, then it is opaque. We start with the
29039 + * .wh. flag so that it is blocked by lookup.
29041 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
29042 + sizeof(AUFS_WH_DIROPQ) - 1);
29045 + * generate whiteout name, which is NOT terminated by NULL.
29046 + * @name: original d_name.name
29047 + * @len: original d_name.len
29048 + * @wh: whiteout qstr
29049 + * returns zero when succeeds, otherwise error.
29050 + * succeeded value as wh->name should be freed by kfree().
29052 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
29056 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
29057 + return -ENAMETOOLONG;
29059 + wh->len = name->len + AUFS_WH_PFX_LEN;
29060 + p = kmalloc(wh->len, GFP_NOFS);
29063 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
29064 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
29071 +/* ---------------------------------------------------------------------- */
29074 + * test if the @wh_name exists under @h_parent.
29075 + * @try_sio specifies the necessary of super-io.
29077 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name,
29078 + struct au_branch *br, int try_sio)
29081 + struct dentry *wh_dentry;
29084 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
29086 + wh_dentry = au_sio_lkup_one(wh_name, h_parent, br);
29087 + err = PTR_ERR(wh_dentry);
29088 + if (IS_ERR(wh_dentry))
29092 + if (!wh_dentry->d_inode)
29093 + goto out_wh; /* success */
29096 + if (S_ISREG(wh_dentry->d_inode->i_mode))
29097 + goto out_wh; /* success */
29100 + AuIOErr("%.*s Invalid whiteout entry type 0%o.\n",
29101 + AuDLNPair(wh_dentry), wh_dentry->d_inode->i_mode);
29110 + * test if the @h_dentry sets opaque or not.
29112 +int au_diropq_test(struct dentry *h_dentry, struct au_branch *br)
29115 + struct inode *h_dir;
29117 + h_dir = h_dentry->d_inode;
29118 + err = au_wh_test(h_dentry, &diropq_name, br,
29119 + au_test_h_perm_sio(h_dir, MAY_EXEC));
29124 + * returns a negative dentry whose name is unique and temporary.
29126 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
29127 + struct qstr *prefix)
29129 + struct dentry *dentry;
29131 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
29133 + /* strict atomic_t is unnecessary here */
29134 + static unsigned short cnt;
29137 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
29140 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
29141 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
29142 + dentry = ERR_PTR(-ENAMETOOLONG);
29143 + if (unlikely(qs.len > NAME_MAX))
29145 + dentry = ERR_PTR(-ENOMEM);
29146 + name = kmalloc(qs.len + 1, GFP_NOFS);
29147 + if (unlikely(!name))
29151 + /* doubly whiteout-ed */
29152 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
29153 + p = name + AUFS_WH_PFX_LEN * 2;
29154 + memcpy(p, prefix->name, prefix->len);
29155 + p += prefix->len;
29157 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
29160 + for (i = 0; i < 3; i++) {
29161 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
29162 + dentry = au_sio_lkup_one(&qs, h_parent, br);
29163 + if (IS_ERR(dentry) || !dentry->d_inode)
29167 + /* pr_warn("could not get random name\n"); */
29168 + dentry = ERR_PTR(-EEXIST);
29169 + AuDbg("%.*s\n", AuLNPair(&qs));
29173 + if (name != defname)
29176 + AuTraceErrPtr(dentry);
29181 + * rename the @h_dentry on @br to the whiteouted temporary name.
29183 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
29186 + struct path h_path = {
29187 + .mnt = au_br_mnt(br)
29189 + struct inode *h_dir;
29190 + struct dentry *h_parent;
29192 + h_parent = h_dentry->d_parent; /* dir inode is locked */
29193 + h_dir = h_parent->d_inode;
29194 + IMustLock(h_dir);
29196 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
29197 + err = PTR_ERR(h_path.dentry);
29198 + if (IS_ERR(h_path.dentry))
29201 + /* under the same dir, no need to lock_rename() */
29202 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path);
29204 + dput(h_path.dentry);
29211 +/* ---------------------------------------------------------------------- */
29213 + * functions for removing a whiteout
29216 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
29221 + * forces superio when the dir has a sticky bit.
29222 + * this may be a violation of unix fs semantics.
29224 + force = (h_dir->i_mode & S_ISVTX)
29225 + && !uid_eq(current_fsuid(), h_path->dentry->d_inode->i_uid);
29226 + return vfsub_unlink(h_dir, h_path, force);
29229 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
29230 + struct dentry *dentry)
29234 + err = do_unlink_wh(h_dir, h_path);
29235 + if (!err && dentry)
29236 + au_set_dbwh(dentry, -1);
29241 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
29242 + struct au_branch *br)
29245 + struct path h_path = {
29246 + .mnt = au_br_mnt(br)
29250 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
29251 + if (IS_ERR(h_path.dentry))
29252 + err = PTR_ERR(h_path.dentry);
29254 + if (h_path.dentry->d_inode
29255 + && S_ISREG(h_path.dentry->d_inode->i_mode))
29256 + err = do_unlink_wh(h_parent->d_inode, &h_path);
29257 + dput(h_path.dentry);
29263 +/* ---------------------------------------------------------------------- */
29265 + * initialize/clean whiteout for a branch
29268 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
29273 + if (!whpath->dentry->d_inode)
29277 + err = vfsub_rmdir(h_dir, whpath);
29279 + err = vfsub_unlink(h_dir, whpath, /*force*/0);
29280 + if (unlikely(err))
29281 + pr_warn("failed removing %.*s (%d), ignored.\n",
29282 + AuDLNPair(whpath->dentry), err);
29285 +static int test_linkable(struct dentry *h_root)
29287 + struct inode *h_dir = h_root->d_inode;
29289 + if (h_dir->i_op->link)
29292 + pr_err("%.*s (%s) doesn't support link(2), use noplink and rw+nolwh\n",
29293 + AuDLNPair(h_root), au_sbtype(h_root->d_sb));
29297 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
29298 +static int au_whdir(struct inode *h_dir, struct path *path)
29303 + if (!path->dentry->d_inode) {
29304 + int mode = S_IRWXU;
29306 + if (au_test_nfs(path->dentry->d_sb))
29308 + err = vfsub_mkdir(h_dir, path, mode);
29309 + } else if (S_ISDIR(path->dentry->d_inode->i_mode))
29312 + pr_err("unknown %.*s exists\n", AuDLNPair(path->dentry));
29317 +struct au_wh_base {
29318 + const struct qstr *name;
29319 + struct dentry *dentry;
29322 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
29323 + struct path *h_path)
29325 + h_path->dentry = base[AuBrWh_BASE].dentry;
29326 + au_wh_clean(h_dir, h_path, /*isdir*/0);
29327 + h_path->dentry = base[AuBrWh_PLINK].dentry;
29328 + au_wh_clean(h_dir, h_path, /*isdir*/1);
29329 + h_path->dentry = base[AuBrWh_ORPH].dentry;
29330 + au_wh_clean(h_dir, h_path, /*isdir*/1);
29334 + * returns tri-state,
29335 + * minus: error, caller should print the mesage
29337 + * plus: error, caller should NOT print the mesage
29339 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
29340 + int do_plink, struct au_wh_base base[],
29341 + struct path *h_path)
29344 + struct inode *h_dir;
29346 + h_dir = h_root->d_inode;
29347 + h_path->dentry = base[AuBrWh_BASE].dentry;
29348 + au_wh_clean(h_dir, h_path, /*isdir*/0);
29349 + h_path->dentry = base[AuBrWh_PLINK].dentry;
29351 + err = test_linkable(h_root);
29352 + if (unlikely(err)) {
29357 + err = au_whdir(h_dir, h_path);
29358 + if (unlikely(err))
29360 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
29362 + au_wh_clean(h_dir, h_path, /*isdir*/1);
29363 + h_path->dentry = base[AuBrWh_ORPH].dentry;
29364 + err = au_whdir(h_dir, h_path);
29365 + if (unlikely(err))
29367 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
29374 + * for the moment, aufs supports the branch filesystem which does not support
29375 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
29376 + * copyup failed. finally, such filesystem will not be used as the writable
29379 + * returns tri-state, see above.
29381 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
29382 + int do_plink, struct au_wh_base base[],
29383 + struct path *h_path)
29386 + struct inode *h_dir;
29388 + WbrWhMustWriteLock(wbr);
29390 + err = test_linkable(h_root);
29391 + if (unlikely(err)) {
29397 + * todo: should this create be done in /sbin/mount.aufs helper?
29400 + h_dir = h_root->d_inode;
29401 + if (!base[AuBrWh_BASE].dentry->d_inode) {
29402 + h_path->dentry = base[AuBrWh_BASE].dentry;
29403 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
29404 + } else if (S_ISREG(base[AuBrWh_BASE].dentry->d_inode->i_mode))
29407 + pr_err("unknown %.*s/%.*s exists\n",
29408 + AuDLNPair(h_root), AuDLNPair(base[AuBrWh_BASE].dentry));
29409 + if (unlikely(err))
29412 + h_path->dentry = base[AuBrWh_PLINK].dentry;
29414 + err = au_whdir(h_dir, h_path);
29415 + if (unlikely(err))
29417 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
29419 + au_wh_clean(h_dir, h_path, /*isdir*/1);
29420 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
29422 + h_path->dentry = base[AuBrWh_ORPH].dentry;
29423 + err = au_whdir(h_dir, h_path);
29424 + if (unlikely(err))
29426 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
29433 + * initialize the whiteout base file/dir for @br.
29435 +int au_wh_init(struct au_branch *br, struct super_block *sb)
29438 + const unsigned char do_plink
29439 + = !!au_opt_test(au_mntflags(sb), PLINK);
29440 + struct inode *h_dir;
29441 + struct path path = br->br_path;
29442 + struct dentry *h_root = path.dentry;
29443 + struct au_wbr *wbr = br->br_wbr;
29444 + static const struct qstr base_name[] = {
29445 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
29446 + sizeof(AUFS_BASE_NAME) - 1),
29447 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
29448 + sizeof(AUFS_PLINKDIR_NAME) - 1),
29449 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
29450 + sizeof(AUFS_ORPHDIR_NAME) - 1)
29452 + struct au_wh_base base[] = {
29453 + [AuBrWh_BASE] = {
29454 + .name = base_name + AuBrWh_BASE,
29457 + [AuBrWh_PLINK] = {
29458 + .name = base_name + AuBrWh_PLINK,
29461 + [AuBrWh_ORPH] = {
29462 + .name = base_name + AuBrWh_ORPH,
29468 + WbrWhMustWriteLock(wbr);
29470 + for (i = 0; i < AuBrWh_Last; i++) {
29471 + /* doubly whiteouted */
29472 + struct dentry *d;
29474 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
29475 + err = PTR_ERR(d);
29479 + base[i].dentry = d;
29481 + && wbr->wbr_wh[i]
29482 + && wbr->wbr_wh[i] != base[i].dentry);
29486 + for (i = 0; i < AuBrWh_Last; i++) {
29487 + dput(wbr->wbr_wh[i]);
29488 + wbr->wbr_wh[i] = NULL;
29492 + if (!au_br_writable(br->br_perm)) {
29493 + h_dir = h_root->d_inode;
29494 + au_wh_init_ro(h_dir, base, &path);
29495 + } else if (!au_br_wh_linkable(br->br_perm)) {
29496 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
29502 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
29508 + goto out; /* success */
29511 + pr_err("an error(%d) on the writable branch %.*s(%s)\n",
29512 + err, AuDLNPair(h_root), au_sbtype(h_root->d_sb));
29514 + for (i = 0; i < AuBrWh_Last; i++)
29515 + dput(base[i].dentry);
29519 +/* ---------------------------------------------------------------------- */
29521 + * whiteouts are all hard-linked usually.
29522 + * when its link count reaches a ceiling, we create a new whiteout base
29523 + * asynchronously.
29526 +struct reinit_br_wh {
29527 + struct super_block *sb;
29528 + struct au_branch *br;
29531 +static void reinit_br_wh(void *arg)
29534 + aufs_bindex_t bindex;
29535 + struct path h_path;
29536 + struct reinit_br_wh *a = arg;
29537 + struct au_wbr *wbr;
29538 + struct inode *dir;
29539 + struct dentry *h_root;
29540 + struct au_hinode *hdir;
29543 + wbr = a->br->br_wbr;
29544 + /* big aufs lock */
29545 + si_noflush_write_lock(a->sb);
29546 + if (!au_br_writable(a->br->br_perm))
29548 + bindex = au_br_index(a->sb, a->br->br_id);
29549 + if (unlikely(bindex < 0))
29552 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
29553 + dir = a->sb->s_root->d_inode;
29554 + hdir = au_hi(dir, bindex);
29555 + h_root = au_h_dptr(a->sb->s_root, bindex);
29556 + AuDebugOn(h_root != au_br_dentry(a->br));
29558 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
29559 + wbr_wh_write_lock(wbr);
29560 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
29563 + h_path.dentry = wbr->wbr_whbase;
29564 + h_path.mnt = au_br_mnt(a->br);
29565 + err = vfsub_unlink(hdir->hi_inode, &h_path, /*force*/0);
29567 + pr_warn("%.*s is moved, ignored\n",
29568 + AuDLNPair(wbr->wbr_whbase));
29571 + dput(wbr->wbr_whbase);
29572 + wbr->wbr_whbase = NULL;
29574 + err = au_wh_init(a->br, a->sb);
29575 + wbr_wh_write_unlock(wbr);
29576 + au_hn_imtx_unlock(hdir);
29577 + di_read_unlock(a->sb->s_root, AuLock_IR);
29581 + atomic_dec(&wbr->wbr_wh_running);
29582 + atomic_dec(&a->br->br_count);
29583 + si_write_unlock(a->sb);
29584 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
29586 + if (unlikely(err))
29587 + AuIOErr("err %d\n", err);
29590 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
29592 + int do_dec, wkq_err;
29593 + struct reinit_br_wh *arg;
29596 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
29599 + /* ignore ENOMEM */
29600 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
29603 + * dec(wh_running), kfree(arg) and dec(br_count)
29604 + * in reinit function
29608 + atomic_inc(&br->br_count);
29609 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
29610 + if (unlikely(wkq_err)) {
29611 + atomic_dec(&br->br_wbr->wbr_wh_running);
29612 + atomic_dec(&br->br_count);
29620 + atomic_dec(&br->br_wbr->wbr_wh_running);
29623 +/* ---------------------------------------------------------------------- */
29626 + * create the whiteout @wh.
29628 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
29629 + struct dentry *wh)
29632 + struct path h_path = {
29635 + struct au_branch *br;
29636 + struct au_wbr *wbr;
29637 + struct dentry *h_parent;
29638 + struct inode *h_dir;
29640 + h_parent = wh->d_parent; /* dir inode is locked */
29641 + h_dir = h_parent->d_inode;
29642 + IMustLock(h_dir);
29644 + br = au_sbr(sb, bindex);
29645 + h_path.mnt = au_br_mnt(br);
29646 + wbr = br->br_wbr;
29647 + wbr_wh_read_lock(wbr);
29648 + if (wbr->wbr_whbase) {
29649 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path);
29650 + if (!err || err != -EMLINK)
29653 + /* link count full. re-initialize br_whbase. */
29654 + kick_reinit_br_wh(sb, br);
29657 + /* return this error in this context */
29658 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
29661 + wbr_wh_read_unlock(wbr);
29665 +/* ---------------------------------------------------------------------- */
29668 + * create or remove the diropq.
29670 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
29671 + unsigned int flags)
29673 + struct dentry *opq_dentry, *h_dentry;
29674 + struct super_block *sb;
29675 + struct au_branch *br;
29678 + sb = dentry->d_sb;
29679 + br = au_sbr(sb, bindex);
29680 + h_dentry = au_h_dptr(dentry, bindex);
29681 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
29682 + if (IS_ERR(opq_dentry))
29685 + if (au_ftest_diropq(flags, CREATE)) {
29686 + err = link_or_create_wh(sb, bindex, opq_dentry);
29688 + au_set_dbdiropq(dentry, bindex);
29689 + goto out; /* success */
29692 + struct path tmp = {
29693 + .dentry = opq_dentry,
29694 + .mnt = au_br_mnt(br)
29696 + err = do_unlink_wh(au_h_iptr(dentry->d_inode, bindex), &tmp);
29698 + au_set_dbdiropq(dentry, -1);
29700 + dput(opq_dentry);
29701 + opq_dentry = ERR_PTR(err);
29704 + return opq_dentry;
29707 +struct do_diropq_args {
29708 + struct dentry **errp;
29709 + struct dentry *dentry;
29710 + aufs_bindex_t bindex;
29711 + unsigned int flags;
29714 +static void call_do_diropq(void *args)
29716 + struct do_diropq_args *a = args;
29717 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
29720 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
29721 + unsigned int flags)
29723 + struct dentry *diropq, *h_dentry;
29725 + h_dentry = au_h_dptr(dentry, bindex);
29726 + if (!au_test_h_perm_sio(h_dentry->d_inode, MAY_EXEC | MAY_WRITE))
29727 + diropq = do_diropq(dentry, bindex, flags);
29730 + struct do_diropq_args args = {
29732 + .dentry = dentry,
29733 + .bindex = bindex,
29737 + wkq_err = au_wkq_wait(call_do_diropq, &args);
29738 + if (unlikely(wkq_err))
29739 + diropq = ERR_PTR(wkq_err);
29745 +/* ---------------------------------------------------------------------- */
29748 + * lookup whiteout dentry.
29749 + * @h_parent: lower parent dentry which must exist and be locked
29750 + * @base_name: name of dentry which will be whiteouted
29751 + * returns dentry for whiteout.
29753 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
29754 + struct au_branch *br)
29757 + struct qstr wh_name;
29758 + struct dentry *wh_dentry;
29760 + err = au_wh_name_alloc(&wh_name, base_name);
29761 + wh_dentry = ERR_PTR(err);
29763 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
29764 + kfree(wh_name.name);
29766 + return wh_dentry;
29770 + * link/create a whiteout for @dentry on @bindex.
29772 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
29773 + struct dentry *h_parent)
29775 + struct dentry *wh_dentry;
29776 + struct super_block *sb;
29779 + sb = dentry->d_sb;
29780 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
29781 + if (!IS_ERR(wh_dentry) && !wh_dentry->d_inode) {
29782 + err = link_or_create_wh(sb, bindex, wh_dentry);
29784 + au_set_dbwh(dentry, bindex);
29787 + wh_dentry = ERR_PTR(err);
29791 + return wh_dentry;
29794 +/* ---------------------------------------------------------------------- */
29796 +/* Delete all whiteouts in this directory on branch bindex. */
29797 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
29798 + aufs_bindex_t bindex, struct au_branch *br)
29801 + unsigned long ul, n;
29802 + struct qstr wh_name;
29804 + struct hlist_head *head;
29805 + struct au_vdir_wh *pos;
29806 + struct au_vdir_destr *str;
29809 + p = (void *)__get_free_page(GFP_NOFS);
29810 + wh_name.name = p;
29811 + if (unlikely(!wh_name.name))
29815 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
29816 + p += AUFS_WH_PFX_LEN;
29817 + n = whlist->nh_num;
29818 + head = whlist->nh_head;
29819 + for (ul = 0; !err && ul < n; ul++, head++) {
29820 + hlist_for_each_entry(pos, head, wh_hash) {
29821 + if (pos->wh_bindex != bindex)
29824 + str = &pos->wh_str;
29825 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
29826 + memcpy(p, str->name, str->len);
29827 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
29828 + err = unlink_wh_name(h_dentry, &wh_name, br);
29833 + AuIOErr("whiteout name too long %.*s\n",
29834 + str->len, str->name);
29839 + free_page((unsigned long)wh_name.name);
29845 +struct del_wh_children_args {
29847 + struct dentry *h_dentry;
29848 + struct au_nhash *whlist;
29849 + aufs_bindex_t bindex;
29850 + struct au_branch *br;
29853 +static void call_del_wh_children(void *args)
29855 + struct del_wh_children_args *a = args;
29856 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
29859 +/* ---------------------------------------------------------------------- */
29861 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
29863 + struct au_whtmp_rmdir *whtmp;
29865 + unsigned int rdhash;
29867 + SiMustAnyLock(sb);
29869 + whtmp = kmalloc(sizeof(*whtmp), gfp);
29870 + if (unlikely(!whtmp)) {
29871 + whtmp = ERR_PTR(-ENOMEM);
29875 + whtmp->dir = NULL;
29876 + whtmp->br = NULL;
29877 + whtmp->wh_dentry = NULL;
29878 + /* no estimation for dir size */
29879 + rdhash = au_sbi(sb)->si_rdhash;
29881 + rdhash = AUFS_RDHASH_DEF;
29882 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
29883 + if (unlikely(err)) {
29885 + whtmp = ERR_PTR(err);
29892 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
29895 + atomic_dec(&whtmp->br->br_count);
29896 + dput(whtmp->wh_dentry);
29897 + iput(whtmp->dir);
29898 + au_nhash_wh_free(&whtmp->whlist);
29903 + * rmdir the whiteouted temporary named dir @h_dentry.
29904 + * @whlist: whiteouted children.
29906 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
29907 + struct dentry *wh_dentry, struct au_nhash *whlist)
29910 + struct path h_tmp;
29911 + struct inode *wh_inode, *h_dir;
29912 + struct au_branch *br;
29914 + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
29915 + IMustLock(h_dir);
29917 + br = au_sbr(dir->i_sb, bindex);
29918 + wh_inode = wh_dentry->d_inode;
29919 + mutex_lock_nested(&wh_inode->i_mutex, AuLsc_I_CHILD);
29922 + * someone else might change some whiteouts while we were sleeping.
29923 + * it means this whlist may have an obsoleted entry.
29925 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
29926 + err = del_wh_children(wh_dentry, whlist, bindex, br);
29929 + struct del_wh_children_args args = {
29931 + .h_dentry = wh_dentry,
29932 + .whlist = whlist,
29933 + .bindex = bindex,
29937 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
29938 + if (unlikely(wkq_err))
29941 + mutex_unlock(&wh_inode->i_mutex);
29944 + h_tmp.dentry = wh_dentry;
29945 + h_tmp.mnt = au_br_mnt(br);
29946 + err = vfsub_rmdir(h_dir, &h_tmp);
29950 + if (au_ibstart(dir) == bindex) {
29951 + /* todo: dir->i_mutex is necessary */
29952 + au_cpup_attr_timesizes(dir);
29953 + vfsub_drop_nlink(dir);
29955 + return 0; /* success */
29958 + pr_warn("failed removing %.*s(%d), ignored\n",
29959 + AuDLNPair(wh_dentry), err);
29963 +static void call_rmdir_whtmp(void *args)
29966 + aufs_bindex_t bindex;
29967 + struct au_whtmp_rmdir *a = args;
29968 + struct super_block *sb;
29969 + struct dentry *h_parent;
29970 + struct inode *h_dir;
29971 + struct au_hinode *hdir;
29973 + /* rmdir by nfsd may cause deadlock with this i_mutex */
29974 + /* mutex_lock(&a->dir->i_mutex); */
29976 + sb = a->dir->i_sb;
29977 + si_read_lock(sb, !AuLock_FLUSH);
29978 + if (!au_br_writable(a->br->br_perm))
29980 + bindex = au_br_index(sb, a->br->br_id);
29981 + if (unlikely(bindex < 0))
29985 + ii_write_lock_parent(a->dir);
29986 + h_parent = dget_parent(a->wh_dentry);
29987 + h_dir = h_parent->d_inode;
29988 + hdir = au_hi(a->dir, bindex);
29989 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
29990 + if (unlikely(err))
29992 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
29993 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
29996 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
29997 + au_hn_imtx_unlock(hdir);
29998 + vfsub_mnt_drop_write(au_br_mnt(a->br));
30002 + ii_write_unlock(a->dir);
30004 + /* mutex_unlock(&a->dir->i_mutex); */
30005 + au_whtmp_rmdir_free(a);
30006 + si_read_unlock(sb);
30007 + au_nwt_done(&au_sbi(sb)->si_nowait);
30008 + if (unlikely(err))
30009 + AuIOErr("err %d\n", err);
30012 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
30013 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
30016 + struct super_block *sb;
30020 + /* all post-process will be done in do_rmdir_whtmp(). */
30022 + args->dir = au_igrab(dir);
30023 + args->br = au_sbr(sb, bindex);
30024 + atomic_inc(&args->br->br_count);
30025 + args->wh_dentry = dget(wh_dentry);
30026 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
30027 + if (unlikely(wkq_err)) {
30028 + pr_warn("rmdir error %.*s (%d), ignored\n",
30029 + AuDLNPair(wh_dentry), wkq_err);
30030 + au_whtmp_rmdir_free(args);
30033 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
30034 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
30035 +++ linux/fs/aufs/whout.h 2013-07-06 13:20:47.760198800 +0200
30038 + * Copyright (C) 2005-2013 Junjiro R. Okajima
30040 + * This program, aufs is free software; you can redistribute it and/or modify
30041 + * it under the terms of the GNU General Public License as published by
30042 + * the Free Software Foundation; either version 2 of the License, or
30043 + * (at your option) any later version.
30045 + * This program is distributed in the hope that it will be useful,
30046 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30047 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30048 + * GNU General Public License for more details.
30050 + * You should have received a copy of the GNU General Public License
30051 + * along with this program; if not, write to the Free Software
30052 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30056 + * whiteout for logical deletion and opaque directory
30059 +#ifndef __AUFS_WHOUT_H__
30060 +#define __AUFS_WHOUT_H__
30067 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
30069 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name,
30070 + struct au_branch *br, int try_sio);
30071 +int au_diropq_test(struct dentry *h_dentry, struct au_branch *br);
30072 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
30073 + struct qstr *prefix);
30074 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
30075 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
30076 + struct dentry *dentry);
30077 +int au_wh_init(struct au_branch *br, struct super_block *sb);
30079 +/* diropq flags */
30080 +#define AuDiropq_CREATE 1
30081 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
30082 +#define au_fset_diropq(flags, name) \
30083 + do { (flags) |= AuDiropq_##name; } while (0)
30084 +#define au_fclr_diropq(flags, name) \
30085 + do { (flags) &= ~AuDiropq_##name; } while (0)
30087 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
30088 + unsigned int flags);
30089 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
30090 + struct au_branch *br);
30091 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
30092 + struct dentry *h_parent);
30094 +/* real rmdir for the whiteout-ed dir */
30095 +struct au_whtmp_rmdir {
30096 + struct inode *dir;
30097 + struct au_branch *br;
30098 + struct dentry *wh_dentry;
30099 + struct au_nhash whlist;
30102 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
30103 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
30104 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
30105 + struct dentry *wh_dentry, struct au_nhash *whlist);
30106 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
30107 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
30109 +/* ---------------------------------------------------------------------- */
30111 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
30112 + aufs_bindex_t bindex)
30114 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
30117 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
30119 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
30122 +#endif /* __KERNEL__ */
30123 +#endif /* __AUFS_WHOUT_H__ */
30124 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
30125 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
30126 +++ linux/fs/aufs/wkq.c 2013-08-23 23:59:39.638250372 +0200
30129 + * Copyright (C) 2005-2013 Junjiro R. Okajima
30131 + * This program, aufs is free software; you can redistribute it and/or modify
30132 + * it under the terms of the GNU General Public License as published by
30133 + * the Free Software Foundation; either version 2 of the License, or
30134 + * (at your option) any later version.
30136 + * This program is distributed in the hope that it will be useful,
30137 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30138 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30139 + * GNU General Public License for more details.
30141 + * You should have received a copy of the GNU General Public License
30142 + * along with this program; if not, write to the Free Software
30143 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30147 + * workqueue for asynchronous/super-io operations
30148 + * todo: try new dredential scheme
30151 +#include <linux/module.h>
30154 +/* internal workqueue named AUFS_WKQ_NAME */
30156 +static struct workqueue_struct *au_wkq;
30158 +struct au_wkinfo {
30159 + struct work_struct wk;
30160 + struct kobject *kobj;
30162 + unsigned int flags; /* see wkq.h */
30164 + au_wkq_func_t func;
30167 + struct completion *comp;
30170 +/* ---------------------------------------------------------------------- */
30172 +static void wkq_func(struct work_struct *wk)
30174 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
30176 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
30177 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
30179 + wkinfo->func(wkinfo->args);
30180 + if (au_ftest_wkq(wkinfo->flags, WAIT))
30181 + complete(wkinfo->comp);
30183 + kobject_put(wkinfo->kobj);
30184 + module_put(THIS_MODULE); /* todo: ?? */
30190 + * Since struct completion is large, try allocating it dynamically.
30192 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
30193 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
30195 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
30197 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
30199 + init_completion(*comp);
30200 + wkinfo->comp = *comp;
30206 +static void au_wkq_comp_free(struct completion *comp)
30214 +#define AuWkqCompDeclare(name) \
30215 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
30216 + struct completion *comp = &_ ## name
30218 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
30220 + wkinfo->comp = *comp;
30224 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
30228 +#endif /* 4KSTACKS */
30230 +static void au_wkq_run(struct au_wkinfo *wkinfo)
30232 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
30233 + if (au_wkq_test()) {
30234 + AuWarn1("wkq from wkq, due to a dead dir by UDBA?\n");
30235 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
30238 + au_dbg_verify_kthread();
30240 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
30241 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
30242 + queue_work(au_wkq, &wkinfo->wk);
30244 + INIT_WORK(&wkinfo->wk, wkq_func);
30245 + schedule_work(&wkinfo->wk);
30250 + * Be careful. It is easy to make deadlock happen.
30251 + * processA: lock, wkq and wait
30252 + * processB: wkq and wait, lock in wkq
30255 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
30258 + AuWkqCompDeclare(comp);
30259 + struct au_wkinfo wkinfo = {
30265 + err = au_wkq_comp_alloc(&wkinfo, &comp);
30267 + au_wkq_run(&wkinfo);
30268 + /* no timeout, no interrupt */
30269 + wait_for_completion(wkinfo.comp);
30270 + au_wkq_comp_free(comp);
30271 + destroy_work_on_stack(&wkinfo.wk);
30279 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
30280 + * problem in a concurrent umounting.
30282 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
30283 + unsigned int flags)
30286 + struct au_wkinfo *wkinfo;
30288 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
30291 + * wkq_func() must free this wkinfo.
30292 + * it highly depends upon the implementation of workqueue.
30295 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
30297 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
30298 + wkinfo->flags = flags & ~AuWkq_WAIT;
30299 + wkinfo->func = func;
30300 + wkinfo->args = args;
30301 + wkinfo->comp = NULL;
30302 + kobject_get(wkinfo->kobj);
30303 + __module_get(THIS_MODULE); /* todo: ?? */
30305 + au_wkq_run(wkinfo);
30308 + au_nwt_done(&au_sbi(sb)->si_nowait);
30314 +/* ---------------------------------------------------------------------- */
30316 +void au_nwt_init(struct au_nowait_tasks *nwt)
30318 + atomic_set(&nwt->nw_len, 0);
30319 + /* smp_mb(); */ /* atomic_set */
30320 + init_waitqueue_head(&nwt->nw_wq);
30323 +void au_wkq_fin(void)
30325 + destroy_workqueue(au_wkq);
30328 +int __init au_wkq_init(void)
30333 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
30334 + if (IS_ERR(au_wkq))
30335 + err = PTR_ERR(au_wkq);
30336 + else if (!au_wkq)
30341 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
30342 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
30343 +++ linux/fs/aufs/wkq.h 2013-07-06 13:20:47.760198800 +0200
30346 + * Copyright (C) 2005-2013 Junjiro R. Okajima
30348 + * This program, aufs is free software; you can redistribute it and/or modify
30349 + * it under the terms of the GNU General Public License as published by
30350 + * the Free Software Foundation; either version 2 of the License, or
30351 + * (at your option) any later version.
30353 + * This program is distributed in the hope that it will be useful,
30354 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30355 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30356 + * GNU General Public License for more details.
30358 + * You should have received a copy of the GNU General Public License
30359 + * along with this program; if not, write to the Free Software
30360 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30364 + * workqueue for asynchronous/super-io operations
30365 + * todo: try new credentials management scheme
30368 +#ifndef __AUFS_WKQ_H__
30369 +#define __AUFS_WKQ_H__
30373 +struct super_block;
30375 +/* ---------------------------------------------------------------------- */
30378 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
30380 +struct au_nowait_tasks {
30382 + wait_queue_head_t nw_wq;
30385 +/* ---------------------------------------------------------------------- */
30387 +typedef void (*au_wkq_func_t)(void *args);
30390 +#define AuWkq_WAIT 1
30391 +#define AuWkq_NEST (1 << 1)
30392 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
30393 +#define au_fset_wkq(flags, name) \
30394 + do { (flags) |= AuWkq_##name; } while (0)
30395 +#define au_fclr_wkq(flags, name) \
30396 + do { (flags) &= ~AuWkq_##name; } while (0)
30398 +#ifndef CONFIG_AUFS_HNOTIFY
30400 +#define AuWkq_NEST 0
30404 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
30405 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
30406 + unsigned int flags);
30407 +void au_nwt_init(struct au_nowait_tasks *nwt);
30408 +int __init au_wkq_init(void);
30409 +void au_wkq_fin(void);
30411 +/* ---------------------------------------------------------------------- */
30413 +static inline int au_wkq_test(void)
30415 + return current->flags & PF_WQ_WORKER;
30418 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
30420 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
30423 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
30425 + if (atomic_dec_and_test(&nwt->nw_len))
30426 + wake_up_all(&nwt->nw_wq);
30429 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
30431 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
30435 +#endif /* __KERNEL__ */
30436 +#endif /* __AUFS_WKQ_H__ */
30437 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
30438 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
30439 +++ linux/fs/aufs/xino.c 2013-07-06 13:20:47.760198800 +0200
30442 + * Copyright (C) 2005-2013 Junjiro R. Okajima
30444 + * This program, aufs is free software; you can redistribute it and/or modify
30445 + * it under the terms of the GNU General Public License as published by
30446 + * the Free Software Foundation; either version 2 of the License, or
30447 + * (at your option) any later version.
30449 + * This program is distributed in the hope that it will be useful,
30450 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30451 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30452 + * GNU General Public License for more details.
30454 + * You should have received a copy of the GNU General Public License
30455 + * along with this program; if not, write to the Free Software
30456 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30460 + * external inode number translation table and bitmap
30463 +#include <linux/seq_file.h>
30466 +/* todo: unnecessary to support mmap_sem since kernel-space? */
30467 +ssize_t xino_fread(au_readf_t func, struct file *file, void *kbuf, size_t size,
30471 + mm_segment_t oldfs;
30478 + oldfs = get_fs();
30479 + set_fs(KERNEL_DS);
30481 + /* todo: signal_pending? */
30482 + err = func(file, buf.u, size, pos);
30483 + } while (err == -EAGAIN || err == -EINTR);
30486 +#if 0 /* reserved for future use */
30488 + fsnotify_access(file->f_dentry);
30494 +/* ---------------------------------------------------------------------- */
30496 +static ssize_t do_xino_fwrite(au_writef_t func, struct file *file, void *kbuf,
30497 + size_t size, loff_t *pos)
30500 + mm_segment_t oldfs;
30503 + const char __user *u;
30507 + oldfs = get_fs();
30508 + set_fs(KERNEL_DS);
30510 + /* todo: signal_pending? */
30511 + err = func(file, buf.u, size, pos);
30512 + } while (err == -EAGAIN || err == -EINTR);
30515 +#if 0 /* reserved for future use */
30517 + fsnotify_modify(file->f_dentry);
30523 +struct do_xino_fwrite_args {
30525 + au_writef_t func;
30526 + struct file *file;
30532 +static void call_do_xino_fwrite(void *args)
30534 + struct do_xino_fwrite_args *a = args;
30535 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
30538 +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size,
30543 + /* todo: signal block and no wkq? */
30544 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
30546 + err = do_xino_fwrite(func, file, buf, size, pos);
30550 + * it breaks RLIMIT_FSIZE and normal user's limit,
30551 + * users should care about quota and real 'filesystem full.'
30554 + struct do_xino_fwrite_args args = {
30563 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
30564 + if (unlikely(wkq_err))
30571 +/* ---------------------------------------------------------------------- */
30574 + * create a new xinofile at the same place/path as @base_file.
30576 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src)
30578 + struct file *file;
30579 + struct dentry *base, *parent;
30580 + struct inode *dir;
30581 + struct qstr *name;
30582 + struct path path;
30585 + base = base_file->f_dentry;
30586 + parent = base->d_parent; /* dir inode is locked */
30587 + dir = parent->d_inode;
30590 + file = ERR_PTR(-EINVAL);
30591 + name = &base->d_name;
30592 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
30593 + if (IS_ERR(path.dentry)) {
30594 + file = (void *)path.dentry;
30595 + pr_err("%.*s lookup err %ld\n",
30596 + AuLNPair(name), PTR_ERR(path.dentry));
30600 + /* no need to mnt_want_write() since we call dentry_open() later */
30601 + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL);
30602 + if (unlikely(err)) {
30603 + file = ERR_PTR(err);
30604 + pr_err("%.*s create err %d\n", AuLNPair(name), err);
30608 + path.mnt = base_file->f_path.mnt;
30609 + file = vfsub_dentry_open(&path,
30610 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
30611 + /* | __FMODE_NONOTIFY */);
30612 + if (IS_ERR(file)) {
30613 + pr_err("%.*s open err %ld\n", AuLNPair(name), PTR_ERR(file));
30617 + err = vfsub_unlink(dir, &file->f_path, /*force*/0);
30618 + if (unlikely(err)) {
30619 + pr_err("%.*s unlink err %d\n", AuLNPair(name), err);
30624 + /* no one can touch copy_src xino */
30625 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
30626 + if (unlikely(err)) {
30627 + pr_err("%.*s copy err %d\n", AuLNPair(name), err);
30631 + goto out_dput; /* success */
30635 + file = ERR_PTR(err);
30637 + dput(path.dentry);
30642 +struct au_xino_lock_dir {
30643 + struct au_hinode *hdir;
30644 + struct dentry *parent;
30645 + struct mutex *mtx;
30648 +static void au_xino_lock_dir(struct super_block *sb, struct file *xino,
30649 + struct au_xino_lock_dir *ldir)
30651 + aufs_bindex_t brid, bindex;
30653 + ldir->hdir = NULL;
30655 + brid = au_xino_brid(sb);
30657 + bindex = au_br_index(sb, brid);
30658 + if (bindex >= 0) {
30659 + ldir->hdir = au_hi(sb->s_root->d_inode, bindex);
30660 + au_hn_imtx_lock_nested(ldir->hdir, AuLsc_I_PARENT);
30662 + ldir->parent = dget_parent(xino->f_dentry);
30663 + ldir->mtx = &ldir->parent->d_inode->i_mutex;
30664 + mutex_lock_nested(ldir->mtx, AuLsc_I_PARENT);
30668 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
30671 + au_hn_imtx_unlock(ldir->hdir);
30673 + mutex_unlock(ldir->mtx);
30674 + dput(ldir->parent);
30678 +/* ---------------------------------------------------------------------- */
30680 +/* trucate xino files asynchronously */
30682 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
30685 + aufs_bindex_t bi, bend;
30686 + struct au_branch *br;
30687 + struct file *new_xino, *file;
30688 + struct super_block *h_sb;
30689 + struct au_xino_lock_dir ldir;
30692 + bend = au_sbend(sb);
30693 + if (unlikely(bindex < 0 || bend < bindex))
30695 + br = au_sbr(sb, bindex);
30696 + file = br->br_xino.xi_file;
30700 + au_xino_lock_dir(sb, file, &ldir);
30701 + /* mnt_want_write() is unnecessary here */
30702 + new_xino = au_xino_create2(file, file);
30703 + au_xino_unlock_dir(&ldir);
30704 + err = PTR_ERR(new_xino);
30705 + if (IS_ERR(new_xino))
30709 + br->br_xino.xi_file = new_xino;
30711 + h_sb = au_br_sb(br);
30712 + for (bi = 0; bi <= bend; bi++) {
30713 + if (unlikely(bi == bindex))
30715 + br = au_sbr(sb, bi);
30716 + if (au_br_sb(br) != h_sb)
30719 + fput(br->br_xino.xi_file);
30720 + br->br_xino.xi_file = new_xino;
30721 + get_file(new_xino);
30728 +struct xino_do_trunc_args {
30729 + struct super_block *sb;
30730 + struct au_branch *br;
30733 +static void xino_do_trunc(void *_args)
30735 + struct xino_do_trunc_args *args = _args;
30736 + struct super_block *sb;
30737 + struct au_branch *br;
30738 + struct inode *dir;
30740 + aufs_bindex_t bindex;
30744 + dir = sb->s_root->d_inode;
30747 + si_noflush_write_lock(sb);
30748 + ii_read_lock_parent(dir);
30749 + bindex = au_br_index(sb, br->br_id);
30750 + err = au_xino_trunc(sb, bindex);
30752 + && file_inode(br->br_xino.xi_file)->i_blocks
30753 + >= br->br_xino_upper)
30754 + br->br_xino_upper += AUFS_XINO_TRUNC_STEP;
30756 + ii_read_unlock(dir);
30757 + if (unlikely(err))
30758 + pr_warn("err b%d, upper %llu, (%d)\n",
30759 + bindex, (unsigned long long)br->br_xino_upper, err);
30760 + atomic_dec(&br->br_xino_running);
30761 + atomic_dec(&br->br_count);
30762 + si_write_unlock(sb);
30763 + au_nwt_done(&au_sbi(sb)->si_nowait);
30767 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
30769 + struct xino_do_trunc_args *args;
30772 + if (file_inode(br->br_xino.xi_file)->i_blocks
30773 + < br->br_xino_upper)
30776 + if (atomic_inc_return(&br->br_xino_running) > 1)
30779 + /* lock and kfree() will be called in trunc_xino() */
30780 + args = kmalloc(sizeof(*args), GFP_NOFS);
30781 + if (unlikely(!args)) {
30782 + AuErr1("no memory\n");
30786 + atomic_inc(&br->br_count);
30789 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
30791 + return; /* success */
30793 + pr_err("wkq %d\n", wkq_err);
30794 + atomic_dec(&br->br_count);
30799 + atomic_dec(&br->br_xino_running);
30802 +/* ---------------------------------------------------------------------- */
30804 +static int au_xino_do_write(au_writef_t write, struct file *file,
30805 + ino_t h_ino, ino_t ino)
30811 + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) {
30812 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
30815 + pos *= sizeof(ino);
30816 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos);
30817 + if (sz == sizeof(ino))
30818 + return 0; /* success */
30820 + AuIOErr("write failed (%zd)\n", sz);
30825 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
30826 + * at the position of @h_ino.
30827 + * even if @ino is zero, it is written to the xinofile and means no entry.
30828 + * if the size of the xino file on a specific filesystem exceeds the watermark,
30829 + * try truncating it.
30831 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
30835 + unsigned int mnt_flags;
30836 + struct au_branch *br;
30838 + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max)
30839 + || ((loff_t)-1) > 0);
30840 + SiMustAnyLock(sb);
30842 + mnt_flags = au_mntflags(sb);
30843 + if (!au_opt_test(mnt_flags, XINO))
30846 + br = au_sbr(sb, bindex);
30847 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
30850 + if (au_opt_test(mnt_flags, TRUNC_XINO)
30851 + && au_test_fs_trunc_xino(au_br_sb(br)))
30852 + xino_try_trunc(sb, br);
30853 + return 0; /* success */
30856 + AuIOErr("write failed (%d)\n", err);
30860 +/* ---------------------------------------------------------------------- */
30862 +/* aufs inode number bitmap */
30864 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
30865 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
30869 + AuDebugOn(bit < 0 || page_bits <= bit);
30870 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
30874 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
30876 + AuDebugOn(ino < AUFS_FIRST_INO);
30877 + ino -= AUFS_FIRST_INO;
30878 + *pindex = ino / page_bits;
30879 + *bit = ino % page_bits;
30882 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
30887 + struct au_sbinfo *sbinfo;
30888 + struct file *xib;
30889 + unsigned long *p;
30891 + sbinfo = au_sbi(sb);
30892 + MtxMustLock(&sbinfo->si_xib_mtx);
30893 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
30894 + || !au_opt_test(sbinfo->si_mntflags, XINO));
30896 + if (pindex == sbinfo->si_xib_last_pindex)
30899 + xib = sbinfo->si_xib;
30900 + p = sbinfo->si_xib_buf;
30901 + pos = sbinfo->si_xib_last_pindex;
30902 + pos *= PAGE_SIZE;
30903 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
30904 + if (unlikely(sz != PAGE_SIZE))
30908 + pos *= PAGE_SIZE;
30909 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
30910 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
30912 + memset(p, 0, PAGE_SIZE);
30913 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
30915 + if (sz == PAGE_SIZE) {
30916 + sbinfo->si_xib_last_pindex = pindex;
30917 + return 0; /* success */
30921 + AuIOErr1("write failed (%zd)\n", sz);
30928 +/* ---------------------------------------------------------------------- */
30930 +static void au_xib_clear_bit(struct inode *inode)
30933 + unsigned long pindex;
30934 + struct super_block *sb;
30935 + struct au_sbinfo *sbinfo;
30937 + AuDebugOn(inode->i_nlink);
30939 + sb = inode->i_sb;
30940 + xib_calc_bit(inode->i_ino, &pindex, &bit);
30941 + AuDebugOn(page_bits <= bit);
30942 + sbinfo = au_sbi(sb);
30943 + mutex_lock(&sbinfo->si_xib_mtx);
30944 + err = xib_pindex(sb, pindex);
30946 + clear_bit(bit, sbinfo->si_xib_buf);
30947 + sbinfo->si_xib_next_bit = bit;
30949 + mutex_unlock(&sbinfo->si_xib_mtx);
30952 +/* for s_op->delete_inode() */
30953 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
30956 + unsigned int mnt_flags;
30957 + aufs_bindex_t bindex, bend, bi;
30958 + unsigned char try_trunc;
30959 + struct au_iinfo *iinfo;
30960 + struct super_block *sb;
30961 + struct au_hinode *hi;
30962 + struct inode *h_inode;
30963 + struct au_branch *br;
30964 + au_writef_t xwrite;
30966 + sb = inode->i_sb;
30967 + mnt_flags = au_mntflags(sb);
30968 + if (!au_opt_test(mnt_flags, XINO)
30969 + || inode->i_ino == AUFS_ROOT_INO)
30973 + au_xigen_inc(inode);
30974 + au_xib_clear_bit(inode);
30977 + iinfo = au_ii(inode);
30981 + bindex = iinfo->ii_bstart;
30985 + xwrite = au_sbi(sb)->si_xwrite;
30986 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
30987 + hi = iinfo->ii_hinode + bindex;
30988 + bend = iinfo->ii_bend;
30989 + for (; bindex <= bend; bindex++, hi++) {
30990 + h_inode = hi->hi_inode;
30992 + || (!unlinked && h_inode->i_nlink))
30995 + /* inode may not be revalidated */
30996 + bi = au_br_index(sb, hi->hi_id);
31000 + br = au_sbr(sb, bi);
31001 + err = au_xino_do_write(xwrite, br->br_xino.xi_file,
31002 + h_inode->i_ino, /*ino*/0);
31003 + if (!err && try_trunc
31004 + && au_test_fs_trunc_xino(au_br_sb(br)))
31005 + xino_try_trunc(sb, br);
31009 +/* get an unused inode number from bitmap */
31010 +ino_t au_xino_new_ino(struct super_block *sb)
31013 + unsigned long *p, pindex, ul, pend;
31014 + struct au_sbinfo *sbinfo;
31015 + struct file *file;
31016 + int free_bit, err;
31018 + if (!au_opt_test(au_mntflags(sb), XINO))
31019 + return iunique(sb, AUFS_FIRST_INO);
31021 + sbinfo = au_sbi(sb);
31022 + mutex_lock(&sbinfo->si_xib_mtx);
31023 + p = sbinfo->si_xib_buf;
31024 + free_bit = sbinfo->si_xib_next_bit;
31025 + if (free_bit < page_bits && !test_bit(free_bit, p))
31026 + goto out; /* success */
31027 + free_bit = find_first_zero_bit(p, page_bits);
31028 + if (free_bit < page_bits)
31029 + goto out; /* success */
31031 + pindex = sbinfo->si_xib_last_pindex;
31032 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
31033 + err = xib_pindex(sb, ul);
31034 + if (unlikely(err))
31036 + free_bit = find_first_zero_bit(p, page_bits);
31037 + if (free_bit < page_bits)
31038 + goto out; /* success */
31041 + file = sbinfo->si_xib;
31042 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
31043 + for (ul = pindex + 1; ul <= pend; ul++) {
31044 + err = xib_pindex(sb, ul);
31045 + if (unlikely(err))
31047 + free_bit = find_first_zero_bit(p, page_bits);
31048 + if (free_bit < page_bits)
31049 + goto out; /* success */
31054 + set_bit(free_bit, p);
31055 + sbinfo->si_xib_next_bit = free_bit + 1;
31056 + pindex = sbinfo->si_xib_last_pindex;
31057 + mutex_unlock(&sbinfo->si_xib_mtx);
31058 + ino = xib_calc_ino(pindex, free_bit);
31059 + AuDbg("i%lu\n", (unsigned long)ino);
31062 + mutex_unlock(&sbinfo->si_xib_mtx);
31068 + * read @ino from xinofile for the specified branch{@sb, @bindex}
31069 + * at the position of @h_ino.
31070 + * if @ino does not exist and @do_new is true, get new one.
31072 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
31078 + struct file *file;
31079 + struct au_sbinfo *sbinfo;
31082 + if (!au_opt_test(au_mntflags(sb), XINO))
31083 + return 0; /* no xino */
31086 + sbinfo = au_sbi(sb);
31088 + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) {
31089 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
31092 + pos *= sizeof(*ino);
31094 + file = au_sbr(sb, bindex)->br_xino.xi_file;
31095 + if (vfsub_f_size_read(file) < pos + sizeof(*ino))
31096 + return 0; /* no ino */
31098 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
31099 + if (sz == sizeof(*ino))
31100 + return 0; /* success */
31103 + if (unlikely(sz >= 0)) {
31105 + AuIOErr("xino read error (%zd)\n", sz);
31111 +/* ---------------------------------------------------------------------- */
31113 +/* create and set a new xino file */
31115 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent)
31117 + struct file *file;
31118 + struct dentry *h_parent, *d;
31119 + struct inode *h_dir;
31123 + * at mount-time, and the xino file is the default path,
31124 + * hnotify is disabled so we have no notify events to ignore.
31125 + * when a user specified the xino, we cannot get au_hdir to be ignored.
31127 + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
31128 + /* | __FMODE_NONOTIFY */,
31129 + S_IRUGO | S_IWUGO);
31130 + if (IS_ERR(file)) {
31132 + pr_err("open %s(%ld)\n", fname, PTR_ERR(file));
31136 + /* keep file count */
31137 + h_parent = dget_parent(file->f_dentry);
31138 + h_dir = h_parent->d_inode;
31139 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
31140 + /* mnt_want_write() is unnecessary here */
31141 + err = vfsub_unlink(h_dir, &file->f_path, /*force*/0);
31142 + mutex_unlock(&h_dir->i_mutex);
31144 + if (unlikely(err)) {
31146 + pr_err("unlink %s(%d)\n", fname, err);
31151 + d = file->f_dentry;
31152 + if (unlikely(sb == d->d_sb)) {
31154 + pr_err("%s must be outside\n", fname);
31157 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
31159 + pr_err("xino doesn't support %s(%s)\n",
31160 + fname, au_sbtype(d->d_sb));
31163 + return file; /* success */
31167 + file = ERR_PTR(err);
31172 + * find another branch who is on the same filesystem of the specified
31173 + * branch{@btgt}. search until @bend.
31175 +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
31176 + aufs_bindex_t bend)
31178 + aufs_bindex_t bindex;
31179 + struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
31181 + for (bindex = 0; bindex < btgt; bindex++)
31182 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
31184 + for (bindex++; bindex <= bend; bindex++)
31185 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
31190 +/* ---------------------------------------------------------------------- */
31193 + * initialize the xinofile for the specified branch @br
31194 + * at the place/path where @base_file indicates.
31195 + * test whether another branch is on the same filesystem or not,
31196 + * if @do_test is true.
31198 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
31199 + struct file *base_file, int do_test)
31203 + aufs_bindex_t bend, bindex;
31204 + struct au_branch *shared_br, *b;
31205 + struct file *file;
31206 + struct super_block *tgt_sb;
31208 + shared_br = NULL;
31209 + bend = au_sbend(sb);
31211 + tgt_sb = au_br_sb(br);
31212 + for (bindex = 0; bindex <= bend; bindex++) {
31213 + b = au_sbr(sb, bindex);
31214 + if (tgt_sb == au_br_sb(b)) {
31221 + if (!shared_br || !shared_br->br_xino.xi_file) {
31222 + struct au_xino_lock_dir ldir;
31224 + au_xino_lock_dir(sb, base_file, &ldir);
31225 + /* mnt_want_write() is unnecessary here */
31226 + file = au_xino_create2(base_file, NULL);
31227 + au_xino_unlock_dir(&ldir);
31228 + err = PTR_ERR(file);
31229 + if (IS_ERR(file))
31231 + br->br_xino.xi_file = file;
31233 + br->br_xino.xi_file = shared_br->br_xino.xi_file;
31234 + get_file(br->br_xino.xi_file);
31237 + ino = AUFS_ROOT_INO;
31238 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
31240 + if (unlikely(err)) {
31241 + fput(br->br_xino.xi_file);
31242 + br->br_xino.xi_file = NULL;
31249 +/* ---------------------------------------------------------------------- */
31251 +/* trucate a xino bitmap file */
31254 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
31258 + unsigned long pindex;
31259 + loff_t pos, pend;
31260 + struct au_sbinfo *sbinfo;
31263 + unsigned long *p;
31266 + sbinfo = au_sbi(sb);
31267 + MtxMustLock(&sbinfo->si_xib_mtx);
31268 + p = sbinfo->si_xib_buf;
31269 + func = sbinfo->si_xread;
31270 + pend = vfsub_f_size_read(file);
31272 + while (pos < pend) {
31273 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
31275 + if (unlikely(sz <= 0))
31279 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
31280 + if (unlikely(*ino < AUFS_FIRST_INO))
31283 + xib_calc_bit(*ino, &pindex, &bit);
31284 + AuDebugOn(page_bits <= bit);
31285 + err = xib_pindex(sb, pindex);
31297 +static int xib_restore(struct super_block *sb)
31300 + aufs_bindex_t bindex, bend;
31304 + page = (void *)__get_free_page(GFP_NOFS);
31305 + if (unlikely(!page))
31309 + bend = au_sbend(sb);
31310 + for (bindex = 0; !err && bindex <= bend; bindex++)
31311 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
31312 + err = do_xib_restore
31313 + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page);
31315 + AuDbg("b%d\n", bindex);
31316 + free_page((unsigned long)page);
31322 +int au_xib_trunc(struct super_block *sb)
31327 + struct au_xino_lock_dir ldir;
31328 + struct au_sbinfo *sbinfo;
31329 + unsigned long *p;
31330 + struct file *file;
31332 + SiMustWriteLock(sb);
31335 + sbinfo = au_sbi(sb);
31336 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
31339 + file = sbinfo->si_xib;
31340 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
31343 + au_xino_lock_dir(sb, file, &ldir);
31344 + /* mnt_want_write() is unnecessary here */
31345 + file = au_xino_create2(sbinfo->si_xib, NULL);
31346 + au_xino_unlock_dir(&ldir);
31347 + err = PTR_ERR(file);
31348 + if (IS_ERR(file))
31350 + fput(sbinfo->si_xib);
31351 + sbinfo->si_xib = file;
31353 + p = sbinfo->si_xib_buf;
31354 + memset(p, 0, PAGE_SIZE);
31356 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
31357 + if (unlikely(sz != PAGE_SIZE)) {
31359 + AuIOErr("err %d\n", err);
31365 + mutex_lock(&sbinfo->si_xib_mtx);
31366 + /* mnt_want_write() is unnecessary here */
31367 + err = xib_restore(sb);
31368 + mutex_unlock(&sbinfo->si_xib_mtx);
31374 +/* ---------------------------------------------------------------------- */
31377 + * xino mount option handlers
31379 +static au_readf_t find_readf(struct file *h_file)
31381 + const struct file_operations *fop = h_file->f_op;
31385 + return fop->read;
31386 + if (fop->aio_read)
31387 + return do_sync_read;
31389 + return ERR_PTR(-ENOSYS);
31392 +static au_writef_t find_writef(struct file *h_file)
31394 + const struct file_operations *fop = h_file->f_op;
31398 + return fop->write;
31399 + if (fop->aio_write)
31400 + return do_sync_write;
31402 + return ERR_PTR(-ENOSYS);
31406 +static void xino_clear_xib(struct super_block *sb)
31408 + struct au_sbinfo *sbinfo;
31410 + SiMustWriteLock(sb);
31412 + sbinfo = au_sbi(sb);
31413 + sbinfo->si_xread = NULL;
31414 + sbinfo->si_xwrite = NULL;
31415 + if (sbinfo->si_xib)
31416 + fput(sbinfo->si_xib);
31417 + sbinfo->si_xib = NULL;
31418 + free_page((unsigned long)sbinfo->si_xib_buf);
31419 + sbinfo->si_xib_buf = NULL;
31422 +static int au_xino_set_xib(struct super_block *sb, struct file *base)
31426 + struct au_sbinfo *sbinfo;
31427 + struct file *file;
31429 + SiMustWriteLock(sb);
31431 + sbinfo = au_sbi(sb);
31432 + file = au_xino_create2(base, sbinfo->si_xib);
31433 + err = PTR_ERR(file);
31434 + if (IS_ERR(file))
31436 + if (sbinfo->si_xib)
31437 + fput(sbinfo->si_xib);
31438 + sbinfo->si_xib = file;
31439 + sbinfo->si_xread = find_readf(file);
31440 + sbinfo->si_xwrite = find_writef(file);
31443 + if (!sbinfo->si_xib_buf)
31444 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
31445 + if (unlikely(!sbinfo->si_xib_buf))
31448 + sbinfo->si_xib_last_pindex = 0;
31449 + sbinfo->si_xib_next_bit = 0;
31450 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
31452 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
31453 + PAGE_SIZE, &pos);
31454 + if (unlikely(err != PAGE_SIZE))
31458 + goto out; /* success */
31461 + free_page((unsigned long)sbinfo->si_xib_buf);
31462 + sbinfo->si_xib_buf = NULL;
31466 + fput(sbinfo->si_xib);
31467 + sbinfo->si_xib = NULL;
31468 + sbinfo->si_xread = NULL;
31469 + sbinfo->si_xwrite = NULL;
31474 +/* xino for each branch */
31475 +static void xino_clear_br(struct super_block *sb)
31477 + aufs_bindex_t bindex, bend;
31478 + struct au_branch *br;
31480 + bend = au_sbend(sb);
31481 + for (bindex = 0; bindex <= bend; bindex++) {
31482 + br = au_sbr(sb, bindex);
31483 + if (!br || !br->br_xino.xi_file)
31486 + fput(br->br_xino.xi_file);
31487 + br->br_xino.xi_file = NULL;
31491 +static int au_xino_set_br(struct super_block *sb, struct file *base)
31495 + aufs_bindex_t bindex, bend, bshared;
31497 + struct file *old, *new;
31499 + struct au_branch *br;
31500 + struct inode *inode;
31501 + au_writef_t writef;
31503 + SiMustWriteLock(sb);
31506 + bend = au_sbend(sb);
31507 + fpair = kcalloc(bend + 1, sizeof(*fpair), GFP_NOFS);
31508 + if (unlikely(!fpair))
31511 + inode = sb->s_root->d_inode;
31512 + ino = AUFS_ROOT_INO;
31513 + writef = au_sbi(sb)->si_xwrite;
31514 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
31515 + br = au_sbr(sb, bindex);
31516 + bshared = is_sb_shared(sb, bindex, bindex - 1);
31517 + if (bshared >= 0) {
31518 + /* shared xino */
31519 + *p = fpair[bshared];
31520 + get_file(p->new);
31525 + p->old = br->br_xino.xi_file;
31526 + p->new = au_xino_create2(base, br->br_xino.xi_file);
31527 + err = PTR_ERR(p->new);
31528 + if (IS_ERR(p->new)) {
31534 + err = au_xino_do_write(writef, p->new,
31535 + au_h_iptr(inode, bindex)->i_ino, ino);
31536 + if (unlikely(err))
31540 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
31541 + br = au_sbr(sb, bindex);
31542 + if (br->br_xino.xi_file)
31543 + fput(br->br_xino.xi_file);
31544 + get_file(p->new);
31545 + br->br_xino.xi_file = p->new;
31549 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++)
31559 +void au_xino_clr(struct super_block *sb)
31561 + struct au_sbinfo *sbinfo;
31563 + au_xigen_clr(sb);
31564 + xino_clear_xib(sb);
31565 + xino_clear_br(sb);
31566 + sbinfo = au_sbi(sb);
31567 + /* lvalue, do not call au_mntflags() */
31568 + au_opt_clr(sbinfo->si_mntflags, XINO);
31571 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
31574 + struct dentry *parent, *cur_parent;
31575 + struct qstr *dname, *cur_name;
31576 + struct file *cur_xino;
31577 + struct inode *dir;
31578 + struct au_sbinfo *sbinfo;
31580 + SiMustWriteLock(sb);
31583 + sbinfo = au_sbi(sb);
31584 + parent = dget_parent(xino->file->f_dentry);
31587 + dname = &xino->file->f_dentry->d_name;
31588 + cur_xino = sbinfo->si_xib;
31590 + cur_parent = dget_parent(cur_xino->f_dentry);
31591 + cur_name = &cur_xino->f_dentry->d_name;
31592 + skip = (cur_parent == parent
31593 + && dname->len == cur_name->len
31594 + && !memcmp(dname->name, cur_name->name,
31596 + dput(cur_parent);
31602 + au_opt_set(sbinfo->si_mntflags, XINO);
31603 + dir = parent->d_inode;
31604 + mutex_lock_nested(&dir->i_mutex, AuLsc_I_PARENT);
31605 + /* mnt_want_write() is unnecessary here */
31606 + err = au_xino_set_xib(sb, xino->file);
31608 + err = au_xigen_set(sb, xino->file);
31610 + err = au_xino_set_br(sb, xino->file);
31611 + mutex_unlock(&dir->i_mutex);
31613 + goto out; /* success */
31616 + AuIOErr("failed creating xino(%d).\n", err);
31623 +/* ---------------------------------------------------------------------- */
31626 + * create a xinofile at the default place/path.
31628 +struct file *au_xino_def(struct super_block *sb)
31630 + struct file *file;
31632 + struct au_branch *br;
31633 + struct super_block *h_sb;
31634 + struct path path;
31635 + aufs_bindex_t bend, bindex, bwr;
31638 + bend = au_sbend(sb);
31640 + for (bindex = 0; bindex <= bend; bindex++) {
31641 + br = au_sbr(sb, bindex);
31642 + if (au_br_writable(br->br_perm)
31643 + && !au_test_fs_bad_xino(au_br_sb(br))) {
31650 + file = ERR_PTR(-ENOMEM);
31651 + page = (void *)__get_free_page(GFP_NOFS);
31652 + if (unlikely(!page))
31654 + path.mnt = au_br_mnt(br);
31655 + path.dentry = au_h_dptr(sb->s_root, bwr);
31656 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
31657 + file = (void *)p;
31658 + if (!IS_ERR(p)) {
31659 + strcat(p, "/" AUFS_XINO_FNAME);
31660 + AuDbg("%s\n", p);
31661 + file = au_xino_create(sb, p, /*silent*/0);
31662 + if (!IS_ERR(file))
31663 + au_xino_brid_set(sb, br->br_id);
31665 + free_page((unsigned long)page);
31667 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
31668 + if (IS_ERR(file))
31670 + h_sb = file->f_dentry->d_sb;
31671 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
31672 + pr_err("xino doesn't support %s(%s)\n",
31673 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
31675 + file = ERR_PTR(-EINVAL);
31677 + if (!IS_ERR(file))
31678 + au_xino_brid_set(sb, -1);
31685 +/* ---------------------------------------------------------------------- */
31687 +int au_xino_path(struct seq_file *seq, struct file *file)
31691 + err = au_seq_path(seq, &file->f_path);
31692 + if (unlikely(err < 0))
31696 +#define Deleted "\\040(deleted)"
31697 + seq->count -= sizeof(Deleted) - 1;
31698 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
31699 + sizeof(Deleted) - 1));
31705 diff -urN /usr/share/empty/include/linux/aufs_type.h linux/include/linux/aufs_type.h
31706 --- /usr/share/empty/include/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
31707 +++ linux/include/linux/aufs_type.h 2013-07-06 13:20:47.760198800 +0200
31710 + * Copyright (C) 2012-2013 Junjiro R. Okajima
31712 + * This program, aufs is free software; you can redistribute it and/or modify
31713 + * it under the terms of the GNU General Public License as published by
31714 + * the Free Software Foundation; either version 2 of the License, or
31715 + * (at your option) any later version.
31717 + * This program is distributed in the hope that it will be useful,
31718 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31719 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31720 + * GNU General Public License for more details.
31722 + * You should have received a copy of the GNU General Public License
31723 + * along with this program; if not, write to the Free Software
31724 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31727 +#include <uapi/linux/aufs_type.h>
31728 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
31729 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
31730 +++ linux/include/uapi/linux/aufs_type.h 2013-08-23 23:59:39.638250372 +0200
31733 + * Copyright (C) 2005-2013 Junjiro R. Okajima
31735 + * This program, aufs is free software; you can redistribute it and/or modify
31736 + * it under the terms of the GNU General Public License as published by
31737 + * the Free Software Foundation; either version 2 of the License, or
31738 + * (at your option) any later version.
31740 + * This program is distributed in the hope that it will be useful,
31741 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31742 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31743 + * GNU General Public License for more details.
31745 + * You should have received a copy of the GNU General Public License
31746 + * along with this program; if not, write to the Free Software
31747 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31750 +#ifndef __AUFS_TYPE_H__
31751 +#define __AUFS_TYPE_H__
31753 +#define AUFS_NAME "aufs"
31757 + * define it before including all other headers.
31758 + * sched.h may use pr_* macros before defining "current", so define the
31759 + * no-current version first, and re-define later.
31761 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
31762 +#include <linux/sched.h>
31764 +#define pr_fmt(fmt) \
31765 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
31766 + (int)sizeof(current->comm), current->comm, current->pid
31768 +#include <stdint.h>
31769 +#include <sys/types.h>
31770 +#endif /* __KERNEL__ */
31772 +#include <linux/limits.h>
31774 +#define AUFS_VERSION "3.10-20130819"
31776 +/* todo? move this to linux-2.6.19/include/magic.h */
31777 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
31779 +/* ---------------------------------------------------------------------- */
31781 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
31782 +typedef int8_t aufs_bindex_t;
31783 +#define AUFS_BRANCH_MAX 127
31785 +typedef int16_t aufs_bindex_t;
31786 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
31787 +#define AUFS_BRANCH_MAX 511
31788 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
31789 +#define AUFS_BRANCH_MAX 1023
31790 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
31791 +#define AUFS_BRANCH_MAX 32767
31796 +#ifndef AUFS_BRANCH_MAX
31797 +#error unknown CONFIG_AUFS_BRANCH_MAX value
31799 +#endif /* __KERNEL__ */
31801 +/* ---------------------------------------------------------------------- */
31803 +#define AUFS_FSTYPE AUFS_NAME
31805 +#define AUFS_ROOT_INO 2
31806 +#define AUFS_FIRST_INO 11
31808 +#define AUFS_WH_PFX ".wh."
31809 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
31810 +#define AUFS_WH_TMP_LEN 4
31811 +/* a limit for rmdir/rename a dir and copyup */
31812 +#define AUFS_MAX_NAMELEN (NAME_MAX \
31813 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
31815 + - AUFS_WH_TMP_LEN) /* hex */
31816 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
31817 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
31818 +#define AUFS_XINO_TRUNC_INIT 64 /* blocks */
31819 +#define AUFS_XINO_TRUNC_STEP 4 /* blocks */
31820 +#define AUFS_DIRWH_DEF 3
31821 +#define AUFS_RDCACHE_DEF 10 /* seconds */
31822 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
31823 +#define AUFS_RDBLK_DEF 512 /* bytes */
31824 +#define AUFS_RDHASH_DEF 32
31825 +#define AUFS_WKQ_NAME AUFS_NAME "d"
31826 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
31827 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
31828 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
31830 +/* pseudo-link maintenace under /proc */
31831 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
31832 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
31833 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
31835 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
31836 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
31838 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
31839 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
31840 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
31842 +/* doubly whiteouted */
31843 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
31844 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
31845 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
31847 +/* branch permissions and attributes */
31848 +#define AUFS_BRPERM_RW "rw"
31849 +#define AUFS_BRPERM_RO "ro"
31850 +#define AUFS_BRPERM_RR "rr"
31851 +#define AUFS_BRRATTR_WH "wh"
31852 +#define AUFS_BRWATTR_NLWH "nolwh"
31853 +#define AUFS_BRATTR_UNPIN "unpin"
31855 +/* ---------------------------------------------------------------------- */
31859 + /* readdir in userspace */
31863 + /* pathconf wrapper */
31873 +/* borrowed from linux/include/linux/kernel.h */
31875 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
31876 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
31879 +/* borrowed from linux/include/linux/compiler-gcc3.h */
31881 +#define __aligned(x) __attribute__((aligned(x)))
31886 +#define __packed __attribute__((packed))
31890 +struct au_rdu_cookie {
31895 + uint32_t generation;
31898 +struct au_rdu_ent {
31907 +static inline int au_rdu_len(int nlen)
31909 + /* include the terminating NULL */
31910 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
31911 + sizeof(uint64_t));
31914 +union au_rdu_ent_ul {
31915 + struct au_rdu_ent __user *e;
31927 + uint64_t sz; /* AuCtl_RDU */
31928 + uint64_t nent; /* AuCtl_RDU_INO */
31930 + union au_rdu_ent_ul ent;
31931 + uint16_t verify[AufsCtlRduV_End];
31933 + /* input/output */
31937 + union au_rdu_ent_ul tail;
31938 + /* number of entries which were added in a single call */
31943 + struct au_rdu_cookie cookie;
31946 +/* ---------------------------------------------------------------------- */
31948 +struct aufs_wbr_fd {
31953 +/* ---------------------------------------------------------------------- */
31955 +struct aufs_ibusy {
31956 + uint64_t ino, h_ino;
31960 +/* ---------------------------------------------------------------------- */
31962 +/* flags for move-down */
31963 +#define AUFS_MVDOWN_VERBOSE 1
31964 +/* will be added more */
31966 +struct aufs_mvdown {
31968 + /* will be added more */
31971 +/* ---------------------------------------------------------------------- */
31973 +#define AuCtlType 'A'
31974 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
31975 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
31976 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
31977 + struct aufs_wbr_fd)
31978 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
31979 +#define AUFS_CTL_MVDOWN _IOR(AuCtlType, AuCtl_MVDOWN, \
31980 + struct aufs_mvdown)
31982 +#endif /* __AUFS_TYPE_H__ */