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/inode.c b/fs/inode.c
39 index 00d5fc3..f324521 100644
42 @@ -1498,7 +1498,7 @@ static int relatime_need_update(struct vfsmount *mnt, struct inode *inode,
43 * This does the actual work of updating an inodes time or version. Must have
44 * had called mnt_want_write() before calling this.
46 -static int update_time(struct inode *inode, struct timespec *time, int flags)
47 +int update_time(struct inode *inode, struct timespec *time, int flags)
49 if (inode->i_op->update_time)
50 return inode->i_op->update_time(inode, time, flags);
51 diff --git a/fs/splice.c b/fs/splice.c
52 index d37431d..987346f 100644
55 @@ -1093,8 +1093,8 @@ EXPORT_SYMBOL(generic_splice_sendpage);
57 * Attempt to initiate a splice from pipe to file.
59 -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
60 - loff_t *ppos, size_t len, unsigned int flags)
61 +long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
62 + loff_t *ppos, size_t len, unsigned int flags)
64 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
65 loff_t *, size_t, unsigned int);
66 @@ -1124,9 +1124,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
68 * Attempt to initiate a splice from a file to a pipe.
70 -static long do_splice_to(struct file *in, loff_t *ppos,
71 - struct pipe_inode_info *pipe, size_t len,
73 +long do_splice_to(struct file *in, loff_t *ppos,
74 + struct pipe_inode_info *pipe, size_t len,
77 ssize_t (*splice_read)(struct file *, loff_t *,
78 struct pipe_inode_info *, size_t, unsigned int);
79 diff --git a/include/linux/fs.h b/include/linux/fs.h
80 index 65c2be2..0148214 100644
81 --- a/include/linux/fs.h
82 +++ b/include/linux/fs.h
83 @@ -2574,6 +2574,7 @@ extern int inode_change_ok(const struct inode *, struct iattr *);
84 extern int inode_newsize_ok(const struct inode *, loff_t offset);
85 extern void setattr_copy(struct inode *inode, const struct iattr *attr);
87 +extern int update_time(struct inode *, struct timespec *, int);
88 extern int file_update_time(struct file *file);
90 extern int generic_show_options(struct seq_file *m, struct dentry *root);
91 diff --git a/include/linux/splice.h b/include/linux/splice.h
92 index 74575cb..bfc6fb6 100644
93 --- a/include/linux/splice.h
94 +++ b/include/linux/splice.h
95 @@ -92,4 +92,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
96 extern void spd_release_page(struct splice_pipe_desc *, unsigned int);
98 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
100 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
101 + loff_t *ppos, size_t len, unsigned int flags);
102 +extern long do_splice_to(struct file *in, loff_t *ppos,
103 + struct pipe_inode_info *pipe, size_t len,
104 + unsigned int flags);
106 aufs3.10 standalone patch
108 diff --git a/fs/inode.c b/fs/inode.c
109 index f324521..bff7670 100644
112 @@ -56,6 +56,7 @@ static struct hlist_head *inode_hashtable __read_mostly;
113 static __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_hash_lock);
115 __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_sb_list_lock);
116 +EXPORT_SYMBOL(inode_sb_list_lock);
119 * Empty aops. Can be used for the cases where the user does not
120 @@ -1514,6 +1515,7 @@ int update_time(struct inode *inode, struct timespec *time, int flags)
121 mark_inode_dirty_sync(inode);
124 +EXPORT_SYMBOL(update_time);
127 * touch_atime - update the access time
128 diff --git a/fs/namespace.c b/fs/namespace.c
129 index 7b1ca9b..51db6ad 100644
132 @@ -54,6 +54,7 @@ EXPORT_SYMBOL_GPL(fs_kobj);
133 * tree or hash is modified or when a vfsmount structure is modified.
135 DEFINE_BRLOCK(vfsmount_lock);
136 +EXPORT_SYMBOL(vfsmount_lock);
138 static inline unsigned long hash(struct vfsmount *mnt, struct dentry *dentry)
140 @@ -427,6 +428,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
141 mnt_dec_writers(real_mount(mnt));
144 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
147 * mnt_drop_write - give up write access to a mount
148 @@ -1456,6 +1458,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
152 +EXPORT_SYMBOL(iterate_mounts);
154 static void cleanup_group_ids(struct mount *mnt, struct mount *end)
156 diff --git a/fs/notify/group.c b/fs/notify/group.c
157 index bd2625b..2ff2a0f 100644
158 --- a/fs/notify/group.c
159 +++ b/fs/notify/group.c
161 #include <linux/srcu.h>
162 #include <linux/rculist.h>
163 #include <linux/wait.h>
164 +#include <linux/module.h>
166 #include <linux/fsnotify_backend.h>
167 #include "fsnotify.h"
168 @@ -65,6 +66,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
170 atomic_inc(&group->refcnt);
172 +EXPORT_SYMBOL(fsnotify_get_group);
175 * Drop a reference to a group. Free it if it's through.
176 @@ -74,6 +76,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
177 if (atomic_dec_and_test(&group->refcnt))
178 fsnotify_final_destroy_group(group);
180 +EXPORT_SYMBOL(fsnotify_put_group);
183 * Create a new fsnotify_group and hold a reference for the group returned.
184 @@ -102,6 +105,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
188 +EXPORT_SYMBOL(fsnotify_alloc_group);
190 int fsnotify_fasync(int fd, struct file *file, int on)
192 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
193 index fc6b49b..a6bb87d 100644
194 --- a/fs/notify/mark.c
195 +++ b/fs/notify/mark.c
196 @@ -115,6 +115,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
197 mark->free_mark(mark);
200 +EXPORT_SYMBOL(fsnotify_put_mark);
203 * Any time a mark is getting freed we end up here.
204 @@ -197,6 +198,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
205 fsnotify_destroy_mark_locked(mark, group);
206 mutex_unlock(&group->mark_mutex);
208 +EXPORT_SYMBOL(fsnotify_destroy_mark);
210 void fsnotify_set_mark_mask_locked(struct fsnotify_mark *mark, __u32 mask)
212 @@ -281,6 +283,7 @@ err:
216 +EXPORT_SYMBOL(fsnotify_add_mark);
218 int fsnotify_add_mark(struct fsnotify_mark *mark, struct fsnotify_group *group,
219 struct inode *inode, struct vfsmount *mnt, int allow_dups)
220 @@ -342,6 +345,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
221 atomic_set(&mark->refcnt, 1);
222 mark->free_mark = free_mark;
224 +EXPORT_SYMBOL(fsnotify_init_mark);
226 static int fsnotify_mark_destroy(void *ignored)
228 diff --git a/fs/open.c b/fs/open.c
229 index 8c74100..be563cd 100644
232 @@ -61,6 +61,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
233 mutex_unlock(&dentry->d_inode->i_mutex);
236 +EXPORT_SYMBOL(do_truncate);
238 long vfs_truncate(struct path *path, loff_t length)
240 diff --git a/fs/splice.c b/fs/splice.c
241 index 987346f..8d6a045 100644
244 @@ -1120,6 +1120,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
248 +EXPORT_SYMBOL(do_splice_from);
251 * Attempt to initiate a splice from a file to a pipe.
252 @@ -1146,6 +1147,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
254 return splice_read(in, ppos, pipe, len, flags);
256 +EXPORT_SYMBOL(do_splice_to);
259 * splice_direct_to_actor - splices data directly between two non-pipes
260 diff --git a/security/commoncap.c b/security/commoncap.c
261 index c44b6fe..d78b003 100644
262 --- a/security/commoncap.c
263 +++ b/security/commoncap.c
264 @@ -988,9 +988,11 @@ int cap_mmap_addr(unsigned long addr)
268 +EXPORT_SYMBOL(cap_mmap_addr);
270 int cap_mmap_file(struct file *file, unsigned long reqprot,
271 unsigned long prot, unsigned long flags)
275 +EXPORT_SYMBOL(cap_mmap_file);
276 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
277 index dd0dc57..9760ecb6 100644
278 --- a/security/device_cgroup.c
279 +++ b/security/device_cgroup.c
281 #include <linux/device_cgroup.h>
282 #include <linux/cgroup.h>
283 #include <linux/ctype.h>
284 +#include <linux/export.h>
285 #include <linux/list.h>
286 #include <linux/uaccess.h>
287 #include <linux/seq_file.h>
288 @@ -789,6 +790,7 @@ int __devcgroup_inode_permission(struct inode *inode, int mask)
289 return __devcgroup_check_permission(type, imajor(inode), iminor(inode),
292 +EXPORT_SYMBOL(__devcgroup_inode_permission);
294 int devcgroup_inode_mknod(int mode, dev_t dev)
296 diff --git a/security/security.c b/security/security.c
297 index a3dce87..06a6ea6 100644
298 --- a/security/security.c
299 +++ b/security/security.c
300 @@ -396,6 +396,7 @@ int security_path_rmdir(struct path *dir, struct dentry *dentry)
302 return security_ops->path_rmdir(dir, dentry);
304 +EXPORT_SYMBOL(security_path_rmdir);
306 int security_path_unlink(struct path *dir, struct dentry *dentry)
308 @@ -412,6 +413,7 @@ int security_path_symlink(struct path *dir, struct dentry *dentry,
310 return security_ops->path_symlink(dir, dentry, old_name);
312 +EXPORT_SYMBOL(security_path_symlink);
314 int security_path_link(struct dentry *old_dentry, struct path *new_dir,
315 struct dentry *new_dentry)
316 @@ -420,6 +422,7 @@ int security_path_link(struct dentry *old_dentry, struct path *new_dir,
318 return security_ops->path_link(old_dentry, new_dir, new_dentry);
320 +EXPORT_SYMBOL(security_path_link);
322 int security_path_rename(struct path *old_dir, struct dentry *old_dentry,
323 struct path *new_dir, struct dentry *new_dentry)
324 @@ -438,6 +441,7 @@ int security_path_truncate(struct path *path)
326 return security_ops->path_truncate(path);
328 +EXPORT_SYMBOL(security_path_truncate);
330 int security_path_chmod(struct path *path, umode_t mode)
332 @@ -445,6 +449,7 @@ int security_path_chmod(struct path *path, umode_t mode)
334 return security_ops->path_chmod(path, mode);
336 +EXPORT_SYMBOL(security_path_chmod);
338 int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
340 @@ -452,6 +457,7 @@ int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
342 return security_ops->path_chown(path, uid, gid);
344 +EXPORT_SYMBOL(security_path_chown);
346 int security_path_chroot(struct path *path)
348 @@ -528,6 +534,7 @@ int security_inode_readlink(struct dentry *dentry)
350 return security_ops->inode_readlink(dentry);
352 +EXPORT_SYMBOL(security_inode_readlink);
354 int security_inode_follow_link(struct dentry *dentry, struct nameidata *nd)
356 @@ -542,6 +549,7 @@ int security_inode_permission(struct inode *inode, int mask)
358 return security_ops->inode_permission(inode, mask);
360 +EXPORT_SYMBOL(security_inode_permission);
362 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
364 @@ -663,6 +671,7 @@ int security_file_permission(struct file *file, int mask)
366 return fsnotify_perm(file, mask);
368 +EXPORT_SYMBOL(security_file_permission);
370 int security_file_alloc(struct file *file)
372 @@ -723,6 +732,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
374 return ima_file_mmap(file, prot);
376 +EXPORT_SYMBOL(security_mmap_file);
378 int security_mmap_addr(unsigned long addr)
380 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
381 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
382 +++ linux/Documentation/ABI/testing/debugfs-aufs 2013-07-06 13:20:47.716863966 +0200
384 +What: /debug/aufs/si_<id>/
386 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
388 + Under /debug/aufs, a directory named si_<id> is created
389 + per aufs mount, where <id> is a unique id generated
392 +What: /debug/aufs/si_<id>/plink
394 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
396 + It has three lines and shows the information about the
397 + pseudo-link. The first line is a single number
398 + representing a number of buckets. The second line is a
399 + number of pseudo-links per buckets (separated by a
400 + blank). The last line is a single number representing a
401 + total number of psedo-links.
402 + When the aufs mount option 'noplink' is specified, it
403 + will show "1\n0\n0\n".
405 +What: /debug/aufs/si_<id>/xib
407 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
409 + It shows the consumed blocks by xib (External Inode Number
410 + Bitmap), its block size and file size.
411 + When the aufs mount option 'noxino' is specified, it
412 + will be empty. About XINO files, see the aufs manual.
414 +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN
416 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
418 + It shows the consumed blocks by xino (External Inode Number
419 + Translation Table), its link count, block size and file
421 + When the aufs mount option 'noxino' is specified, it
422 + will be empty. About XINO files, see the aufs manual.
424 +What: /debug/aufs/si_<id>/xigen
426 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
428 + It shows the consumed blocks by xigen (External Inode
429 + Generation Table), its block size and file size.
430 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
432 + When the aufs mount option 'noxino' is specified, it
433 + will be empty. About XINO files, see the aufs manual.
434 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
435 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
436 +++ linux/Documentation/ABI/testing/sysfs-aufs 2013-07-06 13:20:47.730197761 +0200
438 +What: /sys/fs/aufs/si_<id>/
440 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
442 + Under /sys/fs/aufs, a directory named si_<id> is created
443 + per aufs mount, where <id> is a unique id generated
446 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
448 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
450 + It shows the abolute path of a member directory (which
451 + is called branch) in aufs, and its permission.
453 +What: /sys/fs/aufs/si_<id>/xi_path
455 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
457 + It shows the abolute path of XINO (External Inode Number
458 + Bitmap, Translation Table and Generation Table) file
459 + even if it is the default path.
460 + When the aufs mount option 'noxino' is specified, it
461 + will be empty. About XINO files, see the aufs manual.
462 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
463 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
464 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2013-07-06 13:20:47.730197761 +0200
467 +# Copyright (C) 2005-2013 Junjiro R. Okajima
469 +# This program is free software; you can redistribute it and/or modify
470 +# it under the terms of the GNU General Public License as published by
471 +# the Free Software Foundation; either version 2 of the License, or
472 +# (at your option) any later version.
474 +# This program is distributed in the hope that it will be useful,
475 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
476 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
477 +# GNU General Public License for more details.
479 +# You should have received a copy of the GNU General Public License
480 +# along with this program; if not, write to the Free Software
481 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
484 +----------------------------------------
486 +aufs [ei ju: ef es] | [a u f s]
487 +1. abbrev. for "advanced multi-layered unification filesystem".
488 +2. abbrev. for "another unionfs".
489 +3. abbrev. for "auf das" in German which means "on the" in English.
490 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
491 + But "Filesystem aufs Filesystem" is hard to understand.
493 +AUFS is a filesystem with features:
494 +- multi layered stackable unification filesystem, the member directory
495 + is called as a branch.
496 +- branch permission and attribute, 'readonly', 'real-readonly',
497 + 'readwrite', 'whiteout-able', 'link-able whiteout' and their
499 +- internal "file copy-on-write".
500 +- logical deletion, whiteout.
501 +- dynamic branch manipulation, adding, deleting and changing permission.
502 +- allow bypassing aufs, user's direct branch access.
503 +- external inode number translation table and bitmap which maintains the
504 + persistent aufs inode number.
505 +- seekable directory, including NFS readdir.
506 +- file mapping, mmap and sharing pages.
507 +- pseudo-link, hardlink over branches.
508 +- loopback mounted filesystem as a branch.
509 +- several policies to select one among multiple writable branches.
510 +- revert a single systemcall when an error occurs in aufs.
514 +Multi Layered Stackable Unification Filesystem
515 +----------------------------------------------------------------------
516 +Most people already knows what it is.
517 +It is a filesystem which unifies several directories and provides a
518 +merged single directory. When users access a file, the access will be
519 +passed/re-directed/converted (sorry, I am not sure which English word is
520 +correct) to the real file on the member filesystem. The member
521 +filesystem is called 'lower filesystem' or 'branch' and has a mode
522 +'readonly' and 'readwrite.' And the deletion for a file on the lower
523 +readonly branch is handled by creating 'whiteout' on the upper writable
526 +On LKML, there have been discussions about UnionMount (Jan Blunck,
527 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
528 +different approaches to implement the merged-view.
529 +The former tries putting it into VFS, and the latter implements as a
530 +separate filesystem.
531 +(If I misunderstand about these implementations, please let me know and
532 +I shall correct it. Because it is a long time ago when I read their
533 +source files last time).
535 +UnionMount's approach will be able to small, but may be hard to share
536 +branches between several UnionMount since the whiteout in it is
537 +implemented in the inode on branch filesystem and always
538 +shared. According to Bharata's post, readdir does not seems to be
540 +There are several missing features known in this implementations such as
541 +- for users, the inode number may change silently. eg. copy-up.
542 +- link(2) may break by copy-up.
543 +- read(2) may get an obsoleted filedata (fstat(2) too).
544 +- fcntl(F_SETLK) may be broken by copy-up.
545 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
548 +Unionfs has a longer history. When I started implementing a stacking filesystem
549 +(Aug 2005), it already existed. It has virtual super_block, inode,
550 +dentry and file objects and they have an array pointing lower same kind
551 +objects. After contributing many patches for Unionfs, I re-started my
552 +project AUFS (Jun 2006).
554 +In AUFS, the structure of filesystem resembles to Unionfs, but I
555 +implemented my own ideas, approaches and enhancements and it became
556 +totally different one.
558 +Comparing DM snapshot and fs based implementation
559 +- the number of bytes to be copied between devices is much smaller.
560 +- the type of filesystem must be one and only.
561 +- the fs must be writable, no readonly fs, even for the lower original
562 + device. so the compression fs will not be usable. but if we use
563 + loopback mount, we may address this issue.
565 + mount /cdrom/squashfs.img /sq
566 + losetup /sq/ext2.img
567 + losetup /somewhere/cow
568 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
569 +- it will be difficult (or needs more operations) to extract the
570 + difference between the original device and COW.
571 +- DM snapshot-merge may help a lot when users try merging. in the
572 + fs-layer union, users will use rsync(1).
575 +Several characters/aspects of aufs
576 +----------------------------------------------------------------------
578 +Aufs has several characters or aspects.
579 +1. a filesystem, callee of VFS helper
580 +2. sub-VFS, caller of VFS helper for branches
581 +3. a virtual filesystem which maintains persistent inode number
582 +4. reader/writer of files on branches such like an application
584 +1. Callee of VFS Helper
585 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
586 +unlink(2) from an application reaches sys_unlink() kernel function and
587 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
588 +calls filesystem specific unlink operation. Actually aufs implements the
589 +unlink operation but it behaves like a redirector.
591 +2. Caller of VFS Helper for Branches
592 +aufs_unlink() passes the unlink request to the branch filesystem as if
593 +it were called from VFS. So the called unlink operation of the branch
594 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
595 +every necessary pre/post operation for the branch filesystem.
596 +- acquire the lock for the parent dir on a branch
597 +- lookup in a branch
598 +- revalidate dentry on a branch
599 +- mnt_want_write() for a branch
600 +- vfs_unlink() for a branch
601 +- mnt_drop_write() for a branch
602 +- release the lock on a branch
604 +3. Persistent Inode Number
605 +One of the most important issue for a filesystem is to maintain inode
606 +numbers. This is particularly important to support exporting a
607 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
608 +backend block device for its own. But some storage is necessary to
609 +maintain inode number. It may be a large space and may not suit to keep
610 +in memory. Aufs rents some space from its first writable branch
611 +filesystem (by default) and creates file(s) on it. These files are
612 +created by aufs internally and removed soon (currently) keeping opened.
613 +Note: Because these files are removed, they are totally gone after
614 + unmounting aufs. It means the inode numbers are not persistent
615 + across unmount or reboot. I have a plan to make them really
616 + persistent which will be important for aufs on NFS server.
618 +4. Read/Write Files Internally (copy-on-write)
619 +Because a branch can be readonly, when you write a file on it, aufs will
620 +"copy-up" it to the upper writable branch internally. And then write the
621 +originally requested thing to the file. Generally kernel doesn't
622 +open/read/write file actively. In aufs, even a single write may cause a
623 +internal "file copy". This behaviour is very similar to cp(1) command.
625 +Some people may think it is better to pass such work to user space
626 +helper, instead of doing in kernel space. Actually I am still thinking
627 +about it. But currently I have implemented it in kernel space.
628 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
629 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
630 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2013-08-23 23:59:39.631583456 +0200
633 +# Copyright (C) 2005-2013 Junjiro R. Okajima
635 +# This program is free software; you can redistribute it and/or modify
636 +# it under the terms of the GNU General Public License as published by
637 +# the Free Software Foundation; either version 2 of the License, or
638 +# (at your option) any later version.
640 +# This program is distributed in the hope that it will be useful,
641 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
642 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
643 +# GNU General Public License for more details.
645 +# You should have received a copy of the GNU General Public License
646 +# along with this program; if not, write to the Free Software
647 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
649 +Basic Aufs Internal Structure
651 +Superblock/Inode/Dentry/File Objects
652 +----------------------------------------------------------------------
653 +As like an ordinary filesystem, aufs has its own
654 +superblock/inode/dentry/file objects. All these objects have a
655 +dynamically allocated array and store the same kind of pointers to the
656 +lower filesystem, branch.
657 +For example, when you build a union with one readwrite branch and one
658 +readonly, mounted /au, /rw and /ro respectively.
660 +- /ro/fileA exists but /rw/fileA
662 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
663 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
667 +This style of an array is essentially same to the aufs
668 +superblock/inode/dentry/file objects.
670 +Because aufs supports manipulating branches, ie. add/delete/change
671 +dynamically, these objects has its own generation. When branches are
672 +changed, the generation in aufs superblock is incremented. And a
673 +generation in other object are compared when it is accessed.
674 +When a generation in other objects are obsoleted, aufs refreshes the
679 +----------------------------------------------------------------------
680 +Additionally aufs superblock has some data for policies to select one
681 +among multiple writable branches, XIB files, pseudo-links and kobject.
682 +See below in detail.
683 +About the policies which supports copy-down a directory, see policy.txt
687 +Branch and XINO(External Inode Number Translation Table)
688 +----------------------------------------------------------------------
689 +Every branch has its own xino (external inode number translation table)
690 +file. The xino file is created and unlinked by aufs internally. When two
691 +members of a union exist on the same filesystem, they share the single
693 +The struct of a xino file is simple, just a sequence of aufs inode
694 +numbers which is indexed by the lower inode number.
695 +In the above sample, assume the inode number of /ro/fileA is i111 and
696 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
697 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
699 +When the inode numbers are not contiguous, the xino file will be sparse
700 +which has a hole in it and doesn't consume as much disk space as it
701 +might appear. If your branch filesystem consumes disk space for such
702 +holes, then you should specify 'xino=' option at mounting aufs.
704 +Also a writable branch has three kinds of "whiteout bases". All these
705 +are existed when the branch is joined to aufs and the names are
706 +whiteout-ed doubly, so that users will never see their names in aufs
708 +1. a regular file which will be linked to all whiteouts.
709 +2. a directory to store a pseudo-link.
710 +3. a directory to store an "orphan-ed" file temporary.
713 + When you remove a file on a readonly branch, aufs handles it as a
714 + logical deletion and creates a whiteout on the upper writable branch
715 + as a hardlink of this file in order not to consume inode on the
718 + See below, Pseudo-link.
720 + When "fileC" exists on the lower readonly branch only and it is
721 + opened and removed with its parent dir, and then user writes
722 + something into it, then aufs copies-up fileC to this
723 + directory. Because there is no other dir to store fileC. After
724 + creating a file under this dir, the file is unlinked.
726 +Because aufs supports manipulating branches, ie. add/delete/change
727 +dynamically, a branch has its own id. When the branch order changes, aufs
728 +finds the new index by searching the branch id.
732 +----------------------------------------------------------------------
733 +Assume "fileA" exists on the lower readonly branch only and it is
734 +hardlinked to "fileB" on the branch. When you write something to fileA,
735 +aufs copies-up it to the upper writable branch. Additionally aufs
736 +creates a hardlink under the Pseudo-link Directory of the writable
737 +branch. The inode of a pseudo-link is kept in aufs super_block as a
738 +simple list. If fileB is read after unlinking fileA, aufs returns
739 +filedata from the pseudo-link instead of the lower readonly
740 +branch. Because the pseudo-link is based upon the inode, to keep the
741 +inode number by xino (see above) is important.
743 +All the hardlinks under the Pseudo-link Directory of the writable branch
744 +should be restored in a proper location later. Aufs provides a utility
745 +to do this. The userspace helpers executed at remounting and unmounting
747 +During this utility is running, it puts aufs into the pseudo-link
748 +maintenance mode. In this mode, only the process which began the
749 +maintenance mode (and its child processes) is allowed to operate in
750 +aufs. Some other processes which are not related to the pseudo-link will
751 +be allowed to run too, but the rest have to return an error or wait
752 +until the maintenance mode ends. If a process already acquires an inode
753 +mutex (in VFS), it has to return an error.
756 +XIB(external inode number bitmap)
757 +----------------------------------------------------------------------
758 +Addition to the xino file per a branch, aufs has an external inode number
759 +bitmap in a superblock object. It is also a file such like a xino file.
760 +It is a simple bitmap to mark whether the aufs inode number is in-use or
762 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
764 +Aufs implements a feature to truncate/refresh both of xino and xib to
765 +reduce the number of consumed disk blocks for these files.
768 +Virtual or Vertical Dir, and Readdir in Userspace
769 +----------------------------------------------------------------------
770 +In order to support multiple layers (branches), aufs readdir operation
771 +constructs a virtual dir block on memory. For readdir, aufs calls
772 +vfs_readdir() internally for each dir on branches, merges their entries
773 +with eliminating the whiteout-ed ones, and sets it to file (dir)
774 +object. So the file object has its entry list until it is closed. The
775 +entry list will be updated when the file position is zero and becomes
776 +old. This decision is made in aufs automatically.
778 +The dynamically allocated memory block for the name of entries has a
779 +unit of 512 bytes (by default) and stores the names contiguously (no
780 +padding). Another block for each entry is handled by kmem_cache too.
781 +During building dir blocks, aufs creates hash list and judging whether
782 +the entry is whiteouted by its upper branch or already listed.
783 +The merged result is cached in the corresponding inode object and
784 +maintained by a customizable life-time option.
786 +Some people may call it can be a security hole or invite DoS attack
787 +since the opened and once readdir-ed dir (file object) holds its entry
788 +list and becomes a pressure for system memory. But I'd say it is similar
789 +to files under /proc or /sys. The virtual files in them also holds a
790 +memory page (generally) while they are opened. When an idea to reduce
791 +memory for them is introduced, it will be applied to aufs too.
792 +For those who really hate this situation, I've developed readdir(3)
793 +library which operates this merging in userspace. You just need to set
794 +LD_PRELOAD environment variable, and aufs will not consume no memory in
795 +kernel space for readdir(3).
799 +----------------------------------------------------------------------
800 +Aufs sometimes requires privilege access to a branch. For instance,
801 +in copy-up/down operation. When a user process is going to make changes
802 +to a file which exists in the lower readonly branch only, and the mode
803 +of one of ancestor directories may not be writable by a user
804 +process. Here aufs copy-up the file with its ancestors and they may
805 +require privilege to set its owner/group/mode/etc.
806 +This is a typical case of a application character of aufs (see
809 +Aufs uses workqueue synchronously for this case. It creates its own
810 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
811 +passes the request to call mkdir or write (for example), and wait for
812 +its completion. This approach solves a problem of a signal handler
814 +If aufs didn't adopt the workqueue and changed the privilege of the
815 +process, and if the mkdir/write call arises SIGXFSZ or other signal,
816 +then the user process might gain a privilege or the generated core file
817 +was owned by a superuser.
819 +Also aufs uses the system global workqueue ("events" kernel thread) too
820 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
821 +whiteout base and etc. This is unrelated to a privilege.
822 +Most of aufs operation tries acquiring a rw_semaphore for aufs
823 +superblock at the beginning, at the same time waits for the completion
824 +of all queued asynchronous tasks.
828 +----------------------------------------------------------------------
829 +The whiteout in aufs is very similar to Unionfs's. That is represented
830 +by its filename. UnionMount takes an approach of a file mode, but I am
831 +afraid several utilities (find(1) or something) will have to support it.
833 +Basically the whiteout represents "logical deletion" which stops aufs to
834 +lookup further, but also it represents "dir is opaque" which also stop
837 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
838 +In order to make several functions in a single systemcall to be
839 +revertible, aufs adopts an approach to rename a directory to a temporary
840 +unique whiteouted name.
841 +For example, in rename(2) dir where the target dir already existed, aufs
842 +renames the target dir to a temporary unique whiteouted name before the
843 +actual rename on a branch and then handles other actions (make it opaque,
844 +update the attributes, etc). If an error happens in these actions, aufs
845 +simply renames the whiteouted name back and returns an error. If all are
846 +succeeded, aufs registers a function to remove the whiteouted unique
847 +temporary name completely and asynchronously to the system global
852 +----------------------------------------------------------------------
853 +It is a well-known feature or concept.
854 +When user modifies a file on a readonly branch, aufs operate "copy-up"
855 +internally and makes change to the new file on the upper writable branch.
856 +When the trigger systemcall does not update the timestamps of the parent
857 +dir, aufs reverts it after copy-up.
860 +Move-down (aufs3.9 and later)
861 +----------------------------------------------------------------------
862 +"Copy-up" is one of the essential feature in aufs. It copies a file from
863 +the lower readonly branch to the upper writable branch when a user
864 +changes something about the file.
865 +"Move-down" is an opposite action of copy-up. Basically this action is
866 +ran manually instead of automatically and internally.
868 +Sometimes users want to move-down a file from the upper writable branch
869 +to the lower readonly or writable branch. For instance,
870 +- the free space of the upper writable branch is going to run out.
871 +- create a new intermediate branch between the upper and lower branch.
874 +For this purpose, use "aumvdown" command in aufs-util.git.
875 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
876 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
877 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2013-07-06 13:20:47.730197761 +0200
880 +# Copyright (C) 2005-2013 Junjiro R. Okajima
882 +# This program is free software; you can redistribute it and/or modify
883 +# it under the terms of the GNU General Public License as published by
884 +# the Free Software Foundation; either version 2 of the License, or
885 +# (at your option) any later version.
887 +# This program is distributed in the hope that it will be useful,
888 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
889 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
890 +# GNU General Public License for more details.
892 +# You should have received a copy of the GNU General Public License
893 +# along with this program; if not, write to the Free Software
894 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
897 +----------------------------------------------------------------------
898 +Since aufs has a character of sub-VFS (see Introduction), it operates
899 +lookup for branches as VFS does. It may be a heavy work. Generally
900 +speaking struct nameidata is a bigger structure and includes many
901 +information. But almost all lookup operation in aufs is the simplest
902 +case, ie. lookup only an entry directly connected to its parent. Digging
903 +down the directory hierarchy is unnecessary.
905 +VFS has a function lookup_one_len() for that use, but it is not usable
906 +for a branch filesystem which requires struct nameidata. So aufs
907 +implements a simple lookup wrapper function. When a branch filesystem
908 +allows NULL as nameidata, it calls lookup_one_len(). Otherwise it builds
909 +a simplest nameidata and calls lookup_hash().
910 +Here aufs applies "a principle in NFSD", ie. if the filesystem supports
911 +NFS-export, then it has to support NULL as a nameidata parameter for
912 +->create(), ->lookup() and ->d_revalidate(). So the lookup wrapper in
913 +aufs tests if ->s_export_op in the branch is NULL or not.
915 +When a branch is a remote filesystem, aufs basically trusts its
916 +->d_revalidate(), also aufs forces the hardest revalidate tests for
918 +For d_revalidate, aufs implements three levels of revalidate tests. See
919 +"Revalidate Dentry and UDBA" in detail.
923 +----------------------------------------------------------------------
924 +Basically aufs supports any type of filesystem and block device for a
925 +branch (actually there are some exceptions). But it is prohibited to add
926 +a loopback mounted one whose backend file exists in a filesystem which is
927 +already added to aufs. The reason is to protect aufs from a recursive
928 +lookup. If it was allowed, the aufs lookup operation might re-enter a
929 +lookup for the loopback mounted branch in the same context, and will
933 +Revalidate Dentry and UDBA (User's Direct Branch Access)
934 +----------------------------------------------------------------------
935 +Generally VFS helpers re-validate a dentry as a part of lookup.
936 +0. digging down the directory hierarchy.
937 +1. lock the parent dir by its i_mutex.
938 +2. lookup the final (child) entry.
940 +4. call the actual operation (create, unlink, etc.)
941 +5. unlock the parent dir
943 +If the filesystem implements its ->d_revalidate() (step 3), then it is
944 +called. Actually aufs implements it and checks the dentry on a branch is
946 +But it is not enough. Because aufs has to release the lock for the
947 +parent dir on a branch at the end of ->lookup() (step 2) and
948 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
950 +If the file on a branch is changed directly, eg. bypassing aufs, after
951 +aufs released the lock, then the subsequent operation may cause
952 +something unpleasant result.
954 +This situation is a result of VFS architecture, ->lookup() and
955 +->d_revalidate() is separated. But I never say it is wrong. It is a good
956 +design from VFS's point of view. It is just not suitable for sub-VFS
959 +Aufs supports such case by three level of revalidation which is
961 +1. Simple Revalidate
962 + Addition to the native flow in VFS's, confirm the child-parent
963 + relationship on the branch just after locking the parent dir on the
964 + branch in the "actual operation" (step 4). When this validation
965 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
966 + checks the validation of the dentry on branches.
967 +2. Monitor Changes Internally by Inotify/Fsnotify
968 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
969 + the dentry on the branch, and returns EBUSY if it finds different
971 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
972 + during it is in cache. When the event is notified, aufs registers a
973 + function to kernel 'events' thread by schedule_work(). And the
974 + function sets some special status to the cached aufs dentry and inode
975 + private data. If they are not cached, then aufs has nothing to
976 + do. When the same file is accessed through aufs (step 0-3) later,
977 + aufs will detect the status and refresh all necessary data.
978 + In this mode, aufs has to ignore the event which is fired by aufs
980 +3. No Extra Validation
981 + This is the simplest test and doesn't add any additional revalidation
982 + test, and skip therevalidatin in step 4. It is useful and improves
983 + aufs performance when system surely hide the aufs branches from user,
984 + by over-mounting something (or another method).
985 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
986 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
987 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2013-07-06 13:20:47.730197761 +0200
990 +# Copyright (C) 2005-2013 Junjiro R. Okajima
992 +# This program is free software; you can redistribute it and/or modify
993 +# it under the terms of the GNU General Public License as published by
994 +# the Free Software Foundation; either version 2 of the License, or
995 +# (at your option) any later version.
997 +# This program is distributed in the hope that it will be useful,
998 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
999 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1000 +# GNU General Public License for more details.
1002 +# You should have received a copy of the GNU General Public License
1003 +# along with this program; if not, write to the Free Software
1004 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1006 +Branch Manipulation
1008 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1009 +and changing its permission/attribute, there are a lot of works to do.
1013 +----------------------------------------------------------------------
1014 +o Confirm the adding dir exists outside of aufs, including loopback
1016 +- and other various attributes...
1017 +o Initialize the xino file and whiteout bases if necessary.
1020 +o Check the owner/group/mode of the directory
1021 + When the owner/group/mode of the adding directory differs from the
1022 + existing branch, aufs issues a warning because it may impose a
1024 + For example, when a upper writable branch has a world writable empty
1025 + top directory, a malicious user can create any files on the writable
1026 + branch directly, like copy-up and modify manually. If something like
1027 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1028 + writable branch, and the writable branch is world-writable, then a
1029 + malicious guy may create /etc/passwd on the writable branch directly
1030 + and the infected file will be valid in aufs.
1031 + I am afraid it can be a security issue, but nothing to do except
1032 + producing a warning.
1036 +----------------------------------------------------------------------
1037 +o Confirm the deleting branch is not busy
1038 + To be general, there is one merit to adopt "remount" interface to
1039 + manipulate branches. It is to discard caches. At deleting a branch,
1040 + aufs checks the still cached (and connected) dentries and inodes. If
1041 + there are any, then they are all in-use. An inode without its
1042 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1044 + For the cached one, aufs checks whether the same named entry exists on
1046 + If the cached one is a directory, because aufs provides a merged view
1047 + to users, as long as one dir is left on any branch aufs can show the
1048 + dir to users. In this case, the branch can be removed from aufs.
1049 + Otherwise aufs rejects deleting the branch.
1051 + If any file on the deleting branch is opened by aufs, then aufs
1055 +Modify the Permission of a Branch
1056 +----------------------------------------------------------------------
1057 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1060 +o rw --> ro: Confirm the modifying branch is not busy
1061 + Aufs rejects the request if any of these conditions are true.
1062 + - a file on the branch is mmap-ed.
1063 + - a regular file on the branch is opened for write and there is no
1064 + same named entry on the upper branch.
1065 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1066 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1067 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2013-07-06 13:20:47.730197761 +0200
1070 +# Copyright (C) 2005-2013 Junjiro R. Okajima
1072 +# This program is free software; you can redistribute it and/or modify
1073 +# it under the terms of the GNU General Public License as published by
1074 +# the Free Software Foundation; either version 2 of the License, or
1075 +# (at your option) any later version.
1077 +# This program is distributed in the hope that it will be useful,
1078 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1079 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1080 +# GNU General Public License for more details.
1082 +# You should have received a copy of the GNU General Public License
1083 +# along with this program; if not, write to the Free Software
1084 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1086 +Policies to Select One among Multiple Writable Branches
1087 +----------------------------------------------------------------------
1088 +When the number of writable branch is more than one, aufs has to decide
1089 +the target branch for file creation or copy-up. By default, the highest
1090 +writable branch which has the parent (or ancestor) dir of the target
1091 +file is chosen (top-down-parent policy).
1092 +By user's request, aufs implements some other policies to select the
1093 +writable branch, for file creation two policies, round-robin and
1094 +most-free-space policies. For copy-up three policies, top-down-parent,
1095 +bottom-up-parent and bottom-up policies.
1097 +As expected, the round-robin policy selects the branch in circular. When
1098 +you have two writable branches and creates 10 new files, 5 files will be
1099 +created for each branch. mkdir(2) systemcall is an exception. When you
1100 +create 10 new directories, all will be created on the same branch.
1101 +And the most-free-space policy selects the one which has most free
1102 +space among the writable branches. The amount of free space will be
1103 +checked by aufs internally, and users can specify its time interval.
1105 +The policies for copy-up is more simple,
1106 +top-down-parent is equivalent to the same named on in create policy,
1107 +bottom-up-parent selects the writable branch where the parent dir
1108 +exists and the nearest upper one from the copyup-source,
1109 +bottom-up selects the nearest upper writable branch from the
1110 +copyup-source, regardless the existence of the parent dir.
1112 +There are some rules or exceptions to apply these policies.
1113 +- If there is a readonly branch above the policy-selected branch and
1114 + the parent dir is marked as opaque (a variation of whiteout), or the
1115 + target (creating) file is whiteout-ed on the upper readonly branch,
1116 + then the result of the policy is ignored and the target file will be
1117 + created on the nearest upper writable branch than the readonly branch.
1118 +- If there is a writable branch above the policy-selected branch and
1119 + the parent dir is marked as opaque or the target file is whiteouted
1120 + on the branch, then the result of the policy is ignored and the target
1121 + file will be created on the highest one among the upper writable
1122 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1124 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1125 + They try selecting the branch where the source exists as possible
1126 + since copyup a large file will take long time. If it can't be,
1127 + ie. the branch where the source exists is readonly, then they will
1128 + follow the copyup policy.
1129 +- There is an exception for rename(2) when the target exists.
1130 + If the rename target exists, aufs compares the index of the branches
1131 + where the source and the target exists and selects the higher
1132 + one. If the selected branch is readonly, then aufs follows the
1134 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
1135 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
1136 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2013-07-06 13:20:47.730197761 +0200
1139 +# Copyright (C) 2005-2013 Junjiro R. Okajima
1141 +# This program is free software; you can redistribute it and/or modify
1142 +# it under the terms of the GNU General Public License as published by
1143 +# the Free Software Foundation; either version 2 of the License, or
1144 +# (at your option) any later version.
1146 +# This program is distributed in the hope that it will be useful,
1147 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1148 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1149 +# GNU General Public License for more details.
1151 +# You should have received a copy of the GNU General Public License
1152 +# along with this program; if not, write to the Free Software
1153 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1155 +mmap(2) -- File Memory Mapping
1156 +----------------------------------------------------------------------
1157 +In aufs, the file-mapped pages are handled by a branch fs directly, no
1158 +interaction with aufs. It means aufs_mmap() calls the branch fs's
1160 +This approach is simple and good, but there is one problem.
1161 +Under /proc, several entries show the mmap-ped files by its path (with
1162 +device and inode number), and the printed path will be the path on the
1163 +branch fs's instead of virtual aufs's.
1164 +This is not a problem in most cases, but some utilities lsof(1) (and its
1165 +user) may expect the path on aufs.
1167 +To address this issue, aufs adds a new member called vm_prfile in struct
1168 +vm_area_struct (and struct vm_region). The original vm_file points to
1169 +the file on the branch fs in order to handle everything correctly as
1170 +usual. The new vm_prfile points to a virtual file in aufs, and the
1171 +show-functions in procfs refers to vm_prfile if it is set.
1172 +Also we need to maintain several other places where touching vm_file
1174 +- fork()/clone() copies vma and the reference count of vm_file is
1176 +- merging vma maintains the ref count too.
1178 +This is not a good approach. It just faking the printed path. But it
1179 +leaves all behaviour around f_mapping unchanged. This is surely an
1181 +Actually aufs had adopted another complicated approach which calls
1182 +generic_file_mmap() and handles struct vm_operations_struct. In this
1183 +approach, aufs met a hard problem and I could not solve it without
1184 +switching the approach.
1185 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
1186 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
1187 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2013-07-06 13:20:47.736864659 +0200
1190 +# Copyright (C) 2005-2013 Junjiro R. Okajima
1192 +# This program is free software; you can redistribute it and/or modify
1193 +# it under the terms of the GNU General Public License as published by
1194 +# the Free Software Foundation; either version 2 of the License, or
1195 +# (at your option) any later version.
1197 +# This program is distributed in the hope that it will be useful,
1198 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1199 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1200 +# GNU General Public License for more details.
1202 +# You should have received a copy of the GNU General Public License
1203 +# along with this program; if not, write to the Free Software
1204 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1206 +Export Aufs via NFS
1207 +----------------------------------------------------------------------
1208 +Here is an approach.
1209 +- like xino/xib, add a new file 'xigen' which stores aufs inode
1211 +- iget_locked(): initialize aufs inode generation for a new inode, and
1212 + store it in xigen file.
1213 +- destroy_inode(): increment aufs inode generation and store it in xigen
1214 + file. it is necessary even if it is not unlinked, because any data of
1215 + inode may be changed by UDBA.
1216 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
1217 + build file handle by
1218 + + branch id (4 bytes)
1219 + + superblock generation (4 bytes)
1220 + + inode number (4 or 8 bytes)
1221 + + parent dir inode number (4 or 8 bytes)
1222 + + inode generation (4 bytes))
1223 + + return value of exportfs_encode_fh() for the parent on a branch (4
1225 + + file handle for a branch (by exportfs_encode_fh())
1227 + + find the index of a branch from its id in handle, and check it is
1228 + still exist in aufs.
1229 + + 1st level: get the inode number from handle and search it in cache.
1230 + + 2nd level: if not found, get the parent inode number from handle and
1231 + search it in cache. and then open the parent dir, find the matching
1232 + inode number by vfs_readdir() and get its name, and call
1233 + lookup_one_len() for the target dentry.
1234 + + 3rd level: if the parent dir is not cached, call
1235 + exportfs_decode_fh() for a branch and get the parent on a branch,
1236 + build a pathname of it, convert it a pathname in aufs, call
1237 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
1239 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
1240 + for every branch, but not itself. to get this, (currently) aufs
1241 + searches in current->nsproxy->mnt_ns list. it may not be a good
1242 + idea, but I didn't get other approach.
1243 + + test the generation of the gotten inode.
1244 +- every inode operation: they may get EBUSY due to UDBA. in this case,
1245 + convert it into ESTALE for NFSD.
1246 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
1247 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
1248 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
1249 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
1250 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2013-07-06 13:20:47.736864659 +0200
1253 +# Copyright (C) 2005-2013 Junjiro R. Okajima
1255 +# This program is free software; you can redistribute it and/or modify
1256 +# it under the terms of the GNU General Public License as published by
1257 +# the Free Software Foundation; either version 2 of the License, or
1258 +# (at your option) any later version.
1260 +# This program is distributed in the hope that it will be useful,
1261 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1262 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1263 +# GNU General Public License for more details.
1265 +# You should have received a copy of the GNU General Public License
1266 +# along with this program; if not, write to the Free Software
1267 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1269 +Show Whiteout Mode (shwh)
1270 +----------------------------------------------------------------------
1271 +Generally aufs hides the name of whiteouts. But in some cases, to show
1272 +them is very useful for users. For instance, creating a new middle layer
1273 +(branch) by merging existing layers.
1275 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
1276 +When you have three branches,
1277 +- Bottom: 'system', squashfs (underlying base system), read-only
1278 +- Middle: 'mods', squashfs, read-only
1279 +- Top: 'overlay', ram (tmpfs), read-write
1281 +The top layer is loaded at boot time and saved at shutdown, to preserve
1282 +the changes made to the system during the session.
1283 +When larger changes have been made, or smaller changes have accumulated,
1284 +the size of the saved top layer data grows. At this point, it would be
1285 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
1286 +and rewrite the 'mods' squashfs, clearing the top layer and thus
1287 +restoring save and load speed.
1289 +This merging is simplified by the use of another aufs mount, of just the
1290 +two overlay branches using the 'shwh' option.
1291 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
1292 + aufs /livesys/merge_union
1294 +A merged view of these two branches is then available at
1295 +/livesys/merge_union, and the new feature is that the whiteouts are
1297 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
1298 +writing to all branches. Also the default mode for all branches is 'ro'.
1299 +It is now possible to save the combined contents of the two overlay
1300 +branches to a new squashfs, e.g.:
1301 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
1303 +This new squashfs archive can be stored on the boot device and the
1304 +initramfs will use it to replace the old one at the next boot.
1305 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
1306 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
1307 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2013-07-06 13:20:47.736864659 +0200
1310 +# Copyright (C) 2010-2013 Junjiro R. Okajima
1312 +# This program is free software; you can redistribute it and/or modify
1313 +# it under the terms of the GNU General Public License as published by
1314 +# the Free Software Foundation; either version 2 of the License, or
1315 +# (at your option) any later version.
1317 +# This program is distributed in the hope that it will be useful,
1318 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1319 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1320 +# GNU General Public License for more details.
1322 +# You should have received a copy of the GNU General Public License
1323 +# along with this program; if not, write to the Free Software
1324 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1326 +Dynamically customizable FS operations
1327 +----------------------------------------------------------------------
1328 +Generally FS operations (struct inode_operations, struct
1329 +address_space_operations, struct file_operations, etc.) are defined as
1330 +"static const", but it never means that FS have only one set of
1331 +operation. Some FS have multiple sets of them. For instance, ext2 has
1332 +three sets, one for XIP, for NOBH, and for normal.
1333 +Since aufs overrides and redirects these operations, sometimes aufs has
1334 +to change its behaviour according to the branch FS type. More imporantly
1335 +VFS acts differently if a function (member in the struct) is set or
1336 +not. It means aufs should have several sets of operations and select one
1337 +among them according to the branch FS definition.
1339 +In order to solve this problem and not to affect the behavour of VFS,
1340 +aufs defines these operations dynamically. For instance, aufs defines
1341 +aio_read function for struct file_operations, but it may not be set to
1342 +the file_operations. When the branch FS doesn't have it, aufs doesn't
1343 +set it to its file_operations while the function definition itself is
1344 +still alive. So the behaviour of io_submit(2) will not change, and it
1345 +will return an error when aio_read is not defined.
1347 +The lifetime of these dynamically generated operation object is
1348 +maintained by aufs branch object. When the branch is removed from aufs,
1349 +the reference counter of the object is decremented. When it reaches
1350 +zero, the dynamically generated operation object will be freed.
1352 +This approach is designed to support AIO (io_submit), Direcit I/O and
1354 +Currently this approach is applied to file_operations and
1355 +vm_operations_struct for regular files only.
1356 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt linux/Documentation/filesystems/aufs/design/99plan.txt
1357 --- /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt 1970-01-01 01:00:00.000000000 +0100
1358 +++ linux/Documentation/filesystems/aufs/design/99plan.txt 2013-07-06 13:20:47.736864659 +0200
1361 +# Copyright (C) 2005-2013 Junjiro R. Okajima
1363 +# This program is free software; you can redistribute it and/or modify
1364 +# it under the terms of the GNU General Public License as published by
1365 +# the Free Software Foundation; either version 2 of the License, or
1366 +# (at your option) any later version.
1368 +# This program is distributed in the hope that it will be useful,
1369 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1370 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1371 +# GNU General Public License for more details.
1373 +# You should have received a copy of the GNU General Public License
1374 +# along with this program; if not, write to the Free Software
1375 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1379 +Restoring some features which was implemented in aufs1.
1380 +They were dropped in aufs2 in order to make source files simpler and
1381 +easier to be reviewed.
1384 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1385 +----------------------------------------------------------------------
1386 +Let's try case study.
1387 +- aufs has two branches, upper readwrite and lower readonly.
1389 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1390 +- user invoked "chmod a+rx /au/dirA"
1391 +- then "dirA" becomes world readable?
1393 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1394 +or it may be a natively readonly filesystem. If aufs respects the lower
1395 +branch, it should not respond readdir request from other users. But user
1396 +allowed it by chmod. Should really aufs rejects showing the entries
1399 +To be honest, I don't have a best solution for this case. So I
1400 +implemented 'dirperm1' and 'nodirperm1' option in aufs1, and leave it to
1402 +When dirperm1 is specified, aufs checks only the highest one for the
1403 +directory permission, and shows the entries. Otherwise, as usual, checks
1404 +every dir existing on all branches and rejects the request.
1406 +As a side effect, dirperm1 option improves the performance of aufs
1407 +because the number of permission check is reduced.
1410 +Being Another Aufs's Readonly Branch (robr)
1411 +----------------------------------------------------------------------
1412 +Aufs1 allows aufs to be another aufs's readonly branch.
1413 +This feature was developed by a user's request. But it may not be used
1417 +Copy-up on Open (coo=)
1418 +----------------------------------------------------------------------
1419 +By default the internal copy-up is executed when it is really necessary.
1420 +It is not done when a file is opened for writing, but when write(2) is
1421 +done. Users who have many (over 100) branches want to know and analyse
1422 +when and what file is copied-up. To insert a new upper branch which
1423 +contains such files only may improve the performance of aufs.
1425 +Aufs1 implemented "coo=none | leaf | all" option.
1428 +Refresh the Opened File (refrof)
1429 +----------------------------------------------------------------------
1430 +This option is implemented in aufs1 but incomplete.
1432 +When user reads from a file, he expects to get its latest filedata
1433 +generally. If the file is removed and a new same named file is created,
1434 +the content he gets is unchanged, ie. the unlinked filedata.
1436 +Let's try case study again.
1437 +- aufs has two branches.
1439 +- "fileA" exists under /ro, but /rw.
1440 +- user opened "/au/fileA".
1441 +- he or someone else inserts a branch (/new) between /rw and /ro.
1442 + /au = /rw + /new + /ro
1443 +- the new branch has "fileA".
1444 +- user reads from the opened "fileA"
1445 +- which filedata should aufs return, from /ro or /new?
1447 +Some people says it has to be "from /ro" and it is a semantics of Unix.
1448 +The others say it should be "from /new" because the file is not removed
1449 +and it is equivalent to the case of someone else modifies the file.
1451 +Here again I don't have a best and final answer. I got an idea to
1452 +implement 'refrof' and 'norefrof' option. When 'refrof' (REFResh the
1453 +Opened File) is specified (by default), aufs returns the filedata from
1455 +Otherwise from /new.
1456 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
1457 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
1458 +++ linux/Documentation/filesystems/aufs/README 2013-07-30 22:42:46.229279157 +0200
1461 +Aufs3 -- advanced multi layered unification filesystem version 3.x
1467 +----------------------------------------
1468 +In the early days, aufs was entirely re-designed and re-implemented
1469 +Unionfs Version 1.x series. After many original ideas, approaches,
1470 +improvements and implementations, it becomes totally different from
1471 +Unionfs while keeping the basic features.
1472 +Recently, Unionfs Version 2.x series begin taking some of the same
1473 +approaches to aufs1's.
1474 +Unionfs is being developed by Professor Erez Zadok at Stony Brook
1475 +University and his team.
1477 +Aufs3 supports linux-3.0 and later.
1478 +If you want older kernel version support, try aufs2-2.6.git or
1479 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
1481 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
1482 +According to Christoph Hellwig, linux rejects all union-type filesystems
1484 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
1488 +----------------------------------------
1489 +- unite several directories into a single virtual filesystem. The member
1490 + directory is called as a branch.
1491 +- you can specify the permission flags to the branch, which are 'readonly',
1492 + 'readwrite' and 'whiteout-able.'
1493 +- by upper writable branch, internal copyup and whiteout, files/dirs on
1494 + readonly branch are modifiable logically.
1495 +- dynamic branch manipulation, add, del.
1498 +Also there are many enhancements in aufs1, such as:
1499 +- readdir(3) in userspace.
1500 +- keep inode number by external inode number table
1501 +- keep the timestamps of file/dir in internal copyup operation
1502 +- seekable directory, supporting NFS readdir.
1503 +- whiteout is hardlinked in order to reduce the consumption of inodes
1505 +- do not copyup, nor create a whiteout when it is unnecessary
1506 +- revert a single systemcall when an error occurs in aufs
1507 +- remount interface instead of ioctl
1508 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
1509 +- loopback mounted filesystem as a branch
1510 +- kernel thread for removing the dir who has a plenty of whiteouts
1511 +- support copyup sparse file (a file which has a 'hole' in it)
1512 +- default permission flags for branches
1513 +- selectable permission flags for ro branch, whether whiteout can
1516 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
1517 +- support multiple writable branches, some policies to select one
1518 + among multiple writable branches.
1519 +- a new semantics for link(2) and rename(2) to support multiple
1520 + writable branches.
1521 +- no glibc changes are required.
1522 +- pseudo hardlink (hardlink over branches)
1523 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
1524 + including NFS or remote filesystem branch.
1525 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
1528 +Currently these features are dropped temporary from aufs3.
1529 +See design/08plan.txt in detail.
1530 +- test only the highest one for the directory permission (dirperm1)
1531 +- copyup on open (coo=)
1532 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
1534 +- statistics of aufs thread (/sys/fs/aufs/stat)
1535 +- delegation mode (dlgt)
1536 + a delegation of the internal branch access to support task I/O
1537 + accounting, which also supports Linux Security Modules (LSM) mainly
1538 + for Suse AppArmor.
1539 +- intent.open/create (file open in a single lookup)
1541 +Features or just an idea in the future (see also design/*.txt),
1542 +- reorder the branch index without del/re-add.
1543 +- permanent xino files for NFSD
1544 +- an option for refreshing the opened files after add/del branches
1545 +- 'move' policy for copy-up between two writable branches, after
1546 + checking free space.
1547 +- light version, without branch manipulation. (unnecessary?)
1548 +- copyup in userspace
1549 +- inotify in userspace
1555 +----------------------------------------
1556 +There were three GIT trees for aufs3, aufs3-linux.git,
1557 +aufs3-standalone.git, and aufs-util.git. Note that there is no "3" in
1559 +While the aufs-util is always necessary, you need either of aufs3-linux
1560 +or aufs3-standalone.
1562 +The aufs3-linux tree includes the whole linux mainline GIT tree,
1563 +git://git.kernel.org/.../torvalds/linux.git.
1564 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
1565 +build aufs3 as an external kernel module.
1567 +On the other hand, the aufs3-standalone tree has only aufs source files
1568 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
1570 +You will find GIT branches whose name is in form of "aufs3.x" where "x"
1571 +represents the linux kernel version, "linux-3.x". For instance,
1572 +"aufs3.0" is for linux-3.0. For latest "linux-3.x-rcN", use
1573 +"aufs3.x-rcN" branch.
1576 +$ git clone --reference /your/linux/git/tree \
1577 + git://git.code.sf.net/p/aufs/aufs3-linux aufs-aufs3-linux \
1579 +- if you don't have linux GIT tree, then remove "--reference ..."
1580 +$ cd aufs3-linux.git
1581 +$ git checkout origin/aufs3.0
1583 +o aufs3-standalone tree
1584 +$ git clone git://git.code.sf.net/p/aufs/aufs3-standalone \
1585 + aufs3-standalone.git
1586 +$ cd aufs3-standalone.git
1587 +$ git checkout origin/aufs3.0
1590 +$ git clone git://git.code.sf.net/p/aufs/aufs-util \
1593 +$ git checkout origin/aufs3.0
1595 +Note: The 3.x-rcN branch is to be used with `rc' kernel versions ONLY.
1596 +The minor version number, 'x' in '3.x', of aufs may not always
1597 +follow the minor version number of the kernel.
1598 +Because changes in the kernel that cause the use of a new
1599 +minor version number do not always require changes to aufs-util.
1601 +Since aufs-util has its own minor version number, you may not be
1602 +able to find a GIT branch in aufs-util for your kernel's
1603 +exact minor version number.
1604 +In this case, you should git-checkout the branch for the
1605 +nearest lower number.
1607 +For (an unreleased) example:
1608 +If you are using "linux-3.10" and the "aufs3.10" branch
1609 +does not exist in aufs-util repository, then "aufs3.9", "aufs3.8"
1610 +or something numerically smaller is the branch for your kernel.
1612 +Also you can view all branches by
1616 +3. Configuration and Compilation
1617 +----------------------------------------
1618 +Make sure you have git-checkout'ed the correct branch.
1620 +For aufs3-linux tree,
1621 +- enable CONFIG_AUFS_FS.
1622 +- set other aufs configurations if necessary.
1624 +For aufs3-standalone tree,
1625 +There are several ways to build.
1628 +- apply ./aufs3-kbuild.patch to your kernel source files.
1629 +- apply ./aufs3-base.patch too.
1630 +- apply ./aufs3-proc_map.patch too, if you want to make /proc/PID/maps (and
1631 + others including lsof(1)) show the file path on aufs instead of the
1632 + path on the branch fs.
1633 +- apply ./aufs3-standalone.patch too, if you have a plan to set
1634 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs3-standalone.patch.
1635 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
1636 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
1637 +- enable CONFIG_AUFS_FS, you can select either
1639 +- and build your kernel as usual.
1640 +- install the built kernel.
1641 + Note: Since linux-3.9, every filesystem module requires an alias
1642 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
1643 + modules.aliases file if you set CONFIG_AUFS_FS=m.
1644 +- install the header files too by "make headers_install" to the
1645 + directory where you specify. By default, it is $PWD/usr.
1646 + "make help" shows a brief note for headers_install.
1647 +- and reboot your system.
1650 +- module only (CONFIG_AUFS_FS=m).
1651 +- apply ./aufs3-base.patch to your kernel source files.
1652 +- apply ./aufs3-proc_map.patch too to your kernel source files,
1653 + if you want to make /proc/PID/maps (and others including lsof(1)) show
1654 + the file path on aufs instead of the path on the branch fs.
1655 +- apply ./aufs3-standalone.patch too.
1656 +- build your kernel, don't forget "make headers_install", and reboot.
1657 +- edit ./config.mk and set other aufs configurations if necessary.
1658 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
1659 + every aufs configurations.
1660 +- build the module by simple "make".
1661 + Note: Since linux-3.9, every filesystem module requires an alias
1662 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
1663 + modules.aliases file.
1664 +- you can specify ${KDIR} make variable which points to your kernel
1666 +- install the files
1667 + + run "make install" to install the aufs module, or copy the built
1668 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
1669 + + run "make install_headers" (instead of headers_install) to install
1670 + the modified aufs header file (you can specify DESTDIR which is
1671 + available in aufs standalone version's Makefile only), or copy
1672 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
1673 + you like manually. By default, the target directory is $PWD/usr.
1674 +- no need to apply aufs3-kbuild.patch, nor copying source files to your
1675 + kernel source tree.
1677 +Note: The header file aufs_type.h is necessary to build aufs-util
1678 + as well as "make headers_install" in the kernel source tree.
1679 + headers_install is subject to be forgotten, but it is essentially
1680 + necessary, not only for building aufs-util.
1681 + You may not meet problems without headers_install in some older
1685 +- read README in aufs-util, build and install it
1686 +- note that your distribution may contain an obsoleted version of
1687 + aufs_type.h in /usr/include/linux or something. When you build aufs
1688 + utilities, make sure that your compiler refers the correct aufs header
1689 + file which is built by "make headers_install."
1690 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
1691 + then run "make install_ulib" too. And refer to the aufs manual in
1696 +----------------------------------------
1697 +At first, make sure aufs-util are installed, and please read the aufs
1698 +manual, aufs.5 in aufs-util.git tree.
1702 +$ mkdir /tmp/rw /tmp/aufs
1703 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
1705 +Here is another example. The result is equivalent.
1706 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
1708 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
1709 +# mount -o remount,append:${HOME} /tmp/aufs
1711 +Then, you can see whole tree of your home dir through /tmp/aufs. If
1712 +you modify a file under /tmp/aufs, the one on your home directory is
1713 +not affected, instead the same named file will be newly created under
1714 +/tmp/rw. And all of your modification to a file will be applied to
1715 +the one under /tmp/rw. This is called the file based Copy on Write
1717 +Aufs mount options are described in aufs.5.
1718 +If you run chroot or something and make your aufs as a root directory,
1719 +then you need to customize the shutdown script. See the aufs manual in
1722 +Additionally, there are some sample usages of aufs which are a
1723 +diskless system with network booting, and LiveCD over NFS.
1724 +See sample dir in CVS tree on SourceForge.
1728 +----------------------------------------
1729 +When you have any problems or strange behaviour in aufs, please let me
1731 +- /proc/mounts (instead of the output of mount(8))
1732 +- /sys/module/aufs/*
1733 +- /sys/fs/aufs/* (if you have them)
1734 +- /debug/aufs/* (if you have them)
1735 +- linux kernel version
1736 + if your kernel is not plain, for example modified by distributor,
1737 + the url where i can download its source is necessary too.
1738 +- aufs version which was printed at loading the module or booting the
1739 + system, instead of the date you downloaded.
1740 +- configuration (define/undefine CONFIG_AUFS_xxx)
1741 +- kernel configuration or /proc/config.gz (if you have it)
1742 +- behaviour which you think to be incorrect
1743 +- actual operation, reproducible one is better
1744 +- mailto: aufs-users at lists.sourceforge.net
1746 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
1747 +and Feature Requests) on SourceForge. Please join and write to
1751 +6. Acknowledgements
1752 +----------------------------------------
1753 +Thanks to everyone who have tried and are using aufs, whoever
1754 +have reported a bug or any feedback.
1756 +Especially donators:
1757 +Tomas Matejicek(slax.org) made a donation (much more than once).
1758 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
1759 + scripts) is making "doubling" donations.
1760 + Unfortunately I cannot list all of the donators, but I really
1762 + It ends Aug 2010, but the ordinary donation URL is still available.
1763 + <http://sourceforge.net/donate/index.php?group_id=167503>
1764 +Dai Itasaka made a donation (2007/8).
1765 +Chuck Smith made a donation (2008/4, 10 and 12).
1766 +Henk Schoneveld made a donation (2008/9).
1767 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
1768 +Francois Dupoux made a donation (2008/11).
1769 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
1770 + aufs2 GIT tree (2009/2).
1771 +William Grant made a donation (2009/3).
1772 +Patrick Lane made a donation (2009/4).
1773 +The Mail Archive (mail-archive.com) made donations (2009/5).
1774 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
1775 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
1776 +Pavel Pronskiy made a donation (2011/2).
1777 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
1778 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
1779 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
1781 +Sam Liddicott made a donation (2011/9).
1782 +Era Scarecrow made a donation (2013/4).
1783 +Bor Ratajc made a donation (2013/4).
1784 +Alessandro Gorreta made a donation (2013/4).
1785 +POIRETTE Marc made a donation (2013/4).
1786 +Alessandro Gorreta made a donation (2013/4).
1787 +lauri kasvandik made a donation (2013/5).
1788 +pemasu from Finland made a donation (2013/7).
1790 +Thank you very much.
1791 +Donations are always, including future donations, very important and
1792 +helpful for me to keep on developing aufs.
1796 +----------------------------------------
1797 +If you are an experienced user, no explanation is needed. Aufs is
1798 +just a linux filesystem.
1803 +# Local variables: ;
1806 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
1807 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
1808 +++ linux/fs/aufs/aufs.h 2013-07-06 13:20:47.736864659 +0200
1811 + * Copyright (C) 2005-2013 Junjiro R. Okajima
1813 + * This program, aufs is free software; you can redistribute it and/or modify
1814 + * it under the terms of the GNU General Public License as published by
1815 + * the Free Software Foundation; either version 2 of the License, or
1816 + * (at your option) any later version.
1818 + * This program is distributed in the hope that it will be useful,
1819 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1820 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1821 + * GNU General Public License for more details.
1823 + * You should have received a copy of the GNU General Public License
1824 + * along with this program; if not, write to the Free Software
1825 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1829 + * all header files
1837 +#define AuStub(type, name, body, ...) \
1838 + static inline type name(__VA_ARGS__) { body; }
1840 +#define AuStubVoid(name, ...) \
1841 + AuStub(void, name, , __VA_ARGS__)
1842 +#define AuStubInt0(name, ...) \
1843 + AuStub(int, name, return 0, __VA_ARGS__)
1847 +#include "branch.h"
1850 +#include "dbgaufs.h"
1851 +#include "dentry.h"
1855 +#include "fstype.h"
1858 +#include "module.h"
1863 +#include "sysaufs.h"
1868 +#endif /* __KERNEL__ */
1869 +#endif /* __AUFS_H__ */
1870 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
1871 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
1872 +++ linux/fs/aufs/branch.c 2013-07-30 22:42:55.839613269 +0200
1875 + * Copyright (C) 2005-2013 Junjiro R. Okajima
1877 + * This program, aufs is free software; you can redistribute it and/or modify
1878 + * it under the terms of the GNU General Public License as published by
1879 + * the Free Software Foundation; either version 2 of the License, or
1880 + * (at your option) any later version.
1882 + * This program is distributed in the hope that it will be useful,
1883 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1884 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1885 + * GNU General Public License for more details.
1887 + * You should have received a copy of the GNU General Public License
1888 + * along with this program; if not, write to the Free Software
1889 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1893 + * branch management
1896 +#include <linux/compat.h>
1897 +#include <linux/statfs.h>
1901 + * free a single branch
1904 +/* prohibit rmdir to the root of the branch */
1905 +/* todo: another new flag? */
1906 +static void au_br_dflags_force(struct au_branch *br)
1908 + struct dentry *h_dentry;
1910 + h_dentry = au_br_dentry(br);
1911 + spin_lock(&h_dentry->d_lock);
1912 + br->br_dflags = h_dentry->d_flags & DCACHE_MOUNTED;
1913 + h_dentry->d_flags |= DCACHE_MOUNTED;
1914 + spin_unlock(&h_dentry->d_lock);
1917 +/* restore its d_flags */
1918 +static void au_br_dflags_restore(struct au_branch *br)
1920 + struct dentry *h_dentry;
1922 + if (br->br_dflags)
1925 + h_dentry = au_br_dentry(br);
1926 + spin_lock(&h_dentry->d_lock);
1927 + h_dentry->d_flags &= ~DCACHE_MOUNTED;
1928 + spin_unlock(&h_dentry->d_lock);
1931 +static void au_br_do_free(struct au_branch *br)
1934 + struct au_wbr *wbr;
1935 + struct au_dykey **key;
1937 + au_hnotify_fin_br(br);
1939 + if (br->br_xino.xi_file)
1940 + fput(br->br_xino.xi_file);
1941 + mutex_destroy(&br->br_xino.xi_nondir_mtx);
1943 + AuDebugOn(atomic_read(&br->br_count));
1947 + for (i = 0; i < AuBrWh_Last; i++)
1948 + dput(wbr->wbr_wh[i]);
1949 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
1950 + AuRwDestroy(&wbr->wbr_wh_rwsem);
1953 + key = br->br_dykey;
1954 + for (i = 0; i < AuBrDynOp; i++, key++)
1960 + au_br_dflags_restore(br);
1962 + /* recursive lock, s_umount of branch's */
1964 + path_put(&br->br_path);
1971 + * frees all branches
1973 +void au_br_free(struct au_sbinfo *sbinfo)
1975 + aufs_bindex_t bmax;
1976 + struct au_branch **br;
1978 + AuRwMustWriteLock(&sbinfo->si_rwsem);
1980 + bmax = sbinfo->si_bend + 1;
1981 + br = sbinfo->si_branch;
1983 + au_br_do_free(*br++);
1987 + * find the index of a branch which is specified by @br_id.
1989 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
1991 + aufs_bindex_t bindex, bend;
1993 + bend = au_sbend(sb);
1994 + for (bindex = 0; bindex <= bend; bindex++)
1995 + if (au_sbr_id(sb, bindex) == br_id)
2000 +/* ---------------------------------------------------------------------- */
2006 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
2007 + struct dentry *h_root)
2009 + if (unlikely(h_adding == h_root
2010 + || au_test_loopback_overlap(sb, h_adding)))
2012 + if (h_adding->d_sb != h_root->d_sb)
2014 + return au_test_subdir(h_adding, h_root)
2015 + || au_test_subdir(h_root, h_adding);
2019 + * returns a newly allocated branch. @new_nbranch is a number of branches
2020 + * after adding a branch.
2022 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
2025 + struct au_branch *add_branch;
2026 + struct dentry *root;
2030 + root = sb->s_root;
2031 + add_branch = kmalloc(sizeof(*add_branch), GFP_NOFS);
2032 + if (unlikely(!add_branch))
2035 + err = au_hnotify_init_br(add_branch, perm);
2036 + if (unlikely(err))
2039 + add_branch->br_wbr = NULL;
2040 + if (au_br_writable(perm)) {
2041 + /* may be freed separately at changing the branch permission */
2042 + add_branch->br_wbr = kmalloc(sizeof(*add_branch->br_wbr),
2044 + if (unlikely(!add_branch->br_wbr))
2048 + err = au_sbr_realloc(au_sbi(sb), new_nbranch);
2050 + err = au_di_realloc(au_di(root), new_nbranch);
2052 + err = au_ii_realloc(au_ii(root->d_inode), new_nbranch);
2054 + return add_branch; /* success */
2056 + kfree(add_branch->br_wbr);
2059 + au_hnotify_fin_br(add_branch);
2061 + kfree(add_branch);
2063 + return ERR_PTR(err);
2067 + * test if the branch permission is legal or not.
2069 +static int test_br(struct inode *inode, int brperm, char *path)
2073 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
2078 + pr_err("write permission for readonly mount or inode, %s\n", path);
2086 + * 0: success, the caller will add it
2087 + * plus: success, it is already unified, the caller should ignore it
2090 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
2093 + aufs_bindex_t bend, bindex;
2094 + struct dentry *root;
2095 + struct inode *inode, *h_inode;
2097 + root = sb->s_root;
2098 + bend = au_sbend(sb);
2099 + if (unlikely(bend >= 0
2100 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
2104 + pr_err("%s duplicated\n", add->pathname);
2109 + err = -ENOSPC; /* -E2BIG; */
2110 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
2111 + || AUFS_BRANCH_MAX - 1 <= bend)) {
2112 + pr_err("number of branches exceeded %s\n", add->pathname);
2117 + if (unlikely(add->bindex < 0 || bend + 1 < add->bindex)) {
2118 + pr_err("bad index %d\n", add->bindex);
2122 + inode = add->path.dentry->d_inode;
2124 + if (unlikely(!inode->i_nlink)) {
2125 + pr_err("no existence %s\n", add->pathname);
2130 + if (unlikely(inode->i_sb == sb)) {
2131 + pr_err("%s must be outside\n", add->pathname);
2135 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
2136 + pr_err("unsupported filesystem, %s (%s)\n",
2137 + add->pathname, au_sbtype(inode->i_sb));
2141 + err = test_br(add->path.dentry->d_inode, add->perm, add->pathname);
2142 + if (unlikely(err))
2146 + return 0; /* success */
2149 + for (bindex = 0; bindex <= bend; bindex++)
2150 + if (unlikely(test_overlap(sb, add->path.dentry,
2151 + au_h_dptr(root, bindex)))) {
2152 + pr_err("%s is overlapped\n", add->pathname);
2157 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
2158 + h_inode = au_h_dptr(root, 0)->d_inode;
2159 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
2160 + || !uid_eq(h_inode->i_uid, inode->i_uid)
2161 + || !gid_eq(h_inode->i_gid, inode->i_gid))
2162 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
2164 + i_uid_read(inode), i_gid_read(inode),
2165 + (inode->i_mode & S_IALLUGO),
2166 + i_uid_read(h_inode), i_gid_read(h_inode),
2167 + (h_inode->i_mode & S_IALLUGO));
2175 + * initialize or clean the whiteouts for an adding branch
2177 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
2180 + int err, old_perm;
2181 + aufs_bindex_t bindex;
2182 + struct mutex *h_mtx;
2183 + struct au_wbr *wbr;
2184 + struct au_hinode *hdir;
2186 + err = vfsub_mnt_want_write(au_br_mnt(br));
2187 + if (unlikely(err))
2191 + old_perm = br->br_perm;
2192 + br->br_perm = new_perm;
2195 + bindex = au_br_index(sb, br->br_id);
2196 + if (0 <= bindex) {
2197 + hdir = au_hi(sb->s_root->d_inode, bindex);
2198 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
2200 + h_mtx = &au_br_dentry(br)->d_inode->i_mutex;
2201 + mutex_lock_nested(h_mtx, AuLsc_I_PARENT);
2204 + err = au_wh_init(br, sb);
2206 + wbr_wh_write_lock(wbr);
2207 + err = au_wh_init(br, sb);
2208 + wbr_wh_write_unlock(wbr);
2211 + au_hn_imtx_unlock(hdir);
2213 + mutex_unlock(h_mtx);
2214 + vfsub_mnt_drop_write(au_br_mnt(br));
2215 + br->br_perm = old_perm;
2217 + if (!err && wbr && !au_br_writable(new_perm)) {
2219 + br->br_wbr = NULL;
2226 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
2230 + struct kstatfs kst;
2231 + struct au_wbr *wbr;
2234 + au_rw_init(&wbr->wbr_wh_rwsem);
2235 + memset(wbr->wbr_wh, 0, sizeof(wbr->wbr_wh));
2236 + atomic_set(&wbr->wbr_wh_running, 0);
2237 + wbr->wbr_bytes = 0;
2240 + * a limit for rmdir/rename a dir
2241 + * cf. AUFS_MAX_NAMELEN in include/linux/aufs_type.h
2243 + err = vfs_statfs(&br->br_path, &kst);
2244 + if (unlikely(err))
2247 + if (kst.f_namelen >= NAME_MAX)
2248 + err = au_br_init_wh(sb, br, perm);
2250 + pr_err("%.*s(%s), unsupported namelen %ld\n",
2251 + AuDLNPair(au_br_dentry(br)),
2252 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
2258 +/* intialize a new branch */
2259 +static int au_br_init(struct au_branch *br, struct super_block *sb,
2260 + struct au_opt_add *add)
2265 + memset(&br->br_xino, 0, sizeof(br->br_xino));
2266 + mutex_init(&br->br_xino.xi_nondir_mtx);
2267 + br->br_perm = add->perm;
2268 + BUILD_BUG_ON(sizeof(br->br_dflags)
2269 + != sizeof(br->br_path.dentry->d_flags));
2270 + br->br_dflags = DCACHE_MOUNTED;
2271 + br->br_path = add->path; /* set first, path_get() later */
2272 + spin_lock_init(&br->br_dykey_lock);
2273 + memset(br->br_dykey, 0, sizeof(br->br_dykey));
2274 + atomic_set(&br->br_count, 0);
2275 + br->br_xino_upper = AUFS_XINO_TRUNC_INIT;
2276 + atomic_set(&br->br_xino_running, 0);
2277 + br->br_id = au_new_br_id(sb);
2278 + AuDebugOn(br->br_id < 0);
2280 + if (au_br_writable(add->perm)) {
2281 + err = au_wbr_init(br, sb, add->perm);
2282 + if (unlikely(err))
2286 + if (au_opt_test(au_mntflags(sb), XINO)) {
2287 + err = au_xino_br(sb, br, add->path.dentry->d_inode->i_ino,
2288 + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1);
2289 + if (unlikely(err)) {
2290 + AuDebugOn(br->br_xino.xi_file);
2295 + sysaufs_br_init(br);
2296 + path_get(&br->br_path);
2297 + goto out; /* success */
2300 + memset(&br->br_path, 0, sizeof(br->br_path));
2305 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
2306 + struct au_branch *br, aufs_bindex_t bend,
2307 + aufs_bindex_t amount)
2309 + struct au_branch **brp;
2311 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2313 + brp = sbinfo->si_branch + bindex;
2314 + memmove(brp + 1, brp, sizeof(*brp) * amount);
2316 + sbinfo->si_bend++;
2317 + if (unlikely(bend < 0))
2318 + sbinfo->si_bend = 0;
2321 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
2322 + aufs_bindex_t bend, aufs_bindex_t amount)
2324 + struct au_hdentry *hdp;
2326 + AuRwMustWriteLock(&dinfo->di_rwsem);
2328 + hdp = dinfo->di_hdentry + bindex;
2329 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
2330 + au_h_dentry_init(hdp);
2332 + if (unlikely(bend < 0))
2333 + dinfo->di_bstart = 0;
2336 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
2337 + aufs_bindex_t bend, aufs_bindex_t amount)
2339 + struct au_hinode *hip;
2341 + AuRwMustWriteLock(&iinfo->ii_rwsem);
2343 + hip = iinfo->ii_hinode + bindex;
2344 + memmove(hip + 1, hip, sizeof(*hip) * amount);
2345 + hip->hi_inode = NULL;
2348 + if (unlikely(bend < 0))
2349 + iinfo->ii_bstart = 0;
2352 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
2353 + aufs_bindex_t bindex)
2355 + struct dentry *root, *h_dentry;
2356 + struct inode *root_inode;
2357 + aufs_bindex_t bend, amount;
2359 + au_br_dflags_force(br);
2361 + root = sb->s_root;
2362 + root_inode = root->d_inode;
2363 + bend = au_sbend(sb);
2364 + amount = bend + 1 - bindex;
2365 + h_dentry = au_br_dentry(br);
2366 + au_sbilist_lock();
2367 + au_br_do_add_brp(au_sbi(sb), bindex, br, bend, amount);
2368 + au_br_do_add_hdp(au_di(root), bindex, bend, amount);
2369 + au_br_do_add_hip(au_ii(root_inode), bindex, bend, amount);
2370 + au_set_h_dptr(root, bindex, dget(h_dentry));
2371 + au_set_h_iptr(root_inode, bindex, au_igrab(h_dentry->d_inode),
2373 + au_sbilist_unlock();
2376 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
2379 + aufs_bindex_t bend, add_bindex;
2380 + struct dentry *root, *h_dentry;
2381 + struct inode *root_inode;
2382 + struct au_branch *add_branch;
2384 + root = sb->s_root;
2385 + root_inode = root->d_inode;
2386 + IMustLock(root_inode);
2387 + err = test_add(sb, add, remount);
2388 + if (unlikely(err < 0))
2392 + goto out; /* success */
2395 + bend = au_sbend(sb);
2396 + add_branch = au_br_alloc(sb, bend + 2, add->perm);
2397 + err = PTR_ERR(add_branch);
2398 + if (IS_ERR(add_branch))
2401 + err = au_br_init(add_branch, sb, add);
2402 + if (unlikely(err)) {
2403 + au_br_do_free(add_branch);
2407 + add_bindex = add->bindex;
2409 + au_br_do_add(sb, add_branch, add_bindex);
2411 + sysaufs_brs_del(sb, add_bindex);
2412 + au_br_do_add(sb, add_branch, add_bindex);
2413 + sysaufs_brs_add(sb, add_bindex);
2416 + h_dentry = add->path.dentry;
2417 + if (!add_bindex) {
2418 + au_cpup_attr_all(root_inode, /*force*/1);
2419 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
2421 + au_add_nlink(root_inode, h_dentry->d_inode);
2424 + * this test/set prevents aufs from handling unnecesary notify events
2425 + * of xino files, in case of re-adding a writable branch which was
2426 + * once detached from aufs.
2428 + if (au_xino_brid(sb) < 0
2429 + && au_br_writable(add_branch->br_perm)
2430 + && !au_test_fs_bad_xino(h_dentry->d_sb)
2431 + && add_branch->br_xino.xi_file
2432 + && add_branch->br_xino.xi_file->f_dentry->d_parent == h_dentry)
2433 + au_xino_brid_set(sb, add_branch->br_id);
2439 +/* ---------------------------------------------------------------------- */
2445 +/* to show the line number, do not make it inlined function */
2446 +#define AuVerbose(do_info, fmt, ...) do { \
2448 + pr_info(fmt, ##__VA_ARGS__); \
2451 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t bstart,
2452 + aufs_bindex_t bend)
2454 + return (inode && !S_ISDIR(inode->i_mode)) || bstart == bend;
2457 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t bstart,
2458 + aufs_bindex_t bend)
2460 + return au_test_ibusy(dentry->d_inode, bstart, bend);
2464 + * test if the branch is deletable or not.
2466 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
2467 + unsigned int sigen, const unsigned int verbose)
2469 + int err, i, j, ndentry;
2470 + aufs_bindex_t bstart, bend;
2471 + struct au_dcsub_pages dpages;
2472 + struct au_dpage *dpage;
2475 + err = au_dpages_init(&dpages, GFP_NOFS);
2476 + if (unlikely(err))
2478 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
2479 + if (unlikely(err))
2482 + for (i = 0; !err && i < dpages.ndpage; i++) {
2483 + dpage = dpages.dpages + i;
2484 + ndentry = dpage->ndentry;
2485 + for (j = 0; !err && j < ndentry; j++) {
2486 + d = dpage->dentries[j];
2487 + AuDebugOn(!d->d_count);
2488 + if (!au_digen_test(d, sigen)) {
2489 + di_read_lock_child(d, AuLock_IR);
2490 + if (unlikely(au_dbrange_test(d))) {
2491 + di_read_unlock(d, AuLock_IR);
2495 + di_write_lock_child(d);
2496 + if (unlikely(au_dbrange_test(d))) {
2497 + di_write_unlock(d);
2500 + err = au_reval_dpath(d, sigen);
2502 + di_downgrade_lock(d, AuLock_IR);
2504 + di_write_unlock(d);
2509 + /* AuDbgDentry(d); */
2510 + bstart = au_dbstart(d);
2511 + bend = au_dbend(d);
2512 + if (bstart <= bindex
2514 + && au_h_dptr(d, bindex)
2515 + && au_test_dbusy(d, bstart, bend)) {
2517 + AuVerbose(verbose, "busy %.*s\n", AuDLNPair(d));
2520 + di_read_unlock(d, AuLock_IR);
2525 + au_dpages_free(&dpages);
2530 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
2531 + unsigned int sigen, const unsigned int verbose)
2534 + unsigned long long max, ull;
2535 + struct inode *i, **array;
2536 + aufs_bindex_t bstart, bend;
2538 + array = au_iarray_alloc(sb, &max);
2539 + err = PTR_ERR(array);
2540 + if (IS_ERR(array))
2544 + AuDbg("b%d\n", bindex);
2545 + for (ull = 0; !err && ull < max; ull++) {
2547 + if (i->i_ino == AUFS_ROOT_INO)
2550 + /* AuDbgInode(i); */
2551 + if (au_iigen(i, NULL) == sigen)
2552 + ii_read_lock_child(i);
2554 + ii_write_lock_child(i);
2555 + err = au_refresh_hinode_self(i);
2558 + ii_downgrade_lock(i);
2560 + ii_write_unlock(i);
2565 + bstart = au_ibstart(i);
2566 + bend = au_ibend(i);
2567 + if (bstart <= bindex
2569 + && au_h_iptr(i, bindex)
2570 + && au_test_ibusy(i, bstart, bend)) {
2572 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
2575 + ii_read_unlock(i);
2577 + au_iarray_free(array, max);
2583 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
2584 + const unsigned int verbose)
2587 + unsigned int sigen;
2589 + sigen = au_sigen(root->d_sb);
2590 + DiMustNoWaiters(root);
2591 + IiMustNoWaiters(root->d_inode);
2592 + di_write_unlock(root);
2593 + err = test_dentry_busy(root, bindex, sigen, verbose);
2595 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
2596 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
2601 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
2602 + const aufs_bindex_t bindex,
2603 + const aufs_bindex_t bend)
2605 + struct au_branch **brp, **p;
2607 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2609 + brp = sbinfo->si_branch + bindex;
2610 + if (bindex < bend)
2611 + memmove(brp, brp + 1, sizeof(*brp) * (bend - bindex));
2612 + sbinfo->si_branch[0 + bend] = NULL;
2613 + sbinfo->si_bend--;
2615 + p = krealloc(sbinfo->si_branch, sizeof(*p) * bend, AuGFP_SBILIST);
2617 + sbinfo->si_branch = p;
2618 + /* harmless error */
2621 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
2622 + const aufs_bindex_t bend)
2624 + struct au_hdentry *hdp, *p;
2626 + AuRwMustWriteLock(&dinfo->di_rwsem);
2628 + hdp = dinfo->di_hdentry;
2629 + if (bindex < bend)
2630 + memmove(hdp + bindex, hdp + bindex + 1,
2631 + sizeof(*hdp) * (bend - bindex));
2632 + hdp[0 + bend].hd_dentry = NULL;
2635 + p = krealloc(hdp, sizeof(*p) * bend, AuGFP_SBILIST);
2637 + dinfo->di_hdentry = p;
2638 + /* harmless error */
2641 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
2642 + const aufs_bindex_t bend)
2644 + struct au_hinode *hip, *p;
2646 + AuRwMustWriteLock(&iinfo->ii_rwsem);
2648 + hip = iinfo->ii_hinode + bindex;
2649 + if (bindex < bend)
2650 + memmove(hip, hip + 1, sizeof(*hip) * (bend - bindex));
2651 + iinfo->ii_hinode[0 + bend].hi_inode = NULL;
2652 + au_hn_init(iinfo->ii_hinode + bend);
2655 + p = krealloc(iinfo->ii_hinode, sizeof(*p) * bend, AuGFP_SBILIST);
2657 + iinfo->ii_hinode = p;
2658 + /* harmless error */
2661 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
2662 + struct au_branch *br)
2664 + aufs_bindex_t bend;
2665 + struct au_sbinfo *sbinfo;
2666 + struct dentry *root, *h_root;
2667 + struct inode *inode, *h_inode;
2668 + struct au_hinode *hinode;
2670 + SiMustWriteLock(sb);
2672 + root = sb->s_root;
2673 + inode = root->d_inode;
2674 + sbinfo = au_sbi(sb);
2675 + bend = sbinfo->si_bend;
2677 + h_root = au_h_dptr(root, bindex);
2678 + hinode = au_hi(inode, bindex);
2679 + h_inode = au_igrab(hinode->hi_inode);
2682 + au_sbilist_lock();
2683 + au_br_do_del_brp(sbinfo, bindex, bend);
2684 + au_br_do_del_hdp(au_di(root), bindex, bend);
2685 + au_br_do_del_hip(au_ii(inode), bindex, bend);
2686 + au_sbilist_unlock();
2690 + au_br_do_free(br);
2693 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
2696 + unsigned int mnt_flags;
2697 + aufs_bindex_t bindex, bend, br_id;
2698 + unsigned char do_wh, verbose;
2699 + struct au_branch *br;
2700 + struct au_wbr *wbr;
2703 + bindex = au_find_dbindex(sb->s_root, del->h_path.dentry);
2706 + goto out; /* success */
2708 + pr_err("%s no such branch\n", del->pathname);
2711 + AuDbg("bindex b%d\n", bindex);
2714 + mnt_flags = au_mntflags(sb);
2715 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
2716 + bend = au_sbend(sb);
2717 + if (unlikely(!bend)) {
2718 + AuVerbose(verbose, "no more branches left\n");
2721 + br = au_sbr(sb, bindex);
2722 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
2723 + i = atomic_read(&br->br_count);
2724 + if (unlikely(i)) {
2725 + AuVerbose(verbose, "%d file(s) opened\n", i);
2730 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
2732 + /* instead of WbrWhMustWriteLock(wbr) */
2733 + SiMustWriteLock(sb);
2734 + for (i = 0; i < AuBrWh_Last; i++) {
2735 + dput(wbr->wbr_wh[i]);
2736 + wbr->wbr_wh[i] = NULL;
2740 + err = test_children_busy(sb->s_root, bindex, verbose);
2741 + if (unlikely(err)) {
2748 + br_id = br->br_id;
2750 + au_br_do_del(sb, bindex, br);
2752 + sysaufs_brs_del(sb, bindex);
2753 + au_br_do_del(sb, bindex, br);
2754 + sysaufs_brs_add(sb, bindex);
2758 + au_cpup_attr_all(sb->s_root->d_inode, /*force*/1);
2759 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
2761 + au_sub_nlink(sb->s_root->d_inode, del->h_path.dentry->d_inode);
2762 + if (au_opt_test(mnt_flags, PLINK))
2763 + au_plink_half_refresh(sb, br_id);
2765 + if (au_xino_brid(sb) == br_id)
2766 + au_xino_brid_set(sb, -1);
2767 + goto out; /* success */
2771 + rerr = au_br_init_wh(sb, br, br->br_perm);
2773 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
2774 + del->pathname, rerr);
2779 +/* ---------------------------------------------------------------------- */
2781 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
2784 + aufs_bindex_t bstart, bend;
2785 + struct aufs_ibusy ibusy;
2786 + struct inode *inode, *h_inode;
2789 + if (unlikely(!capable(CAP_SYS_ADMIN)))
2792 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
2794 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
2795 + if (unlikely(err)) {
2802 + si_read_lock(sb, AuLock_FLUSH);
2803 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbend(sb)))
2807 + ibusy.h_ino = 0; /* invalid */
2808 + inode = ilookup(sb, ibusy.ino);
2810 + || inode->i_ino == AUFS_ROOT_INO
2811 + || is_bad_inode(inode))
2814 + ii_read_lock_child(inode);
2815 + bstart = au_ibstart(inode);
2816 + bend = au_ibend(inode);
2817 + if (bstart <= ibusy.bindex && ibusy.bindex <= bend) {
2818 + h_inode = au_h_iptr(inode, ibusy.bindex);
2819 + if (h_inode && au_test_ibusy(inode, bstart, bend))
2820 + ibusy.h_ino = h_inode->i_ino;
2822 + ii_read_unlock(inode);
2826 + si_read_unlock(sb);
2828 + err = __put_user(ibusy.h_ino, &arg->h_ino);
2829 + if (unlikely(err)) {
2838 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
2840 + return au_ibusy(file->f_dentry->d_sb, (void __user *)arg);
2843 +#ifdef CONFIG_COMPAT
2844 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
2846 + return au_ibusy(file->f_dentry->d_sb, compat_ptr(arg));
2850 +/* ---------------------------------------------------------------------- */
2853 + * change a branch permission
2856 +static void au_warn_ima(void)
2859 + /* since it doesn't support mark_files_ro() */
2860 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
2864 +static int do_need_sigen_inc(int a, int b)
2866 + return au_br_whable(a) && !au_br_whable(b);
2869 +static int need_sigen_inc(int old, int new)
2871 + return do_need_sigen_inc(old, new)
2872 + || do_need_sigen_inc(new, old);
2875 +static unsigned long long au_farray_cb(void *a,
2876 + unsigned long long max __maybe_unused,
2879 + unsigned long long n;
2880 + struct file **p, *f;
2881 + struct au_sphlhead *files;
2882 + struct au_finfo *finfo;
2883 + struct super_block *sb = arg;
2887 + files = &au_sbi(sb)->si_files;
2888 + spin_lock(&files->spin);
2889 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
2890 + f = finfo->fi_file;
2892 + && !special_file(file_inode(f)->i_mode)) {
2896 + AuDebugOn(n > max);
2899 + spin_unlock(&files->spin);
2904 +static struct file **au_farray_alloc(struct super_block *sb,
2905 + unsigned long long *max)
2907 + *max = atomic_long_read(&au_sbi(sb)->si_nfiles);
2908 + return au_array_alloc(max, au_farray_cb, sb);
2911 +static void au_farray_free(struct file **a, unsigned long long max)
2913 + unsigned long long ull;
2915 + for (ull = 0; ull < max; ull++)
2921 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
2924 + unsigned int mnt_flags;
2925 + unsigned long long ull, max;
2926 + aufs_bindex_t br_id;
2927 + unsigned char verbose;
2928 + struct file *file, *hf, **array;
2929 + struct inode *inode;
2930 + struct au_hfile *hfile;
2932 + mnt_flags = au_mntflags(sb);
2933 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
2935 + array = au_farray_alloc(sb, &max);
2936 + err = PTR_ERR(array);
2937 + if (IS_ERR(array))
2941 + br_id = au_sbr_id(sb, bindex);
2942 + for (ull = 0; ull < max; ull++) {
2943 + file = array[ull];
2945 + /* AuDbg("%.*s\n", AuDLNPair(file->f_dentry)); */
2946 + fi_read_lock(file);
2947 + if (unlikely(au_test_mmapped(file))) {
2949 + AuVerbose(verbose, "mmapped %.*s\n",
2950 + AuDLNPair(file->f_dentry));
2952 + FiMustNoWaiters(file);
2953 + fi_read_unlock(file);
2957 + inode = file_inode(file);
2958 + hfile = &au_fi(file)->fi_htop;
2959 + hf = hfile->hf_file;
2960 + if (!S_ISREG(inode->i_mode)
2961 + || !(file->f_mode & FMODE_WRITE)
2962 + || hfile->hf_br->br_id != br_id
2963 + || !(hf->f_mode & FMODE_WRITE))
2964 + array[ull] = NULL;
2970 + FiMustNoWaiters(file);
2971 + fi_read_unlock(file);
2979 + for (ull = 0; ull < max; ull++) {
2980 + file = array[ull];
2984 + /* todo: already flushed? */
2986 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
2987 + * approach which resets f_mode and calls mnt_drop_write() and
2988 + * file_release_write() for each file, because the branch
2989 + * attribute in aufs world is totally different from the native
2992 + /* fi_read_lock(file); */
2993 + hfile = &au_fi(file)->fi_htop;
2994 + hf = hfile->hf_file;
2995 + /* fi_read_unlock(file); */
2996 + spin_lock(&hf->f_lock);
2997 + hf->f_mode &= ~FMODE_WRITE;
2998 + spin_unlock(&hf->f_lock);
2999 + if (!file_check_writeable(hf)) {
3000 + __mnt_drop_write(hf->f_path.mnt);
3001 + file_release_write(hf);
3006 + au_farray_free(array, max);
3012 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
3016 + aufs_bindex_t bindex;
3017 + struct dentry *root;
3018 + struct au_branch *br;
3020 + root = sb->s_root;
3021 + bindex = au_find_dbindex(root, mod->h_root);
3024 + return 0; /* success */
3026 + pr_err("%s no such branch\n", mod->path);
3029 + AuDbg("bindex b%d\n", bindex);
3031 + err = test_br(mod->h_root->d_inode, mod->perm, mod->path);
3032 + if (unlikely(err))
3035 + br = au_sbr(sb, bindex);
3036 + AuDebugOn(mod->h_root != au_br_dentry(br));
3037 + if (br->br_perm == mod->perm)
3038 + return 0; /* success */
3040 + if (au_br_writable(br->br_perm)) {
3041 + /* remove whiteout base */
3042 + err = au_br_init_wh(sb, br, mod->perm);
3043 + if (unlikely(err))
3046 + if (!au_br_writable(mod->perm)) {
3047 + /* rw --> ro, file might be mmapped */
3048 + DiMustNoWaiters(root);
3049 + IiMustNoWaiters(root->d_inode);
3050 + di_write_unlock(root);
3051 + err = au_br_mod_files_ro(sb, bindex);
3052 + /* aufs_write_lock() calls ..._child() */
3053 + di_write_lock_child(root);
3055 + if (unlikely(err)) {
3057 + br->br_wbr = kmalloc(sizeof(*br->br_wbr),
3060 + rerr = au_wbr_init(br, sb, br->br_perm);
3061 + if (unlikely(rerr)) {
3062 + AuIOErr("nested error %d (%d)\n",
3064 + br->br_perm = mod->perm;
3068 + } else if (au_br_writable(mod->perm)) {
3071 + br->br_wbr = kmalloc(sizeof(*br->br_wbr), GFP_NOFS);
3073 + err = au_wbr_init(br, sb, mod->perm);
3074 + if (unlikely(err)) {
3075 + kfree(br->br_wbr);
3076 + br->br_wbr = NULL;
3082 + if ((br->br_perm & AuBrAttr_UNPIN)
3083 + && !(mod->perm & AuBrAttr_UNPIN))
3084 + au_br_dflags_force(br);
3085 + else if (!(br->br_perm & AuBrAttr_UNPIN)
3086 + && (mod->perm & AuBrAttr_UNPIN))
3087 + au_br_dflags_restore(br);
3088 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
3089 + br->br_perm = mod->perm;
3096 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
3097 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
3098 +++ linux/fs/aufs/branch.h 2013-07-06 13:20:47.740198107 +0200
3101 + * Copyright (C) 2005-2013 Junjiro R. Okajima
3103 + * This program, aufs is free software; you can redistribute it and/or modify
3104 + * it under the terms of the GNU General Public License as published by
3105 + * the Free Software Foundation; either version 2 of the License, or
3106 + * (at your option) any later version.
3108 + * This program is distributed in the hope that it will be useful,
3109 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3110 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3111 + * GNU General Public License for more details.
3113 + * You should have received a copy of the GNU General Public License
3114 + * along with this program; if not, write to the Free Software
3115 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3119 + * branch filesystems and xino for them
3122 +#ifndef __AUFS_BRANCH_H__
3123 +#define __AUFS_BRANCH_H__
3127 +#include <linux/mount.h>
3132 +/* ---------------------------------------------------------------------- */
3135 +struct au_xino_file {
3136 + struct file *xi_file;
3137 + struct mutex xi_nondir_mtx;
3139 + /* todo: make xino files an array to support huge inode number */
3141 +#ifdef CONFIG_DEBUG_FS
3142 + struct dentry *xi_dbgaufs;
3146 +/* members for writable branch only */
3147 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
3149 + struct au_rwsem wbr_wh_rwsem;
3150 + struct dentry *wbr_wh[AuBrWh_Last];
3151 + atomic_t wbr_wh_running;
3152 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
3153 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
3154 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
3157 + unsigned long long wbr_bytes;
3160 +/* ext2 has 3 types of operations at least, ext3 has 4 */
3161 +#define AuBrDynOp (AuDyLast * 4)
3163 +#ifdef CONFIG_AUFS_HFSNOTIFY
3164 +/* support for asynchronous destruction */
3165 +struct au_br_hfsnotify {
3166 + struct fsnotify_group *hfsn_group;
3170 +/* protected by superblock rwsem */
3172 + struct au_xino_file br_xino;
3174 + aufs_bindex_t br_id;
3177 + unsigned int br_dflags;
3178 + struct path br_path;
3179 + spinlock_t br_dykey_lock;
3180 + struct au_dykey *br_dykey[AuBrDynOp];
3181 + atomic_t br_count;
3183 + struct au_wbr *br_wbr;
3185 + /* xino truncation */
3186 + blkcnt_t br_xino_upper; /* watermark in blocks */
3187 + atomic_t br_xino_running;
3189 +#ifdef CONFIG_AUFS_HFSNOTIFY
3190 + struct au_br_hfsnotify *br_hfsn;
3193 +#ifdef CONFIG_SYSFS
3194 + /* an entry under sysfs per mount-point */
3196 + struct attribute br_attr;
3200 +/* ---------------------------------------------------------------------- */
3202 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
3204 + return br->br_path.mnt;
3207 +static inline struct dentry *au_br_dentry(struct au_branch *br)
3209 + return br->br_path.dentry;
3212 +static inline struct super_block *au_br_sb(struct au_branch *br)
3214 + return au_br_mnt(br)->mnt_sb;
3217 +/* branch permissions and attributes */
3218 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
3219 +#define AuBrPerm_RO (1 << 1) /* readonly */
3220 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
3221 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
3223 +#define AuBrRAttr_WH (1 << 3) /* whiteout-able */
3225 +#define AuBrWAttr_NoLinkWH (1 << 4) /* un-hardlinkable whiteouts */
3227 +#define AuBrAttr_UNPIN (1 << 5) /* rename-able top dir of
3230 +static inline int au_br_writable(int brperm)
3232 + return brperm & AuBrPerm_RW;
3235 +static inline int au_br_whable(int brperm)
3237 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
3240 +static inline int au_br_wh_linkable(int brperm)
3242 + return !(brperm & AuBrWAttr_NoLinkWH);
3245 +static inline int au_br_rdonly(struct au_branch *br)
3247 + return ((au_br_sb(br)->s_flags & MS_RDONLY)
3248 + || !au_br_writable(br->br_perm))
3252 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
3254 +#ifdef CONFIG_AUFS_HNOTIFY
3255 + return !(brperm & AuBrPerm_RR);
3261 +/* ---------------------------------------------------------------------- */
3265 +void au_br_free(struct au_sbinfo *sinfo);
3266 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
3268 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
3270 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
3271 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
3272 +#ifdef CONFIG_COMPAT
3273 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
3276 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
3280 +static const loff_t au_loff_max = LLONG_MAX;
3282 +int au_xib_trunc(struct super_block *sb);
3283 +ssize_t xino_fread(au_readf_t func, struct file *file, void *buf, size_t size,
3285 +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size,
3287 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src);
3288 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent);
3289 +ino_t au_xino_new_ino(struct super_block *sb);
3290 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
3291 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
3293 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
3295 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino,
3296 + struct file *base_file, int do_test);
3297 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex);
3299 +struct au_opt_xino;
3300 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount);
3301 +void au_xino_clr(struct super_block *sb);
3302 +struct file *au_xino_def(struct super_block *sb);
3303 +int au_xino_path(struct seq_file *seq, struct file *file);
3305 +/* ---------------------------------------------------------------------- */
3307 +/* Superblock to branch */
3309 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
3311 + return au_sbr(sb, bindex)->br_id;
3315 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
3317 + return au_br_mnt(au_sbr(sb, bindex));
3321 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
3323 + return au_br_sb(au_sbr(sb, bindex));
3326 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
3328 + atomic_dec(&au_sbr(sb, bindex)->br_count);
3331 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
3333 + return au_sbr(sb, bindex)->br_perm;
3336 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
3338 + return au_br_whable(au_sbr_perm(sb, bindex));
3341 +/* ---------------------------------------------------------------------- */
3344 + * wbr_wh_read_lock, wbr_wh_write_lock
3345 + * wbr_wh_read_unlock, wbr_wh_write_unlock, wbr_wh_downgrade_lock
3347 +AuSimpleRwsemFuncs(wbr_wh, struct au_wbr *wbr, &wbr->wbr_wh_rwsem);
3349 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&wbr->wbr_wh_rwsem)
3350 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&wbr->wbr_wh_rwsem)
3351 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&wbr->wbr_wh_rwsem)
3353 +#endif /* __KERNEL__ */
3354 +#endif /* __AUFS_BRANCH_H__ */
3355 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
3356 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
3357 +++ linux/fs/aufs/conf.mk 2013-07-06 13:20:47.740198107 +0200
3360 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
3364 +AuConfStr += ${1}=${${1}}
3368 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
3370 + HNOTIFY HFSNOTIFY \
3381 +$(foreach i, ${AuConfAll}, \
3382 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
3384 +AuConfName = ${obj}/conf.str
3385 +${AuConfName}.tmp: FORCE
3386 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
3387 +${AuConfName}: ${AuConfName}.tmp
3388 + @diff -q $< $@ > /dev/null 2>&1 || { \
3389 + echo ' GEN ' $@; \
3393 +clean-files += ${AuConfName} ${AuConfName}.tmp
3394 +${obj}/sysfs.o: ${AuConfName}
3396 +-include ${srctree}/${src}/conf_priv.mk
3397 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
3398 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
3399 +++ linux/fs/aufs/cpup.c 2013-08-23 23:59:39.631583456 +0200
3402 + * Copyright (C) 2005-2013 Junjiro R. Okajima
3404 + * This program, aufs is free software; you can redistribute it and/or modify
3405 + * it under the terms of the GNU General Public License as published by
3406 + * the Free Software Foundation; either version 2 of the License, or
3407 + * (at your option) any later version.
3409 + * This program is distributed in the hope that it will be useful,
3410 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3411 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3412 + * GNU General Public License for more details.
3414 + * You should have received a copy of the GNU General Public License
3415 + * along with this program; if not, write to the Free Software
3416 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3420 + * copy-up functions, see wbr_policy.c for copy-down
3423 +#include <linux/fs_stack.h>
3424 +#include <linux/mm.h>
3427 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
3429 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
3430 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
3432 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
3434 + dst->i_flags |= iflags & ~mask;
3435 + if (au_test_fs_notime(dst->i_sb))
3436 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
3439 +void au_cpup_attr_timesizes(struct inode *inode)
3441 + struct inode *h_inode;
3443 + h_inode = au_h_iptr(inode, au_ibstart(inode));
3444 + fsstack_copy_attr_times(inode, h_inode);
3445 + fsstack_copy_inode_size(inode, h_inode);
3448 +void au_cpup_attr_nlink(struct inode *inode, int force)
3450 + struct inode *h_inode;
3451 + struct super_block *sb;
3452 + aufs_bindex_t bindex, bend;
3455 + bindex = au_ibstart(inode);
3456 + h_inode = au_h_iptr(inode, bindex);
3458 + && !S_ISDIR(h_inode->i_mode)
3459 + && au_opt_test(au_mntflags(sb), PLINK)
3460 + && au_plink_test(inode))
3464 + * 0 can happen in revalidating.
3465 + * h_inode->i_mutex is not held, but it is harmless since once i_nlink
3466 + * reaches 0, it will never become positive.
3468 + set_nlink(inode, h_inode->i_nlink);
3471 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
3472 + * it may includes whplink directory.
3474 + if (S_ISDIR(h_inode->i_mode)) {
3475 + bend = au_ibend(inode);
3476 + for (bindex++; bindex <= bend; bindex++) {
3477 + h_inode = au_h_iptr(inode, bindex);
3479 + au_add_nlink(inode, h_inode);
3484 +void au_cpup_attr_changeable(struct inode *inode)
3486 + struct inode *h_inode;
3488 + h_inode = au_h_iptr(inode, au_ibstart(inode));
3489 + inode->i_mode = h_inode->i_mode;
3490 + inode->i_uid = h_inode->i_uid;
3491 + inode->i_gid = h_inode->i_gid;
3492 + au_cpup_attr_timesizes(inode);
3493 + au_cpup_attr_flags(inode, h_inode->i_flags);
3496 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
3498 + struct au_iinfo *iinfo = au_ii(inode);
3500 + IiMustWriteLock(inode);
3502 + iinfo->ii_higen = h_inode->i_generation;
3503 + iinfo->ii_hsb1 = h_inode->i_sb;
3506 +void au_cpup_attr_all(struct inode *inode, int force)
3508 + struct inode *h_inode;
3510 + h_inode = au_h_iptr(inode, au_ibstart(inode));
3511 + au_cpup_attr_changeable(inode);
3512 + if (inode->i_nlink > 0)
3513 + au_cpup_attr_nlink(inode, force);
3514 + inode->i_rdev = h_inode->i_rdev;
3515 + inode->i_blkbits = h_inode->i_blkbits;
3516 + au_cpup_igen(inode, h_inode);
3519 +/* ---------------------------------------------------------------------- */
3521 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
3523 +/* keep the timestamps of the parent dir when cpup */
3524 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
3525 + struct path *h_path)
3527 + struct inode *h_inode;
3529 + dt->dt_dentry = dentry;
3530 + dt->dt_h_path = *h_path;
3531 + h_inode = h_path->dentry->d_inode;
3532 + dt->dt_atime = h_inode->i_atime;
3533 + dt->dt_mtime = h_inode->i_mtime;
3537 +void au_dtime_revert(struct au_dtime *dt)
3539 + struct iattr attr;
3542 + attr.ia_atime = dt->dt_atime;
3543 + attr.ia_mtime = dt->dt_mtime;
3544 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
3545 + | ATTR_ATIME | ATTR_ATIME_SET;
3547 + err = vfsub_notify_change(&dt->dt_h_path, &attr);
3548 + if (unlikely(err))
3549 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
3552 +/* ---------------------------------------------------------------------- */
3554 +/* internal use only */
3555 +struct au_cpup_reg_attr {
3558 + unsigned int iflags; /* inode->i_flags */
3561 +static noinline_for_stack
3562 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
3563 + struct au_cpup_reg_attr *h_src_attr)
3567 + struct path h_path;
3568 + struct inode *h_isrc, *h_idst;
3569 + struct kstat *h_st;
3571 + h_path.dentry = au_h_dptr(dst, bindex);
3572 + h_idst = h_path.dentry->d_inode;
3573 + h_path.mnt = au_sbr_mnt(dst->d_sb, bindex);
3574 + h_isrc = h_src->d_inode;
3575 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
3576 + | ATTR_ATIME | ATTR_MTIME
3577 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
3578 + if (h_src_attr && h_src_attr->valid) {
3579 + h_st = &h_src_attr->st;
3580 + ia.ia_uid = h_st->uid;
3581 + ia.ia_gid = h_st->gid;
3582 + ia.ia_atime = h_st->atime;
3583 + ia.ia_mtime = h_st->mtime;
3584 + if (h_idst->i_mode != h_st->mode
3585 + && !S_ISLNK(h_idst->i_mode)) {
3586 + ia.ia_valid |= ATTR_MODE;
3587 + ia.ia_mode = h_st->mode;
3589 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
3590 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
3592 + ia.ia_uid = h_isrc->i_uid;
3593 + ia.ia_gid = h_isrc->i_gid;
3594 + ia.ia_atime = h_isrc->i_atime;
3595 + ia.ia_mtime = h_isrc->i_mtime;
3596 + if (h_idst->i_mode != h_isrc->i_mode
3597 + && !S_ISLNK(h_idst->i_mode)) {
3598 + ia.ia_valid |= ATTR_MODE;
3599 + ia.ia_mode = h_isrc->i_mode;
3601 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
3602 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
3604 + err = vfsub_notify_change(&h_path, &ia);
3606 + /* is this nfs only? */
3607 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
3608 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
3609 + ia.ia_mode = h_isrc->i_mode;
3610 + err = vfsub_notify_change(&h_path, &ia);
3616 +/* ---------------------------------------------------------------------- */
3618 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
3619 + char *buf, unsigned long blksize)
3622 + size_t sz, rbytes, wbytes;
3623 + unsigned char all_zero;
3625 + struct mutex *h_mtx;
3626 + /* reduce stack usage */
3629 + zp = page_address(ZERO_PAGE(0));
3630 + if (unlikely(!zp))
3631 + return -ENOMEM; /* possible? */
3636 + AuDbg("len %lld\n", len);
3638 + if (len < blksize)
3642 + /* todo: signal_pending? */
3643 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
3644 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
3647 + if (unlikely(err < 0))
3651 + if (len >= rbytes && rbytes == blksize)
3652 + all_zero = !memcmp(buf, zp, rbytes);
3659 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
3661 + /* todo: signal_pending? */
3662 + if (unlikely(err == -EAGAIN || err == -EINTR))
3664 + if (unlikely(err < 0))
3673 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
3675 + if (unlikely(res < 0))
3682 + /* the last block may be a hole */
3683 + if (!err && all_zero) {
3684 + AuLabel(last hole);
3687 + if (au_test_nfs(dst->f_dentry->d_sb)) {
3688 + /* nfs requires this step to make last hole */
3689 + /* is this only nfs? */
3691 + /* todo: signal_pending? */
3692 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
3693 + } while (err == -EAGAIN || err == -EINTR);
3700 + ia->ia_size = dst->f_pos;
3701 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
3702 + ia->ia_file = dst;
3703 + h_mtx = &file_inode(dst)->i_mutex;
3704 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
3705 + err = vfsub_notify_change(&dst->f_path, ia);
3706 + mutex_unlock(h_mtx);
3713 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
3716 + unsigned long blksize;
3717 + unsigned char do_kfree;
3721 + blksize = dst->f_dentry->d_sb->s_blocksize;
3722 + if (!blksize || PAGE_SIZE < blksize)
3723 + blksize = PAGE_SIZE;
3724 + AuDbg("blksize %lu\n", blksize);
3725 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
3727 + buf = kmalloc(blksize, GFP_NOFS);
3729 + buf = (void *)__get_free_page(GFP_NOFS);
3730 + if (unlikely(!buf))
3733 + if (len > (1 << 22))
3734 + AuDbg("copying a large file %lld\n", (long long)len);
3738 + err = au_do_copy_file(dst, src, len, buf, blksize);
3742 + free_page((unsigned long)buf);
3749 + * to support a sparse file which is opened with O_APPEND,
3750 + * we need to close the file.
3752 +static int au_cp_regular(struct au_cp_generic *cpg)
3755 + enum { SRC, DST };
3757 + aufs_bindex_t bindex;
3758 + unsigned int flags;
3759 + struct dentry *dentry;
3760 + struct file *file;
3761 + void *label, *label_file;
3764 + .bindex = cpg->bsrc,
3765 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
3768 + .label_file = &&out_src
3771 + .bindex = cpg->bdst,
3772 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
3774 + .label = &&out_src,
3775 + .label_file = &&out_dst
3778 + struct super_block *sb;
3780 + /* bsrc branch can be ro/rw. */
3781 + sb = cpg->dentry->d_sb;
3783 + for (i = 0; i < 2; i++, f++) {
3784 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
3785 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
3787 + err = PTR_ERR(f->file);
3788 + if (IS_ERR(f->file))
3791 + if (unlikely(!f->file->f_op))
3792 + goto *f->label_file;
3795 + /* try stopping to update while we copyup */
3796 + IMustLock(file[SRC].dentry->d_inode);
3797 + err = au_copy_file(file[DST].file, file[SRC].file, cpg->len);
3800 + fput(file[DST].file);
3801 + au_sbr_put(sb, file[DST].bindex);
3803 + fput(file[SRC].file);
3804 + au_sbr_put(sb, file[SRC].bindex);
3809 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
3810 + struct au_cpup_reg_attr *h_src_attr)
3814 + struct path h_path;
3815 + struct inode *h_src_inode;
3818 + h_src_inode = au_h_iptr(cpg->dentry->d_inode, cpg->bsrc);
3819 + l = i_size_read(h_src_inode);
3820 + if (cpg->len == -1 || l < cpg->len)
3823 + /* try stopping to update while we are referencing */
3824 + mutex_lock_nested(&h_src_inode->i_mutex, AuLsc_I_CHILD);
3825 + au_pin_hdir_unlock(cpg->pin);
3827 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
3828 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
3829 + h_src_attr->iflags = h_src_inode->i_flags;
3830 + err = vfs_getattr(&h_path, &h_src_attr->st);
3831 + if (unlikely(err)) {
3832 + mutex_unlock(&h_src_inode->i_mutex);
3835 + h_src_attr->valid = 1;
3836 + err = au_cp_regular(cpg);
3837 + mutex_unlock(&h_src_inode->i_mutex);
3838 + rerr = au_pin_hdir_relock(cpg->pin);
3847 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
3848 + struct inode *h_dir)
3851 + mm_segment_t old_fs;
3858 + if (unlikely(!h_src->d_inode->i_op->readlink))
3862 + sym.k = (void *)__get_free_page(GFP_NOFS);
3863 + if (unlikely(!sym.k))
3866 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
3867 + old_fs = get_fs();
3868 + set_fs(KERNEL_DS);
3869 + symlen = h_src->d_inode->i_op->readlink(h_src, sym.u, PATH_MAX);
3874 + sym.k[symlen] = 0;
3875 + err = vfsub_symlink(h_dir, h_path, sym.k);
3877 + free_page((unsigned long)sym.k);
3883 +static noinline_for_stack
3884 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
3885 + struct au_cpup_reg_attr *h_src_attr)
3889 + unsigned int mnt_flags;
3890 + unsigned char isdir;
3891 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
3892 + struct au_dtime dt;
3893 + struct path h_path;
3894 + struct dentry *h_src, *h_dst, *h_parent;
3895 + struct inode *h_inode, *h_dir;
3896 + struct super_block *sb;
3898 + /* bsrc branch can be ro/rw. */
3899 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
3900 + h_inode = h_src->d_inode;
3901 + AuDebugOn(h_inode != au_h_iptr(cpg->dentry->d_inode, cpg->bsrc));
3903 + /* try stopping to be referenced while we are creating */
3904 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
3905 + if (au_ftest_cpup(cpg->flags, RENAME))
3906 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
3907 + AUFS_WH_PFX_LEN));
3908 + h_parent = h_dst->d_parent; /* dir inode is locked */
3909 + h_dir = h_parent->d_inode;
3911 + AuDebugOn(h_parent != h_dst->d_parent);
3913 + sb = cpg->dentry->d_sb;
3914 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
3916 + h_path.dentry = h_parent;
3917 + au_dtime_store(&dt, dst_parent, &h_path);
3919 + h_path.dentry = h_dst;
3922 + mode = h_inode->i_mode;
3923 + switch (mode & S_IFMT) {
3925 + err = vfsub_create(h_dir, &h_path, mode | S_IWUSR,
3926 + /*want_excl*/true);
3928 + err = au_do_cpup_regular(cpg, h_src_attr);
3932 + err = vfsub_mkdir(h_dir, &h_path, mode);
3935 + * strange behaviour from the users view,
3936 + * particularry setattr case
3938 + if (au_ibstart(dst_parent->d_inode) == cpg->bdst)
3939 + au_cpup_attr_nlink(dst_parent->d_inode,
3941 + au_cpup_attr_nlink(cpg->dentry->d_inode, /*force*/1);
3945 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
3949 + AuDebugOn(!capable(CAP_MKNOD));
3953 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
3956 + AuIOErr("Unknown inode type 0%o\n", mode);
3960 + mnt_flags = au_mntflags(sb);
3961 + if (!au_opt_test(mnt_flags, UDBA_NONE)
3963 + && au_opt_test(mnt_flags, XINO)
3964 + && h_inode->i_nlink == 1
3965 + /* todo: unnecessary? */
3966 + /* && cpg->dentry->d_inode->i_nlink == 1 */
3967 + && cpg->bdst < cpg->bsrc
3968 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
3969 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
3970 + /* ignore this error */
3973 + au_dtime_revert(&dt);
3977 +static int au_do_ren_after_cpup(struct dentry *dentry, aufs_bindex_t bdst,
3978 + struct path *h_path)
3981 + struct dentry *h_dentry, *h_parent;
3982 + struct inode *h_dir;
3984 + h_dentry = dget(au_h_dptr(dentry, bdst));
3985 + au_set_h_dptr(dentry, bdst, NULL);
3986 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
3987 + if (unlikely(err)) {
3988 + au_set_h_dptr(dentry, bdst, h_dentry);
3992 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
3993 + au_set_h_dptr(dentry, bdst, h_dentry);
3994 + h_parent = h_dentry->d_parent; /* dir inode is locked */
3995 + h_dir = h_parent->d_inode;
3997 + AuDbg("%.*s %.*s\n", AuDLNPair(h_dentry), AuDLNPair(h_path->dentry));
3998 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path);
3999 + dput(h_path->dentry);
4006 + * copyup the @dentry from @bsrc to @bdst.
4007 + * the caller must set the both of lower dentries.
4008 + * @len is for truncating when it is -1 copyup the entire file.
4009 + * in link/rename cases, @dst_parent may be different from the real one.
4010 + * basic->bsrc can be larger than basic->bdst.
4012 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
4015 + aufs_bindex_t old_ibstart;
4016 + unsigned char isdir, plink;
4017 + struct dentry *h_src, *h_dst, *h_parent;
4018 + struct inode *dst_inode, *h_dir, *inode;
4019 + struct super_block *sb;
4020 + struct au_branch *br;
4021 + /* to reuduce stack size */
4023 + struct au_dtime dt;
4024 + struct path h_path;
4025 + struct au_cpup_reg_attr h_src_attr;
4029 + a = kmalloc(sizeof(*a), GFP_NOFS);
4032 + a->h_src_attr.valid = 0;
4034 + sb = cpg->dentry->d_sb;
4035 + br = au_sbr(sb, cpg->bdst);
4036 + a->h_path.mnt = au_br_mnt(br);
4037 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
4038 + h_parent = h_dst->d_parent; /* dir inode is locked */
4039 + h_dir = h_parent->d_inode;
4042 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
4043 + inode = cpg->dentry->d_inode;
4046 + dst_parent = dget_parent(cpg->dentry);
4050 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
4051 + dst_inode = au_h_iptr(inode, cpg->bdst);
4053 + if (unlikely(!plink)) {
4055 + AuIOErr("hi%lu(i%lu) exists on b%d "
4056 + "but plink is disabled\n",
4057 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
4061 + if (dst_inode->i_nlink) {
4062 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
4064 + h_src = au_plink_lkup(inode, cpg->bdst);
4065 + err = PTR_ERR(h_src);
4066 + if (IS_ERR(h_src))
4068 + if (unlikely(!h_src->d_inode)) {
4070 + AuIOErr("i%lu exists on a upper branch "
4071 + "but not pseudo-linked\n",
4078 + a->h_path.dentry = h_parent;
4079 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
4082 + a->h_path.dentry = h_dst;
4083 + err = vfsub_link(h_src, h_dir, &a->h_path);
4084 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
4085 + err = au_do_ren_after_cpup
4086 + (cpg->dentry, cpg->bdst, &a->h_path);
4088 + au_dtime_revert(&a->dt);
4092 + /* todo: cpup_wh_file? */
4094 + au_update_ibrange(inode, /*do_put_zero*/1);
4097 + isdir = S_ISDIR(inode->i_mode);
4098 + old_ibstart = au_ibstart(inode);
4099 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
4100 + if (unlikely(err))
4102 + dst_inode = h_dst->d_inode;
4103 + mutex_lock_nested(&dst_inode->i_mutex, AuLsc_I_CHILD2);
4104 + /* todo: necessary? */
4105 + /* au_pin_hdir_unlock(cpg->pin); */
4107 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
4108 + if (unlikely(err)) {
4109 + /* todo: necessary? */
4110 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
4111 + mutex_unlock(&dst_inode->i_mutex);
4115 + if (cpg->bdst < old_ibstart) {
4116 + if (S_ISREG(inode->i_mode)) {
4117 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
4118 + if (unlikely(err)) {
4119 + /* ignore an error */
4120 + /* au_pin_hdir_relock(cpg->pin); */
4121 + mutex_unlock(&dst_inode->i_mutex);
4125 + au_set_ibstart(inode, cpg->bdst);
4127 + au_set_ibend(inode, cpg->bdst);
4128 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
4129 + au_hi_flags(inode, isdir));
4131 + /* todo: necessary? */
4132 + /* err = au_pin_hdir_relock(cpg->pin); */
4133 + mutex_unlock(&dst_inode->i_mutex);
4134 + if (unlikely(err))
4138 + && h_src->d_inode->i_nlink > 1
4140 + au_plink_append(inode, cpg->bdst, h_dst);
4142 + if (au_ftest_cpup(cpg->flags, RENAME)) {
4143 + a->h_path.dentry = h_dst;
4144 + err = au_do_ren_after_cpup(cpg->dentry, cpg->bdst, &a->h_path);
4147 + goto out_parent; /* success */
4151 + a->h_path.dentry = h_parent;
4152 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
4153 + a->h_path.dentry = h_dst;
4155 + if (h_dst->d_inode) {
4157 + rerr = vfsub_unlink(h_dir, &a->h_path, /*force*/0);
4159 + rerr = vfsub_rmdir(h_dir, &a->h_path);
4161 + au_dtime_revert(&a->dt);
4163 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
4174 +struct au_cpup_single_args {
4176 + struct au_cp_generic *cpg;
4177 + struct dentry *dst_parent;
4180 +static void au_call_cpup_single(void *args)
4182 + struct au_cpup_single_args *a = args;
4184 + au_pin_hdir_acquire_nest(a->cpg->pin);
4185 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
4186 + au_pin_hdir_release(a->cpg->pin);
4191 + * prevent SIGXFSZ in copy-up.
4192 + * testing CAP_MKNOD is for generic fs,
4193 + * but CAP_FSETID is for xfs only, currently.
4195 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
4198 + struct super_block *sb;
4199 + struct inode *h_dir;
4202 + sb = au_pinned_parent(pin)->d_sb;
4203 + if (!au_wkq_test()
4204 + && (!au_sbi(sb)->si_plink_maint_pid
4205 + || au_plink_maint(sb, AuLock_NOPLM))) {
4206 + switch (mode & S_IFMT) {
4208 + /* no condition about RLIMIT_FSIZE and the file size */
4213 + do_sio = !capable(CAP_MKNOD);
4217 + do_sio = ((mode & (S_ISUID | S_ISGID))
4218 + && !capable(CAP_FSETID));
4219 + /* this workaround may be removed in the future */
4221 + h_dir = au_pinned_h_dir(pin);
4222 + do_sio = h_dir->i_mode & S_ISVTX;
4230 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
4233 + struct dentry *h_dentry;
4235 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
4236 + if (!au_cpup_sio_test(pin, h_dentry->d_inode->i_mode))
4237 + err = au_cpup_single(cpg, dst_parent);
4239 + struct au_cpup_single_args args = {
4242 + .dst_parent = dst_parent
4244 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
4245 + if (unlikely(wkq_err))
4254 + * copyup the @dentry from the first active lower branch to @bdst,
4255 + * using au_cpup_single().
4257 +static int au_cpup_simple(struct au_cp_generic *cpg)
4260 + unsigned int flags_orig;
4261 + struct dentry *dentry;
4263 + AuDebugOn(cpg->bsrc < 0);
4265 + dentry = cpg->dentry;
4266 + DiMustWriteLock(dentry);
4268 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
4270 + flags_orig = cpg->flags;
4271 + au_fset_cpup(cpg->flags, RENAME);
4272 + err = au_cpup_single(cpg, NULL);
4273 + cpg->flags = flags_orig;
4275 + return 0; /* success */
4278 + au_set_h_dptr(dentry, cpg->bdst, NULL);
4279 + au_set_dbstart(dentry, cpg->bsrc);
4285 +struct au_cpup_simple_args {
4287 + struct au_cp_generic *cpg;
4290 +static void au_call_cpup_simple(void *args)
4292 + struct au_cpup_simple_args *a = args;
4294 + au_pin_hdir_acquire_nest(a->cpg->pin);
4295 + *a->errp = au_cpup_simple(a->cpg);
4296 + au_pin_hdir_release(a->cpg->pin);
4299 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
4302 + struct dentry *dentry, *parent;
4303 + struct file *h_file;
4304 + struct inode *h_dir;
4306 + dentry = cpg->dentry;
4308 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
4309 + AuDebugOn(cpg->bsrc < 0);
4310 + h_file = au_h_open_pre(dentry, cpg->bsrc);
4311 + err = PTR_ERR(h_file);
4312 + if (IS_ERR(h_file))
4316 + parent = dget_parent(dentry);
4317 + h_dir = au_h_iptr(parent->d_inode, cpg->bdst);
4318 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
4319 + && !au_cpup_sio_test(cpg->pin, dentry->d_inode->i_mode))
4320 + err = au_cpup_simple(cpg);
4322 + struct au_cpup_simple_args args = {
4326 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
4327 + if (unlikely(wkq_err))
4333 + au_h_open_post(dentry, cpg->bsrc, h_file);
4339 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
4341 + aufs_bindex_t bsrc, bend;
4342 + struct dentry *dentry, *h_dentry;
4344 + if (cpg->bsrc < 0) {
4345 + dentry = cpg->dentry;
4346 + bend = au_dbend(dentry);
4347 + for (bsrc = cpg->bdst + 1; bsrc <= bend; bsrc++) {
4348 + h_dentry = au_h_dptr(dentry, bsrc);
4350 + AuDebugOn(!h_dentry->d_inode);
4354 + AuDebugOn(bsrc > bend);
4357 + AuDebugOn(cpg->bsrc <= cpg->bdst);
4358 + return au_do_sio_cpup_simple(cpg);
4361 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
4363 + AuDebugOn(cpg->bdst <= cpg->bsrc);
4364 + return au_do_sio_cpup_simple(cpg);
4367 +/* ---------------------------------------------------------------------- */
4370 + * copyup the deleted file for writing.
4372 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
4373 + struct file *file)
4376 + unsigned int flags_orig;
4377 + aufs_bindex_t bsrc_orig;
4378 + struct dentry *h_d_dst, *h_d_start;
4379 + struct au_dinfo *dinfo;
4380 + struct au_hdentry *hdp;
4382 + dinfo = au_di(cpg->dentry);
4383 + AuRwMustWriteLock(&dinfo->di_rwsem);
4385 + bsrc_orig = cpg->bsrc;
4386 + cpg->bsrc = dinfo->di_bstart;
4387 + hdp = dinfo->di_hdentry;
4388 + h_d_dst = hdp[0 + cpg->bdst].hd_dentry;
4389 + dinfo->di_bstart = cpg->bdst;
4390 + hdp[0 + cpg->bdst].hd_dentry = wh_dentry;
4393 + h_d_start = hdp[0 + cpg->bsrc].hd_dentry;
4394 + hdp[0 + cpg->bsrc].hd_dentry = au_hf_top(file)->f_dentry;
4396 + flags_orig = cpg->flags;
4397 + cpg->flags = !AuCpup_DTIME;
4398 + err = au_cpup_single(cpg, /*h_parent*/NULL);
4399 + cpg->flags = flags_orig;
4402 + err = au_reopen_nondir(file);
4403 + hdp[0 + cpg->bsrc].hd_dentry = h_d_start;
4405 + hdp[0 + cpg->bdst].hd_dentry = h_d_dst;
4406 + dinfo->di_bstart = cpg->bsrc;
4407 + cpg->bsrc = bsrc_orig;
4412 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
4415 + aufs_bindex_t bdst;
4416 + struct au_dtime dt;
4417 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
4418 + struct au_branch *br;
4419 + struct path h_path;
4421 + dentry = cpg->dentry;
4423 + br = au_sbr(dentry->d_sb, bdst);
4424 + parent = dget_parent(dentry);
4425 + h_parent = au_h_dptr(parent, bdst);
4426 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
4427 + err = PTR_ERR(wh_dentry);
4428 + if (IS_ERR(wh_dentry))
4431 + h_path.dentry = h_parent;
4432 + h_path.mnt = au_br_mnt(br);
4433 + au_dtime_store(&dt, parent, &h_path);
4434 + err = au_do_cpup_wh(cpg, wh_dentry, file);
4435 + if (unlikely(err))
4439 + h_path.dentry = wh_dentry;
4440 + if (!S_ISDIR(wh_dentry->d_inode->i_mode))
4441 + err = vfsub_unlink(h_parent->d_inode, &h_path, /*force*/0);
4443 + err = vfsub_rmdir(h_parent->d_inode, &h_path);
4444 + if (unlikely(err)) {
4445 + AuIOErr("failed remove copied-up tmp file %.*s(%d)\n",
4446 + AuDLNPair(wh_dentry), err);
4449 + au_dtime_revert(&dt);
4450 + au_set_hi_wh(dentry->d_inode, bdst, wh_dentry);
4459 +struct au_cpup_wh_args {
4461 + struct au_cp_generic *cpg;
4462 + struct file *file;
4465 +static void au_call_cpup_wh(void *args)
4467 + struct au_cpup_wh_args *a = args;
4469 + au_pin_hdir_acquire_nest(a->cpg->pin);
4470 + *a->errp = au_cpup_wh(a->cpg, a->file);
4471 + au_pin_hdir_release(a->cpg->pin);
4474 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
4477 + aufs_bindex_t bdst;
4478 + struct dentry *dentry, *parent, *h_orph, *h_parent, *h_dentry;
4479 + struct inode *dir, *h_dir, *h_tmpdir;
4480 + struct au_wbr *wbr;
4481 + struct au_pin wh_pin, *pin_orig;
4483 + dentry = cpg->dentry;
4485 + parent = dget_parent(dentry);
4486 + dir = parent->d_inode;
4489 + h_dir = au_igrab(au_h_iptr(dir, bdst));
4492 + if (!h_dir->i_nlink) {
4493 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
4494 + h_orph = wbr->wbr_orph;
4496 + h_parent = dget(au_h_dptr(parent, bdst));
4497 + au_set_h_dptr(parent, bdst, dget(h_orph));
4498 + h_tmpdir = h_orph->d_inode;
4499 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
4502 + h_dentry = au_hf_top(file)->f_dentry;
4504 + h_dentry = au_h_dptr(dentry, au_dbstart(dentry));
4505 + mutex_lock_nested(&h_tmpdir->i_mutex, AuLsc_I_PARENT3);
4506 + /* todo: au_h_open_pre()? */
4508 + pin_orig = cpg->pin;
4509 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
4510 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
4511 + cpg->pin = &wh_pin;
4514 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
4515 + && !au_cpup_sio_test(cpg->pin, dentry->d_inode->i_mode))
4516 + err = au_cpup_wh(cpg, file);
4518 + struct au_cpup_wh_args args = {
4523 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
4524 + if (unlikely(wkq_err))
4529 + mutex_unlock(&h_tmpdir->i_mutex);
4530 + /* todo: au_h_open_post()? */
4531 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
4532 + au_set_h_dptr(parent, bdst, h_parent);
4533 + AuDebugOn(!pin_orig);
4534 + cpg->pin = pin_orig;
4542 +/* ---------------------------------------------------------------------- */
4545 + * generic routine for both of copy-up and copy-down.
4547 +/* cf. revalidate function in file.c */
4548 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
4549 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
4550 + struct au_pin *pin,
4551 + struct dentry *h_parent, void *arg),
4555 + struct au_pin pin;
4556 + struct dentry *d, *parent, *h_parent, *real_parent;
4559 + parent = dget_parent(dentry);
4560 + if (IS_ROOT(parent))
4563 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
4564 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
4566 + /* do not use au_dpage */
4567 + real_parent = parent;
4570 + parent = dget_parent(dentry);
4571 + h_parent = au_h_dptr(parent, bdst);
4573 + goto out; /* success */
4575 + /* find top dir which is necessary to cpup */
4579 + parent = dget_parent(d);
4580 + di_read_lock_parent3(parent, !AuLock_IR);
4581 + h_parent = au_h_dptr(parent, bdst);
4582 + di_read_unlock(parent, !AuLock_IR);
4583 + } while (!h_parent);
4585 + if (d != real_parent)
4586 + di_write_lock_child3(d);
4588 + /* somebody else might create while we were sleeping */
4589 + if (!au_h_dptr(d, bdst) || !au_h_dptr(d, bdst)->d_inode) {
4590 + if (au_h_dptr(d, bdst))
4591 + au_update_dbstart(d);
4593 + au_pin_set_dentry(&pin, d);
4594 + err = au_do_pin(&pin);
4596 + err = cp(d, bdst, &pin, h_parent, arg);
4601 + if (d != real_parent)
4602 + di_write_unlock(d);
4603 + if (unlikely(err))
4612 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
4613 + struct au_pin *pin,
4614 + struct dentry *h_parent __maybe_unused ,
4615 + void *arg __maybe_unused)
4617 + struct au_cp_generic cpg = {
4623 + .flags = AuCpup_DTIME
4625 + return au_sio_cpup_simple(&cpg);
4628 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
4630 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
4633 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
4636 + struct dentry *parent;
4637 + struct inode *dir;
4639 + parent = dget_parent(dentry);
4640 + dir = parent->d_inode;
4642 + if (au_h_iptr(dir, bdst))
4645 + di_read_unlock(parent, AuLock_IR);
4646 + di_write_lock_parent(parent);
4647 + /* someone else might change our inode while we were sleeping */
4648 + if (!au_h_iptr(dir, bdst))
4649 + err = au_cpup_dirs(dentry, bdst);
4650 + di_downgrade_lock(parent, AuLock_IR);
4656 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
4657 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
4658 +++ linux/fs/aufs/cpup.h 2013-08-23 23:59:39.634916914 +0200
4661 + * Copyright (C) 2005-2013 Junjiro R. Okajima
4663 + * This program, aufs is free software; you can redistribute it and/or modify
4664 + * it under the terms of the GNU General Public License as published by
4665 + * the Free Software Foundation; either version 2 of the License, or
4666 + * (at your option) any later version.
4668 + * This program is distributed in the hope that it will be useful,
4669 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4670 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4671 + * GNU General Public License for more details.
4673 + * You should have received a copy of the GNU General Public License
4674 + * along with this program; if not, write to the Free Software
4675 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
4679 + * copy-up/down functions
4682 +#ifndef __AUFS_CPUP_H__
4683 +#define __AUFS_CPUP_H__
4687 +#include <linux/path.h>
4693 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
4694 +void au_cpup_attr_timesizes(struct inode *inode);
4695 +void au_cpup_attr_nlink(struct inode *inode, int force);
4696 +void au_cpup_attr_changeable(struct inode *inode);
4697 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
4698 +void au_cpup_attr_all(struct inode *inode, int force);
4700 +/* ---------------------------------------------------------------------- */
4702 +struct au_cp_generic {
4703 + struct dentry *dentry;
4704 + aufs_bindex_t bdst, bsrc;
4706 + struct au_pin *pin;
4707 + unsigned int flags;
4711 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
4712 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
4714 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
4715 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in cpup */
4717 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
4718 +#define au_fset_cpup(flags, name) \
4719 + do { (flags) |= AuCpup_##name; } while (0)
4720 +#define au_fclr_cpup(flags, name) \
4721 + do { (flags) &= ~AuCpup_##name; } while (0)
4723 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
4724 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
4725 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
4726 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
4728 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
4729 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
4730 + struct au_pin *pin,
4731 + struct dentry *h_parent, void *arg),
4733 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
4734 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
4736 +/* ---------------------------------------------------------------------- */
4738 +/* keep timestamps when copyup */
4740 + struct dentry *dt_dentry;
4741 + struct path dt_h_path;
4742 + struct timespec dt_atime, dt_mtime;
4744 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4745 + struct path *h_path);
4746 +void au_dtime_revert(struct au_dtime *dt);
4748 +#endif /* __KERNEL__ */
4749 +#endif /* __AUFS_CPUP_H__ */
4750 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
4751 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
4752 +++ linux/fs/aufs/dbgaufs.c 2013-07-06 13:20:47.740198107 +0200
4755 + * Copyright (C) 2005-2013 Junjiro R. Okajima
4757 + * This program, aufs is free software; you can redistribute it and/or modify
4758 + * it under the terms of the GNU General Public License as published by
4759 + * the Free Software Foundation; either version 2 of the License, or
4760 + * (at your option) any later version.
4762 + * This program is distributed in the hope that it will be useful,
4763 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4764 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4765 + * GNU General Public License for more details.
4767 + * You should have received a copy of the GNU General Public License
4768 + * along with this program; if not, write to the Free Software
4769 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
4773 + * debugfs interface
4776 +#include <linux/debugfs.h>
4779 +#ifndef CONFIG_SYSFS
4780 +#error DEBUG_FS depends upon SYSFS
4783 +static struct dentry *dbgaufs;
4784 +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH;
4786 +/* 20 is max digits length of ulong 64 */
4787 +struct dbgaufs_arg {
4793 + * common function for all XINO files
4795 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
4796 + struct file *file)
4798 + kfree(file->private_data);
4802 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt)
4806 + struct dbgaufs_arg *p;
4809 + p = kmalloc(sizeof(*p), GFP_NOFS);
4815 + file->private_data = p;
4819 + err = vfs_getattr(&xf->f_path, &st);
4823 + (p->a, sizeof(p->a), "%ld, %llux%lu %lld\n",
4824 + (long)file_count(xf), st.blocks, st.blksize,
4825 + (long long)st.size);
4827 + p->n = snprintf(p->a, sizeof(p->a), "%llux%lu %lld\n",
4828 + st.blocks, st.blksize,
4829 + (long long)st.size);
4830 + AuDebugOn(p->n >= sizeof(p->a));
4832 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
4841 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
4842 + size_t count, loff_t *ppos)
4844 + struct dbgaufs_arg *p;
4846 + p = file->private_data;
4847 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
4850 +/* ---------------------------------------------------------------------- */
4852 +struct dbgaufs_plink_arg {
4857 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
4858 + struct file *file)
4860 + free_page((unsigned long)file->private_data);
4864 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
4866 + int err, i, limit;
4867 + unsigned long n, sum;
4868 + struct dbgaufs_plink_arg *p;
4869 + struct au_sbinfo *sbinfo;
4870 + struct super_block *sb;
4871 + struct au_sphlhead *sphl;
4874 + p = (void *)get_zeroed_page(GFP_NOFS);
4879 + sbinfo = inode->i_private;
4880 + sb = sbinfo->si_sb;
4881 + si_noflush_read_lock(sb);
4882 + if (au_opt_test(au_mntflags(sb), PLINK)) {
4883 + limit = PAGE_SIZE - sizeof(p->n);
4885 + /* the number of buckets */
4886 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
4891 + for (i = 0, sphl = sbinfo->si_plink;
4892 + i < AuPlink_NHASH;
4894 + n = au_sphl_count(sphl);
4897 + n = snprintf(p->a + p->n, limit, "%lu ", n);
4900 + if (unlikely(limit <= 0))
4903 + p->a[p->n - 1] = '\n';
4905 + /* the sum of plinks */
4906 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
4909 + if (unlikely(limit <= 0))
4912 +#define str "1\n0\n0\n"
4913 + p->n = sizeof(str) - 1;
4914 + strcpy(p->a, str);
4917 + si_read_unlock(sb);
4920 + file->private_data = p;
4921 + goto out; /* success */
4924 + free_page((unsigned long)p);
4929 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
4930 + size_t count, loff_t *ppos)
4932 + struct dbgaufs_plink_arg *p;
4934 + p = file->private_data;
4935 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
4938 +static const struct file_operations dbgaufs_plink_fop = {
4939 + .owner = THIS_MODULE,
4940 + .open = dbgaufs_plink_open,
4941 + .release = dbgaufs_plink_release,
4942 + .read = dbgaufs_plink_read
4945 +/* ---------------------------------------------------------------------- */
4947 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
4950 + struct au_sbinfo *sbinfo;
4951 + struct super_block *sb;
4953 + sbinfo = inode->i_private;
4954 + sb = sbinfo->si_sb;
4955 + si_noflush_read_lock(sb);
4956 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
4957 + si_read_unlock(sb);
4961 +static const struct file_operations dbgaufs_xib_fop = {
4962 + .owner = THIS_MODULE,
4963 + .open = dbgaufs_xib_open,
4964 + .release = dbgaufs_xi_release,
4965 + .read = dbgaufs_xi_read
4968 +/* ---------------------------------------------------------------------- */
4970 +#define DbgaufsXi_PREFIX "xi"
4972 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
4976 + struct au_sbinfo *sbinfo;
4977 + struct super_block *sb;
4979 + struct qstr *name;
4983 + name = &file->f_dentry->d_name;
4984 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
4985 + || memcmp(name->name, DbgaufsXi_PREFIX,
4986 + sizeof(DbgaufsXi_PREFIX) - 1)))
4988 + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
4989 + if (unlikely(err))
4992 + sbinfo = inode->i_private;
4993 + sb = sbinfo->si_sb;
4994 + si_noflush_read_lock(sb);
4995 + if (l <= au_sbend(sb)) {
4996 + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file;
4997 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1);
5000 + si_read_unlock(sb);
5006 +static const struct file_operations dbgaufs_xino_fop = {
5007 + .owner = THIS_MODULE,
5008 + .open = dbgaufs_xino_open,
5009 + .release = dbgaufs_xi_release,
5010 + .read = dbgaufs_xi_read
5013 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
5015 + aufs_bindex_t bend;
5016 + struct au_branch *br;
5017 + struct au_xino_file *xi;
5019 + if (!au_sbi(sb)->si_dbgaufs)
5022 + bend = au_sbend(sb);
5023 + for (; bindex <= bend; bindex++) {
5024 + br = au_sbr(sb, bindex);
5025 + xi = &br->br_xino;
5026 + debugfs_remove(xi->xi_dbgaufs);
5027 + xi->xi_dbgaufs = NULL;
5031 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
5033 + struct au_sbinfo *sbinfo;
5034 + struct dentry *parent;
5035 + struct au_branch *br;
5036 + struct au_xino_file *xi;
5037 + aufs_bindex_t bend;
5038 + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
5040 + sbinfo = au_sbi(sb);
5041 + parent = sbinfo->si_dbgaufs;
5045 + bend = au_sbend(sb);
5046 + for (; bindex <= bend; bindex++) {
5047 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
5048 + br = au_sbr(sb, bindex);
5049 + xi = &br->br_xino;
5050 + AuDebugOn(xi->xi_dbgaufs);
5051 + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
5052 + sbinfo, &dbgaufs_xino_fop);
5053 + /* ignore an error */
5054 + if (unlikely(!xi->xi_dbgaufs))
5055 + AuWarn1("failed %s under debugfs\n", name);
5059 +/* ---------------------------------------------------------------------- */
5061 +#ifdef CONFIG_AUFS_EXPORT
5062 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
5065 + struct au_sbinfo *sbinfo;
5066 + struct super_block *sb;
5068 + sbinfo = inode->i_private;
5069 + sb = sbinfo->si_sb;
5070 + si_noflush_read_lock(sb);
5071 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0);
5072 + si_read_unlock(sb);
5076 +static const struct file_operations dbgaufs_xigen_fop = {
5077 + .owner = THIS_MODULE,
5078 + .open = dbgaufs_xigen_open,
5079 + .release = dbgaufs_xi_release,
5080 + .read = dbgaufs_xi_read
5083 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
5088 + * This function is a dynamic '__init' fucntion actually,
5089 + * so the tiny check for si_rwsem is unnecessary.
5091 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
5094 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
5095 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
5096 + &dbgaufs_xigen_fop);
5097 + if (sbinfo->si_dbgaufs_xigen)
5103 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
5107 +#endif /* CONFIG_AUFS_EXPORT */
5109 +/* ---------------------------------------------------------------------- */
5111 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
5114 + * This function is a dynamic '__init' fucntion actually,
5115 + * so the tiny check for si_rwsem is unnecessary.
5117 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
5119 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
5120 + sbinfo->si_dbgaufs = NULL;
5121 + kobject_put(&sbinfo->si_kobj);
5124 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
5127 + char name[SysaufsSiNameLen];
5130 + * This function is a dynamic '__init' fucntion actually,
5131 + * so the tiny check for si_rwsem is unnecessary.
5133 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
5137 + AuErr1("/debug/aufs is uninitialized\n");
5142 + sysaufs_name(sbinfo, name);
5143 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
5144 + if (unlikely(!sbinfo->si_dbgaufs))
5146 + kobject_get(&sbinfo->si_kobj);
5148 + sbinfo->si_dbgaufs_xib = debugfs_create_file
5149 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
5150 + &dbgaufs_xib_fop);
5151 + if (unlikely(!sbinfo->si_dbgaufs_xib))
5154 + sbinfo->si_dbgaufs_plink = debugfs_create_file
5155 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
5156 + &dbgaufs_plink_fop);
5157 + if (unlikely(!sbinfo->si_dbgaufs_plink))
5160 + err = dbgaufs_xigen_init(sbinfo);
5162 + goto out; /* success */
5165 + dbgaufs_si_fin(sbinfo);
5170 +/* ---------------------------------------------------------------------- */
5172 +void dbgaufs_fin(void)
5174 + debugfs_remove(dbgaufs);
5177 +int __init dbgaufs_init(void)
5182 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
5187 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
5188 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
5189 +++ linux/fs/aufs/dbgaufs.h 2013-07-06 13:20:47.740198107 +0200
5192 + * Copyright (C) 2005-2013 Junjiro R. Okajima
5194 + * This program, aufs is free software; you can redistribute it and/or modify
5195 + * it under the terms of the GNU General Public License as published by
5196 + * the Free Software Foundation; either version 2 of the License, or
5197 + * (at your option) any later version.
5199 + * This program is distributed in the hope that it will be useful,
5200 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5201 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5202 + * GNU General Public License for more details.
5204 + * You should have received a copy of the GNU General Public License
5205 + * along with this program; if not, write to the Free Software
5206 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
5210 + * debugfs interface
5213 +#ifndef __DBGAUFS_H__
5214 +#define __DBGAUFS_H__
5218 +struct super_block;
5221 +#ifdef CONFIG_DEBUG_FS
5223 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
5224 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
5225 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
5226 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
5227 +void dbgaufs_fin(void);
5228 +int __init dbgaufs_init(void);
5230 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
5231 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
5232 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
5233 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
5234 +AuStubVoid(dbgaufs_fin, void)
5235 +AuStubInt0(__init dbgaufs_init, void)
5236 +#endif /* CONFIG_DEBUG_FS */
5238 +#endif /* __KERNEL__ */
5239 +#endif /* __DBGAUFS_H__ */
5240 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
5241 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
5242 +++ linux/fs/aufs/dcsub.c 2013-07-30 22:42:55.839613269 +0200
5245 + * Copyright (C) 2005-2013 Junjiro R. Okajima
5247 + * This program, aufs is free software; you can redistribute it and/or modify
5248 + * it under the terms of the GNU General Public License as published by
5249 + * the Free Software Foundation; either version 2 of the License, or
5250 + * (at your option) any later version.
5252 + * This program is distributed in the hope that it will be useful,
5253 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5254 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5255 + * GNU General Public License for more details.
5257 + * You should have received a copy of the GNU General Public License
5258 + * along with this program; if not, write to the Free Software
5259 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
5263 + * sub-routines for dentry cache
5268 +static void au_dpage_free(struct au_dpage *dpage)
5271 + struct dentry **p;
5273 + p = dpage->dentries;
5274 + for (i = 0; i < dpage->ndentry; i++)
5276 + free_page((unsigned long)dpage->dentries);
5279 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
5285 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
5286 + if (unlikely(!dpages->dpages))
5289 + p = (void *)__get_free_page(gfp);
5293 + dpages->dpages[0].ndentry = 0;
5294 + dpages->dpages[0].dentries = p;
5295 + dpages->ndpage = 1;
5296 + return 0; /* success */
5299 + kfree(dpages->dpages);
5304 +void au_dpages_free(struct au_dcsub_pages *dpages)
5307 + struct au_dpage *p;
5309 + p = dpages->dpages;
5310 + for (i = 0; i < dpages->ndpage; i++)
5311 + au_dpage_free(p++);
5312 + kfree(dpages->dpages);
5315 +static int au_dpages_append(struct au_dcsub_pages *dpages,
5316 + struct dentry *dentry, gfp_t gfp)
5319 + struct au_dpage *dpage;
5322 + dpage = dpages->dpages + dpages->ndpage - 1;
5323 + sz = PAGE_SIZE / sizeof(dentry);
5324 + if (unlikely(dpage->ndentry >= sz)) {
5325 + AuLabel(new dpage);
5327 + sz = dpages->ndpage * sizeof(*dpages->dpages);
5328 + p = au_kzrealloc(dpages->dpages, sz,
5329 + sz + sizeof(*dpages->dpages), gfp);
5333 + dpages->dpages = p;
5334 + dpage = dpages->dpages + dpages->ndpage;
5335 + p = (void *)__get_free_page(gfp);
5339 + dpage->ndentry = 0;
5340 + dpage->dentries = p;
5344 + AuDebugOn(!dentry->d_count);
5345 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
5346 + return 0; /* success */
5352 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
5353 + au_dpages_test test, void *arg)
5356 + struct dentry *this_parent;
5357 + struct list_head *next;
5358 + struct super_block *sb = root->d_sb;
5361 + write_seqlock(&rename_lock);
5362 + this_parent = root;
5363 + spin_lock(&this_parent->d_lock);
5365 + next = this_parent->d_subdirs.next;
5367 + if (this_parent->d_sb == sb
5368 + && !IS_ROOT(this_parent)
5369 + && au_di(this_parent)
5370 + && this_parent->d_count
5371 + && (!test || test(this_parent, arg))) {
5372 + err = au_dpages_append(dpages, this_parent, GFP_ATOMIC);
5373 + if (unlikely(err))
5377 + while (next != &this_parent->d_subdirs) {
5378 + struct list_head *tmp = next;
5379 + struct dentry *dentry = list_entry(tmp, struct dentry,
5383 + spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED);
5384 + if (dentry->d_count) {
5385 + if (!list_empty(&dentry->d_subdirs)) {
5386 + spin_unlock(&this_parent->d_lock);
5387 + spin_release(&dentry->d_lock.dep_map, 1,
5389 + this_parent = dentry;
5390 + spin_acquire(&this_parent->d_lock.dep_map, 0, 1,
5394 + if (dentry->d_sb == sb
5396 + && (!test || test(dentry, arg)))
5397 + err = au_dpages_append(dpages, dentry,
5400 + spin_unlock(&dentry->d_lock);
5401 + if (unlikely(err))
5405 + if (this_parent != root) {
5406 + struct dentry *tmp;
5407 + struct dentry *child;
5409 + tmp = this_parent->d_parent;
5411 + spin_unlock(&this_parent->d_lock);
5412 + child = this_parent;
5413 + this_parent = tmp;
5414 + spin_lock(&this_parent->d_lock);
5415 + rcu_read_unlock();
5416 + next = child->d_child.next;
5421 + spin_unlock(&this_parent->d_lock);
5422 + write_sequnlock(&rename_lock);
5426 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
5427 + int do_include, au_dpages_test test, void *arg)
5432 + write_seqlock(&rename_lock);
5433 + spin_lock(&dentry->d_lock);
5435 + && dentry->d_count
5436 + && (!test || test(dentry, arg)))
5437 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
5438 + spin_unlock(&dentry->d_lock);
5439 + if (unlikely(err))
5443 + * RCU for vfsmount is unnecessary since this is a traverse in a single
5446 + while (!IS_ROOT(dentry)) {
5447 + dentry = dentry->d_parent; /* rename_lock is locked */
5448 + spin_lock(&dentry->d_lock);
5449 + if (dentry->d_count
5450 + && (!test || test(dentry, arg)))
5451 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
5452 + spin_unlock(&dentry->d_lock);
5453 + if (unlikely(err))
5458 + write_sequnlock(&rename_lock);
5462 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
5464 + return au_di(dentry) && dentry->d_sb == arg;
5467 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
5468 + struct dentry *dentry, int do_include)
5470 + return au_dcsub_pages_rev(dpages, dentry, do_include,
5471 + au_dcsub_dpages_aufs, dentry->d_sb);
5474 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
5476 + struct path path[2] = {
5485 + return path_is_under(path + 0, path + 1);
5487 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
5488 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
5489 +++ linux/fs/aufs/dcsub.h 2013-07-06 13:20:47.740198107 +0200
5492 + * Copyright (C) 2005-2013 Junjiro R. Okajima
5494 + * This program, aufs is free software; you can redistribute it and/or modify
5495 + * it under the terms of the GNU General Public License as published by
5496 + * the Free Software Foundation; either version 2 of the License, or
5497 + * (at your option) any later version.
5499 + * This program is distributed in the hope that it will be useful,
5500 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5501 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5502 + * GNU General Public License for more details.
5504 + * You should have received a copy of the GNU General Public License
5505 + * along with this program; if not, write to the Free Software
5506 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
5510 + * sub-routines for dentry cache
5513 +#ifndef __AUFS_DCSUB_H__
5514 +#define __AUFS_DCSUB_H__
5518 +#include <linux/dcache.h>
5519 +#include <linux/fs.h>
5525 + struct dentry **dentries;
5528 +struct au_dcsub_pages {
5530 + struct au_dpage *dpages;
5533 +/* ---------------------------------------------------------------------- */
5536 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
5537 +void au_dpages_free(struct au_dcsub_pages *dpages);
5538 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
5539 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
5540 + au_dpages_test test, void *arg);
5541 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
5542 + int do_include, au_dpages_test test, void *arg);
5543 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
5544 + struct dentry *dentry, int do_include);
5545 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
5547 +/* ---------------------------------------------------------------------- */
5549 +static inline int au_d_hashed_positive(struct dentry *d)
5552 + struct inode *inode = d->d_inode;
5554 + if (unlikely(d_unhashed(d) || !inode || !inode->i_nlink))
5559 +static inline int au_d_alive(struct dentry *d)
5562 + struct inode *inode;
5565 + err = au_d_hashed_positive(d);
5567 + inode = d->d_inode;
5568 + if (unlikely(d_unlinked(d) || !inode || !inode->i_nlink))
5574 +static inline int au_alive_dir(struct dentry *d)
5577 + err = au_d_alive(d);
5578 + if (unlikely(err || IS_DEADDIR(d->d_inode)))
5583 +#endif /* __KERNEL__ */
5584 +#endif /* __AUFS_DCSUB_H__ */
5585 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
5586 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
5587 +++ linux/fs/aufs/debug.c 2013-08-23 23:59:39.634916914 +0200
5590 + * Copyright (C) 2005-2013 Junjiro R. Okajima
5592 + * This program, aufs is free software; you can redistribute it and/or modify
5593 + * it under the terms of the GNU General Public License as published by
5594 + * the Free Software Foundation; either version 2 of the License, or
5595 + * (at your option) any later version.
5597 + * This program is distributed in the hope that it will be useful,
5598 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5599 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5600 + * GNU General Public License for more details.
5602 + * You should have received a copy of the GNU General Public License
5603 + * along with this program; if not, write to the Free Software
5604 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
5608 + * debug print functions
5611 +#include <linux/vt_kern.h>
5615 +MODULE_PARM_DESC(debug, "debug print");
5616 +module_param_named(debug, aufs_debug, int, S_IRUGO | S_IWUSR | S_IWGRP);
5618 +char *au_plevel = KERN_DEBUG;
5619 +#define dpri(fmt, ...) do { \
5621 + && strcmp(au_plevel, KERN_DEBUG)) \
5622 + || au_debug_test()) \
5623 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
5626 +/* ---------------------------------------------------------------------- */
5628 +void au_dpri_whlist(struct au_nhash *whlist)
5630 + unsigned long ul, n;
5631 + struct hlist_head *head;
5632 + struct au_vdir_wh *pos;
5634 + n = whlist->nh_num;
5635 + head = whlist->nh_head;
5636 + for (ul = 0; ul < n; ul++) {
5637 + hlist_for_each_entry(pos, head, wh_hash)
5638 + dpri("b%d, %.*s, %d\n",
5640 + pos->wh_str.len, pos->wh_str.name,
5646 +void au_dpri_vdir(struct au_vdir *vdir)
5649 + union au_vdir_deblk_p p;
5652 + if (!vdir || IS_ERR(vdir)) {
5653 + dpri("err %ld\n", PTR_ERR(vdir));
5657 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n",
5658 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
5659 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
5660 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
5661 + p.deblk = vdir->vd_deblk[ul];
5663 + dpri("[%lu]: %p\n", ul, o);
5667 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
5668 + struct dentry *wh)
5673 + if (!inode || IS_ERR(inode)) {
5674 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
5678 + /* the type of i_blocks depends upon CONFIG_LBDAF */
5679 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
5680 + && sizeof(inode->i_blocks) != sizeof(u64));
5682 + n = (void *)wh->d_name.name;
5683 + l = wh->d_name.len;
5686 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
5687 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
5689 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
5690 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
5691 + i_size_read(inode), (unsigned long long)inode->i_blocks,
5692 + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
5693 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
5694 + inode->i_state, inode->i_flags, inode->i_version,
5695 + inode->i_generation,
5696 + l ? ", wh " : "", l, n);
5700 +void au_dpri_inode(struct inode *inode)
5702 + struct au_iinfo *iinfo;
5703 + aufs_bindex_t bindex;
5706 + err = do_pri_inode(-1, inode, -1, NULL);
5707 + if (err || !au_test_aufs(inode->i_sb))
5710 + iinfo = au_ii(inode);
5713 + dpri("i-1: bstart %d, bend %d, gen %d\n",
5714 + iinfo->ii_bstart, iinfo->ii_bend, au_iigen(inode, NULL));
5715 + if (iinfo->ii_bstart < 0)
5718 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend; bindex++) {
5719 + hn = !!au_hn(iinfo->ii_hinode + bindex);
5720 + do_pri_inode(bindex, iinfo->ii_hinode[0 + bindex].hi_inode, hn,
5721 + iinfo->ii_hinode[0 + bindex].hi_whdentry);
5725 +void au_dpri_dalias(struct inode *inode)
5729 + spin_lock(&inode->i_lock);
5730 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
5731 + au_dpri_dentry(d);
5732 + spin_unlock(&inode->i_lock);
5735 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
5737 + struct dentry *wh = NULL;
5740 + if (!dentry || IS_ERR(dentry)) {
5741 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
5744 + /* do not call dget_parent() here */
5745 + /* note: access d_xxx without d_lock */
5746 + dpri("d%d: %.*s?/%.*s, %s, cnt %d, flags 0x%x\n",
5748 + AuDLNPair(dentry->d_parent), AuDLNPair(dentry),
5749 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
5750 + dentry->d_count, dentry->d_flags);
5752 + if (bindex >= 0 && dentry->d_inode && au_test_aufs(dentry->d_sb)) {
5753 + struct au_iinfo *iinfo = au_ii(dentry->d_inode);
5755 + hn = !!au_hn(iinfo->ii_hinode + bindex);
5756 + wh = iinfo->ii_hinode[0 + bindex].hi_whdentry;
5759 + do_pri_inode(bindex, dentry->d_inode, hn, wh);
5763 +void au_dpri_dentry(struct dentry *dentry)
5765 + struct au_dinfo *dinfo;
5766 + aufs_bindex_t bindex;
5768 + struct au_hdentry *hdp;
5770 + err = do_pri_dentry(-1, dentry);
5771 + if (err || !au_test_aufs(dentry->d_sb))
5774 + dinfo = au_di(dentry);
5777 + dpri("d-1: bstart %d, bend %d, bwh %d, bdiropq %d, gen %d\n",
5778 + dinfo->di_bstart, dinfo->di_bend,
5779 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry));
5780 + if (dinfo->di_bstart < 0)
5782 + hdp = dinfo->di_hdentry;
5783 + for (bindex = dinfo->di_bstart; bindex <= dinfo->di_bend; bindex++)
5784 + do_pri_dentry(bindex, hdp[0 + bindex].hd_dentry);
5787 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
5791 + if (!file || IS_ERR(file)) {
5792 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
5798 + && au_test_aufs(file->f_dentry->d_sb)
5800 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
5801 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
5802 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
5803 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
5804 + file->f_version, file->f_pos, a);
5805 + if (file->f_dentry)
5806 + do_pri_dentry(bindex, file->f_dentry);
5810 +void au_dpri_file(struct file *file)
5812 + struct au_finfo *finfo;
5813 + struct au_fidir *fidir;
5814 + struct au_hfile *hfile;
5815 + aufs_bindex_t bindex;
5818 + err = do_pri_file(-1, file);
5819 + if (err || !file->f_dentry || !au_test_aufs(file->f_dentry->d_sb))
5822 + finfo = au_fi(file);
5825 + if (finfo->fi_btop < 0)
5827 + fidir = finfo->fi_hdir;
5829 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
5831 + for (bindex = finfo->fi_btop;
5832 + bindex >= 0 && bindex <= fidir->fd_bbot;
5834 + hfile = fidir->fd_hfile + bindex;
5835 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
5839 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
5841 + struct vfsmount *mnt;
5842 + struct super_block *sb;
5844 + if (!br || IS_ERR(br))
5846 + mnt = au_br_mnt(br);
5847 + if (!mnt || IS_ERR(mnt))
5850 + if (!sb || IS_ERR(sb))
5853 + dpri("s%d: {perm 0x%x, id %d, cnt %d, wbr %p}, "
5854 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
5856 + bindex, br->br_perm, br->br_id, atomic_read(&br->br_count),
5857 + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
5858 + sb->s_flags, sb->s_count,
5859 + atomic_read(&sb->s_active), !!br->br_xino.xi_file);
5863 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
5867 +void au_dpri_sb(struct super_block *sb)
5869 + struct au_sbinfo *sbinfo;
5870 + aufs_bindex_t bindex;
5872 + /* to reuduce stack size */
5874 + struct vfsmount mnt;
5875 + struct au_branch fake;
5878 + /* this function can be called from magic sysrq */
5879 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
5880 + if (unlikely(!a)) {
5881 + dpri("no memory\n");
5885 + a->mnt.mnt_sb = sb;
5886 + a->fake.br_perm = 0;
5887 + a->fake.br_path.mnt = &a->mnt;
5888 + a->fake.br_xino.xi_file = NULL;
5889 + atomic_set(&a->fake.br_count, 0);
5890 + smp_mb(); /* atomic_set */
5891 + err = do_pri_br(-1, &a->fake);
5893 + dpri("dev 0x%x\n", sb->s_dev);
5894 + if (err || !au_test_aufs(sb))
5897 + sbinfo = au_sbi(sb);
5900 + dpri("nw %d, gen %u, kobj %d\n",
5901 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
5902 + atomic_read(&sbinfo->si_kobj.kref.refcount));
5903 + for (bindex = 0; bindex <= sbinfo->si_bend; bindex++)
5904 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
5907 +/* ---------------------------------------------------------------------- */
5909 +void au_dbg_sleep_jiffy(int jiffy)
5912 + jiffy = schedule_timeout_uninterruptible(jiffy);
5915 +void au_dbg_iattr(struct iattr *ia)
5917 +#define AuBit(name) \
5919 + if (ia->ia_valid & ATTR_ ## name) \
5920 + dpri(#name "\n"); \
5940 + dpri("ia_file %p\n", ia->ia_file);
5943 +/* ---------------------------------------------------------------------- */
5945 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
5947 + struct inode *h_inode, *inode = dentry->d_inode;
5948 + struct dentry *h_dentry;
5949 + aufs_bindex_t bindex, bend, bi;
5951 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
5954 + bend = au_dbend(dentry);
5955 + bi = au_ibend(inode);
5958 + bindex = au_dbstart(dentry);
5959 + bi = au_ibstart(inode);
5963 + for (; bindex <= bend; bindex++) {
5964 + h_dentry = au_h_dptr(dentry, bindex);
5967 + h_inode = au_h_iptr(inode, bindex);
5968 + if (unlikely(h_inode != h_dentry->d_inode)) {
5969 + int old = au_debug_test();
5972 + AuDbg("b%d, %s:%d\n", bindex, func, line);
5973 + AuDbgDentry(dentry);
5974 + AuDbgInode(inode);
5982 +void au_dbg_verify_dir_parent(struct dentry *dentry, unsigned int sigen)
5984 + struct dentry *parent;
5986 + parent = dget_parent(dentry);
5987 + AuDebugOn(!S_ISDIR(dentry->d_inode->i_mode));
5988 + AuDebugOn(IS_ROOT(dentry));
5989 + AuDebugOn(au_digen_test(parent, sigen));
5993 +void au_dbg_verify_nondir_parent(struct dentry *dentry, unsigned int sigen)
5995 + struct dentry *parent;
5996 + struct inode *inode;
5998 + parent = dget_parent(dentry);
5999 + inode = dentry->d_inode;
6000 + AuDebugOn(inode && S_ISDIR(dentry->d_inode->i_mode));
6001 + AuDebugOn(au_digen_test(parent, sigen));
6005 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
6008 + struct au_dcsub_pages dpages;
6009 + struct au_dpage *dpage;
6010 + struct dentry **dentries;
6012 + err = au_dpages_init(&dpages, GFP_NOFS);
6014 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
6016 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
6017 + dpage = dpages.dpages + i;
6018 + dentries = dpage->dentries;
6019 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
6020 + AuDebugOn(au_digen_test(dentries[j], sigen));
6022 + au_dpages_free(&dpages);
6025 +void au_dbg_verify_kthread(void)
6027 + if (au_wkq_test()) {
6030 + * It may be recursive, but udba=notify between two aufs mounts,
6031 + * where a single ro branch is shared, is not a problem.
6037 +/* ---------------------------------------------------------------------- */
6039 +void au_debug_sbinfo_init(struct au_sbinfo *sbinfo __maybe_unused)
6041 +#ifdef AuForceNoPlink
6042 + au_opt_clr(sbinfo->si_mntflags, PLINK);
6044 +#ifdef AuForceNoXino
6045 + au_opt_clr(sbinfo->si_mntflags, XINO);
6047 +#ifdef AuForceNoRefrof
6048 + au_opt_clr(sbinfo->si_mntflags, REFROF);
6050 +#ifdef AuForceHnotify
6051 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_HNOTIFY);
6054 + sbinfo->si_rdblk = 0;
6055 + sbinfo->si_rdhash = 0;
6059 +int __init au_debug_init(void)
6061 + aufs_bindex_t bindex;
6062 + struct au_vdir_destr destr;
6065 + AuDebugOn(bindex >= 0);
6068 + AuDebugOn(destr.len < NAME_MAX);
6070 +#ifdef CONFIG_4KSTACKS
6071 + pr_warn("CONFIG_4KSTACKS is defined.\n");
6074 +#ifdef AuForceNoBrs
6080 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
6081 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
6082 +++ linux/fs/aufs/debug.h 2013-07-06 13:20:47.740198107 +0200
6085 + * Copyright (C) 2005-2013 Junjiro R. Okajima
6087 + * This program, aufs is free software; you can redistribute it and/or modify
6088 + * it under the terms of the GNU General Public License as published by
6089 + * the Free Software Foundation; either version 2 of the License, or
6090 + * (at your option) any later version.
6092 + * This program is distributed in the hope that it will be useful,
6093 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6094 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6095 + * GNU General Public License for more details.
6097 + * You should have received a copy of the GNU General Public License
6098 + * along with this program; if not, write to the Free Software
6099 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
6103 + * debug print functions
6106 +#ifndef __AUFS_DEBUG_H__
6107 +#define __AUFS_DEBUG_H__
6111 +#include <linux/module.h>
6112 +#include <linux/kallsyms.h>
6113 +#include <linux/sysrq.h>
6115 +#ifdef CONFIG_AUFS_DEBUG
6116 +#define AuDebugOn(a) BUG_ON(a)
6118 +/* module parameter */
6119 +extern int aufs_debug;
6120 +static inline void au_debug(int n)
6126 +static inline int au_debug_test(void)
6128 + return aufs_debug;
6131 +#define AuDebugOn(a) do {} while (0)
6132 +AuStubVoid(au_debug, int n)
6133 +AuStubInt0(au_debug_test, void)
6134 +#endif /* CONFIG_AUFS_DEBUG */
6136 +/* ---------------------------------------------------------------------- */
6140 +#define AuDbg(fmt, ...) do { \
6141 + if (au_debug_test()) \
6142 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
6144 +#define AuLabel(l) AuDbg(#l "\n")
6145 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
6146 +#define AuWarn1(fmt, ...) do { \
6147 + static unsigned char _c; \
6149 + pr_warn(fmt, ##__VA_ARGS__); \
6152 +#define AuErr1(fmt, ...) do { \
6153 + static unsigned char _c; \
6155 + pr_err(fmt, ##__VA_ARGS__); \
6158 +#define AuIOErr1(fmt, ...) do { \
6159 + static unsigned char _c; \
6161 + AuIOErr(fmt, ##__VA_ARGS__); \
6164 +#define AuUnsupportMsg "This operation is not supported." \
6165 + " Please report this application to aufs-users ML."
6166 +#define AuUnsupport(fmt, ...) do { \
6167 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
6171 +#define AuTraceErr(e) do { \
6172 + if (unlikely((e) < 0)) \
6173 + AuDbg("err %d\n", (int)(e)); \
6176 +#define AuTraceErrPtr(p) do { \
6178 + AuDbg("err %ld\n", PTR_ERR(p)); \
6181 +/* dirty macros for debug print, use with "%.*s" and caution */
6182 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
6183 +#define AuDLNPair(d) AuLNPair(&(d)->d_name)
6185 +/* ---------------------------------------------------------------------- */
6190 +#ifdef CONFIG_AUFS_DEBUG
6191 +extern char *au_plevel;
6193 +void au_dpri_whlist(struct au_nhash *whlist);
6195 +void au_dpri_vdir(struct au_vdir *vdir);
6197 +void au_dpri_inode(struct inode *inode);
6198 +void au_dpri_dalias(struct inode *inode);
6199 +void au_dpri_dentry(struct dentry *dentry);
6201 +void au_dpri_file(struct file *filp);
6202 +struct super_block;
6203 +void au_dpri_sb(struct super_block *sb);
6205 +void au_dbg_sleep_jiffy(int jiffy);
6207 +void au_dbg_iattr(struct iattr *ia);
6209 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
6210 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
6211 +void au_dbg_verify_dir_parent(struct dentry *dentry, unsigned int sigen);
6212 +void au_dbg_verify_nondir_parent(struct dentry *dentry, unsigned int sigen);
6213 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
6214 +void au_dbg_verify_kthread(void);
6216 +int __init au_debug_init(void);
6217 +void au_debug_sbinfo_init(struct au_sbinfo *sbinfo);
6218 +#define AuDbgWhlist(w) do { \
6220 + au_dpri_whlist(w); \
6223 +#define AuDbgVdir(v) do { \
6225 + au_dpri_vdir(v); \
6228 +#define AuDbgInode(i) do { \
6230 + au_dpri_inode(i); \
6233 +#define AuDbgDAlias(i) do { \
6235 + au_dpri_dalias(i); \
6238 +#define AuDbgDentry(d) do { \
6240 + au_dpri_dentry(d); \
6243 +#define AuDbgFile(f) do { \
6245 + au_dpri_file(f); \
6248 +#define AuDbgSb(sb) do { \
6249 + AuDbg(#sb "\n"); \
6253 +#define AuDbgSleep(sec) do { \
6254 + AuDbg("sleep %d sec\n", sec); \
6258 +#define AuDbgSleepJiffy(jiffy) do { \
6259 + AuDbg("sleep %d jiffies\n", jiffy); \
6260 + au_dbg_sleep_jiffy(jiffy); \
6263 +#define AuDbgIAttr(ia) do { \
6264 + AuDbg("ia_valid 0x%x\n", (ia)->ia_valid); \
6265 + au_dbg_iattr(ia); \
6268 +#define AuDbgSym(addr) do { \
6269 + char sym[KSYM_SYMBOL_LEN]; \
6270 + sprint_symbol(sym, (unsigned long)addr); \
6271 + AuDbg("%s\n", sym); \
6274 +#define AuInfoSym(addr) do { \
6275 + char sym[KSYM_SYMBOL_LEN]; \
6276 + sprint_symbol(sym, (unsigned long)addr); \
6277 + AuInfo("%s\n", sym); \
6280 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
6281 +AuStubVoid(au_dbg_verify_dir_parent, struct dentry *dentry, unsigned int sigen)
6282 +AuStubVoid(au_dbg_verify_nondir_parent, struct dentry *dentry,
6283 + unsigned int sigen)
6284 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
6285 +AuStubVoid(au_dbg_verify_kthread, void)
6286 +AuStubInt0(__init au_debug_init, void)
6287 +AuStubVoid(au_debug_sbinfo_init, struct au_sbinfo *sbinfo)
6289 +#define AuDbgWhlist(w) do {} while (0)
6290 +#define AuDbgVdir(v) do {} while (0)
6291 +#define AuDbgInode(i) do {} while (0)
6292 +#define AuDbgDAlias(i) do {} while (0)
6293 +#define AuDbgDentry(d) do {} while (0)
6294 +#define AuDbgFile(f) do {} while (0)
6295 +#define AuDbgSb(sb) do {} while (0)
6296 +#define AuDbgSleep(sec) do {} while (0)
6297 +#define AuDbgSleepJiffy(jiffy) do {} while (0)
6298 +#define AuDbgIAttr(ia) do {} while (0)
6299 +#define AuDbgSym(addr) do {} while (0)
6300 +#define AuInfoSym(addr) do {} while (0)
6301 +#endif /* CONFIG_AUFS_DEBUG */
6303 +/* ---------------------------------------------------------------------- */
6305 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
6306 +int __init au_sysrq_init(void);
6307 +void au_sysrq_fin(void);
6309 +#ifdef CONFIG_HW_CONSOLE
6310 +#define au_dbg_blocked() do { \
6312 + handle_sysrq('w'); \
6315 +AuStubVoid(au_dbg_blocked, void)
6319 +AuStubInt0(__init au_sysrq_init, void)
6320 +AuStubVoid(au_sysrq_fin, void)
6321 +AuStubVoid(au_dbg_blocked, void)
6322 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
6324 +#endif /* __KERNEL__ */
6325 +#endif /* __AUFS_DEBUG_H__ */
6326 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
6327 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
6328 +++ linux/fs/aufs/dentry.c 2013-07-06 13:20:47.740198107 +0200
6331 + * Copyright (C) 2005-2013 Junjiro R. Okajima
6333 + * This program, aufs is free software; you can redistribute it and/or modify
6334 + * it under the terms of the GNU General Public License as published by
6335 + * the Free Software Foundation; either version 2 of the License, or
6336 + * (at your option) any later version.
6338 + * This program is distributed in the hope that it will be useful,
6339 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6340 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6341 + * GNU General Public License for more details.
6343 + * You should have received a copy of the GNU General Public License
6344 + * along with this program; if not, write to the Free Software
6345 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
6349 + * lookup and dentry operations
6352 +#include <linux/namei.h>
6355 +#define AuLkup_ALLOW_NEG 1
6356 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
6357 +#define au_fset_lkup(flags, name) \
6358 + do { (flags) |= AuLkup_##name; } while (0)
6359 +#define au_fclr_lkup(flags, name) \
6360 + do { (flags) &= ~AuLkup_##name; } while (0)
6362 +struct au_do_lookup_args {
6363 + unsigned int flags;
6368 + * returns positive/negative dentry, NULL or an error.
6369 + * NULL means whiteout-ed or not-found.
6371 +static struct dentry*
6372 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
6373 + aufs_bindex_t bindex, struct qstr *wh_name,
6374 + struct au_do_lookup_args *args)
6376 + struct dentry *h_dentry;
6377 + struct inode *h_inode, *inode;
6378 + struct au_branch *br;
6379 + int wh_found, opq;
6380 + unsigned char wh_able;
6381 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
6384 + br = au_sbr(dentry->d_sb, bindex);
6385 + wh_able = !!au_br_whable(br->br_perm);
6387 + wh_found = au_wh_test(h_parent, wh_name, br, /*try_sio*/0);
6388 + h_dentry = ERR_PTR(wh_found);
6391 + if (unlikely(wh_found < 0))
6394 + /* We found a whiteout */
6395 + /* au_set_dbend(dentry, bindex); */
6396 + au_set_dbwh(dentry, bindex);
6398 + return NULL; /* success */
6401 + h_dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
6402 + if (IS_ERR(h_dentry))
6405 + h_inode = h_dentry->d_inode;
6409 + } else if (wh_found
6410 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
6413 + if (au_dbend(dentry) <= bindex)
6414 + au_set_dbend(dentry, bindex);
6415 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
6416 + au_set_dbstart(dentry, bindex);
6417 + au_set_h_dptr(dentry, bindex, h_dentry);
6419 + inode = dentry->d_inode;
6420 + if (!h_inode || !S_ISDIR(h_inode->i_mode) || !wh_able
6421 + || (inode && !S_ISDIR(inode->i_mode)))
6422 + goto out; /* success */
6424 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
6425 + opq = au_diropq_test(h_dentry, br);
6426 + mutex_unlock(&h_inode->i_mutex);
6428 + au_set_dbdiropq(dentry, bindex);
6429 + else if (unlikely(opq < 0)) {
6430 + au_set_h_dptr(dentry, bindex, NULL);
6431 + h_dentry = ERR_PTR(opq);
6442 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
6444 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
6445 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
6451 + * returns the number of lower positive dentries,
6452 + * otherwise an error.
6453 + * can be called at unlinking with @type is zero.
6455 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type)
6457 + int npositive, err;
6458 + aufs_bindex_t bindex, btail, bdiropq;
6459 + unsigned char isdir;
6460 + struct qstr whname;
6461 + struct au_do_lookup_args args = {
6465 + const struct qstr *name = &dentry->d_name;
6466 + struct dentry *parent;
6467 + struct inode *inode;
6469 + err = au_test_shwh(dentry->d_sb, name);
6470 + if (unlikely(err))
6473 + err = au_wh_name_alloc(&whname, name);
6474 + if (unlikely(err))
6477 + inode = dentry->d_inode;
6478 + isdir = !!(inode && S_ISDIR(inode->i_mode));
6480 + au_fset_lkup(args.flags, ALLOW_NEG);
6483 + parent = dget_parent(dentry);
6484 + btail = au_dbtaildir(parent);
6485 + for (bindex = bstart; bindex <= btail; bindex++) {
6486 + struct dentry *h_parent, *h_dentry;
6487 + struct inode *h_inode, *h_dir;
6489 + h_dentry = au_h_dptr(dentry, bindex);
6491 + if (h_dentry->d_inode)
6493 + if (type != S_IFDIR)
6497 + h_parent = au_h_dptr(parent, bindex);
6500 + h_dir = h_parent->d_inode;
6501 + if (!h_dir || !S_ISDIR(h_dir->i_mode))
6504 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
6505 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname,
6507 + mutex_unlock(&h_dir->i_mutex);
6508 + err = PTR_ERR(h_dentry);
6509 + if (IS_ERR(h_dentry))
6511 + au_fclr_lkup(args.flags, ALLOW_NEG);
6513 + if (au_dbwh(dentry) >= 0)
6517 + h_inode = h_dentry->d_inode;
6522 + args.type = h_inode->i_mode & S_IFMT;
6523 + if (args.type != S_IFDIR)
6526 + /* the type of lower may be different */
6527 + bdiropq = au_dbdiropq(dentry);
6528 + if (bdiropq >= 0 && bdiropq <= bindex)
6534 + AuLabel(positive);
6535 + au_update_dbstart(dentry);
6538 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
6539 + && au_dbstart(dentry) < 0)) {
6541 + AuIOErr("both of real entry and whiteout found, %.*s, err %d\n",
6542 + AuDLNPair(dentry), err);
6547 + kfree(whname.name);
6552 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent,
6553 + struct au_branch *br)
6555 + struct dentry *dentry;
6558 + if (!au_test_h_perm_sio(parent->d_inode, MAY_EXEC))
6559 + dentry = vfsub_lkup_one(name, parent);
6561 + struct vfsub_lkup_one_args args = {
6567 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
6568 + if (unlikely(wkq_err))
6569 + dentry = ERR_PTR(wkq_err);
6576 + * lookup @dentry on @bindex which should be negative.
6578 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
6581 + struct dentry *parent, *h_parent, *h_dentry;
6582 + struct au_branch *br;
6584 + parent = dget_parent(dentry);
6585 + h_parent = au_h_dptr(parent, bindex);
6586 + br = au_sbr(dentry->d_sb, bindex);
6588 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
6590 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent, br);
6591 + err = PTR_ERR(h_dentry);
6592 + if (IS_ERR(h_dentry))
6594 + if (unlikely(h_dentry->d_inode)) {
6596 + AuIOErr("%.*s should be negative on b%d.\n",
6597 + AuDLNPair(h_dentry), bindex);
6603 + if (bindex < au_dbstart(dentry))
6604 + au_set_dbstart(dentry, bindex);
6605 + if (au_dbend(dentry) < bindex)
6606 + au_set_dbend(dentry, bindex);
6607 + au_set_h_dptr(dentry, bindex, h_dentry);
6614 +/* ---------------------------------------------------------------------- */
6616 +/* subset of struct inode */
6618 + unsigned long i_ino;
6619 + /* unsigned int i_nlink; */
6625 + blkcnt_t i_blocks;
6630 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
6632 + ia->i_ino = h_inode->i_ino;
6633 + /* ia->i_nlink = h_inode->i_nlink; */
6634 + ia->i_uid = h_inode->i_uid;
6635 + ia->i_gid = h_inode->i_gid;
6636 + ia->i_version = h_inode->i_version;
6638 + ia->i_size = h_inode->i_size;
6639 + ia->i_blocks = h_inode->i_blocks;
6641 + ia->i_mode = (h_inode->i_mode & S_IFMT);
6644 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
6646 + return ia->i_ino != h_inode->i_ino
6647 + /* || ia->i_nlink != h_inode->i_nlink */
6648 + || !uid_eq(ia->i_uid, h_inode->i_uid)
6649 + || !gid_eq(ia->i_gid, h_inode->i_gid)
6650 + || ia->i_version != h_inode->i_version
6652 + || ia->i_size != h_inode->i_size
6653 + || ia->i_blocks != h_inode->i_blocks
6655 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
6658 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
6659 + struct au_branch *br)
6662 + struct au_iattr ia;
6663 + struct inode *h_inode;
6664 + struct dentry *h_d;
6665 + struct super_block *h_sb;
6668 + memset(&ia, -1, sizeof(ia));
6669 + h_sb = h_dentry->d_sb;
6670 + h_inode = h_dentry->d_inode;
6672 + au_iattr_save(&ia, h_inode);
6673 + else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
6674 + /* nfs d_revalidate may return 0 for negative dentry */
6675 + /* fuse d_revalidate always return 0 for negative dentry */
6678 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
6679 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
6680 + err = PTR_ERR(h_d);
6685 + if (unlikely(h_d != h_dentry
6686 + || h_d->d_inode != h_inode
6687 + || (h_inode && au_iattr_test(&ia, h_inode))))
6688 + err = au_busy_or_stale();
6696 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
6697 + struct dentry *h_parent, struct au_branch *br)
6702 + if (udba == AuOpt_UDBA_REVAL
6703 + && !au_test_fs_remote(h_dentry->d_sb)) {
6705 + err = (h_dentry->d_parent->d_inode != h_dir);
6706 + } else if (udba != AuOpt_UDBA_NONE)
6707 + err = au_h_verify_dentry(h_dentry, h_parent, br);
6712 +/* ---------------------------------------------------------------------- */
6714 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
6717 + aufs_bindex_t new_bindex, bindex, bend, bwh, bdiropq;
6718 + struct au_hdentry tmp, *p, *q;
6719 + struct au_dinfo *dinfo;
6720 + struct super_block *sb;
6722 + DiMustWriteLock(dentry);
6724 + sb = dentry->d_sb;
6725 + dinfo = au_di(dentry);
6726 + bend = dinfo->di_bend;
6727 + bwh = dinfo->di_bwh;
6728 + bdiropq = dinfo->di_bdiropq;
6729 + p = dinfo->di_hdentry + dinfo->di_bstart;
6730 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++, p++) {
6731 + if (!p->hd_dentry)
6734 + new_bindex = au_br_index(sb, p->hd_id);
6735 + if (new_bindex == bindex)
6738 + if (dinfo->di_bwh == bindex)
6740 + if (dinfo->di_bdiropq == bindex)
6741 + bdiropq = new_bindex;
6742 + if (new_bindex < 0) {
6744 + p->hd_dentry = NULL;
6748 + /* swap two lower dentries, and loop again */
6749 + q = dinfo->di_hdentry + new_bindex;
6753 + if (tmp.hd_dentry) {
6759 + dinfo->di_bwh = -1;
6760 + if (bwh >= 0 && bwh <= au_sbend(sb) && au_sbr_whable(sb, bwh))
6761 + dinfo->di_bwh = bwh;
6763 + dinfo->di_bdiropq = -1;
6765 + && bdiropq <= au_sbend(sb)
6766 + && au_sbr_whable(sb, bdiropq))
6767 + dinfo->di_bdiropq = bdiropq;
6770 + dinfo->di_bstart = -1;
6771 + dinfo->di_bend = -1;
6772 + bend = au_dbend(parent);
6773 + p = dinfo->di_hdentry;
6774 + for (bindex = 0; bindex <= bend; bindex++, p++)
6775 + if (p->hd_dentry) {
6776 + dinfo->di_bstart = bindex;
6780 + if (dinfo->di_bstart >= 0) {
6781 + p = dinfo->di_hdentry + bend;
6782 + for (bindex = bend; bindex >= 0; bindex--, p--)
6783 + if (p->hd_dentry) {
6784 + dinfo->di_bend = bindex;
6793 +static void au_do_hide(struct dentry *dentry)
6795 + struct inode *inode;
6797 + inode = dentry->d_inode;
6799 + if (!S_ISDIR(inode->i_mode)) {
6800 + if (inode->i_nlink && !d_unhashed(dentry))
6801 + drop_nlink(inode);
6803 + clear_nlink(inode);
6804 + /* stop next lookup */
6805 + inode->i_flags |= S_DEAD;
6807 + smp_mb(); /* necessary? */
6812 +static int au_hide_children(struct dentry *parent)
6814 + int err, i, j, ndentry;
6815 + struct au_dcsub_pages dpages;
6816 + struct au_dpage *dpage;
6817 + struct dentry *dentry;
6819 + err = au_dpages_init(&dpages, GFP_NOFS);
6820 + if (unlikely(err))
6822 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
6823 + if (unlikely(err))
6826 + /* in reverse order */
6827 + for (i = dpages.ndpage - 1; i >= 0; i--) {
6828 + dpage = dpages.dpages + i;
6829 + ndentry = dpage->ndentry;
6830 + for (j = ndentry - 1; j >= 0; j--) {
6831 + dentry = dpage->dentries[j];
6832 + if (dentry != parent)
6833 + au_do_hide(dentry);
6838 + au_dpages_free(&dpages);
6843 +static void au_hide(struct dentry *dentry)
6846 + struct inode *inode;
6848 + AuDbgDentry(dentry);
6849 + inode = dentry->d_inode;
6850 + if (inode && S_ISDIR(inode->i_mode)) {
6851 + /* shrink_dcache_parent(dentry); */
6852 + err = au_hide_children(dentry);
6853 + if (unlikely(err))
6854 + AuIOErr("%.*s, failed hiding children, ignored %d\n",
6855 + AuDLNPair(dentry), err);
6857 + au_do_hide(dentry);
6861 + * By adding a dirty branch, a cached dentry may be affected in various ways.
6863 + * a dirty branch is added
6864 + * - on the top of layers
6865 + * - in the middle of layers
6866 + * - to the bottom of layers
6868 + * on the added branch there exists
6871 + * - a same named entry
6873 + * * negative --> positive
6874 + * * positive --> positive
6875 + * - type is unchanged
6876 + * - type is changed
6878 + * * negative --> negative
6879 + * * positive --> negative (rejected by au_br_del() for non-dir case)
6882 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
6883 + struct au_dinfo *tmp)
6886 + aufs_bindex_t bindex, bend;
6888 + struct dentry *dentry;
6889 + struct inode *inode;
6892 + struct au_hdentry *hd;
6893 + struct inode *inode, *h_inode;
6894 + struct dentry *h_dentry;
6897 + AuDebugOn(dinfo->di_bstart < 0);
6898 + orig_h.dentry = dinfo->di_hdentry[dinfo->di_bstart].hd_dentry;
6899 + orig_h.inode = orig_h.dentry->d_inode;
6902 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
6903 + memset(&tmp_h, 0, sizeof(tmp_h));
6904 + if (tmp->di_bstart >= 0) {
6905 + tmp_h.dentry = tmp->di_hdentry[tmp->di_bstart].hd_dentry;
6906 + tmp_h.inode = tmp_h.dentry->d_inode;
6908 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
6911 + inode = dentry->d_inode;
6912 + if (!orig_h.inode) {
6913 + AuDbg("nagative originally\n");
6919 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
6920 + AuDebugOn(dinfo->di_bdiropq != -1);
6922 + if (!tmp_h.inode) {
6923 + AuDbg("negative --> negative\n");
6924 + /* should have only one negative lower */
6925 + if (tmp->di_bstart >= 0
6926 + && tmp->di_bstart < dinfo->di_bstart) {
6927 + AuDebugOn(tmp->di_bstart != tmp->di_bend);
6928 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
6929 + au_set_h_dptr(dentry, dinfo->di_bstart, NULL);
6930 + au_di_cp(dinfo, tmp);
6931 + hd = tmp->di_hdentry + tmp->di_bstart;
6932 + au_set_h_dptr(dentry, tmp->di_bstart,
6933 + dget(hd->hd_dentry));
6935 + au_dbg_verify_dinode(dentry);
6937 + AuDbg("negative --> positive\n");
6939 + * similar to the behaviour of creating with bypassing
6941 + * unhash it in order to force an error in the
6942 + * succeeding create operation.
6943 + * we should not set S_DEAD here.
6946 + /* au_di_swap(tmp, dinfo); */
6947 + au_dbg_verify_dinode(dentry);
6950 + AuDbg("positive originally\n");
6951 + /* inode may be NULL */
6952 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
6953 + if (!tmp_h.inode) {
6954 + AuDbg("positive --> negative\n");
6955 + /* or bypassing aufs */
6957 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_bstart)
6958 + dinfo->di_bwh = tmp->di_bwh;
6960 + err = au_refresh_hinode_self(inode);
6961 + au_dbg_verify_dinode(dentry);
6962 + } else if (orig_h.mode == tmp_h.mode) {
6963 + AuDbg("positive --> positive, same type\n");
6964 + if (!S_ISDIR(orig_h.mode)
6965 + && dinfo->di_bstart > tmp->di_bstart) {
6967 + * similar to the behaviour of removing and
6972 + err = au_refresh_hinode_self(inode);
6973 + au_dbg_verify_dinode(dentry);
6975 + /* fill empty slots */
6976 + if (dinfo->di_bstart > tmp->di_bstart)
6977 + dinfo->di_bstart = tmp->di_bstart;
6978 + if (dinfo->di_bend < tmp->di_bend)
6979 + dinfo->di_bend = tmp->di_bend;
6980 + dinfo->di_bwh = tmp->di_bwh;
6981 + dinfo->di_bdiropq = tmp->di_bdiropq;
6982 + hd = tmp->di_hdentry;
6983 + bend = dinfo->di_bend;
6984 + for (bindex = tmp->di_bstart; bindex <= bend;
6986 + if (au_h_dptr(dentry, bindex))
6988 + h_dentry = hd[bindex].hd_dentry;
6991 + h_inode = h_dentry->d_inode;
6992 + AuDebugOn(!h_inode);
6993 + AuDebugOn(orig_h.mode
6994 + != (h_inode->i_mode
6996 + au_set_h_dptr(dentry, bindex,
6999 + err = au_refresh_hinode(inode, dentry);
7000 + au_dbg_verify_dinode(dentry);
7003 + AuDbg("positive --> positive, different type\n");
7004 + /* similar to the behaviour of removing and creating */
7007 + err = au_refresh_hinode_self(inode);
7008 + au_dbg_verify_dinode(dentry);
7016 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
7019 + unsigned int sigen;
7020 + struct au_dinfo *dinfo, *tmp;
7021 + struct super_block *sb;
7022 + struct inode *inode;
7024 + DiMustWriteLock(dentry);
7025 + AuDebugOn(IS_ROOT(dentry));
7026 + AuDebugOn(!parent->d_inode);
7028 + sb = dentry->d_sb;
7029 + inode = dentry->d_inode;
7030 + sigen = au_sigen(sb);
7031 + err = au_digen_test(parent, sigen);
7032 + if (unlikely(err))
7035 + dinfo = au_di(dentry);
7036 + err = au_di_realloc(dinfo, au_sbend(sb) + 1);
7037 + if (unlikely(err))
7039 + ebrange = au_dbrange_test(dentry);
7041 + ebrange = au_do_refresh_hdentry(dentry, parent);
7043 + if (d_unhashed(dentry) || ebrange) {
7044 + AuDebugOn(au_dbstart(dentry) < 0 && au_dbend(dentry) >= 0);
7046 + err = au_refresh_hinode_self(inode);
7047 + au_dbg_verify_dinode(dentry);
7049 + goto out_dgen; /* success */
7053 + /* temporary dinfo */
7054 + AuDbgDentry(dentry);
7056 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
7057 + if (unlikely(!tmp))
7059 + au_di_swap(tmp, dinfo);
7060 + /* returns the number of positive dentries */
7062 + * if current working dir is removed, it returns an error.
7063 + * but the dentry is legal.
7065 + err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0);
7066 + AuDbgDentry(dentry);
7067 + au_di_swap(tmp, dinfo);
7068 + if (err == -ENOENT)
7071 + /* compare/refresh by dinfo */
7072 + AuDbgDentry(dentry);
7073 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
7074 + au_dbg_verify_dinode(dentry);
7077 + au_rw_write_unlock(&tmp->di_rwsem);
7079 + if (unlikely(err))
7083 + au_update_digen(dentry);
7085 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
7086 + AuIOErr("failed refreshing %.*s, %d\n",
7087 + AuDLNPair(dentry), err);
7088 + AuDbgDentry(dentry);
7094 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
7095 + struct dentry *dentry, aufs_bindex_t bindex)
7100 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
7103 + AuDbg("b%d\n", bindex);
7105 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
7106 + * due to whiteout and branch permission.
7108 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
7109 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
7110 + /* it may return tri-state */
7111 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
7113 + if (unlikely(valid < 0))
7123 +/* todo: remove this */
7124 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
7125 + unsigned int flags, int do_udba)
7128 + umode_t mode, h_mode;
7129 + aufs_bindex_t bindex, btail, bstart, ibs, ibe;
7130 + unsigned char plus, unhashed, is_root, h_plus;
7131 + struct inode *h_inode, *h_cached_inode;
7132 + struct dentry *h_dentry;
7133 + struct qstr *name, *h_name;
7140 + unhashed = !!d_unhashed(dentry);
7141 + is_root = !!IS_ROOT(dentry);
7142 + name = &dentry->d_name;
7145 + * Theoretically, REVAL test should be unnecessary in case of
7147 + * But {fs,i}notify doesn't fire some necessary events,
7148 + * IN_ATTRIB for atime/nlink/pageio
7149 + * IN_DELETE for NFS dentry
7150 + * Let's do REVAL test too.
7152 + if (do_udba && inode) {
7153 + mode = (inode->i_mode & S_IFMT);
7154 + plus = (inode->i_nlink > 0);
7155 + ibs = au_ibstart(inode);
7156 + ibe = au_ibend(inode);
7159 + bstart = au_dbstart(dentry);
7161 + if (inode && S_ISDIR(inode->i_mode))
7162 + btail = au_dbtaildir(dentry);
7163 + for (bindex = bstart; bindex <= btail; bindex++) {
7164 + h_dentry = au_h_dptr(dentry, bindex);
7168 + AuDbg("b%d, %.*s\n", bindex, AuDLNPair(h_dentry));
7169 + spin_lock(&h_dentry->d_lock);
7170 + h_name = &h_dentry->d_name;
7171 + if (unlikely(do_udba
7173 + && (unhashed != !!d_unhashed(h_dentry)
7174 + || name->len != h_name->len
7175 + || memcmp(name->name, h_name->name, name->len))
7177 + AuDbg("unhash 0x%x 0x%x, %.*s %.*s\n",
7178 + unhashed, d_unhashed(h_dentry),
7179 + AuDLNPair(dentry), AuDLNPair(h_dentry));
7180 + spin_unlock(&h_dentry->d_lock);
7183 + spin_unlock(&h_dentry->d_lock);
7185 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
7186 + if (unlikely(err))
7187 + /* do not goto err, to keep the errno */
7190 + /* todo: plink too? */
7195 + h_inode = h_dentry->d_inode;
7196 + if (unlikely(!!inode != !!h_inode))
7201 + h_cached_inode = h_inode;
7203 + h_mode = (h_inode->i_mode & S_IFMT);
7204 + h_plus = (h_inode->i_nlink > 0);
7206 + if (inode && ibs <= bindex && bindex <= ibe)
7207 + h_cached_inode = au_h_iptr(inode, bindex);
7209 + if (unlikely(plus != h_plus
7211 + || h_cached_inode != h_inode))
7223 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
7224 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
7227 + struct dentry *parent;
7229 + if (!au_digen_test(dentry, sigen))
7232 + parent = dget_parent(dentry);
7233 + di_read_lock_parent(parent, AuLock_IR);
7234 + AuDebugOn(au_digen_test(parent, sigen));
7235 + au_dbg_verify_gen(parent, sigen);
7236 + err = au_refresh_dentry(dentry, parent);
7237 + di_read_unlock(parent, AuLock_IR);
7243 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
7246 + struct dentry *d, *parent;
7247 + struct inode *inode;
7249 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
7250 + return simple_reval_dpath(dentry, sigen);
7252 + /* slow loop, keep it simple and stupid */
7253 + /* cf: au_cpup_dirs() */
7256 + while (au_digen_test(dentry, sigen)) {
7260 + parent = dget_parent(d);
7261 + if (!au_digen_test(parent, sigen))
7266 + inode = d->d_inode;
7268 + di_write_lock_child2(d);
7270 + /* someone might update our dentry while we were sleeping */
7271 + if (au_digen_test(d, sigen)) {
7273 + * todo: consolidate with simple_reval_dpath(),
7274 + * do_refresh() and au_reval_for_attr().
7276 + di_read_lock_parent(parent, AuLock_IR);
7277 + err = au_refresh_dentry(d, parent);
7278 + di_read_unlock(parent, AuLock_IR);
7282 + di_write_unlock(d);
7284 + if (unlikely(err))
7292 + * if valid returns 1, otherwise 0.
7294 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
7297 + unsigned int sigen;
7298 + unsigned char do_udba;
7299 + struct super_block *sb;
7300 + struct inode *inode;
7302 + /* todo: support rcu-walk? */
7303 + if (flags & LOOKUP_RCU)
7307 + if (unlikely(!au_di(dentry)))
7310 + inode = dentry->d_inode;
7311 + if (inode && is_bad_inode(inode))
7315 + sb = dentry->d_sb;
7318 + * i_mutex of parent dir may be held,
7319 + * but we should not return 'invalid' due to busy.
7321 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
7322 + if (unlikely(err)) {
7327 + if (unlikely(au_dbrange_test(dentry))) {
7333 + sigen = au_sigen(sb);
7334 + if (au_digen_test(dentry, sigen)) {
7335 + AuDebugOn(IS_ROOT(dentry));
7336 + err = au_reval_dpath(dentry, sigen);
7337 + if (unlikely(err)) {
7342 + di_downgrade_lock(dentry, AuLock_IR);
7345 + if (inode && (IS_DEADDIR(inode) || !inode->i_nlink))
7348 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
7349 + if (do_udba && inode) {
7350 + aufs_bindex_t bstart = au_ibstart(inode);
7351 + struct inode *h_inode;
7353 + if (bstart >= 0) {
7354 + h_inode = au_h_iptr(inode, bstart);
7355 + if (h_inode && au_test_higen(inode, h_inode))
7360 + err = h_d_revalidate(dentry, inode, flags, do_udba);
7361 + if (unlikely(!err && do_udba && au_dbstart(dentry) < 0)) {
7363 + AuDbg("both of real entry and whiteout found, %.*s, err %d\n",
7364 + AuDLNPair(dentry), err);
7369 + di_downgrade_lock(dentry, AuLock_IR);
7371 + aufs_read_unlock(dentry, AuLock_IR);
7376 + AuDbg("%.*s invalid, %d\n", AuDLNPair(dentry), valid);
7382 +static void aufs_d_release(struct dentry *dentry)
7384 + if (au_di(dentry)) {
7385 + au_di_fin(dentry);
7386 + au_hn_di_reinit(dentry);
7390 +const struct dentry_operations aufs_dop = {
7391 + .d_revalidate = aufs_d_revalidate,
7392 + .d_weak_revalidate = aufs_d_revalidate,
7393 + .d_release = aufs_d_release
7395 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
7396 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
7397 +++ linux/fs/aufs/dentry.h 2013-07-06 13:20:47.740198107 +0200
7400 + * Copyright (C) 2005-2013 Junjiro R. Okajima
7402 + * This program, aufs is free software; you can redistribute it and/or modify
7403 + * it under the terms of the GNU General Public License as published by
7404 + * the Free Software Foundation; either version 2 of the License, or
7405 + * (at your option) any later version.
7407 + * This program is distributed in the hope that it will be useful,
7408 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7409 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7410 + * GNU General Public License for more details.
7412 + * You should have received a copy of the GNU General Public License
7413 + * along with this program; if not, write to the Free Software
7414 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
7418 + * lookup and dentry operations
7421 +#ifndef __AUFS_DENTRY_H__
7422 +#define __AUFS_DENTRY_H__
7426 +#include <linux/dcache.h>
7429 +struct au_hdentry {
7430 + struct dentry *hd_dentry;
7431 + aufs_bindex_t hd_id;
7435 + atomic_t di_generation;
7437 + struct au_rwsem di_rwsem;
7438 + aufs_bindex_t di_bstart, di_bend, di_bwh, di_bdiropq;
7439 + struct au_hdentry *di_hdentry;
7440 +} ____cacheline_aligned_in_smp;
7442 +/* ---------------------------------------------------------------------- */
7445 +extern const struct dentry_operations aufs_dop;
7447 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent,
7448 + struct au_branch *br);
7449 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
7450 + struct dentry *h_parent, struct au_branch *br);
7452 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type);
7453 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
7454 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
7455 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
7458 +void au_di_init_once(void *_di);
7459 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
7460 +void au_di_free(struct au_dinfo *dinfo);
7461 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
7462 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
7463 +int au_di_init(struct dentry *dentry);
7464 +void au_di_fin(struct dentry *dentry);
7465 +int au_di_realloc(struct au_dinfo *dinfo, int nbr);
7467 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
7468 +void di_read_unlock(struct dentry *d, int flags);
7469 +void di_downgrade_lock(struct dentry *d, int flags);
7470 +void di_write_lock(struct dentry *d, unsigned int lsc);
7471 +void di_write_unlock(struct dentry *d);
7472 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
7473 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
7474 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
7476 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
7477 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
7478 +aufs_bindex_t au_dbtail(struct dentry *dentry);
7479 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
7481 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
7482 + struct dentry *h_dentry);
7483 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
7484 +int au_dbrange_test(struct dentry *dentry);
7485 +void au_update_digen(struct dentry *dentry);
7486 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
7487 +void au_update_dbstart(struct dentry *dentry);
7488 +void au_update_dbend(struct dentry *dentry);
7489 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
7491 +/* ---------------------------------------------------------------------- */
7493 +static inline struct au_dinfo *au_di(struct dentry *dentry)
7495 + return dentry->d_fsdata;
7498 +/* ---------------------------------------------------------------------- */
7500 +/* lock subclass for dinfo */
7502 + AuLsc_DI_CHILD, /* child first */
7503 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
7504 + AuLsc_DI_CHILD3, /* copyup dirs */
7508 + AuLsc_DI_TMP /* temp for replacing dinfo */
7512 + * di_read_lock_child, di_write_lock_child,
7513 + * di_read_lock_child2, di_write_lock_child2,
7514 + * di_read_lock_child3, di_write_lock_child3,
7515 + * di_read_lock_parent, di_write_lock_parent,
7516 + * di_read_lock_parent2, di_write_lock_parent2,
7517 + * di_read_lock_parent3, di_write_lock_parent3,
7519 +#define AuReadLockFunc(name, lsc) \
7520 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
7521 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
7523 +#define AuWriteLockFunc(name, lsc) \
7524 +static inline void di_write_lock_##name(struct dentry *d) \
7525 +{ di_write_lock(d, AuLsc_DI_##lsc); }
7527 +#define AuRWLockFuncs(name, lsc) \
7528 + AuReadLockFunc(name, lsc) \
7529 + AuWriteLockFunc(name, lsc)
7531 +AuRWLockFuncs(child, CHILD);
7532 +AuRWLockFuncs(child2, CHILD2);
7533 +AuRWLockFuncs(child3, CHILD3);
7534 +AuRWLockFuncs(parent, PARENT);
7535 +AuRWLockFuncs(parent2, PARENT2);
7536 +AuRWLockFuncs(parent3, PARENT3);
7538 +#undef AuReadLockFunc
7539 +#undef AuWriteLockFunc
7540 +#undef AuRWLockFuncs
7542 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
7543 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
7544 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
7546 +/* ---------------------------------------------------------------------- */
7548 +/* todo: memory barrier? */
7549 +static inline unsigned int au_digen(struct dentry *d)
7551 + return atomic_read(&au_di(d)->di_generation);
7554 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
7556 + hdentry->hd_dentry = NULL;
7559 +static inline void au_hdput(struct au_hdentry *hd)
7562 + dput(hd->hd_dentry);
7565 +static inline aufs_bindex_t au_dbstart(struct dentry *dentry)
7567 + DiMustAnyLock(dentry);
7568 + return au_di(dentry)->di_bstart;
7571 +static inline aufs_bindex_t au_dbend(struct dentry *dentry)
7573 + DiMustAnyLock(dentry);
7574 + return au_di(dentry)->di_bend;
7577 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
7579 + DiMustAnyLock(dentry);
7580 + return au_di(dentry)->di_bwh;
7583 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
7585 + DiMustAnyLock(dentry);
7586 + return au_di(dentry)->di_bdiropq;
7589 +/* todo: hard/soft set? */
7590 +static inline void au_set_dbstart(struct dentry *dentry, aufs_bindex_t bindex)
7592 + DiMustWriteLock(dentry);
7593 + au_di(dentry)->di_bstart = bindex;
7596 +static inline void au_set_dbend(struct dentry *dentry, aufs_bindex_t bindex)
7598 + DiMustWriteLock(dentry);
7599 + au_di(dentry)->di_bend = bindex;
7602 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
7604 + DiMustWriteLock(dentry);
7605 + /* dbwh can be outside of bstart - bend range */
7606 + au_di(dentry)->di_bwh = bindex;
7609 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
7611 + DiMustWriteLock(dentry);
7612 + au_di(dentry)->di_bdiropq = bindex;
7615 +/* ---------------------------------------------------------------------- */
7617 +#ifdef CONFIG_AUFS_HNOTIFY
7618 +static inline void au_digen_dec(struct dentry *d)
7620 + atomic_dec(&au_di(d)->di_generation);
7623 +static inline void au_hn_di_reinit(struct dentry *dentry)
7625 + dentry->d_fsdata = NULL;
7628 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
7629 +#endif /* CONFIG_AUFS_HNOTIFY */
7631 +#endif /* __KERNEL__ */
7632 +#endif /* __AUFS_DENTRY_H__ */
7633 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
7634 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
7635 +++ linux/fs/aufs/dinfo.c 2013-07-30 22:42:55.839613269 +0200
7638 + * Copyright (C) 2005-2013 Junjiro R. Okajima
7640 + * This program, aufs is free software; you can redistribute it and/or modify
7641 + * it under the terms of the GNU General Public License as published by
7642 + * the Free Software Foundation; either version 2 of the License, or
7643 + * (at your option) any later version.
7645 + * This program is distributed in the hope that it will be useful,
7646 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7647 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7648 + * GNU General Public License for more details.
7650 + * You should have received a copy of the GNU General Public License
7651 + * along with this program; if not, write to the Free Software
7652 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
7656 + * dentry private data
7661 +void au_di_init_once(void *_dinfo)
7663 + struct au_dinfo *dinfo = _dinfo;
7664 + static struct lock_class_key aufs_di;
7666 + au_rw_init(&dinfo->di_rwsem);
7667 + au_rw_class(&dinfo->di_rwsem, &aufs_di);
7670 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
7672 + struct au_dinfo *dinfo;
7675 + dinfo = au_cache_alloc_dinfo();
7676 + if (unlikely(!dinfo))
7679 + nbr = au_sbend(sb) + 1;
7682 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
7683 + if (dinfo->di_hdentry) {
7684 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
7685 + dinfo->di_bstart = -1;
7686 + dinfo->di_bend = -1;
7687 + dinfo->di_bwh = -1;
7688 + dinfo->di_bdiropq = -1;
7689 + for (i = 0; i < nbr; i++)
7690 + dinfo->di_hdentry[i].hd_id = -1;
7694 + au_cache_free_dinfo(dinfo);
7701 +void au_di_free(struct au_dinfo *dinfo)
7703 + struct au_hdentry *p;
7704 + aufs_bindex_t bend, bindex;
7706 + /* dentry may not be revalidated */
7707 + bindex = dinfo->di_bstart;
7708 + if (bindex >= 0) {
7709 + bend = dinfo->di_bend;
7710 + p = dinfo->di_hdentry + bindex;
7711 + while (bindex++ <= bend)
7714 + kfree(dinfo->di_hdentry);
7715 + au_cache_free_dinfo(dinfo);
7718 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
7720 + struct au_hdentry *p;
7723 + AuRwMustWriteLock(&a->di_rwsem);
7724 + AuRwMustWriteLock(&b->di_rwsem);
7726 +#define DiSwap(v, name) \
7728 + v = a->di_##name; \
7729 + a->di_##name = b->di_##name; \
7730 + b->di_##name = v; \
7733 + DiSwap(p, hdentry);
7734 + DiSwap(bi, bstart);
7737 + DiSwap(bi, bdiropq);
7743 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
7745 + AuRwMustWriteLock(&dst->di_rwsem);
7746 + AuRwMustWriteLock(&src->di_rwsem);
7748 + dst->di_bstart = src->di_bstart;
7749 + dst->di_bend = src->di_bend;
7750 + dst->di_bwh = src->di_bwh;
7751 + dst->di_bdiropq = src->di_bdiropq;
7755 +int au_di_init(struct dentry *dentry)
7758 + struct super_block *sb;
7759 + struct au_dinfo *dinfo;
7762 + sb = dentry->d_sb;
7763 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
7765 + atomic_set(&dinfo->di_generation, au_sigen(sb));
7766 + /* smp_mb(); */ /* atomic_set */
7767 + dentry->d_fsdata = dinfo;
7774 +void au_di_fin(struct dentry *dentry)
7776 + struct au_dinfo *dinfo;
7778 + dinfo = au_di(dentry);
7779 + AuRwDestroy(&dinfo->di_rwsem);
7780 + au_di_free(dinfo);
7783 +int au_di_realloc(struct au_dinfo *dinfo, int nbr)
7786 + struct au_hdentry *hdp;
7788 + AuRwMustWriteLock(&dinfo->di_rwsem);
7791 + sz = sizeof(*hdp) * (dinfo->di_bend + 1);
7793 + sz = sizeof(*hdp);
7794 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS);
7796 + dinfo->di_hdentry = hdp;
7803 +/* ---------------------------------------------------------------------- */
7805 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
7808 + case AuLsc_DI_CHILD:
7809 + ii_write_lock_child(inode);
7811 + case AuLsc_DI_CHILD2:
7812 + ii_write_lock_child2(inode);
7814 + case AuLsc_DI_CHILD3:
7815 + ii_write_lock_child3(inode);
7817 + case AuLsc_DI_PARENT:
7818 + ii_write_lock_parent(inode);
7820 + case AuLsc_DI_PARENT2:
7821 + ii_write_lock_parent2(inode);
7823 + case AuLsc_DI_PARENT3:
7824 + ii_write_lock_parent3(inode);
7831 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
7834 + case AuLsc_DI_CHILD:
7835 + ii_read_lock_child(inode);
7837 + case AuLsc_DI_CHILD2:
7838 + ii_read_lock_child2(inode);
7840 + case AuLsc_DI_CHILD3:
7841 + ii_read_lock_child3(inode);
7843 + case AuLsc_DI_PARENT:
7844 + ii_read_lock_parent(inode);
7846 + case AuLsc_DI_PARENT2:
7847 + ii_read_lock_parent2(inode);
7849 + case AuLsc_DI_PARENT3:
7850 + ii_read_lock_parent3(inode);
7857 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
7859 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
7861 + if (au_ftest_lock(flags, IW))
7862 + do_ii_write_lock(d->d_inode, lsc);
7863 + else if (au_ftest_lock(flags, IR))
7864 + do_ii_read_lock(d->d_inode, lsc);
7868 +void di_read_unlock(struct dentry *d, int flags)
7871 + if (au_ftest_lock(flags, IW)) {
7872 + au_dbg_verify_dinode(d);
7873 + ii_write_unlock(d->d_inode);
7874 + } else if (au_ftest_lock(flags, IR)) {
7875 + au_dbg_verify_dinode(d);
7876 + ii_read_unlock(d->d_inode);
7879 + au_rw_read_unlock(&au_di(d)->di_rwsem);
7882 +void di_downgrade_lock(struct dentry *d, int flags)
7884 + if (d->d_inode && au_ftest_lock(flags, IR))
7885 + ii_downgrade_lock(d->d_inode);
7886 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
7889 +void di_write_lock(struct dentry *d, unsigned int lsc)
7891 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
7893 + do_ii_write_lock(d->d_inode, lsc);
7896 +void di_write_unlock(struct dentry *d)
7898 + au_dbg_verify_dinode(d);
7900 + ii_write_unlock(d->d_inode);
7901 + au_rw_write_unlock(&au_di(d)->di_rwsem);
7904 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
7906 + AuDebugOn(d1 == d2
7907 + || d1->d_inode == d2->d_inode
7908 + || d1->d_sb != d2->d_sb);
7910 + if (isdir && au_test_subdir(d1, d2)) {
7911 + di_write_lock_child(d1);
7912 + di_write_lock_child2(d2);
7914 + /* there should be no races */
7915 + di_write_lock_child(d2);
7916 + di_write_lock_child2(d1);
7920 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
7922 + AuDebugOn(d1 == d2
7923 + || d1->d_inode == d2->d_inode
7924 + || d1->d_sb != d2->d_sb);
7926 + if (isdir && au_test_subdir(d1, d2)) {
7927 + di_write_lock_parent(d1);
7928 + di_write_lock_parent2(d2);
7930 + /* there should be no races */
7931 + di_write_lock_parent(d2);
7932 + di_write_lock_parent2(d1);
7936 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
7938 + di_write_unlock(d1);
7939 + if (d1->d_inode == d2->d_inode)
7940 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
7942 + di_write_unlock(d2);
7945 +/* ---------------------------------------------------------------------- */
7947 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
7951 + DiMustAnyLock(dentry);
7953 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
7955 + AuDebugOn(bindex < 0);
7956 + d = au_di(dentry)->di_hdentry[0 + bindex].hd_dentry;
7957 + AuDebugOn(d && d->d_count <= 0);
7962 + * extended version of au_h_dptr().
7963 + * returns a hashed and positive h_dentry in bindex, NULL, or error.
7965 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
7967 + struct dentry *h_dentry;
7968 + struct inode *inode, *h_inode;
7970 + inode = dentry->d_inode;
7971 + AuDebugOn(!inode);
7974 + if (au_dbstart(dentry) <= bindex
7975 + && bindex <= au_dbend(dentry))
7976 + h_dentry = au_h_dptr(dentry, bindex);
7977 + if (h_dentry && !au_d_hashed_positive(h_dentry)) {
7979 + goto out; /* success */
7982 + AuDebugOn(bindex < au_ibstart(inode));
7983 + AuDebugOn(au_ibend(inode) < bindex);
7984 + h_inode = au_h_iptr(inode, bindex);
7985 + h_dentry = d_find_alias(h_inode);
7987 + if (!IS_ERR(h_dentry)) {
7988 + if (!au_d_hashed_positive(h_dentry))
7989 + goto out; /* success */
7995 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
7996 + h_dentry = au_plink_lkup(inode, bindex);
7997 + AuDebugOn(!h_dentry);
7998 + if (!IS_ERR(h_dentry)) {
7999 + if (!au_d_hashed_positive(h_dentry))
8000 + goto out; /* success */
8007 + AuDbgDentry(h_dentry);
8011 +aufs_bindex_t au_dbtail(struct dentry *dentry)
8013 + aufs_bindex_t bend, bwh;
8015 + bend = au_dbend(dentry);
8017 + bwh = au_dbwh(dentry);
8020 + if (0 < bwh && bwh < bend)
8026 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
8028 + aufs_bindex_t bend, bopq;
8030 + bend = au_dbtail(dentry);
8032 + bopq = au_dbdiropq(dentry);
8033 + if (0 <= bopq && bopq < bend)
8039 +/* ---------------------------------------------------------------------- */
8041 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
8042 + struct dentry *h_dentry)
8044 + struct au_hdentry *hd = au_di(dentry)->di_hdentry + bindex;
8045 + struct au_branch *br;
8047 + DiMustWriteLock(dentry);
8050 + hd->hd_dentry = h_dentry;
8052 + br = au_sbr(dentry->d_sb, bindex);
8053 + hd->hd_id = br->br_id;
8057 +int au_dbrange_test(struct dentry *dentry)
8060 + aufs_bindex_t bstart, bend;
8063 + bstart = au_dbstart(dentry);
8064 + bend = au_dbend(dentry);
8066 + AuDebugOn(bend < 0 && bstart > bend);
8069 + AuDebugOn(bend >= 0);
8075 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
8080 + if (unlikely(au_digen(dentry) != sigen
8081 + || au_iigen_test(dentry->d_inode, sigen)))
8087 +void au_update_digen(struct dentry *dentry)
8089 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
8090 + /* smp_mb(); */ /* atomic_set */
8093 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
8095 + struct au_dinfo *dinfo;
8096 + struct dentry *h_d;
8097 + struct au_hdentry *hdp;
8099 + DiMustWriteLock(dentry);
8101 + dinfo = au_di(dentry);
8102 + if (!dinfo || dinfo->di_bstart < 0)
8105 + hdp = dinfo->di_hdentry;
8106 + if (do_put_zero) {
8107 + aufs_bindex_t bindex, bend;
8109 + bend = dinfo->di_bend;
8110 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++) {
8111 + h_d = hdp[0 + bindex].hd_dentry;
8112 + if (h_d && !h_d->d_inode)
8113 + au_set_h_dptr(dentry, bindex, NULL);
8117 + dinfo->di_bstart = -1;
8118 + while (++dinfo->di_bstart <= dinfo->di_bend)
8119 + if (hdp[0 + dinfo->di_bstart].hd_dentry)
8121 + if (dinfo->di_bstart > dinfo->di_bend) {
8122 + dinfo->di_bstart = -1;
8123 + dinfo->di_bend = -1;
8128 + while (0 <= --dinfo->di_bend)
8129 + if (hdp[0 + dinfo->di_bend].hd_dentry)
8131 + AuDebugOn(dinfo->di_bstart > dinfo->di_bend || dinfo->di_bend < 0);
8134 +void au_update_dbstart(struct dentry *dentry)
8136 + aufs_bindex_t bindex, bend;
8137 + struct dentry *h_dentry;
8139 + bend = au_dbend(dentry);
8140 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
8141 + h_dentry = au_h_dptr(dentry, bindex);
8144 + if (h_dentry->d_inode) {
8145 + au_set_dbstart(dentry, bindex);
8148 + au_set_h_dptr(dentry, bindex, NULL);
8152 +void au_update_dbend(struct dentry *dentry)
8154 + aufs_bindex_t bindex, bstart;
8155 + struct dentry *h_dentry;
8157 + bstart = au_dbstart(dentry);
8158 + for (bindex = au_dbend(dentry); bindex >= bstart; bindex--) {
8159 + h_dentry = au_h_dptr(dentry, bindex);
8162 + if (h_dentry->d_inode) {
8163 + au_set_dbend(dentry, bindex);
8166 + au_set_h_dptr(dentry, bindex, NULL);
8170 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
8172 + aufs_bindex_t bindex, bend;
8174 + bend = au_dbend(dentry);
8175 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++)
8176 + if (au_h_dptr(dentry, bindex) == h_dentry)
8180 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
8181 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
8182 +++ linux/fs/aufs/dir.c 2013-07-30 22:42:55.839613269 +0200
8185 + * Copyright (C) 2005-2013 Junjiro R. Okajima
8187 + * This program, aufs is free software; you can redistribute it and/or modify
8188 + * it under the terms of the GNU General Public License as published by
8189 + * the Free Software Foundation; either version 2 of the License, or
8190 + * (at your option) any later version.
8192 + * This program is distributed in the hope that it will be useful,
8193 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8194 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8195 + * GNU General Public License for more details.
8197 + * You should have received a copy of the GNU General Public License
8198 + * along with this program; if not, write to the Free Software
8199 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
8203 + * directory operations
8206 +#include <linux/fs_stack.h>
8209 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
8211 + unsigned int nlink;
8213 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
8215 + nlink = dir->i_nlink;
8216 + nlink += h_dir->i_nlink - 2;
8217 + if (h_dir->i_nlink < 2)
8220 + /* 0 can happen in revaliding */
8221 + set_nlink(dir, nlink);
8224 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
8226 + unsigned int nlink;
8228 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
8230 + nlink = dir->i_nlink;
8231 + nlink -= h_dir->i_nlink - 2;
8232 + if (h_dir->i_nlink < 2)
8235 + /* nlink == 0 means the branch-fs is broken */
8236 + set_nlink(dir, nlink);
8239 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
8242 + aufs_bindex_t bindex, bend;
8243 + struct file *h_file;
8244 + struct dentry *h_dentry;
8248 + AuDebugOn(!file_inode(file));
8249 + AuDebugOn(!S_ISDIR(file_inode(file)->i_mode));
8251 + bend = au_fbend_dir(file);
8252 + for (bindex = au_fbstart(file);
8253 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
8255 + h_file = au_hf_dir(file, bindex);
8256 + if (h_file && file_inode(h_file))
8257 + sz += vfsub_f_size_read(h_file);
8260 + AuDebugOn(!dentry);
8261 + AuDebugOn(!dentry->d_inode);
8262 + AuDebugOn(!S_ISDIR(dentry->d_inode->i_mode));
8264 + bend = au_dbtaildir(dentry);
8265 + for (bindex = au_dbstart(dentry);
8266 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
8268 + h_dentry = au_h_dptr(dentry, bindex);
8269 + if (h_dentry && h_dentry->d_inode)
8270 + sz += i_size_read(h_dentry->d_inode);
8273 + if (sz < KMALLOC_MAX_SIZE)
8274 + sz = roundup_pow_of_two(sz);
8275 + if (sz > KMALLOC_MAX_SIZE)
8276 + sz = KMALLOC_MAX_SIZE;
8277 + else if (sz < NAME_MAX) {
8278 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
8279 + sz = AUFS_RDBLK_DEF;
8284 +/* ---------------------------------------------------------------------- */
8286 +static int reopen_dir(struct file *file)
8289 + unsigned int flags;
8290 + aufs_bindex_t bindex, btail, bstart;
8291 + struct dentry *dentry, *h_dentry;
8292 + struct file *h_file;
8294 + /* open all lower dirs */
8295 + dentry = file->f_dentry;
8296 + bstart = au_dbstart(dentry);
8297 + for (bindex = au_fbstart(file); bindex < bstart; bindex++)
8298 + au_set_h_fptr(file, bindex, NULL);
8299 + au_set_fbstart(file, bstart);
8301 + btail = au_dbtaildir(dentry);
8302 + for (bindex = au_fbend_dir(file); btail < bindex; bindex--)
8303 + au_set_h_fptr(file, bindex, NULL);
8304 + au_set_fbend_dir(file, btail);
8306 + flags = vfsub_file_flags(file);
8307 + for (bindex = bstart; bindex <= btail; bindex++) {
8308 + h_dentry = au_h_dptr(dentry, bindex);
8311 + h_file = au_hf_dir(file, bindex);
8315 + h_file = au_h_open(dentry, bindex, flags, file);
8316 + err = PTR_ERR(h_file);
8317 + if (IS_ERR(h_file))
8318 + goto out; /* close all? */
8319 + au_set_h_fptr(file, bindex, h_file);
8321 + au_update_figen(file);
8322 + /* todo: necessary? */
8323 + /* file->f_ra = h_file->f_ra; */
8330 +static int do_open_dir(struct file *file, int flags)
8333 + aufs_bindex_t bindex, btail;
8334 + struct dentry *dentry, *h_dentry;
8335 + struct file *h_file;
8337 + FiMustWriteLock(file);
8339 + dentry = file->f_dentry;
8340 + err = au_alive_dir(dentry);
8341 + if (unlikely(err))
8344 + file->f_version = dentry->d_inode->i_version;
8345 + bindex = au_dbstart(dentry);
8346 + au_set_fbstart(file, bindex);
8347 + btail = au_dbtaildir(dentry);
8348 + au_set_fbend_dir(file, btail);
8349 + for (; !err && bindex <= btail; bindex++) {
8350 + h_dentry = au_h_dptr(dentry, bindex);
8354 + h_file = au_h_open(dentry, bindex, flags, file);
8355 + if (IS_ERR(h_file)) {
8356 + err = PTR_ERR(h_file);
8359 + au_set_h_fptr(file, bindex, h_file);
8361 + au_update_figen(file);
8362 + /* todo: necessary? */
8363 + /* file->f_ra = h_file->f_ra; */
8365 + return 0; /* success */
8368 + for (bindex = au_fbstart(file); bindex <= btail; bindex++)
8369 + au_set_h_fptr(file, bindex, NULL);
8370 + au_set_fbstart(file, -1);
8371 + au_set_fbend_dir(file, -1);
8377 +static int aufs_open_dir(struct inode *inode __maybe_unused,
8378 + struct file *file)
8381 + struct super_block *sb;
8382 + struct au_fidir *fidir;
8385 + sb = file->f_dentry->d_sb;
8386 + si_read_lock(sb, AuLock_FLUSH);
8387 + fidir = au_fidir_alloc(sb);
8389 + err = au_do_open(file, do_open_dir, fidir);
8390 + if (unlikely(err))
8393 + si_read_unlock(sb);
8397 +static int aufs_release_dir(struct inode *inode __maybe_unused,
8398 + struct file *file)
8400 + struct au_vdir *vdir_cache;
8401 + struct au_finfo *finfo;
8402 + struct au_fidir *fidir;
8403 + aufs_bindex_t bindex, bend;
8405 + finfo = au_fi(file);
8406 + fidir = finfo->fi_hdir;
8408 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
8410 + au_vdir_free(vdir_cache);
8412 + bindex = finfo->fi_btop;
8413 + if (bindex >= 0) {
8415 + * calls fput() instead of filp_close(),
8416 + * since no dnotify or lock for the lower file.
8418 + bend = fidir->fd_bbot;
8419 + for (; bindex <= bend; bindex++)
8420 + au_set_h_fptr(file, bindex, NULL);
8423 + finfo->fi_hdir = NULL;
8425 + au_finfo_fin(file);
8429 +/* ---------------------------------------------------------------------- */
8431 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
8434 + aufs_bindex_t bindex, bend;
8435 + struct file *h_file;
8438 + bend = au_fbend_dir(file);
8439 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
8440 + h_file = au_hf_dir(file, bindex);
8442 + err = vfsub_flush(h_file, id);
8447 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
8449 + return au_do_flush(file, id, au_do_flush_dir);
8452 +/* ---------------------------------------------------------------------- */
8454 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
8457 + aufs_bindex_t bend, bindex;
8458 + struct inode *inode;
8459 + struct super_block *sb;
8462 + sb = dentry->d_sb;
8463 + inode = dentry->d_inode;
8465 + bend = au_dbend(dentry);
8466 + for (bindex = au_dbstart(dentry); !err && bindex <= bend; bindex++) {
8467 + struct path h_path;
8469 + if (au_test_ro(sb, bindex, inode))
8471 + h_path.dentry = au_h_dptr(dentry, bindex);
8472 + if (!h_path.dentry)
8475 + h_path.mnt = au_sbr_mnt(sb, bindex);
8476 + err = vfsub_fsync(NULL, &h_path, datasync);
8482 +static int au_do_fsync_dir(struct file *file, int datasync)
8485 + aufs_bindex_t bend, bindex;
8486 + struct file *h_file;
8487 + struct super_block *sb;
8488 + struct inode *inode;
8490 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
8491 + if (unlikely(err))
8494 + sb = file->f_dentry->d_sb;
8495 + inode = file_inode(file);
8496 + bend = au_fbend_dir(file);
8497 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
8498 + h_file = au_hf_dir(file, bindex);
8499 + if (!h_file || au_test_ro(sb, bindex, inode))
8502 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
8510 + * @file may be NULL
8512 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
8516 + struct dentry *dentry;
8517 + struct super_block *sb;
8518 + struct mutex *mtx;
8521 + dentry = file->f_dentry;
8522 + mtx = &dentry->d_inode->i_mutex;
8524 + sb = dentry->d_sb;
8525 + si_noflush_read_lock(sb);
8527 + err = au_do_fsync_dir(file, datasync);
8529 + di_write_lock_child(dentry);
8530 + err = au_do_fsync_dir_no_file(dentry, datasync);
8532 + au_cpup_attr_timesizes(dentry->d_inode);
8533 + di_write_unlock(dentry);
8535 + fi_write_unlock(file);
8537 + si_read_unlock(sb);
8538 + mutex_unlock(mtx);
8542 +/* ---------------------------------------------------------------------- */
8544 +static int aufs_readdir(struct file *file, void *dirent, filldir_t filldir)
8547 + struct dentry *dentry;
8548 + struct inode *inode, *h_inode;
8549 + struct super_block *sb;
8551 + dentry = file->f_dentry;
8552 + inode = dentry->d_inode;
8555 + sb = dentry->d_sb;
8556 + si_read_lock(sb, AuLock_FLUSH);
8557 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
8558 + if (unlikely(err))
8560 + err = au_alive_dir(dentry);
8562 + err = au_vdir_init(file);
8563 + di_downgrade_lock(dentry, AuLock_IR);
8564 + if (unlikely(err))
8567 + h_inode = au_h_iptr(inode, au_ibstart(inode));
8568 + if (!au_test_nfsd()) {
8569 + err = au_vdir_fill_de(file, dirent, filldir);
8570 + fsstack_copy_attr_atime(inode, h_inode);
8573 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
8574 + * encode_fh() and others.
8576 + atomic_inc(&h_inode->i_count);
8577 + di_read_unlock(dentry, AuLock_IR);
8578 + si_read_unlock(sb);
8579 + err = au_vdir_fill_de(file, dirent, filldir);
8580 + fsstack_copy_attr_atime(inode, h_inode);
8581 + fi_write_unlock(file);
8589 + di_read_unlock(dentry, AuLock_IR);
8590 + fi_write_unlock(file);
8592 + si_read_unlock(sb);
8596 +/* ---------------------------------------------------------------------- */
8598 +#define AuTestEmpty_WHONLY 1
8599 +#define AuTestEmpty_CALLED (1 << 1)
8600 +#define AuTestEmpty_SHWH (1 << 2)
8601 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
8602 +#define au_fset_testempty(flags, name) \
8603 + do { (flags) |= AuTestEmpty_##name; } while (0)
8604 +#define au_fclr_testempty(flags, name) \
8605 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
8607 +#ifndef CONFIG_AUFS_SHWH
8608 +#undef AuTestEmpty_SHWH
8609 +#define AuTestEmpty_SHWH 0
8612 +struct test_empty_arg {
8613 + struct au_nhash *whlist;
8614 + unsigned int flags;
8616 + aufs_bindex_t bindex;
8619 +static int test_empty_cb(void *__arg, const char *__name, int namelen,
8620 + loff_t offset __maybe_unused, u64 ino,
8621 + unsigned int d_type)
8623 + struct test_empty_arg *arg = __arg;
8624 + char *name = (void *)__name;
8627 + au_fset_testempty(arg->flags, CALLED);
8629 + if (name[0] == '.'
8630 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
8631 + goto out; /* success */
8633 + if (namelen <= AUFS_WH_PFX_LEN
8634 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
8635 + if (au_ftest_testempty(arg->flags, WHONLY)
8636 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
8637 + arg->err = -ENOTEMPTY;
8641 + name += AUFS_WH_PFX_LEN;
8642 + namelen -= AUFS_WH_PFX_LEN;
8643 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
8644 + arg->err = au_nhash_append_wh
8645 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
8646 + au_ftest_testempty(arg->flags, SHWH));
8650 + AuTraceErr(arg->err);
8654 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
8657 + struct file *h_file;
8659 + h_file = au_h_open(dentry, arg->bindex,
8660 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
8662 + err = PTR_ERR(h_file);
8663 + if (IS_ERR(h_file))
8667 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
8668 + && !file_inode(h_file)->i_nlink)
8673 + au_fclr_testempty(arg->flags, CALLED);
8675 + err = vfsub_readdir(h_file, test_empty_cb, arg);
8678 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
8682 + au_sbr_put(dentry->d_sb, arg->bindex);
8687 +struct do_test_empty_args {
8689 + struct dentry *dentry;
8690 + struct test_empty_arg *arg;
8693 +static void call_do_test_empty(void *args)
8695 + struct do_test_empty_args *a = args;
8696 + *a->errp = do_test_empty(a->dentry, a->arg);
8699 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
8702 + struct dentry *h_dentry;
8703 + struct inode *h_inode;
8705 + h_dentry = au_h_dptr(dentry, arg->bindex);
8706 + h_inode = h_dentry->d_inode;
8707 + /* todo: i_mode changes anytime? */
8708 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
8709 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
8710 + mutex_unlock(&h_inode->i_mutex);
8712 + err = do_test_empty(dentry, arg);
8714 + struct do_test_empty_args args = {
8719 + unsigned int flags = arg->flags;
8721 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
8722 + if (unlikely(wkq_err))
8724 + arg->flags = flags;
8730 +int au_test_empty_lower(struct dentry *dentry)
8733 + unsigned int rdhash;
8734 + aufs_bindex_t bindex, bstart, btail;
8735 + struct au_nhash whlist;
8736 + struct test_empty_arg arg;
8738 + SiMustAnyLock(dentry->d_sb);
8740 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
8742 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
8743 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
8744 + if (unlikely(err))
8748 + arg.whlist = &whlist;
8749 + bstart = au_dbstart(dentry);
8750 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
8751 + au_fset_testempty(arg.flags, SHWH);
8752 + arg.bindex = bstart;
8753 + err = do_test_empty(dentry, &arg);
8754 + if (unlikely(err))
8757 + au_fset_testempty(arg.flags, WHONLY);
8758 + btail = au_dbtaildir(dentry);
8759 + for (bindex = bstart + 1; !err && bindex <= btail; bindex++) {
8760 + struct dentry *h_dentry;
8762 + h_dentry = au_h_dptr(dentry, bindex);
8763 + if (h_dentry && h_dentry->d_inode) {
8764 + arg.bindex = bindex;
8765 + err = do_test_empty(dentry, &arg);
8770 + au_nhash_wh_free(&whlist);
8775 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
8778 + struct test_empty_arg arg;
8779 + aufs_bindex_t bindex, btail;
8782 + arg.whlist = whlist;
8783 + arg.flags = AuTestEmpty_WHONLY;
8784 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
8785 + au_fset_testempty(arg.flags, SHWH);
8786 + btail = au_dbtaildir(dentry);
8787 + for (bindex = au_dbstart(dentry); !err && bindex <= btail; bindex++) {
8788 + struct dentry *h_dentry;
8790 + h_dentry = au_h_dptr(dentry, bindex);
8791 + if (h_dentry && h_dentry->d_inode) {
8792 + arg.bindex = bindex;
8793 + err = sio_test_empty(dentry, &arg);
8800 +/* ---------------------------------------------------------------------- */
8802 +const struct file_operations aufs_dir_fop = {
8803 + .owner = THIS_MODULE,
8804 + .llseek = default_llseek,
8805 + .read = generic_read_dir,
8806 + .readdir = aufs_readdir,
8807 + .unlocked_ioctl = aufs_ioctl_dir,
8808 +#ifdef CONFIG_COMPAT
8809 + .compat_ioctl = aufs_compat_ioctl_dir,
8811 + .open = aufs_open_dir,
8812 + .release = aufs_release_dir,
8813 + .flush = aufs_flush_dir,
8814 + .fsync = aufs_fsync_dir
8816 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
8817 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
8818 +++ linux/fs/aufs/dir.h 2013-07-30 22:42:55.839613269 +0200
8821 + * Copyright (C) 2005-2013 Junjiro R. Okajima
8823 + * This program, aufs is free software; you can redistribute it and/or modify
8824 + * it under the terms of the GNU General Public License as published by
8825 + * the Free Software Foundation; either version 2 of the License, or
8826 + * (at your option) any later version.
8828 + * This program is distributed in the hope that it will be useful,
8829 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8830 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8831 + * GNU General Public License for more details.
8833 + * You should have received a copy of the GNU General Public License
8834 + * along with this program; if not, write to the Free Software
8835 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
8839 + * directory operations
8842 +#ifndef __AUFS_DIR_H__
8843 +#define __AUFS_DIR_H__
8847 +#include <linux/fs.h>
8849 +/* ---------------------------------------------------------------------- */
8851 +/* need to be faster and smaller */
8854 + unsigned int nh_num;
8855 + struct hlist_head *nh_head;
8858 +struct au_vdir_destr {
8859 + unsigned char len;
8860 + unsigned char name[0];
8863 +struct au_vdir_dehstr {
8864 + struct hlist_node hash;
8865 + struct au_vdir_destr *str;
8866 +} ____cacheline_aligned_in_smp;
8868 +struct au_vdir_de {
8870 + unsigned char de_type;
8871 + /* caution: packed */
8872 + struct au_vdir_destr de_str;
8875 +struct au_vdir_wh {
8876 + struct hlist_node wh_hash;
8877 +#ifdef CONFIG_AUFS_SHWH
8879 + aufs_bindex_t wh_bindex;
8880 + unsigned char wh_type;
8882 + aufs_bindex_t wh_bindex;
8884 + /* caution: packed */
8885 + struct au_vdir_destr wh_str;
8888 +union au_vdir_deblk_p {
8889 + unsigned char *deblk;
8890 + struct au_vdir_de *de;
8894 + unsigned char **vd_deblk;
8895 + unsigned long vd_nblk;
8898 + union au_vdir_deblk_p p;
8901 + unsigned long vd_version;
8902 + unsigned int vd_deblk_sz;
8903 + unsigned long vd_jiffy;
8904 +} ____cacheline_aligned_in_smp;
8906 +/* ---------------------------------------------------------------------- */
8909 +extern const struct file_operations aufs_dir_fop;
8910 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
8911 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
8912 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
8913 +int au_test_empty_lower(struct dentry *dentry);
8914 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
8917 +unsigned int au_rdhash_est(loff_t sz);
8918 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
8919 +void au_nhash_wh_free(struct au_nhash *whlist);
8920 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
8922 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
8923 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
8924 + unsigned int d_type, aufs_bindex_t bindex,
8925 + unsigned char shwh);
8926 +void au_vdir_free(struct au_vdir *vdir);
8927 +int au_vdir_init(struct file *file);
8928 +int au_vdir_fill_de(struct file *file, void *dirent, filldir_t filldir);
8931 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
8933 +#ifdef CONFIG_AUFS_RDU
8935 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
8936 +#ifdef CONFIG_COMPAT
8937 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
8938 + unsigned long arg);
8941 +static inline long au_rdu_ioctl(struct file *file, unsigned int cmd,
8942 + unsigned long arg)
8946 +#ifdef CONFIG_COMPAT
8947 +static inline long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
8948 + unsigned long arg)
8955 +#endif /* __KERNEL__ */
8956 +#endif /* __AUFS_DIR_H__ */
8957 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
8958 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
8959 +++ linux/fs/aufs/dynop.c 2013-07-30 22:42:55.839613269 +0200
8962 + * Copyright (C) 2010-2013 Junjiro R. Okajima
8964 + * This program, aufs is free software; you can redistribute it and/or modify
8965 + * it under the terms of the GNU General Public License as published by
8966 + * the Free Software Foundation; either version 2 of the License, or
8967 + * (at your option) any later version.
8969 + * This program is distributed in the hope that it will be useful,
8970 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8971 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8972 + * GNU General Public License for more details.
8974 + * You should have received a copy of the GNU General Public License
8975 + * along with this program; if not, write to the Free Software
8976 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
8980 + * dynamically customizable operations for regular files
8985 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
8988 + * How large will these lists be?
8989 + * Usually just a few elements, 20-30 at most for each, I guess.
8991 +static struct au_splhead dynop[AuDyLast];
8993 +static struct au_dykey *dy_gfind_get(struct au_splhead *spl, const void *h_op)
8995 + struct au_dykey *key, *tmp;
8996 + struct list_head *head;
8999 + head = &spl->head;
9001 + list_for_each_entry_rcu(tmp, head, dk_list)
9002 + if (tmp->dk_op.dy_hop == h_op) {
9004 + kref_get(&key->dk_kref);
9007 + rcu_read_unlock();
9012 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
9014 + struct au_dykey **k, *found;
9015 + const void *h_op = key->dk_op.dy_hop;
9020 + for (i = 0; i < AuBrDynOp; i++)
9022 + if (k[i]->dk_op.dy_hop == h_op) {
9029 + spin_lock(&br->br_dykey_lock);
9030 + for (; i < AuBrDynOp; i++)
9032 + if (k[i]->dk_op.dy_hop == h_op) {
9040 + spin_unlock(&br->br_dykey_lock);
9041 + BUG_ON(i == AuBrDynOp); /* expand the array */
9047 +/* kref_get() if @key is already added */
9048 +static struct au_dykey *dy_gadd(struct au_splhead *spl, struct au_dykey *key)
9050 + struct au_dykey *tmp, *found;
9051 + struct list_head *head;
9052 + const void *h_op = key->dk_op.dy_hop;
9055 + head = &spl->head;
9056 + spin_lock(&spl->spin);
9057 + list_for_each_entry(tmp, head, dk_list)
9058 + if (tmp->dk_op.dy_hop == h_op) {
9059 + kref_get(&tmp->dk_kref);
9064 + list_add_rcu(&key->dk_list, head);
9065 + spin_unlock(&spl->spin);
9072 +static void dy_free_rcu(struct rcu_head *rcu)
9074 + struct au_dykey *key;
9076 + key = container_of(rcu, struct au_dykey, dk_rcu);
9081 +static void dy_free(struct kref *kref)
9083 + struct au_dykey *key;
9084 + struct au_splhead *spl;
9086 + key = container_of(kref, struct au_dykey, dk_kref);
9087 + spl = dynop + key->dk_op.dy_type;
9088 + au_spl_del_rcu(&key->dk_list, spl);
9089 + call_rcu(&key->dk_rcu, dy_free_rcu);
9092 +void au_dy_put(struct au_dykey *key)
9094 + kref_put(&key->dk_kref, dy_free);
9097 +/* ---------------------------------------------------------------------- */
9099 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
9101 +#ifdef CONFIG_AUFS_DEBUG
9102 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
9103 +#define DyDbgInc(cnt) do { cnt++; } while (0)
9105 +#define DyDbgDeclare(cnt) do {} while (0)
9106 +#define DyDbgInc(cnt) do {} while (0)
9109 +#define DySet(func, dst, src, h_op, h_sb) do { \
9111 + if (h_op->func) { \
9113 + dst.func = src.func; \
9115 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
9119 +#define DySetForce(func, dst, src) do { \
9120 + AuDebugOn(!src.func); \
9122 + dst.func = src.func; \
9125 +#define DySetAop(func) \
9126 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
9127 +#define DySetAopForce(func) \
9128 + DySetForce(func, dyaop->da_op, aufs_aop)
9130 +static void dy_aop(struct au_dykey *key, const void *h_op,
9131 + struct super_block *h_sb __maybe_unused)
9133 + struct au_dyaop *dyaop = (void *)key;
9134 + const struct address_space_operations *h_aop = h_op;
9135 + DyDbgDeclare(cnt);
9137 + AuDbg("%s\n", au_sbtype(h_sb));
9139 + DySetAop(writepage);
9140 + DySetAopForce(readpage); /* force */
9141 + DySetAop(writepages);
9142 + DySetAop(set_page_dirty);
9143 + DySetAop(readpages);
9144 + DySetAop(write_begin);
9145 + DySetAop(write_end);
9147 + DySetAop(invalidatepage);
9148 + DySetAop(releasepage);
9149 + DySetAop(freepage);
9150 + /* these two will be changed according to an aufs mount option */
9151 + DySetAop(direct_IO);
9152 + DySetAop(get_xip_mem);
9153 + DySetAop(migratepage);
9154 + DySetAop(launder_page);
9155 + DySetAop(is_partially_uptodate);
9156 + DySetAop(error_remove_page);
9157 + DySetAop(swap_activate);
9158 + DySetAop(swap_deactivate);
9160 + DyDbgSize(cnt, *h_aop);
9161 + dyaop->da_get_xip_mem = h_aop->get_xip_mem;
9164 +/* ---------------------------------------------------------------------- */
9166 +static void dy_bug(struct kref *kref)
9171 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
9173 + struct au_dykey *key, *old;
9174 + struct au_splhead *spl;
9177 + void (*set)(struct au_dykey *key, const void *h_op,
9178 + struct super_block *h_sb __maybe_unused);
9180 + static const struct op a[] = {
9182 + .sz = sizeof(struct au_dyaop),
9186 + const struct op *p;
9188 + spl = dynop + op->dy_type;
9189 + key = dy_gfind_get(spl, op->dy_hop);
9191 + goto out_add; /* success */
9193 + p = a + op->dy_type;
9194 + key = kzalloc(p->sz, GFP_NOFS);
9195 + if (unlikely(!key)) {
9196 + key = ERR_PTR(-ENOMEM);
9200 + key->dk_op.dy_hop = op->dy_hop;
9201 + kref_init(&key->dk_kref);
9202 + p->set(key, op->dy_hop, au_br_sb(br));
9203 + old = dy_gadd(spl, key);
9210 + old = dy_bradd(br, key);
9212 + /* its ref-count should never be zero here */
9213 + kref_put(&key->dk_kref, dy_bug);
9218 +/* ---------------------------------------------------------------------- */
9220 + * Aufs prohibits O_DIRECT by defaut even if the branch supports it.
9221 + * This behaviour is neccessary to return an error from open(O_DIRECT) instead
9222 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
9223 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
9224 + * See the aufs manual in detail.
9226 + * To keep this behaviour, aufs has to set NULL to ->get_xip_mem too, and the
9227 + * performance of fadvise() and madvise() may be affected.
9229 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
9232 + dyaop->da_op.direct_IO = NULL;
9233 + dyaop->da_op.get_xip_mem = NULL;
9235 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
9236 + dyaop->da_op.get_xip_mem = aufs_aop.get_xip_mem;
9237 + if (!dyaop->da_get_xip_mem)
9238 + dyaop->da_op.get_xip_mem = NULL;
9242 +static struct au_dyaop *dy_aget(struct au_branch *br,
9243 + const struct address_space_operations *h_aop,
9246 + struct au_dyaop *dyaop;
9247 + struct au_dynop op;
9249 + op.dy_type = AuDy_AOP;
9250 + op.dy_haop = h_aop;
9251 + dyaop = (void *)dy_get(&op, br);
9252 + if (IS_ERR(dyaop))
9254 + dy_adx(dyaop, do_dx);
9260 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
9261 + struct inode *h_inode)
9264 + struct super_block *sb;
9265 + struct au_branch *br;
9266 + struct au_dyaop *dyaop;
9268 + AuDebugOn(!S_ISREG(h_inode->i_mode));
9269 + IiMustWriteLock(inode);
9272 + br = au_sbr(sb, bindex);
9273 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
9274 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
9275 + err = PTR_ERR(dyaop);
9276 + if (IS_ERR(dyaop))
9277 + /* unnecessary to call dy_fput() */
9281 + inode->i_mapping->a_ops = &dyaop->da_op;
9288 + * Is it safe to replace a_ops during the inode/file is in operation?
9291 +int au_dy_irefresh(struct inode *inode)
9294 + aufs_bindex_t bstart;
9295 + struct inode *h_inode;
9298 + if (S_ISREG(inode->i_mode)) {
9299 + bstart = au_ibstart(inode);
9300 + h_inode = au_h_iptr(inode, bstart);
9301 + err = au_dy_iaop(inode, bstart, h_inode);
9306 +void au_dy_arefresh(int do_dx)
9308 + struct au_splhead *spl;
9309 + struct list_head *head;
9310 + struct au_dykey *key;
9312 + spl = dynop + AuDy_AOP;
9313 + head = &spl->head;
9314 + spin_lock(&spl->spin);
9315 + list_for_each_entry(key, head, dk_list)
9316 + dy_adx((void *)key, do_dx);
9317 + spin_unlock(&spl->spin);
9320 +/* ---------------------------------------------------------------------- */
9322 +void __init au_dy_init(void)
9326 + /* make sure that 'struct au_dykey *' can be any type */
9327 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
9329 + for (i = 0; i < AuDyLast; i++)
9330 + au_spl_init(dynop + i);
9333 +void au_dy_fin(void)
9337 + for (i = 0; i < AuDyLast; i++)
9338 + WARN_ON(!list_empty(&dynop[i].head));
9340 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
9341 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
9342 +++ linux/fs/aufs/dynop.h 2013-07-06 13:20:47.740198107 +0200
9345 + * Copyright (C) 2010-2013 Junjiro R. Okajima
9347 + * This program, aufs is free software; you can redistribute it and/or modify
9348 + * it under the terms of the GNU General Public License as published by
9349 + * the Free Software Foundation; either version 2 of the License, or
9350 + * (at your option) any later version.
9352 + * This program is distributed in the hope that it will be useful,
9353 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9354 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9355 + * GNU General Public License for more details.
9357 + * You should have received a copy of the GNU General Public License
9358 + * along with this program; if not, write to the Free Software
9359 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
9363 + * dynamically customizable operations (for regular files only)
9366 +#ifndef __AUFS_DYNOP_H__
9367 +#define __AUFS_DYNOP_H__
9373 +enum {AuDy_AOP, AuDyLast};
9378 + const void *dy_hop;
9379 + const struct address_space_operations *dy_haop;
9385 + struct list_head dk_list;
9386 + struct rcu_head dk_rcu;
9388 + struct au_dynop dk_op;
9391 + * during I am in the branch local array, kref is gotten. when the
9392 + * branch is removed, kref is put.
9394 + struct kref dk_kref;
9397 +/* stop unioning since their sizes are very different from each other */
9399 + struct au_dykey da_key;
9400 + struct address_space_operations da_op; /* not const */
9401 + int (*da_get_xip_mem)(struct address_space *, pgoff_t, int,
9402 + void **, unsigned long *);
9405 +/* ---------------------------------------------------------------------- */
9409 +void au_dy_put(struct au_dykey *key);
9410 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
9411 + struct inode *h_inode);
9412 +int au_dy_irefresh(struct inode *inode);
9413 +void au_dy_arefresh(int do_dio);
9415 +void __init au_dy_init(void);
9416 +void au_dy_fin(void);
9418 +#endif /* __KERNEL__ */
9419 +#endif /* __AUFS_DYNOP_H__ */
9420 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
9421 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
9422 +++ linux/fs/aufs/export.c 2013-07-30 22:42:55.839613269 +0200
9425 + * Copyright (C) 2005-2013 Junjiro R. Okajima
9427 + * This program, aufs is free software; you can redistribute it and/or modify
9428 + * it under the terms of the GNU General Public License as published by
9429 + * the Free Software Foundation; either version 2 of the License, or
9430 + * (at your option) any later version.
9432 + * This program is distributed in the hope that it will be useful,
9433 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9434 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9435 + * GNU General Public License for more details.
9437 + * You should have received a copy of the GNU General Public License
9438 + * along with this program; if not, write to the Free Software
9439 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
9446 +#include <linux/exportfs.h>
9447 +#include <linux/fs_struct.h>
9448 +#include <linux/namei.h>
9449 +#include <linux/nsproxy.h>
9450 +#include <linux/random.h>
9451 +#include <linux/writeback.h>
9452 +#include "../fs/mount.h"
9456 +#ifdef CONFIG_AUFS_INO_T_64
9464 +static ino_t decode_ino(__u32 *a)
9468 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
9470 +#ifdef CONFIG_AUFS_INO_T_64
9476 +static void encode_ino(__u32 *a, ino_t ino)
9482 +#ifdef CONFIG_AUFS_INO_T_64
9487 +/* NFS file handle */
9491 +#ifdef CONFIG_AUFS_INO_T_64
9492 + /* support 64bit inode number */
9506 + Fh_dir_ino = Fh_dir_ino1
9509 +static int au_test_anon(struct dentry *dentry)
9511 + /* note: read d_flags without d_lock */
9512 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
9515 +int au_test_nfsd(void)
9518 + struct task_struct *tsk = current;
9519 + char comm[sizeof(tsk->comm)];
9522 + if (tsk->flags & PF_KTHREAD) {
9523 + get_task_comm(comm, tsk);
9524 + ret = !strcmp(comm, "nfsd");
9530 +/* ---------------------------------------------------------------------- */
9531 +/* inode generation external table */
9533 +void au_xigen_inc(struct inode *inode)
9538 + struct super_block *sb;
9539 + struct au_sbinfo *sbinfo;
9542 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
9544 + sbinfo = au_sbi(sb);
9545 + pos = inode->i_ino;
9546 + pos *= sizeof(igen);
9547 + igen = inode->i_generation + 1;
9548 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
9549 + sizeof(igen), &pos);
9550 + if (sz == sizeof(igen))
9551 + return; /* success */
9553 + if (unlikely(sz >= 0))
9554 + AuIOErr("xigen error (%zd)\n", sz);
9557 +int au_xigen_new(struct inode *inode)
9562 + struct super_block *sb;
9563 + struct au_sbinfo *sbinfo;
9564 + struct file *file;
9567 + /* todo: dirty, at mount time */
9568 + if (inode->i_ino == AUFS_ROOT_INO)
9571 + SiMustAnyLock(sb);
9572 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
9576 + pos = inode->i_ino;
9577 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
9578 + AuIOErr1("too large i%lld\n", pos);
9581 + pos *= sizeof(inode->i_generation);
9584 + sbinfo = au_sbi(sb);
9585 + file = sbinfo->si_xigen;
9588 + if (vfsub_f_size_read(file)
9589 + < pos + sizeof(inode->i_generation)) {
9590 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
9591 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
9592 + sizeof(inode->i_generation), &pos);
9594 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
9595 + sizeof(inode->i_generation), &pos);
9596 + if (sz == sizeof(inode->i_generation))
9597 + goto out; /* success */
9600 + if (unlikely(sz >= 0)) {
9602 + AuIOErr("xigen error (%zd)\n", sz);
9609 +int au_xigen_set(struct super_block *sb, struct file *base)
9612 + struct au_sbinfo *sbinfo;
9613 + struct file *file;
9615 + SiMustWriteLock(sb);
9617 + sbinfo = au_sbi(sb);
9618 + file = au_xino_create2(base, sbinfo->si_xigen);
9619 + err = PTR_ERR(file);
9623 + if (sbinfo->si_xigen)
9624 + fput(sbinfo->si_xigen);
9625 + sbinfo->si_xigen = file;
9631 +void au_xigen_clr(struct super_block *sb)
9633 + struct au_sbinfo *sbinfo;
9635 + SiMustWriteLock(sb);
9637 + sbinfo = au_sbi(sb);
9638 + if (sbinfo->si_xigen) {
9639 + fput(sbinfo->si_xigen);
9640 + sbinfo->si_xigen = NULL;
9644 +/* ---------------------------------------------------------------------- */
9646 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
9649 + struct dentry *dentry, *d;
9650 + struct inode *inode;
9651 + unsigned int sigen;
9654 + inode = ilookup(sb, ino);
9658 + dentry = ERR_PTR(-ESTALE);
9659 + sigen = au_sigen(sb);
9660 + if (unlikely(is_bad_inode(inode)
9661 + || IS_DEADDIR(inode)
9662 + || sigen != au_iigen(inode, NULL)))
9666 + if (!dir_ino || S_ISDIR(inode->i_mode))
9667 + dentry = d_find_alias(inode);
9669 + spin_lock(&inode->i_lock);
9670 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
9671 + spin_lock(&d->d_lock);
9672 + if (!au_test_anon(d)
9673 + && d->d_parent->d_inode->i_ino == dir_ino) {
9674 + dentry = dget_dlock(d);
9675 + spin_unlock(&d->d_lock);
9678 + spin_unlock(&d->d_lock);
9680 + spin_unlock(&inode->i_lock);
9682 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
9683 + /* need to refresh */
9691 + AuTraceErrPtr(dentry);
9695 +/* ---------------------------------------------------------------------- */
9698 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
9700 +struct au_compare_mnt_args {
9702 + struct super_block *sb;
9705 + struct vfsmount *mnt;
9708 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
9710 + struct au_compare_mnt_args *a = arg;
9712 + if (mnt->mnt_sb != a->sb)
9714 + a->mnt = mntget(mnt);
9718 +static struct vfsmount *au_mnt_get(struct super_block *sb)
9722 + struct au_compare_mnt_args args = {
9726 + get_fs_root(current->fs, &root);
9728 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
9729 + rcu_read_unlock();
9732 + AuDebugOn(!args.mnt);
9736 +struct au_nfsd_si_lock {
9737 + unsigned int sigen;
9738 + aufs_bindex_t bindex, br_id;
9739 + unsigned char force_lock;
9742 +static int si_nfsd_read_lock(struct super_block *sb,
9743 + struct au_nfsd_si_lock *nsi_lock)
9746 + aufs_bindex_t bindex;
9748 + si_read_lock(sb, AuLock_FLUSH);
9750 + /* branch id may be wrapped around */
9752 + bindex = au_br_index(sb, nsi_lock->br_id);
9753 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
9754 + goto out; /* success */
9758 + if (!nsi_lock->force_lock)
9759 + si_read_unlock(sb);
9762 + nsi_lock->bindex = bindex;
9766 +struct find_name_by_ino {
9767 + int called, found;
9774 +find_name_by_ino(void *arg, const char *name, int namelen, loff_t offset,
9775 + u64 ino, unsigned int d_type)
9777 + struct find_name_by_ino *a = arg;
9780 + if (a->ino != ino)
9783 + memcpy(a->name, name, namelen);
9784 + a->namelen = namelen;
9789 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
9790 + struct au_nfsd_si_lock *nsi_lock)
9792 + struct dentry *dentry, *parent;
9793 + struct file *file;
9794 + struct inode *dir;
9795 + struct find_name_by_ino arg;
9798 + parent = path->dentry;
9800 + si_read_unlock(parent->d_sb);
9801 + file = vfsub_dentry_open(path, au_dir_roflags);
9802 + dentry = (void *)file;
9806 + dentry = ERR_PTR(-ENOMEM);
9807 + arg.name = (void *)__get_free_page(GFP_NOFS);
9808 + if (unlikely(!arg.name))
9815 + err = vfsub_readdir(file, find_name_by_ino, &arg);
9816 + } while (!err && !arg.found && arg.called);
9817 + dentry = ERR_PTR(err);
9818 + if (unlikely(err))
9820 + /* instead of ENOENT */
9821 + dentry = ERR_PTR(-ESTALE);
9825 + /* do not call vfsub_lkup_one() */
9826 + dir = parent->d_inode;
9827 + mutex_lock(&dir->i_mutex);
9828 + dentry = vfsub_lookup_one_len(arg.name, parent, arg.namelen);
9829 + mutex_unlock(&dir->i_mutex);
9830 + AuTraceErrPtr(dentry);
9831 + if (IS_ERR(dentry))
9833 + AuDebugOn(au_test_anon(dentry));
9834 + if (unlikely(!dentry->d_inode)) {
9836 + dentry = ERR_PTR(-ENOENT);
9840 + free_page((unsigned long)arg.name);
9844 + if (unlikely(nsi_lock
9845 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
9846 + if (!IS_ERR(dentry)) {
9848 + dentry = ERR_PTR(-ESTALE);
9850 + AuTraceErrPtr(dentry);
9854 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
9856 + struct au_nfsd_si_lock *nsi_lock)
9858 + struct dentry *dentry;
9861 + if (dir_ino != AUFS_ROOT_INO) {
9862 + path.dentry = decode_by_ino(sb, dir_ino, 0);
9863 + dentry = path.dentry;
9864 + if (!path.dentry || IS_ERR(path.dentry))
9866 + AuDebugOn(au_test_anon(path.dentry));
9868 + path.dentry = dget(sb->s_root);
9870 + path.mnt = au_mnt_get(sb);
9871 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
9875 + AuTraceErrPtr(dentry);
9879 +/* ---------------------------------------------------------------------- */
9881 +static int h_acceptable(void *expv, struct dentry *dentry)
9886 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
9887 + char *buf, int len, struct super_block *sb)
9893 + p = d_path(h_rootpath, buf, len);
9898 + path.mnt = h_rootpath->mnt;
9899 + path.dentry = h_parent;
9900 + p = d_path(&path, buf, len);
9906 + path.mnt = au_mnt_get(sb);
9907 + path.dentry = sb->s_root;
9908 + p = d_path(&path, buf, len - strlen(p));
9913 + p[strlen(p)] = '/';
9921 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
9922 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
9924 + struct dentry *dentry, *h_parent, *root;
9925 + struct super_block *h_sb;
9926 + char *pathname, *p;
9927 + struct vfsmount *h_mnt;
9928 + struct au_branch *br;
9932 + br = au_sbr(sb, nsi_lock->bindex);
9933 + h_mnt = au_br_mnt(br);
9934 + h_sb = h_mnt->mnt_sb;
9935 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
9936 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
9937 + fh_len - Fh_tail, fh[Fh_h_type],
9938 + h_acceptable, /*context*/NULL);
9939 + dentry = h_parent;
9940 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
9941 + AuWarn1("%s decode_fh failed, %ld\n",
9942 + au_sbtype(h_sb), PTR_ERR(h_parent));
9946 + if (unlikely(au_test_anon(h_parent))) {
9947 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
9949 + goto out_h_parent;
9952 + dentry = ERR_PTR(-ENOMEM);
9953 + pathname = (void *)__get_free_page(GFP_NOFS);
9954 + if (unlikely(!pathname))
9955 + goto out_h_parent;
9957 + root = sb->s_root;
9959 + di_read_lock_parent(root, !AuLock_IR);
9960 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
9961 + di_read_unlock(root, !AuLock_IR);
9962 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
9963 + dentry = (void *)p;
9965 + goto out_pathname;
9967 + si_read_unlock(sb);
9968 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
9969 + dentry = ERR_PTR(err);
9970 + if (unlikely(err))
9973 + dentry = ERR_PTR(-ENOENT);
9974 + AuDebugOn(au_test_anon(path.dentry));
9975 + if (unlikely(!path.dentry->d_inode))
9978 + if (ino != path.dentry->d_inode->i_ino)
9979 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
9981 + dentry = dget(path.dentry);
9986 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
9987 + if (!IS_ERR(dentry)) {
9989 + dentry = ERR_PTR(-ESTALE);
9992 + free_page((unsigned long)pathname);
9996 + AuTraceErrPtr(dentry);
10000 +/* ---------------------------------------------------------------------- */
10002 +static struct dentry *
10003 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
10006 + struct dentry *dentry;
10007 + __u32 *fh = fid->raw;
10008 + struct au_branch *br;
10009 + ino_t ino, dir_ino;
10010 + struct au_nfsd_si_lock nsi_lock = {
10014 + dentry = ERR_PTR(-ESTALE);
10015 + /* it should never happen, but the file handle is unreliable */
10016 + if (unlikely(fh_len < Fh_tail))
10018 + nsi_lock.sigen = fh[Fh_sigen];
10019 + nsi_lock.br_id = fh[Fh_br_id];
10021 + /* branch id may be wrapped around */
10023 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
10025 + nsi_lock.force_lock = 1;
10027 + /* is this inode still cached? */
10028 + ino = decode_ino(fh + Fh_ino);
10029 + /* it should never happen */
10030 + if (unlikely(ino == AUFS_ROOT_INO))
10033 + dir_ino = decode_ino(fh + Fh_dir_ino);
10034 + dentry = decode_by_ino(sb, ino, dir_ino);
10035 + if (IS_ERR(dentry))
10040 + /* is the parent dir cached? */
10041 + br = au_sbr(sb, nsi_lock.bindex);
10042 + atomic_inc(&br->br_count);
10043 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
10044 + if (IS_ERR(dentry))
10049 + /* lookup path */
10050 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
10051 + if (IS_ERR(dentry))
10053 + if (unlikely(!dentry))
10054 + /* todo?: make it ESTALE */
10058 + if (!au_digen_test(dentry, au_sigen(sb))
10059 + && dentry->d_inode->i_generation == fh[Fh_igen])
10060 + goto out_unlock; /* success */
10063 + dentry = ERR_PTR(-ESTALE);
10066 + atomic_dec(&br->br_count);
10067 + si_read_unlock(sb);
10069 + AuTraceErrPtr(dentry);
10073 +#if 0 /* reserved for future use */
10074 +/* support subtreecheck option */
10075 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
10076 + int fh_len, int fh_type)
10078 + struct dentry *parent;
10079 + __u32 *fh = fid->raw;
10082 + dir_ino = decode_ino(fh + Fh_dir_ino);
10083 + parent = decode_by_ino(sb, dir_ino, 0);
10084 + if (IS_ERR(parent))
10087 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
10088 + dir_ino, fh, fh_len);
10091 + AuTraceErrPtr(parent);
10096 +/* ---------------------------------------------------------------------- */
10098 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
10099 + struct inode *dir)
10102 + aufs_bindex_t bindex;
10103 + struct super_block *sb, *h_sb;
10104 + struct dentry *dentry, *parent, *h_parent;
10105 + struct inode *h_dir;
10106 + struct au_branch *br;
10109 + if (unlikely(*max_len <= Fh_tail)) {
10110 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
10114 + err = FILEID_ROOT;
10115 + if (inode->i_ino == AUFS_ROOT_INO) {
10116 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
10121 + sb = inode->i_sb;
10122 + err = si_read_lock(sb, AuLock_FLUSH);
10123 + if (unlikely(err))
10126 +#ifdef CONFIG_AUFS_DEBUG
10127 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
10128 + AuWarn1("NFS-exporting requires xino\n");
10132 + ii_read_lock_child(inode);
10133 + bindex = au_ibstart(inode);
10135 + dentry = d_find_alias(inode);
10136 + if (unlikely(!dentry))
10138 + AuDebugOn(au_test_anon(dentry));
10139 + parent = dget_parent(dentry);
10141 + if (unlikely(!parent))
10143 + dir = parent->d_inode;
10146 + ii_read_lock_parent(dir);
10147 + h_dir = au_h_iptr(dir, bindex);
10148 + ii_read_unlock(dir);
10149 + if (unlikely(!h_dir))
10151 + h_parent = d_find_alias(h_dir);
10152 + if (unlikely(!h_parent))
10153 + goto out_hparent;
10156 + br = au_sbr(sb, bindex);
10157 + h_sb = au_br_sb(br);
10158 + if (unlikely(!h_sb->s_export_op)) {
10159 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
10160 + goto out_hparent;
10163 + fh[Fh_br_id] = br->br_id;
10164 + fh[Fh_sigen] = au_sigen(sb);
10165 + encode_ino(fh + Fh_ino, inode->i_ino);
10166 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
10167 + fh[Fh_igen] = inode->i_generation;
10169 + *max_len -= Fh_tail;
10170 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
10172 + /*connectable or subtreecheck*/0);
10173 + err = fh[Fh_h_type];
10174 + *max_len += Fh_tail;
10175 + /* todo: macros? */
10176 + if (err != FILEID_INVALID)
10179 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
10186 + ii_read_unlock(inode);
10187 + si_read_unlock(sb);
10189 + if (unlikely(err < 0))
10190 + err = FILEID_INVALID;
10194 +/* ---------------------------------------------------------------------- */
10196 +static int aufs_commit_metadata(struct inode *inode)
10199 + aufs_bindex_t bindex;
10200 + struct super_block *sb;
10201 + struct inode *h_inode;
10202 + int (*f)(struct inode *inode);
10204 + sb = inode->i_sb;
10205 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
10206 + ii_write_lock_child(inode);
10207 + bindex = au_ibstart(inode);
10208 + AuDebugOn(bindex < 0);
10209 + h_inode = au_h_iptr(inode, bindex);
10211 + f = h_inode->i_sb->s_export_op->commit_metadata;
10213 + err = f(h_inode);
10215 + struct writeback_control wbc = {
10216 + .sync_mode = WB_SYNC_ALL,
10217 + .nr_to_write = 0 /* metadata only */
10220 + err = sync_inode(h_inode, &wbc);
10223 + au_cpup_attr_timesizes(inode);
10224 + ii_write_unlock(inode);
10225 + si_read_unlock(sb);
10229 +/* ---------------------------------------------------------------------- */
10231 +static struct export_operations aufs_export_op = {
10232 + .fh_to_dentry = aufs_fh_to_dentry,
10233 + /* .fh_to_parent = aufs_fh_to_parent, */
10234 + .encode_fh = aufs_encode_fh,
10235 + .commit_metadata = aufs_commit_metadata
10238 +void au_export_init(struct super_block *sb)
10240 + struct au_sbinfo *sbinfo;
10243 + sb->s_export_op = &aufs_export_op;
10244 + sbinfo = au_sbi(sb);
10245 + sbinfo->si_xigen = NULL;
10246 + get_random_bytes(&u, sizeof(u));
10247 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
10248 + atomic_set(&sbinfo->si_xigen_next, u);
10250 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
10251 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
10252 +++ linux/fs/aufs/file.c 2013-08-23 23:59:39.634916914 +0200
10255 + * Copyright (C) 2005-2013 Junjiro R. Okajima
10257 + * This program, aufs is free software; you can redistribute it and/or modify
10258 + * it under the terms of the GNU General Public License as published by
10259 + * the Free Software Foundation; either version 2 of the License, or
10260 + * (at your option) any later version.
10262 + * This program is distributed in the hope that it will be useful,
10263 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10264 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10265 + * GNU General Public License for more details.
10267 + * You should have received a copy of the GNU General Public License
10268 + * along with this program; if not, write to the Free Software
10269 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
10273 + * handling file/dir, and address_space operation
10276 +#ifdef CONFIG_AUFS_DEBUG
10277 +#include <linux/migrate.h>
10279 +#include <linux/pagemap.h>
10282 +/* drop flags for writing */
10283 +unsigned int au_file_roflags(unsigned int flags)
10285 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
10286 + flags |= O_RDONLY | O_NOATIME;
10290 +/* common functions to regular file and dir */
10291 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
10292 + struct file *file)
10294 + struct file *h_file;
10295 + struct dentry *h_dentry;
10296 + struct inode *h_inode;
10297 + struct super_block *sb;
10298 + struct au_branch *br;
10299 + struct path h_path;
10300 + int err, exec_flag;
10302 + /* a race condition can happen between open and unlink/rmdir */
10303 + h_file = ERR_PTR(-ENOENT);
10304 + h_dentry = au_h_dptr(dentry, bindex);
10305 + if (au_test_nfsd() && !h_dentry)
10307 + h_inode = h_dentry->d_inode;
10308 + if (au_test_nfsd() && !h_inode)
10310 + spin_lock(&h_dentry->d_lock);
10311 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
10313 + /* || !dentry->d_inode->i_nlink */
10315 + spin_unlock(&h_dentry->d_lock);
10316 + if (unlikely(err))
10319 + sb = dentry->d_sb;
10320 + br = au_sbr(sb, bindex);
10321 + h_file = ERR_PTR(-EACCES);
10322 + exec_flag = flags & __FMODE_EXEC;
10323 + if (exec_flag && (au_br_mnt(br)->mnt_flags & MNT_NOEXEC))
10326 + /* drop flags for writing */
10327 + if (au_test_ro(sb, bindex, dentry->d_inode))
10328 + flags = au_file_roflags(flags);
10329 + flags &= ~O_CREAT;
10330 + atomic_inc(&br->br_count);
10331 + h_path.dentry = h_dentry;
10332 + h_path.mnt = au_br_mnt(br);
10333 + if (!au_special_file(h_inode->i_mode))
10334 + h_file = vfsub_dentry_open(&h_path, flags);
10336 + /* this block depends upon the configuration */
10337 + di_read_unlock(dentry, AuLock_IR);
10338 + fi_write_unlock(file);
10339 + si_read_unlock(sb);
10340 + h_file = vfsub_dentry_open(&h_path, flags);
10341 + si_noflush_read_lock(sb);
10342 + fi_write_lock(file);
10343 + di_read_lock_child(dentry, AuLock_IR);
10345 + if (IS_ERR(h_file))
10349 + err = deny_write_access(h_file);
10350 + if (unlikely(err)) {
10352 + h_file = ERR_PTR(err);
10356 + fsnotify_open(h_file);
10357 + goto out; /* success */
10360 + atomic_dec(&br->br_count);
10365 +int au_do_open(struct file *file, int (*open)(struct file *file, int flags),
10366 + struct au_fidir *fidir)
10369 + struct dentry *dentry;
10371 + err = au_finfo_init(file, fidir);
10372 + if (unlikely(err))
10375 + dentry = file->f_dentry;
10376 + di_read_lock_child(dentry, AuLock_IR);
10377 + err = open(file, vfsub_file_flags(file));
10378 + di_read_unlock(dentry, AuLock_IR);
10380 + fi_write_unlock(file);
10381 + if (unlikely(err)) {
10382 + au_fi(file)->fi_hdir = NULL;
10383 + au_finfo_fin(file);
10390 +int au_reopen_nondir(struct file *file)
10393 + aufs_bindex_t bstart;
10394 + struct dentry *dentry;
10395 + struct file *h_file, *h_file_tmp;
10397 + dentry = file->f_dentry;
10398 + AuDebugOn(au_special_file(dentry->d_inode->i_mode));
10399 + bstart = au_dbstart(dentry);
10400 + h_file_tmp = NULL;
10401 + if (au_fbstart(file) == bstart) {
10402 + h_file = au_hf_top(file);
10403 + if (file->f_mode == h_file->f_mode)
10404 + return 0; /* success */
10405 + h_file_tmp = h_file;
10406 + get_file(h_file_tmp);
10407 + au_set_h_fptr(file, bstart, NULL);
10409 + AuDebugOn(au_fi(file)->fi_hdir);
10412 + * file exists on both of rw and ro
10413 + * open --> dbstart and fbstart are both 0
10414 + * prepend a branch as rw, "rw" become ro
10416 + * delete the top branch, "rw" becomes rw again
10417 + * --> dbstart is 1, fbstart is still 0
10418 + * write --> fbstart is 0 but dbstart is 1
10420 + /* AuDebugOn(au_fbstart(file) < bstart); */
10422 + h_file = au_h_open(dentry, bstart, vfsub_file_flags(file) & ~O_TRUNC,
10424 + err = PTR_ERR(h_file);
10425 + if (IS_ERR(h_file)) {
10426 + if (h_file_tmp) {
10427 + atomic_inc(&au_sbr(dentry->d_sb, bstart)->br_count);
10428 + au_set_h_fptr(file, bstart, h_file_tmp);
10429 + h_file_tmp = NULL;
10431 + goto out; /* todo: close all? */
10435 + au_set_fbstart(file, bstart);
10436 + au_set_h_fptr(file, bstart, h_file);
10437 + au_update_figen(file);
10438 + /* todo: necessary? */
10439 + /* file->f_ra = h_file->f_ra; */
10443 + fput(h_file_tmp);
10447 +/* ---------------------------------------------------------------------- */
10449 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
10450 + struct dentry *hi_wh)
10453 + aufs_bindex_t bstart;
10454 + struct au_dinfo *dinfo;
10455 + struct dentry *h_dentry;
10456 + struct au_hdentry *hdp;
10458 + dinfo = au_di(file->f_dentry);
10459 + AuRwMustWriteLock(&dinfo->di_rwsem);
10461 + bstart = dinfo->di_bstart;
10462 + dinfo->di_bstart = btgt;
10463 + hdp = dinfo->di_hdentry;
10464 + h_dentry = hdp[0 + btgt].hd_dentry;
10465 + hdp[0 + btgt].hd_dentry = hi_wh;
10466 + err = au_reopen_nondir(file);
10467 + hdp[0 + btgt].hd_dentry = h_dentry;
10468 + dinfo->di_bstart = bstart;
10473 +static int au_ready_to_write_wh(struct file *file, loff_t len,
10474 + aufs_bindex_t bcpup, struct au_pin *pin)
10477 + struct inode *inode, *h_inode;
10478 + struct dentry *h_dentry, *hi_wh;
10479 + struct au_cp_generic cpg = {
10480 + .dentry = file->f_dentry,
10487 + au_update_dbstart(cpg.dentry);
10488 + inode = cpg.dentry->d_inode;
10490 + if (au_dbstart(cpg.dentry) <= bcpup
10491 + && au_dbend(cpg.dentry) >= bcpup) {
10492 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
10494 + h_inode = h_dentry->d_inode;
10496 + hi_wh = au_hi_wh(inode, bcpup);
10497 + if (!hi_wh && !h_inode)
10498 + err = au_sio_cpup_wh(&cpg, file);
10500 + /* already copied-up after unlink */
10501 + err = au_reopen_wh(file, bcpup, hi_wh);
10504 + && inode->i_nlink > 1
10505 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
10506 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
10512 + * prepare the @file for writing.
10514 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
10517 + aufs_bindex_t dbstart;
10518 + struct dentry *parent, *h_dentry;
10519 + struct inode *inode;
10520 + struct super_block *sb;
10521 + struct file *h_file;
10522 + struct au_cp_generic cpg = {
10523 + .dentry = file->f_dentry,
10528 + .flags = AuCpup_DTIME
10531 + sb = cpg.dentry->d_sb;
10532 + inode = cpg.dentry->d_inode;
10533 + AuDebugOn(au_special_file(inode->i_mode));
10534 + cpg.bsrc = au_fbstart(file);
10535 + err = au_test_ro(sb, cpg.bsrc, inode);
10536 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
10537 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
10542 + /* need to cpup or reopen */
10543 + parent = dget_parent(cpg.dentry);
10544 + di_write_lock_parent(parent);
10545 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
10547 + if (unlikely(err < 0))
10551 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
10552 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
10553 + if (unlikely(err))
10557 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
10558 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
10559 + if (unlikely(err))
10562 + h_dentry = au_hf_top(file)->f_dentry;
10563 + dbstart = au_dbstart(cpg.dentry);
10564 + if (dbstart <= cpg.bdst) {
10565 + h_dentry = au_h_dptr(cpg.dentry, cpg.bdst);
10566 + AuDebugOn(!h_dentry);
10567 + cpg.bsrc = cpg.bdst;
10570 + if (dbstart <= cpg.bdst /* just reopen */
10571 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
10573 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc);
10574 + if (IS_ERR(h_file))
10575 + err = PTR_ERR(h_file);
10577 + di_downgrade_lock(parent, AuLock_IR);
10578 + if (dbstart > cpg.bdst)
10579 + err = au_sio_cpup_simple(&cpg);
10581 + err = au_reopen_nondir(file);
10582 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
10584 + } else { /* copyup as wh and reopen */
10586 + * since writable hfsplus branch is not supported,
10587 + * h_open_pre/post() are unnecessary.
10589 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
10590 + di_downgrade_lock(parent, AuLock_IR);
10594 + au_pin_set_parent_lflag(pin, /*lflag*/0);
10595 + goto out_dput; /* success */
10601 + di_downgrade_lock(parent, AuLock_IR);
10603 + di_read_unlock(parent, AuLock_IR);
10610 +/* ---------------------------------------------------------------------- */
10612 +int au_do_flush(struct file *file, fl_owner_t id,
10613 + int (*flush)(struct file *file, fl_owner_t id))
10616 + struct super_block *sb;
10617 + struct inode *inode;
10619 + inode = file_inode(file);
10620 + sb = inode->i_sb;
10621 + si_noflush_read_lock(sb);
10622 + fi_read_lock(file);
10623 + ii_read_lock_child(inode);
10625 + err = flush(file, id);
10626 + au_cpup_attr_timesizes(inode);
10628 + ii_read_unlock(inode);
10629 + fi_read_unlock(file);
10630 + si_read_unlock(sb);
10634 +/* ---------------------------------------------------------------------- */
10636 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
10639 + struct au_pin pin;
10640 + struct au_finfo *finfo;
10641 + struct dentry *parent, *hi_wh;
10642 + struct inode *inode;
10643 + struct super_block *sb;
10644 + struct au_cp_generic cpg = {
10645 + .dentry = file->f_dentry,
10650 + .flags = AuCpup_DTIME
10653 + FiMustWriteLock(file);
10656 + finfo = au_fi(file);
10657 + sb = cpg.dentry->d_sb;
10658 + inode = cpg.dentry->d_inode;
10659 + cpg.bdst = au_ibstart(inode);
10660 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
10663 + parent = dget_parent(cpg.dentry);
10664 + if (au_test_ro(sb, cpg.bdst, inode)) {
10665 + di_read_lock_parent(parent, !AuLock_IR);
10666 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
10668 + di_read_unlock(parent, !AuLock_IR);
10669 + if (unlikely(err < 0))
10674 + di_read_lock_parent(parent, AuLock_IR);
10675 + hi_wh = au_hi_wh(inode, cpg.bdst);
10676 + if (!S_ISDIR(inode->i_mode)
10677 + && au_opt_test(au_mntflags(sb), PLINK)
10678 + && au_plink_test(inode)
10679 + && !d_unhashed(cpg.dentry)
10680 + && cpg.bdst < au_dbstart(cpg.dentry)) {
10681 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
10682 + if (unlikely(err))
10685 + /* always superio. */
10686 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
10687 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
10689 + err = au_sio_cpup_simple(&cpg);
10692 + } else if (hi_wh) {
10693 + /* already copied-up after unlink */
10694 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
10695 + *need_reopen = 0;
10699 + di_read_unlock(parent, AuLock_IR);
10706 +static void au_do_refresh_dir(struct file *file)
10708 + aufs_bindex_t bindex, bend, new_bindex, brid;
10709 + struct au_hfile *p, tmp, *q;
10710 + struct au_finfo *finfo;
10711 + struct super_block *sb;
10712 + struct au_fidir *fidir;
10714 + FiMustWriteLock(file);
10716 + sb = file->f_dentry->d_sb;
10717 + finfo = au_fi(file);
10718 + fidir = finfo->fi_hdir;
10719 + AuDebugOn(!fidir);
10720 + p = fidir->fd_hfile + finfo->fi_btop;
10721 + brid = p->hf_br->br_id;
10722 + bend = fidir->fd_bbot;
10723 + for (bindex = finfo->fi_btop; bindex <= bend; bindex++, p++) {
10727 + new_bindex = au_br_index(sb, p->hf_br->br_id);
10728 + if (new_bindex == bindex)
10730 + if (new_bindex < 0) {
10731 + au_set_h_fptr(file, bindex, NULL);
10735 + /* swap two lower inode, and loop again */
10736 + q = fidir->fd_hfile + new_bindex;
10740 + if (tmp.hf_file) {
10746 + p = fidir->fd_hfile;
10747 + if (!au_test_mmapped(file) && !d_unlinked(file->f_dentry)) {
10748 + bend = au_sbend(sb);
10749 + for (finfo->fi_btop = 0; finfo->fi_btop <= bend;
10750 + finfo->fi_btop++, p++)
10751 + if (p->hf_file) {
10752 + if (file_inode(p->hf_file))
10755 + au_hfput(p, file);
10758 + bend = au_br_index(sb, brid);
10759 + for (finfo->fi_btop = 0; finfo->fi_btop < bend;
10760 + finfo->fi_btop++, p++)
10762 + au_hfput(p, file);
10763 + bend = au_sbend(sb);
10766 + p = fidir->fd_hfile + bend;
10767 + for (fidir->fd_bbot = bend; fidir->fd_bbot >= finfo->fi_btop;
10768 + fidir->fd_bbot--, p--)
10769 + if (p->hf_file) {
10770 + if (file_inode(p->hf_file))
10773 + au_hfput(p, file);
10775 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
10779 + * after branch manipulating, refresh the file.
10781 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
10783 + int err, need_reopen;
10784 + aufs_bindex_t bend, bindex;
10785 + struct dentry *dentry;
10786 + struct au_finfo *finfo;
10787 + struct au_hfile *hfile;
10789 + dentry = file->f_dentry;
10790 + finfo = au_fi(file);
10791 + if (!finfo->fi_hdir) {
10792 + hfile = &finfo->fi_htop;
10793 + AuDebugOn(!hfile->hf_file);
10794 + bindex = au_br_index(dentry->d_sb, hfile->hf_br->br_id);
10795 + AuDebugOn(bindex < 0);
10796 + if (bindex != finfo->fi_btop)
10797 + au_set_fbstart(file, bindex);
10799 + err = au_fidir_realloc(finfo, au_sbend(dentry->d_sb) + 1);
10800 + if (unlikely(err))
10802 + au_do_refresh_dir(file);
10807 + if (!au_test_mmapped(file))
10808 + err = au_file_refresh_by_inode(file, &need_reopen);
10809 + if (!err && need_reopen && !d_unlinked(dentry))
10810 + err = reopen(file);
10812 + au_update_figen(file);
10813 + goto out; /* success */
10816 + /* error, close all lower files */
10817 + if (finfo->fi_hdir) {
10818 + bend = au_fbend_dir(file);
10819 + for (bindex = au_fbstart(file); bindex <= bend; bindex++)
10820 + au_set_h_fptr(file, bindex, NULL);
10827 +/* common function to regular file and dir */
10828 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
10832 + unsigned int sigen, figen;
10833 + aufs_bindex_t bstart;
10834 + unsigned char pseudo_link;
10835 + struct dentry *dentry;
10836 + struct inode *inode;
10839 + dentry = file->f_dentry;
10840 + inode = dentry->d_inode;
10841 + AuDebugOn(au_special_file(inode->i_mode));
10842 + sigen = au_sigen(dentry->d_sb);
10843 + fi_write_lock(file);
10844 + figen = au_figen(file);
10845 + di_write_lock_child(dentry);
10846 + bstart = au_dbstart(dentry);
10847 + pseudo_link = (bstart != au_ibstart(inode));
10848 + if (sigen == figen && !pseudo_link && au_fbstart(file) == bstart) {
10850 + di_downgrade_lock(dentry, AuLock_IR);
10851 + fi_downgrade_lock(file);
10853 + goto out; /* success */
10856 + AuDbg("sigen %d, figen %d\n", sigen, figen);
10857 + if (au_digen_test(dentry, sigen)) {
10858 + err = au_reval_dpath(dentry, sigen);
10859 + AuDebugOn(!err && au_digen_test(dentry, sigen));
10863 + err = refresh_file(file, reopen);
10866 + di_downgrade_lock(dentry, AuLock_IR);
10867 + fi_downgrade_lock(file);
10870 + di_write_unlock(dentry);
10871 + fi_write_unlock(file);
10878 +/* ---------------------------------------------------------------------- */
10880 +/* cf. aufs_nopage() */
10881 +/* for madvise(2) */
10882 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
10884 + unlock_page(page);
10888 +/* it will never be called, but necessary to support O_DIRECT */
10889 +static ssize_t aufs_direct_IO(int rw, struct kiocb *iocb,
10890 + const struct iovec *iov, loff_t offset,
10891 + unsigned long nr_segs)
10892 +{ BUG(); return 0; }
10895 + * it will never be called, but madvise and fadvise behaves differently
10896 + * when get_xip_mem is defined
10898 +static int aufs_get_xip_mem(struct address_space *mapping, pgoff_t pgoff,
10899 + int create, void **kmem, unsigned long *pfn)
10900 +{ BUG(); return 0; }
10902 +/* they will never be called. */
10903 +#ifdef CONFIG_AUFS_DEBUG
10904 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
10905 + loff_t pos, unsigned len, unsigned flags,
10906 + struct page **pagep, void **fsdata)
10907 +{ AuUnsupport(); return 0; }
10908 +static int aufs_write_end(struct file *file, struct address_space *mapping,
10909 + loff_t pos, unsigned len, unsigned copied,
10910 + struct page *page, void *fsdata)
10911 +{ AuUnsupport(); return 0; }
10912 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
10913 +{ AuUnsupport(); return 0; }
10915 +static int aufs_set_page_dirty(struct page *page)
10916 +{ AuUnsupport(); return 0; }
10917 +static void aufs_invalidatepage(struct page *page, unsigned long offset)
10918 +{ AuUnsupport(); }
10919 +static int aufs_releasepage(struct page *page, gfp_t gfp)
10920 +{ AuUnsupport(); return 0; }
10921 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
10922 + struct page *page, enum migrate_mode mode)
10923 +{ AuUnsupport(); return 0; }
10924 +static int aufs_launder_page(struct page *page)
10925 +{ AuUnsupport(); return 0; }
10926 +static int aufs_is_partially_uptodate(struct page *page,
10927 + read_descriptor_t *desc,
10928 + unsigned long from)
10929 +{ AuUnsupport(); return 0; }
10930 +static int aufs_error_remove_page(struct address_space *mapping,
10931 + struct page *page)
10932 +{ AuUnsupport(); return 0; }
10933 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
10935 +{ AuUnsupport(); return 0; }
10936 +static void aufs_swap_deactivate(struct file *file)
10937 +{ AuUnsupport(); }
10938 +#endif /* CONFIG_AUFS_DEBUG */
10940 +const struct address_space_operations aufs_aop = {
10941 + .readpage = aufs_readpage,
10942 + .direct_IO = aufs_direct_IO,
10943 + .get_xip_mem = aufs_get_xip_mem,
10944 +#ifdef CONFIG_AUFS_DEBUG
10945 + .writepage = aufs_writepage,
10946 + /* no writepages, because of writepage */
10947 + .set_page_dirty = aufs_set_page_dirty,
10948 + /* no readpages, because of readpage */
10949 + .write_begin = aufs_write_begin,
10950 + .write_end = aufs_write_end,
10951 + /* no bmap, no block device */
10952 + .invalidatepage = aufs_invalidatepage,
10953 + .releasepage = aufs_releasepage,
10954 + .migratepage = aufs_migratepage,
10955 + .launder_page = aufs_launder_page,
10956 + .is_partially_uptodate = aufs_is_partially_uptodate,
10957 + .error_remove_page = aufs_error_remove_page,
10958 + .swap_activate = aufs_swap_activate,
10959 + .swap_deactivate = aufs_swap_deactivate
10960 +#endif /* CONFIG_AUFS_DEBUG */
10962 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
10963 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
10964 +++ linux/fs/aufs/file.h 2013-08-23 23:59:39.634916914 +0200
10967 + * Copyright (C) 2005-2013 Junjiro R. Okajima
10969 + * This program, aufs is free software; you can redistribute it and/or modify
10970 + * it under the terms of the GNU General Public License as published by
10971 + * the Free Software Foundation; either version 2 of the License, or
10972 + * (at your option) any later version.
10974 + * This program is distributed in the hope that it will be useful,
10975 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10976 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10977 + * GNU General Public License for more details.
10979 + * You should have received a copy of the GNU General Public License
10980 + * along with this program; if not, write to the Free Software
10981 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
10985 + * file operations
10988 +#ifndef __AUFS_FILE_H__
10989 +#define __AUFS_FILE_H__
10993 +#include <linux/file.h>
10994 +#include <linux/fs.h>
10995 +#include <linux/poll.h>
10996 +#include "rwsem.h"
11000 + struct file *hf_file;
11001 + struct au_branch *hf_br;
11006 + aufs_bindex_t fd_bbot;
11007 + aufs_bindex_t fd_nent;
11008 + struct au_vdir *fd_vdir_cache;
11009 + struct au_hfile fd_hfile[];
11012 +static inline int au_fidir_sz(int nent)
11014 + AuDebugOn(nent < 0);
11015 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
11019 + atomic_t fi_generation;
11021 + struct au_rwsem fi_rwsem;
11022 + aufs_bindex_t fi_btop;
11024 + /* do not union them */
11025 + struct { /* for non-dir */
11026 + struct au_hfile fi_htop;
11027 + atomic_t fi_mmapped;
11029 + struct au_fidir *fi_hdir; /* for dir only */
11031 + struct hlist_node fi_hlist;
11032 + struct file *fi_file; /* very ugly */
11033 +} ____cacheline_aligned_in_smp;
11035 +/* ---------------------------------------------------------------------- */
11038 +extern const struct address_space_operations aufs_aop;
11039 +unsigned int au_file_roflags(unsigned int flags);
11040 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
11041 + struct file *file);
11042 +int au_do_open(struct file *file, int (*open)(struct file *file, int flags),
11043 + struct au_fidir *fidir);
11044 +int au_reopen_nondir(struct file *file);
11046 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
11047 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
11049 +int au_do_flush(struct file *file, fl_owner_t id,
11050 + int (*flush)(struct file *file, fl_owner_t id));
11053 +#ifdef CONFIG_AUFS_POLL
11054 +unsigned int aufs_poll(struct file *file, poll_table *wait);
11057 +#ifdef CONFIG_AUFS_BR_HFSPLUS
11059 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex);
11060 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
11061 + struct file *h_file);
11064 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex)
11069 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
11070 + struct file *h_file);
11074 +extern const struct file_operations aufs_file_fop;
11075 +int au_do_open_nondir(struct file *file, int flags);
11076 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
11078 +#ifdef CONFIG_AUFS_SP_IATTR
11080 +struct au_finfo *au_fi_sp(struct file *file);
11081 +int au_special_file(umode_t mode);
11082 +void au_init_special_fop(struct inode *inode, umode_t mode, dev_t rdev);
11084 +static inline struct au_finfo *au_fi_sp(struct file *file)
11088 +AuStubInt0(au_special_file, umode_t mode)
11089 +static inline void au_init_special_fop(struct inode *inode, umode_t mode,
11092 + init_special_inode(inode, mode, rdev);
11097 +void au_hfput(struct au_hfile *hf, struct file *file);
11098 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
11099 + struct file *h_file);
11101 +void au_update_figen(struct file *file);
11102 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
11103 +int au_fidir_realloc(struct au_finfo *finfo, int nbr);
11105 +void au_fi_init_once(void *_fi);
11106 +void au_finfo_fin(struct file *file);
11107 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
11110 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
11111 +#ifdef CONFIG_COMPAT
11112 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
11113 + unsigned long arg);
11114 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
11115 + unsigned long arg);
11118 +/* ---------------------------------------------------------------------- */
11120 +static inline struct au_finfo *au_fi(struct file *file)
11122 + struct au_finfo *finfo;
11124 + finfo = au_fi_sp(file);
11126 + finfo = file->private_data;
11130 +/* ---------------------------------------------------------------------- */
11133 + * fi_read_lock, fi_write_lock,
11134 + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock
11136 +AuSimpleRwsemFuncs(fi, struct file *f, &au_fi(f)->fi_rwsem);
11138 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
11139 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
11140 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
11142 +/* ---------------------------------------------------------------------- */
11144 +/* todo: hard/soft set? */
11145 +static inline aufs_bindex_t au_fbstart(struct file *file)
11147 + FiMustAnyLock(file);
11148 + return au_fi(file)->fi_btop;
11151 +static inline aufs_bindex_t au_fbend_dir(struct file *file)
11153 + FiMustAnyLock(file);
11154 + AuDebugOn(!au_fi(file)->fi_hdir);
11155 + return au_fi(file)->fi_hdir->fd_bbot;
11158 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
11160 + FiMustAnyLock(file);
11161 + AuDebugOn(!au_fi(file)->fi_hdir);
11162 + return au_fi(file)->fi_hdir->fd_vdir_cache;
11165 +static inline void au_set_fbstart(struct file *file, aufs_bindex_t bindex)
11167 + FiMustWriteLock(file);
11168 + au_fi(file)->fi_btop = bindex;
11171 +static inline void au_set_fbend_dir(struct file *file, aufs_bindex_t bindex)
11173 + FiMustWriteLock(file);
11174 + AuDebugOn(!au_fi(file)->fi_hdir);
11175 + au_fi(file)->fi_hdir->fd_bbot = bindex;
11178 +static inline void au_set_fvdir_cache(struct file *file,
11179 + struct au_vdir *vdir_cache)
11181 + FiMustWriteLock(file);
11182 + AuDebugOn(!au_fi(file)->fi_hdir);
11183 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
11186 +static inline struct file *au_hf_top(struct file *file)
11188 + FiMustAnyLock(file);
11189 + AuDebugOn(au_fi(file)->fi_hdir);
11190 + return au_fi(file)->fi_htop.hf_file;
11193 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
11195 + FiMustAnyLock(file);
11196 + AuDebugOn(!au_fi(file)->fi_hdir);
11197 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
11200 +/* todo: memory barrier? */
11201 +static inline unsigned int au_figen(struct file *f)
11203 + return atomic_read(&au_fi(f)->fi_generation);
11206 +static inline void au_set_mmapped(struct file *f)
11208 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
11210 + pr_warn("fi_mmapped wrapped around\n");
11211 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
11215 +static inline void au_unset_mmapped(struct file *f)
11217 + atomic_dec(&au_fi(f)->fi_mmapped);
11220 +static inline int au_test_mmapped(struct file *f)
11222 + return atomic_read(&au_fi(f)->fi_mmapped);
11225 +/* customize vma->vm_file */
11227 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
11228 + struct file *file)
11232 + f = vma->vm_file;
11234 + vma->vm_file = file;
11239 +#define AuDbgVmRegion(file, vma) do {} while (0)
11241 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
11242 + struct file *file)
11244 + au_do_vm_file_reset(vma, file);
11247 +#define AuDbgVmRegion(file, vma) \
11248 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
11250 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
11251 + struct file *file)
11255 + au_do_vm_file_reset(vma, file);
11256 + f = vma->vm_region->vm_file;
11258 + vma->vm_region->vm_file = file;
11261 +#endif /* CONFIG_MMU */
11263 +/* handle vma->vm_prfile */
11264 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
11265 + struct file *file)
11267 +#ifdef CONFIG_AUFS_PROC_MAP
11269 + vma->vm_prfile = file;
11270 +#ifndef CONFIG_MMU
11272 + vma->vm_region->vm_prfile = file;
11277 +#endif /* __KERNEL__ */
11278 +#endif /* __AUFS_FILE_H__ */
11279 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
11280 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
11281 +++ linux/fs/aufs/finfo.c 2013-07-06 13:20:47.750198454 +0200
11284 + * Copyright (C) 2005-2013 Junjiro R. Okajima
11286 + * This program, aufs is free software; you can redistribute it and/or modify
11287 + * it under the terms of the GNU General Public License as published by
11288 + * the Free Software Foundation; either version 2 of the License, or
11289 + * (at your option) any later version.
11291 + * This program is distributed in the hope that it will be useful,
11292 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11293 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11294 + * GNU General Public License for more details.
11296 + * You should have received a copy of the GNU General Public License
11297 + * along with this program; if not, write to the Free Software
11298 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11302 + * file private data
11307 +void au_hfput(struct au_hfile *hf, struct file *file)
11309 + /* todo: direct access f_flags */
11310 + if (vfsub_file_flags(file) & __FMODE_EXEC)
11311 + allow_write_access(hf->hf_file);
11312 + fput(hf->hf_file);
11313 + hf->hf_file = NULL;
11314 + atomic_dec(&hf->hf_br->br_count);
11315 + hf->hf_br = NULL;
11318 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
11320 + struct au_finfo *finfo = au_fi(file);
11321 + struct au_hfile *hf;
11322 + struct au_fidir *fidir;
11324 + fidir = finfo->fi_hdir;
11326 + AuDebugOn(finfo->fi_btop != bindex);
11327 + hf = &finfo->fi_htop;
11329 + hf = fidir->fd_hfile + bindex;
11331 + if (hf && hf->hf_file)
11332 + au_hfput(hf, file);
11334 + FiMustWriteLock(file);
11335 + hf->hf_file = val;
11336 + hf->hf_br = au_sbr(file->f_dentry->d_sb, bindex);
11340 +void au_update_figen(struct file *file)
11342 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_dentry));
11343 + /* smp_mb(); */ /* atomic_set */
11346 +/* ---------------------------------------------------------------------- */
11348 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
11350 + struct au_fidir *fidir;
11353 + nbr = au_sbend(sb) + 1;
11355 + nbr = 2; /* initial allocate for 2 branches */
11356 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
11358 + fidir->fd_bbot = -1;
11359 + fidir->fd_nent = nbr;
11360 + fidir->fd_vdir_cache = NULL;
11366 +int au_fidir_realloc(struct au_finfo *finfo, int nbr)
11369 + struct au_fidir *fidir, *p;
11371 + AuRwMustWriteLock(&finfo->fi_rwsem);
11372 + fidir = finfo->fi_hdir;
11373 + AuDebugOn(!fidir);
11376 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
11379 + p->fd_nent = nbr;
11380 + finfo->fi_hdir = p;
11387 +/* ---------------------------------------------------------------------- */
11389 +void au_finfo_fin(struct file *file)
11391 + struct au_finfo *finfo;
11393 + au_nfiles_dec(file->f_dentry->d_sb);
11395 + finfo = au_fi(file);
11396 + AuDebugOn(finfo->fi_hdir);
11397 + AuRwDestroy(&finfo->fi_rwsem);
11398 + au_cache_free_finfo(finfo);
11401 +void au_fi_init_once(void *_finfo)
11403 + struct au_finfo *finfo = _finfo;
11404 + static struct lock_class_key aufs_fi;
11406 + au_rw_init(&finfo->fi_rwsem);
11407 + au_rw_class(&finfo->fi_rwsem, &aufs_fi);
11410 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
11413 + struct au_finfo *finfo;
11414 + struct dentry *dentry;
11417 + dentry = file->f_dentry;
11418 + finfo = au_cache_alloc_finfo();
11419 + if (unlikely(!finfo))
11423 + au_nfiles_inc(dentry->d_sb);
11424 + /* verbose coding for lock class name */
11426 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcNonDir_FIINFO);
11428 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcDir_FIINFO);
11429 + au_rw_write_lock(&finfo->fi_rwsem);
11430 + finfo->fi_btop = -1;
11431 + finfo->fi_hdir = fidir;
11432 + atomic_set(&finfo->fi_generation, au_digen(dentry));
11433 + /* smp_mb(); */ /* atomic_set */
11435 + file->private_data = finfo;
11440 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
11441 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
11442 +++ linux/fs/aufs/f_op.c 2013-08-23 23:59:39.634916914 +0200
11445 + * Copyright (C) 2005-2013 Junjiro R. Okajima
11447 + * This program, aufs is free software; you can redistribute it and/or modify
11448 + * it under the terms of the GNU General Public License as published by
11449 + * the Free Software Foundation; either version 2 of the License, or
11450 + * (at your option) any later version.
11452 + * This program is distributed in the hope that it will be useful,
11453 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11454 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11455 + * GNU General Public License for more details.
11457 + * You should have received a copy of the GNU General Public License
11458 + * along with this program; if not, write to the Free Software
11459 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11463 + * file and vm operations
11466 +#include <linux/aio.h>
11467 +#include <linux/fs_stack.h>
11468 +#include <linux/mman.h>
11469 +#include <linux/security.h>
11472 +int au_do_open_nondir(struct file *file, int flags)
11475 + aufs_bindex_t bindex;
11476 + struct file *h_file;
11477 + struct dentry *dentry;
11478 + struct au_finfo *finfo;
11480 + FiMustWriteLock(file);
11482 + dentry = file->f_dentry;
11483 + err = au_d_alive(dentry);
11484 + if (unlikely(err))
11487 + finfo = au_fi(file);
11488 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
11489 + atomic_set(&finfo->fi_mmapped, 0);
11490 + bindex = au_dbstart(dentry);
11491 + h_file = au_h_open(dentry, bindex, flags, file);
11492 + if (IS_ERR(h_file))
11493 + err = PTR_ERR(h_file);
11495 + au_set_fbstart(file, bindex);
11496 + au_set_h_fptr(file, bindex, h_file);
11497 + au_update_figen(file);
11498 + /* todo: necessary? */
11499 + /* file->f_ra = h_file->f_ra; */
11506 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
11507 + struct file *file)
11510 + struct super_block *sb;
11512 + AuDbg("%.*s, f_flags 0x%x, f_mode 0x%x\n",
11513 + AuDLNPair(file->f_dentry), vfsub_file_flags(file),
11516 + sb = file->f_dentry->d_sb;
11517 + si_read_lock(sb, AuLock_FLUSH);
11518 + err = au_do_open(file, au_do_open_nondir, /*fidir*/NULL);
11519 + si_read_unlock(sb);
11523 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
11525 + struct au_finfo *finfo;
11526 + aufs_bindex_t bindex;
11528 + finfo = au_fi(file);
11529 + bindex = finfo->fi_btop;
11531 + au_set_h_fptr(file, bindex, NULL);
11533 + au_finfo_fin(file);
11537 +/* ---------------------------------------------------------------------- */
11539 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
11542 + struct file *h_file;
11545 + h_file = au_hf_top(file);
11547 + err = vfsub_flush(h_file, id);
11551 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
11553 + return au_do_flush(file, id, au_do_flush_nondir);
11556 +/* ---------------------------------------------------------------------- */
11558 + * read and write functions acquire [fdi]_rwsem once, but release before
11559 + * mmap_sem. This is because to stop a race condition between mmap(2).
11560 + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping
11561 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
11562 + * read functions after [fdi]_rwsem are released, but it should be harmless.
11565 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
11569 + struct dentry *dentry;
11570 + struct file *h_file;
11571 + struct super_block *sb;
11573 + dentry = file->f_dentry;
11574 + sb = dentry->d_sb;
11575 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11576 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
11577 + if (unlikely(err))
11580 + h_file = au_hf_top(file);
11581 + get_file(h_file);
11582 + di_read_unlock(dentry, AuLock_IR);
11583 + fi_read_unlock(file);
11585 + /* filedata may be obsoleted by concurrent copyup, but no problem */
11586 + err = vfsub_read_u(h_file, buf, count, ppos);
11587 + /* todo: necessary? */
11588 + /* file->f_ra = h_file->f_ra; */
11589 + /* update without lock, I don't think it a problem */
11590 + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
11594 + si_read_unlock(sb);
11599 + * todo: very ugly
11600 + * it locks both of i_mutex and si_rwsem for read in safe.
11601 + * if the plink maintenance mode continues forever (that is the problem),
11602 + * may loop forever.
11604 +static void au_mtx_and_read_lock(struct inode *inode)
11607 + struct super_block *sb = inode->i_sb;
11610 + mutex_lock(&inode->i_mutex);
11611 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
11614 + mutex_unlock(&inode->i_mutex);
11615 + si_read_lock(sb, AuLock_NOPLMW);
11616 + si_read_unlock(sb);
11620 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
11621 + size_t count, loff_t *ppos)
11624 + struct au_pin pin;
11625 + struct dentry *dentry;
11626 + struct super_block *sb;
11627 + struct inode *inode;
11628 + struct file *h_file;
11629 + char __user *buf = (char __user *)ubuf;
11631 + dentry = file->f_dentry;
11632 + sb = dentry->d_sb;
11633 + inode = dentry->d_inode;
11634 + au_mtx_and_read_lock(inode);
11636 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
11637 + if (unlikely(err))
11640 + err = au_ready_to_write(file, -1, &pin);
11641 + di_downgrade_lock(dentry, AuLock_IR);
11642 + if (unlikely(err)) {
11643 + di_read_unlock(dentry, AuLock_IR);
11644 + fi_write_unlock(file);
11648 + h_file = au_hf_top(file);
11649 + get_file(h_file);
11651 + di_read_unlock(dentry, AuLock_IR);
11652 + fi_write_unlock(file);
11654 + err = vfsub_write_u(h_file, buf, count, ppos);
11655 + ii_write_lock_child(inode);
11656 + au_cpup_attr_timesizes(inode);
11657 + inode->i_mode = file_inode(h_file)->i_mode;
11658 + ii_write_unlock(inode);
11662 + si_read_unlock(sb);
11663 + mutex_unlock(&inode->i_mutex);
11667 +static ssize_t au_do_aio(struct file *h_file, int rw, struct kiocb *kio,
11668 + const struct iovec *iov, unsigned long nv, loff_t pos)
11671 + struct file *file;
11672 + ssize_t (*func)(struct kiocb *, const struct iovec *, unsigned long,
11675 + err = security_file_permission(h_file, rw);
11676 + if (unlikely(err))
11681 + if (rw == MAY_READ)
11682 + func = h_file->f_op->aio_read;
11683 + else if (rw == MAY_WRITE)
11684 + func = h_file->f_op->aio_write;
11686 + file = kio->ki_filp;
11687 + kio->ki_filp = h_file;
11689 + err = func(kio, iov, nv, pos);
11691 + kio->ki_filp = file;
11693 + /* currently there is no such fs */
11700 +static ssize_t aufs_aio_read(struct kiocb *kio, const struct iovec *iov,
11701 + unsigned long nv, loff_t pos)
11704 + struct file *file, *h_file;
11705 + struct dentry *dentry;
11706 + struct super_block *sb;
11708 + file = kio->ki_filp;
11709 + dentry = file->f_dentry;
11710 + sb = dentry->d_sb;
11711 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11712 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
11713 + if (unlikely(err))
11716 + h_file = au_hf_top(file);
11717 + get_file(h_file);
11718 + di_read_unlock(dentry, AuLock_IR);
11719 + fi_read_unlock(file);
11721 + err = au_do_aio(h_file, MAY_READ, kio, iov, nv, pos);
11722 + /* todo: necessary? */
11723 + /* file->f_ra = h_file->f_ra; */
11724 + /* update without lock, I don't think it a problem */
11725 + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
11729 + si_read_unlock(sb);
11733 +static ssize_t aufs_aio_write(struct kiocb *kio, const struct iovec *iov,
11734 + unsigned long nv, loff_t pos)
11737 + struct au_pin pin;
11738 + struct dentry *dentry;
11739 + struct inode *inode;
11740 + struct file *file, *h_file;
11741 + struct super_block *sb;
11743 + file = kio->ki_filp;
11744 + dentry = file->f_dentry;
11745 + sb = dentry->d_sb;
11746 + inode = dentry->d_inode;
11747 + au_mtx_and_read_lock(inode);
11749 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
11750 + if (unlikely(err))
11753 + err = au_ready_to_write(file, -1, &pin);
11754 + di_downgrade_lock(dentry, AuLock_IR);
11755 + if (unlikely(err)) {
11756 + di_read_unlock(dentry, AuLock_IR);
11757 + fi_write_unlock(file);
11761 + h_file = au_hf_top(file);
11762 + get_file(h_file);
11764 + di_read_unlock(dentry, AuLock_IR);
11765 + fi_write_unlock(file);
11767 + err = au_do_aio(h_file, MAY_WRITE, kio, iov, nv, pos);
11768 + ii_write_lock_child(inode);
11769 + au_cpup_attr_timesizes(inode);
11770 + inode->i_mode = file_inode(h_file)->i_mode;
11771 + ii_write_unlock(inode);
11775 + si_read_unlock(sb);
11776 + mutex_unlock(&inode->i_mutex);
11780 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
11781 + struct pipe_inode_info *pipe, size_t len,
11782 + unsigned int flags)
11785 + struct file *h_file;
11786 + struct dentry *dentry;
11787 + struct super_block *sb;
11789 + dentry = file->f_dentry;
11790 + sb = dentry->d_sb;
11791 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11792 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
11793 + if (unlikely(err))
11797 + h_file = au_hf_top(file);
11798 + get_file(h_file);
11799 + if (au_test_loopback_kthread()) {
11800 + au_warn_loopback(h_file->f_dentry->d_sb);
11801 + if (file->f_mapping != h_file->f_mapping) {
11802 + file->f_mapping = h_file->f_mapping;
11803 + smp_mb(); /* unnecessary? */
11806 + di_read_unlock(dentry, AuLock_IR);
11807 + fi_read_unlock(file);
11809 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
11810 + /* todo: necessasry? */
11811 + /* file->f_ra = h_file->f_ra; */
11812 + /* update without lock, I don't think it a problem */
11813 + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
11817 + si_read_unlock(sb);
11822 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
11823 + size_t len, unsigned int flags)
11826 + struct au_pin pin;
11827 + struct dentry *dentry;
11828 + struct inode *inode;
11829 + struct file *h_file;
11830 + struct super_block *sb;
11832 + dentry = file->f_dentry;
11833 + sb = dentry->d_sb;
11834 + inode = dentry->d_inode;
11835 + au_mtx_and_read_lock(inode);
11837 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
11838 + if (unlikely(err))
11841 + err = au_ready_to_write(file, -1, &pin);
11842 + di_downgrade_lock(dentry, AuLock_IR);
11843 + if (unlikely(err)) {
11844 + di_read_unlock(dentry, AuLock_IR);
11845 + fi_write_unlock(file);
11849 + h_file = au_hf_top(file);
11850 + get_file(h_file);
11852 + di_read_unlock(dentry, AuLock_IR);
11853 + fi_write_unlock(file);
11855 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
11856 + ii_write_lock_child(inode);
11857 + au_cpup_attr_timesizes(inode);
11858 + inode->i_mode = file_inode(h_file)->i_mode;
11859 + ii_write_unlock(inode);
11863 + si_read_unlock(sb);
11864 + mutex_unlock(&inode->i_mutex);
11868 +/* ---------------------------------------------------------------------- */
11871 + * The locking order around current->mmap_sem.
11872 + * - in most and regular cases
11873 + * file I/O syscall -- aufs_read() or something
11874 + * -- si_rwsem for read -- mmap_sem
11875 + * (Note that [fdi]i_rwsem are released before mmap_sem).
11877 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
11878 + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
11879 + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
11880 + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
11881 + * It means that when aufs acquires si_rwsem for write, the process should never
11882 + * acquire mmap_sem.
11884 + * Actually aufs_readdir() holds [fdi]i_rwsem before mmap_sem, but this is not a
11885 + * problem either since any directory is not able to be mmap-ed.
11886 + * The similar scenario is applied to aufs_readlink() too.
11889 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
11890 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
11892 +static unsigned long au_arch_prot_conv(unsigned long flags)
11894 + /* currently ppc64 only */
11895 +#ifdef CONFIG_PPC64
11896 + /* cf. linux/arch/powerpc/include/asm/mman.h */
11897 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
11898 + return AuConv_VM_PROT(flags, SAO);
11900 + AuDebugOn(arch_calc_vm_prot_bits(-1));
11905 +static unsigned long au_prot_conv(unsigned long flags)
11907 + return AuConv_VM_PROT(flags, READ)
11908 + | AuConv_VM_PROT(flags, WRITE)
11909 + | AuConv_VM_PROT(flags, EXEC)
11910 + | au_arch_prot_conv(flags);
11913 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
11914 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
11916 +static unsigned long au_flag_conv(unsigned long flags)
11918 + return AuConv_VM_MAP(flags, GROWSDOWN)
11919 + | AuConv_VM_MAP(flags, DENYWRITE)
11920 + | AuConv_VM_MAP(flags, LOCKED);
11923 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
11926 + aufs_bindex_t bstart;
11927 + const unsigned char wlock
11928 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
11929 + struct dentry *dentry;
11930 + struct super_block *sb;
11931 + struct file *h_file;
11932 + struct au_branch *br;
11933 + struct au_pin pin;
11935 + AuDbgVmRegion(file, vma);
11937 + dentry = file->f_dentry;
11938 + sb = dentry->d_sb;
11940 + si_read_lock(sb, AuLock_NOPLMW);
11941 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
11942 + if (unlikely(err))
11946 + err = au_ready_to_write(file, -1, &pin);
11947 + di_write_unlock(dentry);
11948 + if (unlikely(err)) {
11949 + fi_write_unlock(file);
11954 + di_write_unlock(dentry);
11956 + bstart = au_fbstart(file);
11957 + br = au_sbr(sb, bstart);
11958 + h_file = au_hf_top(file);
11959 + get_file(h_file);
11960 + au_set_mmapped(file);
11961 + fi_write_unlock(file);
11964 + au_vm_file_reset(vma, h_file);
11965 + err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
11966 + au_flag_conv(vma->vm_flags));
11968 + err = h_file->f_op->mmap(h_file, vma);
11969 + if (unlikely(err))
11972 + au_vm_prfile_set(vma, file);
11973 + /* update without lock, I don't think it a problem */
11974 + fsstack_copy_attr_atime(file_inode(file), file_inode(h_file));
11975 + goto out_fput; /* success */
11978 + au_unset_mmapped(file);
11979 + au_vm_file_reset(vma, file);
11984 + si_read_unlock(sb);
11990 +/* ---------------------------------------------------------------------- */
11992 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
11996 + struct au_pin pin;
11997 + struct dentry *dentry;
11998 + struct inode *inode;
11999 + struct file *h_file;
12000 + struct super_block *sb;
12002 + dentry = file->f_dentry;
12003 + inode = dentry->d_inode;
12004 + sb = dentry->d_sb;
12005 + mutex_lock(&inode->i_mutex);
12006 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
12007 + if (unlikely(err))
12010 + err = 0; /* -EBADF; */ /* posix? */
12011 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
12013 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
12014 + if (unlikely(err))
12017 + err = au_ready_to_write(file, -1, &pin);
12018 + di_downgrade_lock(dentry, AuLock_IR);
12019 + if (unlikely(err))
12024 + h_file = au_hf_top(file);
12025 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
12026 + au_cpup_attr_timesizes(inode);
12029 + di_read_unlock(dentry, AuLock_IR);
12030 + fi_write_unlock(file);
12032 + si_read_unlock(sb);
12034 + mutex_unlock(&inode->i_mutex);
12038 +/* no one supports this operation, currently */
12040 +static int aufs_aio_fsync_nondir(struct kiocb *kio, int datasync)
12043 + struct au_pin pin;
12044 + struct dentry *dentry;
12045 + struct inode *inode;
12046 + struct file *file, *h_file;
12048 + file = kio->ki_filp;
12049 + dentry = file->f_dentry;
12050 + inode = dentry->d_inode;
12051 + au_mtx_and_read_lock(inode);
12053 + err = 0; /* -EBADF; */ /* posix? */
12054 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
12056 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
12057 + if (unlikely(err))
12060 + err = au_ready_to_write(file, -1, &pin);
12061 + di_downgrade_lock(dentry, AuLock_IR);
12062 + if (unlikely(err))
12067 + h_file = au_hf_top(file);
12068 + if (h_file->f_op && h_file->f_op->aio_fsync) {
12069 + struct mutex *h_mtx;
12071 + h_mtx = &file_inode(h_file)->i_mutex;
12072 + if (!is_sync_kiocb(kio)) {
12073 + get_file(h_file);
12076 + kio->ki_filp = h_file;
12077 + err = h_file->f_op->aio_fsync(kio, datasync);
12078 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
12080 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL);
12082 + au_cpup_attr_timesizes(inode);
12083 + mutex_unlock(h_mtx);
12087 + di_read_unlock(dentry, AuLock_IR);
12088 + fi_write_unlock(file);
12090 + si_read_unlock(inode->sb);
12091 + mutex_unlock(&inode->i_mutex);
12096 +static int aufs_fasync(int fd, struct file *file, int flag)
12099 + struct file *h_file;
12100 + struct dentry *dentry;
12101 + struct super_block *sb;
12103 + dentry = file->f_dentry;
12104 + sb = dentry->d_sb;
12105 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
12106 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
12107 + if (unlikely(err))
12110 + h_file = au_hf_top(file);
12111 + if (h_file->f_op && h_file->f_op->fasync)
12112 + err = h_file->f_op->fasync(fd, h_file, flag);
12114 + di_read_unlock(dentry, AuLock_IR);
12115 + fi_read_unlock(file);
12118 + si_read_unlock(sb);
12122 +/* ---------------------------------------------------------------------- */
12124 +/* no one supports this operation, currently */
12126 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
12127 + size_t len, loff_t *pos , int more)
12132 +/* ---------------------------------------------------------------------- */
12134 +const struct file_operations aufs_file_fop = {
12135 + .owner = THIS_MODULE,
12137 + .llseek = default_llseek,
12139 + .read = aufs_read,
12140 + .write = aufs_write,
12141 + .aio_read = aufs_aio_read,
12142 + .aio_write = aufs_aio_write,
12143 +#ifdef CONFIG_AUFS_POLL
12144 + .poll = aufs_poll,
12146 + .unlocked_ioctl = aufs_ioctl_nondir,
12147 +#ifdef CONFIG_COMPAT
12148 + .compat_ioctl = aufs_compat_ioctl_nondir,
12150 + .mmap = aufs_mmap,
12151 + .open = aufs_open_nondir,
12152 + .flush = aufs_flush_nondir,
12153 + .release = aufs_release_nondir,
12154 + .fsync = aufs_fsync_nondir,
12155 + /* .aio_fsync = aufs_aio_fsync_nondir, */
12156 + .fasync = aufs_fasync,
12157 + /* .sendpage = aufs_sendpage, */
12158 + .splice_write = aufs_splice_write,
12159 + .splice_read = aufs_splice_read,
12161 + .aio_splice_write = aufs_aio_splice_write,
12162 + .aio_splice_read = aufs_aio_splice_read
12165 diff -urN /usr/share/empty/fs/aufs/f_op_sp.c linux/fs/aufs/f_op_sp.c
12166 --- /usr/share/empty/fs/aufs/f_op_sp.c 1970-01-01 01:00:00.000000000 +0100
12167 +++ linux/fs/aufs/f_op_sp.c 2013-08-23 23:59:39.634916914 +0200
12170 + * Copyright (C) 2005-2013 Junjiro R. Okajima
12172 + * This program, aufs is free software; you can redistribute it and/or modify
12173 + * it under the terms of the GNU General Public License as published by
12174 + * the Free Software Foundation; either version 2 of the License, or
12175 + * (at your option) any later version.
12177 + * This program is distributed in the hope that it will be useful,
12178 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12179 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12180 + * GNU General Public License for more details.
12182 + * You should have received a copy of the GNU General Public License
12183 + * along with this program; if not, write to the Free Software
12184 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
12188 + * file operations for special files.
12189 + * while they exist in aufs virtually,
12190 + * their file I/O is handled out of aufs.
12193 +#include <linux/aio.h>
12197 + * I don't think the size of this list grows much.
12198 + * so here is a very simple list implemented in order to find finfo matching a
12201 +static struct au_sphlhead au_finfo_sp = {
12202 + .spin = __SPIN_LOCK_INITIALIZER(au_finfo_sp.spin),
12203 + .head = HLIST_HEAD_INIT
12206 +struct au_finfo_sp {
12207 + struct hlist_node hlist;
12208 + struct file *file;
12209 + struct au_finfo *finfo;
12212 +struct au_finfo *au_fi_sp(struct file *file)
12214 + struct au_finfo *finfo;
12215 + struct au_finfo_sp *sp;
12218 + spin_lock(&au_finfo_sp.spin);
12219 + hlist_for_each_entry(sp, &au_finfo_sp.head, hlist) {
12220 + if (sp->file != file)
12222 + finfo = sp->finfo;
12225 + spin_unlock(&au_finfo_sp.spin);
12230 +static int au_fi_sp_add(struct file *file)
12233 + struct au_finfo_sp *sp;
12236 + sp = kmalloc(sizeof(*sp), GFP_NOFS);
12240 + sp->finfo = file->private_data;
12241 + spin_lock(&au_finfo_sp.spin);
12242 + hlist_add_head(&sp->hlist, &au_finfo_sp.head);
12243 + spin_unlock(&au_finfo_sp.spin);
12248 +static void au_fi_sp_del(struct file *file)
12250 + struct au_finfo_sp *sp, *do_free;
12253 + spin_lock(&au_finfo_sp.spin);
12254 + hlist_for_each_entry(sp, &au_finfo_sp.head, hlist) {
12255 + if (sp->file != file)
12257 + hlist_del(&sp->hlist);
12261 + spin_unlock(&au_finfo_sp.spin);
12265 +/* ---------------------------------------------------------------------- */
12267 +static ssize_t aufs_aio_read_sp(struct kiocb *kio, const struct iovec *iov,
12268 + unsigned long nv, loff_t pos)
12271 + aufs_bindex_t bstart;
12272 + unsigned char wbr;
12273 + struct file *file, *h_file;
12274 + struct super_block *sb;
12276 + file = kio->ki_filp;
12277 + sb = file->f_dentry->d_sb;
12278 + si_read_lock(sb, AuLock_FLUSH);
12279 + fi_read_lock(file);
12280 + bstart = au_fbstart(file);
12281 + h_file = au_hf_top(file);
12282 + fi_read_unlock(file);
12283 + wbr = !!au_br_writable(au_sbr(sb, bstart)->br_perm);
12284 + si_read_unlock(sb);
12286 + /* do not change the file in kio */
12287 + AuDebugOn(!h_file->f_op || !h_file->f_op->aio_read);
12288 + err = h_file->f_op->aio_read(kio, iov, nv, pos);
12289 + if (err > 0 && wbr)
12290 + file_accessed(h_file);
12295 +static ssize_t aufs_aio_write_sp(struct kiocb *kio, const struct iovec *iov,
12296 + unsigned long nv, loff_t pos)
12299 + aufs_bindex_t bstart;
12300 + unsigned char wbr;
12301 + struct super_block *sb;
12302 + struct file *file, *h_file;
12304 + file = kio->ki_filp;
12305 + sb = file->f_dentry->d_sb;
12306 + si_read_lock(sb, AuLock_FLUSH);
12307 + fi_read_lock(file);
12308 + bstart = au_fbstart(file);
12309 + h_file = au_hf_top(file);
12310 + fi_read_unlock(file);
12311 + wbr = !!au_br_writable(au_sbr(sb, bstart)->br_perm);
12312 + si_read_unlock(sb);
12314 + /* do not change the file in kio */
12315 + AuDebugOn(!h_file->f_op || !h_file->f_op->aio_write);
12316 + err = h_file->f_op->aio_write(kio, iov, nv, pos);
12320 +/* ---------------------------------------------------------------------- */
12322 +static int aufs_release_sp(struct inode *inode, struct file *file)
12325 + struct file *h_file;
12327 + fi_read_lock(file);
12328 + h_file = au_hf_top(file);
12329 + fi_read_unlock(file);
12330 + /* close this fifo in aufs */
12331 + err = h_file->f_op->release(inode, file); /* ignore */
12332 + aufs_release_nondir(inode, file); /* ignore */
12333 + au_fi_sp_del(file);
12337 +/* ---------------------------------------------------------------------- */
12339 +/* currently, support only FIFO */
12341 + AuSp_FIFO, AuSp_FIFO_R, AuSp_FIFO_W, AuSp_FIFO_RW,
12342 + /* AuSp_SOCK, AuSp_CHR, AuSp_BLK, */
12345 +static int aufs_open_sp(struct inode *inode, struct file *file);
12346 +static struct au_sp_fop {
12348 + struct file_operations fop; /* not 'const' */
12350 +} au_sp_fop[AuSp_Last] = {
12353 + .owner = THIS_MODULE,
12354 + .open = aufs_open_sp
12359 +static void au_init_fop_sp(struct file *file)
12361 + struct au_sp_fop *p;
12363 + struct file *h_file;
12366 + if (unlikely(!p->done)) {
12367 + /* initialize first time only */
12368 + static DEFINE_SPINLOCK(spin);
12370 + spin_lock(&spin);
12372 + BUILD_BUG_ON(sizeof(au_sp_fop)/sizeof(*au_sp_fop)
12374 + for (i = 0; i < AuSp_Last; i++)
12375 + spin_lock_init(&p[i].spin);
12378 + spin_unlock(&spin);
12381 + switch (file->f_mode & (FMODE_READ | FMODE_WRITE)) {
12385 + case FMODE_WRITE:
12388 + case FMODE_READ | FMODE_WRITE:
12389 + i = AuSp_FIFO_RW;
12396 + if (unlikely(!p->done)) {
12397 + /* initialize first time only */
12398 + h_file = au_hf_top(file);
12399 + spin_lock(&p->spin);
12401 + p->fop = *h_file->f_op;
12402 + p->fop.owner = THIS_MODULE;
12403 + if (p->fop.aio_read)
12404 + p->fop.aio_read = aufs_aio_read_sp;
12405 + if (p->fop.aio_write)
12406 + p->fop.aio_write = aufs_aio_write_sp;
12407 + p->fop.release = aufs_release_sp;
12410 + spin_unlock(&p->spin);
12412 + file->f_op = &p->fop;
12415 +static int au_cpup_sp(struct dentry *dentry)
12418 + struct au_pin pin;
12419 + struct au_wr_dir_args wr_dir_args = {
12420 + .force_btgt = -1,
12423 + struct au_cp_generic cpg = {
12424 + .dentry = dentry,
12429 + .flags = AuCpup_DTIME
12432 + AuDbg("%.*s\n", AuDLNPair(dentry));
12434 + di_read_unlock(dentry, AuLock_IR);
12435 + di_write_lock_child(dentry);
12436 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
12437 + if (unlikely(err < 0))
12441 + if (cpg.bdst == au_dbstart(dentry))
12442 + goto out; /* success */
12444 + err = au_pin(&pin, dentry, cpg.bdst, au_opt_udba(dentry->d_sb),
12445 + AuPin_MNT_WRITE);
12447 + err = au_sio_cpup_simple(&cpg);
12452 + di_downgrade_lock(dentry, AuLock_IR);
12456 +static int au_do_open_sp(struct file *file, int flags)
12459 + struct dentry *dentry;
12460 + struct super_block *sb;
12461 + struct file *h_file;
12462 + struct inode *h_inode;
12464 + err = au_fi_sp_add(file);
12465 + if (unlikely(err))
12468 + dentry = file->f_dentry;
12469 + AuDbg("%.*s\n", AuDLNPair(dentry));
12472 + * try copying-up.
12473 + * operate on the ro branch is not an error.
12475 + au_cpup_sp(dentry); /* ignore */
12477 + /* prepare h_file */
12478 + err = au_do_open_nondir(file, vfsub_file_flags(file));
12479 + if (unlikely(err))
12482 + sb = dentry->d_sb;
12483 + h_file = au_hf_top(file);
12484 + h_inode = file_inode(h_file);
12485 + di_read_unlock(dentry, AuLock_IR);
12486 + fi_write_unlock(file);
12487 + si_read_unlock(sb);
12488 + /* open this fifo in aufs */
12489 + err = h_inode->i_fop->open(file_inode(file), file);
12490 + si_noflush_read_lock(sb);
12491 + fi_write_lock(file);
12492 + di_read_lock_child(dentry, AuLock_IR);
12494 + au_init_fop_sp(file);
12495 + goto out; /* success */
12499 + au_fi_sp_del(file);
12504 +static int aufs_open_sp(struct inode *inode, struct file *file)
12507 + struct super_block *sb;
12509 + sb = file->f_dentry->d_sb;
12510 + si_read_lock(sb, AuLock_FLUSH);
12511 + err = au_do_open(file, au_do_open_sp, /*fidir*/NULL);
12512 + si_read_unlock(sb);
12516 +/* ---------------------------------------------------------------------- */
12518 +void au_init_special_fop(struct inode *inode, umode_t mode, dev_t rdev)
12520 + init_special_inode(inode, mode, rdev);
12522 + switch (mode & S_IFMT) {
12524 + inode->i_fop = &au_sp_fop[AuSp_FIFO].fop;
12535 +int au_special_file(umode_t mode)
12540 + switch (mode & S_IFMT) {
12552 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
12553 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
12554 +++ linux/fs/aufs/fstype.h 2013-08-23 23:59:39.634916914 +0200
12557 + * Copyright (C) 2005-2013 Junjiro R. Okajima
12559 + * This program, aufs is free software; you can redistribute it and/or modify
12560 + * it under the terms of the GNU General Public License as published by
12561 + * the Free Software Foundation; either version 2 of the License, or
12562 + * (at your option) any later version.
12564 + * This program is distributed in the hope that it will be useful,
12565 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12566 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12567 + * GNU General Public License for more details.
12569 + * You should have received a copy of the GNU General Public License
12570 + * along with this program; if not, write to the Free Software
12571 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
12575 + * judging filesystem type
12578 +#ifndef __AUFS_FSTYPE_H__
12579 +#define __AUFS_FSTYPE_H__
12583 +#include <linux/fs.h>
12584 +#include <linux/magic.h>
12585 +#include <linux/romfs_fs.h>
12587 +static inline int au_test_aufs(struct super_block *sb)
12589 + return sb->s_magic == AUFS_SUPER_MAGIC;
12592 +static inline const char *au_sbtype(struct super_block *sb)
12594 + return sb->s_type->name;
12597 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
12599 +#if defined(CONFIG_ROMFS_FS) || defined(CONFIG_ROMFS_FS_MODULE)
12600 + return sb->s_magic == ROMFS_MAGIC;
12606 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
12608 +#if defined(CONFIG_ISO9660_FS) || defined(CONFIG_ISO9660_FS_MODULE)
12609 + return sb->s_magic == ISOFS_SUPER_MAGIC;
12615 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
12617 +#if defined(CONFIG_CRAMFS) || defined(CONFIG_CRAMFS_MODULE)
12618 + return sb->s_magic == CRAMFS_MAGIC;
12623 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
12625 +#if defined(CONFIG_NFS_FS) || defined(CONFIG_NFS_FS_MODULE)
12626 + return sb->s_magic == NFS_SUPER_MAGIC;
12632 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
12634 +#if defined(CONFIG_FUSE_FS) || defined(CONFIG_FUSE_FS_MODULE)
12635 + return sb->s_magic == FUSE_SUPER_MAGIC;
12641 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
12643 +#if defined(CONFIG_XFS_FS) || defined(CONFIG_XFS_FS_MODULE)
12644 + return sb->s_magic == XFS_SB_MAGIC;
12650 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
12652 +#ifdef CONFIG_TMPFS
12653 + return sb->s_magic == TMPFS_MAGIC;
12659 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
12661 +#if defined(CONFIG_ECRYPT_FS) || defined(CONFIG_ECRYPT_FS_MODULE)
12662 + return !strcmp(au_sbtype(sb), "ecryptfs");
12668 +static inline int au_test_ocfs2(struct super_block *sb __maybe_unused)
12670 +#if defined(CONFIG_OCFS2_FS) || defined(CONFIG_OCFS2_FS_MODULE)
12671 + return sb->s_magic == OCFS2_SUPER_MAGIC;
12677 +static inline int au_test_ocfs2_dlmfs(struct super_block *sb __maybe_unused)
12679 +#if defined(CONFIG_OCFS2_FS_O2CB) || defined(CONFIG_OCFS2_FS_O2CB_MODULE)
12680 + return sb->s_magic == DLMFS_MAGIC;
12686 +static inline int au_test_coda(struct super_block *sb __maybe_unused)
12688 +#if defined(CONFIG_CODA_FS) || defined(CONFIG_CODA_FS_MODULE)
12689 + return sb->s_magic == CODA_SUPER_MAGIC;
12695 +static inline int au_test_v9fs(struct super_block *sb __maybe_unused)
12697 +#if defined(CONFIG_9P_FS) || defined(CONFIG_9P_FS_MODULE)
12698 + return sb->s_magic == V9FS_MAGIC;
12704 +static inline int au_test_ext4(struct super_block *sb __maybe_unused)
12706 +#if defined(CONFIG_EXT4_FS) || defined(CONFIG_EXT4_FS_MODULE)
12707 + return sb->s_magic == EXT4_SUPER_MAGIC;
12713 +static inline int au_test_sysv(struct super_block *sb __maybe_unused)
12715 +#if defined(CONFIG_SYSV_FS) || defined(CONFIG_SYSV_FS_MODULE)
12716 + return !strcmp(au_sbtype(sb), "sysv");
12722 +static inline int au_test_ramfs(struct super_block *sb)
12724 + return sb->s_magic == RAMFS_MAGIC;
12727 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
12729 +#if defined(CONFIG_UBIFS_FS) || defined(CONFIG_UBIFS_FS_MODULE)
12730 + return sb->s_magic == UBIFS_SUPER_MAGIC;
12736 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
12738 +#ifdef CONFIG_PROC_FS
12739 + return sb->s_magic == PROC_SUPER_MAGIC;
12745 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
12747 +#ifdef CONFIG_SYSFS
12748 + return sb->s_magic == SYSFS_MAGIC;
12754 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
12756 +#if defined(CONFIG_CONFIGFS_FS) || defined(CONFIG_CONFIGFS_FS_MODULE)
12757 + return sb->s_magic == CONFIGFS_MAGIC;
12763 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
12765 +#if defined(CONFIG_MINIX_FS) || defined(CONFIG_MINIX_FS_MODULE)
12766 + return sb->s_magic == MINIX3_SUPER_MAGIC
12767 + || sb->s_magic == MINIX2_SUPER_MAGIC
12768 + || sb->s_magic == MINIX2_SUPER_MAGIC2
12769 + || sb->s_magic == MINIX_SUPER_MAGIC
12770 + || sb->s_magic == MINIX_SUPER_MAGIC2;
12776 +static inline int au_test_cifs(struct super_block *sb __maybe_unused)
12778 +#if defined(CONFIG_CIFS_FS) || defined(CONFIGCIFS_FS_MODULE)
12779 + return sb->s_magic == CIFS_MAGIC_NUMBER;
12785 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
12787 +#if defined(CONFIG_FAT_FS) || defined(CONFIG_FAT_FS_MODULE)
12788 + return sb->s_magic == MSDOS_SUPER_MAGIC;
12794 +static inline int au_test_msdos(struct super_block *sb)
12796 + return au_test_fat(sb);
12799 +static inline int au_test_vfat(struct super_block *sb)
12801 + return au_test_fat(sb);
12804 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
12806 +#ifdef CONFIG_SECURITYFS
12807 + return sb->s_magic == SECURITYFS_MAGIC;
12813 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
12815 +#if defined(CONFIG_SQUASHFS) || defined(CONFIG_SQUASHFS_MODULE)
12816 + return sb->s_magic == SQUASHFS_MAGIC;
12822 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
12824 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
12825 + return sb->s_magic == BTRFS_SUPER_MAGIC;
12831 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
12833 +#if defined(CONFIG_XENFS) || defined(CONFIG_XENFS_MODULE)
12834 + return sb->s_magic == XENFS_SUPER_MAGIC;
12840 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
12842 +#ifdef CONFIG_DEBUG_FS
12843 + return sb->s_magic == DEBUGFS_MAGIC;
12849 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
12851 +#if defined(CONFIG_NILFS) || defined(CONFIG_NILFS_MODULE)
12852 + return sb->s_magic == NILFS_SUPER_MAGIC;
12858 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
12860 +#if defined(CONFIG_HFSPLUS_FS) || defined(CONFIG_HFSPLUS_FS_MODULE)
12861 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
12867 +/* ---------------------------------------------------------------------- */
12869 + * they can't be an aufs branch.
12871 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
12874 +#ifndef CONFIG_AUFS_BR_RAMFS
12875 + au_test_ramfs(sb) ||
12877 + au_test_procfs(sb)
12878 + || au_test_sysfs(sb)
12879 + || au_test_configfs(sb)
12880 + || au_test_debugfs(sb)
12881 + || au_test_securityfs(sb)
12882 + || au_test_xenfs(sb)
12883 + || au_test_ecryptfs(sb)
12884 + /* || !strcmp(au_sbtype(sb), "unionfs") */
12885 + || au_test_aufs(sb); /* will be supported in next version */
12888 +static inline int au_test_fs_remote(struct super_block *sb)
12890 + return !au_test_tmpfs(sb)
12891 +#ifdef CONFIG_AUFS_BR_RAMFS
12892 + && !au_test_ramfs(sb)
12894 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
12897 +/* ---------------------------------------------------------------------- */
12900 + * Note: these functions (below) are created after reading ->getattr() in all
12901 + * filesystems under linux/fs. it means we have to do so in every update...
12905 + * some filesystems require getattr to refresh the inode attributes before
12907 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
12908 + * and leave the work for d_revalidate()
12910 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
12912 + return au_test_nfs(sb)
12913 + || au_test_fuse(sb)
12914 + /* || au_test_ocfs2(sb) */ /* untested */
12915 + /* || au_test_btrfs(sb) */ /* untested */
12916 + /* || au_test_coda(sb) */ /* untested */
12917 + /* || au_test_v9fs(sb) */ /* untested */
12922 + * filesystems which don't maintain i_size or i_blocks.
12924 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
12926 + return au_test_xfs(sb)
12927 + || au_test_btrfs(sb)
12928 + || au_test_ubifs(sb)
12929 + || au_test_hfsplus(sb) /* maintained, but incorrect */
12930 + /* || au_test_ext4(sb) */ /* untested */
12931 + /* || au_test_ocfs2(sb) */ /* untested */
12932 + /* || au_test_ocfs2_dlmfs(sb) */ /* untested */
12933 + /* || au_test_sysv(sb) */ /* untested */
12934 + /* || au_test_minix(sb) */ /* untested */
12939 + * filesystems which don't store the correct value in some of their inode
12942 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
12944 + return au_test_fs_bad_iattr_size(sb)
12945 + /* || au_test_cifs(sb) */ /* untested */
12946 + || au_test_fat(sb)
12947 + || au_test_msdos(sb)
12948 + || au_test_vfat(sb);
12951 +/* they don't check i_nlink in link(2) */
12952 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
12954 + return au_test_tmpfs(sb)
12955 +#ifdef CONFIG_AUFS_BR_RAMFS
12956 + || au_test_ramfs(sb)
12958 + || au_test_ubifs(sb)
12959 + || au_test_hfsplus(sb);
12963 + * filesystems which sets S_NOATIME and S_NOCMTIME.
12965 +static inline int au_test_fs_notime(struct super_block *sb)
12967 + return au_test_nfs(sb)
12968 + || au_test_fuse(sb)
12969 + || au_test_ubifs(sb)
12970 + /* || au_test_cifs(sb) */ /* untested */
12975 + * filesystems which requires replacing i_mapping.
12977 +static inline int au_test_fs_bad_mapping(struct super_block *sb)
12979 + return au_test_fuse(sb)
12980 + || au_test_ubifs(sb);
12983 +/* temporary support for i#1 in cramfs */
12984 +static inline int au_test_fs_unique_ino(struct inode *inode)
12986 + if (au_test_cramfs(inode->i_sb))
12987 + return inode->i_ino != 1;
12991 +/* ---------------------------------------------------------------------- */
12994 + * the filesystem where the xino files placed must support i/o after unlink and
12995 + * maintain i_size and i_blocks.
12997 +static inline int au_test_fs_bad_xino(struct super_block *sb)
12999 + return au_test_fs_remote(sb)
13000 + || au_test_fs_bad_iattr_size(sb)
13001 + /* don't want unnecessary work for xino */
13002 + || au_test_aufs(sb)
13003 + || au_test_ecryptfs(sb)
13004 + || au_test_nilfs(sb);
13007 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
13009 + return au_test_tmpfs(sb)
13010 + || au_test_ramfs(sb);
13014 + * test if the @sb is real-readonly.
13016 +static inline int au_test_fs_rr(struct super_block *sb)
13018 + return au_test_squashfs(sb)
13019 + || au_test_iso9660(sb)
13020 + || au_test_cramfs(sb)
13021 + || au_test_romfs(sb);
13024 +#endif /* __KERNEL__ */
13025 +#endif /* __AUFS_FSTYPE_H__ */
13026 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
13027 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
13028 +++ linux/fs/aufs/hfsnotify.c 2013-07-06 13:20:47.750198454 +0200
13031 + * Copyright (C) 2005-2013 Junjiro R. Okajima
13033 + * This program, aufs is free software; you can redistribute it and/or modify
13034 + * it under the terms of the GNU General Public License as published by
13035 + * the Free Software Foundation; either version 2 of the License, or
13036 + * (at your option) any later version.
13038 + * This program is distributed in the hope that it will be useful,
13039 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13040 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13041 + * GNU General Public License for more details.
13043 + * You should have received a copy of the GNU General Public License
13044 + * along with this program; if not, write to the Free Software
13045 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13049 + * fsnotify for the lower directories
13054 +/* FS_IN_IGNORED is unnecessary */
13055 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
13056 + | FS_CREATE | FS_EVENT_ON_CHILD);
13057 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
13058 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
13060 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
13062 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
13065 + au_cache_free_hnotify(hn);
13066 + smp_mb__before_atomic_dec();
13067 + if (atomic64_dec_and_test(&au_hfsn_ifree))
13068 + wake_up(&au_hfsn_wq);
13071 +static int au_hfsn_alloc(struct au_hinode *hinode)
13074 + struct au_hnotify *hn;
13075 + struct super_block *sb;
13076 + struct au_branch *br;
13077 + struct fsnotify_mark *mark;
13078 + aufs_bindex_t bindex;
13080 + hn = hinode->hi_notify;
13081 + sb = hn->hn_aufs_inode->i_sb;
13082 + bindex = au_br_index(sb, hinode->hi_id);
13083 + br = au_sbr(sb, bindex);
13084 + AuDebugOn(!br->br_hfsn);
13086 + mark = &hn->hn_mark;
13087 + fsnotify_init_mark(mark, au_hfsn_free_mark);
13088 + mark->mask = AuHfsnMask;
13090 + * by udba rename or rmdir, aufs assign a new inode to the known
13091 + * h_inode, so specify 1 to allow dups.
13093 + err = fsnotify_add_mark(mark, br->br_hfsn->hfsn_group, hinode->hi_inode,
13094 + /*mnt*/NULL, /*allow_dups*/1);
13095 + /* even if err */
13096 + fsnotify_put_mark(mark);
13101 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
13103 + struct fsnotify_mark *mark;
13104 + unsigned long long ull;
13105 + struct fsnotify_group *group;
13107 + ull = atomic64_inc_return(&au_hfsn_ifree);
13110 + mark = &hn->hn_mark;
13111 + spin_lock(&mark->lock);
13112 + group = mark->group;
13113 + fsnotify_get_group(group);
13114 + spin_unlock(&mark->lock);
13115 + fsnotify_destroy_mark(mark, group);
13116 + fsnotify_put_group(group);
13118 + /* free hn by myself */
13122 +/* ---------------------------------------------------------------------- */
13124 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
13126 + struct fsnotify_mark *mark;
13128 + mark = &hinode->hi_notify->hn_mark;
13129 + spin_lock(&mark->lock);
13131 + AuDebugOn(mark->mask & AuHfsnMask);
13132 + mark->mask |= AuHfsnMask;
13134 + AuDebugOn(!(mark->mask & AuHfsnMask));
13135 + mark->mask &= ~AuHfsnMask;
13137 + spin_unlock(&mark->lock);
13138 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
13141 +/* ---------------------------------------------------------------------- */
13143 +/* #define AuDbgHnotify */
13144 +#ifdef AuDbgHnotify
13145 +static char *au_hfsn_name(u32 mask)
13147 +#ifdef CONFIG_AUFS_DEBUG
13148 +#define test_ret(flag) \
13150 + if (mask & flag) \
13153 + test_ret(FS_ACCESS);
13154 + test_ret(FS_MODIFY);
13155 + test_ret(FS_ATTRIB);
13156 + test_ret(FS_CLOSE_WRITE);
13157 + test_ret(FS_CLOSE_NOWRITE);
13158 + test_ret(FS_OPEN);
13159 + test_ret(FS_MOVED_FROM);
13160 + test_ret(FS_MOVED_TO);
13161 + test_ret(FS_CREATE);
13162 + test_ret(FS_DELETE);
13163 + test_ret(FS_DELETE_SELF);
13164 + test_ret(FS_MOVE_SELF);
13165 + test_ret(FS_UNMOUNT);
13166 + test_ret(FS_Q_OVERFLOW);
13167 + test_ret(FS_IN_IGNORED);
13168 + test_ret(FS_IN_ISDIR);
13169 + test_ret(FS_IN_ONESHOT);
13170 + test_ret(FS_EVENT_ON_CHILD);
13179 +/* ---------------------------------------------------------------------- */
13181 +static void au_hfsn_free_group(struct fsnotify_group *group)
13183 + struct au_br_hfsnotify *hfsn = group->private;
13189 +static int au_hfsn_handle_event(struct fsnotify_group *group,
13190 + struct fsnotify_mark *inode_mark,
13191 + struct fsnotify_mark *vfsmount_mark,
13192 + struct fsnotify_event *event)
13195 + struct au_hnotify *hnotify;
13196 + struct inode *h_dir, *h_inode;
13198 + struct qstr h_child_qstr = QSTR_INIT(event->file_name, event->name_len);
13200 + AuDebugOn(event->data_type != FSNOTIFY_EVENT_INODE);
13203 + /* if FS_UNMOUNT happens, there must be another bug */
13204 + mask = event->mask;
13205 + AuDebugOn(mask & FS_UNMOUNT);
13206 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
13209 + h_dir = event->to_tell;
13210 + h_inode = event->inode;
13211 +#ifdef AuDbgHnotify
13213 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
13214 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
13215 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
13216 + h_dir->i_ino, mask, au_hfsn_name(mask),
13217 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
13218 + /* WARN_ON(1); */
13223 + AuDebugOn(!inode_mark);
13224 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
13225 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
13231 +/* isn't it waste to ask every registered 'group'? */
13232 +/* copied from linux/fs/notify/inotify/inotify_fsnotiry.c */
13233 +/* it should be exported to modules */
13234 +static bool au_hfsn_should_send_event(struct fsnotify_group *group,
13235 + struct inode *h_inode,
13236 + struct fsnotify_mark *inode_mark,
13237 + struct fsnotify_mark *vfsmount_mark,
13238 + __u32 mask, void *data, int data_type)
13240 + mask = (mask & ~FS_EVENT_ON_CHILD);
13241 + return inode_mark->mask & mask;
13244 +static struct fsnotify_ops au_hfsn_ops = {
13245 + .should_send_event = au_hfsn_should_send_event,
13246 + .handle_event = au_hfsn_handle_event,
13247 + .free_group_priv = au_hfsn_free_group
13250 +/* ---------------------------------------------------------------------- */
13252 +static void au_hfsn_fin_br(struct au_branch *br)
13254 + struct au_br_hfsnotify *hfsn;
13256 + hfsn = br->br_hfsn;
13258 + fsnotify_put_group(hfsn->hfsn_group);
13261 +static int au_hfsn_init_br(struct au_branch *br, int perm)
13264 + struct fsnotify_group *group;
13265 + struct au_br_hfsnotify *hfsn;
13268 + br->br_hfsn = NULL;
13269 + if (!au_br_hnotifyable(perm))
13273 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
13274 + if (unlikely(!hfsn))
13278 + group = fsnotify_alloc_group(&au_hfsn_ops);
13279 + if (IS_ERR(group)) {
13280 + err = PTR_ERR(group);
13281 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
13285 + group->private = hfsn;
13286 + hfsn->hfsn_group = group;
13287 + br->br_hfsn = hfsn;
13288 + goto out; /* success */
13296 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
13301 + if (!br->br_hfsn)
13302 + err = au_hfsn_init_br(br, perm);
13307 +/* ---------------------------------------------------------------------- */
13309 +static void au_hfsn_fin(void)
13311 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
13312 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
13315 +const struct au_hnotify_op au_hnotify_op = {
13316 + .ctl = au_hfsn_ctl,
13317 + .alloc = au_hfsn_alloc,
13318 + .free = au_hfsn_free,
13320 + .fin = au_hfsn_fin,
13322 + .reset_br = au_hfsn_reset_br,
13323 + .fin_br = au_hfsn_fin_br,
13324 + .init_br = au_hfsn_init_br
13326 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
13327 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
13328 +++ linux/fs/aufs/hfsplus.c 2013-07-06 13:20:47.750198454 +0200
13331 + * Copyright (C) 2010-2013 Junjiro R. Okajima
13333 + * This program, aufs is free software; you can redistribute it and/or modify
13334 + * it under the terms of the GNU General Public License as published by
13335 + * the Free Software Foundation; either version 2 of the License, or
13336 + * (at your option) any later version.
13338 + * This program is distributed in the hope that it will be useful,
13339 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13340 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13341 + * GNU General Public License for more details.
13343 + * You should have received a copy of the GNU General Public License
13344 + * along with this program; if not, write to the Free Software
13345 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13349 + * special support for filesystems which aqucires an inode mutex
13350 + * at final closing a file, eg, hfsplus.
13352 + * This trick is very simple and stupid, just to open the file before really
13353 + * neceeary open to tell hfsplus that this is not the final closing.
13354 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
13355 + * and au_h_open_post() after releasing it.
13360 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex)
13362 + struct file *h_file;
13363 + struct dentry *h_dentry;
13365 + h_dentry = au_h_dptr(dentry, bindex);
13366 + AuDebugOn(!h_dentry);
13367 + AuDebugOn(!h_dentry->d_inode);
13370 + if (au_test_hfsplus(h_dentry->d_sb)
13371 + && S_ISREG(h_dentry->d_inode->i_mode))
13372 + h_file = au_h_open(dentry, bindex,
13373 + O_RDONLY | O_NOATIME | O_LARGEFILE,
13378 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
13379 + struct file *h_file)
13383 + au_sbr_put(dentry->d_sb, bindex);
13386 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
13387 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
13388 +++ linux/fs/aufs/hnotify.c 2013-07-30 22:42:55.842946719 +0200
13391 + * Copyright (C) 2005-2013 Junjiro R. Okajima
13393 + * This program, aufs is free software; you can redistribute it and/or modify
13394 + * it under the terms of the GNU General Public License as published by
13395 + * the Free Software Foundation; either version 2 of the License, or
13396 + * (at your option) any later version.
13398 + * This program is distributed in the hope that it will be useful,
13399 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13400 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13401 + * GNU General Public License for more details.
13403 + * You should have received a copy of the GNU General Public License
13404 + * along with this program; if not, write to the Free Software
13405 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13409 + * abstraction to notify the direct changes on lower directories
13414 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
13417 + struct au_hnotify *hn;
13420 + hn = au_cache_alloc_hnotify();
13422 + hn->hn_aufs_inode = inode;
13423 + hinode->hi_notify = hn;
13424 + err = au_hnotify_op.alloc(hinode);
13426 + if (unlikely(err)) {
13427 + hinode->hi_notify = NULL;
13428 + au_cache_free_hnotify(hn);
13430 + * The upper dir was removed by udba, but the same named
13431 + * dir left. In this case, aufs assignes a new inode
13432 + * number and set the monitor again.
13433 + * For the lower dir, the old monitnor is still left.
13435 + if (err == -EEXIST)
13444 +void au_hn_free(struct au_hinode *hinode)
13446 + struct au_hnotify *hn;
13448 + hn = hinode->hi_notify;
13450 + hinode->hi_notify = NULL;
13451 + if (au_hnotify_op.free(hinode, hn))
13452 + au_cache_free_hnotify(hn);
13456 +/* ---------------------------------------------------------------------- */
13458 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
13460 + if (hinode->hi_notify)
13461 + au_hnotify_op.ctl(hinode, do_set);
13464 +void au_hn_reset(struct inode *inode, unsigned int flags)
13466 + aufs_bindex_t bindex, bend;
13467 + struct inode *hi;
13468 + struct dentry *iwhdentry;
13470 + bend = au_ibend(inode);
13471 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
13472 + hi = au_h_iptr(inode, bindex);
13476 + /* mutex_lock_nested(&hi->i_mutex, AuLsc_I_CHILD); */
13477 + iwhdentry = au_hi_wh(inode, bindex);
13481 + au_set_h_iptr(inode, bindex, NULL, 0);
13482 + au_set_h_iptr(inode, bindex, au_igrab(hi),
13483 + flags & ~AuHi_XINO);
13486 + /* mutex_unlock(&hi->i_mutex); */
13490 +/* ---------------------------------------------------------------------- */
13492 +static int hn_xino(struct inode *inode, struct inode *h_inode)
13495 + aufs_bindex_t bindex, bend, bfound, bstart;
13496 + struct inode *h_i;
13499 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
13500 + pr_warn("branch root dir was changed\n");
13505 + bend = au_ibend(inode);
13506 + bstart = au_ibstart(inode);
13507 +#if 0 /* reserved for future use */
13508 + if (bindex == bend) {
13509 + /* keep this ino in rename case */
13513 + for (bindex = bstart; bindex <= bend; bindex++)
13514 + if (au_h_iptr(inode, bindex) == h_inode) {
13521 + for (bindex = bstart; bindex <= bend; bindex++) {
13522 + h_i = au_h_iptr(inode, bindex);
13526 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
13527 + /* ignore this error */
13528 + /* bad action? */
13531 + /* children inode number will be broken */
13538 +static int hn_gen_tree(struct dentry *dentry)
13540 + int err, i, j, ndentry;
13541 + struct au_dcsub_pages dpages;
13542 + struct au_dpage *dpage;
13543 + struct dentry **dentries;
13545 + err = au_dpages_init(&dpages, GFP_NOFS);
13546 + if (unlikely(err))
13548 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
13549 + if (unlikely(err))
13552 + for (i = 0; i < dpages.ndpage; i++) {
13553 + dpage = dpages.dpages + i;
13554 + dentries = dpage->dentries;
13555 + ndentry = dpage->ndentry;
13556 + for (j = 0; j < ndentry; j++) {
13557 + struct dentry *d;
13565 + /* todo: reset children xino?
13566 + cached children only? */
13567 + au_iigen_dec(d->d_inode);
13572 + au_dpages_free(&dpages);
13575 + /* discard children */
13576 + dentry_unhash(dentry);
13584 + * return 0 if processed.
13586 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
13587 + const unsigned int isdir)
13590 + struct dentry *d;
13591 + struct qstr *dname;
13594 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
13595 + pr_warn("branch root dir was changed\n");
13601 + AuDebugOn(!name);
13602 + au_iigen_dec(inode);
13603 + spin_lock(&inode->i_lock);
13604 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13605 + spin_lock(&d->d_lock);
13606 + dname = &d->d_name;
13607 + if (dname->len != nlen
13608 + && memcmp(dname->name, name, nlen)) {
13609 + spin_unlock(&d->d_lock);
13614 + spin_unlock(&d->d_lock);
13617 + spin_unlock(&inode->i_lock);
13619 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
13620 + d = d_find_alias(inode);
13622 + au_iigen_dec(inode);
13626 + spin_lock(&d->d_lock);
13627 + dname = &d->d_name;
13628 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
13629 + spin_unlock(&d->d_lock);
13630 + err = hn_gen_tree(d);
13631 + spin_lock(&d->d_lock);
13633 + spin_unlock(&d->d_lock);
13642 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
13645 + struct inode *inode;
13647 + inode = dentry->d_inode;
13648 + if (IS_ROOT(dentry)
13649 + /* || (inode && inode->i_ino == AUFS_ROOT_INO) */
13651 + pr_warn("branch root dir was changed\n");
13657 + au_digen_dec(dentry);
13659 + au_iigen_dec(inode);
13661 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
13663 + err = hn_gen_tree(dentry);
13670 +/* ---------------------------------------------------------------------- */
13672 +/* hnotify job flags */
13673 +#define AuHnJob_XINO0 1
13674 +#define AuHnJob_GEN (1 << 1)
13675 +#define AuHnJob_DIRENT (1 << 2)
13676 +#define AuHnJob_ISDIR (1 << 3)
13677 +#define AuHnJob_TRYXINO0 (1 << 4)
13678 +#define AuHnJob_MNTPNT (1 << 5)
13679 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
13680 +#define au_fset_hnjob(flags, name) \
13681 + do { (flags) |= AuHnJob_##name; } while (0)
13682 +#define au_fclr_hnjob(flags, name) \
13683 + do { (flags) &= ~AuHnJob_##name; } while (0)
13691 +struct au_hnotify_args {
13692 + struct inode *h_dir, *dir, *h_child_inode;
13694 + unsigned int flags[AuHnLast];
13695 + unsigned int h_child_nlen;
13696 + char h_child_name[];
13699 +struct hn_job_args {
13700 + unsigned int flags;
13701 + struct inode *inode, *h_inode, *dir, *h_dir;
13702 + struct dentry *dentry;
13707 +static int hn_job(struct hn_job_args *a)
13709 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
13712 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
13713 + hn_xino(a->inode, a->h_inode); /* ignore this error */
13715 + if (au_ftest_hnjob(a->flags, TRYXINO0)
13718 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
13719 + if (!a->h_inode->i_nlink)
13720 + hn_xino(a->inode, a->h_inode); /* ignore this error */
13721 + mutex_unlock(&a->h_inode->i_mutex);
13724 + /* make the generation obsolete */
13725 + if (au_ftest_hnjob(a->flags, GEN)) {
13728 + err = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
13730 + if (err && a->dentry)
13731 + hn_gen_by_name(a->dentry, isdir);
13732 + /* ignore this error */
13735 + /* make dir entries obsolete */
13736 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
13737 + struct au_vdir *vdir;
13739 + vdir = au_ivdir(a->inode);
13741 + vdir->vd_jiffy = 0;
13742 + /* IMustLock(a->inode); */
13743 + /* a->inode->i_version++; */
13746 + /* can do nothing but warn */
13747 + if (au_ftest_hnjob(a->flags, MNTPNT)
13749 + && d_mountpoint(a->dentry))
13750 + pr_warn("mount-point %.*s is removed or renamed\n",
13751 + AuDLNPair(a->dentry));
13756 +/* ---------------------------------------------------------------------- */
13758 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
13759 + struct inode *dir)
13761 + struct dentry *dentry, *d, *parent;
13762 + struct qstr *dname;
13764 + parent = d_find_alias(dir);
13769 + spin_lock(&parent->d_lock);
13770 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
13771 + /* AuDbg("%.*s\n", AuDLNPair(d)); */
13772 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
13773 + dname = &d->d_name;
13774 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
13775 + goto cont_unlock;
13779 + goto cont_unlock;
13780 + if (d->d_count) {
13781 + dentry = dget_dlock(d);
13782 + spin_unlock(&d->d_lock);
13787 + spin_unlock(&d->d_lock);
13789 + spin_unlock(&parent->d_lock);
13793 + di_write_lock_child(dentry);
13798 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
13799 + aufs_bindex_t bindex, ino_t h_ino)
13801 + struct inode *inode;
13806 + err = au_xino_read(sb, bindex, h_ino, &ino);
13808 + inode = ilookup(sb, ino);
13812 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
13813 + pr_warn("wrong root branch\n");
13819 + ii_write_lock_child(inode);
13825 +static void au_hn_bh(void *_args)
13827 + struct au_hnotify_args *a = _args;
13828 + struct super_block *sb;
13829 + aufs_bindex_t bindex, bend, bfound;
13830 + unsigned char xino, try_iput;
13832 + struct inode *inode;
13834 + struct hn_job_args args;
13835 + struct dentry *dentry;
13836 + struct au_sbinfo *sbinfo;
13838 + AuDebugOn(!_args);
13839 + AuDebugOn(!a->h_dir);
13840 + AuDebugOn(!a->dir);
13841 + AuDebugOn(!a->mask);
13842 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
13843 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
13844 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
13849 + * do not lock a->dir->i_mutex here
13850 + * because of d_revalidate() may cause a deadlock.
13852 + sb = a->dir->i_sb;
13854 + sbinfo = au_sbi(sb);
13855 + AuDebugOn(!sbinfo);
13856 + si_write_lock(sb, AuLock_NOPLMW);
13858 + ii_read_lock_parent(a->dir);
13860 + bend = au_ibend(a->dir);
13861 + for (bindex = au_ibstart(a->dir); bindex <= bend; bindex++)
13862 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
13866 + ii_read_unlock(a->dir);
13867 + if (unlikely(bfound < 0))
13870 + xino = !!au_opt_test(au_mntflags(sb), XINO);
13872 + if (a->h_child_inode)
13873 + h_ino = a->h_child_inode->i_ino;
13875 + if (a->h_child_nlen
13876 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
13877 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
13878 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
13882 + inode = dentry->d_inode;
13883 + if (xino && !inode && h_ino
13884 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
13885 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
13886 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
13887 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
13891 + args.flags = a->flags[AuHn_CHILD];
13892 + args.dentry = dentry;
13893 + args.inode = inode;
13894 + args.h_inode = a->h_child_inode;
13895 + args.dir = a->dir;
13896 + args.h_dir = a->h_dir;
13897 + args.h_name = a->h_child_name;
13898 + args.h_nlen = a->h_child_nlen;
13899 + err = hn_job(&args);
13901 + if (au_di(dentry))
13902 + di_write_unlock(dentry);
13905 + if (inode && try_iput) {
13906 + ii_write_unlock(inode);
13910 + ii_write_lock_parent(a->dir);
13911 + args.flags = a->flags[AuHn_PARENT];
13912 + args.dentry = NULL;
13913 + args.inode = a->dir;
13914 + args.h_inode = a->h_dir;
13916 + args.h_dir = NULL;
13917 + args.h_name = NULL;
13919 + err = hn_job(&args);
13920 + ii_write_unlock(a->dir);
13923 + iput(a->h_child_inode);
13926 + si_write_unlock(sb);
13927 + au_nwt_done(&sbinfo->si_nowait);
13931 +/* ---------------------------------------------------------------------- */
13933 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
13934 + struct qstr *h_child_qstr, struct inode *h_child_inode)
13937 + unsigned int flags[AuHnLast], f;
13938 + unsigned char isdir, isroot, wh;
13939 + struct inode *dir;
13940 + struct au_hnotify_args *args;
13941 + char *p, *h_child_name;
13944 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
13945 + dir = igrab(hnotify->hn_aufs_inode);
13949 + isroot = (dir->i_ino == AUFS_ROOT_INO);
13951 + h_child_name = (void *)h_child_qstr->name;
13952 + len = h_child_qstr->len;
13953 + if (h_child_name) {
13954 + if (len > AUFS_WH_PFX_LEN
13955 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
13956 + h_child_name += AUFS_WH_PFX_LEN;
13957 + len -= AUFS_WH_PFX_LEN;
13963 + if (h_child_inode)
13964 + isdir = !!S_ISDIR(h_child_inode->i_mode);
13965 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
13966 + flags[AuHn_CHILD] = 0;
13968 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
13969 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
13970 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
13971 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
13972 + case FS_MOVED_FROM:
13973 + case FS_MOVED_TO:
13974 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
13975 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
13978 + AuDebugOn(!h_child_name || !h_child_inode);
13983 + * aufs never be able to get this child inode.
13984 + * revalidation should be in d_revalidate()
13985 + * by checking i_nlink, i_generation or d_unhashed().
13987 + AuDebugOn(!h_child_name);
13988 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
13989 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
13997 + h_child_inode = NULL;
14000 + /* iput() and kfree() will be called in au_hnotify() */
14001 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
14002 + if (unlikely(!args)) {
14003 + AuErr1("no memory\n");
14007 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
14008 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
14009 + args->mask = mask;
14011 + args->h_dir = igrab(h_dir);
14012 + if (h_child_inode)
14013 + h_child_inode = igrab(h_child_inode); /* can be NULL */
14014 + args->h_child_inode = h_child_inode;
14015 + args->h_child_nlen = len;
14017 + p = (void *)args;
14018 + p += sizeof(*args);
14019 + memcpy(p, h_child_name, len);
14024 + if (!dir->i_nlink)
14026 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
14027 + if (unlikely(err)) {
14028 + pr_err("wkq %d\n", err);
14029 + iput(args->h_child_inode);
14030 + iput(args->h_dir);
14039 +/* ---------------------------------------------------------------------- */
14041 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
14045 + AuDebugOn(!(udba & AuOptMask_UDBA));
14048 + if (au_hnotify_op.reset_br)
14049 + err = au_hnotify_op.reset_br(udba, br, perm);
14054 +int au_hnotify_init_br(struct au_branch *br, int perm)
14059 + if (au_hnotify_op.init_br)
14060 + err = au_hnotify_op.init_br(br, perm);
14065 +void au_hnotify_fin_br(struct au_branch *br)
14067 + if (au_hnotify_op.fin_br)
14068 + au_hnotify_op.fin_br(br);
14071 +static void au_hn_destroy_cache(void)
14073 + kmem_cache_destroy(au_cachep[AuCache_HNOTIFY]);
14074 + au_cachep[AuCache_HNOTIFY] = NULL;
14077 +int __init au_hnotify_init(void)
14082 + au_cachep[AuCache_HNOTIFY] = AuCache(au_hnotify);
14083 + if (au_cachep[AuCache_HNOTIFY]) {
14085 + if (au_hnotify_op.init)
14086 + err = au_hnotify_op.init();
14087 + if (unlikely(err))
14088 + au_hn_destroy_cache();
14094 +void au_hnotify_fin(void)
14096 + if (au_hnotify_op.fin)
14097 + au_hnotify_op.fin();
14098 + /* cf. au_cache_fin() */
14099 + if (au_cachep[AuCache_HNOTIFY])
14100 + au_hn_destroy_cache();
14102 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
14103 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
14104 +++ linux/fs/aufs/iinfo.c 2013-07-06 13:20:47.750198454 +0200
14107 + * Copyright (C) 2005-2013 Junjiro R. Okajima
14109 + * This program, aufs is free software; you can redistribute it and/or modify
14110 + * it under the terms of the GNU General Public License as published by
14111 + * the Free Software Foundation; either version 2 of the License, or
14112 + * (at your option) any later version.
14114 + * This program is distributed in the hope that it will be useful,
14115 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14116 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14117 + * GNU General Public License for more details.
14119 + * You should have received a copy of the GNU General Public License
14120 + * along with this program; if not, write to the Free Software
14121 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14125 + * inode private data
14130 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
14132 + struct inode *h_inode;
14134 + IiMustAnyLock(inode);
14136 + h_inode = au_ii(inode)->ii_hinode[0 + bindex].hi_inode;
14137 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
14141 +/* todo: hard/soft set? */
14142 +void au_hiput(struct au_hinode *hinode)
14144 + au_hn_free(hinode);
14145 + dput(hinode->hi_whdentry);
14146 + iput(hinode->hi_inode);
14149 +unsigned int au_hi_flags(struct inode *inode, int isdir)
14151 + unsigned int flags;
14152 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
14155 + if (au_opt_test(mnt_flags, XINO))
14156 + au_fset_hi(flags, XINO);
14157 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
14158 + au_fset_hi(flags, HNOTIFY);
14162 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
14163 + struct inode *h_inode, unsigned int flags)
14165 + struct au_hinode *hinode;
14166 + struct inode *hi;
14167 + struct au_iinfo *iinfo = au_ii(inode);
14169 + IiMustWriteLock(inode);
14171 + hinode = iinfo->ii_hinode + bindex;
14172 + hi = hinode->hi_inode;
14173 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
14176 + au_hiput(hinode);
14177 + hinode->hi_inode = h_inode;
14180 + struct super_block *sb = inode->i_sb;
14181 + struct au_branch *br;
14183 + AuDebugOn(inode->i_mode
14184 + && (h_inode->i_mode & S_IFMT)
14185 + != (inode->i_mode & S_IFMT));
14186 + if (bindex == iinfo->ii_bstart)
14187 + au_cpup_igen(inode, h_inode);
14188 + br = au_sbr(sb, bindex);
14189 + hinode->hi_id = br->br_id;
14190 + if (au_ftest_hi(flags, XINO)) {
14191 + err = au_xino_write(sb, bindex, h_inode->i_ino,
14193 + if (unlikely(err))
14194 + AuIOErr1("failed au_xino_write() %d\n", err);
14197 + if (au_ftest_hi(flags, HNOTIFY)
14198 + && au_br_hnotifyable(br->br_perm)) {
14199 + err = au_hn_alloc(hinode, inode);
14200 + if (unlikely(err))
14201 + AuIOErr1("au_hn_alloc() %d\n", err);
14206 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
14207 + struct dentry *h_wh)
14209 + struct au_hinode *hinode;
14211 + IiMustWriteLock(inode);
14213 + hinode = au_ii(inode)->ii_hinode + bindex;
14214 + AuDebugOn(hinode->hi_whdentry);
14215 + hinode->hi_whdentry = h_wh;
14218 +void au_update_iigen(struct inode *inode, int half)
14220 + struct au_iinfo *iinfo;
14221 + struct au_iigen *iigen;
14222 + unsigned int sigen;
14224 + sigen = au_sigen(inode->i_sb);
14225 + iinfo = au_ii(inode);
14226 + iigen = &iinfo->ii_generation;
14227 + spin_lock(&iinfo->ii_genspin);
14228 + iigen->ig_generation = sigen;
14230 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
14232 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
14233 + spin_unlock(&iinfo->ii_genspin);
14236 +/* it may be called at remount time, too */
14237 +void au_update_ibrange(struct inode *inode, int do_put_zero)
14239 + struct au_iinfo *iinfo;
14240 + aufs_bindex_t bindex, bend;
14242 + iinfo = au_ii(inode);
14246 + IiMustWriteLock(inode);
14248 + if (do_put_zero && iinfo->ii_bstart >= 0) {
14249 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
14251 + struct inode *h_i;
14253 + h_i = iinfo->ii_hinode[0 + bindex].hi_inode;
14254 + if (h_i && !h_i->i_nlink)
14255 + au_set_h_iptr(inode, bindex, NULL, 0);
14259 + iinfo->ii_bstart = -1;
14260 + iinfo->ii_bend = -1;
14261 + bend = au_sbend(inode->i_sb);
14262 + for (bindex = 0; bindex <= bend; bindex++)
14263 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
14264 + iinfo->ii_bstart = bindex;
14267 + if (iinfo->ii_bstart >= 0)
14268 + for (bindex = bend; bindex >= iinfo->ii_bstart; bindex--)
14269 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
14270 + iinfo->ii_bend = bindex;
14273 + AuDebugOn(iinfo->ii_bstart > iinfo->ii_bend);
14276 +/* ---------------------------------------------------------------------- */
14278 +void au_icntnr_init_once(void *_c)
14280 + struct au_icntnr *c = _c;
14281 + struct au_iinfo *iinfo = &c->iinfo;
14282 + static struct lock_class_key aufs_ii;
14284 + spin_lock_init(&iinfo->ii_genspin);
14285 + au_rw_init(&iinfo->ii_rwsem);
14286 + au_rw_class(&iinfo->ii_rwsem, &aufs_ii);
14287 + inode_init_once(&c->vfs_inode);
14290 +int au_iinfo_init(struct inode *inode)
14292 + struct au_iinfo *iinfo;
14293 + struct super_block *sb;
14296 + sb = inode->i_sb;
14297 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
14298 + nbr = au_sbend(sb) + 1;
14299 + if (unlikely(nbr <= 0))
14301 + iinfo->ii_hinode = kcalloc(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
14302 + if (iinfo->ii_hinode) {
14303 + au_ninodes_inc(sb);
14304 + for (i = 0; i < nbr; i++)
14305 + iinfo->ii_hinode[i].hi_id = -1;
14307 + iinfo->ii_generation.ig_generation = au_sigen(sb);
14308 + iinfo->ii_bstart = -1;
14309 + iinfo->ii_bend = -1;
14310 + iinfo->ii_vdir = NULL;
14316 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr)
14319 + struct au_hinode *hip;
14321 + AuRwMustWriteLock(&iinfo->ii_rwsem);
14324 + sz = sizeof(*hip) * (iinfo->ii_bend + 1);
14326 + sz = sizeof(*hip);
14327 + hip = au_kzrealloc(iinfo->ii_hinode, sz, sizeof(*hip) * nbr, GFP_NOFS);
14329 + iinfo->ii_hinode = hip;
14336 +void au_iinfo_fin(struct inode *inode)
14338 + struct au_iinfo *iinfo;
14339 + struct au_hinode *hi;
14340 + struct super_block *sb;
14341 + aufs_bindex_t bindex, bend;
14342 + const unsigned char unlinked = !inode->i_nlink;
14344 + iinfo = au_ii(inode);
14345 + /* bad_inode case */
14349 + sb = inode->i_sb;
14350 + au_ninodes_dec(sb);
14351 + if (si_pid_test(sb))
14352 + au_xino_delete_inode(inode, unlinked);
14355 + * it is safe to hide the dependency between sbinfo and
14359 + si_noflush_read_lock(sb);
14360 + au_xino_delete_inode(inode, unlinked);
14361 + si_read_unlock(sb);
14365 + if (iinfo->ii_vdir)
14366 + au_vdir_free(iinfo->ii_vdir);
14368 + bindex = iinfo->ii_bstart;
14369 + if (bindex >= 0) {
14370 + hi = iinfo->ii_hinode + bindex;
14371 + bend = iinfo->ii_bend;
14372 + while (bindex++ <= bend) {
14373 + if (hi->hi_inode)
14378 + kfree(iinfo->ii_hinode);
14379 + iinfo->ii_hinode = NULL;
14380 + AuRwDestroy(&iinfo->ii_rwsem);
14382 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
14383 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
14384 +++ linux/fs/aufs/inode.c 2013-07-06 13:20:47.750198454 +0200
14387 + * Copyright (C) 2005-2013 Junjiro R. Okajima
14389 + * This program, aufs is free software; you can redistribute it and/or modify
14390 + * it under the terms of the GNU General Public License as published by
14391 + * the Free Software Foundation; either version 2 of the License, or
14392 + * (at your option) any later version.
14394 + * This program is distributed in the hope that it will be useful,
14395 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14396 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14397 + * GNU General Public License for more details.
14399 + * You should have received a copy of the GNU General Public License
14400 + * along with this program; if not, write to the Free Software
14401 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14405 + * inode functions
14410 +struct inode *au_igrab(struct inode *inode)
14413 + AuDebugOn(!atomic_read(&inode->i_count));
14419 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
14421 + au_cpup_attr_all(inode, /*force*/0);
14422 + au_update_iigen(inode, /*half*/1);
14424 + inode->i_version++;
14427 +static int au_ii_refresh(struct inode *inode, int *update)
14431 + aufs_bindex_t bindex, new_bindex;
14432 + struct super_block *sb;
14433 + struct au_iinfo *iinfo;
14434 + struct au_hinode *p, *q, tmp;
14436 + IiMustWriteLock(inode);
14439 + sb = inode->i_sb;
14440 + type = inode->i_mode & S_IFMT;
14441 + iinfo = au_ii(inode);
14442 + err = au_ii_realloc(iinfo, au_sbend(sb) + 1);
14443 + if (unlikely(err))
14446 + AuDebugOn(iinfo->ii_bstart < 0);
14447 + p = iinfo->ii_hinode + iinfo->ii_bstart;
14448 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
14450 + if (!p->hi_inode)
14453 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
14454 + new_bindex = au_br_index(sb, p->hi_id);
14455 + if (new_bindex == bindex)
14458 + if (new_bindex < 0) {
14461 + p->hi_inode = NULL;
14465 + if (new_bindex < iinfo->ii_bstart)
14466 + iinfo->ii_bstart = new_bindex;
14467 + if (iinfo->ii_bend < new_bindex)
14468 + iinfo->ii_bend = new_bindex;
14469 + /* swap two lower inode, and loop again */
14470 + q = iinfo->ii_hinode + new_bindex;
14474 + if (tmp.hi_inode) {
14479 + au_update_ibrange(inode, /*do_put_zero*/0);
14480 + e = au_dy_irefresh(inode);
14481 + if (unlikely(e && !err))
14489 +int au_refresh_hinode_self(struct inode *inode)
14493 + err = au_ii_refresh(inode, &update);
14495 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
14501 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
14503 + int err, e, update;
14504 + unsigned int flags;
14506 + aufs_bindex_t bindex, bend;
14507 + unsigned char isdir;
14508 + struct au_hinode *p;
14509 + struct au_iinfo *iinfo;
14511 + err = au_ii_refresh(inode, &update);
14512 + if (unlikely(err))
14516 + iinfo = au_ii(inode);
14517 + p = iinfo->ii_hinode + iinfo->ii_bstart;
14518 + mode = (inode->i_mode & S_IFMT);
14519 + isdir = S_ISDIR(mode);
14520 + flags = au_hi_flags(inode, isdir);
14521 + bend = au_dbend(dentry);
14522 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
14523 + struct inode *h_i;
14524 + struct dentry *h_d;
14526 + h_d = au_h_dptr(dentry, bindex);
14527 + if (!h_d || !h_d->d_inode)
14530 + AuDebugOn(mode != (h_d->d_inode->i_mode & S_IFMT));
14531 + if (iinfo->ii_bstart <= bindex && bindex <= iinfo->ii_bend) {
14532 + h_i = au_h_iptr(inode, bindex);
14534 + if (h_i == h_d->d_inode)
14540 + if (bindex < iinfo->ii_bstart)
14541 + iinfo->ii_bstart = bindex;
14542 + if (iinfo->ii_bend < bindex)
14543 + iinfo->ii_bend = bindex;
14544 + au_set_h_iptr(inode, bindex, au_igrab(h_d->d_inode), flags);
14547 + au_update_ibrange(inode, /*do_put_zero*/0);
14548 + e = au_dy_irefresh(inode);
14549 + if (unlikely(e && !err))
14552 + au_refresh_hinode_attr(inode, update && isdir);
14559 +static int set_inode(struct inode *inode, struct dentry *dentry)
14562 + unsigned int flags;
14564 + aufs_bindex_t bindex, bstart, btail;
14565 + unsigned char isdir;
14566 + struct dentry *h_dentry;
14567 + struct inode *h_inode;
14568 + struct au_iinfo *iinfo;
14570 + IiMustWriteLock(inode);
14574 + bstart = au_dbstart(dentry);
14575 + h_inode = au_h_dptr(dentry, bstart)->d_inode;
14576 + mode = h_inode->i_mode;
14577 + switch (mode & S_IFMT) {
14579 + btail = au_dbtail(dentry);
14580 + inode->i_op = &aufs_iop;
14581 + inode->i_fop = &aufs_file_fop;
14582 + err = au_dy_iaop(inode, bstart, h_inode);
14583 + if (unlikely(err))
14588 + btail = au_dbtaildir(dentry);
14589 + inode->i_op = &aufs_dir_iop;
14590 + inode->i_fop = &aufs_dir_fop;
14593 + btail = au_dbtail(dentry);
14594 + inode->i_op = &aufs_symlink_iop;
14600 + btail = au_dbtail(dentry);
14601 + inode->i_op = &aufs_iop;
14602 + au_init_special_fop(inode, mode, h_inode->i_rdev);
14605 + AuIOErr("Unknown file type 0%o\n", mode);
14610 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
14611 + flags = au_hi_flags(inode, isdir);
14612 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
14613 + && au_ftest_hi(flags, HNOTIFY)
14614 + && dentry->d_name.len > AUFS_WH_PFX_LEN
14615 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
14616 + au_fclr_hi(flags, HNOTIFY);
14617 + iinfo = au_ii(inode);
14618 + iinfo->ii_bstart = bstart;
14619 + iinfo->ii_bend = btail;
14620 + for (bindex = bstart; bindex <= btail; bindex++) {
14621 + h_dentry = au_h_dptr(dentry, bindex);
14623 + au_set_h_iptr(inode, bindex,
14624 + au_igrab(h_dentry->d_inode), flags);
14626 + au_cpup_attr_all(inode, /*force*/1);
14633 + * successful returns with iinfo write_locked
14635 + * zero: success, matched
14636 + * plus: no error, but unmatched
14638 +static int reval_inode(struct inode *inode, struct dentry *dentry)
14641 + unsigned int gen;
14642 + struct au_iigen iigen;
14643 + aufs_bindex_t bindex, bend;
14644 + struct inode *h_inode, *h_dinode;
14647 + * before this function, if aufs got any iinfo lock, it must be only
14648 + * one, the parent dir.
14649 + * it can happen by UDBA and the obsoleted inode number.
14652 + if (unlikely(inode->i_ino == parent_ino(dentry)))
14656 + ii_write_lock_new_child(inode);
14657 + h_dinode = au_h_dptr(dentry, au_dbstart(dentry))->d_inode;
14658 + bend = au_ibend(inode);
14659 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
14660 + h_inode = au_h_iptr(inode, bindex);
14661 + if (!h_inode || h_inode != h_dinode)
14665 + gen = au_iigen(inode, &iigen);
14666 + if (gen == au_digen(dentry)
14667 + && !au_ig_ftest(iigen.ig_flags, HALF_REFRESHED))
14670 + /* fully refresh inode using dentry */
14671 + err = au_refresh_hinode(inode, dentry);
14673 + au_update_iigen(inode, /*half*/0);
14677 + if (unlikely(err))
14678 + ii_write_unlock(inode);
14683 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
14684 + unsigned int d_type, ino_t *ino)
14687 + struct mutex *mtx;
14689 + /* prevent hardlinked inode number from race condition */
14691 + if (d_type != DT_DIR) {
14692 + mtx = &au_sbr(sb, bindex)->br_xino.xi_nondir_mtx;
14695 + err = au_xino_read(sb, bindex, h_ino, ino);
14696 + if (unlikely(err))
14701 + *ino = au_xino_new_ino(sb);
14702 + if (unlikely(!*ino))
14704 + err = au_xino_write(sb, bindex, h_ino, *ino);
14705 + if (unlikely(err))
14711 + mutex_unlock(mtx);
14715 +/* successful returns with iinfo write_locked */
14716 +/* todo: return with unlocked? */
14717 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
14719 + struct inode *inode, *h_inode;
14720 + struct dentry *h_dentry;
14721 + struct super_block *sb;
14722 + struct mutex *mtx;
14723 + ino_t h_ino, ino;
14725 + aufs_bindex_t bstart;
14727 + sb = dentry->d_sb;
14728 + bstart = au_dbstart(dentry);
14729 + h_dentry = au_h_dptr(dentry, bstart);
14730 + h_inode = h_dentry->d_inode;
14731 + h_ino = h_inode->i_ino;
14734 + * stop 'race'-ing between hardlinks under different
14738 + if (!S_ISDIR(h_inode->i_mode))
14739 + mtx = &au_sbr(sb, bstart)->br_xino.xi_nondir_mtx;
14744 + err = au_xino_read(sb, bstart, h_ino, &ino);
14745 + inode = ERR_PTR(err);
14746 + if (unlikely(err))
14750 + ino = au_xino_new_ino(sb);
14751 + if (unlikely(!ino)) {
14752 + inode = ERR_PTR(-EIO);
14757 + AuDbg("i%lu\n", (unsigned long)ino);
14758 + inode = au_iget_locked(sb, ino);
14759 + err = PTR_ERR(inode);
14760 + if (IS_ERR(inode))
14763 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
14764 + if (inode->i_state & I_NEW) {
14765 + /* verbose coding for lock class name */
14766 + if (unlikely(S_ISLNK(h_inode->i_mode)))
14767 + au_rw_class(&au_ii(inode)->ii_rwsem,
14768 + au_lc_key + AuLcSymlink_IIINFO);
14769 + else if (unlikely(S_ISDIR(h_inode->i_mode)))
14770 + au_rw_class(&au_ii(inode)->ii_rwsem,
14771 + au_lc_key + AuLcDir_IIINFO);
14772 + else /* likely */
14773 + au_rw_class(&au_ii(inode)->ii_rwsem,
14774 + au_lc_key + AuLcNonDir_IIINFO);
14776 + ii_write_lock_new_child(inode);
14777 + err = set_inode(inode, dentry);
14779 + unlock_new_inode(inode);
14780 + goto out; /* success */
14784 + * iget_failed() calls iput(), but we need to call
14785 + * ii_write_unlock() after iget_failed(). so dirty hack for
14788 + atomic_inc(&inode->i_count);
14789 + iget_failed(inode);
14790 + ii_write_unlock(inode);
14791 + au_xino_write(sb, bstart, h_ino, /*ino*/0);
14792 + /* ignore this error */
14794 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
14796 + * horrible race condition between lookup, readdir and copyup
14797 + * (or something).
14800 + mutex_unlock(mtx);
14801 + err = reval_inode(inode, dentry);
14802 + if (unlikely(err < 0)) {
14809 + goto out; /* success */
14814 + if (unlikely(au_test_fs_unique_ino(h_dentry->d_inode)))
14815 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
14816 + " b%d, %s, %.*s, hi%lu, i%lu.\n",
14817 + bstart, au_sbtype(h_dentry->d_sb), AuDLNPair(dentry),
14818 + (unsigned long)h_ino, (unsigned long)ino);
14820 + err = au_xino_write(sb, bstart, h_ino, /*ino*/0);
14824 + mutex_unlock(mtx);
14830 + inode = ERR_PTR(err);
14833 + mutex_unlock(mtx);
14837 +/* ---------------------------------------------------------------------- */
14839 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
14840 + struct inode *inode)
14844 + err = au_br_rdonly(au_sbr(sb, bindex));
14846 + /* pseudo-link after flushed may happen out of bounds */
14849 + && au_ibstart(inode) <= bindex
14850 + && bindex <= au_ibend(inode)) {
14852 + * permission check is unnecessary since vfsub routine
14853 + * will be called later
14855 + struct inode *hi = au_h_iptr(inode, bindex);
14857 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
14863 +int au_test_h_perm(struct inode *h_inode, int mask)
14865 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
14867 + return inode_permission(h_inode, mask);
14870 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
14872 + if (au_test_nfs(h_inode->i_sb)
14873 + && (mask & MAY_WRITE)
14874 + && S_ISDIR(h_inode->i_mode))
14875 + mask |= MAY_READ; /* force permission check */
14876 + return au_test_h_perm(h_inode, mask);
14878 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
14879 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
14880 +++ linux/fs/aufs/inode.h 2013-07-06 13:20:47.750198454 +0200
14883 + * Copyright (C) 2005-2013 Junjiro R. Okajima
14885 + * This program, aufs is free software; you can redistribute it and/or modify
14886 + * it under the terms of the GNU General Public License as published by
14887 + * the Free Software Foundation; either version 2 of the License, or
14888 + * (at your option) any later version.
14890 + * This program is distributed in the hope that it will be useful,
14891 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14892 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14893 + * GNU General Public License for more details.
14895 + * You should have received a copy of the GNU General Public License
14896 + * along with this program; if not, write to the Free Software
14897 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14901 + * inode operations
14904 +#ifndef __AUFS_INODE_H__
14905 +#define __AUFS_INODE_H__
14909 +#include <linux/fsnotify.h>
14910 +#include "rwsem.h"
14914 +struct au_hnotify {
14915 +#ifdef CONFIG_AUFS_HNOTIFY
14916 +#ifdef CONFIG_AUFS_HFSNOTIFY
14917 + /* never use fsnotify_add_vfsmount_mark() */
14918 + struct fsnotify_mark hn_mark;
14920 + struct inode *hn_aufs_inode; /* no get/put */
14922 +} ____cacheline_aligned_in_smp;
14924 +struct au_hinode {
14925 + struct inode *hi_inode;
14926 + aufs_bindex_t hi_id;
14927 +#ifdef CONFIG_AUFS_HNOTIFY
14928 + struct au_hnotify *hi_notify;
14931 + /* reference to the copied-up whiteout with get/put */
14932 + struct dentry *hi_whdentry;
14936 +#define AuIG_HALF_REFRESHED 1
14937 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
14938 +#define au_ig_fset(flags, name) \
14939 + do { (flags) |= AuIG_##name; } while (0)
14940 +#define au_ig_fclr(flags, name) \
14941 + do { (flags) &= ~AuIG_##name; } while (0)
14944 + __u32 ig_generation, ig_flags;
14949 + spinlock_t ii_genspin;
14950 + struct au_iigen ii_generation;
14951 + struct super_block *ii_hsb1; /* no get/put */
14953 + struct au_rwsem ii_rwsem;
14954 + aufs_bindex_t ii_bstart, ii_bend;
14956 + struct au_hinode *ii_hinode;
14957 + struct au_vdir *ii_vdir;
14960 +struct au_icntnr {
14961 + struct au_iinfo iinfo;
14962 + struct inode vfs_inode;
14963 +} ____cacheline_aligned_in_smp;
14965 +/* au_pin flags */
14966 +#define AuPin_DI_LOCKED 1
14967 +#define AuPin_MNT_WRITE (1 << 1)
14968 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
14969 +#define au_fset_pin(flags, name) \
14970 + do { (flags) |= AuPin_##name; } while (0)
14971 +#define au_fclr_pin(flags, name) \
14972 + do { (flags) &= ~AuPin_##name; } while (0)
14976 + struct dentry *dentry;
14977 + unsigned int udba;
14978 + unsigned char lsc_di, lsc_hi, flags;
14979 + aufs_bindex_t bindex;
14982 + struct dentry *parent;
14983 + struct au_hinode *hdir;
14984 + struct vfsmount *h_mnt;
14986 + /* temporary unlock/relock for copyup */
14987 + struct dentry *h_dentry, *h_parent;
14988 + struct au_branch *br;
14989 + struct task_struct *task;
14992 +void au_pin_hdir_unlock(struct au_pin *p);
14993 +int au_pin_hdir_relock(struct au_pin *p);
14994 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task);
14995 +void au_pin_hdir_acquire_nest(struct au_pin *p);
14996 +void au_pin_hdir_release(struct au_pin *p);
14998 +/* ---------------------------------------------------------------------- */
15000 +static inline struct au_iinfo *au_ii(struct inode *inode)
15002 + struct au_iinfo *iinfo;
15004 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
15005 + if (iinfo->ii_hinode)
15007 + return NULL; /* debugging bad_inode case */
15010 +/* ---------------------------------------------------------------------- */
15013 +struct inode *au_igrab(struct inode *inode);
15014 +int au_refresh_hinode_self(struct inode *inode);
15015 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
15016 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
15017 + unsigned int d_type, ino_t *ino);
15018 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
15019 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
15020 + struct inode *inode);
15021 +int au_test_h_perm(struct inode *h_inode, int mask);
15022 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
15024 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
15025 + ino_t h_ino, unsigned int d_type, ino_t *ino)
15027 +#ifdef CONFIG_AUFS_SHWH
15028 + return au_ino(sb, bindex, h_ino, d_type, ino);
15035 +extern struct inode_operations aufs_iop, aufs_symlink_iop, aufs_dir_iop;
15037 +/* au_wr_dir flags */
15038 +#define AuWrDir_ADD_ENTRY 1
15039 +#define AuWrDir_TMP_WHENTRY (1 << 1)
15040 +#define AuWrDir_ISDIR (1 << 2)
15041 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
15042 +#define au_fset_wrdir(flags, name) \
15043 + do { (flags) |= AuWrDir_##name; } while (0)
15044 +#define au_fclr_wrdir(flags, name) \
15045 + do { (flags) &= ~AuWrDir_##name; } while (0)
15047 +struct au_wr_dir_args {
15048 + aufs_bindex_t force_btgt;
15049 + unsigned char flags;
15051 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
15052 + struct au_wr_dir_args *args);
15054 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
15055 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
15056 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
15057 + unsigned int udba, unsigned char flags);
15058 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
15059 + unsigned int udba, unsigned char flags) __must_check;
15060 +int au_do_pin(struct au_pin *pin) __must_check;
15061 +void au_unpin(struct au_pin *pin);
15064 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
15065 + struct dentry *h_parent, int isdir);
15066 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
15068 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
15069 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
15071 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
15072 + struct dentry *dentry);
15073 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
15076 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
15077 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
15078 + struct dentry *h_parent, int isdir);
15079 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
15080 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
15083 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
15084 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
15085 + struct inode *dir, struct dentry *dentry);
15088 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
15089 +void au_hiput(struct au_hinode *hinode);
15090 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
15091 + struct dentry *h_wh);
15092 +unsigned int au_hi_flags(struct inode *inode, int isdir);
15094 +/* hinode flags */
15095 +#define AuHi_XINO 1
15096 +#define AuHi_HNOTIFY (1 << 1)
15097 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
15098 +#define au_fset_hi(flags, name) \
15099 + do { (flags) |= AuHi_##name; } while (0)
15100 +#define au_fclr_hi(flags, name) \
15101 + do { (flags) &= ~AuHi_##name; } while (0)
15103 +#ifndef CONFIG_AUFS_HNOTIFY
15104 +#undef AuHi_HNOTIFY
15105 +#define AuHi_HNOTIFY 0
15108 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
15109 + struct inode *h_inode, unsigned int flags);
15111 +void au_update_iigen(struct inode *inode, int half);
15112 +void au_update_ibrange(struct inode *inode, int do_put_zero);
15114 +void au_icntnr_init_once(void *_c);
15115 +int au_iinfo_init(struct inode *inode);
15116 +void au_iinfo_fin(struct inode *inode);
15117 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr);
15119 +#ifdef CONFIG_PROC_FS
15121 +int au_plink_maint(struct super_block *sb, int flags);
15122 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
15123 +int au_plink_maint_enter(struct super_block *sb);
15124 +#ifdef CONFIG_AUFS_DEBUG
15125 +void au_plink_list(struct super_block *sb);
15127 +AuStubVoid(au_plink_list, struct super_block *sb)
15129 +int au_plink_test(struct inode *inode);
15130 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
15131 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
15132 + struct dentry *h_dentry);
15133 +void au_plink_put(struct super_block *sb, int verbose);
15134 +void au_plink_clean(struct super_block *sb, int verbose);
15135 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
15137 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
15138 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
15139 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
15140 +AuStubVoid(au_plink_list, struct super_block *sb);
15141 +AuStubInt0(au_plink_test, struct inode *inode);
15142 +AuStub(struct dentry *, au_plink_lkup, return NULL,
15143 + struct inode *inode, aufs_bindex_t bindex);
15144 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
15145 + struct dentry *h_dentry);
15146 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
15147 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
15148 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
15149 +#endif /* CONFIG_PROC_FS */
15151 +/* ---------------------------------------------------------------------- */
15153 +/* lock subclass for iinfo */
15155 + AuLsc_II_CHILD, /* child first */
15156 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
15157 + AuLsc_II_CHILD3, /* copyup dirs */
15158 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
15159 + AuLsc_II_PARENT2,
15160 + AuLsc_II_PARENT3, /* copyup dirs */
15161 + AuLsc_II_NEW_CHILD
15165 + * ii_read_lock_child, ii_write_lock_child,
15166 + * ii_read_lock_child2, ii_write_lock_child2,
15167 + * ii_read_lock_child3, ii_write_lock_child3,
15168 + * ii_read_lock_parent, ii_write_lock_parent,
15169 + * ii_read_lock_parent2, ii_write_lock_parent2,
15170 + * ii_read_lock_parent3, ii_write_lock_parent3,
15171 + * ii_read_lock_new_child, ii_write_lock_new_child,
15173 +#define AuReadLockFunc(name, lsc) \
15174 +static inline void ii_read_lock_##name(struct inode *i) \
15176 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
15179 +#define AuWriteLockFunc(name, lsc) \
15180 +static inline void ii_write_lock_##name(struct inode *i) \
15182 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
15185 +#define AuRWLockFuncs(name, lsc) \
15186 + AuReadLockFunc(name, lsc) \
15187 + AuWriteLockFunc(name, lsc)
15189 +AuRWLockFuncs(child, CHILD);
15190 +AuRWLockFuncs(child2, CHILD2);
15191 +AuRWLockFuncs(child3, CHILD3);
15192 +AuRWLockFuncs(parent, PARENT);
15193 +AuRWLockFuncs(parent2, PARENT2);
15194 +AuRWLockFuncs(parent3, PARENT3);
15195 +AuRWLockFuncs(new_child, NEW_CHILD);
15197 +#undef AuReadLockFunc
15198 +#undef AuWriteLockFunc
15199 +#undef AuRWLockFuncs
15202 + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock
15204 +AuSimpleUnlockRwsemFuncs(ii, struct inode *i, &au_ii(i)->ii_rwsem);
15206 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
15207 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
15208 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
15210 +/* ---------------------------------------------------------------------- */
15212 +static inline void au_icntnr_init(struct au_icntnr *c)
15214 +#ifdef CONFIG_AUFS_DEBUG
15215 + c->vfs_inode.i_mode = 0;
15219 +static inline unsigned int au_iigen(struct inode *inode, struct au_iigen *iigen)
15221 + unsigned int gen;
15222 + struct au_iinfo *iinfo;
15224 + iinfo = au_ii(inode);
15225 + spin_lock(&iinfo->ii_genspin);
15227 + *iigen = iinfo->ii_generation;
15228 + gen = iinfo->ii_generation.ig_generation;
15229 + spin_unlock(&iinfo->ii_genspin);
15234 +/* tiny test for inode number */
15235 +/* tmpfs generation is too rough */
15236 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
15238 + struct au_iinfo *iinfo;
15240 + iinfo = au_ii(inode);
15241 + AuRwMustAnyLock(&iinfo->ii_rwsem);
15242 + return !(iinfo->ii_hsb1 == h_inode->i_sb
15243 + && iinfo->ii_higen == h_inode->i_generation);
15246 +static inline void au_iigen_dec(struct inode *inode)
15248 + struct au_iinfo *iinfo;
15250 + iinfo = au_ii(inode);
15251 + spin_lock(&iinfo->ii_genspin);
15252 + iinfo->ii_generation.ig_generation--;
15253 + spin_unlock(&iinfo->ii_genspin);
15256 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
15261 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
15267 +/* ---------------------------------------------------------------------- */
15269 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
15270 + aufs_bindex_t bindex)
15272 + IiMustAnyLock(inode);
15273 + return au_ii(inode)->ii_hinode[0 + bindex].hi_id;
15276 +static inline aufs_bindex_t au_ibstart(struct inode *inode)
15278 + IiMustAnyLock(inode);
15279 + return au_ii(inode)->ii_bstart;
15282 +static inline aufs_bindex_t au_ibend(struct inode *inode)
15284 + IiMustAnyLock(inode);
15285 + return au_ii(inode)->ii_bend;
15288 +static inline struct au_vdir *au_ivdir(struct inode *inode)
15290 + IiMustAnyLock(inode);
15291 + return au_ii(inode)->ii_vdir;
15294 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
15296 + IiMustAnyLock(inode);
15297 + return au_ii(inode)->ii_hinode[0 + bindex].hi_whdentry;
15300 +static inline void au_set_ibstart(struct inode *inode, aufs_bindex_t bindex)
15302 + IiMustWriteLock(inode);
15303 + au_ii(inode)->ii_bstart = bindex;
15306 +static inline void au_set_ibend(struct inode *inode, aufs_bindex_t bindex)
15308 + IiMustWriteLock(inode);
15309 + au_ii(inode)->ii_bend = bindex;
15312 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
15314 + IiMustWriteLock(inode);
15315 + au_ii(inode)->ii_vdir = vdir;
15318 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
15320 + IiMustAnyLock(inode);
15321 + return au_ii(inode)->ii_hinode + bindex;
15324 +/* ---------------------------------------------------------------------- */
15326 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
15329 + return pin->parent;
15333 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
15335 + if (pin && pin->hdir)
15336 + return pin->hdir->hi_inode;
15340 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
15343 + return pin->hdir;
15347 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
15350 + pin->dentry = dentry;
15353 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
15354 + unsigned char lflag)
15358 + au_fset_pin(pin->flags, DI_LOCKED);
15360 + au_fclr_pin(pin->flags, DI_LOCKED);
15364 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
15367 + dput(pin->parent);
15368 + pin->parent = dget(parent);
15372 +/* ---------------------------------------------------------------------- */
15375 +#ifdef CONFIG_AUFS_HNOTIFY
15376 +struct au_hnotify_op {
15377 + void (*ctl)(struct au_hinode *hinode, int do_set);
15378 + int (*alloc)(struct au_hinode *hinode);
15381 + * if it returns true, the the caller should free hinode->hi_notify,
15382 + * otherwise ->free() frees it.
15384 + int (*free)(struct au_hinode *hinode,
15385 + struct au_hnotify *hn) __must_check;
15387 + void (*fin)(void);
15388 + int (*init)(void);
15390 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
15391 + void (*fin_br)(struct au_branch *br);
15392 + int (*init_br)(struct au_branch *br, int perm);
15396 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
15397 +void au_hn_free(struct au_hinode *hinode);
15398 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
15399 +void au_hn_reset(struct inode *inode, unsigned int flags);
15400 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
15401 + struct qstr *h_child_qstr, struct inode *h_child_inode);
15402 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
15403 +int au_hnotify_init_br(struct au_branch *br, int perm);
15404 +void au_hnotify_fin_br(struct au_branch *br);
15405 +int __init au_hnotify_init(void);
15406 +void au_hnotify_fin(void);
15409 +extern const struct au_hnotify_op au_hnotify_op;
15412 +void au_hn_init(struct au_hinode *hinode)
15414 + hinode->hi_notify = NULL;
15417 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
15419 + return hinode->hi_notify;
15424 +int au_hn_alloc(struct au_hinode *hinode __maybe_unused,
15425 + struct inode *inode __maybe_unused)
15427 + return -EOPNOTSUPP;
15430 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
15435 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
15436 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
15437 + int do_set __maybe_unused)
15438 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
15439 + unsigned int flags __maybe_unused)
15440 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
15441 + struct au_branch *br __maybe_unused,
15442 + int perm __maybe_unused)
15443 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
15444 + int perm __maybe_unused)
15445 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
15446 +AuStubInt0(__init au_hnotify_init, void)
15447 +AuStubVoid(au_hnotify_fin, void)
15448 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
15449 +#endif /* CONFIG_AUFS_HNOTIFY */
15451 +static inline void au_hn_suspend(struct au_hinode *hdir)
15453 + au_hn_ctl(hdir, /*do_set*/0);
15456 +static inline void au_hn_resume(struct au_hinode *hdir)
15458 + au_hn_ctl(hdir, /*do_set*/1);
15461 +static inline void au_hn_imtx_lock(struct au_hinode *hdir)
15463 + mutex_lock(&hdir->hi_inode->i_mutex);
15464 + au_hn_suspend(hdir);
15467 +static inline void au_hn_imtx_lock_nested(struct au_hinode *hdir,
15468 + unsigned int sc __maybe_unused)
15470 + mutex_lock_nested(&hdir->hi_inode->i_mutex, sc);
15471 + au_hn_suspend(hdir);
15474 +static inline void au_hn_imtx_unlock(struct au_hinode *hdir)
15476 + au_hn_resume(hdir);
15477 + mutex_unlock(&hdir->hi_inode->i_mutex);
15480 +#endif /* __KERNEL__ */
15481 +#endif /* __AUFS_INODE_H__ */
15482 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
15483 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
15484 +++ linux/fs/aufs/ioctl.c 2013-08-23 23:59:39.634916914 +0200
15487 + * Copyright (C) 2005-2013 Junjiro R. Okajima
15489 + * This program, aufs is free software; you can redistribute it and/or modify
15490 + * it under the terms of the GNU General Public License as published by
15491 + * the Free Software Foundation; either version 2 of the License, or
15492 + * (at your option) any later version.
15494 + * This program is distributed in the hope that it will be useful,
15495 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15496 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15497 + * GNU General Public License for more details.
15499 + * You should have received a copy of the GNU General Public License
15500 + * along with this program; if not, write to the Free Software
15501 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15506 + * plink-management and readdir in userspace.
15507 + * assist the pathconf(3) wrapper library.
15511 +#include <linux/compat.h>
15512 +#include <linux/file.h>
15515 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
15518 + aufs_bindex_t wbi, bindex, bend;
15519 + struct file *h_file;
15520 + struct super_block *sb;
15521 + struct dentry *root;
15522 + struct au_branch *br;
15523 + struct aufs_wbr_fd wbrfd = {
15524 + .oflags = au_dir_roflags,
15527 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
15528 + | O_NOATIME | O_CLOEXEC;
15530 + AuDebugOn(wbrfd.oflags & ~valid);
15533 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
15534 + if (unlikely(err)) {
15540 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
15541 + wbrfd.oflags |= au_dir_roflags;
15542 + AuDbg("0%o\n", wbrfd.oflags);
15543 + if (unlikely(wbrfd.oflags & ~valid))
15547 + fd = get_unused_fd();
15549 + if (unlikely(fd < 0))
15552 + h_file = ERR_PTR(-EINVAL);
15555 + sb = path->dentry->d_sb;
15556 + root = sb->s_root;
15557 + aufs_read_lock(root, AuLock_IR);
15558 + bend = au_sbend(sb);
15559 + if (wbrfd.brid >= 0) {
15560 + wbi = au_br_index(sb, wbrfd.brid);
15561 + if (unlikely(wbi < 0 || wbi > bend))
15565 + h_file = ERR_PTR(-ENOENT);
15566 + br = au_sbr(sb, wbi);
15567 + if (!au_br_writable(br->br_perm)) {
15571 + bindex = wbi + 1;
15573 + for (; bindex <= bend; bindex++) {
15574 + br = au_sbr(sb, bindex);
15575 + if (au_br_writable(br->br_perm)) {
15577 + br = au_sbr(sb, wbi);
15582 + AuDbg("wbi %d\n", wbi);
15584 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL);
15587 + aufs_read_unlock(root, AuLock_IR);
15588 + err = PTR_ERR(h_file);
15589 + if (IS_ERR(h_file))
15592 + atomic_dec(&br->br_count); /* cf. au_h_open() */
15593 + fd_install(fd, h_file);
15595 + goto out; /* success */
15598 + put_unused_fd(fd);
15604 +/* ---------------------------------------------------------------------- */
15606 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
15611 + case AUFS_CTL_RDU:
15612 + case AUFS_CTL_RDU_INO:
15613 + err = au_rdu_ioctl(file, cmd, arg);
15616 + case AUFS_CTL_WBR_FD:
15617 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
15620 + case AUFS_CTL_IBUSY:
15621 + err = au_ibusy_ioctl(file, arg);
15625 + /* do not call the lower */
15626 + AuDbg("0x%x\n", cmd);
15634 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
15639 + case AUFS_CTL_MVDOWN:
15640 + WARN_ONCE(1, "move-down is still testing...\n");
15641 + err = au_mvdown(file->f_dentry, (void __user *)arg);
15644 + case AUFS_CTL_WBR_FD:
15645 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
15649 + /* do not call the lower */
15650 + AuDbg("0x%x\n", cmd);
15658 +#ifdef CONFIG_COMPAT
15659 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15660 + unsigned long arg)
15665 + case AUFS_CTL_RDU:
15666 + case AUFS_CTL_RDU_INO:
15667 + err = au_rdu_compat_ioctl(file, cmd, arg);
15670 + case AUFS_CTL_IBUSY:
15671 + err = au_ibusy_compat_ioctl(file, arg);
15675 + err = aufs_ioctl_dir(file, cmd, arg);
15682 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15683 + unsigned long arg)
15685 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
15688 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
15689 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
15690 +++ linux/fs/aufs/i_op_add.c 2013-08-23 23:59:39.634916914 +0200
15693 + * Copyright (C) 2005-2013 Junjiro R. Okajima
15695 + * This program, aufs is free software; you can redistribute it and/or modify
15696 + * it under the terms of the GNU General Public License as published by
15697 + * the Free Software Foundation; either version 2 of the License, or
15698 + * (at your option) any later version.
15700 + * This program is distributed in the hope that it will be useful,
15701 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15702 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15703 + * GNU General Public License for more details.
15705 + * You should have received a copy of the GNU General Public License
15706 + * along with this program; if not, write to the Free Software
15707 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15711 + * inode operations (add entry)
15717 + * final procedure of adding a new entry, except link(2).
15718 + * remove whiteout, instantiate, copyup the parent dir's times and size
15719 + * and update version.
15720 + * if it failed, re-create the removed whiteout.
15722 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
15723 + struct dentry *wh_dentry, struct dentry *dentry)
15726 + aufs_bindex_t bwh;
15727 + struct path h_path;
15728 + struct inode *inode, *h_dir;
15729 + struct dentry *wh;
15733 + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
15734 + IMustLock(h_dir);
15735 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
15736 + bwh = au_dbwh(dentry);
15737 + h_path.dentry = wh_dentry;
15738 + h_path.mnt = au_sbr_mnt(dir->i_sb, bindex);
15739 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
15741 + if (unlikely(err))
15745 + inode = au_new_inode(dentry, /*must_new*/1);
15746 + if (!IS_ERR(inode)) {
15747 + d_instantiate(dentry, inode);
15748 + dir = dentry->d_parent->d_inode; /* dir inode is locked */
15750 + if (au_ibstart(dir) == au_dbstart(dentry))
15751 + au_cpup_attr_timesizes(dir);
15752 + dir->i_version++;
15753 + return 0; /* success */
15756 + err = PTR_ERR(inode);
15761 + /* dir inode is locked */
15762 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
15763 + rerr = PTR_ERR(wh);
15764 + if (IS_ERR(wh)) {
15765 + AuIOErr("%.*s reverting whiteout failed(%d, %d)\n",
15766 + AuDLNPair(dentry), err, rerr);
15775 +static int au_d_may_add(struct dentry *dentry)
15780 + if (unlikely(d_unhashed(dentry)))
15782 + if (unlikely(dentry->d_inode))
15788 + * simple tests for the adding inode operations.
15789 + * following the checks in vfs, plus the parent-child relationship.
15791 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
15792 + struct dentry *h_parent, int isdir)
15796 + struct dentry *h_dentry;
15797 + struct inode *h_inode;
15799 + err = -ENAMETOOLONG;
15800 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
15803 + h_dentry = au_h_dptr(dentry, bindex);
15804 + h_inode = h_dentry->d_inode;
15805 + if (!dentry->d_inode) {
15807 + if (unlikely(h_inode))
15810 + /* rename(2) case */
15812 + if (unlikely(!h_inode || !h_inode->i_nlink))
15815 + h_mode = h_inode->i_mode;
15818 + if (unlikely(S_ISDIR(h_mode)))
15820 + } else if (unlikely(!S_ISDIR(h_mode))) {
15827 + /* expected parent dir is locked */
15828 + if (unlikely(h_parent != h_dentry->d_parent))
15837 + * initial procedure of adding a new entry.
15838 + * prepare writable branch and the parent dir, lock it,
15839 + * and lookup whiteout for the new entry.
15841 +static struct dentry*
15842 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
15843 + struct dentry *src_dentry, struct au_pin *pin,
15844 + struct au_wr_dir_args *wr_dir_args)
15846 + struct dentry *wh_dentry, *h_parent;
15847 + struct super_block *sb;
15848 + struct au_branch *br;
15850 + unsigned int udba;
15851 + aufs_bindex_t bcpup;
15853 + AuDbg("%.*s\n", AuDLNPair(dentry));
15855 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
15857 + wh_dentry = ERR_PTR(err);
15858 + if (unlikely(err < 0))
15861 + sb = dentry->d_sb;
15862 + udba = au_opt_udba(sb);
15863 + err = au_pin(pin, dentry, bcpup, udba,
15864 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
15865 + wh_dentry = ERR_PTR(err);
15866 + if (unlikely(err))
15869 + h_parent = au_pinned_h_parent(pin);
15870 + if (udba != AuOpt_UDBA_NONE
15871 + && au_dbstart(dentry) == bcpup)
15872 + err = au_may_add(dentry, bcpup, h_parent,
15873 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
15874 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
15875 + err = -ENAMETOOLONG;
15876 + wh_dentry = ERR_PTR(err);
15877 + if (unlikely(err))
15880 + br = au_sbr(sb, bcpup);
15882 + struct path tmp = {
15883 + .dentry = h_parent,
15884 + .mnt = au_br_mnt(br)
15886 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
15889 + wh_dentry = NULL;
15890 + if (bcpup != au_dbwh(dentry))
15891 + goto out; /* success */
15893 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
15896 + if (IS_ERR(wh_dentry))
15899 + return wh_dentry;
15902 +/* ---------------------------------------------------------------------- */
15904 +enum { Mknod, Symlink, Creat };
15905 +struct simple_arg {
15913 + const char *symname;
15922 +static int add_simple(struct inode *dir, struct dentry *dentry,
15923 + struct simple_arg *arg)
15926 + aufs_bindex_t bstart;
15927 + unsigned char created;
15928 + struct dentry *wh_dentry, *parent;
15929 + struct inode *h_dir;
15930 + /* to reuduce stack size */
15932 + struct au_dtime dt;
15933 + struct au_pin pin;
15934 + struct path h_path;
15935 + struct au_wr_dir_args wr_dir_args;
15938 + AuDbg("%.*s\n", AuDLNPair(dentry));
15942 + a = kmalloc(sizeof(*a), GFP_NOFS);
15943 + if (unlikely(!a))
15945 + a->wr_dir_args.force_btgt = -1;
15946 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
15948 + parent = dentry->d_parent; /* dir inode is locked */
15949 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
15950 + if (unlikely(err))
15952 + err = au_d_may_add(dentry);
15953 + if (unlikely(err))
15955 + di_write_lock_parent(parent);
15956 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
15957 + &a->pin, &a->wr_dir_args);
15958 + err = PTR_ERR(wh_dentry);
15959 + if (IS_ERR(wh_dentry))
15962 + bstart = au_dbstart(dentry);
15963 + a->h_path.dentry = au_h_dptr(dentry, bstart);
15964 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
15965 + h_dir = au_pinned_h_dir(&a->pin);
15966 + switch (arg->type) {
15968 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
15969 + arg->u.c.want_excl);
15972 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
15975 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
15983 + err = epilog(dir, bstart, wh_dentry, dentry);
15986 + if (unlikely(created && err && a->h_path.dentry->d_inode)) {
15988 + rerr = vfsub_unlink(h_dir, &a->h_path, /*force*/0);
15990 + AuIOErr("%.*s revert failure(%d, %d)\n",
15991 + AuDLNPair(dentry), err, rerr);
15994 + au_dtime_revert(&a->dt);
15997 + au_unpin(&a->pin);
16001 + di_write_unlock(parent);
16003 + if (unlikely(err)) {
16004 + au_update_dbstart(dentry);
16007 + aufs_read_unlock(dentry, AuLock_DW);
16014 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
16017 + struct simple_arg arg = {
16024 + return add_simple(dir, dentry, &arg);
16027 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
16029 + struct simple_arg arg = {
16031 + .u.s.symname = symname
16033 + return add_simple(dir, dentry, &arg);
16036 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
16039 + struct simple_arg arg = {
16043 + .want_excl = want_excl
16046 + return add_simple(dir, dentry, &arg);
16049 +/* ---------------------------------------------------------------------- */
16051 +struct au_link_args {
16052 + aufs_bindex_t bdst, bsrc;
16053 + struct au_pin pin;
16054 + struct path h_path;
16055 + struct dentry *src_parent, *parent;
16058 +static int au_cpup_before_link(struct dentry *src_dentry,
16059 + struct au_link_args *a)
16062 + struct dentry *h_src_dentry;
16063 + struct au_cp_generic cpg = {
16064 + .dentry = src_dentry,
16069 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
16072 + di_read_lock_parent(a->src_parent, AuLock_IR);
16073 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
16074 + if (unlikely(err))
16077 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
16078 + err = au_pin(&a->pin, src_dentry, a->bdst,
16079 + au_opt_udba(src_dentry->d_sb),
16080 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
16081 + if (unlikely(err))
16084 + err = au_sio_cpup_simple(&cpg);
16085 + au_unpin(&a->pin);
16088 + di_read_unlock(a->src_parent, AuLock_IR);
16092 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
16093 + struct au_link_args *a)
16096 + unsigned char plink;
16097 + aufs_bindex_t bend;
16098 + struct dentry *h_src_dentry;
16099 + struct inode *h_inode, *inode;
16100 + struct super_block *sb;
16101 + struct file *h_file;
16105 + sb = src_dentry->d_sb;
16106 + inode = src_dentry->d_inode;
16107 + if (au_ibstart(inode) <= a->bdst)
16108 + h_inode = au_h_iptr(inode, a->bdst);
16109 + if (!h_inode || !h_inode->i_nlink) {
16110 + /* copyup src_dentry as the name of dentry. */
16111 + bend = au_dbend(dentry);
16112 + if (bend < a->bsrc)
16113 + au_set_dbend(dentry, a->bsrc);
16114 + au_set_h_dptr(dentry, a->bsrc,
16115 + dget(au_h_dptr(src_dentry, a->bsrc)));
16116 + dget(a->h_path.dentry);
16117 + au_set_h_dptr(dentry, a->bdst, NULL);
16118 + dentry->d_inode = src_dentry->d_inode; /* tmp */
16119 + h_file = au_h_open_pre(dentry, a->bsrc);
16120 + if (IS_ERR(h_file))
16121 + err = PTR_ERR(h_file);
16123 + struct au_cp_generic cpg = {
16124 + .dentry = dentry,
16129 + .flags = AuCpup_KEEPLINO
16131 + err = au_sio_cpup_simple(&cpg);
16132 + au_h_open_post(dentry, a->bsrc, h_file);
16134 + dput(a->h_path.dentry);
16135 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
16137 + au_set_h_dptr(dentry, a->bdst,
16138 + a->h_path.dentry);
16140 + dentry->d_inode = NULL; /* restore */
16141 + au_set_h_dptr(dentry, a->bsrc, NULL);
16142 + au_set_dbend(dentry, bend);
16144 + /* the inode of src_dentry already exists on a.bdst branch */
16145 + h_src_dentry = d_find_alias(h_inode);
16146 + if (!h_src_dentry && au_plink_test(inode)) {
16148 + h_src_dentry = au_plink_lkup(inode, a->bdst);
16149 + err = PTR_ERR(h_src_dentry);
16150 + if (IS_ERR(h_src_dentry))
16153 + if (unlikely(!h_src_dentry->d_inode)) {
16154 + dput(h_src_dentry);
16155 + h_src_dentry = NULL;
16159 + if (h_src_dentry) {
16160 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
16162 + dput(h_src_dentry);
16164 + AuIOErr("no dentry found for hi%lu on b%d\n",
16165 + h_inode->i_ino, a->bdst);
16170 + if (!err && !plink)
16171 + au_plink_append(inode, a->bdst, a->h_path.dentry);
16178 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
16179 + struct dentry *dentry)
16182 + struct au_dtime dt;
16183 + struct au_link_args *a;
16184 + struct dentry *wh_dentry, *h_src_dentry;
16185 + struct inode *inode;
16186 + struct super_block *sb;
16187 + struct au_wr_dir_args wr_dir_args = {
16188 + /* .force_btgt = -1, */
16189 + .flags = AuWrDir_ADD_ENTRY
16193 + inode = src_dentry->d_inode;
16194 + IMustLock(inode);
16197 + a = kzalloc(sizeof(*a), GFP_NOFS);
16198 + if (unlikely(!a))
16201 + a->parent = dentry->d_parent; /* dir inode is locked */
16202 + err = aufs_read_and_write_lock2(dentry, src_dentry,
16203 + AuLock_NOPLM | AuLock_GEN);
16204 + if (unlikely(err))
16206 + err = au_d_hashed_positive(src_dentry);
16207 + if (unlikely(err))
16209 + err = au_d_may_add(dentry);
16210 + if (unlikely(err))
16213 + a->src_parent = dget_parent(src_dentry);
16214 + wr_dir_args.force_btgt = au_ibstart(inode);
16216 + di_write_lock_parent(a->parent);
16217 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
16218 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
16220 + err = PTR_ERR(wh_dentry);
16221 + if (IS_ERR(wh_dentry))
16225 + sb = dentry->d_sb;
16226 + a->bdst = au_dbstart(dentry);
16227 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
16228 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
16229 + a->bsrc = au_ibstart(inode);
16230 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
16231 + if (!h_src_dentry) {
16232 + a->bsrc = au_dbstart(src_dentry);
16233 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
16234 + AuDebugOn(!h_src_dentry);
16235 + } else if (IS_ERR(h_src_dentry))
16238 + if (au_opt_test(au_mntflags(sb), PLINK)) {
16239 + if (a->bdst < a->bsrc
16240 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
16241 + err = au_cpup_or_link(src_dentry, dentry, a);
16243 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
16245 + dput(h_src_dentry);
16248 + * copyup src_dentry to the branch we process,
16249 + * and then link(2) to it.
16251 + dput(h_src_dentry);
16252 + if (a->bdst < a->bsrc
16253 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
16254 + au_unpin(&a->pin);
16255 + di_write_unlock(a->parent);
16256 + err = au_cpup_before_link(src_dentry, a);
16257 + di_write_lock_parent(a->parent);
16259 + err = au_pin(&a->pin, dentry, a->bdst,
16261 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
16262 + if (unlikely(err))
16266 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
16268 + if (h_src_dentry && h_src_dentry->d_inode)
16269 + err = vfsub_link(h_src_dentry,
16270 + au_pinned_h_dir(&a->pin),
16274 + if (unlikely(err))
16278 + a->h_path.dentry = wh_dentry;
16279 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
16281 + if (unlikely(err))
16285 + dir->i_version++;
16286 + if (au_ibstart(dir) == au_dbstart(dentry))
16287 + au_cpup_attr_timesizes(dir);
16288 + inc_nlink(inode);
16289 + inode->i_ctime = dir->i_ctime;
16290 + d_instantiate(dentry, au_igrab(inode));
16291 + if (d_unhashed(a->h_path.dentry))
16292 + /* some filesystem calls d_drop() */
16294 + goto out_unpin; /* success */
16297 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path, /*force*/0);
16298 + if (unlikely(rerr)) {
16299 + AuIOErr("%.*s reverting failed(%d, %d)\n",
16300 + AuDLNPair(dentry), err, rerr);
16303 + au_dtime_revert(&dt);
16305 + au_unpin(&a->pin);
16309 + di_write_unlock(a->parent);
16310 + dput(a->src_parent);
16312 + if (unlikely(err)) {
16313 + au_update_dbstart(dentry);
16316 + aufs_read_and_write_unlock2(dentry, src_dentry);
16324 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
16327 + aufs_bindex_t bindex;
16328 + unsigned char diropq;
16329 + struct path h_path;
16330 + struct dentry *wh_dentry, *parent, *opq_dentry;
16331 + struct mutex *h_mtx;
16332 + struct super_block *sb;
16334 + struct au_pin pin;
16335 + struct au_dtime dt;
16336 + } *a; /* reduce the stack usage */
16337 + struct au_wr_dir_args wr_dir_args = {
16338 + .force_btgt = -1,
16339 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
16345 + a = kmalloc(sizeof(*a), GFP_NOFS);
16346 + if (unlikely(!a))
16349 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
16350 + if (unlikely(err))
16352 + err = au_d_may_add(dentry);
16353 + if (unlikely(err))
16356 + parent = dentry->d_parent; /* dir inode is locked */
16357 + di_write_lock_parent(parent);
16358 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
16359 + &a->pin, &wr_dir_args);
16360 + err = PTR_ERR(wh_dentry);
16361 + if (IS_ERR(wh_dentry))
16364 + sb = dentry->d_sb;
16365 + bindex = au_dbstart(dentry);
16366 + h_path.dentry = au_h_dptr(dentry, bindex);
16367 + h_path.mnt = au_sbr_mnt(sb, bindex);
16368 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
16369 + if (unlikely(err))
16372 + /* make the dir opaque */
16374 + h_mtx = &h_path.dentry->d_inode->i_mutex;
16376 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
16377 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
16378 + opq_dentry = au_diropq_create(dentry, bindex);
16379 + mutex_unlock(h_mtx);
16380 + err = PTR_ERR(opq_dentry);
16381 + if (IS_ERR(opq_dentry))
16383 + dput(opq_dentry);
16387 + err = epilog(dir, bindex, wh_dentry, dentry);
16390 + goto out_unpin; /* success */
16395 + AuLabel(revert opq);
16396 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
16397 + rerr = au_diropq_remove(dentry, bindex);
16398 + mutex_unlock(h_mtx);
16400 + AuIOErr("%.*s reverting diropq failed(%d, %d)\n",
16401 + AuDLNPair(dentry), err, rerr);
16407 + AuLabel(revert dir);
16408 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
16410 + AuIOErr("%.*s reverting dir failed(%d, %d)\n",
16411 + AuDLNPair(dentry), err, rerr);
16414 + au_dtime_revert(&a->dt);
16416 + au_unpin(&a->pin);
16419 + di_write_unlock(parent);
16421 + if (unlikely(err)) {
16422 + au_update_dbstart(dentry);
16425 + aufs_read_unlock(dentry, AuLock_DW);
16431 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
16432 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
16433 +++ linux/fs/aufs/i_op.c 2013-08-23 23:59:39.634916914 +0200
16436 + * Copyright (C) 2005-2013 Junjiro R. Okajima
16438 + * This program, aufs is free software; you can redistribute it and/or modify
16439 + * it under the terms of the GNU General Public License as published by
16440 + * the Free Software Foundation; either version 2 of the License, or
16441 + * (at your option) any later version.
16443 + * This program is distributed in the hope that it will be useful,
16444 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16445 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16446 + * GNU General Public License for more details.
16448 + * You should have received a copy of the GNU General Public License
16449 + * along with this program; if not, write to the Free Software
16450 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16454 + * inode operations (except add/del/rename)
16457 +#include <linux/device_cgroup.h>
16458 +#include <linux/fs_stack.h>
16459 +#include <linux/mm.h>
16460 +#include <linux/namei.h>
16461 +#include <linux/security.h>
16464 +static int h_permission(struct inode *h_inode, int mask,
16465 + struct vfsmount *h_mnt, int brperm)
16468 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
16471 + if ((write_mask && IS_IMMUTABLE(h_inode))
16472 + || ((mask & MAY_EXEC)
16473 + && S_ISREG(h_inode->i_mode)
16474 + && ((h_mnt->mnt_flags & MNT_NOEXEC)
16475 + || !(h_inode->i_mode & S_IXUGO))))
16479 + * - skip the lower fs test in the case of write to ro branch.
16480 + * - nfs dir permission write check is optimized, but a policy for
16481 + * link/rename requires a real check.
16483 + if ((write_mask && !au_br_writable(brperm))
16484 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
16485 + && write_mask && !(mask & MAY_READ))
16486 + || !h_inode->i_op->permission) {
16487 + /* AuLabel(generic_permission); */
16488 + err = generic_permission(h_inode, mask);
16490 + /* AuLabel(h_inode->permission); */
16491 + err = h_inode->i_op->permission(h_inode, mask);
16496 + err = devcgroup_inode_permission(h_inode, mask);
16498 + err = security_inode_permission(h_inode, mask);
16502 + /* todo: do we need to call ima_path_check()? */
16503 + struct path h_path = {
16507 + err = ima_path_check(&h_path,
16508 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
16509 + IMA_COUNT_LEAVE);
16517 +static int aufs_permission(struct inode *inode, int mask)
16520 + aufs_bindex_t bindex, bend;
16521 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
16522 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
16523 + struct inode *h_inode;
16524 + struct super_block *sb;
16525 + struct au_branch *br;
16527 + /* todo: support rcu-walk? */
16528 + if (mask & MAY_NOT_BLOCK)
16531 + sb = inode->i_sb;
16532 + si_read_lock(sb, AuLock_FLUSH);
16533 + ii_read_lock_child(inode);
16535 + err = au_iigen_test(inode, au_sigen(sb));
16536 + if (unlikely(err))
16540 + if (!isdir || write_mask) {
16541 + err = au_busy_or_stale();
16542 + h_inode = au_h_iptr(inode, au_ibstart(inode));
16543 + if (unlikely(!h_inode
16544 + || (h_inode->i_mode & S_IFMT)
16545 + != (inode->i_mode & S_IFMT)))
16549 + bindex = au_ibstart(inode);
16550 + br = au_sbr(sb, bindex);
16551 + err = h_permission(h_inode, mask, au_br_mnt(br), br->br_perm);
16554 + && !special_file(h_inode->i_mode)) {
16555 + /* test whether the upper writable branch exists */
16557 + for (; bindex >= 0; bindex--)
16558 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
16566 + /* non-write to dir */
16568 + bend = au_ibend(inode);
16569 + for (bindex = au_ibstart(inode); !err && bindex <= bend; bindex++) {
16570 + h_inode = au_h_iptr(inode, bindex);
16572 + err = au_busy_or_stale();
16573 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
16576 + br = au_sbr(sb, bindex);
16577 + err = h_permission(h_inode, mask, au_br_mnt(br),
16583 + ii_read_unlock(inode);
16584 + si_read_unlock(sb);
16588 +/* ---------------------------------------------------------------------- */
16590 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
16591 + unsigned int flags)
16593 + struct dentry *ret, *parent;
16594 + struct inode *inode;
16595 + struct super_block *sb;
16596 + int err, npositive;
16600 + /* todo: support rcu-walk? */
16601 + ret = ERR_PTR(-ECHILD);
16602 + if (flags & LOOKUP_RCU)
16605 + ret = ERR_PTR(-ENAMETOOLONG);
16606 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
16610 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16611 + ret = ERR_PTR(err);
16612 + if (unlikely(err))
16615 + err = au_di_init(dentry);
16616 + ret = ERR_PTR(err);
16617 + if (unlikely(err))
16621 + npositive = 0; /* suppress a warning */
16622 + parent = dentry->d_parent; /* dir inode is locked */
16623 + di_read_lock_parent(parent, AuLock_IR);
16624 + err = au_alive_dir(parent);
16626 + err = au_digen_test(parent, au_sigen(sb));
16628 + npositive = au_lkup_dentry(dentry, au_dbstart(parent),
16632 + di_read_unlock(parent, AuLock_IR);
16633 + ret = ERR_PTR(err);
16634 + if (unlikely(err < 0))
16638 + inode = au_new_inode(dentry, /*must_new*/0);
16639 + ret = (void *)inode;
16641 + if (IS_ERR(inode)) {
16646 + ret = d_splice_alias(inode, dentry);
16648 + if (unlikely(d_need_lookup(dentry))) {
16649 + spin_lock(&dentry->d_lock);
16650 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
16651 + spin_unlock(&dentry->d_lock);
16654 + if (unlikely(IS_ERR(ret) && inode)) {
16655 + ii_write_unlock(inode);
16661 + di_write_unlock(dentry);
16663 + /* verbose coding for lock class name */
16664 + if (unlikely(S_ISLNK(inode->i_mode)))
16665 + au_rw_class(&au_di(dentry)->di_rwsem,
16666 + au_lc_key + AuLcSymlink_DIINFO);
16667 + else if (unlikely(S_ISDIR(inode->i_mode)))
16668 + au_rw_class(&au_di(dentry)->di_rwsem,
16669 + au_lc_key + AuLcDir_DIINFO);
16670 + else /* likely */
16671 + au_rw_class(&au_di(dentry)->di_rwsem,
16672 + au_lc_key + AuLcNonDir_DIINFO);
16675 + si_read_unlock(sb);
16680 +/* ---------------------------------------------------------------------- */
16682 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
16683 + const unsigned char add_entry, aufs_bindex_t bcpup,
16684 + aufs_bindex_t bstart)
16687 + struct dentry *h_parent;
16688 + struct inode *h_dir;
16691 + IMustLock(parent->d_inode);
16693 + di_write_lock_parent(parent);
16696 + if (!au_h_dptr(parent, bcpup)) {
16697 + if (bstart > bcpup)
16698 + err = au_cpup_dirs(dentry, bcpup);
16699 + else if (bstart < bcpup)
16700 + err = au_cpdown_dirs(dentry, bcpup);
16704 + if (!err && add_entry) {
16705 + h_parent = au_h_dptr(parent, bcpup);
16706 + h_dir = h_parent->d_inode;
16707 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
16708 + err = au_lkup_neg(dentry, bcpup,
16709 + au_ftest_wrdir(add_entry, TMP_WHENTRY));
16710 + /* todo: no unlock here */
16711 + mutex_unlock(&h_dir->i_mutex);
16713 + AuDbg("bcpup %d\n", bcpup);
16715 + if (!dentry->d_inode)
16716 + au_set_h_dptr(dentry, bstart, NULL);
16717 + au_update_dbrange(dentry, /*do_put_zero*/0);
16722 + di_write_unlock(parent);
16724 + err = bcpup; /* success */
16731 + * decide the branch and the parent dir where we will create a new entry.
16732 + * returns new bindex or an error.
16733 + * copyup the parent dir if needed.
16735 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
16736 + struct au_wr_dir_args *args)
16739 + aufs_bindex_t bcpup, bstart, src_bstart;
16740 + const unsigned char add_entry
16741 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
16742 + | au_ftest_wrdir(args->flags, TMP_WHENTRY);
16743 + struct super_block *sb;
16744 + struct dentry *parent;
16745 + struct au_sbinfo *sbinfo;
16747 + sb = dentry->d_sb;
16748 + sbinfo = au_sbi(sb);
16749 + parent = dget_parent(dentry);
16750 + bstart = au_dbstart(dentry);
16752 + if (args->force_btgt < 0) {
16753 + if (src_dentry) {
16754 + src_bstart = au_dbstart(src_dentry);
16755 + if (src_bstart < bstart)
16756 + bcpup = src_bstart;
16757 + } else if (add_entry) {
16758 + err = AuWbrCreate(sbinfo, dentry,
16759 + au_ftest_wrdir(args->flags, ISDIR));
16763 + if (bcpup < 0 || au_test_ro(sb, bcpup, dentry->d_inode)) {
16765 + err = AuWbrCopyup(sbinfo, dentry);
16767 + if (!IS_ROOT(dentry)) {
16768 + di_read_lock_parent(parent, !AuLock_IR);
16769 + err = AuWbrCopyup(sbinfo, dentry);
16770 + di_read_unlock(parent, !AuLock_IR);
16772 + err = AuWbrCopyup(sbinfo, dentry);
16775 + if (unlikely(err < 0))
16779 + bcpup = args->force_btgt;
16780 + AuDebugOn(au_test_ro(sb, bcpup, dentry->d_inode));
16783 + AuDbg("bstart %d, bcpup %d\n", bstart, bcpup);
16785 + if (bcpup == bstart)
16786 + goto out; /* success */
16788 + /* copyup the new parent into the branch we process */
16789 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, bstart);
16791 + if (!dentry->d_inode) {
16792 + au_set_h_dptr(dentry, bstart, NULL);
16793 + au_set_dbstart(dentry, bcpup);
16794 + au_set_dbend(dentry, bcpup);
16796 + AuDebugOn(add_entry && !au_h_dptr(dentry, bcpup));
16804 +/* ---------------------------------------------------------------------- */
16806 +void au_pin_hdir_unlock(struct au_pin *p)
16809 + au_hn_imtx_unlock(p->hdir);
16812 +static int au_pin_hdir_lock(struct au_pin *p)
16820 + /* even if an error happens later, keep this lock */
16821 + au_hn_imtx_lock_nested(p->hdir, p->lsc_hi);
16824 + if (unlikely(p->hdir->hi_inode != p->h_parent->d_inode))
16829 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
16830 + p->h_parent, p->br);
16836 +int au_pin_hdir_relock(struct au_pin *p)
16839 + struct inode *h_i;
16840 + struct dentry *h_d[] = {
16845 + err = au_pin_hdir_lock(p);
16846 + if (unlikely(err))
16849 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
16852 + h_i = h_d[i]->d_inode;
16854 + err = !h_i->i_nlink;
16861 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
16863 +#if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
16864 + p->hdir->hi_inode->i_mutex.owner = task;
16868 +void au_pin_hdir_acquire_nest(struct au_pin *p)
16871 + mutex_acquire_nest(&p->hdir->hi_inode->i_mutex.dep_map,
16872 + p->lsc_hi, 0, NULL, _RET_IP_);
16873 + au_pin_hdir_set_owner(p, current);
16877 +void au_pin_hdir_release(struct au_pin *p)
16880 + au_pin_hdir_set_owner(p, p->task);
16881 + mutex_release(&p->hdir->hi_inode->i_mutex.dep_map, 1, _RET_IP_);
16885 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
16887 + if (pin && pin->parent)
16888 + return au_h_dptr(pin->parent, pin->bindex);
16892 +void au_unpin(struct au_pin *p)
16895 + au_pin_hdir_unlock(p);
16896 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
16897 + vfsub_mnt_drop_write(p->h_mnt);
16901 + if (!au_ftest_pin(p->flags, DI_LOCKED))
16902 + di_read_unlock(p->parent, AuLock_IR);
16903 + iput(p->hdir->hi_inode);
16905 + p->parent = NULL;
16908 + /* do not clear p->task */
16911 +int au_do_pin(struct au_pin *p)
16914 + struct super_block *sb;
16915 + struct inode *h_dir;
16918 + sb = p->dentry->d_sb;
16919 + p->br = au_sbr(sb, p->bindex);
16920 + if (IS_ROOT(p->dentry)) {
16921 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
16922 + p->h_mnt = au_br_mnt(p->br);
16923 + err = vfsub_mnt_want_write(p->h_mnt);
16924 + if (unlikely(err)) {
16925 + au_fclr_pin(p->flags, MNT_WRITE);
16932 + p->h_dentry = NULL;
16933 + if (p->bindex <= au_dbend(p->dentry))
16934 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
16936 + p->parent = dget_parent(p->dentry);
16937 + if (!au_ftest_pin(p->flags, DI_LOCKED))
16938 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
16941 + p->h_parent = au_h_dptr(p->parent, p->bindex);
16942 + p->hdir = au_hi(p->parent->d_inode, p->bindex);
16944 + h_dir = p->hdir->hi_inode;
16948 + * if DI_LOCKED is not set, then p->parent may be different
16949 + * and h_parent can be NULL.
16951 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
16953 + if (!au_ftest_pin(p->flags, DI_LOCKED))
16954 + di_read_unlock(p->parent, AuLock_IR);
16956 + p->parent = NULL;
16960 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
16961 + p->h_mnt = au_br_mnt(p->br);
16962 + err = vfsub_mnt_want_write(p->h_mnt);
16963 + if (unlikely(err)) {
16964 + au_fclr_pin(p->flags, MNT_WRITE);
16965 + if (!au_ftest_pin(p->flags, DI_LOCKED))
16966 + di_read_unlock(p->parent, AuLock_IR);
16968 + p->parent = NULL;
16974 + err = au_pin_hdir_lock(p);
16976 + goto out; /* success */
16979 + pr_err("err %d\n", err);
16980 + err = au_busy_or_stale();
16985 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
16986 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
16987 + unsigned int udba, unsigned char flags)
16989 + p->dentry = dentry;
16991 + p->lsc_di = lsc_di;
16992 + p->lsc_hi = lsc_hi;
16993 + p->flags = flags;
16994 + p->bindex = bindex;
16996 + p->parent = NULL;
17000 + p->h_dentry = NULL;
17001 + p->h_parent = NULL;
17003 + p->task = current;
17006 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
17007 + unsigned int udba, unsigned char flags)
17009 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
17011 + return au_do_pin(pin);
17014 +/* ---------------------------------------------------------------------- */
17017 + * ->setattr() and ->getattr() are called in various cases.
17018 + * chmod, stat: dentry is revalidated.
17019 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
17021 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
17023 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
17024 +static int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
17027 + struct inode *inode;
17028 + struct dentry *parent;
17031 + inode = dentry->d_inode;
17032 + if (au_digen_test(dentry, sigen)) {
17033 + parent = dget_parent(dentry);
17034 + di_read_lock_parent(parent, AuLock_IR);
17035 + err = au_refresh_dentry(dentry, parent);
17036 + di_read_unlock(parent, AuLock_IR);
17044 +#define AuIcpup_DID_CPUP 1
17045 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
17046 +#define au_fset_icpup(flags, name) \
17047 + do { (flags) |= AuIcpup_##name; } while (0)
17048 +#define au_fclr_icpup(flags, name) \
17049 + do { (flags) &= ~AuIcpup_##name; } while (0)
17051 +struct au_icpup_args {
17052 + unsigned char flags;
17053 + unsigned char pin_flags;
17054 + aufs_bindex_t btgt;
17055 + unsigned int udba;
17056 + struct au_pin pin;
17057 + struct path h_path;
17058 + struct inode *h_inode;
17061 +static int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
17062 + struct au_icpup_args *a)
17066 + aufs_bindex_t bstart, ibstart;
17067 + struct dentry *hi_wh, *parent;
17068 + struct inode *inode;
17069 + struct au_wr_dir_args wr_dir_args = {
17070 + .force_btgt = -1,
17074 + bstart = au_dbstart(dentry);
17075 + inode = dentry->d_inode;
17076 + if (S_ISDIR(inode->i_mode))
17077 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
17078 + /* plink or hi_wh() case */
17079 + ibstart = au_ibstart(inode);
17080 + if (bstart != ibstart && !au_test_ro(inode->i_sb, ibstart, inode))
17081 + wr_dir_args.force_btgt = ibstart;
17082 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
17083 + if (unlikely(err < 0))
17086 + if (err != bstart)
17087 + au_fset_icpup(a->flags, DID_CPUP);
17090 + a->pin_flags = AuPin_MNT_WRITE;
17092 + if (!IS_ROOT(dentry)) {
17093 + au_fset_pin(a->pin_flags, DI_LOCKED);
17094 + parent = dget_parent(dentry);
17095 + di_write_lock_parent(parent);
17098 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
17099 + if (unlikely(err))
17102 + a->h_path.dentry = au_h_dptr(dentry, bstart);
17103 + a->h_inode = a->h_path.dentry->d_inode;
17104 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
17106 + if ((ia->ia_valid & ATTR_SIZE) && ia->ia_size < i_size_read(a->h_inode))
17107 + sz = ia->ia_size;
17108 + mutex_unlock(&a->h_inode->i_mutex);
17111 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
17112 + hi_wh = au_hi_wh(inode, a->btgt);
17114 + struct au_cp_generic cpg = {
17115 + .dentry = dentry,
17121 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
17122 + if (unlikely(err))
17124 + hi_wh = au_hi_wh(inode, a->btgt);
17125 + /* todo: revalidate hi_wh? */
17130 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
17131 + di_downgrade_lock(parent, AuLock_IR);
17135 + if (!au_ftest_icpup(a->flags, DID_CPUP))
17136 + goto out; /* success */
17138 + if (!d_unhashed(dentry)) {
17139 + struct au_cp_generic cpg = {
17140 + .dentry = dentry,
17145 + .flags = AuCpup_DTIME | AuCpup_HOPEN
17147 + err = au_sio_cpup_simple(&cpg);
17149 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
17150 + } else if (!hi_wh)
17151 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
17153 + a->h_path.dentry = hi_wh; /* do not dget here */
17156 + a->h_inode = a->h_path.dentry->d_inode;
17158 + goto out; /* success */
17159 + au_unpin(&a->pin);
17162 + di_write_unlock(parent);
17167 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
17171 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
17174 + struct inode *inode;
17175 + struct super_block *sb;
17176 + struct file *file;
17177 + struct au_icpup_args *a;
17179 + inode = dentry->d_inode;
17180 + IMustLock(inode);
17183 + a = kzalloc(sizeof(*a), GFP_NOFS);
17184 + if (unlikely(!a))
17187 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
17188 + ia->ia_valid &= ~ATTR_MODE;
17191 + sb = dentry->d_sb;
17192 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
17193 + if (unlikely(err))
17196 + if (ia->ia_valid & ATTR_FILE) {
17197 + /* currently ftruncate(2) only */
17198 + AuDebugOn(!S_ISREG(inode->i_mode));
17199 + file = ia->ia_file;
17200 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
17201 + if (unlikely(err))
17203 + ia->ia_file = au_hf_top(file);
17204 + a->udba = AuOpt_UDBA_NONE;
17206 + /* fchmod() doesn't pass ia_file */
17207 + a->udba = au_opt_udba(sb);
17208 + di_write_lock_child(dentry);
17209 + /* no d_unlinked(), to set UDBA_NONE for root */
17210 + if (d_unhashed(dentry))
17211 + a->udba = AuOpt_UDBA_NONE;
17212 + if (a->udba != AuOpt_UDBA_NONE) {
17213 + AuDebugOn(IS_ROOT(dentry));
17214 + err = au_reval_for_attr(dentry, au_sigen(sb));
17215 + if (unlikely(err))
17220 + err = au_pin_and_icpup(dentry, ia, a);
17221 + if (unlikely(err < 0))
17223 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
17224 + ia->ia_file = NULL;
17225 + ia->ia_valid &= ~ATTR_FILE;
17228 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
17229 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
17230 + == (ATTR_MODE | ATTR_CTIME)) {
17231 + err = security_path_chmod(&a->h_path, ia->ia_mode);
17232 + if (unlikely(err))
17234 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
17235 + && (ia->ia_valid & ATTR_CTIME)) {
17236 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
17237 + if (unlikely(err))
17241 + if (ia->ia_valid & ATTR_SIZE) {
17244 + if (ia->ia_size < i_size_read(inode))
17246 + truncate_setsize(inode, ia->ia_size);
17249 + if (ia->ia_valid & ATTR_FILE)
17251 + mutex_unlock(&a->h_inode->i_mutex);
17252 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
17253 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
17255 + err = vfsub_notify_change(&a->h_path, ia);
17257 + au_cpup_attr_changeable(inode);
17260 + mutex_unlock(&a->h_inode->i_mutex);
17261 + au_unpin(&a->pin);
17262 + if (unlikely(err))
17263 + au_update_dbstart(dentry);
17265 + di_write_unlock(dentry);
17267 + fi_write_unlock(file);
17268 + ia->ia_file = file;
17269 + ia->ia_valid |= ATTR_FILE;
17272 + si_read_unlock(sb);
17280 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
17281 + unsigned int nlink)
17285 + inode->i_mode = st->mode;
17286 + /* don't i_[ug]id_write() here */
17287 + inode->i_uid = st->uid;
17288 + inode->i_gid = st->gid;
17289 + inode->i_atime = st->atime;
17290 + inode->i_mtime = st->mtime;
17291 + inode->i_ctime = st->ctime;
17293 + au_cpup_attr_nlink(inode, /*force*/0);
17294 + if (S_ISDIR(inode->i_mode)) {
17295 + n = inode->i_nlink;
17299 + /* 0 can happen */
17300 + set_nlink(inode, n);
17303 + spin_lock(&inode->i_lock);
17304 + inode->i_blocks = st->blocks;
17305 + i_size_write(inode, st->size);
17306 + spin_unlock(&inode->i_lock);
17309 +static int aufs_getattr(struct vfsmount *mnt __maybe_unused,
17310 + struct dentry *dentry, struct kstat *st)
17313 + unsigned int mnt_flags;
17314 + aufs_bindex_t bindex;
17315 + unsigned char udba_none, positive;
17316 + struct super_block *sb, *h_sb;
17317 + struct inode *inode;
17318 + struct path h_path;
17320 + sb = dentry->d_sb;
17321 + inode = dentry->d_inode;
17322 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
17323 + if (unlikely(err))
17325 + mnt_flags = au_mntflags(sb);
17326 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
17328 + /* support fstat(2) */
17329 + if (!d_unlinked(dentry) && !udba_none) {
17330 + unsigned int sigen = au_sigen(sb);
17331 + err = au_digen_test(dentry, sigen);
17333 + di_read_lock_child(dentry, AuLock_IR);
17334 + err = au_dbrange_test(dentry);
17335 + if (unlikely(err))
17338 + AuDebugOn(IS_ROOT(dentry));
17339 + di_write_lock_child(dentry);
17340 + err = au_dbrange_test(dentry);
17342 + err = au_reval_for_attr(dentry, sigen);
17343 + di_downgrade_lock(dentry, AuLock_IR);
17344 + if (unlikely(err))
17348 + di_read_lock_child(dentry, AuLock_IR);
17350 + bindex = au_ibstart(inode);
17351 + h_path.mnt = au_sbr_mnt(sb, bindex);
17352 + h_sb = h_path.mnt->mnt_sb;
17353 + if (!au_test_fs_bad_iattr(h_sb) && udba_none)
17354 + goto out_fill; /* success */
17356 + h_path.dentry = NULL;
17357 + if (au_dbstart(dentry) == bindex)
17358 + h_path.dentry = dget(au_h_dptr(dentry, bindex));
17359 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
17360 + h_path.dentry = au_plink_lkup(inode, bindex);
17361 + if (IS_ERR(h_path.dentry))
17362 + goto out_fill; /* pretending success */
17364 + /* illegally overlapped or something */
17365 + if (unlikely(!h_path.dentry))
17366 + goto out_fill; /* pretending success */
17368 + positive = !!h_path.dentry->d_inode;
17370 + err = vfs_getattr(&h_path, st);
17371 + dput(h_path.dentry);
17374 + au_refresh_iattr(inode, st,
17375 + h_path.dentry->d_inode->i_nlink);
17376 + goto out_fill; /* success */
17382 + generic_fillattr(inode, st);
17384 + di_read_unlock(dentry, AuLock_IR);
17385 + si_read_unlock(sb);
17391 +/* ---------------------------------------------------------------------- */
17393 +static int h_readlink(struct dentry *dentry, int bindex, char __user *buf,
17397 + struct super_block *sb;
17398 + struct dentry *h_dentry;
17401 + h_dentry = au_h_dptr(dentry, bindex);
17402 + if (unlikely(!h_dentry->d_inode->i_op->readlink))
17405 + err = security_inode_readlink(h_dentry);
17406 + if (unlikely(err))
17409 + sb = dentry->d_sb;
17410 + if (!au_test_ro(sb, bindex, dentry->d_inode)) {
17411 + vfsub_touch_atime(au_sbr_mnt(sb, bindex), h_dentry);
17412 + fsstack_copy_attr_atime(dentry->d_inode, h_dentry->d_inode);
17414 + err = h_dentry->d_inode->i_op->readlink(h_dentry, buf, bufsiz);
17420 +static int aufs_readlink(struct dentry *dentry, char __user *buf, int bufsiz)
17424 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
17425 + if (unlikely(err))
17427 + err = au_d_hashed_positive(dentry);
17429 + err = h_readlink(dentry, au_dbstart(dentry), buf, bufsiz);
17430 + aufs_read_unlock(dentry, AuLock_IR);
17436 +static void *aufs_follow_link(struct dentry *dentry, struct nameidata *nd)
17439 + mm_segment_t old_fs;
17446 + buf.k = (void *)__get_free_page(GFP_NOFS);
17447 + if (unlikely(!buf.k))
17450 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
17451 + if (unlikely(err))
17454 + err = au_d_hashed_positive(dentry);
17456 + old_fs = get_fs();
17457 + set_fs(KERNEL_DS);
17458 + err = h_readlink(dentry, au_dbstart(dentry), buf.u, PATH_MAX);
17461 + aufs_read_unlock(dentry, AuLock_IR);
17465 + /* will be freed by put_link */
17466 + nd_set_link(nd, buf.k);
17467 + return NULL; /* success */
17471 + free_page((unsigned long)buf.k);
17474 + return ERR_PTR(err);
17477 +static void aufs_put_link(struct dentry *dentry __maybe_unused,
17478 + struct nameidata *nd, void *cookie __maybe_unused)
17482 + p = nd_get_link(nd);
17483 + if (!IS_ERR_OR_NULL(p))
17484 + free_page((unsigned long)p);
17487 +/* ---------------------------------------------------------------------- */
17489 +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags)
17492 + struct super_block *sb;
17493 + struct inode *h_inode;
17495 + sb = inode->i_sb;
17496 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
17498 + si_read_lock(sb, AuLock_FLUSH);
17499 + ii_write_lock_child(inode);
17501 + h_inode = au_h_iptr(inode, au_ibstart(inode));
17502 + err = vfsub_update_time(h_inode, ts, flags);
17504 + ii_write_unlock(inode);
17505 + si_read_unlock(sb);
17510 +/* ---------------------------------------------------------------------- */
17512 +struct inode_operations aufs_symlink_iop = {
17513 + .permission = aufs_permission,
17514 + .setattr = aufs_setattr,
17515 + .getattr = aufs_getattr,
17517 + .readlink = aufs_readlink,
17518 + .follow_link = aufs_follow_link,
17519 + .put_link = aufs_put_link,
17521 + /* .update_time = aufs_update_time */
17524 +struct inode_operations aufs_dir_iop = {
17525 + .create = aufs_create,
17526 + .lookup = aufs_lookup,
17527 + .link = aufs_link,
17528 + .unlink = aufs_unlink,
17529 + .symlink = aufs_symlink,
17530 + .mkdir = aufs_mkdir,
17531 + .rmdir = aufs_rmdir,
17532 + .mknod = aufs_mknod,
17533 + .rename = aufs_rename,
17535 + .permission = aufs_permission,
17536 + .setattr = aufs_setattr,
17537 + .getattr = aufs_getattr,
17539 + .update_time = aufs_update_time
17540 + /* no support for atomic_open() */
17543 +struct inode_operations aufs_iop = {
17544 + .permission = aufs_permission,
17545 + .setattr = aufs_setattr,
17546 + .getattr = aufs_getattr,
17548 + .update_time = aufs_update_time
17550 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
17551 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
17552 +++ linux/fs/aufs/i_op_del.c 2013-08-23 23:59:39.634916914 +0200
17555 + * Copyright (C) 2005-2013 Junjiro R. Okajima
17557 + * This program, aufs is free software; you can redistribute it and/or modify
17558 + * it under the terms of the GNU General Public License as published by
17559 + * the Free Software Foundation; either version 2 of the License, or
17560 + * (at your option) any later version.
17562 + * This program is distributed in the hope that it will be useful,
17563 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17564 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17565 + * GNU General Public License for more details.
17567 + * You should have received a copy of the GNU General Public License
17568 + * along with this program; if not, write to the Free Software
17569 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17573 + * inode operations (del entry)
17579 + * decide if a new whiteout for @dentry is necessary or not.
17580 + * when it is necessary, prepare the parent dir for the upper branch whose
17581 + * branch index is @bcpup for creation. the actual creation of the whiteout will
17582 + * be done by caller.
17584 + * 0: wh is unnecessary
17585 + * plus: wh is necessary
17588 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
17590 + int need_wh, err;
17591 + aufs_bindex_t bstart;
17592 + struct super_block *sb;
17594 + sb = dentry->d_sb;
17595 + bstart = au_dbstart(dentry);
17596 + if (*bcpup < 0) {
17598 + if (au_test_ro(sb, bstart, dentry->d_inode)) {
17599 + err = AuWbrCopyup(au_sbi(sb), dentry);
17601 + if (unlikely(err < 0))
17605 + AuDebugOn(bstart < *bcpup
17606 + || au_test_ro(sb, *bcpup, dentry->d_inode));
17607 + AuDbg("bcpup %d, bstart %d\n", *bcpup, bstart);
17609 + if (*bcpup != bstart) {
17610 + err = au_cpup_dirs(dentry, *bcpup);
17611 + if (unlikely(err))
17615 + struct au_dinfo *dinfo, *tmp;
17617 + need_wh = -ENOMEM;
17618 + dinfo = au_di(dentry);
17619 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
17621 + au_di_cp(tmp, dinfo);
17622 + au_di_swap(tmp, dinfo);
17623 + /* returns the number of positive dentries */
17624 + need_wh = au_lkup_dentry(dentry, bstart + 1, /*type*/0);
17625 + au_di_swap(tmp, dinfo);
17626 + au_rw_write_unlock(&tmp->di_rwsem);
17630 + AuDbg("need_wh %d\n", need_wh);
17638 + * simple tests for the del-entry operations.
17639 + * following the checks in vfs, plus the parent-child relationship.
17641 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
17642 + struct dentry *h_parent, int isdir)
17646 + struct dentry *h_dentry, *h_latest;
17647 + struct inode *h_inode;
17649 + h_dentry = au_h_dptr(dentry, bindex);
17650 + h_inode = h_dentry->d_inode;
17651 + if (dentry->d_inode) {
17653 + if (unlikely(!h_inode || !h_inode->i_nlink))
17656 + h_mode = h_inode->i_mode;
17659 + if (unlikely(S_ISDIR(h_mode)))
17661 + } else if (unlikely(!S_ISDIR(h_mode))) {
17666 + /* rename(2) case */
17668 + if (unlikely(h_inode))
17673 + /* expected parent dir is locked */
17674 + if (unlikely(h_parent != h_dentry->d_parent))
17679 + * rmdir a dir may break the consistency on some filesystem.
17680 + * let's try heavy test.
17683 + if (unlikely(au_test_h_perm(h_parent->d_inode, MAY_EXEC | MAY_WRITE)))
17686 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent,
17687 + au_sbr(dentry->d_sb, bindex));
17689 + if (IS_ERR(h_latest))
17691 + if (h_latest == h_dentry)
17700 + * decide the branch where we operate for @dentry. the branch index will be set
17701 + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent
17702 + * dir for reverting.
17703 + * when a new whiteout is necessary, create it.
17705 +static struct dentry*
17706 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
17707 + struct au_dtime *dt, struct au_pin *pin)
17709 + struct dentry *wh_dentry;
17710 + struct super_block *sb;
17711 + struct path h_path;
17712 + int err, need_wh;
17713 + unsigned int udba;
17714 + aufs_bindex_t bcpup;
17716 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
17717 + wh_dentry = ERR_PTR(need_wh);
17718 + if (unlikely(need_wh < 0))
17721 + sb = dentry->d_sb;
17722 + udba = au_opt_udba(sb);
17724 + err = au_pin(pin, dentry, bcpup, udba,
17725 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17726 + wh_dentry = ERR_PTR(err);
17727 + if (unlikely(err))
17730 + h_path.dentry = au_pinned_h_parent(pin);
17731 + if (udba != AuOpt_UDBA_NONE
17732 + && au_dbstart(dentry) == bcpup) {
17733 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
17734 + wh_dentry = ERR_PTR(err);
17735 + if (unlikely(err))
17739 + h_path.mnt = au_sbr_mnt(sb, bcpup);
17740 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
17741 + wh_dentry = NULL;
17743 + goto out; /* success, no need to create whiteout */
17745 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
17746 + if (IS_ERR(wh_dentry))
17749 + /* returns with the parent is locked and wh_dentry is dget-ed */
17750 + goto out; /* success */
17755 + return wh_dentry;
17759 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
17760 + * in order to be revertible and save time for removing many child whiteouts
17762 + * returns 1 when there are too many child whiteout and caller should remove
17763 + * them asynchronously. returns 0 when the number of children is enough small to
17764 + * remove now or the branch fs is a remote fs.
17765 + * otherwise return an error.
17767 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
17768 + struct au_nhash *whlist, struct inode *dir)
17770 + int rmdir_later, err, dirwh;
17771 + struct dentry *h_dentry;
17772 + struct super_block *sb;
17774 + sb = dentry->d_sb;
17775 + SiMustAnyLock(sb);
17776 + h_dentry = au_h_dptr(dentry, bindex);
17777 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
17778 + if (unlikely(err))
17781 + /* stop monitoring */
17782 + au_hn_free(au_hi(dentry->d_inode, bindex));
17784 + if (!au_test_fs_remote(h_dentry->d_sb)) {
17785 + dirwh = au_sbi(sb)->si_dirwh;
17786 + rmdir_later = (dirwh <= 1);
17787 + if (!rmdir_later)
17788 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
17791 + return rmdir_later;
17794 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
17795 + if (unlikely(err)) {
17796 + AuIOErr("rmdir %.*s, b%d failed, %d. ignored\n",
17797 + AuDLNPair(h_dentry), bindex, err);
17807 + * final procedure for deleting a entry.
17808 + * maintain dentry and iattr.
17810 +static void epilog(struct inode *dir, struct dentry *dentry,
17811 + aufs_bindex_t bindex)
17813 + struct inode *inode;
17815 + inode = dentry->d_inode;
17817 + inode->i_ctime = dir->i_ctime;
17819 + if (au_ibstart(dir) == bindex)
17820 + au_cpup_attr_timesizes(dir);
17821 + dir->i_version++;
17825 + * when an error happened, remove the created whiteout and revert everything.
17827 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
17828 + aufs_bindex_t bwh, struct dentry *wh_dentry,
17829 + struct dentry *dentry, struct au_dtime *dt)
17832 + struct path h_path = {
17833 + .dentry = wh_dentry,
17834 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
17837 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
17839 + au_set_dbwh(dentry, bwh);
17840 + au_dtime_revert(dt);
17844 + AuIOErr("%.*s reverting whiteout failed(%d, %d)\n",
17845 + AuDLNPair(dentry), err, rerr);
17849 +/* ---------------------------------------------------------------------- */
17851 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
17854 + aufs_bindex_t bwh, bindex, bstart;
17855 + struct inode *inode, *h_dir;
17856 + struct dentry *parent, *wh_dentry;
17857 + /* to reuduce stack size */
17859 + struct au_dtime dt;
17860 + struct au_pin pin;
17861 + struct path h_path;
17867 + a = kmalloc(sizeof(*a), GFP_NOFS);
17868 + if (unlikely(!a))
17871 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
17872 + if (unlikely(err))
17874 + err = au_d_hashed_positive(dentry);
17875 + if (unlikely(err))
17877 + inode = dentry->d_inode;
17878 + IMustLock(inode);
17880 + if (unlikely(S_ISDIR(inode->i_mode)))
17881 + goto out_unlock; /* possible? */
17883 + bstart = au_dbstart(dentry);
17884 + bwh = au_dbwh(dentry);
17886 + parent = dentry->d_parent; /* dir inode is locked */
17887 + di_write_lock_parent(parent);
17888 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
17890 + err = PTR_ERR(wh_dentry);
17891 + if (IS_ERR(wh_dentry))
17894 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
17895 + a->h_path.dentry = au_h_dptr(dentry, bstart);
17896 + dget(a->h_path.dentry);
17897 + if (bindex == bstart) {
17898 + h_dir = au_pinned_h_dir(&a->pin);
17899 + err = vfsub_unlink(h_dir, &a->h_path, /*force*/0);
17901 + /* dir inode is locked */
17902 + h_dir = wh_dentry->d_parent->d_inode;
17903 + IMustLock(h_dir);
17908 + vfsub_drop_nlink(inode);
17909 + epilog(dir, dentry, bindex);
17911 + /* update target timestamps */
17912 + if (bindex == bstart) {
17913 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
17915 + inode->i_ctime = a->h_path.dentry->d_inode->i_ctime;
17917 + /* todo: this timestamp may be reverted later */
17918 + inode->i_ctime = h_dir->i_ctime;
17919 + goto out_unpin; /* success */
17926 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
17933 + au_unpin(&a->pin);
17935 + dput(a->h_path.dentry);
17937 + di_write_unlock(parent);
17939 + aufs_read_unlock(dentry, AuLock_DW);
17946 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
17948 + int err, rmdir_later;
17949 + aufs_bindex_t bwh, bindex, bstart;
17950 + struct inode *inode;
17951 + struct dentry *parent, *wh_dentry, *h_dentry;
17952 + struct au_whtmp_rmdir *args;
17953 + /* to reuduce stack size */
17955 + struct au_dtime dt;
17956 + struct au_pin pin;
17962 + a = kmalloc(sizeof(*a), GFP_NOFS);
17963 + if (unlikely(!a))
17966 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
17967 + if (unlikely(err))
17969 + err = au_alive_dir(dentry);
17970 + if (unlikely(err))
17972 + inode = dentry->d_inode;
17973 + IMustLock(inode);
17975 + if (unlikely(!S_ISDIR(inode->i_mode)))
17976 + goto out_unlock; /* possible? */
17979 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
17980 + if (unlikely(!args))
17983 + parent = dentry->d_parent; /* dir inode is locked */
17984 + di_write_lock_parent(parent);
17985 + err = au_test_empty(dentry, &args->whlist);
17986 + if (unlikely(err))
17989 + bstart = au_dbstart(dentry);
17990 + bwh = au_dbwh(dentry);
17992 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
17994 + err = PTR_ERR(wh_dentry);
17995 + if (IS_ERR(wh_dentry))
17998 + h_dentry = au_h_dptr(dentry, bstart);
18001 + if (bindex == bstart) {
18002 + err = renwh_and_rmdir(dentry, bstart, &args->whlist, dir);
18004 + rmdir_later = err;
18008 + /* stop monitoring */
18009 + au_hn_free(au_hi(inode, bstart));
18011 + /* dir inode is locked */
18012 + IMustLock(wh_dentry->d_parent->d_inode);
18017 + vfsub_dead_dir(inode);
18018 + au_set_dbdiropq(dentry, -1);
18019 + epilog(dir, dentry, bindex);
18021 + if (rmdir_later) {
18022 + au_whtmp_kick_rmdir(dir, bstart, h_dentry, args);
18026 + goto out_unpin; /* success */
18034 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
18041 + au_unpin(&a->pin);
18045 + di_write_unlock(parent);
18047 + au_whtmp_rmdir_free(args);
18049 + aufs_read_unlock(dentry, AuLock_DW);
18056 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
18057 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
18058 +++ linux/fs/aufs/i_op_ren.c 2013-08-23 23:59:39.634916914 +0200
18061 + * Copyright (C) 2005-2013 Junjiro R. Okajima
18063 + * This program, aufs is free software; you can redistribute it and/or modify
18064 + * it under the terms of the GNU General Public License as published by
18065 + * the Free Software Foundation; either version 2 of the License, or
18066 + * (at your option) any later version.
18068 + * This program is distributed in the hope that it will be useful,
18069 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18070 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18071 + * GNU General Public License for more details.
18073 + * You should have received a copy of the GNU General Public License
18074 + * along with this program; if not, write to the Free Software
18075 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18079 + * inode operation (rename entry)
18080 + * todo: this is crazy monster
18085 +enum { AuSRC, AuDST, AuSrcDst };
18086 +enum { AuPARENT, AuCHILD, AuParentChild };
18088 +#define AuRen_ISDIR 1
18089 +#define AuRen_ISSAMEDIR (1 << 1)
18090 +#define AuRen_WHSRC (1 << 2)
18091 +#define AuRen_WHDST (1 << 3)
18092 +#define AuRen_MNT_WRITE (1 << 4)
18093 +#define AuRen_DT_DSTDIR (1 << 5)
18094 +#define AuRen_DIROPQ (1 << 6)
18095 +#define AuRen_CPUP (1 << 7)
18096 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
18097 +#define au_fset_ren(flags, name) \
18098 + do { (flags) |= AuRen_##name; } while (0)
18099 +#define au_fclr_ren(flags, name) \
18100 + do { (flags) &= ~AuRen_##name; } while (0)
18102 +struct au_ren_args {
18104 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
18106 + struct inode *dir, *inode;
18107 + struct au_hinode *hdir;
18108 + struct au_dtime dt[AuParentChild];
18109 + aufs_bindex_t bstart;
18112 +#define src_dentry sd[AuSRC].dentry
18113 +#define src_dir sd[AuSRC].dir
18114 +#define src_inode sd[AuSRC].inode
18115 +#define src_h_dentry sd[AuSRC].h_dentry
18116 +#define src_parent sd[AuSRC].parent
18117 +#define src_h_parent sd[AuSRC].h_parent
18118 +#define src_wh_dentry sd[AuSRC].wh_dentry
18119 +#define src_hdir sd[AuSRC].hdir
18120 +#define src_h_dir sd[AuSRC].hdir->hi_inode
18121 +#define src_dt sd[AuSRC].dt
18122 +#define src_bstart sd[AuSRC].bstart
18124 +#define dst_dentry sd[AuDST].dentry
18125 +#define dst_dir sd[AuDST].dir
18126 +#define dst_inode sd[AuDST].inode
18127 +#define dst_h_dentry sd[AuDST].h_dentry
18128 +#define dst_parent sd[AuDST].parent
18129 +#define dst_h_parent sd[AuDST].h_parent
18130 +#define dst_wh_dentry sd[AuDST].wh_dentry
18131 +#define dst_hdir sd[AuDST].hdir
18132 +#define dst_h_dir sd[AuDST].hdir->hi_inode
18133 +#define dst_dt sd[AuDST].dt
18134 +#define dst_bstart sd[AuDST].bstart
18136 + struct dentry *h_trap;
18137 + struct au_branch *br;
18138 + struct au_hinode *src_hinode;
18139 + struct path h_path;
18140 + struct au_nhash whlist;
18141 + aufs_bindex_t btgt, src_bwh, src_bdiropq;
18143 + unsigned int flags;
18145 + struct au_whtmp_rmdir *thargs;
18146 + struct dentry *h_dst;
18149 +/* ---------------------------------------------------------------------- */
18152 + * functions for reverting.
18153 + * when an error happened in a single rename systemcall, we should revert
18154 + * everything as if nothing happend.
18155 + * we don't need to revert the copied-up/down the parent dir since they are
18159 +#define RevertFailure(fmt, ...) do { \
18160 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
18161 + ##__VA_ARGS__, err, rerr); \
18165 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
18169 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
18170 + rerr = au_diropq_remove(a->src_dentry, a->btgt);
18171 + au_hn_imtx_unlock(a->src_hinode);
18172 + au_set_dbdiropq(a->src_dentry, a->src_bdiropq);
18174 + RevertFailure("remove diropq %.*s", AuDLNPair(a->src_dentry));
18177 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
18181 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
18182 + a->src_h_parent);
18183 + rerr = PTR_ERR(a->h_path.dentry);
18184 + if (IS_ERR(a->h_path.dentry)) {
18185 + RevertFailure("lkup one %.*s", AuDLNPair(a->src_dentry));
18189 + rerr = vfsub_rename(a->dst_h_dir,
18190 + au_h_dptr(a->src_dentry, a->btgt),
18191 + a->src_h_dir, &a->h_path);
18192 + d_drop(a->h_path.dentry);
18193 + dput(a->h_path.dentry);
18194 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
18196 + RevertFailure("rename %.*s", AuDLNPair(a->src_dentry));
18199 +static void au_ren_rev_cpup(int err, struct au_ren_args *a)
18203 + a->h_path.dentry = a->dst_h_dentry;
18204 + rerr = vfsub_unlink(a->dst_h_dir, &a->h_path, /*force*/0);
18205 + au_set_h_dptr(a->src_dentry, a->btgt, NULL);
18206 + au_set_dbstart(a->src_dentry, a->src_bstart);
18208 + RevertFailure("unlink %.*s", AuDLNPair(a->dst_h_dentry));
18211 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
18215 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
18216 + a->dst_h_parent);
18217 + rerr = PTR_ERR(a->h_path.dentry);
18218 + if (IS_ERR(a->h_path.dentry)) {
18219 + RevertFailure("lkup one %.*s", AuDLNPair(a->dst_dentry));
18222 + if (a->h_path.dentry->d_inode) {
18223 + d_drop(a->h_path.dentry);
18224 + dput(a->h_path.dentry);
18228 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path);
18229 + d_drop(a->h_path.dentry);
18230 + dput(a->h_path.dentry);
18232 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
18234 + RevertFailure("rename %.*s", AuDLNPair(a->h_dst));
18237 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
18241 + a->h_path.dentry = a->src_wh_dentry;
18242 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
18243 + au_set_dbwh(a->src_dentry, a->src_bwh);
18245 + RevertFailure("unlink %.*s", AuDLNPair(a->src_wh_dentry));
18247 +#undef RevertFailure
18249 +/* ---------------------------------------------------------------------- */
18252 + * when we have to copyup the renaming entry, do it with the rename-target name
18253 + * in order to minimize the cost (the later actual rename is unnecessary).
18254 + * otherwise rename it on the target branch.
18256 +static int au_ren_or_cpup(struct au_ren_args *a)
18259 + struct dentry *d;
18261 + d = a->src_dentry;
18262 + if (au_dbstart(d) == a->btgt) {
18263 + a->h_path.dentry = a->dst_h_dentry;
18264 + if (au_ftest_ren(a->flags, DIROPQ)
18265 + && au_dbdiropq(d) == a->btgt)
18266 + au_fclr_ren(a->flags, DIROPQ);
18267 + AuDebugOn(au_dbstart(d) != a->btgt);
18268 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
18269 + a->dst_h_dir, &a->h_path);
18273 + if (!err && a->h_dst)
18274 + /* it will be set to dinfo later */
18280 +/* cf. aufs_rmdir() */
18281 +static int au_ren_del_whtmp(struct au_ren_args *a)
18284 + struct inode *dir;
18286 + dir = a->dst_dir;
18287 + SiMustAnyLock(dir->i_sb);
18288 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
18289 + au_sbi(dir->i_sb)->si_dirwh)
18290 + || au_test_fs_remote(a->h_dst->d_sb)) {
18291 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
18292 + if (unlikely(err))
18293 + pr_warn("failed removing whtmp dir %.*s (%d), "
18294 + "ignored.\n", AuDLNPair(a->h_dst), err);
18296 + au_nhash_wh_free(&a->thargs->whlist);
18297 + a->thargs->whlist = a->whlist;
18298 + a->whlist.nh_num = 0;
18299 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
18301 + a->thargs = NULL;
18307 +/* make it 'opaque' dir. */
18308 +static int au_ren_diropq(struct au_ren_args *a)
18311 + struct dentry *diropq;
18314 + a->src_bdiropq = au_dbdiropq(a->src_dentry);
18315 + a->src_hinode = au_hi(a->src_inode, a->btgt);
18316 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
18317 + diropq = au_diropq_create(a->src_dentry, a->btgt);
18318 + au_hn_imtx_unlock(a->src_hinode);
18319 + if (IS_ERR(diropq))
18320 + err = PTR_ERR(diropq);
18326 +static int do_rename(struct au_ren_args *a)
18329 + struct dentry *d, *h_d;
18331 + /* prepare workqueue args for asynchronous rmdir */
18332 + h_d = a->dst_h_dentry;
18333 + if (au_ftest_ren(a->flags, ISDIR) && h_d->d_inode) {
18335 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb, GFP_NOFS);
18336 + if (unlikely(!a->thargs))
18338 + a->h_dst = dget(h_d);
18341 + /* create whiteout for src_dentry */
18342 + if (au_ftest_ren(a->flags, WHSRC)) {
18343 + a->src_bwh = au_dbwh(a->src_dentry);
18344 + AuDebugOn(a->src_bwh >= 0);
18346 + = au_wh_create(a->src_dentry, a->btgt, a->src_h_parent);
18347 + err = PTR_ERR(a->src_wh_dentry);
18348 + if (IS_ERR(a->src_wh_dentry))
18352 + /* lookup whiteout for dentry */
18353 + if (au_ftest_ren(a->flags, WHDST)) {
18354 + h_d = au_wh_lkup(a->dst_h_parent, &a->dst_dentry->d_name,
18356 + err = PTR_ERR(h_d);
18359 + if (!h_d->d_inode)
18362 + a->dst_wh_dentry = h_d;
18365 + /* rename dentry to tmpwh */
18367 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
18368 + if (unlikely(err))
18371 + d = a->dst_dentry;
18372 + au_set_h_dptr(d, a->btgt, NULL);
18373 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
18374 + if (unlikely(err))
18376 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
18379 + BUG_ON(a->dst_h_dentry->d_inode && a->src_bstart != a->btgt);
18381 + /* rename by vfs_rename or cpup */
18382 + d = a->dst_dentry;
18383 + if (au_ftest_ren(a->flags, ISDIR)
18384 + && (a->dst_wh_dentry
18385 + || au_dbdiropq(d) == a->btgt
18386 + /* hide the lower to keep xino */
18387 + || a->btgt < au_dbend(d)
18388 + || au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ)))
18389 + au_fset_ren(a->flags, DIROPQ);
18390 + err = au_ren_or_cpup(a);
18391 + if (unlikely(err))
18392 + /* leave the copied-up one */
18395 + /* make dir opaque */
18396 + if (au_ftest_ren(a->flags, DIROPQ)) {
18397 + err = au_ren_diropq(a);
18398 + if (unlikely(err))
18402 + /* update target timestamps */
18403 + AuDebugOn(au_dbstart(a->src_dentry) != a->btgt);
18404 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
18405 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
18406 + a->src_inode->i_ctime = a->h_path.dentry->d_inode->i_ctime;
18408 + /* remove whiteout for dentry */
18409 + if (a->dst_wh_dentry) {
18410 + a->h_path.dentry = a->dst_wh_dentry;
18411 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
18413 + if (unlikely(err))
18417 + /* remove whtmp */
18419 + au_ren_del_whtmp(a); /* ignore this error */
18422 + goto out_success;
18425 + if (au_ftest_ren(a->flags, DIROPQ))
18426 + au_ren_rev_diropq(err, a);
18428 + if (!au_ftest_ren(a->flags, CPUP))
18429 + au_ren_rev_rename(err, a);
18431 + au_ren_rev_cpup(err, a);
18435 + au_ren_rev_whtmp(err, a);
18437 + dput(a->dst_wh_dentry);
18438 + a->dst_wh_dentry = NULL;
18440 + if (a->src_wh_dentry)
18441 + au_ren_rev_whsrc(err, a);
18443 + dput(a->src_wh_dentry);
18444 + dput(a->dst_wh_dentry);
18448 + au_whtmp_rmdir_free(a->thargs);
18449 + a->thargs = NULL;
18455 +/* ---------------------------------------------------------------------- */
18458 + * test if @dentry dir can be rename destination or not.
18459 + * success means, it is a logically empty dir.
18461 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
18463 + return au_test_empty(dentry, whlist);
18467 + * test if @dentry dir can be rename source or not.
18468 + * if it can, return 0 and @children is filled.
18470 + * - it is a logically empty dir.
18471 + * - or, it exists on writable branch and has no children including whiteouts
18472 + * on the lower branch.
18474 +static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt)
18477 + unsigned int rdhash;
18478 + aufs_bindex_t bstart;
18480 + bstart = au_dbstart(dentry);
18481 + if (bstart != btgt) {
18482 + struct au_nhash whlist;
18484 + SiMustAnyLock(dentry->d_sb);
18485 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
18487 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
18489 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
18490 + if (unlikely(err))
18492 + err = au_test_empty(dentry, &whlist);
18493 + au_nhash_wh_free(&whlist);
18497 + if (bstart == au_dbtaildir(dentry))
18498 + return 0; /* success */
18500 + err = au_test_empty_lower(dentry);
18503 + if (err == -ENOTEMPTY) {
18504 + AuWarn1("renaming dir who has child(ren) on multiple branches,"
18505 + " is not supported\n");
18511 +/* side effect: sets whlist and h_dentry */
18512 +static int au_ren_may_dir(struct au_ren_args *a)
18515 + unsigned int rdhash;
18516 + struct dentry *d;
18518 + d = a->dst_dentry;
18519 + SiMustAnyLock(d->d_sb);
18522 + if (au_ftest_ren(a->flags, ISDIR) && a->dst_inode) {
18523 + rdhash = au_sbi(d->d_sb)->si_rdhash;
18525 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
18526 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
18527 + if (unlikely(err))
18530 + au_set_dbstart(d, a->dst_bstart);
18531 + err = may_rename_dstdir(d, &a->whlist);
18532 + au_set_dbstart(d, a->btgt);
18534 + a->dst_h_dentry = au_h_dptr(d, au_dbstart(d));
18535 + if (unlikely(err))
18538 + d = a->src_dentry;
18539 + a->src_h_dentry = au_h_dptr(d, au_dbstart(d));
18540 + if (au_ftest_ren(a->flags, ISDIR)) {
18541 + err = may_rename_srcdir(d, a->btgt);
18542 + if (unlikely(err)) {
18543 + au_nhash_wh_free(&a->whlist);
18544 + a->whlist.nh_num = 0;
18551 +/* ---------------------------------------------------------------------- */
18554 + * simple tests for rename.
18555 + * following the checks in vfs, plus the parent-child relationship.
18557 +static int au_may_ren(struct au_ren_args *a)
18560 + struct inode *h_inode;
18562 + if (a->src_bstart == a->btgt) {
18563 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
18564 + au_ftest_ren(a->flags, ISDIR));
18565 + if (unlikely(err))
18568 + if (unlikely(a->src_h_dentry == a->h_trap))
18573 + if (a->dst_bstart != a->btgt)
18576 + err = -ENOTEMPTY;
18577 + if (unlikely(a->dst_h_dentry == a->h_trap))
18581 + h_inode = a->dst_h_dentry->d_inode;
18582 + isdir = !!au_ftest_ren(a->flags, ISDIR);
18583 + if (!a->dst_dentry->d_inode) {
18584 + if (unlikely(h_inode))
18586 + err = au_may_add(a->dst_dentry, a->btgt, a->dst_h_parent,
18589 + if (unlikely(!h_inode || !h_inode->i_nlink))
18591 + err = au_may_del(a->dst_dentry, a->btgt, a->dst_h_parent,
18593 + if (unlikely(err))
18598 + if (unlikely(err == -ENOENT || err == -EEXIST))
18604 +/* ---------------------------------------------------------------------- */
18609 + * - src_dir and dir by lock_rename()
18610 + * - inode if exitsts
18613 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
18615 + * + di_write_lock2_child()
18616 + * + di_write_lock_child()
18617 + * + ii_write_lock_child()
18618 + * + di_write_lock_child2()
18619 + * + ii_write_lock_child2()
18620 + * + src_parent and parent
18621 + * + di_write_lock_parent()
18622 + * + ii_write_lock_parent()
18623 + * + di_write_lock_parent2()
18624 + * + ii_write_lock_parent2()
18625 + * + lower src_dir and dir by vfsub_lock_rename()
18626 + * + verify the every relationships between child and parent. if any
18627 + * of them failed, unlock all and return -EBUSY.
18629 +static void au_ren_unlock(struct au_ren_args *a)
18631 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
18632 + a->dst_h_parent, a->dst_hdir);
18633 + if (au_ftest_ren(a->flags, MNT_WRITE))
18634 + vfsub_mnt_drop_write(au_br_mnt(a->br));
18637 +static int au_ren_lock(struct au_ren_args *a)
18640 + unsigned int udba;
18643 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
18644 + a->src_hdir = au_hi(a->src_dir, a->btgt);
18645 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
18646 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
18648 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
18649 + if (unlikely(err))
18651 + au_fset_ren(a->flags, MNT_WRITE);
18652 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
18653 + a->dst_h_parent, a->dst_hdir);
18654 + udba = au_opt_udba(a->src_dentry->d_sb);
18655 + if (unlikely(a->src_hdir->hi_inode != a->src_h_parent->d_inode
18656 + || a->dst_hdir->hi_inode != a->dst_h_parent->d_inode))
18657 + err = au_busy_or_stale();
18658 + if (!err && au_dbstart(a->src_dentry) == a->btgt)
18659 + err = au_h_verify(a->src_h_dentry, udba,
18660 + a->src_h_parent->d_inode, a->src_h_parent,
18662 + if (!err && au_dbstart(a->dst_dentry) == a->btgt)
18663 + err = au_h_verify(a->dst_h_dentry, udba,
18664 + a->dst_h_parent->d_inode, a->dst_h_parent,
18667 + goto out; /* success */
18669 + err = au_busy_or_stale();
18670 + au_ren_unlock(a);
18676 +/* ---------------------------------------------------------------------- */
18678 +static void au_ren_refresh_dir(struct au_ren_args *a)
18680 + struct inode *dir;
18682 + dir = a->dst_dir;
18683 + dir->i_version++;
18684 + if (au_ftest_ren(a->flags, ISDIR)) {
18685 + /* is this updating defined in POSIX? */
18686 + au_cpup_attr_timesizes(a->src_inode);
18687 + au_cpup_attr_nlink(dir, /*force*/1);
18690 + if (au_ibstart(dir) == a->btgt)
18691 + au_cpup_attr_timesizes(dir);
18693 + if (au_ftest_ren(a->flags, ISSAMEDIR))
18696 + dir = a->src_dir;
18697 + dir->i_version++;
18698 + if (au_ftest_ren(a->flags, ISDIR))
18699 + au_cpup_attr_nlink(dir, /*force*/1);
18700 + if (au_ibstart(dir) == a->btgt)
18701 + au_cpup_attr_timesizes(dir);
18704 +static void au_ren_refresh(struct au_ren_args *a)
18706 + aufs_bindex_t bend, bindex;
18707 + struct dentry *d, *h_d;
18708 + struct inode *i, *h_i;
18709 + struct super_block *sb;
18711 + d = a->dst_dentry;
18714 + /* already dget-ed by au_ren_or_cpup() */
18715 + au_set_h_dptr(d, a->btgt, a->h_dst);
18717 + i = a->dst_inode;
18719 + if (!au_ftest_ren(a->flags, ISDIR))
18720 + vfsub_drop_nlink(i);
18722 + vfsub_dead_dir(i);
18723 + au_cpup_attr_timesizes(i);
18725 + au_update_dbrange(d, /*do_put_zero*/1);
18728 + for (bindex = au_dbstart(d); bindex < bend; bindex++)
18729 + au_set_h_dptr(d, bindex, NULL);
18730 + bend = au_dbend(d);
18731 + for (bindex = a->btgt + 1; bindex <= bend; bindex++)
18732 + au_set_h_dptr(d, bindex, NULL);
18733 + au_update_dbrange(d, /*do_put_zero*/0);
18736 + d = a->src_dentry;
18737 + au_set_dbwh(d, -1);
18738 + bend = au_dbend(d);
18739 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
18740 + h_d = au_h_dptr(d, bindex);
18742 + au_set_h_dptr(d, bindex, NULL);
18744 + au_set_dbend(d, a->btgt);
18747 + i = a->src_inode;
18748 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
18749 + return; /* success */
18751 + bend = au_ibend(i);
18752 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
18753 + h_i = au_h_iptr(i, bindex);
18755 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
18756 + /* ignore this error */
18757 + au_set_h_iptr(i, bindex, NULL, 0);
18760 + au_set_ibend(i, a->btgt);
18763 +/* ---------------------------------------------------------------------- */
18765 +/* mainly for link(2) and rename(2) */
18766 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
18768 + aufs_bindex_t bdiropq, bwh;
18769 + struct dentry *parent;
18770 + struct au_branch *br;
18772 + parent = dentry->d_parent;
18773 + IMustLock(parent->d_inode); /* dir is locked */
18775 + bdiropq = au_dbdiropq(parent);
18776 + bwh = au_dbwh(dentry);
18777 + br = au_sbr(dentry->d_sb, btgt);
18778 + if (au_br_rdonly(br)
18779 + || (0 <= bdiropq && bdiropq < btgt)
18780 + || (0 <= bwh && bwh < btgt))
18783 + AuDbg("btgt %d\n", btgt);
18787 +/* sets src_bstart, dst_bstart and btgt */
18788 +static int au_ren_wbr(struct au_ren_args *a)
18791 + struct au_wr_dir_args wr_dir_args = {
18792 + /* .force_btgt = -1, */
18793 + .flags = AuWrDir_ADD_ENTRY
18796 + a->src_bstart = au_dbstart(a->src_dentry);
18797 + a->dst_bstart = au_dbstart(a->dst_dentry);
18798 + if (au_ftest_ren(a->flags, ISDIR))
18799 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
18800 + wr_dir_args.force_btgt = a->src_bstart;
18801 + if (a->dst_inode && a->dst_bstart < a->src_bstart)
18802 + wr_dir_args.force_btgt = a->dst_bstart;
18803 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
18804 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
18810 +static void au_ren_dt(struct au_ren_args *a)
18812 + a->h_path.dentry = a->src_h_parent;
18813 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
18814 + if (!au_ftest_ren(a->flags, ISSAMEDIR)) {
18815 + a->h_path.dentry = a->dst_h_parent;
18816 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
18819 + au_fclr_ren(a->flags, DT_DSTDIR);
18820 + if (!au_ftest_ren(a->flags, ISDIR))
18823 + a->h_path.dentry = a->src_h_dentry;
18824 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
18825 + if (a->dst_h_dentry->d_inode) {
18826 + au_fset_ren(a->flags, DT_DSTDIR);
18827 + a->h_path.dentry = a->dst_h_dentry;
18828 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
18832 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
18834 + struct dentry *h_d;
18835 + struct mutex *h_mtx;
18837 + au_dtime_revert(a->src_dt + AuPARENT);
18838 + if (!au_ftest_ren(a->flags, ISSAMEDIR))
18839 + au_dtime_revert(a->dst_dt + AuPARENT);
18841 + if (au_ftest_ren(a->flags, ISDIR) && err != -EIO) {
18842 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
18843 + h_mtx = &h_d->d_inode->i_mutex;
18844 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
18845 + au_dtime_revert(a->src_dt + AuCHILD);
18846 + mutex_unlock(h_mtx);
18848 + if (au_ftest_ren(a->flags, DT_DSTDIR)) {
18849 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
18850 + h_mtx = &h_d->d_inode->i_mutex;
18851 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
18852 + au_dtime_revert(a->dst_dt + AuCHILD);
18853 + mutex_unlock(h_mtx);
18858 +/* ---------------------------------------------------------------------- */
18860 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
18861 + struct inode *_dst_dir, struct dentry *_dst_dentry)
18864 + /* reduce stack space */
18865 + struct au_ren_args *a;
18867 + AuDbg("%.*s, %.*s\n", AuDLNPair(_src_dentry), AuDLNPair(_dst_dentry));
18868 + IMustLock(_src_dir);
18869 + IMustLock(_dst_dir);
18872 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
18873 + a = kzalloc(sizeof(*a), GFP_NOFS);
18874 + if (unlikely(!a))
18877 + a->src_dir = _src_dir;
18878 + a->src_dentry = _src_dentry;
18879 + a->src_inode = a->src_dentry->d_inode;
18880 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
18881 + a->dst_dir = _dst_dir;
18882 + a->dst_dentry = _dst_dentry;
18883 + a->dst_inode = a->dst_dentry->d_inode;
18884 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
18885 + if (a->dst_inode) {
18886 + IMustLock(a->dst_inode);
18887 + au_igrab(a->dst_inode);
18891 + flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
18892 + if (S_ISDIR(a->src_inode->i_mode)) {
18893 + au_fset_ren(a->flags, ISDIR);
18894 + if (unlikely(a->dst_inode && !S_ISDIR(a->dst_inode->i_mode)))
18896 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
18897 + AuLock_DIR | flags);
18899 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
18901 + if (unlikely(err))
18904 + err = au_d_hashed_positive(a->src_dentry);
18905 + if (unlikely(err))
18908 + if (a->dst_inode) {
18910 + * If it is a dir, VFS unhash dst_dentry before this
18911 + * function. It means we cannot rely upon d_unhashed().
18913 + if (unlikely(!a->dst_inode->i_nlink))
18915 + if (!S_ISDIR(a->dst_inode->i_mode)) {
18916 + err = au_d_hashed_positive(a->dst_dentry);
18917 + if (unlikely(err))
18919 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
18921 + } else if (unlikely(d_unhashed(a->dst_dentry)))
18925 + * is it possible?
18926 + * yes, it happend (in linux-3.3-rcN) but I don't know why.
18927 + * there may exist a problem somewhere else.
18930 + if (unlikely(a->dst_parent->d_inode == a->src_dentry->d_inode))
18933 + au_fset_ren(a->flags, ISSAMEDIR); /* temporary */
18934 + di_write_lock_parent(a->dst_parent);
18936 + /* which branch we process */
18937 + err = au_ren_wbr(a);
18938 + if (unlikely(err < 0))
18940 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
18941 + a->h_path.mnt = au_br_mnt(a->br);
18943 + /* are they available to be renamed */
18944 + err = au_ren_may_dir(a);
18945 + if (unlikely(err))
18946 + goto out_children;
18948 + /* prepare the writable parent dir on the same branch */
18949 + if (a->dst_bstart == a->btgt) {
18950 + au_fset_ren(a->flags, WHDST);
18952 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
18953 + if (unlikely(err))
18954 + goto out_children;
18957 + if (a->src_dir != a->dst_dir) {
18959 + * this temporary unlock is safe,
18960 + * because both dir->i_mutex are locked.
18962 + di_write_unlock(a->dst_parent);
18963 + di_write_lock_parent(a->src_parent);
18964 + err = au_wr_dir_need_wh(a->src_dentry,
18965 + au_ftest_ren(a->flags, ISDIR),
18967 + di_write_unlock(a->src_parent);
18968 + di_write_lock2_parent(a->src_parent, a->dst_parent, /*isdir*/1);
18969 + au_fclr_ren(a->flags, ISSAMEDIR);
18971 + err = au_wr_dir_need_wh(a->src_dentry,
18972 + au_ftest_ren(a->flags, ISDIR),
18974 + if (unlikely(err < 0))
18975 + goto out_children;
18977 + au_fset_ren(a->flags, WHSRC);
18980 + if (a->src_bstart != a->btgt) {
18981 + struct au_pin pin;
18983 + err = au_pin(&pin, a->src_dentry, a->btgt,
18984 + au_opt_udba(a->src_dentry->d_sb),
18985 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
18987 + struct au_cp_generic cpg = {
18988 + .dentry = a->src_dentry,
18990 + .bsrc = a->src_bstart,
18993 + .flags = AuCpup_DTIME | AuCpup_HOPEN
18995 + AuDebugOn(au_dbstart(a->src_dentry) != a->src_bstart);
18996 + err = au_sio_cpup_simple(&cpg);
18999 + if (unlikely(err))
19000 + goto out_children;
19001 + a->src_bstart = a->btgt;
19002 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
19003 + au_fset_ren(a->flags, WHSRC);
19006 + /* lock them all */
19007 + err = au_ren_lock(a);
19008 + if (unlikely(err))
19009 + /* leave the copied-up one */
19010 + goto out_children;
19012 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
19013 + err = au_may_ren(a);
19014 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
19015 + err = -ENAMETOOLONG;
19016 + if (unlikely(err))
19019 + /* store timestamps to be revertible */
19023 + err = do_rename(a);
19024 + if (unlikely(err))
19027 + /* update dir attributes */
19028 + au_ren_refresh_dir(a);
19030 + /* dput/iput all lower dentries */
19031 + au_ren_refresh(a);
19033 + goto out_hdir; /* success */
19036 + au_ren_rev_dt(err, a);
19038 + au_ren_unlock(a);
19040 + au_nhash_wh_free(&a->whlist);
19041 + if (err && a->dst_inode && a->dst_bstart != a->btgt) {
19042 + AuDbg("bstart %d, btgt %d\n", a->dst_bstart, a->btgt);
19043 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
19044 + au_set_dbstart(a->dst_dentry, a->dst_bstart);
19048 + d_move(a->src_dentry, a->dst_dentry);
19050 + au_update_dbstart(a->dst_dentry);
19051 + if (!a->dst_inode)
19052 + d_drop(a->dst_dentry);
19054 + if (au_ftest_ren(a->flags, ISSAMEDIR))
19055 + di_write_unlock(a->dst_parent);
19057 + di_write_unlock2(a->src_parent, a->dst_parent);
19059 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
19061 + iput(a->dst_inode);
19063 + au_whtmp_rmdir_free(a->thargs);
19069 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
19070 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
19071 +++ linux/fs/aufs/Kconfig 2013-07-06 13:20:47.736864659 +0200
19074 + tristate "Aufs (Advanced multi layered unification filesystem) support"
19076 + Aufs is a stackable unification filesystem such as Unionfs,
19077 + which unifies several directories and provides a merged single
19079 + In the early days, aufs was entirely re-designed and
19080 + re-implemented Unionfs Version 1.x series. Introducing many
19081 + original ideas, approaches and improvements, it becomes totally
19082 + different from Unionfs while keeping the basic features.
19086 + prompt "Maximum number of branches"
19087 + default AUFS_BRANCH_MAX_127
19089 + Specifies the maximum number of branches (or member directories)
19090 + in a single aufs. The larger value consumes more system
19091 + resources and has a minor impact to performance.
19092 +config AUFS_BRANCH_MAX_127
19095 + Specifies the maximum number of branches (or member directories)
19096 + in a single aufs. The larger value consumes more system
19097 + resources and has a minor impact to performance.
19098 +config AUFS_BRANCH_MAX_511
19101 + Specifies the maximum number of branches (or member directories)
19102 + in a single aufs. The larger value consumes more system
19103 + resources and has a minor impact to performance.
19104 +config AUFS_BRANCH_MAX_1023
19107 + Specifies the maximum number of branches (or member directories)
19108 + in a single aufs. The larger value consumes more system
19109 + resources and has a minor impact to performance.
19110 +config AUFS_BRANCH_MAX_32767
19113 + Specifies the maximum number of branches (or member directories)
19114 + in a single aufs. The larger value consumes more system
19115 + resources and has a minor impact to performance.
19118 +config AUFS_SBILIST
19120 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
19123 + Automatic configuration for internal use.
19124 + When aufs supports Magic SysRq or /proc, enabled automatically.
19126 +config AUFS_HNOTIFY
19127 + bool "Detect direct branch access (bypassing aufs)"
19129 + If you want to modify files on branches directly, eg. bypassing aufs,
19130 + and want aufs to detect the changes of them fully, then enable this
19131 + option and use 'udba=notify' mount option.
19132 + Currently there is only one available configuration, "fsnotify".
19133 + It will have a negative impact to the performance.
19134 + See detail in aufs.5.
19137 + prompt "method" if AUFS_HNOTIFY
19138 + default AUFS_HFSNOTIFY
19139 +config AUFS_HFSNOTIFY
19144 +config AUFS_EXPORT
19145 + bool "NFS-exportable aufs"
19146 + depends on EXPORTFS
19148 + If you want to export your mounted aufs via NFS, then enable this
19149 + option. There are several requirements for this configuration.
19150 + See detail in aufs.5.
19152 +config AUFS_INO_T_64
19154 + depends on AUFS_EXPORT
19155 + depends on 64BIT && !(ALPHA || S390)
19158 + Automatic configuration for internal use.
19159 + /* typedef unsigned long/int __kernel_ino_t */
19160 + /* alpha and s390x are int */
19163 + bool "Readdir in userspace"
19165 + Aufs has two methods to provide a merged view for a directory,
19166 + by a user-space library and by kernel-space natively. The latter
19167 + is always enabled but sometimes large and slow.
19168 + If you enable this option, install the library in aufs2-util
19169 + package, and set some environment variables for your readdir(3),
19170 + then the work will be handled in user-space which generally
19171 + shows better performance in most cases.
19172 + See detail in aufs.5.
19174 +config AUFS_PROC_MAP
19175 + bool "support for /proc/maps and lsof(1)"
19176 + depends on PROC_FS
19178 + When you issue mmap(2) in aufs, it is actually a direct mmap(2)
19179 + call to the file on the branch fs since the file in aufs is
19180 + purely virtual. And the file path printed in /proc/maps (and
19181 + others) will be the path on the branch fs. In most cases, it
19182 + does no harm. But some utilities like lsof(1) may confuse since
19183 + the utility or user may expect the file path in aufs to be
19185 + To address this issue, aufs provides a patch which introduces a
19186 + new member called vm_prfile into struct vm_are_struct. The patch
19187 + is meaningless without enabling this configuration since nobody
19188 + sets the new vm_prfile member.
19189 + If you don't apply the patch, then enabling this configuration
19190 + will cause a compile error.
19191 + This approach is fragile since if someone else make some changes
19192 + around vm_file, then vm_prfile may not work anymore. As a
19193 + workaround such case, aufs provides this configuration. If you
19194 + disable it, then lsof(1) may produce incorrect result but the
19195 + problem will be gone even if the aufs patch is applied (I hope).
19197 +config AUFS_SP_IATTR
19198 + bool "Respect the attributes (mtime/ctime mainly) of special files"
19200 + When you write something to a special file, some attributes of it
19201 + (mtime/ctime mainly) may be updated. Generally such updates are
19202 + less important (actually some device drivers and NFS ignore
19203 + it). But some applications (such like test program) requires
19204 + such updates. If you need these updates, then enable this
19205 + configuration which introduces some overhead.
19206 + Currently this configuration handles FIFO only.
19209 + bool "Show whiteouts"
19211 + If you want to make the whiteouts in aufs visible, then enable
19212 + this option and specify 'shwh' mount option. Although it may
19213 + sounds like philosophy or something, but in technically it
19214 + simply shows the name of whiteout with keeping its behaviour.
19216 +config AUFS_BR_RAMFS
19217 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
19219 + If you want to use ramfs as an aufs branch fs, then enable this
19220 + option. Generally tmpfs is recommended.
19221 + Aufs prohibited them to be a branch fs by default, because
19222 + initramfs becomes unusable after switch_root or something
19223 + generally. If you sets initramfs as an aufs branch and boot your
19224 + system by switch_root, you will meet a problem easily since the
19225 + files in initramfs may be inaccessible.
19226 + Unless you are going to use ramfs as an aufs branch fs without
19227 + switch_root or something, leave it N.
19229 +config AUFS_BR_FUSE
19230 + bool "Fuse fs as an aufs branch"
19231 + depends on FUSE_FS
19234 + If you want to use fuse-based userspace filesystem as an aufs
19235 + branch fs, then enable this option.
19236 + It implements the internal poll(2) operation which is
19237 + implemented by fuse only (curretnly).
19242 + Automatic configuration for internal use.
19244 +config AUFS_BR_HFSPLUS
19245 + bool "Hfsplus as an aufs branch"
19246 + depends on HFSPLUS_FS
19249 + If you want to use hfsplus fs as an aufs branch fs, then enable
19250 + this option. This option introduces a small overhead at
19251 + copying-up a file on hfsplus.
19253 +config AUFS_BDEV_LOOP
19255 + depends on BLK_DEV_LOOP
19258 + Automatic configuration for internal use.
19259 + Convert =[ym] into =y.
19262 + bool "Debug aufs"
19264 + Enable this to compile aufs internal debug code.
19265 + It will have a negative impact to the performance.
19267 +config AUFS_MAGIC_SYSRQ
19269 + depends on AUFS_DEBUG && MAGIC_SYSRQ
19272 + Automatic configuration for internal use.
19273 + When aufs supports Magic SysRq, enabled automatically.
19275 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
19276 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
19277 +++ linux/fs/aufs/loop.c 2013-07-30 22:42:55.842946719 +0200
19280 + * Copyright (C) 2005-2013 Junjiro R. Okajima
19282 + * This program, aufs is free software; you can redistribute it and/or modify
19283 + * it under the terms of the GNU General Public License as published by
19284 + * the Free Software Foundation; either version 2 of the License, or
19285 + * (at your option) any later version.
19287 + * This program is distributed in the hope that it will be useful,
19288 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19289 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19290 + * GNU General Public License for more details.
19292 + * You should have received a copy of the GNU General Public License
19293 + * along with this program; if not, write to the Free Software
19294 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19298 + * support for loopback block device as a branch
19301 +#include <linux/loop.h>
19305 + * test if two lower dentries have overlapping branches.
19307 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
19309 + struct super_block *h_sb;
19310 + struct loop_device *l;
19312 + h_sb = h_adding->d_sb;
19313 + if (MAJOR(h_sb->s_dev) != LOOP_MAJOR)
19316 + l = h_sb->s_bdev->bd_disk->private_data;
19317 + h_adding = l->lo_backing_file->f_dentry;
19319 + * h_adding can be local NFS.
19320 + * in this case aufs cannot detect the loop.
19322 + if (unlikely(h_adding->d_sb == sb))
19324 + return !!au_test_subdir(h_adding, sb->s_root);
19327 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
19328 +int au_test_loopback_kthread(void)
19331 + struct task_struct *tsk = current;
19332 + char c, comm[sizeof(tsk->comm)];
19335 + if (tsk->flags & PF_KTHREAD) {
19336 + get_task_comm(comm, tsk);
19338 + ret = ('0' <= c && c <= '9'
19339 + && !strncmp(comm, "loop", 4));
19345 +/* ---------------------------------------------------------------------- */
19347 +#define au_warn_loopback_step 16
19348 +static int au_warn_loopback_nelem = au_warn_loopback_step;
19349 +static unsigned long *au_warn_loopback_array;
19351 +void au_warn_loopback(struct super_block *h_sb)
19353 + int i, new_nelem;
19354 + unsigned long *a, magic;
19355 + static DEFINE_SPINLOCK(spin);
19357 + magic = h_sb->s_magic;
19358 + spin_lock(&spin);
19359 + a = au_warn_loopback_array;
19360 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
19361 + if (a[i] == magic) {
19362 + spin_unlock(&spin);
19366 + /* h_sb is new to us, print it */
19367 + if (i < au_warn_loopback_nelem) {
19372 + /* expand the array */
19373 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
19374 + a = au_kzrealloc(au_warn_loopback_array,
19375 + au_warn_loopback_nelem * sizeof(unsigned long),
19376 + new_nelem * sizeof(unsigned long), GFP_ATOMIC);
19378 + au_warn_loopback_nelem = new_nelem;
19379 + au_warn_loopback_array = a;
19384 + spin_unlock(&spin);
19385 + AuWarn1("realloc failed, ignored\n");
19389 + spin_unlock(&spin);
19390 + pr_warn("you may want to try another patch for loopback file "
19391 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
19394 +int au_loopback_init(void)
19397 + struct super_block *sb __maybe_unused;
19399 + AuDebugOn(sizeof(sb->s_magic) != sizeof(unsigned long));
19402 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
19403 + sizeof(unsigned long), GFP_NOFS);
19404 + if (unlikely(!au_warn_loopback_array))
19410 +void au_loopback_fin(void)
19412 + kfree(au_warn_loopback_array);
19414 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
19415 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
19416 +++ linux/fs/aufs/loop.h 2013-07-30 22:42:55.842946719 +0200
19419 + * Copyright (C) 2005-2013 Junjiro R. Okajima
19421 + * This program, aufs is free software; you can redistribute it and/or modify
19422 + * it under the terms of the GNU General Public License as published by
19423 + * the Free Software Foundation; either version 2 of the License, or
19424 + * (at your option) any later version.
19426 + * This program is distributed in the hope that it will be useful,
19427 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19428 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19429 + * GNU General Public License for more details.
19431 + * You should have received a copy of the GNU General Public License
19432 + * along with this program; if not, write to the Free Software
19433 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19437 + * support for loopback mount as a branch
19440 +#ifndef __AUFS_LOOP_H__
19441 +#define __AUFS_LOOP_H__
19446 +struct super_block;
19448 +#ifdef CONFIG_AUFS_BDEV_LOOP
19450 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
19451 +int au_test_loopback_kthread(void);
19452 +void au_warn_loopback(struct super_block *h_sb);
19454 +int au_loopback_init(void);
19455 +void au_loopback_fin(void);
19457 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
19458 + struct dentry *h_adding)
19459 +AuStubInt0(au_test_loopback_kthread, void)
19460 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
19462 +AuStubInt0(au_loopback_init, void)
19463 +AuStubVoid(au_loopback_fin, void)
19464 +#endif /* BLK_DEV_LOOP */
19466 +#endif /* __KERNEL__ */
19467 +#endif /* __AUFS_LOOP_H__ */
19468 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
19469 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
19470 +++ linux/fs/aufs/magic.mk 2013-07-06 13:20:47.750198454 +0200
19473 +# defined in ${srctree}/fs/fuse/inode.c
19475 +ifdef CONFIG_FUSE_FS
19476 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
19479 +# defined in ${srctree}/fs/ocfs2/ocfs2_fs.h
19481 +ifdef CONFIG_OCFS2_FS
19482 +ccflags-y += -DOCFS2_SUPER_MAGIC=0x7461636f
19485 +# defined in ${srctree}/fs/ocfs2/dlm/userdlm.h
19487 +ifdef CONFIG_OCFS2_FS_O2CB
19488 +ccflags-y += -DDLMFS_MAGIC=0x76a9f425
19491 +# defined in ${srctree}/fs/cifs/cifsfs.c
19493 +ifdef CONFIG_CIFS_FS
19494 +ccflags-y += -DCIFS_MAGIC_NUMBER=0xFF534D42
19497 +# defined in ${srctree}/fs/xfs/xfs_sb.h
19499 +ifdef CONFIG_XFS_FS
19500 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
19503 +# defined in ${srctree}/fs/configfs/mount.c
19505 +ifdef CONFIG_CONFIGFS_FS
19506 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
19509 +# defined in ${srctree}/fs/9p/v9fs.h
19511 +ifdef CONFIG_9P_FS
19512 +ccflags-y += -DV9FS_MAGIC=0x01021997
19515 +# defined in ${srctree}/fs/ubifs/ubifs.h
19517 +ifdef CONFIG_UBIFS_FS
19518 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
19521 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
19523 +ifdef CONFIG_HFSPLUS_FS
19524 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
19526 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
19527 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
19528 +++ linux/fs/aufs/Makefile 2013-08-23 23:59:39.631583456 +0200
19531 +include ${src}/magic.mk
19532 +ifeq (${CONFIG_AUFS_FS},m)
19533 +include ${src}/conf.mk
19535 +-include ${src}/priv_def.mk
19537 +# cf. include/linux/kernel.h
19539 +ccflags-y += -DDEBUG
19540 +# sparse requires the full pathname
19542 +ccflags-y += -include ${M}/../../include/linux/aufs_type.h
19544 +ccflags-y += -include ${srctree}/include/linux/aufs_type.h
19547 +obj-$(CONFIG_AUFS_FS) += aufs.o
19548 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
19549 + wkq.o vfsub.o dcsub.o \
19550 + cpup.o whout.o wbr_policy.o \
19551 + dinfo.o dentry.o \
19553 + finfo.o file.o f_op.o \
19555 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
19559 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
19560 +aufs-$(CONFIG_SYSFS) += sysfs.o
19561 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
19562 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
19563 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
19564 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
19565 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
19566 +aufs-$(CONFIG_AUFS_POLL) += poll.o
19567 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
19568 +aufs-$(CONFIG_AUFS_SP_IATTR) += f_op_sp.o
19569 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
19570 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
19571 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
19572 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
19573 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
19574 +++ linux/fs/aufs/module.c 2013-07-06 13:20:47.750198454 +0200
19577 + * Copyright (C) 2005-2013 Junjiro R. Okajima
19579 + * This program, aufs is free software; you can redistribute it and/or modify
19580 + * it under the terms of the GNU General Public License as published by
19581 + * the Free Software Foundation; either version 2 of the License, or
19582 + * (at your option) any later version.
19584 + * This program is distributed in the hope that it will be useful,
19585 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19586 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19587 + * GNU General Public License for more details.
19589 + * You should have received a copy of the GNU General Public License
19590 + * along with this program; if not, write to the Free Software
19591 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19595 + * module global variables and operations
19598 +#include <linux/module.h>
19599 +#include <linux/seq_file.h>
19602 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp)
19604 + if (new_sz <= nused)
19607 + p = krealloc(p, new_sz, gfp);
19609 + memset(p + nused, 0, new_sz - nused);
19613 +/* ---------------------------------------------------------------------- */
19618 +struct kmem_cache *au_cachep[AuCache_Last];
19619 +static int __init au_cache_init(void)
19621 + au_cachep[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
19622 + if (au_cachep[AuCache_DINFO])
19623 + /* SLAB_DESTROY_BY_RCU */
19624 + au_cachep[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
19625 + au_icntnr_init_once);
19626 + if (au_cachep[AuCache_ICNTNR])
19627 + au_cachep[AuCache_FINFO] = AuCacheCtor(au_finfo,
19628 + au_fi_init_once);
19629 + if (au_cachep[AuCache_FINFO])
19630 + au_cachep[AuCache_VDIR] = AuCache(au_vdir);
19631 + if (au_cachep[AuCache_VDIR])
19632 + au_cachep[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
19633 + if (au_cachep[AuCache_DEHSTR])
19639 +static void au_cache_fin(void)
19644 + * Make sure all delayed rcu free inodes are flushed before we
19649 + /* excluding AuCache_HNOTIFY */
19650 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
19651 + for (i = 0; i < AuCache_HNOTIFY; i++)
19652 + if (au_cachep[i]) {
19653 + kmem_cache_destroy(au_cachep[i]);
19654 + au_cachep[i] = NULL;
19658 +/* ---------------------------------------------------------------------- */
19660 +int au_dir_roflags;
19662 +#ifdef CONFIG_AUFS_SBILIST
19664 + * iterate_supers_type() doesn't protect us from
19665 + * remounting (branch management)
19667 +struct au_splhead au_sbilist;
19670 +struct lock_class_key au_lc_key[AuLcKey_Last];
19673 + * functions for module interface.
19675 +MODULE_LICENSE("GPL");
19676 +/* MODULE_LICENSE("GPL v2"); */
19677 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
19678 +MODULE_DESCRIPTION(AUFS_NAME
19679 + " -- Advanced multi layered unification filesystem");
19680 +MODULE_VERSION(AUFS_VERSION);
19681 +MODULE_ALIAS_FS(AUFS_NAME);
19683 +/* this module parameter has no meaning when SYSFS is disabled */
19684 +int sysaufs_brs = 1;
19685 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
19686 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
19688 +/* ---------------------------------------------------------------------- */
19690 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
19692 +int au_seq_path(struct seq_file *seq, struct path *path)
19694 + return seq_path(seq, path, au_esc_chars);
19697 +/* ---------------------------------------------------------------------- */
19699 +static int __init aufs_init(void)
19704 + p = au_esc_chars;
19705 + for (i = 1; i <= ' '; i++)
19711 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
19713 + au_sbilist_init();
19714 + sysaufs_brs_init();
19717 + err = sysaufs_init();
19718 + if (unlikely(err))
19720 + err = au_procfs_init();
19721 + if (unlikely(err))
19722 + goto out_sysaufs;
19723 + err = au_wkq_init();
19724 + if (unlikely(err))
19726 + err = au_loopback_init();
19727 + if (unlikely(err))
19729 + err = au_hnotify_init();
19730 + if (unlikely(err))
19731 + goto out_loopback;
19732 + err = au_sysrq_init();
19733 + if (unlikely(err))
19735 + err = au_cache_init();
19736 + if (unlikely(err))
19738 + err = register_filesystem(&aufs_fs_type);
19739 + if (unlikely(err))
19741 + /* since we define pr_fmt, call printk directly */
19742 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
19743 + goto out; /* success */
19750 + au_hnotify_fin();
19752 + au_loopback_fin();
19764 +static void __exit aufs_exit(void)
19766 + unregister_filesystem(&aufs_fs_type);
19769 + au_hnotify_fin();
19770 + au_loopback_fin();
19777 +module_init(aufs_init);
19778 +module_exit(aufs_exit);
19779 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
19780 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
19781 +++ linux/fs/aufs/module.h 2013-07-06 13:20:47.750198454 +0200
19784 + * Copyright (C) 2005-2013 Junjiro R. Okajima
19786 + * This program, aufs is free software; you can redistribute it and/or modify
19787 + * it under the terms of the GNU General Public License as published by
19788 + * the Free Software Foundation; either version 2 of the License, or
19789 + * (at your option) any later version.
19791 + * This program is distributed in the hope that it will be useful,
19792 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19793 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19794 + * GNU General Public License for more details.
19796 + * You should have received a copy of the GNU General Public License
19797 + * along with this program; if not, write to the Free Software
19798 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19802 + * module initialization and module-global
19805 +#ifndef __AUFS_MODULE_H__
19806 +#define __AUFS_MODULE_H__
19810 +#include <linux/slab.h>
19815 +/* module parameters */
19816 +extern int sysaufs_brs;
19818 +/* ---------------------------------------------------------------------- */
19820 +extern int au_dir_roflags;
19823 + AuLcNonDir_FIINFO,
19824 + AuLcNonDir_DIINFO,
19825 + AuLcNonDir_IIINFO,
19831 + AuLcSymlink_DIINFO,
19832 + AuLcSymlink_IIINFO,
19836 +extern struct lock_class_key au_lc_key[AuLcKey_Last];
19838 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp);
19839 +int au_seq_path(struct seq_file *seq, struct path *path);
19841 +#ifdef CONFIG_PROC_FS
19843 +int __init au_procfs_init(void);
19844 +void au_procfs_fin(void);
19846 +AuStubInt0(au_procfs_init, void);
19847 +AuStubVoid(au_procfs_fin, void);
19850 +/* ---------------------------------------------------------------------- */
19859 + AuCache_HNOTIFY, /* must be last */
19863 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
19864 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
19865 +#define AuCacheCtor(type, ctor) \
19866 + kmem_cache_create(#type, sizeof(struct type), \
19867 + __alignof__(struct type), AuCacheFlags, ctor)
19869 +extern struct kmem_cache *au_cachep[];
19871 +#define AuCacheFuncs(name, index) \
19872 +static inline struct au_##name *au_cache_alloc_##name(void) \
19873 +{ return kmem_cache_alloc(au_cachep[AuCache_##index], GFP_NOFS); } \
19874 +static inline void au_cache_free_##name(struct au_##name *p) \
19875 +{ kmem_cache_free(au_cachep[AuCache_##index], p); }
19877 +AuCacheFuncs(dinfo, DINFO);
19878 +AuCacheFuncs(icntnr, ICNTNR);
19879 +AuCacheFuncs(finfo, FINFO);
19880 +AuCacheFuncs(vdir, VDIR);
19881 +AuCacheFuncs(vdir_dehstr, DEHSTR);
19882 +#ifdef CONFIG_AUFS_HNOTIFY
19883 +AuCacheFuncs(hnotify, HNOTIFY);
19886 +#endif /* __KERNEL__ */
19887 +#endif /* __AUFS_MODULE_H__ */
19888 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
19889 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
19890 +++ linux/fs/aufs/mvdown.c 2013-08-23 23:59:39.634916914 +0200
19893 + * Copyright (C) 2011-2013 Junjiro R. Okajima
19895 + * This program, aufs is free software; you can redistribute it and/or modify
19896 + * it under the terms of the GNU General Public License as published by
19897 + * the Free Software Foundation; either version 2 of the License, or
19898 + * (at your option) any later version.
19900 + * This program is distributed in the hope that it will be useful,
19901 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19902 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19903 + * GNU General Public License for more details.
19905 + * You should have received a copy of the GNU General Public License
19906 + * along with this program; if not, write to the Free Software
19907 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19915 + AUFS_MVDOWN_NARRAY
19918 +struct au_mvd_args {
19920 + aufs_bindex_t bindex;
19921 + struct super_block *h_sb;
19922 + struct dentry *h_parent;
19923 + struct au_hinode *hdir;
19924 + struct inode *h_dir;
19925 + } info[AUFS_MVDOWN_NARRAY];
19927 + struct aufs_mvdown mvdown;
19928 + struct dentry *dentry, *parent;
19929 + struct inode *inode, *dir;
19930 + struct super_block *sb;
19931 + aufs_bindex_t bopq, bwh, bfound;
19932 + unsigned char rename_lock;
19933 + struct au_pin pin;
19936 +#define mvd_bsrc info[AUFS_MVDOWN_SRC].bindex
19937 +#define mvd_h_src_sb info[AUFS_MVDOWN_SRC].h_sb
19938 +#define mvd_h_src_parent info[AUFS_MVDOWN_SRC].h_parent
19939 +#define mvd_hdir_src info[AUFS_MVDOWN_SRC].hdir
19940 +#define mvd_h_src_dir info[AUFS_MVDOWN_SRC].h_dir
19942 +#define mvd_bdst info[AUFS_MVDOWN_DST].bindex
19943 +#define mvd_h_dst_sb info[AUFS_MVDOWN_DST].h_sb
19944 +#define mvd_h_dst_parent info[AUFS_MVDOWN_DST].h_parent
19945 +#define mvd_hdir_dst info[AUFS_MVDOWN_DST].hdir
19946 +#define mvd_h_dst_dir info[AUFS_MVDOWN_DST].h_dir
19948 +#define AU_MVD_PR(flag, ...) do { \
19950 + pr_err(__VA_ARGS__); \
19953 +/* make the parent dir on bdst */
19954 +static int au_do_mkdir(const unsigned char verbose, struct au_mvd_args *a)
19959 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
19960 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
19961 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
19962 + a->mvd_h_dst_parent = NULL;
19963 + if (au_dbend(a->parent) >= a->mvd_bdst)
19964 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
19965 + if (!a->mvd_h_dst_parent) {
19966 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
19967 + if (unlikely(err)) {
19968 + AU_MVD_PR(verbose, "cpdown_dirs failed\n");
19971 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
19979 +/* lock them all */
19980 +static int au_do_lock(const unsigned char verbose, struct au_mvd_args *a)
19983 + struct dentry *h_trap;
19985 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
19986 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
19987 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
19988 + a->rename_lock = 0;
19989 + err = au_pin(&a->pin, a->dentry, a->mvd_bdst, au_opt_udba(a->sb),
19990 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
19992 + a->mvd_h_src_dir = a->mvd_h_src_parent->d_inode;
19993 + mutex_lock_nested(&a->mvd_h_src_dir->i_mutex,
19994 + AuLsc_I_PARENT3);
19996 + AU_MVD_PR(verbose, "pin failed\n");
20001 + a->rename_lock = 1;
20002 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
20003 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
20005 + err = (h_trap != a->mvd_h_src_parent);
20007 + err = (h_trap != a->mvd_h_dst_parent);
20009 + BUG_ON(err); /* it should never happen */
20016 +static void au_do_unlock(const unsigned char verbose, struct au_mvd_args *a)
20018 + if (!a->rename_lock) {
20019 + mutex_unlock(&a->mvd_h_src_dir->i_mutex);
20020 + au_unpin(&a->pin);
20022 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
20023 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
20026 +/* copy-down the file */
20027 +static int au_do_cpdown(const unsigned char verbose, struct au_mvd_args *a)
20030 + struct au_cp_generic cpg = {
20031 + .dentry = a->dentry,
20032 + .bdst = a->mvd_bdst,
20033 + .bsrc = a->mvd_bsrc,
20036 + .flags = AuCpup_DTIME | AuCpup_HOPEN
20039 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
20040 + err = au_sio_cpdown_simple(&cpg);
20041 + if (unlikely(err))
20042 + AU_MVD_PR(verbose, "cpdown failed\n");
20049 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
20052 +static int au_do_unlink_wh(const unsigned char verbose, struct au_mvd_args *a)
20055 + struct path h_path;
20056 + struct au_branch *br;
20058 + br = au_sbr(a->sb, a->mvd_bdst);
20059 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
20060 + err = PTR_ERR(h_path.dentry);
20061 + if (IS_ERR(h_path.dentry)) {
20062 + AU_MVD_PR(verbose, "wh_lkup failed\n");
20067 + if (h_path.dentry->d_inode) {
20068 + h_path.mnt = au_br_mnt(br);
20069 + err = vfsub_unlink(a->mvd_h_dst_parent->d_inode, &h_path,
20071 + if (unlikely(err))
20072 + AU_MVD_PR(verbose, "wh_unlink failed\n");
20074 + dput(h_path.dentry);
20082 + * unlink the topmost h_dentry
20083 + * Note: the target file MAY be modified by UDBA between this mutex_unlock() and
20084 + * mutex_lock() in vfs_unlink(). in this case, such changes may be lost.
20086 +static int au_do_unlink(const unsigned char verbose, struct au_mvd_args *a)
20089 + struct path h_path;
20091 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
20092 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
20093 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, /*force*/0);
20094 + if (unlikely(err))
20095 + AU_MVD_PR(verbose, "unlink failed\n");
20102 + * copy-down the file and unlink the bsrc file.
20103 + * - unlink the bdst whout if exist
20104 + * - copy-down the file (with whtmp name and rename)
20105 + * - unlink the bsrc file
20107 +static int au_do_mvdown(const unsigned char verbose, struct au_mvd_args *a)
20111 + err = au_do_mkdir(verbose, a);
20113 + err = au_do_lock(verbose, a);
20114 + if (unlikely(err))
20118 + * do not revert the activities we made on bdst since they should be
20119 + * harmless in aufs.
20122 + err = au_do_cpdown(verbose, a);
20124 + err = au_do_unlink_wh(verbose, a);
20126 + err = au_do_unlink(verbose, a);
20127 + if (unlikely(err))
20130 + /* maintain internal array */
20131 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
20132 + au_set_dbstart(a->dentry, a->mvd_bdst);
20133 + if (au_dbend(a->dentry) < a->mvd_bdst)
20134 + au_set_dbend(a->dentry, a->mvd_bdst);
20135 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
20136 + au_set_ibstart(a->inode, a->mvd_bdst);
20137 + if (au_ibend(a->inode) < a->mvd_bdst)
20138 + au_set_ibend(a->inode, a->mvd_bdst);
20141 + au_do_unlock(verbose, a);
20147 +/* ---------------------------------------------------------------------- */
20149 +static int find_lower_writable(struct super_block *sb, aufs_bindex_t bindex)
20151 + aufs_bindex_t bend;
20152 + struct au_branch *br;
20154 + bend = au_sbend(sb);
20155 + for (bindex++; bindex <= bend; bindex++) {
20156 + br = au_sbr(sb, bindex);
20157 + if (!au_br_rdonly(br))
20164 +/* make sure the file is idle */
20165 +static int au_mvd_args_busy(const unsigned char verbose, struct au_mvd_args *a)
20167 + int err, plinked;
20168 + struct inode *h_src_inode;
20171 + h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
20172 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
20173 + if (au_dbstart(a->dentry) == a->mvd_bsrc
20174 + && a->dentry->d_count == 1
20175 + && atomic_read(&a->inode->i_count) == 1
20176 + /* && h_src_inode->i_nlink == 1 */
20177 + && (!plinked || !au_plink_test(a->inode))
20178 + && a->inode->i_nlink == 1)
20182 + AU_MVD_PR(verbose,
20183 + "b%d, d{b%d, c%u?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
20184 + a->mvd_bsrc, au_dbstart(a->dentry), a->dentry->d_count,
20185 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
20186 + h_src_inode->i_nlink,
20187 + plinked, plinked ? au_plink_test(a->inode) : 0);
20194 +/* make sure the parent dir is fine */
20195 +static int au_mvd_args_parent(const unsigned char verbose,
20196 + struct au_mvd_args *a)
20199 + aufs_bindex_t bindex;
20202 + if (unlikely(au_alive_dir(a->parent))) {
20204 + AU_MVD_PR(verbose, "parent dir is dead\n");
20208 + a->bopq = au_dbdiropq(a->parent);
20209 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
20210 + AuDbg("b%d\n", bindex);
20211 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
20212 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
20214 + AU_MVD_PR(verbose, "parent dir is opaque b%d, b%d\n",
20215 + a->bopq, a->mvd_bdst);
20223 +static int au_mvd_args_intermediate(const unsigned char verbose,
20224 + struct au_mvd_args *a)
20227 + struct au_dinfo *dinfo, *tmp;
20229 + /* lookup the next lower positive entry */
20231 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
20232 + if (unlikely(!tmp))
20237 + dinfo = au_di(a->dentry);
20238 + au_di_cp(tmp, dinfo);
20239 + au_di_swap(tmp, dinfo);
20241 + /* returns the number of positive dentries */
20242 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1, /*type*/0);
20244 + a->bwh = au_dbwh(a->dentry);
20245 + else if (err > 0)
20246 + a->bfound = au_dbstart(a->dentry);
20248 + au_di_swap(tmp, dinfo);
20249 + au_rw_write_unlock(&tmp->di_rwsem);
20251 + if (unlikely(err < 0))
20252 + AU_MVD_PR(verbose, "failed look-up lower\n");
20255 + * here, we have these cases.
20257 + * no positive dentry under bsrc. there are more sub-cases.
20259 + * there no whiteout, we can safely move-down.
20262 + * bsrc < bwh && bwh < bdst
20263 + * there is a whiteout on RO branch. cannot proceed.
20265 + * there is a whiteout on the RW target branch. it should
20268 + * there is a whiteout somewhere unrelated branch.
20269 + * -1 < bfound && bfound <= bsrc
20272 + * found, but it is on RO branch between bsrc and bdst. cannot
20275 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
20278 + * found, after we create the file on bdst, it will be hidden.
20281 + AuDebugOn(a->bfound == -1
20283 + && a->bwh <= a->mvd_bsrc);
20284 + AuDebugOn(-1 < a->bfound
20285 + && a->bfound <= a->mvd_bsrc);
20288 + if (a->bfound == -1
20289 + && a->mvd_bsrc < a->bwh
20291 + && a->bwh < a->mvd_bdst) {
20292 + AU_MVD_PR(verbose, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
20293 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
20295 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
20296 + AU_MVD_PR(verbose, "bdst %d, bfound %d\n",
20297 + a->mvd_bdst, a->bfound);
20301 + err = 0; /* success */
20308 +static int au_mvd_args_exist(const unsigned char verbose, struct au_mvd_args *a)
20312 + err = (a->bfound != a->mvd_bdst) ? 0 : -EEXIST;
20317 +static int au_mvd_args(const unsigned char verbose, struct au_mvd_args *a)
20320 + struct au_branch *br;
20323 + if (unlikely(S_ISDIR(a->inode->i_mode)))
20327 + a->mvd_bsrc = au_ibstart(a->inode);
20328 + if (unlikely(a->mvd_bsrc == au_sbend(a->sb))) {
20329 + AU_MVD_PR(verbose, "on the bottom\n");
20332 + br = au_sbr(a->sb, a->mvd_bsrc);
20333 + err = au_br_rdonly(br);
20334 + if (unlikely(err))
20338 + a->mvd_bdst = find_lower_writable(a->sb, a->mvd_bsrc);
20339 + if (unlikely(a->mvd_bdst < 0)) {
20340 + AU_MVD_PR(verbose, "no writable lower branch\n");
20344 + err = au_mvd_args_busy(verbose, a);
20346 + err = au_mvd_args_parent(verbose, a);
20348 + err = au_mvd_args_intermediate(verbose, a);
20350 + err = au_mvd_args_exist(verbose, a);
20352 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
20359 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
20362 + unsigned char verbose;
20363 + struct au_mvd_args args = {
20364 + .dentry = dentry,
20365 + .inode = dentry->d_inode,
20366 + .sb = dentry->d_sb
20370 + if (unlikely(!capable(CAP_SYS_ADMIN)))
20373 + err = copy_from_user(&args.mvdown, uarg, sizeof(args.mvdown));
20374 + if (unlikely(err)) {
20378 + AuDbg("flags 0x%x\n", args.mvdown.flags);
20381 + verbose = !!(args.mvdown.flags & AUFS_MVDOWN_VERBOSE);
20382 + args.parent = dget_parent(dentry);
20383 + args.dir = args.parent->d_inode;
20384 + mutex_lock_nested(&args.dir->i_mutex, I_MUTEX_PARENT);
20385 + dput(args.parent);
20386 + if (unlikely(args.parent != dentry->d_parent)) {
20387 + AU_MVD_PR(verbose, "parent dir is moved\n");
20391 + mutex_lock_nested(&args.inode->i_mutex, I_MUTEX_CHILD);
20392 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH);
20393 + if (unlikely(err))
20396 + di_write_lock_parent(args.parent);
20397 + err = au_mvd_args(verbose, &args);
20398 + if (unlikely(err))
20401 + AuDbgDentry(dentry);
20402 + AuDbgInode(args.inode);
20403 + err = au_do_mvdown(verbose, &args);
20404 + if (unlikely(err))
20406 + AuDbgDentry(dentry);
20407 + AuDbgInode(args.inode);
20409 + au_cpup_attr_timesizes(args.dir);
20410 + au_cpup_attr_timesizes(args.inode);
20411 + au_cpup_igen(args.inode, au_h_iptr(args.inode, args.mvd_bdst));
20412 + /* au_digen_dec(dentry); */
20415 + di_write_unlock(args.parent);
20416 + aufs_read_unlock(dentry, AuLock_DW);
20418 + mutex_unlock(&args.inode->i_mutex);
20420 + mutex_unlock(&args.dir->i_mutex);
20425 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
20426 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
20427 +++ linux/fs/aufs/opts.c 2013-07-06 13:20:47.753531903 +0200
20430 + * Copyright (C) 2005-2013 Junjiro R. Okajima
20432 + * This program, aufs is free software; you can redistribute it and/or modify
20433 + * it under the terms of the GNU General Public License as published by
20434 + * the Free Software Foundation; either version 2 of the License, or
20435 + * (at your option) any later version.
20437 + * This program is distributed in the hope that it will be useful,
20438 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20439 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20440 + * GNU General Public License for more details.
20442 + * You should have received a copy of the GNU General Public License
20443 + * along with this program; if not, write to the Free Software
20444 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20448 + * mount options/flags
20451 +#include <linux/namei.h>
20452 +#include <linux/types.h> /* a distribution requires */
20453 +#include <linux/parser.h>
20456 +/* ---------------------------------------------------------------------- */
20460 + Opt_add, Opt_del, Opt_mod, Opt_reorder, Opt_append, Opt_prepend,
20461 + Opt_idel, Opt_imod, Opt_ireorder,
20462 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash, Opt_rendir,
20463 + Opt_rdblk_def, Opt_rdhash_def,
20464 + Opt_xino, Opt_zxino, Opt_noxino,
20465 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
20466 + Opt_trunc_xino_path, Opt_itrunc_xino,
20467 + Opt_trunc_xib, Opt_notrunc_xib,
20468 + Opt_shwh, Opt_noshwh,
20469 + Opt_plink, Opt_noplink, Opt_list_plink,
20471 + Opt_dio, Opt_nodio,
20472 + /* Opt_lock, Opt_unlock, */
20473 + Opt_cmd, Opt_cmd_args,
20474 + Opt_diropq_a, Opt_diropq_w,
20475 + Opt_warn_perm, Opt_nowarn_perm,
20476 + Opt_wbr_copyup, Opt_wbr_create,
20477 + Opt_refrof, Opt_norefrof,
20478 + Opt_verbose, Opt_noverbose,
20479 + Opt_sum, Opt_nosum, Opt_wsum,
20480 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
20483 +static match_table_t options = {
20484 + {Opt_br, "br=%s"},
20485 + {Opt_br, "br:%s"},
20487 + {Opt_add, "add=%d:%s"},
20488 + {Opt_add, "add:%d:%s"},
20489 + {Opt_add, "ins=%d:%s"},
20490 + {Opt_add, "ins:%d:%s"},
20491 + {Opt_append, "append=%s"},
20492 + {Opt_append, "append:%s"},
20493 + {Opt_prepend, "prepend=%s"},
20494 + {Opt_prepend, "prepend:%s"},
20496 + {Opt_del, "del=%s"},
20497 + {Opt_del, "del:%s"},
20498 + /* {Opt_idel, "idel:%d"}, */
20499 + {Opt_mod, "mod=%s"},
20500 + {Opt_mod, "mod:%s"},
20501 + /* {Opt_imod, "imod:%d:%s"}, */
20503 + {Opt_dirwh, "dirwh=%d"},
20505 + {Opt_xino, "xino=%s"},
20506 + {Opt_noxino, "noxino"},
20507 + {Opt_trunc_xino, "trunc_xino"},
20508 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
20509 + {Opt_notrunc_xino, "notrunc_xino"},
20510 + {Opt_trunc_xino_path, "trunc_xino=%s"},
20511 + {Opt_itrunc_xino, "itrunc_xino=%d"},
20512 + /* {Opt_zxino, "zxino=%s"}, */
20513 + {Opt_trunc_xib, "trunc_xib"},
20514 + {Opt_notrunc_xib, "notrunc_xib"},
20516 +#ifdef CONFIG_PROC_FS
20517 + {Opt_plink, "plink"},
20519 + {Opt_ignore_silent, "plink"},
20522 + {Opt_noplink, "noplink"},
20524 +#ifdef CONFIG_AUFS_DEBUG
20525 + {Opt_list_plink, "list_plink"},
20528 + {Opt_udba, "udba=%s"},
20530 + {Opt_dio, "dio"},
20531 + {Opt_nodio, "nodio"},
20533 + {Opt_diropq_a, "diropq=always"},
20534 + {Opt_diropq_a, "diropq=a"},
20535 + {Opt_diropq_w, "diropq=whiteouted"},
20536 + {Opt_diropq_w, "diropq=w"},
20538 + {Opt_warn_perm, "warn_perm"},
20539 + {Opt_nowarn_perm, "nowarn_perm"},
20541 + /* keep them temporary */
20542 + {Opt_ignore_silent, "coo=%s"},
20543 + {Opt_ignore_silent, "nodlgt"},
20544 + {Opt_ignore_silent, "nodirperm1"},
20545 + {Opt_ignore_silent, "clean_plink"},
20547 +#ifdef CONFIG_AUFS_SHWH
20548 + {Opt_shwh, "shwh"},
20550 + {Opt_noshwh, "noshwh"},
20552 + {Opt_rendir, "rendir=%d"},
20554 + {Opt_refrof, "refrof"},
20555 + {Opt_norefrof, "norefrof"},
20557 + {Opt_verbose, "verbose"},
20558 + {Opt_verbose, "v"},
20559 + {Opt_noverbose, "noverbose"},
20560 + {Opt_noverbose, "quiet"},
20561 + {Opt_noverbose, "q"},
20562 + {Opt_noverbose, "silent"},
20564 + {Opt_sum, "sum"},
20565 + {Opt_nosum, "nosum"},
20566 + {Opt_wsum, "wsum"},
20568 + {Opt_rdcache, "rdcache=%d"},
20569 + {Opt_rdblk, "rdblk=%d"},
20570 + {Opt_rdblk_def, "rdblk=def"},
20571 + {Opt_rdhash, "rdhash=%d"},
20572 + {Opt_rdhash_def, "rdhash=def"},
20574 + {Opt_wbr_create, "create=%s"},
20575 + {Opt_wbr_create, "create_policy=%s"},
20576 + {Opt_wbr_copyup, "cpup=%s"},
20577 + {Opt_wbr_copyup, "copyup=%s"},
20578 + {Opt_wbr_copyup, "copyup_policy=%s"},
20580 + /* internal use for the scripts */
20581 + {Opt_ignore_silent, "si=%s"},
20583 + {Opt_br, "dirs=%s"},
20584 + {Opt_ignore, "debug=%d"},
20585 + {Opt_ignore, "delete=whiteout"},
20586 + {Opt_ignore, "delete=all"},
20587 + {Opt_ignore, "imap=%s"},
20589 + /* temporary workaround, due to old mount(8)? */
20590 + {Opt_ignore_silent, "relatime"},
20595 +/* ---------------------------------------------------------------------- */
20597 +static const char *au_parser_pattern(int val, struct match_token *token)
20599 + while (token->pattern) {
20600 + if (token->token == val)
20601 + return token->pattern;
20608 +/* ---------------------------------------------------------------------- */
20610 +static match_table_t brperm = {
20611 + {AuBrPerm_RO, AUFS_BRPERM_RO},
20612 + {AuBrPerm_RR, AUFS_BRPERM_RR},
20613 + {AuBrPerm_RW, AUFS_BRPERM_RW},
20617 +static match_table_t brattr = {
20618 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
20619 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
20620 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
20624 +#define AuBrStr_LONGEST AUFS_BRPERM_RW \
20625 + "+" AUFS_BRATTR_UNPIN \
20626 + "+" AUFS_BRWATTR_NLWH
20628 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
20635 + p = strchr(str, '+');
20638 + v = match_token(str, table, args);
20644 + pr_warn("ignored branch attribute %s\n", str);
20654 +static int noinline_for_stack br_perm_val(char *perm)
20658 + substring_t args[MAX_OPT_ARGS];
20660 + p = strchr(perm, '+');
20663 + val = match_token(perm, brperm, args);
20667 + pr_warn("ignored branch permission %s\n", perm);
20668 + val = AuBrPerm_RO;
20676 + q = strchr(p, '+');
20679 + val |= br_attr_val(p, brattr, args);
20686 + switch (val & AuBrPerm_Mask) {
20687 + case AuBrPerm_RO:
20688 + case AuBrPerm_RR:
20689 + if (unlikely(val & AuBrWAttr_NoLinkWH)) {
20690 + pr_warn("ignored branch attribute %s\n",
20691 + AUFS_BRWATTR_NLWH);
20692 + val &= ~AuBrWAttr_NoLinkWH;
20695 + case AuBrPerm_RW:
20696 + if (unlikely(val & AuBrRAttr_WH)) {
20697 + pr_warn("ignored branch attribute %s\n",
20698 + AUFS_BRRATTR_WH);
20699 + val &= ~AuBrRAttr_WH;
20708 +/* Caller should free the return value */
20709 +char *au_optstr_br_perm(int brperm)
20711 + char *p, a[sizeof(AuBrStr_LONGEST)];
20714 +#define SetPerm(str) do { \
20715 + sz = sizeof(str); \
20716 + memcpy(a, str, sz); \
20717 + p = a + sz - 1; \
20720 +#define AppendAttr(flag, str) do { \
20721 + if (brperm & flag) { \
20722 + sz = sizeof(str); \
20724 + memcpy(p, str, sz); \
20729 + switch (brperm & AuBrPerm_Mask) {
20730 + case AuBrPerm_RO:
20731 + SetPerm(AUFS_BRPERM_RO);
20733 + case AuBrPerm_RR:
20734 + SetPerm(AUFS_BRPERM_RR);
20736 + case AuBrPerm_RW:
20737 + SetPerm(AUFS_BRPERM_RW);
20743 + AppendAttr(AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN);
20744 + AppendAttr(AuBrRAttr_WH, AUFS_BRRATTR_WH);
20745 + AppendAttr(AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH);
20747 + AuDebugOn(strlen(a) >= sizeof(a));
20748 + return kstrdup(a, GFP_NOFS);
20753 +/* ---------------------------------------------------------------------- */
20755 +static match_table_t udbalevel = {
20756 + {AuOpt_UDBA_REVAL, "reval"},
20757 + {AuOpt_UDBA_NONE, "none"},
20758 +#ifdef CONFIG_AUFS_HNOTIFY
20759 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
20760 +#ifdef CONFIG_AUFS_HFSNOTIFY
20761 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
20767 +static int noinline_for_stack udba_val(char *str)
20769 + substring_t args[MAX_OPT_ARGS];
20771 + return match_token(str, udbalevel, args);
20774 +const char *au_optstr_udba(int udba)
20776 + return au_parser_pattern(udba, (void *)udbalevel);
20779 +/* ---------------------------------------------------------------------- */
20781 +static match_table_t au_wbr_create_policy = {
20782 + {AuWbrCreate_TDP, "tdp"},
20783 + {AuWbrCreate_TDP, "top-down-parent"},
20784 + {AuWbrCreate_RR, "rr"},
20785 + {AuWbrCreate_RR, "round-robin"},
20786 + {AuWbrCreate_MFS, "mfs"},
20787 + {AuWbrCreate_MFS, "most-free-space"},
20788 + {AuWbrCreate_MFSV, "mfs:%d"},
20789 + {AuWbrCreate_MFSV, "most-free-space:%d"},
20791 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
20792 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
20793 + {AuWbrCreate_PMFS, "pmfs"},
20794 + {AuWbrCreate_PMFSV, "pmfs:%d"},
20800 + * cf. linux/lib/parser.c and cmdline.c
20801 + * gave up calling memparse() since it uses simple_strtoull() instead of
20804 +static int noinline_for_stack
20805 +au_match_ull(substring_t *s, unsigned long long *result)
20808 + unsigned int len;
20812 + len = s->to - s->from;
20813 + if (len + 1 <= sizeof(a)) {
20814 + memcpy(a, s->from, len);
20816 + err = kstrtoull(a, 0, result);
20821 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
20822 + struct au_opt_wbr_create *create)
20825 + unsigned long long ull;
20828 + if (!au_match_ull(arg, &ull))
20829 + create->mfsrr_watermark = ull;
20831 + pr_err("bad integer in %s\n", str);
20838 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
20839 + struct au_opt_wbr_create *create)
20844 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
20845 + create->mfs_second = n;
20847 + pr_err("bad integer in %s\n", str);
20854 +static int noinline_for_stack
20855 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
20858 + substring_t args[MAX_OPT_ARGS];
20860 + err = match_token(str, au_wbr_create_policy, args);
20861 + create->wbr_create = err;
20863 + case AuWbrCreate_MFSRRV:
20864 + e = au_wbr_mfs_wmark(&args[0], str, create);
20866 + e = au_wbr_mfs_sec(&args[1], str, create);
20870 + case AuWbrCreate_MFSRR:
20871 + e = au_wbr_mfs_wmark(&args[0], str, create);
20872 + if (unlikely(e)) {
20877 + case AuWbrCreate_MFS:
20878 + case AuWbrCreate_PMFS:
20879 + create->mfs_second = AUFS_MFS_DEF_SEC;
20881 + case AuWbrCreate_MFSV:
20882 + case AuWbrCreate_PMFSV:
20883 + e = au_wbr_mfs_sec(&args[0], str, create);
20892 +const char *au_optstr_wbr_create(int wbr_create)
20894 + return au_parser_pattern(wbr_create, (void *)au_wbr_create_policy);
20897 +static match_table_t au_wbr_copyup_policy = {
20898 + {AuWbrCopyup_TDP, "tdp"},
20899 + {AuWbrCopyup_TDP, "top-down-parent"},
20900 + {AuWbrCopyup_BUP, "bup"},
20901 + {AuWbrCopyup_BUP, "bottom-up-parent"},
20902 + {AuWbrCopyup_BU, "bu"},
20903 + {AuWbrCopyup_BU, "bottom-up"},
20907 +static int noinline_for_stack au_wbr_copyup_val(char *str)
20909 + substring_t args[MAX_OPT_ARGS];
20911 + return match_token(str, au_wbr_copyup_policy, args);
20914 +const char *au_optstr_wbr_copyup(int wbr_copyup)
20916 + return au_parser_pattern(wbr_copyup, (void *)au_wbr_copyup_policy);
20919 +/* ---------------------------------------------------------------------- */
20921 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
20923 +static void dump_opts(struct au_opts *opts)
20925 +#ifdef CONFIG_AUFS_DEBUG
20926 + /* reduce stack space */
20928 + struct au_opt_add *add;
20929 + struct au_opt_del *del;
20930 + struct au_opt_mod *mod;
20931 + struct au_opt_xino *xino;
20932 + struct au_opt_xino_itrunc *xino_itrunc;
20933 + struct au_opt_wbr_create *create;
20935 + struct au_opt *opt;
20938 + while (opt->type != Opt_tail) {
20939 + switch (opt->type) {
20941 + u.add = &opt->add;
20942 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
20943 + u.add->bindex, u.add->pathname, u.add->perm,
20944 + u.add->path.dentry);
20948 + u.del = &opt->del;
20949 + AuDbg("del {%s, %p}\n",
20950 + u.del->pathname, u.del->h_path.dentry);
20954 + u.mod = &opt->mod;
20955 + AuDbg("mod {%s, 0x%x, %p}\n",
20956 + u.mod->path, u.mod->perm, u.mod->h_root);
20959 + u.add = &opt->add;
20960 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
20961 + u.add->bindex, u.add->pathname, u.add->perm,
20962 + u.add->path.dentry);
20964 + case Opt_prepend:
20965 + u.add = &opt->add;
20966 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
20967 + u.add->bindex, u.add->pathname, u.add->perm,
20968 + u.add->path.dentry);
20971 + AuDbg("dirwh %d\n", opt->dirwh);
20973 + case Opt_rdcache:
20974 + AuDbg("rdcache %d\n", opt->rdcache);
20977 + AuDbg("rdblk %u\n", opt->rdblk);
20979 + case Opt_rdblk_def:
20980 + AuDbg("rdblk_def\n");
20983 + AuDbg("rdhash %u\n", opt->rdhash);
20985 + case Opt_rdhash_def:
20986 + AuDbg("rdhash_def\n");
20989 + u.xino = &opt->xino;
20990 + AuDbg("xino {%s %.*s}\n",
20992 + AuDLNPair(u.xino->file->f_dentry));
20994 + case Opt_trunc_xino:
20995 + AuLabel(trunc_xino);
20997 + case Opt_notrunc_xino:
20998 + AuLabel(notrunc_xino);
21000 + case Opt_trunc_xino_path:
21001 + case Opt_itrunc_xino:
21002 + u.xino_itrunc = &opt->xino_itrunc;
21003 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
21009 + case Opt_trunc_xib:
21010 + AuLabel(trunc_xib);
21012 + case Opt_notrunc_xib:
21013 + AuLabel(notrunc_xib);
21024 + case Opt_noplink:
21025 + AuLabel(noplink);
21027 + case Opt_list_plink:
21028 + AuLabel(list_plink);
21031 + AuDbg("udba %d, %s\n",
21032 + opt->udba, au_optstr_udba(opt->udba));
21040 + case Opt_diropq_a:
21041 + AuLabel(diropq_a);
21043 + case Opt_diropq_w:
21044 + AuLabel(diropq_w);
21046 + case Opt_warn_perm:
21047 + AuLabel(warn_perm);
21049 + case Opt_nowarn_perm:
21050 + AuLabel(nowarn_perm);
21055 + case Opt_norefrof:
21056 + AuLabel(norefrof);
21058 + case Opt_verbose:
21059 + AuLabel(verbose);
21061 + case Opt_noverbose:
21062 + AuLabel(noverbose);
21073 + case Opt_wbr_create:
21074 + u.create = &opt->wbr_create;
21075 + AuDbg("create %d, %s\n", u.create->wbr_create,
21076 + au_optstr_wbr_create(u.create->wbr_create));
21077 + switch (u.create->wbr_create) {
21078 + case AuWbrCreate_MFSV:
21079 + case AuWbrCreate_PMFSV:
21080 + AuDbg("%d sec\n", u.create->mfs_second);
21082 + case AuWbrCreate_MFSRR:
21083 + AuDbg("%llu watermark\n",
21084 + u.create->mfsrr_watermark);
21086 + case AuWbrCreate_MFSRRV:
21087 + AuDbg("%llu watermark, %d sec\n",
21088 + u.create->mfsrr_watermark,
21089 + u.create->mfs_second);
21093 + case Opt_wbr_copyup:
21094 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
21095 + au_optstr_wbr_copyup(opt->wbr_copyup));
21105 +void au_opts_free(struct au_opts *opts)
21107 + struct au_opt *opt;
21110 + while (opt->type != Opt_tail) {
21111 + switch (opt->type) {
21114 + case Opt_prepend:
21115 + path_put(&opt->add.path);
21119 + path_put(&opt->del.h_path);
21123 + dput(opt->mod.h_root);
21126 + fput(opt->xino.file);
21133 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
21134 + aufs_bindex_t bindex)
21137 + struct au_opt_add *add = &opt->add;
21140 + add->bindex = bindex;
21141 + add->perm = AuBrPerm_RO;
21142 + add->pathname = opt_str;
21143 + p = strchr(opt_str, '=');
21147 + add->perm = br_perm_val(p);
21150 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
21153 + add->perm = AuBrPerm_RO;
21154 + if (au_test_fs_rr(add->path.dentry->d_sb))
21155 + add->perm = AuBrPerm_RR;
21156 + else if (!bindex && !(sb_flags & MS_RDONLY))
21157 + add->perm = AuBrPerm_RW;
21159 + opt->type = Opt_add;
21162 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
21169 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
21173 + del->pathname = args[0].from;
21174 + AuDbg("del path %s\n", del->pathname);
21176 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
21177 + if (unlikely(err))
21178 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
21183 +#if 0 /* reserved for future use */
21184 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
21185 + struct au_opt_del *del, substring_t args[])
21188 + struct dentry *root;
21191 + root = sb->s_root;
21192 + aufs_read_lock(root, AuLock_FLUSH);
21193 + if (bindex < 0 || au_sbend(sb) < bindex) {
21194 + pr_err("out of bounds, %d\n", bindex);
21199 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
21200 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
21203 + aufs_read_unlock(root, !AuLock_IR);
21208 +static int noinline_for_stack
21209 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
21212 + struct path path;
21216 + mod->path = args[0].from;
21217 + p = strchr(mod->path, '=');
21218 + if (unlikely(!p)) {
21219 + pr_err("no permssion %s\n", args[0].from);
21224 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
21225 + if (unlikely(err)) {
21226 + pr_err("lookup failed %s (%d)\n", mod->path, err);
21230 + mod->perm = br_perm_val(p);
21231 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
21232 + mod->h_root = dget(path.dentry);
21239 +#if 0 /* reserved for future use */
21240 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
21241 + struct au_opt_mod *mod, substring_t args[])
21244 + struct dentry *root;
21247 + root = sb->s_root;
21248 + aufs_read_lock(root, AuLock_FLUSH);
21249 + if (bindex < 0 || au_sbend(sb) < bindex) {
21250 + pr_err("out of bounds, %d\n", bindex);
21255 + mod->perm = br_perm_val(args[1].from);
21256 + AuDbg("mod path %s, perm 0x%x, %s\n",
21257 + mod->path, mod->perm, args[1].from);
21258 + mod->h_root = dget(au_h_dptr(root, bindex));
21261 + aufs_read_unlock(root, !AuLock_IR);
21266 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
21267 + substring_t args[])
21270 + struct file *file;
21272 + file = au_xino_create(sb, args[0].from, /*silent*/0);
21273 + err = PTR_ERR(file);
21274 + if (IS_ERR(file))
21278 + if (unlikely(file->f_dentry->d_sb == sb)) {
21280 + pr_err("%s must be outside\n", args[0].from);
21285 + xino->file = file;
21286 + xino->path = args[0].from;
21292 +static int noinline_for_stack
21293 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
21294 + struct au_opt_xino_itrunc *xino_itrunc,
21295 + substring_t args[])
21298 + aufs_bindex_t bend, bindex;
21299 + struct path path;
21300 + struct dentry *root;
21302 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
21303 + if (unlikely(err)) {
21304 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
21308 + xino_itrunc->bindex = -1;
21309 + root = sb->s_root;
21310 + aufs_read_lock(root, AuLock_FLUSH);
21311 + bend = au_sbend(sb);
21312 + for (bindex = 0; bindex <= bend; bindex++) {
21313 + if (au_h_dptr(root, bindex) == path.dentry) {
21314 + xino_itrunc->bindex = bindex;
21318 + aufs_read_unlock(root, !AuLock_IR);
21321 + if (unlikely(xino_itrunc->bindex < 0)) {
21322 + pr_err("no such branch %s\n", args[0].from);
21330 +/* called without aufs lock */
21331 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
21333 + int err, n, token;
21334 + aufs_bindex_t bindex;
21335 + unsigned char skipped;
21336 + struct dentry *root;
21337 + struct au_opt *opt, *opt_tail;
21339 + /* reduce the stack space */
21341 + struct au_opt_xino_itrunc *xino_itrunc;
21342 + struct au_opt_wbr_create *create;
21345 + substring_t args[MAX_OPT_ARGS];
21349 + a = kmalloc(sizeof(*a), GFP_NOFS);
21350 + if (unlikely(!a))
21353 + root = sb->s_root;
21357 + opt_tail = opt + opts->max_opt - 1;
21358 + opt->type = Opt_tail;
21359 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
21362 + token = match_token(opt_str, options, a->args);
21366 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
21368 + err = opt_add(opt, opt_str, opts->sb_flags,
21370 + if (unlikely(!err && ++opt > opt_tail)) {
21374 + opt->type = Opt_tail;
21379 + if (unlikely(match_int(&a->args[0], &n))) {
21380 + pr_err("bad integer in %s\n", opt_str);
21384 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
21387 + opt->type = token;
21390 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
21391 + /*dummy bindex*/1);
21393 + opt->type = token;
21395 + case Opt_prepend:
21396 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
21399 + opt->type = token;
21402 + err = au_opts_parse_del(&opt->del, a->args);
21404 + opt->type = token;
21406 +#if 0 /* reserved for future use */
21408 + del->pathname = "(indexed)";
21409 + if (unlikely(match_int(&args[0], &n))) {
21410 + pr_err("bad integer in %s\n", opt_str);
21413 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
21415 + opt->type = token;
21419 + err = au_opts_parse_mod(&opt->mod, a->args);
21421 + opt->type = token;
21423 +#ifdef IMOD /* reserved for future use */
21425 + u.mod->path = "(indexed)";
21426 + if (unlikely(match_int(&a->args[0], &n))) {
21427 + pr_err("bad integer in %s\n", opt_str);
21430 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
21432 + opt->type = token;
21436 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
21438 + opt->type = token;
21441 + case Opt_trunc_xino_path:
21442 + err = au_opts_parse_xino_itrunc_path
21443 + (sb, &opt->xino_itrunc, a->args);
21445 + opt->type = token;
21448 + case Opt_itrunc_xino:
21449 + u.xino_itrunc = &opt->xino_itrunc;
21450 + if (unlikely(match_int(&a->args[0], &n))) {
21451 + pr_err("bad integer in %s\n", opt_str);
21454 + u.xino_itrunc->bindex = n;
21455 + aufs_read_lock(root, AuLock_FLUSH);
21456 + if (n < 0 || au_sbend(sb) < n) {
21457 + pr_err("out of bounds, %d\n", n);
21458 + aufs_read_unlock(root, !AuLock_IR);
21461 + aufs_read_unlock(root, !AuLock_IR);
21463 + opt->type = token;
21467 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
21470 + opt->type = token;
21473 + case Opt_rdcache:
21474 + if (unlikely(match_int(&a->args[0], &n))) {
21475 + pr_err("bad integer in %s\n", opt_str);
21478 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
21479 + pr_err("rdcache must be smaller than %d\n",
21480 + AUFS_RDCACHE_MAX);
21483 + opt->rdcache = n;
21485 + opt->type = token;
21488 + if (unlikely(match_int(&a->args[0], &n)
21490 + || n > KMALLOC_MAX_SIZE)) {
21491 + pr_err("bad integer in %s\n", opt_str);
21494 + if (unlikely(n && n < NAME_MAX)) {
21495 + pr_err("rdblk must be larger than %d\n",
21501 + opt->type = token;
21504 + if (unlikely(match_int(&a->args[0], &n)
21506 + || n * sizeof(struct hlist_head)
21507 + > KMALLOC_MAX_SIZE)) {
21508 + pr_err("bad integer in %s\n", opt_str);
21513 + opt->type = token;
21516 + case Opt_trunc_xino:
21517 + case Opt_notrunc_xino:
21519 + case Opt_trunc_xib:
21520 + case Opt_notrunc_xib:
21524 + case Opt_noplink:
21525 + case Opt_list_plink:
21528 + case Opt_diropq_a:
21529 + case Opt_diropq_w:
21530 + case Opt_warn_perm:
21531 + case Opt_nowarn_perm:
21533 + case Opt_norefrof:
21534 + case Opt_verbose:
21535 + case Opt_noverbose:
21539 + case Opt_rdblk_def:
21540 + case Opt_rdhash_def:
21542 + opt->type = token;
21546 + opt->udba = udba_val(a->args[0].from);
21547 + if (opt->udba >= 0) {
21549 + opt->type = token;
21551 + pr_err("wrong value, %s\n", opt_str);
21554 + case Opt_wbr_create:
21555 + u.create = &opt->wbr_create;
21556 + u.create->wbr_create
21557 + = au_wbr_create_val(a->args[0].from, u.create);
21558 + if (u.create->wbr_create >= 0) {
21560 + opt->type = token;
21562 + pr_err("wrong value, %s\n", opt_str);
21564 + case Opt_wbr_copyup:
21565 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
21566 + if (opt->wbr_copyup >= 0) {
21568 + opt->type = token;
21570 + pr_err("wrong value, %s\n", opt_str);
21574 + pr_warn("ignored %s\n", opt_str);
21576 + case Opt_ignore_silent:
21581 + pr_err("unknown option %s\n", opt_str);
21585 + if (!err && !skipped) {
21586 + if (unlikely(++opt > opt_tail)) {
21589 + opt->type = Opt_tail;
21592 + opt->type = Opt_tail;
21598 + if (unlikely(err))
21599 + au_opts_free(opts);
21605 +static int au_opt_wbr_create(struct super_block *sb,
21606 + struct au_opt_wbr_create *create)
21609 + struct au_sbinfo *sbinfo;
21611 + SiMustWriteLock(sb);
21613 + err = 1; /* handled */
21614 + sbinfo = au_sbi(sb);
21615 + if (sbinfo->si_wbr_create_ops->fin) {
21616 + err = sbinfo->si_wbr_create_ops->fin(sb);
21621 + sbinfo->si_wbr_create = create->wbr_create;
21622 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
21623 + switch (create->wbr_create) {
21624 + case AuWbrCreate_MFSRRV:
21625 + case AuWbrCreate_MFSRR:
21626 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
21628 + case AuWbrCreate_MFS:
21629 + case AuWbrCreate_MFSV:
21630 + case AuWbrCreate_PMFS:
21631 + case AuWbrCreate_PMFSV:
21632 + sbinfo->si_wbr_mfs.mfs_expire
21633 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
21637 + if (sbinfo->si_wbr_create_ops->init)
21638 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
21645 + * plus: processed without an error
21646 + * zero: unprocessed
21648 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
21649 + struct au_opts *opts)
21652 + struct au_sbinfo *sbinfo;
21654 + SiMustWriteLock(sb);
21656 + err = 1; /* handled */
21657 + sbinfo = au_sbi(sb);
21658 + switch (opt->type) {
21660 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
21661 + sbinfo->si_mntflags |= opt->udba;
21662 + opts->given_udba |= opt->udba;
21666 + au_opt_set(sbinfo->si_mntflags, PLINK);
21668 + case Opt_noplink:
21669 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
21670 + au_plink_put(sb, /*verbose*/1);
21671 + au_opt_clr(sbinfo->si_mntflags, PLINK);
21673 + case Opt_list_plink:
21674 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
21675 + au_plink_list(sb);
21679 + au_opt_set(sbinfo->si_mntflags, DIO);
21680 + au_fset_opts(opts->flags, REFRESH_DYAOP);
21683 + au_opt_clr(sbinfo->si_mntflags, DIO);
21684 + au_fset_opts(opts->flags, REFRESH_DYAOP);
21687 + case Opt_diropq_a:
21688 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
21690 + case Opt_diropq_w:
21691 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
21694 + case Opt_warn_perm:
21695 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
21697 + case Opt_nowarn_perm:
21698 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
21702 + au_opt_set(sbinfo->si_mntflags, REFROF);
21704 + case Opt_norefrof:
21705 + au_opt_clr(sbinfo->si_mntflags, REFROF);
21708 + case Opt_verbose:
21709 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
21711 + case Opt_noverbose:
21712 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
21716 + au_opt_set(sbinfo->si_mntflags, SUM);
21719 + au_opt_clr(sbinfo->si_mntflags, SUM);
21720 + au_opt_set(sbinfo->si_mntflags, SUM_W);
21722 + au_opt_clr(sbinfo->si_mntflags, SUM);
21723 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
21726 + case Opt_wbr_create:
21727 + err = au_opt_wbr_create(sb, &opt->wbr_create);
21729 + case Opt_wbr_copyup:
21730 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
21731 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
21735 + sbinfo->si_dirwh = opt->dirwh;
21738 + case Opt_rdcache:
21739 + sbinfo->si_rdcache
21740 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
21743 + sbinfo->si_rdblk = opt->rdblk;
21745 + case Opt_rdblk_def:
21746 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
21749 + sbinfo->si_rdhash = opt->rdhash;
21751 + case Opt_rdhash_def:
21752 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
21756 + au_opt_set(sbinfo->si_mntflags, SHWH);
21759 + au_opt_clr(sbinfo->si_mntflags, SHWH);
21762 + case Opt_trunc_xino:
21763 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
21765 + case Opt_notrunc_xino:
21766 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
21769 + case Opt_trunc_xino_path:
21770 + case Opt_itrunc_xino:
21771 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
21776 + case Opt_trunc_xib:
21777 + au_fset_opts(opts->flags, TRUNC_XIB);
21779 + case Opt_notrunc_xib:
21780 + au_fclr_opts(opts->flags, TRUNC_XIB);
21792 + * returns tri-state.
21793 + * plus: processed without an error
21794 + * zero: unprocessed
21797 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
21798 + struct au_opts *opts)
21800 + int err, do_refresh;
21803 + switch (opt->type) {
21805 + opt->add.bindex = au_sbend(sb) + 1;
21806 + if (opt->add.bindex < 0)
21807 + opt->add.bindex = 0;
21809 + case Opt_prepend:
21810 + opt->add.bindex = 0;
21813 + err = au_br_add(sb, &opt->add,
21814 + au_ftest_opts(opts->flags, REMOUNT));
21817 + au_fset_opts(opts->flags, REFRESH);
21823 + err = au_br_del(sb, &opt->del,
21824 + au_ftest_opts(opts->flags, REMOUNT));
21827 + au_fset_opts(opts->flags, TRUNC_XIB);
21828 + au_fset_opts(opts->flags, REFRESH);
21834 + err = au_br_mod(sb, &opt->mod,
21835 + au_ftest_opts(opts->flags, REMOUNT),
21840 + au_fset_opts(opts->flags, REFRESH);
21848 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
21849 + struct au_opt_xino **opt_xino,
21850 + struct au_opts *opts)
21853 + aufs_bindex_t bend, bindex;
21854 + struct dentry *root, *parent, *h_root;
21857 + switch (opt->type) {
21859 + err = au_xino_set(sb, &opt->xino,
21860 + !!au_ftest_opts(opts->flags, REMOUNT));
21861 + if (unlikely(err))
21864 + *opt_xino = &opt->xino;
21865 + au_xino_brid_set(sb, -1);
21867 + /* safe d_parent access */
21868 + parent = opt->xino.file->f_dentry->d_parent;
21869 + root = sb->s_root;
21870 + bend = au_sbend(sb);
21871 + for (bindex = 0; bindex <= bend; bindex++) {
21872 + h_root = au_h_dptr(root, bindex);
21873 + if (h_root == parent) {
21874 + au_xino_brid_set(sb, au_sbr_id(sb, bindex));
21882 + au_xino_brid_set(sb, -1);
21883 + *opt_xino = (void *)-1;
21890 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
21891 + unsigned int pending)
21894 + aufs_bindex_t bindex, bend;
21895 + unsigned char do_plink, skip, do_free;
21896 + struct au_branch *br;
21897 + struct au_wbr *wbr;
21898 + struct dentry *root;
21899 + struct inode *dir, *h_dir;
21900 + struct au_sbinfo *sbinfo;
21901 + struct au_hinode *hdir;
21903 + SiMustAnyLock(sb);
21905 + sbinfo = au_sbi(sb);
21906 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
21908 + if (!(sb_flags & MS_RDONLY)) {
21909 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
21910 + pr_warn("first branch should be rw\n");
21911 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
21912 + pr_warn("shwh should be used with ro\n");
21915 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
21916 + && !au_opt_test(sbinfo->si_mntflags, XINO))
21917 + pr_warn("udba=*notify requires xino\n");
21920 + root = sb->s_root;
21921 + dir = root->d_inode;
21922 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
21923 + bend = au_sbend(sb);
21924 + for (bindex = 0; !err && bindex <= bend; bindex++) {
21926 + h_dir = au_h_iptr(dir, bindex);
21927 + br = au_sbr(sb, bindex);
21930 + wbr = br->br_wbr;
21932 + wbr_wh_read_lock(wbr);
21934 + if (!au_br_writable(br->br_perm)) {
21937 + || (!wbr->wbr_whbase
21938 + && !wbr->wbr_plink
21939 + && !wbr->wbr_orph));
21940 + } else if (!au_br_wh_linkable(br->br_perm)) {
21941 + /* skip = (!br->br_whbase && !br->br_orph); */
21942 + skip = (!wbr || !wbr->wbr_whbase);
21943 + if (skip && wbr) {
21945 + skip = !!wbr->wbr_plink;
21947 + skip = !wbr->wbr_plink;
21950 + /* skip = (br->br_whbase && br->br_ohph); */
21951 + skip = (wbr && wbr->wbr_whbase);
21954 + skip = !!wbr->wbr_plink;
21956 + skip = !wbr->wbr_plink;
21960 + wbr_wh_read_unlock(wbr);
21965 + hdir = au_hi(dir, bindex);
21966 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
21968 + wbr_wh_write_lock(wbr);
21969 + err = au_wh_init(br, sb);
21971 + wbr_wh_write_unlock(wbr);
21972 + au_hn_imtx_unlock(hdir);
21974 + if (!err && do_free) {
21976 + br->br_wbr = NULL;
21983 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
21986 + unsigned int tmp;
21987 + aufs_bindex_t bindex, bend;
21988 + struct au_opt *opt;
21989 + struct au_opt_xino *opt_xino, xino;
21990 + struct au_sbinfo *sbinfo;
21991 + struct au_branch *br;
21993 + SiMustWriteLock(sb);
21998 + while (err >= 0 && opt->type != Opt_tail)
21999 + err = au_opt_simple(sb, opt++, opts);
22002 + else if (unlikely(err < 0))
22005 + /* disable xino and udba temporary */
22006 + sbinfo = au_sbi(sb);
22007 + tmp = sbinfo->si_mntflags;
22008 + au_opt_clr(sbinfo->si_mntflags, XINO);
22009 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
22012 + while (err >= 0 && opt->type != Opt_tail)
22013 + err = au_opt_br(sb, opt++, opts);
22016 + else if (unlikely(err < 0))
22019 + bend = au_sbend(sb);
22020 + if (unlikely(bend < 0)) {
22022 + pr_err("no branches\n");
22026 + if (au_opt_test(tmp, XINO))
22027 + au_opt_set(sbinfo->si_mntflags, XINO);
22029 + while (!err && opt->type != Opt_tail)
22030 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
22031 + if (unlikely(err))
22034 + err = au_opts_verify(sb, sb->s_flags, tmp);
22035 + if (unlikely(err))
22038 + /* restore xino */
22039 + if (au_opt_test(tmp, XINO) && !opt_xino) {
22040 + xino.file = au_xino_def(sb);
22041 + err = PTR_ERR(xino.file);
22042 + if (IS_ERR(xino.file))
22045 + err = au_xino_set(sb, &xino, /*remount*/0);
22047 + if (unlikely(err))
22051 + /* restore udba */
22052 + tmp &= AuOptMask_UDBA;
22053 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
22054 + sbinfo->si_mntflags |= tmp;
22055 + bend = au_sbend(sb);
22056 + for (bindex = 0; bindex <= bend; bindex++) {
22057 + br = au_sbr(sb, bindex);
22058 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
22059 + if (unlikely(err))
22060 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
22062 + /* go on even if err */
22064 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
22065 + struct inode *dir = sb->s_root->d_inode;
22066 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
22073 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
22076 + struct inode *dir;
22077 + struct au_opt_xino *opt_xino;
22078 + struct au_opt *opt;
22079 + struct au_sbinfo *sbinfo;
22081 + SiMustWriteLock(sb);
22083 + dir = sb->s_root->d_inode;
22084 + sbinfo = au_sbi(sb);
22088 + while (err >= 0 && opt->type != Opt_tail) {
22089 + err = au_opt_simple(sb, opt, opts);
22091 + err = au_opt_br(sb, opt, opts);
22093 + err = au_opt_xino(sb, opt, &opt_xino, opts);
22099 + /* go on even err */
22101 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
22102 + if (unlikely(rerr && !err))
22105 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
22106 + rerr = au_xib_trunc(sb);
22107 + if (unlikely(rerr && !err))
22111 + /* will be handled by the caller */
22112 + if (!au_ftest_opts(opts->flags, REFRESH)
22113 + && (opts->given_udba || au_opt_test(sbinfo->si_mntflags, XINO)))
22114 + au_fset_opts(opts->flags, REFRESH);
22116 + AuDbg("status 0x%x\n", opts->flags);
22120 +/* ---------------------------------------------------------------------- */
22122 +unsigned int au_opt_udba(struct super_block *sb)
22124 + return au_mntflags(sb) & AuOptMask_UDBA;
22126 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
22127 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
22128 +++ linux/fs/aufs/opts.h 2013-07-06 13:20:47.753531903 +0200
22131 + * Copyright (C) 2005-2013 Junjiro R. Okajima
22133 + * This program, aufs is free software; you can redistribute it and/or modify
22134 + * it under the terms of the GNU General Public License as published by
22135 + * the Free Software Foundation; either version 2 of the License, or
22136 + * (at your option) any later version.
22138 + * This program is distributed in the hope that it will be useful,
22139 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22140 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22141 + * GNU General Public License for more details.
22143 + * You should have received a copy of the GNU General Public License
22144 + * along with this program; if not, write to the Free Software
22145 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22149 + * mount options/flags
22152 +#ifndef __AUFS_OPTS_H__
22153 +#define __AUFS_OPTS_H__
22157 +#include <linux/path.h>
22160 +struct super_block;
22162 +/* ---------------------------------------------------------------------- */
22165 +#define AuOpt_XINO 1 /* external inode number bitmap
22166 + and translation table */
22167 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
22168 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
22169 +#define AuOpt_UDBA_REVAL (1 << 3)
22170 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
22171 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
22172 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
22173 +#define AuOpt_DIRPERM1 (1 << 7) /* unimplemented */
22174 +#define AuOpt_REFROF (1 << 8) /* unimplemented */
22175 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
22176 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
22177 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
22178 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
22179 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
22180 +#define AuOpt_DIO (1 << 14) /* direct io */
22182 +#ifndef CONFIG_AUFS_HNOTIFY
22183 +#undef AuOpt_UDBA_HNOTIFY
22184 +#define AuOpt_UDBA_HNOTIFY 0
22186 +#ifndef CONFIG_AUFS_SHWH
22188 +#define AuOpt_SHWH 0
22191 +#define AuOpt_Def (AuOpt_XINO \
22192 + | AuOpt_UDBA_REVAL \
22194 + /* | AuOpt_DIRPERM1 */ \
22195 + | AuOpt_WARN_PERM)
22196 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
22197 + | AuOpt_UDBA_REVAL \
22198 + | AuOpt_UDBA_HNOTIFY)
22200 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
22201 +#define au_opt_set(flags, name) do { \
22202 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
22203 + ((flags) |= AuOpt_##name); \
22205 +#define au_opt_set_udba(flags, name) do { \
22206 + (flags) &= ~AuOptMask_UDBA; \
22207 + ((flags) |= AuOpt_##name); \
22209 +#define au_opt_clr(flags, name) do { \
22210 + ((flags) &= ~AuOpt_##name); \
22213 +static inline unsigned int au_opts_plink(unsigned int mntflags)
22215 +#ifdef CONFIG_PROC_FS
22218 + return mntflags & ~AuOpt_PLINK;
22222 +/* ---------------------------------------------------------------------- */
22224 +/* policies to select one among multiple writable branches */
22226 + AuWbrCreate_TDP, /* top down parent */
22227 + AuWbrCreate_RR, /* round robin */
22228 + AuWbrCreate_MFS, /* most free space */
22229 + AuWbrCreate_MFSV, /* mfs with seconds */
22230 + AuWbrCreate_MFSRR, /* mfs then rr */
22231 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
22232 + AuWbrCreate_PMFS, /* parent and mfs */
22233 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
22235 + AuWbrCreate_Def = AuWbrCreate_TDP
22239 + AuWbrCopyup_TDP, /* top down parent */
22240 + AuWbrCopyup_BUP, /* bottom up parent */
22241 + AuWbrCopyup_BU, /* bottom up */
22243 + AuWbrCopyup_Def = AuWbrCopyup_TDP
22246 +/* ---------------------------------------------------------------------- */
22248 +struct au_opt_add {
22249 + aufs_bindex_t bindex;
22252 + struct path path;
22255 +struct au_opt_del {
22257 + struct path h_path;
22260 +struct au_opt_mod {
22263 + struct dentry *h_root;
22266 +struct au_opt_xino {
22268 + struct file *file;
22271 +struct au_opt_xino_itrunc {
22272 + aufs_bindex_t bindex;
22275 +struct au_opt_wbr_create {
22278 + unsigned long long mfsrr_watermark;
22284 + struct au_opt_xino xino;
22285 + struct au_opt_xino_itrunc xino_itrunc;
22286 + struct au_opt_add add;
22287 + struct au_opt_del del;
22288 + struct au_opt_mod mod;
22291 + unsigned int rdblk;
22292 + unsigned int rdhash;
22294 + struct au_opt_wbr_create wbr_create;
22300 +#define AuOpts_REMOUNT 1
22301 +#define AuOpts_REFRESH (1 << 1)
22302 +#define AuOpts_TRUNC_XIB (1 << 2)
22303 +#define AuOpts_REFRESH_DYAOP (1 << 3)
22304 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
22305 +#define au_fset_opts(flags, name) \
22306 + do { (flags) |= AuOpts_##name; } while (0)
22307 +#define au_fclr_opts(flags, name) \
22308 + do { (flags) &= ~AuOpts_##name; } while (0)
22311 + struct au_opt *opt;
22314 + unsigned int given_udba;
22315 + unsigned int flags;
22316 + unsigned long sb_flags;
22319 +/* ---------------------------------------------------------------------- */
22321 +char *au_optstr_br_perm(int brperm);
22322 +const char *au_optstr_udba(int udba);
22323 +const char *au_optstr_wbr_copyup(int wbr_copyup);
22324 +const char *au_optstr_wbr_create(int wbr_create);
22326 +void au_opts_free(struct au_opts *opts);
22327 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
22328 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
22329 + unsigned int pending);
22330 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
22331 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
22333 +unsigned int au_opt_udba(struct super_block *sb);
22335 +/* ---------------------------------------------------------------------- */
22337 +#endif /* __KERNEL__ */
22338 +#endif /* __AUFS_OPTS_H__ */
22339 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
22340 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
22341 +++ linux/fs/aufs/plink.c 2013-07-06 13:20:47.753531903 +0200
22344 + * Copyright (C) 2005-2013 Junjiro R. Okajima
22346 + * This program, aufs is free software; you can redistribute it and/or modify
22347 + * it under the terms of the GNU General Public License as published by
22348 + * the Free Software Foundation; either version 2 of the License, or
22349 + * (at your option) any later version.
22351 + * This program is distributed in the hope that it will be useful,
22352 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22353 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22354 + * GNU General Public License for more details.
22356 + * You should have received a copy of the GNU General Public License
22357 + * along with this program; if not, write to the Free Software
22358 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22368 + * the pseudo-link maintenance mode.
22369 + * during a user process maintains the pseudo-links,
22370 + * prohibit adding a new plink and branch manipulation.
22374 + * For entry functions which will handle plink, and i_mutex is already held
22376 + * They cannot wait and should return an error at once.
22377 + * Callers has to check the error.
22379 + * For entry functions which will handle plink, but i_mutex is not held
22381 + * They can wait the plink maintenance mode to finish.
22383 + * They behave like F_SETLK and F_SETLKW.
22384 + * If the caller never handle plink, then both flags are unnecessary.
22387 +int au_plink_maint(struct super_block *sb, int flags)
22391 + struct au_sbinfo *sbi;
22393 + SiMustAnyLock(sb);
22396 + if (!au_opt_test(au_mntflags(sb), PLINK))
22399 + sbi = au_sbi(sb);
22400 + pid = sbi->si_plink_maint_pid;
22401 + if (!pid || pid == current->pid)
22404 + /* todo: it highly depends upon /sbin/mount.aufs */
22406 + ppid = task_pid_vnr(rcu_dereference(current->real_parent));
22407 + rcu_read_unlock();
22411 + if (au_ftest_lock(flags, NOPLMW)) {
22412 + /* if there is no i_mutex lock in VFS, we don't need to wait */
22413 + /* AuDebugOn(!lockdep_depth(current)); */
22414 + while (sbi->si_plink_maint_pid) {
22415 + si_read_unlock(sb);
22416 + /* gave up wake_up_bit() */
22417 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
22419 + if (au_ftest_lock(flags, FLUSH))
22420 + au_nwt_flush(&sbi->si_nowait);
22421 + si_noflush_read_lock(sb);
22423 + } else if (au_ftest_lock(flags, NOPLM)) {
22424 + AuDbg("ppid %d, pid %d\n", ppid, pid);
22432 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
22434 + spin_lock(&sbinfo->si_plink_maint_lock);
22435 + sbinfo->si_plink_maint_pid = 0;
22436 + spin_unlock(&sbinfo->si_plink_maint_lock);
22437 + wake_up_all(&sbinfo->si_plink_wq);
22440 +int au_plink_maint_enter(struct super_block *sb)
22443 + struct au_sbinfo *sbinfo;
22446 + sbinfo = au_sbi(sb);
22447 + /* make sure i am the only one in this fs */
22448 + si_write_lock(sb, AuLock_FLUSH);
22449 + if (au_opt_test(au_mntflags(sb), PLINK)) {
22450 + spin_lock(&sbinfo->si_plink_maint_lock);
22451 + if (!sbinfo->si_plink_maint_pid)
22452 + sbinfo->si_plink_maint_pid = current->pid;
22455 + spin_unlock(&sbinfo->si_plink_maint_lock);
22457 + si_write_unlock(sb);
22462 +/* ---------------------------------------------------------------------- */
22464 +#ifdef CONFIG_AUFS_DEBUG
22465 +void au_plink_list(struct super_block *sb)
22468 + struct au_sbinfo *sbinfo;
22469 + struct hlist_head *plink_hlist;
22470 + struct pseudo_link *plink;
22472 + SiMustAnyLock(sb);
22474 + sbinfo = au_sbi(sb);
22475 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
22476 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
22478 + for (i = 0; i < AuPlink_NHASH; i++) {
22479 + plink_hlist = &sbinfo->si_plink[i].head;
22481 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
22482 + AuDbg("%lu\n", plink->inode->i_ino);
22483 + rcu_read_unlock();
22488 +/* is the inode pseudo-linked? */
22489 +int au_plink_test(struct inode *inode)
22492 + struct au_sbinfo *sbinfo;
22493 + struct hlist_head *plink_hlist;
22494 + struct pseudo_link *plink;
22496 + sbinfo = au_sbi(inode->i_sb);
22497 + AuRwMustAnyLock(&sbinfo->si_rwsem);
22498 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
22499 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
22502 + i = au_plink_hash(inode->i_ino);
22503 + plink_hlist = &sbinfo->si_plink[i].head;
22505 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
22506 + if (plink->inode == inode) {
22510 + rcu_read_unlock();
22514 +/* ---------------------------------------------------------------------- */
22517 + * generate a name for plink.
22518 + * the file will be stored under AUFS_WH_PLINKDIR.
22520 +/* 20 is max digits length of ulong 64 */
22521 +#define PLINK_NAME_LEN ((20 + 1) * 2)
22523 +static int plink_name(char *name, int len, struct inode *inode,
22524 + aufs_bindex_t bindex)
22527 + struct inode *h_inode;
22529 + h_inode = au_h_iptr(inode, bindex);
22530 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
22534 +struct au_do_plink_lkup_args {
22535 + struct dentry **errp;
22536 + struct qstr *tgtname;
22537 + struct dentry *h_parent;
22538 + struct au_branch *br;
22541 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
22542 + struct dentry *h_parent,
22543 + struct au_branch *br)
22545 + struct dentry *h_dentry;
22546 + struct mutex *h_mtx;
22548 + h_mtx = &h_parent->d_inode->i_mutex;
22549 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
22550 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
22551 + mutex_unlock(h_mtx);
22555 +static void au_call_do_plink_lkup(void *args)
22557 + struct au_do_plink_lkup_args *a = args;
22558 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
22561 +/* lookup the plink-ed @inode under the branch at @bindex */
22562 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
22564 + struct dentry *h_dentry, *h_parent;
22565 + struct au_branch *br;
22566 + struct inode *h_dir;
22568 + char a[PLINK_NAME_LEN];
22569 + struct qstr tgtname = QSTR_INIT(a, 0);
22571 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
22573 + br = au_sbr(inode->i_sb, bindex);
22574 + h_parent = br->br_wbr->wbr_plink;
22575 + h_dir = h_parent->d_inode;
22576 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
22578 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
22579 + struct au_do_plink_lkup_args args = {
22580 + .errp = &h_dentry,
22581 + .tgtname = &tgtname,
22582 + .h_parent = h_parent,
22586 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
22587 + if (unlikely(wkq_err))
22588 + h_dentry = ERR_PTR(wkq_err);
22590 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
22595 +/* create a pseudo-link */
22596 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
22597 + struct dentry *h_dentry, struct au_branch *br)
22600 + struct path h_path = {
22601 + .mnt = au_br_mnt(br)
22603 + struct inode *h_dir;
22605 + h_dir = h_parent->d_inode;
22606 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_CHILD2);
22608 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
22609 + err = PTR_ERR(h_path.dentry);
22610 + if (IS_ERR(h_path.dentry))
22614 + /* wh.plink dir is not monitored */
22615 + /* todo: is it really safe? */
22616 + if (h_path.dentry->d_inode
22617 + && h_path.dentry->d_inode != h_dentry->d_inode) {
22618 + err = vfsub_unlink(h_dir, &h_path, /*force*/0);
22619 + dput(h_path.dentry);
22620 + h_path.dentry = NULL;
22624 + if (!err && !h_path.dentry->d_inode)
22625 + err = vfsub_link(h_dentry, h_dir, &h_path);
22626 + dput(h_path.dentry);
22629 + mutex_unlock(&h_dir->i_mutex);
22633 +struct do_whplink_args {
22635 + struct qstr *tgt;
22636 + struct dentry *h_parent;
22637 + struct dentry *h_dentry;
22638 + struct au_branch *br;
22641 +static void call_do_whplink(void *args)
22643 + struct do_whplink_args *a = args;
22644 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
22647 +static int whplink(struct dentry *h_dentry, struct inode *inode,
22648 + aufs_bindex_t bindex, struct au_branch *br)
22650 + int err, wkq_err;
22651 + struct au_wbr *wbr;
22652 + struct dentry *h_parent;
22653 + struct inode *h_dir;
22654 + char a[PLINK_NAME_LEN];
22655 + struct qstr tgtname = QSTR_INIT(a, 0);
22657 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
22658 + h_parent = wbr->wbr_plink;
22659 + h_dir = h_parent->d_inode;
22660 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
22662 + /* always superio. */
22663 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
22664 + struct do_whplink_args args = {
22667 + .h_parent = h_parent,
22668 + .h_dentry = h_dentry,
22671 + wkq_err = au_wkq_wait(call_do_whplink, &args);
22672 + if (unlikely(wkq_err))
22675 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
22680 +/* free a single plink */
22681 +static void do_put_plink(struct pseudo_link *plink, int do_del)
22684 + hlist_del(&plink->hlist);
22685 + iput(plink->inode);
22689 +static void do_put_plink_rcu(struct rcu_head *rcu)
22691 + struct pseudo_link *plink;
22693 + plink = container_of(rcu, struct pseudo_link, rcu);
22694 + iput(plink->inode);
22699 + * create a new pseudo-link for @h_dentry on @bindex.
22700 + * the linked inode is held in aufs @inode.
22702 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
22703 + struct dentry *h_dentry)
22705 + struct super_block *sb;
22706 + struct au_sbinfo *sbinfo;
22707 + struct hlist_head *plink_hlist;
22708 + struct pseudo_link *plink, *tmp;
22709 + struct au_sphlhead *sphl;
22710 + int found, err, cnt, i;
22712 + sb = inode->i_sb;
22713 + sbinfo = au_sbi(sb);
22714 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
22715 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
22717 + found = au_plink_test(inode);
22721 + i = au_plink_hash(inode->i_ino);
22722 + sphl = sbinfo->si_plink + i;
22723 + plink_hlist = &sphl->head;
22724 + tmp = kmalloc(sizeof(*plink), GFP_NOFS);
22726 + tmp->inode = au_igrab(inode);
22732 + spin_lock(&sphl->spin);
22733 + hlist_for_each_entry(plink, plink_hlist, hlist) {
22734 + if (plink->inode == inode) {
22740 + hlist_add_head_rcu(&tmp->hlist, plink_hlist);
22741 + spin_unlock(&sphl->spin);
22743 + cnt = au_sphl_count(sphl);
22744 +#define msg "unexpectedly unblanced or too many pseudo-links"
22745 + if (cnt > AUFS_PLINK_WARN)
22746 + AuWarn1(msg ", %d\n", cnt);
22748 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
22750 + do_put_plink(tmp, 0);
22755 + if (unlikely(err)) {
22756 + pr_warn("err %d, damaged pseudo link.\n", err);
22758 + au_sphl_del_rcu(&tmp->hlist, sphl);
22759 + call_rcu(&tmp->rcu, do_put_plink_rcu);
22764 +/* free all plinks */
22765 +void au_plink_put(struct super_block *sb, int verbose)
22768 + struct au_sbinfo *sbinfo;
22769 + struct hlist_head *plink_hlist;
22770 + struct hlist_node *tmp;
22771 + struct pseudo_link *plink;
22773 + SiMustWriteLock(sb);
22775 + sbinfo = au_sbi(sb);
22776 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
22777 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
22779 + /* no spin_lock since sbinfo is write-locked */
22781 + for (i = 0; i < AuPlink_NHASH; i++) {
22782 + plink_hlist = &sbinfo->si_plink[i].head;
22783 + if (!warned && verbose && !hlist_empty(plink_hlist)) {
22784 + pr_warn("pseudo-link is not flushed");
22787 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist)
22788 + do_put_plink(plink, 0);
22789 + INIT_HLIST_HEAD(plink_hlist);
22793 +void au_plink_clean(struct super_block *sb, int verbose)
22795 + struct dentry *root;
22797 + root = sb->s_root;
22798 + aufs_write_lock(root);
22799 + if (au_opt_test(au_mntflags(sb), PLINK))
22800 + au_plink_put(sb, verbose);
22801 + aufs_write_unlock(root);
22804 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
22807 + aufs_bindex_t bstart, bend, bindex;
22810 + bstart = au_ibstart(inode);
22811 + bend = au_ibend(inode);
22812 + if (bstart >= 0) {
22813 + for (bindex = bstart; bindex <= bend; bindex++) {
22814 + if (!au_h_iptr(inode, bindex)
22815 + || au_ii_br_id(inode, bindex) != br_id)
22817 + au_set_h_iptr(inode, bindex, NULL, 0);
22822 + for (bindex = bstart; bindex <= bend; bindex++)
22823 + if (au_h_iptr(inode, bindex)) {
22833 +/* free the plinks on a branch specified by @br_id */
22834 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
22836 + struct au_sbinfo *sbinfo;
22837 + struct hlist_head *plink_hlist;
22838 + struct hlist_node *tmp;
22839 + struct pseudo_link *plink;
22840 + struct inode *inode;
22843 + SiMustWriteLock(sb);
22845 + sbinfo = au_sbi(sb);
22846 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
22847 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
22849 + /* no spin_lock since sbinfo is write-locked */
22850 + for (i = 0; i < AuPlink_NHASH; i++) {
22851 + plink_hlist = &sbinfo->si_plink[i].head;
22852 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist) {
22853 + inode = au_igrab(plink->inode);
22854 + ii_write_lock_child(inode);
22855 + do_put = au_plink_do_half_refresh(inode, br_id);
22857 + do_put_plink(plink, 1);
22858 + ii_write_unlock(inode);
22863 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
22864 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
22865 +++ linux/fs/aufs/poll.c 2013-07-06 13:20:47.753531903 +0200
22868 + * Copyright (C) 2005-2013 Junjiro R. Okajima
22870 + * This program, aufs is free software; you can redistribute it and/or modify
22871 + * it under the terms of the GNU General Public License as published by
22872 + * the Free Software Foundation; either version 2 of the License, or
22873 + * (at your option) any later version.
22875 + * This program is distributed in the hope that it will be useful,
22876 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22877 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22878 + * GNU General Public License for more details.
22880 + * You should have received a copy of the GNU General Public License
22881 + * along with this program; if not, write to the Free Software
22882 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22887 + * There is only one filesystem which implements ->poll operation, currently.
22892 +unsigned int aufs_poll(struct file *file, poll_table *wait)
22894 + unsigned int mask;
22896 + struct file *h_file;
22897 + struct dentry *dentry;
22898 + struct super_block *sb;
22900 + /* We should pretend an error happened. */
22901 + mask = POLLERR /* | POLLIN | POLLOUT */;
22902 + dentry = file->f_dentry;
22903 + sb = dentry->d_sb;
22904 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
22905 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
22906 + if (unlikely(err))
22909 + /* it is not an error if h_file has no operation */
22910 + mask = DEFAULT_POLLMASK;
22911 + h_file = au_hf_top(file);
22912 + if (h_file->f_op && h_file->f_op->poll)
22913 + mask = h_file->f_op->poll(h_file, wait);
22915 + di_read_unlock(dentry, AuLock_IR);
22916 + fi_read_unlock(file);
22919 + si_read_unlock(sb);
22920 + AuTraceErr((int)mask);
22923 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
22924 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
22925 +++ linux/fs/aufs/procfs.c 2013-07-06 13:20:47.753531903 +0200
22928 + * Copyright (C) 2010-2013 Junjiro R. Okajima
22930 + * This program, aufs is free software; you can redistribute it and/or modify
22931 + * it under the terms of the GNU General Public License as published by
22932 + * the Free Software Foundation; either version 2 of the License, or
22933 + * (at your option) any later version.
22935 + * This program is distributed in the hope that it will be useful,
22936 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22937 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22938 + * GNU General Public License for more details.
22940 + * You should have received a copy of the GNU General Public License
22941 + * along with this program; if not, write to the Free Software
22942 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22946 + * procfs interfaces
22949 +#include <linux/proc_fs.h>
22952 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
22954 + struct au_sbinfo *sbinfo;
22956 + sbinfo = file->private_data;
22958 + au_plink_maint_leave(sbinfo);
22959 + kobject_put(&sbinfo->si_kobj);
22965 +static void au_procfs_plm_write_clean(struct file *file)
22967 + struct au_sbinfo *sbinfo;
22969 + sbinfo = file->private_data;
22971 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
22974 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
22977 + struct super_block *sb;
22978 + struct au_sbinfo *sbinfo;
22981 + if (unlikely(file->private_data))
22985 + /* don't use au_sbilist_lock() here */
22986 + spin_lock(&au_sbilist.spin);
22987 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
22988 + if (id == sysaufs_si_id(sbinfo)) {
22989 + kobject_get(&sbinfo->si_kobj);
22990 + sb = sbinfo->si_sb;
22993 + spin_unlock(&au_sbilist.spin);
22996 + if (unlikely(!sb))
22999 + err = au_plink_maint_enter(sb);
23001 + /* keep kobject_get() */
23002 + file->private_data = sbinfo;
23004 + kobject_put(&sbinfo->si_kobj);
23010 + * Accept a valid "si=xxxx" only.
23011 + * Once it is accepted successfully, accept "clean" too.
23013 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
23014 + size_t count, loff_t *ppos)
23017 + unsigned long id;
23018 + /* last newline is allowed */
23019 + char buf[3 + sizeof(unsigned long) * 2 + 1];
23022 + if (unlikely(!capable(CAP_SYS_ADMIN)))
23026 + if (unlikely(count > sizeof(buf)))
23029 + err = copy_from_user(buf, ubuf, count);
23030 + if (unlikely(err)) {
23037 + if (!strcmp("clean", buf)) {
23038 + au_procfs_plm_write_clean(file);
23039 + goto out_success;
23040 + } else if (unlikely(strncmp("si=", buf, 3)))
23043 + err = kstrtoul(buf + 3, 16, &id);
23044 + if (unlikely(err))
23047 + err = au_procfs_plm_write_si(file, id);
23048 + if (unlikely(err))
23052 + err = count; /* success */
23057 +static const struct file_operations au_procfs_plm_fop = {
23058 + .write = au_procfs_plm_write,
23059 + .release = au_procfs_plm_release,
23060 + .owner = THIS_MODULE
23063 +/* ---------------------------------------------------------------------- */
23065 +static struct proc_dir_entry *au_procfs_dir;
23067 +void au_procfs_fin(void)
23069 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
23070 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
23073 +int __init au_procfs_init(void)
23076 + struct proc_dir_entry *entry;
23079 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
23080 + if (unlikely(!au_procfs_dir))
23083 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR,
23084 + au_procfs_dir, &au_procfs_plm_fop);
23085 + if (unlikely(!entry))
23089 + goto out; /* success */
23093 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
23097 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
23098 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
23099 +++ linux/fs/aufs/rdu.c 2013-07-30 22:42:55.842946719 +0200
23102 + * Copyright (C) 2005-2013 Junjiro R. Okajima
23104 + * This program, aufs is free software; you can redistribute it and/or modify
23105 + * it under the terms of the GNU General Public License as published by
23106 + * the Free Software Foundation; either version 2 of the License, or
23107 + * (at your option) any later version.
23109 + * This program is distributed in the hope that it will be useful,
23110 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23111 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23112 + * GNU General Public License for more details.
23114 + * You should have received a copy of the GNU General Public License
23115 + * along with this program; if not, write to the Free Software
23116 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23120 + * readdir in userspace.
23123 +#include <linux/compat.h>
23124 +#include <linux/fs_stack.h>
23125 +#include <linux/security.h>
23128 +/* bits for struct aufs_rdu.flags */
23129 +#define AuRdu_CALLED 1
23130 +#define AuRdu_CONT (1 << 1)
23131 +#define AuRdu_FULL (1 << 2)
23132 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
23133 +#define au_fset_rdu(flags, name) \
23134 + do { (flags) |= AuRdu_##name; } while (0)
23135 +#define au_fclr_rdu(flags, name) \
23136 + do { (flags) &= ~AuRdu_##name; } while (0)
23138 +struct au_rdu_arg {
23139 + struct aufs_rdu *rdu;
23140 + union au_rdu_ent_ul ent;
23141 + unsigned long end;
23143 + struct super_block *sb;
23147 +static int au_rdu_fill(void *__arg, const char *name, int nlen,
23148 + loff_t offset, u64 h_ino, unsigned int d_type)
23151 + struct au_rdu_arg *arg = __arg;
23152 + struct aufs_rdu *rdu = arg->rdu;
23153 + struct au_rdu_ent ent;
23157 + au_fset_rdu(rdu->cookie.flags, CALLED);
23158 + len = au_rdu_len(nlen);
23159 + if (arg->ent.ul + len < arg->end) {
23161 + ent.bindex = rdu->cookie.bindex;
23162 + ent.type = d_type;
23164 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
23165 + ent.type = DT_UNKNOWN;
23167 + /* unnecessary to support mmap_sem since this is a dir */
23169 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
23171 + if (copy_to_user(arg->ent.e->name, name, nlen))
23173 + /* the terminating NULL */
23174 + if (__put_user(0, arg->ent.e->name + nlen))
23177 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
23178 + arg->ent.ul += len;
23182 + au_fset_rdu(rdu->cookie.flags, FULL);
23184 + rdu->tail = arg->ent;
23188 + /* AuTraceErr(err); */
23192 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
23196 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
23198 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
23199 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
23201 + if (unlikely(offset != cookie->h_pos))
23207 + au_fclr_rdu(cookie->flags, CALLED);
23209 + err = vfsub_readdir(h_file, au_rdu_fill, arg);
23213 + && au_ftest_rdu(cookie->flags, CALLED)
23214 + && !au_ftest_rdu(cookie->flags, FULL));
23215 + cookie->h_pos = h_file->f_pos;
23222 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
23225 + aufs_bindex_t bend;
23226 + struct au_rdu_arg arg;
23227 + struct dentry *dentry;
23228 + struct inode *inode;
23229 + struct file *h_file;
23230 + struct au_rdu_cookie *cookie = &rdu->cookie;
23232 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
23233 + if (unlikely(err)) {
23239 + rdu->tail = rdu->ent;
23242 + arg.ent = rdu->ent;
23243 + arg.end = arg.ent.ul;
23244 + arg.end += rdu->sz;
23247 + if (unlikely(!file->f_op || !file->f_op->readdir))
23250 + err = security_file_permission(file, MAY_READ);
23252 + if (unlikely(err))
23255 + dentry = file->f_dentry;
23256 + inode = dentry->d_inode;
23258 + mutex_lock(&inode->i_mutex);
23260 + err = mutex_lock_killable(&inode->i_mutex);
23262 + if (unlikely(err))
23266 + arg.sb = inode->i_sb;
23267 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
23268 + if (unlikely(err))
23270 + err = au_alive_dir(dentry);
23271 + if (unlikely(err))
23273 + /* todo: reval? */
23274 + fi_read_lock(file);
23277 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
23278 + && cookie->generation != au_figen(file)))
23283 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
23285 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
23287 + bend = au_fbstart(file);
23288 + if (cookie->bindex < bend)
23289 + cookie->bindex = bend;
23290 + bend = au_fbend_dir(file);
23291 + /* AuDbg("b%d, b%d\n", cookie->bindex, bend); */
23292 + for (; !err && cookie->bindex <= bend;
23293 + cookie->bindex++, cookie->h_pos = 0) {
23294 + h_file = au_hf_dir(file, cookie->bindex);
23298 + au_fclr_rdu(cookie->flags, FULL);
23299 + err = au_rdu_do(h_file, &arg);
23301 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
23304 + AuDbg("rent %llu\n", rdu->rent);
23306 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
23307 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
23308 + au_fset_rdu(cookie->flags, CONT);
23309 + cookie->generation = au_figen(file);
23312 + ii_read_lock_child(inode);
23313 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibstart(inode)));
23314 + ii_read_unlock(inode);
23317 + fi_read_unlock(file);
23319 + si_read_unlock(arg.sb);
23321 + mutex_unlock(&inode->i_mutex);
23327 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
23331 + unsigned long long nent;
23332 + union au_rdu_ent_ul *u;
23333 + struct au_rdu_ent ent;
23334 + struct super_block *sb;
23337 + nent = rdu->nent;
23339 + sb = file->f_dentry->d_sb;
23340 + si_read_lock(sb, AuLock_FLUSH);
23341 + while (nent-- > 0) {
23342 + /* unnecessary to support mmap_sem since this is a dir */
23343 + err = copy_from_user(&ent, u->e, sizeof(ent));
23345 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
23346 + if (unlikely(err)) {
23352 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
23354 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
23356 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
23358 + if (unlikely(err)) {
23363 + err = __put_user(ino, &u->e->ino);
23364 + if (unlikely(err)) {
23369 + u->ul += au_rdu_len(ent.nlen);
23371 + si_read_unlock(sb);
23376 +/* ---------------------------------------------------------------------- */
23378 +static int au_rdu_verify(struct aufs_rdu *rdu)
23380 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
23381 + "%llu, b%d, 0x%x, g%u}\n",
23382 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
23384 + rdu->rent, rdu->shwh, rdu->full,
23385 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
23386 + rdu->cookie.generation);
23388 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
23392 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
23396 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
23399 + struct aufs_rdu rdu;
23400 + void __user *p = (void __user *)arg;
23402 + err = copy_from_user(&rdu, p, sizeof(rdu));
23403 + if (unlikely(err)) {
23408 + err = au_rdu_verify(&rdu);
23409 + if (unlikely(err))
23413 + case AUFS_CTL_RDU:
23414 + err = au_rdu(file, &rdu);
23415 + if (unlikely(err))
23418 + e = copy_to_user(p, &rdu, sizeof(rdu));
23419 + if (unlikely(e)) {
23424 + case AUFS_CTL_RDU_INO:
23425 + err = au_rdu_ino(file, &rdu);
23429 + /* err = -ENOTTY; */
23438 +#ifdef CONFIG_COMPAT
23439 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
23442 + struct aufs_rdu rdu;
23443 + void __user *p = compat_ptr(arg);
23445 + /* todo: get_user()? */
23446 + err = copy_from_user(&rdu, p, sizeof(rdu));
23447 + if (unlikely(err)) {
23452 + rdu.ent.e = compat_ptr(rdu.ent.ul);
23453 + err = au_rdu_verify(&rdu);
23454 + if (unlikely(err))
23458 + case AUFS_CTL_RDU:
23459 + err = au_rdu(file, &rdu);
23460 + if (unlikely(err))
23463 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
23464 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
23465 + e = copy_to_user(p, &rdu, sizeof(rdu));
23466 + if (unlikely(e)) {
23471 + case AUFS_CTL_RDU_INO:
23472 + err = au_rdu_ino(file, &rdu);
23476 + /* err = -ENOTTY; */
23485 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
23486 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
23487 +++ linux/fs/aufs/rwsem.h 2013-07-06 13:20:47.753531903 +0200
23490 + * Copyright (C) 2005-2013 Junjiro R. Okajima
23492 + * This program, aufs is free software; you can redistribute it and/or modify
23493 + * it under the terms of the GNU General Public License as published by
23494 + * the Free Software Foundation; either version 2 of the License, or
23495 + * (at your option) any later version.
23497 + * This program is distributed in the hope that it will be useful,
23498 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23499 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23500 + * GNU General Public License for more details.
23502 + * You should have received a copy of the GNU General Public License
23503 + * along with this program; if not, write to the Free Software
23504 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23508 + * simple read-write semaphore wrappers
23511 +#ifndef __AUFS_RWSEM_H__
23512 +#define __AUFS_RWSEM_H__
23516 +#include "debug.h"
23519 + struct rw_semaphore rwsem;
23520 +#ifdef CONFIG_AUFS_DEBUG
23521 + /* just for debugging, not almighty counter */
23522 + atomic_t rcnt, wcnt;
23526 +#ifdef CONFIG_AUFS_DEBUG
23527 +#define AuDbgCntInit(rw) do { \
23528 + atomic_set(&(rw)->rcnt, 0); \
23529 + atomic_set(&(rw)->wcnt, 0); \
23530 + smp_mb(); /* atomic set */ \
23533 +#define AuDbgRcntInc(rw) atomic_inc(&(rw)->rcnt)
23534 +#define AuDbgRcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->rcnt) < 0)
23535 +#define AuDbgWcntInc(rw) atomic_inc(&(rw)->wcnt)
23536 +#define AuDbgWcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->wcnt) < 0)
23538 +#define AuDbgCntInit(rw) do {} while (0)
23539 +#define AuDbgRcntInc(rw) do {} while (0)
23540 +#define AuDbgRcntDec(rw) do {} while (0)
23541 +#define AuDbgWcntInc(rw) do {} while (0)
23542 +#define AuDbgWcntDec(rw) do {} while (0)
23543 +#endif /* CONFIG_AUFS_DEBUG */
23545 +/* to debug easier, do not make them inlined functions */
23546 +#define AuRwMustNoWaiters(rw) AuDebugOn(!list_empty(&(rw)->rwsem.wait_list))
23547 +/* rwsem_is_locked() is unusable */
23548 +#define AuRwMustReadLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0)
23549 +#define AuRwMustWriteLock(rw) AuDebugOn(atomic_read(&(rw)->wcnt) <= 0)
23550 +#define AuRwMustAnyLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0 \
23551 + && atomic_read(&(rw)->wcnt) <= 0)
23552 +#define AuRwDestroy(rw) AuDebugOn(atomic_read(&(rw)->rcnt) \
23553 + || atomic_read(&(rw)->wcnt))
23555 +#define au_rw_class(rw, key) lockdep_set_class(&(rw)->rwsem, key)
23557 +static inline void au_rw_init(struct au_rwsem *rw)
23559 + AuDbgCntInit(rw);
23560 + init_rwsem(&rw->rwsem);
23563 +static inline void au_rw_init_wlock(struct au_rwsem *rw)
23566 + down_write(&rw->rwsem);
23567 + AuDbgWcntInc(rw);
23570 +static inline void au_rw_init_wlock_nested(struct au_rwsem *rw,
23571 + unsigned int lsc)
23574 + down_write_nested(&rw->rwsem, lsc);
23575 + AuDbgWcntInc(rw);
23578 +static inline void au_rw_read_lock(struct au_rwsem *rw)
23580 + down_read(&rw->rwsem);
23581 + AuDbgRcntInc(rw);
23584 +static inline void au_rw_read_lock_nested(struct au_rwsem *rw, unsigned int lsc)
23586 + down_read_nested(&rw->rwsem, lsc);
23587 + AuDbgRcntInc(rw);
23590 +static inline void au_rw_read_unlock(struct au_rwsem *rw)
23592 + AuRwMustReadLock(rw);
23593 + AuDbgRcntDec(rw);
23594 + up_read(&rw->rwsem);
23597 +static inline void au_rw_dgrade_lock(struct au_rwsem *rw)
23599 + AuRwMustWriteLock(rw);
23600 + AuDbgRcntInc(rw);
23601 + AuDbgWcntDec(rw);
23602 + downgrade_write(&rw->rwsem);
23605 +static inline void au_rw_write_lock(struct au_rwsem *rw)
23607 + down_write(&rw->rwsem);
23608 + AuDbgWcntInc(rw);
23611 +static inline void au_rw_write_lock_nested(struct au_rwsem *rw,
23612 + unsigned int lsc)
23614 + down_write_nested(&rw->rwsem, lsc);
23615 + AuDbgWcntInc(rw);
23618 +static inline void au_rw_write_unlock(struct au_rwsem *rw)
23620 + AuRwMustWriteLock(rw);
23621 + AuDbgWcntDec(rw);
23622 + up_write(&rw->rwsem);
23625 +/* why is not _nested version defined */
23626 +static inline int au_rw_read_trylock(struct au_rwsem *rw)
23628 + int ret = down_read_trylock(&rw->rwsem);
23630 + AuDbgRcntInc(rw);
23634 +static inline int au_rw_write_trylock(struct au_rwsem *rw)
23636 + int ret = down_write_trylock(&rw->rwsem);
23638 + AuDbgWcntInc(rw);
23642 +#undef AuDbgCntInit
23643 +#undef AuDbgRcntInc
23644 +#undef AuDbgRcntDec
23645 +#undef AuDbgWcntInc
23646 +#undef AuDbgWcntDec
23648 +#define AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
23649 +static inline void prefix##_read_lock(param) \
23650 +{ au_rw_read_lock(rwsem); } \
23651 +static inline void prefix##_write_lock(param) \
23652 +{ au_rw_write_lock(rwsem); } \
23653 +static inline int prefix##_read_trylock(param) \
23654 +{ return au_rw_read_trylock(rwsem); } \
23655 +static inline int prefix##_write_trylock(param) \
23656 +{ return au_rw_write_trylock(rwsem); }
23657 +/* why is not _nested version defined */
23658 +/* static inline void prefix##_read_trylock_nested(param, lsc)
23659 +{ au_rw_read_trylock_nested(rwsem, lsc)); }
23660 +static inline void prefix##_write_trylock_nestd(param, lsc)
23661 +{ au_rw_write_trylock_nested(rwsem, lsc); } */
23663 +#define AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) \
23664 +static inline void prefix##_read_unlock(param) \
23665 +{ au_rw_read_unlock(rwsem); } \
23666 +static inline void prefix##_write_unlock(param) \
23667 +{ au_rw_write_unlock(rwsem); } \
23668 +static inline void prefix##_downgrade_lock(param) \
23669 +{ au_rw_dgrade_lock(rwsem); }
23671 +#define AuSimpleRwsemFuncs(prefix, param, rwsem) \
23672 + AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
23673 + AuSimpleUnlockRwsemFuncs(prefix, param, rwsem)
23675 +#endif /* __KERNEL__ */
23676 +#endif /* __AUFS_RWSEM_H__ */
23677 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
23678 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
23679 +++ linux/fs/aufs/sbinfo.c 2013-07-06 13:20:47.753531903 +0200
23682 + * Copyright (C) 2005-2013 Junjiro R. Okajima
23684 + * This program, aufs is free software; you can redistribute it and/or modify
23685 + * it under the terms of the GNU General Public License as published by
23686 + * the Free Software Foundation; either version 2 of the License, or
23687 + * (at your option) any later version.
23689 + * This program is distributed in the hope that it will be useful,
23690 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23691 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23692 + * GNU General Public License for more details.
23694 + * You should have received a copy of the GNU General Public License
23695 + * along with this program; if not, write to the Free Software
23696 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23700 + * superblock private data
23706 + * they are necessary regardless sysfs is disabled.
23708 +void au_si_free(struct kobject *kobj)
23711 + struct au_sbinfo *sbinfo;
23712 + char *locked __maybe_unused; /* debug only */
23714 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
23715 + for (i = 0; i < AuPlink_NHASH; i++)
23716 + AuDebugOn(!hlist_empty(&sbinfo->si_plink[i].head));
23717 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
23719 + au_rw_write_lock(&sbinfo->si_rwsem);
23720 + au_br_free(sbinfo);
23721 + au_rw_write_unlock(&sbinfo->si_rwsem);
23723 + AuDebugOn(radix_tree_gang_lookup
23724 + (&sbinfo->au_si_pid.tree, (void **)&locked,
23725 + /*first_index*/PID_MAX_DEFAULT - 1,
23726 + /*max_items*/sizeof(locked)/sizeof(*locked)));
23728 + kfree(sbinfo->si_branch);
23729 + kfree(sbinfo->au_si_pid.bitmap);
23730 + mutex_destroy(&sbinfo->si_xib_mtx);
23731 + AuRwDestroy(&sbinfo->si_rwsem);
23736 +int au_si_alloc(struct super_block *sb)
23739 + struct au_sbinfo *sbinfo;
23740 + static struct lock_class_key aufs_si;
23743 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
23744 + if (unlikely(!sbinfo))
23747 + BUILD_BUG_ON(sizeof(unsigned long) !=
23748 + sizeof(*sbinfo->au_si_pid.bitmap));
23749 + sbinfo->au_si_pid.bitmap = kcalloc(BITS_TO_LONGS(PID_MAX_DEFAULT),
23750 + sizeof(*sbinfo->au_si_pid.bitmap),
23752 + if (unlikely(!sbinfo->au_si_pid.bitmap))
23755 + /* will be reallocated separately */
23756 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
23757 + if (unlikely(!sbinfo->si_branch))
23760 + err = sysaufs_si_init(sbinfo);
23761 + if (unlikely(err))
23764 + au_nwt_init(&sbinfo->si_nowait);
23765 + au_rw_init_wlock(&sbinfo->si_rwsem);
23766 + au_rw_class(&sbinfo->si_rwsem, &aufs_si);
23767 + spin_lock_init(&sbinfo->au_si_pid.tree_lock);
23768 + INIT_RADIX_TREE(&sbinfo->au_si_pid.tree, GFP_ATOMIC | __GFP_NOFAIL);
23770 + atomic_long_set(&sbinfo->si_ninodes, 0);
23771 + atomic_long_set(&sbinfo->si_nfiles, 0);
23773 + sbinfo->si_bend = -1;
23775 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
23776 + sbinfo->si_wbr_create = AuWbrCreate_Def;
23777 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
23778 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
23780 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
23782 + mutex_init(&sbinfo->si_xib_mtx);
23783 + sbinfo->si_xino_brid = -1;
23784 + /* leave si_xib_last_pindex and si_xib_next_bit */
23786 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
23787 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
23788 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
23789 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
23791 + for (i = 0; i < AuPlink_NHASH; i++)
23792 + au_sphl_init(sbinfo->si_plink + i);
23793 + init_waitqueue_head(&sbinfo->si_plink_wq);
23794 + spin_lock_init(&sbinfo->si_plink_maint_lock);
23796 + au_sphl_init(&sbinfo->si_files);
23798 + /* leave other members for sysaufs and si_mnt. */
23799 + sbinfo->si_sb = sb;
23800 + sb->s_fs_info = sbinfo;
23802 + au_debug_sbinfo_init(sbinfo);
23803 + return 0; /* success */
23806 + kfree(sbinfo->si_branch);
23808 + kfree(sbinfo->au_si_pid.bitmap);
23815 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr)
23818 + struct au_branch **brp;
23820 + AuRwMustWriteLock(&sbinfo->si_rwsem);
23823 + sz = sizeof(*brp) * (sbinfo->si_bend + 1);
23824 + if (unlikely(!sz))
23825 + sz = sizeof(*brp);
23826 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS);
23828 + sbinfo->si_branch = brp;
23835 +/* ---------------------------------------------------------------------- */
23837 +unsigned int au_sigen_inc(struct super_block *sb)
23839 + unsigned int gen;
23841 + SiMustWriteLock(sb);
23843 + gen = ++au_sbi(sb)->si_generation;
23844 + au_update_digen(sb->s_root);
23845 + au_update_iigen(sb->s_root->d_inode, /*half*/0);
23846 + sb->s_root->d_inode->i_version++;
23850 +aufs_bindex_t au_new_br_id(struct super_block *sb)
23852 + aufs_bindex_t br_id;
23854 + struct au_sbinfo *sbinfo;
23856 + SiMustWriteLock(sb);
23858 + sbinfo = au_sbi(sb);
23859 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
23860 + br_id = ++sbinfo->si_last_br_id;
23861 + AuDebugOn(br_id < 0);
23862 + if (br_id && au_br_index(sb, br_id) < 0)
23869 +/* ---------------------------------------------------------------------- */
23871 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
23872 +int si_read_lock(struct super_block *sb, int flags)
23877 + if (au_ftest_lock(flags, FLUSH))
23878 + au_nwt_flush(&au_sbi(sb)->si_nowait);
23880 + si_noflush_read_lock(sb);
23881 + err = au_plink_maint(sb, flags);
23882 + if (unlikely(err))
23883 + si_read_unlock(sb);
23888 +int si_write_lock(struct super_block *sb, int flags)
23892 + if (au_ftest_lock(flags, FLUSH))
23893 + au_nwt_flush(&au_sbi(sb)->si_nowait);
23895 + si_noflush_write_lock(sb);
23896 + err = au_plink_maint(sb, flags);
23897 + if (unlikely(err))
23898 + si_write_unlock(sb);
23903 +/* dentry and super_block lock. call at entry point */
23904 +int aufs_read_lock(struct dentry *dentry, int flags)
23907 + struct super_block *sb;
23909 + sb = dentry->d_sb;
23910 + err = si_read_lock(sb, flags);
23911 + if (unlikely(err))
23914 + if (au_ftest_lock(flags, DW))
23915 + di_write_lock_child(dentry);
23917 + di_read_lock_child(dentry, flags);
23919 + if (au_ftest_lock(flags, GEN)) {
23920 + err = au_digen_test(dentry, au_sigen(sb));
23921 + AuDebugOn(!err && au_dbrange_test(dentry));
23922 + if (unlikely(err))
23923 + aufs_read_unlock(dentry, flags);
23930 +void aufs_read_unlock(struct dentry *dentry, int flags)
23932 + if (au_ftest_lock(flags, DW))
23933 + di_write_unlock(dentry);
23935 + di_read_unlock(dentry, flags);
23936 + si_read_unlock(dentry->d_sb);
23939 +void aufs_write_lock(struct dentry *dentry)
23941 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
23942 + di_write_lock_child(dentry);
23945 +void aufs_write_unlock(struct dentry *dentry)
23947 + di_write_unlock(dentry);
23948 + si_write_unlock(dentry->d_sb);
23951 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
23954 + unsigned int sigen;
23955 + struct super_block *sb;
23958 + err = si_read_lock(sb, flags);
23959 + if (unlikely(err))
23962 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIR));
23964 + if (au_ftest_lock(flags, GEN)) {
23965 + sigen = au_sigen(sb);
23966 + err = au_digen_test(d1, sigen);
23967 + AuDebugOn(!err && au_dbrange_test(d1));
23969 + err = au_digen_test(d2, sigen);
23970 + AuDebugOn(!err && au_dbrange_test(d2));
23972 + if (unlikely(err))
23973 + aufs_read_and_write_unlock2(d1, d2);
23980 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
23982 + di_write_unlock2(d1, d2);
23983 + si_read_unlock(d1->d_sb);
23986 +/* ---------------------------------------------------------------------- */
23988 +int si_pid_test_slow(struct super_block *sb)
23993 + p = radix_tree_lookup(&au_sbi(sb)->au_si_pid.tree, current->pid);
23994 + rcu_read_unlock();
23996 + return (long)!!p;
23999 +void si_pid_set_slow(struct super_block *sb)
24002 + struct au_sbinfo *sbinfo;
24004 + AuDebugOn(si_pid_test_slow(sb));
24006 + sbinfo = au_sbi(sb);
24007 + err = radix_tree_preload(GFP_NOFS | __GFP_NOFAIL);
24009 + spin_lock(&sbinfo->au_si_pid.tree_lock);
24010 + err = radix_tree_insert(&sbinfo->au_si_pid.tree, current->pid,
24011 + /*any valid ptr*/sb);
24012 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
24014 + radix_tree_preload_end();
24017 +void si_pid_clr_slow(struct super_block *sb)
24020 + struct au_sbinfo *sbinfo;
24022 + AuDebugOn(!si_pid_test_slow(sb));
24024 + sbinfo = au_sbi(sb);
24025 + spin_lock(&sbinfo->au_si_pid.tree_lock);
24026 + p = radix_tree_delete(&sbinfo->au_si_pid.tree, current->pid);
24027 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
24029 diff -urN /usr/share/empty/fs/aufs/spl.h linux/fs/aufs/spl.h
24030 --- /usr/share/empty/fs/aufs/spl.h 1970-01-01 01:00:00.000000000 +0100
24031 +++ linux/fs/aufs/spl.h 2013-07-06 13:20:47.753531903 +0200
24034 + * Copyright (C) 2005-2013 Junjiro R. Okajima
24036 + * This program, aufs is free software; you can redistribute it and/or modify
24037 + * it under the terms of the GNU General Public License as published by
24038 + * the Free Software Foundation; either version 2 of the License, or
24039 + * (at your option) any later version.
24041 + * This program is distributed in the hope that it will be useful,
24042 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24043 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24044 + * GNU General Public License for more details.
24046 + * You should have received a copy of the GNU General Public License
24047 + * along with this program; if not, write to the Free Software
24048 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24052 + * simple list protected by a spinlock
24055 +#ifndef __AUFS_SPL_H__
24056 +#define __AUFS_SPL_H__
24060 +struct au_splhead {
24062 + struct list_head head;
24065 +static inline void au_spl_init(struct au_splhead *spl)
24067 + spin_lock_init(&spl->spin);
24068 + INIT_LIST_HEAD(&spl->head);
24071 +static inline void au_spl_add(struct list_head *list, struct au_splhead *spl)
24073 + spin_lock(&spl->spin);
24074 + list_add(list, &spl->head);
24075 + spin_unlock(&spl->spin);
24078 +static inline void au_spl_del(struct list_head *list, struct au_splhead *spl)
24080 + spin_lock(&spl->spin);
24082 + spin_unlock(&spl->spin);
24085 +static inline void au_spl_del_rcu(struct list_head *list,
24086 + struct au_splhead *spl)
24088 + spin_lock(&spl->spin);
24089 + list_del_rcu(list);
24090 + spin_unlock(&spl->spin);
24093 +/* ---------------------------------------------------------------------- */
24095 +struct au_sphlhead {
24097 + struct hlist_head head;
24100 +static inline void au_sphl_init(struct au_sphlhead *sphl)
24102 + spin_lock_init(&sphl->spin);
24103 + INIT_HLIST_HEAD(&sphl->head);
24106 +static inline void au_sphl_add(struct hlist_node *hlist,
24107 + struct au_sphlhead *sphl)
24109 + spin_lock(&sphl->spin);
24110 + hlist_add_head(hlist, &sphl->head);
24111 + spin_unlock(&sphl->spin);
24114 +static inline void au_sphl_del(struct hlist_node *hlist,
24115 + struct au_sphlhead *sphl)
24117 + spin_lock(&sphl->spin);
24118 + hlist_del(hlist);
24119 + spin_unlock(&sphl->spin);
24122 +static inline void au_sphl_del_rcu(struct hlist_node *hlist,
24123 + struct au_sphlhead *sphl)
24125 + spin_lock(&sphl->spin);
24126 + hlist_del_rcu(hlist);
24127 + spin_unlock(&sphl->spin);
24130 +static inline unsigned long au_sphl_count(struct au_sphlhead *sphl)
24132 + unsigned long cnt;
24133 + struct hlist_node *pos;
24136 + spin_lock(&sphl->spin);
24137 + hlist_for_each(pos, &sphl->head)
24139 + spin_unlock(&sphl->spin);
24143 +#endif /* __KERNEL__ */
24144 +#endif /* __AUFS_SPL_H__ */
24145 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
24146 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
24147 +++ linux/fs/aufs/super.c 2013-08-23 23:59:39.634916914 +0200
24150 + * Copyright (C) 2005-2013 Junjiro R. Okajima
24152 + * This program, aufs is free software; you can redistribute it and/or modify
24153 + * it under the terms of the GNU General Public License as published by
24154 + * the Free Software Foundation; either version 2 of the License, or
24155 + * (at your option) any later version.
24157 + * This program is distributed in the hope that it will be useful,
24158 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24159 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24160 + * GNU General Public License for more details.
24162 + * You should have received a copy of the GNU General Public License
24163 + * along with this program; if not, write to the Free Software
24164 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24168 + * mount and super_block operations
24171 +#include <linux/mm.h>
24172 +#include <linux/module.h>
24173 +#include <linux/seq_file.h>
24174 +#include <linux/statfs.h>
24175 +#include <linux/vmalloc.h>
24176 +#include <linux/writeback.h>
24180 + * super_operations
24182 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
24184 + struct au_icntnr *c;
24186 + c = au_cache_alloc_icntnr();
24188 + au_icntnr_init(c);
24189 + c->vfs_inode.i_version = 1; /* sigen(sb); */
24190 + c->iinfo.ii_hinode = NULL;
24191 + return &c->vfs_inode;
24196 +static void aufs_destroy_inode_cb(struct rcu_head *head)
24198 + struct inode *inode = container_of(head, struct inode, i_rcu);
24200 + INIT_HLIST_HEAD(&inode->i_dentry);
24201 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
24204 +static void aufs_destroy_inode(struct inode *inode)
24206 + au_iinfo_fin(inode);
24207 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
24210 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
24212 + struct inode *inode;
24215 + inode = iget_locked(sb, ino);
24216 + if (unlikely(!inode)) {
24217 + inode = ERR_PTR(-ENOMEM);
24220 + if (!(inode->i_state & I_NEW))
24223 + err = au_xigen_new(inode);
24225 + err = au_iinfo_init(inode);
24227 + inode->i_version++;
24229 + iget_failed(inode);
24230 + inode = ERR_PTR(err);
24234 + /* never return NULL */
24235 + AuDebugOn(!inode);
24236 + AuTraceErrPtr(inode);
24240 +/* lock free root dinfo */
24241 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
24244 + aufs_bindex_t bindex, bend;
24245 + struct path path;
24246 + struct au_hdentry *hdp;
24247 + struct au_branch *br;
24251 + bend = au_sbend(sb);
24252 + hdp = au_di(sb->s_root)->di_hdentry;
24253 + for (bindex = 0; !err && bindex <= bend; bindex++) {
24254 + br = au_sbr(sb, bindex);
24255 + path.mnt = au_br_mnt(br);
24256 + path.dentry = hdp[bindex].hd_dentry;
24257 + err = au_seq_path(seq, &path);
24259 + perm = au_optstr_br_perm(br->br_perm);
24261 + err = seq_printf(seq, "=%s", perm);
24268 + if (!err && bindex != bend)
24269 + err = seq_putc(seq, ':');
24275 +static void au_show_wbr_create(struct seq_file *m, int v,
24276 + struct au_sbinfo *sbinfo)
24280 + AuRwMustAnyLock(&sbinfo->si_rwsem);
24282 + seq_puts(m, ",create=");
24283 + pat = au_optstr_wbr_create(v);
24285 + case AuWbrCreate_TDP:
24286 + case AuWbrCreate_RR:
24287 + case AuWbrCreate_MFS:
24288 + case AuWbrCreate_PMFS:
24289 + seq_puts(m, pat);
24291 + case AuWbrCreate_MFSV:
24292 + seq_printf(m, /*pat*/"mfs:%lu",
24293 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
24296 + case AuWbrCreate_PMFSV:
24297 + seq_printf(m, /*pat*/"pmfs:%lu",
24298 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
24301 + case AuWbrCreate_MFSRR:
24302 + seq_printf(m, /*pat*/"mfsrr:%llu",
24303 + sbinfo->si_wbr_mfs.mfsrr_watermark);
24305 + case AuWbrCreate_MFSRRV:
24306 + seq_printf(m, /*pat*/"mfsrr:%llu:%lu",
24307 + sbinfo->si_wbr_mfs.mfsrr_watermark,
24308 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
24314 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
24316 +#ifdef CONFIG_SYSFS
24320 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
24321 + aufs_bindex_t bindex, brid;
24322 + struct qstr *name;
24324 + struct dentry *d, *h_root;
24325 + struct au_hdentry *hdp;
24327 + AuRwMustAnyLock(&sbinfo->si_rwsem);
24330 + f = au_sbi(sb)->si_xib;
24334 + /* stop printing the default xino path on the first writable branch */
24336 + brid = au_xino_brid(sb);
24338 + bindex = au_br_index(sb, brid);
24339 + hdp = au_di(sb->s_root)->di_hdentry;
24340 + h_root = hdp[0 + bindex].hd_dentry;
24343 + name = &d->d_name;
24344 + /* safe ->d_parent because the file is unlinked */
24345 + if (d->d_parent == h_root
24346 + && name->len == len
24347 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
24350 + seq_puts(seq, ",xino=");
24351 + err = au_xino_path(seq, f);
24358 +/* seq_file will re-call me in case of too long string */
24359 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
24362 + unsigned int mnt_flags, v;
24363 + struct super_block *sb;
24364 + struct au_sbinfo *sbinfo;
24366 +#define AuBool(name, str) do { \
24367 + v = au_opt_test(mnt_flags, name); \
24368 + if (v != au_opt_test(AuOpt_Def, name)) \
24369 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
24372 +#define AuStr(name, str) do { \
24373 + v = mnt_flags & AuOptMask_##name; \
24374 + if (v != (AuOpt_Def & AuOptMask_##name)) \
24375 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
24378 +#define AuUInt(name, str, val) do { \
24379 + if (val != AUFS_##name##_DEF) \
24380 + seq_printf(m, "," #str "=%u", val); \
24383 + /* lock free root dinfo */
24384 + sb = dentry->d_sb;
24385 + si_noflush_read_lock(sb);
24386 + sbinfo = au_sbi(sb);
24387 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
24389 + mnt_flags = au_mntflags(sb);
24390 + if (au_opt_test(mnt_flags, XINO)) {
24391 + err = au_show_xino(m, sb);
24392 + if (unlikely(err))
24395 + seq_puts(m, ",noxino");
24397 + AuBool(TRUNC_XINO, trunc_xino);
24398 + AuStr(UDBA, udba);
24399 + AuBool(SHWH, shwh);
24400 + AuBool(PLINK, plink);
24401 + AuBool(DIO, dio);
24402 + /* AuBool(DIRPERM1, dirperm1); */
24403 + /* AuBool(REFROF, refrof); */
24405 + v = sbinfo->si_wbr_create;
24406 + if (v != AuWbrCreate_Def)
24407 + au_show_wbr_create(m, v, sbinfo);
24409 + v = sbinfo->si_wbr_copyup;
24410 + if (v != AuWbrCopyup_Def)
24411 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
24413 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
24414 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
24415 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
24417 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
24419 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
24420 + AuUInt(RDCACHE, rdcache, v);
24422 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
24423 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
24425 + AuBool(SUM, sum);
24426 + /* AuBool(SUM_W, wsum); */
24427 + AuBool(WARN_PERM, warn_perm);
24428 + AuBool(VERBOSE, verbose);
24431 + /* be sure to print "br:" last */
24432 + if (!sysaufs_brs) {
24433 + seq_puts(m, ",br:");
24434 + au_show_brs(m, sb);
24436 + si_read_unlock(sb);
24444 +/* ---------------------------------------------------------------------- */
24446 +/* sum mode which returns the summation for statfs(2) */
24448 +static u64 au_add_till_max(u64 a, u64 b)
24456 + return ULLONG_MAX;
24459 +static u64 au_mul_till_max(u64 a, long mul)
24467 + return ULLONG_MAX;
24470 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
24473 + long bsize, factor;
24474 + u64 blocks, bfree, bavail, files, ffree;
24475 + aufs_bindex_t bend, bindex, i;
24476 + unsigned char shared;
24477 + struct path h_path;
24478 + struct super_block *h_sb;
24481 + bsize = LONG_MAX;
24487 + bend = au_sbend(sb);
24488 + for (bindex = 0; bindex <= bend; bindex++) {
24489 + h_path.mnt = au_sbr_mnt(sb, bindex);
24490 + h_sb = h_path.mnt->mnt_sb;
24492 + for (i = 0; !shared && i < bindex; i++)
24493 + shared = (au_sbr_sb(sb, i) == h_sb);
24497 + /* sb->s_root for NFS is unreliable */
24498 + h_path.dentry = h_path.mnt->mnt_root;
24499 + err = vfs_statfs(&h_path, buf);
24500 + if (unlikely(err))
24503 + if (bsize > buf->f_bsize) {
24505 + * we will reduce bsize, so we have to expand blocks
24506 + * etc. to match them again
24508 + factor = (bsize / buf->f_bsize);
24509 + blocks = au_mul_till_max(blocks, factor);
24510 + bfree = au_mul_till_max(bfree, factor);
24511 + bavail = au_mul_till_max(bavail, factor);
24512 + bsize = buf->f_bsize;
24515 + factor = (buf->f_bsize / bsize);
24516 + blocks = au_add_till_max(blocks,
24517 + au_mul_till_max(buf->f_blocks, factor));
24518 + bfree = au_add_till_max(bfree,
24519 + au_mul_till_max(buf->f_bfree, factor));
24520 + bavail = au_add_till_max(bavail,
24521 + au_mul_till_max(buf->f_bavail, factor));
24522 + files = au_add_till_max(files, buf->f_files);
24523 + ffree = au_add_till_max(ffree, buf->f_ffree);
24526 + buf->f_bsize = bsize;
24527 + buf->f_blocks = blocks;
24528 + buf->f_bfree = bfree;
24529 + buf->f_bavail = bavail;
24530 + buf->f_files = files;
24531 + buf->f_ffree = ffree;
24532 + buf->f_frsize = 0;
24538 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
24541 + struct path h_path;
24542 + struct super_block *sb;
24544 + /* lock free root dinfo */
24545 + sb = dentry->d_sb;
24546 + si_noflush_read_lock(sb);
24547 + if (!au_opt_test(au_mntflags(sb), SUM)) {
24548 + /* sb->s_root for NFS is unreliable */
24549 + h_path.mnt = au_sbr_mnt(sb, 0);
24550 + h_path.dentry = h_path.mnt->mnt_root;
24551 + err = vfs_statfs(&h_path, buf);
24553 + err = au_statfs_sum(sb, buf);
24554 + si_read_unlock(sb);
24557 + buf->f_type = AUFS_SUPER_MAGIC;
24558 + buf->f_namelen = AUFS_MAX_NAMELEN;
24559 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
24561 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
24566 +/* ---------------------------------------------------------------------- */
24568 +static int aufs_sync_fs(struct super_block *sb, int wait)
24571 + aufs_bindex_t bend, bindex;
24572 + struct au_branch *br;
24573 + struct super_block *h_sb;
24576 + si_noflush_read_lock(sb);
24577 + bend = au_sbend(sb);
24578 + for (bindex = 0; bindex <= bend; bindex++) {
24579 + br = au_sbr(sb, bindex);
24580 + if (!au_br_writable(br->br_perm))
24583 + h_sb = au_sbr_sb(sb, bindex);
24584 + if (h_sb->s_op->sync_fs) {
24585 + e = h_sb->s_op->sync_fs(h_sb, wait);
24586 + if (unlikely(e && !err))
24588 + /* go on even if an error happens */
24591 + si_read_unlock(sb);
24596 +/* ---------------------------------------------------------------------- */
24598 +/* final actions when unmounting a file system */
24599 +static void aufs_put_super(struct super_block *sb)
24601 + struct au_sbinfo *sbinfo;
24603 + sbinfo = au_sbi(sb);
24607 + dbgaufs_si_fin(sbinfo);
24608 + kobject_put(&sbinfo->si_kobj);
24611 +/* ---------------------------------------------------------------------- */
24613 +void au_array_free(void *array)
24616 + if (!is_vmalloc_addr(array))
24623 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg)
24626 + unsigned long long n;
24633 + if (*hint > ULLONG_MAX / sizeof(array)) {
24634 + array = ERR_PTR(-EMFILE);
24635 + pr_err("hint %llu\n", *hint);
24639 + array = kmalloc(sizeof(array) * *hint, GFP_NOFS);
24640 + if (unlikely(!array))
24641 + array = vmalloc(sizeof(array) * *hint);
24642 + if (unlikely(!array)) {
24643 + array = ERR_PTR(-ENOMEM);
24647 + n = cb(array, *hint, arg);
24648 + AuDebugOn(n > *hint);
24655 +static unsigned long long au_iarray_cb(void *a,
24656 + unsigned long long max __maybe_unused,
24659 + unsigned long long n;
24660 + struct inode **p, *inode;
24661 + struct list_head *head;
24666 + spin_lock(&inode_sb_list_lock);
24667 + list_for_each_entry(inode, head, i_sb_list) {
24668 + if (!is_bad_inode(inode)
24669 + && au_ii(inode)->ii_bstart >= 0) {
24670 + spin_lock(&inode->i_lock);
24671 + if (atomic_read(&inode->i_count)) {
24675 + AuDebugOn(n > max);
24677 + spin_unlock(&inode->i_lock);
24680 + spin_unlock(&inode_sb_list_lock);
24685 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
24687 + *max = atomic_long_read(&au_sbi(sb)->si_ninodes);
24688 + return au_array_alloc(max, au_iarray_cb, &sb->s_inodes);
24691 +void au_iarray_free(struct inode **a, unsigned long long max)
24693 + unsigned long long ull;
24695 + for (ull = 0; ull < max; ull++)
24697 + au_array_free(a);
24700 +/* ---------------------------------------------------------------------- */
24703 + * refresh dentry and inode at remount time.
24705 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
24706 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
24707 + struct dentry *parent)
24711 + di_write_lock_child(dentry);
24712 + di_read_lock_parent(parent, AuLock_IR);
24713 + err = au_refresh_dentry(dentry, parent);
24714 + if (!err && dir_flags)
24715 + au_hn_reset(dentry->d_inode, dir_flags);
24716 + di_read_unlock(parent, AuLock_IR);
24717 + di_write_unlock(dentry);
24722 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
24723 + struct au_sbinfo *sbinfo,
24724 + const unsigned int dir_flags)
24727 + struct dentry *parent;
24728 + struct inode *inode;
24731 + parent = dget_parent(dentry);
24732 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
24733 + inode = dentry->d_inode;
24735 + if (!S_ISDIR(inode->i_mode))
24736 + err = au_do_refresh(dentry, /*dir_flags*/0,
24739 + err = au_do_refresh(dentry, dir_flags, parent);
24740 + if (unlikely(err))
24741 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
24744 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
24745 + AuDbgDentry(dentry);
24753 +static int au_refresh_d(struct super_block *sb)
24755 + int err, i, j, ndentry, e;
24756 + unsigned int sigen;
24757 + struct au_dcsub_pages dpages;
24758 + struct au_dpage *dpage;
24759 + struct dentry **dentries, *d;
24760 + struct au_sbinfo *sbinfo;
24761 + struct dentry *root = sb->s_root;
24762 + const unsigned int dir_flags = au_hi_flags(root->d_inode, /*isdir*/1);
24764 + err = au_dpages_init(&dpages, GFP_NOFS);
24765 + if (unlikely(err))
24767 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
24768 + if (unlikely(err))
24771 + sigen = au_sigen(sb);
24772 + sbinfo = au_sbi(sb);
24773 + for (i = 0; i < dpages.ndpage; i++) {
24774 + dpage = dpages.dpages + i;
24775 + dentries = dpage->dentries;
24776 + ndentry = dpage->ndentry;
24777 + for (j = 0; j < ndentry; j++) {
24779 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags);
24780 + if (unlikely(e && !err))
24782 + /* go on even err */
24787 + au_dpages_free(&dpages);
24792 +static int au_refresh_i(struct super_block *sb)
24795 + unsigned int sigen;
24796 + unsigned long long max, ull;
24797 + struct inode *inode, **array;
24799 + array = au_iarray_alloc(sb, &max);
24800 + err = PTR_ERR(array);
24801 + if (IS_ERR(array))
24805 + sigen = au_sigen(sb);
24806 + for (ull = 0; ull < max; ull++) {
24807 + inode = array[ull];
24808 + if (au_iigen(inode, NULL) != sigen) {
24809 + ii_write_lock_child(inode);
24810 + e = au_refresh_hinode_self(inode);
24811 + ii_write_unlock(inode);
24812 + if (unlikely(e)) {
24813 + pr_err("error %d, i%lu\n", e, inode->i_ino);
24816 + /* go on even if err */
24821 + au_iarray_free(array, max);
24827 +static void au_remount_refresh(struct super_block *sb)
24830 + unsigned int udba;
24831 + aufs_bindex_t bindex, bend;
24832 + struct dentry *root;
24833 + struct inode *inode;
24834 + struct au_branch *br;
24836 + au_sigen_inc(sb);
24837 + au_fclr_si(au_sbi(sb), FAILED_REFRESH_DIR);
24839 + root = sb->s_root;
24840 + DiMustNoWaiters(root);
24841 + inode = root->d_inode;
24842 + IiMustNoWaiters(inode);
24844 + udba = au_opt_udba(sb);
24845 + bend = au_sbend(sb);
24846 + for (bindex = 0; bindex <= bend; bindex++) {
24847 + br = au_sbr(sb, bindex);
24848 + err = au_hnotify_reset_br(udba, br, br->br_perm);
24849 + if (unlikely(err))
24850 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
24852 + /* go on even if err */
24854 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
24856 + di_write_unlock(root);
24857 + err = au_refresh_d(sb);
24858 + e = au_refresh_i(sb);
24859 + if (unlikely(e && !err))
24861 + /* aufs_write_lock() calls ..._child() */
24862 + di_write_lock_child(root);
24864 + au_cpup_attr_all(inode, /*force*/1);
24866 + if (unlikely(err))
24867 + AuIOErr("refresh failed, ignored, %d\n", err);
24870 +/* stop extra interpretation of errno in mount(8), and strange error messages */
24871 +static int cvt_err(int err)
24885 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
24888 + unsigned int mntflags;
24889 + struct au_opts opts;
24890 + struct dentry *root;
24891 + struct inode *inode;
24892 + struct au_sbinfo *sbinfo;
24895 + root = sb->s_root;
24896 + if (!data || !*data) {
24897 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
24899 + di_write_lock_child(root);
24900 + err = au_opts_verify(sb, *flags, /*pending*/0);
24901 + aufs_write_unlock(root);
24907 + memset(&opts, 0, sizeof(opts));
24908 + opts.opt = (void *)__get_free_page(GFP_NOFS);
24909 + if (unlikely(!opts.opt))
24911 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
24912 + opts.flags = AuOpts_REMOUNT;
24913 + opts.sb_flags = *flags;
24915 + /* parse it before aufs lock */
24916 + err = au_opts_parse(sb, data, &opts);
24917 + if (unlikely(err))
24920 + sbinfo = au_sbi(sb);
24921 + inode = root->d_inode;
24922 + mutex_lock(&inode->i_mutex);
24923 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
24924 + if (unlikely(err))
24926 + di_write_lock_child(root);
24928 + /* au_opts_remount() may return an error */
24929 + err = au_opts_remount(sb, &opts);
24930 + au_opts_free(&opts);
24932 + if (au_ftest_opts(opts.flags, REFRESH))
24933 + au_remount_refresh(sb);
24935 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
24936 + mntflags = au_mntflags(sb);
24937 + do_dx = !!au_opt_test(mntflags, DIO);
24938 + au_dy_arefresh(do_dx);
24941 + aufs_write_unlock(root);
24944 + mutex_unlock(&inode->i_mutex);
24946 + free_page((unsigned long)opts.opt);
24948 + err = cvt_err(err);
24953 +static const struct super_operations aufs_sop = {
24954 + .alloc_inode = aufs_alloc_inode,
24955 + .destroy_inode = aufs_destroy_inode,
24956 + /* always deleting, no clearing */
24957 + .drop_inode = generic_delete_inode,
24958 + .show_options = aufs_show_options,
24959 + .statfs = aufs_statfs,
24960 + .put_super = aufs_put_super,
24961 + .sync_fs = aufs_sync_fs,
24962 + .remount_fs = aufs_remount_fs
24965 +/* ---------------------------------------------------------------------- */
24967 +static int alloc_root(struct super_block *sb)
24970 + struct inode *inode;
24971 + struct dentry *root;
24974 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
24975 + err = PTR_ERR(inode);
24976 + if (IS_ERR(inode))
24979 + inode->i_op = &aufs_dir_iop;
24980 + inode->i_fop = &aufs_dir_fop;
24981 + inode->i_mode = S_IFDIR;
24982 + set_nlink(inode, 2);
24983 + unlock_new_inode(inode);
24985 + root = d_make_root(inode);
24986 + if (unlikely(!root))
24988 + err = PTR_ERR(root);
24989 + if (IS_ERR(root))
24992 + err = au_di_init(root);
24994 + sb->s_root = root;
24995 + return 0; /* success */
25003 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
25004 + int silent __maybe_unused)
25007 + struct au_opts opts;
25008 + struct dentry *root;
25009 + struct inode *inode;
25010 + char *arg = raw_data;
25012 + if (unlikely(!arg || !*arg)) {
25014 + pr_err("no arg\n");
25019 + memset(&opts, 0, sizeof(opts));
25020 + opts.opt = (void *)__get_free_page(GFP_NOFS);
25021 + if (unlikely(!opts.opt))
25023 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
25024 + opts.sb_flags = sb->s_flags;
25026 + err = au_si_alloc(sb);
25027 + if (unlikely(err))
25030 + /* all timestamps always follow the ones on the branch */
25031 + sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
25032 + sb->s_op = &aufs_sop;
25033 + sb->s_d_op = &aufs_dop;
25034 + sb->s_magic = AUFS_SUPER_MAGIC;
25035 + sb->s_maxbytes = 0;
25036 + au_export_init(sb);
25038 + err = alloc_root(sb);
25039 + if (unlikely(err)) {
25040 + si_write_unlock(sb);
25043 + root = sb->s_root;
25044 + inode = root->d_inode;
25047 + * actually we can parse options regardless aufs lock here.
25048 + * but at remount time, parsing must be done before aufs lock.
25049 + * so we follow the same rule.
25051 + ii_write_lock_parent(inode);
25052 + aufs_write_unlock(root);
25053 + err = au_opts_parse(sb, arg, &opts);
25054 + if (unlikely(err))
25057 + /* lock vfs_inode first, then aufs. */
25058 + mutex_lock(&inode->i_mutex);
25059 + aufs_write_lock(root);
25060 + err = au_opts_mount(sb, &opts);
25061 + au_opts_free(&opts);
25062 + aufs_write_unlock(root);
25063 + mutex_unlock(&inode->i_mutex);
25065 + goto out_opts; /* success */
25069 + sb->s_root = NULL;
25071 + dbgaufs_si_fin(au_sbi(sb));
25072 + kobject_put(&au_sbi(sb)->si_kobj);
25073 + sb->s_fs_info = NULL;
25075 + free_page((unsigned long)opts.opt);
25078 + err = cvt_err(err);
25083 +/* ---------------------------------------------------------------------- */
25085 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
25086 + const char *dev_name __maybe_unused,
25089 + struct dentry *root;
25090 + struct super_block *sb;
25092 + /* all timestamps always follow the ones on the branch */
25093 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
25094 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
25095 + if (IS_ERR(root))
25099 + si_write_lock(sb, !AuLock_FLUSH);
25100 + sysaufs_brs_add(sb, 0);
25101 + si_write_unlock(sb);
25102 + au_sbilist_add(sb);
25108 +static void aufs_kill_sb(struct super_block *sb)
25110 + struct au_sbinfo *sbinfo;
25112 + sbinfo = au_sbi(sb);
25114 + au_sbilist_del(sb);
25115 + aufs_write_lock(sb->s_root);
25116 + if (sbinfo->si_wbr_create_ops->fin)
25117 + sbinfo->si_wbr_create_ops->fin(sb);
25118 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
25119 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
25120 + au_remount_refresh(sb);
25122 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
25123 + au_plink_put(sb, /*verbose*/1);
25125 + sbinfo->si_sb = NULL;
25126 + aufs_write_unlock(sb->s_root);
25127 + au_nwt_flush(&sbinfo->si_nowait);
25129 + generic_shutdown_super(sb);
25132 +struct file_system_type aufs_fs_type = {
25133 + .name = AUFS_FSTYPE,
25134 + /* a race between rename and others */
25135 + .fs_flags = FS_RENAME_DOES_D_MOVE,
25136 + .mount = aufs_mount,
25137 + .kill_sb = aufs_kill_sb,
25138 + /* no need to __module_get() and module_put(). */
25139 + .owner = THIS_MODULE,
25141 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
25142 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
25143 +++ linux/fs/aufs/super.h 2013-08-23 23:59:39.638250372 +0200
25146 + * Copyright (C) 2005-2013 Junjiro R. Okajima
25148 + * This program, aufs is free software; you can redistribute it and/or modify
25149 + * it under the terms of the GNU General Public License as published by
25150 + * the Free Software Foundation; either version 2 of the License, or
25151 + * (at your option) any later version.
25153 + * This program is distributed in the hope that it will be useful,
25154 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25155 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25156 + * GNU General Public License for more details.
25158 + * You should have received a copy of the GNU General Public License
25159 + * along with this program; if not, write to the Free Software
25160 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25164 + * super_block operations
25167 +#ifndef __AUFS_SUPER_H__
25168 +#define __AUFS_SUPER_H__
25172 +#include <linux/fs.h>
25173 +#include "rwsem.h"
25177 +typedef ssize_t (*au_readf_t)(struct file *, char __user *, size_t, loff_t *);
25178 +typedef ssize_t (*au_writef_t)(struct file *, const char __user *, size_t,
25181 +/* policies to select one among multiple writable branches */
25182 +struct au_wbr_copyup_operations {
25183 + int (*copyup)(struct dentry *dentry);
25186 +struct au_wbr_create_operations {
25187 + int (*create)(struct dentry *dentry, int isdir);
25188 + int (*init)(struct super_block *sb);
25189 + int (*fin)(struct super_block *sb);
25192 +struct au_wbr_mfs {
25193 + struct mutex mfs_lock; /* protect this structure */
25194 + unsigned long mfs_jiffy;
25195 + unsigned long mfs_expire;
25196 + aufs_bindex_t mfs_bindex;
25198 + unsigned long long mfsrr_bytes;
25199 + unsigned long long mfsrr_watermark;
25202 +struct pseudo_link {
25204 + struct hlist_node hlist;
25205 + struct rcu_head rcu;
25207 + struct inode *inode;
25210 +#define AuPlink_NHASH 100
25211 +static inline int au_plink_hash(ino_t ino)
25213 + return ino % AuPlink_NHASH;
25217 +struct au_sbinfo {
25218 + /* nowait tasks in the system-wide workqueue */
25219 + struct au_nowait_tasks si_nowait;
25222 + * tried sb->s_umount, but failed due to the dependecy between i_mutex.
25223 + * rwsem for au_sbinfo is necessary.
25225 + struct au_rwsem si_rwsem;
25227 + /* prevent recursive locking in deleting inode */
25229 + unsigned long *bitmap;
25230 + spinlock_t tree_lock;
25231 + struct radix_tree_root tree;
25235 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
25238 + atomic_long_t si_ninodes, si_nfiles;
25240 + /* branch management */
25241 + unsigned int si_generation;
25243 + /* see above flags */
25244 + unsigned char au_si_status;
25246 + aufs_bindex_t si_bend;
25248 + /* dirty trick to keep br_id plus */
25249 + unsigned int si_last_br_id :
25250 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
25251 + struct au_branch **si_branch;
25253 + /* policy to select a writable branch */
25254 + unsigned char si_wbr_copyup;
25255 + unsigned char si_wbr_create;
25256 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
25257 + struct au_wbr_create_operations *si_wbr_create_ops;
25259 + /* round robin */
25260 + atomic_t si_wbr_rr_next;
25262 + /* most free space */
25263 + struct au_wbr_mfs si_wbr_mfs;
25265 + /* mount flags */
25266 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
25267 + unsigned int si_mntflags;
25269 + /* external inode number (bitmap and translation table) */
25270 + au_readf_t si_xread;
25271 + au_writef_t si_xwrite;
25272 + struct file *si_xib;
25273 + struct mutex si_xib_mtx; /* protect xib members */
25274 + unsigned long *si_xib_buf;
25275 + unsigned long si_xib_last_pindex;
25276 + int si_xib_next_bit;
25277 + aufs_bindex_t si_xino_brid;
25278 + /* reserved for future use */
25279 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
25281 +#ifdef CONFIG_AUFS_EXPORT
25282 + /* i_generation */
25283 + struct file *si_xigen;
25284 + atomic_t si_xigen_next;
25287 + /* vdir parameters */
25288 + unsigned long si_rdcache; /* max cache time in jiffies */
25289 + unsigned int si_rdblk; /* deblk size */
25290 + unsigned int si_rdhash; /* hash size */
25293 + * If the number of whiteouts are larger than si_dirwh, leave all of
25294 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
25295 + * future fsck.aufs or kernel thread will remove them later.
25296 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
25298 + unsigned int si_dirwh;
25301 + * rename(2) a directory with all children.
25303 + /* reserved for future use */
25304 + /* int si_rendir; */
25306 + /* pseudo_link list */
25307 + struct au_sphlhead si_plink[AuPlink_NHASH];
25308 + wait_queue_head_t si_plink_wq;
25309 + spinlock_t si_plink_maint_lock;
25310 + pid_t si_plink_maint_pid;
25313 + struct au_sphlhead si_files;
25316 + * sysfs and lifetime management.
25317 + * this is not a small structure and it may be a waste of memory in case
25318 + * of sysfs is disabled, particulary when many aufs-es are mounted.
25319 + * but using sysfs is majority.
25321 + struct kobject si_kobj;
25322 +#ifdef CONFIG_DEBUG_FS
25323 + struct dentry *si_dbgaufs;
25324 + struct dentry *si_dbgaufs_plink;
25325 + struct dentry *si_dbgaufs_xib;
25326 +#ifdef CONFIG_AUFS_EXPORT
25327 + struct dentry *si_dbgaufs_xigen;
25331 +#ifdef CONFIG_AUFS_SBILIST
25332 + struct list_head si_list;
25335 + /* dirty, necessary for unmounting, sysfs and sysrq */
25336 + struct super_block *si_sb;
25339 +/* sbinfo status flags */
25341 + * set true when refresh_dirs() failed at remount time.
25342 + * then try refreshing dirs at access time again.
25343 + * if it is false, refreshing dirs at access time is unnecesary
25345 +#define AuSi_FAILED_REFRESH_DIR 1
25346 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
25347 + unsigned int flag)
25349 + AuRwMustAnyLock(&sbi->si_rwsem);
25350 + return sbi->au_si_status & flag;
25352 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
25353 +#define au_fset_si(sbinfo, name) do { \
25354 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
25355 + (sbinfo)->au_si_status |= AuSi_##name; \
25357 +#define au_fclr_si(sbinfo, name) do { \
25358 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
25359 + (sbinfo)->au_si_status &= ~AuSi_##name; \
25362 +/* ---------------------------------------------------------------------- */
25364 +/* policy to select one among writable branches */
25365 +#define AuWbrCopyup(sbinfo, ...) \
25366 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
25367 +#define AuWbrCreate(sbinfo, ...) \
25368 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
25370 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
25371 +#define AuLock_DW 1 /* write-lock dentry */
25372 +#define AuLock_IR (1 << 1) /* read-lock inode */
25373 +#define AuLock_IW (1 << 2) /* write-lock inode */
25374 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
25375 +#define AuLock_DIR (1 << 4) /* target is a dir */
25376 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
25377 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
25378 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
25379 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
25380 +#define au_fset_lock(flags, name) \
25381 + do { (flags) |= AuLock_##name; } while (0)
25382 +#define au_fclr_lock(flags, name) \
25383 + do { (flags) &= ~AuLock_##name; } while (0)
25385 +/* ---------------------------------------------------------------------- */
25388 +extern struct file_system_type aufs_fs_type;
25389 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
25390 +typedef unsigned long long (*au_arraycb_t)(void *array, unsigned long long max,
25392 +void au_array_free(void *array);
25393 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg);
25394 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
25395 +void au_iarray_free(struct inode **a, unsigned long long max);
25398 +void au_si_free(struct kobject *kobj);
25399 +int au_si_alloc(struct super_block *sb);
25400 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr);
25402 +unsigned int au_sigen_inc(struct super_block *sb);
25403 +aufs_bindex_t au_new_br_id(struct super_block *sb);
25405 +int si_read_lock(struct super_block *sb, int flags);
25406 +int si_write_lock(struct super_block *sb, int flags);
25407 +int aufs_read_lock(struct dentry *dentry, int flags);
25408 +void aufs_read_unlock(struct dentry *dentry, int flags);
25409 +void aufs_write_lock(struct dentry *dentry);
25410 +void aufs_write_unlock(struct dentry *dentry);
25411 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
25412 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
25414 +int si_pid_test_slow(struct super_block *sb);
25415 +void si_pid_set_slow(struct super_block *sb);
25416 +void si_pid_clr_slow(struct super_block *sb);
25418 +/* wbr_policy.c */
25419 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
25420 +extern struct au_wbr_create_operations au_wbr_create_ops[];
25421 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
25422 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
25425 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
25427 +/* ---------------------------------------------------------------------- */
25429 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
25431 + return sb->s_fs_info;
25434 +/* ---------------------------------------------------------------------- */
25436 +#ifdef CONFIG_AUFS_EXPORT
25437 +int au_test_nfsd(void);
25438 +void au_export_init(struct super_block *sb);
25439 +void au_xigen_inc(struct inode *inode);
25440 +int au_xigen_new(struct inode *inode);
25441 +int au_xigen_set(struct super_block *sb, struct file *base);
25442 +void au_xigen_clr(struct super_block *sb);
25444 +static inline int au_busy_or_stale(void)
25446 + if (!au_test_nfsd())
25451 +AuStubInt0(au_test_nfsd, void)
25452 +AuStubVoid(au_export_init, struct super_block *sb)
25453 +AuStubVoid(au_xigen_inc, struct inode *inode)
25454 +AuStubInt0(au_xigen_new, struct inode *inode)
25455 +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base)
25456 +AuStubVoid(au_xigen_clr, struct super_block *sb)
25457 +static inline int au_busy_or_stale(void)
25461 +#endif /* CONFIG_AUFS_EXPORT */
25463 +/* ---------------------------------------------------------------------- */
25465 +#ifdef CONFIG_AUFS_SBILIST
25467 +extern struct au_splhead au_sbilist;
25469 +static inline void au_sbilist_init(void)
25471 + au_spl_init(&au_sbilist);
25474 +static inline void au_sbilist_add(struct super_block *sb)
25476 + au_spl_add(&au_sbi(sb)->si_list, &au_sbilist);
25479 +static inline void au_sbilist_del(struct super_block *sb)
25481 + au_spl_del(&au_sbi(sb)->si_list, &au_sbilist);
25484 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
25485 +static inline void au_sbilist_lock(void)
25487 + spin_lock(&au_sbilist.spin);
25490 +static inline void au_sbilist_unlock(void)
25492 + spin_unlock(&au_sbilist.spin);
25494 +#define AuGFP_SBILIST GFP_ATOMIC
25496 +AuStubVoid(au_sbilist_lock, void)
25497 +AuStubVoid(au_sbilist_unlock, void)
25498 +#define AuGFP_SBILIST GFP_NOFS
25499 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
25501 +AuStubVoid(au_sbilist_init, void)
25502 +AuStubVoid(au_sbilist_add, struct super_block*)
25503 +AuStubVoid(au_sbilist_del, struct super_block*)
25504 +AuStubVoid(au_sbilist_lock, void)
25505 +AuStubVoid(au_sbilist_unlock, void)
25506 +#define AuGFP_SBILIST GFP_NOFS
25509 +/* ---------------------------------------------------------------------- */
25511 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
25514 + * This function is a dynamic '__init' fucntion actually,
25515 + * so the tiny check for si_rwsem is unnecessary.
25517 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
25518 +#ifdef CONFIG_DEBUG_FS
25519 + sbinfo->si_dbgaufs = NULL;
25520 + sbinfo->si_dbgaufs_plink = NULL;
25521 + sbinfo->si_dbgaufs_xib = NULL;
25522 +#ifdef CONFIG_AUFS_EXPORT
25523 + sbinfo->si_dbgaufs_xigen = NULL;
25528 +/* ---------------------------------------------------------------------- */
25530 +static inline pid_t si_pid_bit(void)
25532 + /* the origin of pid is 1, but the bitmap's is 0 */
25533 + return current->pid - 1;
25536 +static inline int si_pid_test(struct super_block *sb)
25538 + pid_t bit = si_pid_bit();
25539 + if (bit < PID_MAX_DEFAULT)
25540 + return test_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
25542 + return si_pid_test_slow(sb);
25545 +static inline void si_pid_set(struct super_block *sb)
25547 + pid_t bit = si_pid_bit();
25548 + if (bit < PID_MAX_DEFAULT) {
25549 + AuDebugOn(test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
25550 + set_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
25553 + si_pid_set_slow(sb);
25556 +static inline void si_pid_clr(struct super_block *sb)
25558 + pid_t bit = si_pid_bit();
25559 + if (bit < PID_MAX_DEFAULT) {
25560 + AuDebugOn(!test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
25561 + clear_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
25564 + si_pid_clr_slow(sb);
25567 +/* ---------------------------------------------------------------------- */
25569 +/* lock superblock. mainly for entry point functions */
25571 + * __si_read_lock, __si_write_lock,
25572 + * __si_read_unlock, __si_write_unlock, __si_downgrade_lock
25574 +AuSimpleRwsemFuncs(__si, struct super_block *sb, &au_sbi(sb)->si_rwsem);
25576 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
25577 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
25578 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
25580 +static inline void si_noflush_read_lock(struct super_block *sb)
25582 + __si_read_lock(sb);
25586 +static inline int si_noflush_read_trylock(struct super_block *sb)
25588 + int locked = __si_read_trylock(sb);
25594 +static inline void si_noflush_write_lock(struct super_block *sb)
25596 + __si_write_lock(sb);
25600 +static inline int si_noflush_write_trylock(struct super_block *sb)
25602 + int locked = __si_write_trylock(sb);
25608 +#if 0 /* unused */
25609 +static inline int si_read_trylock(struct super_block *sb, int flags)
25611 + if (au_ftest_lock(flags, FLUSH))
25612 + au_nwt_flush(&au_sbi(sb)->si_nowait);
25613 + return si_noflush_read_trylock(sb);
25617 +static inline void si_read_unlock(struct super_block *sb)
25620 + __si_read_unlock(sb);
25623 +#if 0 /* unused */
25624 +static inline int si_write_trylock(struct super_block *sb, int flags)
25626 + if (au_ftest_lock(flags, FLUSH))
25627 + au_nwt_flush(&au_sbi(sb)->si_nowait);
25628 + return si_noflush_write_trylock(sb);
25632 +static inline void si_write_unlock(struct super_block *sb)
25635 + __si_write_unlock(sb);
25638 +#if 0 /* unused */
25639 +static inline void si_downgrade_lock(struct super_block *sb)
25641 + __si_downgrade_lock(sb);
25645 +/* ---------------------------------------------------------------------- */
25647 +static inline aufs_bindex_t au_sbend(struct super_block *sb)
25649 + SiMustAnyLock(sb);
25650 + return au_sbi(sb)->si_bend;
25653 +static inline unsigned int au_mntflags(struct super_block *sb)
25655 + SiMustAnyLock(sb);
25656 + return au_sbi(sb)->si_mntflags;
25659 +static inline unsigned int au_sigen(struct super_block *sb)
25661 + SiMustAnyLock(sb);
25662 + return au_sbi(sb)->si_generation;
25665 +static inline void au_ninodes_inc(struct super_block *sb)
25667 + atomic_long_inc(&au_sbi(sb)->si_ninodes);
25670 +static inline void au_ninodes_dec(struct super_block *sb)
25672 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_ninodes));
25673 + atomic_long_dec(&au_sbi(sb)->si_ninodes);
25676 +static inline void au_nfiles_inc(struct super_block *sb)
25678 + atomic_long_inc(&au_sbi(sb)->si_nfiles);
25681 +static inline void au_nfiles_dec(struct super_block *sb)
25683 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_nfiles));
25684 + atomic_long_dec(&au_sbi(sb)->si_nfiles);
25687 +static inline struct au_branch *au_sbr(struct super_block *sb,
25688 + aufs_bindex_t bindex)
25690 + SiMustAnyLock(sb);
25691 + return au_sbi(sb)->si_branch[0 + bindex];
25694 +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid)
25696 + SiMustWriteLock(sb);
25697 + au_sbi(sb)->si_xino_brid = brid;
25700 +static inline aufs_bindex_t au_xino_brid(struct super_block *sb)
25702 + SiMustAnyLock(sb);
25703 + return au_sbi(sb)->si_xino_brid;
25706 +#endif /* __KERNEL__ */
25707 +#endif /* __AUFS_SUPER_H__ */
25708 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
25709 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
25710 +++ linux/fs/aufs/sysaufs.c 2013-07-06 13:20:47.753531903 +0200
25713 + * Copyright (C) 2005-2013 Junjiro R. Okajima
25715 + * This program, aufs is free software; you can redistribute it and/or modify
25716 + * it under the terms of the GNU General Public License as published by
25717 + * the Free Software Foundation; either version 2 of the License, or
25718 + * (at your option) any later version.
25720 + * This program is distributed in the hope that it will be useful,
25721 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25722 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25723 + * GNU General Public License for more details.
25725 + * You should have received a copy of the GNU General Public License
25726 + * along with this program; if not, write to the Free Software
25727 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25731 + * sysfs interface and lifetime management
25732 + * they are necessary regardless sysfs is disabled.
25735 +#include <linux/random.h>
25738 +unsigned long sysaufs_si_mask;
25739 +struct kset *sysaufs_kset;
25741 +#define AuSiAttr(_name) { \
25742 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
25743 + .show = sysaufs_si_##_name, \
25746 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
25747 +struct attribute *sysaufs_si_attrs[] = {
25748 + &sysaufs_si_attr_xi_path.attr,
25752 +static const struct sysfs_ops au_sbi_ops = {
25753 + .show = sysaufs_si_show
25756 +static struct kobj_type au_sbi_ktype = {
25757 + .release = au_si_free,
25758 + .sysfs_ops = &au_sbi_ops,
25759 + .default_attrs = sysaufs_si_attrs
25762 +/* ---------------------------------------------------------------------- */
25764 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
25768 + sbinfo->si_kobj.kset = sysaufs_kset;
25769 + /* cf. sysaufs_name() */
25770 + err = kobject_init_and_add
25771 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
25772 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
25774 + dbgaufs_si_null(sbinfo);
25776 + err = dbgaufs_si_init(sbinfo);
25777 + if (unlikely(err))
25778 + kobject_put(&sbinfo->si_kobj);
25783 +void sysaufs_fin(void)
25786 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
25787 + kset_unregister(sysaufs_kset);
25790 +int __init sysaufs_init(void)
25795 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
25796 + } while (!sysaufs_si_mask);
25799 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
25800 + if (unlikely(!sysaufs_kset))
25802 + err = PTR_ERR(sysaufs_kset);
25803 + if (IS_ERR(sysaufs_kset))
25805 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
25806 + if (unlikely(err)) {
25807 + kset_unregister(sysaufs_kset);
25811 + err = dbgaufs_init();
25812 + if (unlikely(err))
25817 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
25818 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
25819 +++ linux/fs/aufs/sysaufs.h 2013-07-06 13:20:47.753531903 +0200
25822 + * Copyright (C) 2005-2013 Junjiro R. Okajima
25824 + * This program, aufs is free software; you can redistribute it and/or modify
25825 + * it under the terms of the GNU General Public License as published by
25826 + * the Free Software Foundation; either version 2 of the License, or
25827 + * (at your option) any later version.
25829 + * This program is distributed in the hope that it will be useful,
25830 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25831 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25832 + * GNU General Public License for more details.
25834 + * You should have received a copy of the GNU General Public License
25835 + * along with this program; if not, write to the Free Software
25836 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25840 + * sysfs interface and mount lifetime management
25843 +#ifndef __SYSAUFS_H__
25844 +#define __SYSAUFS_H__
25848 +#include <linux/sysfs.h>
25849 +#include "module.h"
25851 +struct super_block;
25854 +struct sysaufs_si_attr {
25855 + struct attribute attr;
25856 + int (*show)(struct seq_file *seq, struct super_block *sb);
25859 +/* ---------------------------------------------------------------------- */
25862 +extern unsigned long sysaufs_si_mask;
25863 +extern struct kset *sysaufs_kset;
25864 +extern struct attribute *sysaufs_si_attrs[];
25865 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
25866 +int __init sysaufs_init(void);
25867 +void sysaufs_fin(void);
25869 +/* ---------------------------------------------------------------------- */
25871 +/* some people doesn't like to show a pointer in kernel */
25872 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
25874 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
25877 +#define SysaufsSiNamePrefix "si_"
25878 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
25879 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
25881 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
25882 + sysaufs_si_id(sbinfo));
25886 +#ifdef CONFIG_SYSFS
25888 +extern struct attribute_group *sysaufs_attr_group;
25890 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
25891 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
25894 +void sysaufs_br_init(struct au_branch *br);
25895 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
25896 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
25898 +#define sysaufs_brs_init() do {} while (0)
25901 +#define sysaufs_attr_group NULL
25903 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
25906 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
25912 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
25913 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
25914 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
25916 +static inline void sysaufs_brs_init(void)
25921 +#endif /* CONFIG_SYSFS */
25923 +#endif /* __KERNEL__ */
25924 +#endif /* __SYSAUFS_H__ */
25925 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
25926 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
25927 +++ linux/fs/aufs/sysfs.c 2013-07-06 13:20:47.753531903 +0200
25930 + * Copyright (C) 2005-2013 Junjiro R. Okajima
25932 + * This program, aufs is free software; you can redistribute it and/or modify
25933 + * it under the terms of the GNU General Public License as published by
25934 + * the Free Software Foundation; either version 2 of the License, or
25935 + * (at your option) any later version.
25937 + * This program is distributed in the hope that it will be useful,
25938 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25939 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25940 + * GNU General Public License for more details.
25942 + * You should have received a copy of the GNU General Public License
25943 + * along with this program; if not, write to the Free Software
25944 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25948 + * sysfs interface
25951 +#include <linux/seq_file.h>
25954 +#ifdef CONFIG_AUFS_FS_MODULE
25955 +/* this entry violates the "one line per file" policy of sysfs */
25956 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
25960 + static char *conf =
25961 +/* this file is generated at compiling */
25962 +#include "conf.str"
25965 + err = snprintf(buf, PAGE_SIZE, conf);
25966 + if (unlikely(err >= PAGE_SIZE))
25971 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
25974 +static struct attribute *au_attr[] = {
25975 +#ifdef CONFIG_AUFS_FS_MODULE
25976 + &au_config_attr.attr,
25978 + NULL, /* need to NULL terminate the list of attributes */
25981 +static struct attribute_group sysaufs_attr_group_body = {
25985 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
25987 +/* ---------------------------------------------------------------------- */
25989 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
25993 + SiMustAnyLock(sb);
25996 + if (au_opt_test(au_mntflags(sb), XINO)) {
25997 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
25998 + seq_putc(seq, '\n');
26004 + * the lifetime of branch is independent from the entry under sysfs.
26005 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
26008 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
26009 + aufs_bindex_t bindex)
26012 + struct path path;
26013 + struct dentry *root;
26014 + struct au_branch *br;
26017 + AuDbg("b%d\n", bindex);
26020 + root = sb->s_root;
26021 + di_read_lock_parent(root, !AuLock_IR);
26022 + br = au_sbr(sb, bindex);
26023 + path.mnt = au_br_mnt(br);
26024 + path.dentry = au_h_dptr(root, bindex);
26025 + au_seq_path(seq, &path);
26026 + di_read_unlock(root, !AuLock_IR);
26027 + perm = au_optstr_br_perm(br->br_perm);
26029 + err = seq_printf(seq, "=%s\n", perm);
26038 +/* ---------------------------------------------------------------------- */
26040 +static struct seq_file *au_seq(char *p, ssize_t len)
26042 + struct seq_file *seq;
26044 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
26046 + /* mutex_init(&seq.lock); */
26049 + return seq; /* success */
26052 + seq = ERR_PTR(-ENOMEM);
26056 +#define SysaufsBr_PREFIX "br"
26058 +/* todo: file size may exceed PAGE_SIZE */
26059 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
26064 + aufs_bindex_t bend;
26065 + struct au_sbinfo *sbinfo;
26066 + struct super_block *sb;
26067 + struct seq_file *seq;
26069 + struct attribute **cattr;
26071 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
26072 + sb = sbinfo->si_sb;
26075 + * prevent a race condition between sysfs and aufs.
26076 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
26077 + * prohibits maintaining the sysfs entries.
26078 + * hew we acquire read lock after sysfs_get_active_two().
26079 + * on the other hand, the remount process may maintain the sysfs/aufs
26080 + * entries after acquiring write lock.
26081 + * it can cause a deadlock.
26082 + * simply we gave up processing read here.
26085 + if (unlikely(!si_noflush_read_trylock(sb)))
26088 + seq = au_seq(buf, PAGE_SIZE);
26089 + err = PTR_ERR(seq);
26093 + name = (void *)attr->name;
26094 + cattr = sysaufs_si_attrs;
26096 + if (!strcmp(name, (*cattr)->name)) {
26097 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
26104 + bend = au_sbend(sb);
26105 + if (!strncmp(name, SysaufsBr_PREFIX, sizeof(SysaufsBr_PREFIX) - 1)) {
26106 + name += sizeof(SysaufsBr_PREFIX) - 1;
26107 + err = kstrtol(name, 10, &l);
26110 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l);
26120 + err = seq->count;
26121 + /* sysfs limit */
26122 + if (unlikely(err == PAGE_SIZE))
26127 + si_read_unlock(sb);
26132 +/* ---------------------------------------------------------------------- */
26134 +void sysaufs_br_init(struct au_branch *br)
26136 + struct attribute *attr = &br->br_attr;
26138 + sysfs_attr_init(attr);
26139 + attr->name = br->br_name;
26140 + attr->mode = S_IRUGO;
26143 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
26145 + struct au_branch *br;
26146 + struct kobject *kobj;
26147 + aufs_bindex_t bend;
26149 + dbgaufs_brs_del(sb, bindex);
26151 + if (!sysaufs_brs)
26154 + kobj = &au_sbi(sb)->si_kobj;
26155 + bend = au_sbend(sb);
26156 + for (; bindex <= bend; bindex++) {
26157 + br = au_sbr(sb, bindex);
26158 + sysfs_remove_file(kobj, &br->br_attr);
26162 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
26165 + aufs_bindex_t bend;
26166 + struct kobject *kobj;
26167 + struct au_branch *br;
26169 + dbgaufs_brs_add(sb, bindex);
26171 + if (!sysaufs_brs)
26174 + kobj = &au_sbi(sb)->si_kobj;
26175 + bend = au_sbend(sb);
26176 + for (; bindex <= bend; bindex++) {
26177 + br = au_sbr(sb, bindex);
26178 + snprintf(br->br_name, sizeof(br->br_name), SysaufsBr_PREFIX
26180 + err = sysfs_create_file(kobj, &br->br_attr);
26181 + if (unlikely(err))
26182 + pr_warn("failed %s under sysfs(%d)\n",
26183 + br->br_name, err);
26186 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
26187 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
26188 +++ linux/fs/aufs/sysrq.c 2013-07-06 13:20:47.753531903 +0200
26191 + * Copyright (C) 2005-2013 Junjiro R. Okajima
26193 + * This program, aufs is free software; you can redistribute it and/or modify
26194 + * it under the terms of the GNU General Public License as published by
26195 + * the Free Software Foundation; either version 2 of the License, or
26196 + * (at your option) any later version.
26198 + * This program is distributed in the hope that it will be useful,
26199 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26200 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26201 + * GNU General Public License for more details.
26203 + * You should have received a copy of the GNU General Public License
26204 + * along with this program; if not, write to the Free Software
26205 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26209 + * magic sysrq hanlder
26212 +/* #include <linux/sysrq.h> */
26213 +#include <linux/writeback.h>
26216 +/* ---------------------------------------------------------------------- */
26218 +static void sysrq_sb(struct super_block *sb)
26221 + struct au_sbinfo *sbinfo;
26222 + struct file *file;
26223 + struct au_sphlhead *files;
26224 + struct au_finfo *finfo;
26226 + plevel = au_plevel;
26227 + au_plevel = KERN_WARNING;
26229 + /* since we define pr_fmt, call printk directly */
26230 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
26232 + sbinfo = au_sbi(sb);
26233 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
26234 + pr("superblock\n");
26238 + pr("root dentry\n");
26239 + au_dpri_dentry(sb->s_root);
26240 + pr("root inode\n");
26241 + au_dpri_inode(sb->s_root->d_inode);
26246 + int err, i, j, ndentry;
26247 + struct au_dcsub_pages dpages;
26248 + struct au_dpage *dpage;
26250 + err = au_dpages_init(&dpages, GFP_ATOMIC);
26251 + if (unlikely(err))
26253 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
26255 + for (i = 0; i < dpages.ndpage; i++) {
26256 + dpage = dpages.dpages + i;
26257 + ndentry = dpage->ndentry;
26258 + for (j = 0; j < ndentry; j++)
26259 + au_dpri_dentry(dpage->dentries[j]);
26261 + au_dpages_free(&dpages);
26268 + pr("isolated inode\n");
26269 + spin_lock(&inode_sb_list_lock);
26270 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
26271 + spin_lock(&i->i_lock);
26272 + if (1 || hlist_empty(&i->i_dentry))
26273 + au_dpri_inode(i);
26274 + spin_unlock(&i->i_lock);
26276 + spin_unlock(&inode_sb_list_lock);
26280 + files = &au_sbi(sb)->si_files;
26281 + spin_lock(&files->spin);
26282 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
26284 + file = finfo->fi_file;
26285 + mode = file_inode(file)->i_mode;
26286 + if (!special_file(mode) || au_special_file(mode))
26287 + au_dpri_file(file);
26289 + spin_unlock(&files->spin);
26293 + au_plevel = plevel;
26296 +/* ---------------------------------------------------------------------- */
26298 +/* module parameter */
26299 +static char *aufs_sysrq_key = "a";
26300 +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO);
26301 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
26303 +static void au_sysrq(int key __maybe_unused)
26305 + struct au_sbinfo *sbinfo;
26308 + au_sbilist_lock();
26309 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
26310 + sysrq_sb(sbinfo->si_sb);
26311 + au_sbilist_unlock();
26315 +static struct sysrq_key_op au_sysrq_op = {
26316 + .handler = au_sysrq,
26317 + .help_msg = "Aufs",
26318 + .action_msg = "Aufs",
26319 + .enable_mask = SYSRQ_ENABLE_DUMP
26322 +/* ---------------------------------------------------------------------- */
26324 +int __init au_sysrq_init(void)
26330 + key = *aufs_sysrq_key;
26331 + if ('a' <= key && key <= 'z')
26332 + err = register_sysrq_key(key, &au_sysrq_op);
26333 + if (unlikely(err))
26334 + pr_err("err %d, sysrq=%c\n", err, key);
26338 +void au_sysrq_fin(void)
26341 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
26342 + if (unlikely(err))
26343 + pr_err("err %d (ignored)\n", err);
26345 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
26346 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
26347 +++ linux/fs/aufs/vdir.c 2013-07-30 22:42:55.842946719 +0200
26350 + * Copyright (C) 2005-2013 Junjiro R. Okajima
26352 + * This program, aufs is free software; you can redistribute it and/or modify
26353 + * it under the terms of the GNU General Public License as published by
26354 + * the Free Software Foundation; either version 2 of the License, or
26355 + * (at your option) any later version.
26357 + * This program is distributed in the hope that it will be useful,
26358 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26359 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26360 + * GNU General Public License for more details.
26362 + * You should have received a copy of the GNU General Public License
26363 + * along with this program; if not, write to the Free Software
26364 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26368 + * virtual or vertical directory
26373 +static unsigned int calc_size(int nlen)
26375 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
26378 +static int set_deblk_end(union au_vdir_deblk_p *p,
26379 + union au_vdir_deblk_p *deblk_end)
26381 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
26382 + p->de->de_str.len = 0;
26386 + return -1; /* error */
26389 +/* returns true or false */
26390 +static int is_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 + return !p->de->de_str.len;
26398 +static unsigned char *last_deblk(struct au_vdir *vdir)
26400 + return vdir->vd_deblk[vdir->vd_nblk - 1];
26403 +/* ---------------------------------------------------------------------- */
26405 +/* estimate the apropriate size for name hash table */
26406 +unsigned int au_rdhash_est(loff_t sz)
26414 + if (sz < AUFS_RDHASH_DEF)
26415 + n = AUFS_RDHASH_DEF;
26416 + /* pr_info("n %u\n", n); */
26421 + * the allocated memory has to be freed by
26422 + * au_nhash_wh_free() or au_nhash_de_free().
26424 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
26426 + struct hlist_head *head;
26429 + head = kmalloc(sizeof(*nhash->nh_head) * num_hash, gfp);
26431 + nhash->nh_num = num_hash;
26432 + nhash->nh_head = head;
26433 + for (u = 0; u < num_hash; u++)
26434 + INIT_HLIST_HEAD(head++);
26435 + return 0; /* success */
26441 +static void nhash_count(struct hlist_head *head)
26445 + struct hlist_node *pos;
26448 + hlist_for_each(pos, head)
26450 + pr_info("%lu\n", n);
26454 +static void au_nhash_wh_do_free(struct hlist_head *head)
26456 + struct au_vdir_wh *pos;
26457 + struct hlist_node *node;
26459 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
26463 +static void au_nhash_de_do_free(struct hlist_head *head)
26465 + struct au_vdir_dehstr *pos;
26466 + struct hlist_node *node;
26468 + hlist_for_each_entry_safe(pos, node, head, hash)
26469 + au_cache_free_vdir_dehstr(pos);
26472 +static void au_nhash_do_free(struct au_nhash *nhash,
26473 + void (*free)(struct hlist_head *head))
26476 + struct hlist_head *head;
26478 + n = nhash->nh_num;
26482 + head = nhash->nh_head;
26483 + while (n-- > 0) {
26484 + nhash_count(head);
26487 + kfree(nhash->nh_head);
26490 +void au_nhash_wh_free(struct au_nhash *whlist)
26492 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
26495 +static void au_nhash_de_free(struct au_nhash *delist)
26497 + au_nhash_do_free(delist, au_nhash_de_do_free);
26500 +/* ---------------------------------------------------------------------- */
26502 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
26506 + unsigned int u, n;
26507 + struct hlist_head *head;
26508 + struct au_vdir_wh *pos;
26511 + n = whlist->nh_num;
26512 + head = whlist->nh_head;
26513 + for (u = 0; u < n; u++, head++)
26514 + hlist_for_each_entry(pos, head, wh_hash)
26515 + if (pos->wh_bindex == btgt && ++num > limit)
26520 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
26521 + unsigned char *name,
26522 + unsigned int len)
26525 + /* const unsigned int magic_bit = 12; */
26527 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
26532 + /* v = hash_long(v, magic_bit); */
26533 + v %= nhash->nh_num;
26534 + return nhash->nh_head + v;
26537 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
26540 + return str->len == nlen && !memcmp(str->name, name, nlen);
26543 +/* returns found or not */
26544 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
26546 + struct hlist_head *head;
26547 + struct au_vdir_wh *pos;
26548 + struct au_vdir_destr *str;
26550 + head = au_name_hash(whlist, name, nlen);
26551 + hlist_for_each_entry(pos, head, wh_hash) {
26552 + str = &pos->wh_str;
26553 + AuDbg("%.*s\n", str->len, str->name);
26554 + if (au_nhash_test_name(str, name, nlen))
26560 +/* returns found(true) or not */
26561 +static int test_known(struct au_nhash *delist, char *name, int nlen)
26563 + struct hlist_head *head;
26564 + struct au_vdir_dehstr *pos;
26565 + struct au_vdir_destr *str;
26567 + head = au_name_hash(delist, name, nlen);
26568 + hlist_for_each_entry(pos, head, hash) {
26570 + AuDbg("%.*s\n", str->len, str->name);
26571 + if (au_nhash_test_name(str, name, nlen))
26577 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
26578 + unsigned char d_type)
26580 +#ifdef CONFIG_AUFS_SHWH
26581 + wh->wh_ino = ino;
26582 + wh->wh_type = d_type;
26586 +/* ---------------------------------------------------------------------- */
26588 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
26589 + unsigned int d_type, aufs_bindex_t bindex,
26590 + unsigned char shwh)
26593 + struct au_vdir_destr *str;
26594 + struct au_vdir_wh *wh;
26596 + AuDbg("%.*s\n", nlen, name);
26597 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
26600 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
26601 + if (unlikely(!wh))
26605 + wh->wh_bindex = bindex;
26607 + au_shwh_init_wh(wh, ino, d_type);
26608 + str = &wh->wh_str;
26610 + memcpy(str->name, name, nlen);
26611 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
26618 +static int append_deblk(struct au_vdir *vdir)
26621 + unsigned long ul;
26622 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
26623 + union au_vdir_deblk_p p, deblk_end;
26624 + unsigned char **o;
26627 + o = krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
26629 + if (unlikely(!o))
26632 + vdir->vd_deblk = o;
26633 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
26635 + ul = vdir->vd_nblk++;
26636 + vdir->vd_deblk[ul] = p.deblk;
26637 + vdir->vd_last.ul = ul;
26638 + vdir->vd_last.p.deblk = p.deblk;
26639 + deblk_end.deblk = p.deblk + deblk_sz;
26640 + err = set_deblk_end(&p, &deblk_end);
26647 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
26648 + unsigned int d_type, struct au_nhash *delist)
26652 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
26653 + union au_vdir_deblk_p p, *room, deblk_end;
26654 + struct au_vdir_dehstr *dehstr;
26656 + p.deblk = last_deblk(vdir);
26657 + deblk_end.deblk = p.deblk + deblk_sz;
26658 + room = &vdir->vd_last.p;
26659 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
26660 + || !is_deblk_end(room, &deblk_end));
26662 + sz = calc_size(nlen);
26663 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
26664 + err = append_deblk(vdir);
26665 + if (unlikely(err))
26668 + p.deblk = last_deblk(vdir);
26669 + deblk_end.deblk = p.deblk + deblk_sz;
26671 + AuDebugOn(room->deblk != p.deblk);
26675 + dehstr = au_cache_alloc_vdir_dehstr();
26676 + if (unlikely(!dehstr))
26679 + dehstr->str = &room->de->de_str;
26680 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
26681 + room->de->de_ino = ino;
26682 + room->de->de_type = d_type;
26683 + room->de->de_str.len = nlen;
26684 + memcpy(room->de->de_str.name, name, nlen);
26687 + room->deblk += sz;
26688 + if (unlikely(set_deblk_end(room, &deblk_end)))
26689 + err = append_deblk(vdir);
26696 +/* ---------------------------------------------------------------------- */
26698 +void au_vdir_free(struct au_vdir *vdir)
26700 + unsigned char **deblk;
26702 + deblk = vdir->vd_deblk;
26703 + while (vdir->vd_nblk--)
26705 + kfree(vdir->vd_deblk);
26706 + au_cache_free_vdir(vdir);
26709 +static struct au_vdir *alloc_vdir(struct file *file)
26711 + struct au_vdir *vdir;
26712 + struct super_block *sb;
26715 + sb = file->f_dentry->d_sb;
26716 + SiMustAnyLock(sb);
26719 + vdir = au_cache_alloc_vdir();
26720 + if (unlikely(!vdir))
26723 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
26724 + if (unlikely(!vdir->vd_deblk))
26727 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
26728 + if (!vdir->vd_deblk_sz) {
26729 + /* estimate the apropriate size for deblk */
26730 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
26731 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
26733 + vdir->vd_nblk = 0;
26734 + vdir->vd_version = 0;
26735 + vdir->vd_jiffy = 0;
26736 + err = append_deblk(vdir);
26738 + return vdir; /* success */
26740 + kfree(vdir->vd_deblk);
26743 + au_cache_free_vdir(vdir);
26745 + vdir = ERR_PTR(err);
26749 +static int reinit_vdir(struct au_vdir *vdir)
26752 + union au_vdir_deblk_p p, deblk_end;
26754 + while (vdir->vd_nblk > 1) {
26755 + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
26756 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
26759 + p.deblk = vdir->vd_deblk[0];
26760 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
26761 + err = set_deblk_end(&p, &deblk_end);
26762 + /* keep vd_dblk_sz */
26763 + vdir->vd_last.ul = 0;
26764 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
26765 + vdir->vd_version = 0;
26766 + vdir->vd_jiffy = 0;
26771 +/* ---------------------------------------------------------------------- */
26773 +#define AuFillVdir_CALLED 1
26774 +#define AuFillVdir_WHABLE (1 << 1)
26775 +#define AuFillVdir_SHWH (1 << 2)
26776 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
26777 +#define au_fset_fillvdir(flags, name) \
26778 + do { (flags) |= AuFillVdir_##name; } while (0)
26779 +#define au_fclr_fillvdir(flags, name) \
26780 + do { (flags) &= ~AuFillVdir_##name; } while (0)
26782 +#ifndef CONFIG_AUFS_SHWH
26783 +#undef AuFillVdir_SHWH
26784 +#define AuFillVdir_SHWH 0
26787 +struct fillvdir_arg {
26788 + struct file *file;
26789 + struct au_vdir *vdir;
26790 + struct au_nhash delist;
26791 + struct au_nhash whlist;
26792 + aufs_bindex_t bindex;
26793 + unsigned int flags;
26797 +static int fillvdir(void *__arg, const char *__name, int nlen,
26798 + loff_t offset __maybe_unused, u64 h_ino,
26799 + unsigned int d_type)
26801 + struct fillvdir_arg *arg = __arg;
26802 + char *name = (void *)__name;
26803 + struct super_block *sb;
26805 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
26808 + sb = arg->file->f_dentry->d_sb;
26809 + au_fset_fillvdir(arg->flags, CALLED);
26811 + if (nlen <= AUFS_WH_PFX_LEN
26812 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
26813 + if (test_known(&arg->delist, name, nlen)
26814 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
26815 + goto out; /* already exists or whiteouted */
26817 + sb = arg->file->f_dentry->d_sb;
26818 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
26820 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
26821 + d_type = DT_UNKNOWN;
26822 + arg->err = append_de(arg->vdir, name, nlen, ino,
26823 + d_type, &arg->delist);
26825 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
26826 + name += AUFS_WH_PFX_LEN;
26827 + nlen -= AUFS_WH_PFX_LEN;
26828 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
26829 + goto out; /* already whiteouted */
26832 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
26835 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
26836 + d_type = DT_UNKNOWN;
26837 + arg->err = au_nhash_append_wh
26838 + (&arg->whlist, name, nlen, ino, d_type,
26839 + arg->bindex, shwh);
26845 + arg->vdir->vd_jiffy = jiffies;
26847 + AuTraceErr(arg->err);
26851 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
26852 + struct au_nhash *whlist, struct au_nhash *delist)
26854 +#ifdef CONFIG_AUFS_SHWH
26856 + unsigned int nh, u;
26857 + struct hlist_head *head;
26858 + struct au_vdir_wh *pos;
26859 + struct hlist_node *n;
26861 + struct au_vdir_destr *destr;
26863 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
26866 + o = p = (void *)__get_free_page(GFP_NOFS);
26867 + if (unlikely(!p))
26871 + nh = whlist->nh_num;
26872 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
26873 + p += AUFS_WH_PFX_LEN;
26874 + for (u = 0; u < nh; u++) {
26875 + head = whlist->nh_head + u;
26876 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
26877 + destr = &pos->wh_str;
26878 + memcpy(p, destr->name, destr->len);
26879 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
26880 + pos->wh_ino, pos->wh_type, delist);
26881 + if (unlikely(err))
26886 + free_page((unsigned long)o);
26896 +static int au_do_read_vdir(struct fillvdir_arg *arg)
26899 + unsigned int rdhash;
26901 + aufs_bindex_t bend, bindex, bstart;
26902 + unsigned char shwh;
26903 + struct file *hf, *file;
26904 + struct super_block *sb;
26906 + file = arg->file;
26907 + sb = file->f_dentry->d_sb;
26908 + SiMustAnyLock(sb);
26910 + rdhash = au_sbi(sb)->si_rdhash;
26912 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
26913 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
26914 + if (unlikely(err))
26916 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
26917 + if (unlikely(err))
26923 + if (au_opt_test(au_mntflags(sb), SHWH)) {
26925 + au_fset_fillvdir(arg->flags, SHWH);
26927 + bstart = au_fbstart(file);
26928 + bend = au_fbend_dir(file);
26929 + for (bindex = bstart; !err && bindex <= bend; bindex++) {
26930 + hf = au_hf_dir(file, bindex);
26934 + offset = vfsub_llseek(hf, 0, SEEK_SET);
26936 + if (unlikely(offset))
26939 + arg->bindex = bindex;
26940 + au_fclr_fillvdir(arg->flags, WHABLE);
26942 + || (bindex != bend
26943 + && au_br_whable(au_sbr_perm(sb, bindex))))
26944 + au_fset_fillvdir(arg->flags, WHABLE);
26947 + au_fclr_fillvdir(arg->flags, CALLED);
26949 + err = vfsub_readdir(hf, fillvdir, arg);
26952 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
26955 + if (!err && shwh)
26956 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
26958 + au_nhash_wh_free(&arg->whlist);
26961 + au_nhash_de_free(&arg->delist);
26966 +static int read_vdir(struct file *file, int may_read)
26969 + unsigned long expire;
26970 + unsigned char do_read;
26971 + struct fillvdir_arg arg;
26972 + struct inode *inode;
26973 + struct au_vdir *vdir, *allocated;
26976 + inode = file_inode(file);
26977 + IMustLock(inode);
26978 + SiMustAnyLock(inode->i_sb);
26980 + allocated = NULL;
26982 + expire = au_sbi(inode->i_sb)->si_rdcache;
26983 + vdir = au_ivdir(inode);
26986 + vdir = alloc_vdir(file);
26987 + err = PTR_ERR(vdir);
26988 + if (IS_ERR(vdir))
26991 + allocated = vdir;
26992 + } else if (may_read
26993 + && (inode->i_version != vdir->vd_version
26994 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
26996 + err = reinit_vdir(vdir);
26997 + if (unlikely(err))
27002 + return 0; /* success */
27006 + err = au_do_read_vdir(&arg);
27008 + /* file->f_pos = 0; */
27009 + vdir->vd_version = inode->i_version;
27010 + vdir->vd_last.ul = 0;
27011 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
27013 + au_set_ivdir(inode, allocated);
27014 + } else if (allocated)
27015 + au_vdir_free(allocated);
27021 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
27024 + unsigned long ul, n;
27025 + const unsigned int deblk_sz = src->vd_deblk_sz;
27027 + AuDebugOn(tgt->vd_nblk != 1);
27030 + if (tgt->vd_nblk < src->vd_nblk) {
27031 + unsigned char **p;
27033 + p = krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
27035 + if (unlikely(!p))
27037 + tgt->vd_deblk = p;
27040 + if (tgt->vd_deblk_sz != deblk_sz) {
27041 + unsigned char *p;
27043 + tgt->vd_deblk_sz = deblk_sz;
27044 + p = krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS);
27045 + if (unlikely(!p))
27047 + tgt->vd_deblk[0] = p;
27049 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
27050 + tgt->vd_version = src->vd_version;
27051 + tgt->vd_jiffy = src->vd_jiffy;
27053 + n = src->vd_nblk;
27054 + for (ul = 1; ul < n; ul++) {
27055 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
27057 + if (unlikely(!tgt->vd_deblk[ul]))
27061 + tgt->vd_nblk = n;
27062 + tgt->vd_last.ul = tgt->vd_last.ul;
27063 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
27064 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
27065 + - src->vd_deblk[src->vd_last.ul];
27067 + return 0; /* success */
27070 + rerr = reinit_vdir(tgt);
27075 +int au_vdir_init(struct file *file)
27078 + struct inode *inode;
27079 + struct au_vdir *vdir_cache, *allocated;
27081 + err = read_vdir(file, !file->f_pos);
27082 + if (unlikely(err))
27085 + allocated = NULL;
27086 + vdir_cache = au_fvdir_cache(file);
27087 + if (!vdir_cache) {
27088 + vdir_cache = alloc_vdir(file);
27089 + err = PTR_ERR(vdir_cache);
27090 + if (IS_ERR(vdir_cache))
27092 + allocated = vdir_cache;
27093 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
27094 + err = reinit_vdir(vdir_cache);
27095 + if (unlikely(err))
27098 + return 0; /* success */
27100 + inode = file_inode(file);
27101 + err = copy_vdir(vdir_cache, au_ivdir(inode));
27103 + file->f_version = inode->i_version;
27105 + au_set_fvdir_cache(file, allocated);
27106 + } else if (allocated)
27107 + au_vdir_free(allocated);
27113 +static loff_t calc_offset(struct au_vdir *vdir)
27116 + union au_vdir_deblk_p p;
27118 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
27119 + offset = vdir->vd_last.p.deblk - p.deblk;
27120 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
27124 +/* returns true or false */
27125 +static int seek_vdir(struct file *file)
27128 + unsigned int deblk_sz;
27129 + unsigned long ul, n;
27131 + union au_vdir_deblk_p p, deblk_end;
27132 + struct au_vdir *vdir_cache;
27135 + vdir_cache = au_fvdir_cache(file);
27136 + offset = calc_offset(vdir_cache);
27137 + AuDbg("offset %lld\n", offset);
27138 + if (file->f_pos == offset)
27141 + vdir_cache->vd_last.ul = 0;
27142 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
27143 + if (!file->f_pos)
27147 + deblk_sz = vdir_cache->vd_deblk_sz;
27148 + ul = div64_u64(file->f_pos, deblk_sz);
27149 + AuDbg("ul %lu\n", ul);
27150 + if (ul >= vdir_cache->vd_nblk)
27153 + n = vdir_cache->vd_nblk;
27154 + for (; ul < n; ul++) {
27155 + p.deblk = vdir_cache->vd_deblk[ul];
27156 + deblk_end.deblk = p.deblk + deblk_sz;
27158 + offset *= deblk_sz;
27159 + while (!is_deblk_end(&p, &deblk_end) && offset < file->f_pos) {
27162 + l = calc_size(p.de->de_str.len);
27166 + if (!is_deblk_end(&p, &deblk_end)) {
27168 + vdir_cache->vd_last.ul = ul;
27169 + vdir_cache->vd_last.p = p;
27176 + AuTraceErr(!valid);
27180 +int au_vdir_fill_de(struct file *file, void *dirent, filldir_t filldir)
27183 + unsigned int l, deblk_sz;
27184 + union au_vdir_deblk_p deblk_end;
27185 + struct au_vdir *vdir_cache;
27186 + struct au_vdir_de *de;
27188 + vdir_cache = au_fvdir_cache(file);
27189 + if (!seek_vdir(file))
27192 + deblk_sz = vdir_cache->vd_deblk_sz;
27194 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
27195 + deblk_end.deblk += deblk_sz;
27196 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
27197 + de = vdir_cache->vd_last.p.de;
27198 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
27199 + de->de_str.len, de->de_str.name, file->f_pos,
27200 + (unsigned long)de->de_ino, de->de_type);
27201 + err = filldir(dirent, de->de_str.name, de->de_str.len,
27202 + file->f_pos, de->de_ino, de->de_type);
27203 + if (unlikely(err)) {
27205 + /* todo: ignore the error caused by udba? */
27206 + /* return err; */
27210 + l = calc_size(de->de_str.len);
27211 + vdir_cache->vd_last.p.deblk += l;
27212 + file->f_pos += l;
27214 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
27215 + vdir_cache->vd_last.ul++;
27216 + vdir_cache->vd_last.p.deblk
27217 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
27218 + file->f_pos = deblk_sz * vdir_cache->vd_last.ul;
27227 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
27228 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
27229 +++ linux/fs/aufs/vfsub.c 2013-07-30 22:42:55.842946719 +0200
27232 + * Copyright (C) 2005-2013 Junjiro R. Okajima
27234 + * This program, aufs is free software; you can redistribute it and/or modify
27235 + * it under the terms of the GNU General Public License as published by
27236 + * the Free Software Foundation; either version 2 of the License, or
27237 + * (at your option) any later version.
27239 + * This program is distributed in the hope that it will be useful,
27240 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27241 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27242 + * GNU General Public License for more details.
27244 + * You should have received a copy of the GNU General Public License
27245 + * along with this program; if not, write to the Free Software
27246 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27250 + * sub-routines for VFS
27253 +#include <linux/ima.h>
27254 +#include <linux/namei.h>
27255 +#include <linux/security.h>
27256 +#include <linux/splice.h>
27259 +int vfsub_update_h_iattr(struct path *h_path, int *did)
27263 + struct super_block *h_sb;
27265 + /* for remote fs, leave work for its getattr or d_revalidate */
27266 + /* for bad i_attr fs, handle them in aufs_getattr() */
27267 + /* still some fs may acquire i_mutex. we need to skip them */
27271 + h_sb = h_path->dentry->d_sb;
27272 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
27274 + err = vfs_getattr(h_path, &st);
27279 +/* ---------------------------------------------------------------------- */
27281 +struct file *vfsub_dentry_open(struct path *path, int flags)
27283 + struct file *file;
27285 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
27287 + if (!IS_ERR_OR_NULL(file)
27288 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
27289 + i_readcount_inc(path->dentry->d_inode);
27294 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
27296 + struct file *file;
27299 + file = filp_open(path,
27300 + oflags /* | __FMODE_NONOTIFY */,
27303 + if (IS_ERR(file))
27305 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
27311 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
27315 + err = kern_path(name, flags, path);
27316 + if (!err && path->dentry->d_inode)
27317 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
27321 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
27324 + struct path path = {
27328 + /* VFS checks it too, but by WARN_ON_ONCE() */
27329 + IMustLock(parent->d_inode);
27331 + path.dentry = lookup_one_len(name, parent, len);
27332 + if (IS_ERR(path.dentry))
27334 + if (path.dentry->d_inode)
27335 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
27338 + AuTraceErrPtr(path.dentry);
27339 + return path.dentry;
27342 +void vfsub_call_lkup_one(void *args)
27344 + struct vfsub_lkup_one_args *a = args;
27345 + *a->errp = vfsub_lkup_one(a->name, a->parent);
27348 +/* ---------------------------------------------------------------------- */
27350 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
27351 + struct dentry *d2, struct au_hinode *hdir2)
27353 + struct dentry *d;
27356 + d = lock_rename(d1, d2);
27358 + au_hn_suspend(hdir1);
27359 + if (hdir1 != hdir2)
27360 + au_hn_suspend(hdir2);
27365 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
27366 + struct dentry *d2, struct au_hinode *hdir2)
27368 + au_hn_resume(hdir1);
27369 + if (hdir1 != hdir2)
27370 + au_hn_resume(hdir2);
27372 + unlock_rename(d1, d2);
27376 +/* ---------------------------------------------------------------------- */
27378 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
27381 + struct dentry *d;
27385 + d = path->dentry;
27386 + path->dentry = d->d_parent;
27387 + err = security_path_mknod(path, d, mode, 0);
27388 + path->dentry = d;
27389 + if (unlikely(err))
27392 + err = vfs_create(dir, path->dentry, mode, want_excl);
27394 + struct path tmp = *path;
27397 + vfsub_update_h_iattr(&tmp, &did);
27399 + tmp.dentry = path->dentry->d_parent;
27400 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27409 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
27412 + struct dentry *d;
27416 + d = path->dentry;
27417 + path->dentry = d->d_parent;
27418 + err = security_path_symlink(path, d, symname);
27419 + path->dentry = d;
27420 + if (unlikely(err))
27423 + err = vfs_symlink(dir, path->dentry, symname);
27425 + struct path tmp = *path;
27428 + vfsub_update_h_iattr(&tmp, &did);
27430 + tmp.dentry = path->dentry->d_parent;
27431 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27440 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
27443 + struct dentry *d;
27447 + d = path->dentry;
27448 + path->dentry = d->d_parent;
27449 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
27450 + path->dentry = d;
27451 + if (unlikely(err))
27454 + err = vfs_mknod(dir, path->dentry, mode, dev);
27456 + struct path tmp = *path;
27459 + vfsub_update_h_iattr(&tmp, &did);
27461 + tmp.dentry = path->dentry->d_parent;
27462 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27471 +static int au_test_nlink(struct inode *inode)
27473 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
27475 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
27476 + || inode->i_nlink < link_max)
27481 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path)
27484 + struct dentry *d;
27488 + err = au_test_nlink(src_dentry->d_inode);
27489 + if (unlikely(err))
27492 + /* we don't call may_linkat() */
27493 + d = path->dentry;
27494 + path->dentry = d->d_parent;
27495 + err = security_path_link(src_dentry, path, d);
27496 + path->dentry = d;
27497 + if (unlikely(err))
27501 + err = vfs_link(src_dentry, dir, path->dentry);
27504 + struct path tmp = *path;
27507 + /* fuse has different memory inode for the same inumber */
27508 + vfsub_update_h_iattr(&tmp, &did);
27510 + tmp.dentry = path->dentry->d_parent;
27511 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27512 + tmp.dentry = src_dentry;
27513 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27522 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
27523 + struct inode *dir, struct path *path)
27526 + struct path tmp = {
27529 + struct dentry *d;
27532 + IMustLock(src_dir);
27534 + d = path->dentry;
27535 + path->dentry = d->d_parent;
27536 + tmp.dentry = src_dentry->d_parent;
27537 + err = security_path_rename(&tmp, src_dentry, path, d);
27538 + path->dentry = d;
27539 + if (unlikely(err))
27543 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry);
27548 + tmp.dentry = d->d_parent;
27549 + vfsub_update_h_iattr(&tmp, &did);
27551 + tmp.dentry = src_dentry;
27552 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27553 + tmp.dentry = src_dentry->d_parent;
27554 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27563 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
27566 + struct dentry *d;
27570 + d = path->dentry;
27571 + path->dentry = d->d_parent;
27572 + err = security_path_mkdir(path, d, mode);
27573 + path->dentry = d;
27574 + if (unlikely(err))
27577 + err = vfs_mkdir(dir, path->dentry, mode);
27579 + struct path tmp = *path;
27582 + vfsub_update_h_iattr(&tmp, &did);
27584 + tmp.dentry = path->dentry->d_parent;
27585 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27594 +int vfsub_rmdir(struct inode *dir, struct path *path)
27597 + struct dentry *d;
27601 + d = path->dentry;
27602 + path->dentry = d->d_parent;
27603 + err = security_path_rmdir(path, d);
27604 + path->dentry = d;
27605 + if (unlikely(err))
27609 + err = vfs_rmdir(dir, path->dentry);
27612 + struct path tmp = {
27613 + .dentry = path->dentry->d_parent,
27617 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
27624 +/* ---------------------------------------------------------------------- */
27626 +/* todo: support mmap_sem? */
27627 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
27633 + err = vfs_read(file, ubuf, count, ppos);
27636 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
27640 +/* todo: kernel_read()? */
27641 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
27645 + mm_segment_t oldfs;
27652 + oldfs = get_fs();
27653 + set_fs(KERNEL_DS);
27654 + err = vfsub_read_u(file, buf.u, count, ppos);
27659 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
27665 + err = vfs_write(file, ubuf, count, ppos);
27668 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
27672 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
27675 + mm_segment_t oldfs;
27678 + const char __user *u;
27682 + oldfs = get_fs();
27683 + set_fs(KERNEL_DS);
27684 + err = vfsub_write_u(file, buf.u, count, ppos);
27689 +int vfsub_flush(struct file *file, fl_owner_t id)
27694 + if (file->f_op && file->f_op->flush) {
27695 + if (!au_test_nfs(file->f_dentry->d_sb))
27696 + err = file->f_op->flush(file, id);
27699 + err = file->f_op->flush(file, id);
27703 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
27709 +int vfsub_readdir(struct file *file, filldir_t filldir, void *arg)
27714 + err = vfs_readdir(file, filldir, arg);
27717 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
27721 +long vfsub_splice_to(struct file *in, loff_t *ppos,
27722 + struct pipe_inode_info *pipe, size_t len,
27723 + unsigned int flags)
27728 + err = do_splice_to(in, ppos, pipe, len, flags);
27730 + file_accessed(in);
27732 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
27736 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
27737 + loff_t *ppos, size_t len, unsigned int flags)
27742 + err = do_splice_from(pipe, out, ppos, len, flags);
27745 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
27749 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
27753 + /* file can be NULL */
27755 + err = vfs_fsync(file, datasync);
27759 + AuDebugOn(!file);
27760 + path = &file->f_path;
27762 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
27767 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
27768 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
27769 + struct file *h_file)
27772 + struct inode *h_inode;
27773 + struct super_block *h_sb;
27776 + err = vfsub_truncate(h_path, length);
27780 + h_inode = h_path->dentry->d_inode;
27781 + h_sb = h_inode->i_sb;
27783 + sb_start_write(h_sb);
27785 + err = locks_verify_truncate(h_inode, h_file, length);
27787 + err = security_path_truncate(h_path);
27790 + err = do_truncate(h_path->dentry, length, attr, h_file);
27794 + sb_end_write(h_sb);
27801 +/* ---------------------------------------------------------------------- */
27803 +struct au_vfsub_mkdir_args {
27805 + struct inode *dir;
27806 + struct path *path;
27810 +static void au_call_vfsub_mkdir(void *args)
27812 + struct au_vfsub_mkdir_args *a = args;
27813 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
27816 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
27818 + int err, do_sio, wkq_err;
27820 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
27822 + err = vfsub_mkdir(dir, path, mode);
27824 + struct au_vfsub_mkdir_args args = {
27830 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
27831 + if (unlikely(wkq_err))
27838 +struct au_vfsub_rmdir_args {
27840 + struct inode *dir;
27841 + struct path *path;
27844 +static void au_call_vfsub_rmdir(void *args)
27846 + struct au_vfsub_rmdir_args *a = args;
27847 + *a->errp = vfsub_rmdir(a->dir, a->path);
27850 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
27852 + int err, do_sio, wkq_err;
27854 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
27856 + err = vfsub_rmdir(dir, path);
27858 + struct au_vfsub_rmdir_args args = {
27863 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
27864 + if (unlikely(wkq_err))
27871 +/* ---------------------------------------------------------------------- */
27873 +struct notify_change_args {
27875 + struct path *path;
27876 + struct iattr *ia;
27879 +static void call_notify_change(void *args)
27881 + struct notify_change_args *a = args;
27882 + struct inode *h_inode;
27884 + h_inode = a->path->dentry->d_inode;
27885 + IMustLock(h_inode);
27887 + *a->errp = -EPERM;
27888 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
27889 + *a->errp = notify_change(a->path->dentry, a->ia);
27891 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
27893 + AuTraceErr(*a->errp);
27896 +int vfsub_notify_change(struct path *path, struct iattr *ia)
27899 + struct notify_change_args args = {
27905 + call_notify_change(&args);
27910 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia)
27912 + int err, wkq_err;
27913 + struct notify_change_args args = {
27919 + wkq_err = au_wkq_wait(call_notify_change, &args);
27920 + if (unlikely(wkq_err))
27926 +/* ---------------------------------------------------------------------- */
27928 +struct unlink_args {
27930 + struct inode *dir;
27931 + struct path *path;
27934 +static void call_unlink(void *args)
27936 + struct unlink_args *a = args;
27937 + struct dentry *d = a->path->dentry;
27938 + struct inode *h_inode;
27939 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
27940 + && d->d_count == 1);
27942 + IMustLock(a->dir);
27944 + a->path->dentry = d->d_parent;
27945 + *a->errp = security_path_unlink(a->path, d);
27946 + a->path->dentry = d;
27947 + if (unlikely(*a->errp))
27950 + if (!stop_sillyrename)
27952 + h_inode = d->d_inode;
27957 + *a->errp = vfs_unlink(a->dir, d);
27960 + struct path tmp = {
27961 + .dentry = d->d_parent,
27962 + .mnt = a->path->mnt
27964 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
27967 + if (!stop_sillyrename)
27972 + AuTraceErr(*a->errp);
27976 + * @dir: must be locked.
27977 + * @dentry: target dentry.
27979 +int vfsub_unlink(struct inode *dir, struct path *path, int force)
27982 + struct unlink_args args = {
27989 + call_unlink(&args);
27993 + wkq_err = au_wkq_wait(call_unlink, &args);
27994 + if (unlikely(wkq_err))
28000 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
28001 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
28002 +++ linux/fs/aufs/vfsub.h 2013-07-30 22:42:55.842946719 +0200
28005 + * Copyright (C) 2005-2013 Junjiro R. Okajima
28007 + * This program, aufs is free software; you can redistribute it and/or modify
28008 + * it under the terms of the GNU General Public License as published by
28009 + * the Free Software Foundation; either version 2 of the License, or
28010 + * (at your option) any later version.
28012 + * This program is distributed in the hope that it will be useful,
28013 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28014 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28015 + * GNU General Public License for more details.
28017 + * You should have received a copy of the GNU General Public License
28018 + * along with this program; if not, write to the Free Software
28019 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28023 + * sub-routines for VFS
28026 +#ifndef __AUFS_VFSUB_H__
28027 +#define __AUFS_VFSUB_H__
28031 +#include <linux/fs.h>
28032 +#include <linux/mount.h>
28033 +#include "debug.h"
28035 +/* copied from linux/fs/internal.h */
28036 +/* todo: BAD approach!! */
28037 +extern void __mnt_drop_write(struct vfsmount *);
28038 +extern spinlock_t inode_sb_list_lock;
28040 +/* lock subclass for lower inode */
28041 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
28042 +/* reduce? gave up. */
28044 + AuLsc_I_Begin = I_MUTEX_QUOTA, /* 4 */
28045 + AuLsc_I_PARENT, /* lower inode, parent first */
28046 + AuLsc_I_PARENT2, /* copyup dirs */
28047 + AuLsc_I_PARENT3, /* copyup wh */
28053 +/* to debug easier, do not make them inlined functions */
28054 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
28055 +#define IMustLock(i) MtxMustLock(&(i)->i_mutex)
28057 +/* ---------------------------------------------------------------------- */
28059 +static inline void vfsub_drop_nlink(struct inode *inode)
28061 + AuDebugOn(!inode->i_nlink);
28062 + drop_nlink(inode);
28065 +static inline void vfsub_dead_dir(struct inode *inode)
28067 + AuDebugOn(!S_ISDIR(inode->i_mode));
28068 + inode->i_flags |= S_DEAD;
28069 + clear_nlink(inode);
28072 +/* ---------------------------------------------------------------------- */
28074 +int vfsub_update_h_iattr(struct path *h_path, int *did);
28075 +struct file *vfsub_dentry_open(struct path *path, int flags);
28076 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
28077 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
28079 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
28082 +struct vfsub_lkup_one_args {
28083 + struct dentry **errp;
28084 + struct qstr *name;
28085 + struct dentry *parent;
28088 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
28089 + struct dentry *parent)
28091 + return vfsub_lookup_one_len(name->name, parent, name->len);
28094 +void vfsub_call_lkup_one(void *args);
28096 +/* ---------------------------------------------------------------------- */
28098 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
28102 + err = mnt_want_write(mnt);
28107 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
28110 + mnt_drop_write(mnt);
28114 +static inline void vfsub_mnt_drop_write_file(struct file *file)
28117 + mnt_drop_write_file(file);
28121 +/* ---------------------------------------------------------------------- */
28124 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
28125 + struct dentry *d2, struct au_hinode *hdir2);
28126 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
28127 + struct dentry *d2, struct au_hinode *hdir2);
28129 +int vfsub_create(struct inode *dir, struct path *path, int mode,
28131 +int vfsub_symlink(struct inode *dir, struct path *path,
28132 + const char *symname);
28133 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
28134 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
28135 + struct path *path);
28136 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
28137 + struct inode *hdir, struct path *path);
28138 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
28139 +int vfsub_rmdir(struct inode *dir, struct path *path);
28141 +/* ---------------------------------------------------------------------- */
28143 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
28145 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
28147 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
28149 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
28151 +int vfsub_flush(struct file *file, fl_owner_t id);
28152 +int vfsub_readdir(struct file *file, filldir_t filldir, void *arg);
28154 +static inline loff_t vfsub_f_size_read(struct file *file)
28156 + return i_size_read(file_inode(file));
28159 +static inline unsigned int vfsub_file_flags(struct file *file)
28161 + unsigned int flags;
28163 + spin_lock(&file->f_lock);
28164 + flags = file->f_flags;
28165 + spin_unlock(&file->f_lock);
28170 +static inline void vfsub_file_accessed(struct file *h_file)
28172 + file_accessed(h_file);
28173 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
28176 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
28177 + struct dentry *h_dentry)
28179 + struct path h_path = {
28180 + .dentry = h_dentry,
28183 + touch_atime(&h_path);
28184 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
28187 +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts,
28190 + return update_time(h_inode, ts, flags);
28191 + /* no vfsub_update_h_iattr() since we don't have struct path */
28194 +long vfsub_splice_to(struct file *in, loff_t *ppos,
28195 + struct pipe_inode_info *pipe, size_t len,
28196 + unsigned int flags);
28197 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
28198 + loff_t *ppos, size_t len, unsigned int flags);
28200 +static inline long vfsub_truncate(struct path *path, loff_t length)
28204 + err = vfs_truncate(path, length);
28209 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
28210 + struct file *h_file);
28211 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
28213 +/* ---------------------------------------------------------------------- */
28215 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
28220 + err = vfs_llseek(file, offset, origin);
28225 +/* ---------------------------------------------------------------------- */
28227 +/* dirty workaround for strict type of fmode_t */
28233 +static inline unsigned int vfsub_fmode_to_uint(fmode_t fm)
28235 + union vfsub_fmu u = {
28239 + BUILD_BUG_ON(sizeof(u.fm) != sizeof(u.ui));
28244 +static inline fmode_t vfsub_uint_to_fmode(unsigned int ui)
28246 + union vfsub_fmu u = {
28253 +/* ---------------------------------------------------------------------- */
28255 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
28256 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
28257 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia);
28258 +int vfsub_notify_change(struct path *path, struct iattr *ia);
28259 +int vfsub_unlink(struct inode *dir, struct path *path, int force);
28261 +#endif /* __KERNEL__ */
28262 +#endif /* __AUFS_VFSUB_H__ */
28263 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
28264 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
28265 +++ linux/fs/aufs/wbr_policy.c 2013-08-23 23:59:39.638250372 +0200
28268 + * Copyright (C) 2005-2013 Junjiro R. Okajima
28270 + * This program, aufs is free software; you can redistribute it and/or modify
28271 + * it under the terms of the GNU General Public License as published by
28272 + * the Free Software Foundation; either version 2 of the License, or
28273 + * (at your option) any later version.
28275 + * This program is distributed in the hope that it will be useful,
28276 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28277 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28278 + * GNU General Public License for more details.
28280 + * You should have received a copy of the GNU General Public License
28281 + * along with this program; if not, write to the Free Software
28282 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28286 + * policies for selecting one among multiple writable branches
28289 +#include <linux/statfs.h>
28292 +/* subset of cpup_attr() */
28293 +static noinline_for_stack
28294 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
28298 + struct inode *h_isrc;
28300 + h_isrc = h_src->d_inode;
28301 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
28302 + ia.ia_mode = h_isrc->i_mode;
28303 + ia.ia_uid = h_isrc->i_uid;
28304 + ia.ia_gid = h_isrc->i_gid;
28305 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
28306 + au_cpup_attr_flags(h_path->dentry->d_inode, h_isrc->i_flags);
28307 + err = vfsub_sio_notify_change(h_path, &ia);
28309 + /* is this nfs only? */
28310 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
28311 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
28312 + ia.ia_mode = h_isrc->i_mode;
28313 + err = vfsub_sio_notify_change(h_path, &ia);
28319 +#define AuCpdown_PARENT_OPQ 1
28320 +#define AuCpdown_WHED (1 << 1)
28321 +#define AuCpdown_MADE_DIR (1 << 2)
28322 +#define AuCpdown_DIROPQ (1 << 3)
28323 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
28324 +#define au_fset_cpdown(flags, name) \
28325 + do { (flags) |= AuCpdown_##name; } while (0)
28326 +#define au_fclr_cpdown(flags, name) \
28327 + do { (flags) &= ~AuCpdown_##name; } while (0)
28329 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
28330 + unsigned int *flags)
28333 + struct dentry *opq_dentry;
28335 + opq_dentry = au_diropq_create(dentry, bdst);
28336 + err = PTR_ERR(opq_dentry);
28337 + if (IS_ERR(opq_dentry))
28339 + dput(opq_dentry);
28340 + au_fset_cpdown(*flags, DIROPQ);
28346 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
28347 + struct inode *dir, aufs_bindex_t bdst)
28350 + struct path h_path;
28351 + struct au_branch *br;
28353 + br = au_sbr(dentry->d_sb, bdst);
28354 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
28355 + err = PTR_ERR(h_path.dentry);
28356 + if (IS_ERR(h_path.dentry))
28360 + if (h_path.dentry->d_inode) {
28361 + h_path.mnt = au_br_mnt(br);
28362 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
28365 + dput(h_path.dentry);
28371 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
28372 + struct au_pin *pin,
28373 + struct dentry *h_parent, void *arg)
28376 + aufs_bindex_t bopq, bstart;
28377 + struct path h_path;
28378 + struct dentry *parent;
28379 + struct inode *h_dir, *h_inode, *inode, *dir;
28380 + unsigned int *flags = arg;
28382 + bstart = au_dbstart(dentry);
28383 + /* dentry is di-locked */
28384 + parent = dget_parent(dentry);
28385 + dir = parent->d_inode;
28386 + h_dir = h_parent->d_inode;
28387 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
28388 + IMustLock(h_dir);
28390 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
28391 + if (unlikely(err < 0))
28393 + h_path.dentry = au_h_dptr(dentry, bdst);
28394 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
28395 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path,
28396 + S_IRWXU | S_IRUGO | S_IXUGO);
28397 + if (unlikely(err))
28399 + au_fset_cpdown(*flags, MADE_DIR);
28401 + bopq = au_dbdiropq(dentry);
28402 + au_fclr_cpdown(*flags, WHED);
28403 + au_fclr_cpdown(*flags, DIROPQ);
28404 + if (au_dbwh(dentry) == bdst)
28405 + au_fset_cpdown(*flags, WHED);
28406 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
28407 + au_fset_cpdown(*flags, PARENT_OPQ);
28408 + h_inode = h_path.dentry->d_inode;
28409 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
28410 + if (au_ftest_cpdown(*flags, WHED)) {
28411 + err = au_cpdown_dir_opq(dentry, bdst, flags);
28412 + if (unlikely(err)) {
28413 + mutex_unlock(&h_inode->i_mutex);
28418 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, bstart));
28419 + mutex_unlock(&h_inode->i_mutex);
28420 + if (unlikely(err))
28423 + if (au_ftest_cpdown(*flags, WHED)) {
28424 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
28425 + if (unlikely(err))
28429 + inode = dentry->d_inode;
28430 + if (au_ibend(inode) < bdst)
28431 + au_set_ibend(inode, bdst);
28432 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
28433 + au_hi_flags(inode, /*isdir*/1));
28434 + goto out; /* success */
28438 + if (au_ftest_cpdown(*flags, DIROPQ)) {
28439 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
28440 + rerr = au_diropq_remove(dentry, bdst);
28441 + mutex_unlock(&h_inode->i_mutex);
28442 + if (unlikely(rerr)) {
28443 + AuIOErr("failed removing diropq for %.*s b%d (%d)\n",
28444 + AuDLNPair(dentry), bdst, rerr);
28450 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
28451 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
28452 + if (unlikely(rerr)) {
28453 + AuIOErr("failed removing %.*s b%d (%d)\n",
28454 + AuDLNPair(dentry), bdst, rerr);
28459 + au_set_h_dptr(dentry, bdst, NULL);
28460 + if (au_dbend(dentry) == bdst)
28461 + au_update_dbend(dentry);
28467 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
28470 + unsigned int flags;
28473 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
28478 +/* ---------------------------------------------------------------------- */
28480 +/* policies for create */
28482 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
28484 + int err, i, j, ndentry;
28485 + aufs_bindex_t bopq;
28486 + struct au_dcsub_pages dpages;
28487 + struct au_dpage *dpage;
28488 + struct dentry **dentries, *parent, *d;
28490 + err = au_dpages_init(&dpages, GFP_NOFS);
28491 + if (unlikely(err))
28493 + parent = dget_parent(dentry);
28494 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
28495 + if (unlikely(err))
28499 + for (i = 0; i < dpages.ndpage; i++) {
28500 + dpage = dpages.dpages + i;
28501 + dentries = dpage->dentries;
28502 + ndentry = dpage->ndentry;
28503 + for (j = 0; j < ndentry; j++) {
28505 + di_read_lock_parent2(d, !AuLock_IR);
28506 + bopq = au_dbdiropq(d);
28507 + di_read_unlock(d, !AuLock_IR);
28508 + if (bopq >= 0 && bopq < err)
28515 + au_dpages_free(&dpages);
28520 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
28522 + for (; bindex >= 0; bindex--)
28523 + if (!au_br_rdonly(au_sbr(sb, bindex)))
28528 +/* top down parent */
28529 +static int au_wbr_create_tdp(struct dentry *dentry, int isdir __maybe_unused)
28532 + aufs_bindex_t bstart, bindex;
28533 + struct super_block *sb;
28534 + struct dentry *parent, *h_parent;
28536 + sb = dentry->d_sb;
28537 + bstart = au_dbstart(dentry);
28539 + if (!au_br_rdonly(au_sbr(sb, bstart)))
28543 + parent = dget_parent(dentry);
28544 + for (bindex = au_dbstart(parent); bindex < bstart; bindex++) {
28545 + h_parent = au_h_dptr(parent, bindex);
28546 + if (!h_parent || !h_parent->d_inode)
28549 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
28556 + /* bottom up here */
28557 + if (unlikely(err < 0)) {
28558 + err = au_wbr_bu(sb, bstart - 1);
28560 + err = au_wbr_nonopq(dentry, err);
28564 + AuDbg("b%d\n", err);
28568 +/* ---------------------------------------------------------------------- */
28570 +/* an exception for the policy other than tdp */
28571 +static int au_wbr_create_exp(struct dentry *dentry)
28574 + aufs_bindex_t bwh, bdiropq;
28575 + struct dentry *parent;
28578 + bwh = au_dbwh(dentry);
28579 + parent = dget_parent(dentry);
28580 + bdiropq = au_dbdiropq(parent);
28582 + if (bdiropq >= 0)
28583 + err = min(bdiropq, bwh);
28586 + AuDbg("%d\n", err);
28587 + } else if (bdiropq >= 0) {
28589 + AuDbg("%d\n", err);
28594 + err = au_wbr_nonopq(dentry, err);
28596 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
28599 + AuDbg("%d\n", err);
28603 +/* ---------------------------------------------------------------------- */
28606 +static int au_wbr_create_init_rr(struct super_block *sb)
28610 + err = au_wbr_bu(sb, au_sbend(sb));
28611 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
28614 + AuDbg("b%d\n", err);
28618 +static int au_wbr_create_rr(struct dentry *dentry, int isdir)
28622 + aufs_bindex_t bindex, bend;
28623 + struct super_block *sb;
28626 + err = au_wbr_create_exp(dentry);
28630 + sb = dentry->d_sb;
28631 + next = &au_sbi(sb)->si_wbr_rr_next;
28632 + bend = au_sbend(sb);
28634 + for (bindex = 0; bindex <= bend; bindex++) {
28636 + err = atomic_dec_return(next) + 1;
28637 + /* modulo for 0 is meaningless */
28638 + if (unlikely(!err))
28639 + err = atomic_dec_return(next) + 1;
28641 + err = atomic_read(next);
28642 + AuDbg("%d\n", err);
28645 + AuDbg("%d\n", err);
28646 + if (!au_br_rdonly(au_sbr(sb, err)))
28652 + err = au_wbr_nonopq(dentry, err);
28655 + AuDbg("%d\n", err);
28659 +/* ---------------------------------------------------------------------- */
28661 +/* most free space */
28662 +static void au_mfs(struct dentry *dentry)
28664 + struct super_block *sb;
28665 + struct au_branch *br;
28666 + struct au_wbr_mfs *mfs;
28667 + aufs_bindex_t bindex, bend;
28669 + unsigned long long b, bavail;
28670 + struct path h_path;
28671 + /* reduce the stack usage */
28672 + struct kstatfs *st;
28674 + st = kmalloc(sizeof(*st), GFP_NOFS);
28675 + if (unlikely(!st)) {
28676 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
28681 + sb = dentry->d_sb;
28682 + mfs = &au_sbi(sb)->si_wbr_mfs;
28683 + MtxMustLock(&mfs->mfs_lock);
28684 + mfs->mfs_bindex = -EROFS;
28685 + mfs->mfsrr_bytes = 0;
28686 + bend = au_sbend(sb);
28687 + for (bindex = 0; bindex <= bend; bindex++) {
28688 + br = au_sbr(sb, bindex);
28689 + if (au_br_rdonly(br))
28692 + /* sb->s_root for NFS is unreliable */
28693 + h_path.mnt = au_br_mnt(br);
28694 + h_path.dentry = h_path.mnt->mnt_root;
28695 + err = vfs_statfs(&h_path, st);
28696 + if (unlikely(err)) {
28697 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
28701 + /* when the available size is equal, select the lower one */
28702 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
28703 + || sizeof(b) < sizeof(st->f_bsize));
28704 + b = st->f_bavail * st->f_bsize;
28705 + br->br_wbr->wbr_bytes = b;
28706 + if (b >= bavail) {
28708 + mfs->mfs_bindex = bindex;
28709 + mfs->mfs_jiffy = jiffies;
28713 + mfs->mfsrr_bytes = bavail;
28714 + AuDbg("b%d\n", mfs->mfs_bindex);
28718 +static int au_wbr_create_mfs(struct dentry *dentry, int isdir __maybe_unused)
28721 + struct super_block *sb;
28722 + struct au_wbr_mfs *mfs;
28724 + err = au_wbr_create_exp(dentry);
28728 + sb = dentry->d_sb;
28729 + mfs = &au_sbi(sb)->si_wbr_mfs;
28730 + mutex_lock(&mfs->mfs_lock);
28731 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
28732 + || mfs->mfs_bindex < 0
28733 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
28735 + mutex_unlock(&mfs->mfs_lock);
28736 + err = mfs->mfs_bindex;
28739 + err = au_wbr_nonopq(dentry, err);
28742 + AuDbg("b%d\n", err);
28746 +static int au_wbr_create_init_mfs(struct super_block *sb)
28748 + struct au_wbr_mfs *mfs;
28750 + mfs = &au_sbi(sb)->si_wbr_mfs;
28751 + mutex_init(&mfs->mfs_lock);
28752 + mfs->mfs_jiffy = 0;
28753 + mfs->mfs_bindex = -EROFS;
28758 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
28760 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
28764 +/* ---------------------------------------------------------------------- */
28766 +/* most free space and then round robin */
28767 +static int au_wbr_create_mfsrr(struct dentry *dentry, int isdir)
28770 + struct au_wbr_mfs *mfs;
28772 + err = au_wbr_create_mfs(dentry, isdir);
28774 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
28775 + mutex_lock(&mfs->mfs_lock);
28776 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
28777 + err = au_wbr_create_rr(dentry, isdir);
28778 + mutex_unlock(&mfs->mfs_lock);
28781 + AuDbg("b%d\n", err);
28785 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
28789 + au_wbr_create_init_mfs(sb); /* ignore */
28790 + err = au_wbr_create_init_rr(sb);
28795 +/* ---------------------------------------------------------------------- */
28797 +/* top down parent and most free space */
28798 +static int au_wbr_create_pmfs(struct dentry *dentry, int isdir)
28801 + unsigned long long b;
28802 + aufs_bindex_t bindex, bstart, bend;
28803 + struct super_block *sb;
28804 + struct dentry *parent, *h_parent;
28805 + struct au_branch *br;
28807 + err = au_wbr_create_tdp(dentry, isdir);
28808 + if (unlikely(err < 0))
28810 + parent = dget_parent(dentry);
28811 + bstart = au_dbstart(parent);
28812 + bend = au_dbtaildir(parent);
28813 + if (bstart == bend)
28814 + goto out_parent; /* success */
28816 + e2 = au_wbr_create_mfs(dentry, isdir);
28818 + goto out_parent; /* success */
28820 + /* when the available size is equal, select upper one */
28821 + sb = dentry->d_sb;
28822 + br = au_sbr(sb, err);
28823 + b = br->br_wbr->wbr_bytes;
28824 + AuDbg("b%d, %llu\n", err, b);
28826 + for (bindex = bstart; bindex <= bend; bindex++) {
28827 + h_parent = au_h_dptr(parent, bindex);
28828 + if (!h_parent || !h_parent->d_inode)
28831 + br = au_sbr(sb, bindex);
28832 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
28833 + b = br->br_wbr->wbr_bytes;
28835 + AuDbg("b%d, %llu\n", err, b);
28840 + err = au_wbr_nonopq(dentry, err);
28845 + AuDbg("b%d\n", err);
28849 +/* ---------------------------------------------------------------------- */
28851 +/* policies for copyup */
28853 +/* top down parent */
28854 +static int au_wbr_copyup_tdp(struct dentry *dentry)
28856 + return au_wbr_create_tdp(dentry, /*isdir, anything is ok*/0);
28859 +/* bottom up parent */
28860 +static int au_wbr_copyup_bup(struct dentry *dentry)
28863 + aufs_bindex_t bindex, bstart;
28864 + struct dentry *parent, *h_parent;
28865 + struct super_block *sb;
28868 + sb = dentry->d_sb;
28869 + parent = dget_parent(dentry);
28870 + bstart = au_dbstart(parent);
28871 + for (bindex = au_dbstart(dentry); bindex >= bstart; bindex--) {
28872 + h_parent = au_h_dptr(parent, bindex);
28873 + if (!h_parent || !h_parent->d_inode)
28876 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
28883 + /* bottom up here */
28884 + if (unlikely(err < 0))
28885 + err = au_wbr_bu(sb, bstart - 1);
28887 + AuDbg("b%d\n", err);
28892 +static int au_wbr_copyup_bu(struct dentry *dentry)
28895 + aufs_bindex_t bstart;
28897 + bstart = au_dbstart(dentry);
28898 + err = au_wbr_bu(dentry->d_sb, bstart);
28899 + AuDbg("b%d\n", err);
28900 + if (err > bstart)
28901 + err = au_wbr_nonopq(dentry, err);
28903 + AuDbg("b%d\n", err);
28907 +/* ---------------------------------------------------------------------- */
28909 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
28910 + [AuWbrCopyup_TDP] = {
28911 + .copyup = au_wbr_copyup_tdp
28913 + [AuWbrCopyup_BUP] = {
28914 + .copyup = au_wbr_copyup_bup
28916 + [AuWbrCopyup_BU] = {
28917 + .copyup = au_wbr_copyup_bu
28921 +struct au_wbr_create_operations au_wbr_create_ops[] = {
28922 + [AuWbrCreate_TDP] = {
28923 + .create = au_wbr_create_tdp
28925 + [AuWbrCreate_RR] = {
28926 + .create = au_wbr_create_rr,
28927 + .init = au_wbr_create_init_rr
28929 + [AuWbrCreate_MFS] = {
28930 + .create = au_wbr_create_mfs,
28931 + .init = au_wbr_create_init_mfs,
28932 + .fin = au_wbr_create_fin_mfs
28934 + [AuWbrCreate_MFSV] = {
28935 + .create = au_wbr_create_mfs,
28936 + .init = au_wbr_create_init_mfs,
28937 + .fin = au_wbr_create_fin_mfs
28939 + [AuWbrCreate_MFSRR] = {
28940 + .create = au_wbr_create_mfsrr,
28941 + .init = au_wbr_create_init_mfsrr,
28942 + .fin = au_wbr_create_fin_mfs
28944 + [AuWbrCreate_MFSRRV] = {
28945 + .create = au_wbr_create_mfsrr,
28946 + .init = au_wbr_create_init_mfsrr,
28947 + .fin = au_wbr_create_fin_mfs
28949 + [AuWbrCreate_PMFS] = {
28950 + .create = au_wbr_create_pmfs,
28951 + .init = au_wbr_create_init_mfs,
28952 + .fin = au_wbr_create_fin_mfs
28954 + [AuWbrCreate_PMFSV] = {
28955 + .create = au_wbr_create_pmfs,
28956 + .init = au_wbr_create_init_mfs,
28957 + .fin = au_wbr_create_fin_mfs
28960 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
28961 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
28962 +++ linux/fs/aufs/whout.c 2013-07-06 13:20:47.760198800 +0200
28965 + * Copyright (C) 2005-2013 Junjiro R. Okajima
28967 + * This program, aufs is free software; you can redistribute it and/or modify
28968 + * it under the terms of the GNU General Public License as published by
28969 + * the Free Software Foundation; either version 2 of the License, or
28970 + * (at your option) any later version.
28972 + * This program is distributed in the hope that it will be useful,
28973 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28974 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28975 + * GNU General Public License for more details.
28977 + * You should have received a copy of the GNU General Public License
28978 + * along with this program; if not, write to the Free Software
28979 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28983 + * whiteout for logical deletion and opaque directory
28988 +#define WH_MASK S_IRUGO
28991 + * If a directory contains this file, then it is opaque. We start with the
28992 + * .wh. flag so that it is blocked by lookup.
28994 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
28995 + sizeof(AUFS_WH_DIROPQ) - 1);
28998 + * generate whiteout name, which is NOT terminated by NULL.
28999 + * @name: original d_name.name
29000 + * @len: original d_name.len
29001 + * @wh: whiteout qstr
29002 + * returns zero when succeeds, otherwise error.
29003 + * succeeded value as wh->name should be freed by kfree().
29005 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
29009 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
29010 + return -ENAMETOOLONG;
29012 + wh->len = name->len + AUFS_WH_PFX_LEN;
29013 + p = kmalloc(wh->len, GFP_NOFS);
29016 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
29017 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
29024 +/* ---------------------------------------------------------------------- */
29027 + * test if the @wh_name exists under @h_parent.
29028 + * @try_sio specifies the necessary of super-io.
29030 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name,
29031 + struct au_branch *br, int try_sio)
29034 + struct dentry *wh_dentry;
29037 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
29039 + wh_dentry = au_sio_lkup_one(wh_name, h_parent, br);
29040 + err = PTR_ERR(wh_dentry);
29041 + if (IS_ERR(wh_dentry))
29045 + if (!wh_dentry->d_inode)
29046 + goto out_wh; /* success */
29049 + if (S_ISREG(wh_dentry->d_inode->i_mode))
29050 + goto out_wh; /* success */
29053 + AuIOErr("%.*s Invalid whiteout entry type 0%o.\n",
29054 + AuDLNPair(wh_dentry), wh_dentry->d_inode->i_mode);
29063 + * test if the @h_dentry sets opaque or not.
29065 +int au_diropq_test(struct dentry *h_dentry, struct au_branch *br)
29068 + struct inode *h_dir;
29070 + h_dir = h_dentry->d_inode;
29071 + err = au_wh_test(h_dentry, &diropq_name, br,
29072 + au_test_h_perm_sio(h_dir, MAY_EXEC));
29077 + * returns a negative dentry whose name is unique and temporary.
29079 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
29080 + struct qstr *prefix)
29082 + struct dentry *dentry;
29084 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
29086 + /* strict atomic_t is unnecessary here */
29087 + static unsigned short cnt;
29090 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
29093 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
29094 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
29095 + dentry = ERR_PTR(-ENAMETOOLONG);
29096 + if (unlikely(qs.len > NAME_MAX))
29098 + dentry = ERR_PTR(-ENOMEM);
29099 + name = kmalloc(qs.len + 1, GFP_NOFS);
29100 + if (unlikely(!name))
29104 + /* doubly whiteout-ed */
29105 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
29106 + p = name + AUFS_WH_PFX_LEN * 2;
29107 + memcpy(p, prefix->name, prefix->len);
29108 + p += prefix->len;
29110 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
29113 + for (i = 0; i < 3; i++) {
29114 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
29115 + dentry = au_sio_lkup_one(&qs, h_parent, br);
29116 + if (IS_ERR(dentry) || !dentry->d_inode)
29120 + /* pr_warn("could not get random name\n"); */
29121 + dentry = ERR_PTR(-EEXIST);
29122 + AuDbg("%.*s\n", AuLNPair(&qs));
29126 + if (name != defname)
29129 + AuTraceErrPtr(dentry);
29134 + * rename the @h_dentry on @br to the whiteouted temporary name.
29136 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
29139 + struct path h_path = {
29140 + .mnt = au_br_mnt(br)
29142 + struct inode *h_dir;
29143 + struct dentry *h_parent;
29145 + h_parent = h_dentry->d_parent; /* dir inode is locked */
29146 + h_dir = h_parent->d_inode;
29147 + IMustLock(h_dir);
29149 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
29150 + err = PTR_ERR(h_path.dentry);
29151 + if (IS_ERR(h_path.dentry))
29154 + /* under the same dir, no need to lock_rename() */
29155 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path);
29157 + dput(h_path.dentry);
29164 +/* ---------------------------------------------------------------------- */
29166 + * functions for removing a whiteout
29169 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
29174 + * forces superio when the dir has a sticky bit.
29175 + * this may be a violation of unix fs semantics.
29177 + force = (h_dir->i_mode & S_ISVTX)
29178 + && !uid_eq(current_fsuid(), h_path->dentry->d_inode->i_uid);
29179 + return vfsub_unlink(h_dir, h_path, force);
29182 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
29183 + struct dentry *dentry)
29187 + err = do_unlink_wh(h_dir, h_path);
29188 + if (!err && dentry)
29189 + au_set_dbwh(dentry, -1);
29194 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
29195 + struct au_branch *br)
29198 + struct path h_path = {
29199 + .mnt = au_br_mnt(br)
29203 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
29204 + if (IS_ERR(h_path.dentry))
29205 + err = PTR_ERR(h_path.dentry);
29207 + if (h_path.dentry->d_inode
29208 + && S_ISREG(h_path.dentry->d_inode->i_mode))
29209 + err = do_unlink_wh(h_parent->d_inode, &h_path);
29210 + dput(h_path.dentry);
29216 +/* ---------------------------------------------------------------------- */
29218 + * initialize/clean whiteout for a branch
29221 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
29226 + if (!whpath->dentry->d_inode)
29230 + err = vfsub_rmdir(h_dir, whpath);
29232 + err = vfsub_unlink(h_dir, whpath, /*force*/0);
29233 + if (unlikely(err))
29234 + pr_warn("failed removing %.*s (%d), ignored.\n",
29235 + AuDLNPair(whpath->dentry), err);
29238 +static int test_linkable(struct dentry *h_root)
29240 + struct inode *h_dir = h_root->d_inode;
29242 + if (h_dir->i_op->link)
29245 + pr_err("%.*s (%s) doesn't support link(2), use noplink and rw+nolwh\n",
29246 + AuDLNPair(h_root), au_sbtype(h_root->d_sb));
29250 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
29251 +static int au_whdir(struct inode *h_dir, struct path *path)
29256 + if (!path->dentry->d_inode) {
29257 + int mode = S_IRWXU;
29259 + if (au_test_nfs(path->dentry->d_sb))
29261 + err = vfsub_mkdir(h_dir, path, mode);
29262 + } else if (S_ISDIR(path->dentry->d_inode->i_mode))
29265 + pr_err("unknown %.*s exists\n", AuDLNPair(path->dentry));
29270 +struct au_wh_base {
29271 + const struct qstr *name;
29272 + struct dentry *dentry;
29275 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
29276 + struct path *h_path)
29278 + h_path->dentry = base[AuBrWh_BASE].dentry;
29279 + au_wh_clean(h_dir, h_path, /*isdir*/0);
29280 + h_path->dentry = base[AuBrWh_PLINK].dentry;
29281 + au_wh_clean(h_dir, h_path, /*isdir*/1);
29282 + h_path->dentry = base[AuBrWh_ORPH].dentry;
29283 + au_wh_clean(h_dir, h_path, /*isdir*/1);
29287 + * returns tri-state,
29288 + * minus: error, caller should print the mesage
29290 + * plus: error, caller should NOT print the mesage
29292 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
29293 + int do_plink, struct au_wh_base base[],
29294 + struct path *h_path)
29297 + struct inode *h_dir;
29299 + h_dir = h_root->d_inode;
29300 + h_path->dentry = base[AuBrWh_BASE].dentry;
29301 + au_wh_clean(h_dir, h_path, /*isdir*/0);
29302 + h_path->dentry = base[AuBrWh_PLINK].dentry;
29304 + err = test_linkable(h_root);
29305 + if (unlikely(err)) {
29310 + err = au_whdir(h_dir, h_path);
29311 + if (unlikely(err))
29313 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
29315 + au_wh_clean(h_dir, h_path, /*isdir*/1);
29316 + h_path->dentry = base[AuBrWh_ORPH].dentry;
29317 + err = au_whdir(h_dir, h_path);
29318 + if (unlikely(err))
29320 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
29327 + * for the moment, aufs supports the branch filesystem which does not support
29328 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
29329 + * copyup failed. finally, such filesystem will not be used as the writable
29332 + * returns tri-state, see above.
29334 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
29335 + int do_plink, struct au_wh_base base[],
29336 + struct path *h_path)
29339 + struct inode *h_dir;
29341 + WbrWhMustWriteLock(wbr);
29343 + err = test_linkable(h_root);
29344 + if (unlikely(err)) {
29350 + * todo: should this create be done in /sbin/mount.aufs helper?
29353 + h_dir = h_root->d_inode;
29354 + if (!base[AuBrWh_BASE].dentry->d_inode) {
29355 + h_path->dentry = base[AuBrWh_BASE].dentry;
29356 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
29357 + } else if (S_ISREG(base[AuBrWh_BASE].dentry->d_inode->i_mode))
29360 + pr_err("unknown %.*s/%.*s exists\n",
29361 + AuDLNPair(h_root), AuDLNPair(base[AuBrWh_BASE].dentry));
29362 + if (unlikely(err))
29365 + h_path->dentry = base[AuBrWh_PLINK].dentry;
29367 + err = au_whdir(h_dir, h_path);
29368 + if (unlikely(err))
29370 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
29372 + au_wh_clean(h_dir, h_path, /*isdir*/1);
29373 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
29375 + h_path->dentry = base[AuBrWh_ORPH].dentry;
29376 + err = au_whdir(h_dir, h_path);
29377 + if (unlikely(err))
29379 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
29386 + * initialize the whiteout base file/dir for @br.
29388 +int au_wh_init(struct au_branch *br, struct super_block *sb)
29391 + const unsigned char do_plink
29392 + = !!au_opt_test(au_mntflags(sb), PLINK);
29393 + struct inode *h_dir;
29394 + struct path path = br->br_path;
29395 + struct dentry *h_root = path.dentry;
29396 + struct au_wbr *wbr = br->br_wbr;
29397 + static const struct qstr base_name[] = {
29398 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
29399 + sizeof(AUFS_BASE_NAME) - 1),
29400 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
29401 + sizeof(AUFS_PLINKDIR_NAME) - 1),
29402 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
29403 + sizeof(AUFS_ORPHDIR_NAME) - 1)
29405 + struct au_wh_base base[] = {
29406 + [AuBrWh_BASE] = {
29407 + .name = base_name + AuBrWh_BASE,
29410 + [AuBrWh_PLINK] = {
29411 + .name = base_name + AuBrWh_PLINK,
29414 + [AuBrWh_ORPH] = {
29415 + .name = base_name + AuBrWh_ORPH,
29421 + WbrWhMustWriteLock(wbr);
29423 + for (i = 0; i < AuBrWh_Last; i++) {
29424 + /* doubly whiteouted */
29425 + struct dentry *d;
29427 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
29428 + err = PTR_ERR(d);
29432 + base[i].dentry = d;
29434 + && wbr->wbr_wh[i]
29435 + && wbr->wbr_wh[i] != base[i].dentry);
29439 + for (i = 0; i < AuBrWh_Last; i++) {
29440 + dput(wbr->wbr_wh[i]);
29441 + wbr->wbr_wh[i] = NULL;
29445 + if (!au_br_writable(br->br_perm)) {
29446 + h_dir = h_root->d_inode;
29447 + au_wh_init_ro(h_dir, base, &path);
29448 + } else if (!au_br_wh_linkable(br->br_perm)) {
29449 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
29455 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
29461 + goto out; /* success */
29464 + pr_err("an error(%d) on the writable branch %.*s(%s)\n",
29465 + err, AuDLNPair(h_root), au_sbtype(h_root->d_sb));
29467 + for (i = 0; i < AuBrWh_Last; i++)
29468 + dput(base[i].dentry);
29472 +/* ---------------------------------------------------------------------- */
29474 + * whiteouts are all hard-linked usually.
29475 + * when its link count reaches a ceiling, we create a new whiteout base
29476 + * asynchronously.
29479 +struct reinit_br_wh {
29480 + struct super_block *sb;
29481 + struct au_branch *br;
29484 +static void reinit_br_wh(void *arg)
29487 + aufs_bindex_t bindex;
29488 + struct path h_path;
29489 + struct reinit_br_wh *a = arg;
29490 + struct au_wbr *wbr;
29491 + struct inode *dir;
29492 + struct dentry *h_root;
29493 + struct au_hinode *hdir;
29496 + wbr = a->br->br_wbr;
29497 + /* big aufs lock */
29498 + si_noflush_write_lock(a->sb);
29499 + if (!au_br_writable(a->br->br_perm))
29501 + bindex = au_br_index(a->sb, a->br->br_id);
29502 + if (unlikely(bindex < 0))
29505 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
29506 + dir = a->sb->s_root->d_inode;
29507 + hdir = au_hi(dir, bindex);
29508 + h_root = au_h_dptr(a->sb->s_root, bindex);
29509 + AuDebugOn(h_root != au_br_dentry(a->br));
29511 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
29512 + wbr_wh_write_lock(wbr);
29513 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
29516 + h_path.dentry = wbr->wbr_whbase;
29517 + h_path.mnt = au_br_mnt(a->br);
29518 + err = vfsub_unlink(hdir->hi_inode, &h_path, /*force*/0);
29520 + pr_warn("%.*s is moved, ignored\n",
29521 + AuDLNPair(wbr->wbr_whbase));
29524 + dput(wbr->wbr_whbase);
29525 + wbr->wbr_whbase = NULL;
29527 + err = au_wh_init(a->br, a->sb);
29528 + wbr_wh_write_unlock(wbr);
29529 + au_hn_imtx_unlock(hdir);
29530 + di_read_unlock(a->sb->s_root, AuLock_IR);
29534 + atomic_dec(&wbr->wbr_wh_running);
29535 + atomic_dec(&a->br->br_count);
29536 + si_write_unlock(a->sb);
29537 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
29539 + if (unlikely(err))
29540 + AuIOErr("err %d\n", err);
29543 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
29545 + int do_dec, wkq_err;
29546 + struct reinit_br_wh *arg;
29549 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
29552 + /* ignore ENOMEM */
29553 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
29556 + * dec(wh_running), kfree(arg) and dec(br_count)
29557 + * in reinit function
29561 + atomic_inc(&br->br_count);
29562 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
29563 + if (unlikely(wkq_err)) {
29564 + atomic_dec(&br->br_wbr->wbr_wh_running);
29565 + atomic_dec(&br->br_count);
29573 + atomic_dec(&br->br_wbr->wbr_wh_running);
29576 +/* ---------------------------------------------------------------------- */
29579 + * create the whiteout @wh.
29581 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
29582 + struct dentry *wh)
29585 + struct path h_path = {
29588 + struct au_branch *br;
29589 + struct au_wbr *wbr;
29590 + struct dentry *h_parent;
29591 + struct inode *h_dir;
29593 + h_parent = wh->d_parent; /* dir inode is locked */
29594 + h_dir = h_parent->d_inode;
29595 + IMustLock(h_dir);
29597 + br = au_sbr(sb, bindex);
29598 + h_path.mnt = au_br_mnt(br);
29599 + wbr = br->br_wbr;
29600 + wbr_wh_read_lock(wbr);
29601 + if (wbr->wbr_whbase) {
29602 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path);
29603 + if (!err || err != -EMLINK)
29606 + /* link count full. re-initialize br_whbase. */
29607 + kick_reinit_br_wh(sb, br);
29610 + /* return this error in this context */
29611 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
29614 + wbr_wh_read_unlock(wbr);
29618 +/* ---------------------------------------------------------------------- */
29621 + * create or remove the diropq.
29623 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
29624 + unsigned int flags)
29626 + struct dentry *opq_dentry, *h_dentry;
29627 + struct super_block *sb;
29628 + struct au_branch *br;
29631 + sb = dentry->d_sb;
29632 + br = au_sbr(sb, bindex);
29633 + h_dentry = au_h_dptr(dentry, bindex);
29634 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
29635 + if (IS_ERR(opq_dentry))
29638 + if (au_ftest_diropq(flags, CREATE)) {
29639 + err = link_or_create_wh(sb, bindex, opq_dentry);
29641 + au_set_dbdiropq(dentry, bindex);
29642 + goto out; /* success */
29645 + struct path tmp = {
29646 + .dentry = opq_dentry,
29647 + .mnt = au_br_mnt(br)
29649 + err = do_unlink_wh(au_h_iptr(dentry->d_inode, bindex), &tmp);
29651 + au_set_dbdiropq(dentry, -1);
29653 + dput(opq_dentry);
29654 + opq_dentry = ERR_PTR(err);
29657 + return opq_dentry;
29660 +struct do_diropq_args {
29661 + struct dentry **errp;
29662 + struct dentry *dentry;
29663 + aufs_bindex_t bindex;
29664 + unsigned int flags;
29667 +static void call_do_diropq(void *args)
29669 + struct do_diropq_args *a = args;
29670 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
29673 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
29674 + unsigned int flags)
29676 + struct dentry *diropq, *h_dentry;
29678 + h_dentry = au_h_dptr(dentry, bindex);
29679 + if (!au_test_h_perm_sio(h_dentry->d_inode, MAY_EXEC | MAY_WRITE))
29680 + diropq = do_diropq(dentry, bindex, flags);
29683 + struct do_diropq_args args = {
29685 + .dentry = dentry,
29686 + .bindex = bindex,
29690 + wkq_err = au_wkq_wait(call_do_diropq, &args);
29691 + if (unlikely(wkq_err))
29692 + diropq = ERR_PTR(wkq_err);
29698 +/* ---------------------------------------------------------------------- */
29701 + * lookup whiteout dentry.
29702 + * @h_parent: lower parent dentry which must exist and be locked
29703 + * @base_name: name of dentry which will be whiteouted
29704 + * returns dentry for whiteout.
29706 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
29707 + struct au_branch *br)
29710 + struct qstr wh_name;
29711 + struct dentry *wh_dentry;
29713 + err = au_wh_name_alloc(&wh_name, base_name);
29714 + wh_dentry = ERR_PTR(err);
29716 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
29717 + kfree(wh_name.name);
29719 + return wh_dentry;
29723 + * link/create a whiteout for @dentry on @bindex.
29725 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
29726 + struct dentry *h_parent)
29728 + struct dentry *wh_dentry;
29729 + struct super_block *sb;
29732 + sb = dentry->d_sb;
29733 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
29734 + if (!IS_ERR(wh_dentry) && !wh_dentry->d_inode) {
29735 + err = link_or_create_wh(sb, bindex, wh_dentry);
29737 + au_set_dbwh(dentry, bindex);
29740 + wh_dentry = ERR_PTR(err);
29744 + return wh_dentry;
29747 +/* ---------------------------------------------------------------------- */
29749 +/* Delete all whiteouts in this directory on branch bindex. */
29750 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
29751 + aufs_bindex_t bindex, struct au_branch *br)
29754 + unsigned long ul, n;
29755 + struct qstr wh_name;
29757 + struct hlist_head *head;
29758 + struct au_vdir_wh *pos;
29759 + struct au_vdir_destr *str;
29762 + p = (void *)__get_free_page(GFP_NOFS);
29763 + wh_name.name = p;
29764 + if (unlikely(!wh_name.name))
29768 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
29769 + p += AUFS_WH_PFX_LEN;
29770 + n = whlist->nh_num;
29771 + head = whlist->nh_head;
29772 + for (ul = 0; !err && ul < n; ul++, head++) {
29773 + hlist_for_each_entry(pos, head, wh_hash) {
29774 + if (pos->wh_bindex != bindex)
29777 + str = &pos->wh_str;
29778 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
29779 + memcpy(p, str->name, str->len);
29780 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
29781 + err = unlink_wh_name(h_dentry, &wh_name, br);
29786 + AuIOErr("whiteout name too long %.*s\n",
29787 + str->len, str->name);
29792 + free_page((unsigned long)wh_name.name);
29798 +struct del_wh_children_args {
29800 + struct dentry *h_dentry;
29801 + struct au_nhash *whlist;
29802 + aufs_bindex_t bindex;
29803 + struct au_branch *br;
29806 +static void call_del_wh_children(void *args)
29808 + struct del_wh_children_args *a = args;
29809 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
29812 +/* ---------------------------------------------------------------------- */
29814 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
29816 + struct au_whtmp_rmdir *whtmp;
29818 + unsigned int rdhash;
29820 + SiMustAnyLock(sb);
29822 + whtmp = kmalloc(sizeof(*whtmp), gfp);
29823 + if (unlikely(!whtmp)) {
29824 + whtmp = ERR_PTR(-ENOMEM);
29828 + whtmp->dir = NULL;
29829 + whtmp->br = NULL;
29830 + whtmp->wh_dentry = NULL;
29831 + /* no estimation for dir size */
29832 + rdhash = au_sbi(sb)->si_rdhash;
29834 + rdhash = AUFS_RDHASH_DEF;
29835 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
29836 + if (unlikely(err)) {
29838 + whtmp = ERR_PTR(err);
29845 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
29848 + atomic_dec(&whtmp->br->br_count);
29849 + dput(whtmp->wh_dentry);
29850 + iput(whtmp->dir);
29851 + au_nhash_wh_free(&whtmp->whlist);
29856 + * rmdir the whiteouted temporary named dir @h_dentry.
29857 + * @whlist: whiteouted children.
29859 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
29860 + struct dentry *wh_dentry, struct au_nhash *whlist)
29863 + struct path h_tmp;
29864 + struct inode *wh_inode, *h_dir;
29865 + struct au_branch *br;
29867 + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
29868 + IMustLock(h_dir);
29870 + br = au_sbr(dir->i_sb, bindex);
29871 + wh_inode = wh_dentry->d_inode;
29872 + mutex_lock_nested(&wh_inode->i_mutex, AuLsc_I_CHILD);
29875 + * someone else might change some whiteouts while we were sleeping.
29876 + * it means this whlist may have an obsoleted entry.
29878 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
29879 + err = del_wh_children(wh_dentry, whlist, bindex, br);
29882 + struct del_wh_children_args args = {
29884 + .h_dentry = wh_dentry,
29885 + .whlist = whlist,
29886 + .bindex = bindex,
29890 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
29891 + if (unlikely(wkq_err))
29894 + mutex_unlock(&wh_inode->i_mutex);
29897 + h_tmp.dentry = wh_dentry;
29898 + h_tmp.mnt = au_br_mnt(br);
29899 + err = vfsub_rmdir(h_dir, &h_tmp);
29903 + if (au_ibstart(dir) == bindex) {
29904 + /* todo: dir->i_mutex is necessary */
29905 + au_cpup_attr_timesizes(dir);
29906 + vfsub_drop_nlink(dir);
29908 + return 0; /* success */
29911 + pr_warn("failed removing %.*s(%d), ignored\n",
29912 + AuDLNPair(wh_dentry), err);
29916 +static void call_rmdir_whtmp(void *args)
29919 + aufs_bindex_t bindex;
29920 + struct au_whtmp_rmdir *a = args;
29921 + struct super_block *sb;
29922 + struct dentry *h_parent;
29923 + struct inode *h_dir;
29924 + struct au_hinode *hdir;
29926 + /* rmdir by nfsd may cause deadlock with this i_mutex */
29927 + /* mutex_lock(&a->dir->i_mutex); */
29929 + sb = a->dir->i_sb;
29930 + si_read_lock(sb, !AuLock_FLUSH);
29931 + if (!au_br_writable(a->br->br_perm))
29933 + bindex = au_br_index(sb, a->br->br_id);
29934 + if (unlikely(bindex < 0))
29938 + ii_write_lock_parent(a->dir);
29939 + h_parent = dget_parent(a->wh_dentry);
29940 + h_dir = h_parent->d_inode;
29941 + hdir = au_hi(a->dir, bindex);
29942 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
29943 + if (unlikely(err))
29945 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
29946 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
29949 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
29950 + au_hn_imtx_unlock(hdir);
29951 + vfsub_mnt_drop_write(au_br_mnt(a->br));
29955 + ii_write_unlock(a->dir);
29957 + /* mutex_unlock(&a->dir->i_mutex); */
29958 + au_whtmp_rmdir_free(a);
29959 + si_read_unlock(sb);
29960 + au_nwt_done(&au_sbi(sb)->si_nowait);
29961 + if (unlikely(err))
29962 + AuIOErr("err %d\n", err);
29965 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
29966 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
29969 + struct super_block *sb;
29973 + /* all post-process will be done in do_rmdir_whtmp(). */
29975 + args->dir = au_igrab(dir);
29976 + args->br = au_sbr(sb, bindex);
29977 + atomic_inc(&args->br->br_count);
29978 + args->wh_dentry = dget(wh_dentry);
29979 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
29980 + if (unlikely(wkq_err)) {
29981 + pr_warn("rmdir error %.*s (%d), ignored\n",
29982 + AuDLNPair(wh_dentry), wkq_err);
29983 + au_whtmp_rmdir_free(args);
29986 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
29987 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
29988 +++ linux/fs/aufs/whout.h 2013-07-06 13:20:47.760198800 +0200
29991 + * Copyright (C) 2005-2013 Junjiro R. Okajima
29993 + * This program, aufs is free software; you can redistribute it and/or modify
29994 + * it under the terms of the GNU General Public License as published by
29995 + * the Free Software Foundation; either version 2 of the License, or
29996 + * (at your option) any later version.
29998 + * This program is distributed in the hope that it will be useful,
29999 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30000 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30001 + * GNU General Public License for more details.
30003 + * You should have received a copy of the GNU General Public License
30004 + * along with this program; if not, write to the Free Software
30005 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30009 + * whiteout for logical deletion and opaque directory
30012 +#ifndef __AUFS_WHOUT_H__
30013 +#define __AUFS_WHOUT_H__
30020 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
30022 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name,
30023 + struct au_branch *br, int try_sio);
30024 +int au_diropq_test(struct dentry *h_dentry, struct au_branch *br);
30025 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
30026 + struct qstr *prefix);
30027 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
30028 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
30029 + struct dentry *dentry);
30030 +int au_wh_init(struct au_branch *br, struct super_block *sb);
30032 +/* diropq flags */
30033 +#define AuDiropq_CREATE 1
30034 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
30035 +#define au_fset_diropq(flags, name) \
30036 + do { (flags) |= AuDiropq_##name; } while (0)
30037 +#define au_fclr_diropq(flags, name) \
30038 + do { (flags) &= ~AuDiropq_##name; } while (0)
30040 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
30041 + unsigned int flags);
30042 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
30043 + struct au_branch *br);
30044 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
30045 + struct dentry *h_parent);
30047 +/* real rmdir for the whiteout-ed dir */
30048 +struct au_whtmp_rmdir {
30049 + struct inode *dir;
30050 + struct au_branch *br;
30051 + struct dentry *wh_dentry;
30052 + struct au_nhash whlist;
30055 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
30056 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
30057 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
30058 + struct dentry *wh_dentry, struct au_nhash *whlist);
30059 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
30060 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
30062 +/* ---------------------------------------------------------------------- */
30064 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
30065 + aufs_bindex_t bindex)
30067 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
30070 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
30072 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
30075 +#endif /* __KERNEL__ */
30076 +#endif /* __AUFS_WHOUT_H__ */
30077 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
30078 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
30079 +++ linux/fs/aufs/wkq.c 2013-08-23 23:59:39.638250372 +0200
30082 + * Copyright (C) 2005-2013 Junjiro R. Okajima
30084 + * This program, aufs is free software; you can redistribute it and/or modify
30085 + * it under the terms of the GNU General Public License as published by
30086 + * the Free Software Foundation; either version 2 of the License, or
30087 + * (at your option) any later version.
30089 + * This program is distributed in the hope that it will be useful,
30090 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30091 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30092 + * GNU General Public License for more details.
30094 + * You should have received a copy of the GNU General Public License
30095 + * along with this program; if not, write to the Free Software
30096 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30100 + * workqueue for asynchronous/super-io operations
30101 + * todo: try new dredential scheme
30104 +#include <linux/module.h>
30107 +/* internal workqueue named AUFS_WKQ_NAME */
30109 +static struct workqueue_struct *au_wkq;
30111 +struct au_wkinfo {
30112 + struct work_struct wk;
30113 + struct kobject *kobj;
30115 + unsigned int flags; /* see wkq.h */
30117 + au_wkq_func_t func;
30120 + struct completion *comp;
30123 +/* ---------------------------------------------------------------------- */
30125 +static void wkq_func(struct work_struct *wk)
30127 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
30129 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
30130 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
30132 + wkinfo->func(wkinfo->args);
30133 + if (au_ftest_wkq(wkinfo->flags, WAIT))
30134 + complete(wkinfo->comp);
30136 + kobject_put(wkinfo->kobj);
30137 + module_put(THIS_MODULE); /* todo: ?? */
30143 + * Since struct completion is large, try allocating it dynamically.
30145 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
30146 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
30148 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
30150 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
30152 + init_completion(*comp);
30153 + wkinfo->comp = *comp;
30159 +static void au_wkq_comp_free(struct completion *comp)
30167 +#define AuWkqCompDeclare(name) \
30168 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
30169 + struct completion *comp = &_ ## name
30171 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
30173 + wkinfo->comp = *comp;
30177 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
30181 +#endif /* 4KSTACKS */
30183 +static void au_wkq_run(struct au_wkinfo *wkinfo)
30185 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
30186 + if (au_wkq_test()) {
30187 + AuWarn1("wkq from wkq, due to a dead dir by UDBA?\n");
30188 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
30191 + au_dbg_verify_kthread();
30193 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
30194 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
30195 + queue_work(au_wkq, &wkinfo->wk);
30197 + INIT_WORK(&wkinfo->wk, wkq_func);
30198 + schedule_work(&wkinfo->wk);
30203 + * Be careful. It is easy to make deadlock happen.
30204 + * processA: lock, wkq and wait
30205 + * processB: wkq and wait, lock in wkq
30208 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
30211 + AuWkqCompDeclare(comp);
30212 + struct au_wkinfo wkinfo = {
30218 + err = au_wkq_comp_alloc(&wkinfo, &comp);
30220 + au_wkq_run(&wkinfo);
30221 + /* no timeout, no interrupt */
30222 + wait_for_completion(wkinfo.comp);
30223 + au_wkq_comp_free(comp);
30224 + destroy_work_on_stack(&wkinfo.wk);
30232 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
30233 + * problem in a concurrent umounting.
30235 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
30236 + unsigned int flags)
30239 + struct au_wkinfo *wkinfo;
30241 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
30244 + * wkq_func() must free this wkinfo.
30245 + * it highly depends upon the implementation of workqueue.
30248 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
30250 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
30251 + wkinfo->flags = flags & ~AuWkq_WAIT;
30252 + wkinfo->func = func;
30253 + wkinfo->args = args;
30254 + wkinfo->comp = NULL;
30255 + kobject_get(wkinfo->kobj);
30256 + __module_get(THIS_MODULE); /* todo: ?? */
30258 + au_wkq_run(wkinfo);
30261 + au_nwt_done(&au_sbi(sb)->si_nowait);
30267 +/* ---------------------------------------------------------------------- */
30269 +void au_nwt_init(struct au_nowait_tasks *nwt)
30271 + atomic_set(&nwt->nw_len, 0);
30272 + /* smp_mb(); */ /* atomic_set */
30273 + init_waitqueue_head(&nwt->nw_wq);
30276 +void au_wkq_fin(void)
30278 + destroy_workqueue(au_wkq);
30281 +int __init au_wkq_init(void)
30286 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
30287 + if (IS_ERR(au_wkq))
30288 + err = PTR_ERR(au_wkq);
30289 + else if (!au_wkq)
30294 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
30295 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
30296 +++ linux/fs/aufs/wkq.h 2013-07-06 13:20:47.760198800 +0200
30299 + * Copyright (C) 2005-2013 Junjiro R. Okajima
30301 + * This program, aufs is free software; you can redistribute it and/or modify
30302 + * it under the terms of the GNU General Public License as published by
30303 + * the Free Software Foundation; either version 2 of the License, or
30304 + * (at your option) any later version.
30306 + * This program is distributed in the hope that it will be useful,
30307 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30308 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30309 + * GNU General Public License for more details.
30311 + * You should have received a copy of the GNU General Public License
30312 + * along with this program; if not, write to the Free Software
30313 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30317 + * workqueue for asynchronous/super-io operations
30318 + * todo: try new credentials management scheme
30321 +#ifndef __AUFS_WKQ_H__
30322 +#define __AUFS_WKQ_H__
30326 +struct super_block;
30328 +/* ---------------------------------------------------------------------- */
30331 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
30333 +struct au_nowait_tasks {
30335 + wait_queue_head_t nw_wq;
30338 +/* ---------------------------------------------------------------------- */
30340 +typedef void (*au_wkq_func_t)(void *args);
30343 +#define AuWkq_WAIT 1
30344 +#define AuWkq_NEST (1 << 1)
30345 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
30346 +#define au_fset_wkq(flags, name) \
30347 + do { (flags) |= AuWkq_##name; } while (0)
30348 +#define au_fclr_wkq(flags, name) \
30349 + do { (flags) &= ~AuWkq_##name; } while (0)
30351 +#ifndef CONFIG_AUFS_HNOTIFY
30353 +#define AuWkq_NEST 0
30357 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
30358 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
30359 + unsigned int flags);
30360 +void au_nwt_init(struct au_nowait_tasks *nwt);
30361 +int __init au_wkq_init(void);
30362 +void au_wkq_fin(void);
30364 +/* ---------------------------------------------------------------------- */
30366 +static inline int au_wkq_test(void)
30368 + return current->flags & PF_WQ_WORKER;
30371 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
30373 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
30376 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
30378 + if (atomic_dec_and_test(&nwt->nw_len))
30379 + wake_up_all(&nwt->nw_wq);
30382 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
30384 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
30388 +#endif /* __KERNEL__ */
30389 +#endif /* __AUFS_WKQ_H__ */
30390 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
30391 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
30392 +++ linux/fs/aufs/xino.c 2013-07-06 13:20:47.760198800 +0200
30395 + * Copyright (C) 2005-2013 Junjiro R. Okajima
30397 + * This program, aufs is free software; you can redistribute it and/or modify
30398 + * it under the terms of the GNU General Public License as published by
30399 + * the Free Software Foundation; either version 2 of the License, or
30400 + * (at your option) any later version.
30402 + * This program is distributed in the hope that it will be useful,
30403 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30404 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30405 + * GNU General Public License for more details.
30407 + * You should have received a copy of the GNU General Public License
30408 + * along with this program; if not, write to the Free Software
30409 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30413 + * external inode number translation table and bitmap
30416 +#include <linux/seq_file.h>
30419 +/* todo: unnecessary to support mmap_sem since kernel-space? */
30420 +ssize_t xino_fread(au_readf_t func, struct file *file, void *kbuf, size_t size,
30424 + mm_segment_t oldfs;
30431 + oldfs = get_fs();
30432 + set_fs(KERNEL_DS);
30434 + /* todo: signal_pending? */
30435 + err = func(file, buf.u, size, pos);
30436 + } while (err == -EAGAIN || err == -EINTR);
30439 +#if 0 /* reserved for future use */
30441 + fsnotify_access(file->f_dentry);
30447 +/* ---------------------------------------------------------------------- */
30449 +static ssize_t do_xino_fwrite(au_writef_t func, struct file *file, void *kbuf,
30450 + size_t size, loff_t *pos)
30453 + mm_segment_t oldfs;
30456 + const char __user *u;
30460 + oldfs = get_fs();
30461 + set_fs(KERNEL_DS);
30463 + /* todo: signal_pending? */
30464 + err = func(file, buf.u, size, pos);
30465 + } while (err == -EAGAIN || err == -EINTR);
30468 +#if 0 /* reserved for future use */
30470 + fsnotify_modify(file->f_dentry);
30476 +struct do_xino_fwrite_args {
30478 + au_writef_t func;
30479 + struct file *file;
30485 +static void call_do_xino_fwrite(void *args)
30487 + struct do_xino_fwrite_args *a = args;
30488 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
30491 +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size,
30496 + /* todo: signal block and no wkq? */
30497 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
30499 + err = do_xino_fwrite(func, file, buf, size, pos);
30503 + * it breaks RLIMIT_FSIZE and normal user's limit,
30504 + * users should care about quota and real 'filesystem full.'
30507 + struct do_xino_fwrite_args args = {
30516 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
30517 + if (unlikely(wkq_err))
30524 +/* ---------------------------------------------------------------------- */
30527 + * create a new xinofile at the same place/path as @base_file.
30529 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src)
30531 + struct file *file;
30532 + struct dentry *base, *parent;
30533 + struct inode *dir;
30534 + struct qstr *name;
30535 + struct path path;
30538 + base = base_file->f_dentry;
30539 + parent = base->d_parent; /* dir inode is locked */
30540 + dir = parent->d_inode;
30543 + file = ERR_PTR(-EINVAL);
30544 + name = &base->d_name;
30545 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
30546 + if (IS_ERR(path.dentry)) {
30547 + file = (void *)path.dentry;
30548 + pr_err("%.*s lookup err %ld\n",
30549 + AuLNPair(name), PTR_ERR(path.dentry));
30553 + /* no need to mnt_want_write() since we call dentry_open() later */
30554 + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL);
30555 + if (unlikely(err)) {
30556 + file = ERR_PTR(err);
30557 + pr_err("%.*s create err %d\n", AuLNPair(name), err);
30561 + path.mnt = base_file->f_path.mnt;
30562 + file = vfsub_dentry_open(&path,
30563 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
30564 + /* | __FMODE_NONOTIFY */);
30565 + if (IS_ERR(file)) {
30566 + pr_err("%.*s open err %ld\n", AuLNPair(name), PTR_ERR(file));
30570 + err = vfsub_unlink(dir, &file->f_path, /*force*/0);
30571 + if (unlikely(err)) {
30572 + pr_err("%.*s unlink err %d\n", AuLNPair(name), err);
30577 + /* no one can touch copy_src xino */
30578 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
30579 + if (unlikely(err)) {
30580 + pr_err("%.*s copy err %d\n", AuLNPair(name), err);
30584 + goto out_dput; /* success */
30588 + file = ERR_PTR(err);
30590 + dput(path.dentry);
30595 +struct au_xino_lock_dir {
30596 + struct au_hinode *hdir;
30597 + struct dentry *parent;
30598 + struct mutex *mtx;
30601 +static void au_xino_lock_dir(struct super_block *sb, struct file *xino,
30602 + struct au_xino_lock_dir *ldir)
30604 + aufs_bindex_t brid, bindex;
30606 + ldir->hdir = NULL;
30608 + brid = au_xino_brid(sb);
30610 + bindex = au_br_index(sb, brid);
30611 + if (bindex >= 0) {
30612 + ldir->hdir = au_hi(sb->s_root->d_inode, bindex);
30613 + au_hn_imtx_lock_nested(ldir->hdir, AuLsc_I_PARENT);
30615 + ldir->parent = dget_parent(xino->f_dentry);
30616 + ldir->mtx = &ldir->parent->d_inode->i_mutex;
30617 + mutex_lock_nested(ldir->mtx, AuLsc_I_PARENT);
30621 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
30624 + au_hn_imtx_unlock(ldir->hdir);
30626 + mutex_unlock(ldir->mtx);
30627 + dput(ldir->parent);
30631 +/* ---------------------------------------------------------------------- */
30633 +/* trucate xino files asynchronously */
30635 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
30638 + aufs_bindex_t bi, bend;
30639 + struct au_branch *br;
30640 + struct file *new_xino, *file;
30641 + struct super_block *h_sb;
30642 + struct au_xino_lock_dir ldir;
30645 + bend = au_sbend(sb);
30646 + if (unlikely(bindex < 0 || bend < bindex))
30648 + br = au_sbr(sb, bindex);
30649 + file = br->br_xino.xi_file;
30653 + au_xino_lock_dir(sb, file, &ldir);
30654 + /* mnt_want_write() is unnecessary here */
30655 + new_xino = au_xino_create2(file, file);
30656 + au_xino_unlock_dir(&ldir);
30657 + err = PTR_ERR(new_xino);
30658 + if (IS_ERR(new_xino))
30662 + br->br_xino.xi_file = new_xino;
30664 + h_sb = au_br_sb(br);
30665 + for (bi = 0; bi <= bend; bi++) {
30666 + if (unlikely(bi == bindex))
30668 + br = au_sbr(sb, bi);
30669 + if (au_br_sb(br) != h_sb)
30672 + fput(br->br_xino.xi_file);
30673 + br->br_xino.xi_file = new_xino;
30674 + get_file(new_xino);
30681 +struct xino_do_trunc_args {
30682 + struct super_block *sb;
30683 + struct au_branch *br;
30686 +static void xino_do_trunc(void *_args)
30688 + struct xino_do_trunc_args *args = _args;
30689 + struct super_block *sb;
30690 + struct au_branch *br;
30691 + struct inode *dir;
30693 + aufs_bindex_t bindex;
30697 + dir = sb->s_root->d_inode;
30700 + si_noflush_write_lock(sb);
30701 + ii_read_lock_parent(dir);
30702 + bindex = au_br_index(sb, br->br_id);
30703 + err = au_xino_trunc(sb, bindex);
30705 + && file_inode(br->br_xino.xi_file)->i_blocks
30706 + >= br->br_xino_upper)
30707 + br->br_xino_upper += AUFS_XINO_TRUNC_STEP;
30709 + ii_read_unlock(dir);
30710 + if (unlikely(err))
30711 + pr_warn("err b%d, upper %llu, (%d)\n",
30712 + bindex, (unsigned long long)br->br_xino_upper, err);
30713 + atomic_dec(&br->br_xino_running);
30714 + atomic_dec(&br->br_count);
30715 + si_write_unlock(sb);
30716 + au_nwt_done(&au_sbi(sb)->si_nowait);
30720 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
30722 + struct xino_do_trunc_args *args;
30725 + if (file_inode(br->br_xino.xi_file)->i_blocks
30726 + < br->br_xino_upper)
30729 + if (atomic_inc_return(&br->br_xino_running) > 1)
30732 + /* lock and kfree() will be called in trunc_xino() */
30733 + args = kmalloc(sizeof(*args), GFP_NOFS);
30734 + if (unlikely(!args)) {
30735 + AuErr1("no memory\n");
30739 + atomic_inc(&br->br_count);
30742 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
30744 + return; /* success */
30746 + pr_err("wkq %d\n", wkq_err);
30747 + atomic_dec(&br->br_count);
30752 + atomic_dec(&br->br_xino_running);
30755 +/* ---------------------------------------------------------------------- */
30757 +static int au_xino_do_write(au_writef_t write, struct file *file,
30758 + ino_t h_ino, ino_t ino)
30764 + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) {
30765 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
30768 + pos *= sizeof(ino);
30769 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos);
30770 + if (sz == sizeof(ino))
30771 + return 0; /* success */
30773 + AuIOErr("write failed (%zd)\n", sz);
30778 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
30779 + * at the position of @h_ino.
30780 + * even if @ino is zero, it is written to the xinofile and means no entry.
30781 + * if the size of the xino file on a specific filesystem exceeds the watermark,
30782 + * try truncating it.
30784 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
30788 + unsigned int mnt_flags;
30789 + struct au_branch *br;
30791 + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max)
30792 + || ((loff_t)-1) > 0);
30793 + SiMustAnyLock(sb);
30795 + mnt_flags = au_mntflags(sb);
30796 + if (!au_opt_test(mnt_flags, XINO))
30799 + br = au_sbr(sb, bindex);
30800 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
30803 + if (au_opt_test(mnt_flags, TRUNC_XINO)
30804 + && au_test_fs_trunc_xino(au_br_sb(br)))
30805 + xino_try_trunc(sb, br);
30806 + return 0; /* success */
30809 + AuIOErr("write failed (%d)\n", err);
30813 +/* ---------------------------------------------------------------------- */
30815 +/* aufs inode number bitmap */
30817 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
30818 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
30822 + AuDebugOn(bit < 0 || page_bits <= bit);
30823 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
30827 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
30829 + AuDebugOn(ino < AUFS_FIRST_INO);
30830 + ino -= AUFS_FIRST_INO;
30831 + *pindex = ino / page_bits;
30832 + *bit = ino % page_bits;
30835 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
30840 + struct au_sbinfo *sbinfo;
30841 + struct file *xib;
30842 + unsigned long *p;
30844 + sbinfo = au_sbi(sb);
30845 + MtxMustLock(&sbinfo->si_xib_mtx);
30846 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
30847 + || !au_opt_test(sbinfo->si_mntflags, XINO));
30849 + if (pindex == sbinfo->si_xib_last_pindex)
30852 + xib = sbinfo->si_xib;
30853 + p = sbinfo->si_xib_buf;
30854 + pos = sbinfo->si_xib_last_pindex;
30855 + pos *= PAGE_SIZE;
30856 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
30857 + if (unlikely(sz != PAGE_SIZE))
30861 + pos *= PAGE_SIZE;
30862 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
30863 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
30865 + memset(p, 0, PAGE_SIZE);
30866 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
30868 + if (sz == PAGE_SIZE) {
30869 + sbinfo->si_xib_last_pindex = pindex;
30870 + return 0; /* success */
30874 + AuIOErr1("write failed (%zd)\n", sz);
30881 +/* ---------------------------------------------------------------------- */
30883 +static void au_xib_clear_bit(struct inode *inode)
30886 + unsigned long pindex;
30887 + struct super_block *sb;
30888 + struct au_sbinfo *sbinfo;
30890 + AuDebugOn(inode->i_nlink);
30892 + sb = inode->i_sb;
30893 + xib_calc_bit(inode->i_ino, &pindex, &bit);
30894 + AuDebugOn(page_bits <= bit);
30895 + sbinfo = au_sbi(sb);
30896 + mutex_lock(&sbinfo->si_xib_mtx);
30897 + err = xib_pindex(sb, pindex);
30899 + clear_bit(bit, sbinfo->si_xib_buf);
30900 + sbinfo->si_xib_next_bit = bit;
30902 + mutex_unlock(&sbinfo->si_xib_mtx);
30905 +/* for s_op->delete_inode() */
30906 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
30909 + unsigned int mnt_flags;
30910 + aufs_bindex_t bindex, bend, bi;
30911 + unsigned char try_trunc;
30912 + struct au_iinfo *iinfo;
30913 + struct super_block *sb;
30914 + struct au_hinode *hi;
30915 + struct inode *h_inode;
30916 + struct au_branch *br;
30917 + au_writef_t xwrite;
30919 + sb = inode->i_sb;
30920 + mnt_flags = au_mntflags(sb);
30921 + if (!au_opt_test(mnt_flags, XINO)
30922 + || inode->i_ino == AUFS_ROOT_INO)
30926 + au_xigen_inc(inode);
30927 + au_xib_clear_bit(inode);
30930 + iinfo = au_ii(inode);
30934 + bindex = iinfo->ii_bstart;
30938 + xwrite = au_sbi(sb)->si_xwrite;
30939 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
30940 + hi = iinfo->ii_hinode + bindex;
30941 + bend = iinfo->ii_bend;
30942 + for (; bindex <= bend; bindex++, hi++) {
30943 + h_inode = hi->hi_inode;
30945 + || (!unlinked && h_inode->i_nlink))
30948 + /* inode may not be revalidated */
30949 + bi = au_br_index(sb, hi->hi_id);
30953 + br = au_sbr(sb, bi);
30954 + err = au_xino_do_write(xwrite, br->br_xino.xi_file,
30955 + h_inode->i_ino, /*ino*/0);
30956 + if (!err && try_trunc
30957 + && au_test_fs_trunc_xino(au_br_sb(br)))
30958 + xino_try_trunc(sb, br);
30962 +/* get an unused inode number from bitmap */
30963 +ino_t au_xino_new_ino(struct super_block *sb)
30966 + unsigned long *p, pindex, ul, pend;
30967 + struct au_sbinfo *sbinfo;
30968 + struct file *file;
30969 + int free_bit, err;
30971 + if (!au_opt_test(au_mntflags(sb), XINO))
30972 + return iunique(sb, AUFS_FIRST_INO);
30974 + sbinfo = au_sbi(sb);
30975 + mutex_lock(&sbinfo->si_xib_mtx);
30976 + p = sbinfo->si_xib_buf;
30977 + free_bit = sbinfo->si_xib_next_bit;
30978 + if (free_bit < page_bits && !test_bit(free_bit, p))
30979 + goto out; /* success */
30980 + free_bit = find_first_zero_bit(p, page_bits);
30981 + if (free_bit < page_bits)
30982 + goto out; /* success */
30984 + pindex = sbinfo->si_xib_last_pindex;
30985 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
30986 + err = xib_pindex(sb, ul);
30987 + if (unlikely(err))
30989 + free_bit = find_first_zero_bit(p, page_bits);
30990 + if (free_bit < page_bits)
30991 + goto out; /* success */
30994 + file = sbinfo->si_xib;
30995 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
30996 + for (ul = pindex + 1; ul <= pend; ul++) {
30997 + err = xib_pindex(sb, ul);
30998 + if (unlikely(err))
31000 + free_bit = find_first_zero_bit(p, page_bits);
31001 + if (free_bit < page_bits)
31002 + goto out; /* success */
31007 + set_bit(free_bit, p);
31008 + sbinfo->si_xib_next_bit = free_bit + 1;
31009 + pindex = sbinfo->si_xib_last_pindex;
31010 + mutex_unlock(&sbinfo->si_xib_mtx);
31011 + ino = xib_calc_ino(pindex, free_bit);
31012 + AuDbg("i%lu\n", (unsigned long)ino);
31015 + mutex_unlock(&sbinfo->si_xib_mtx);
31021 + * read @ino from xinofile for the specified branch{@sb, @bindex}
31022 + * at the position of @h_ino.
31023 + * if @ino does not exist and @do_new is true, get new one.
31025 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
31031 + struct file *file;
31032 + struct au_sbinfo *sbinfo;
31035 + if (!au_opt_test(au_mntflags(sb), XINO))
31036 + return 0; /* no xino */
31039 + sbinfo = au_sbi(sb);
31041 + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) {
31042 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
31045 + pos *= sizeof(*ino);
31047 + file = au_sbr(sb, bindex)->br_xino.xi_file;
31048 + if (vfsub_f_size_read(file) < pos + sizeof(*ino))
31049 + return 0; /* no ino */
31051 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
31052 + if (sz == sizeof(*ino))
31053 + return 0; /* success */
31056 + if (unlikely(sz >= 0)) {
31058 + AuIOErr("xino read error (%zd)\n", sz);
31064 +/* ---------------------------------------------------------------------- */
31066 +/* create and set a new xino file */
31068 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent)
31070 + struct file *file;
31071 + struct dentry *h_parent, *d;
31072 + struct inode *h_dir;
31076 + * at mount-time, and the xino file is the default path,
31077 + * hnotify is disabled so we have no notify events to ignore.
31078 + * when a user specified the xino, we cannot get au_hdir to be ignored.
31080 + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
31081 + /* | __FMODE_NONOTIFY */,
31082 + S_IRUGO | S_IWUGO);
31083 + if (IS_ERR(file)) {
31085 + pr_err("open %s(%ld)\n", fname, PTR_ERR(file));
31089 + /* keep file count */
31090 + h_parent = dget_parent(file->f_dentry);
31091 + h_dir = h_parent->d_inode;
31092 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
31093 + /* mnt_want_write() is unnecessary here */
31094 + err = vfsub_unlink(h_dir, &file->f_path, /*force*/0);
31095 + mutex_unlock(&h_dir->i_mutex);
31097 + if (unlikely(err)) {
31099 + pr_err("unlink %s(%d)\n", fname, err);
31104 + d = file->f_dentry;
31105 + if (unlikely(sb == d->d_sb)) {
31107 + pr_err("%s must be outside\n", fname);
31110 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
31112 + pr_err("xino doesn't support %s(%s)\n",
31113 + fname, au_sbtype(d->d_sb));
31116 + return file; /* success */
31120 + file = ERR_PTR(err);
31125 + * find another branch who is on the same filesystem of the specified
31126 + * branch{@btgt}. search until @bend.
31128 +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
31129 + aufs_bindex_t bend)
31131 + aufs_bindex_t bindex;
31132 + struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
31134 + for (bindex = 0; bindex < btgt; bindex++)
31135 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
31137 + for (bindex++; bindex <= bend; bindex++)
31138 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
31143 +/* ---------------------------------------------------------------------- */
31146 + * initialize the xinofile for the specified branch @br
31147 + * at the place/path where @base_file indicates.
31148 + * test whether another branch is on the same filesystem or not,
31149 + * if @do_test is true.
31151 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
31152 + struct file *base_file, int do_test)
31156 + aufs_bindex_t bend, bindex;
31157 + struct au_branch *shared_br, *b;
31158 + struct file *file;
31159 + struct super_block *tgt_sb;
31161 + shared_br = NULL;
31162 + bend = au_sbend(sb);
31164 + tgt_sb = au_br_sb(br);
31165 + for (bindex = 0; bindex <= bend; bindex++) {
31166 + b = au_sbr(sb, bindex);
31167 + if (tgt_sb == au_br_sb(b)) {
31174 + if (!shared_br || !shared_br->br_xino.xi_file) {
31175 + struct au_xino_lock_dir ldir;
31177 + au_xino_lock_dir(sb, base_file, &ldir);
31178 + /* mnt_want_write() is unnecessary here */
31179 + file = au_xino_create2(base_file, NULL);
31180 + au_xino_unlock_dir(&ldir);
31181 + err = PTR_ERR(file);
31182 + if (IS_ERR(file))
31184 + br->br_xino.xi_file = file;
31186 + br->br_xino.xi_file = shared_br->br_xino.xi_file;
31187 + get_file(br->br_xino.xi_file);
31190 + ino = AUFS_ROOT_INO;
31191 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
31193 + if (unlikely(err)) {
31194 + fput(br->br_xino.xi_file);
31195 + br->br_xino.xi_file = NULL;
31202 +/* ---------------------------------------------------------------------- */
31204 +/* trucate a xino bitmap file */
31207 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
31211 + unsigned long pindex;
31212 + loff_t pos, pend;
31213 + struct au_sbinfo *sbinfo;
31216 + unsigned long *p;
31219 + sbinfo = au_sbi(sb);
31220 + MtxMustLock(&sbinfo->si_xib_mtx);
31221 + p = sbinfo->si_xib_buf;
31222 + func = sbinfo->si_xread;
31223 + pend = vfsub_f_size_read(file);
31225 + while (pos < pend) {
31226 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
31228 + if (unlikely(sz <= 0))
31232 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
31233 + if (unlikely(*ino < AUFS_FIRST_INO))
31236 + xib_calc_bit(*ino, &pindex, &bit);
31237 + AuDebugOn(page_bits <= bit);
31238 + err = xib_pindex(sb, pindex);
31250 +static int xib_restore(struct super_block *sb)
31253 + aufs_bindex_t bindex, bend;
31257 + page = (void *)__get_free_page(GFP_NOFS);
31258 + if (unlikely(!page))
31262 + bend = au_sbend(sb);
31263 + for (bindex = 0; !err && bindex <= bend; bindex++)
31264 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
31265 + err = do_xib_restore
31266 + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page);
31268 + AuDbg("b%d\n", bindex);
31269 + free_page((unsigned long)page);
31275 +int au_xib_trunc(struct super_block *sb)
31280 + struct au_xino_lock_dir ldir;
31281 + struct au_sbinfo *sbinfo;
31282 + unsigned long *p;
31283 + struct file *file;
31285 + SiMustWriteLock(sb);
31288 + sbinfo = au_sbi(sb);
31289 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
31292 + file = sbinfo->si_xib;
31293 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
31296 + au_xino_lock_dir(sb, file, &ldir);
31297 + /* mnt_want_write() is unnecessary here */
31298 + file = au_xino_create2(sbinfo->si_xib, NULL);
31299 + au_xino_unlock_dir(&ldir);
31300 + err = PTR_ERR(file);
31301 + if (IS_ERR(file))
31303 + fput(sbinfo->si_xib);
31304 + sbinfo->si_xib = file;
31306 + p = sbinfo->si_xib_buf;
31307 + memset(p, 0, PAGE_SIZE);
31309 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
31310 + if (unlikely(sz != PAGE_SIZE)) {
31312 + AuIOErr("err %d\n", err);
31318 + mutex_lock(&sbinfo->si_xib_mtx);
31319 + /* mnt_want_write() is unnecessary here */
31320 + err = xib_restore(sb);
31321 + mutex_unlock(&sbinfo->si_xib_mtx);
31327 +/* ---------------------------------------------------------------------- */
31330 + * xino mount option handlers
31332 +static au_readf_t find_readf(struct file *h_file)
31334 + const struct file_operations *fop = h_file->f_op;
31338 + return fop->read;
31339 + if (fop->aio_read)
31340 + return do_sync_read;
31342 + return ERR_PTR(-ENOSYS);
31345 +static au_writef_t find_writef(struct file *h_file)
31347 + const struct file_operations *fop = h_file->f_op;
31351 + return fop->write;
31352 + if (fop->aio_write)
31353 + return do_sync_write;
31355 + return ERR_PTR(-ENOSYS);
31359 +static void xino_clear_xib(struct super_block *sb)
31361 + struct au_sbinfo *sbinfo;
31363 + SiMustWriteLock(sb);
31365 + sbinfo = au_sbi(sb);
31366 + sbinfo->si_xread = NULL;
31367 + sbinfo->si_xwrite = NULL;
31368 + if (sbinfo->si_xib)
31369 + fput(sbinfo->si_xib);
31370 + sbinfo->si_xib = NULL;
31371 + free_page((unsigned long)sbinfo->si_xib_buf);
31372 + sbinfo->si_xib_buf = NULL;
31375 +static int au_xino_set_xib(struct super_block *sb, struct file *base)
31379 + struct au_sbinfo *sbinfo;
31380 + struct file *file;
31382 + SiMustWriteLock(sb);
31384 + sbinfo = au_sbi(sb);
31385 + file = au_xino_create2(base, sbinfo->si_xib);
31386 + err = PTR_ERR(file);
31387 + if (IS_ERR(file))
31389 + if (sbinfo->si_xib)
31390 + fput(sbinfo->si_xib);
31391 + sbinfo->si_xib = file;
31392 + sbinfo->si_xread = find_readf(file);
31393 + sbinfo->si_xwrite = find_writef(file);
31396 + if (!sbinfo->si_xib_buf)
31397 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
31398 + if (unlikely(!sbinfo->si_xib_buf))
31401 + sbinfo->si_xib_last_pindex = 0;
31402 + sbinfo->si_xib_next_bit = 0;
31403 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
31405 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
31406 + PAGE_SIZE, &pos);
31407 + if (unlikely(err != PAGE_SIZE))
31411 + goto out; /* success */
31414 + free_page((unsigned long)sbinfo->si_xib_buf);
31415 + sbinfo->si_xib_buf = NULL;
31419 + fput(sbinfo->si_xib);
31420 + sbinfo->si_xib = NULL;
31421 + sbinfo->si_xread = NULL;
31422 + sbinfo->si_xwrite = NULL;
31427 +/* xino for each branch */
31428 +static void xino_clear_br(struct super_block *sb)
31430 + aufs_bindex_t bindex, bend;
31431 + struct au_branch *br;
31433 + bend = au_sbend(sb);
31434 + for (bindex = 0; bindex <= bend; bindex++) {
31435 + br = au_sbr(sb, bindex);
31436 + if (!br || !br->br_xino.xi_file)
31439 + fput(br->br_xino.xi_file);
31440 + br->br_xino.xi_file = NULL;
31444 +static int au_xino_set_br(struct super_block *sb, struct file *base)
31448 + aufs_bindex_t bindex, bend, bshared;
31450 + struct file *old, *new;
31452 + struct au_branch *br;
31453 + struct inode *inode;
31454 + au_writef_t writef;
31456 + SiMustWriteLock(sb);
31459 + bend = au_sbend(sb);
31460 + fpair = kcalloc(bend + 1, sizeof(*fpair), GFP_NOFS);
31461 + if (unlikely(!fpair))
31464 + inode = sb->s_root->d_inode;
31465 + ino = AUFS_ROOT_INO;
31466 + writef = au_sbi(sb)->si_xwrite;
31467 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
31468 + br = au_sbr(sb, bindex);
31469 + bshared = is_sb_shared(sb, bindex, bindex - 1);
31470 + if (bshared >= 0) {
31471 + /* shared xino */
31472 + *p = fpair[bshared];
31473 + get_file(p->new);
31478 + p->old = br->br_xino.xi_file;
31479 + p->new = au_xino_create2(base, br->br_xino.xi_file);
31480 + err = PTR_ERR(p->new);
31481 + if (IS_ERR(p->new)) {
31487 + err = au_xino_do_write(writef, p->new,
31488 + au_h_iptr(inode, bindex)->i_ino, ino);
31489 + if (unlikely(err))
31493 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
31494 + br = au_sbr(sb, bindex);
31495 + if (br->br_xino.xi_file)
31496 + fput(br->br_xino.xi_file);
31497 + get_file(p->new);
31498 + br->br_xino.xi_file = p->new;
31502 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++)
31512 +void au_xino_clr(struct super_block *sb)
31514 + struct au_sbinfo *sbinfo;
31516 + au_xigen_clr(sb);
31517 + xino_clear_xib(sb);
31518 + xino_clear_br(sb);
31519 + sbinfo = au_sbi(sb);
31520 + /* lvalue, do not call au_mntflags() */
31521 + au_opt_clr(sbinfo->si_mntflags, XINO);
31524 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
31527 + struct dentry *parent, *cur_parent;
31528 + struct qstr *dname, *cur_name;
31529 + struct file *cur_xino;
31530 + struct inode *dir;
31531 + struct au_sbinfo *sbinfo;
31533 + SiMustWriteLock(sb);
31536 + sbinfo = au_sbi(sb);
31537 + parent = dget_parent(xino->file->f_dentry);
31540 + dname = &xino->file->f_dentry->d_name;
31541 + cur_xino = sbinfo->si_xib;
31543 + cur_parent = dget_parent(cur_xino->f_dentry);
31544 + cur_name = &cur_xino->f_dentry->d_name;
31545 + skip = (cur_parent == parent
31546 + && dname->len == cur_name->len
31547 + && !memcmp(dname->name, cur_name->name,
31549 + dput(cur_parent);
31555 + au_opt_set(sbinfo->si_mntflags, XINO);
31556 + dir = parent->d_inode;
31557 + mutex_lock_nested(&dir->i_mutex, AuLsc_I_PARENT);
31558 + /* mnt_want_write() is unnecessary here */
31559 + err = au_xino_set_xib(sb, xino->file);
31561 + err = au_xigen_set(sb, xino->file);
31563 + err = au_xino_set_br(sb, xino->file);
31564 + mutex_unlock(&dir->i_mutex);
31566 + goto out; /* success */
31569 + AuIOErr("failed creating xino(%d).\n", err);
31576 +/* ---------------------------------------------------------------------- */
31579 + * create a xinofile at the default place/path.
31581 +struct file *au_xino_def(struct super_block *sb)
31583 + struct file *file;
31585 + struct au_branch *br;
31586 + struct super_block *h_sb;
31587 + struct path path;
31588 + aufs_bindex_t bend, bindex, bwr;
31591 + bend = au_sbend(sb);
31593 + for (bindex = 0; bindex <= bend; bindex++) {
31594 + br = au_sbr(sb, bindex);
31595 + if (au_br_writable(br->br_perm)
31596 + && !au_test_fs_bad_xino(au_br_sb(br))) {
31603 + file = ERR_PTR(-ENOMEM);
31604 + page = (void *)__get_free_page(GFP_NOFS);
31605 + if (unlikely(!page))
31607 + path.mnt = au_br_mnt(br);
31608 + path.dentry = au_h_dptr(sb->s_root, bwr);
31609 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
31610 + file = (void *)p;
31611 + if (!IS_ERR(p)) {
31612 + strcat(p, "/" AUFS_XINO_FNAME);
31613 + AuDbg("%s\n", p);
31614 + file = au_xino_create(sb, p, /*silent*/0);
31615 + if (!IS_ERR(file))
31616 + au_xino_brid_set(sb, br->br_id);
31618 + free_page((unsigned long)page);
31620 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
31621 + if (IS_ERR(file))
31623 + h_sb = file->f_dentry->d_sb;
31624 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
31625 + pr_err("xino doesn't support %s(%s)\n",
31626 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
31628 + file = ERR_PTR(-EINVAL);
31630 + if (!IS_ERR(file))
31631 + au_xino_brid_set(sb, -1);
31638 +/* ---------------------------------------------------------------------- */
31640 +int au_xino_path(struct seq_file *seq, struct file *file)
31644 + err = au_seq_path(seq, &file->f_path);
31645 + if (unlikely(err < 0))
31649 +#define Deleted "\\040(deleted)"
31650 + seq->count -= sizeof(Deleted) - 1;
31651 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
31652 + sizeof(Deleted) - 1));
31658 diff -urN /usr/share/empty/include/linux/aufs_type.h linux/include/linux/aufs_type.h
31659 --- /usr/share/empty/include/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
31660 +++ linux/include/linux/aufs_type.h 2013-07-06 13:20:47.760198800 +0200
31663 + * Copyright (C) 2012-2013 Junjiro R. Okajima
31665 + * This program, aufs is free software; you can redistribute it and/or modify
31666 + * it under the terms of the GNU General Public License as published by
31667 + * the Free Software Foundation; either version 2 of the License, or
31668 + * (at your option) any later version.
31670 + * This program is distributed in the hope that it will be useful,
31671 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31672 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31673 + * GNU General Public License for more details.
31675 + * You should have received a copy of the GNU General Public License
31676 + * along with this program; if not, write to the Free Software
31677 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31680 +#include <uapi/linux/aufs_type.h>
31681 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
31682 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
31683 +++ linux/include/uapi/linux/aufs_type.h 2013-08-23 23:59:39.638250372 +0200
31686 + * Copyright (C) 2005-2013 Junjiro R. Okajima
31688 + * This program, aufs is free software; you can redistribute it and/or modify
31689 + * it under the terms of the GNU General Public License as published by
31690 + * the Free Software Foundation; either version 2 of the License, or
31691 + * (at your option) any later version.
31693 + * This program is distributed in the hope that it will be useful,
31694 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31695 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31696 + * GNU General Public License for more details.
31698 + * You should have received a copy of the GNU General Public License
31699 + * along with this program; if not, write to the Free Software
31700 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31703 +#ifndef __AUFS_TYPE_H__
31704 +#define __AUFS_TYPE_H__
31706 +#define AUFS_NAME "aufs"
31710 + * define it before including all other headers.
31711 + * sched.h may use pr_* macros before defining "current", so define the
31712 + * no-current version first, and re-define later.
31714 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
31715 +#include <linux/sched.h>
31717 +#define pr_fmt(fmt) \
31718 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
31719 + (int)sizeof(current->comm), current->comm, current->pid
31721 +#include <stdint.h>
31722 +#include <sys/types.h>
31723 +#endif /* __KERNEL__ */
31725 +#include <linux/limits.h>
31727 +#define AUFS_VERSION "3.10-20130819"
31729 +/* todo? move this to linux-2.6.19/include/magic.h */
31730 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
31732 +/* ---------------------------------------------------------------------- */
31734 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
31735 +typedef int8_t aufs_bindex_t;
31736 +#define AUFS_BRANCH_MAX 127
31738 +typedef int16_t aufs_bindex_t;
31739 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
31740 +#define AUFS_BRANCH_MAX 511
31741 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
31742 +#define AUFS_BRANCH_MAX 1023
31743 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
31744 +#define AUFS_BRANCH_MAX 32767
31749 +#ifndef AUFS_BRANCH_MAX
31750 +#error unknown CONFIG_AUFS_BRANCH_MAX value
31752 +#endif /* __KERNEL__ */
31754 +/* ---------------------------------------------------------------------- */
31756 +#define AUFS_FSTYPE AUFS_NAME
31758 +#define AUFS_ROOT_INO 2
31759 +#define AUFS_FIRST_INO 11
31761 +#define AUFS_WH_PFX ".wh."
31762 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
31763 +#define AUFS_WH_TMP_LEN 4
31764 +/* a limit for rmdir/rename a dir and copyup */
31765 +#define AUFS_MAX_NAMELEN (NAME_MAX \
31766 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
31768 + - AUFS_WH_TMP_LEN) /* hex */
31769 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
31770 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
31771 +#define AUFS_XINO_TRUNC_INIT 64 /* blocks */
31772 +#define AUFS_XINO_TRUNC_STEP 4 /* blocks */
31773 +#define AUFS_DIRWH_DEF 3
31774 +#define AUFS_RDCACHE_DEF 10 /* seconds */
31775 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
31776 +#define AUFS_RDBLK_DEF 512 /* bytes */
31777 +#define AUFS_RDHASH_DEF 32
31778 +#define AUFS_WKQ_NAME AUFS_NAME "d"
31779 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
31780 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
31781 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
31783 +/* pseudo-link maintenace under /proc */
31784 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
31785 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
31786 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
31788 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
31789 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
31791 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
31792 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
31793 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
31795 +/* doubly whiteouted */
31796 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
31797 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
31798 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
31800 +/* branch permissions and attributes */
31801 +#define AUFS_BRPERM_RW "rw"
31802 +#define AUFS_BRPERM_RO "ro"
31803 +#define AUFS_BRPERM_RR "rr"
31804 +#define AUFS_BRRATTR_WH "wh"
31805 +#define AUFS_BRWATTR_NLWH "nolwh"
31806 +#define AUFS_BRATTR_UNPIN "unpin"
31808 +/* ---------------------------------------------------------------------- */
31812 + /* readdir in userspace */
31816 + /* pathconf wrapper */
31826 +/* borrowed from linux/include/linux/kernel.h */
31828 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
31829 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
31832 +/* borrowed from linux/include/linux/compiler-gcc3.h */
31834 +#define __aligned(x) __attribute__((aligned(x)))
31839 +#define __packed __attribute__((packed))
31843 +struct au_rdu_cookie {
31848 + uint32_t generation;
31851 +struct au_rdu_ent {
31860 +static inline int au_rdu_len(int nlen)
31862 + /* include the terminating NULL */
31863 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
31864 + sizeof(uint64_t));
31867 +union au_rdu_ent_ul {
31868 + struct au_rdu_ent __user *e;
31880 + uint64_t sz; /* AuCtl_RDU */
31881 + uint64_t nent; /* AuCtl_RDU_INO */
31883 + union au_rdu_ent_ul ent;
31884 + uint16_t verify[AufsCtlRduV_End];
31886 + /* input/output */
31890 + union au_rdu_ent_ul tail;
31891 + /* number of entries which were added in a single call */
31896 + struct au_rdu_cookie cookie;
31899 +/* ---------------------------------------------------------------------- */
31901 +struct aufs_wbr_fd {
31906 +/* ---------------------------------------------------------------------- */
31908 +struct aufs_ibusy {
31909 + uint64_t ino, h_ino;
31913 +/* ---------------------------------------------------------------------- */
31915 +/* flags for move-down */
31916 +#define AUFS_MVDOWN_VERBOSE 1
31917 +/* will be added more */
31919 +struct aufs_mvdown {
31921 + /* will be added more */
31924 +/* ---------------------------------------------------------------------- */
31926 +#define AuCtlType 'A'
31927 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
31928 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
31929 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
31930 + struct aufs_wbr_fd)
31931 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
31932 +#define AUFS_CTL_MVDOWN _IOR(AuCtlType, AuCtl_MVDOWN, \
31933 + struct aufs_mvdown)
31935 +#endif /* __AUFS_TYPE_H__ */