1 aufs3.x-rcN kbuild patch
3 diff --git a/fs/Kconfig b/fs/Kconfig
4 index d621f02..9b9694c 100644
7 @@ -215,6 +215,7 @@ source "fs/pstore/Kconfig"
8 source "fs/sysv/Kconfig"
9 source "fs/ufs/Kconfig"
10 source "fs/exofs/Kconfig"
11 +source "fs/aufs/Kconfig"
13 endif # MISC_FILESYSTEMS
15 diff --git a/fs/Makefile b/fs/Makefile
16 index 93804d4..cf3dcb9 100644
19 @@ -124,3 +124,4 @@ obj-$(CONFIG_GFS2_FS) += gfs2/
20 obj-y += exofs/ # Multiple modules
21 obj-$(CONFIG_CEPH_FS) += ceph/
22 obj-$(CONFIG_PSTORE) += pstore/
23 +obj-$(CONFIG_AUFS_FS) += aufs/
24 diff --git a/include/linux/Kbuild b/include/linux/Kbuild
25 index c94e717..fccb9df 100644
26 --- a/include/linux/Kbuild
27 +++ b/include/linux/Kbuild
28 @@ -65,6 +65,7 @@ header-y += atmppp.h
32 +header-y += aufs_type.h
34 header-y += auto_fs4.h
36 aufs3.x-rcN base patch
38 diff --git a/fs/namei.c b/fs/namei.c
39 index e2ba628..fde8ea2 100644
42 @@ -1781,7 +1781,7 @@ static struct dentry *__lookup_hash(struct qstr *name,
43 * needs parent already locked. Doesn't follow mounts.
46 -static struct dentry *lookup_hash(struct nameidata *nd)
47 +struct dentry *lookup_hash(struct nameidata *nd)
49 return __lookup_hash(&nd->last, nd->path.dentry, nd);
51 diff --git a/fs/splice.c b/fs/splice.c
52 index 1ec0493..c599f73 100644
55 @@ -1084,8 +1084,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 @@ -1112,9 +1112,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/namei.h b/include/linux/namei.h
80 index ffc0213..ef35a31 100644
81 --- a/include/linux/namei.h
82 +++ b/include/linux/namei.h
83 @@ -85,6 +85,7 @@ extern int vfs_path_lookup(struct dentry *, struct vfsmount *,
84 extern struct file *lookup_instantiate_filp(struct nameidata *nd, struct dentry *dentry,
85 int (*open)(struct inode *, struct file *));
87 +extern struct dentry *lookup_hash(struct nameidata *nd);
88 extern struct dentry *lookup_one_len(const char *, struct dentry *, int);
90 extern int follow_down_one(struct path *);
91 diff --git a/include/linux/splice.h b/include/linux/splice.h
92 index 26e5b61..3ffef2f 100644
93 --- a/include/linux/splice.h
94 +++ b/include/linux/splice.h
95 @@ -91,4 +91,10 @@ extern void splice_shrink_spd(struct pipe_inode_info *,
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.x-rcN standalone patch
108 diff --git a/fs/file_table.c b/fs/file_table.c
109 index 20002e3..6d792ad 100644
110 --- a/fs/file_table.c
111 +++ b/fs/file_table.c
112 @@ -443,6 +443,8 @@ void file_sb_list_del(struct file *file)
116 +EXPORT_SYMBOL(file_sb_list_del);
121 diff --git a/fs/inode.c b/fs/inode.c
122 index d3ebdbe..6db6251 100644
125 @@ -66,6 +66,7 @@ static struct hlist_head *inode_hashtable __read_mostly;
126 static __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_hash_lock);
128 __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_sb_list_lock);
129 +EXPORT_SYMBOL(inode_sb_list_lock);
132 * Empty aops. Can be used for the cases where the user does not
133 diff --git a/fs/namei.c b/fs/namei.c
134 index fde8ea2..62f2302 100644
137 @@ -1785,6 +1785,7 @@ struct dentry *lookup_hash(struct nameidata *nd)
139 return __lookup_hash(&nd->last, nd->path.dentry, nd);
141 +EXPORT_SYMBOL(lookup_hash);
144 * lookup_one_len - filesystem helper to lookup single pathname component
145 diff --git a/fs/namespace.c b/fs/namespace.c
146 index e608199..38fcc2e 100644
149 @@ -1339,6 +1339,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
153 +EXPORT_SYMBOL(iterate_mounts);
155 static void cleanup_group_ids(struct mount *mnt, struct mount *end)
157 diff --git a/fs/notify/group.c b/fs/notify/group.c
158 index 63fc294..6f4adca 100644
159 --- a/fs/notify/group.c
160 +++ b/fs/notify/group.c
162 #include <linux/srcu.h>
163 #include <linux/rculist.h>
164 #include <linux/wait.h>
165 +#include <linux/module.h>
167 #include <linux/fsnotify_backend.h>
168 #include "fsnotify.h"
169 @@ -70,6 +71,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
170 if (atomic_dec_and_test(&group->refcnt))
171 fsnotify_destroy_group(group);
173 +EXPORT_SYMBOL(fsnotify_put_group);
176 * Create a new fsnotify_group and hold a reference for the group returned.
177 @@ -102,3 +104,4 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
181 +EXPORT_SYMBOL(fsnotify_alloc_group);
182 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
183 index f104d56..54f36db 100644
184 --- a/fs/notify/mark.c
185 +++ b/fs/notify/mark.c
186 @@ -112,6 +112,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
187 if (atomic_dec_and_test(&mark->refcnt))
188 mark->free_mark(mark);
190 +EXPORT_SYMBOL(fsnotify_put_mark);
193 * Any time a mark is getting freed we end up here.
194 @@ -191,6 +192,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark)
195 if (unlikely(atomic_dec_and_test(&group->num_marks)))
196 fsnotify_final_destroy_group(group);
198 +EXPORT_SYMBOL(fsnotify_destroy_mark);
200 void fsnotify_set_mark_mask_locked(struct fsnotify_mark *mark, __u32 mask)
202 @@ -278,6 +280,7 @@ err:
206 +EXPORT_SYMBOL(fsnotify_add_mark);
209 * clear any marks in a group in which mark->flags & flags is true
210 @@ -333,6 +336,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
211 atomic_set(&mark->refcnt, 1);
212 mark->free_mark = free_mark;
214 +EXPORT_SYMBOL(fsnotify_init_mark);
216 static int fsnotify_mark_destroy(void *ignored)
218 diff --git a/fs/open.c b/fs/open.c
219 index 77becc0..f634f02 100644
222 @@ -60,6 +60,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
223 mutex_unlock(&dentry->d_inode->i_mutex);
226 +EXPORT_SYMBOL(do_truncate);
228 static long do_sys_truncate(const char __user *pathname, loff_t length)
230 diff --git a/fs/splice.c b/fs/splice.c
231 index c599f73..00303ba 100644
234 @@ -1108,6 +1108,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
236 return splice_write(pipe, out, ppos, len, flags);
238 +EXPORT_SYMBOL(do_splice_from);
241 * Attempt to initiate a splice from a file to a pipe.
242 @@ -1134,6 +1135,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
244 return splice_read(in, ppos, pipe, len, flags);
246 +EXPORT_SYMBOL(do_splice_to);
249 * splice_direct_to_actor - splices data directly between two non-pipes
250 diff --git a/security/commoncap.c b/security/commoncap.c
251 index 7ce191e..19a95be 100644
252 --- a/security/commoncap.c
253 +++ b/security/commoncap.c
254 @@ -965,3 +965,4 @@ int cap_file_mmap(struct file *file, unsigned long reqprot,
258 +EXPORT_SYMBOL(cap_file_mmap);
259 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
260 index 8b5b5d8..911850c 100644
261 --- a/security/device_cgroup.c
262 +++ b/security/device_cgroup.c
264 #include <linux/device_cgroup.h>
265 #include <linux/cgroup.h>
266 #include <linux/ctype.h>
267 +#include <linux/export.h>
268 #include <linux/list.h>
269 #include <linux/uaccess.h>
270 #include <linux/seq_file.h>
271 @@ -501,6 +502,7 @@ found:
275 +EXPORT_SYMBOL(__devcgroup_inode_permission);
277 int devcgroup_inode_mknod(int mode, dev_t dev)
279 diff --git a/security/security.c b/security/security.c
280 index d754249..1aa6154 100644
281 --- a/security/security.c
282 +++ b/security/security.c
283 @@ -392,6 +392,7 @@ int security_path_rmdir(struct path *dir, struct dentry *dentry)
285 return security_ops->path_rmdir(dir, dentry);
287 +EXPORT_SYMBOL(security_path_rmdir);
289 int security_path_unlink(struct path *dir, struct dentry *dentry)
291 @@ -408,6 +409,7 @@ int security_path_symlink(struct path *dir, struct dentry *dentry,
293 return security_ops->path_symlink(dir, dentry, old_name);
295 +EXPORT_SYMBOL(security_path_symlink);
297 int security_path_link(struct dentry *old_dentry, struct path *new_dir,
298 struct dentry *new_dentry)
299 @@ -416,6 +418,7 @@ int security_path_link(struct dentry *old_dentry, struct path *new_dir,
301 return security_ops->path_link(old_dentry, new_dir, new_dentry);
303 +EXPORT_SYMBOL(security_path_link);
305 int security_path_rename(struct path *old_dir, struct dentry *old_dentry,
306 struct path *new_dir, struct dentry *new_dentry)
307 @@ -434,6 +437,7 @@ int security_path_truncate(struct path *path)
309 return security_ops->path_truncate(path);
311 +EXPORT_SYMBOL(security_path_truncate);
313 int security_path_chmod(struct path *path, umode_t mode)
315 @@ -441,6 +445,7 @@ int security_path_chmod(struct path *path, umode_t mode)
317 return security_ops->path_chmod(path, mode);
319 +EXPORT_SYMBOL(security_path_chmod);
321 int security_path_chown(struct path *path, uid_t uid, gid_t gid)
323 @@ -448,6 +453,7 @@ int security_path_chown(struct path *path, uid_t uid, gid_t gid)
325 return security_ops->path_chown(path, uid, gid);
327 +EXPORT_SYMBOL(security_path_chown);
329 int security_path_chroot(struct path *path)
331 @@ -524,6 +530,7 @@ int security_inode_readlink(struct dentry *dentry)
333 return security_ops->inode_readlink(dentry);
335 +EXPORT_SYMBOL(security_inode_readlink);
337 int security_inode_follow_link(struct dentry *dentry, struct nameidata *nd)
339 @@ -538,6 +545,7 @@ int security_inode_permission(struct inode *inode, int mask)
341 return security_ops->inode_permission(inode, mask);
343 +EXPORT_SYMBOL(security_inode_permission);
345 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
347 @@ -653,6 +661,7 @@ int security_file_permission(struct file *file, int mask)
349 return fsnotify_perm(file, mask);
351 +EXPORT_SYMBOL(security_file_permission);
353 int security_file_alloc(struct file *file)
355 @@ -680,6 +689,7 @@ int security_file_mmap(struct file *file, unsigned long reqprot,
357 return ima_file_mmap(file, prot);
359 +EXPORT_SYMBOL(security_file_mmap);
361 int security_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot,
363 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
364 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
365 +++ linux/Documentation/ABI/testing/debugfs-aufs 2012-03-19 12:24:13.676467669 +0100
367 +What: /debug/aufs/si_<id>/
369 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
371 + Under /debug/aufs, a directory named si_<id> is created
372 + per aufs mount, where <id> is a unique id generated
375 +What: /debug/aufs/si_<id>/xib
377 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
379 + It shows the consumed blocks by xib (External Inode Number
380 + Bitmap), its block size and file size.
381 + When the aufs mount option 'noxino' is specified, it
382 + will be empty. About XINO files, see the aufs manual.
384 +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN
386 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
388 + It shows the consumed blocks by xino (External Inode Number
389 + Translation Table), its link count, block size and file
391 + When the aufs mount option 'noxino' is specified, it
392 + will be empty. About XINO files, see the aufs manual.
394 +What: /debug/aufs/si_<id>/xigen
396 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
398 + It shows the consumed blocks by xigen (External Inode
399 + Generation Table), its block size and file size.
400 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
402 + When the aufs mount option 'noxino' is specified, it
403 + will be empty. About XINO files, see the aufs manual.
404 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
405 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
406 +++ linux/Documentation/ABI/testing/sysfs-aufs 2012-03-19 12:24:13.676467669 +0100
408 +What: /sys/fs/aufs/si_<id>/
410 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
412 + Under /sys/fs/aufs, a directory named si_<id> is created
413 + per aufs mount, where <id> is a unique id generated
416 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
418 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
420 + It shows the abolute path of a member directory (which
421 + is called branch) in aufs, and its permission.
423 +What: /sys/fs/aufs/si_<id>/xi_path
425 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
427 + It shows the abolute path of XINO (External Inode Number
428 + Bitmap, Translation Table and Generation Table) file
429 + even if it is the default path.
430 + When the aufs mount option 'noxino' is specified, it
431 + will be empty. About XINO files, see the aufs manual.
432 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
433 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
434 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2012-03-19 12:24:13.676467669 +0100
437 +# Copyright (C) 2005-2011 Junjiro R. Okajima
439 +# This program is free software; you can redistribute it and/or modify
440 +# it under the terms of the GNU General Public License as published by
441 +# the Free Software Foundation; either version 2 of the License, or
442 +# (at your option) any later version.
444 +# This program is distributed in the hope that it will be useful,
445 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
446 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
447 +# GNU General Public License for more details.
449 +# You should have received a copy of the GNU General Public License
450 +# along with this program; if not, write to the Free Software
451 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
454 +----------------------------------------
456 +aufs [ei ju: ef es] | [a u f s]
457 +1. abbrev. for "advanced multi-layered unification filesystem".
458 +2. abbrev. for "another unionfs".
459 +3. abbrev. for "auf das" in German which means "on the" in English.
460 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
461 + But "Filesystem aufs Filesystem" is hard to understand.
463 +AUFS is a filesystem with features:
464 +- multi layered stackable unification filesystem, the member directory
465 + is called as a branch.
466 +- branch permission and attribute, 'readonly', 'real-readonly',
467 + 'readwrite', 'whiteout-able', 'link-able whiteout' and their
469 +- internal "file copy-on-write".
470 +- logical deletion, whiteout.
471 +- dynamic branch manipulation, adding, deleting and changing permission.
472 +- allow bypassing aufs, user's direct branch access.
473 +- external inode number translation table and bitmap which maintains the
474 + persistent aufs inode number.
475 +- seekable directory, including NFS readdir.
476 +- file mapping, mmap and sharing pages.
477 +- pseudo-link, hardlink over branches.
478 +- loopback mounted filesystem as a branch.
479 +- several policies to select one among multiple writable branches.
480 +- revert a single systemcall when an error occurs in aufs.
484 +Multi Layered Stackable Unification Filesystem
485 +----------------------------------------------------------------------
486 +Most people already knows what it is.
487 +It is a filesystem which unifies several directories and provides a
488 +merged single directory. When users access a file, the access will be
489 +passed/re-directed/converted (sorry, I am not sure which English word is
490 +correct) to the real file on the member filesystem. The member
491 +filesystem is called 'lower filesystem' or 'branch' and has a mode
492 +'readonly' and 'readwrite.' And the deletion for a file on the lower
493 +readonly branch is handled by creating 'whiteout' on the upper writable
496 +On LKML, there have been discussions about UnionMount (Jan Blunck,
497 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
498 +different approaches to implement the merged-view.
499 +The former tries putting it into VFS, and the latter implements as a
500 +separate filesystem.
501 +(If I misunderstand about these implementations, please let me know and
502 +I shall correct it. Because it is a long time ago when I read their
503 +source files last time).
505 +UnionMount's approach will be able to small, but may be hard to share
506 +branches between several UnionMount since the whiteout in it is
507 +implemented in the inode on branch filesystem and always
508 +shared. According to Bharata's post, readdir does not seems to be
510 +There are several missing features known in this implementations such as
511 +- for users, the inode number may change silently. eg. copy-up.
512 +- link(2) may break by copy-up.
513 +- read(2) may get an obsoleted filedata (fstat(2) too).
514 +- fcntl(F_SETLK) may be broken by copy-up.
515 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
518 +Unionfs has a longer history. When I started implementing a stacking filesystem
519 +(Aug 2005), it already existed. It has virtual super_block, inode,
520 +dentry and file objects and they have an array pointing lower same kind
521 +objects. After contributing many patches for Unionfs, I re-started my
522 +project AUFS (Jun 2006).
524 +In AUFS, the structure of filesystem resembles to Unionfs, but I
525 +implemented my own ideas, approaches and enhancements and it became
526 +totally different one.
528 +Comparing DM snapshot and fs based implementation
529 +- the number of bytes to be copied between devices is much smaller.
530 +- the type of filesystem must be one and only.
531 +- the fs must be writable, no readonly fs, even for the lower original
532 + device. so the compression fs will not be usable. but if we use
533 + loopback mount, we may address this issue.
535 + mount /cdrom/squashfs.img /sq
536 + losetup /sq/ext2.img
537 + losetup /somewhere/cow
538 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
539 +- it will be difficult (or needs more operations) to extract the
540 + difference between the original device and COW.
541 +- DM snapshot-merge may help a lot when users try merging. in the
542 + fs-layer union, users will use rsync(1).
545 +Several characters/aspects of aufs
546 +----------------------------------------------------------------------
548 +Aufs has several characters or aspects.
549 +1. a filesystem, callee of VFS helper
550 +2. sub-VFS, caller of VFS helper for branches
551 +3. a virtual filesystem which maintains persistent inode number
552 +4. reader/writer of files on branches such like an application
554 +1. Callee of VFS Helper
555 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
556 +unlink(2) from an application reaches sys_unlink() kernel function and
557 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
558 +calls filesystem specific unlink operation. Actually aufs implements the
559 +unlink operation but it behaves like a redirector.
561 +2. Caller of VFS Helper for Branches
562 +aufs_unlink() passes the unlink request to the branch filesystem as if
563 +it were called from VFS. So the called unlink operation of the branch
564 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
565 +every necessary pre/post operation for the branch filesystem.
566 +- acquire the lock for the parent dir on a branch
567 +- lookup in a branch
568 +- revalidate dentry on a branch
569 +- mnt_want_write() for a branch
570 +- vfs_unlink() for a branch
571 +- mnt_drop_write() for a branch
572 +- release the lock on a branch
574 +3. Persistent Inode Number
575 +One of the most important issue for a filesystem is to maintain inode
576 +numbers. This is particularly important to support exporting a
577 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
578 +backend block device for its own. But some storage is necessary to
579 +maintain inode number. It may be a large space and may not suit to keep
580 +in memory. Aufs rents some space from its first writable branch
581 +filesystem (by default) and creates file(s) on it. These files are
582 +created by aufs internally and removed soon (currently) keeping opened.
583 +Note: Because these files are removed, they are totally gone after
584 + unmounting aufs. It means the inode numbers are not persistent
585 + across unmount or reboot. I have a plan to make them really
586 + persistent which will be important for aufs on NFS server.
588 +4. Read/Write Files Internally (copy-on-write)
589 +Because a branch can be readonly, when you write a file on it, aufs will
590 +"copy-up" it to the upper writable branch internally. And then write the
591 +originally requested thing to the file. Generally kernel doesn't
592 +open/read/write file actively. In aufs, even a single write may cause a
593 +internal "file copy". This behaviour is very similar to cp(1) command.
595 +Some people may think it is better to pass such work to user space
596 +helper, instead of doing in kernel space. Actually I am still thinking
597 +about it. But currently I have implemented it in kernel space.
598 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
599 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
600 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2012-03-19 12:24:13.676467669 +0100
603 +# Copyright (C) 2005-2011 Junjiro R. Okajima
605 +# This program is free software; you can redistribute it and/or modify
606 +# it under the terms of the GNU General Public License as published by
607 +# the Free Software Foundation; either version 2 of the License, or
608 +# (at your option) any later version.
610 +# This program is distributed in the hope that it will be useful,
611 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
612 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
613 +# GNU General Public License for more details.
615 +# You should have received a copy of the GNU General Public License
616 +# along with this program; if not, write to the Free Software
617 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
619 +Basic Aufs Internal Structure
621 +Superblock/Inode/Dentry/File Objects
622 +----------------------------------------------------------------------
623 +As like an ordinary filesystem, aufs has its own
624 +superblock/inode/dentry/file objects. All these objects have a
625 +dynamically allocated array and store the same kind of pointers to the
626 +lower filesystem, branch.
627 +For example, when you build a union with one readwrite branch and one
628 +readonly, mounted /au, /rw and /ro respectively.
630 +- /ro/fileA exists but /rw/fileA
632 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
633 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
637 +This style of an array is essentially same to the aufs
638 +superblock/inode/dentry/file objects.
640 +Because aufs supports manipulating branches, ie. add/delete/change
641 +dynamically, these objects has its own generation. When branches are
642 +changed, the generation in aufs superblock is incremented. And a
643 +generation in other object are compared when it is accessed.
644 +When a generation in other objects are obsoleted, aufs refreshes the
649 +----------------------------------------------------------------------
650 +Additionally aufs superblock has some data for policies to select one
651 +among multiple writable branches, XIB files, pseudo-links and kobject.
652 +See below in detail.
653 +About the policies which supports copy-down a directory, see policy.txt
657 +Branch and XINO(External Inode Number Translation Table)
658 +----------------------------------------------------------------------
659 +Every branch has its own xino (external inode number translation table)
660 +file. The xino file is created and unlinked by aufs internally. When two
661 +members of a union exist on the same filesystem, they share the single
663 +The struct of a xino file is simple, just a sequence of aufs inode
664 +numbers which is indexed by the lower inode number.
665 +In the above sample, assume the inode number of /ro/fileA is i111 and
666 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
667 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
669 +When the inode numbers are not contiguous, the xino file will be sparse
670 +which has a hole in it and doesn't consume as much disk space as it
671 +might appear. If your branch filesystem consumes disk space for such
672 +holes, then you should specify 'xino=' option at mounting aufs.
674 +Also a writable branch has three kinds of "whiteout bases". All these
675 +are existed when the branch is joined to aufs and the names are
676 +whiteout-ed doubly, so that users will never see their names in aufs
678 +1. a regular file which will be linked to all whiteouts.
679 +2. a directory to store a pseudo-link.
680 +3. a directory to store an "orphan-ed" file temporary.
683 + When you remove a file on a readonly branch, aufs handles it as a
684 + logical deletion and creates a whiteout on the upper writable branch
685 + as a hardlink of this file in order not to consume inode on the
688 + See below, Pseudo-link.
690 + When "fileC" exists on the lower readonly branch only and it is
691 + opened and removed with its parent dir, and then user writes
692 + something into it, then aufs copies-up fileC to this
693 + directory. Because there is no other dir to store fileC. After
694 + creating a file under this dir, the file is unlinked.
696 +Because aufs supports manipulating branches, ie. add/delete/change
697 +dynamically, a branch has its own id. When the branch order changes, aufs
698 +finds the new index by searching the branch id.
702 +----------------------------------------------------------------------
703 +Assume "fileA" exists on the lower readonly branch only and it is
704 +hardlinked to "fileB" on the branch. When you write something to fileA,
705 +aufs copies-up it to the upper writable branch. Additionally aufs
706 +creates a hardlink under the Pseudo-link Directory of the writable
707 +branch. The inode of a pseudo-link is kept in aufs super_block as a
708 +simple list. If fileB is read after unlinking fileA, aufs returns
709 +filedata from the pseudo-link instead of the lower readonly
710 +branch. Because the pseudo-link is based upon the inode, to keep the
711 +inode number by xino (see above) is important.
713 +All the hardlinks under the Pseudo-link Directory of the writable branch
714 +should be restored in a proper location later. Aufs provides a utility
715 +to do this. The userspace helpers executed at remounting and unmounting
717 +During this utility is running, it puts aufs into the pseudo-link
718 +maintenance mode. In this mode, only the process which began the
719 +maintenance mode (and its child processes) is allowed to operate in
720 +aufs. Some other processes which are not related to the pseudo-link will
721 +be allowed to run too, but the rest have to return an error or wait
722 +until the maintenance mode ends. If a process already acquires an inode
723 +mutex (in VFS), it has to return an error.
726 +XIB(external inode number bitmap)
727 +----------------------------------------------------------------------
728 +Addition to the xino file per a branch, aufs has an external inode number
729 +bitmap in a superblock object. It is also a file such like a xino file.
730 +It is a simple bitmap to mark whether the aufs inode number is in-use or
732 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
734 +Aufs implements a feature to truncate/refresh both of xino and xib to
735 +reduce the number of consumed disk blocks for these files.
738 +Virtual or Vertical Dir, and Readdir in Userspace
739 +----------------------------------------------------------------------
740 +In order to support multiple layers (branches), aufs readdir operation
741 +constructs a virtual dir block on memory. For readdir, aufs calls
742 +vfs_readdir() internally for each dir on branches, merges their entries
743 +with eliminating the whiteout-ed ones, and sets it to file (dir)
744 +object. So the file object has its entry list until it is closed. The
745 +entry list will be updated when the file position is zero and becomes
746 +old. This decision is made in aufs automatically.
748 +The dynamically allocated memory block for the name of entries has a
749 +unit of 512 bytes (by default) and stores the names contiguously (no
750 +padding). Another block for each entry is handled by kmem_cache too.
751 +During building dir blocks, aufs creates hash list and judging whether
752 +the entry is whiteouted by its upper branch or already listed.
753 +The merged result is cached in the corresponding inode object and
754 +maintained by a customizable life-time option.
756 +Some people may call it can be a security hole or invite DoS attack
757 +since the opened and once readdir-ed dir (file object) holds its entry
758 +list and becomes a pressure for system memory. But I'd say it is similar
759 +to files under /proc or /sys. The virtual files in them also holds a
760 +memory page (generally) while they are opened. When an idea to reduce
761 +memory for them is introduced, it will be applied to aufs too.
762 +For those who really hate this situation, I've developed readdir(3)
763 +library which operates this merging in userspace. You just need to set
764 +LD_PRELOAD environment variable, and aufs will not consume no memory in
765 +kernel space for readdir(3).
769 +----------------------------------------------------------------------
770 +Aufs sometimes requires privilege access to a branch. For instance,
771 +in copy-up/down operation. When a user process is going to make changes
772 +to a file which exists in the lower readonly branch only, and the mode
773 +of one of ancestor directories may not be writable by a user
774 +process. Here aufs copy-up the file with its ancestors and they may
775 +require privilege to set its owner/group/mode/etc.
776 +This is a typical case of a application character of aufs (see
779 +Aufs uses workqueue synchronously for this case. It creates its own
780 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
781 +passes the request to call mkdir or write (for example), and wait for
782 +its completion. This approach solves a problem of a signal handler
784 +If aufs didn't adopt the workqueue and changed the privilege of the
785 +process, and if the mkdir/write call arises SIGXFSZ or other signal,
786 +then the user process might gain a privilege or the generated core file
787 +was owned by a superuser.
789 +Also aufs uses the system global workqueue ("events" kernel thread) too
790 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
791 +whiteout base and etc. This is unrelated to a privilege.
792 +Most of aufs operation tries acquiring a rw_semaphore for aufs
793 +superblock at the beginning, at the same time waits for the completion
794 +of all queued asynchronous tasks.
798 +----------------------------------------------------------------------
799 +The whiteout in aufs is very similar to Unionfs's. That is represented
800 +by its filename. UnionMount takes an approach of a file mode, but I am
801 +afraid several utilities (find(1) or something) will have to support it.
803 +Basically the whiteout represents "logical deletion" which stops aufs to
804 +lookup further, but also it represents "dir is opaque" which also stop
807 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
808 +In order to make several functions in a single systemcall to be
809 +revertible, aufs adopts an approach to rename a directory to a temporary
810 +unique whiteouted name.
811 +For example, in rename(2) dir where the target dir already existed, aufs
812 +renames the target dir to a temporary unique whiteouted name before the
813 +actual rename on a branch and then handles other actions (make it opaque,
814 +update the attributes, etc). If an error happens in these actions, aufs
815 +simply renames the whiteouted name back and returns an error. If all are
816 +succeeded, aufs registers a function to remove the whiteouted unique
817 +temporary name completely and asynchronously to the system global
822 +----------------------------------------------------------------------
823 +It is a well-known feature or concept.
824 +When user modifies a file on a readonly branch, aufs operate "copy-up"
825 +internally and makes change to the new file on the upper writable branch.
826 +When the trigger systemcall does not update the timestamps of the parent
827 +dir, aufs reverts it after copy-up.
828 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
829 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
830 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2012-03-19 12:24:13.676467669 +0100
833 +# Copyright (C) 2005-2011 Junjiro R. Okajima
835 +# This program is free software; you can redistribute it and/or modify
836 +# it under the terms of the GNU General Public License as published by
837 +# the Free Software Foundation; either version 2 of the License, or
838 +# (at your option) any later version.
840 +# This program is distributed in the hope that it will be useful,
841 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
842 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
843 +# GNU General Public License for more details.
845 +# You should have received a copy of the GNU General Public License
846 +# along with this program; if not, write to the Free Software
847 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
850 +----------------------------------------------------------------------
851 +Since aufs has a character of sub-VFS (see Introduction), it operates
852 +lookup for branches as VFS does. It may be a heavy work. Generally
853 +speaking struct nameidata is a bigger structure and includes many
854 +information. But almost all lookup operation in aufs is the simplest
855 +case, ie. lookup only an entry directly connected to its parent. Digging
856 +down the directory hierarchy is unnecessary.
858 +VFS has a function lookup_one_len() for that use, but it is not usable
859 +for a branch filesystem which requires struct nameidata. So aufs
860 +implements a simple lookup wrapper function. When a branch filesystem
861 +allows NULL as nameidata, it calls lookup_one_len(). Otherwise it builds
862 +a simplest nameidata and calls lookup_hash().
863 +Here aufs applies "a principle in NFSD", ie. if the filesystem supports
864 +NFS-export, then it has to support NULL as a nameidata parameter for
865 +->create(), ->lookup() and ->d_revalidate(). So the lookup wrapper in
866 +aufs tests if ->s_export_op in the branch is NULL or not.
868 +When a branch is a remote filesystem, aufs basically trusts its
869 +->d_revalidate(), also aufs forces the hardest revalidate tests for
871 +For d_revalidate, aufs implements three levels of revalidate tests. See
872 +"Revalidate Dentry and UDBA" in detail.
876 +----------------------------------------------------------------------
877 +Basically aufs supports any type of filesystem and block device for a
878 +branch (actually there are some exceptions). But it is prohibited to add
879 +a loopback mounted one whose backend file exists in a filesystem which is
880 +already added to aufs. The reason is to protect aufs from a recursive
881 +lookup. If it was allowed, the aufs lookup operation might re-enter a
882 +lookup for the loopback mounted branch in the same context, and will
886 +Revalidate Dentry and UDBA (User's Direct Branch Access)
887 +----------------------------------------------------------------------
888 +Generally VFS helpers re-validate a dentry as a part of lookup.
889 +0. digging down the directory hierarchy.
890 +1. lock the parent dir by its i_mutex.
891 +2. lookup the final (child) entry.
893 +4. call the actual operation (create, unlink, etc.)
894 +5. unlock the parent dir
896 +If the filesystem implements its ->d_revalidate() (step 3), then it is
897 +called. Actually aufs implements it and checks the dentry on a branch is
899 +But it is not enough. Because aufs has to release the lock for the
900 +parent dir on a branch at the end of ->lookup() (step 2) and
901 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
903 +If the file on a branch is changed directly, eg. bypassing aufs, after
904 +aufs released the lock, then the subsequent operation may cause
905 +something unpleasant result.
907 +This situation is a result of VFS architecture, ->lookup() and
908 +->d_revalidate() is separated. But I never say it is wrong. It is a good
909 +design from VFS's point of view. It is just not suitable for sub-VFS
912 +Aufs supports such case by three level of revalidation which is
914 +1. Simple Revalidate
915 + Addition to the native flow in VFS's, confirm the child-parent
916 + relationship on the branch just after locking the parent dir on the
917 + branch in the "actual operation" (step 4). When this validation
918 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
919 + checks the validation of the dentry on branches.
920 +2. Monitor Changes Internally by Inotify/Fsnotify
921 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
922 + the dentry on the branch, and returns EBUSY if it finds different
924 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
925 + during it is in cache. When the event is notified, aufs registers a
926 + function to kernel 'events' thread by schedule_work(). And the
927 + function sets some special status to the cached aufs dentry and inode
928 + private data. If they are not cached, then aufs has nothing to
929 + do. When the same file is accessed through aufs (step 0-3) later,
930 + aufs will detect the status and refresh all necessary data.
931 + In this mode, aufs has to ignore the event which is fired by aufs
933 +3. No Extra Validation
934 + This is the simplest test and doesn't add any additional revalidation
935 + test, and skip therevalidatin in step 4. It is useful and improves
936 + aufs performance when system surely hide the aufs branches from user,
937 + by over-mounting something (or another method).
938 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
939 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
940 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2012-03-19 12:24:13.676467669 +0100
943 +# Copyright (C) 2005-2011 Junjiro R. Okajima
945 +# This program is free software; you can redistribute it and/or modify
946 +# it under the terms of the GNU General Public License as published by
947 +# the Free Software Foundation; either version 2 of the License, or
948 +# (at your option) any later version.
950 +# This program is distributed in the hope that it will be useful,
951 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
952 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
953 +# GNU General Public License for more details.
955 +# You should have received a copy of the GNU General Public License
956 +# along with this program; if not, write to the Free Software
957 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
961 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
962 +and changing its permission/attribute, there are a lot of works to do.
966 +----------------------------------------------------------------------
967 +o Confirm the adding dir exists outside of aufs, including loopback
969 +- and other various attributes...
970 +o Initialize the xino file and whiteout bases if necessary.
973 +o Check the owner/group/mode of the directory
974 + When the owner/group/mode of the adding directory differs from the
975 + existing branch, aufs issues a warning because it may impose a
977 + For example, when a upper writable branch has a world writable empty
978 + top directory, a malicious user can create any files on the writable
979 + branch directly, like copy-up and modify manually. If something like
980 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
981 + writable branch, and the writable branch is world-writable, then a
982 + malicious guy may create /etc/passwd on the writable branch directly
983 + and the infected file will be valid in aufs.
984 + I am afraid it can be a security issue, but nothing to do except
985 + producing a warning.
989 +----------------------------------------------------------------------
990 +o Confirm the deleting branch is not busy
991 + To be general, there is one merit to adopt "remount" interface to
992 + manipulate branches. It is to discard caches. At deleting a branch,
993 + aufs checks the still cached (and connected) dentries and inodes. If
994 + there are any, then they are all in-use. An inode without its
995 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
997 + For the cached one, aufs checks whether the same named entry exists on
999 + If the cached one is a directory, because aufs provides a merged view
1000 + to users, as long as one dir is left on any branch aufs can show the
1001 + dir to users. In this case, the branch can be removed from aufs.
1002 + Otherwise aufs rejects deleting the branch.
1004 + If any file on the deleting branch is opened by aufs, then aufs
1008 +Modify the Permission of a Branch
1009 +----------------------------------------------------------------------
1010 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1013 +o rw --> ro: Confirm the modifying branch is not busy
1014 + Aufs rejects the request if any of these conditions are true.
1015 + - a file on the branch is mmap-ed.
1016 + - a regular file on the branch is opened for write and there is no
1017 + same named entry on the upper branch.
1018 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1019 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1020 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2012-03-19 12:24:13.676467669 +0100
1023 +# Copyright (C) 2005-2011 Junjiro R. Okajima
1025 +# This program is free software; you can redistribute it and/or modify
1026 +# it under the terms of the GNU General Public License as published by
1027 +# the Free Software Foundation; either version 2 of the License, or
1028 +# (at your option) any later version.
1030 +# This program is distributed in the hope that it will be useful,
1031 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1032 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1033 +# GNU General Public License for more details.
1035 +# You should have received a copy of the GNU General Public License
1036 +# along with this program; if not, write to the Free Software
1037 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1039 +Policies to Select One among Multiple Writable Branches
1040 +----------------------------------------------------------------------
1041 +When the number of writable branch is more than one, aufs has to decide
1042 +the target branch for file creation or copy-up. By default, the highest
1043 +writable branch which has the parent (or ancestor) dir of the target
1044 +file is chosen (top-down-parent policy).
1045 +By user's request, aufs implements some other policies to select the
1046 +writable branch, for file creation two policies, round-robin and
1047 +most-free-space policies. For copy-up three policies, top-down-parent,
1048 +bottom-up-parent and bottom-up policies.
1050 +As expected, the round-robin policy selects the branch in circular. When
1051 +you have two writable branches and creates 10 new files, 5 files will be
1052 +created for each branch. mkdir(2) systemcall is an exception. When you
1053 +create 10 new directories, all will be created on the same branch.
1054 +And the most-free-space policy selects the one which has most free
1055 +space among the writable branches. The amount of free space will be
1056 +checked by aufs internally, and users can specify its time interval.
1058 +The policies for copy-up is more simple,
1059 +top-down-parent is equivalent to the same named on in create policy,
1060 +bottom-up-parent selects the writable branch where the parent dir
1061 +exists and the nearest upper one from the copyup-source,
1062 +bottom-up selects the nearest upper writable branch from the
1063 +copyup-source, regardless the existence of the parent dir.
1065 +There are some rules or exceptions to apply these policies.
1066 +- If there is a readonly branch above the policy-selected branch and
1067 + the parent dir is marked as opaque (a variation of whiteout), or the
1068 + target (creating) file is whiteout-ed on the upper readonly branch,
1069 + then the result of the policy is ignored and the target file will be
1070 + created on the nearest upper writable branch than the readonly branch.
1071 +- If there is a writable branch above the policy-selected branch and
1072 + the parent dir is marked as opaque or the target file is whiteouted
1073 + on the branch, then the result of the policy is ignored and the target
1074 + file will be created on the highest one among the upper writable
1075 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1077 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1078 + They try selecting the branch where the source exists as possible
1079 + since copyup a large file will take long time. If it can't be,
1080 + ie. the branch where the source exists is readonly, then they will
1081 + follow the copyup policy.
1082 +- There is an exception for rename(2) when the target exists.
1083 + If the rename target exists, aufs compares the index of the branches
1084 + where the source and the target exists and selects the higher
1085 + one. If the selected branch is readonly, then aufs follows the
1087 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
1088 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
1089 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2012-03-19 12:24:13.676467669 +0100
1092 +# Copyright (C) 2005-2011 Junjiro R. Okajima
1094 +# This program is free software; you can redistribute it and/or modify
1095 +# it under the terms of the GNU General Public License as published by
1096 +# the Free Software Foundation; either version 2 of the License, or
1097 +# (at your option) any later version.
1099 +# This program is distributed in the hope that it will be useful,
1100 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1101 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1102 +# GNU General Public License for more details.
1104 +# You should have received a copy of the GNU General Public License
1105 +# along with this program; if not, write to the Free Software
1106 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1108 +mmap(2) -- File Memory Mapping
1109 +----------------------------------------------------------------------
1110 +In aufs, the file-mapped pages are handled by a branch fs directly, no
1111 +interaction with aufs. It means aufs_mmap() calls the branch fs's
1113 +This approach is simple and good, but there is one problem.
1114 +Under /proc, several entries show the mmap-ped files by its path (with
1115 +device and inode number), and the printed path will be the path on the
1116 +branch fs's instead of virtual aufs's.
1117 +This is not a problem in most cases, but some utilities lsof(1) (and its
1118 +user) may expect the path on aufs.
1120 +To address this issue, aufs adds a new member called vm_prfile in struct
1121 +vm_area_struct (and struct vm_region). The original vm_file points to
1122 +the file on the branch fs in order to handle everything correctly as
1123 +usual. The new vm_prfile points to a virtual file in aufs, and the
1124 +show-functions in procfs refers to vm_prfile if it is set.
1125 +Also we need to maintain several other places where touching vm_file
1127 +- fork()/clone() copies vma and the reference count of vm_file is
1129 +- merging vma maintains the ref count too.
1131 +This is not a good approach. It just faking the printed path. But it
1132 +leaves all behaviour around f_mapping unchanged. This is surely an
1134 +Actually aufs had adopted another complicated approach which calls
1135 +generic_file_mmap() and handles struct vm_operations_struct. In this
1136 +approach, aufs met a hard problem and I could not solve it without
1137 +switching the approach.
1138 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
1139 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
1140 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2012-03-19 12:24:13.676467669 +0100
1143 +# Copyright (C) 2005-2011 Junjiro R. Okajima
1145 +# This program is free software; you can redistribute it and/or modify
1146 +# it under the terms of the GNU General Public License as published by
1147 +# the Free Software Foundation; either version 2 of the License, or
1148 +# (at your option) any later version.
1150 +# This program is distributed in the hope that it will be useful,
1151 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1152 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1153 +# GNU General Public License for more details.
1155 +# You should have received a copy of the GNU General Public License
1156 +# along with this program; if not, write to the Free Software
1157 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1159 +Export Aufs via NFS
1160 +----------------------------------------------------------------------
1161 +Here is an approach.
1162 +- like xino/xib, add a new file 'xigen' which stores aufs inode
1164 +- iget_locked(): initialize aufs inode generation for a new inode, and
1165 + store it in xigen file.
1166 +- destroy_inode(): increment aufs inode generation and store it in xigen
1167 + file. it is necessary even if it is not unlinked, because any data of
1168 + inode may be changed by UDBA.
1169 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
1170 + build file handle by
1171 + + branch id (4 bytes)
1172 + + superblock generation (4 bytes)
1173 + + inode number (4 or 8 bytes)
1174 + + parent dir inode number (4 or 8 bytes)
1175 + + inode generation (4 bytes))
1176 + + return value of exportfs_encode_fh() for the parent on a branch (4
1178 + + file handle for a branch (by exportfs_encode_fh())
1180 + + find the index of a branch from its id in handle, and check it is
1181 + still exist in aufs.
1182 + + 1st level: get the inode number from handle and search it in cache.
1183 + + 2nd level: if not found, get the parent inode number from handle and
1184 + search it in cache. and then open the parent dir, find the matching
1185 + inode number by vfs_readdir() and get its name, and call
1186 + lookup_one_len() for the target dentry.
1187 + + 3rd level: if the parent dir is not cached, call
1188 + exportfs_decode_fh() for a branch and get the parent on a branch,
1189 + build a pathname of it, convert it a pathname in aufs, call
1190 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
1192 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
1193 + for every branch, but not itself. to get this, (currently) aufs
1194 + searches in current->nsproxy->mnt_ns list. it may not be a good
1195 + idea, but I didn't get other approach.
1196 + + test the generation of the gotten inode.
1197 +- every inode operation: they may get EBUSY due to UDBA. in this case,
1198 + convert it into ESTALE for NFSD.
1199 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
1200 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
1201 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
1202 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
1203 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2012-03-19 12:24:13.676467669 +0100
1206 +# Copyright (C) 2005-2011 Junjiro R. Okajima
1208 +# This program is free software; you can redistribute it and/or modify
1209 +# it under the terms of the GNU General Public License as published by
1210 +# the Free Software Foundation; either version 2 of the License, or
1211 +# (at your option) any later version.
1213 +# This program is distributed in the hope that it will be useful,
1214 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1215 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1216 +# GNU General Public License for more details.
1218 +# You should have received a copy of the GNU General Public License
1219 +# along with this program; if not, write to the Free Software
1220 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1222 +Show Whiteout Mode (shwh)
1223 +----------------------------------------------------------------------
1224 +Generally aufs hides the name of whiteouts. But in some cases, to show
1225 +them is very useful for users. For instance, creating a new middle layer
1226 +(branch) by merging existing layers.
1228 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
1229 +When you have three branches,
1230 +- Bottom: 'system', squashfs (underlying base system), read-only
1231 +- Middle: 'mods', squashfs, read-only
1232 +- Top: 'overlay', ram (tmpfs), read-write
1234 +The top layer is loaded at boot time and saved at shutdown, to preserve
1235 +the changes made to the system during the session.
1236 +When larger changes have been made, or smaller changes have accumulated,
1237 +the size of the saved top layer data grows. At this point, it would be
1238 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
1239 +and rewrite the 'mods' squashfs, clearing the top layer and thus
1240 +restoring save and load speed.
1242 +This merging is simplified by the use of another aufs mount, of just the
1243 +two overlay branches using the 'shwh' option.
1244 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
1245 + aufs /livesys/merge_union
1247 +A merged view of these two branches is then available at
1248 +/livesys/merge_union, and the new feature is that the whiteouts are
1250 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
1251 +writing to all branches. Also the default mode for all branches is 'ro'.
1252 +It is now possible to save the combined contents of the two overlay
1253 +branches to a new squashfs, e.g.:
1254 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
1256 +This new squashfs archive can be stored on the boot device and the
1257 +initramfs will use it to replace the old one at the next boot.
1258 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
1259 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
1260 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2012-03-19 12:24:13.676467669 +0100
1263 +# Copyright (C) 2010-2011 Junjiro R. Okajima
1265 +# This program is free software; you can redistribute it and/or modify
1266 +# it under the terms of the GNU General Public License as published by
1267 +# the Free Software Foundation; either version 2 of the License, or
1268 +# (at your option) any later version.
1270 +# This program is distributed in the hope that it will be useful,
1271 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1272 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1273 +# GNU General Public License for more details.
1275 +# You should have received a copy of the GNU General Public License
1276 +# along with this program; if not, write to the Free Software
1277 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1279 +Dynamically customizable FS operations
1280 +----------------------------------------------------------------------
1281 +Generally FS operations (struct inode_operations, struct
1282 +address_space_operations, struct file_operations, etc.) are defined as
1283 +"static const", but it never means that FS have only one set of
1284 +operation. Some FS have multiple sets of them. For instance, ext2 has
1285 +three sets, one for XIP, for NOBH, and for normal.
1286 +Since aufs overrides and redirects these operations, sometimes aufs has
1287 +to change its behaviour according to the branch FS type. More imporantly
1288 +VFS acts differently if a function (member in the struct) is set or
1289 +not. It means aufs should have several sets of operations and select one
1290 +among them according to the branch FS definition.
1292 +In order to solve this problem and not to affect the behavour of VFS,
1293 +aufs defines these operations dynamically. For instance, aufs defines
1294 +aio_read function for struct file_operations, but it may not be set to
1295 +the file_operations. When the branch FS doesn't have it, aufs doesn't
1296 +set it to its file_operations while the function definition itself is
1297 +still alive. So the behaviour of io_submit(2) will not change, and it
1298 +will return an error when aio_read is not defined.
1300 +The lifetime of these dynamically generated operation object is
1301 +maintained by aufs branch object. When the branch is removed from aufs,
1302 +the reference counter of the object is decremented. When it reaches
1303 +zero, the dynamically generated operation object will be freed.
1305 +This approach is designed to support AIO (io_submit), Direcit I/O and
1307 +Currently this approach is applied to file_operations and
1308 +vm_operations_struct for regular files only.
1309 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt linux/Documentation/filesystems/aufs/design/99plan.txt
1310 --- /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt 1970-01-01 01:00:00.000000000 +0100
1311 +++ linux/Documentation/filesystems/aufs/design/99plan.txt 2012-03-19 12:24:13.676467669 +0100
1314 +# Copyright (C) 2005-2011 Junjiro R. Okajima
1316 +# This program is free software; you can redistribute it and/or modify
1317 +# it under the terms of the GNU General Public License as published by
1318 +# the Free Software Foundation; either version 2 of the License, or
1319 +# (at your option) any later version.
1321 +# This program is distributed in the hope that it will be useful,
1322 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1323 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1324 +# GNU General Public License for more details.
1326 +# You should have received a copy of the GNU General Public License
1327 +# along with this program; if not, write to the Free Software
1328 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1332 +Restoring some features which was implemented in aufs1.
1333 +They were dropped in aufs2 in order to make source files simpler and
1334 +easier to be reviewed.
1337 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1338 +----------------------------------------------------------------------
1339 +Let's try case study.
1340 +- aufs has two branches, upper readwrite and lower readonly.
1342 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1343 +- user invoked "chmod a+rx /au/dirA"
1344 +- then "dirA" becomes world readable?
1346 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1347 +or it may be a natively readonly filesystem. If aufs respects the lower
1348 +branch, it should not respond readdir request from other users. But user
1349 +allowed it by chmod. Should really aufs rejects showing the entries
1352 +To be honest, I don't have a best solution for this case. So I
1353 +implemented 'dirperm1' and 'nodirperm1' option in aufs1, and leave it to
1355 +When dirperm1 is specified, aufs checks only the highest one for the
1356 +directory permission, and shows the entries. Otherwise, as usual, checks
1357 +every dir existing on all branches and rejects the request.
1359 +As a side effect, dirperm1 option improves the performance of aufs
1360 +because the number of permission check is reduced.
1363 +Being Another Aufs's Readonly Branch (robr)
1364 +----------------------------------------------------------------------
1365 +Aufs1 allows aufs to be another aufs's readonly branch.
1366 +This feature was developed by a user's request. But it may not be used
1370 +Copy-up on Open (coo=)
1371 +----------------------------------------------------------------------
1372 +By default the internal copy-up is executed when it is really necessary.
1373 +It is not done when a file is opened for writing, but when write(2) is
1374 +done. Users who have many (over 100) branches want to know and analyse
1375 +when and what file is copied-up. To insert a new upper branch which
1376 +contains such files only may improve the performance of aufs.
1378 +Aufs1 implemented "coo=none | leaf | all" option.
1381 +Refresh the Opened File (refrof)
1382 +----------------------------------------------------------------------
1383 +This option is implemented in aufs1 but incomplete.
1385 +When user reads from a file, he expects to get its latest filedata
1386 +generally. If the file is removed and a new same named file is created,
1387 +the content he gets is unchanged, ie. the unlinked filedata.
1389 +Let's try case study again.
1390 +- aufs has two branches.
1392 +- "fileA" exists under /ro, but /rw.
1393 +- user opened "/au/fileA".
1394 +- he or someone else inserts a branch (/new) between /rw and /ro.
1395 + /au = /rw + /new + /ro
1396 +- the new branch has "fileA".
1397 +- user reads from the opened "fileA"
1398 +- which filedata should aufs return, from /ro or /new?
1400 +Some people says it has to be "from /ro" and it is a semantics of Unix.
1401 +The others say it should be "from /new" because the file is not removed
1402 +and it is equivalent to the case of someone else modifies the file.
1404 +Here again I don't have a best and final answer. I got an idea to
1405 +implement 'refrof' and 'norefrof' option. When 'refrof' (REFResh the
1406 +Opened File) is specified (by default), aufs returns the filedata from
1408 +Otherwise from /new.
1409 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
1410 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
1411 +++ linux/Documentation/filesystems/aufs/README 2012-03-19 12:24:13.676467669 +0100
1414 +Aufs3 -- advanced multi layered unification filesystem version 3.x
1420 +----------------------------------------
1421 +In the early days, aufs was entirely re-designed and re-implemented
1422 +Unionfs Version 1.x series. After many original ideas, approaches,
1423 +improvements and implementations, it becomes totally different from
1424 +Unionfs while keeping the basic features.
1425 +Recently, Unionfs Version 2.x series begin taking some of the same
1426 +approaches to aufs1's.
1427 +Unionfs is being developed by Professor Erez Zadok at Stony Brook
1428 +University and his team.
1430 +Aufs3 supports linux-3.0 and later.
1431 +If you want older kernel version support, try aufs2-2.6.git or
1432 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
1434 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
1435 +According to Christoph Hellwig, linux rejects all union-type filesystems
1437 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
1441 +----------------------------------------
1442 +- unite several directories into a single virtual filesystem. The member
1443 + directory is called as a branch.
1444 +- you can specify the permission flags to the branch, which are 'readonly',
1445 + 'readwrite' and 'whiteout-able.'
1446 +- by upper writable branch, internal copyup and whiteout, files/dirs on
1447 + readonly branch are modifiable logically.
1448 +- dynamic branch manipulation, add, del.
1451 +Also there are many enhancements in aufs1, such as:
1452 +- readdir(3) in userspace.
1453 +- keep inode number by external inode number table
1454 +- keep the timestamps of file/dir in internal copyup operation
1455 +- seekable directory, supporting NFS readdir.
1456 +- whiteout is hardlinked in order to reduce the consumption of inodes
1458 +- do not copyup, nor create a whiteout when it is unnecessary
1459 +- revert a single systemcall when an error occurs in aufs
1460 +- remount interface instead of ioctl
1461 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
1462 +- loopback mounted filesystem as a branch
1463 +- kernel thread for removing the dir who has a plenty of whiteouts
1464 +- support copyup sparse file (a file which has a 'hole' in it)
1465 +- default permission flags for branches
1466 +- selectable permission flags for ro branch, whether whiteout can
1469 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
1470 +- support multiple writable branches, some policies to select one
1471 + among multiple writable branches.
1472 +- a new semantics for link(2) and rename(2) to support multiple
1473 + writable branches.
1474 +- no glibc changes are required.
1475 +- pseudo hardlink (hardlink over branches)
1476 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
1477 + including NFS or remote filesystem branch.
1478 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
1481 +Currently these features are dropped temporary from aufs3.
1482 +See design/08plan.txt in detail.
1483 +- test only the highest one for the directory permission (dirperm1)
1484 +- copyup on open (coo=)
1485 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
1487 +- statistics of aufs thread (/sys/fs/aufs/stat)
1488 +- delegation mode (dlgt)
1489 + a delegation of the internal branch access to support task I/O
1490 + accounting, which also supports Linux Security Modules (LSM) mainly
1491 + for Suse AppArmor.
1492 +- intent.open/create (file open in a single lookup)
1494 +Features or just an idea in the future (see also design/*.txt),
1495 +- reorder the branch index without del/re-add.
1496 +- permanent xino files for NFSD
1497 +- an option for refreshing the opened files after add/del branches
1498 +- 'move' policy for copy-up between two writable branches, after
1499 + checking free space.
1500 +- light version, without branch manipulation. (unnecessary?)
1501 +- copyup in userspace
1502 +- inotify in userspace
1508 +----------------------------------------
1509 +There were three GIT trees for aufs3, aufs3-linux.git,
1510 +aufs3-standalone.git, and aufs-util.git. Note that there is no "3" in
1512 +While the aufs-util is always necessary, you need either of aufs3-linux
1513 +or aufs3-standalone.
1515 +The aufs3-linux tree includes the whole linux mainline GIT tree,
1516 +git://git.kernel.org/.../torvalds/linux.git.
1517 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
1518 +build aufs3 as an externel kernel module.
1520 +On the other hand, the aufs3-standalone tree has only aufs source files
1521 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
1523 +You will find GIT branches whose name is in form of "aufs3.x" where "x"
1524 +represents the linux kernel version, "linux-3.x". For instance,
1525 +"aufs3.0" is for linux-3.0. For latest "linux-3.x-rcN", use
1526 +"aufs3.x-rcN" branch.
1529 +$ git clone --reference /your/linux/git/tree \
1530 + git://aufs.git.sourceforge.net/gitroot/aufs/aufs3-linux.git \
1532 +- if you don't have linux GIT tree, then remove "--reference ..."
1533 +$ cd aufs3-linux.git
1534 +$ git checkout origin/aufs3.0
1536 +o aufs3-standalone tree
1537 +$ git clone git://aufs.git.sourceforge.net/gitroot/aufs/aufs3-standalone.git \
1538 + aufs3-standalone.git
1539 +$ cd aufs3-standalone.git
1540 +$ git checkout origin/aufs3.0
1543 +$ git clone git://aufs.git.sourceforge.net/gitroot/aufs/aufs-util.git \
1546 +$ git checkout origin/aufs3.0
1548 +Note: The 3.x-rcN branch is to be used with `rc' kernel versions ONLY.
1549 +The minor version number, 'x' in '3.x', of aufs may not always
1550 +follow the minor version number of the kernel.
1551 +Because changes in the kernel that cause the use of a new
1552 +minor version number do not always require changes to aufs-util.
1554 +Since aufs-util has its own minor version number, you may not be
1555 +able to find a GIT branch in aufs-util for your kernel's
1556 +exact minor version number.
1557 +In this case, you should git-checkout the branch for the
1558 +nearest lower number.
1560 +For (an unreleased) example:
1561 +If you are using "linux-3.10" and the "aufs3.10" branch
1562 +does not exist in aufs-util repository, then "aufs3.9", "aufs3.8"
1563 +or something numerically smaller is the branch for your kernel.
1565 +Also you can view all branches by
1569 +3. Configuration and Compilation
1570 +----------------------------------------
1571 +Make sure you have git-checkout'ed the correct branch.
1573 +For aufs3-linux tree,
1574 +- enable CONFIG_EXPERIMENTAL and CONFIG_AUFS_FS.
1575 +- set other aufs configurations if necessary.
1577 +For aufs3-standalone tree,
1578 +There are several ways to build.
1581 +- apply ./aufs3-kbuild.patch to your kernel source files.
1582 +- apply ./aufs3-base.patch too.
1583 +- apply ./aufs3-proc_map.patch too, if you want to make /proc/PID/maps (and
1584 + others including lsof(1)) show the file path on aufs instead of the
1585 + path on the branch fs.
1586 +- apply ./aufs3-standalone.patch too, if you have a plan to set
1587 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs3-standalone.patch.
1588 +- copy ./{Documentation,fs,include/linux/aufs_type.h} files to your
1589 + kernel source tree. Never copy ./include/linux/Kbuild.
1590 +- enable CONFIG_EXPERIMENTAL and CONFIG_AUFS_FS, you can select either
1592 +- and build your kernel as usual.
1593 +- install the built kernel.
1594 +- install the header files too by "make headers_install" to the
1595 + directory where you specify. By default, it is $PWD/usr.
1596 +- and reboot your system.
1599 +- module only (CONFIG_AUFS_FS=m).
1600 +- apply ./aufs3-base.patch to your kernel source files.
1601 +- apply ./aufs3-proc_map.patch too to your kernel source files,
1602 + if you want to make /proc/PID/maps (and others including lsof(1)) show
1603 + the file path on aufs instead of the path on the branch fs.
1604 +- apply ./aufs3-standalone.patch too.
1605 +- build your kernel, don't forget "make headers_install", and reboot.
1606 +- edit ./config.mk and set other aufs configurations if necessary.
1607 + Note: You should read ./fs/aufs/Kconfig carefully which describes
1608 + every aufs configurations.
1609 +- build the module by simple "make".
1610 +- you can specify ${KDIR} make variable which points to your kernel
1612 +- install the files
1613 + + run "make install" to install the aufs module, or copy the built
1614 + ./aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
1615 + + run "make headers_install" to install the aufs header file (you can
1616 + specify DESTDIR), or copty ./usr/include/linux/aufs_type.h to
1617 + /usr/include/linux or wherever you like. By default, the target
1618 + directory is $PWD/usr.
1619 +- no need to apply aufs3-kbuild.patch, nor copying source files to your
1620 + kernel source tree.
1622 +Note: The haeder file aufs_type.h is necessary to build aufs-util
1623 + as well as "make headers_install" in the kernel source tree.
1624 + headers_install is subject to be forgotten, but it is essentially
1625 + necessary, not only for building aufs-util.
1626 + You may not meet problems without headers_install in some older
1630 +- read README in aufs-util, build and install it
1631 +- note that your distribution may contain an obsoleted version of
1632 + aufs_type.h in /usr/include/linux or something. When you build aufs
1633 + utilities, make sure that your compiler refers the correct aufs header
1634 + file which is built by "make headers_install."
1635 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
1636 + then run "make install_ulib" too. And refer to the aufs manual in
1641 +----------------------------------------
1642 +At first, make sure aufs-util are installed, and please read the aufs
1643 +manual, aufs.5 in aufs-util.git tree.
1647 +$ mkdir /tmp/rw /tmp/aufs
1648 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
1650 +Here is another example. The result is equivalent.
1651 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
1653 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
1654 +# mount -o remount,append:${HOME} /tmp/aufs
1656 +Then, you can see whole tree of your home dir through /tmp/aufs. If
1657 +you modify a file under /tmp/aufs, the one on your home directory is
1658 +not affected, instead the same named file will be newly created under
1659 +/tmp/rw. And all of your modification to a file will be applied to
1660 +the one under /tmp/rw. This is called the file based Copy on Write
1662 +Aufs mount options are described in aufs.5.
1663 +If you run chroot or something and make your aufs as a root directory,
1664 +then you need to customize the shutdown script. See the aufs manual in
1667 +Additionally, there are some sample usages of aufs which are a
1668 +diskless system with network booting, and LiveCD over NFS.
1669 +See sample dir in CVS tree on SourceForge.
1673 +----------------------------------------
1674 +When you have any problems or strange behaviour in aufs, please let me
1676 +- /proc/mounts (instead of the output of mount(8))
1677 +- /sys/module/aufs/*
1678 +- /sys/fs/aufs/* (if you have them)
1679 +- /debug/aufs/* (if you have them)
1680 +- linux kernel version
1681 + if your kernel is not plain, for example modified by distributor,
1682 + the url where i can download its source is necessary too.
1683 +- aufs version which was printed at loading the module or booting the
1684 + system, instead of the date you downloaded.
1685 +- configuration (define/undefine CONFIG_AUFS_xxx)
1686 +- kernel configuration or /proc/config.gz (if you have it)
1687 +- behaviour which you think to be incorrect
1688 +- actual operation, reproducible one is better
1689 +- mailto: aufs-users at lists.sourceforge.net
1691 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
1692 +and Feature Requests) on SourceForge. Please join and write to
1696 +6. Acknowledgements
1697 +----------------------------------------
1698 +Thanks to everyone who have tried and are using aufs, whoever
1699 +have reported a bug or any feedback.
1701 +Especially donators:
1702 +Tomas Matejicek(slax.org) made a donation (much more than once).
1703 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
1704 + scripts) is making "doubling" donations.
1705 + Unfortunately I cannot list all of the donators, but I really
1707 + It ends Aug 2010, but the ordinary donation URL is still available.
1708 + <http://sourceforge.net/donate/index.php?group_id=167503>
1709 +Dai Itasaka made a donation (2007/8).
1710 +Chuck Smith made a donation (2008/4, 10 and 12).
1711 +Henk Schoneveld made a donation (2008/9).
1712 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
1713 +Francois Dupoux made a donation (2008/11).
1714 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
1715 + aufs2 GIT tree (2009/2).
1716 +William Grant made a donation (2009/3).
1717 +Patrick Lane made a donation (2009/4).
1718 +The Mail Archive (mail-archive.com) made donations (2009/5).
1719 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
1720 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
1721 +Pavel Pronskiy made a donation (2011/2).
1722 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
1723 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
1724 +Max Lekomcev (DOM-TV project) made a donation (2011/7 and 12).
1725 +Sam Liddicott made a donation (2011/9).
1727 +Thank you very much.
1728 +Donations are always, including future donations, very important and
1729 +helpful for me to keep on developing aufs.
1733 +----------------------------------------
1734 +If you are an experienced user, no explanation is needed. Aufs is
1735 +just a linux filesystem.
1740 +# Local variables: ;
1743 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
1744 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
1745 +++ linux/fs/aufs/aufs.h 2012-03-19 12:24:13.679801090 +0100
1748 + * Copyright (C) 2005-2012 Junjiro R. Okajima
1750 + * This program, aufs is free software; you can redistribute it and/or modify
1751 + * it under the terms of the GNU General Public License as published by
1752 + * the Free Software Foundation; either version 2 of the License, or
1753 + * (at your option) any later version.
1755 + * This program is distributed in the hope that it will be useful,
1756 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1757 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1758 + * GNU General Public License for more details.
1760 + * You should have received a copy of the GNU General Public License
1761 + * along with this program; if not, write to the Free Software
1762 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1766 + * all header files
1774 +#define AuStub(type, name, body, ...) \
1775 + static inline type name(__VA_ARGS__) { body; }
1777 +#define AuStubVoid(name, ...) \
1778 + AuStub(void, name, , __VA_ARGS__)
1779 +#define AuStubInt0(name, ...) \
1780 + AuStub(int, name, return 0, __VA_ARGS__)
1784 +#include "branch.h"
1787 +#include "dbgaufs.h"
1788 +#include "dentry.h"
1792 +#include "fstype.h"
1795 +#include "module.h"
1800 +#include "sysaufs.h"
1805 +#endif /* __KERNEL__ */
1806 +#endif /* __AUFS_H__ */
1807 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
1808 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
1809 +++ linux/fs/aufs/branch.c 2012-03-19 12:24:13.679801090 +0100
1812 + * Copyright (C) 2005-2012 Junjiro R. Okajima
1814 + * This program, aufs is free software; you can redistribute it and/or modify
1815 + * it under the terms of the GNU General Public License as published by
1816 + * the Free Software Foundation; either version 2 of the License, or
1817 + * (at your option) any later version.
1819 + * This program is distributed in the hope that it will be useful,
1820 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1821 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1822 + * GNU General Public License for more details.
1824 + * You should have received a copy of the GNU General Public License
1825 + * along with this program; if not, write to the Free Software
1826 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1830 + * branch management
1833 +#include <linux/compat.h>
1834 +#include <linux/statfs.h>
1838 + * free a single branch
1840 +static void au_br_do_free(struct au_branch *br)
1843 + struct au_wbr *wbr;
1844 + struct au_dykey **key;
1846 + au_hnotify_fin_br(br);
1848 + if (br->br_xino.xi_file)
1849 + fput(br->br_xino.xi_file);
1850 + mutex_destroy(&br->br_xino.xi_nondir_mtx);
1852 + AuDebugOn(atomic_read(&br->br_count));
1856 + for (i = 0; i < AuBrWh_Last; i++)
1857 + dput(wbr->wbr_wh[i]);
1858 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
1859 + AuRwDestroy(&wbr->wbr_wh_rwsem);
1862 + key = br->br_dykey;
1863 + for (i = 0; i < AuBrDynOp; i++, key++)
1869 + mntput(br->br_mnt);
1875 + * frees all branches
1877 +void au_br_free(struct au_sbinfo *sbinfo)
1879 + aufs_bindex_t bmax;
1880 + struct au_branch **br;
1882 + AuRwMustWriteLock(&sbinfo->si_rwsem);
1884 + bmax = sbinfo->si_bend + 1;
1885 + br = sbinfo->si_branch;
1887 + au_br_do_free(*br++);
1891 + * find the index of a branch which is specified by @br_id.
1893 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
1895 + aufs_bindex_t bindex, bend;
1897 + bend = au_sbend(sb);
1898 + for (bindex = 0; bindex <= bend; bindex++)
1899 + if (au_sbr_id(sb, bindex) == br_id)
1904 +/* ---------------------------------------------------------------------- */
1910 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
1911 + struct dentry *h_root)
1913 + if (unlikely(h_adding == h_root
1914 + || au_test_loopback_overlap(sb, h_adding)))
1916 + if (h_adding->d_sb != h_root->d_sb)
1918 + return au_test_subdir(h_adding, h_root)
1919 + || au_test_subdir(h_root, h_adding);
1923 + * returns a newly allocated branch. @new_nbranch is a number of branches
1924 + * after adding a branch.
1926 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
1929 + struct au_branch *add_branch;
1930 + struct dentry *root;
1934 + root = sb->s_root;
1935 + add_branch = kmalloc(sizeof(*add_branch), GFP_NOFS);
1936 + if (unlikely(!add_branch))
1939 + err = au_hnotify_init_br(add_branch, perm);
1940 + if (unlikely(err))
1943 + add_branch->br_wbr = NULL;
1944 + if (au_br_writable(perm)) {
1945 + /* may be freed separately at changing the branch permission */
1946 + add_branch->br_wbr = kmalloc(sizeof(*add_branch->br_wbr),
1948 + if (unlikely(!add_branch->br_wbr))
1952 + err = au_sbr_realloc(au_sbi(sb), new_nbranch);
1954 + err = au_di_realloc(au_di(root), new_nbranch);
1956 + err = au_ii_realloc(au_ii(root->d_inode), new_nbranch);
1958 + return add_branch; /* success */
1960 + kfree(add_branch->br_wbr);
1963 + au_hnotify_fin_br(add_branch);
1965 + kfree(add_branch);
1967 + return ERR_PTR(err);
1971 + * test if the branch permission is legal or not.
1973 +static int test_br(struct inode *inode, int brperm, char *path)
1977 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
1982 + pr_err("write permission for readonly mount or inode, %s\n", path);
1990 + * 0: success, the caller will add it
1991 + * plus: success, it is already unified, the caller should ignore it
1994 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
1997 + aufs_bindex_t bend, bindex;
1998 + struct dentry *root;
1999 + struct inode *inode, *h_inode;
2001 + root = sb->s_root;
2002 + bend = au_sbend(sb);
2003 + if (unlikely(bend >= 0
2004 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
2008 + pr_err("%s duplicated\n", add->pathname);
2013 + err = -ENOSPC; /* -E2BIG; */
2014 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
2015 + || AUFS_BRANCH_MAX - 1 <= bend)) {
2016 + pr_err("number of branches exceeded %s\n", add->pathname);
2021 + if (unlikely(add->bindex < 0 || bend + 1 < add->bindex)) {
2022 + pr_err("bad index %d\n", add->bindex);
2026 + inode = add->path.dentry->d_inode;
2028 + if (unlikely(!inode->i_nlink)) {
2029 + pr_err("no existence %s\n", add->pathname);
2034 + if (unlikely(inode->i_sb == sb)) {
2035 + pr_err("%s must be outside\n", add->pathname);
2039 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
2040 + pr_err("unsupported filesystem, %s (%s)\n",
2041 + add->pathname, au_sbtype(inode->i_sb));
2045 + err = test_br(add->path.dentry->d_inode, add->perm, add->pathname);
2046 + if (unlikely(err))
2050 + return 0; /* success */
2053 + for (bindex = 0; bindex <= bend; bindex++)
2054 + if (unlikely(test_overlap(sb, add->path.dentry,
2055 + au_h_dptr(root, bindex)))) {
2056 + pr_err("%s is overlapped\n", add->pathname);
2061 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
2062 + h_inode = au_h_dptr(root, 0)->d_inode;
2063 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
2064 + || h_inode->i_uid != inode->i_uid
2065 + || h_inode->i_gid != inode->i_gid)
2066 + pr_warning("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
2068 + inode->i_uid, inode->i_gid,
2069 + (inode->i_mode & S_IALLUGO),
2070 + h_inode->i_uid, h_inode->i_gid,
2071 + (h_inode->i_mode & S_IALLUGO));
2079 + * initialize or clean the whiteouts for an adding branch
2081 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
2082 + int new_perm, struct dentry *h_root)
2084 + int err, old_perm;
2085 + aufs_bindex_t bindex;
2086 + struct mutex *h_mtx;
2087 + struct au_wbr *wbr;
2088 + struct au_hinode *hdir;
2091 + old_perm = br->br_perm;
2092 + br->br_perm = new_perm;
2095 + bindex = au_br_index(sb, br->br_id);
2096 + if (0 <= bindex) {
2097 + hdir = au_hi(sb->s_root->d_inode, bindex);
2098 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
2100 + h_mtx = &h_root->d_inode->i_mutex;
2101 + mutex_lock_nested(h_mtx, AuLsc_I_PARENT);
2104 + err = au_wh_init(h_root, br, sb);
2106 + wbr_wh_write_lock(wbr);
2107 + err = au_wh_init(h_root, br, sb);
2108 + wbr_wh_write_unlock(wbr);
2111 + au_hn_imtx_unlock(hdir);
2113 + mutex_unlock(h_mtx);
2114 + br->br_perm = old_perm;
2116 + if (!err && wbr && !au_br_writable(new_perm)) {
2118 + br->br_wbr = NULL;
2124 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
2125 + int perm, struct path *path)
2128 + struct kstatfs kst;
2129 + struct au_wbr *wbr;
2130 + struct dentry *h_dentry;
2133 + au_rw_init(&wbr->wbr_wh_rwsem);
2134 + memset(wbr->wbr_wh, 0, sizeof(wbr->wbr_wh));
2135 + atomic_set(&wbr->wbr_wh_running, 0);
2136 + wbr->wbr_bytes = 0;
2139 + * a limit for rmdir/rename a dir
2140 + * cf. AUFS_MAX_NAMELEN in include/linux/aufs_type.h
2142 + err = vfs_statfs(path, &kst);
2143 + if (unlikely(err))
2146 + h_dentry = path->dentry;
2147 + if (kst.f_namelen >= NAME_MAX)
2148 + err = au_br_init_wh(sb, br, perm, h_dentry);
2150 + pr_err("%.*s(%s), unsupported namelen %ld\n",
2151 + AuDLNPair(h_dentry), au_sbtype(h_dentry->d_sb),
2158 +/* intialize a new branch */
2159 +static int au_br_init(struct au_branch *br, struct super_block *sb,
2160 + struct au_opt_add *add)
2165 + memset(&br->br_xino, 0, sizeof(br->br_xino));
2166 + mutex_init(&br->br_xino.xi_nondir_mtx);
2167 + br->br_perm = add->perm;
2168 + br->br_mnt = add->path.mnt; /* set first, mntget() later */
2169 + spin_lock_init(&br->br_dykey_lock);
2170 + memset(br->br_dykey, 0, sizeof(br->br_dykey));
2171 + atomic_set(&br->br_count, 0);
2172 + br->br_xino_upper = AUFS_XINO_TRUNC_INIT;
2173 + atomic_set(&br->br_xino_running, 0);
2174 + br->br_id = au_new_br_id(sb);
2175 + AuDebugOn(br->br_id < 0);
2177 + if (au_br_writable(add->perm)) {
2178 + err = au_wbr_init(br, sb, add->perm, &add->path);
2179 + if (unlikely(err))
2183 + if (au_opt_test(au_mntflags(sb), XINO)) {
2184 + err = au_xino_br(sb, br, add->path.dentry->d_inode->i_ino,
2185 + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1);
2186 + if (unlikely(err)) {
2187 + AuDebugOn(br->br_xino.xi_file);
2192 + sysaufs_br_init(br);
2193 + mntget(add->path.mnt);
2194 + goto out; /* success */
2197 + br->br_mnt = NULL;
2202 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
2203 + struct au_branch *br, aufs_bindex_t bend,
2204 + aufs_bindex_t amount)
2206 + struct au_branch **brp;
2208 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2210 + brp = sbinfo->si_branch + bindex;
2211 + memmove(brp + 1, brp, sizeof(*brp) * amount);
2213 + sbinfo->si_bend++;
2214 + if (unlikely(bend < 0))
2215 + sbinfo->si_bend = 0;
2218 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
2219 + aufs_bindex_t bend, aufs_bindex_t amount)
2221 + struct au_hdentry *hdp;
2223 + AuRwMustWriteLock(&dinfo->di_rwsem);
2225 + hdp = dinfo->di_hdentry + bindex;
2226 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
2227 + au_h_dentry_init(hdp);
2229 + if (unlikely(bend < 0))
2230 + dinfo->di_bstart = 0;
2233 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
2234 + aufs_bindex_t bend, aufs_bindex_t amount)
2236 + struct au_hinode *hip;
2238 + AuRwMustWriteLock(&iinfo->ii_rwsem);
2240 + hip = iinfo->ii_hinode + bindex;
2241 + memmove(hip + 1, hip, sizeof(*hip) * amount);
2242 + hip->hi_inode = NULL;
2245 + if (unlikely(bend < 0))
2246 + iinfo->ii_bstart = 0;
2249 +static void au_br_do_add(struct super_block *sb, struct dentry *h_dentry,
2250 + struct au_branch *br, aufs_bindex_t bindex)
2252 + struct dentry *root;
2253 + struct inode *root_inode;
2254 + aufs_bindex_t bend, amount;
2256 + root = sb->s_root;
2257 + root_inode = root->d_inode;
2258 + bend = au_sbend(sb);
2259 + amount = bend + 1 - bindex;
2260 + au_sbilist_lock();
2261 + au_br_do_add_brp(au_sbi(sb), bindex, br, bend, amount);
2262 + au_br_do_add_hdp(au_di(root), bindex, bend, amount);
2263 + au_br_do_add_hip(au_ii(root_inode), bindex, bend, amount);
2264 + au_set_h_dptr(root, bindex, dget(h_dentry));
2265 + au_set_h_iptr(root_inode, bindex, au_igrab(h_dentry->d_inode),
2267 + au_sbilist_unlock();
2270 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
2273 + aufs_bindex_t bend, add_bindex;
2274 + struct dentry *root, *h_dentry;
2275 + struct inode *root_inode;
2276 + struct au_branch *add_branch;
2278 + root = sb->s_root;
2279 + root_inode = root->d_inode;
2280 + IMustLock(root_inode);
2281 + err = test_add(sb, add, remount);
2282 + if (unlikely(err < 0))
2286 + goto out; /* success */
2289 + bend = au_sbend(sb);
2290 + add_branch = au_br_alloc(sb, bend + 2, add->perm);
2291 + err = PTR_ERR(add_branch);
2292 + if (IS_ERR(add_branch))
2295 + err = au_br_init(add_branch, sb, add);
2296 + if (unlikely(err)) {
2297 + au_br_do_free(add_branch);
2301 + add_bindex = add->bindex;
2302 + h_dentry = add->path.dentry;
2304 + au_br_do_add(sb, h_dentry, add_branch, add_bindex);
2306 + sysaufs_brs_del(sb, add_bindex);
2307 + au_br_do_add(sb, h_dentry, add_branch, add_bindex);
2308 + sysaufs_brs_add(sb, add_bindex);
2311 + if (!add_bindex) {
2312 + au_cpup_attr_all(root_inode, /*force*/1);
2313 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
2315 + au_add_nlink(root_inode, h_dentry->d_inode);
2318 + * this test/set prevents aufs from handling unnecesary notify events
2319 + * of xino files, in case of re-adding a writable branch which was
2320 + * once detached from aufs.
2322 + if (au_xino_brid(sb) < 0
2323 + && au_br_writable(add_branch->br_perm)
2324 + && !au_test_fs_bad_xino(h_dentry->d_sb)
2325 + && add_branch->br_xino.xi_file
2326 + && add_branch->br_xino.xi_file->f_dentry->d_parent == h_dentry)
2327 + au_xino_brid_set(sb, add_branch->br_id);
2333 +/* ---------------------------------------------------------------------- */
2339 +/* to show the line number, do not make it inlined function */
2340 +#define AuVerbose(do_info, fmt, ...) do { \
2342 + pr_info(fmt, ##__VA_ARGS__); \
2345 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t bstart,
2346 + aufs_bindex_t bend)
2348 + return (inode && !S_ISDIR(inode->i_mode)) || bstart == bend;
2351 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t bstart,
2352 + aufs_bindex_t bend)
2354 + return au_test_ibusy(dentry->d_inode, bstart, bend);
2358 + * test if the branch is deletable or not.
2360 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
2361 + unsigned int sigen, const unsigned int verbose)
2363 + int err, i, j, ndentry;
2364 + aufs_bindex_t bstart, bend;
2365 + struct au_dcsub_pages dpages;
2366 + struct au_dpage *dpage;
2369 + err = au_dpages_init(&dpages, GFP_NOFS);
2370 + if (unlikely(err))
2372 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
2373 + if (unlikely(err))
2376 + for (i = 0; !err && i < dpages.ndpage; i++) {
2377 + dpage = dpages.dpages + i;
2378 + ndentry = dpage->ndentry;
2379 + for (j = 0; !err && j < ndentry; j++) {
2380 + d = dpage->dentries[j];
2381 + AuDebugOn(!d->d_count);
2382 + if (!au_digen_test(d, sigen)) {
2383 + di_read_lock_child(d, AuLock_IR);
2384 + if (unlikely(au_dbrange_test(d))) {
2385 + di_read_unlock(d, AuLock_IR);
2389 + di_write_lock_child(d);
2390 + if (unlikely(au_dbrange_test(d))) {
2391 + di_write_unlock(d);
2394 + err = au_reval_dpath(d, sigen);
2396 + di_downgrade_lock(d, AuLock_IR);
2398 + di_write_unlock(d);
2403 + /* AuDbgDentry(d); */
2404 + bstart = au_dbstart(d);
2405 + bend = au_dbend(d);
2406 + if (bstart <= bindex
2408 + && au_h_dptr(d, bindex)
2409 + && au_test_dbusy(d, bstart, bend)) {
2411 + AuVerbose(verbose, "busy %.*s\n", AuDLNPair(d));
2414 + di_read_unlock(d, AuLock_IR);
2419 + au_dpages_free(&dpages);
2424 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
2425 + unsigned int sigen, const unsigned int verbose)
2428 + unsigned long long max, ull;
2429 + struct inode *i, **array;
2430 + aufs_bindex_t bstart, bend;
2432 + array = au_iarray_alloc(sb, &max);
2433 + err = PTR_ERR(array);
2434 + if (IS_ERR(array))
2438 + AuDbg("b%d\n", bindex);
2439 + for (ull = 0; !err && ull < max; ull++) {
2441 + if (i->i_ino == AUFS_ROOT_INO)
2444 + /* AuDbgInode(i); */
2445 + if (au_iigen(i) == sigen)
2446 + ii_read_lock_child(i);
2448 + ii_write_lock_child(i);
2449 + err = au_refresh_hinode_self(i);
2452 + ii_downgrade_lock(i);
2454 + ii_write_unlock(i);
2459 + bstart = au_ibstart(i);
2460 + bend = au_ibend(i);
2461 + if (bstart <= bindex
2463 + && au_h_iptr(i, bindex)
2464 + && au_test_ibusy(i, bstart, bend)) {
2466 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
2469 + ii_read_unlock(i);
2471 + au_iarray_free(array, max);
2477 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
2478 + const unsigned int verbose)
2481 + unsigned int sigen;
2483 + sigen = au_sigen(root->d_sb);
2484 + DiMustNoWaiters(root);
2485 + IiMustNoWaiters(root->d_inode);
2486 + di_write_unlock(root);
2487 + err = test_dentry_busy(root, bindex, sigen, verbose);
2489 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
2490 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
2495 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
2496 + const aufs_bindex_t bindex,
2497 + const aufs_bindex_t bend)
2499 + struct au_branch **brp, **p;
2501 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2503 + brp = sbinfo->si_branch + bindex;
2504 + if (bindex < bend)
2505 + memmove(brp, brp + 1, sizeof(*brp) * (bend - bindex));
2506 + sbinfo->si_branch[0 + bend] = NULL;
2507 + sbinfo->si_bend--;
2509 + p = krealloc(sbinfo->si_branch, sizeof(*p) * bend, AuGFP_SBILIST);
2511 + sbinfo->si_branch = p;
2512 + /* harmless error */
2515 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
2516 + const aufs_bindex_t bend)
2518 + struct au_hdentry *hdp, *p;
2520 + AuRwMustWriteLock(&dinfo->di_rwsem);
2522 + hdp = dinfo->di_hdentry;
2523 + if (bindex < bend)
2524 + memmove(hdp + bindex, hdp + bindex + 1,
2525 + sizeof(*hdp) * (bend - bindex));
2526 + hdp[0 + bend].hd_dentry = NULL;
2529 + p = krealloc(hdp, sizeof(*p) * bend, AuGFP_SBILIST);
2531 + dinfo->di_hdentry = p;
2532 + /* harmless error */
2535 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
2536 + const aufs_bindex_t bend)
2538 + struct au_hinode *hip, *p;
2540 + AuRwMustWriteLock(&iinfo->ii_rwsem);
2542 + hip = iinfo->ii_hinode + bindex;
2543 + if (bindex < bend)
2544 + memmove(hip, hip + 1, sizeof(*hip) * (bend - bindex));
2545 + iinfo->ii_hinode[0 + bend].hi_inode = NULL;
2546 + au_hn_init(iinfo->ii_hinode + bend);
2549 + p = krealloc(iinfo->ii_hinode, sizeof(*p) * bend, AuGFP_SBILIST);
2551 + iinfo->ii_hinode = p;
2552 + /* harmless error */
2555 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
2556 + struct au_branch *br)
2558 + aufs_bindex_t bend;
2559 + struct au_sbinfo *sbinfo;
2560 + struct dentry *root, *h_root;
2561 + struct inode *inode, *h_inode;
2562 + struct au_hinode *hinode;
2564 + SiMustWriteLock(sb);
2566 + root = sb->s_root;
2567 + inode = root->d_inode;
2568 + sbinfo = au_sbi(sb);
2569 + bend = sbinfo->si_bend;
2571 + h_root = au_h_dptr(root, bindex);
2572 + hinode = au_hi(inode, bindex);
2573 + h_inode = au_igrab(hinode->hi_inode);
2576 + au_sbilist_lock();
2577 + au_br_do_del_brp(sbinfo, bindex, bend);
2578 + au_br_do_del_hdp(au_di(root), bindex, bend);
2579 + au_br_do_del_hip(au_ii(inode), bindex, bend);
2580 + au_sbilist_unlock();
2584 + au_br_do_free(br);
2587 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
2590 + unsigned int mnt_flags;
2591 + aufs_bindex_t bindex, bend, br_id;
2592 + unsigned char do_wh, verbose;
2593 + struct au_branch *br;
2594 + struct au_wbr *wbr;
2597 + bindex = au_find_dbindex(sb->s_root, del->h_path.dentry);
2600 + goto out; /* success */
2602 + pr_err("%s no such branch\n", del->pathname);
2605 + AuDbg("bindex b%d\n", bindex);
2608 + mnt_flags = au_mntflags(sb);
2609 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
2610 + bend = au_sbend(sb);
2611 + if (unlikely(!bend)) {
2612 + AuVerbose(verbose, "no more branches left\n");
2615 + br = au_sbr(sb, bindex);
2616 + i = atomic_read(&br->br_count);
2617 + if (unlikely(i)) {
2618 + AuVerbose(verbose, "%d file(s) opened\n", i);
2623 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
2625 + /* instead of WbrWhMustWriteLock(wbr) */
2626 + SiMustWriteLock(sb);
2627 + for (i = 0; i < AuBrWh_Last; i++) {
2628 + dput(wbr->wbr_wh[i]);
2629 + wbr->wbr_wh[i] = NULL;
2633 + err = test_children_busy(sb->s_root, bindex, verbose);
2634 + if (unlikely(err)) {
2641 + br_id = br->br_id;
2643 + au_br_do_del(sb, bindex, br);
2645 + sysaufs_brs_del(sb, bindex);
2646 + au_br_do_del(sb, bindex, br);
2647 + sysaufs_brs_add(sb, bindex);
2651 + au_cpup_attr_all(sb->s_root->d_inode, /*force*/1);
2652 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
2654 + au_sub_nlink(sb->s_root->d_inode, del->h_path.dentry->d_inode);
2655 + if (au_opt_test(mnt_flags, PLINK))
2656 + au_plink_half_refresh(sb, br_id);
2658 + if (au_xino_brid(sb) == br_id)
2659 + au_xino_brid_set(sb, -1);
2660 + goto out; /* success */
2664 + rerr = au_br_init_wh(sb, br, br->br_perm, del->h_path.dentry);
2666 + pr_warning("failed re-creating base whiteout, %s. (%d)\n",
2667 + del->pathname, rerr);
2672 +/* ---------------------------------------------------------------------- */
2674 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
2677 + aufs_bindex_t bstart, bend;
2678 + struct aufs_ibusy ibusy;
2679 + struct inode *inode, *h_inode;
2682 + if (unlikely(!capable(CAP_SYS_ADMIN)))
2685 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
2687 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
2688 + if (unlikely(err)) {
2695 + si_read_lock(sb, AuLock_FLUSH);
2696 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbend(sb)))
2700 + ibusy.h_ino = 0; /* invalid */
2701 + inode = ilookup(sb, ibusy.ino);
2703 + || inode->i_ino == AUFS_ROOT_INO
2704 + || is_bad_inode(inode))
2707 + ii_read_lock_child(inode);
2708 + bstart = au_ibstart(inode);
2709 + bend = au_ibend(inode);
2710 + if (bstart <= ibusy.bindex && ibusy.bindex <= bend) {
2711 + h_inode = au_h_iptr(inode, ibusy.bindex);
2712 + if (h_inode && au_test_ibusy(inode, bstart, bend))
2713 + ibusy.h_ino = h_inode->i_ino;
2715 + ii_read_unlock(inode);
2719 + si_read_unlock(sb);
2721 + err = __put_user(ibusy.h_ino, &arg->h_ino);
2722 + if (unlikely(err)) {
2731 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
2733 + return au_ibusy(file->f_dentry->d_sb, (void __user *)arg);
2736 +#ifdef CONFIG_COMPAT
2737 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
2739 + return au_ibusy(file->f_dentry->d_sb, compat_ptr(arg));
2743 +/* ---------------------------------------------------------------------- */
2746 + * change a branch permission
2749 +static void au_warn_ima(void)
2752 + /* since it doesn't support mark_files_ro() */
2753 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
2757 +static int do_need_sigen_inc(int a, int b)
2759 + return au_br_whable(a) && !au_br_whable(b);
2762 +static int need_sigen_inc(int old, int new)
2764 + return do_need_sigen_inc(old, new)
2765 + || do_need_sigen_inc(new, old);
2768 +static unsigned long long au_farray_cb(void *a,
2769 + unsigned long long max __maybe_unused,
2772 + unsigned long long n;
2773 + struct file **p, *f;
2774 + struct super_block *sb = arg;
2778 + lg_global_lock(files_lglock);
2779 + do_file_list_for_each_entry(sb, f) {
2782 + && !special_file(f->f_dentry->d_inode->i_mode)) {
2786 + AuDebugOn(n > max);
2788 + } while_file_list_for_each_entry;
2789 + lg_global_unlock(files_lglock);
2794 +static struct file **au_farray_alloc(struct super_block *sb,
2795 + unsigned long long *max)
2797 + *max = atomic_long_read(&au_sbi(sb)->si_nfiles);
2798 + return au_array_alloc(max, au_farray_cb, sb);
2801 +static void au_farray_free(struct file **a, unsigned long long max)
2803 + unsigned long long ull;
2805 + for (ull = 0; ull < max; ull++)
2811 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
2814 + unsigned int mnt_flags;
2815 + unsigned long long ull, max;
2816 + aufs_bindex_t br_id;
2817 + unsigned char verbose;
2818 + struct file *file, *hf, **array;
2819 + struct inode *inode;
2820 + struct au_hfile *hfile;
2822 + mnt_flags = au_mntflags(sb);
2823 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
2825 + array = au_farray_alloc(sb, &max);
2826 + err = PTR_ERR(array);
2827 + if (IS_ERR(array))
2831 + br_id = au_sbr_id(sb, bindex);
2832 + for (ull = 0; ull < max; ull++) {
2833 + file = array[ull];
2835 + /* AuDbg("%.*s\n", AuDLNPair(file->f_dentry)); */
2836 + fi_read_lock(file);
2837 + if (unlikely(au_test_mmapped(file))) {
2839 + AuVerbose(verbose, "mmapped %.*s\n",
2840 + AuDLNPair(file->f_dentry));
2842 + FiMustNoWaiters(file);
2843 + fi_read_unlock(file);
2847 + inode = file->f_dentry->d_inode;
2848 + hfile = &au_fi(file)->fi_htop;
2849 + hf = hfile->hf_file;
2850 + if (!S_ISREG(inode->i_mode)
2851 + || !(file->f_mode & FMODE_WRITE)
2852 + || hfile->hf_br->br_id != br_id
2853 + || !(hf->f_mode & FMODE_WRITE))
2854 + array[ull] = NULL;
2860 + FiMustNoWaiters(file);
2861 + fi_read_unlock(file);
2869 + for (ull = 0; ull < max; ull++) {
2870 + file = array[ull];
2874 + /* todo: already flushed? */
2875 + /* cf. fs/super.c:mark_files_ro() */
2876 + /* fi_read_lock(file); */
2877 + hfile = &au_fi(file)->fi_htop;
2878 + hf = hfile->hf_file;
2879 + /* fi_read_unlock(file); */
2880 + spin_lock(&hf->f_lock);
2881 + hf->f_mode &= ~FMODE_WRITE;
2882 + spin_unlock(&hf->f_lock);
2883 + if (!file_check_writeable(hf)) {
2884 + file_release_write(hf);
2885 + mnt_drop_write(hf->f_vfsmnt);
2890 + au_farray_free(array, max);
2896 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
2900 + aufs_bindex_t bindex;
2902 + struct dentry *root;
2903 + struct au_branch *br;
2905 + root = sb->s_root;
2906 + bindex = au_find_dbindex(root, mod->h_root);
2909 + return 0; /* success */
2911 + pr_err("%s no such branch\n", mod->path);
2914 + AuDbg("bindex b%d\n", bindex);
2916 + err = test_br(mod->h_root->d_inode, mod->perm, mod->path);
2917 + if (unlikely(err))
2920 + br = au_sbr(sb, bindex);
2921 + if (br->br_perm == mod->perm)
2922 + return 0; /* success */
2924 + if (au_br_writable(br->br_perm)) {
2925 + /* remove whiteout base */
2926 + err = au_br_init_wh(sb, br, mod->perm, mod->h_root);
2927 + if (unlikely(err))
2930 + if (!au_br_writable(mod->perm)) {
2931 + /* rw --> ro, file might be mmapped */
2932 + DiMustNoWaiters(root);
2933 + IiMustNoWaiters(root->d_inode);
2934 + di_write_unlock(root);
2935 + err = au_br_mod_files_ro(sb, bindex);
2936 + /* aufs_write_lock() calls ..._child() */
2937 + di_write_lock_child(root);
2939 + if (unlikely(err)) {
2941 + br->br_wbr = kmalloc(sizeof(*br->br_wbr),
2944 + path.mnt = br->br_mnt;
2945 + path.dentry = mod->h_root;
2946 + rerr = au_wbr_init(br, sb, br->br_perm,
2949 + if (unlikely(rerr)) {
2950 + AuIOErr("nested error %d (%d)\n",
2952 + br->br_perm = mod->perm;
2956 + } else if (au_br_writable(mod->perm)) {
2959 + br->br_wbr = kmalloc(sizeof(*br->br_wbr), GFP_NOFS);
2961 + path.mnt = br->br_mnt;
2962 + path.dentry = mod->h_root;
2963 + err = au_wbr_init(br, sb, mod->perm, &path);
2964 + if (unlikely(err)) {
2965 + kfree(br->br_wbr);
2966 + br->br_wbr = NULL;
2972 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
2973 + br->br_perm = mod->perm;
2980 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
2981 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
2982 +++ linux/fs/aufs/branch.h 2012-03-19 12:24:13.679801090 +0100
2985 + * Copyright (C) 2005-2012 Junjiro R. Okajima
2987 + * This program, aufs is free software; you can redistribute it and/or modify
2988 + * it under the terms of the GNU General Public License as published by
2989 + * the Free Software Foundation; either version 2 of the License, or
2990 + * (at your option) any later version.
2992 + * This program is distributed in the hope that it will be useful,
2993 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2994 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2995 + * GNU General Public License for more details.
2997 + * You should have received a copy of the GNU General Public License
2998 + * along with this program; if not, write to the Free Software
2999 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3003 + * branch filesystems and xino for them
3006 +#ifndef __AUFS_BRANCH_H__
3007 +#define __AUFS_BRANCH_H__
3011 +#include <linux/mount.h>
3016 +/* ---------------------------------------------------------------------- */
3019 +struct au_xino_file {
3020 + struct file *xi_file;
3021 + struct mutex xi_nondir_mtx;
3023 + /* todo: make xino files an array to support huge inode number */
3025 +#ifdef CONFIG_DEBUG_FS
3026 + struct dentry *xi_dbgaufs;
3030 +/* members for writable branch only */
3031 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
3033 + struct au_rwsem wbr_wh_rwsem;
3034 + struct dentry *wbr_wh[AuBrWh_Last];
3035 + atomic_t wbr_wh_running;
3036 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
3037 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
3038 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
3041 + unsigned long long wbr_bytes;
3044 +/* ext2 has 3 types of operations at least, ext3 has 4 */
3045 +#define AuBrDynOp (AuDyLast * 4)
3047 +/* protected by superblock rwsem */
3049 + struct au_xino_file br_xino;
3051 + aufs_bindex_t br_id;
3054 + struct vfsmount *br_mnt;
3055 + spinlock_t br_dykey_lock;
3056 + struct au_dykey *br_dykey[AuBrDynOp];
3057 + atomic_t br_count;
3059 + struct au_wbr *br_wbr;
3061 + /* xino truncation */
3062 + blkcnt_t br_xino_upper; /* watermark in blocks */
3063 + atomic_t br_xino_running;
3065 +#ifdef CONFIG_AUFS_HFSNOTIFY
3066 + struct fsnotify_group *br_hfsn_group;
3067 + struct fsnotify_ops br_hfsn_ops;
3070 +#ifdef CONFIG_SYSFS
3071 + /* an entry under sysfs per mount-point */
3073 + struct attribute br_attr;
3077 +/* ---------------------------------------------------------------------- */
3079 +/* branch permissions and attributes */
3080 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
3081 +#define AuBrPerm_RO (1 << 1) /* readonly */
3082 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
3083 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
3085 +#define AuBrRAttr_WH (1 << 3) /* whiteout-able */
3087 +#define AuBrWAttr_NoLinkWH (1 << 4) /* un-hardlinkable whiteouts */
3089 +static inline int au_br_writable(int brperm)
3091 + return brperm & AuBrPerm_RW;
3094 +static inline int au_br_whable(int brperm)
3096 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
3099 +static inline int au_br_wh_linkable(int brperm)
3101 + return !(brperm & AuBrWAttr_NoLinkWH);
3104 +static inline int au_br_rdonly(struct au_branch *br)
3106 + return ((br->br_mnt->mnt_sb->s_flags & MS_RDONLY)
3107 + || !au_br_writable(br->br_perm))
3111 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
3113 +#ifdef CONFIG_AUFS_HNOTIFY
3114 + return !(brperm & AuBrPerm_RR);
3120 +/* ---------------------------------------------------------------------- */
3124 +void au_br_free(struct au_sbinfo *sinfo);
3125 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
3127 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
3129 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
3130 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
3131 +#ifdef CONFIG_COMPAT
3132 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
3135 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
3139 +static const loff_t au_loff_max = LLONG_MAX;
3141 +int au_xib_trunc(struct super_block *sb);
3142 +ssize_t xino_fread(au_readf_t func, struct file *file, void *buf, size_t size,
3144 +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size,
3146 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src);
3147 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent);
3148 +ino_t au_xino_new_ino(struct super_block *sb);
3149 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
3150 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
3152 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
3154 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino,
3155 + struct file *base_file, int do_test);
3156 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex);
3158 +struct au_opt_xino;
3159 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount);
3160 +void au_xino_clr(struct super_block *sb);
3161 +struct file *au_xino_def(struct super_block *sb);
3162 +int au_xino_path(struct seq_file *seq, struct file *file);
3164 +/* ---------------------------------------------------------------------- */
3166 +/* Superblock to branch */
3168 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
3170 + return au_sbr(sb, bindex)->br_id;
3174 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
3176 + return au_sbr(sb, bindex)->br_mnt;
3180 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
3182 + return au_sbr_mnt(sb, bindex)->mnt_sb;
3185 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
3187 + atomic_dec(&au_sbr(sb, bindex)->br_count);
3190 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
3192 + return au_sbr(sb, bindex)->br_perm;
3195 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
3197 + return au_br_whable(au_sbr_perm(sb, bindex));
3200 +/* ---------------------------------------------------------------------- */
3203 + * wbr_wh_read_lock, wbr_wh_write_lock
3204 + * wbr_wh_read_unlock, wbr_wh_write_unlock, wbr_wh_downgrade_lock
3206 +AuSimpleRwsemFuncs(wbr_wh, struct au_wbr *wbr, &wbr->wbr_wh_rwsem);
3208 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&wbr->wbr_wh_rwsem)
3209 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&wbr->wbr_wh_rwsem)
3210 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&wbr->wbr_wh_rwsem)
3212 +#endif /* __KERNEL__ */
3213 +#endif /* __AUFS_BRANCH_H__ */
3214 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
3215 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
3216 +++ linux/fs/aufs/conf.mk 2012-03-19 12:24:13.679801090 +0100
3219 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
3223 +AuConfStr += ${1}=${${1}}
3227 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
3229 + HNOTIFY HFSNOTIFY \
3240 +$(foreach i, ${AuConfAll}, \
3241 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
3243 +AuConfName = ${obj}/conf.str
3244 +${AuConfName}.tmp: FORCE
3245 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
3246 +${AuConfName}: ${AuConfName}.tmp
3247 + @diff -q $< $@ > /dev/null 2>&1 || { \
3248 + echo ' GEN ' $@; \
3252 +clean-files += ${AuConfName} ${AuConfName}.tmp
3253 +${obj}/sysfs.o: ${AuConfName}
3255 +-include ${srctree}/${src}/conf_priv.mk
3256 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
3257 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
3258 +++ linux/fs/aufs/cpup.c 2012-03-19 12:24:13.679801090 +0100
3261 + * Copyright (C) 2005-2012 Junjiro R. Okajima
3263 + * This program, aufs is free software; you can redistribute it and/or modify
3264 + * it under the terms of the GNU General Public License as published by
3265 + * the Free Software Foundation; either version 2 of the License, or
3266 + * (at your option) any later version.
3268 + * This program is distributed in the hope that it will be useful,
3269 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3270 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3271 + * GNU General Public License for more details.
3273 + * You should have received a copy of the GNU General Public License
3274 + * along with this program; if not, write to the Free Software
3275 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3279 + * copy-up functions, see wbr_policy.c for copy-down
3282 +#include <linux/fs_stack.h>
3283 +#include <linux/mm.h>
3286 +void au_cpup_attr_flags(struct inode *dst, struct inode *src)
3288 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
3289 + | S_NOATIME | S_NOCMTIME;
3291 + dst->i_flags |= src->i_flags & ~mask;
3292 + if (au_test_fs_notime(dst->i_sb))
3293 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
3296 +void au_cpup_attr_timesizes(struct inode *inode)
3298 + struct inode *h_inode;
3300 + h_inode = au_h_iptr(inode, au_ibstart(inode));
3301 + fsstack_copy_attr_times(inode, h_inode);
3302 + fsstack_copy_inode_size(inode, h_inode);
3305 +void au_cpup_attr_nlink(struct inode *inode, int force)
3307 + struct inode *h_inode;
3308 + struct super_block *sb;
3309 + aufs_bindex_t bindex, bend;
3312 + bindex = au_ibstart(inode);
3313 + h_inode = au_h_iptr(inode, bindex);
3315 + && !S_ISDIR(h_inode->i_mode)
3316 + && au_opt_test(au_mntflags(sb), PLINK)
3317 + && au_plink_test(inode))
3321 + * 0 can happen in revalidating.
3322 + * h_inode->i_mutex is not held, but it is harmless since once i_nlink
3323 + * reaches 0, it will never become positive.
3325 + vfsub_set_nlink(inode, h_inode->i_nlink);
3328 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
3329 + * it may includes whplink directory.
3331 + if (S_ISDIR(h_inode->i_mode)) {
3332 + bend = au_ibend(inode);
3333 + for (bindex++; bindex <= bend; bindex++) {
3334 + h_inode = au_h_iptr(inode, bindex);
3336 + au_add_nlink(inode, h_inode);
3341 +void au_cpup_attr_changeable(struct inode *inode)
3343 + struct inode *h_inode;
3345 + h_inode = au_h_iptr(inode, au_ibstart(inode));
3346 + inode->i_mode = h_inode->i_mode;
3347 + inode->i_uid = h_inode->i_uid;
3348 + inode->i_gid = h_inode->i_gid;
3349 + au_cpup_attr_timesizes(inode);
3350 + au_cpup_attr_flags(inode, h_inode);
3353 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
3355 + struct au_iinfo *iinfo = au_ii(inode);
3357 + IiMustWriteLock(inode);
3359 + iinfo->ii_higen = h_inode->i_generation;
3360 + iinfo->ii_hsb1 = h_inode->i_sb;
3363 +void au_cpup_attr_all(struct inode *inode, int force)
3365 + struct inode *h_inode;
3367 + h_inode = au_h_iptr(inode, au_ibstart(inode));
3368 + au_cpup_attr_changeable(inode);
3369 + if (inode->i_nlink > 0)
3370 + au_cpup_attr_nlink(inode, force);
3371 + inode->i_rdev = h_inode->i_rdev;
3372 + inode->i_blkbits = h_inode->i_blkbits;
3373 + au_cpup_igen(inode, h_inode);
3376 +/* ---------------------------------------------------------------------- */
3378 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
3380 +/* keep the timestamps of the parent dir when cpup */
3381 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
3382 + struct path *h_path)
3384 + struct inode *h_inode;
3386 + dt->dt_dentry = dentry;
3387 + dt->dt_h_path = *h_path;
3388 + h_inode = h_path->dentry->d_inode;
3389 + dt->dt_atime = h_inode->i_atime;
3390 + dt->dt_mtime = h_inode->i_mtime;
3394 +void au_dtime_revert(struct au_dtime *dt)
3396 + struct iattr attr;
3399 + attr.ia_atime = dt->dt_atime;
3400 + attr.ia_mtime = dt->dt_mtime;
3401 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
3402 + | ATTR_ATIME | ATTR_ATIME_SET;
3404 + err = vfsub_notify_change(&dt->dt_h_path, &attr);
3405 + if (unlikely(err))
3406 + pr_warning("restoring timestamps failed(%d). ignored\n", err);
3409 +/* ---------------------------------------------------------------------- */
3411 +static noinline_for_stack
3412 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src)
3416 + struct path h_path;
3417 + struct inode *h_isrc, *h_idst;
3419 + h_path.dentry = au_h_dptr(dst, bindex);
3420 + h_idst = h_path.dentry->d_inode;
3421 + h_path.mnt = au_sbr_mnt(dst->d_sb, bindex);
3422 + h_isrc = h_src->d_inode;
3423 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
3424 + | ATTR_ATIME | ATTR_MTIME
3425 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
3426 + ia.ia_uid = h_isrc->i_uid;
3427 + ia.ia_gid = h_isrc->i_gid;
3428 + ia.ia_atime = h_isrc->i_atime;
3429 + ia.ia_mtime = h_isrc->i_mtime;
3430 + if (h_idst->i_mode != h_isrc->i_mode
3431 + && !S_ISLNK(h_idst->i_mode)) {
3432 + ia.ia_valid |= ATTR_MODE;
3433 + ia.ia_mode = h_isrc->i_mode;
3435 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
3436 + au_cpup_attr_flags(h_idst, h_isrc);
3437 + err = vfsub_notify_change(&h_path, &ia);
3439 + /* is this nfs only? */
3440 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
3441 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
3442 + ia.ia_mode = h_isrc->i_mode;
3443 + err = vfsub_notify_change(&h_path, &ia);
3449 +/* ---------------------------------------------------------------------- */
3451 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
3452 + char *buf, unsigned long blksize)
3455 + size_t sz, rbytes, wbytes;
3456 + unsigned char all_zero;
3458 + struct mutex *h_mtx;
3459 + /* reduce stack usage */
3462 + zp = page_address(ZERO_PAGE(0));
3463 + if (unlikely(!zp))
3464 + return -ENOMEM; /* possible? */
3469 + AuDbg("len %lld\n", len);
3471 + if (len < blksize)
3475 + /* todo: signal_pending? */
3476 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
3477 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
3480 + if (unlikely(err < 0))
3484 + if (len >= rbytes && rbytes == blksize)
3485 + all_zero = !memcmp(buf, zp, rbytes);
3492 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
3494 + /* todo: signal_pending? */
3495 + if (unlikely(err == -EAGAIN || err == -EINTR))
3497 + if (unlikely(err < 0))
3506 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
3508 + if (unlikely(res < 0))
3515 + /* the last block may be a hole */
3516 + if (!err && all_zero) {
3517 + AuLabel(last hole);
3520 + if (au_test_nfs(dst->f_dentry->d_sb)) {
3521 + /* nfs requires this step to make last hole */
3522 + /* is this only nfs? */
3524 + /* todo: signal_pending? */
3525 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
3526 + } while (err == -EAGAIN || err == -EINTR);
3533 + ia->ia_size = dst->f_pos;
3534 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
3535 + ia->ia_file = dst;
3536 + h_mtx = &dst->f_dentry->d_inode->i_mutex;
3537 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
3538 + err = vfsub_notify_change(&dst->f_path, ia);
3539 + mutex_unlock(h_mtx);
3546 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
3549 + unsigned long blksize;
3550 + unsigned char do_kfree;
3554 + blksize = dst->f_dentry->d_sb->s_blocksize;
3555 + if (!blksize || PAGE_SIZE < blksize)
3556 + blksize = PAGE_SIZE;
3557 + AuDbg("blksize %lu\n", blksize);
3558 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
3560 + buf = kmalloc(blksize, GFP_NOFS);
3562 + buf = (void *)__get_free_page(GFP_NOFS);
3563 + if (unlikely(!buf))
3566 + if (len > (1 << 22))
3567 + AuDbg("copying a large file %lld\n", (long long)len);
3571 + err = au_do_copy_file(dst, src, len, buf, blksize);
3575 + free_page((unsigned long)buf);
3582 + * to support a sparse file which is opened with O_APPEND,
3583 + * we need to close the file.
3585 +static int au_cp_regular(struct dentry *dentry, aufs_bindex_t bdst,
3586 + aufs_bindex_t bsrc, loff_t len)
3589 + enum { SRC, DST };
3591 + aufs_bindex_t bindex;
3592 + unsigned int flags;
3593 + struct dentry *dentry;
3594 + struct file *file;
3595 + void *label, *label_file;
3599 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
3602 + .label_file = &&out_src
3606 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
3608 + .label = &&out_src,
3609 + .label_file = &&out_dst
3612 + struct super_block *sb;
3614 + /* bsrc branch can be ro/rw. */
3615 + sb = dentry->d_sb;
3617 + for (i = 0; i < 2; i++, f++) {
3618 + f->dentry = au_h_dptr(dentry, f->bindex);
3619 + f->file = au_h_open(dentry, f->bindex, f->flags, /*file*/NULL);
3620 + err = PTR_ERR(f->file);
3621 + if (IS_ERR(f->file))
3624 + if (unlikely(!f->file->f_op))
3625 + goto *f->label_file;
3628 + /* try stopping to update while we copyup */
3629 + IMustLock(file[SRC].dentry->d_inode);
3630 + err = au_copy_file(file[DST].file, file[SRC].file, len);
3633 + fput(file[DST].file);
3634 + au_sbr_put(sb, file[DST].bindex);
3636 + fput(file[SRC].file);
3637 + au_sbr_put(sb, file[SRC].bindex);
3642 +static int au_do_cpup_regular(struct dentry *dentry, aufs_bindex_t bdst,
3643 + aufs_bindex_t bsrc, loff_t len,
3644 + struct inode *h_dir, struct path *h_path)
3650 + l = i_size_read(au_h_iptr(dentry->d_inode, bsrc));
3651 + if (len == -1 || l < len)
3654 + err = au_cp_regular(dentry, bdst, bsrc, len);
3656 + goto out; /* success */
3658 + rerr = vfsub_unlink(h_dir, h_path, /*force*/0);
3660 + AuIOErr("failed unlinking cpup-ed %.*s(%d, %d)\n",
3661 + AuDLNPair(h_path->dentry), err, rerr);
3669 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
3670 + struct inode *h_dir)
3673 + mm_segment_t old_fs;
3680 + if (unlikely(!h_src->d_inode->i_op->readlink))
3684 + sym.k = __getname_gfp(GFP_NOFS);
3685 + if (unlikely(!sym.k))
3688 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
3689 + old_fs = get_fs();
3690 + set_fs(KERNEL_DS);
3691 + symlen = h_src->d_inode->i_op->readlink(h_src, sym.u, PATH_MAX);
3696 + sym.k[symlen] = 0;
3697 + err = vfsub_symlink(h_dir, h_path, sym.k);
3705 +/* return with the lower dst inode is locked */
3706 +static noinline_for_stack
3707 +int cpup_entry(struct dentry *dentry, aufs_bindex_t bdst,
3708 + aufs_bindex_t bsrc, loff_t len, unsigned int flags,
3709 + struct dentry *dst_parent)
3713 + unsigned int mnt_flags;
3714 + unsigned char isdir;
3715 + const unsigned char do_dt = !!au_ftest_cpup(flags, DTIME);
3716 + struct au_dtime dt;
3717 + struct path h_path;
3718 + struct dentry *h_src, *h_dst, *h_parent;
3719 + struct inode *h_inode, *h_dir;
3720 + struct super_block *sb;
3722 + /* bsrc branch can be ro/rw. */
3723 + h_src = au_h_dptr(dentry, bsrc);
3724 + h_inode = h_src->d_inode;
3725 + AuDebugOn(h_inode != au_h_iptr(dentry->d_inode, bsrc));
3727 + /* try stopping to be referenced while we are creating */
3728 + h_dst = au_h_dptr(dentry, bdst);
3729 + h_parent = h_dst->d_parent; /* dir inode is locked */
3730 + h_dir = h_parent->d_inode;
3732 + AuDebugOn(h_parent != h_dst->d_parent);
3734 + sb = dentry->d_sb;
3735 + h_path.mnt = au_sbr_mnt(sb, bdst);
3737 + h_path.dentry = h_parent;
3738 + au_dtime_store(&dt, dst_parent, &h_path);
3740 + h_path.dentry = h_dst;
3743 + mode = h_inode->i_mode;
3744 + switch (mode & S_IFMT) {
3746 + /* try stopping to update while we are referencing */
3747 + IMustLock(h_inode);
3748 + err = vfsub_create(h_dir, &h_path, mode | S_IWUSR);
3750 + err = au_do_cpup_regular
3751 + (dentry, bdst, bsrc, len,
3752 + au_h_iptr(dst_parent->d_inode, bdst), &h_path);
3756 + err = vfsub_mkdir(h_dir, &h_path, mode);
3759 + * strange behaviour from the users view,
3760 + * particularry setattr case
3762 + if (au_ibstart(dst_parent->d_inode) == bdst)
3763 + au_cpup_attr_nlink(dst_parent->d_inode,
3765 + au_cpup_attr_nlink(dentry->d_inode, /*force*/1);
3769 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
3773 + AuDebugOn(!capable(CAP_MKNOD));
3777 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
3780 + AuIOErr("Unknown inode type 0%o\n", mode);
3784 + mnt_flags = au_mntflags(sb);
3785 + if (!au_opt_test(mnt_flags, UDBA_NONE)
3787 + && au_opt_test(mnt_flags, XINO)
3788 + && h_inode->i_nlink == 1
3789 + /* todo: unnecessary? */
3790 + /* && dentry->d_inode->i_nlink == 1 */
3792 + && !au_ftest_cpup(flags, KEEPLINO))
3793 + au_xino_write(sb, bsrc, h_inode->i_ino, /*ino*/0);
3794 + /* ignore this error */
3797 + au_dtime_revert(&dt);
3802 + * copyup the @dentry from @bsrc to @bdst.
3803 + * the caller must set the both of lower dentries.
3804 + * @len is for truncating when it is -1 copyup the entire file.
3805 + * in link/rename cases, @dst_parent may be different from the real one.
3807 +static int au_cpup_single(struct dentry *dentry, aufs_bindex_t bdst,
3808 + aufs_bindex_t bsrc, loff_t len, unsigned int flags,
3809 + struct dentry *dst_parent)
3812 + aufs_bindex_t old_ibstart;
3813 + unsigned char isdir, plink;
3814 + struct au_dtime dt;
3815 + struct path h_path;
3816 + struct dentry *h_src, *h_dst, *h_parent;
3817 + struct inode *dst_inode, *h_dir, *inode;
3818 + struct super_block *sb;
3820 + AuDebugOn(bsrc <= bdst);
3822 + sb = dentry->d_sb;
3823 + h_path.mnt = au_sbr_mnt(sb, bdst);
3824 + h_dst = au_h_dptr(dentry, bdst);
3825 + h_parent = h_dst->d_parent; /* dir inode is locked */
3826 + h_dir = h_parent->d_inode;
3829 + h_src = au_h_dptr(dentry, bsrc);
3830 + inode = dentry->d_inode;
3833 + dst_parent = dget_parent(dentry);
3837 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
3838 + dst_inode = au_h_iptr(inode, bdst);
3840 + if (unlikely(!plink)) {
3842 + AuIOErr("hi%lu(i%lu) exists on b%d "
3843 + "but plink is disabled\n",
3844 + dst_inode->i_ino, inode->i_ino, bdst);
3848 + if (dst_inode->i_nlink) {
3849 + const int do_dt = au_ftest_cpup(flags, DTIME);
3851 + h_src = au_plink_lkup(inode, bdst);
3852 + err = PTR_ERR(h_src);
3853 + if (IS_ERR(h_src))
3855 + if (unlikely(!h_src->d_inode)) {
3857 + AuIOErr("i%lu exists on a upper branch "
3858 + "but not pseudo-linked\n",
3865 + h_path.dentry = h_parent;
3866 + au_dtime_store(&dt, dst_parent, &h_path);
3868 + h_path.dentry = h_dst;
3869 + err = vfsub_link(h_src, h_dir, &h_path);
3871 + au_dtime_revert(&dt);
3875 + /* todo: cpup_wh_file? */
3877 + au_update_ibrange(inode, /*do_put_zero*/1);
3880 + old_ibstart = au_ibstart(inode);
3881 + err = cpup_entry(dentry, bdst, bsrc, len, flags, dst_parent);
3882 + if (unlikely(err))
3884 + dst_inode = h_dst->d_inode;
3885 + mutex_lock_nested(&dst_inode->i_mutex, AuLsc_I_CHILD2);
3887 + err = cpup_iattr(dentry, bdst, h_src);
3888 + isdir = S_ISDIR(dst_inode->i_mode);
3890 + if (bdst < old_ibstart) {
3891 + if (S_ISREG(inode->i_mode)) {
3892 + err = au_dy_iaop(inode, bdst, dst_inode);
3893 + if (unlikely(err))
3896 + au_set_ibstart(inode, bdst);
3898 + au_set_h_iptr(inode, bdst, au_igrab(dst_inode),
3899 + au_hi_flags(inode, isdir));
3900 + mutex_unlock(&dst_inode->i_mutex);
3902 + && h_src->d_inode->i_nlink > 1
3904 + au_plink_append(inode, bdst, h_dst);
3905 + goto out; /* success */
3910 + h_path.dentry = h_parent;
3911 + mutex_unlock(&dst_inode->i_mutex);
3912 + au_dtime_store(&dt, dst_parent, &h_path);
3913 + h_path.dentry = h_dst;
3915 + rerr = vfsub_unlink(h_dir, &h_path, /*force*/0);
3917 + rerr = vfsub_rmdir(h_dir, &h_path);
3918 + au_dtime_revert(&dt);
3920 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
3929 +struct au_cpup_single_args {
3931 + struct dentry *dentry;
3932 + aufs_bindex_t bdst, bsrc;
3934 + unsigned int flags;
3935 + struct dentry *dst_parent;
3938 +static void au_call_cpup_single(void *args)
3940 + struct au_cpup_single_args *a = args;
3941 + *a->errp = au_cpup_single(a->dentry, a->bdst, a->bsrc, a->len,
3942 + a->flags, a->dst_parent);
3946 + * prevent SIGXFSZ in copy-up.
3947 + * testing CAP_MKNOD is for generic fs,
3948 + * but CAP_FSETID is for xfs only, currently.
3950 +static int au_cpup_sio_test(struct super_block *sb, umode_t mode)
3955 + if (!au_wkq_test()
3956 + && (!au_sbi(sb)->si_plink_maint_pid
3957 + || au_plink_maint(sb, AuLock_NOPLM))) {
3958 + switch (mode & S_IFMT) {
3960 + /* no condition about RLIMIT_FSIZE and the file size */
3965 + do_sio = !capable(CAP_MKNOD);
3969 + do_sio = ((mode & (S_ISUID | S_ISGID))
3970 + && !capable(CAP_FSETID));
3976 +int au_sio_cpup_single(struct dentry *dentry, aufs_bindex_t bdst,
3977 + aufs_bindex_t bsrc, loff_t len, unsigned int flags,
3978 + struct dentry *dst_parent)
3981 + struct dentry *h_dentry;
3983 + h_dentry = au_h_dptr(dentry, bsrc);
3984 + if (!au_cpup_sio_test(dentry->d_sb, h_dentry->d_inode->i_mode))
3985 + err = au_cpup_single(dentry, bdst, bsrc, len, flags,
3988 + struct au_cpup_single_args args = {
3995 + .dst_parent = dst_parent
3997 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
3998 + if (unlikely(wkq_err))
4006 + * copyup the @dentry from the first active lower branch to @bdst,
4007 + * using au_cpup_single().
4009 +static int au_cpup_simple(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
4010 + unsigned int flags)
4013 + aufs_bindex_t bsrc, bend;
4015 + bend = au_dbend(dentry);
4016 + for (bsrc = bdst + 1; bsrc <= bend; bsrc++)
4017 + if (au_h_dptr(dentry, bsrc))
4020 + err = au_lkup_neg(dentry, bdst);
4022 + err = au_cpup_single(dentry, bdst, bsrc, len, flags, NULL);
4024 + return 0; /* success */
4027 + au_set_h_dptr(dentry, bdst, NULL);
4028 + au_set_dbstart(dentry, bsrc);
4034 +struct au_cpup_simple_args {
4036 + struct dentry *dentry;
4037 + aufs_bindex_t bdst;
4039 + unsigned int flags;
4042 +static void au_call_cpup_simple(void *args)
4044 + struct au_cpup_simple_args *a = args;
4045 + *a->errp = au_cpup_simple(a->dentry, a->bdst, a->len, a->flags);
4048 +int au_sio_cpup_simple(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
4049 + unsigned int flags)
4052 + struct dentry *parent;
4053 + struct inode *h_dir;
4055 + parent = dget_parent(dentry);
4056 + h_dir = au_h_iptr(parent->d_inode, bdst);
4057 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
4058 + && !au_cpup_sio_test(dentry->d_sb, dentry->d_inode->i_mode))
4059 + err = au_cpup_simple(dentry, bdst, len, flags);
4061 + struct au_cpup_simple_args args = {
4068 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
4069 + if (unlikely(wkq_err))
4077 +/* ---------------------------------------------------------------------- */
4080 + * copyup the deleted file for writing.
4082 +static int au_do_cpup_wh(struct dentry *dentry, aufs_bindex_t bdst,
4083 + struct dentry *wh_dentry, struct file *file,
4087 + aufs_bindex_t bstart;
4088 + struct au_dinfo *dinfo;
4089 + struct dentry *h_d_dst, *h_d_start;
4090 + struct au_hdentry *hdp;
4092 + dinfo = au_di(dentry);
4093 + AuRwMustWriteLock(&dinfo->di_rwsem);
4095 + bstart = dinfo->di_bstart;
4096 + hdp = dinfo->di_hdentry;
4097 + h_d_dst = hdp[0 + bdst].hd_dentry;
4098 + dinfo->di_bstart = bdst;
4099 + hdp[0 + bdst].hd_dentry = wh_dentry;
4101 + h_d_start = hdp[0 + bstart].hd_dentry;
4102 + hdp[0 + bstart].hd_dentry = au_hf_top(file)->f_dentry;
4104 + err = au_cpup_single(dentry, bdst, bstart, len, !AuCpup_DTIME,
4105 + /*h_parent*/NULL);
4108 + err = au_reopen_nondir(file);
4109 + hdp[0 + bstart].hd_dentry = h_d_start;
4111 + hdp[0 + bdst].hd_dentry = h_d_dst;
4112 + dinfo->di_bstart = bstart;
4117 +static int au_cpup_wh(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
4118 + struct file *file)
4121 + struct au_dtime dt;
4122 + struct dentry *parent, *h_parent, *wh_dentry;
4123 + struct au_branch *br;
4124 + struct path h_path;
4126 + br = au_sbr(dentry->d_sb, bdst);
4127 + parent = dget_parent(dentry);
4128 + h_parent = au_h_dptr(parent, bdst);
4129 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
4130 + err = PTR_ERR(wh_dentry);
4131 + if (IS_ERR(wh_dentry))
4134 + h_path.dentry = h_parent;
4135 + h_path.mnt = br->br_mnt;
4136 + au_dtime_store(&dt, parent, &h_path);
4137 + err = au_do_cpup_wh(dentry, bdst, wh_dentry, file, len);
4138 + if (unlikely(err))
4142 + h_path.dentry = wh_dentry;
4143 + if (!S_ISDIR(wh_dentry->d_inode->i_mode))
4144 + err = vfsub_unlink(h_parent->d_inode, &h_path, /*force*/0);
4146 + err = vfsub_rmdir(h_parent->d_inode, &h_path);
4147 + if (unlikely(err)) {
4148 + AuIOErr("failed remove copied-up tmp file %.*s(%d)\n",
4149 + AuDLNPair(wh_dentry), err);
4152 + au_dtime_revert(&dt);
4153 + au_set_hi_wh(dentry->d_inode, bdst, wh_dentry);
4162 +struct au_cpup_wh_args {
4164 + struct dentry *dentry;
4165 + aufs_bindex_t bdst;
4167 + struct file *file;
4170 +static void au_call_cpup_wh(void *args)
4172 + struct au_cpup_wh_args *a = args;
4173 + *a->errp = au_cpup_wh(a->dentry, a->bdst, a->len, a->file);
4176 +int au_sio_cpup_wh(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
4177 + struct file *file)
4180 + struct dentry *parent, *h_orph, *h_parent, *h_dentry;
4181 + struct inode *dir, *h_dir, *h_tmpdir, *h_inode;
4182 + struct au_wbr *wbr;
4184 + parent = dget_parent(dentry);
4185 + dir = parent->d_inode;
4188 + h_dir = au_igrab(au_h_iptr(dir, bdst));
4190 + if (!h_dir->i_nlink) {
4191 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
4192 + h_orph = wbr->wbr_orph;
4194 + h_parent = dget(au_h_dptr(parent, bdst));
4195 + au_set_h_dptr(parent, bdst, dget(h_orph));
4196 + h_tmpdir = h_orph->d_inode;
4197 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
4199 + /* this temporary unlock is safe */
4201 + h_dentry = au_hf_top(file)->f_dentry;
4203 + h_dentry = au_h_dptr(dentry, au_dbstart(dentry));
4204 + h_inode = h_dentry->d_inode;
4205 + IMustLock(h_inode);
4206 + mutex_unlock(&h_inode->i_mutex);
4207 + mutex_lock_nested(&h_tmpdir->i_mutex, AuLsc_I_PARENT3);
4208 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
4209 + /* todo: au_h_open_pre()? */
4212 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
4213 + && !au_cpup_sio_test(dentry->d_sb, dentry->d_inode->i_mode))
4214 + err = au_cpup_wh(dentry, bdst, len, file);
4216 + struct au_cpup_wh_args args = {
4223 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
4224 + if (unlikely(wkq_err))
4229 + mutex_unlock(&h_tmpdir->i_mutex);
4230 + /* todo: au_h_open_post()? */
4231 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
4232 + au_set_h_dptr(parent, bdst, h_parent);
4240 +/* ---------------------------------------------------------------------- */
4243 + * generic routine for both of copy-up and copy-down.
4245 +/* cf. revalidate function in file.c */
4246 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
4247 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
4248 + struct dentry *h_parent, void *arg),
4252 + struct au_pin pin;
4253 + struct dentry *d, *parent, *h_parent, *real_parent;
4256 + parent = dget_parent(dentry);
4257 + if (IS_ROOT(parent))
4260 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
4261 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
4263 + /* do not use au_dpage */
4264 + real_parent = parent;
4267 + parent = dget_parent(dentry);
4268 + h_parent = au_h_dptr(parent, bdst);
4270 + goto out; /* success */
4272 + /* find top dir which is necessary to cpup */
4276 + parent = dget_parent(d);
4277 + di_read_lock_parent3(parent, !AuLock_IR);
4278 + h_parent = au_h_dptr(parent, bdst);
4279 + di_read_unlock(parent, !AuLock_IR);
4280 + } while (!h_parent);
4282 + if (d != real_parent)
4283 + di_write_lock_child3(d);
4285 + /* somebody else might create while we were sleeping */
4286 + if (!au_h_dptr(d, bdst) || !au_h_dptr(d, bdst)->d_inode) {
4287 + if (au_h_dptr(d, bdst))
4288 + au_update_dbstart(d);
4290 + au_pin_set_dentry(&pin, d);
4291 + err = au_do_pin(&pin);
4293 + err = cp(d, bdst, h_parent, arg);
4298 + if (d != real_parent)
4299 + di_write_unlock(d);
4300 + if (unlikely(err))
4309 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
4310 + struct dentry *h_parent __maybe_unused ,
4311 + void *arg __maybe_unused)
4313 + return au_sio_cpup_simple(dentry, bdst, -1, AuCpup_DTIME);
4316 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
4318 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
4321 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
4324 + struct dentry *parent;
4325 + struct inode *dir;
4327 + parent = dget_parent(dentry);
4328 + dir = parent->d_inode;
4330 + if (au_h_iptr(dir, bdst))
4333 + di_read_unlock(parent, AuLock_IR);
4334 + di_write_lock_parent(parent);
4335 + /* someone else might change our inode while we were sleeping */
4336 + if (!au_h_iptr(dir, bdst))
4337 + err = au_cpup_dirs(dentry, bdst);
4338 + di_downgrade_lock(parent, AuLock_IR);
4344 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
4345 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
4346 +++ linux/fs/aufs/cpup.h 2012-03-19 12:24:13.679801090 +0100
4349 + * Copyright (C) 2005-2012 Junjiro R. Okajima
4351 + * This program, aufs is free software; you can redistribute it and/or modify
4352 + * it under the terms of the GNU General Public License as published by
4353 + * the Free Software Foundation; either version 2 of the License, or
4354 + * (at your option) any later version.
4356 + * This program is distributed in the hope that it will be useful,
4357 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4358 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4359 + * GNU General Public License for more details.
4361 + * You should have received a copy of the GNU General Public License
4362 + * along with this program; if not, write to the Free Software
4363 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
4367 + * copy-up/down functions
4370 +#ifndef __AUFS_CPUP_H__
4371 +#define __AUFS_CPUP_H__
4375 +#include <linux/path.h>
4380 +void au_cpup_attr_flags(struct inode *dst, struct inode *src);
4381 +void au_cpup_attr_timesizes(struct inode *inode);
4382 +void au_cpup_attr_nlink(struct inode *inode, int force);
4383 +void au_cpup_attr_changeable(struct inode *inode);
4384 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
4385 +void au_cpup_attr_all(struct inode *inode, int force);
4387 +/* ---------------------------------------------------------------------- */
4390 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
4391 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
4393 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
4394 +#define au_fset_cpup(flags, name) \
4395 + do { (flags) |= AuCpup_##name; } while (0)
4396 +#define au_fclr_cpup(flags, name) \
4397 + do { (flags) &= ~AuCpup_##name; } while (0)
4399 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
4400 +int au_sio_cpup_single(struct dentry *dentry, aufs_bindex_t bdst,
4401 + aufs_bindex_t bsrc, loff_t len, unsigned int flags,
4402 + struct dentry *dst_parent);
4403 +int au_sio_cpup_simple(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
4404 + unsigned int flags);
4405 +int au_sio_cpup_wh(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
4406 + struct file *file);
4408 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
4409 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
4410 + struct dentry *h_parent, void *arg),
4412 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
4413 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
4415 +/* ---------------------------------------------------------------------- */
4417 +/* keep timestamps when copyup */
4419 + struct dentry *dt_dentry;
4420 + struct path dt_h_path;
4421 + struct timespec dt_atime, dt_mtime;
4423 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4424 + struct path *h_path);
4425 +void au_dtime_revert(struct au_dtime *dt);
4427 +#endif /* __KERNEL__ */
4428 +#endif /* __AUFS_CPUP_H__ */
4429 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
4430 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
4431 +++ linux/fs/aufs/dbgaufs.c 2012-03-19 12:24:13.679801090 +0100
4434 + * Copyright (C) 2005-2012 Junjiro R. Okajima
4436 + * This program, aufs is free software; you can redistribute it and/or modify
4437 + * it under the terms of the GNU General Public License as published by
4438 + * the Free Software Foundation; either version 2 of the License, or
4439 + * (at your option) any later version.
4441 + * This program is distributed in the hope that it will be useful,
4442 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4443 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4444 + * GNU General Public License for more details.
4446 + * You should have received a copy of the GNU General Public License
4447 + * along with this program; if not, write to the Free Software
4448 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
4452 + * debugfs interface
4455 +#include <linux/debugfs.h>
4458 +#ifndef CONFIG_SYSFS
4459 +#error DEBUG_FS depends upon SYSFS
4462 +static struct dentry *dbgaufs;
4463 +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH;
4465 +/* 20 is max digits length of ulong 64 */
4466 +struct dbgaufs_arg {
4472 + * common function for all XINO files
4474 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
4475 + struct file *file)
4477 + kfree(file->private_data);
4481 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt)
4485 + struct dbgaufs_arg *p;
4488 + p = kmalloc(sizeof(*p), GFP_NOFS);
4494 + file->private_data = p;
4498 + err = vfs_getattr(xf->f_vfsmnt, xf->f_dentry, &st);
4502 + (p->a, sizeof(p->a), "%ld, %llux%lu %lld\n",
4503 + (long)file_count(xf), st.blocks, st.blksize,
4504 + (long long)st.size);
4506 + p->n = snprintf(p->a, sizeof(p->a), "%llux%lu %lld\n",
4507 + st.blocks, st.blksize,
4508 + (long long)st.size);
4509 + AuDebugOn(p->n >= sizeof(p->a));
4511 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
4520 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
4521 + size_t count, loff_t *ppos)
4523 + struct dbgaufs_arg *p;
4525 + p = file->private_data;
4526 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
4529 +/* ---------------------------------------------------------------------- */
4531 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
4534 + struct au_sbinfo *sbinfo;
4535 + struct super_block *sb;
4537 + sbinfo = inode->i_private;
4538 + sb = sbinfo->si_sb;
4539 + si_noflush_read_lock(sb);
4540 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
4541 + si_read_unlock(sb);
4545 +static const struct file_operations dbgaufs_xib_fop = {
4546 + .owner = THIS_MODULE,
4547 + .open = dbgaufs_xib_open,
4548 + .release = dbgaufs_xi_release,
4549 + .read = dbgaufs_xi_read
4552 +/* ---------------------------------------------------------------------- */
4554 +#define DbgaufsXi_PREFIX "xi"
4556 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
4560 + struct au_sbinfo *sbinfo;
4561 + struct super_block *sb;
4563 + struct qstr *name;
4567 + name = &file->f_dentry->d_name;
4568 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
4569 + || memcmp(name->name, DbgaufsXi_PREFIX,
4570 + sizeof(DbgaufsXi_PREFIX) - 1)))
4572 + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
4573 + if (unlikely(err))
4576 + sbinfo = inode->i_private;
4577 + sb = sbinfo->si_sb;
4578 + si_noflush_read_lock(sb);
4579 + if (l <= au_sbend(sb)) {
4580 + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file;
4581 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1);
4584 + si_read_unlock(sb);
4590 +static const struct file_operations dbgaufs_xino_fop = {
4591 + .owner = THIS_MODULE,
4592 + .open = dbgaufs_xino_open,
4593 + .release = dbgaufs_xi_release,
4594 + .read = dbgaufs_xi_read
4597 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
4599 + aufs_bindex_t bend;
4600 + struct au_branch *br;
4601 + struct au_xino_file *xi;
4603 + if (!au_sbi(sb)->si_dbgaufs)
4606 + bend = au_sbend(sb);
4607 + for (; bindex <= bend; bindex++) {
4608 + br = au_sbr(sb, bindex);
4609 + xi = &br->br_xino;
4610 + if (xi->xi_dbgaufs) {
4611 + debugfs_remove(xi->xi_dbgaufs);
4612 + xi->xi_dbgaufs = NULL;
4617 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
4619 + struct au_sbinfo *sbinfo;
4620 + struct dentry *parent;
4621 + struct au_branch *br;
4622 + struct au_xino_file *xi;
4623 + aufs_bindex_t bend;
4624 + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
4626 + sbinfo = au_sbi(sb);
4627 + parent = sbinfo->si_dbgaufs;
4631 + bend = au_sbend(sb);
4632 + for (; bindex <= bend; bindex++) {
4633 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
4634 + br = au_sbr(sb, bindex);
4635 + xi = &br->br_xino;
4636 + AuDebugOn(xi->xi_dbgaufs);
4637 + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
4638 + sbinfo, &dbgaufs_xino_fop);
4639 + /* ignore an error */
4640 + if (unlikely(!xi->xi_dbgaufs))
4641 + AuWarn1("failed %s under debugfs\n", name);
4645 +/* ---------------------------------------------------------------------- */
4647 +#ifdef CONFIG_AUFS_EXPORT
4648 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
4651 + struct au_sbinfo *sbinfo;
4652 + struct super_block *sb;
4654 + sbinfo = inode->i_private;
4655 + sb = sbinfo->si_sb;
4656 + si_noflush_read_lock(sb);
4657 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0);
4658 + si_read_unlock(sb);
4662 +static const struct file_operations dbgaufs_xigen_fop = {
4663 + .owner = THIS_MODULE,
4664 + .open = dbgaufs_xigen_open,
4665 + .release = dbgaufs_xi_release,
4666 + .read = dbgaufs_xi_read
4669 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
4674 + * This function is a dynamic '__init' fucntion actually,
4675 + * so the tiny check for si_rwsem is unnecessary.
4677 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
4680 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
4681 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
4682 + &dbgaufs_xigen_fop);
4683 + if (sbinfo->si_dbgaufs_xigen)
4689 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
4693 +#endif /* CONFIG_AUFS_EXPORT */
4695 +/* ---------------------------------------------------------------------- */
4697 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
4700 + * This function is a dynamic '__init' fucntion actually,
4701 + * so the tiny check for si_rwsem is unnecessary.
4703 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
4705 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
4706 + sbinfo->si_dbgaufs = NULL;
4707 + kobject_put(&sbinfo->si_kobj);
4710 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
4713 + char name[SysaufsSiNameLen];
4716 + * This function is a dynamic '__init' fucntion actually,
4717 + * so the tiny check for si_rwsem is unnecessary.
4719 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
4723 + AuErr1("/debug/aufs is uninitialized\n");
4728 + sysaufs_name(sbinfo, name);
4729 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
4730 + if (unlikely(!sbinfo->si_dbgaufs))
4732 + kobject_get(&sbinfo->si_kobj);
4734 + sbinfo->si_dbgaufs_xib = debugfs_create_file
4735 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
4736 + &dbgaufs_xib_fop);
4737 + if (unlikely(!sbinfo->si_dbgaufs_xib))
4740 + err = dbgaufs_xigen_init(sbinfo);
4742 + goto out; /* success */
4745 + dbgaufs_si_fin(sbinfo);
4750 +/* ---------------------------------------------------------------------- */
4752 +void dbgaufs_fin(void)
4754 + debugfs_remove(dbgaufs);
4757 +int __init dbgaufs_init(void)
4762 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
4767 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
4768 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
4769 +++ linux/fs/aufs/dbgaufs.h 2012-03-19 12:24:13.679801090 +0100
4772 + * Copyright (C) 2005-2012 Junjiro R. Okajima
4774 + * This program, aufs is free software; you can redistribute it and/or modify
4775 + * it under the terms of the GNU General Public License as published by
4776 + * the Free Software Foundation; either version 2 of the License, or
4777 + * (at your option) any later version.
4779 + * This program is distributed in the hope that it will be useful,
4780 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4781 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4782 + * GNU General Public License for more details.
4784 + * You should have received a copy of the GNU General Public License
4785 + * along with this program; if not, write to the Free Software
4786 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
4790 + * debugfs interface
4793 +#ifndef __DBGAUFS_H__
4794 +#define __DBGAUFS_H__
4798 +struct super_block;
4801 +#ifdef CONFIG_DEBUG_FS
4803 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
4804 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
4805 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
4806 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
4807 +void dbgaufs_fin(void);
4808 +int __init dbgaufs_init(void);
4810 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
4811 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
4812 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
4813 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
4814 +AuStubVoid(dbgaufs_fin, void)
4815 +AuStubInt0(__init dbgaufs_init, void)
4816 +#endif /* CONFIG_DEBUG_FS */
4818 +#endif /* __KERNEL__ */
4819 +#endif /* __DBGAUFS_H__ */
4820 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
4821 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
4822 +++ linux/fs/aufs/dcsub.c 2012-03-19 12:24:13.679801090 +0100
4825 + * Copyright (C) 2005-2012 Junjiro R. Okajima
4827 + * This program, aufs is free software; you can redistribute it and/or modify
4828 + * it under the terms of the GNU General Public License as published by
4829 + * the Free Software Foundation; either version 2 of the License, or
4830 + * (at your option) any later version.
4832 + * This program is distributed in the hope that it will be useful,
4833 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4834 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4835 + * GNU General Public License for more details.
4837 + * You should have received a copy of the GNU General Public License
4838 + * along with this program; if not, write to the Free Software
4839 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
4843 + * sub-routines for dentry cache
4848 +static void au_dpage_free(struct au_dpage *dpage)
4851 + struct dentry **p;
4853 + p = dpage->dentries;
4854 + for (i = 0; i < dpage->ndentry; i++)
4856 + free_page((unsigned long)dpage->dentries);
4859 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
4865 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
4866 + if (unlikely(!dpages->dpages))
4869 + p = (void *)__get_free_page(gfp);
4873 + dpages->dpages[0].ndentry = 0;
4874 + dpages->dpages[0].dentries = p;
4875 + dpages->ndpage = 1;
4876 + return 0; /* success */
4879 + kfree(dpages->dpages);
4884 +void au_dpages_free(struct au_dcsub_pages *dpages)
4887 + struct au_dpage *p;
4889 + p = dpages->dpages;
4890 + for (i = 0; i < dpages->ndpage; i++)
4891 + au_dpage_free(p++);
4892 + kfree(dpages->dpages);
4895 +static int au_dpages_append(struct au_dcsub_pages *dpages,
4896 + struct dentry *dentry, gfp_t gfp)
4899 + struct au_dpage *dpage;
4902 + dpage = dpages->dpages + dpages->ndpage - 1;
4903 + sz = PAGE_SIZE / sizeof(dentry);
4904 + if (unlikely(dpage->ndentry >= sz)) {
4905 + AuLabel(new dpage);
4907 + sz = dpages->ndpage * sizeof(*dpages->dpages);
4908 + p = au_kzrealloc(dpages->dpages, sz,
4909 + sz + sizeof(*dpages->dpages), gfp);
4913 + dpages->dpages = p;
4914 + dpage = dpages->dpages + dpages->ndpage;
4915 + p = (void *)__get_free_page(gfp);
4919 + dpage->ndentry = 0;
4920 + dpage->dentries = p;
4924 + AuDebugOn(!dentry->d_count);
4925 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
4926 + return 0; /* success */
4932 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
4933 + au_dpages_test test, void *arg)
4936 + struct dentry *this_parent;
4937 + struct list_head *next;
4938 + struct super_block *sb = root->d_sb;
4941 + write_seqlock(&rename_lock);
4942 + this_parent = root;
4943 + spin_lock(&this_parent->d_lock);
4945 + next = this_parent->d_subdirs.next;
4947 + if (this_parent->d_sb == sb
4948 + && !IS_ROOT(this_parent)
4949 + && au_di(this_parent)
4950 + && this_parent->d_count
4951 + && (!test || test(this_parent, arg))) {
4952 + err = au_dpages_append(dpages, this_parent, GFP_ATOMIC);
4953 + if (unlikely(err))
4957 + while (next != &this_parent->d_subdirs) {
4958 + struct list_head *tmp = next;
4959 + struct dentry *dentry = list_entry(tmp, struct dentry,
4963 + spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED);
4964 + if (dentry->d_count) {
4965 + if (!list_empty(&dentry->d_subdirs)) {
4966 + spin_unlock(&this_parent->d_lock);
4967 + spin_release(&dentry->d_lock.dep_map, 1,
4969 + this_parent = dentry;
4970 + spin_acquire(&this_parent->d_lock.dep_map, 0, 1,
4974 + if (dentry->d_sb == sb
4976 + && (!test || test(dentry, arg)))
4977 + err = au_dpages_append(dpages, dentry,
4980 + spin_unlock(&dentry->d_lock);
4981 + if (unlikely(err))
4985 + if (this_parent != root) {
4986 + struct dentry *tmp;
4987 + struct dentry *child;
4989 + tmp = this_parent->d_parent;
4991 + spin_unlock(&this_parent->d_lock);
4992 + child = this_parent;
4993 + this_parent = tmp;
4994 + spin_lock(&this_parent->d_lock);
4995 + rcu_read_unlock();
4996 + next = child->d_u.d_child.next;
5001 + spin_unlock(&this_parent->d_lock);
5002 + write_sequnlock(&rename_lock);
5006 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
5007 + int do_include, au_dpages_test test, void *arg)
5012 + write_seqlock(&rename_lock);
5013 + spin_lock(&dentry->d_lock);
5015 + && dentry->d_count
5016 + && (!test || test(dentry, arg)))
5017 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
5018 + spin_unlock(&dentry->d_lock);
5019 + if (unlikely(err))
5023 + * vfsmount_lock is unnecessary since this is a traverse in a single
5026 + while (!IS_ROOT(dentry)) {
5027 + dentry = dentry->d_parent; /* rename_lock is locked */
5028 + spin_lock(&dentry->d_lock);
5029 + if (dentry->d_count
5030 + && (!test || test(dentry, arg)))
5031 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
5032 + spin_unlock(&dentry->d_lock);
5033 + if (unlikely(err))
5038 + write_sequnlock(&rename_lock);
5042 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
5044 + return au_di(dentry) && dentry->d_sb == arg;
5047 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
5048 + struct dentry *dentry, int do_include)
5050 + return au_dcsub_pages_rev(dpages, dentry, do_include,
5051 + au_dcsub_dpages_aufs, dentry->d_sb);
5054 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
5056 + struct path path[2] = {
5065 + return path_is_under(path + 0, path + 1);
5067 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
5068 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
5069 +++ linux/fs/aufs/dcsub.h 2012-03-19 12:24:13.679801090 +0100
5072 + * Copyright (C) 2005-2012 Junjiro R. Okajima
5074 + * This program, aufs is free software; you can redistribute it and/or modify
5075 + * it under the terms of the GNU General Public License as published by
5076 + * the Free Software Foundation; either version 2 of the License, or
5077 + * (at your option) any later version.
5079 + * This program is distributed in the hope that it will be useful,
5080 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5081 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5082 + * GNU General Public License for more details.
5084 + * You should have received a copy of the GNU General Public License
5085 + * along with this program; if not, write to the Free Software
5086 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
5090 + * sub-routines for dentry cache
5093 +#ifndef __AUFS_DCSUB_H__
5094 +#define __AUFS_DCSUB_H__
5098 +#include <linux/dcache.h>
5099 +#include <linux/fs.h>
5105 + struct dentry **dentries;
5108 +struct au_dcsub_pages {
5110 + struct au_dpage *dpages;
5113 +/* ---------------------------------------------------------------------- */
5116 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
5117 +void au_dpages_free(struct au_dcsub_pages *dpages);
5118 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
5119 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
5120 + au_dpages_test test, void *arg);
5121 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
5122 + int do_include, au_dpages_test test, void *arg);
5123 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
5124 + struct dentry *dentry, int do_include);
5125 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
5127 +/* ---------------------------------------------------------------------- */
5129 +static inline int au_d_hashed_positive(struct dentry *d)
5132 + struct inode *inode = d->d_inode;
5134 + if (unlikely(d_unhashed(d) || !inode || !inode->i_nlink))
5139 +static inline int au_d_alive(struct dentry *d)
5142 + struct inode *inode;
5145 + err = au_d_hashed_positive(d);
5147 + inode = d->d_inode;
5148 + if (unlikely(d_unlinked(d) || !inode || !inode->i_nlink))
5154 +static inline int au_alive_dir(struct dentry *d)
5157 + err = au_d_alive(d);
5158 + if (unlikely(err || IS_DEADDIR(d->d_inode)))
5163 +#endif /* __KERNEL__ */
5164 +#endif /* __AUFS_DCSUB_H__ */
5165 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
5166 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
5167 +++ linux/fs/aufs/debug.c 2012-03-19 12:24:13.679801090 +0100
5170 + * Copyright (C) 2005-2012 Junjiro R. Okajima
5172 + * This program, aufs is free software; you can redistribute it and/or modify
5173 + * it under the terms of the GNU General Public License as published by
5174 + * the Free Software Foundation; either version 2 of the License, or
5175 + * (at your option) any later version.
5177 + * This program is distributed in the hope that it will be useful,
5178 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5179 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5180 + * GNU General Public License for more details.
5182 + * You should have received a copy of the GNU General Public License
5183 + * along with this program; if not, write to the Free Software
5184 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
5188 + * debug print functions
5191 +#include <linux/vt_kern.h>
5195 +MODULE_PARM_DESC(debug, "debug print");
5196 +module_param_named(debug, aufs_debug, int, S_IRUGO | S_IWUSR | S_IWGRP);
5198 +char *au_plevel = KERN_DEBUG;
5199 +#define dpri(fmt, ...) do { \
5201 + && strcmp(au_plevel, KERN_DEBUG)) \
5202 + || au_debug_test()) \
5203 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
5206 +/* ---------------------------------------------------------------------- */
5208 +void au_dpri_whlist(struct au_nhash *whlist)
5210 + unsigned long ul, n;
5211 + struct hlist_head *head;
5212 + struct au_vdir_wh *tpos;
5213 + struct hlist_node *pos;
5215 + n = whlist->nh_num;
5216 + head = whlist->nh_head;
5217 + for (ul = 0; ul < n; ul++) {
5218 + hlist_for_each_entry(tpos, pos, head, wh_hash)
5219 + dpri("b%d, %.*s, %d\n",
5221 + tpos->wh_str.len, tpos->wh_str.name,
5222 + tpos->wh_str.len);
5227 +void au_dpri_vdir(struct au_vdir *vdir)
5230 + union au_vdir_deblk_p p;
5233 + if (!vdir || IS_ERR(vdir)) {
5234 + dpri("err %ld\n", PTR_ERR(vdir));
5238 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n",
5239 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
5240 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
5241 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
5242 + p.deblk = vdir->vd_deblk[ul];
5244 + dpri("[%lu]: %p\n", ul, o);
5248 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
5249 + struct dentry *wh)
5254 + if (!inode || IS_ERR(inode)) {
5255 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
5259 + /* the type of i_blocks depends upon CONFIG_LSF */
5260 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
5261 + && sizeof(inode->i_blocks) != sizeof(u64));
5263 + n = (void *)wh->d_name.name;
5264 + l = wh->d_name.len;
5267 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
5268 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
5270 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
5271 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
5272 + i_size_read(inode), (unsigned long long)inode->i_blocks,
5273 + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
5274 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
5275 + inode->i_state, inode->i_flags, inode->i_version,
5276 + inode->i_generation,
5277 + l ? ", wh " : "", l, n);
5281 +void au_dpri_inode(struct inode *inode)
5283 + struct au_iinfo *iinfo;
5284 + aufs_bindex_t bindex;
5287 + err = do_pri_inode(-1, inode, -1, NULL);
5288 + if (err || !au_test_aufs(inode->i_sb))
5291 + iinfo = au_ii(inode);
5294 + dpri("i-1: bstart %d, bend %d, gen %d\n",
5295 + iinfo->ii_bstart, iinfo->ii_bend, au_iigen(inode));
5296 + if (iinfo->ii_bstart < 0)
5299 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend; bindex++) {
5300 + hn = !!au_hn(iinfo->ii_hinode + bindex);
5301 + do_pri_inode(bindex, iinfo->ii_hinode[0 + bindex].hi_inode, hn,
5302 + iinfo->ii_hinode[0 + bindex].hi_whdentry);
5306 +void au_dpri_dalias(struct inode *inode)
5310 + spin_lock(&inode->i_lock);
5311 + list_for_each_entry(d, &inode->i_dentry, d_alias)
5312 + au_dpri_dentry(d);
5313 + spin_unlock(&inode->i_lock);
5316 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
5318 + struct dentry *wh = NULL;
5321 + if (!dentry || IS_ERR(dentry)) {
5322 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
5325 + /* do not call dget_parent() here */
5326 + /* note: access d_xxx without d_lock */
5327 + dpri("d%d: %.*s?/%.*s, %s, cnt %d, flags 0x%x\n",
5329 + AuDLNPair(dentry->d_parent), AuDLNPair(dentry),
5330 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
5331 + dentry->d_count, dentry->d_flags);
5333 + if (bindex >= 0 && dentry->d_inode && au_test_aufs(dentry->d_sb)) {
5334 + struct au_iinfo *iinfo = au_ii(dentry->d_inode);
5336 + hn = !!au_hn(iinfo->ii_hinode + bindex);
5337 + wh = iinfo->ii_hinode[0 + bindex].hi_whdentry;
5340 + do_pri_inode(bindex, dentry->d_inode, hn, wh);
5344 +void au_dpri_dentry(struct dentry *dentry)
5346 + struct au_dinfo *dinfo;
5347 + aufs_bindex_t bindex;
5349 + struct au_hdentry *hdp;
5351 + err = do_pri_dentry(-1, dentry);
5352 + if (err || !au_test_aufs(dentry->d_sb))
5355 + dinfo = au_di(dentry);
5358 + dpri("d-1: bstart %d, bend %d, bwh %d, bdiropq %d, gen %d\n",
5359 + dinfo->di_bstart, dinfo->di_bend,
5360 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry));
5361 + if (dinfo->di_bstart < 0)
5363 + hdp = dinfo->di_hdentry;
5364 + for (bindex = dinfo->di_bstart; bindex <= dinfo->di_bend; bindex++)
5365 + do_pri_dentry(bindex, hdp[0 + bindex].hd_dentry);
5368 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
5372 + if (!file || IS_ERR(file)) {
5373 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
5379 + && au_test_aufs(file->f_dentry->d_sb)
5381 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
5382 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
5383 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
5384 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
5385 + file->f_version, file->f_pos, a);
5386 + if (file->f_dentry)
5387 + do_pri_dentry(bindex, file->f_dentry);
5391 +void au_dpri_file(struct file *file)
5393 + struct au_finfo *finfo;
5394 + struct au_fidir *fidir;
5395 + struct au_hfile *hfile;
5396 + aufs_bindex_t bindex;
5399 + err = do_pri_file(-1, file);
5400 + if (err || !file->f_dentry || !au_test_aufs(file->f_dentry->d_sb))
5403 + finfo = au_fi(file);
5406 + if (finfo->fi_btop < 0)
5408 + fidir = finfo->fi_hdir;
5410 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
5412 + for (bindex = finfo->fi_btop;
5413 + bindex >= 0 && bindex <= fidir->fd_bbot;
5415 + hfile = fidir->fd_hfile + bindex;
5416 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
5420 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
5422 + struct vfsmount *mnt;
5423 + struct super_block *sb;
5425 + if (!br || IS_ERR(br))
5428 + if (!mnt || IS_ERR(mnt))
5431 + if (!sb || IS_ERR(sb))
5434 + dpri("s%d: {perm 0x%x, id %d, cnt %d, wbr %p}, "
5435 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
5437 + bindex, br->br_perm, br->br_id, atomic_read(&br->br_count),
5438 + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
5439 + sb->s_flags, sb->s_count,
5440 + atomic_read(&sb->s_active), !!br->br_xino.xi_file);
5444 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
5448 +void au_dpri_sb(struct super_block *sb)
5450 + struct au_sbinfo *sbinfo;
5451 + aufs_bindex_t bindex;
5453 + /* to reuduce stack size */
5455 + struct vfsmount mnt;
5456 + struct au_branch fake;
5459 + /* this function can be called from magic sysrq */
5460 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
5461 + if (unlikely(!a)) {
5462 + dpri("no memory\n");
5466 + a->mnt.mnt_sb = sb;
5467 + a->fake.br_perm = 0;
5468 + a->fake.br_mnt = &a->mnt;
5469 + a->fake.br_xino.xi_file = NULL;
5470 + atomic_set(&a->fake.br_count, 0);
5471 + smp_mb(); /* atomic_set */
5472 + err = do_pri_br(-1, &a->fake);
5474 + dpri("dev 0x%x\n", sb->s_dev);
5475 + if (err || !au_test_aufs(sb))
5478 + sbinfo = au_sbi(sb);
5481 + dpri("nw %d, gen %u, kobj %d\n",
5482 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
5483 + atomic_read(&sbinfo->si_kobj.kref.refcount));
5484 + for (bindex = 0; bindex <= sbinfo->si_bend; bindex++)
5485 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
5488 +/* ---------------------------------------------------------------------- */
5490 +void au_dbg_sleep_jiffy(int jiffy)
5493 + jiffy = schedule_timeout_uninterruptible(jiffy);
5496 +void au_dbg_iattr(struct iattr *ia)
5498 +#define AuBit(name) if (ia->ia_valid & ATTR_ ## name) \
5518 + dpri("ia_file %p\n", ia->ia_file);
5521 +/* ---------------------------------------------------------------------- */
5523 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
5525 + struct inode *h_inode, *inode = dentry->d_inode;
5526 + struct dentry *h_dentry;
5527 + aufs_bindex_t bindex, bend, bi;
5529 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
5532 + bend = au_dbend(dentry);
5533 + bi = au_ibend(inode);
5536 + bindex = au_dbstart(dentry);
5537 + bi = au_ibstart(inode);
5541 + for (; bindex <= bend; bindex++) {
5542 + h_dentry = au_h_dptr(dentry, bindex);
5545 + h_inode = au_h_iptr(inode, bindex);
5546 + if (unlikely(h_inode != h_dentry->d_inode)) {
5547 + int old = au_debug_test();
5550 + AuDbg("b%d, %s:%d\n", bindex, func, line);
5551 + AuDbgDentry(dentry);
5552 + AuDbgInode(inode);
5560 +void au_dbg_verify_dir_parent(struct dentry *dentry, unsigned int sigen)
5562 + struct dentry *parent;
5564 + parent = dget_parent(dentry);
5565 + AuDebugOn(!S_ISDIR(dentry->d_inode->i_mode));
5566 + AuDebugOn(IS_ROOT(dentry));
5567 + AuDebugOn(au_digen_test(parent, sigen));
5571 +void au_dbg_verify_nondir_parent(struct dentry *dentry, unsigned int sigen)
5573 + struct dentry *parent;
5574 + struct inode *inode;
5576 + parent = dget_parent(dentry);
5577 + inode = dentry->d_inode;
5578 + AuDebugOn(inode && S_ISDIR(dentry->d_inode->i_mode));
5579 + AuDebugOn(au_digen_test(parent, sigen));
5583 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
5586 + struct au_dcsub_pages dpages;
5587 + struct au_dpage *dpage;
5588 + struct dentry **dentries;
5590 + err = au_dpages_init(&dpages, GFP_NOFS);
5592 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
5594 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
5595 + dpage = dpages.dpages + i;
5596 + dentries = dpage->dentries;
5597 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
5598 + AuDebugOn(au_digen_test(dentries[j], sigen));
5600 + au_dpages_free(&dpages);
5603 +void au_dbg_verify_kthread(void)
5605 + if (au_wkq_test()) {
5608 + * It may be recursive, but udba=notify between two aufs mounts,
5609 + * where a single ro branch is shared, is not a problem.
5615 +/* ---------------------------------------------------------------------- */
5617 +void au_debug_sbinfo_init(struct au_sbinfo *sbinfo __maybe_unused)
5619 +#ifdef AuForceNoPlink
5620 + au_opt_clr(sbinfo->si_mntflags, PLINK);
5622 +#ifdef AuForceNoXino
5623 + au_opt_clr(sbinfo->si_mntflags, XINO);
5625 +#ifdef AuForceNoRefrof
5626 + au_opt_clr(sbinfo->si_mntflags, REFROF);
5628 +#ifdef AuForceHnotify
5629 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_HNOTIFY);
5632 + sbinfo->si_rdblk = 0;
5633 + sbinfo->si_rdhash = 0;
5637 +int __init au_debug_init(void)
5639 + aufs_bindex_t bindex;
5640 + struct au_vdir_destr destr;
5643 + AuDebugOn(bindex >= 0);
5646 + AuDebugOn(destr.len < NAME_MAX);
5648 +#ifdef CONFIG_4KSTACKS
5649 + pr_warning("CONFIG_4KSTACKS is defined.\n");
5652 +#ifdef AuForceNoBrs
5658 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
5659 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
5660 +++ linux/fs/aufs/debug.h 2012-03-19 12:24:13.679801090 +0100
5663 + * Copyright (C) 2005-2012 Junjiro R. Okajima
5665 + * This program, aufs is free software; you can redistribute it and/or modify
5666 + * it under the terms of the GNU General Public License as published by
5667 + * the Free Software Foundation; either version 2 of the License, or
5668 + * (at your option) any later version.
5670 + * This program is distributed in the hope that it will be useful,
5671 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5672 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5673 + * GNU General Public License for more details.
5675 + * You should have received a copy of the GNU General Public License
5676 + * along with this program; if not, write to the Free Software
5677 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
5681 + * debug print functions
5684 +#ifndef __AUFS_DEBUG_H__
5685 +#define __AUFS_DEBUG_H__
5689 +#include <asm/system.h>
5690 +#include <linux/module.h>
5691 +#include <linux/kallsyms.h>
5692 +#include <linux/sysrq.h>
5694 +#ifdef CONFIG_AUFS_DEBUG
5695 +#define AuDebugOn(a) BUG_ON(a)
5697 +/* module parameter */
5698 +extern int aufs_debug;
5699 +static inline void au_debug(int n)
5705 +static inline int au_debug_test(void)
5707 + return aufs_debug;
5710 +#define AuDebugOn(a) do {} while (0)
5711 +AuStubVoid(au_debug, int n)
5712 +AuStubInt0(au_debug_test, void)
5713 +#endif /* CONFIG_AUFS_DEBUG */
5715 +/* ---------------------------------------------------------------------- */
5719 +#define AuDbg(fmt, ...) do { \
5720 + if (au_debug_test()) \
5721 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
5723 +#define AuLabel(l) AuDbg(#l "\n")
5724 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
5725 +#define AuWarn1(fmt, ...) do { \
5726 + static unsigned char _c; \
5728 + pr_warning(fmt, ##__VA_ARGS__); \
5731 +#define AuErr1(fmt, ...) do { \
5732 + static unsigned char _c; \
5734 + pr_err(fmt, ##__VA_ARGS__); \
5737 +#define AuIOErr1(fmt, ...) do { \
5738 + static unsigned char _c; \
5740 + AuIOErr(fmt, ##__VA_ARGS__); \
5743 +#define AuUnsupportMsg "This operation is not supported." \
5744 + " Please report this application to aufs-users ML."
5745 +#define AuUnsupport(fmt, ...) do { \
5746 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
5750 +#define AuTraceErr(e) do { \
5751 + if (unlikely((e) < 0)) \
5752 + AuDbg("err %d\n", (int)(e)); \
5755 +#define AuTraceErrPtr(p) do { \
5757 + AuDbg("err %ld\n", PTR_ERR(p)); \
5760 +/* dirty macros for debug print, use with "%.*s" and caution */
5761 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
5762 +#define AuDLNPair(d) AuLNPair(&(d)->d_name)
5764 +/* ---------------------------------------------------------------------- */
5769 +#ifdef CONFIG_AUFS_DEBUG
5770 +extern char *au_plevel;
5772 +void au_dpri_whlist(struct au_nhash *whlist);
5774 +void au_dpri_vdir(struct au_vdir *vdir);
5776 +void au_dpri_inode(struct inode *inode);
5777 +void au_dpri_dalias(struct inode *inode);
5778 +void au_dpri_dentry(struct dentry *dentry);
5780 +void au_dpri_file(struct file *filp);
5781 +struct super_block;
5782 +void au_dpri_sb(struct super_block *sb);
5784 +void au_dbg_sleep_jiffy(int jiffy);
5786 +void au_dbg_iattr(struct iattr *ia);
5788 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
5789 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
5790 +void au_dbg_verify_dir_parent(struct dentry *dentry, unsigned int sigen);
5791 +void au_dbg_verify_nondir_parent(struct dentry *dentry, unsigned int sigen);
5792 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
5793 +void au_dbg_verify_kthread(void);
5795 +int __init au_debug_init(void);
5796 +void au_debug_sbinfo_init(struct au_sbinfo *sbinfo);
5797 +#define AuDbgWhlist(w) do { \
5799 + au_dpri_whlist(w); \
5802 +#define AuDbgVdir(v) do { \
5804 + au_dpri_vdir(v); \
5807 +#define AuDbgInode(i) do { \
5809 + au_dpri_inode(i); \
5812 +#define AuDbgDAlias(i) do { \
5814 + au_dpri_dalias(i); \
5817 +#define AuDbgDentry(d) do { \
5819 + au_dpri_dentry(d); \
5822 +#define AuDbgFile(f) do { \
5824 + au_dpri_file(f); \
5827 +#define AuDbgSb(sb) do { \
5828 + AuDbg(#sb "\n"); \
5832 +#define AuDbgSleep(sec) do { \
5833 + AuDbg("sleep %d sec\n", sec); \
5837 +#define AuDbgSleepJiffy(jiffy) do { \
5838 + AuDbg("sleep %d jiffies\n", jiffy); \
5839 + au_dbg_sleep_jiffy(jiffy); \
5842 +#define AuDbgIAttr(ia) do { \
5843 + AuDbg("ia_valid 0x%x\n", (ia)->ia_valid); \
5844 + au_dbg_iattr(ia); \
5847 +#define AuDbgSym(addr) do { \
5848 + char sym[KSYM_SYMBOL_LEN]; \
5849 + sprint_symbol(sym, (unsigned long)addr); \
5850 + AuDbg("%s\n", sym); \
5853 +#define AuInfoSym(addr) do { \
5854 + char sym[KSYM_SYMBOL_LEN]; \
5855 + sprint_symbol(sym, (unsigned long)addr); \
5856 + AuInfo("%s\n", sym); \
5859 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
5860 +AuStubVoid(au_dbg_verify_dir_parent, struct dentry *dentry, unsigned int sigen)
5861 +AuStubVoid(au_dbg_verify_nondir_parent, struct dentry *dentry,
5862 + unsigned int sigen)
5863 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
5864 +AuStubVoid(au_dbg_verify_kthread, void)
5865 +AuStubInt0(__init au_debug_init, void)
5866 +AuStubVoid(au_debug_sbinfo_init, struct au_sbinfo *sbinfo)
5868 +#define AuDbgWhlist(w) do {} while (0)
5869 +#define AuDbgVdir(v) do {} while (0)
5870 +#define AuDbgInode(i) do {} while (0)
5871 +#define AuDbgDAlias(i) do {} while (0)
5872 +#define AuDbgDentry(d) do {} while (0)
5873 +#define AuDbgFile(f) do {} while (0)
5874 +#define AuDbgSb(sb) do {} while (0)
5875 +#define AuDbgSleep(sec) do {} while (0)
5876 +#define AuDbgSleepJiffy(jiffy) do {} while (0)
5877 +#define AuDbgIAttr(ia) do {} while (0)
5878 +#define AuDbgSym(addr) do {} while (0)
5879 +#define AuInfoSym(addr) do {} while (0)
5880 +#endif /* CONFIG_AUFS_DEBUG */
5882 +/* ---------------------------------------------------------------------- */
5884 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
5885 +int __init au_sysrq_init(void);
5886 +void au_sysrq_fin(void);
5888 +#ifdef CONFIG_HW_CONSOLE
5889 +#define au_dbg_blocked() do { \
5891 + handle_sysrq('w'); \
5894 +AuStubVoid(au_dbg_blocked, void)
5898 +AuStubInt0(__init au_sysrq_init, void)
5899 +AuStubVoid(au_sysrq_fin, void)
5900 +AuStubVoid(au_dbg_blocked, void)
5901 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
5903 +#endif /* __KERNEL__ */
5904 +#endif /* __AUFS_DEBUG_H__ */
5905 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
5906 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
5907 +++ linux/fs/aufs/dentry.c 2012-03-19 12:24:13.679801090 +0100
5910 + * Copyright (C) 2005-2012 Junjiro R. Okajima
5912 + * This program, aufs is free software; you can redistribute it and/or modify
5913 + * it under the terms of the GNU General Public License as published by
5914 + * the Free Software Foundation; either version 2 of the License, or
5915 + * (at your option) any later version.
5917 + * This program is distributed in the hope that it will be useful,
5918 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5919 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5920 + * GNU General Public License for more details.
5922 + * You should have received a copy of the GNU General Public License
5923 + * along with this program; if not, write to the Free Software
5924 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
5928 + * lookup and dentry operations
5931 +#include <linux/namei.h>
5934 +static void au_h_nd(struct nameidata *h_nd, struct nameidata *nd)
5940 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
5941 + * due to whiteout and branch permission.
5943 + h_nd->flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
5944 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
5945 + /* unnecessary? */
5946 + h_nd->intent.open.file = NULL;
5948 + memset(h_nd, 0, sizeof(*h_nd));
5951 +struct au_lkup_one_args {
5952 + struct dentry **errp;
5953 + struct qstr *name;
5954 + struct dentry *h_parent;
5955 + struct au_branch *br;
5956 + struct nameidata *nd;
5959 +struct dentry *au_lkup_one(struct qstr *name, struct dentry *h_parent,
5960 + struct au_branch *br, struct nameidata *nd)
5962 + struct dentry *h_dentry;
5964 + struct nameidata h_nd;
5966 + if (au_test_fs_null_nd(h_parent->d_sb))
5967 + return vfsub_lookup_one_len(name->name, h_parent, name->len);
5969 + au_h_nd(&h_nd, nd);
5970 + h_nd.path.dentry = h_parent;
5971 + h_nd.path.mnt = br->br_mnt;
5973 + err = vfsub_name_hash(name->name, &h_nd.last, name->len);
5974 + h_dentry = ERR_PTR(err);
5976 + path_get(&h_nd.path);
5977 + h_dentry = vfsub_lookup_hash(&h_nd);
5978 + path_put(&h_nd.path);
5981 + AuTraceErrPtr(h_dentry);
5985 +static void au_call_lkup_one(void *args)
5987 + struct au_lkup_one_args *a = args;
5988 + *a->errp = au_lkup_one(a->name, a->h_parent, a->br, a->nd);
5991 +#define AuLkup_ALLOW_NEG 1
5992 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
5993 +#define au_fset_lkup(flags, name) \
5994 + do { (flags) |= AuLkup_##name; } while (0)
5995 +#define au_fclr_lkup(flags, name) \
5996 + do { (flags) &= ~AuLkup_##name; } while (0)
5998 +struct au_do_lookup_args {
5999 + unsigned int flags;
6001 + struct nameidata *nd;
6005 + * returns positive/negative dentry, NULL or an error.
6006 + * NULL means whiteout-ed or not-found.
6008 +static struct dentry*
6009 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
6010 + aufs_bindex_t bindex, struct qstr *wh_name,
6011 + struct au_do_lookup_args *args)
6013 + struct dentry *h_dentry;
6014 + struct inode *h_inode, *inode;
6015 + struct au_branch *br;
6016 + int wh_found, opq;
6017 + unsigned char wh_able;
6018 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
6021 + br = au_sbr(dentry->d_sb, bindex);
6022 + wh_able = !!au_br_whable(br->br_perm);
6024 + wh_found = au_wh_test(h_parent, wh_name, br, /*try_sio*/0);
6025 + h_dentry = ERR_PTR(wh_found);
6028 + if (unlikely(wh_found < 0))
6031 + /* We found a whiteout */
6032 + /* au_set_dbend(dentry, bindex); */
6033 + au_set_dbwh(dentry, bindex);
6035 + return NULL; /* success */
6038 + h_dentry = au_lkup_one(&dentry->d_name, h_parent, br, args->nd);
6039 + if (IS_ERR(h_dentry))
6042 + h_inode = h_dentry->d_inode;
6046 + } else if (wh_found
6047 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
6050 + if (au_dbend(dentry) <= bindex)
6051 + au_set_dbend(dentry, bindex);
6052 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
6053 + au_set_dbstart(dentry, bindex);
6054 + au_set_h_dptr(dentry, bindex, h_dentry);
6056 + inode = dentry->d_inode;
6057 + if (!h_inode || !S_ISDIR(h_inode->i_mode) || !wh_able
6058 + || (inode && !S_ISDIR(inode->i_mode)))
6059 + goto out; /* success */
6061 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
6062 + opq = au_diropq_test(h_dentry, br);
6063 + mutex_unlock(&h_inode->i_mutex);
6065 + au_set_dbdiropq(dentry, bindex);
6066 + else if (unlikely(opq < 0)) {
6067 + au_set_h_dptr(dentry, bindex, NULL);
6068 + h_dentry = ERR_PTR(opq);
6079 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
6081 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
6082 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
6088 + * returns the number of lower positive dentries,
6089 + * otherwise an error.
6090 + * can be called at unlinking with @type is zero.
6092 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type,
6093 + struct nameidata *nd)
6095 + int npositive, err;
6096 + aufs_bindex_t bindex, btail, bdiropq;
6097 + unsigned char isdir;
6098 + struct qstr whname;
6099 + struct au_do_lookup_args args = {
6104 + const struct qstr *name = &dentry->d_name;
6105 + struct dentry *parent;
6106 + struct inode *inode;
6108 + err = au_test_shwh(dentry->d_sb, name);
6109 + if (unlikely(err))
6112 + err = au_wh_name_alloc(&whname, name);
6113 + if (unlikely(err))
6116 + inode = dentry->d_inode;
6117 + isdir = !!(inode && S_ISDIR(inode->i_mode));
6119 + au_fset_lkup(args.flags, ALLOW_NEG);
6122 + parent = dget_parent(dentry);
6123 + btail = au_dbtaildir(parent);
6124 + for (bindex = bstart; bindex <= btail; bindex++) {
6125 + struct dentry *h_parent, *h_dentry;
6126 + struct inode *h_inode, *h_dir;
6128 + h_dentry = au_h_dptr(dentry, bindex);
6130 + if (h_dentry->d_inode)
6132 + if (type != S_IFDIR)
6136 + h_parent = au_h_dptr(parent, bindex);
6139 + h_dir = h_parent->d_inode;
6140 + if (!h_dir || !S_ISDIR(h_dir->i_mode))
6143 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
6144 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname,
6146 + mutex_unlock(&h_dir->i_mutex);
6147 + err = PTR_ERR(h_dentry);
6148 + if (IS_ERR(h_dentry))
6150 + au_fclr_lkup(args.flags, ALLOW_NEG);
6152 + if (au_dbwh(dentry) >= 0)
6156 + h_inode = h_dentry->d_inode;
6161 + args.type = h_inode->i_mode & S_IFMT;
6162 + if (args.type != S_IFDIR)
6165 + /* the type of lower may be different */
6166 + bdiropq = au_dbdiropq(dentry);
6167 + if (bdiropq >= 0 && bdiropq <= bindex)
6173 + AuLabel(positive);
6174 + au_update_dbstart(dentry);
6177 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
6178 + && au_dbstart(dentry) < 0)) {
6180 + AuIOErr("both of real entry and whiteout found, %.*s, err %d\n",
6181 + AuDLNPair(dentry), err);
6186 + kfree(whname.name);
6191 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent,
6192 + struct au_branch *br)
6194 + struct dentry *dentry;
6197 + if (!au_test_h_perm_sio(parent->d_inode, MAY_EXEC))
6198 + dentry = au_lkup_one(name, parent, br, /*nd*/NULL);
6200 + struct au_lkup_one_args args = {
6203 + .h_parent = parent,
6208 + wkq_err = au_wkq_wait(au_call_lkup_one, &args);
6209 + if (unlikely(wkq_err))
6210 + dentry = ERR_PTR(wkq_err);
6217 + * lookup @dentry on @bindex which should be negative.
6219 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex)
6222 + struct dentry *parent, *h_parent, *h_dentry;
6224 + parent = dget_parent(dentry);
6225 + h_parent = au_h_dptr(parent, bindex);
6226 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent,
6227 + au_sbr(dentry->d_sb, bindex));
6228 + err = PTR_ERR(h_dentry);
6229 + if (IS_ERR(h_dentry))
6231 + if (unlikely(h_dentry->d_inode)) {
6233 + AuIOErr("%.*s should be negative on b%d.\n",
6234 + AuDLNPair(h_dentry), bindex);
6240 + if (bindex < au_dbstart(dentry))
6241 + au_set_dbstart(dentry, bindex);
6242 + if (au_dbend(dentry) < bindex)
6243 + au_set_dbend(dentry, bindex);
6244 + au_set_h_dptr(dentry, bindex, h_dentry);
6251 +/* ---------------------------------------------------------------------- */
6253 +/* subset of struct inode */
6255 + unsigned long i_ino;
6256 + /* unsigned int i_nlink; */
6262 + blkcnt_t i_blocks;
6267 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
6269 + ia->i_ino = h_inode->i_ino;
6270 + /* ia->i_nlink = h_inode->i_nlink; */
6271 + ia->i_uid = h_inode->i_uid;
6272 + ia->i_gid = h_inode->i_gid;
6273 + ia->i_version = h_inode->i_version;
6275 + ia->i_size = h_inode->i_size;
6276 + ia->i_blocks = h_inode->i_blocks;
6278 + ia->i_mode = (h_inode->i_mode & S_IFMT);
6281 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
6283 + return ia->i_ino != h_inode->i_ino
6284 + /* || ia->i_nlink != h_inode->i_nlink */
6285 + || ia->i_uid != h_inode->i_uid
6286 + || ia->i_gid != h_inode->i_gid
6287 + || ia->i_version != h_inode->i_version
6289 + || ia->i_size != h_inode->i_size
6290 + || ia->i_blocks != h_inode->i_blocks
6292 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
6295 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
6296 + struct au_branch *br)
6299 + struct au_iattr ia;
6300 + struct inode *h_inode;
6301 + struct dentry *h_d;
6302 + struct super_block *h_sb;
6305 + memset(&ia, -1, sizeof(ia));
6306 + h_sb = h_dentry->d_sb;
6307 + h_inode = h_dentry->d_inode;
6309 + au_iattr_save(&ia, h_inode);
6310 + else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
6311 + /* nfs d_revalidate may return 0 for negative dentry */
6312 + /* fuse d_revalidate always return 0 for negative dentry */
6315 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
6316 + h_d = au_lkup_one(&h_dentry->d_name, h_parent, br, /*nd*/NULL);
6317 + err = PTR_ERR(h_d);
6322 + if (unlikely(h_d != h_dentry
6323 + || h_d->d_inode != h_inode
6324 + || (h_inode && au_iattr_test(&ia, h_inode))))
6325 + err = au_busy_or_stale();
6333 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
6334 + struct dentry *h_parent, struct au_branch *br)
6339 + if (udba == AuOpt_UDBA_REVAL
6340 + && !au_test_fs_remote(h_dentry->d_sb)) {
6342 + err = (h_dentry->d_parent->d_inode != h_dir);
6343 + } else if (udba != AuOpt_UDBA_NONE)
6344 + err = au_h_verify_dentry(h_dentry, h_parent, br);
6349 +/* ---------------------------------------------------------------------- */
6351 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
6354 + aufs_bindex_t new_bindex, bindex, bend, bwh, bdiropq;
6355 + struct au_hdentry tmp, *p, *q;
6356 + struct au_dinfo *dinfo;
6357 + struct super_block *sb;
6359 + DiMustWriteLock(dentry);
6361 + sb = dentry->d_sb;
6362 + dinfo = au_di(dentry);
6363 + bend = dinfo->di_bend;
6364 + bwh = dinfo->di_bwh;
6365 + bdiropq = dinfo->di_bdiropq;
6366 + p = dinfo->di_hdentry + dinfo->di_bstart;
6367 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++, p++) {
6368 + if (!p->hd_dentry)
6371 + new_bindex = au_br_index(sb, p->hd_id);
6372 + if (new_bindex == bindex)
6375 + if (dinfo->di_bwh == bindex)
6377 + if (dinfo->di_bdiropq == bindex)
6378 + bdiropq = new_bindex;
6379 + if (new_bindex < 0) {
6381 + p->hd_dentry = NULL;
6385 + /* swap two lower dentries, and loop again */
6386 + q = dinfo->di_hdentry + new_bindex;
6390 + if (tmp.hd_dentry) {
6396 + dinfo->di_bwh = -1;
6397 + if (bwh >= 0 && bwh <= au_sbend(sb) && au_sbr_whable(sb, bwh))
6398 + dinfo->di_bwh = bwh;
6400 + dinfo->di_bdiropq = -1;
6402 + && bdiropq <= au_sbend(sb)
6403 + && au_sbr_whable(sb, bdiropq))
6404 + dinfo->di_bdiropq = bdiropq;
6407 + dinfo->di_bstart = -1;
6408 + dinfo->di_bend = -1;
6409 + bend = au_dbend(parent);
6410 + p = dinfo->di_hdentry;
6411 + for (bindex = 0; bindex <= bend; bindex++, p++)
6412 + if (p->hd_dentry) {
6413 + dinfo->di_bstart = bindex;
6417 + if (dinfo->di_bstart >= 0) {
6418 + p = dinfo->di_hdentry + bend;
6419 + for (bindex = bend; bindex >= 0; bindex--, p--)
6420 + if (p->hd_dentry) {
6421 + dinfo->di_bend = bindex;
6430 +static void au_do_hide(struct dentry *dentry)
6432 + struct inode *inode;
6434 + inode = dentry->d_inode;
6436 + if (!S_ISDIR(inode->i_mode)) {
6437 + if (inode->i_nlink && !d_unhashed(dentry))
6438 + drop_nlink(inode);
6440 + clear_nlink(inode);
6441 + /* stop next lookup */
6442 + inode->i_flags |= S_DEAD;
6444 + smp_mb(); /* necessary? */
6449 +static int au_hide_children(struct dentry *parent)
6451 + int err, i, j, ndentry;
6452 + struct au_dcsub_pages dpages;
6453 + struct au_dpage *dpage;
6454 + struct dentry *dentry;
6456 + err = au_dpages_init(&dpages, GFP_NOFS);
6457 + if (unlikely(err))
6459 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
6460 + if (unlikely(err))
6463 + /* in reverse order */
6464 + for (i = dpages.ndpage - 1; i >= 0; i--) {
6465 + dpage = dpages.dpages + i;
6466 + ndentry = dpage->ndentry;
6467 + for (j = ndentry - 1; j >= 0; j--) {
6468 + dentry = dpage->dentries[j];
6469 + if (dentry != parent)
6470 + au_do_hide(dentry);
6475 + au_dpages_free(&dpages);
6480 +static void au_hide(struct dentry *dentry)
6483 + struct inode *inode;
6485 + AuDbgDentry(dentry);
6486 + inode = dentry->d_inode;
6487 + if (inode && S_ISDIR(inode->i_mode)) {
6488 + /* shrink_dcache_parent(dentry); */
6489 + err = au_hide_children(dentry);
6490 + if (unlikely(err))
6491 + AuIOErr("%.*s, failed hiding children, ignored %d\n",
6492 + AuDLNPair(dentry), err);
6494 + au_do_hide(dentry);
6498 + * By adding a dirty branch, a cached dentry may be affected in various ways.
6500 + * a dirty branch is added
6501 + * - on the top of layers
6502 + * - in the middle of layers
6503 + * - to the bottom of layers
6505 + * on the added branch there exists
6508 + * - a same named entry
6510 + * * negative --> positive
6511 + * * positive --> positive
6512 + * - type is unchanged
6513 + * - type is changed
6515 + * * negative --> negative
6516 + * * positive --> negative (rejected by au_br_del() for non-dir case)
6519 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
6520 + struct au_dinfo *tmp)
6523 + aufs_bindex_t bindex, bend;
6525 + struct dentry *dentry;
6526 + struct inode *inode;
6529 + struct au_hdentry *hd;
6530 + struct inode *inode, *h_inode;
6531 + struct dentry *h_dentry;
6534 + AuDebugOn(dinfo->di_bstart < 0);
6535 + orig_h.dentry = dinfo->di_hdentry[dinfo->di_bstart].hd_dentry;
6536 + orig_h.inode = orig_h.dentry->d_inode;
6539 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
6540 + memset(&tmp_h, 0, sizeof(tmp_h));
6541 + if (tmp->di_bstart >= 0) {
6542 + tmp_h.dentry = tmp->di_hdentry[tmp->di_bstart].hd_dentry;
6543 + tmp_h.inode = tmp_h.dentry->d_inode;
6545 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
6548 + inode = dentry->d_inode;
6549 + if (!orig_h.inode) {
6550 + AuDbg("nagative originally\n");
6556 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
6557 + AuDebugOn(dinfo->di_bdiropq != -1);
6559 + if (!tmp_h.inode) {
6560 + AuDbg("negative --> negative\n");
6561 + /* should have only one negative lower */
6562 + if (tmp->di_bstart >= 0
6563 + && tmp->di_bstart < dinfo->di_bstart) {
6564 + AuDebugOn(tmp->di_bstart != tmp->di_bend);
6565 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
6566 + au_set_h_dptr(dentry, dinfo->di_bstart, NULL);
6567 + au_di_cp(dinfo, tmp);
6568 + hd = tmp->di_hdentry + tmp->di_bstart;
6569 + au_set_h_dptr(dentry, tmp->di_bstart,
6570 + dget(hd->hd_dentry));
6572 + au_dbg_verify_dinode(dentry);
6574 + AuDbg("negative --> positive\n");
6576 + * similar to the behaviour of creating with bypassing
6578 + * unhash it in order to force an error in the
6579 + * succeeding create operation.
6580 + * we should not set S_DEAD here.
6583 + /* au_di_swap(tmp, dinfo); */
6584 + au_dbg_verify_dinode(dentry);
6587 + AuDbg("positive originally\n");
6588 + /* inode may be NULL */
6589 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
6590 + if (!tmp_h.inode) {
6591 + AuDbg("positive --> negative\n");
6592 + /* or bypassing aufs */
6594 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_bstart)
6595 + dinfo->di_bwh = tmp->di_bwh;
6597 + err = au_refresh_hinode_self(inode);
6598 + au_dbg_verify_dinode(dentry);
6599 + } else if (orig_h.mode == tmp_h.mode) {
6600 + AuDbg("positive --> positive, same type\n");
6601 + if (!S_ISDIR(orig_h.mode)
6602 + && dinfo->di_bstart > tmp->di_bstart) {
6604 + * similar to the behaviour of removing and
6609 + err = au_refresh_hinode_self(inode);
6610 + au_dbg_verify_dinode(dentry);
6612 + /* fill empty slots */
6613 + if (dinfo->di_bstart > tmp->di_bstart)
6614 + dinfo->di_bstart = tmp->di_bstart;
6615 + if (dinfo->di_bend < tmp->di_bend)
6616 + dinfo->di_bend = tmp->di_bend;
6617 + dinfo->di_bwh = tmp->di_bwh;
6618 + dinfo->di_bdiropq = tmp->di_bdiropq;
6619 + hd = tmp->di_hdentry;
6620 + bend = dinfo->di_bend;
6621 + for (bindex = tmp->di_bstart; bindex <= bend;
6623 + if (au_h_dptr(dentry, bindex))
6625 + h_dentry = hd[bindex].hd_dentry;
6628 + h_inode = h_dentry->d_inode;
6629 + AuDebugOn(!h_inode);
6630 + AuDebugOn(orig_h.mode
6631 + != (h_inode->i_mode
6633 + au_set_h_dptr(dentry, bindex,
6636 + err = au_refresh_hinode(inode, dentry);
6637 + au_dbg_verify_dinode(dentry);
6640 + AuDbg("positive --> positive, different type\n");
6641 + /* similar to the behaviour of removing and creating */
6644 + err = au_refresh_hinode_self(inode);
6645 + au_dbg_verify_dinode(dentry);
6653 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
6656 + unsigned int sigen;
6657 + struct au_dinfo *dinfo, *tmp;
6658 + struct super_block *sb;
6659 + struct inode *inode;
6661 + DiMustWriteLock(dentry);
6662 + AuDebugOn(IS_ROOT(dentry));
6663 + AuDebugOn(!parent->d_inode);
6665 + sb = dentry->d_sb;
6666 + inode = dentry->d_inode;
6667 + sigen = au_sigen(sb);
6668 + err = au_digen_test(parent, sigen);
6669 + if (unlikely(err))
6672 + dinfo = au_di(dentry);
6673 + err = au_di_realloc(dinfo, au_sbend(sb) + 1);
6674 + if (unlikely(err))
6676 + ebrange = au_dbrange_test(dentry);
6678 + ebrange = au_do_refresh_hdentry(dentry, parent);
6680 + if (d_unhashed(dentry) || ebrange) {
6681 + AuDebugOn(au_dbstart(dentry) < 0 && au_dbend(dentry) >= 0);
6683 + err = au_refresh_hinode_self(inode);
6684 + au_dbg_verify_dinode(dentry);
6686 + goto out_dgen; /* success */
6690 + /* temporary dinfo */
6691 + AuDbgDentry(dentry);
6693 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
6694 + if (unlikely(!tmp))
6696 + au_di_swap(tmp, dinfo);
6697 + /* returns the number of positive dentries */
6699 + * if current working dir is removed, it returns an error.
6700 + * but the dentry is legal.
6702 + err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0, /*nd*/NULL);
6703 + AuDbgDentry(dentry);
6704 + au_di_swap(tmp, dinfo);
6705 + if (err == -ENOENT)
6708 + /* compare/refresh by dinfo */
6709 + AuDbgDentry(dentry);
6710 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
6711 + au_dbg_verify_dinode(dentry);
6714 + au_rw_write_unlock(&tmp->di_rwsem);
6716 + if (unlikely(err))
6720 + au_update_digen(dentry);
6722 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
6723 + AuIOErr("failed refreshing %.*s, %d\n",
6724 + AuDLNPair(dentry), err);
6725 + AuDbgDentry(dentry);
6731 +static noinline_for_stack
6732 +int au_do_h_d_reval(struct dentry *h_dentry, struct nameidata *nd,
6733 + struct dentry *dentry, aufs_bindex_t bindex)
6736 + int (*reval)(struct dentry *, struct nameidata *);
6739 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
6741 + reval = h_dentry->d_op->d_revalidate;
6743 + AuDbg("b%d\n", bindex);
6744 + if (au_test_fs_null_nd(h_dentry->d_sb))
6745 + /* it may return tri-state */
6746 + valid = reval(h_dentry, NULL);
6748 + struct nameidata h_nd;
6750 + struct dentry *parent;
6752 + au_h_nd(&h_nd, nd);
6753 + parent = nd->path.dentry;
6754 + locked = (nd && nd->path.dentry != dentry);
6756 + di_read_lock_parent(parent, AuLock_IR);
6757 + BUG_ON(bindex > au_dbend(parent));
6758 + h_nd.path.dentry = au_h_dptr(parent, bindex);
6759 + BUG_ON(!h_nd.path.dentry);
6760 + h_nd.path.mnt = au_sbr(parent->d_sb, bindex)->br_mnt;
6761 + path_get(&h_nd.path);
6762 + valid = reval(h_dentry, &h_nd);
6763 + path_put(&h_nd.path);
6765 + di_read_unlock(parent, AuLock_IR);
6768 + if (unlikely(valid < 0))
6778 +/* todo: remove this */
6779 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
6780 + struct nameidata *nd, int do_udba)
6783 + umode_t mode, h_mode;
6784 + aufs_bindex_t bindex, btail, bstart, ibs, ibe;
6785 + unsigned char plus, unhashed, is_root, h_plus;
6786 + struct inode *h_inode, *h_cached_inode;
6787 + struct dentry *h_dentry;
6788 + struct qstr *name, *h_name;
6795 + unhashed = !!d_unhashed(dentry);
6796 + is_root = !!IS_ROOT(dentry);
6797 + name = &dentry->d_name;
6800 + * Theoretically, REVAL test should be unnecessary in case of
6802 + * But {fs,i}notify doesn't fire some necessary events,
6803 + * IN_ATTRIB for atime/nlink/pageio
6804 + * IN_DELETE for NFS dentry
6805 + * Let's do REVAL test too.
6807 + if (do_udba && inode) {
6808 + mode = (inode->i_mode & S_IFMT);
6809 + plus = (inode->i_nlink > 0);
6810 + ibs = au_ibstart(inode);
6811 + ibe = au_ibend(inode);
6814 + bstart = au_dbstart(dentry);
6816 + if (inode && S_ISDIR(inode->i_mode))
6817 + btail = au_dbtaildir(dentry);
6818 + for (bindex = bstart; bindex <= btail; bindex++) {
6819 + h_dentry = au_h_dptr(dentry, bindex);
6823 + AuDbg("b%d, %.*s\n", bindex, AuDLNPair(h_dentry));
6824 + spin_lock(&h_dentry->d_lock);
6825 + h_name = &h_dentry->d_name;
6826 + if (unlikely(do_udba
6828 + && (unhashed != !!d_unhashed(h_dentry)
6829 + || name->len != h_name->len
6830 + || memcmp(name->name, h_name->name, name->len))
6832 + AuDbg("unhash 0x%x 0x%x, %.*s %.*s\n",
6833 + unhashed, d_unhashed(h_dentry),
6834 + AuDLNPair(dentry), AuDLNPair(h_dentry));
6835 + spin_unlock(&h_dentry->d_lock);
6838 + spin_unlock(&h_dentry->d_lock);
6840 + err = au_do_h_d_reval(h_dentry, nd, dentry, bindex);
6841 + if (unlikely(err))
6842 + /* do not goto err, to keep the errno */
6845 + /* todo: plink too? */
6850 + h_inode = h_dentry->d_inode;
6851 + if (unlikely(!!inode != !!h_inode))
6856 + h_cached_inode = h_inode;
6858 + h_mode = (h_inode->i_mode & S_IFMT);
6859 + h_plus = (h_inode->i_nlink > 0);
6861 + if (inode && ibs <= bindex && bindex <= ibe)
6862 + h_cached_inode = au_h_iptr(inode, bindex);
6864 + if (unlikely(plus != h_plus
6866 + || h_cached_inode != h_inode))
6878 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
6879 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
6882 + struct dentry *parent;
6884 + if (!au_digen_test(dentry, sigen))
6887 + parent = dget_parent(dentry);
6888 + di_read_lock_parent(parent, AuLock_IR);
6889 + AuDebugOn(au_digen_test(parent, sigen));
6890 + au_dbg_verify_gen(parent, sigen);
6891 + err = au_refresh_dentry(dentry, parent);
6892 + di_read_unlock(parent, AuLock_IR);
6898 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
6901 + struct dentry *d, *parent;
6902 + struct inode *inode;
6904 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
6905 + return simple_reval_dpath(dentry, sigen);
6907 + /* slow loop, keep it simple and stupid */
6908 + /* cf: au_cpup_dirs() */
6911 + while (au_digen_test(dentry, sigen)) {
6915 + parent = dget_parent(d);
6916 + if (!au_digen_test(parent, sigen))
6921 + inode = d->d_inode;
6923 + di_write_lock_child2(d);
6925 + /* someone might update our dentry while we were sleeping */
6926 + if (au_digen_test(d, sigen)) {
6928 + * todo: consolidate with simple_reval_dpath(),
6929 + * do_refresh() and au_reval_for_attr().
6931 + di_read_lock_parent(parent, AuLock_IR);
6932 + err = au_refresh_dentry(d, parent);
6933 + di_read_unlock(parent, AuLock_IR);
6937 + di_write_unlock(d);
6939 + if (unlikely(err))
6947 + * if valid returns 1, otherwise 0.
6949 +static int aufs_d_revalidate(struct dentry *dentry, struct nameidata *nd)
6952 + unsigned int sigen;
6953 + unsigned char do_udba;
6954 + struct super_block *sb;
6955 + struct inode *inode;
6957 + /* todo: support rcu-walk? */
6958 + if (nd && (nd->flags & LOOKUP_RCU))
6962 + if (unlikely(!au_di(dentry)))
6965 + inode = dentry->d_inode;
6966 + if (inode && is_bad_inode(inode))
6970 + sb = dentry->d_sb;
6973 + * i_mutex of parent dir may be held,
6974 + * but we should not return 'invalid' due to busy.
6976 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
6977 + if (unlikely(err)) {
6982 + if (unlikely(au_dbrange_test(dentry))) {
6988 + sigen = au_sigen(sb);
6989 + if (au_digen_test(dentry, sigen)) {
6990 + AuDebugOn(IS_ROOT(dentry));
6991 + err = au_reval_dpath(dentry, sigen);
6992 + if (unlikely(err)) {
6997 + di_downgrade_lock(dentry, AuLock_IR);
7000 + if (inode && (IS_DEADDIR(inode) || !inode->i_nlink))
7003 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
7004 + if (do_udba && inode) {
7005 + aufs_bindex_t bstart = au_ibstart(inode);
7006 + struct inode *h_inode;
7008 + if (bstart >= 0) {
7009 + h_inode = au_h_iptr(inode, bstart);
7010 + if (h_inode && au_test_higen(inode, h_inode))
7015 + err = h_d_revalidate(dentry, inode, nd, do_udba);
7016 + if (unlikely(!err && do_udba && au_dbstart(dentry) < 0)) {
7018 + AuDbg("both of real entry and whiteout found, %.*s, err %d\n",
7019 + AuDLNPair(dentry), err);
7024 + di_downgrade_lock(dentry, AuLock_IR);
7026 + aufs_read_unlock(dentry, AuLock_IR);
7031 + AuDbg("%.*s invalid, %d\n", AuDLNPair(dentry), valid);
7037 +static void aufs_d_release(struct dentry *dentry)
7039 + if (au_di(dentry)) {
7040 + au_di_fin(dentry);
7041 + au_hn_di_reinit(dentry);
7045 +const struct dentry_operations aufs_dop = {
7046 + .d_revalidate = aufs_d_revalidate,
7047 + .d_release = aufs_d_release
7049 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
7050 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
7051 +++ linux/fs/aufs/dentry.h 2012-03-19 12:24:13.679801090 +0100
7054 + * Copyright (C) 2005-2012 Junjiro R. Okajima
7056 + * This program, aufs is free software; you can redistribute it and/or modify
7057 + * it under the terms of the GNU General Public License as published by
7058 + * the Free Software Foundation; either version 2 of the License, or
7059 + * (at your option) any later version.
7061 + * This program is distributed in the hope that it will be useful,
7062 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7063 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7064 + * GNU General Public License for more details.
7066 + * You should have received a copy of the GNU General Public License
7067 + * along with this program; if not, write to the Free Software
7068 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
7072 + * lookup and dentry operations
7075 +#ifndef __AUFS_DENTRY_H__
7076 +#define __AUFS_DENTRY_H__
7080 +#include <linux/dcache.h>
7083 +struct au_hdentry {
7084 + struct dentry *hd_dentry;
7085 + aufs_bindex_t hd_id;
7089 + atomic_t di_generation;
7091 + struct au_rwsem di_rwsem;
7092 + aufs_bindex_t di_bstart, di_bend, di_bwh, di_bdiropq;
7093 + struct au_hdentry *di_hdentry;
7094 +} ____cacheline_aligned_in_smp;
7096 +/* ---------------------------------------------------------------------- */
7099 +extern const struct dentry_operations aufs_dop;
7101 +struct dentry *au_lkup_one(struct qstr *name, struct dentry *h_parent,
7102 + struct au_branch *br, struct nameidata *nd);
7103 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent,
7104 + struct au_branch *br);
7105 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
7106 + struct dentry *h_parent, struct au_branch *br);
7108 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type,
7109 + struct nameidata *nd);
7110 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex);
7111 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
7112 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
7115 +void au_di_init_once(void *_di);
7116 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
7117 +void au_di_free(struct au_dinfo *dinfo);
7118 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
7119 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
7120 +int au_di_init(struct dentry *dentry);
7121 +void au_di_fin(struct dentry *dentry);
7122 +int au_di_realloc(struct au_dinfo *dinfo, int nbr);
7124 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
7125 +void di_read_unlock(struct dentry *d, int flags);
7126 +void di_downgrade_lock(struct dentry *d, int flags);
7127 +void di_write_lock(struct dentry *d, unsigned int lsc);
7128 +void di_write_unlock(struct dentry *d);
7129 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
7130 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
7131 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
7133 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
7134 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
7135 +aufs_bindex_t au_dbtail(struct dentry *dentry);
7136 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
7138 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
7139 + struct dentry *h_dentry);
7140 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
7141 +int au_dbrange_test(struct dentry *dentry);
7142 +void au_update_digen(struct dentry *dentry);
7143 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
7144 +void au_update_dbstart(struct dentry *dentry);
7145 +void au_update_dbend(struct dentry *dentry);
7146 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
7148 +/* ---------------------------------------------------------------------- */
7150 +static inline struct au_dinfo *au_di(struct dentry *dentry)
7152 + return dentry->d_fsdata;
7155 +/* ---------------------------------------------------------------------- */
7157 +/* lock subclass for dinfo */
7159 + AuLsc_DI_CHILD, /* child first */
7160 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
7161 + AuLsc_DI_CHILD3, /* copyup dirs */
7165 + AuLsc_DI_TMP /* temp for replacing dinfo */
7169 + * di_read_lock_child, di_write_lock_child,
7170 + * di_read_lock_child2, di_write_lock_child2,
7171 + * di_read_lock_child3, di_write_lock_child3,
7172 + * di_read_lock_parent, di_write_lock_parent,
7173 + * di_read_lock_parent2, di_write_lock_parent2,
7174 + * di_read_lock_parent3, di_write_lock_parent3,
7176 +#define AuReadLockFunc(name, lsc) \
7177 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
7178 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
7180 +#define AuWriteLockFunc(name, lsc) \
7181 +static inline void di_write_lock_##name(struct dentry *d) \
7182 +{ di_write_lock(d, AuLsc_DI_##lsc); }
7184 +#define AuRWLockFuncs(name, lsc) \
7185 + AuReadLockFunc(name, lsc) \
7186 + AuWriteLockFunc(name, lsc)
7188 +AuRWLockFuncs(child, CHILD);
7189 +AuRWLockFuncs(child2, CHILD2);
7190 +AuRWLockFuncs(child3, CHILD3);
7191 +AuRWLockFuncs(parent, PARENT);
7192 +AuRWLockFuncs(parent2, PARENT2);
7193 +AuRWLockFuncs(parent3, PARENT3);
7195 +#undef AuReadLockFunc
7196 +#undef AuWriteLockFunc
7197 +#undef AuRWLockFuncs
7199 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
7200 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
7201 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
7203 +/* ---------------------------------------------------------------------- */
7205 +/* todo: memory barrier? */
7206 +static inline unsigned int au_digen(struct dentry *d)
7208 + return atomic_read(&au_di(d)->di_generation);
7211 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
7213 + hdentry->hd_dentry = NULL;
7216 +static inline void au_hdput(struct au_hdentry *hd)
7219 + dput(hd->hd_dentry);
7222 +static inline aufs_bindex_t au_dbstart(struct dentry *dentry)
7224 + DiMustAnyLock(dentry);
7225 + return au_di(dentry)->di_bstart;
7228 +static inline aufs_bindex_t au_dbend(struct dentry *dentry)
7230 + DiMustAnyLock(dentry);
7231 + return au_di(dentry)->di_bend;
7234 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
7236 + DiMustAnyLock(dentry);
7237 + return au_di(dentry)->di_bwh;
7240 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
7242 + DiMustAnyLock(dentry);
7243 + return au_di(dentry)->di_bdiropq;
7246 +/* todo: hard/soft set? */
7247 +static inline void au_set_dbstart(struct dentry *dentry, aufs_bindex_t bindex)
7249 + DiMustWriteLock(dentry);
7250 + au_di(dentry)->di_bstart = bindex;
7253 +static inline void au_set_dbend(struct dentry *dentry, aufs_bindex_t bindex)
7255 + DiMustWriteLock(dentry);
7256 + au_di(dentry)->di_bend = bindex;
7259 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
7261 + DiMustWriteLock(dentry);
7262 + /* dbwh can be outside of bstart - bend range */
7263 + au_di(dentry)->di_bwh = bindex;
7266 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
7268 + DiMustWriteLock(dentry);
7269 + au_di(dentry)->di_bdiropq = bindex;
7272 +/* ---------------------------------------------------------------------- */
7274 +#ifdef CONFIG_AUFS_HNOTIFY
7275 +static inline void au_digen_dec(struct dentry *d)
7277 + atomic_dec(&au_di(d)->di_generation);
7280 +static inline void au_hn_di_reinit(struct dentry *dentry)
7282 + dentry->d_fsdata = NULL;
7285 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
7286 +#endif /* CONFIG_AUFS_HNOTIFY */
7288 +#endif /* __KERNEL__ */
7289 +#endif /* __AUFS_DENTRY_H__ */
7290 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
7291 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
7292 +++ linux/fs/aufs/dinfo.c 2012-03-19 12:24:13.679801090 +0100
7295 + * Copyright (C) 2005-2012 Junjiro R. Okajima
7297 + * This program, aufs is free software; you can redistribute it and/or modify
7298 + * it under the terms of the GNU General Public License as published by
7299 + * the Free Software Foundation; either version 2 of the License, or
7300 + * (at your option) any later version.
7302 + * This program is distributed in the hope that it will be useful,
7303 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7304 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7305 + * GNU General Public License for more details.
7307 + * You should have received a copy of the GNU General Public License
7308 + * along with this program; if not, write to the Free Software
7309 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
7313 + * dentry private data
7318 +void au_di_init_once(void *_dinfo)
7320 + struct au_dinfo *dinfo = _dinfo;
7321 + static struct lock_class_key aufs_di;
7323 + au_rw_init(&dinfo->di_rwsem);
7324 + au_rw_class(&dinfo->di_rwsem, &aufs_di);
7327 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
7329 + struct au_dinfo *dinfo;
7332 + dinfo = au_cache_alloc_dinfo();
7333 + if (unlikely(!dinfo))
7336 + nbr = au_sbend(sb) + 1;
7339 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
7340 + if (dinfo->di_hdentry) {
7341 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
7342 + dinfo->di_bstart = -1;
7343 + dinfo->di_bend = -1;
7344 + dinfo->di_bwh = -1;
7345 + dinfo->di_bdiropq = -1;
7346 + for (i = 0; i < nbr; i++)
7347 + dinfo->di_hdentry[i].hd_id = -1;
7351 + au_cache_free_dinfo(dinfo);
7358 +void au_di_free(struct au_dinfo *dinfo)
7360 + struct au_hdentry *p;
7361 + aufs_bindex_t bend, bindex;
7363 + /* dentry may not be revalidated */
7364 + bindex = dinfo->di_bstart;
7365 + if (bindex >= 0) {
7366 + bend = dinfo->di_bend;
7367 + p = dinfo->di_hdentry + bindex;
7368 + while (bindex++ <= bend)
7371 + kfree(dinfo->di_hdentry);
7372 + au_cache_free_dinfo(dinfo);
7375 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
7377 + struct au_hdentry *p;
7380 + AuRwMustWriteLock(&a->di_rwsem);
7381 + AuRwMustWriteLock(&b->di_rwsem);
7383 +#define DiSwap(v, name) \
7385 + v = a->di_##name; \
7386 + a->di_##name = b->di_##name; \
7387 + b->di_##name = v; \
7390 + DiSwap(p, hdentry);
7391 + DiSwap(bi, bstart);
7394 + DiSwap(bi, bdiropq);
7400 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
7402 + AuRwMustWriteLock(&dst->di_rwsem);
7403 + AuRwMustWriteLock(&src->di_rwsem);
7405 + dst->di_bstart = src->di_bstart;
7406 + dst->di_bend = src->di_bend;
7407 + dst->di_bwh = src->di_bwh;
7408 + dst->di_bdiropq = src->di_bdiropq;
7412 +int au_di_init(struct dentry *dentry)
7415 + struct super_block *sb;
7416 + struct au_dinfo *dinfo;
7419 + sb = dentry->d_sb;
7420 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
7422 + atomic_set(&dinfo->di_generation, au_sigen(sb));
7423 + /* smp_mb(); */ /* atomic_set */
7424 + dentry->d_fsdata = dinfo;
7431 +void au_di_fin(struct dentry *dentry)
7433 + struct au_dinfo *dinfo;
7435 + dinfo = au_di(dentry);
7436 + AuRwDestroy(&dinfo->di_rwsem);
7437 + au_di_free(dinfo);
7440 +int au_di_realloc(struct au_dinfo *dinfo, int nbr)
7443 + struct au_hdentry *hdp;
7445 + AuRwMustWriteLock(&dinfo->di_rwsem);
7448 + sz = sizeof(*hdp) * (dinfo->di_bend + 1);
7450 + sz = sizeof(*hdp);
7451 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS);
7453 + dinfo->di_hdentry = hdp;
7460 +/* ---------------------------------------------------------------------- */
7462 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
7465 + case AuLsc_DI_CHILD:
7466 + ii_write_lock_child(inode);
7468 + case AuLsc_DI_CHILD2:
7469 + ii_write_lock_child2(inode);
7471 + case AuLsc_DI_CHILD3:
7472 + ii_write_lock_child3(inode);
7474 + case AuLsc_DI_PARENT:
7475 + ii_write_lock_parent(inode);
7477 + case AuLsc_DI_PARENT2:
7478 + ii_write_lock_parent2(inode);
7480 + case AuLsc_DI_PARENT3:
7481 + ii_write_lock_parent3(inode);
7488 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
7491 + case AuLsc_DI_CHILD:
7492 + ii_read_lock_child(inode);
7494 + case AuLsc_DI_CHILD2:
7495 + ii_read_lock_child2(inode);
7497 + case AuLsc_DI_CHILD3:
7498 + ii_read_lock_child3(inode);
7500 + case AuLsc_DI_PARENT:
7501 + ii_read_lock_parent(inode);
7503 + case AuLsc_DI_PARENT2:
7504 + ii_read_lock_parent2(inode);
7506 + case AuLsc_DI_PARENT3:
7507 + ii_read_lock_parent3(inode);
7514 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
7516 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
7518 + if (au_ftest_lock(flags, IW))
7519 + do_ii_write_lock(d->d_inode, lsc);
7520 + else if (au_ftest_lock(flags, IR))
7521 + do_ii_read_lock(d->d_inode, lsc);
7525 +void di_read_unlock(struct dentry *d, int flags)
7528 + if (au_ftest_lock(flags, IW)) {
7529 + au_dbg_verify_dinode(d);
7530 + ii_write_unlock(d->d_inode);
7531 + } else if (au_ftest_lock(flags, IR)) {
7532 + au_dbg_verify_dinode(d);
7533 + ii_read_unlock(d->d_inode);
7536 + au_rw_read_unlock(&au_di(d)->di_rwsem);
7539 +void di_downgrade_lock(struct dentry *d, int flags)
7541 + if (d->d_inode && au_ftest_lock(flags, IR))
7542 + ii_downgrade_lock(d->d_inode);
7543 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
7546 +void di_write_lock(struct dentry *d, unsigned int lsc)
7548 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
7550 + do_ii_write_lock(d->d_inode, lsc);
7553 +void di_write_unlock(struct dentry *d)
7555 + au_dbg_verify_dinode(d);
7557 + ii_write_unlock(d->d_inode);
7558 + au_rw_write_unlock(&au_di(d)->di_rwsem);
7561 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
7563 + AuDebugOn(d1 == d2
7564 + || d1->d_inode == d2->d_inode
7565 + || d1->d_sb != d2->d_sb);
7567 + if (isdir && au_test_subdir(d1, d2)) {
7568 + di_write_lock_child(d1);
7569 + di_write_lock_child2(d2);
7571 + /* there should be no races */
7572 + di_write_lock_child(d2);
7573 + di_write_lock_child2(d1);
7577 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
7579 + AuDebugOn(d1 == d2
7580 + || d1->d_inode == d2->d_inode
7581 + || d1->d_sb != d2->d_sb);
7583 + if (isdir && au_test_subdir(d1, d2)) {
7584 + di_write_lock_parent(d1);
7585 + di_write_lock_parent2(d2);
7587 + /* there should be no races */
7588 + di_write_lock_parent(d2);
7589 + di_write_lock_parent2(d1);
7593 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
7595 + di_write_unlock(d1);
7596 + if (d1->d_inode == d2->d_inode)
7597 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
7599 + di_write_unlock(d2);
7602 +/* ---------------------------------------------------------------------- */
7604 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
7608 + DiMustAnyLock(dentry);
7610 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
7612 + AuDebugOn(bindex < 0);
7613 + d = au_di(dentry)->di_hdentry[0 + bindex].hd_dentry;
7614 + AuDebugOn(d && d->d_count <= 0);
7619 + * extended version of au_h_dptr().
7620 + * returns a hashed and positive h_dentry in bindex, NULL, or error.
7622 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
7624 + struct dentry *h_dentry;
7625 + struct inode *inode, *h_inode;
7627 + inode = dentry->d_inode;
7628 + AuDebugOn(!inode);
7631 + if (au_dbstart(dentry) <= bindex
7632 + && bindex <= au_dbend(dentry))
7633 + h_dentry = au_h_dptr(dentry, bindex);
7634 + if (h_dentry && !au_d_hashed_positive(h_dentry)) {
7636 + goto out; /* success */
7639 + AuDebugOn(bindex < au_ibstart(inode));
7640 + AuDebugOn(au_ibend(inode) < bindex);
7641 + h_inode = au_h_iptr(inode, bindex);
7642 + h_dentry = d_find_alias(h_inode);
7644 + if (!IS_ERR(h_dentry)) {
7645 + if (!au_d_hashed_positive(h_dentry))
7646 + goto out; /* success */
7652 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
7653 + h_dentry = au_plink_lkup(inode, bindex);
7654 + AuDebugOn(!h_dentry);
7655 + if (!IS_ERR(h_dentry)) {
7656 + if (!au_d_hashed_positive(h_dentry))
7657 + goto out; /* success */
7664 + AuDbgDentry(h_dentry);
7668 +aufs_bindex_t au_dbtail(struct dentry *dentry)
7670 + aufs_bindex_t bend, bwh;
7672 + bend = au_dbend(dentry);
7674 + bwh = au_dbwh(dentry);
7677 + if (0 < bwh && bwh < bend)
7683 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
7685 + aufs_bindex_t bend, bopq;
7687 + bend = au_dbtail(dentry);
7689 + bopq = au_dbdiropq(dentry);
7690 + if (0 <= bopq && bopq < bend)
7696 +/* ---------------------------------------------------------------------- */
7698 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
7699 + struct dentry *h_dentry)
7701 + struct au_hdentry *hd = au_di(dentry)->di_hdentry + bindex;
7702 + struct au_branch *br;
7704 + DiMustWriteLock(dentry);
7707 + hd->hd_dentry = h_dentry;
7709 + br = au_sbr(dentry->d_sb, bindex);
7710 + hd->hd_id = br->br_id;
7714 +int au_dbrange_test(struct dentry *dentry)
7717 + aufs_bindex_t bstart, bend;
7720 + bstart = au_dbstart(dentry);
7721 + bend = au_dbend(dentry);
7723 + AuDebugOn(bend < 0 && bstart > bend);
7726 + AuDebugOn(bend >= 0);
7732 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
7737 + if (unlikely(au_digen(dentry) != sigen
7738 + || au_iigen_test(dentry->d_inode, sigen)))
7744 +void au_update_digen(struct dentry *dentry)
7746 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
7747 + /* smp_mb(); */ /* atomic_set */
7750 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
7752 + struct au_dinfo *dinfo;
7753 + struct dentry *h_d;
7754 + struct au_hdentry *hdp;
7756 + DiMustWriteLock(dentry);
7758 + dinfo = au_di(dentry);
7759 + if (!dinfo || dinfo->di_bstart < 0)
7762 + hdp = dinfo->di_hdentry;
7763 + if (do_put_zero) {
7764 + aufs_bindex_t bindex, bend;
7766 + bend = dinfo->di_bend;
7767 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++) {
7768 + h_d = hdp[0 + bindex].hd_dentry;
7769 + if (h_d && !h_d->d_inode)
7770 + au_set_h_dptr(dentry, bindex, NULL);
7774 + dinfo->di_bstart = -1;
7775 + while (++dinfo->di_bstart <= dinfo->di_bend)
7776 + if (hdp[0 + dinfo->di_bstart].hd_dentry)
7778 + if (dinfo->di_bstart > dinfo->di_bend) {
7779 + dinfo->di_bstart = -1;
7780 + dinfo->di_bend = -1;
7785 + while (0 <= --dinfo->di_bend)
7786 + if (hdp[0 + dinfo->di_bend].hd_dentry)
7788 + AuDebugOn(dinfo->di_bstart > dinfo->di_bend || dinfo->di_bend < 0);
7791 +void au_update_dbstart(struct dentry *dentry)
7793 + aufs_bindex_t bindex, bend;
7794 + struct dentry *h_dentry;
7796 + bend = au_dbend(dentry);
7797 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
7798 + h_dentry = au_h_dptr(dentry, bindex);
7801 + if (h_dentry->d_inode) {
7802 + au_set_dbstart(dentry, bindex);
7805 + au_set_h_dptr(dentry, bindex, NULL);
7809 +void au_update_dbend(struct dentry *dentry)
7811 + aufs_bindex_t bindex, bstart;
7812 + struct dentry *h_dentry;
7814 + bstart = au_dbstart(dentry);
7815 + for (bindex = au_dbend(dentry); bindex >= bstart; bindex--) {
7816 + h_dentry = au_h_dptr(dentry, bindex);
7819 + if (h_dentry->d_inode) {
7820 + au_set_dbend(dentry, bindex);
7823 + au_set_h_dptr(dentry, bindex, NULL);
7827 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
7829 + aufs_bindex_t bindex, bend;
7831 + bend = au_dbend(dentry);
7832 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++)
7833 + if (au_h_dptr(dentry, bindex) == h_dentry)
7837 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
7838 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
7839 +++ linux/fs/aufs/dir.c 2012-03-19 12:24:13.679801090 +0100
7842 + * Copyright (C) 2005-2012 Junjiro R. Okajima
7844 + * This program, aufs is free software; you can redistribute it and/or modify
7845 + * it under the terms of the GNU General Public License as published by
7846 + * the Free Software Foundation; either version 2 of the License, or
7847 + * (at your option) any later version.
7849 + * This program is distributed in the hope that it will be useful,
7850 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7851 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7852 + * GNU General Public License for more details.
7854 + * You should have received a copy of the GNU General Public License
7855 + * along with this program; if not, write to the Free Software
7856 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
7860 + * directory operations
7863 +#include <linux/fs_stack.h>
7866 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
7868 + unsigned int nlink;
7870 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
7872 + nlink = dir->i_nlink;
7873 + nlink += h_dir->i_nlink - 2;
7874 + if (h_dir->i_nlink < 2)
7876 + /* 0 can happen in revaliding */
7877 + vfsub_set_nlink(dir, nlink);
7880 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
7882 + unsigned int nlink;
7884 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
7886 + nlink = dir->i_nlink;
7887 + nlink -= h_dir->i_nlink - 2;
7888 + if (h_dir->i_nlink < 2)
7890 + /* no vfsub version. nlink == 0 means the branch-fs is broken */
7891 + set_nlink(dir, nlink);
7894 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
7897 + aufs_bindex_t bindex, bend;
7898 + struct file *h_file;
7899 + struct dentry *h_dentry;
7903 + AuDebugOn(!file->f_dentry);
7904 + AuDebugOn(!file->f_dentry->d_inode);
7905 + AuDebugOn(!S_ISDIR(file->f_dentry->d_inode->i_mode));
7907 + bend = au_fbend_dir(file);
7908 + for (bindex = au_fbstart(file);
7909 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
7911 + h_file = au_hf_dir(file, bindex);
7913 + && h_file->f_dentry
7914 + && h_file->f_dentry->d_inode)
7915 + sz += i_size_read(h_file->f_dentry->d_inode);
7918 + AuDebugOn(!dentry);
7919 + AuDebugOn(!dentry->d_inode);
7920 + AuDebugOn(!S_ISDIR(dentry->d_inode->i_mode));
7922 + bend = au_dbtaildir(dentry);
7923 + for (bindex = au_dbstart(dentry);
7924 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
7926 + h_dentry = au_h_dptr(dentry, bindex);
7927 + if (h_dentry && h_dentry->d_inode)
7928 + sz += i_size_read(h_dentry->d_inode);
7931 + if (sz < KMALLOC_MAX_SIZE)
7932 + sz = roundup_pow_of_two(sz);
7933 + if (sz > KMALLOC_MAX_SIZE)
7934 + sz = KMALLOC_MAX_SIZE;
7935 + else if (sz < NAME_MAX) {
7936 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
7937 + sz = AUFS_RDBLK_DEF;
7942 +/* ---------------------------------------------------------------------- */
7944 +static int reopen_dir(struct file *file)
7947 + unsigned int flags;
7948 + aufs_bindex_t bindex, btail, bstart;
7949 + struct dentry *dentry, *h_dentry;
7950 + struct file *h_file;
7952 + /* open all lower dirs */
7953 + dentry = file->f_dentry;
7954 + bstart = au_dbstart(dentry);
7955 + for (bindex = au_fbstart(file); bindex < bstart; bindex++)
7956 + au_set_h_fptr(file, bindex, NULL);
7957 + au_set_fbstart(file, bstart);
7959 + btail = au_dbtaildir(dentry);
7960 + for (bindex = au_fbend_dir(file); btail < bindex; bindex--)
7961 + au_set_h_fptr(file, bindex, NULL);
7962 + au_set_fbend_dir(file, btail);
7964 + flags = vfsub_file_flags(file);
7965 + for (bindex = bstart; bindex <= btail; bindex++) {
7966 + h_dentry = au_h_dptr(dentry, bindex);
7969 + h_file = au_hf_dir(file, bindex);
7973 + h_file = au_h_open(dentry, bindex, flags, file);
7974 + err = PTR_ERR(h_file);
7975 + if (IS_ERR(h_file))
7976 + goto out; /* close all? */
7977 + au_set_h_fptr(file, bindex, h_file);
7979 + au_update_figen(file);
7980 + /* todo: necessary? */
7981 + /* file->f_ra = h_file->f_ra; */
7988 +static int do_open_dir(struct file *file, int flags)
7991 + aufs_bindex_t bindex, btail;
7992 + struct dentry *dentry, *h_dentry;
7993 + struct file *h_file;
7995 + FiMustWriteLock(file);
7997 + dentry = file->f_dentry;
7998 + err = au_alive_dir(dentry);
7999 + if (unlikely(err))
8002 + file->f_version = dentry->d_inode->i_version;
8003 + bindex = au_dbstart(dentry);
8004 + au_set_fbstart(file, bindex);
8005 + btail = au_dbtaildir(dentry);
8006 + au_set_fbend_dir(file, btail);
8007 + for (; !err && bindex <= btail; bindex++) {
8008 + h_dentry = au_h_dptr(dentry, bindex);
8012 + h_file = au_h_open(dentry, bindex, flags, file);
8013 + if (IS_ERR(h_file)) {
8014 + err = PTR_ERR(h_file);
8017 + au_set_h_fptr(file, bindex, h_file);
8019 + au_update_figen(file);
8020 + /* todo: necessary? */
8021 + /* file->f_ra = h_file->f_ra; */
8023 + return 0; /* success */
8026 + for (bindex = au_fbstart(file); bindex <= btail; bindex++)
8027 + au_set_h_fptr(file, bindex, NULL);
8028 + au_set_fbstart(file, -1);
8029 + au_set_fbend_dir(file, -1);
8035 +static int aufs_open_dir(struct inode *inode __maybe_unused,
8036 + struct file *file)
8039 + struct super_block *sb;
8040 + struct au_fidir *fidir;
8043 + sb = file->f_dentry->d_sb;
8044 + si_read_lock(sb, AuLock_FLUSH);
8045 + fidir = au_fidir_alloc(sb);
8047 + err = au_do_open(file, do_open_dir, fidir);
8048 + if (unlikely(err))
8051 + si_read_unlock(sb);
8055 +static int aufs_release_dir(struct inode *inode __maybe_unused,
8056 + struct file *file)
8058 + struct au_vdir *vdir_cache;
8059 + struct au_finfo *finfo;
8060 + struct au_fidir *fidir;
8061 + aufs_bindex_t bindex, bend;
8063 + finfo = au_fi(file);
8064 + fidir = finfo->fi_hdir;
8066 + /* remove me from sb->s_files */
8067 + file_sb_list_del(file);
8069 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
8071 + au_vdir_free(vdir_cache);
8073 + bindex = finfo->fi_btop;
8074 + if (bindex >= 0) {
8076 + * calls fput() instead of filp_close(),
8077 + * since no dnotify or lock for the lower file.
8079 + bend = fidir->fd_bbot;
8080 + for (; bindex <= bend; bindex++)
8081 + au_set_h_fptr(file, bindex, NULL);
8084 + finfo->fi_hdir = NULL;
8086 + au_finfo_fin(file);
8090 +/* ---------------------------------------------------------------------- */
8092 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
8095 + aufs_bindex_t bindex, bend;
8096 + struct file *h_file;
8099 + bend = au_fbend_dir(file);
8100 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
8101 + h_file = au_hf_dir(file, bindex);
8103 + err = vfsub_flush(h_file, id);
8108 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
8110 + return au_do_flush(file, id, au_do_flush_dir);
8113 +/* ---------------------------------------------------------------------- */
8115 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
8118 + aufs_bindex_t bend, bindex;
8119 + struct inode *inode;
8120 + struct super_block *sb;
8123 + sb = dentry->d_sb;
8124 + inode = dentry->d_inode;
8126 + bend = au_dbend(dentry);
8127 + for (bindex = au_dbstart(dentry); !err && bindex <= bend; bindex++) {
8128 + struct path h_path;
8130 + if (au_test_ro(sb, bindex, inode))
8132 + h_path.dentry = au_h_dptr(dentry, bindex);
8133 + if (!h_path.dentry)
8136 + h_path.mnt = au_sbr_mnt(sb, bindex);
8137 + err = vfsub_fsync(NULL, &h_path, datasync);
8143 +static int au_do_fsync_dir(struct file *file, int datasync)
8146 + aufs_bindex_t bend, bindex;
8147 + struct file *h_file;
8148 + struct super_block *sb;
8149 + struct inode *inode;
8151 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
8152 + if (unlikely(err))
8155 + sb = file->f_dentry->d_sb;
8156 + inode = file->f_dentry->d_inode;
8157 + bend = au_fbend_dir(file);
8158 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
8159 + h_file = au_hf_dir(file, bindex);
8160 + if (!h_file || au_test_ro(sb, bindex, inode))
8163 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
8171 + * @file may be NULL
8173 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
8177 + struct dentry *dentry;
8178 + struct super_block *sb;
8179 + struct mutex *mtx;
8182 + dentry = file->f_dentry;
8183 + mtx = &dentry->d_inode->i_mutex;
8185 + sb = dentry->d_sb;
8186 + si_noflush_read_lock(sb);
8188 + err = au_do_fsync_dir(file, datasync);
8190 + di_write_lock_child(dentry);
8191 + err = au_do_fsync_dir_no_file(dentry, datasync);
8193 + au_cpup_attr_timesizes(dentry->d_inode);
8194 + di_write_unlock(dentry);
8196 + fi_write_unlock(file);
8198 + si_read_unlock(sb);
8199 + mutex_unlock(mtx);
8203 +/* ---------------------------------------------------------------------- */
8205 +static int aufs_readdir(struct file *file, void *dirent, filldir_t filldir)
8208 + struct dentry *dentry;
8209 + struct inode *inode, *h_inode;
8210 + struct super_block *sb;
8212 + dentry = file->f_dentry;
8213 + inode = dentry->d_inode;
8216 + sb = dentry->d_sb;
8217 + si_read_lock(sb, AuLock_FLUSH);
8218 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
8219 + if (unlikely(err))
8221 + err = au_alive_dir(dentry);
8223 + err = au_vdir_init(file);
8224 + di_downgrade_lock(dentry, AuLock_IR);
8225 + if (unlikely(err))
8228 + h_inode = au_h_iptr(inode, au_ibstart(inode));
8229 + if (!au_test_nfsd()) {
8230 + err = au_vdir_fill_de(file, dirent, filldir);
8231 + fsstack_copy_attr_atime(inode, h_inode);
8234 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
8235 + * encode_fh() and others.
8237 + atomic_inc(&h_inode->i_count);
8238 + di_read_unlock(dentry, AuLock_IR);
8239 + si_read_unlock(sb);
8240 + err = au_vdir_fill_de(file, dirent, filldir);
8241 + fsstack_copy_attr_atime(inode, h_inode);
8242 + fi_write_unlock(file);
8250 + di_read_unlock(dentry, AuLock_IR);
8251 + fi_write_unlock(file);
8253 + si_read_unlock(sb);
8257 +/* ---------------------------------------------------------------------- */
8259 +#define AuTestEmpty_WHONLY 1
8260 +#define AuTestEmpty_CALLED (1 << 1)
8261 +#define AuTestEmpty_SHWH (1 << 2)
8262 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
8263 +#define au_fset_testempty(flags, name) \
8264 + do { (flags) |= AuTestEmpty_##name; } while (0)
8265 +#define au_fclr_testempty(flags, name) \
8266 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
8268 +#ifndef CONFIG_AUFS_SHWH
8269 +#undef AuTestEmpty_SHWH
8270 +#define AuTestEmpty_SHWH 0
8273 +struct test_empty_arg {
8274 + struct au_nhash *whlist;
8275 + unsigned int flags;
8277 + aufs_bindex_t bindex;
8280 +static int test_empty_cb(void *__arg, const char *__name, int namelen,
8281 + loff_t offset __maybe_unused, u64 ino,
8282 + unsigned int d_type)
8284 + struct test_empty_arg *arg = __arg;
8285 + char *name = (void *)__name;
8288 + au_fset_testempty(arg->flags, CALLED);
8290 + if (name[0] == '.'
8291 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
8292 + goto out; /* success */
8294 + if (namelen <= AUFS_WH_PFX_LEN
8295 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
8296 + if (au_ftest_testempty(arg->flags, WHONLY)
8297 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
8298 + arg->err = -ENOTEMPTY;
8302 + name += AUFS_WH_PFX_LEN;
8303 + namelen -= AUFS_WH_PFX_LEN;
8304 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
8305 + arg->err = au_nhash_append_wh
8306 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
8307 + au_ftest_testempty(arg->flags, SHWH));
8311 + AuTraceErr(arg->err);
8315 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
8318 + struct file *h_file;
8320 + h_file = au_h_open(dentry, arg->bindex,
8321 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
8323 + err = PTR_ERR(h_file);
8324 + if (IS_ERR(h_file))
8328 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
8329 + && !h_file->f_dentry->d_inode->i_nlink)
8334 + au_fclr_testempty(arg->flags, CALLED);
8336 + err = vfsub_readdir(h_file, test_empty_cb, arg);
8339 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
8343 + au_sbr_put(dentry->d_sb, arg->bindex);
8348 +struct do_test_empty_args {
8350 + struct dentry *dentry;
8351 + struct test_empty_arg *arg;
8354 +static void call_do_test_empty(void *args)
8356 + struct do_test_empty_args *a = args;
8357 + *a->errp = do_test_empty(a->dentry, a->arg);
8360 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
8363 + struct dentry *h_dentry;
8364 + struct inode *h_inode;
8366 + h_dentry = au_h_dptr(dentry, arg->bindex);
8367 + h_inode = h_dentry->d_inode;
8368 + /* todo: i_mode changes anytime? */
8369 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
8370 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
8371 + mutex_unlock(&h_inode->i_mutex);
8373 + err = do_test_empty(dentry, arg);
8375 + struct do_test_empty_args args = {
8380 + unsigned int flags = arg->flags;
8382 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
8383 + if (unlikely(wkq_err))
8385 + arg->flags = flags;
8391 +int au_test_empty_lower(struct dentry *dentry)
8394 + unsigned int rdhash;
8395 + aufs_bindex_t bindex, bstart, btail;
8396 + struct au_nhash whlist;
8397 + struct test_empty_arg arg;
8399 + SiMustAnyLock(dentry->d_sb);
8401 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
8403 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
8404 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
8405 + if (unlikely(err))
8409 + arg.whlist = &whlist;
8410 + bstart = au_dbstart(dentry);
8411 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
8412 + au_fset_testempty(arg.flags, SHWH);
8413 + arg.bindex = bstart;
8414 + err = do_test_empty(dentry, &arg);
8415 + if (unlikely(err))
8418 + au_fset_testempty(arg.flags, WHONLY);
8419 + btail = au_dbtaildir(dentry);
8420 + for (bindex = bstart + 1; !err && bindex <= btail; bindex++) {
8421 + struct dentry *h_dentry;
8423 + h_dentry = au_h_dptr(dentry, bindex);
8424 + if (h_dentry && h_dentry->d_inode) {
8425 + arg.bindex = bindex;
8426 + err = do_test_empty(dentry, &arg);
8431 + au_nhash_wh_free(&whlist);
8436 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
8439 + struct test_empty_arg arg;
8440 + aufs_bindex_t bindex, btail;
8443 + arg.whlist = whlist;
8444 + arg.flags = AuTestEmpty_WHONLY;
8445 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
8446 + au_fset_testempty(arg.flags, SHWH);
8447 + btail = au_dbtaildir(dentry);
8448 + for (bindex = au_dbstart(dentry); !err && bindex <= btail; bindex++) {
8449 + struct dentry *h_dentry;
8451 + h_dentry = au_h_dptr(dentry, bindex);
8452 + if (h_dentry && h_dentry->d_inode) {
8453 + arg.bindex = bindex;
8454 + err = sio_test_empty(dentry, &arg);
8461 +/* ---------------------------------------------------------------------- */
8463 +const struct file_operations aufs_dir_fop = {
8464 + .owner = THIS_MODULE,
8465 + .llseek = default_llseek,
8466 + .read = generic_read_dir,
8467 + .readdir = aufs_readdir,
8468 + .unlocked_ioctl = aufs_ioctl_dir,
8469 +#ifdef CONFIG_COMPAT
8470 + .compat_ioctl = aufs_compat_ioctl_dir,
8472 + .open = aufs_open_dir,
8473 + .release = aufs_release_dir,
8474 + .flush = aufs_flush_dir,
8475 + .fsync = aufs_fsync_dir
8477 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
8478 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
8479 +++ linux/fs/aufs/dir.h 2012-03-19 12:24:13.679801090 +0100
8482 + * Copyright (C) 2005-2012 Junjiro R. Okajima
8484 + * This program, aufs is free software; you can redistribute it and/or modify
8485 + * it under the terms of the GNU General Public License as published by
8486 + * the Free Software Foundation; either version 2 of the License, or
8487 + * (at your option) any later version.
8489 + * This program is distributed in the hope that it will be useful,
8490 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8491 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8492 + * GNU General Public License for more details.
8494 + * You should have received a copy of the GNU General Public License
8495 + * along with this program; if not, write to the Free Software
8496 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
8500 + * directory operations
8503 +#ifndef __AUFS_DIR_H__
8504 +#define __AUFS_DIR_H__
8508 +#include <linux/fs.h>
8510 +/* ---------------------------------------------------------------------- */
8512 +/* need to be faster and smaller */
8515 + unsigned int nh_num;
8516 + struct hlist_head *nh_head;
8519 +struct au_vdir_destr {
8520 + unsigned char len;
8521 + unsigned char name[0];
8524 +struct au_vdir_dehstr {
8525 + struct hlist_node hash;
8526 + struct au_vdir_destr *str;
8527 +} ____cacheline_aligned_in_smp;
8529 +struct au_vdir_de {
8531 + unsigned char de_type;
8532 + /* caution: packed */
8533 + struct au_vdir_destr de_str;
8536 +struct au_vdir_wh {
8537 + struct hlist_node wh_hash;
8538 +#ifdef CONFIG_AUFS_SHWH
8540 + aufs_bindex_t wh_bindex;
8541 + unsigned char wh_type;
8543 + aufs_bindex_t wh_bindex;
8545 + /* caution: packed */
8546 + struct au_vdir_destr wh_str;
8549 +union au_vdir_deblk_p {
8550 + unsigned char *deblk;
8551 + struct au_vdir_de *de;
8555 + unsigned char **vd_deblk;
8556 + unsigned long vd_nblk;
8559 + union au_vdir_deblk_p p;
8562 + unsigned long vd_version;
8563 + unsigned int vd_deblk_sz;
8564 + unsigned long vd_jiffy;
8565 +} ____cacheline_aligned_in_smp;
8567 +/* ---------------------------------------------------------------------- */
8570 +extern const struct file_operations aufs_dir_fop;
8571 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
8572 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
8573 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
8574 +int au_test_empty_lower(struct dentry *dentry);
8575 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
8578 +unsigned int au_rdhash_est(loff_t sz);
8579 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
8580 +void au_nhash_wh_free(struct au_nhash *whlist);
8581 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
8583 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
8584 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
8585 + unsigned int d_type, aufs_bindex_t bindex,
8586 + unsigned char shwh);
8587 +void au_vdir_free(struct au_vdir *vdir);
8588 +int au_vdir_init(struct file *file);
8589 +int au_vdir_fill_de(struct file *file, void *dirent, filldir_t filldir);
8592 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
8594 +#ifdef CONFIG_AUFS_RDU
8596 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
8597 +#ifdef CONFIG_COMPAT
8598 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
8599 + unsigned long arg);
8602 +static inline long au_rdu_ioctl(struct file *file, unsigned int cmd,
8603 + unsigned long arg)
8607 +#ifdef CONFIG_COMPAT
8608 +static inline long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
8609 + unsigned long arg)
8616 +#endif /* __KERNEL__ */
8617 +#endif /* __AUFS_DIR_H__ */
8618 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
8619 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
8620 +++ linux/fs/aufs/dynop.c 2012-03-19 12:24:13.679801090 +0100
8623 + * Copyright (C) 2010-2012 Junjiro R. Okajima
8625 + * This program, aufs is free software; you can redistribute it and/or modify
8626 + * it under the terms of the GNU General Public License as published by
8627 + * the Free Software Foundation; either version 2 of the License, or
8628 + * (at your option) any later version.
8630 + * This program is distributed in the hope that it will be useful,
8631 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8632 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8633 + * GNU General Public License for more details.
8635 + * You should have received a copy of the GNU General Public License
8636 + * along with this program; if not, write to the Free Software
8637 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
8641 + * dynamically customizable operations for regular files
8646 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
8649 + * How large will these lists be?
8650 + * Usually just a few elements, 20-30 at most for each, I guess.
8652 +static struct au_splhead dynop[AuDyLast];
8654 +static struct au_dykey *dy_gfind_get(struct au_splhead *spl, const void *h_op)
8656 + struct au_dykey *key, *tmp;
8657 + struct list_head *head;
8660 + head = &spl->head;
8662 + list_for_each_entry_rcu(tmp, head, dk_list)
8663 + if (tmp->dk_op.dy_hop == h_op) {
8665 + kref_get(&key->dk_kref);
8668 + rcu_read_unlock();
8673 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
8675 + struct au_dykey **k, *found;
8676 + const void *h_op = key->dk_op.dy_hop;
8681 + for (i = 0; i < AuBrDynOp; i++)
8683 + if (k[i]->dk_op.dy_hop == h_op) {
8690 + spin_lock(&br->br_dykey_lock);
8691 + for (; i < AuBrDynOp; i++)
8693 + if (k[i]->dk_op.dy_hop == h_op) {
8701 + spin_unlock(&br->br_dykey_lock);
8702 + BUG_ON(i == AuBrDynOp); /* expand the array */
8708 +/* kref_get() if @key is already added */
8709 +static struct au_dykey *dy_gadd(struct au_splhead *spl, struct au_dykey *key)
8711 + struct au_dykey *tmp, *found;
8712 + struct list_head *head;
8713 + const void *h_op = key->dk_op.dy_hop;
8716 + head = &spl->head;
8717 + spin_lock(&spl->spin);
8718 + list_for_each_entry(tmp, head, dk_list)
8719 + if (tmp->dk_op.dy_hop == h_op) {
8720 + kref_get(&tmp->dk_kref);
8725 + list_add_rcu(&key->dk_list, head);
8726 + spin_unlock(&spl->spin);
8733 +static void dy_free_rcu(struct rcu_head *rcu)
8735 + struct au_dykey *key;
8737 + key = container_of(rcu, struct au_dykey, dk_rcu);
8742 +static void dy_free(struct kref *kref)
8744 + struct au_dykey *key;
8745 + struct au_splhead *spl;
8747 + key = container_of(kref, struct au_dykey, dk_kref);
8748 + spl = dynop + key->dk_op.dy_type;
8749 + au_spl_del_rcu(&key->dk_list, spl);
8750 + call_rcu(&key->dk_rcu, dy_free_rcu);
8753 +void au_dy_put(struct au_dykey *key)
8755 + kref_put(&key->dk_kref, dy_free);
8758 +/* ---------------------------------------------------------------------- */
8760 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
8762 +#ifdef CONFIG_AUFS_DEBUG
8763 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
8764 +#define DyDbgInc(cnt) do { cnt++; } while (0)
8766 +#define DyDbgDeclare(cnt) do {} while (0)
8767 +#define DyDbgInc(cnt) do {} while (0)
8770 +#define DySet(func, dst, src, h_op, h_sb) do { \
8772 + if (h_op->func) { \
8774 + dst.func = src.func; \
8776 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
8780 +#define DySetForce(func, dst, src) do { \
8781 + AuDebugOn(!src.func); \
8783 + dst.func = src.func; \
8786 +#define DySetAop(func) \
8787 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
8788 +#define DySetAopForce(func) \
8789 + DySetForce(func, dyaop->da_op, aufs_aop)
8791 +static void dy_aop(struct au_dykey *key, const void *h_op,
8792 + struct super_block *h_sb __maybe_unused)
8794 + struct au_dyaop *dyaop = (void *)key;
8795 + const struct address_space_operations *h_aop = h_op;
8796 + DyDbgDeclare(cnt);
8798 + AuDbg("%s\n", au_sbtype(h_sb));
8800 + DySetAop(writepage);
8801 + DySetAopForce(readpage); /* force */
8802 + DySetAop(writepages);
8803 + DySetAop(set_page_dirty);
8804 + DySetAop(readpages);
8805 + DySetAop(write_begin);
8806 + DySetAop(write_end);
8808 + DySetAop(invalidatepage);
8809 + DySetAop(releasepage);
8810 + DySetAop(freepage);
8811 + /* these two will be changed according to an aufs mount option */
8812 + DySetAop(direct_IO);
8813 + DySetAop(get_xip_mem);
8814 + DySetAop(migratepage);
8815 + DySetAop(launder_page);
8816 + DySetAop(is_partially_uptodate);
8817 + DySetAop(error_remove_page);
8819 + DyDbgSize(cnt, *h_aop);
8820 + dyaop->da_get_xip_mem = h_aop->get_xip_mem;
8823 +/* ---------------------------------------------------------------------- */
8825 +static void dy_bug(struct kref *kref)
8830 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
8832 + struct au_dykey *key, *old;
8833 + struct au_splhead *spl;
8836 + void (*set)(struct au_dykey *key, const void *h_op,
8837 + struct super_block *h_sb __maybe_unused);
8839 + static const struct op a[] = {
8841 + .sz = sizeof(struct au_dyaop),
8845 + const struct op *p;
8847 + spl = dynop + op->dy_type;
8848 + key = dy_gfind_get(spl, op->dy_hop);
8850 + goto out_add; /* success */
8852 + p = a + op->dy_type;
8853 + key = kzalloc(p->sz, GFP_NOFS);
8854 + if (unlikely(!key)) {
8855 + key = ERR_PTR(-ENOMEM);
8859 + key->dk_op.dy_hop = op->dy_hop;
8860 + kref_init(&key->dk_kref);
8861 + p->set(key, op->dy_hop, br->br_mnt->mnt_sb);
8862 + old = dy_gadd(spl, key);
8869 + old = dy_bradd(br, key);
8871 + /* its ref-count should never be zero here */
8872 + kref_put(&key->dk_kref, dy_bug);
8877 +/* ---------------------------------------------------------------------- */
8879 + * Aufs prohibits O_DIRECT by defaut even if the branch supports it.
8880 + * This behaviour is neccessary to return an error from open(O_DIRECT) instead
8881 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
8882 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
8883 + * See the aufs manual in detail.
8885 + * To keep this behaviour, aufs has to set NULL to ->get_xip_mem too, and the
8886 + * performance of fadvise() and madvise() may be affected.
8888 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
8891 + dyaop->da_op.direct_IO = NULL;
8892 + dyaop->da_op.get_xip_mem = NULL;
8894 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
8895 + dyaop->da_op.get_xip_mem = aufs_aop.get_xip_mem;
8896 + if (!dyaop->da_get_xip_mem)
8897 + dyaop->da_op.get_xip_mem = NULL;
8901 +static struct au_dyaop *dy_aget(struct au_branch *br,
8902 + const struct address_space_operations *h_aop,
8905 + struct au_dyaop *dyaop;
8906 + struct au_dynop op;
8908 + op.dy_type = AuDy_AOP;
8909 + op.dy_haop = h_aop;
8910 + dyaop = (void *)dy_get(&op, br);
8911 + if (IS_ERR(dyaop))
8913 + dy_adx(dyaop, do_dx);
8919 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
8920 + struct inode *h_inode)
8923 + struct super_block *sb;
8924 + struct au_branch *br;
8925 + struct au_dyaop *dyaop;
8927 + AuDebugOn(!S_ISREG(h_inode->i_mode));
8928 + IiMustWriteLock(inode);
8931 + br = au_sbr(sb, bindex);
8932 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
8933 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
8934 + err = PTR_ERR(dyaop);
8935 + if (IS_ERR(dyaop))
8936 + /* unnecessary to call dy_fput() */
8940 + inode->i_mapping->a_ops = &dyaop->da_op;
8947 + * Is it safe to replace a_ops during the inode/file is in operation?
8950 +int au_dy_irefresh(struct inode *inode)
8953 + aufs_bindex_t bstart;
8954 + struct inode *h_inode;
8957 + if (S_ISREG(inode->i_mode)) {
8958 + bstart = au_ibstart(inode);
8959 + h_inode = au_h_iptr(inode, bstart);
8960 + err = au_dy_iaop(inode, bstart, h_inode);
8965 +void au_dy_arefresh(int do_dx)
8967 + struct au_splhead *spl;
8968 + struct list_head *head;
8969 + struct au_dykey *key;
8971 + spl = dynop + AuDy_AOP;
8972 + head = &spl->head;
8973 + spin_lock(&spl->spin);
8974 + list_for_each_entry(key, head, dk_list)
8975 + dy_adx((void *)key, do_dx);
8976 + spin_unlock(&spl->spin);
8979 +/* ---------------------------------------------------------------------- */
8981 +void __init au_dy_init(void)
8985 + /* make sure that 'struct au_dykey *' can be any type */
8986 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
8988 + for (i = 0; i < AuDyLast; i++)
8989 + au_spl_init(dynop + i);
8992 +void au_dy_fin(void)
8996 + for (i = 0; i < AuDyLast; i++)
8997 + WARN_ON(!list_empty(&dynop[i].head));
8999 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
9000 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
9001 +++ linux/fs/aufs/dynop.h 2012-03-19 12:24:13.679801090 +0100
9004 + * Copyright (C) 2010-2012 Junjiro R. Okajima
9006 + * This program, aufs is free software; you can redistribute it and/or modify
9007 + * it under the terms of the GNU General Public License as published by
9008 + * the Free Software Foundation; either version 2 of the License, or
9009 + * (at your option) any later version.
9011 + * This program is distributed in the hope that it will be useful,
9012 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9013 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9014 + * GNU General Public License for more details.
9016 + * You should have received a copy of the GNU General Public License
9017 + * along with this program; if not, write to the Free Software
9018 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
9022 + * dynamically customizable operations (for regular files only)
9025 +#ifndef __AUFS_DYNOP_H__
9026 +#define __AUFS_DYNOP_H__
9032 +enum {AuDy_AOP, AuDyLast};
9037 + const void *dy_hop;
9038 + const struct address_space_operations *dy_haop;
9044 + struct list_head dk_list;
9045 + struct rcu_head dk_rcu;
9047 + struct au_dynop dk_op;
9050 + * during I am in the branch local array, kref is gotten. when the
9051 + * branch is removed, kref is put.
9053 + struct kref dk_kref;
9056 +/* stop unioning since their sizes are very different from each other */
9058 + struct au_dykey da_key;
9059 + struct address_space_operations da_op; /* not const */
9060 + int (*da_get_xip_mem)(struct address_space *, pgoff_t, int,
9061 + void **, unsigned long *);
9064 +/* ---------------------------------------------------------------------- */
9068 +void au_dy_put(struct au_dykey *key);
9069 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
9070 + struct inode *h_inode);
9071 +int au_dy_irefresh(struct inode *inode);
9072 +void au_dy_arefresh(int do_dio);
9074 +void __init au_dy_init(void);
9075 +void au_dy_fin(void);
9077 +#endif /* __KERNEL__ */
9078 +#endif /* __AUFS_DYNOP_H__ */
9079 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
9080 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
9081 +++ linux/fs/aufs/export.c 2012-03-19 12:24:13.679801090 +0100
9084 + * Copyright (C) 2005-2012 Junjiro R. Okajima
9086 + * This program, aufs is free software; you can redistribute it and/or modify
9087 + * it under the terms of the GNU General Public License as published by
9088 + * the Free Software Foundation; either version 2 of the License, or
9089 + * (at your option) any later version.
9091 + * This program is distributed in the hope that it will be useful,
9092 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9093 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9094 + * GNU General Public License for more details.
9096 + * You should have received a copy of the GNU General Public License
9097 + * along with this program; if not, write to the Free Software
9098 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
9105 +#include <linux/exportfs.h>
9106 +#include <linux/fs_struct.h>
9107 +#include <linux/namei.h>
9108 +#include <linux/nsproxy.h>
9109 +#include <linux/random.h>
9110 +#include <linux/writeback.h>
9111 +#include "../fs/mount.h"
9115 +#ifdef CONFIG_AUFS_INO_T_64
9123 +static ino_t decode_ino(__u32 *a)
9127 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
9129 +#ifdef CONFIG_AUFS_INO_T_64
9135 +static void encode_ino(__u32 *a, ino_t ino)
9141 +#ifdef CONFIG_AUFS_INO_T_64
9146 +/* NFS file handle */
9150 +#ifdef CONFIG_AUFS_INO_T_64
9151 + /* support 64bit inode number */
9165 + Fh_dir_ino = Fh_dir_ino1
9168 +static int au_test_anon(struct dentry *dentry)
9170 + /* note: read d_flags without d_lock */
9171 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
9174 +/* ---------------------------------------------------------------------- */
9175 +/* inode generation external table */
9177 +void au_xigen_inc(struct inode *inode)
9182 + struct super_block *sb;
9183 + struct au_sbinfo *sbinfo;
9186 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
9188 + sbinfo = au_sbi(sb);
9189 + pos = inode->i_ino;
9190 + pos *= sizeof(igen);
9191 + igen = inode->i_generation + 1;
9192 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
9193 + sizeof(igen), &pos);
9194 + if (sz == sizeof(igen))
9195 + return; /* success */
9197 + if (unlikely(sz >= 0))
9198 + AuIOErr("xigen error (%zd)\n", sz);
9201 +int au_xigen_new(struct inode *inode)
9206 + struct super_block *sb;
9207 + struct au_sbinfo *sbinfo;
9208 + struct file *file;
9211 + /* todo: dirty, at mount time */
9212 + if (inode->i_ino == AUFS_ROOT_INO)
9215 + SiMustAnyLock(sb);
9216 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
9220 + pos = inode->i_ino;
9221 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
9222 + AuIOErr1("too large i%lld\n", pos);
9225 + pos *= sizeof(inode->i_generation);
9228 + sbinfo = au_sbi(sb);
9229 + file = sbinfo->si_xigen;
9232 + if (i_size_read(file->f_dentry->d_inode)
9233 + < pos + sizeof(inode->i_generation)) {
9234 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
9235 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
9236 + sizeof(inode->i_generation), &pos);
9238 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
9239 + sizeof(inode->i_generation), &pos);
9240 + if (sz == sizeof(inode->i_generation))
9241 + goto out; /* success */
9244 + if (unlikely(sz >= 0)) {
9246 + AuIOErr("xigen error (%zd)\n", sz);
9253 +int au_xigen_set(struct super_block *sb, struct file *base)
9256 + struct au_sbinfo *sbinfo;
9257 + struct file *file;
9259 + SiMustWriteLock(sb);
9261 + sbinfo = au_sbi(sb);
9262 + file = au_xino_create2(base, sbinfo->si_xigen);
9263 + err = PTR_ERR(file);
9267 + if (sbinfo->si_xigen)
9268 + fput(sbinfo->si_xigen);
9269 + sbinfo->si_xigen = file;
9275 +void au_xigen_clr(struct super_block *sb)
9277 + struct au_sbinfo *sbinfo;
9279 + SiMustWriteLock(sb);
9281 + sbinfo = au_sbi(sb);
9282 + if (sbinfo->si_xigen) {
9283 + fput(sbinfo->si_xigen);
9284 + sbinfo->si_xigen = NULL;
9288 +/* ---------------------------------------------------------------------- */
9290 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
9293 + struct dentry *dentry, *d;
9294 + struct inode *inode;
9295 + unsigned int sigen;
9298 + inode = ilookup(sb, ino);
9302 + dentry = ERR_PTR(-ESTALE);
9303 + sigen = au_sigen(sb);
9304 + if (unlikely(is_bad_inode(inode)
9305 + || IS_DEADDIR(inode)
9306 + || sigen != au_iigen(inode)))
9310 + if (!dir_ino || S_ISDIR(inode->i_mode))
9311 + dentry = d_find_alias(inode);
9313 + spin_lock(&inode->i_lock);
9314 + list_for_each_entry(d, &inode->i_dentry, d_alias) {
9315 + spin_lock(&d->d_lock);
9316 + if (!au_test_anon(d)
9317 + && d->d_parent->d_inode->i_ino == dir_ino) {
9318 + dentry = dget_dlock(d);
9319 + spin_unlock(&d->d_lock);
9322 + spin_unlock(&d->d_lock);
9324 + spin_unlock(&inode->i_lock);
9326 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
9327 + /* need to refresh */
9335 + AuTraceErrPtr(dentry);
9339 +/* ---------------------------------------------------------------------- */
9342 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
9344 +struct au_compare_mnt_args {
9346 + struct super_block *sb;
9349 + struct vfsmount *mnt;
9352 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
9354 + struct au_compare_mnt_args *a = arg;
9356 + if (mnt->mnt_sb != a->sb)
9358 + a->mnt = mntget(mnt);
9362 +static struct vfsmount *au_mnt_get(struct super_block *sb)
9366 + struct au_compare_mnt_args args = {
9370 + get_fs_root(current->fs, &root);
9371 + br_read_lock(vfsmount_lock);
9372 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
9373 + br_read_unlock(vfsmount_lock);
9376 + AuDebugOn(!args.mnt);
9380 +struct au_nfsd_si_lock {
9381 + unsigned int sigen;
9382 + aufs_bindex_t bindex, br_id;
9383 + unsigned char force_lock;
9386 +static int si_nfsd_read_lock(struct super_block *sb,
9387 + struct au_nfsd_si_lock *nsi_lock)
9390 + aufs_bindex_t bindex;
9392 + si_read_lock(sb, AuLock_FLUSH);
9394 + /* branch id may be wrapped around */
9396 + bindex = au_br_index(sb, nsi_lock->br_id);
9397 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
9398 + goto out; /* success */
9402 + if (!nsi_lock->force_lock)
9403 + si_read_unlock(sb);
9406 + nsi_lock->bindex = bindex;
9410 +struct find_name_by_ino {
9411 + int called, found;
9418 +find_name_by_ino(void *arg, const char *name, int namelen, loff_t offset,
9419 + u64 ino, unsigned int d_type)
9421 + struct find_name_by_ino *a = arg;
9424 + if (a->ino != ino)
9427 + memcpy(a->name, name, namelen);
9428 + a->namelen = namelen;
9433 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
9434 + struct au_nfsd_si_lock *nsi_lock)
9436 + struct dentry *dentry, *parent;
9437 + struct file *file;
9438 + struct inode *dir;
9439 + struct find_name_by_ino arg;
9442 + parent = path->dentry;
9444 + si_read_unlock(parent->d_sb);
9445 + file = vfsub_dentry_open(path, au_dir_roflags);
9446 + dentry = (void *)file;
9450 + dentry = ERR_PTR(-ENOMEM);
9451 + arg.name = __getname_gfp(GFP_NOFS);
9452 + if (unlikely(!arg.name))
9459 + err = vfsub_readdir(file, find_name_by_ino, &arg);
9460 + } while (!err && !arg.found && arg.called);
9461 + dentry = ERR_PTR(err);
9462 + if (unlikely(err))
9464 + dentry = ERR_PTR(-ENOENT);
9468 + /* do not call au_lkup_one() */
9469 + dir = parent->d_inode;
9470 + mutex_lock(&dir->i_mutex);
9471 + dentry = vfsub_lookup_one_len(arg.name, parent, arg.namelen);
9472 + mutex_unlock(&dir->i_mutex);
9473 + AuTraceErrPtr(dentry);
9474 + if (IS_ERR(dentry))
9476 + AuDebugOn(au_test_anon(dentry));
9477 + if (unlikely(!dentry->d_inode)) {
9479 + dentry = ERR_PTR(-ENOENT);
9483 + __putname(arg.name);
9487 + if (unlikely(nsi_lock
9488 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
9489 + if (!IS_ERR(dentry)) {
9491 + dentry = ERR_PTR(-ESTALE);
9493 + AuTraceErrPtr(dentry);
9497 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
9499 + struct au_nfsd_si_lock *nsi_lock)
9501 + struct dentry *dentry;
9504 + if (dir_ino != AUFS_ROOT_INO) {
9505 + path.dentry = decode_by_ino(sb, dir_ino, 0);
9506 + dentry = path.dentry;
9507 + if (!path.dentry || IS_ERR(path.dentry))
9509 + AuDebugOn(au_test_anon(path.dentry));
9511 + path.dentry = dget(sb->s_root);
9513 + path.mnt = au_mnt_get(sb);
9514 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
9518 + AuTraceErrPtr(dentry);
9522 +/* ---------------------------------------------------------------------- */
9524 +static int h_acceptable(void *expv, struct dentry *dentry)
9529 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
9530 + char *buf, int len, struct super_block *sb)
9536 + p = d_path(h_rootpath, buf, len);
9541 + path.mnt = h_rootpath->mnt;
9542 + path.dentry = h_parent;
9543 + p = d_path(&path, buf, len);
9549 + path.mnt = au_mnt_get(sb);
9550 + path.dentry = sb->s_root;
9551 + p = d_path(&path, buf, len - strlen(p));
9556 + p[strlen(p)] = '/';
9564 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
9565 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
9567 + struct dentry *dentry, *h_parent, *root;
9568 + struct super_block *h_sb;
9569 + char *pathname, *p;
9570 + struct vfsmount *h_mnt;
9571 + struct au_branch *br;
9575 + br = au_sbr(sb, nsi_lock->bindex);
9576 + h_mnt = br->br_mnt;
9577 + h_sb = h_mnt->mnt_sb;
9578 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
9579 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
9580 + fh_len - Fh_tail, fh[Fh_h_type],
9581 + h_acceptable, /*context*/NULL);
9582 + dentry = h_parent;
9583 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
9584 + AuWarn1("%s decode_fh failed, %ld\n",
9585 + au_sbtype(h_sb), PTR_ERR(h_parent));
9589 + if (unlikely(au_test_anon(h_parent))) {
9590 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
9592 + goto out_h_parent;
9595 + dentry = ERR_PTR(-ENOMEM);
9596 + pathname = (void *)__get_free_page(GFP_NOFS);
9597 + if (unlikely(!pathname))
9598 + goto out_h_parent;
9600 + root = sb->s_root;
9602 + di_read_lock_parent(root, !AuLock_IR);
9603 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
9604 + di_read_unlock(root, !AuLock_IR);
9605 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
9606 + dentry = (void *)p;
9608 + goto out_pathname;
9610 + si_read_unlock(sb);
9611 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
9612 + dentry = ERR_PTR(err);
9613 + if (unlikely(err))
9616 + dentry = ERR_PTR(-ENOENT);
9617 + AuDebugOn(au_test_anon(path.dentry));
9618 + if (unlikely(!path.dentry->d_inode))
9621 + if (ino != path.dentry->d_inode->i_ino)
9622 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
9624 + dentry = dget(path.dentry);
9629 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
9630 + if (!IS_ERR(dentry)) {
9632 + dentry = ERR_PTR(-ESTALE);
9635 + free_page((unsigned long)pathname);
9639 + AuTraceErrPtr(dentry);
9643 +/* ---------------------------------------------------------------------- */
9645 +static struct dentry *
9646 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
9649 + struct dentry *dentry;
9650 + __u32 *fh = fid->raw;
9651 + struct au_branch *br;
9652 + ino_t ino, dir_ino;
9653 + struct au_nfsd_si_lock nsi_lock = {
9657 + dentry = ERR_PTR(-ESTALE);
9658 + /* it should never happen, but the file handle is unreliable */
9659 + if (unlikely(fh_len < Fh_tail))
9661 + nsi_lock.sigen = fh[Fh_sigen];
9662 + nsi_lock.br_id = fh[Fh_br_id];
9664 + /* branch id may be wrapped around */
9666 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
9668 + nsi_lock.force_lock = 1;
9670 + /* is this inode still cached? */
9671 + ino = decode_ino(fh + Fh_ino);
9672 + /* it should never happen */
9673 + if (unlikely(ino == AUFS_ROOT_INO))
9676 + dir_ino = decode_ino(fh + Fh_dir_ino);
9677 + dentry = decode_by_ino(sb, ino, dir_ino);
9678 + if (IS_ERR(dentry))
9683 + /* is the parent dir cached? */
9684 + br = au_sbr(sb, nsi_lock.bindex);
9685 + atomic_inc(&br->br_count);
9686 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
9687 + if (IS_ERR(dentry))
9693 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
9694 + if (IS_ERR(dentry))
9696 + if (unlikely(!dentry))
9697 + /* todo?: make it ESTALE */
9701 + if (!au_digen_test(dentry, au_sigen(sb))
9702 + && dentry->d_inode->i_generation == fh[Fh_igen])
9703 + goto out_unlock; /* success */
9706 + dentry = ERR_PTR(-ESTALE);
9709 + atomic_dec(&br->br_count);
9710 + si_read_unlock(sb);
9712 + AuTraceErrPtr(dentry);
9716 +#if 0 /* reserved for future use */
9717 +/* support subtreecheck option */
9718 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
9719 + int fh_len, int fh_type)
9721 + struct dentry *parent;
9722 + __u32 *fh = fid->raw;
9725 + dir_ino = decode_ino(fh + Fh_dir_ino);
9726 + parent = decode_by_ino(sb, dir_ino, 0);
9727 + if (IS_ERR(parent))
9730 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
9731 + dir_ino, fh, fh_len);
9734 + AuTraceErrPtr(parent);
9739 +/* ---------------------------------------------------------------------- */
9741 +static int aufs_encode_fh(struct dentry *dentry, __u32 *fh, int *max_len,
9745 + aufs_bindex_t bindex, bend;
9746 + struct super_block *sb, *h_sb;
9747 + struct inode *inode;
9748 + struct dentry *parent, *h_parent;
9749 + struct au_branch *br;
9751 + AuDebugOn(au_test_anon(dentry));
9755 + if (unlikely(*max_len <= Fh_tail)) {
9756 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
9760 + err = FILEID_ROOT;
9761 + if (IS_ROOT(dentry)) {
9762 + AuDebugOn(dentry->d_inode->i_ino != AUFS_ROOT_INO);
9767 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_IR | AuLock_GEN);
9768 + if (unlikely(err))
9771 + inode = dentry->d_inode;
9772 + AuDebugOn(!inode);
9773 + sb = dentry->d_sb;
9774 +#ifdef CONFIG_AUFS_DEBUG
9775 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
9776 + AuWarn1("NFS-exporting requires xino\n");
9779 + parent = dget_parent(dentry);
9780 + di_read_lock_parent(parent, !AuLock_IR);
9781 + bend = au_dbtaildir(parent);
9782 + for (bindex = au_dbstart(parent); bindex <= bend; bindex++) {
9783 + h_parent = au_h_dptr(parent, bindex);
9789 + if (unlikely(!h_parent))
9793 + br = au_sbr(sb, bindex);
9794 + h_sb = br->br_mnt->mnt_sb;
9795 + if (unlikely(!h_sb->s_export_op)) {
9796 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
9800 + fh[Fh_br_id] = br->br_id;
9801 + fh[Fh_sigen] = au_sigen(sb);
9802 + encode_ino(fh + Fh_ino, inode->i_ino);
9803 + encode_ino(fh + Fh_dir_ino, parent->d_inode->i_ino);
9804 + fh[Fh_igen] = inode->i_generation;
9806 + *max_len -= Fh_tail;
9807 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
9809 + /*connectable or subtreecheck*/0);
9810 + err = fh[Fh_h_type];
9811 + *max_len += Fh_tail;
9812 + /* todo: macros? */
9816 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
9821 + di_read_unlock(parent, !AuLock_IR);
9823 + aufs_read_unlock(dentry, AuLock_IR);
9825 + if (unlikely(err < 0))
9830 +/* ---------------------------------------------------------------------- */
9832 +static int aufs_commit_metadata(struct inode *inode)
9835 + aufs_bindex_t bindex;
9836 + struct super_block *sb;
9837 + struct inode *h_inode;
9838 + int (*f)(struct inode *inode);
9841 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
9842 + ii_write_lock_child(inode);
9843 + bindex = au_ibstart(inode);
9844 + AuDebugOn(bindex < 0);
9845 + h_inode = au_h_iptr(inode, bindex);
9847 + f = h_inode->i_sb->s_export_op->commit_metadata;
9851 + struct writeback_control wbc = {
9852 + .sync_mode = WB_SYNC_ALL,
9853 + .nr_to_write = 0 /* metadata only */
9856 + err = sync_inode(h_inode, &wbc);
9859 + au_cpup_attr_timesizes(inode);
9860 + ii_write_unlock(inode);
9861 + si_read_unlock(sb);
9865 +/* ---------------------------------------------------------------------- */
9867 +static struct export_operations aufs_export_op = {
9868 + .fh_to_dentry = aufs_fh_to_dentry,
9869 + /* .fh_to_parent = aufs_fh_to_parent, */
9870 + .encode_fh = aufs_encode_fh,
9871 + .commit_metadata = aufs_commit_metadata
9874 +void au_export_init(struct super_block *sb)
9876 + struct au_sbinfo *sbinfo;
9879 + sb->s_export_op = &aufs_export_op;
9880 + sbinfo = au_sbi(sb);
9881 + sbinfo->si_xigen = NULL;
9882 + get_random_bytes(&u, sizeof(u));
9883 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
9884 + atomic_set(&sbinfo->si_xigen_next, u);
9886 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
9887 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
9888 +++ linux/fs/aufs/file.c 2012-03-19 12:24:13.679801090 +0100
9891 + * Copyright (C) 2005-2012 Junjiro R. Okajima
9893 + * This program, aufs is free software; you can redistribute it and/or modify
9894 + * it under the terms of the GNU General Public License as published by
9895 + * the Free Software Foundation; either version 2 of the License, or
9896 + * (at your option) any later version.
9898 + * This program is distributed in the hope that it will be useful,
9899 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9900 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9901 + * GNU General Public License for more details.
9903 + * You should have received a copy of the GNU General Public License
9904 + * along with this program; if not, write to the Free Software
9905 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
9909 + * handling file/dir, and address_space operation
9912 +#ifdef CONFIG_AUFS_DEBUG
9913 +#include <linux/migrate.h>
9915 +#include <linux/pagemap.h>
9918 +/* drop flags for writing */
9919 +unsigned int au_file_roflags(unsigned int flags)
9921 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
9922 + flags |= O_RDONLY | O_NOATIME;
9926 +/* common functions to regular file and dir */
9927 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
9928 + struct file *file)
9930 + struct file *h_file;
9931 + struct dentry *h_dentry;
9932 + struct inode *h_inode;
9933 + struct super_block *sb;
9934 + struct au_branch *br;
9935 + struct path h_path;
9936 + int err, exec_flag;
9938 + /* a race condition can happen between open and unlink/rmdir */
9939 + h_file = ERR_PTR(-ENOENT);
9940 + h_dentry = au_h_dptr(dentry, bindex);
9941 + if (au_test_nfsd() && !h_dentry)
9943 + h_inode = h_dentry->d_inode;
9944 + if (au_test_nfsd() && !h_inode)
9946 + spin_lock(&h_dentry->d_lock);
9947 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
9949 + /* || !dentry->d_inode->i_nlink */
9951 + spin_unlock(&h_dentry->d_lock);
9952 + if (unlikely(err))
9955 + sb = dentry->d_sb;
9956 + br = au_sbr(sb, bindex);
9957 + h_file = ERR_PTR(-EACCES);
9958 + exec_flag = flags & __FMODE_EXEC;
9959 + if (exec_flag && (br->br_mnt->mnt_flags & MNT_NOEXEC))
9962 + /* drop flags for writing */
9963 + if (au_test_ro(sb, bindex, dentry->d_inode))
9964 + flags = au_file_roflags(flags);
9965 + flags &= ~O_CREAT;
9966 + atomic_inc(&br->br_count);
9967 + h_path.dentry = h_dentry;
9968 + h_path.mnt = br->br_mnt;
9969 + if (!au_special_file(h_inode->i_mode))
9970 + h_file = vfsub_dentry_open(&h_path, flags);
9972 + /* this block depends upon the configuration */
9973 + di_read_unlock(dentry, AuLock_IR);
9974 + fi_write_unlock(file);
9975 + si_read_unlock(sb);
9976 + h_file = vfsub_dentry_open(&h_path, flags);
9977 + si_noflush_read_lock(sb);
9978 + fi_write_lock(file);
9979 + di_read_lock_child(dentry, AuLock_IR);
9981 + if (IS_ERR(h_file))
9985 + err = deny_write_access(h_file);
9986 + if (unlikely(err)) {
9988 + h_file = ERR_PTR(err);
9992 + fsnotify_open(h_file);
9993 + goto out; /* success */
9996 + atomic_dec(&br->br_count);
10001 +int au_do_open(struct file *file, int (*open)(struct file *file, int flags),
10002 + struct au_fidir *fidir)
10005 + struct dentry *dentry;
10007 + err = au_finfo_init(file, fidir);
10008 + if (unlikely(err))
10011 + dentry = file->f_dentry;
10012 + di_read_lock_child(dentry, AuLock_IR);
10013 + err = open(file, vfsub_file_flags(file));
10014 + di_read_unlock(dentry, AuLock_IR);
10016 + fi_write_unlock(file);
10017 + if (unlikely(err)) {
10018 + au_fi(file)->fi_hdir = NULL;
10019 + au_finfo_fin(file);
10026 +int au_reopen_nondir(struct file *file)
10029 + aufs_bindex_t bstart;
10030 + struct dentry *dentry;
10031 + struct file *h_file, *h_file_tmp;
10033 + dentry = file->f_dentry;
10034 + AuDebugOn(au_special_file(dentry->d_inode->i_mode));
10035 + bstart = au_dbstart(dentry);
10036 + h_file_tmp = NULL;
10037 + if (au_fbstart(file) == bstart) {
10038 + h_file = au_hf_top(file);
10039 + if (file->f_mode == h_file->f_mode)
10040 + return 0; /* success */
10041 + h_file_tmp = h_file;
10042 + get_file(h_file_tmp);
10043 + au_set_h_fptr(file, bstart, NULL);
10045 + AuDebugOn(au_fi(file)->fi_hdir);
10046 + AuDebugOn(au_fbstart(file) < bstart);
10048 + h_file = au_h_open(dentry, bstart, vfsub_file_flags(file) & ~O_TRUNC,
10050 + err = PTR_ERR(h_file);
10051 + if (IS_ERR(h_file))
10052 + goto out; /* todo: close all? */
10055 + au_set_fbstart(file, bstart);
10056 + au_set_h_fptr(file, bstart, h_file);
10057 + au_update_figen(file);
10058 + /* todo: necessary? */
10059 + /* file->f_ra = h_file->f_ra; */
10063 + fput(h_file_tmp);
10067 +/* ---------------------------------------------------------------------- */
10069 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
10070 + struct dentry *hi_wh)
10073 + aufs_bindex_t bstart;
10074 + struct au_dinfo *dinfo;
10075 + struct dentry *h_dentry;
10076 + struct au_hdentry *hdp;
10078 + dinfo = au_di(file->f_dentry);
10079 + AuRwMustWriteLock(&dinfo->di_rwsem);
10081 + bstart = dinfo->di_bstart;
10082 + dinfo->di_bstart = btgt;
10083 + hdp = dinfo->di_hdentry;
10084 + h_dentry = hdp[0 + btgt].hd_dentry;
10085 + hdp[0 + btgt].hd_dentry = hi_wh;
10086 + err = au_reopen_nondir(file);
10087 + hdp[0 + btgt].hd_dentry = h_dentry;
10088 + dinfo->di_bstart = bstart;
10093 +static int au_ready_to_write_wh(struct file *file, loff_t len,
10094 + aufs_bindex_t bcpup)
10097 + struct inode *inode, *h_inode;
10098 + struct dentry *dentry, *h_dentry, *hi_wh;
10100 + dentry = file->f_dentry;
10101 + au_update_dbstart(dentry);
10102 + inode = dentry->d_inode;
10104 + if (au_dbstart(dentry) <= bcpup && au_dbend(dentry) >= bcpup) {
10105 + h_dentry = au_h_dptr(dentry, bcpup);
10107 + h_inode = h_dentry->d_inode;
10109 + hi_wh = au_hi_wh(inode, bcpup);
10110 + if (!hi_wh && !h_inode)
10111 + err = au_sio_cpup_wh(dentry, bcpup, len, file);
10113 + /* already copied-up after unlink */
10114 + err = au_reopen_wh(file, bcpup, hi_wh);
10117 + && inode->i_nlink > 1
10118 + && au_opt_test(au_mntflags(dentry->d_sb), PLINK))
10119 + au_plink_append(inode, bcpup, au_h_dptr(dentry, bcpup));
10125 + * prepare the @file for writing.
10127 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
10130 + aufs_bindex_t bstart, bcpup, dbstart;
10131 + struct dentry *dentry, *parent, *h_dentry;
10132 + struct inode *h_inode, *inode;
10133 + struct super_block *sb;
10134 + struct file *h_file;
10136 + dentry = file->f_dentry;
10137 + sb = dentry->d_sb;
10138 + inode = dentry->d_inode;
10139 + AuDebugOn(au_special_file(inode->i_mode));
10140 + bstart = au_fbstart(file);
10141 + err = au_test_ro(sb, bstart, inode);
10142 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
10143 + err = au_pin(pin, dentry, bstart, AuOpt_UDBA_NONE, /*flags*/0);
10147 + /* need to cpup or reopen */
10148 + parent = dget_parent(dentry);
10149 + di_write_lock_parent(parent);
10150 + err = AuWbrCopyup(au_sbi(sb), dentry);
10152 + if (unlikely(err < 0))
10156 + if (!d_unhashed(dentry) && !au_h_dptr(parent, bcpup)) {
10157 + err = au_cpup_dirs(dentry, bcpup);
10158 + if (unlikely(err))
10162 + err = au_pin(pin, dentry, bcpup, AuOpt_UDBA_NONE,
10163 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
10164 + if (unlikely(err))
10167 + h_dentry = au_hf_top(file)->f_dentry;
10168 + h_inode = h_dentry->d_inode;
10169 + dbstart = au_dbstart(dentry);
10170 + if (dbstart <= bcpup) {
10171 + h_dentry = au_h_dptr(dentry, bcpup);
10172 + AuDebugOn(!h_dentry);
10173 + h_inode = h_dentry->d_inode;
10174 + AuDebugOn(!h_inode);
10178 + if (dbstart <= bcpup /* just reopen */
10179 + || !d_unhashed(dentry) /* copyup and reopen */
10181 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
10182 + h_file = au_h_open_pre(dentry, bstart);
10183 + if (IS_ERR(h_file)) {
10184 + err = PTR_ERR(h_file);
10187 + di_downgrade_lock(parent, AuLock_IR);
10188 + if (dbstart > bcpup)
10189 + err = au_sio_cpup_simple(dentry, bcpup, len,
10192 + err = au_reopen_nondir(file);
10194 + mutex_unlock(&h_inode->i_mutex);
10195 + au_h_open_post(dentry, bstart, h_file);
10196 + } else { /* copyup as wh and reopen */
10198 + * since writable hfsplus branch is not supported,
10199 + * h_open_pre/post() are unnecessary.
10201 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
10202 + err = au_ready_to_write_wh(file, len, bcpup);
10203 + di_downgrade_lock(parent, AuLock_IR);
10204 + mutex_unlock(&h_inode->i_mutex);
10208 + au_pin_set_parent_lflag(pin, /*lflag*/0);
10209 + goto out_dput; /* success */
10215 + di_downgrade_lock(parent, AuLock_IR);
10217 + di_read_unlock(parent, AuLock_IR);
10224 +/* ---------------------------------------------------------------------- */
10226 +int au_do_flush(struct file *file, fl_owner_t id,
10227 + int (*flush)(struct file *file, fl_owner_t id))
10230 + struct dentry *dentry;
10231 + struct super_block *sb;
10232 + struct inode *inode;
10234 + dentry = file->f_dentry;
10235 + sb = dentry->d_sb;
10236 + inode = dentry->d_inode;
10237 + si_noflush_read_lock(sb);
10238 + fi_read_lock(file);
10239 + ii_read_lock_child(inode);
10241 + err = flush(file, id);
10242 + au_cpup_attr_timesizes(inode);
10244 + ii_read_unlock(inode);
10245 + fi_read_unlock(file);
10246 + si_read_unlock(sb);
10250 +/* ---------------------------------------------------------------------- */
10252 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
10255 + aufs_bindex_t bstart;
10256 + struct au_pin pin;
10257 + struct au_finfo *finfo;
10258 + struct dentry *dentry, *parent, *hi_wh;
10259 + struct inode *inode;
10260 + struct super_block *sb;
10262 + FiMustWriteLock(file);
10265 + finfo = au_fi(file);
10266 + dentry = file->f_dentry;
10267 + sb = dentry->d_sb;
10268 + inode = dentry->d_inode;
10269 + bstart = au_ibstart(inode);
10270 + if (bstart == finfo->fi_btop || IS_ROOT(dentry))
10273 + parent = dget_parent(dentry);
10274 + if (au_test_ro(sb, bstart, inode)) {
10275 + di_read_lock_parent(parent, !AuLock_IR);
10276 + err = AuWbrCopyup(au_sbi(sb), dentry);
10278 + di_read_unlock(parent, !AuLock_IR);
10279 + if (unlikely(err < 0))
10284 + di_read_lock_parent(parent, AuLock_IR);
10285 + hi_wh = au_hi_wh(inode, bstart);
10286 + if (!S_ISDIR(inode->i_mode)
10287 + && au_opt_test(au_mntflags(sb), PLINK)
10288 + && au_plink_test(inode)
10289 + && !d_unhashed(dentry)) {
10290 + err = au_test_and_cpup_dirs(dentry, bstart);
10291 + if (unlikely(err))
10294 + /* always superio. */
10295 + err = au_pin(&pin, dentry, bstart, AuOpt_UDBA_NONE,
10296 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
10298 + err = au_sio_cpup_simple(dentry, bstart, -1,
10301 + } else if (hi_wh) {
10302 + /* already copied-up after unlink */
10303 + err = au_reopen_wh(file, bstart, hi_wh);
10304 + *need_reopen = 0;
10308 + di_read_unlock(parent, AuLock_IR);
10315 +static void au_do_refresh_dir(struct file *file)
10317 + aufs_bindex_t bindex, bend, new_bindex, brid;
10318 + struct au_hfile *p, tmp, *q;
10319 + struct au_finfo *finfo;
10320 + struct super_block *sb;
10321 + struct au_fidir *fidir;
10323 + FiMustWriteLock(file);
10325 + sb = file->f_dentry->d_sb;
10326 + finfo = au_fi(file);
10327 + fidir = finfo->fi_hdir;
10328 + AuDebugOn(!fidir);
10329 + p = fidir->fd_hfile + finfo->fi_btop;
10330 + brid = p->hf_br->br_id;
10331 + bend = fidir->fd_bbot;
10332 + for (bindex = finfo->fi_btop; bindex <= bend; bindex++, p++) {
10336 + new_bindex = au_br_index(sb, p->hf_br->br_id);
10337 + if (new_bindex == bindex)
10339 + if (new_bindex < 0) {
10340 + au_set_h_fptr(file, bindex, NULL);
10344 + /* swap two lower inode, and loop again */
10345 + q = fidir->fd_hfile + new_bindex;
10349 + if (tmp.hf_file) {
10355 + p = fidir->fd_hfile;
10356 + if (!au_test_mmapped(file) && !d_unlinked(file->f_dentry)) {
10357 + bend = au_sbend(sb);
10358 + for (finfo->fi_btop = 0; finfo->fi_btop <= bend;
10359 + finfo->fi_btop++, p++)
10360 + if (p->hf_file) {
10361 + if (p->hf_file->f_dentry
10362 + && p->hf_file->f_dentry->d_inode)
10365 + au_hfput(p, file);
10368 + bend = au_br_index(sb, brid);
10369 + for (finfo->fi_btop = 0; finfo->fi_btop < bend;
10370 + finfo->fi_btop++, p++)
10372 + au_hfput(p, file);
10373 + bend = au_sbend(sb);
10376 + p = fidir->fd_hfile + bend;
10377 + for (fidir->fd_bbot = bend; fidir->fd_bbot >= finfo->fi_btop;
10378 + fidir->fd_bbot--, p--)
10379 + if (p->hf_file) {
10380 + if (p->hf_file->f_dentry
10381 + && p->hf_file->f_dentry->d_inode)
10384 + au_hfput(p, file);
10386 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
10390 + * after branch manipulating, refresh the file.
10392 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
10394 + int err, need_reopen;
10395 + aufs_bindex_t bend, bindex;
10396 + struct dentry *dentry;
10397 + struct au_finfo *finfo;
10398 + struct au_hfile *hfile;
10400 + dentry = file->f_dentry;
10401 + finfo = au_fi(file);
10402 + if (!finfo->fi_hdir) {
10403 + hfile = &finfo->fi_htop;
10404 + AuDebugOn(!hfile->hf_file);
10405 + bindex = au_br_index(dentry->d_sb, hfile->hf_br->br_id);
10406 + AuDebugOn(bindex < 0);
10407 + if (bindex != finfo->fi_btop)
10408 + au_set_fbstart(file, bindex);
10410 + err = au_fidir_realloc(finfo, au_sbend(dentry->d_sb) + 1);
10411 + if (unlikely(err))
10413 + au_do_refresh_dir(file);
10418 + if (!au_test_mmapped(file))
10419 + err = au_file_refresh_by_inode(file, &need_reopen);
10420 + if (!err && need_reopen && !d_unlinked(dentry))
10421 + err = reopen(file);
10423 + au_update_figen(file);
10424 + goto out; /* success */
10427 + /* error, close all lower files */
10428 + if (finfo->fi_hdir) {
10429 + bend = au_fbend_dir(file);
10430 + for (bindex = au_fbstart(file); bindex <= bend; bindex++)
10431 + au_set_h_fptr(file, bindex, NULL);
10438 +/* common function to regular file and dir */
10439 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
10443 + unsigned int sigen, figen;
10444 + aufs_bindex_t bstart;
10445 + unsigned char pseudo_link;
10446 + struct dentry *dentry;
10447 + struct inode *inode;
10450 + dentry = file->f_dentry;
10451 + inode = dentry->d_inode;
10452 + AuDebugOn(au_special_file(inode->i_mode));
10453 + sigen = au_sigen(dentry->d_sb);
10454 + fi_write_lock(file);
10455 + figen = au_figen(file);
10456 + di_write_lock_child(dentry);
10457 + bstart = au_dbstart(dentry);
10458 + pseudo_link = (bstart != au_ibstart(inode));
10459 + if (sigen == figen && !pseudo_link && au_fbstart(file) == bstart) {
10461 + di_downgrade_lock(dentry, AuLock_IR);
10462 + fi_downgrade_lock(file);
10464 + goto out; /* success */
10467 + AuDbg("sigen %d, figen %d\n", sigen, figen);
10468 + if (au_digen_test(dentry, sigen)) {
10469 + err = au_reval_dpath(dentry, sigen);
10470 + AuDebugOn(!err && au_digen_test(dentry, sigen));
10474 + err = refresh_file(file, reopen);
10477 + di_downgrade_lock(dentry, AuLock_IR);
10478 + fi_downgrade_lock(file);
10481 + di_write_unlock(dentry);
10482 + fi_write_unlock(file);
10489 +/* ---------------------------------------------------------------------- */
10491 +/* cf. aufs_nopage() */
10492 +/* for madvise(2) */
10493 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
10495 + unlock_page(page);
10499 +/* it will never be called, but necessary to support O_DIRECT */
10500 +static ssize_t aufs_direct_IO(int rw, struct kiocb *iocb,
10501 + const struct iovec *iov, loff_t offset,
10502 + unsigned long nr_segs)
10503 +{ BUG(); return 0; }
10506 + * it will never be called, but madvise and fadvise behaves differently
10507 + * when get_xip_mem is defined
10509 +static int aufs_get_xip_mem(struct address_space *mapping, pgoff_t pgoff,
10510 + int create, void **kmem, unsigned long *pfn)
10511 +{ BUG(); return 0; }
10513 +/* they will never be called. */
10514 +#ifdef CONFIG_AUFS_DEBUG
10515 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
10516 + loff_t pos, unsigned len, unsigned flags,
10517 + struct page **pagep, void **fsdata)
10518 +{ AuUnsupport(); return 0; }
10519 +static int aufs_write_end(struct file *file, struct address_space *mapping,
10520 + loff_t pos, unsigned len, unsigned copied,
10521 + struct page *page, void *fsdata)
10522 +{ AuUnsupport(); return 0; }
10523 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
10524 +{ AuUnsupport(); return 0; }
10526 +static int aufs_set_page_dirty(struct page *page)
10527 +{ AuUnsupport(); return 0; }
10528 +static void aufs_invalidatepage(struct page *page, unsigned long offset)
10529 +{ AuUnsupport(); }
10530 +static int aufs_releasepage(struct page *page, gfp_t gfp)
10531 +{ AuUnsupport(); return 0; }
10532 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
10533 + struct page *page, enum migrate_mode mode)
10534 +{ AuUnsupport(); return 0; }
10535 +static int aufs_launder_page(struct page *page)
10536 +{ AuUnsupport(); return 0; }
10537 +static int aufs_is_partially_uptodate(struct page *page,
10538 + read_descriptor_t *desc,
10539 + unsigned long from)
10540 +{ AuUnsupport(); return 0; }
10541 +static int aufs_error_remove_page(struct address_space *mapping,
10542 + struct page *page)
10543 +{ AuUnsupport(); return 0; }
10544 +#endif /* CONFIG_AUFS_DEBUG */
10546 +const struct address_space_operations aufs_aop = {
10547 + .readpage = aufs_readpage,
10548 + .direct_IO = aufs_direct_IO,
10549 + .get_xip_mem = aufs_get_xip_mem,
10550 +#ifdef CONFIG_AUFS_DEBUG
10551 + .writepage = aufs_writepage,
10552 + /* no writepages, because of writepage */
10553 + .set_page_dirty = aufs_set_page_dirty,
10554 + /* no readpages, because of readpage */
10555 + .write_begin = aufs_write_begin,
10556 + .write_end = aufs_write_end,
10557 + /* no bmap, no block device */
10558 + .invalidatepage = aufs_invalidatepage,
10559 + .releasepage = aufs_releasepage,
10560 + .migratepage = aufs_migratepage,
10561 + .launder_page = aufs_launder_page,
10562 + .is_partially_uptodate = aufs_is_partially_uptodate,
10563 + .error_remove_page = aufs_error_remove_page
10564 +#endif /* CONFIG_AUFS_DEBUG */
10566 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
10567 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
10568 +++ linux/fs/aufs/file.h 2012-03-19 12:24:13.683134508 +0100
10571 + * Copyright (C) 2005-2012 Junjiro R. Okajima
10573 + * This program, aufs is free software; you can redistribute it and/or modify
10574 + * it under the terms of the GNU General Public License as published by
10575 + * the Free Software Foundation; either version 2 of the License, or
10576 + * (at your option) any later version.
10578 + * This program is distributed in the hope that it will be useful,
10579 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10580 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10581 + * GNU General Public License for more details.
10583 + * You should have received a copy of the GNU General Public License
10584 + * along with this program; if not, write to the Free Software
10585 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
10589 + * file operations
10592 +#ifndef __AUFS_FILE_H__
10593 +#define __AUFS_FILE_H__
10597 +#include <linux/file.h>
10598 +#include <linux/fs.h>
10599 +#include <linux/poll.h>
10600 +#include "rwsem.h"
10604 + struct file *hf_file;
10605 + struct au_branch *hf_br;
10610 + aufs_bindex_t fd_bbot;
10611 + aufs_bindex_t fd_nent;
10612 + struct au_vdir *fd_vdir_cache;
10613 + struct au_hfile fd_hfile[];
10616 +static inline int au_fidir_sz(int nent)
10618 + AuDebugOn(nent < 0);
10619 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
10623 + atomic_t fi_generation;
10625 + struct au_rwsem fi_rwsem;
10626 + aufs_bindex_t fi_btop;
10628 + /* do not union them */
10629 + struct { /* for non-dir */
10630 + struct au_hfile fi_htop;
10631 + atomic_t fi_mmapped;
10633 + struct au_fidir *fi_hdir; /* for dir only */
10634 +} ____cacheline_aligned_in_smp;
10636 +/* ---------------------------------------------------------------------- */
10639 +extern const struct address_space_operations aufs_aop;
10640 +unsigned int au_file_roflags(unsigned int flags);
10641 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
10642 + struct file *file);
10643 +int au_do_open(struct file *file, int (*open)(struct file *file, int flags),
10644 + struct au_fidir *fidir);
10645 +int au_reopen_nondir(struct file *file);
10647 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
10648 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
10650 +int au_do_flush(struct file *file, fl_owner_t id,
10651 + int (*flush)(struct file *file, fl_owner_t id));
10654 +#ifdef CONFIG_AUFS_POLL
10655 +unsigned int aufs_poll(struct file *file, poll_table *wait);
10658 +#ifdef CONFIG_AUFS_BR_HFSPLUS
10660 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex);
10661 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
10662 + struct file *h_file);
10665 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex)
10670 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
10671 + struct file *h_file);
10675 +extern const struct file_operations aufs_file_fop;
10676 +int au_do_open_nondir(struct file *file, int flags);
10677 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
10679 +#ifdef CONFIG_AUFS_SP_IATTR
10681 +int au_special_file(umode_t mode);
10682 +void au_init_special_fop(struct inode *inode, umode_t mode, dev_t rdev);
10684 +AuStubInt0(au_special_file, umode_t mode)
10685 +static inline void au_init_special_fop(struct inode *inode, umode_t mode,
10688 + init_special_inode(inode, mode, rdev);
10693 +void au_hfput(struct au_hfile *hf, struct file *file);
10694 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
10695 + struct file *h_file);
10697 +void au_update_figen(struct file *file);
10698 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
10699 +int au_fidir_realloc(struct au_finfo *finfo, int nbr);
10701 +void au_fi_init_once(void *_fi);
10702 +void au_finfo_fin(struct file *file);
10703 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
10706 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
10707 +#ifdef CONFIG_COMPAT
10708 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
10709 + unsigned long arg);
10712 +/* ---------------------------------------------------------------------- */
10714 +static inline struct au_finfo *au_fi(struct file *file)
10716 + return file->private_data;
10719 +/* ---------------------------------------------------------------------- */
10722 + * fi_read_lock, fi_write_lock,
10723 + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock
10725 +AuSimpleRwsemFuncs(fi, struct file *f, &au_fi(f)->fi_rwsem);
10727 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
10728 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
10729 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
10731 +/* ---------------------------------------------------------------------- */
10733 +/* todo: hard/soft set? */
10734 +static inline aufs_bindex_t au_fbstart(struct file *file)
10736 + FiMustAnyLock(file);
10737 + return au_fi(file)->fi_btop;
10740 +static inline aufs_bindex_t au_fbend_dir(struct file *file)
10742 + FiMustAnyLock(file);
10743 + AuDebugOn(!au_fi(file)->fi_hdir);
10744 + return au_fi(file)->fi_hdir->fd_bbot;
10747 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
10749 + FiMustAnyLock(file);
10750 + AuDebugOn(!au_fi(file)->fi_hdir);
10751 + return au_fi(file)->fi_hdir->fd_vdir_cache;
10754 +static inline void au_set_fbstart(struct file *file, aufs_bindex_t bindex)
10756 + FiMustWriteLock(file);
10757 + au_fi(file)->fi_btop = bindex;
10760 +static inline void au_set_fbend_dir(struct file *file, aufs_bindex_t bindex)
10762 + FiMustWriteLock(file);
10763 + AuDebugOn(!au_fi(file)->fi_hdir);
10764 + au_fi(file)->fi_hdir->fd_bbot = bindex;
10767 +static inline void au_set_fvdir_cache(struct file *file,
10768 + struct au_vdir *vdir_cache)
10770 + FiMustWriteLock(file);
10771 + AuDebugOn(!au_fi(file)->fi_hdir);
10772 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
10775 +static inline struct file *au_hf_top(struct file *file)
10777 + FiMustAnyLock(file);
10778 + AuDebugOn(au_fi(file)->fi_hdir);
10779 + return au_fi(file)->fi_htop.hf_file;
10782 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
10784 + FiMustAnyLock(file);
10785 + AuDebugOn(!au_fi(file)->fi_hdir);
10786 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
10789 +/* todo: memory barrier? */
10790 +static inline unsigned int au_figen(struct file *f)
10792 + return atomic_read(&au_fi(f)->fi_generation);
10795 +static inline void au_set_mmapped(struct file *f)
10797 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
10799 + pr_warning("fi_mmapped wrapped around\n");
10800 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
10804 +static inline void au_unset_mmapped(struct file *f)
10806 + atomic_dec(&au_fi(f)->fi_mmapped);
10809 +static inline int au_test_mmapped(struct file *f)
10811 + return atomic_read(&au_fi(f)->fi_mmapped);
10814 +/* customize vma->vm_file */
10816 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
10817 + struct file *file)
10821 + f = vma->vm_file;
10823 + vma->vm_file = file;
10828 +#define AuDbgVmRegion(file, vma) do {} while (0)
10830 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
10831 + struct file *file)
10833 + au_do_vm_file_reset(vma, file);
10836 +#define AuDbgVmRegion(file, vma) \
10837 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
10839 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
10840 + struct file *file)
10844 + au_do_vm_file_reset(vma, file);
10845 + f = vma->vm_region->vm_file;
10847 + vma->vm_region->vm_file = file;
10850 +#endif /* CONFIG_MMU */
10852 +/* handle vma->vm_prfile */
10853 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
10854 + struct file *file)
10856 +#ifdef CONFIG_AUFS_PROC_MAP
10858 + vma->vm_prfile = file;
10859 +#ifndef CONFIG_MMU
10861 + vma->vm_region->vm_prfile = file;
10866 +#endif /* __KERNEL__ */
10867 +#endif /* __AUFS_FILE_H__ */
10868 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
10869 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
10870 +++ linux/fs/aufs/finfo.c 2012-03-19 12:24:13.683134508 +0100
10873 + * Copyright (C) 2005-2012 Junjiro R. Okajima
10875 + * This program, aufs is free software; you can redistribute it and/or modify
10876 + * it under the terms of the GNU General Public License as published by
10877 + * the Free Software Foundation; either version 2 of the License, or
10878 + * (at your option) any later version.
10880 + * This program is distributed in the hope that it will be useful,
10881 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10882 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10883 + * GNU General Public License for more details.
10885 + * You should have received a copy of the GNU General Public License
10886 + * along with this program; if not, write to the Free Software
10887 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
10891 + * file private data
10896 +void au_hfput(struct au_hfile *hf, struct file *file)
10898 + /* todo: direct access f_flags */
10899 + if (vfsub_file_flags(file) & __FMODE_EXEC)
10900 + allow_write_access(hf->hf_file);
10901 + fput(hf->hf_file);
10902 + hf->hf_file = NULL;
10903 + atomic_dec(&hf->hf_br->br_count);
10904 + hf->hf_br = NULL;
10907 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
10909 + struct au_finfo *finfo = au_fi(file);
10910 + struct au_hfile *hf;
10911 + struct au_fidir *fidir;
10913 + fidir = finfo->fi_hdir;
10915 + AuDebugOn(finfo->fi_btop != bindex);
10916 + hf = &finfo->fi_htop;
10918 + hf = fidir->fd_hfile + bindex;
10920 + if (hf && hf->hf_file)
10921 + au_hfput(hf, file);
10923 + FiMustWriteLock(file);
10924 + hf->hf_file = val;
10925 + hf->hf_br = au_sbr(file->f_dentry->d_sb, bindex);
10929 +void au_update_figen(struct file *file)
10931 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_dentry));
10932 + /* smp_mb(); */ /* atomic_set */
10935 +/* ---------------------------------------------------------------------- */
10937 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
10939 + struct au_fidir *fidir;
10942 + nbr = au_sbend(sb) + 1;
10944 + nbr = 2; /* initial allocate for 2 branches */
10945 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
10947 + fidir->fd_bbot = -1;
10948 + fidir->fd_nent = nbr;
10949 + fidir->fd_vdir_cache = NULL;
10955 +int au_fidir_realloc(struct au_finfo *finfo, int nbr)
10958 + struct au_fidir *fidir, *p;
10960 + AuRwMustWriteLock(&finfo->fi_rwsem);
10961 + fidir = finfo->fi_hdir;
10962 + AuDebugOn(!fidir);
10965 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
10968 + p->fd_nent = nbr;
10969 + finfo->fi_hdir = p;
10976 +/* ---------------------------------------------------------------------- */
10978 +void au_finfo_fin(struct file *file)
10980 + struct au_finfo *finfo;
10982 + au_nfiles_dec(file->f_dentry->d_sb);
10984 + finfo = au_fi(file);
10985 + AuDebugOn(finfo->fi_hdir);
10986 + AuRwDestroy(&finfo->fi_rwsem);
10987 + au_cache_free_finfo(finfo);
10990 +void au_fi_init_once(void *_finfo)
10992 + struct au_finfo *finfo = _finfo;
10993 + static struct lock_class_key aufs_fi;
10995 + au_rw_init(&finfo->fi_rwsem);
10996 + au_rw_class(&finfo->fi_rwsem, &aufs_fi);
10999 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
11002 + struct au_finfo *finfo;
11003 + struct dentry *dentry;
11006 + dentry = file->f_dentry;
11007 + finfo = au_cache_alloc_finfo();
11008 + if (unlikely(!finfo))
11012 + au_nfiles_inc(dentry->d_sb);
11013 + lc_idx = AuLcNonDir_FIINFO;
11015 + lc_idx = AuLcDir_FIINFO;
11016 + au_rw_class(&finfo->fi_rwsem, au_lc_key + lc_idx);
11017 + au_rw_write_lock(&finfo->fi_rwsem);
11018 + finfo->fi_btop = -1;
11019 + finfo->fi_hdir = fidir;
11020 + atomic_set(&finfo->fi_generation, au_digen(dentry));
11021 + /* smp_mb(); */ /* atomic_set */
11023 + file->private_data = finfo;
11028 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
11029 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
11030 +++ linux/fs/aufs/f_op.c 2012-03-19 12:24:13.679801090 +0100
11033 + * Copyright (C) 2005-2012 Junjiro R. Okajima
11035 + * This program, aufs is free software; you can redistribute it and/or modify
11036 + * it under the terms of the GNU General Public License as published by
11037 + * the Free Software Foundation; either version 2 of the License, or
11038 + * (at your option) any later version.
11040 + * This program is distributed in the hope that it will be useful,
11041 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11042 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11043 + * GNU General Public License for more details.
11045 + * You should have received a copy of the GNU General Public License
11046 + * along with this program; if not, write to the Free Software
11047 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11051 + * file and vm operations
11054 +#include <linux/fs_stack.h>
11055 +#include <linux/mman.h>
11056 +#include <linux/security.h>
11059 +int au_do_open_nondir(struct file *file, int flags)
11062 + aufs_bindex_t bindex;
11063 + struct file *h_file;
11064 + struct dentry *dentry;
11065 + struct au_finfo *finfo;
11067 + FiMustWriteLock(file);
11069 + dentry = file->f_dentry;
11070 + err = au_d_alive(dentry);
11071 + if (unlikely(err))
11074 + finfo = au_fi(file);
11075 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
11076 + atomic_set(&finfo->fi_mmapped, 0);
11077 + bindex = au_dbstart(dentry);
11078 + h_file = au_h_open(dentry, bindex, flags, file);
11079 + if (IS_ERR(h_file))
11080 + err = PTR_ERR(h_file);
11082 + au_set_fbstart(file, bindex);
11083 + au_set_h_fptr(file, bindex, h_file);
11084 + au_update_figen(file);
11085 + /* todo: necessary? */
11086 + /* file->f_ra = h_file->f_ra; */
11093 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
11094 + struct file *file)
11097 + struct super_block *sb;
11099 + AuDbg("%.*s, f_flags 0x%x, f_mode 0x%x\n",
11100 + AuDLNPair(file->f_dentry), vfsub_file_flags(file),
11103 + sb = file->f_dentry->d_sb;
11104 + si_read_lock(sb, AuLock_FLUSH);
11105 + err = au_do_open(file, au_do_open_nondir, /*fidir*/NULL);
11106 + si_read_unlock(sb);
11110 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
11112 + struct au_finfo *finfo;
11113 + aufs_bindex_t bindex;
11115 + finfo = au_fi(file);
11116 + bindex = finfo->fi_btop;
11117 + if (bindex >= 0) {
11118 + /* remove me from sb->s_files */
11119 + file_sb_list_del(file);
11120 + au_set_h_fptr(file, bindex, NULL);
11123 + au_finfo_fin(file);
11127 +/* ---------------------------------------------------------------------- */
11129 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
11132 + struct file *h_file;
11135 + h_file = au_hf_top(file);
11137 + err = vfsub_flush(h_file, id);
11141 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
11143 + return au_do_flush(file, id, au_do_flush_nondir);
11146 +/* ---------------------------------------------------------------------- */
11148 + * read and write functions acquire [fdi]_rwsem once, but release before
11149 + * mmap_sem. This is because to stop a race condition between mmap(2).
11150 + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping
11151 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
11152 + * read functions after [fdi]_rwsem are released, but it should be harmless.
11155 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
11159 + struct dentry *dentry;
11160 + struct file *h_file;
11161 + struct super_block *sb;
11163 + dentry = file->f_dentry;
11164 + sb = dentry->d_sb;
11165 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11166 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
11167 + if (unlikely(err))
11170 + h_file = au_hf_top(file);
11171 + get_file(h_file);
11172 + di_read_unlock(dentry, AuLock_IR);
11173 + fi_read_unlock(file);
11175 + /* filedata may be obsoleted by concurrent copyup, but no problem */
11176 + err = vfsub_read_u(h_file, buf, count, ppos);
11177 + /* todo: necessary? */
11178 + /* file->f_ra = h_file->f_ra; */
11179 + /* update without lock, I don't think it a problem */
11180 + fsstack_copy_attr_atime(dentry->d_inode, h_file->f_dentry->d_inode);
11184 + si_read_unlock(sb);
11189 + * todo: very ugly
11190 + * it locks both of i_mutex and si_rwsem for read in safe.
11191 + * if the plink maintenance mode continues forever (that is the problem),
11192 + * may loop forever.
11194 +static void au_mtx_and_read_lock(struct inode *inode)
11197 + struct super_block *sb = inode->i_sb;
11200 + mutex_lock(&inode->i_mutex);
11201 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
11204 + mutex_unlock(&inode->i_mutex);
11205 + si_read_lock(sb, AuLock_NOPLMW);
11206 + si_read_unlock(sb);
11210 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
11211 + size_t count, loff_t *ppos)
11214 + struct au_pin pin;
11215 + struct dentry *dentry;
11216 + struct super_block *sb;
11217 + struct inode *inode;
11218 + struct file *h_file;
11219 + char __user *buf = (char __user *)ubuf;
11221 + dentry = file->f_dentry;
11222 + sb = dentry->d_sb;
11223 + inode = dentry->d_inode;
11224 + au_mtx_and_read_lock(inode);
11226 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
11227 + if (unlikely(err))
11230 + err = au_ready_to_write(file, -1, &pin);
11231 + di_downgrade_lock(dentry, AuLock_IR);
11232 + if (unlikely(err)) {
11233 + di_read_unlock(dentry, AuLock_IR);
11234 + fi_write_unlock(file);
11238 + h_file = au_hf_top(file);
11239 + get_file(h_file);
11241 + di_read_unlock(dentry, AuLock_IR);
11242 + fi_write_unlock(file);
11244 + err = vfsub_write_u(h_file, buf, count, ppos);
11245 + ii_write_lock_child(inode);
11246 + au_cpup_attr_timesizes(inode);
11247 + inode->i_mode = h_file->f_dentry->d_inode->i_mode;
11248 + ii_write_unlock(inode);
11252 + si_read_unlock(sb);
11253 + mutex_unlock(&inode->i_mutex);
11257 +static ssize_t au_do_aio(struct file *h_file, int rw, struct kiocb *kio,
11258 + const struct iovec *iov, unsigned long nv, loff_t pos)
11261 + struct file *file;
11262 + ssize_t (*func)(struct kiocb *, const struct iovec *, unsigned long,
11265 + err = security_file_permission(h_file, rw);
11266 + if (unlikely(err))
11271 + if (rw == MAY_READ)
11272 + func = h_file->f_op->aio_read;
11273 + else if (rw == MAY_WRITE)
11274 + func = h_file->f_op->aio_write;
11276 + file = kio->ki_filp;
11277 + kio->ki_filp = h_file;
11279 + err = func(kio, iov, nv, pos);
11281 + kio->ki_filp = file;
11283 + /* currently there is no such fs */
11290 +static ssize_t aufs_aio_read(struct kiocb *kio, const struct iovec *iov,
11291 + unsigned long nv, loff_t pos)
11294 + struct file *file, *h_file;
11295 + struct dentry *dentry;
11296 + struct super_block *sb;
11298 + file = kio->ki_filp;
11299 + dentry = file->f_dentry;
11300 + sb = dentry->d_sb;
11301 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11302 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
11303 + if (unlikely(err))
11306 + h_file = au_hf_top(file);
11307 + get_file(h_file);
11308 + di_read_unlock(dentry, AuLock_IR);
11309 + fi_read_unlock(file);
11311 + err = au_do_aio(h_file, MAY_READ, kio, iov, nv, pos);
11312 + /* todo: necessary? */
11313 + /* file->f_ra = h_file->f_ra; */
11314 + /* update without lock, I don't think it a problem */
11315 + fsstack_copy_attr_atime(dentry->d_inode, h_file->f_dentry->d_inode);
11319 + si_read_unlock(sb);
11323 +static ssize_t aufs_aio_write(struct kiocb *kio, const struct iovec *iov,
11324 + unsigned long nv, loff_t pos)
11327 + struct au_pin pin;
11328 + struct dentry *dentry;
11329 + struct inode *inode;
11330 + struct file *file, *h_file;
11331 + struct super_block *sb;
11333 + file = kio->ki_filp;
11334 + dentry = file->f_dentry;
11335 + sb = dentry->d_sb;
11336 + inode = dentry->d_inode;
11337 + au_mtx_and_read_lock(inode);
11339 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
11340 + if (unlikely(err))
11343 + err = au_ready_to_write(file, -1, &pin);
11344 + di_downgrade_lock(dentry, AuLock_IR);
11345 + if (unlikely(err)) {
11346 + di_read_unlock(dentry, AuLock_IR);
11347 + fi_write_unlock(file);
11351 + h_file = au_hf_top(file);
11352 + get_file(h_file);
11354 + di_read_unlock(dentry, AuLock_IR);
11355 + fi_write_unlock(file);
11357 + err = au_do_aio(h_file, MAY_WRITE, kio, iov, nv, pos);
11358 + ii_write_lock_child(inode);
11359 + au_cpup_attr_timesizes(inode);
11360 + inode->i_mode = h_file->f_dentry->d_inode->i_mode;
11361 + ii_write_unlock(inode);
11365 + si_read_unlock(sb);
11366 + mutex_unlock(&inode->i_mutex);
11370 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
11371 + struct pipe_inode_info *pipe, size_t len,
11372 + unsigned int flags)
11375 + struct file *h_file;
11376 + struct dentry *dentry;
11377 + struct super_block *sb;
11379 + dentry = file->f_dentry;
11380 + sb = dentry->d_sb;
11381 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11382 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
11383 + if (unlikely(err))
11387 + h_file = au_hf_top(file);
11388 + get_file(h_file);
11389 + if (au_test_loopback_kthread()) {
11390 + au_warn_loopback(h_file->f_dentry->d_sb);
11391 + if (file->f_mapping != h_file->f_mapping) {
11392 + file->f_mapping = h_file->f_mapping;
11393 + smp_mb(); /* unnecessary? */
11396 + di_read_unlock(dentry, AuLock_IR);
11397 + fi_read_unlock(file);
11399 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
11400 + /* todo: necessasry? */
11401 + /* file->f_ra = h_file->f_ra; */
11402 + /* update without lock, I don't think it a problem */
11403 + fsstack_copy_attr_atime(dentry->d_inode, h_file->f_dentry->d_inode);
11407 + si_read_unlock(sb);
11412 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
11413 + size_t len, unsigned int flags)
11416 + struct au_pin pin;
11417 + struct dentry *dentry;
11418 + struct inode *inode;
11419 + struct file *h_file;
11420 + struct super_block *sb;
11422 + dentry = file->f_dentry;
11423 + sb = dentry->d_sb;
11424 + inode = dentry->d_inode;
11425 + au_mtx_and_read_lock(inode);
11427 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
11428 + if (unlikely(err))
11431 + err = au_ready_to_write(file, -1, &pin);
11432 + di_downgrade_lock(dentry, AuLock_IR);
11433 + if (unlikely(err)) {
11434 + di_read_unlock(dentry, AuLock_IR);
11435 + fi_write_unlock(file);
11439 + h_file = au_hf_top(file);
11440 + get_file(h_file);
11442 + di_read_unlock(dentry, AuLock_IR);
11443 + fi_write_unlock(file);
11445 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
11446 + ii_write_lock_child(inode);
11447 + au_cpup_attr_timesizes(inode);
11448 + inode->i_mode = h_file->f_dentry->d_inode->i_mode;
11449 + ii_write_unlock(inode);
11453 + si_read_unlock(sb);
11454 + mutex_unlock(&inode->i_mutex);
11458 +/* ---------------------------------------------------------------------- */
11461 + * The locking order around current->mmap_sem.
11462 + * - in most and regular cases
11463 + * file I/O syscall -- aufs_read() or something
11464 + * -- si_rwsem for read -- mmap_sem
11465 + * (Note that [fdi]i_rwsem are released before mmap_sem).
11467 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
11468 + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
11469 + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
11470 + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
11471 + * It means that when aufs acquires si_rwsem for write, the process should never
11472 + * acquire mmap_sem.
11474 + * Actually aufs_readdir() holds [fdi]i_rwsem before mmap_sem, but this is not a
11475 + * problem either since any directory is not able to be mmap-ed.
11476 + * The similar scenario is applied to aufs_readlink() too.
11479 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
11480 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
11482 +static unsigned long au_arch_prot_conv(unsigned long flags)
11484 + /* currently ppc64 only */
11485 +#ifdef CONFIG_PPC64
11486 + /* cf. linux/arch/powerpc/include/asm/mman.h */
11487 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
11488 + return AuConv_VM_PROT(flags, SAO);
11490 + AuDebugOn(arch_calc_vm_prot_bits(-1));
11495 +static unsigned long au_prot_conv(unsigned long flags)
11497 + return AuConv_VM_PROT(flags, READ)
11498 + | AuConv_VM_PROT(flags, WRITE)
11499 + | AuConv_VM_PROT(flags, EXEC)
11500 + | au_arch_prot_conv(flags);
11503 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
11504 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
11506 +static unsigned long au_flag_conv(unsigned long flags)
11508 + return AuConv_VM_MAP(flags, GROWSDOWN)
11509 + | AuConv_VM_MAP(flags, DENYWRITE)
11510 + | AuConv_VM_MAP(flags, EXECUTABLE)
11511 + | AuConv_VM_MAP(flags, LOCKED);
11514 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
11517 + unsigned long prot;
11518 + aufs_bindex_t bstart;
11519 + const unsigned char wlock
11520 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
11521 + struct dentry *dentry;
11522 + struct super_block *sb;
11523 + struct file *h_file;
11524 + struct au_branch *br;
11525 + struct au_pin pin;
11527 + AuDbgVmRegion(file, vma);
11529 + dentry = file->f_dentry;
11530 + sb = dentry->d_sb;
11532 + si_read_lock(sb, AuLock_NOPLMW);
11533 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
11534 + if (unlikely(err))
11538 + err = au_ready_to_write(file, -1, &pin);
11539 + di_write_unlock(dentry);
11540 + if (unlikely(err)) {
11541 + fi_write_unlock(file);
11546 + di_write_unlock(dentry);
11548 + bstart = au_fbstart(file);
11549 + br = au_sbr(sb, bstart);
11550 + h_file = au_hf_top(file);
11551 + get_file(h_file);
11552 + au_set_mmapped(file);
11553 + fi_write_unlock(file);
11556 + au_vm_file_reset(vma, h_file);
11557 + prot = au_prot_conv(vma->vm_flags);
11558 + err = security_file_mmap(h_file, /*reqprot*/prot, prot,
11559 + au_flag_conv(vma->vm_flags), vma->vm_start, 0);
11561 + err = h_file->f_op->mmap(h_file, vma);
11562 + if (unlikely(err))
11565 + au_vm_prfile_set(vma, file);
11566 + /* update without lock, I don't think it a problem */
11567 + fsstack_copy_attr_atime(file->f_dentry->d_inode,
11568 + h_file->f_dentry->d_inode);
11569 + goto out_fput; /* success */
11572 + au_unset_mmapped(file);
11573 + au_vm_file_reset(vma, file);
11578 + si_read_unlock(sb);
11584 +/* ---------------------------------------------------------------------- */
11586 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
11590 + struct au_pin pin;
11591 + struct dentry *dentry;
11592 + struct inode *inode;
11593 + struct file *h_file;
11594 + struct super_block *sb;
11596 + dentry = file->f_dentry;
11597 + inode = dentry->d_inode;
11598 + sb = dentry->d_sb;
11599 + mutex_lock(&inode->i_mutex);
11600 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
11601 + if (unlikely(err))
11604 + err = 0; /* -EBADF; */ /* posix? */
11605 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
11607 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
11608 + if (unlikely(err))
11611 + err = au_ready_to_write(file, -1, &pin);
11612 + di_downgrade_lock(dentry, AuLock_IR);
11613 + if (unlikely(err))
11618 + h_file = au_hf_top(file);
11619 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
11620 + au_cpup_attr_timesizes(inode);
11623 + di_read_unlock(dentry, AuLock_IR);
11624 + fi_write_unlock(file);
11626 + si_read_unlock(sb);
11628 + mutex_unlock(&inode->i_mutex);
11632 +/* no one supports this operation, currently */
11634 +static int aufs_aio_fsync_nondir(struct kiocb *kio, int datasync)
11637 + struct au_pin pin;
11638 + struct dentry *dentry;
11639 + struct inode *inode;
11640 + struct file *file, *h_file;
11642 + file = kio->ki_filp;
11643 + dentry = file->f_dentry;
11644 + inode = dentry->d_inode;
11645 + au_mtx_and_read_lock(inode);
11647 + err = 0; /* -EBADF; */ /* posix? */
11648 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
11650 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
11651 + if (unlikely(err))
11654 + err = au_ready_to_write(file, -1, &pin);
11655 + di_downgrade_lock(dentry, AuLock_IR);
11656 + if (unlikely(err))
11661 + h_file = au_hf_top(file);
11662 + if (h_file->f_op && h_file->f_op->aio_fsync) {
11663 + struct dentry *h_d;
11664 + struct mutex *h_mtx;
11666 + h_d = h_file->f_dentry;
11667 + h_mtx = &h_d->d_inode->i_mutex;
11668 + if (!is_sync_kiocb(kio)) {
11669 + get_file(h_file);
11672 + kio->ki_filp = h_file;
11673 + err = h_file->f_op->aio_fsync(kio, datasync);
11674 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
11676 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL);
11678 + au_cpup_attr_timesizes(inode);
11679 + mutex_unlock(h_mtx);
11683 + di_read_unlock(dentry, AuLock_IR);
11684 + fi_write_unlock(file);
11686 + si_read_unlock(inode->sb);
11687 + mutex_unlock(&inode->i_mutex);
11692 +static int aufs_fasync(int fd, struct file *file, int flag)
11695 + struct file *h_file;
11696 + struct dentry *dentry;
11697 + struct super_block *sb;
11699 + dentry = file->f_dentry;
11700 + sb = dentry->d_sb;
11701 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11702 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
11703 + if (unlikely(err))
11706 + h_file = au_hf_top(file);
11707 + if (h_file->f_op && h_file->f_op->fasync)
11708 + err = h_file->f_op->fasync(fd, h_file, flag);
11710 + di_read_unlock(dentry, AuLock_IR);
11711 + fi_read_unlock(file);
11714 + si_read_unlock(sb);
11718 +/* ---------------------------------------------------------------------- */
11720 +/* no one supports this operation, currently */
11722 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
11723 + size_t len, loff_t *pos , int more)
11728 +/* ---------------------------------------------------------------------- */
11730 +const struct file_operations aufs_file_fop = {
11731 + .owner = THIS_MODULE,
11733 + .llseek = default_llseek,
11735 + .read = aufs_read,
11736 + .write = aufs_write,
11737 + .aio_read = aufs_aio_read,
11738 + .aio_write = aufs_aio_write,
11739 +#ifdef CONFIG_AUFS_POLL
11740 + .poll = aufs_poll,
11742 + .unlocked_ioctl = aufs_ioctl_nondir,
11743 +#ifdef CONFIG_COMPAT
11744 + .compat_ioctl = aufs_ioctl_nondir, /* same */
11746 + .mmap = aufs_mmap,
11747 + .open = aufs_open_nondir,
11748 + .flush = aufs_flush_nondir,
11749 + .release = aufs_release_nondir,
11750 + .fsync = aufs_fsync_nondir,
11751 + /* .aio_fsync = aufs_aio_fsync_nondir, */
11752 + .fasync = aufs_fasync,
11753 + /* .sendpage = aufs_sendpage, */
11754 + .splice_write = aufs_splice_write,
11755 + .splice_read = aufs_splice_read,
11757 + .aio_splice_write = aufs_aio_splice_write,
11758 + .aio_splice_read = aufs_aio_splice_read
11761 diff -urN /usr/share/empty/fs/aufs/f_op_sp.c linux/fs/aufs/f_op_sp.c
11762 --- /usr/share/empty/fs/aufs/f_op_sp.c 1970-01-01 01:00:00.000000000 +0100
11763 +++ linux/fs/aufs/f_op_sp.c 2012-03-19 12:24:13.679801090 +0100
11766 + * Copyright (C) 2005-2012 Junjiro R. Okajima
11768 + * This program, aufs is free software; you can redistribute it and/or modify
11769 + * it under the terms of the GNU General Public License as published by
11770 + * the Free Software Foundation; either version 2 of the License, or
11771 + * (at your option) any later version.
11773 + * This program is distributed in the hope that it will be useful,
11774 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11775 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11776 + * GNU General Public License for more details.
11778 + * You should have received a copy of the GNU General Public License
11779 + * along with this program; if not, write to the Free Software
11780 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11784 + * file operations for special files.
11785 + * while they exist in aufs virtually,
11786 + * their file I/O is handled out of aufs.
11791 +static ssize_t aufs_aio_read_sp(struct kiocb *kio, const struct iovec *iov,
11792 + unsigned long nv, loff_t pos)
11795 + aufs_bindex_t bstart;
11796 + unsigned char wbr;
11797 + struct file *file, *h_file;
11798 + struct super_block *sb;
11800 + file = kio->ki_filp;
11801 + sb = file->f_dentry->d_sb;
11802 + si_read_lock(sb, AuLock_FLUSH);
11803 + fi_read_lock(file);
11804 + bstart = au_fbstart(file);
11805 + h_file = au_hf_top(file);
11806 + fi_read_unlock(file);
11807 + wbr = !!au_br_writable(au_sbr(sb, bstart)->br_perm);
11808 + si_read_unlock(sb);
11810 + /* do not change the file in kio */
11811 + AuDebugOn(!h_file->f_op || !h_file->f_op->aio_read);
11812 + err = h_file->f_op->aio_read(kio, iov, nv, pos);
11813 + if (err > 0 && wbr)
11814 + file_accessed(h_file);
11819 +static ssize_t aufs_aio_write_sp(struct kiocb *kio, const struct iovec *iov,
11820 + unsigned long nv, loff_t pos)
11823 + aufs_bindex_t bstart;
11824 + unsigned char wbr;
11825 + struct super_block *sb;
11826 + struct file *file, *h_file;
11828 + file = kio->ki_filp;
11829 + sb = file->f_dentry->d_sb;
11830 + si_read_lock(sb, AuLock_FLUSH);
11831 + fi_read_lock(file);
11832 + bstart = au_fbstart(file);
11833 + h_file = au_hf_top(file);
11834 + fi_read_unlock(file);
11835 + wbr = !!au_br_writable(au_sbr(sb, bstart)->br_perm);
11836 + si_read_unlock(sb);
11838 + /* do not change the file in kio */
11839 + AuDebugOn(!h_file->f_op || !h_file->f_op->aio_write);
11840 + err = h_file->f_op->aio_write(kio, iov, nv, pos);
11841 + if (err > 0 && wbr)
11842 + file_update_time(h_file);
11847 +/* ---------------------------------------------------------------------- */
11849 +static int aufs_release_sp(struct inode *inode, struct file *file)
11852 + struct file *h_file;
11854 + fi_read_lock(file);
11855 + h_file = au_hf_top(file);
11856 + fi_read_unlock(file);
11857 + /* close this fifo in aufs */
11858 + err = h_file->f_op->release(inode, file); /* ignore */
11859 + aufs_release_nondir(inode, file); /* ignore */
11863 +/* ---------------------------------------------------------------------- */
11865 +/* currently, support only FIFO */
11867 + AuSp_FIFO, AuSp_FIFO_R, AuSp_FIFO_W, AuSp_FIFO_RW,
11868 + /* AuSp_SOCK, AuSp_CHR, AuSp_BLK, */
11871 +static int aufs_open_sp(struct inode *inode, struct file *file);
11872 +static struct au_sp_fop {
11874 + struct file_operations fop; /* not 'const' */
11876 +} au_sp_fop[AuSp_Last] = {
11879 + .owner = THIS_MODULE,
11880 + .open = aufs_open_sp
11885 +static void au_init_fop_sp(struct file *file)
11887 + struct au_sp_fop *p;
11889 + struct file *h_file;
11892 + if (unlikely(!p->done)) {
11893 + /* initialize first time only */
11894 + static DEFINE_SPINLOCK(spin);
11896 + spin_lock(&spin);
11898 + BUILD_BUG_ON(sizeof(au_sp_fop)/sizeof(*au_sp_fop)
11900 + for (i = 0; i < AuSp_Last; i++)
11901 + spin_lock_init(&p[i].spin);
11904 + spin_unlock(&spin);
11907 + switch (file->f_mode & (FMODE_READ | FMODE_WRITE)) {
11911 + case FMODE_WRITE:
11914 + case FMODE_READ | FMODE_WRITE:
11915 + i = AuSp_FIFO_RW;
11922 + if (unlikely(!p->done)) {
11923 + /* initialize first time only */
11924 + h_file = au_hf_top(file);
11925 + spin_lock(&p->spin);
11927 + p->fop = *h_file->f_op;
11928 + p->fop.owner = THIS_MODULE;
11929 + if (p->fop.aio_read)
11930 + p->fop.aio_read = aufs_aio_read_sp;
11931 + if (p->fop.aio_write)
11932 + p->fop.aio_write = aufs_aio_write_sp;
11933 + p->fop.release = aufs_release_sp;
11936 + spin_unlock(&p->spin);
11938 + file->f_op = &p->fop;
11941 +static int au_cpup_sp(struct dentry *dentry)
11944 + aufs_bindex_t bcpup;
11945 + struct au_pin pin;
11946 + struct au_wr_dir_args wr_dir_args = {
11947 + .force_btgt = -1,
11951 + AuDbg("%.*s\n", AuDLNPair(dentry));
11953 + di_read_unlock(dentry, AuLock_IR);
11954 + di_write_lock_child(dentry);
11955 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
11956 + if (unlikely(err < 0))
11960 + if (bcpup == au_dbstart(dentry))
11961 + goto out; /* success */
11963 + err = au_pin(&pin, dentry, bcpup, au_opt_udba(dentry->d_sb),
11964 + AuPin_MNT_WRITE);
11966 + err = au_sio_cpup_simple(dentry, bcpup, -1, AuCpup_DTIME);
11971 + di_downgrade_lock(dentry, AuLock_IR);
11975 +static int au_do_open_sp(struct file *file, int flags)
11978 + struct dentry *dentry;
11979 + struct super_block *sb;
11980 + struct file *h_file;
11981 + struct inode *h_inode;
11983 + dentry = file->f_dentry;
11984 + AuDbg("%.*s\n", AuDLNPair(dentry));
11987 + * try copying-up.
11988 + * operate on the ro branch is not an error.
11990 + au_cpup_sp(dentry); /* ignore */
11992 + /* prepare h_file */
11993 + err = au_do_open_nondir(file, vfsub_file_flags(file));
11994 + if (unlikely(err))
11997 + sb = dentry->d_sb;
11998 + h_file = au_hf_top(file);
11999 + h_inode = h_file->f_dentry->d_inode;
12000 + di_read_unlock(dentry, AuLock_IR);
12001 + fi_write_unlock(file);
12002 + si_read_unlock(sb);
12003 + /* open this fifo in aufs */
12004 + err = h_inode->i_fop->open(file->f_dentry->d_inode, file);
12005 + si_noflush_read_lock(sb);
12006 + fi_write_lock(file);
12007 + di_read_lock_child(dentry, AuLock_IR);
12009 + au_init_fop_sp(file);
12015 +static int aufs_open_sp(struct inode *inode, struct file *file)
12018 + struct super_block *sb;
12020 + sb = file->f_dentry->d_sb;
12021 + si_read_lock(sb, AuLock_FLUSH);
12022 + err = au_do_open(file, au_do_open_sp, /*fidir*/NULL);
12023 + si_read_unlock(sb);
12027 +/* ---------------------------------------------------------------------- */
12029 +void au_init_special_fop(struct inode *inode, umode_t mode, dev_t rdev)
12031 + init_special_inode(inode, mode, rdev);
12033 + switch (mode & S_IFMT) {
12035 + inode->i_fop = &au_sp_fop[AuSp_FIFO].fop;
12046 +int au_special_file(umode_t mode)
12051 + switch (mode & S_IFMT) {
12063 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
12064 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
12065 +++ linux/fs/aufs/fstype.h 2012-03-19 12:24:13.683134508 +0100
12068 + * Copyright (C) 2005-2012 Junjiro R. Okajima
12070 + * This program, aufs is free software; you can redistribute it and/or modify
12071 + * it under the terms of the GNU General Public License as published by
12072 + * the Free Software Foundation; either version 2 of the License, or
12073 + * (at your option) any later version.
12075 + * This program is distributed in the hope that it will be useful,
12076 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12077 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12078 + * GNU General Public License for more details.
12080 + * You should have received a copy of the GNU General Public License
12081 + * along with this program; if not, write to the Free Software
12082 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
12086 + * judging filesystem type
12089 +#ifndef __AUFS_FSTYPE_H__
12090 +#define __AUFS_FSTYPE_H__
12094 +#include <linux/fs.h>
12095 +#include <linux/magic.h>
12096 +#include <linux/romfs_fs.h>
12098 +static inline int au_test_aufs(struct super_block *sb)
12100 + return sb->s_magic == AUFS_SUPER_MAGIC;
12103 +static inline const char *au_sbtype(struct super_block *sb)
12105 + return sb->s_type->name;
12108 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
12110 +#if defined(CONFIG_ROMFS_FS) || defined(CONFIG_ROMFS_FS_MODULE)
12111 + return sb->s_magic == ROMFS_MAGIC;
12117 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
12119 +#if defined(CONFIG_ISO9660_FS) || defined(CONFIG_ISO9660_FS_MODULE)
12120 + return sb->s_magic == ISOFS_SUPER_MAGIC;
12126 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
12128 +#if defined(CONFIG_CRAMFS) || defined(CONFIG_CRAMFS_MODULE)
12129 + return sb->s_magic == CRAMFS_MAGIC;
12134 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
12136 +#if defined(CONFIG_NFS_FS) || defined(CONFIG_NFS_FS_MODULE)
12137 + return sb->s_magic == NFS_SUPER_MAGIC;
12143 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
12145 +#if defined(CONFIG_FUSE_FS) || defined(CONFIG_FUSE_FS_MODULE)
12146 + return sb->s_magic == FUSE_SUPER_MAGIC;
12152 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
12154 +#if defined(CONFIG_XFS_FS) || defined(CONFIG_XFS_FS_MODULE)
12155 + return sb->s_magic == XFS_SB_MAGIC;
12161 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
12163 +#ifdef CONFIG_TMPFS
12164 + return sb->s_magic == TMPFS_MAGIC;
12170 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
12172 +#if defined(CONFIG_ECRYPT_FS) || defined(CONFIG_ECRYPT_FS_MODULE)
12173 + return !strcmp(au_sbtype(sb), "ecryptfs");
12179 +static inline int au_test_smbfs(struct super_block *sb __maybe_unused)
12181 +#if defined(CONFIG_SMB_FS) || defined(CONFIG_SMB_FS_MODULE)
12182 + return sb->s_magic == SMB_SUPER_MAGIC;
12188 +static inline int au_test_ocfs2(struct super_block *sb __maybe_unused)
12190 +#if defined(CONFIG_OCFS2_FS) || defined(CONFIG_OCFS2_FS_MODULE)
12191 + return sb->s_magic == OCFS2_SUPER_MAGIC;
12197 +static inline int au_test_ocfs2_dlmfs(struct super_block *sb __maybe_unused)
12199 +#if defined(CONFIG_OCFS2_FS_O2CB) || defined(CONFIG_OCFS2_FS_O2CB_MODULE)
12200 + return sb->s_magic == DLMFS_MAGIC;
12206 +static inline int au_test_coda(struct super_block *sb __maybe_unused)
12208 +#if defined(CONFIG_CODA_FS) || defined(CONFIG_CODA_FS_MODULE)
12209 + return sb->s_magic == CODA_SUPER_MAGIC;
12215 +static inline int au_test_v9fs(struct super_block *sb __maybe_unused)
12217 +#if defined(CONFIG_9P_FS) || defined(CONFIG_9P_FS_MODULE)
12218 + return sb->s_magic == V9FS_MAGIC;
12224 +static inline int au_test_ext4(struct super_block *sb __maybe_unused)
12226 +#if defined(CONFIG_EXT4DEV_FS) || defined(CONFIG_EXT4DEV_FS_MODULE)
12227 + return sb->s_magic == EXT4_SUPER_MAGIC;
12233 +static inline int au_test_sysv(struct super_block *sb __maybe_unused)
12235 +#if defined(CONFIG_SYSV_FS) || defined(CONFIG_SYSV_FS_MODULE)
12236 + return !strcmp(au_sbtype(sb), "sysv");
12242 +static inline int au_test_ramfs(struct super_block *sb)
12244 + return sb->s_magic == RAMFS_MAGIC;
12247 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
12249 +#if defined(CONFIG_UBIFS_FS) || defined(CONFIG_UBIFS_FS_MODULE)
12250 + return sb->s_magic == UBIFS_SUPER_MAGIC;
12256 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
12258 +#ifdef CONFIG_PROC_FS
12259 + return sb->s_magic == PROC_SUPER_MAGIC;
12265 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
12267 +#ifdef CONFIG_SYSFS
12268 + return sb->s_magic == SYSFS_MAGIC;
12274 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
12276 +#if defined(CONFIG_CONFIGFS_FS) || defined(CONFIG_CONFIGFS_FS_MODULE)
12277 + return sb->s_magic == CONFIGFS_MAGIC;
12283 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
12285 +#if defined(CONFIG_MINIX_FS) || defined(CONFIG_MINIX_FS_MODULE)
12286 + return sb->s_magic == MINIX3_SUPER_MAGIC
12287 + || sb->s_magic == MINIX2_SUPER_MAGIC
12288 + || sb->s_magic == MINIX2_SUPER_MAGIC2
12289 + || sb->s_magic == MINIX_SUPER_MAGIC
12290 + || sb->s_magic == MINIX_SUPER_MAGIC2;
12296 +static inline int au_test_cifs(struct super_block *sb __maybe_unused)
12298 +#if defined(CONFIG_CIFS_FS) || defined(CONFIGCIFS_FS_MODULE)
12299 + return sb->s_magic == CIFS_MAGIC_NUMBER;
12305 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
12307 +#if defined(CONFIG_FAT_FS) || defined(CONFIG_FAT_FS_MODULE)
12308 + return sb->s_magic == MSDOS_SUPER_MAGIC;
12314 +static inline int au_test_msdos(struct super_block *sb)
12316 + return au_test_fat(sb);
12319 +static inline int au_test_vfat(struct super_block *sb)
12321 + return au_test_fat(sb);
12324 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
12326 +#ifdef CONFIG_SECURITYFS
12327 + return sb->s_magic == SECURITYFS_MAGIC;
12333 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
12335 +#if defined(CONFIG_SQUASHFS) || defined(CONFIG_SQUASHFS_MODULE)
12336 + return sb->s_magic == SQUASHFS_MAGIC;
12342 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
12344 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
12345 + return sb->s_magic == BTRFS_SUPER_MAGIC;
12351 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
12353 +#if defined(CONFIG_XENFS) || defined(CONFIG_XENFS_MODULE)
12354 + return sb->s_magic == XENFS_SUPER_MAGIC;
12360 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
12362 +#ifdef CONFIG_DEBUG_FS
12363 + return sb->s_magic == DEBUGFS_MAGIC;
12369 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
12371 +#if defined(CONFIG_NILFS) || defined(CONFIG_NILFS_MODULE)
12372 + return sb->s_magic == NILFS_SUPER_MAGIC;
12378 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
12380 +#if defined(CONFIG_HFSPLUS_FS) || defined(CONFIG_HFSPLUS_FS_MODULE)
12381 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
12387 +/* ---------------------------------------------------------------------- */
12389 + * they can't be an aufs branch.
12391 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
12394 +#ifndef CONFIG_AUFS_BR_RAMFS
12395 + au_test_ramfs(sb) ||
12397 + au_test_procfs(sb)
12398 + || au_test_sysfs(sb)
12399 + || au_test_configfs(sb)
12400 + || au_test_debugfs(sb)
12401 + || au_test_securityfs(sb)
12402 + || au_test_xenfs(sb)
12403 + || au_test_ecryptfs(sb)
12404 + /* || !strcmp(au_sbtype(sb), "unionfs") */
12405 + || au_test_aufs(sb); /* will be supported in next version */
12409 + * If the filesystem supports NFS-export, then it has to support NULL as
12410 + * a nameidata parameter for ->create(), ->lookup() and ->d_revalidate().
12411 + * We can apply this principle when we handle a lower filesystem.
12413 +static inline int au_test_fs_null_nd(struct super_block *sb)
12415 + return !!sb->s_export_op;
12418 +static inline int au_test_fs_remote(struct super_block *sb)
12420 + return !au_test_tmpfs(sb)
12421 +#ifdef CONFIG_AUFS_BR_RAMFS
12422 + && !au_test_ramfs(sb)
12424 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
12427 +/* ---------------------------------------------------------------------- */
12430 + * Note: these functions (below) are created after reading ->getattr() in all
12431 + * filesystems under linux/fs. it means we have to do so in every update...
12435 + * some filesystems require getattr to refresh the inode attributes before
12437 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
12438 + * and leave the work for d_revalidate()
12440 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
12442 + return au_test_nfs(sb)
12443 + || au_test_fuse(sb)
12444 + /* || au_test_smbfs(sb) */ /* untested */
12445 + /* || au_test_ocfs2(sb) */ /* untested */
12446 + /* || au_test_btrfs(sb) */ /* untested */
12447 + /* || au_test_coda(sb) */ /* untested */
12448 + /* || au_test_v9fs(sb) */ /* untested */
12453 + * filesystems which don't maintain i_size or i_blocks.
12455 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
12457 + return au_test_xfs(sb)
12458 + || au_test_btrfs(sb)
12459 + || au_test_ubifs(sb)
12460 + || au_test_hfsplus(sb) /* maintained, but incorrect */
12461 + /* || au_test_ext4(sb) */ /* untested */
12462 + /* || au_test_ocfs2(sb) */ /* untested */
12463 + /* || au_test_ocfs2_dlmfs(sb) */ /* untested */
12464 + /* || au_test_sysv(sb) */ /* untested */
12465 + /* || au_test_minix(sb) */ /* untested */
12470 + * filesystems which don't store the correct value in some of their inode
12473 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
12475 + return au_test_fs_bad_iattr_size(sb)
12476 + /* || au_test_cifs(sb) */ /* untested */
12477 + || au_test_fat(sb)
12478 + || au_test_msdos(sb)
12479 + || au_test_vfat(sb);
12482 +/* they don't check i_nlink in link(2) */
12483 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
12485 + return au_test_tmpfs(sb)
12486 +#ifdef CONFIG_AUFS_BR_RAMFS
12487 + || au_test_ramfs(sb)
12489 + || au_test_ubifs(sb)
12490 + || au_test_btrfs(sb)
12491 + || au_test_hfsplus(sb);
12495 + * filesystems which sets S_NOATIME and S_NOCMTIME.
12497 +static inline int au_test_fs_notime(struct super_block *sb)
12499 + return au_test_nfs(sb)
12500 + || au_test_fuse(sb)
12501 + || au_test_ubifs(sb)
12502 + /* || au_test_cifs(sb) */ /* untested */
12507 + * filesystems which requires replacing i_mapping.
12509 +static inline int au_test_fs_bad_mapping(struct super_block *sb)
12511 + return au_test_fuse(sb)
12512 + || au_test_ubifs(sb);
12515 +/* temporary support for i#1 in cramfs */
12516 +static inline int au_test_fs_unique_ino(struct inode *inode)
12518 + if (au_test_cramfs(inode->i_sb))
12519 + return inode->i_ino != 1;
12523 +/* ---------------------------------------------------------------------- */
12526 + * the filesystem where the xino files placed must support i/o after unlink and
12527 + * maintain i_size and i_blocks.
12529 +static inline int au_test_fs_bad_xino(struct super_block *sb)
12531 + return au_test_fs_remote(sb)
12532 + || au_test_fs_bad_iattr_size(sb)
12533 +#ifdef CONFIG_AUFS_BR_RAMFS
12534 + || !(au_test_ramfs(sb) || au_test_fs_null_nd(sb))
12536 + || !au_test_fs_null_nd(sb) /* to keep xino code simple */
12538 + /* don't want unnecessary work for xino */
12539 + || au_test_aufs(sb)
12540 + || au_test_ecryptfs(sb)
12541 + || au_test_nilfs(sb);
12544 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
12546 + return au_test_tmpfs(sb)
12547 + || au_test_ramfs(sb);
12551 + * test if the @sb is real-readonly.
12553 +static inline int au_test_fs_rr(struct super_block *sb)
12555 + return au_test_squashfs(sb)
12556 + || au_test_iso9660(sb)
12557 + || au_test_cramfs(sb)
12558 + || au_test_romfs(sb);
12561 +#endif /* __KERNEL__ */
12562 +#endif /* __AUFS_FSTYPE_H__ */
12563 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
12564 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
12565 +++ linux/fs/aufs/hfsnotify.c 2012-03-19 12:24:13.683134508 +0100
12568 + * Copyright (C) 2005-2012 Junjiro R. Okajima
12570 + * This program, aufs is free software; you can redistribute it and/or modify
12571 + * it under the terms of the GNU General Public License as published by
12572 + * the Free Software Foundation; either version 2 of the License, or
12573 + * (at your option) any later version.
12575 + * This program is distributed in the hope that it will be useful,
12576 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12577 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12578 + * GNU General Public License for more details.
12580 + * You should have received a copy of the GNU General Public License
12581 + * along with this program; if not, write to the Free Software
12582 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
12586 + * fsnotify for the lower directories
12591 +/* FS_IN_IGNORED is unnecessary */
12592 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
12593 + | FS_CREATE | FS_EVENT_ON_CHILD);
12594 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
12595 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
12597 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
12599 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
12602 + au_cache_free_hnotify(hn);
12603 + smp_mb__before_atomic_dec();
12604 + atomic64_dec(&au_hfsn_ifree);
12605 + wake_up(&au_hfsn_wq);
12608 +static int au_hfsn_alloc(struct au_hinode *hinode)
12610 + struct au_hnotify *hn;
12611 + struct super_block *sb;
12612 + struct au_branch *br;
12613 + struct fsnotify_mark *mark;
12614 + aufs_bindex_t bindex;
12616 + hn = hinode->hi_notify;
12617 + sb = hn->hn_aufs_inode->i_sb;
12618 + bindex = au_br_index(sb, hinode->hi_id);
12619 + br = au_sbr(sb, bindex);
12620 + mark = &hn->hn_mark;
12621 + fsnotify_init_mark(mark, au_hfsn_free_mark);
12622 + mark->mask = AuHfsnMask;
12624 + * by udba rename or rmdir, aufs assign a new inode to the known
12625 + * h_inode, so specify 1 to allow dups.
12627 + return fsnotify_add_mark(mark, br->br_hfsn_group, hinode->hi_inode,
12628 + /*mnt*/NULL, /*allow_dups*/1);
12631 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
12633 + struct fsnotify_mark *mark;
12634 + unsigned long long ull;
12636 + ull = atomic64_inc_return(&au_hfsn_ifree);
12639 + mark = &hn->hn_mark;
12640 + fsnotify_destroy_mark(mark);
12641 + fsnotify_put_mark(mark);
12643 + /* free hn by myself */
12647 +/* ---------------------------------------------------------------------- */
12649 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
12651 + struct fsnotify_mark *mark;
12653 + mark = &hinode->hi_notify->hn_mark;
12654 + spin_lock(&mark->lock);
12656 + AuDebugOn(mark->mask & AuHfsnMask);
12657 + mark->mask |= AuHfsnMask;
12659 + AuDebugOn(!(mark->mask & AuHfsnMask));
12660 + mark->mask &= ~AuHfsnMask;
12662 + spin_unlock(&mark->lock);
12663 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
12666 +/* ---------------------------------------------------------------------- */
12668 +/* #define AuDbgHnotify */
12669 +#ifdef AuDbgHnotify
12670 +static char *au_hfsn_name(u32 mask)
12672 +#ifdef CONFIG_AUFS_DEBUG
12673 +#define test_ret(flag) if (mask & flag) \
12675 + test_ret(FS_ACCESS);
12676 + test_ret(FS_MODIFY);
12677 + test_ret(FS_ATTRIB);
12678 + test_ret(FS_CLOSE_WRITE);
12679 + test_ret(FS_CLOSE_NOWRITE);
12680 + test_ret(FS_OPEN);
12681 + test_ret(FS_MOVED_FROM);
12682 + test_ret(FS_MOVED_TO);
12683 + test_ret(FS_CREATE);
12684 + test_ret(FS_DELETE);
12685 + test_ret(FS_DELETE_SELF);
12686 + test_ret(FS_MOVE_SELF);
12687 + test_ret(FS_UNMOUNT);
12688 + test_ret(FS_Q_OVERFLOW);
12689 + test_ret(FS_IN_IGNORED);
12690 + test_ret(FS_IN_ISDIR);
12691 + test_ret(FS_IN_ONESHOT);
12692 + test_ret(FS_EVENT_ON_CHILD);
12701 +/* ---------------------------------------------------------------------- */
12703 +static int au_hfsn_handle_event(struct fsnotify_group *group,
12704 + struct fsnotify_mark *inode_mark,
12705 + struct fsnotify_mark *vfsmount_mark,
12706 + struct fsnotify_event *event)
12709 + struct au_hnotify *hnotify;
12710 + struct inode *h_dir, *h_inode;
12712 + struct qstr h_child_qstr = {
12713 + .name = event->file_name,
12714 + .len = event->name_len
12717 + AuDebugOn(event->data_type != FSNOTIFY_EVENT_INODE);
12720 + /* if FS_UNMOUNT happens, there must be another bug */
12721 + mask = event->mask;
12722 + AuDebugOn(mask & FS_UNMOUNT);
12723 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
12726 + h_dir = event->to_tell;
12727 + h_inode = event->inode;
12728 +#ifdef AuDbgHnotify
12730 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
12731 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
12732 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
12733 + h_dir->i_ino, mask, au_hfsn_name(mask),
12734 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
12735 + /* WARN_ON(1); */
12740 + AuDebugOn(!inode_mark);
12741 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
12742 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
12748 +/* isn't it waste to ask every registered 'group'? */
12749 +/* copied from linux/fs/notify/inotify/inotify_fsnotiry.c */
12750 +/* it should be exported to modules */
12751 +static bool au_hfsn_should_send_event(struct fsnotify_group *group,
12752 + struct inode *h_inode,
12753 + struct fsnotify_mark *inode_mark,
12754 + struct fsnotify_mark *vfsmount_mark,
12755 + __u32 mask, void *data, int data_type)
12757 + mask = (mask & ~FS_EVENT_ON_CHILD);
12758 + return inode_mark->mask & mask;
12761 +static struct fsnotify_ops au_hfsn_ops = {
12762 + .should_send_event = au_hfsn_should_send_event,
12763 + .handle_event = au_hfsn_handle_event
12766 +/* ---------------------------------------------------------------------- */
12768 +static void au_hfsn_fin_br(struct au_branch *br)
12770 + if (br->br_hfsn_group)
12771 + fsnotify_put_group(br->br_hfsn_group);
12774 +static int au_hfsn_init_br(struct au_branch *br, int perm)
12776 + br->br_hfsn_group = NULL;
12777 + br->br_hfsn_ops = au_hfsn_ops;
12781 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
12786 + if (udba != AuOpt_UDBA_HNOTIFY
12787 + || !au_br_hnotifyable(perm)) {
12788 + au_hfsn_fin_br(br);
12789 + br->br_hfsn_group = NULL;
12793 + if (br->br_hfsn_group)
12796 + br->br_hfsn_group = fsnotify_alloc_group(&br->br_hfsn_ops);
12797 + if (IS_ERR(br->br_hfsn_group)) {
12798 + err = PTR_ERR(br->br_hfsn_group);
12799 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
12800 + br->br_hfsn_group = NULL;
12808 +/* ---------------------------------------------------------------------- */
12810 +static void au_hfsn_fin(void)
12812 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
12813 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
12816 +const struct au_hnotify_op au_hnotify_op = {
12817 + .ctl = au_hfsn_ctl,
12818 + .alloc = au_hfsn_alloc,
12819 + .free = au_hfsn_free,
12821 + .fin = au_hfsn_fin,
12823 + .reset_br = au_hfsn_reset_br,
12824 + .fin_br = au_hfsn_fin_br,
12825 + .init_br = au_hfsn_init_br
12827 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
12828 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
12829 +++ linux/fs/aufs/hfsplus.c 2012-03-19 12:24:13.683134508 +0100
12832 + * Copyright (C) 2010-2012 Junjiro R. Okajima
12834 + * This program, aufs is free software; you can redistribute it and/or modify
12835 + * it under the terms of the GNU General Public License as published by
12836 + * the Free Software Foundation; either version 2 of the License, or
12837 + * (at your option) any later version.
12839 + * This program is distributed in the hope that it will be useful,
12840 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12841 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12842 + * GNU General Public License for more details.
12844 + * You should have received a copy of the GNU General Public License
12845 + * along with this program; if not, write to the Free Software
12846 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
12850 + * special support for filesystems which aqucires an inode mutex
12851 + * at final closing a file, eg, hfsplus.
12853 + * This trick is very simple and stupid, just to open the file before really
12854 + * neceeary open to tell hfsplus that this is not the final closing.
12855 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
12856 + * and au_h_open_post() after releasing it.
12861 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex)
12863 + struct file *h_file;
12864 + struct dentry *h_dentry;
12866 + h_dentry = au_h_dptr(dentry, bindex);
12867 + AuDebugOn(!h_dentry);
12868 + AuDebugOn(!h_dentry->d_inode);
12869 + IMustLock(h_dentry->d_inode);
12872 + if (au_test_hfsplus(h_dentry->d_sb)
12873 + && S_ISREG(h_dentry->d_inode->i_mode))
12874 + h_file = au_h_open(dentry, bindex,
12875 + O_RDONLY | O_NOATIME | O_LARGEFILE,
12880 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
12881 + struct file *h_file)
12885 + au_sbr_put(dentry->d_sb, bindex);
12888 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
12889 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
12890 +++ linux/fs/aufs/hnotify.c 2012-03-19 12:24:13.683134508 +0100
12893 + * Copyright (C) 2005-2012 Junjiro R. Okajima
12895 + * This program, aufs is free software; you can redistribute it and/or modify
12896 + * it under the terms of the GNU General Public License as published by
12897 + * the Free Software Foundation; either version 2 of the License, or
12898 + * (at your option) any later version.
12900 + * This program is distributed in the hope that it will be useful,
12901 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12902 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12903 + * GNU General Public License for more details.
12905 + * You should have received a copy of the GNU General Public License
12906 + * along with this program; if not, write to the Free Software
12907 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
12911 + * abstraction to notify the direct changes on lower directories
12916 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
12919 + struct au_hnotify *hn;
12922 + hn = au_cache_alloc_hnotify();
12924 + hn->hn_aufs_inode = inode;
12925 + hinode->hi_notify = hn;
12926 + err = au_hnotify_op.alloc(hinode);
12928 + if (unlikely(err)) {
12929 + hinode->hi_notify = NULL;
12930 + au_cache_free_hnotify(hn);
12932 + * The upper dir was removed by udba, but the same named
12933 + * dir left. In this case, aufs assignes a new inode
12934 + * number and set the monitor again.
12935 + * For the lower dir, the old monitnor is still left.
12937 + if (err == -EEXIST)
12946 +void au_hn_free(struct au_hinode *hinode)
12948 + struct au_hnotify *hn;
12950 + hn = hinode->hi_notify;
12952 + hinode->hi_notify = NULL;
12953 + if (au_hnotify_op.free(hinode, hn))
12954 + au_cache_free_hnotify(hn);
12958 +/* ---------------------------------------------------------------------- */
12960 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
12962 + if (hinode->hi_notify)
12963 + au_hnotify_op.ctl(hinode, do_set);
12966 +void au_hn_reset(struct inode *inode, unsigned int flags)
12968 + aufs_bindex_t bindex, bend;
12969 + struct inode *hi;
12970 + struct dentry *iwhdentry;
12972 + bend = au_ibend(inode);
12973 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
12974 + hi = au_h_iptr(inode, bindex);
12978 + /* mutex_lock_nested(&hi->i_mutex, AuLsc_I_CHILD); */
12979 + iwhdentry = au_hi_wh(inode, bindex);
12983 + au_set_h_iptr(inode, bindex, NULL, 0);
12984 + au_set_h_iptr(inode, bindex, au_igrab(hi),
12985 + flags & ~AuHi_XINO);
12988 + /* mutex_unlock(&hi->i_mutex); */
12992 +/* ---------------------------------------------------------------------- */
12994 +static int hn_xino(struct inode *inode, struct inode *h_inode)
12997 + aufs_bindex_t bindex, bend, bfound, bstart;
12998 + struct inode *h_i;
13001 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
13002 + pr_warning("branch root dir was changed\n");
13007 + bend = au_ibend(inode);
13008 + bstart = au_ibstart(inode);
13009 +#if 0 /* reserved for future use */
13010 + if (bindex == bend) {
13011 + /* keep this ino in rename case */
13015 + for (bindex = bstart; bindex <= bend; bindex++)
13016 + if (au_h_iptr(inode, bindex) == h_inode) {
13023 + for (bindex = bstart; bindex <= bend; bindex++) {
13024 + h_i = au_h_iptr(inode, bindex);
13028 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
13029 + /* ignore this error */
13030 + /* bad action? */
13033 + /* children inode number will be broken */
13040 +static int hn_gen_tree(struct dentry *dentry)
13042 + int err, i, j, ndentry;
13043 + struct au_dcsub_pages dpages;
13044 + struct au_dpage *dpage;
13045 + struct dentry **dentries;
13047 + err = au_dpages_init(&dpages, GFP_NOFS);
13048 + if (unlikely(err))
13050 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
13051 + if (unlikely(err))
13054 + for (i = 0; i < dpages.ndpage; i++) {
13055 + dpage = dpages.dpages + i;
13056 + dentries = dpage->dentries;
13057 + ndentry = dpage->ndentry;
13058 + for (j = 0; j < ndentry; j++) {
13059 + struct dentry *d;
13067 + /* todo: reset children xino?
13068 + cached children only? */
13069 + au_iigen_dec(d->d_inode);
13074 + au_dpages_free(&dpages);
13077 + /* discard children */
13078 + dentry_unhash(dentry);
13086 + * return 0 if processed.
13088 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
13089 + const unsigned int isdir)
13092 + struct dentry *d;
13093 + struct qstr *dname;
13096 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
13097 + pr_warning("branch root dir was changed\n");
13103 + AuDebugOn(!name);
13104 + au_iigen_dec(inode);
13105 + spin_lock(&inode->i_lock);
13106 + list_for_each_entry(d, &inode->i_dentry, d_alias) {
13107 + spin_lock(&d->d_lock);
13108 + dname = &d->d_name;
13109 + if (dname->len != nlen
13110 + && memcmp(dname->name, name, nlen)) {
13111 + spin_unlock(&d->d_lock);
13116 + spin_unlock(&d->d_lock);
13119 + spin_unlock(&inode->i_lock);
13121 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
13122 + d = d_find_alias(inode);
13124 + au_iigen_dec(inode);
13128 + spin_lock(&d->d_lock);
13129 + dname = &d->d_name;
13130 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
13131 + spin_unlock(&d->d_lock);
13132 + err = hn_gen_tree(d);
13133 + spin_lock(&d->d_lock);
13135 + spin_unlock(&d->d_lock);
13144 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
13147 + struct inode *inode;
13149 + inode = dentry->d_inode;
13150 + if (IS_ROOT(dentry)
13151 + /* || (inode && inode->i_ino == AUFS_ROOT_INO) */
13153 + pr_warning("branch root dir was changed\n");
13159 + au_digen_dec(dentry);
13161 + au_iigen_dec(inode);
13163 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
13165 + err = hn_gen_tree(dentry);
13172 +/* ---------------------------------------------------------------------- */
13174 +/* hnotify job flags */
13175 +#define AuHnJob_XINO0 1
13176 +#define AuHnJob_GEN (1 << 1)
13177 +#define AuHnJob_DIRENT (1 << 2)
13178 +#define AuHnJob_ISDIR (1 << 3)
13179 +#define AuHnJob_TRYXINO0 (1 << 4)
13180 +#define AuHnJob_MNTPNT (1 << 5)
13181 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
13182 +#define au_fset_hnjob(flags, name) \
13183 + do { (flags) |= AuHnJob_##name; } while (0)
13184 +#define au_fclr_hnjob(flags, name) \
13185 + do { (flags) &= ~AuHnJob_##name; } while (0)
13193 +struct au_hnotify_args {
13194 + struct inode *h_dir, *dir, *h_child_inode;
13196 + unsigned int flags[AuHnLast];
13197 + unsigned int h_child_nlen;
13198 + char h_child_name[];
13201 +struct hn_job_args {
13202 + unsigned int flags;
13203 + struct inode *inode, *h_inode, *dir, *h_dir;
13204 + struct dentry *dentry;
13209 +static int hn_job(struct hn_job_args *a)
13211 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
13214 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
13215 + hn_xino(a->inode, a->h_inode); /* ignore this error */
13217 + if (au_ftest_hnjob(a->flags, TRYXINO0)
13220 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
13221 + if (!a->h_inode->i_nlink)
13222 + hn_xino(a->inode, a->h_inode); /* ignore this error */
13223 + mutex_unlock(&a->h_inode->i_mutex);
13226 + /* make the generation obsolete */
13227 + if (au_ftest_hnjob(a->flags, GEN)) {
13230 + err = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
13232 + if (err && a->dentry)
13233 + hn_gen_by_name(a->dentry, isdir);
13234 + /* ignore this error */
13237 + /* make dir entries obsolete */
13238 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
13239 + struct au_vdir *vdir;
13241 + vdir = au_ivdir(a->inode);
13243 + vdir->vd_jiffy = 0;
13244 + /* IMustLock(a->inode); */
13245 + /* a->inode->i_version++; */
13248 + /* can do nothing but warn */
13249 + if (au_ftest_hnjob(a->flags, MNTPNT)
13251 + && d_mountpoint(a->dentry))
13252 + pr_warning("mount-point %.*s is removed or renamed\n",
13253 + AuDLNPair(a->dentry));
13258 +/* ---------------------------------------------------------------------- */
13260 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
13261 + struct inode *dir)
13263 + struct dentry *dentry, *d, *parent;
13264 + struct qstr *dname;
13266 + parent = d_find_alias(dir);
13271 + spin_lock(&parent->d_lock);
13272 + list_for_each_entry(d, &parent->d_subdirs, d_u.d_child) {
13273 + /* AuDbg("%.*s\n", AuDLNPair(d)); */
13274 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
13275 + dname = &d->d_name;
13276 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
13277 + goto cont_unlock;
13281 + goto cont_unlock;
13282 + if (d->d_count) {
13283 + dentry = dget_dlock(d);
13284 + spin_unlock(&d->d_lock);
13289 + spin_unlock(&d->d_lock);
13291 + spin_unlock(&parent->d_lock);
13295 + di_write_lock_child(dentry);
13300 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
13301 + aufs_bindex_t bindex, ino_t h_ino)
13303 + struct inode *inode;
13308 + err = au_xino_read(sb, bindex, h_ino, &ino);
13310 + inode = ilookup(sb, ino);
13314 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
13315 + pr_warning("wrong root branch\n");
13321 + ii_write_lock_child(inode);
13327 +static void au_hn_bh(void *_args)
13329 + struct au_hnotify_args *a = _args;
13330 + struct super_block *sb;
13331 + aufs_bindex_t bindex, bend, bfound;
13332 + unsigned char xino, try_iput;
13334 + struct inode *inode;
13336 + struct hn_job_args args;
13337 + struct dentry *dentry;
13338 + struct au_sbinfo *sbinfo;
13340 + AuDebugOn(!_args);
13341 + AuDebugOn(!a->h_dir);
13342 + AuDebugOn(!a->dir);
13343 + AuDebugOn(!a->mask);
13344 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
13345 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
13346 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
13351 + * do not lock a->dir->i_mutex here
13352 + * because of d_revalidate() may cause a deadlock.
13354 + sb = a->dir->i_sb;
13356 + sbinfo = au_sbi(sb);
13357 + AuDebugOn(!sbinfo);
13358 + si_write_lock(sb, AuLock_NOPLMW);
13360 + ii_read_lock_parent(a->dir);
13362 + bend = au_ibend(a->dir);
13363 + for (bindex = au_ibstart(a->dir); bindex <= bend; bindex++)
13364 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
13368 + ii_read_unlock(a->dir);
13369 + if (unlikely(bfound < 0))
13372 + xino = !!au_opt_test(au_mntflags(sb), XINO);
13374 + if (a->h_child_inode)
13375 + h_ino = a->h_child_inode->i_ino;
13377 + if (a->h_child_nlen
13378 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
13379 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
13380 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
13384 + inode = dentry->d_inode;
13385 + if (xino && !inode && h_ino
13386 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
13387 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
13388 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
13389 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
13393 + args.flags = a->flags[AuHn_CHILD];
13394 + args.dentry = dentry;
13395 + args.inode = inode;
13396 + args.h_inode = a->h_child_inode;
13397 + args.dir = a->dir;
13398 + args.h_dir = a->h_dir;
13399 + args.h_name = a->h_child_name;
13400 + args.h_nlen = a->h_child_nlen;
13401 + err = hn_job(&args);
13403 + if (au_di(dentry))
13404 + di_write_unlock(dentry);
13407 + if (inode && try_iput) {
13408 + ii_write_unlock(inode);
13412 + ii_write_lock_parent(a->dir);
13413 + args.flags = a->flags[AuHn_PARENT];
13414 + args.dentry = NULL;
13415 + args.inode = a->dir;
13416 + args.h_inode = a->h_dir;
13418 + args.h_dir = NULL;
13419 + args.h_name = NULL;
13421 + err = hn_job(&args);
13422 + ii_write_unlock(a->dir);
13425 + iput(a->h_child_inode);
13428 + si_write_unlock(sb);
13429 + au_nwt_done(&sbinfo->si_nowait);
13433 +/* ---------------------------------------------------------------------- */
13435 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
13436 + struct qstr *h_child_qstr, struct inode *h_child_inode)
13439 + unsigned int flags[AuHnLast], f;
13440 + unsigned char isdir, isroot, wh;
13441 + struct inode *dir;
13442 + struct au_hnotify_args *args;
13443 + char *p, *h_child_name;
13446 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
13447 + dir = igrab(hnotify->hn_aufs_inode);
13451 + isroot = (dir->i_ino == AUFS_ROOT_INO);
13453 + h_child_name = (void *)h_child_qstr->name;
13454 + len = h_child_qstr->len;
13455 + if (h_child_name) {
13456 + if (len > AUFS_WH_PFX_LEN
13457 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
13458 + h_child_name += AUFS_WH_PFX_LEN;
13459 + len -= AUFS_WH_PFX_LEN;
13465 + if (h_child_inode)
13466 + isdir = !!S_ISDIR(h_child_inode->i_mode);
13467 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
13468 + flags[AuHn_CHILD] = 0;
13470 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
13471 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
13472 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
13473 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
13474 + case FS_MOVED_FROM:
13475 + case FS_MOVED_TO:
13476 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
13477 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
13480 + AuDebugOn(!h_child_name || !h_child_inode);
13485 + * aufs never be able to get this child inode.
13486 + * revalidation should be in d_revalidate()
13487 + * by checking i_nlink, i_generation or d_unhashed().
13489 + AuDebugOn(!h_child_name);
13490 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
13491 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
13499 + h_child_inode = NULL;
13502 + /* iput() and kfree() will be called in au_hnotify() */
13503 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
13504 + if (unlikely(!args)) {
13505 + AuErr1("no memory\n");
13509 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
13510 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
13511 + args->mask = mask;
13513 + args->h_dir = igrab(h_dir);
13514 + if (h_child_inode)
13515 + h_child_inode = igrab(h_child_inode); /* can be NULL */
13516 + args->h_child_inode = h_child_inode;
13517 + args->h_child_nlen = len;
13519 + p = (void *)args;
13520 + p += sizeof(*args);
13521 + memcpy(p, h_child_name, len);
13526 + if (!dir->i_nlink)
13528 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
13529 + if (unlikely(err)) {
13530 + pr_err("wkq %d\n", err);
13531 + iput(args->h_child_inode);
13532 + iput(args->h_dir);
13541 +/* ---------------------------------------------------------------------- */
13543 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
13547 + AuDebugOn(!(udba & AuOptMask_UDBA));
13550 + if (au_hnotify_op.reset_br)
13551 + err = au_hnotify_op.reset_br(udba, br, perm);
13556 +int au_hnotify_init_br(struct au_branch *br, int perm)
13561 + if (au_hnotify_op.init_br)
13562 + err = au_hnotify_op.init_br(br, perm);
13567 +void au_hnotify_fin_br(struct au_branch *br)
13569 + if (au_hnotify_op.fin_br)
13570 + au_hnotify_op.fin_br(br);
13573 +static void au_hn_destroy_cache(void)
13575 + kmem_cache_destroy(au_cachep[AuCache_HNOTIFY]);
13576 + au_cachep[AuCache_HNOTIFY] = NULL;
13579 +int __init au_hnotify_init(void)
13584 + au_cachep[AuCache_HNOTIFY] = AuCache(au_hnotify);
13585 + if (au_cachep[AuCache_HNOTIFY]) {
13587 + if (au_hnotify_op.init)
13588 + err = au_hnotify_op.init();
13589 + if (unlikely(err))
13590 + au_hn_destroy_cache();
13596 +void au_hnotify_fin(void)
13598 + if (au_hnotify_op.fin)
13599 + au_hnotify_op.fin();
13600 + /* cf. au_cache_fin() */
13601 + if (au_cachep[AuCache_HNOTIFY])
13602 + au_hn_destroy_cache();
13604 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
13605 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
13606 +++ linux/fs/aufs/iinfo.c 2012-03-19 12:24:13.683134508 +0100
13609 + * Copyright (C) 2005-2012 Junjiro R. Okajima
13611 + * This program, aufs is free software; you can redistribute it and/or modify
13612 + * it under the terms of the GNU General Public License as published by
13613 + * the Free Software Foundation; either version 2 of the License, or
13614 + * (at your option) any later version.
13616 + * This program is distributed in the hope that it will be useful,
13617 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13618 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13619 + * GNU General Public License for more details.
13621 + * You should have received a copy of the GNU General Public License
13622 + * along with this program; if not, write to the Free Software
13623 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13627 + * inode private data
13632 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
13634 + struct inode *h_inode;
13636 + IiMustAnyLock(inode);
13638 + h_inode = au_ii(inode)->ii_hinode[0 + bindex].hi_inode;
13639 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
13643 +/* todo: hard/soft set? */
13644 +void au_hiput(struct au_hinode *hinode)
13646 + au_hn_free(hinode);
13647 + dput(hinode->hi_whdentry);
13648 + iput(hinode->hi_inode);
13651 +unsigned int au_hi_flags(struct inode *inode, int isdir)
13653 + unsigned int flags;
13654 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
13657 + if (au_opt_test(mnt_flags, XINO))
13658 + au_fset_hi(flags, XINO);
13659 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
13660 + au_fset_hi(flags, HNOTIFY);
13664 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
13665 + struct inode *h_inode, unsigned int flags)
13667 + struct au_hinode *hinode;
13668 + struct inode *hi;
13669 + struct au_iinfo *iinfo = au_ii(inode);
13671 + IiMustWriteLock(inode);
13673 + hinode = iinfo->ii_hinode + bindex;
13674 + hi = hinode->hi_inode;
13675 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
13678 + au_hiput(hinode);
13679 + hinode->hi_inode = h_inode;
13682 + struct super_block *sb = inode->i_sb;
13683 + struct au_branch *br;
13685 + AuDebugOn(inode->i_mode
13686 + && (h_inode->i_mode & S_IFMT)
13687 + != (inode->i_mode & S_IFMT));
13688 + if (bindex == iinfo->ii_bstart)
13689 + au_cpup_igen(inode, h_inode);
13690 + br = au_sbr(sb, bindex);
13691 + hinode->hi_id = br->br_id;
13692 + if (au_ftest_hi(flags, XINO)) {
13693 + err = au_xino_write(sb, bindex, h_inode->i_ino,
13695 + if (unlikely(err))
13696 + AuIOErr1("failed au_xino_write() %d\n", err);
13699 + if (au_ftest_hi(flags, HNOTIFY)
13700 + && au_br_hnotifyable(br->br_perm)) {
13701 + err = au_hn_alloc(hinode, inode);
13702 + if (unlikely(err))
13703 + AuIOErr1("au_hn_alloc() %d\n", err);
13708 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
13709 + struct dentry *h_wh)
13711 + struct au_hinode *hinode;
13713 + IiMustWriteLock(inode);
13715 + hinode = au_ii(inode)->ii_hinode + bindex;
13716 + AuDebugOn(hinode->hi_whdentry);
13717 + hinode->hi_whdentry = h_wh;
13720 +void au_update_iigen(struct inode *inode)
13722 + atomic_set(&au_ii(inode)->ii_generation, au_sigen(inode->i_sb));
13723 + /* smp_mb(); */ /* atomic_set */
13726 +/* it may be called at remount time, too */
13727 +void au_update_ibrange(struct inode *inode, int do_put_zero)
13729 + struct au_iinfo *iinfo;
13730 + aufs_bindex_t bindex, bend;
13732 + iinfo = au_ii(inode);
13736 + IiMustWriteLock(inode);
13738 + if (do_put_zero && iinfo->ii_bstart >= 0) {
13739 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
13741 + struct inode *h_i;
13743 + h_i = iinfo->ii_hinode[0 + bindex].hi_inode;
13744 + if (h_i && !h_i->i_nlink)
13745 + au_set_h_iptr(inode, bindex, NULL, 0);
13749 + iinfo->ii_bstart = -1;
13750 + iinfo->ii_bend = -1;
13751 + bend = au_sbend(inode->i_sb);
13752 + for (bindex = 0; bindex <= bend; bindex++)
13753 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
13754 + iinfo->ii_bstart = bindex;
13757 + if (iinfo->ii_bstart >= 0)
13758 + for (bindex = bend; bindex >= iinfo->ii_bstart; bindex--)
13759 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
13760 + iinfo->ii_bend = bindex;
13763 + AuDebugOn(iinfo->ii_bstart > iinfo->ii_bend);
13766 +/* ---------------------------------------------------------------------- */
13768 +void au_icntnr_init_once(void *_c)
13770 + struct au_icntnr *c = _c;
13771 + struct au_iinfo *iinfo = &c->iinfo;
13772 + static struct lock_class_key aufs_ii;
13774 + au_rw_init(&iinfo->ii_rwsem);
13775 + au_rw_class(&iinfo->ii_rwsem, &aufs_ii);
13776 + inode_init_once(&c->vfs_inode);
13779 +int au_iinfo_init(struct inode *inode)
13781 + struct au_iinfo *iinfo;
13782 + struct super_block *sb;
13785 + sb = inode->i_sb;
13786 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
13787 + nbr = au_sbend(sb) + 1;
13788 + if (unlikely(nbr <= 0))
13790 + iinfo->ii_hinode = kcalloc(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
13791 + if (iinfo->ii_hinode) {
13792 + au_ninodes_inc(sb);
13793 + for (i = 0; i < nbr; i++)
13794 + iinfo->ii_hinode[i].hi_id = -1;
13796 + atomic_set(&iinfo->ii_generation, au_sigen(sb));
13797 + /* smp_mb(); */ /* atomic_set */
13798 + iinfo->ii_bstart = -1;
13799 + iinfo->ii_bend = -1;
13800 + iinfo->ii_vdir = NULL;
13806 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr)
13809 + struct au_hinode *hip;
13811 + AuRwMustWriteLock(&iinfo->ii_rwsem);
13814 + sz = sizeof(*hip) * (iinfo->ii_bend + 1);
13816 + sz = sizeof(*hip);
13817 + hip = au_kzrealloc(iinfo->ii_hinode, sz, sizeof(*hip) * nbr, GFP_NOFS);
13819 + iinfo->ii_hinode = hip;
13826 +void au_iinfo_fin(struct inode *inode)
13828 + struct au_iinfo *iinfo;
13829 + struct au_hinode *hi;
13830 + struct super_block *sb;
13831 + aufs_bindex_t bindex, bend;
13832 + const unsigned char unlinked = !inode->i_nlink;
13834 + iinfo = au_ii(inode);
13835 + /* bad_inode case */
13839 + sb = inode->i_sb;
13840 + au_ninodes_dec(sb);
13841 + if (si_pid_test(sb))
13842 + au_xino_delete_inode(inode, unlinked);
13845 + * it is safe to hide the dependency between sbinfo and
13849 + si_noflush_read_lock(sb);
13850 + au_xino_delete_inode(inode, unlinked);
13851 + si_read_unlock(sb);
13855 + if (iinfo->ii_vdir)
13856 + au_vdir_free(iinfo->ii_vdir);
13858 + bindex = iinfo->ii_bstart;
13859 + if (bindex >= 0) {
13860 + hi = iinfo->ii_hinode + bindex;
13861 + bend = iinfo->ii_bend;
13862 + while (bindex++ <= bend) {
13863 + if (hi->hi_inode)
13868 + kfree(iinfo->ii_hinode);
13869 + iinfo->ii_hinode = NULL;
13870 + AuRwDestroy(&iinfo->ii_rwsem);
13872 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
13873 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
13874 +++ linux/fs/aufs/inode.c 2012-03-19 12:24:13.683134508 +0100
13877 + * Copyright (C) 2005-2012 Junjiro R. Okajima
13879 + * This program, aufs is free software; you can redistribute it and/or modify
13880 + * it under the terms of the GNU General Public License as published by
13881 + * the Free Software Foundation; either version 2 of the License, or
13882 + * (at your option) any later version.
13884 + * This program is distributed in the hope that it will be useful,
13885 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13886 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13887 + * GNU General Public License for more details.
13889 + * You should have received a copy of the GNU General Public License
13890 + * along with this program; if not, write to the Free Software
13891 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13895 + * inode functions
13900 +struct inode *au_igrab(struct inode *inode)
13903 + AuDebugOn(!atomic_read(&inode->i_count));
13909 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
13911 + au_cpup_attr_all(inode, /*force*/0);
13912 + au_update_iigen(inode);
13914 + inode->i_version++;
13917 +static int au_ii_refresh(struct inode *inode, int *update)
13921 + aufs_bindex_t bindex, new_bindex;
13922 + struct super_block *sb;
13923 + struct au_iinfo *iinfo;
13924 + struct au_hinode *p, *q, tmp;
13926 + IiMustWriteLock(inode);
13929 + sb = inode->i_sb;
13930 + type = inode->i_mode & S_IFMT;
13931 + iinfo = au_ii(inode);
13932 + err = au_ii_realloc(iinfo, au_sbend(sb) + 1);
13933 + if (unlikely(err))
13936 + AuDebugOn(iinfo->ii_bstart < 0);
13937 + p = iinfo->ii_hinode + iinfo->ii_bstart;
13938 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
13940 + if (!p->hi_inode)
13943 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
13944 + new_bindex = au_br_index(sb, p->hi_id);
13945 + if (new_bindex == bindex)
13948 + if (new_bindex < 0) {
13951 + p->hi_inode = NULL;
13955 + if (new_bindex < iinfo->ii_bstart)
13956 + iinfo->ii_bstart = new_bindex;
13957 + if (iinfo->ii_bend < new_bindex)
13958 + iinfo->ii_bend = new_bindex;
13959 + /* swap two lower inode, and loop again */
13960 + q = iinfo->ii_hinode + new_bindex;
13964 + if (tmp.hi_inode) {
13969 + au_update_ibrange(inode, /*do_put_zero*/0);
13970 + e = au_dy_irefresh(inode);
13971 + if (unlikely(e && !err))
13979 +int au_refresh_hinode_self(struct inode *inode)
13983 + err = au_ii_refresh(inode, &update);
13985 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
13991 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
13993 + int err, e, update;
13994 + unsigned int flags;
13996 + aufs_bindex_t bindex, bend;
13997 + unsigned char isdir;
13998 + struct au_hinode *p;
13999 + struct au_iinfo *iinfo;
14001 + err = au_ii_refresh(inode, &update);
14002 + if (unlikely(err))
14006 + iinfo = au_ii(inode);
14007 + p = iinfo->ii_hinode + iinfo->ii_bstart;
14008 + mode = (inode->i_mode & S_IFMT);
14009 + isdir = S_ISDIR(mode);
14010 + flags = au_hi_flags(inode, isdir);
14011 + bend = au_dbend(dentry);
14012 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
14013 + struct inode *h_i;
14014 + struct dentry *h_d;
14016 + h_d = au_h_dptr(dentry, bindex);
14017 + if (!h_d || !h_d->d_inode)
14020 + AuDebugOn(mode != (h_d->d_inode->i_mode & S_IFMT));
14021 + if (iinfo->ii_bstart <= bindex && bindex <= iinfo->ii_bend) {
14022 + h_i = au_h_iptr(inode, bindex);
14024 + if (h_i == h_d->d_inode)
14030 + if (bindex < iinfo->ii_bstart)
14031 + iinfo->ii_bstart = bindex;
14032 + if (iinfo->ii_bend < bindex)
14033 + iinfo->ii_bend = bindex;
14034 + au_set_h_iptr(inode, bindex, au_igrab(h_d->d_inode), flags);
14037 + au_update_ibrange(inode, /*do_put_zero*/0);
14038 + e = au_dy_irefresh(inode);
14039 + if (unlikely(e && !err))
14042 + au_refresh_hinode_attr(inode, update && isdir);
14049 +static int set_inode(struct inode *inode, struct dentry *dentry)
14052 + unsigned int flags;
14054 + aufs_bindex_t bindex, bstart, btail;
14055 + unsigned char isdir;
14056 + struct dentry *h_dentry;
14057 + struct inode *h_inode;
14058 + struct au_iinfo *iinfo;
14060 + IiMustWriteLock(inode);
14064 + bstart = au_dbstart(dentry);
14065 + h_inode = au_h_dptr(dentry, bstart)->d_inode;
14066 + mode = h_inode->i_mode;
14067 + switch (mode & S_IFMT) {
14069 + btail = au_dbtail(dentry);
14070 + inode->i_op = &aufs_iop;
14071 + inode->i_fop = &aufs_file_fop;
14072 + err = au_dy_iaop(inode, bstart, h_inode);
14073 + if (unlikely(err))
14078 + btail = au_dbtaildir(dentry);
14079 + inode->i_op = &aufs_dir_iop;
14080 + inode->i_fop = &aufs_dir_fop;
14083 + btail = au_dbtail(dentry);
14084 + inode->i_op = &aufs_symlink_iop;
14090 + btail = au_dbtail(dentry);
14091 + inode->i_op = &aufs_iop;
14092 + au_init_special_fop(inode, mode, h_inode->i_rdev);
14095 + AuIOErr("Unknown file type 0%o\n", mode);
14100 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
14101 + flags = au_hi_flags(inode, isdir);
14102 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
14103 + && au_ftest_hi(flags, HNOTIFY)
14104 + && dentry->d_name.len > AUFS_WH_PFX_LEN
14105 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
14106 + au_fclr_hi(flags, HNOTIFY);
14107 + iinfo = au_ii(inode);
14108 + iinfo->ii_bstart = bstart;
14109 + iinfo->ii_bend = btail;
14110 + for (bindex = bstart; bindex <= btail; bindex++) {
14111 + h_dentry = au_h_dptr(dentry, bindex);
14113 + au_set_h_iptr(inode, bindex,
14114 + au_igrab(h_dentry->d_inode), flags);
14116 + au_cpup_attr_all(inode, /*force*/1);
14123 + * successful returns with iinfo write_locked
14125 + * zero: success, matched
14126 + * plus: no error, but unmatched
14128 +static int reval_inode(struct inode *inode, struct dentry *dentry)
14131 + aufs_bindex_t bindex, bend;
14132 + struct inode *h_inode, *h_dinode;
14135 + * before this function, if aufs got any iinfo lock, it must be only
14136 + * one, the parent dir.
14137 + * it can happen by UDBA and the obsoleted inode number.
14140 + if (unlikely(inode->i_ino == parent_ino(dentry)))
14144 + ii_write_lock_new_child(inode);
14145 + h_dinode = au_h_dptr(dentry, au_dbstart(dentry))->d_inode;
14146 + bend = au_ibend(inode);
14147 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
14148 + h_inode = au_h_iptr(inode, bindex);
14149 + if (h_inode && h_inode == h_dinode) {
14151 + if (au_iigen_test(inode, au_digen(dentry)))
14152 + err = au_refresh_hinode(inode, dentry);
14157 + if (unlikely(err))
14158 + ii_write_unlock(inode);
14163 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
14164 + unsigned int d_type, ino_t *ino)
14167 + struct mutex *mtx;
14169 + /* prevent hardlinked inode number from race condition */
14171 + if (d_type != DT_DIR) {
14172 + mtx = &au_sbr(sb, bindex)->br_xino.xi_nondir_mtx;
14175 + err = au_xino_read(sb, bindex, h_ino, ino);
14176 + if (unlikely(err))
14181 + *ino = au_xino_new_ino(sb);
14182 + if (unlikely(!*ino))
14184 + err = au_xino_write(sb, bindex, h_ino, *ino);
14185 + if (unlikely(err))
14191 + mutex_unlock(mtx);
14195 +/* successful returns with iinfo write_locked */
14196 +/* todo: return with unlocked? */
14197 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
14199 + struct inode *inode, *h_inode;
14200 + struct dentry *h_dentry;
14201 + struct super_block *sb;
14202 + struct mutex *mtx;
14203 + ino_t h_ino, ino;
14205 + aufs_bindex_t bstart;
14207 + sb = dentry->d_sb;
14208 + bstart = au_dbstart(dentry);
14209 + h_dentry = au_h_dptr(dentry, bstart);
14210 + h_inode = h_dentry->d_inode;
14211 + h_ino = h_inode->i_ino;
14214 + * stop 'race'-ing between hardlinks under different
14218 + if (!S_ISDIR(h_inode->i_mode))
14219 + mtx = &au_sbr(sb, bstart)->br_xino.xi_nondir_mtx;
14224 + err = au_xino_read(sb, bstart, h_ino, &ino);
14225 + inode = ERR_PTR(err);
14226 + if (unlikely(err))
14230 + ino = au_xino_new_ino(sb);
14231 + if (unlikely(!ino)) {
14232 + inode = ERR_PTR(-EIO);
14237 + AuDbg("i%lu\n", (unsigned long)ino);
14238 + inode = au_iget_locked(sb, ino);
14239 + err = PTR_ERR(inode);
14240 + if (IS_ERR(inode))
14243 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
14244 + if (inode->i_state & I_NEW) {
14245 + ii_write_lock_new_child(inode);
14246 + err = set_inode(inode, dentry);
14248 + unlock_new_inode(inode);
14249 + goto out; /* success */
14253 + * iget_failed() calls iput(), but we need to call
14254 + * ii_write_unlock() after iget_failed(). so dirty hack for
14257 + atomic_inc(&inode->i_count);
14258 + iget_failed(inode);
14259 + ii_write_unlock(inode);
14260 + au_xino_write(sb, bstart, h_ino, /*ino*/0);
14261 + /* ignore this error */
14263 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
14265 + * horrible race condition between lookup, readdir and copyup
14266 + * (or something).
14269 + mutex_unlock(mtx);
14270 + err = reval_inode(inode, dentry);
14271 + if (unlikely(err < 0)) {
14278 + goto out; /* success */
14283 + if (unlikely(au_test_fs_unique_ino(h_dentry->d_inode)))
14284 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
14285 + " b%d, %s, %.*s, hi%lu, i%lu.\n",
14286 + bstart, au_sbtype(h_dentry->d_sb), AuDLNPair(dentry),
14287 + (unsigned long)h_ino, (unsigned long)ino);
14289 + err = au_xino_write(sb, bstart, h_ino, /*ino*/0);
14293 + mutex_unlock(mtx);
14299 + inode = ERR_PTR(err);
14302 + mutex_unlock(mtx);
14306 +/* ---------------------------------------------------------------------- */
14308 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
14309 + struct inode *inode)
14313 + err = au_br_rdonly(au_sbr(sb, bindex));
14315 + /* pseudo-link after flushed may happen out of bounds */
14318 + && au_ibstart(inode) <= bindex
14319 + && bindex <= au_ibend(inode)) {
14321 + * permission check is unnecessary since vfsub routine
14322 + * will be called later
14324 + struct inode *hi = au_h_iptr(inode, bindex);
14326 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
14332 +int au_test_h_perm(struct inode *h_inode, int mask)
14334 + if (!current_fsuid())
14336 + return inode_permission(h_inode, mask);
14339 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
14341 + if (au_test_nfs(h_inode->i_sb)
14342 + && (mask & MAY_WRITE)
14343 + && S_ISDIR(h_inode->i_mode))
14344 + mask |= MAY_READ; /* force permission check */
14345 + return au_test_h_perm(h_inode, mask);
14347 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
14348 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
14349 +++ linux/fs/aufs/inode.h 2012-03-19 12:24:13.683134508 +0100
14352 + * Copyright (C) 2005-2012 Junjiro R. Okajima
14354 + * This program, aufs is free software; you can redistribute it and/or modify
14355 + * it under the terms of the GNU General Public License as published by
14356 + * the Free Software Foundation; either version 2 of the License, or
14357 + * (at your option) any later version.
14359 + * This program is distributed in the hope that it will be useful,
14360 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14361 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14362 + * GNU General Public License for more details.
14364 + * You should have received a copy of the GNU General Public License
14365 + * along with this program; if not, write to the Free Software
14366 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14370 + * inode operations
14373 +#ifndef __AUFS_INODE_H__
14374 +#define __AUFS_INODE_H__
14378 +#include <linux/fsnotify.h>
14379 +#include "rwsem.h"
14383 +struct au_hnotify {
14384 +#ifdef CONFIG_AUFS_HNOTIFY
14385 +#ifdef CONFIG_AUFS_HFSNOTIFY
14386 + /* never use fsnotify_add_vfsmount_mark() */
14387 + struct fsnotify_mark hn_mark;
14389 + struct inode *hn_aufs_inode; /* no get/put */
14391 +} ____cacheline_aligned_in_smp;
14393 +struct au_hinode {
14394 + struct inode *hi_inode;
14395 + aufs_bindex_t hi_id;
14396 +#ifdef CONFIG_AUFS_HNOTIFY
14397 + struct au_hnotify *hi_notify;
14400 + /* reference to the copied-up whiteout with get/put */
14401 + struct dentry *hi_whdentry;
14406 + atomic_t ii_generation;
14407 + struct super_block *ii_hsb1; /* no get/put */
14409 + struct au_rwsem ii_rwsem;
14410 + aufs_bindex_t ii_bstart, ii_bend;
14412 + struct au_hinode *ii_hinode;
14413 + struct au_vdir *ii_vdir;
14416 +struct au_icntnr {
14417 + struct au_iinfo iinfo;
14418 + struct inode vfs_inode;
14419 +} ____cacheline_aligned_in_smp;
14421 +/* au_pin flags */
14422 +#define AuPin_DI_LOCKED 1
14423 +#define AuPin_MNT_WRITE (1 << 1)
14424 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
14425 +#define au_fset_pin(flags, name) \
14426 + do { (flags) |= AuPin_##name; } while (0)
14427 +#define au_fclr_pin(flags, name) \
14428 + do { (flags) &= ~AuPin_##name; } while (0)
14432 + struct dentry *dentry;
14433 + unsigned int udba;
14434 + unsigned char lsc_di, lsc_hi, flags;
14435 + aufs_bindex_t bindex;
14438 + struct dentry *parent;
14439 + struct au_hinode *hdir;
14440 + struct vfsmount *h_mnt;
14443 +/* ---------------------------------------------------------------------- */
14445 +static inline struct au_iinfo *au_ii(struct inode *inode)
14447 + struct au_iinfo *iinfo;
14449 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
14450 + if (iinfo->ii_hinode)
14452 + return NULL; /* debugging bad_inode case */
14455 +/* ---------------------------------------------------------------------- */
14458 +struct inode *au_igrab(struct inode *inode);
14459 +int au_refresh_hinode_self(struct inode *inode);
14460 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
14461 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
14462 + unsigned int d_type, ino_t *ino);
14463 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
14464 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
14465 + struct inode *inode);
14466 +int au_test_h_perm(struct inode *h_inode, int mask);
14467 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
14469 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
14470 + ino_t h_ino, unsigned int d_type, ino_t *ino)
14472 +#ifdef CONFIG_AUFS_SHWH
14473 + return au_ino(sb, bindex, h_ino, d_type, ino);
14480 +extern struct inode_operations aufs_iop, aufs_symlink_iop, aufs_dir_iop;
14482 +/* au_wr_dir flags */
14483 +#define AuWrDir_ADD_ENTRY 1
14484 +#define AuWrDir_ISDIR (1 << 1)
14485 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
14486 +#define au_fset_wrdir(flags, name) \
14487 + do { (flags) |= AuWrDir_##name; } while (0)
14488 +#define au_fclr_wrdir(flags, name) \
14489 + do { (flags) &= ~AuWrDir_##name; } while (0)
14491 +struct au_wr_dir_args {
14492 + aufs_bindex_t force_btgt;
14493 + unsigned char flags;
14495 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
14496 + struct au_wr_dir_args *args);
14498 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
14499 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
14500 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
14501 + unsigned int udba, unsigned char flags);
14502 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
14503 + unsigned int udba, unsigned char flags) __must_check;
14504 +int au_do_pin(struct au_pin *pin) __must_check;
14505 +void au_unpin(struct au_pin *pin);
14508 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
14509 + struct dentry *h_parent, int isdir);
14510 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
14512 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
14513 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
14514 + struct nameidata *nd);
14515 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
14516 + struct dentry *dentry);
14517 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
14520 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
14521 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
14522 + struct dentry *h_parent, int isdir);
14523 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
14524 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
14527 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
14528 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
14529 + struct inode *dir, struct dentry *dentry);
14532 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
14533 +void au_hiput(struct au_hinode *hinode);
14534 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
14535 + struct dentry *h_wh);
14536 +unsigned int au_hi_flags(struct inode *inode, int isdir);
14538 +/* hinode flags */
14539 +#define AuHi_XINO 1
14540 +#define AuHi_HNOTIFY (1 << 1)
14541 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
14542 +#define au_fset_hi(flags, name) \
14543 + do { (flags) |= AuHi_##name; } while (0)
14544 +#define au_fclr_hi(flags, name) \
14545 + do { (flags) &= ~AuHi_##name; } while (0)
14547 +#ifndef CONFIG_AUFS_HNOTIFY
14548 +#undef AuHi_HNOTIFY
14549 +#define AuHi_HNOTIFY 0
14552 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
14553 + struct inode *h_inode, unsigned int flags);
14555 +void au_update_iigen(struct inode *inode);
14556 +void au_update_ibrange(struct inode *inode, int do_put_zero);
14558 +void au_icntnr_init_once(void *_c);
14559 +int au_iinfo_init(struct inode *inode);
14560 +void au_iinfo_fin(struct inode *inode);
14561 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr);
14563 +#ifdef CONFIG_PROC_FS
14565 +int au_plink_maint(struct super_block *sb, int flags);
14566 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
14567 +int au_plink_maint_enter(struct super_block *sb);
14568 +#ifdef CONFIG_AUFS_DEBUG
14569 +void au_plink_list(struct super_block *sb);
14571 +AuStubVoid(au_plink_list, struct super_block *sb)
14573 +int au_plink_test(struct inode *inode);
14574 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
14575 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
14576 + struct dentry *h_dentry);
14577 +void au_plink_put(struct super_block *sb, int verbose);
14578 +void au_plink_clean(struct super_block *sb, int verbose);
14579 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
14581 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
14582 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
14583 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
14584 +AuStubVoid(au_plink_list, struct super_block *sb);
14585 +AuStubInt0(au_plink_test, struct inode *inode);
14586 +AuStub(struct dentry *, au_plink_lkup, return NULL,
14587 + struct inode *inode, aufs_bindex_t bindex);
14588 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
14589 + struct dentry *h_dentry);
14590 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
14591 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
14592 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
14593 +#endif /* CONFIG_PROC_FS */
14595 +/* ---------------------------------------------------------------------- */
14597 +/* lock subclass for iinfo */
14599 + AuLsc_II_CHILD, /* child first */
14600 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
14601 + AuLsc_II_CHILD3, /* copyup dirs */
14602 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
14603 + AuLsc_II_PARENT2,
14604 + AuLsc_II_PARENT3, /* copyup dirs */
14605 + AuLsc_II_NEW_CHILD
14609 + * ii_read_lock_child, ii_write_lock_child,
14610 + * ii_read_lock_child2, ii_write_lock_child2,
14611 + * ii_read_lock_child3, ii_write_lock_child3,
14612 + * ii_read_lock_parent, ii_write_lock_parent,
14613 + * ii_read_lock_parent2, ii_write_lock_parent2,
14614 + * ii_read_lock_parent3, ii_write_lock_parent3,
14615 + * ii_read_lock_new_child, ii_write_lock_new_child,
14617 +#define AuReadLockFunc(name, lsc) \
14618 +static inline void ii_read_lock_##name(struct inode *i) \
14620 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
14623 +#define AuWriteLockFunc(name, lsc) \
14624 +static inline void ii_write_lock_##name(struct inode *i) \
14626 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
14629 +#define AuRWLockFuncs(name, lsc) \
14630 + AuReadLockFunc(name, lsc) \
14631 + AuWriteLockFunc(name, lsc)
14633 +AuRWLockFuncs(child, CHILD);
14634 +AuRWLockFuncs(child2, CHILD2);
14635 +AuRWLockFuncs(child3, CHILD3);
14636 +AuRWLockFuncs(parent, PARENT);
14637 +AuRWLockFuncs(parent2, PARENT2);
14638 +AuRWLockFuncs(parent3, PARENT3);
14639 +AuRWLockFuncs(new_child, NEW_CHILD);
14641 +#undef AuReadLockFunc
14642 +#undef AuWriteLockFunc
14643 +#undef AuRWLockFuncs
14646 + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock
14648 +AuSimpleUnlockRwsemFuncs(ii, struct inode *i, &au_ii(i)->ii_rwsem);
14650 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
14651 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
14652 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
14654 +/* ---------------------------------------------------------------------- */
14656 +static inline void au_icntnr_init(struct au_icntnr *c)
14658 +#ifdef CONFIG_AUFS_DEBUG
14659 + c->vfs_inode.i_mode = 0;
14663 +static inline unsigned int au_iigen(struct inode *inode)
14665 + return atomic_read(&au_ii(inode)->ii_generation);
14668 +/* tiny test for inode number */
14669 +/* tmpfs generation is too rough */
14670 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
14672 + struct au_iinfo *iinfo;
14674 + iinfo = au_ii(inode);
14675 + AuRwMustAnyLock(&iinfo->ii_rwsem);
14676 + return !(iinfo->ii_hsb1 == h_inode->i_sb
14677 + && iinfo->ii_higen == h_inode->i_generation);
14680 +static inline void au_iigen_dec(struct inode *inode)
14682 + atomic_dec(&au_ii(inode)->ii_generation);
14685 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
14690 + if (unlikely(inode && au_iigen(inode) != sigen))
14696 +/* ---------------------------------------------------------------------- */
14698 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
14699 + aufs_bindex_t bindex)
14701 + IiMustAnyLock(inode);
14702 + return au_ii(inode)->ii_hinode[0 + bindex].hi_id;
14705 +static inline aufs_bindex_t au_ibstart(struct inode *inode)
14707 + IiMustAnyLock(inode);
14708 + return au_ii(inode)->ii_bstart;
14711 +static inline aufs_bindex_t au_ibend(struct inode *inode)
14713 + IiMustAnyLock(inode);
14714 + return au_ii(inode)->ii_bend;
14717 +static inline struct au_vdir *au_ivdir(struct inode *inode)
14719 + IiMustAnyLock(inode);
14720 + return au_ii(inode)->ii_vdir;
14723 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
14725 + IiMustAnyLock(inode);
14726 + return au_ii(inode)->ii_hinode[0 + bindex].hi_whdentry;
14729 +static inline void au_set_ibstart(struct inode *inode, aufs_bindex_t bindex)
14731 + IiMustWriteLock(inode);
14732 + au_ii(inode)->ii_bstart = bindex;
14735 +static inline void au_set_ibend(struct inode *inode, aufs_bindex_t bindex)
14737 + IiMustWriteLock(inode);
14738 + au_ii(inode)->ii_bend = bindex;
14741 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
14743 + IiMustWriteLock(inode);
14744 + au_ii(inode)->ii_vdir = vdir;
14747 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
14749 + IiMustAnyLock(inode);
14750 + return au_ii(inode)->ii_hinode + bindex;
14753 +/* ---------------------------------------------------------------------- */
14755 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
14758 + return pin->parent;
14762 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
14764 + if (pin && pin->hdir)
14765 + return pin->hdir->hi_inode;
14769 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
14772 + return pin->hdir;
14776 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
14779 + pin->dentry = dentry;
14782 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
14783 + unsigned char lflag)
14787 + au_fset_pin(pin->flags, DI_LOCKED);
14789 + au_fclr_pin(pin->flags, DI_LOCKED);
14793 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
14796 + dput(pin->parent);
14797 + pin->parent = dget(parent);
14801 +/* ---------------------------------------------------------------------- */
14804 +#ifdef CONFIG_AUFS_HNOTIFY
14805 +struct au_hnotify_op {
14806 + void (*ctl)(struct au_hinode *hinode, int do_set);
14807 + int (*alloc)(struct au_hinode *hinode);
14810 + * if it returns true, the the caller should free hinode->hi_notify,
14811 + * otherwise ->free() frees it.
14813 + int (*free)(struct au_hinode *hinode,
14814 + struct au_hnotify *hn) __must_check;
14816 + void (*fin)(void);
14817 + int (*init)(void);
14819 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
14820 + void (*fin_br)(struct au_branch *br);
14821 + int (*init_br)(struct au_branch *br, int perm);
14825 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
14826 +void au_hn_free(struct au_hinode *hinode);
14827 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
14828 +void au_hn_reset(struct inode *inode, unsigned int flags);
14829 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
14830 + struct qstr *h_child_qstr, struct inode *h_child_inode);
14831 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
14832 +int au_hnotify_init_br(struct au_branch *br, int perm);
14833 +void au_hnotify_fin_br(struct au_branch *br);
14834 +int __init au_hnotify_init(void);
14835 +void au_hnotify_fin(void);
14838 +extern const struct au_hnotify_op au_hnotify_op;
14841 +void au_hn_init(struct au_hinode *hinode)
14843 + hinode->hi_notify = NULL;
14846 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
14848 + return hinode->hi_notify;
14853 +int au_hn_alloc(struct au_hinode *hinode __maybe_unused,
14854 + struct inode *inode __maybe_unused)
14856 + return -EOPNOTSUPP;
14859 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
14864 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
14865 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
14866 + int do_set __maybe_unused)
14867 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
14868 + unsigned int flags __maybe_unused)
14869 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
14870 + struct au_branch *br __maybe_unused,
14871 + int perm __maybe_unused)
14872 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
14873 + int perm __maybe_unused)
14874 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
14875 +AuStubInt0(__init au_hnotify_init, void)
14876 +AuStubVoid(au_hnotify_fin, void)
14877 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
14878 +#endif /* CONFIG_AUFS_HNOTIFY */
14880 +static inline void au_hn_suspend(struct au_hinode *hdir)
14882 + au_hn_ctl(hdir, /*do_set*/0);
14885 +static inline void au_hn_resume(struct au_hinode *hdir)
14887 + au_hn_ctl(hdir, /*do_set*/1);
14890 +static inline void au_hn_imtx_lock(struct au_hinode *hdir)
14892 + mutex_lock(&hdir->hi_inode->i_mutex);
14893 + au_hn_suspend(hdir);
14896 +static inline void au_hn_imtx_lock_nested(struct au_hinode *hdir,
14897 + unsigned int sc __maybe_unused)
14899 + mutex_lock_nested(&hdir->hi_inode->i_mutex, sc);
14900 + au_hn_suspend(hdir);
14903 +static inline void au_hn_imtx_unlock(struct au_hinode *hdir)
14905 + au_hn_resume(hdir);
14906 + mutex_unlock(&hdir->hi_inode->i_mutex);
14909 +#endif /* __KERNEL__ */
14910 +#endif /* __AUFS_INODE_H__ */
14911 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
14912 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
14913 +++ linux/fs/aufs/ioctl.c 2012-03-19 12:24:13.683134508 +0100
14916 + * Copyright (C) 2005-2012 Junjiro R. Okajima
14918 + * This program, aufs is free software; you can redistribute it and/or modify
14919 + * it under the terms of the GNU General Public License as published by
14920 + * the Free Software Foundation; either version 2 of the License, or
14921 + * (at your option) any later version.
14923 + * This program is distributed in the hope that it will be useful,
14924 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14925 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14926 + * GNU General Public License for more details.
14928 + * You should have received a copy of the GNU General Public License
14929 + * along with this program; if not, write to the Free Software
14930 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14935 + * plink-management and readdir in userspace.
14936 + * assist the pathconf(3) wrapper library.
14941 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
14944 + aufs_bindex_t wbi, bindex, bend;
14945 + struct file *h_file;
14946 + struct super_block *sb;
14947 + struct dentry *root;
14948 + struct au_branch *br;
14949 + struct aufs_wbr_fd wbrfd = {
14950 + .oflags = au_dir_roflags,
14953 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
14954 + | O_NOATIME | O_CLOEXEC;
14956 + AuDebugOn(wbrfd.oflags & ~valid);
14959 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
14960 + if (unlikely(err)) {
14966 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
14967 + wbrfd.oflags |= au_dir_roflags;
14968 + AuDbg("0%o\n", wbrfd.oflags);
14969 + if (unlikely(wbrfd.oflags & ~valid))
14973 + fd = get_unused_fd();
14975 + if (unlikely(fd < 0))
14978 + h_file = ERR_PTR(-EINVAL);
14981 + sb = path->dentry->d_sb;
14982 + root = sb->s_root;
14983 + aufs_read_lock(root, AuLock_IR);
14984 + bend = au_sbend(sb);
14985 + if (wbrfd.brid >= 0) {
14986 + wbi = au_br_index(sb, wbrfd.brid);
14987 + if (unlikely(wbi < 0 || wbi > bend))
14991 + h_file = ERR_PTR(-ENOENT);
14992 + br = au_sbr(sb, wbi);
14993 + if (!au_br_writable(br->br_perm)) {
14997 + bindex = wbi + 1;
14999 + for (; bindex <= bend; bindex++) {
15000 + br = au_sbr(sb, bindex);
15001 + if (au_br_writable(br->br_perm)) {
15003 + br = au_sbr(sb, wbi);
15008 + AuDbg("wbi %d\n", wbi);
15010 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL);
15013 + aufs_read_unlock(root, AuLock_IR);
15014 + err = PTR_ERR(h_file);
15015 + if (IS_ERR(h_file))
15018 + atomic_dec(&br->br_count); /* cf. au_h_open() */
15019 + fd_install(fd, h_file);
15021 + goto out; /* success */
15024 + put_unused_fd(fd);
15030 +/* ---------------------------------------------------------------------- */
15032 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
15037 + case AUFS_CTL_RDU:
15038 + case AUFS_CTL_RDU_INO:
15039 + err = au_rdu_ioctl(file, cmd, arg);
15042 + case AUFS_CTL_WBR_FD:
15043 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
15046 + case AUFS_CTL_IBUSY:
15047 + err = au_ibusy_ioctl(file, arg);
15051 + /* do not call the lower */
15052 + AuDbg("0x%x\n", cmd);
15060 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
15065 + case AUFS_CTL_WBR_FD:
15066 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
15070 + /* do not call the lower */
15071 + AuDbg("0x%x\n", cmd);
15079 +#ifdef CONFIG_COMPAT
15080 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15081 + unsigned long arg)
15086 + case AUFS_CTL_RDU:
15087 + case AUFS_CTL_RDU_INO:
15088 + err = au_rdu_compat_ioctl(file, cmd, arg);
15091 + case AUFS_CTL_IBUSY:
15092 + err = au_ibusy_compat_ioctl(file, arg);
15096 + err = aufs_ioctl_dir(file, cmd, arg);
15103 +#if 0 /* unused yet */
15104 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15105 + unsigned long arg)
15107 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
15111 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
15112 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
15113 +++ linux/fs/aufs/i_op_add.c 2012-03-19 12:24:13.683134508 +0100
15116 + * Copyright (C) 2005-2012 Junjiro R. Okajima
15118 + * This program, aufs is free software; you can redistribute it and/or modify
15119 + * it under the terms of the GNU General Public License as published by
15120 + * the Free Software Foundation; either version 2 of the License, or
15121 + * (at your option) any later version.
15123 + * This program is distributed in the hope that it will be useful,
15124 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15125 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15126 + * GNU General Public License for more details.
15128 + * You should have received a copy of the GNU General Public License
15129 + * along with this program; if not, write to the Free Software
15130 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15134 + * inode operations (add entry)
15140 + * final procedure of adding a new entry, except link(2).
15141 + * remove whiteout, instantiate, copyup the parent dir's times and size
15142 + * and update version.
15143 + * if it failed, re-create the removed whiteout.
15145 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
15146 + struct dentry *wh_dentry, struct dentry *dentry)
15149 + aufs_bindex_t bwh;
15150 + struct path h_path;
15151 + struct inode *inode, *h_dir;
15152 + struct dentry *wh;
15156 + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
15157 + IMustLock(h_dir);
15158 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
15159 + bwh = au_dbwh(dentry);
15160 + h_path.dentry = wh_dentry;
15161 + h_path.mnt = au_sbr_mnt(dir->i_sb, bindex);
15162 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
15164 + if (unlikely(err))
15168 + inode = au_new_inode(dentry, /*must_new*/1);
15169 + if (!IS_ERR(inode)) {
15170 + d_instantiate(dentry, inode);
15171 + dir = dentry->d_parent->d_inode; /* dir inode is locked */
15173 + if (au_ibstart(dir) == au_dbstart(dentry))
15174 + au_cpup_attr_timesizes(dir);
15175 + dir->i_version++;
15176 + return 0; /* success */
15179 + err = PTR_ERR(inode);
15184 + /* dir inode is locked */
15185 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
15186 + rerr = PTR_ERR(wh);
15187 + if (IS_ERR(wh)) {
15188 + AuIOErr("%.*s reverting whiteout failed(%d, %d)\n",
15189 + AuDLNPair(dentry), err, rerr);
15198 +static int au_d_may_add(struct dentry *dentry)
15203 + if (unlikely(d_unhashed(dentry)))
15205 + if (unlikely(dentry->d_inode))
15211 + * simple tests for the adding inode operations.
15212 + * following the checks in vfs, plus the parent-child relationship.
15214 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
15215 + struct dentry *h_parent, int isdir)
15219 + struct dentry *h_dentry;
15220 + struct inode *h_inode;
15222 + err = -ENAMETOOLONG;
15223 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
15226 + h_dentry = au_h_dptr(dentry, bindex);
15227 + h_inode = h_dentry->d_inode;
15228 + if (!dentry->d_inode) {
15230 + if (unlikely(h_inode))
15233 + /* rename(2) case */
15235 + if (unlikely(!h_inode || !h_inode->i_nlink))
15238 + h_mode = h_inode->i_mode;
15241 + if (unlikely(S_ISDIR(h_mode)))
15243 + } else if (unlikely(!S_ISDIR(h_mode))) {
15250 + /* expected parent dir is locked */
15251 + if (unlikely(h_parent != h_dentry->d_parent))
15260 + * initial procedure of adding a new entry.
15261 + * prepare writable branch and the parent dir, lock it,
15262 + * and lookup whiteout for the new entry.
15264 +static struct dentry*
15265 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
15266 + struct dentry *src_dentry, struct au_pin *pin,
15267 + struct au_wr_dir_args *wr_dir_args)
15269 + struct dentry *wh_dentry, *h_parent;
15270 + struct super_block *sb;
15271 + struct au_branch *br;
15273 + unsigned int udba;
15274 + aufs_bindex_t bcpup;
15276 + AuDbg("%.*s\n", AuDLNPair(dentry));
15278 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
15280 + wh_dentry = ERR_PTR(err);
15281 + if (unlikely(err < 0))
15284 + sb = dentry->d_sb;
15285 + udba = au_opt_udba(sb);
15286 + err = au_pin(pin, dentry, bcpup, udba,
15287 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
15288 + wh_dentry = ERR_PTR(err);
15289 + if (unlikely(err))
15292 + h_parent = au_pinned_h_parent(pin);
15293 + if (udba != AuOpt_UDBA_NONE
15294 + && au_dbstart(dentry) == bcpup)
15295 + err = au_may_add(dentry, bcpup, h_parent,
15296 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
15297 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
15298 + err = -ENAMETOOLONG;
15299 + wh_dentry = ERR_PTR(err);
15300 + if (unlikely(err))
15303 + br = au_sbr(sb, bcpup);
15305 + struct path tmp = {
15306 + .dentry = h_parent,
15307 + .mnt = br->br_mnt
15309 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
15312 + wh_dentry = NULL;
15313 + if (bcpup != au_dbwh(dentry))
15314 + goto out; /* success */
15316 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
15319 + if (IS_ERR(wh_dentry))
15322 + return wh_dentry;
15325 +/* ---------------------------------------------------------------------- */
15327 +enum { Mknod, Symlink, Creat };
15328 +struct simple_arg {
15333 + struct nameidata *nd;
15336 + const char *symname;
15345 +static int add_simple(struct inode *dir, struct dentry *dentry,
15346 + struct simple_arg *arg)
15349 + aufs_bindex_t bstart;
15350 + unsigned char created;
15351 + struct au_dtime dt;
15352 + struct au_pin pin;
15353 + struct path h_path;
15354 + struct dentry *wh_dentry, *parent;
15355 + struct inode *h_dir;
15356 + struct au_wr_dir_args wr_dir_args = {
15357 + .force_btgt = -1,
15358 + .flags = AuWrDir_ADD_ENTRY
15361 + AuDbg("%.*s\n", AuDLNPair(dentry));
15364 + parent = dentry->d_parent; /* dir inode is locked */
15365 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
15366 + if (unlikely(err))
15368 + err = au_d_may_add(dentry);
15369 + if (unlikely(err))
15371 + di_write_lock_parent(parent);
15372 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, /*src_dentry*/NULL, &pin,
15374 + err = PTR_ERR(wh_dentry);
15375 + if (IS_ERR(wh_dentry))
15378 + bstart = au_dbstart(dentry);
15379 + h_path.dentry = au_h_dptr(dentry, bstart);
15380 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
15381 + h_dir = au_pinned_h_dir(&pin);
15382 + switch (arg->type) {
15384 + err = vfsub_create(h_dir, &h_path, arg->u.c.mode);
15387 + err = vfsub_symlink(h_dir, &h_path, arg->u.s.symname);
15390 + err = vfsub_mknod(h_dir, &h_path, arg->u.m.mode, arg->u.m.dev);
15397 + err = epilog(dir, bstart, wh_dentry, dentry);
15400 + if (unlikely(created && err && h_path.dentry->d_inode)) {
15402 + rerr = vfsub_unlink(h_dir, &h_path, /*force*/0);
15404 + AuIOErr("%.*s revert failure(%d, %d)\n",
15405 + AuDLNPair(dentry), err, rerr);
15408 + au_dtime_revert(&dt);
15415 + di_write_unlock(parent);
15417 + if (unlikely(err)) {
15418 + au_update_dbstart(dentry);
15421 + aufs_read_unlock(dentry, AuLock_DW);
15426 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
15429 + struct simple_arg arg = {
15436 + return add_simple(dir, dentry, &arg);
15439 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
15441 + struct simple_arg arg = {
15443 + .u.s.symname = symname
15445 + return add_simple(dir, dentry, &arg);
15448 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
15449 + struct nameidata *nd)
15451 + struct simple_arg arg = {
15458 + return add_simple(dir, dentry, &arg);
15461 +/* ---------------------------------------------------------------------- */
15463 +struct au_link_args {
15464 + aufs_bindex_t bdst, bsrc;
15465 + struct au_pin pin;
15466 + struct path h_path;
15467 + struct dentry *src_parent, *parent;
15470 +static int au_cpup_before_link(struct dentry *src_dentry,
15471 + struct au_link_args *a)
15474 + struct dentry *h_src_dentry;
15475 + struct mutex *h_mtx;
15476 + struct file *h_file;
15478 + di_read_lock_parent(a->src_parent, AuLock_IR);
15479 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
15480 + if (unlikely(err))
15483 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
15484 + h_mtx = &h_src_dentry->d_inode->i_mutex;
15485 + err = au_pin(&a->pin, src_dentry, a->bdst,
15486 + au_opt_udba(src_dentry->d_sb),
15487 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
15488 + if (unlikely(err))
15490 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
15491 + h_file = au_h_open_pre(src_dentry, a->bsrc);
15492 + if (IS_ERR(h_file)) {
15493 + err = PTR_ERR(h_file);
15496 + err = au_sio_cpup_simple(src_dentry, a->bdst, -1,
15497 + AuCpup_DTIME /* | AuCpup_KEEPLINO */);
15498 + mutex_unlock(h_mtx);
15499 + au_h_open_post(src_dentry, a->bsrc, h_file);
15500 + au_unpin(&a->pin);
15503 + di_read_unlock(a->src_parent, AuLock_IR);
15507 +static int au_cpup_or_link(struct dentry *src_dentry, struct au_link_args *a)
15510 + unsigned char plink;
15511 + struct inode *h_inode, *inode;
15512 + struct dentry *h_src_dentry;
15513 + struct super_block *sb;
15514 + struct file *h_file;
15518 + sb = src_dentry->d_sb;
15519 + inode = src_dentry->d_inode;
15520 + if (au_ibstart(inode) <= a->bdst)
15521 + h_inode = au_h_iptr(inode, a->bdst);
15522 + if (!h_inode || !h_inode->i_nlink) {
15523 + /* copyup src_dentry as the name of dentry. */
15524 + au_set_dbstart(src_dentry, a->bdst);
15525 + au_set_h_dptr(src_dentry, a->bdst, dget(a->h_path.dentry));
15526 + h_inode = au_h_dptr(src_dentry, a->bsrc)->d_inode;
15527 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
15528 + h_file = au_h_open_pre(src_dentry, a->bsrc);
15529 + if (IS_ERR(h_file)) {
15530 + err = PTR_ERR(h_file);
15533 + err = au_sio_cpup_single(src_dentry, a->bdst, a->bsrc,
15534 + -1, AuCpup_KEEPLINO,
15536 + mutex_unlock(&h_inode->i_mutex);
15537 + au_h_open_post(src_dentry, a->bsrc, h_file);
15538 + au_set_h_dptr(src_dentry, a->bdst, NULL);
15539 + au_set_dbstart(src_dentry, a->bsrc);
15541 + /* the inode of src_dentry already exists on a.bdst branch */
15542 + h_src_dentry = d_find_alias(h_inode);
15543 + if (!h_src_dentry && au_plink_test(inode)) {
15545 + h_src_dentry = au_plink_lkup(inode, a->bdst);
15546 + err = PTR_ERR(h_src_dentry);
15547 + if (IS_ERR(h_src_dentry))
15550 + if (unlikely(!h_src_dentry->d_inode)) {
15551 + dput(h_src_dentry);
15552 + h_src_dentry = NULL;
15556 + if (h_src_dentry) {
15557 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
15559 + dput(h_src_dentry);
15561 + AuIOErr("no dentry found for hi%lu on b%d\n",
15562 + h_inode->i_ino, a->bdst);
15567 + if (!err && !plink)
15568 + au_plink_append(inode, a->bdst, a->h_path.dentry);
15575 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
15576 + struct dentry *dentry)
15579 + struct au_dtime dt;
15580 + struct au_link_args *a;
15581 + struct dentry *wh_dentry, *h_src_dentry;
15582 + struct inode *inode;
15583 + struct super_block *sb;
15584 + struct au_wr_dir_args wr_dir_args = {
15585 + /* .force_btgt = -1, */
15586 + .flags = AuWrDir_ADD_ENTRY
15590 + inode = src_dentry->d_inode;
15591 + IMustLock(inode);
15594 + a = kzalloc(sizeof(*a), GFP_NOFS);
15595 + if (unlikely(!a))
15598 + a->parent = dentry->d_parent; /* dir inode is locked */
15599 + err = aufs_read_and_write_lock2(dentry, src_dentry,
15600 + AuLock_NOPLM | AuLock_GEN);
15601 + if (unlikely(err))
15603 + err = au_d_hashed_positive(src_dentry);
15604 + if (unlikely(err))
15606 + err = au_d_may_add(dentry);
15607 + if (unlikely(err))
15610 + a->src_parent = dget_parent(src_dentry);
15611 + wr_dir_args.force_btgt = au_ibstart(inode);
15613 + di_write_lock_parent(a->parent);
15614 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
15615 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
15617 + err = PTR_ERR(wh_dentry);
15618 + if (IS_ERR(wh_dentry))
15622 + sb = dentry->d_sb;
15623 + a->bdst = au_dbstart(dentry);
15624 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
15625 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
15626 + a->bsrc = au_ibstart(inode);
15627 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
15628 + if (!h_src_dentry) {
15629 + a->bsrc = au_dbstart(src_dentry);
15630 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
15631 + AuDebugOn(!h_src_dentry);
15632 + } else if (IS_ERR(h_src_dentry))
15635 + if (au_opt_test(au_mntflags(sb), PLINK)) {
15636 + if (a->bdst < a->bsrc
15637 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
15638 + err = au_cpup_or_link(src_dentry, a);
15640 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
15642 + dput(h_src_dentry);
15645 + * copyup src_dentry to the branch we process,
15646 + * and then link(2) to it.
15648 + dput(h_src_dentry);
15649 + if (a->bdst < a->bsrc
15650 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
15651 + au_unpin(&a->pin);
15652 + di_write_unlock(a->parent);
15653 + err = au_cpup_before_link(src_dentry, a);
15654 + di_write_lock_parent(a->parent);
15656 + err = au_pin(&a->pin, dentry, a->bdst,
15658 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
15659 + if (unlikely(err))
15663 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
15665 + if (h_src_dentry && h_src_dentry->d_inode)
15666 + err = vfsub_link(h_src_dentry,
15667 + au_pinned_h_dir(&a->pin),
15671 + if (unlikely(err))
15675 + a->h_path.dentry = wh_dentry;
15676 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
15678 + if (unlikely(err))
15682 + dir->i_version++;
15683 + if (au_ibstart(dir) == au_dbstart(dentry))
15684 + au_cpup_attr_timesizes(dir);
15685 + inc_nlink(inode);
15686 + inode->i_ctime = dir->i_ctime;
15687 + d_instantiate(dentry, au_igrab(inode));
15688 + if (d_unhashed(a->h_path.dentry))
15689 + /* some filesystem calls d_drop() */
15691 + goto out_unpin; /* success */
15694 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path, /*force*/0);
15695 + if (unlikely(rerr)) {
15696 + AuIOErr("%.*s reverting failed(%d, %d)\n",
15697 + AuDLNPair(dentry), err, rerr);
15700 + au_dtime_revert(&dt);
15702 + au_unpin(&a->pin);
15706 + di_write_unlock(a->parent);
15707 + dput(a->src_parent);
15709 + if (unlikely(err)) {
15710 + au_update_dbstart(dentry);
15713 + aufs_read_and_write_unlock2(dentry, src_dentry);
15720 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
15723 + aufs_bindex_t bindex;
15724 + unsigned char diropq;
15725 + struct path h_path;
15726 + struct dentry *wh_dentry, *parent, *opq_dentry;
15727 + struct mutex *h_mtx;
15728 + struct super_block *sb;
15730 + struct au_pin pin;
15731 + struct au_dtime dt;
15732 + } *a; /* reduce the stack usage */
15733 + struct au_wr_dir_args wr_dir_args = {
15734 + .force_btgt = -1,
15735 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
15741 + a = kmalloc(sizeof(*a), GFP_NOFS);
15742 + if (unlikely(!a))
15745 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
15746 + if (unlikely(err))
15748 + err = au_d_may_add(dentry);
15749 + if (unlikely(err))
15752 + parent = dentry->d_parent; /* dir inode is locked */
15753 + di_write_lock_parent(parent);
15754 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
15755 + &a->pin, &wr_dir_args);
15756 + err = PTR_ERR(wh_dentry);
15757 + if (IS_ERR(wh_dentry))
15760 + sb = dentry->d_sb;
15761 + bindex = au_dbstart(dentry);
15762 + h_path.dentry = au_h_dptr(dentry, bindex);
15763 + h_path.mnt = au_sbr_mnt(sb, bindex);
15764 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
15765 + if (unlikely(err))
15768 + /* make the dir opaque */
15770 + h_mtx = &h_path.dentry->d_inode->i_mutex;
15772 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
15773 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
15774 + opq_dentry = au_diropq_create(dentry, bindex);
15775 + mutex_unlock(h_mtx);
15776 + err = PTR_ERR(opq_dentry);
15777 + if (IS_ERR(opq_dentry))
15779 + dput(opq_dentry);
15783 + err = epilog(dir, bindex, wh_dentry, dentry);
15786 + goto out_unpin; /* success */
15791 + AuLabel(revert opq);
15792 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
15793 + rerr = au_diropq_remove(dentry, bindex);
15794 + mutex_unlock(h_mtx);
15796 + AuIOErr("%.*s reverting diropq failed(%d, %d)\n",
15797 + AuDLNPair(dentry), err, rerr);
15803 + AuLabel(revert dir);
15804 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
15806 + AuIOErr("%.*s reverting dir failed(%d, %d)\n",
15807 + AuDLNPair(dentry), err, rerr);
15810 + au_dtime_revert(&a->dt);
15812 + au_unpin(&a->pin);
15815 + di_write_unlock(parent);
15817 + if (unlikely(err)) {
15818 + au_update_dbstart(dentry);
15821 + aufs_read_unlock(dentry, AuLock_DW);
15827 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
15828 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
15829 +++ linux/fs/aufs/i_op.c 2012-03-19 12:24:13.683134508 +0100
15832 + * Copyright (C) 2005-2012 Junjiro R. Okajima
15834 + * This program, aufs is free software; you can redistribute it and/or modify
15835 + * it under the terms of the GNU General Public License as published by
15836 + * the Free Software Foundation; either version 2 of the License, or
15837 + * (at your option) any later version.
15839 + * This program is distributed in the hope that it will be useful,
15840 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15841 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15842 + * GNU General Public License for more details.
15844 + * You should have received a copy of the GNU General Public License
15845 + * along with this program; if not, write to the Free Software
15846 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15850 + * inode operations (except add/del/rename)
15853 +#include <linux/device_cgroup.h>
15854 +#include <linux/fs_stack.h>
15855 +#include <linux/namei.h>
15856 +#include <linux/security.h>
15859 +static int h_permission(struct inode *h_inode, int mask,
15860 + struct vfsmount *h_mnt, int brperm)
15863 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
15866 + if ((write_mask && IS_IMMUTABLE(h_inode))
15867 + || ((mask & MAY_EXEC)
15868 + && S_ISREG(h_inode->i_mode)
15869 + && ((h_mnt->mnt_flags & MNT_NOEXEC)
15870 + || !(h_inode->i_mode & S_IXUGO))))
15874 + * - skip the lower fs test in the case of write to ro branch.
15875 + * - nfs dir permission write check is optimized, but a policy for
15876 + * link/rename requires a real check.
15878 + if ((write_mask && !au_br_writable(brperm))
15879 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
15880 + && write_mask && !(mask & MAY_READ))
15881 + || !h_inode->i_op->permission) {
15882 + /* AuLabel(generic_permission); */
15883 + err = generic_permission(h_inode, mask);
15885 + /* AuLabel(h_inode->permission); */
15886 + err = h_inode->i_op->permission(h_inode, mask);
15891 + err = devcgroup_inode_permission(h_inode, mask);
15893 + err = security_inode_permission(h_inode, mask);
15897 + /* todo: do we need to call ima_path_check()? */
15898 + struct path h_path = {
15902 + err = ima_path_check(&h_path,
15903 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
15904 + IMA_COUNT_LEAVE);
15912 +static int aufs_permission(struct inode *inode, int mask)
15915 + aufs_bindex_t bindex, bend;
15916 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
15917 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
15918 + struct inode *h_inode;
15919 + struct super_block *sb;
15920 + struct au_branch *br;
15922 + /* todo: support rcu-walk? */
15923 + if (mask & MAY_NOT_BLOCK)
15926 + sb = inode->i_sb;
15927 + si_read_lock(sb, AuLock_FLUSH);
15928 + ii_read_lock_child(inode);
15930 + err = au_iigen_test(inode, au_sigen(sb));
15931 + if (unlikely(err))
15935 + if (!isdir || write_mask) {
15936 + err = au_busy_or_stale();
15937 + h_inode = au_h_iptr(inode, au_ibstart(inode));
15938 + if (unlikely(!h_inode
15939 + || (h_inode->i_mode & S_IFMT)
15940 + != (inode->i_mode & S_IFMT)))
15944 + bindex = au_ibstart(inode);
15945 + br = au_sbr(sb, bindex);
15946 + err = h_permission(h_inode, mask, br->br_mnt, br->br_perm);
15949 + && !special_file(h_inode->i_mode)) {
15950 + /* test whether the upper writable branch exists */
15952 + for (; bindex >= 0; bindex--)
15953 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
15961 + /* non-write to dir */
15963 + bend = au_ibend(inode);
15964 + for (bindex = au_ibstart(inode); !err && bindex <= bend; bindex++) {
15965 + h_inode = au_h_iptr(inode, bindex);
15967 + err = au_busy_or_stale();
15968 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
15971 + br = au_sbr(sb, bindex);
15972 + err = h_permission(h_inode, mask, br->br_mnt,
15978 + ii_read_unlock(inode);
15979 + si_read_unlock(sb);
15983 +/* ---------------------------------------------------------------------- */
15985 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
15986 + struct nameidata *nd)
15988 + struct dentry *ret, *parent;
15989 + struct inode *inode;
15990 + struct super_block *sb;
15991 + int err, npositive, lc_idx;
15996 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15997 + ret = ERR_PTR(err);
15998 + if (unlikely(err))
16001 + ret = ERR_PTR(-ENAMETOOLONG);
16002 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
16004 + err = au_di_init(dentry);
16005 + ret = ERR_PTR(err);
16006 + if (unlikely(err))
16010 + npositive = 0; /* suppress a warning */
16011 + parent = dentry->d_parent; /* dir inode is locked */
16012 + di_read_lock_parent(parent, AuLock_IR);
16013 + err = au_alive_dir(parent);
16015 + err = au_digen_test(parent, au_sigen(sb));
16017 + npositive = au_lkup_dentry(dentry, au_dbstart(parent),
16021 + di_read_unlock(parent, AuLock_IR);
16022 + ret = ERR_PTR(err);
16023 + if (unlikely(err < 0))
16027 + inode = au_new_inode(dentry, /*must_new*/0);
16028 + ret = (void *)inode;
16030 + if (IS_ERR(inode)) {
16035 + ret = d_splice_alias(inode, dentry);
16036 + if (unlikely(IS_ERR(ret) && inode)) {
16037 + ii_write_unlock(inode);
16038 + lc_idx = AuLcNonDir_IIINFO;
16039 + if (S_ISLNK(inode->i_mode))
16040 + lc_idx = AuLcSymlink_IIINFO;
16041 + else if (S_ISDIR(inode->i_mode))
16042 + lc_idx = AuLcDir_IIINFO;
16043 + au_rw_class(&au_ii(inode)->ii_rwsem, au_lc_key + lc_idx);
16048 + di_write_unlock(dentry);
16049 + if (unlikely(IS_ERR(ret) && inode)) {
16050 + lc_idx = AuLcNonDir_DIINFO;
16051 + if (S_ISLNK(inode->i_mode))
16052 + lc_idx = AuLcSymlink_DIINFO;
16053 + else if (S_ISDIR(inode->i_mode))
16054 + lc_idx = AuLcDir_DIINFO;
16055 + au_rw_class(&au_di(dentry)->di_rwsem, au_lc_key + lc_idx);
16058 + si_read_unlock(sb);
16063 +/* ---------------------------------------------------------------------- */
16065 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
16066 + const unsigned char add_entry, aufs_bindex_t bcpup,
16067 + aufs_bindex_t bstart)
16070 + struct dentry *h_parent;
16071 + struct inode *h_dir;
16074 + IMustLock(parent->d_inode);
16076 + di_write_lock_parent(parent);
16079 + if (!au_h_dptr(parent, bcpup)) {
16080 + if (bstart < bcpup)
16081 + err = au_cpdown_dirs(dentry, bcpup);
16083 + err = au_cpup_dirs(dentry, bcpup);
16085 + if (!err && add_entry) {
16086 + h_parent = au_h_dptr(parent, bcpup);
16087 + h_dir = h_parent->d_inode;
16088 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
16089 + err = au_lkup_neg(dentry, bcpup);
16090 + /* todo: no unlock here */
16091 + mutex_unlock(&h_dir->i_mutex);
16093 + AuDbg("bcpup %d\n", bcpup);
16095 + if (!dentry->d_inode)
16096 + au_set_h_dptr(dentry, bstart, NULL);
16097 + au_update_dbrange(dentry, /*do_put_zero*/0);
16102 + di_write_unlock(parent);
16104 + err = bcpup; /* success */
16111 + * decide the branch and the parent dir where we will create a new entry.
16112 + * returns new bindex or an error.
16113 + * copyup the parent dir if needed.
16115 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
16116 + struct au_wr_dir_args *args)
16119 + aufs_bindex_t bcpup, bstart, src_bstart;
16120 + const unsigned char add_entry = !!au_ftest_wrdir(args->flags,
16122 + struct super_block *sb;
16123 + struct dentry *parent;
16124 + struct au_sbinfo *sbinfo;
16126 + sb = dentry->d_sb;
16127 + sbinfo = au_sbi(sb);
16128 + parent = dget_parent(dentry);
16129 + bstart = au_dbstart(dentry);
16131 + if (args->force_btgt < 0) {
16132 + if (src_dentry) {
16133 + src_bstart = au_dbstart(src_dentry);
16134 + if (src_bstart < bstart)
16135 + bcpup = src_bstart;
16136 + } else if (add_entry) {
16137 + err = AuWbrCreate(sbinfo, dentry,
16138 + au_ftest_wrdir(args->flags, ISDIR));
16142 + if (bcpup < 0 || au_test_ro(sb, bcpup, dentry->d_inode)) {
16144 + err = AuWbrCopyup(sbinfo, dentry);
16146 + if (!IS_ROOT(dentry)) {
16147 + di_read_lock_parent(parent, !AuLock_IR);
16148 + err = AuWbrCopyup(sbinfo, dentry);
16149 + di_read_unlock(parent, !AuLock_IR);
16151 + err = AuWbrCopyup(sbinfo, dentry);
16154 + if (unlikely(err < 0))
16158 + bcpup = args->force_btgt;
16159 + AuDebugOn(au_test_ro(sb, bcpup, dentry->d_inode));
16162 + AuDbg("bstart %d, bcpup %d\n", bstart, bcpup);
16164 + if (bcpup == bstart)
16165 + goto out; /* success */
16167 + /* copyup the new parent into the branch we process */
16168 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, bstart);
16170 + if (!dentry->d_inode) {
16171 + au_set_h_dptr(dentry, bstart, NULL);
16172 + au_set_dbstart(dentry, bcpup);
16173 + au_set_dbend(dentry, bcpup);
16175 + AuDebugOn(add_entry && !au_h_dptr(dentry, bcpup));
16183 +/* ---------------------------------------------------------------------- */
16185 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
16187 + if (pin && pin->parent)
16188 + return au_h_dptr(pin->parent, pin->bindex);
16192 +void au_unpin(struct au_pin *p)
16194 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
16195 + mnt_drop_write(p->h_mnt);
16199 + au_hn_imtx_unlock(p->hdir);
16200 + if (!au_ftest_pin(p->flags, DI_LOCKED))
16201 + di_read_unlock(p->parent, AuLock_IR);
16202 + iput(p->hdir->hi_inode);
16204 + p->parent = NULL;
16209 +int au_do_pin(struct au_pin *p)
16212 + struct super_block *sb;
16213 + struct dentry *h_dentry, *h_parent;
16214 + struct au_branch *br;
16215 + struct inode *h_dir;
16218 + sb = p->dentry->d_sb;
16219 + br = au_sbr(sb, p->bindex);
16220 + if (IS_ROOT(p->dentry)) {
16221 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
16222 + p->h_mnt = br->br_mnt;
16223 + err = mnt_want_write(p->h_mnt);
16224 + if (unlikely(err)) {
16225 + au_fclr_pin(p->flags, MNT_WRITE);
16233 + if (p->bindex <= au_dbend(p->dentry))
16234 + h_dentry = au_h_dptr(p->dentry, p->bindex);
16236 + p->parent = dget_parent(p->dentry);
16237 + if (!au_ftest_pin(p->flags, DI_LOCKED))
16238 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
16241 + h_parent = au_h_dptr(p->parent, p->bindex);
16242 + p->hdir = au_hi(p->parent->d_inode, p->bindex);
16244 + h_dir = p->hdir->hi_inode;
16248 + * if DI_LOCKED is not set, then p->parent may be different
16249 + * and h_parent can be NULL.
16251 + if (unlikely(!p->hdir || !h_dir || !h_parent)) {
16253 + if (!au_ftest_pin(p->flags, DI_LOCKED))
16254 + di_read_unlock(p->parent, AuLock_IR);
16256 + p->parent = NULL;
16261 + au_hn_imtx_lock_nested(p->hdir, p->lsc_hi);
16263 + if (unlikely(p->hdir->hi_inode != h_parent->d_inode)) {
16268 + err = au_h_verify(h_dentry, p->udba, h_dir, h_parent, br);
16269 + if (unlikely(err)) {
16270 + au_fclr_pin(p->flags, MNT_WRITE);
16275 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
16276 + p->h_mnt = br->br_mnt;
16277 + err = mnt_want_write(p->h_mnt);
16278 + if (unlikely(err)) {
16279 + au_fclr_pin(p->flags, MNT_WRITE);
16283 + goto out; /* success */
16288 + pr_err("err %d\n", err);
16289 + err = au_busy_or_stale();
16294 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
16295 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
16296 + unsigned int udba, unsigned char flags)
16298 + p->dentry = dentry;
16300 + p->lsc_di = lsc_di;
16301 + p->lsc_hi = lsc_hi;
16302 + p->flags = flags;
16303 + p->bindex = bindex;
16305 + p->parent = NULL;
16310 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
16311 + unsigned int udba, unsigned char flags)
16313 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
16315 + return au_do_pin(pin);
16318 +/* ---------------------------------------------------------------------- */
16321 + * ->setattr() and ->getattr() are called in various cases.
16322 + * chmod, stat: dentry is revalidated.
16323 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
16325 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
16327 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
16328 +static int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
16331 + struct inode *inode;
16332 + struct dentry *parent;
16335 + inode = dentry->d_inode;
16336 + if (au_digen_test(dentry, sigen)) {
16337 + parent = dget_parent(dentry);
16338 + di_read_lock_parent(parent, AuLock_IR);
16339 + err = au_refresh_dentry(dentry, parent);
16340 + di_read_unlock(parent, AuLock_IR);
16348 +#define AuIcpup_DID_CPUP 1
16349 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
16350 +#define au_fset_icpup(flags, name) \
16351 + do { (flags) |= AuIcpup_##name; } while (0)
16352 +#define au_fclr_icpup(flags, name) \
16353 + do { (flags) &= ~AuIcpup_##name; } while (0)
16355 +struct au_icpup_args {
16356 + unsigned char flags;
16357 + unsigned char pin_flags;
16358 + aufs_bindex_t btgt;
16359 + unsigned int udba;
16360 + struct au_pin pin;
16361 + struct path h_path;
16362 + struct inode *h_inode;
16365 +static int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
16366 + struct au_icpup_args *a)
16370 + aufs_bindex_t bstart, ibstart;
16371 + struct dentry *hi_wh, *parent;
16372 + struct inode *inode;
16373 + struct file *h_file;
16374 + struct au_wr_dir_args wr_dir_args = {
16375 + .force_btgt = -1,
16379 + bstart = au_dbstart(dentry);
16380 + inode = dentry->d_inode;
16381 + if (S_ISDIR(inode->i_mode))
16382 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
16383 + /* plink or hi_wh() case */
16384 + ibstart = au_ibstart(inode);
16385 + if (bstart != ibstart && !au_test_ro(inode->i_sb, ibstart, inode))
16386 + wr_dir_args.force_btgt = ibstart;
16387 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
16388 + if (unlikely(err < 0))
16391 + if (err != bstart)
16392 + au_fset_icpup(a->flags, DID_CPUP);
16395 + a->pin_flags = AuPin_MNT_WRITE;
16397 + if (!IS_ROOT(dentry)) {
16398 + au_fset_pin(a->pin_flags, DI_LOCKED);
16399 + parent = dget_parent(dentry);
16400 + di_write_lock_parent(parent);
16403 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
16404 + if (unlikely(err))
16407 + a->h_path.dentry = au_h_dptr(dentry, bstart);
16408 + a->h_inode = a->h_path.dentry->d_inode;
16409 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
16411 + if ((ia->ia_valid & ATTR_SIZE) && ia->ia_size < i_size_read(a->h_inode))
16412 + sz = ia->ia_size;
16416 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
16417 + hi_wh = au_hi_wh(inode, a->btgt);
16419 + err = au_sio_cpup_wh(dentry, a->btgt, sz, /*file*/NULL);
16420 + if (unlikely(err))
16422 + hi_wh = au_hi_wh(inode, a->btgt);
16423 + /* todo: revalidate hi_wh? */
16428 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
16429 + di_downgrade_lock(parent, AuLock_IR);
16433 + if (!au_ftest_icpup(a->flags, DID_CPUP))
16434 + goto out; /* success */
16436 + if (!d_unhashed(dentry)) {
16437 + h_file = au_h_open_pre(dentry, bstart);
16438 + if (IS_ERR(h_file)) {
16439 + err = PTR_ERR(h_file);
16442 + err = au_sio_cpup_simple(dentry, a->btgt, sz,
16445 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
16446 + } else if (!hi_wh)
16447 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
16449 + a->h_path.dentry = hi_wh; /* do not dget here */
16452 + mutex_unlock(&a->h_inode->i_mutex);
16453 + au_h_open_post(dentry, bstart, h_file);
16454 + a->h_inode = a->h_path.dentry->d_inode;
16456 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
16457 + goto out; /* success */
16460 + au_unpin(&a->pin);
16463 + di_write_unlock(parent);
16470 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
16473 + struct inode *inode;
16474 + struct super_block *sb;
16475 + struct file *file;
16476 + struct au_icpup_args *a;
16478 + inode = dentry->d_inode;
16479 + IMustLock(inode);
16482 + a = kzalloc(sizeof(*a), GFP_NOFS);
16483 + if (unlikely(!a))
16486 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
16487 + ia->ia_valid &= ~ATTR_MODE;
16490 + sb = dentry->d_sb;
16491 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16492 + if (unlikely(err))
16495 + if (ia->ia_valid & ATTR_FILE) {
16496 + /* currently ftruncate(2) only */
16497 + AuDebugOn(!S_ISREG(inode->i_mode));
16498 + file = ia->ia_file;
16499 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
16500 + if (unlikely(err))
16502 + ia->ia_file = au_hf_top(file);
16503 + a->udba = AuOpt_UDBA_NONE;
16505 + /* fchmod() doesn't pass ia_file */
16506 + a->udba = au_opt_udba(sb);
16507 + di_write_lock_child(dentry);
16508 + /* no d_unlinked(), to set UDBA_NONE for root */
16509 + if (d_unhashed(dentry))
16510 + a->udba = AuOpt_UDBA_NONE;
16511 + if (a->udba != AuOpt_UDBA_NONE) {
16512 + AuDebugOn(IS_ROOT(dentry));
16513 + err = au_reval_for_attr(dentry, au_sigen(sb));
16514 + if (unlikely(err))
16519 + err = au_pin_and_icpup(dentry, ia, a);
16520 + if (unlikely(err < 0))
16522 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
16523 + ia->ia_file = NULL;
16524 + ia->ia_valid &= ~ATTR_FILE;
16527 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
16528 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
16529 + == (ATTR_MODE | ATTR_CTIME)) {
16530 + err = security_path_chmod(&a->h_path, ia->ia_mode);
16531 + if (unlikely(err))
16533 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
16534 + && (ia->ia_valid & ATTR_CTIME)) {
16535 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
16536 + if (unlikely(err))
16540 + if (ia->ia_valid & ATTR_SIZE) {
16543 + if (ia->ia_size < i_size_read(inode))
16545 + truncate_setsize(inode, ia->ia_size);
16548 + if (ia->ia_valid & ATTR_FILE)
16550 + mutex_unlock(&a->h_inode->i_mutex);
16551 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
16552 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
16554 + err = vfsub_notify_change(&a->h_path, ia);
16556 + au_cpup_attr_changeable(inode);
16559 + mutex_unlock(&a->h_inode->i_mutex);
16560 + au_unpin(&a->pin);
16561 + if (unlikely(err))
16562 + au_update_dbstart(dentry);
16564 + di_write_unlock(dentry);
16566 + fi_write_unlock(file);
16567 + ia->ia_file = file;
16568 + ia->ia_valid |= ATTR_FILE;
16571 + si_read_unlock(sb);
16579 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
16580 + unsigned int nlink)
16584 + inode->i_mode = st->mode;
16585 + inode->i_uid = st->uid;
16586 + inode->i_gid = st->gid;
16587 + inode->i_atime = st->atime;
16588 + inode->i_mtime = st->mtime;
16589 + inode->i_ctime = st->ctime;
16591 + au_cpup_attr_nlink(inode, /*force*/0);
16592 + if (S_ISDIR(inode->i_mode)) {
16593 + n = inode->i_nlink;
16596 + /* 0 can happen */
16597 + vfsub_set_nlink(inode, n);
16600 + spin_lock(&inode->i_lock);
16601 + inode->i_blocks = st->blocks;
16602 + i_size_write(inode, st->size);
16603 + spin_unlock(&inode->i_lock);
16606 +static int aufs_getattr(struct vfsmount *mnt __maybe_unused,
16607 + struct dentry *dentry, struct kstat *st)
16610 + unsigned int mnt_flags;
16611 + aufs_bindex_t bindex;
16612 + unsigned char udba_none, positive;
16613 + struct super_block *sb, *h_sb;
16614 + struct inode *inode;
16615 + struct vfsmount *h_mnt;
16616 + struct dentry *h_dentry;
16618 + sb = dentry->d_sb;
16619 + inode = dentry->d_inode;
16620 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16621 + if (unlikely(err))
16623 + mnt_flags = au_mntflags(sb);
16624 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
16626 + /* support fstat(2) */
16627 + if (!d_unlinked(dentry) && !udba_none) {
16628 + unsigned int sigen = au_sigen(sb);
16629 + err = au_digen_test(dentry, sigen);
16631 + di_read_lock_child(dentry, AuLock_IR);
16632 + err = au_dbrange_test(dentry);
16633 + if (unlikely(err))
16636 + AuDebugOn(IS_ROOT(dentry));
16637 + di_write_lock_child(dentry);
16638 + err = au_dbrange_test(dentry);
16640 + err = au_reval_for_attr(dentry, sigen);
16641 + di_downgrade_lock(dentry, AuLock_IR);
16642 + if (unlikely(err))
16646 + di_read_lock_child(dentry, AuLock_IR);
16648 + bindex = au_ibstart(inode);
16649 + h_mnt = au_sbr_mnt(sb, bindex);
16650 + h_sb = h_mnt->mnt_sb;
16651 + if (!au_test_fs_bad_iattr(h_sb) && udba_none)
16652 + goto out_fill; /* success */
16655 + if (au_dbstart(dentry) == bindex)
16656 + h_dentry = dget(au_h_dptr(dentry, bindex));
16657 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
16658 + h_dentry = au_plink_lkup(inode, bindex);
16659 + if (IS_ERR(h_dentry))
16660 + goto out_fill; /* pretending success */
16662 + /* illegally overlapped or something */
16663 + if (unlikely(!h_dentry))
16664 + goto out_fill; /* pretending success */
16666 + positive = !!h_dentry->d_inode;
16668 + err = vfs_getattr(h_mnt, h_dentry, st);
16672 + au_refresh_iattr(inode, st, h_dentry->d_inode->i_nlink);
16673 + goto out_fill; /* success */
16679 + generic_fillattr(inode, st);
16681 + di_read_unlock(dentry, AuLock_IR);
16682 + si_read_unlock(sb);
16688 +/* ---------------------------------------------------------------------- */
16690 +static int h_readlink(struct dentry *dentry, int bindex, char __user *buf,
16694 + struct super_block *sb;
16695 + struct dentry *h_dentry;
16698 + h_dentry = au_h_dptr(dentry, bindex);
16699 + if (unlikely(!h_dentry->d_inode->i_op->readlink))
16702 + err = security_inode_readlink(h_dentry);
16703 + if (unlikely(err))
16706 + sb = dentry->d_sb;
16707 + if (!au_test_ro(sb, bindex, dentry->d_inode)) {
16708 + vfsub_touch_atime(au_sbr_mnt(sb, bindex), h_dentry);
16709 + fsstack_copy_attr_atime(dentry->d_inode, h_dentry->d_inode);
16711 + err = h_dentry->d_inode->i_op->readlink(h_dentry, buf, bufsiz);
16717 +static int aufs_readlink(struct dentry *dentry, char __user *buf, int bufsiz)
16721 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
16722 + if (unlikely(err))
16724 + err = au_d_hashed_positive(dentry);
16726 + err = h_readlink(dentry, au_dbstart(dentry), buf, bufsiz);
16727 + aufs_read_unlock(dentry, AuLock_IR);
16733 +static void *aufs_follow_link(struct dentry *dentry, struct nameidata *nd)
16736 + mm_segment_t old_fs;
16743 + buf.k = __getname_gfp(GFP_NOFS);
16744 + if (unlikely(!buf.k))
16747 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
16748 + if (unlikely(err))
16751 + err = au_d_hashed_positive(dentry);
16753 + old_fs = get_fs();
16754 + set_fs(KERNEL_DS);
16755 + err = h_readlink(dentry, au_dbstart(dentry), buf.u, PATH_MAX);
16758 + aufs_read_unlock(dentry, AuLock_IR);
16762 + /* will be freed by put_link */
16763 + nd_set_link(nd, buf.k);
16764 + return NULL; /* success */
16768 + __putname(buf.k);
16770 + path_put(&nd->path);
16772 + return ERR_PTR(err);
16775 +static void aufs_put_link(struct dentry *dentry __maybe_unused,
16776 + struct nameidata *nd, void *cookie __maybe_unused)
16778 + __putname(nd_get_link(nd));
16781 +/* ---------------------------------------------------------------------- */
16783 +static void aufs_truncate_range(struct inode *inode __maybe_unused,
16784 + loff_t start __maybe_unused,
16785 + loff_t end __maybe_unused)
16790 +/* ---------------------------------------------------------------------- */
16792 +struct inode_operations aufs_symlink_iop = {
16793 + .permission = aufs_permission,
16794 + .setattr = aufs_setattr,
16795 + .getattr = aufs_getattr,
16796 + .readlink = aufs_readlink,
16797 + .follow_link = aufs_follow_link,
16798 + .put_link = aufs_put_link
16801 +struct inode_operations aufs_dir_iop = {
16802 + .create = aufs_create,
16803 + .lookup = aufs_lookup,
16804 + .link = aufs_link,
16805 + .unlink = aufs_unlink,
16806 + .symlink = aufs_symlink,
16807 + .mkdir = aufs_mkdir,
16808 + .rmdir = aufs_rmdir,
16809 + .mknod = aufs_mknod,
16810 + .rename = aufs_rename,
16812 + .permission = aufs_permission,
16813 + .setattr = aufs_setattr,
16814 + .getattr = aufs_getattr
16817 +struct inode_operations aufs_iop = {
16818 + .permission = aufs_permission,
16819 + .setattr = aufs_setattr,
16820 + .getattr = aufs_getattr,
16821 + .truncate_range = aufs_truncate_range
16823 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
16824 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
16825 +++ linux/fs/aufs/i_op_del.c 2012-03-19 12:24:13.683134508 +0100
16828 + * Copyright (C) 2005-2012 Junjiro R. Okajima
16830 + * This program, aufs is free software; you can redistribute it and/or modify
16831 + * it under the terms of the GNU General Public License as published by
16832 + * the Free Software Foundation; either version 2 of the License, or
16833 + * (at your option) any later version.
16835 + * This program is distributed in the hope that it will be useful,
16836 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16837 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16838 + * GNU General Public License for more details.
16840 + * You should have received a copy of the GNU General Public License
16841 + * along with this program; if not, write to the Free Software
16842 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16846 + * inode operations (del entry)
16852 + * decide if a new whiteout for @dentry is necessary or not.
16853 + * when it is necessary, prepare the parent dir for the upper branch whose
16854 + * branch index is @bcpup for creation. the actual creation of the whiteout will
16855 + * be done by caller.
16857 + * 0: wh is unnecessary
16858 + * plus: wh is necessary
16861 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
16863 + int need_wh, err;
16864 + aufs_bindex_t bstart;
16865 + struct super_block *sb;
16867 + sb = dentry->d_sb;
16868 + bstart = au_dbstart(dentry);
16869 + if (*bcpup < 0) {
16871 + if (au_test_ro(sb, bstart, dentry->d_inode)) {
16872 + err = AuWbrCopyup(au_sbi(sb), dentry);
16874 + if (unlikely(err < 0))
16878 + AuDebugOn(bstart < *bcpup
16879 + || au_test_ro(sb, *bcpup, dentry->d_inode));
16880 + AuDbg("bcpup %d, bstart %d\n", *bcpup, bstart);
16882 + if (*bcpup != bstart) {
16883 + err = au_cpup_dirs(dentry, *bcpup);
16884 + if (unlikely(err))
16888 + struct au_dinfo *dinfo, *tmp;
16890 + need_wh = -ENOMEM;
16891 + dinfo = au_di(dentry);
16892 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
16894 + au_di_cp(tmp, dinfo);
16895 + au_di_swap(tmp, dinfo);
16896 + /* returns the number of positive dentries */
16897 + need_wh = au_lkup_dentry(dentry, bstart + 1, /*type*/0,
16899 + au_di_swap(tmp, dinfo);
16900 + au_rw_write_unlock(&tmp->di_rwsem);
16904 + AuDbg("need_wh %d\n", need_wh);
16912 + * simple tests for the del-entry operations.
16913 + * following the checks in vfs, plus the parent-child relationship.
16915 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
16916 + struct dentry *h_parent, int isdir)
16920 + struct dentry *h_dentry, *h_latest;
16921 + struct inode *h_inode;
16923 + h_dentry = au_h_dptr(dentry, bindex);
16924 + h_inode = h_dentry->d_inode;
16925 + if (dentry->d_inode) {
16927 + if (unlikely(!h_inode || !h_inode->i_nlink))
16930 + h_mode = h_inode->i_mode;
16933 + if (unlikely(S_ISDIR(h_mode)))
16935 + } else if (unlikely(!S_ISDIR(h_mode))) {
16940 + /* rename(2) case */
16942 + if (unlikely(h_inode))
16947 + /* expected parent dir is locked */
16948 + if (unlikely(h_parent != h_dentry->d_parent))
16953 + * rmdir a dir may break the consistency on some filesystem.
16954 + * let's try heavy test.
16957 + if (unlikely(au_test_h_perm(h_parent->d_inode, MAY_EXEC | MAY_WRITE)))
16960 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent,
16961 + au_sbr(dentry->d_sb, bindex));
16963 + if (IS_ERR(h_latest))
16965 + if (h_latest == h_dentry)
16974 + * decide the branch where we operate for @dentry. the branch index will be set
16975 + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent
16976 + * dir for reverting.
16977 + * when a new whiteout is necessary, create it.
16979 +static struct dentry*
16980 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
16981 + struct au_dtime *dt, struct au_pin *pin)
16983 + struct dentry *wh_dentry;
16984 + struct super_block *sb;
16985 + struct path h_path;
16986 + int err, need_wh;
16987 + unsigned int udba;
16988 + aufs_bindex_t bcpup;
16990 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
16991 + wh_dentry = ERR_PTR(need_wh);
16992 + if (unlikely(need_wh < 0))
16995 + sb = dentry->d_sb;
16996 + udba = au_opt_udba(sb);
16998 + err = au_pin(pin, dentry, bcpup, udba,
16999 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17000 + wh_dentry = ERR_PTR(err);
17001 + if (unlikely(err))
17004 + h_path.dentry = au_pinned_h_parent(pin);
17005 + if (udba != AuOpt_UDBA_NONE
17006 + && au_dbstart(dentry) == bcpup) {
17007 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
17008 + wh_dentry = ERR_PTR(err);
17009 + if (unlikely(err))
17013 + h_path.mnt = au_sbr_mnt(sb, bcpup);
17014 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
17015 + wh_dentry = NULL;
17017 + goto out; /* success, no need to create whiteout */
17019 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
17020 + if (IS_ERR(wh_dentry))
17023 + /* returns with the parent is locked and wh_dentry is dget-ed */
17024 + goto out; /* success */
17029 + return wh_dentry;
17033 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
17034 + * in order to be revertible and save time for removing many child whiteouts
17036 + * returns 1 when there are too many child whiteout and caller should remove
17037 + * them asynchronously. returns 0 when the number of children is enough small to
17038 + * remove now or the branch fs is a remote fs.
17039 + * otherwise return an error.
17041 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
17042 + struct au_nhash *whlist, struct inode *dir)
17044 + int rmdir_later, err, dirwh;
17045 + struct dentry *h_dentry;
17046 + struct super_block *sb;
17048 + sb = dentry->d_sb;
17049 + SiMustAnyLock(sb);
17050 + h_dentry = au_h_dptr(dentry, bindex);
17051 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
17052 + if (unlikely(err))
17055 + /* stop monitoring */
17056 + au_hn_free(au_hi(dentry->d_inode, bindex));
17058 + if (!au_test_fs_remote(h_dentry->d_sb)) {
17059 + dirwh = au_sbi(sb)->si_dirwh;
17060 + rmdir_later = (dirwh <= 1);
17061 + if (!rmdir_later)
17062 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
17065 + return rmdir_later;
17068 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
17069 + if (unlikely(err)) {
17070 + AuIOErr("rmdir %.*s, b%d failed, %d. ignored\n",
17071 + AuDLNPair(h_dentry), bindex, err);
17081 + * final procedure for deleting a entry.
17082 + * maintain dentry and iattr.
17084 +static void epilog(struct inode *dir, struct dentry *dentry,
17085 + aufs_bindex_t bindex)
17087 + struct inode *inode;
17089 + inode = dentry->d_inode;
17091 + inode->i_ctime = dir->i_ctime;
17093 + if (au_ibstart(dir) == bindex)
17094 + au_cpup_attr_timesizes(dir);
17095 + dir->i_version++;
17099 + * when an error happened, remove the created whiteout and revert everything.
17101 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
17102 + aufs_bindex_t bwh, struct dentry *wh_dentry,
17103 + struct dentry *dentry, struct au_dtime *dt)
17106 + struct path h_path = {
17107 + .dentry = wh_dentry,
17108 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
17111 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
17113 + au_set_dbwh(dentry, bwh);
17114 + au_dtime_revert(dt);
17118 + AuIOErr("%.*s reverting whiteout failed(%d, %d)\n",
17119 + AuDLNPair(dentry), err, rerr);
17123 +/* ---------------------------------------------------------------------- */
17125 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
17128 + aufs_bindex_t bwh, bindex, bstart;
17129 + struct au_dtime dt;
17130 + struct au_pin pin;
17131 + struct path h_path;
17132 + struct inode *inode, *h_dir;
17133 + struct dentry *parent, *wh_dentry;
17137 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
17138 + if (unlikely(err))
17140 + err = au_d_hashed_positive(dentry);
17141 + if (unlikely(err))
17143 + inode = dentry->d_inode;
17144 + IMustLock(inode);
17146 + if (unlikely(S_ISDIR(inode->i_mode)))
17147 + goto out_unlock; /* possible? */
17149 + bstart = au_dbstart(dentry);
17150 + bwh = au_dbwh(dentry);
17152 + parent = dentry->d_parent; /* dir inode is locked */
17153 + di_write_lock_parent(parent);
17154 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &dt, &pin);
17155 + err = PTR_ERR(wh_dentry);
17156 + if (IS_ERR(wh_dentry))
17159 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
17160 + h_path.dentry = au_h_dptr(dentry, bstart);
17161 + dget(h_path.dentry);
17162 + if (bindex == bstart) {
17163 + h_dir = au_pinned_h_dir(&pin);
17164 + err = vfsub_unlink(h_dir, &h_path, /*force*/0);
17166 + /* dir inode is locked */
17167 + h_dir = wh_dentry->d_parent->d_inode;
17168 + IMustLock(h_dir);
17173 + vfsub_drop_nlink(inode);
17174 + epilog(dir, dentry, bindex);
17176 + /* update target timestamps */
17177 + if (bindex == bstart) {
17178 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
17179 + inode->i_ctime = h_path.dentry->d_inode->i_ctime;
17181 + /* todo: this timestamp may be reverted later */
17182 + inode->i_ctime = h_dir->i_ctime;
17183 + goto out_unpin; /* success */
17190 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry, &dt);
17198 + dput(h_path.dentry);
17200 + di_write_unlock(parent);
17202 + aufs_read_unlock(dentry, AuLock_DW);
17207 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
17209 + int err, rmdir_later;
17210 + aufs_bindex_t bwh, bindex, bstart;
17211 + struct au_dtime dt;
17212 + struct au_pin pin;
17213 + struct inode *inode;
17214 + struct dentry *parent, *wh_dentry, *h_dentry;
17215 + struct au_whtmp_rmdir *args;
17219 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
17220 + if (unlikely(err))
17222 + err = au_alive_dir(dentry);
17223 + if (unlikely(err))
17225 + inode = dentry->d_inode;
17226 + IMustLock(inode);
17228 + if (unlikely(!S_ISDIR(inode->i_mode)))
17229 + goto out_unlock; /* possible? */
17232 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
17233 + if (unlikely(!args))
17236 + parent = dentry->d_parent; /* dir inode is locked */
17237 + di_write_lock_parent(parent);
17238 + err = au_test_empty(dentry, &args->whlist);
17239 + if (unlikely(err))
17242 + bstart = au_dbstart(dentry);
17243 + bwh = au_dbwh(dentry);
17245 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &dt, &pin);
17246 + err = PTR_ERR(wh_dentry);
17247 + if (IS_ERR(wh_dentry))
17250 + h_dentry = au_h_dptr(dentry, bstart);
17253 + if (bindex == bstart) {
17254 + err = renwh_and_rmdir(dentry, bstart, &args->whlist, dir);
17256 + rmdir_later = err;
17260 + /* stop monitoring */
17261 + au_hn_free(au_hi(inode, bstart));
17263 + /* dir inode is locked */
17264 + IMustLock(wh_dentry->d_parent->d_inode);
17269 + vfsub_dead_dir(inode);
17270 + au_set_dbdiropq(dentry, -1);
17271 + epilog(dir, dentry, bindex);
17273 + if (rmdir_later) {
17274 + au_whtmp_kick_rmdir(dir, bstart, h_dentry, args);
17278 + goto out_unpin; /* success */
17286 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry, &dt);
17296 + di_write_unlock(parent);
17298 + au_whtmp_rmdir_free(args);
17300 + aufs_read_unlock(dentry, AuLock_DW);
17305 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
17306 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
17307 +++ linux/fs/aufs/i_op_ren.c 2012-03-19 12:24:13.683134508 +0100
17310 + * Copyright (C) 2005-2012 Junjiro R. Okajima
17312 + * This program, aufs is free software; you can redistribute it and/or modify
17313 + * it under the terms of the GNU General Public License as published by
17314 + * the Free Software Foundation; either version 2 of the License, or
17315 + * (at your option) any later version.
17317 + * This program is distributed in the hope that it will be useful,
17318 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17319 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17320 + * GNU General Public License for more details.
17322 + * You should have received a copy of the GNU General Public License
17323 + * along with this program; if not, write to the Free Software
17324 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17328 + * inode operation (rename entry)
17329 + * todo: this is crazy monster
17334 +enum { AuSRC, AuDST, AuSrcDst };
17335 +enum { AuPARENT, AuCHILD, AuParentChild };
17337 +#define AuRen_ISDIR 1
17338 +#define AuRen_ISSAMEDIR (1 << 1)
17339 +#define AuRen_WHSRC (1 << 2)
17340 +#define AuRen_WHDST (1 << 3)
17341 +#define AuRen_MNT_WRITE (1 << 4)
17342 +#define AuRen_DT_DSTDIR (1 << 5)
17343 +#define AuRen_DIROPQ (1 << 6)
17344 +#define AuRen_CPUP (1 << 7)
17345 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
17346 +#define au_fset_ren(flags, name) \
17347 + do { (flags) |= AuRen_##name; } while (0)
17348 +#define au_fclr_ren(flags, name) \
17349 + do { (flags) &= ~AuRen_##name; } while (0)
17351 +struct au_ren_args {
17353 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
17355 + struct inode *dir, *inode;
17356 + struct au_hinode *hdir;
17357 + struct au_dtime dt[AuParentChild];
17358 + aufs_bindex_t bstart;
17361 +#define src_dentry sd[AuSRC].dentry
17362 +#define src_dir sd[AuSRC].dir
17363 +#define src_inode sd[AuSRC].inode
17364 +#define src_h_dentry sd[AuSRC].h_dentry
17365 +#define src_parent sd[AuSRC].parent
17366 +#define src_h_parent sd[AuSRC].h_parent
17367 +#define src_wh_dentry sd[AuSRC].wh_dentry
17368 +#define src_hdir sd[AuSRC].hdir
17369 +#define src_h_dir sd[AuSRC].hdir->hi_inode
17370 +#define src_dt sd[AuSRC].dt
17371 +#define src_bstart sd[AuSRC].bstart
17373 +#define dst_dentry sd[AuDST].dentry
17374 +#define dst_dir sd[AuDST].dir
17375 +#define dst_inode sd[AuDST].inode
17376 +#define dst_h_dentry sd[AuDST].h_dentry
17377 +#define dst_parent sd[AuDST].parent
17378 +#define dst_h_parent sd[AuDST].h_parent
17379 +#define dst_wh_dentry sd[AuDST].wh_dentry
17380 +#define dst_hdir sd[AuDST].hdir
17381 +#define dst_h_dir sd[AuDST].hdir->hi_inode
17382 +#define dst_dt sd[AuDST].dt
17383 +#define dst_bstart sd[AuDST].bstart
17385 + struct dentry *h_trap;
17386 + struct au_branch *br;
17387 + struct au_hinode *src_hinode;
17388 + struct path h_path;
17389 + struct au_nhash whlist;
17390 + aufs_bindex_t btgt, src_bwh, src_bdiropq;
17392 + unsigned int flags;
17394 + struct au_whtmp_rmdir *thargs;
17395 + struct dentry *h_dst;
17398 +/* ---------------------------------------------------------------------- */
17401 + * functions for reverting.
17402 + * when an error happened in a single rename systemcall, we should revert
17403 + * everything as if nothing happend.
17404 + * we don't need to revert the copied-up/down the parent dir since they are
17408 +#define RevertFailure(fmt, ...) do { \
17409 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
17410 + ##__VA_ARGS__, err, rerr); \
17414 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
17418 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
17419 + rerr = au_diropq_remove(a->src_dentry, a->btgt);
17420 + au_hn_imtx_unlock(a->src_hinode);
17421 + au_set_dbdiropq(a->src_dentry, a->src_bdiropq);
17423 + RevertFailure("remove diropq %.*s", AuDLNPair(a->src_dentry));
17426 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
17430 + a->h_path.dentry = au_lkup_one(&a->src_dentry->d_name, a->src_h_parent,
17431 + a->br, /*nd*/NULL);
17432 + rerr = PTR_ERR(a->h_path.dentry);
17433 + if (IS_ERR(a->h_path.dentry)) {
17434 + RevertFailure("au_lkup_one %.*s", AuDLNPair(a->src_dentry));
17438 + rerr = vfsub_rename(a->dst_h_dir,
17439 + au_h_dptr(a->src_dentry, a->btgt),
17440 + a->src_h_dir, &a->h_path);
17441 + d_drop(a->h_path.dentry);
17442 + dput(a->h_path.dentry);
17443 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
17445 + RevertFailure("rename %.*s", AuDLNPair(a->src_dentry));
17448 +static void au_ren_rev_cpup(int err, struct au_ren_args *a)
17452 + a->h_path.dentry = a->dst_h_dentry;
17453 + rerr = vfsub_unlink(a->dst_h_dir, &a->h_path, /*force*/0);
17454 + au_set_h_dptr(a->src_dentry, a->btgt, NULL);
17455 + au_set_dbstart(a->src_dentry, a->src_bstart);
17457 + RevertFailure("unlink %.*s", AuDLNPair(a->dst_h_dentry));
17460 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
17464 + a->h_path.dentry = au_lkup_one(&a->dst_dentry->d_name, a->dst_h_parent,
17465 + a->br, /*nd*/NULL);
17466 + rerr = PTR_ERR(a->h_path.dentry);
17467 + if (IS_ERR(a->h_path.dentry)) {
17468 + RevertFailure("lookup %.*s", AuDLNPair(a->dst_dentry));
17471 + if (a->h_path.dentry->d_inode) {
17472 + d_drop(a->h_path.dentry);
17473 + dput(a->h_path.dentry);
17477 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path);
17478 + d_drop(a->h_path.dentry);
17479 + dput(a->h_path.dentry);
17481 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
17483 + RevertFailure("rename %.*s", AuDLNPair(a->h_dst));
17486 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
17490 + a->h_path.dentry = a->src_wh_dentry;
17491 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
17492 + au_set_dbwh(a->src_dentry, a->src_bwh);
17494 + RevertFailure("unlink %.*s", AuDLNPair(a->src_wh_dentry));
17496 +#undef RevertFailure
17498 +/* ---------------------------------------------------------------------- */
17501 + * when we have to copyup the renaming entry, do it with the rename-target name
17502 + * in order to minimize the cost (the later actual rename is unnecessary).
17503 + * otherwise rename it on the target branch.
17505 +static int au_ren_or_cpup(struct au_ren_args *a)
17508 + struct dentry *d;
17510 + d = a->src_dentry;
17511 + if (au_dbstart(d) == a->btgt) {
17512 + a->h_path.dentry = a->dst_h_dentry;
17513 + if (au_ftest_ren(a->flags, DIROPQ)
17514 + && au_dbdiropq(d) == a->btgt)
17515 + au_fclr_ren(a->flags, DIROPQ);
17516 + AuDebugOn(au_dbstart(d) != a->btgt);
17517 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
17518 + a->dst_h_dir, &a->h_path);
17520 + struct mutex *h_mtx = &a->src_h_dentry->d_inode->i_mutex;
17521 + struct file *h_file;
17523 + au_fset_ren(a->flags, CPUP);
17524 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
17525 + au_set_dbstart(d, a->btgt);
17526 + au_set_h_dptr(d, a->btgt, dget(a->dst_h_dentry));
17527 + h_file = au_h_open_pre(d, a->src_bstart);
17528 + if (IS_ERR(h_file)) {
17529 + err = PTR_ERR(h_file);
17532 + err = au_sio_cpup_single(d, a->btgt, a->src_bstart, -1,
17533 + !AuCpup_DTIME, a->dst_parent);
17534 + mutex_unlock(h_mtx);
17535 + au_h_open_post(d, a->src_bstart, h_file);
17537 + d = a->dst_dentry;
17538 + au_set_h_dptr(d, a->btgt, NULL);
17539 + au_update_dbstart(d);
17541 + au_set_h_dptr(d, a->btgt, NULL);
17542 + au_set_dbstart(d, a->src_bstart);
17545 + if (!err && a->h_dst)
17546 + /* it will be set to dinfo later */
17552 +/* cf. aufs_rmdir() */
17553 +static int au_ren_del_whtmp(struct au_ren_args *a)
17556 + struct inode *dir;
17558 + dir = a->dst_dir;
17559 + SiMustAnyLock(dir->i_sb);
17560 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
17561 + au_sbi(dir->i_sb)->si_dirwh)
17562 + || au_test_fs_remote(a->h_dst->d_sb)) {
17563 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
17564 + if (unlikely(err))
17565 + pr_warning("failed removing whtmp dir %.*s (%d), "
17566 + "ignored.\n", AuDLNPair(a->h_dst), err);
17568 + au_nhash_wh_free(&a->thargs->whlist);
17569 + a->thargs->whlist = a->whlist;
17570 + a->whlist.nh_num = 0;
17571 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
17573 + a->thargs = NULL;
17579 +/* make it 'opaque' dir. */
17580 +static int au_ren_diropq(struct au_ren_args *a)
17583 + struct dentry *diropq;
17586 + a->src_bdiropq = au_dbdiropq(a->src_dentry);
17587 + a->src_hinode = au_hi(a->src_inode, a->btgt);
17588 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
17589 + diropq = au_diropq_create(a->src_dentry, a->btgt);
17590 + au_hn_imtx_unlock(a->src_hinode);
17591 + if (IS_ERR(diropq))
17592 + err = PTR_ERR(diropq);
17598 +static int do_rename(struct au_ren_args *a)
17601 + struct dentry *d, *h_d;
17603 + /* prepare workqueue args for asynchronous rmdir */
17604 + h_d = a->dst_h_dentry;
17605 + if (au_ftest_ren(a->flags, ISDIR) && h_d->d_inode) {
17607 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb, GFP_NOFS);
17608 + if (unlikely(!a->thargs))
17610 + a->h_dst = dget(h_d);
17613 + /* create whiteout for src_dentry */
17614 + if (au_ftest_ren(a->flags, WHSRC)) {
17615 + a->src_bwh = au_dbwh(a->src_dentry);
17616 + AuDebugOn(a->src_bwh >= 0);
17618 + = au_wh_create(a->src_dentry, a->btgt, a->src_h_parent);
17619 + err = PTR_ERR(a->src_wh_dentry);
17620 + if (IS_ERR(a->src_wh_dentry))
17624 + /* lookup whiteout for dentry */
17625 + if (au_ftest_ren(a->flags, WHDST)) {
17626 + h_d = au_wh_lkup(a->dst_h_parent, &a->dst_dentry->d_name,
17628 + err = PTR_ERR(h_d);
17631 + if (!h_d->d_inode)
17634 + a->dst_wh_dentry = h_d;
17637 + /* rename dentry to tmpwh */
17639 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
17640 + if (unlikely(err))
17643 + d = a->dst_dentry;
17644 + au_set_h_dptr(d, a->btgt, NULL);
17645 + err = au_lkup_neg(d, a->btgt);
17646 + if (unlikely(err))
17648 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
17652 + if (a->dst_h_dentry->d_inode && a->src_bstart != a->btgt) {
17653 + struct mutex *h_mtx = &a->src_h_dentry->d_inode->i_mutex;
17654 + struct file *h_file;
17656 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
17657 + AuDebugOn(au_dbstart(a->src_dentry) != a->src_bstart);
17658 + h_file = au_h_open_pre(a->src_dentry, a->src_bstart);
17659 + if (IS_ERR(h_file)) {
17660 + err = PTR_ERR(h_file);
17663 + err = au_sio_cpup_simple(a->src_dentry, a->btgt, -1,
17665 + mutex_unlock(h_mtx);
17666 + au_h_open_post(a->src_dentry, a->src_bstart, h_file);
17667 + if (unlikely(err))
17671 + /* rename by vfs_rename or cpup */
17672 + d = a->dst_dentry;
17673 + if (au_ftest_ren(a->flags, ISDIR)
17674 + && (a->dst_wh_dentry
17675 + || au_dbdiropq(d) == a->btgt
17676 + /* hide the lower to keep xino */
17677 + || a->btgt < au_dbend(d)
17678 + || au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ)))
17679 + au_fset_ren(a->flags, DIROPQ);
17680 + err = au_ren_or_cpup(a);
17681 + if (unlikely(err))
17682 + /* leave the copied-up one */
17685 + /* make dir opaque */
17686 + if (au_ftest_ren(a->flags, DIROPQ)) {
17687 + err = au_ren_diropq(a);
17688 + if (unlikely(err))
17692 + /* update target timestamps */
17693 + AuDebugOn(au_dbstart(a->src_dentry) != a->btgt);
17694 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
17695 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
17696 + a->src_inode->i_ctime = a->h_path.dentry->d_inode->i_ctime;
17698 + /* remove whiteout for dentry */
17699 + if (a->dst_wh_dentry) {
17700 + a->h_path.dentry = a->dst_wh_dentry;
17701 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
17703 + if (unlikely(err))
17707 + /* remove whtmp */
17709 + au_ren_del_whtmp(a); /* ignore this error */
17712 + goto out_success;
17715 + if (au_ftest_ren(a->flags, DIROPQ))
17716 + au_ren_rev_diropq(err, a);
17718 + if (!au_ftest_ren(a->flags, CPUP))
17719 + au_ren_rev_rename(err, a);
17721 + au_ren_rev_cpup(err, a);
17725 + au_ren_rev_whtmp(err, a);
17727 + dput(a->dst_wh_dentry);
17728 + a->dst_wh_dentry = NULL;
17730 + if (a->src_wh_dentry)
17731 + au_ren_rev_whsrc(err, a);
17733 + dput(a->src_wh_dentry);
17734 + dput(a->dst_wh_dentry);
17738 + au_whtmp_rmdir_free(a->thargs);
17739 + a->thargs = NULL;
17745 +/* ---------------------------------------------------------------------- */
17748 + * test if @dentry dir can be rename destination or not.
17749 + * success means, it is a logically empty dir.
17751 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
17753 + return au_test_empty(dentry, whlist);
17757 + * test if @dentry dir can be rename source or not.
17758 + * if it can, return 0 and @children is filled.
17760 + * - it is a logically empty dir.
17761 + * - or, it exists on writable branch and has no children including whiteouts
17762 + * on the lower branch.
17764 +static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt)
17767 + unsigned int rdhash;
17768 + aufs_bindex_t bstart;
17770 + bstart = au_dbstart(dentry);
17771 + if (bstart != btgt) {
17772 + struct au_nhash whlist;
17774 + SiMustAnyLock(dentry->d_sb);
17775 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
17777 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
17779 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
17780 + if (unlikely(err))
17782 + err = au_test_empty(dentry, &whlist);
17783 + au_nhash_wh_free(&whlist);
17787 + if (bstart == au_dbtaildir(dentry))
17788 + return 0; /* success */
17790 + err = au_test_empty_lower(dentry);
17793 + if (err == -ENOTEMPTY) {
17794 + AuWarn1("renaming dir who has child(ren) on multiple branches,"
17795 + " is not supported\n");
17801 +/* side effect: sets whlist and h_dentry */
17802 +static int au_ren_may_dir(struct au_ren_args *a)
17805 + unsigned int rdhash;
17806 + struct dentry *d;
17808 + d = a->dst_dentry;
17809 + SiMustAnyLock(d->d_sb);
17812 + if (au_ftest_ren(a->flags, ISDIR) && a->dst_inode) {
17813 + rdhash = au_sbi(d->d_sb)->si_rdhash;
17815 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
17816 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
17817 + if (unlikely(err))
17820 + au_set_dbstart(d, a->dst_bstart);
17821 + err = may_rename_dstdir(d, &a->whlist);
17822 + au_set_dbstart(d, a->btgt);
17824 + a->dst_h_dentry = au_h_dptr(d, au_dbstart(d));
17825 + if (unlikely(err))
17828 + d = a->src_dentry;
17829 + a->src_h_dentry = au_h_dptr(d, au_dbstart(d));
17830 + if (au_ftest_ren(a->flags, ISDIR)) {
17831 + err = may_rename_srcdir(d, a->btgt);
17832 + if (unlikely(err)) {
17833 + au_nhash_wh_free(&a->whlist);
17834 + a->whlist.nh_num = 0;
17841 +/* ---------------------------------------------------------------------- */
17844 + * simple tests for rename.
17845 + * following the checks in vfs, plus the parent-child relationship.
17847 +static int au_may_ren(struct au_ren_args *a)
17850 + struct inode *h_inode;
17852 + if (a->src_bstart == a->btgt) {
17853 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
17854 + au_ftest_ren(a->flags, ISDIR));
17855 + if (unlikely(err))
17858 + if (unlikely(a->src_h_dentry == a->h_trap))
17863 + if (a->dst_bstart != a->btgt)
17866 + err = -ENOTEMPTY;
17867 + if (unlikely(a->dst_h_dentry == a->h_trap))
17871 + h_inode = a->dst_h_dentry->d_inode;
17872 + isdir = !!au_ftest_ren(a->flags, ISDIR);
17873 + if (!a->dst_dentry->d_inode) {
17874 + if (unlikely(h_inode))
17876 + err = au_may_add(a->dst_dentry, a->btgt, a->dst_h_parent,
17879 + if (unlikely(!h_inode || !h_inode->i_nlink))
17881 + err = au_may_del(a->dst_dentry, a->btgt, a->dst_h_parent,
17883 + if (unlikely(err))
17888 + if (unlikely(err == -ENOENT || err == -EEXIST))
17894 +/* ---------------------------------------------------------------------- */
17899 + * - src_dir and dir by lock_rename()
17900 + * - inode if exitsts
17903 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
17905 + * + di_write_lock2_child()
17906 + * + di_write_lock_child()
17907 + * + ii_write_lock_child()
17908 + * + di_write_lock_child2()
17909 + * + ii_write_lock_child2()
17910 + * + src_parent and parent
17911 + * + di_write_lock_parent()
17912 + * + ii_write_lock_parent()
17913 + * + di_write_lock_parent2()
17914 + * + ii_write_lock_parent2()
17915 + * + lower src_dir and dir by vfsub_lock_rename()
17916 + * + verify the every relationships between child and parent. if any
17917 + * of them failed, unlock all and return -EBUSY.
17919 +static void au_ren_unlock(struct au_ren_args *a)
17921 + struct super_block *sb;
17923 + sb = a->dst_dentry->d_sb;
17924 + if (au_ftest_ren(a->flags, MNT_WRITE))
17925 + mnt_drop_write(a->br->br_mnt);
17926 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
17927 + a->dst_h_parent, a->dst_hdir);
17930 +static int au_ren_lock(struct au_ren_args *a)
17933 + unsigned int udba;
17936 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
17937 + a->src_hdir = au_hi(a->src_dir, a->btgt);
17938 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
17939 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
17940 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
17941 + a->dst_h_parent, a->dst_hdir);
17942 + udba = au_opt_udba(a->src_dentry->d_sb);
17943 + if (unlikely(a->src_hdir->hi_inode != a->src_h_parent->d_inode
17944 + || a->dst_hdir->hi_inode != a->dst_h_parent->d_inode))
17945 + err = au_busy_or_stale();
17946 + if (!err && au_dbstart(a->src_dentry) == a->btgt)
17947 + err = au_h_verify(a->src_h_dentry, udba,
17948 + a->src_h_parent->d_inode, a->src_h_parent,
17950 + if (!err && au_dbstart(a->dst_dentry) == a->btgt)
17951 + err = au_h_verify(a->dst_h_dentry, udba,
17952 + a->dst_h_parent->d_inode, a->dst_h_parent,
17955 + err = mnt_want_write(a->br->br_mnt);
17956 + if (unlikely(err))
17958 + au_fset_ren(a->flags, MNT_WRITE);
17959 + goto out; /* success */
17962 + err = au_busy_or_stale();
17965 + au_ren_unlock(a);
17970 +/* ---------------------------------------------------------------------- */
17972 +static void au_ren_refresh_dir(struct au_ren_args *a)
17974 + struct inode *dir;
17976 + dir = a->dst_dir;
17977 + dir->i_version++;
17978 + if (au_ftest_ren(a->flags, ISDIR)) {
17979 + /* is this updating defined in POSIX? */
17980 + au_cpup_attr_timesizes(a->src_inode);
17981 + au_cpup_attr_nlink(dir, /*force*/1);
17984 + if (au_ibstart(dir) == a->btgt)
17985 + au_cpup_attr_timesizes(dir);
17987 + if (au_ftest_ren(a->flags, ISSAMEDIR))
17990 + dir = a->src_dir;
17991 + dir->i_version++;
17992 + if (au_ftest_ren(a->flags, ISDIR))
17993 + au_cpup_attr_nlink(dir, /*force*/1);
17994 + if (au_ibstart(dir) == a->btgt)
17995 + au_cpup_attr_timesizes(dir);
17998 +static void au_ren_refresh(struct au_ren_args *a)
18000 + aufs_bindex_t bend, bindex;
18001 + struct dentry *d, *h_d;
18002 + struct inode *i, *h_i;
18003 + struct super_block *sb;
18005 + d = a->dst_dentry;
18008 + /* already dget-ed by au_ren_or_cpup() */
18009 + au_set_h_dptr(d, a->btgt, a->h_dst);
18011 + i = a->dst_inode;
18013 + if (!au_ftest_ren(a->flags, ISDIR))
18014 + vfsub_drop_nlink(i);
18016 + vfsub_dead_dir(i);
18017 + au_cpup_attr_timesizes(i);
18019 + au_update_dbrange(d, /*do_put_zero*/1);
18022 + for (bindex = au_dbstart(d); bindex < bend; bindex++)
18023 + au_set_h_dptr(d, bindex, NULL);
18024 + bend = au_dbend(d);
18025 + for (bindex = a->btgt + 1; bindex <= bend; bindex++)
18026 + au_set_h_dptr(d, bindex, NULL);
18027 + au_update_dbrange(d, /*do_put_zero*/0);
18030 + d = a->src_dentry;
18031 + au_set_dbwh(d, -1);
18032 + bend = au_dbend(d);
18033 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
18034 + h_d = au_h_dptr(d, bindex);
18036 + au_set_h_dptr(d, bindex, NULL);
18038 + au_set_dbend(d, a->btgt);
18041 + i = a->src_inode;
18042 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
18043 + return; /* success */
18045 + bend = au_ibend(i);
18046 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
18047 + h_i = au_h_iptr(i, bindex);
18049 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
18050 + /* ignore this error */
18051 + au_set_h_iptr(i, bindex, NULL, 0);
18054 + au_set_ibend(i, a->btgt);
18057 +/* ---------------------------------------------------------------------- */
18059 +/* mainly for link(2) and rename(2) */
18060 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
18062 + aufs_bindex_t bdiropq, bwh;
18063 + struct dentry *parent;
18064 + struct au_branch *br;
18066 + parent = dentry->d_parent;
18067 + IMustLock(parent->d_inode); /* dir is locked */
18069 + bdiropq = au_dbdiropq(parent);
18070 + bwh = au_dbwh(dentry);
18071 + br = au_sbr(dentry->d_sb, btgt);
18072 + if (au_br_rdonly(br)
18073 + || (0 <= bdiropq && bdiropq < btgt)
18074 + || (0 <= bwh && bwh < btgt))
18077 + AuDbg("btgt %d\n", btgt);
18081 +/* sets src_bstart, dst_bstart and btgt */
18082 +static int au_ren_wbr(struct au_ren_args *a)
18085 + struct au_wr_dir_args wr_dir_args = {
18086 + /* .force_btgt = -1, */
18087 + .flags = AuWrDir_ADD_ENTRY
18090 + a->src_bstart = au_dbstart(a->src_dentry);
18091 + a->dst_bstart = au_dbstart(a->dst_dentry);
18092 + if (au_ftest_ren(a->flags, ISDIR))
18093 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
18094 + wr_dir_args.force_btgt = a->src_bstart;
18095 + if (a->dst_inode && a->dst_bstart < a->src_bstart)
18096 + wr_dir_args.force_btgt = a->dst_bstart;
18097 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
18098 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
18104 +static void au_ren_dt(struct au_ren_args *a)
18106 + a->h_path.dentry = a->src_h_parent;
18107 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
18108 + if (!au_ftest_ren(a->flags, ISSAMEDIR)) {
18109 + a->h_path.dentry = a->dst_h_parent;
18110 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
18113 + au_fclr_ren(a->flags, DT_DSTDIR);
18114 + if (!au_ftest_ren(a->flags, ISDIR))
18117 + a->h_path.dentry = a->src_h_dentry;
18118 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
18119 + if (a->dst_h_dentry->d_inode) {
18120 + au_fset_ren(a->flags, DT_DSTDIR);
18121 + a->h_path.dentry = a->dst_h_dentry;
18122 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
18126 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
18128 + struct dentry *h_d;
18129 + struct mutex *h_mtx;
18131 + au_dtime_revert(a->src_dt + AuPARENT);
18132 + if (!au_ftest_ren(a->flags, ISSAMEDIR))
18133 + au_dtime_revert(a->dst_dt + AuPARENT);
18135 + if (au_ftest_ren(a->flags, ISDIR) && err != -EIO) {
18136 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
18137 + h_mtx = &h_d->d_inode->i_mutex;
18138 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
18139 + au_dtime_revert(a->src_dt + AuCHILD);
18140 + mutex_unlock(h_mtx);
18142 + if (au_ftest_ren(a->flags, DT_DSTDIR)) {
18143 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
18144 + h_mtx = &h_d->d_inode->i_mutex;
18145 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
18146 + au_dtime_revert(a->dst_dt + AuCHILD);
18147 + mutex_unlock(h_mtx);
18152 +/* ---------------------------------------------------------------------- */
18154 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
18155 + struct inode *_dst_dir, struct dentry *_dst_dentry)
18158 + /* reduce stack space */
18159 + struct au_ren_args *a;
18161 + AuDbg("%.*s, %.*s\n", AuDLNPair(_src_dentry), AuDLNPair(_dst_dentry));
18162 + IMustLock(_src_dir);
18163 + IMustLock(_dst_dir);
18166 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
18167 + a = kzalloc(sizeof(*a), GFP_NOFS);
18168 + if (unlikely(!a))
18171 + a->src_dir = _src_dir;
18172 + a->src_dentry = _src_dentry;
18173 + a->src_inode = a->src_dentry->d_inode;
18174 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
18175 + a->dst_dir = _dst_dir;
18176 + a->dst_dentry = _dst_dentry;
18177 + a->dst_inode = a->dst_dentry->d_inode;
18178 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
18179 + if (a->dst_inode) {
18180 + IMustLock(a->dst_inode);
18181 + au_igrab(a->dst_inode);
18185 + flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
18186 + if (S_ISDIR(a->src_inode->i_mode)) {
18187 + au_fset_ren(a->flags, ISDIR);
18188 + if (unlikely(a->dst_inode && !S_ISDIR(a->dst_inode->i_mode)))
18190 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
18191 + AuLock_DIR | flags);
18193 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
18195 + if (unlikely(err))
18198 + err = au_d_hashed_positive(a->src_dentry);
18199 + if (unlikely(err))
18202 + if (a->dst_inode) {
18204 + * If it is a dir, VFS unhash dst_dentry before this
18205 + * function. It means we cannot rely upon d_unhashed().
18207 + if (unlikely(!a->dst_inode->i_nlink))
18209 + if (!S_ISDIR(a->dst_inode->i_mode)) {
18210 + err = au_d_hashed_positive(a->dst_dentry);
18211 + if (unlikely(err))
18213 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
18215 + } else if (unlikely(d_unhashed(a->dst_dentry)))
18219 + * is it possible?
18220 + * yes, it happend (in linux-3.3-rcN) but I don't know why.
18221 + * there may exist a problem somewhere else.
18224 + if (unlikely(a->dst_parent->d_inode == a->src_dentry->d_inode))
18227 + au_fset_ren(a->flags, ISSAMEDIR); /* temporary */
18228 + di_write_lock_parent(a->dst_parent);
18230 + /* which branch we process */
18231 + err = au_ren_wbr(a);
18232 + if (unlikely(err < 0))
18234 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
18235 + a->h_path.mnt = a->br->br_mnt;
18237 + /* are they available to be renamed */
18238 + err = au_ren_may_dir(a);
18239 + if (unlikely(err))
18240 + goto out_children;
18242 + /* prepare the writable parent dir on the same branch */
18243 + if (a->dst_bstart == a->btgt) {
18244 + au_fset_ren(a->flags, WHDST);
18246 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
18247 + if (unlikely(err))
18248 + goto out_children;
18251 + if (a->src_dir != a->dst_dir) {
18253 + * this temporary unlock is safe,
18254 + * because both dir->i_mutex are locked.
18256 + di_write_unlock(a->dst_parent);
18257 + di_write_lock_parent(a->src_parent);
18258 + err = au_wr_dir_need_wh(a->src_dentry,
18259 + au_ftest_ren(a->flags, ISDIR),
18261 + di_write_unlock(a->src_parent);
18262 + di_write_lock2_parent(a->src_parent, a->dst_parent, /*isdir*/1);
18263 + au_fclr_ren(a->flags, ISSAMEDIR);
18265 + err = au_wr_dir_need_wh(a->src_dentry,
18266 + au_ftest_ren(a->flags, ISDIR),
18268 + if (unlikely(err < 0))
18269 + goto out_children;
18271 + au_fset_ren(a->flags, WHSRC);
18273 + /* lock them all */
18274 + err = au_ren_lock(a);
18275 + if (unlikely(err))
18276 + goto out_children;
18278 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
18279 + err = au_may_ren(a);
18280 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
18281 + err = -ENAMETOOLONG;
18282 + if (unlikely(err))
18285 + /* store timestamps to be revertible */
18289 + err = do_rename(a);
18290 + if (unlikely(err))
18293 + /* update dir attributes */
18294 + au_ren_refresh_dir(a);
18296 + /* dput/iput all lower dentries */
18297 + au_ren_refresh(a);
18299 + goto out_hdir; /* success */
18302 + au_ren_rev_dt(err, a);
18304 + au_ren_unlock(a);
18306 + au_nhash_wh_free(&a->whlist);
18307 + if (err && a->dst_inode && a->dst_bstart != a->btgt) {
18308 + AuDbg("bstart %d, btgt %d\n", a->dst_bstart, a->btgt);
18309 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
18310 + au_set_dbstart(a->dst_dentry, a->dst_bstart);
18314 + d_move(a->src_dentry, a->dst_dentry);
18316 + au_update_dbstart(a->dst_dentry);
18317 + if (!a->dst_inode)
18318 + d_drop(a->dst_dentry);
18320 + if (au_ftest_ren(a->flags, ISSAMEDIR))
18321 + di_write_unlock(a->dst_parent);
18323 + di_write_unlock2(a->src_parent, a->dst_parent);
18325 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
18327 + iput(a->dst_inode);
18329 + au_whtmp_rmdir_free(a->thargs);
18335 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
18336 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
18337 +++ linux/fs/aufs/Kconfig 2012-03-19 12:24:13.679801090 +0100
18340 + tristate "Aufs (Advanced multi layered unification filesystem) support"
18341 + depends on EXPERIMENTAL
18343 + Aufs is a stackable unification filesystem such as Unionfs,
18344 + which unifies several directories and provides a merged single
18346 + In the early days, aufs was entirely re-designed and
18347 + re-implemented Unionfs Version 1.x series. Introducing many
18348 + original ideas, approaches and improvements, it becomes totally
18349 + different from Unionfs while keeping the basic features.
18353 + prompt "Maximum number of branches"
18354 + default AUFS_BRANCH_MAX_127
18356 + Specifies the maximum number of branches (or member directories)
18357 + in a single aufs. The larger value consumes more system
18358 + resources and has a minor impact to performance.
18359 +config AUFS_BRANCH_MAX_127
18362 + Specifies the maximum number of branches (or member directories)
18363 + in a single aufs. The larger value consumes more system
18364 + resources and has a minor impact to performance.
18365 +config AUFS_BRANCH_MAX_511
18368 + Specifies the maximum number of branches (or member directories)
18369 + in a single aufs. The larger value consumes more system
18370 + resources and has a minor impact to performance.
18371 +config AUFS_BRANCH_MAX_1023
18374 + Specifies the maximum number of branches (or member directories)
18375 + in a single aufs. The larger value consumes more system
18376 + resources and has a minor impact to performance.
18377 +config AUFS_BRANCH_MAX_32767
18380 + Specifies the maximum number of branches (or member directories)
18381 + in a single aufs. The larger value consumes more system
18382 + resources and has a minor impact to performance.
18385 +config AUFS_SBILIST
18387 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
18390 + Automatic configuration for internal use.
18391 + When aufs supports Magic SysRq or /proc, enabled automatically.
18393 +config AUFS_HNOTIFY
18394 + bool "Detect direct branch access (bypassing aufs)"
18396 + If you want to modify files on branches directly, eg. bypassing aufs,
18397 + and want aufs to detect the changes of them fully, then enable this
18398 + option and use 'udba=notify' mount option.
18399 + Currently there is only one available configuration, "fsnotify".
18400 + It will have a negative impact to the performance.
18401 + See detail in aufs.5.
18404 + prompt "method" if AUFS_HNOTIFY
18405 + default AUFS_HFSNOTIFY
18406 +config AUFS_HFSNOTIFY
18411 +config AUFS_EXPORT
18412 + bool "NFS-exportable aufs"
18413 + depends on EXPORTFS
18415 + If you want to export your mounted aufs via NFS, then enable this
18416 + option. There are several requirements for this configuration.
18417 + See detail in aufs.5.
18419 +config AUFS_INO_T_64
18421 + depends on AUFS_EXPORT
18422 + depends on 64BIT && !(ALPHA || S390)
18425 + Automatic configuration for internal use.
18426 + /* typedef unsigned long/int __kernel_ino_t */
18427 + /* alpha and s390x are int */
18430 + bool "Readdir in userspace"
18432 + Aufs has two methods to provide a merged view for a directory,
18433 + by a user-space library and by kernel-space natively. The latter
18434 + is always enabled but sometimes large and slow.
18435 + If you enable this option, install the library in aufs2-util
18436 + package, and set some environment variables for your readdir(3),
18437 + then the work will be handled in user-space which generally
18438 + shows better performance in most cases.
18439 + See detail in aufs.5.
18441 +config AUFS_PROC_MAP
18442 + bool "support for /proc/maps and lsof(1)"
18443 + depends on PROC_FS
18445 + When you issue mmap(2) in aufs, it is actually a direct mmap(2)
18446 + call to the file on the branch fs since the file in aufs is
18447 + purely virtual. And the file path printed in /proc/maps (and
18448 + others) will be the path on the branch fs. In most cases, it
18449 + does no harm. But some utilities like lsof(1) may confuse since
18450 + the utility or user may expect the file path in aufs to be
18452 + To address this issue, aufs provides a patch which introduces a
18453 + new member called vm_prfile into struct vm_are_struct. The patch
18454 + is meaningless without enabling this configuration since nobody
18455 + sets the new vm_prfile member.
18456 + If you don't apply the patch, then enabling this configuration
18457 + will cause a compile error.
18458 + This approach is fragile since if someone else make some changes
18459 + around vm_file, then vm_prfile may not work anymore. As a
18460 + workaround such case, aufs provides this configuration. If you
18461 + disable it, then lsof(1) may produce incorrect result but the
18462 + problem will be gone even if the aufs patch is applied (I hope).
18464 +config AUFS_SP_IATTR
18465 + bool "Respect the attributes (mtime/ctime mainly) of special files"
18467 + When you write something to a special file, some attributes of it
18468 + (mtime/ctime mainly) may be updated. Generally such updates are
18469 + less important (actually some device drivers and NFS ignore
18470 + it). But some applications (such like test program) requires
18471 + such updates. If you need these updates, then enable this
18472 + configuration which introduces some overhead.
18473 + Currently this configuration handles FIFO only.
18476 + bool "Show whiteouts"
18478 + If you want to make the whiteouts in aufs visible, then enable
18479 + this option and specify 'shwh' mount option. Although it may
18480 + sounds like philosophy or something, but in technically it
18481 + simply shows the name of whiteout with keeping its behaviour.
18483 +config AUFS_BR_RAMFS
18484 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
18486 + If you want to use ramfs as an aufs branch fs, then enable this
18487 + option. Generally tmpfs is recommended.
18488 + Aufs prohibited them to be a branch fs by default, because
18489 + initramfs becomes unusable after switch_root or something
18490 + generally. If you sets initramfs as an aufs branch and boot your
18491 + system by switch_root, you will meet a problem easily since the
18492 + files in initramfs may be inaccessible.
18493 + Unless you are going to use ramfs as an aufs branch fs without
18494 + switch_root or something, leave it N.
18496 +config AUFS_BR_FUSE
18497 + bool "Fuse fs as an aufs branch"
18498 + depends on FUSE_FS
18501 + If you want to use fuse-based userspace filesystem as an aufs
18502 + branch fs, then enable this option.
18503 + It implements the internal poll(2) operation which is
18504 + implemented by fuse only (curretnly).
18509 + Automatic configuration for internal use.
18511 +config AUFS_BR_HFSPLUS
18512 + bool "Hfsplus as an aufs branch"
18513 + depends on HFSPLUS_FS
18516 + If you want to use hfsplus fs as an aufs branch fs, then enable
18517 + this option. This option introduces a small overhead at
18518 + copying-up a file on hfsplus.
18520 +config AUFS_BDEV_LOOP
18522 + depends on BLK_DEV_LOOP
18525 + Automatic configuration for internal use.
18526 + Convert =[ym] into =y.
18529 + bool "Debug aufs"
18531 + Enable this to compile aufs internal debug code.
18532 + It will have a negative impact to the performance.
18534 +config AUFS_MAGIC_SYSRQ
18536 + depends on AUFS_DEBUG && MAGIC_SYSRQ
18539 + Automatic configuration for internal use.
18540 + When aufs supports Magic SysRq, enabled automatically.
18542 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
18543 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
18544 +++ linux/fs/aufs/loop.c 2012-03-19 12:24:13.683134508 +0100
18547 + * Copyright (C) 2005-2012 Junjiro R. Okajima
18549 + * This program, aufs is free software; you can redistribute it and/or modify
18550 + * it under the terms of the GNU General Public License as published by
18551 + * the Free Software Foundation; either version 2 of the License, or
18552 + * (at your option) any later version.
18554 + * This program is distributed in the hope that it will be useful,
18555 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18556 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18557 + * GNU General Public License for more details.
18559 + * You should have received a copy of the GNU General Public License
18560 + * along with this program; if not, write to the Free Software
18561 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18565 + * support for loopback block device as a branch
18568 +#include <linux/loop.h>
18572 + * test if two lower dentries have overlapping branches.
18574 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
18576 + struct super_block *h_sb;
18577 + struct loop_device *l;
18579 + h_sb = h_adding->d_sb;
18580 + if (MAJOR(h_sb->s_dev) != LOOP_MAJOR)
18583 + l = h_sb->s_bdev->bd_disk->private_data;
18584 + h_adding = l->lo_backing_file->f_dentry;
18586 + * h_adding can be local NFS.
18587 + * in this case aufs cannot detect the loop.
18589 + if (unlikely(h_adding->d_sb == sb))
18591 + return !!au_test_subdir(h_adding, sb->s_root);
18594 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
18595 +int au_test_loopback_kthread(void)
18598 + struct task_struct *tsk = current;
18601 + if (tsk->flags & PF_KTHREAD) {
18602 + const char c = tsk->comm[4];
18603 + ret = ('0' <= c && c <= '9'
18604 + && !strncmp(tsk->comm, "loop", 4));
18610 +/* ---------------------------------------------------------------------- */
18612 +#define au_warn_loopback_step 16
18613 +static int au_warn_loopback_nelem = au_warn_loopback_step;
18614 +static unsigned long *au_warn_loopback_array;
18616 +void au_warn_loopback(struct super_block *h_sb)
18618 + int i, new_nelem;
18619 + unsigned long *a, magic;
18620 + static DEFINE_SPINLOCK(spin);
18622 + magic = h_sb->s_magic;
18623 + spin_lock(&spin);
18624 + a = au_warn_loopback_array;
18625 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
18626 + if (a[i] == magic) {
18627 + spin_unlock(&spin);
18631 + /* h_sb is new to us, print it */
18632 + if (i < au_warn_loopback_nelem) {
18637 + /* expand the array */
18638 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
18639 + a = au_kzrealloc(au_warn_loopback_array,
18640 + au_warn_loopback_nelem * sizeof(unsigned long),
18641 + new_nelem * sizeof(unsigned long), GFP_ATOMIC);
18643 + au_warn_loopback_nelem = new_nelem;
18644 + au_warn_loopback_array = a;
18649 + spin_unlock(&spin);
18650 + AuWarn1("realloc failed, ignored\n");
18654 + spin_unlock(&spin);
18655 + pr_warning("you may want to try another patch for loopback file "
18656 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
18659 +int au_loopback_init(void)
18662 + struct super_block *sb __maybe_unused;
18664 + AuDebugOn(sizeof(sb->s_magic) != sizeof(unsigned long));
18667 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
18668 + sizeof(unsigned long), GFP_NOFS);
18669 + if (unlikely(!au_warn_loopback_array))
18675 +void au_loopback_fin(void)
18677 + kfree(au_warn_loopback_array);
18679 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
18680 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
18681 +++ linux/fs/aufs/loop.h 2012-03-19 12:24:13.683134508 +0100
18684 + * Copyright (C) 2005-2012 Junjiro R. Okajima
18686 + * This program, aufs is free software; you can redistribute it and/or modify
18687 + * it under the terms of the GNU General Public License as published by
18688 + * the Free Software Foundation; either version 2 of the License, or
18689 + * (at your option) any later version.
18691 + * This program is distributed in the hope that it will be useful,
18692 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18693 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18694 + * GNU General Public License for more details.
18696 + * You should have received a copy of the GNU General Public License
18697 + * along with this program; if not, write to the Free Software
18698 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18702 + * support for loopback mount as a branch
18705 +#ifndef __AUFS_LOOP_H__
18706 +#define __AUFS_LOOP_H__
18711 +struct super_block;
18713 +#ifdef CONFIG_AUFS_BDEV_LOOP
18715 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
18716 +int au_test_loopback_kthread(void);
18717 +void au_warn_loopback(struct super_block *h_sb);
18719 +int au_loopback_init(void);
18720 +void au_loopback_fin(void);
18722 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
18723 + struct dentry *h_adding)
18724 +AuStubInt0(au_test_loopback_kthread, void)
18725 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
18727 +AuStubInt0(au_loopback_init, void)
18728 +AuStubVoid(au_loopback_fin, void)
18729 +#endif /* BLK_DEV_LOOP */
18731 +#endif /* __KERNEL__ */
18732 +#endif /* __AUFS_LOOP_H__ */
18733 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
18734 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
18735 +++ linux/fs/aufs/magic.mk 2012-03-19 12:24:13.683134508 +0100
18738 +# defined in ${srctree}/fs/fuse/inode.c
18740 +ifdef CONFIG_FUSE_FS
18741 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
18744 +# defined in ${srctree}/fs/ocfs2/ocfs2_fs.h
18746 +ifdef CONFIG_OCFS2_FS
18747 +ccflags-y += -DOCFS2_SUPER_MAGIC=0x7461636f
18750 +# defined in ${srctree}/fs/ocfs2/dlm/userdlm.h
18752 +ifdef CONFIG_OCFS2_FS_O2CB
18753 +ccflags-y += -DDLMFS_MAGIC=0x76a9f425
18756 +# defined in ${srctree}/fs/cifs/cifsfs.c
18758 +ifdef CONFIG_CIFS_FS
18759 +ccflags-y += -DCIFS_MAGIC_NUMBER=0xFF534D42
18762 +# defined in ${srctree}/fs/xfs/xfs_sb.h
18764 +ifdef CONFIG_XFS_FS
18765 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
18768 +# defined in ${srctree}/fs/configfs/mount.c
18770 +ifdef CONFIG_CONFIGFS_FS
18771 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
18774 +# defined in ${srctree}/fs/9p/v9fs.h
18776 +ifdef CONFIG_9P_FS
18777 +ccflags-y += -DV9FS_MAGIC=0x01021997
18780 +# defined in ${srctree}/fs/ubifs/ubifs.h
18782 +ifdef CONFIG_UBIFS_FS
18783 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
18786 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
18788 +ifdef CONFIG_HFSPLUS_FS
18789 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
18791 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
18792 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
18793 +++ linux/fs/aufs/Makefile 2012-03-19 12:24:13.679801090 +0100
18796 +include ${src}/magic.mk
18797 +ifeq (${CONFIG_AUFS_FS},m)
18798 +include ${src}/conf.mk
18800 +-include ${src}/priv_def.mk
18802 +# cf. include/linux/kernel.h
18804 +ccflags-y += -DDEBUG
18805 +# sparse requires the full pathname
18807 +ccflags-y += -include ${M}/../../include/linux/aufs_type.h
18809 +ccflags-y += -include ${srctree}/include/linux/aufs_type.h
18812 +obj-$(CONFIG_AUFS_FS) += aufs.o
18813 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
18814 + wkq.o vfsub.o dcsub.o \
18815 + cpup.o whout.o wbr_policy.o \
18816 + dinfo.o dentry.o \
18818 + finfo.o file.o f_op.o \
18820 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
18824 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
18825 +aufs-$(CONFIG_SYSFS) += sysfs.o
18826 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
18827 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
18828 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
18829 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
18830 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
18831 +aufs-$(CONFIG_AUFS_POLL) += poll.o
18832 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
18833 +aufs-$(CONFIG_AUFS_SP_IATTR) += f_op_sp.o
18834 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
18835 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
18836 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
18837 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
18838 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
18839 +++ linux/fs/aufs/module.c 2012-03-19 12:24:13.683134508 +0100
18842 + * Copyright (C) 2005-2012 Junjiro R. Okajima
18844 + * This program, aufs is free software; you can redistribute it and/or modify
18845 + * it under the terms of the GNU General Public License as published by
18846 + * the Free Software Foundation; either version 2 of the License, or
18847 + * (at your option) any later version.
18849 + * This program is distributed in the hope that it will be useful,
18850 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18851 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18852 + * GNU General Public License for more details.
18854 + * You should have received a copy of the GNU General Public License
18855 + * along with this program; if not, write to the Free Software
18856 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18860 + * module global variables and operations
18863 +#include <linux/module.h>
18864 +#include <linux/seq_file.h>
18867 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp)
18869 + if (new_sz <= nused)
18872 + p = krealloc(p, new_sz, gfp);
18874 + memset(p + nused, 0, new_sz - nused);
18878 +/* ---------------------------------------------------------------------- */
18883 +struct kmem_cache *au_cachep[AuCache_Last];
18884 +static int __init au_cache_init(void)
18886 + au_cachep[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
18887 + if (au_cachep[AuCache_DINFO])
18888 + /* SLAB_DESTROY_BY_RCU */
18889 + au_cachep[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
18890 + au_icntnr_init_once);
18891 + if (au_cachep[AuCache_ICNTNR])
18892 + au_cachep[AuCache_FINFO] = AuCacheCtor(au_finfo,
18893 + au_fi_init_once);
18894 + if (au_cachep[AuCache_FINFO])
18895 + au_cachep[AuCache_VDIR] = AuCache(au_vdir);
18896 + if (au_cachep[AuCache_VDIR])
18897 + au_cachep[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
18898 + if (au_cachep[AuCache_DEHSTR])
18904 +static void au_cache_fin(void)
18908 + /* excluding AuCache_HNOTIFY */
18909 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
18910 + for (i = 0; i < AuCache_HNOTIFY; i++)
18911 + if (au_cachep[i]) {
18912 + kmem_cache_destroy(au_cachep[i]);
18913 + au_cachep[i] = NULL;
18917 +/* ---------------------------------------------------------------------- */
18919 +int au_dir_roflags;
18921 +#ifdef CONFIG_AUFS_SBILIST
18923 + * iterate_supers_type() doesn't protect us from
18924 + * remounting (branch management)
18926 +struct au_splhead au_sbilist;
18929 +struct lock_class_key au_lc_key[AuLcKey_Last];
18932 + * functions for module interface.
18934 +MODULE_LICENSE("GPL");
18935 +/* MODULE_LICENSE("GPL v2"); */
18936 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
18937 +MODULE_DESCRIPTION(AUFS_NAME
18938 + " -- Advanced multi layered unification filesystem");
18939 +MODULE_VERSION(AUFS_VERSION);
18941 +/* this module parameter has no meaning when SYSFS is disabled */
18942 +int sysaufs_brs = 1;
18943 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
18944 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
18946 +/* ---------------------------------------------------------------------- */
18948 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
18950 +int au_seq_path(struct seq_file *seq, struct path *path)
18952 + return seq_path(seq, path, au_esc_chars);
18955 +/* ---------------------------------------------------------------------- */
18957 +static int __init aufs_init(void)
18962 + p = au_esc_chars;
18963 + for (i = 1; i <= ' '; i++)
18969 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
18971 + au_sbilist_init();
18972 + sysaufs_brs_init();
18975 + err = sysaufs_init();
18976 + if (unlikely(err))
18978 + err = au_procfs_init();
18979 + if (unlikely(err))
18980 + goto out_sysaufs;
18981 + err = au_wkq_init();
18982 + if (unlikely(err))
18984 + err = au_loopback_init();
18985 + if (unlikely(err))
18987 + err = au_hnotify_init();
18988 + if (unlikely(err))
18989 + goto out_loopback;
18990 + err = au_sysrq_init();
18991 + if (unlikely(err))
18993 + err = au_cache_init();
18994 + if (unlikely(err))
18996 + err = register_filesystem(&aufs_fs_type);
18997 + if (unlikely(err))
18999 + /* since we define pr_fmt, call printk directly */
19000 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
19001 + goto out; /* success */
19008 + au_hnotify_fin();
19010 + au_loopback_fin();
19022 +static void __exit aufs_exit(void)
19024 + unregister_filesystem(&aufs_fs_type);
19027 + au_hnotify_fin();
19028 + au_loopback_fin();
19035 +module_init(aufs_init);
19036 +module_exit(aufs_exit);
19037 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
19038 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
19039 +++ linux/fs/aufs/module.h 2012-03-19 12:24:13.683134508 +0100
19042 + * Copyright (C) 2005-2012 Junjiro R. Okajima
19044 + * This program, aufs is free software; you can redistribute it and/or modify
19045 + * it under the terms of the GNU General Public License as published by
19046 + * the Free Software Foundation; either version 2 of the License, or
19047 + * (at your option) any later version.
19049 + * This program is distributed in the hope that it will be useful,
19050 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19051 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19052 + * GNU General Public License for more details.
19054 + * You should have received a copy of the GNU General Public License
19055 + * along with this program; if not, write to the Free Software
19056 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19060 + * module initialization and module-global
19063 +#ifndef __AUFS_MODULE_H__
19064 +#define __AUFS_MODULE_H__
19068 +#include <linux/slab.h>
19073 +/* module parameters */
19074 +extern int sysaufs_brs;
19076 +/* ---------------------------------------------------------------------- */
19078 +extern int au_dir_roflags;
19081 + AuLcNonDir_FIINFO,
19082 + AuLcNonDir_DIINFO,
19083 + AuLcNonDir_IIINFO,
19089 + AuLcSymlink_DIINFO,
19090 + AuLcSymlink_IIINFO,
19094 +extern struct lock_class_key au_lc_key[AuLcKey_Last];
19096 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp);
19097 +int au_seq_path(struct seq_file *seq, struct path *path);
19099 +#ifdef CONFIG_PROC_FS
19101 +int __init au_procfs_init(void);
19102 +void au_procfs_fin(void);
19104 +AuStubInt0(au_procfs_init, void);
19105 +AuStubVoid(au_procfs_fin, void);
19108 +/* ---------------------------------------------------------------------- */
19117 + AuCache_HNOTIFY, /* must be last */
19121 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
19122 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
19123 +#define AuCacheCtor(type, ctor) \
19124 + kmem_cache_create(#type, sizeof(struct type), \
19125 + __alignof__(struct type), AuCacheFlags, ctor)
19127 +extern struct kmem_cache *au_cachep[];
19129 +#define AuCacheFuncs(name, index) \
19130 +static inline struct au_##name *au_cache_alloc_##name(void) \
19131 +{ return kmem_cache_alloc(au_cachep[AuCache_##index], GFP_NOFS); } \
19132 +static inline void au_cache_free_##name(struct au_##name *p) \
19133 +{ kmem_cache_free(au_cachep[AuCache_##index], p); }
19135 +AuCacheFuncs(dinfo, DINFO);
19136 +AuCacheFuncs(icntnr, ICNTNR);
19137 +AuCacheFuncs(finfo, FINFO);
19138 +AuCacheFuncs(vdir, VDIR);
19139 +AuCacheFuncs(vdir_dehstr, DEHSTR);
19140 +#ifdef CONFIG_AUFS_HNOTIFY
19141 +AuCacheFuncs(hnotify, HNOTIFY);
19144 +#endif /* __KERNEL__ */
19145 +#endif /* __AUFS_MODULE_H__ */
19146 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
19147 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
19148 +++ linux/fs/aufs/opts.c 2012-03-19 12:24:13.683134508 +0100
19151 + * Copyright (C) 2005-2012 Junjiro R. Okajima
19153 + * This program, aufs is free software; you can redistribute it and/or modify
19154 + * it under the terms of the GNU General Public License as published by
19155 + * the Free Software Foundation; either version 2 of the License, or
19156 + * (at your option) any later version.
19158 + * This program is distributed in the hope that it will be useful,
19159 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19160 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19161 + * GNU General Public License for more details.
19163 + * You should have received a copy of the GNU General Public License
19164 + * along with this program; if not, write to the Free Software
19165 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19169 + * mount options/flags
19172 +#include <linux/namei.h>
19173 +#include <linux/types.h> /* a distribution requires */
19174 +#include <linux/parser.h>
19177 +/* ---------------------------------------------------------------------- */
19181 + Opt_add, Opt_del, Opt_mod, Opt_reorder, Opt_append, Opt_prepend,
19182 + Opt_idel, Opt_imod, Opt_ireorder,
19183 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash, Opt_rendir,
19184 + Opt_rdblk_def, Opt_rdhash_def,
19185 + Opt_xino, Opt_zxino, Opt_noxino,
19186 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
19187 + Opt_trunc_xino_path, Opt_itrunc_xino,
19188 + Opt_trunc_xib, Opt_notrunc_xib,
19189 + Opt_shwh, Opt_noshwh,
19190 + Opt_plink, Opt_noplink, Opt_list_plink,
19192 + Opt_dio, Opt_nodio,
19193 + /* Opt_lock, Opt_unlock, */
19194 + Opt_cmd, Opt_cmd_args,
19195 + Opt_diropq_a, Opt_diropq_w,
19196 + Opt_warn_perm, Opt_nowarn_perm,
19197 + Opt_wbr_copyup, Opt_wbr_create,
19198 + Opt_refrof, Opt_norefrof,
19199 + Opt_verbose, Opt_noverbose,
19200 + Opt_sum, Opt_nosum, Opt_wsum,
19201 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
19204 +static match_table_t options = {
19205 + {Opt_br, "br=%s"},
19206 + {Opt_br, "br:%s"},
19208 + {Opt_add, "add=%d:%s"},
19209 + {Opt_add, "add:%d:%s"},
19210 + {Opt_add, "ins=%d:%s"},
19211 + {Opt_add, "ins:%d:%s"},
19212 + {Opt_append, "append=%s"},
19213 + {Opt_append, "append:%s"},
19214 + {Opt_prepend, "prepend=%s"},
19215 + {Opt_prepend, "prepend:%s"},
19217 + {Opt_del, "del=%s"},
19218 + {Opt_del, "del:%s"},
19219 + /* {Opt_idel, "idel:%d"}, */
19220 + {Opt_mod, "mod=%s"},
19221 + {Opt_mod, "mod:%s"},
19222 + /* {Opt_imod, "imod:%d:%s"}, */
19224 + {Opt_dirwh, "dirwh=%d"},
19226 + {Opt_xino, "xino=%s"},
19227 + {Opt_noxino, "noxino"},
19228 + {Opt_trunc_xino, "trunc_xino"},
19229 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
19230 + {Opt_notrunc_xino, "notrunc_xino"},
19231 + {Opt_trunc_xino_path, "trunc_xino=%s"},
19232 + {Opt_itrunc_xino, "itrunc_xino=%d"},
19233 + /* {Opt_zxino, "zxino=%s"}, */
19234 + {Opt_trunc_xib, "trunc_xib"},
19235 + {Opt_notrunc_xib, "notrunc_xib"},
19237 +#ifdef CONFIG_PROC_FS
19238 + {Opt_plink, "plink"},
19240 + {Opt_ignore_silent, "plink"},
19243 + {Opt_noplink, "noplink"},
19245 +#ifdef CONFIG_AUFS_DEBUG
19246 + {Opt_list_plink, "list_plink"},
19249 + {Opt_udba, "udba=%s"},
19251 + {Opt_dio, "dio"},
19252 + {Opt_nodio, "nodio"},
19254 + {Opt_diropq_a, "diropq=always"},
19255 + {Opt_diropq_a, "diropq=a"},
19256 + {Opt_diropq_w, "diropq=whiteouted"},
19257 + {Opt_diropq_w, "diropq=w"},
19259 + {Opt_warn_perm, "warn_perm"},
19260 + {Opt_nowarn_perm, "nowarn_perm"},
19262 + /* keep them temporary */
19263 + {Opt_ignore_silent, "coo=%s"},
19264 + {Opt_ignore_silent, "nodlgt"},
19265 + {Opt_ignore_silent, "nodirperm1"},
19266 + {Opt_ignore_silent, "clean_plink"},
19268 +#ifdef CONFIG_AUFS_SHWH
19269 + {Opt_shwh, "shwh"},
19271 + {Opt_noshwh, "noshwh"},
19273 + {Opt_rendir, "rendir=%d"},
19275 + {Opt_refrof, "refrof"},
19276 + {Opt_norefrof, "norefrof"},
19278 + {Opt_verbose, "verbose"},
19279 + {Opt_verbose, "v"},
19280 + {Opt_noverbose, "noverbose"},
19281 + {Opt_noverbose, "quiet"},
19282 + {Opt_noverbose, "q"},
19283 + {Opt_noverbose, "silent"},
19285 + {Opt_sum, "sum"},
19286 + {Opt_nosum, "nosum"},
19287 + {Opt_wsum, "wsum"},
19289 + {Opt_rdcache, "rdcache=%d"},
19290 + {Opt_rdblk, "rdblk=%d"},
19291 + {Opt_rdblk_def, "rdblk=def"},
19292 + {Opt_rdhash, "rdhash=%d"},
19293 + {Opt_rdhash_def, "rdhash=def"},
19295 + {Opt_wbr_create, "create=%s"},
19296 + {Opt_wbr_create, "create_policy=%s"},
19297 + {Opt_wbr_copyup, "cpup=%s"},
19298 + {Opt_wbr_copyup, "copyup=%s"},
19299 + {Opt_wbr_copyup, "copyup_policy=%s"},
19301 + /* internal use for the scripts */
19302 + {Opt_ignore_silent, "si=%s"},
19304 + {Opt_br, "dirs=%s"},
19305 + {Opt_ignore, "debug=%d"},
19306 + {Opt_ignore, "delete=whiteout"},
19307 + {Opt_ignore, "delete=all"},
19308 + {Opt_ignore, "imap=%s"},
19310 + /* temporary workaround, due to old mount(8)? */
19311 + {Opt_ignore_silent, "relatime"},
19316 +/* ---------------------------------------------------------------------- */
19318 +static const char *au_parser_pattern(int val, struct match_token *token)
19320 + while (token->pattern) {
19321 + if (token->token == val)
19322 + return token->pattern;
19329 +/* ---------------------------------------------------------------------- */
19331 +static match_table_t brperm = {
19332 + {AuBrPerm_RO, AUFS_BRPERM_RO},
19333 + {AuBrPerm_RR, AUFS_BRPERM_RR},
19334 + {AuBrPerm_RW, AUFS_BRPERM_RW},
19338 +static match_table_t brrattr = {
19339 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
19343 +static match_table_t brwattr = {
19344 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
19348 +#define AuBrStr_LONGEST AUFS_BRPERM_RW "+" AUFS_BRWATTR_NLWH
19350 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
19357 + p = strchr(str, '+');
19360 + v = match_token(str, table, args);
19366 + pr_warning("ignored branch attribute %s\n", str);
19376 +static int noinline_for_stack br_perm_val(char *perm)
19380 + substring_t args[MAX_OPT_ARGS];
19382 + p = strchr(perm, '+');
19385 + val = match_token(perm, brperm, args);
19389 + pr_warning("ignored branch permission %s\n", perm);
19390 + val = AuBrPerm_RO;
19397 + case AuBrPerm_RO:
19398 + case AuBrPerm_RR:
19399 + val |= br_attr_val(p + 1, brrattr, args);
19401 + case AuBrPerm_RW:
19402 + val |= br_attr_val(p + 1, brwattr, args);
19410 +/* Caller should free the return value */
19411 +char *au_optstr_br_perm(int brperm)
19413 + char *p, a[sizeof(AuBrStr_LONGEST)];
19416 +#define SetPerm(str) do { \
19417 + sz = sizeof(str); \
19418 + memcpy(a, str, sz); \
19419 + p = a + sz - 1; \
19422 +#define AppendAttr(flag, str) do { \
19423 + if (brperm & flag) { \
19424 + sz = sizeof(str); \
19426 + memcpy(p, str, sz); \
19431 + switch (brperm & AuBrPerm_Mask) {
19432 + case AuBrPerm_RO:
19433 + SetPerm(AUFS_BRPERM_RO);
19435 + case AuBrPerm_RR:
19436 + SetPerm(AUFS_BRPERM_RR);
19438 + case AuBrPerm_RW:
19439 + SetPerm(AUFS_BRPERM_RW);
19445 + AppendAttr(AuBrRAttr_WH, AUFS_BRRATTR_WH);
19446 + AppendAttr(AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH);
19448 + AuDebugOn(strlen(a) >= sizeof(a));
19449 + return kstrdup(a, GFP_NOFS);
19454 +/* ---------------------------------------------------------------------- */
19456 +static match_table_t udbalevel = {
19457 + {AuOpt_UDBA_REVAL, "reval"},
19458 + {AuOpt_UDBA_NONE, "none"},
19459 +#ifdef CONFIG_AUFS_HNOTIFY
19460 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
19461 +#ifdef CONFIG_AUFS_HFSNOTIFY
19462 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
19468 +static int noinline_for_stack udba_val(char *str)
19470 + substring_t args[MAX_OPT_ARGS];
19472 + return match_token(str, udbalevel, args);
19475 +const char *au_optstr_udba(int udba)
19477 + return au_parser_pattern(udba, (void *)udbalevel);
19480 +/* ---------------------------------------------------------------------- */
19482 +static match_table_t au_wbr_create_policy = {
19483 + {AuWbrCreate_TDP, "tdp"},
19484 + {AuWbrCreate_TDP, "top-down-parent"},
19485 + {AuWbrCreate_RR, "rr"},
19486 + {AuWbrCreate_RR, "round-robin"},
19487 + {AuWbrCreate_MFS, "mfs"},
19488 + {AuWbrCreate_MFS, "most-free-space"},
19489 + {AuWbrCreate_MFSV, "mfs:%d"},
19490 + {AuWbrCreate_MFSV, "most-free-space:%d"},
19492 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
19493 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
19494 + {AuWbrCreate_PMFS, "pmfs"},
19495 + {AuWbrCreate_PMFSV, "pmfs:%d"},
19501 + * cf. linux/lib/parser.c and cmdline.c
19502 + * gave up calling memparse() since it uses simple_strtoull() instead of
19505 +static int noinline_for_stack
19506 +au_match_ull(substring_t *s, unsigned long long *result)
19509 + unsigned int len;
19513 + len = s->to - s->from;
19514 + if (len + 1 <= sizeof(a)) {
19515 + memcpy(a, s->from, len);
19517 + err = kstrtoull(a, 0, result);
19522 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
19523 + struct au_opt_wbr_create *create)
19526 + unsigned long long ull;
19529 + if (!au_match_ull(arg, &ull))
19530 + create->mfsrr_watermark = ull;
19532 + pr_err("bad integer in %s\n", str);
19539 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
19540 + struct au_opt_wbr_create *create)
19545 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
19546 + create->mfs_second = n;
19548 + pr_err("bad integer in %s\n", str);
19555 +static int noinline_for_stack
19556 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
19559 + substring_t args[MAX_OPT_ARGS];
19561 + err = match_token(str, au_wbr_create_policy, args);
19562 + create->wbr_create = err;
19564 + case AuWbrCreate_MFSRRV:
19565 + e = au_wbr_mfs_wmark(&args[0], str, create);
19567 + e = au_wbr_mfs_sec(&args[1], str, create);
19571 + case AuWbrCreate_MFSRR:
19572 + e = au_wbr_mfs_wmark(&args[0], str, create);
19573 + if (unlikely(e)) {
19578 + case AuWbrCreate_MFS:
19579 + case AuWbrCreate_PMFS:
19580 + create->mfs_second = AUFS_MFS_DEF_SEC;
19582 + case AuWbrCreate_MFSV:
19583 + case AuWbrCreate_PMFSV:
19584 + e = au_wbr_mfs_sec(&args[0], str, create);
19593 +const char *au_optstr_wbr_create(int wbr_create)
19595 + return au_parser_pattern(wbr_create, (void *)au_wbr_create_policy);
19598 +static match_table_t au_wbr_copyup_policy = {
19599 + {AuWbrCopyup_TDP, "tdp"},
19600 + {AuWbrCopyup_TDP, "top-down-parent"},
19601 + {AuWbrCopyup_BUP, "bup"},
19602 + {AuWbrCopyup_BUP, "bottom-up-parent"},
19603 + {AuWbrCopyup_BU, "bu"},
19604 + {AuWbrCopyup_BU, "bottom-up"},
19608 +static int noinline_for_stack au_wbr_copyup_val(char *str)
19610 + substring_t args[MAX_OPT_ARGS];
19612 + return match_token(str, au_wbr_copyup_policy, args);
19615 +const char *au_optstr_wbr_copyup(int wbr_copyup)
19617 + return au_parser_pattern(wbr_copyup, (void *)au_wbr_copyup_policy);
19620 +/* ---------------------------------------------------------------------- */
19622 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
19624 +static void dump_opts(struct au_opts *opts)
19626 +#ifdef CONFIG_AUFS_DEBUG
19627 + /* reduce stack space */
19629 + struct au_opt_add *add;
19630 + struct au_opt_del *del;
19631 + struct au_opt_mod *mod;
19632 + struct au_opt_xino *xino;
19633 + struct au_opt_xino_itrunc *xino_itrunc;
19634 + struct au_opt_wbr_create *create;
19636 + struct au_opt *opt;
19639 + while (opt->type != Opt_tail) {
19640 + switch (opt->type) {
19642 + u.add = &opt->add;
19643 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
19644 + u.add->bindex, u.add->pathname, u.add->perm,
19645 + u.add->path.dentry);
19649 + u.del = &opt->del;
19650 + AuDbg("del {%s, %p}\n",
19651 + u.del->pathname, u.del->h_path.dentry);
19655 + u.mod = &opt->mod;
19656 + AuDbg("mod {%s, 0x%x, %p}\n",
19657 + u.mod->path, u.mod->perm, u.mod->h_root);
19660 + u.add = &opt->add;
19661 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
19662 + u.add->bindex, u.add->pathname, u.add->perm,
19663 + u.add->path.dentry);
19665 + case Opt_prepend:
19666 + u.add = &opt->add;
19667 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
19668 + u.add->bindex, u.add->pathname, u.add->perm,
19669 + u.add->path.dentry);
19672 + AuDbg("dirwh %d\n", opt->dirwh);
19674 + case Opt_rdcache:
19675 + AuDbg("rdcache %d\n", opt->rdcache);
19678 + AuDbg("rdblk %u\n", opt->rdblk);
19680 + case Opt_rdblk_def:
19681 + AuDbg("rdblk_def\n");
19684 + AuDbg("rdhash %u\n", opt->rdhash);
19686 + case Opt_rdhash_def:
19687 + AuDbg("rdhash_def\n");
19690 + u.xino = &opt->xino;
19691 + AuDbg("xino {%s %.*s}\n",
19693 + AuDLNPair(u.xino->file->f_dentry));
19695 + case Opt_trunc_xino:
19696 + AuLabel(trunc_xino);
19698 + case Opt_notrunc_xino:
19699 + AuLabel(notrunc_xino);
19701 + case Opt_trunc_xino_path:
19702 + case Opt_itrunc_xino:
19703 + u.xino_itrunc = &opt->xino_itrunc;
19704 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
19710 + case Opt_trunc_xib:
19711 + AuLabel(trunc_xib);
19713 + case Opt_notrunc_xib:
19714 + AuLabel(notrunc_xib);
19725 + case Opt_noplink:
19726 + AuLabel(noplink);
19728 + case Opt_list_plink:
19729 + AuLabel(list_plink);
19732 + AuDbg("udba %d, %s\n",
19733 + opt->udba, au_optstr_udba(opt->udba));
19741 + case Opt_diropq_a:
19742 + AuLabel(diropq_a);
19744 + case Opt_diropq_w:
19745 + AuLabel(diropq_w);
19747 + case Opt_warn_perm:
19748 + AuLabel(warn_perm);
19750 + case Opt_nowarn_perm:
19751 + AuLabel(nowarn_perm);
19756 + case Opt_norefrof:
19757 + AuLabel(norefrof);
19759 + case Opt_verbose:
19760 + AuLabel(verbose);
19762 + case Opt_noverbose:
19763 + AuLabel(noverbose);
19774 + case Opt_wbr_create:
19775 + u.create = &opt->wbr_create;
19776 + AuDbg("create %d, %s\n", u.create->wbr_create,
19777 + au_optstr_wbr_create(u.create->wbr_create));
19778 + switch (u.create->wbr_create) {
19779 + case AuWbrCreate_MFSV:
19780 + case AuWbrCreate_PMFSV:
19781 + AuDbg("%d sec\n", u.create->mfs_second);
19783 + case AuWbrCreate_MFSRR:
19784 + AuDbg("%llu watermark\n",
19785 + u.create->mfsrr_watermark);
19787 + case AuWbrCreate_MFSRRV:
19788 + AuDbg("%llu watermark, %d sec\n",
19789 + u.create->mfsrr_watermark,
19790 + u.create->mfs_second);
19794 + case Opt_wbr_copyup:
19795 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
19796 + au_optstr_wbr_copyup(opt->wbr_copyup));
19806 +void au_opts_free(struct au_opts *opts)
19808 + struct au_opt *opt;
19811 + while (opt->type != Opt_tail) {
19812 + switch (opt->type) {
19815 + case Opt_prepend:
19816 + path_put(&opt->add.path);
19820 + path_put(&opt->del.h_path);
19824 + dput(opt->mod.h_root);
19827 + fput(opt->xino.file);
19834 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
19835 + aufs_bindex_t bindex)
19838 + struct au_opt_add *add = &opt->add;
19841 + add->bindex = bindex;
19842 + add->perm = AuBrPerm_RO;
19843 + add->pathname = opt_str;
19844 + p = strchr(opt_str, '=');
19848 + add->perm = br_perm_val(p);
19851 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
19854 + add->perm = AuBrPerm_RO;
19855 + if (au_test_fs_rr(add->path.dentry->d_sb))
19856 + add->perm = AuBrPerm_RR;
19857 + else if (!bindex && !(sb_flags & MS_RDONLY))
19858 + add->perm = AuBrPerm_RW;
19860 + opt->type = Opt_add;
19863 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
19870 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
19874 + del->pathname = args[0].from;
19875 + AuDbg("del path %s\n", del->pathname);
19877 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
19878 + if (unlikely(err))
19879 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
19884 +#if 0 /* reserved for future use */
19885 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
19886 + struct au_opt_del *del, substring_t args[])
19889 + struct dentry *root;
19892 + root = sb->s_root;
19893 + aufs_read_lock(root, AuLock_FLUSH);
19894 + if (bindex < 0 || au_sbend(sb) < bindex) {
19895 + pr_err("out of bounds, %d\n", bindex);
19900 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
19901 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
19904 + aufs_read_unlock(root, !AuLock_IR);
19909 +static int noinline_for_stack
19910 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
19913 + struct path path;
19917 + mod->path = args[0].from;
19918 + p = strchr(mod->path, '=');
19919 + if (unlikely(!p)) {
19920 + pr_err("no permssion %s\n", args[0].from);
19925 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
19926 + if (unlikely(err)) {
19927 + pr_err("lookup failed %s (%d)\n", mod->path, err);
19931 + mod->perm = br_perm_val(p);
19932 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
19933 + mod->h_root = dget(path.dentry);
19940 +#if 0 /* reserved for future use */
19941 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
19942 + struct au_opt_mod *mod, substring_t args[])
19945 + struct dentry *root;
19948 + root = sb->s_root;
19949 + aufs_read_lock(root, AuLock_FLUSH);
19950 + if (bindex < 0 || au_sbend(sb) < bindex) {
19951 + pr_err("out of bounds, %d\n", bindex);
19956 + mod->perm = br_perm_val(args[1].from);
19957 + AuDbg("mod path %s, perm 0x%x, %s\n",
19958 + mod->path, mod->perm, args[1].from);
19959 + mod->h_root = dget(au_h_dptr(root, bindex));
19962 + aufs_read_unlock(root, !AuLock_IR);
19967 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
19968 + substring_t args[])
19971 + struct file *file;
19973 + file = au_xino_create(sb, args[0].from, /*silent*/0);
19974 + err = PTR_ERR(file);
19975 + if (IS_ERR(file))
19979 + if (unlikely(file->f_dentry->d_sb == sb)) {
19981 + pr_err("%s must be outside\n", args[0].from);
19986 + xino->file = file;
19987 + xino->path = args[0].from;
19993 +static int noinline_for_stack
19994 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
19995 + struct au_opt_xino_itrunc *xino_itrunc,
19996 + substring_t args[])
19999 + aufs_bindex_t bend, bindex;
20000 + struct path path;
20001 + struct dentry *root;
20003 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
20004 + if (unlikely(err)) {
20005 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
20009 + xino_itrunc->bindex = -1;
20010 + root = sb->s_root;
20011 + aufs_read_lock(root, AuLock_FLUSH);
20012 + bend = au_sbend(sb);
20013 + for (bindex = 0; bindex <= bend; bindex++) {
20014 + if (au_h_dptr(root, bindex) == path.dentry) {
20015 + xino_itrunc->bindex = bindex;
20019 + aufs_read_unlock(root, !AuLock_IR);
20022 + if (unlikely(xino_itrunc->bindex < 0)) {
20023 + pr_err("no such branch %s\n", args[0].from);
20031 +/* called without aufs lock */
20032 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
20034 + int err, n, token;
20035 + aufs_bindex_t bindex;
20036 + unsigned char skipped;
20037 + struct dentry *root;
20038 + struct au_opt *opt, *opt_tail;
20040 + /* reduce the stack space */
20042 + struct au_opt_xino_itrunc *xino_itrunc;
20043 + struct au_opt_wbr_create *create;
20046 + substring_t args[MAX_OPT_ARGS];
20050 + a = kmalloc(sizeof(*a), GFP_NOFS);
20051 + if (unlikely(!a))
20054 + root = sb->s_root;
20058 + opt_tail = opt + opts->max_opt - 1;
20059 + opt->type = Opt_tail;
20060 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
20063 + token = match_token(opt_str, options, a->args);
20067 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
20069 + err = opt_add(opt, opt_str, opts->sb_flags,
20071 + if (unlikely(!err && ++opt > opt_tail)) {
20075 + opt->type = Opt_tail;
20080 + if (unlikely(match_int(&a->args[0], &n))) {
20081 + pr_err("bad integer in %s\n", opt_str);
20085 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
20088 + opt->type = token;
20091 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
20092 + /*dummy bindex*/1);
20094 + opt->type = token;
20096 + case Opt_prepend:
20097 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
20100 + opt->type = token;
20103 + err = au_opts_parse_del(&opt->del, a->args);
20105 + opt->type = token;
20107 +#if 0 /* reserved for future use */
20109 + del->pathname = "(indexed)";
20110 + if (unlikely(match_int(&args[0], &n))) {
20111 + pr_err("bad integer in %s\n", opt_str);
20114 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
20116 + opt->type = token;
20120 + err = au_opts_parse_mod(&opt->mod, a->args);
20122 + opt->type = token;
20124 +#ifdef IMOD /* reserved for future use */
20126 + u.mod->path = "(indexed)";
20127 + if (unlikely(match_int(&a->args[0], &n))) {
20128 + pr_err("bad integer in %s\n", opt_str);
20131 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
20133 + opt->type = token;
20137 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
20139 + opt->type = token;
20142 + case Opt_trunc_xino_path:
20143 + err = au_opts_parse_xino_itrunc_path
20144 + (sb, &opt->xino_itrunc, a->args);
20146 + opt->type = token;
20149 + case Opt_itrunc_xino:
20150 + u.xino_itrunc = &opt->xino_itrunc;
20151 + if (unlikely(match_int(&a->args[0], &n))) {
20152 + pr_err("bad integer in %s\n", opt_str);
20155 + u.xino_itrunc->bindex = n;
20156 + aufs_read_lock(root, AuLock_FLUSH);
20157 + if (n < 0 || au_sbend(sb) < n) {
20158 + pr_err("out of bounds, %d\n", n);
20159 + aufs_read_unlock(root, !AuLock_IR);
20162 + aufs_read_unlock(root, !AuLock_IR);
20164 + opt->type = token;
20168 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
20171 + opt->type = token;
20174 + case Opt_rdcache:
20175 + if (unlikely(match_int(&a->args[0], &n))) {
20176 + pr_err("bad integer in %s\n", opt_str);
20179 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
20180 + pr_err("rdcache must be smaller than %d\n",
20181 + AUFS_RDCACHE_MAX);
20184 + opt->rdcache = n;
20186 + opt->type = token;
20189 + if (unlikely(match_int(&a->args[0], &n)
20191 + || n > KMALLOC_MAX_SIZE)) {
20192 + pr_err("bad integer in %s\n", opt_str);
20195 + if (unlikely(n && n < NAME_MAX)) {
20196 + pr_err("rdblk must be larger than %d\n",
20202 + opt->type = token;
20205 + if (unlikely(match_int(&a->args[0], &n)
20207 + || n * sizeof(struct hlist_head)
20208 + > KMALLOC_MAX_SIZE)) {
20209 + pr_err("bad integer in %s\n", opt_str);
20214 + opt->type = token;
20217 + case Opt_trunc_xino:
20218 + case Opt_notrunc_xino:
20220 + case Opt_trunc_xib:
20221 + case Opt_notrunc_xib:
20225 + case Opt_noplink:
20226 + case Opt_list_plink:
20229 + case Opt_diropq_a:
20230 + case Opt_diropq_w:
20231 + case Opt_warn_perm:
20232 + case Opt_nowarn_perm:
20234 + case Opt_norefrof:
20235 + case Opt_verbose:
20236 + case Opt_noverbose:
20240 + case Opt_rdblk_def:
20241 + case Opt_rdhash_def:
20243 + opt->type = token;
20247 + opt->udba = udba_val(a->args[0].from);
20248 + if (opt->udba >= 0) {
20250 + opt->type = token;
20252 + pr_err("wrong value, %s\n", opt_str);
20255 + case Opt_wbr_create:
20256 + u.create = &opt->wbr_create;
20257 + u.create->wbr_create
20258 + = au_wbr_create_val(a->args[0].from, u.create);
20259 + if (u.create->wbr_create >= 0) {
20261 + opt->type = token;
20263 + pr_err("wrong value, %s\n", opt_str);
20265 + case Opt_wbr_copyup:
20266 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
20267 + if (opt->wbr_copyup >= 0) {
20269 + opt->type = token;
20271 + pr_err("wrong value, %s\n", opt_str);
20275 + pr_warning("ignored %s\n", opt_str);
20277 + case Opt_ignore_silent:
20282 + pr_err("unknown option %s\n", opt_str);
20286 + if (!err && !skipped) {
20287 + if (unlikely(++opt > opt_tail)) {
20290 + opt->type = Opt_tail;
20293 + opt->type = Opt_tail;
20299 + if (unlikely(err))
20300 + au_opts_free(opts);
20306 +static int au_opt_wbr_create(struct super_block *sb,
20307 + struct au_opt_wbr_create *create)
20310 + struct au_sbinfo *sbinfo;
20312 + SiMustWriteLock(sb);
20314 + err = 1; /* handled */
20315 + sbinfo = au_sbi(sb);
20316 + if (sbinfo->si_wbr_create_ops->fin) {
20317 + err = sbinfo->si_wbr_create_ops->fin(sb);
20322 + sbinfo->si_wbr_create = create->wbr_create;
20323 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
20324 + switch (create->wbr_create) {
20325 + case AuWbrCreate_MFSRRV:
20326 + case AuWbrCreate_MFSRR:
20327 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
20329 + case AuWbrCreate_MFS:
20330 + case AuWbrCreate_MFSV:
20331 + case AuWbrCreate_PMFS:
20332 + case AuWbrCreate_PMFSV:
20333 + sbinfo->si_wbr_mfs.mfs_expire
20334 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
20338 + if (sbinfo->si_wbr_create_ops->init)
20339 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
20346 + * plus: processed without an error
20347 + * zero: unprocessed
20349 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
20350 + struct au_opts *opts)
20353 + struct au_sbinfo *sbinfo;
20355 + SiMustWriteLock(sb);
20357 + err = 1; /* handled */
20358 + sbinfo = au_sbi(sb);
20359 + switch (opt->type) {
20361 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
20362 + sbinfo->si_mntflags |= opt->udba;
20363 + opts->given_udba |= opt->udba;
20367 + au_opt_set(sbinfo->si_mntflags, PLINK);
20369 + case Opt_noplink:
20370 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
20371 + au_plink_put(sb, /*verbose*/1);
20372 + au_opt_clr(sbinfo->si_mntflags, PLINK);
20374 + case Opt_list_plink:
20375 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
20376 + au_plink_list(sb);
20380 + au_opt_set(sbinfo->si_mntflags, DIO);
20381 + au_fset_opts(opts->flags, REFRESH_DYAOP);
20384 + au_opt_clr(sbinfo->si_mntflags, DIO);
20385 + au_fset_opts(opts->flags, REFRESH_DYAOP);
20388 + case Opt_diropq_a:
20389 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
20391 + case Opt_diropq_w:
20392 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
20395 + case Opt_warn_perm:
20396 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
20398 + case Opt_nowarn_perm:
20399 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
20403 + au_opt_set(sbinfo->si_mntflags, REFROF);
20405 + case Opt_norefrof:
20406 + au_opt_clr(sbinfo->si_mntflags, REFROF);
20409 + case Opt_verbose:
20410 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
20412 + case Opt_noverbose:
20413 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
20417 + au_opt_set(sbinfo->si_mntflags, SUM);
20420 + au_opt_clr(sbinfo->si_mntflags, SUM);
20421 + au_opt_set(sbinfo->si_mntflags, SUM_W);
20423 + au_opt_clr(sbinfo->si_mntflags, SUM);
20424 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
20427 + case Opt_wbr_create:
20428 + err = au_opt_wbr_create(sb, &opt->wbr_create);
20430 + case Opt_wbr_copyup:
20431 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
20432 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
20436 + sbinfo->si_dirwh = opt->dirwh;
20439 + case Opt_rdcache:
20440 + sbinfo->si_rdcache
20441 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
20444 + sbinfo->si_rdblk = opt->rdblk;
20446 + case Opt_rdblk_def:
20447 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
20450 + sbinfo->si_rdhash = opt->rdhash;
20452 + case Opt_rdhash_def:
20453 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
20457 + au_opt_set(sbinfo->si_mntflags, SHWH);
20460 + au_opt_clr(sbinfo->si_mntflags, SHWH);
20463 + case Opt_trunc_xino:
20464 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
20466 + case Opt_notrunc_xino:
20467 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
20470 + case Opt_trunc_xino_path:
20471 + case Opt_itrunc_xino:
20472 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
20477 + case Opt_trunc_xib:
20478 + au_fset_opts(opts->flags, TRUNC_XIB);
20480 + case Opt_notrunc_xib:
20481 + au_fclr_opts(opts->flags, TRUNC_XIB);
20493 + * returns tri-state.
20494 + * plus: processed without an error
20495 + * zero: unprocessed
20498 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
20499 + struct au_opts *opts)
20501 + int err, do_refresh;
20504 + switch (opt->type) {
20506 + opt->add.bindex = au_sbend(sb) + 1;
20507 + if (opt->add.bindex < 0)
20508 + opt->add.bindex = 0;
20510 + case Opt_prepend:
20511 + opt->add.bindex = 0;
20514 + err = au_br_add(sb, &opt->add,
20515 + au_ftest_opts(opts->flags, REMOUNT));
20518 + au_fset_opts(opts->flags, REFRESH);
20524 + err = au_br_del(sb, &opt->del,
20525 + au_ftest_opts(opts->flags, REMOUNT));
20528 + au_fset_opts(opts->flags, TRUNC_XIB);
20529 + au_fset_opts(opts->flags, REFRESH);
20535 + err = au_br_mod(sb, &opt->mod,
20536 + au_ftest_opts(opts->flags, REMOUNT),
20541 + au_fset_opts(opts->flags, REFRESH);
20549 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
20550 + struct au_opt_xino **opt_xino,
20551 + struct au_opts *opts)
20554 + aufs_bindex_t bend, bindex;
20555 + struct dentry *root, *parent, *h_root;
20558 + switch (opt->type) {
20560 + err = au_xino_set(sb, &opt->xino,
20561 + !!au_ftest_opts(opts->flags, REMOUNT));
20562 + if (unlikely(err))
20565 + *opt_xino = &opt->xino;
20566 + au_xino_brid_set(sb, -1);
20568 + /* safe d_parent access */
20569 + parent = opt->xino.file->f_dentry->d_parent;
20570 + root = sb->s_root;
20571 + bend = au_sbend(sb);
20572 + for (bindex = 0; bindex <= bend; bindex++) {
20573 + h_root = au_h_dptr(root, bindex);
20574 + if (h_root == parent) {
20575 + au_xino_brid_set(sb, au_sbr_id(sb, bindex));
20583 + au_xino_brid_set(sb, -1);
20584 + *opt_xino = (void *)-1;
20591 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
20592 + unsigned int pending)
20595 + aufs_bindex_t bindex, bend;
20596 + unsigned char do_plink, skip, do_free;
20597 + struct au_branch *br;
20598 + struct au_wbr *wbr;
20599 + struct dentry *root;
20600 + struct inode *dir, *h_dir;
20601 + struct au_sbinfo *sbinfo;
20602 + struct au_hinode *hdir;
20604 + SiMustAnyLock(sb);
20606 + sbinfo = au_sbi(sb);
20607 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
20609 + if (!(sb_flags & MS_RDONLY)) {
20610 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
20611 + pr_warning("first branch should be rw\n");
20612 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
20613 + pr_warning("shwh should be used with ro\n");
20616 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
20617 + && !au_opt_test(sbinfo->si_mntflags, XINO))
20618 + pr_warning("udba=*notify requires xino\n");
20621 + root = sb->s_root;
20622 + dir = root->d_inode;
20623 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
20624 + bend = au_sbend(sb);
20625 + for (bindex = 0; !err && bindex <= bend; bindex++) {
20627 + h_dir = au_h_iptr(dir, bindex);
20628 + br = au_sbr(sb, bindex);
20631 + wbr = br->br_wbr;
20633 + wbr_wh_read_lock(wbr);
20635 + if (!au_br_writable(br->br_perm)) {
20638 + || (!wbr->wbr_whbase
20639 + && !wbr->wbr_plink
20640 + && !wbr->wbr_orph));
20641 + } else if (!au_br_wh_linkable(br->br_perm)) {
20642 + /* skip = (!br->br_whbase && !br->br_orph); */
20643 + skip = (!wbr || !wbr->wbr_whbase);
20644 + if (skip && wbr) {
20646 + skip = !!wbr->wbr_plink;
20648 + skip = !wbr->wbr_plink;
20651 + /* skip = (br->br_whbase && br->br_ohph); */
20652 + skip = (wbr && wbr->wbr_whbase);
20655 + skip = !!wbr->wbr_plink;
20657 + skip = !wbr->wbr_plink;
20661 + wbr_wh_read_unlock(wbr);
20666 + hdir = au_hi(dir, bindex);
20667 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
20669 + wbr_wh_write_lock(wbr);
20670 + err = au_wh_init(au_h_dptr(root, bindex), br, sb);
20672 + wbr_wh_write_unlock(wbr);
20673 + au_hn_imtx_unlock(hdir);
20675 + if (!err && do_free) {
20677 + br->br_wbr = NULL;
20684 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
20687 + unsigned int tmp;
20688 + aufs_bindex_t bindex, bend;
20689 + struct au_opt *opt;
20690 + struct au_opt_xino *opt_xino, xino;
20691 + struct au_sbinfo *sbinfo;
20692 + struct au_branch *br;
20694 + SiMustWriteLock(sb);
20699 + while (err >= 0 && opt->type != Opt_tail)
20700 + err = au_opt_simple(sb, opt++, opts);
20703 + else if (unlikely(err < 0))
20706 + /* disable xino and udba temporary */
20707 + sbinfo = au_sbi(sb);
20708 + tmp = sbinfo->si_mntflags;
20709 + au_opt_clr(sbinfo->si_mntflags, XINO);
20710 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
20713 + while (err >= 0 && opt->type != Opt_tail)
20714 + err = au_opt_br(sb, opt++, opts);
20717 + else if (unlikely(err < 0))
20720 + bend = au_sbend(sb);
20721 + if (unlikely(bend < 0)) {
20723 + pr_err("no branches\n");
20727 + if (au_opt_test(tmp, XINO))
20728 + au_opt_set(sbinfo->si_mntflags, XINO);
20730 + while (!err && opt->type != Opt_tail)
20731 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
20732 + if (unlikely(err))
20735 + err = au_opts_verify(sb, sb->s_flags, tmp);
20736 + if (unlikely(err))
20739 + /* restore xino */
20740 + if (au_opt_test(tmp, XINO) && !opt_xino) {
20741 + xino.file = au_xino_def(sb);
20742 + err = PTR_ERR(xino.file);
20743 + if (IS_ERR(xino.file))
20746 + err = au_xino_set(sb, &xino, /*remount*/0);
20748 + if (unlikely(err))
20752 + /* restore udba */
20753 + tmp &= AuOptMask_UDBA;
20754 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
20755 + sbinfo->si_mntflags |= tmp;
20756 + bend = au_sbend(sb);
20757 + for (bindex = 0; bindex <= bend; bindex++) {
20758 + br = au_sbr(sb, bindex);
20759 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
20760 + if (unlikely(err))
20761 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
20763 + /* go on even if err */
20765 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
20766 + struct inode *dir = sb->s_root->d_inode;
20767 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
20774 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
20777 + struct inode *dir;
20778 + struct au_opt_xino *opt_xino;
20779 + struct au_opt *opt;
20780 + struct au_sbinfo *sbinfo;
20782 + SiMustWriteLock(sb);
20784 + dir = sb->s_root->d_inode;
20785 + sbinfo = au_sbi(sb);
20789 + while (err >= 0 && opt->type != Opt_tail) {
20790 + err = au_opt_simple(sb, opt, opts);
20792 + err = au_opt_br(sb, opt, opts);
20794 + err = au_opt_xino(sb, opt, &opt_xino, opts);
20800 + /* go on even err */
20802 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
20803 + if (unlikely(rerr && !err))
20806 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
20807 + rerr = au_xib_trunc(sb);
20808 + if (unlikely(rerr && !err))
20812 + /* will be handled by the caller */
20813 + if (!au_ftest_opts(opts->flags, REFRESH)
20814 + && (opts->given_udba || au_opt_test(sbinfo->si_mntflags, XINO)))
20815 + au_fset_opts(opts->flags, REFRESH);
20817 + AuDbg("status 0x%x\n", opts->flags);
20821 +/* ---------------------------------------------------------------------- */
20823 +unsigned int au_opt_udba(struct super_block *sb)
20825 + return au_mntflags(sb) & AuOptMask_UDBA;
20827 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
20828 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
20829 +++ linux/fs/aufs/opts.h 2012-03-19 12:24:13.683134508 +0100
20832 + * Copyright (C) 2005-2012 Junjiro R. Okajima
20834 + * This program, aufs is free software; you can redistribute it and/or modify
20835 + * it under the terms of the GNU General Public License as published by
20836 + * the Free Software Foundation; either version 2 of the License, or
20837 + * (at your option) any later version.
20839 + * This program is distributed in the hope that it will be useful,
20840 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20841 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20842 + * GNU General Public License for more details.
20844 + * You should have received a copy of the GNU General Public License
20845 + * along with this program; if not, write to the Free Software
20846 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20850 + * mount options/flags
20853 +#ifndef __AUFS_OPTS_H__
20854 +#define __AUFS_OPTS_H__
20858 +#include <linux/path.h>
20861 +struct super_block;
20863 +/* ---------------------------------------------------------------------- */
20866 +#define AuOpt_XINO 1 /* external inode number bitmap
20867 + and translation table */
20868 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
20869 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
20870 +#define AuOpt_UDBA_REVAL (1 << 3)
20871 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
20872 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
20873 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
20874 +#define AuOpt_DIRPERM1 (1 << 7) /* unimplemented */
20875 +#define AuOpt_REFROF (1 << 8) /* unimplemented */
20876 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
20877 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
20878 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
20879 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
20880 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
20881 +#define AuOpt_DIO (1 << 14) /* direct io */
20883 +#ifndef CONFIG_AUFS_HNOTIFY
20884 +#undef AuOpt_UDBA_HNOTIFY
20885 +#define AuOpt_UDBA_HNOTIFY 0
20887 +#ifndef CONFIG_AUFS_SHWH
20889 +#define AuOpt_SHWH 0
20892 +#define AuOpt_Def (AuOpt_XINO \
20893 + | AuOpt_UDBA_REVAL \
20895 + /* | AuOpt_DIRPERM1 */ \
20896 + | AuOpt_WARN_PERM)
20897 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
20898 + | AuOpt_UDBA_REVAL \
20899 + | AuOpt_UDBA_HNOTIFY)
20901 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
20902 +#define au_opt_set(flags, name) do { \
20903 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
20904 + ((flags) |= AuOpt_##name); \
20906 +#define au_opt_set_udba(flags, name) do { \
20907 + (flags) &= ~AuOptMask_UDBA; \
20908 + ((flags) |= AuOpt_##name); \
20910 +#define au_opt_clr(flags, name) do { \
20911 + ((flags) &= ~AuOpt_##name); \
20914 +static inline unsigned int au_opts_plink(unsigned int mntflags)
20916 +#ifdef CONFIG_PROC_FS
20919 + return mntflags & ~AuOpt_PLINK;
20923 +/* ---------------------------------------------------------------------- */
20925 +/* policies to select one among multiple writable branches */
20927 + AuWbrCreate_TDP, /* top down parent */
20928 + AuWbrCreate_RR, /* round robin */
20929 + AuWbrCreate_MFS, /* most free space */
20930 + AuWbrCreate_MFSV, /* mfs with seconds */
20931 + AuWbrCreate_MFSRR, /* mfs then rr */
20932 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
20933 + AuWbrCreate_PMFS, /* parent and mfs */
20934 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
20936 + AuWbrCreate_Def = AuWbrCreate_TDP
20940 + AuWbrCopyup_TDP, /* top down parent */
20941 + AuWbrCopyup_BUP, /* bottom up parent */
20942 + AuWbrCopyup_BU, /* bottom up */
20944 + AuWbrCopyup_Def = AuWbrCopyup_TDP
20947 +/* ---------------------------------------------------------------------- */
20949 +struct au_opt_add {
20950 + aufs_bindex_t bindex;
20953 + struct path path;
20956 +struct au_opt_del {
20958 + struct path h_path;
20961 +struct au_opt_mod {
20964 + struct dentry *h_root;
20967 +struct au_opt_xino {
20969 + struct file *file;
20972 +struct au_opt_xino_itrunc {
20973 + aufs_bindex_t bindex;
20976 +struct au_opt_wbr_create {
20979 + unsigned long long mfsrr_watermark;
20985 + struct au_opt_xino xino;
20986 + struct au_opt_xino_itrunc xino_itrunc;
20987 + struct au_opt_add add;
20988 + struct au_opt_del del;
20989 + struct au_opt_mod mod;
20992 + unsigned int rdblk;
20993 + unsigned int rdhash;
20995 + struct au_opt_wbr_create wbr_create;
21001 +#define AuOpts_REMOUNT 1
21002 +#define AuOpts_REFRESH (1 << 1)
21003 +#define AuOpts_TRUNC_XIB (1 << 2)
21004 +#define AuOpts_REFRESH_DYAOP (1 << 3)
21005 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
21006 +#define au_fset_opts(flags, name) \
21007 + do { (flags) |= AuOpts_##name; } while (0)
21008 +#define au_fclr_opts(flags, name) \
21009 + do { (flags) &= ~AuOpts_##name; } while (0)
21012 + struct au_opt *opt;
21015 + unsigned int given_udba;
21016 + unsigned int flags;
21017 + unsigned long sb_flags;
21020 +/* ---------------------------------------------------------------------- */
21022 +char *au_optstr_br_perm(int brperm);
21023 +const char *au_optstr_udba(int udba);
21024 +const char *au_optstr_wbr_copyup(int wbr_copyup);
21025 +const char *au_optstr_wbr_create(int wbr_create);
21027 +void au_opts_free(struct au_opts *opts);
21028 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
21029 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
21030 + unsigned int pending);
21031 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
21032 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
21034 +unsigned int au_opt_udba(struct super_block *sb);
21036 +/* ---------------------------------------------------------------------- */
21038 +#endif /* __KERNEL__ */
21039 +#endif /* __AUFS_OPTS_H__ */
21040 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
21041 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
21042 +++ linux/fs/aufs/plink.c 2012-03-19 12:24:13.683134508 +0100
21045 + * Copyright (C) 2005-2012 Junjiro R. Okajima
21047 + * This program, aufs is free software; you can redistribute it and/or modify
21048 + * it under the terms of the GNU General Public License as published by
21049 + * the Free Software Foundation; either version 2 of the License, or
21050 + * (at your option) any later version.
21052 + * This program is distributed in the hope that it will be useful,
21053 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21054 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21055 + * GNU General Public License for more details.
21057 + * You should have received a copy of the GNU General Public License
21058 + * along with this program; if not, write to the Free Software
21059 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21069 + * the pseudo-link maintenance mode.
21070 + * during a user process maintains the pseudo-links,
21071 + * prohibit adding a new plink and branch manipulation.
21075 + * For entry functions which will handle plink, and i_mutex is already held
21077 + * They cannot wait and should return an error at once.
21078 + * Callers has to check the error.
21080 + * For entry functions which will handle plink, but i_mutex is not held
21082 + * They can wait the plink maintenance mode to finish.
21084 + * They behave like F_SETLK and F_SETLKW.
21085 + * If the caller never handle plink, then both flags are unnecessary.
21088 +int au_plink_maint(struct super_block *sb, int flags)
21092 + struct au_sbinfo *sbi;
21094 + SiMustAnyLock(sb);
21097 + if (!au_opt_test(au_mntflags(sb), PLINK))
21100 + sbi = au_sbi(sb);
21101 + pid = sbi->si_plink_maint_pid;
21102 + if (!pid || pid == current->pid)
21105 + /* todo: it highly depends upon /sbin/mount.aufs */
21107 + ppid = task_pid_vnr(rcu_dereference(current->real_parent));
21108 + rcu_read_unlock();
21112 + if (au_ftest_lock(flags, NOPLMW)) {
21113 + /* if there is no i_mutex lock in VFS, we don't need to wait */
21114 + /* AuDebugOn(!lockdep_depth(current)); */
21115 + while (sbi->si_plink_maint_pid) {
21116 + si_read_unlock(sb);
21117 + /* gave up wake_up_bit() */
21118 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
21120 + if (au_ftest_lock(flags, FLUSH))
21121 + au_nwt_flush(&sbi->si_nowait);
21122 + si_noflush_read_lock(sb);
21124 + } else if (au_ftest_lock(flags, NOPLM)) {
21125 + AuDbg("ppid %d, pid %d\n", ppid, pid);
21133 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
21135 + spin_lock(&sbinfo->si_plink_maint_lock);
21136 + sbinfo->si_plink_maint_pid = 0;
21137 + spin_unlock(&sbinfo->si_plink_maint_lock);
21138 + wake_up_all(&sbinfo->si_plink_wq);
21141 +int au_plink_maint_enter(struct super_block *sb)
21144 + struct au_sbinfo *sbinfo;
21147 + sbinfo = au_sbi(sb);
21148 + /* make sure i am the only one in this fs */
21149 + si_write_lock(sb, AuLock_FLUSH);
21150 + if (au_opt_test(au_mntflags(sb), PLINK)) {
21151 + spin_lock(&sbinfo->si_plink_maint_lock);
21152 + if (!sbinfo->si_plink_maint_pid)
21153 + sbinfo->si_plink_maint_pid = current->pid;
21156 + spin_unlock(&sbinfo->si_plink_maint_lock);
21158 + si_write_unlock(sb);
21163 +/* ---------------------------------------------------------------------- */
21165 +struct pseudo_link {
21167 + struct list_head list;
21168 + struct rcu_head rcu;
21170 + struct inode *inode;
21173 +#ifdef CONFIG_AUFS_DEBUG
21174 +void au_plink_list(struct super_block *sb)
21176 + struct au_sbinfo *sbinfo;
21177 + struct list_head *plink_list;
21178 + struct pseudo_link *plink;
21180 + SiMustAnyLock(sb);
21182 + sbinfo = au_sbi(sb);
21183 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
21184 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
21186 + plink_list = &sbinfo->si_plink.head;
21188 + list_for_each_entry_rcu(plink, plink_list, list)
21189 + AuDbg("%lu\n", plink->inode->i_ino);
21190 + rcu_read_unlock();
21194 +/* is the inode pseudo-linked? */
21195 +int au_plink_test(struct inode *inode)
21198 + struct au_sbinfo *sbinfo;
21199 + struct list_head *plink_list;
21200 + struct pseudo_link *plink;
21202 + sbinfo = au_sbi(inode->i_sb);
21203 + AuRwMustAnyLock(&sbinfo->si_rwsem);
21204 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
21205 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
21208 + plink_list = &sbinfo->si_plink.head;
21210 + list_for_each_entry_rcu(plink, plink_list, list)
21211 + if (plink->inode == inode) {
21215 + rcu_read_unlock();
21219 +/* ---------------------------------------------------------------------- */
21222 + * generate a name for plink.
21223 + * the file will be stored under AUFS_WH_PLINKDIR.
21225 +/* 20 is max digits length of ulong 64 */
21226 +#define PLINK_NAME_LEN ((20 + 1) * 2)
21228 +static int plink_name(char *name, int len, struct inode *inode,
21229 + aufs_bindex_t bindex)
21232 + struct inode *h_inode;
21234 + h_inode = au_h_iptr(inode, bindex);
21235 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
21239 +struct au_do_plink_lkup_args {
21240 + struct dentry **errp;
21241 + struct qstr *tgtname;
21242 + struct dentry *h_parent;
21243 + struct au_branch *br;
21246 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
21247 + struct dentry *h_parent,
21248 + struct au_branch *br)
21250 + struct dentry *h_dentry;
21251 + struct mutex *h_mtx;
21253 + h_mtx = &h_parent->d_inode->i_mutex;
21254 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
21255 + h_dentry = au_lkup_one(tgtname, h_parent, br, /*nd*/NULL);
21256 + mutex_unlock(h_mtx);
21260 +static void au_call_do_plink_lkup(void *args)
21262 + struct au_do_plink_lkup_args *a = args;
21263 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
21266 +/* lookup the plink-ed @inode under the branch at @bindex */
21267 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
21269 + struct dentry *h_dentry, *h_parent;
21270 + struct au_branch *br;
21271 + struct inode *h_dir;
21273 + char a[PLINK_NAME_LEN];
21274 + struct qstr tgtname = {
21278 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
21280 + br = au_sbr(inode->i_sb, bindex);
21281 + h_parent = br->br_wbr->wbr_plink;
21282 + h_dir = h_parent->d_inode;
21283 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
21285 + if (current_fsuid()) {
21286 + struct au_do_plink_lkup_args args = {
21287 + .errp = &h_dentry,
21288 + .tgtname = &tgtname,
21289 + .h_parent = h_parent,
21293 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
21294 + if (unlikely(wkq_err))
21295 + h_dentry = ERR_PTR(wkq_err);
21297 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
21302 +/* create a pseudo-link */
21303 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
21304 + struct dentry *h_dentry, struct au_branch *br)
21307 + struct path h_path = {
21308 + .mnt = br->br_mnt
21310 + struct inode *h_dir;
21312 + h_dir = h_parent->d_inode;
21313 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_CHILD2);
21315 + h_path.dentry = au_lkup_one(tgt, h_parent, br, /*nd*/NULL);
21316 + err = PTR_ERR(h_path.dentry);
21317 + if (IS_ERR(h_path.dentry))
21321 + /* wh.plink dir is not monitored */
21322 + /* todo: is it really safe? */
21323 + if (h_path.dentry->d_inode
21324 + && h_path.dentry->d_inode != h_dentry->d_inode) {
21325 + err = vfsub_unlink(h_dir, &h_path, /*force*/0);
21326 + dput(h_path.dentry);
21327 + h_path.dentry = NULL;
21331 + if (!err && !h_path.dentry->d_inode)
21332 + err = vfsub_link(h_dentry, h_dir, &h_path);
21333 + dput(h_path.dentry);
21336 + mutex_unlock(&h_dir->i_mutex);
21340 +struct do_whplink_args {
21342 + struct qstr *tgt;
21343 + struct dentry *h_parent;
21344 + struct dentry *h_dentry;
21345 + struct au_branch *br;
21348 +static void call_do_whplink(void *args)
21350 + struct do_whplink_args *a = args;
21351 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
21354 +static int whplink(struct dentry *h_dentry, struct inode *inode,
21355 + aufs_bindex_t bindex, struct au_branch *br)
21357 + int err, wkq_err;
21358 + struct au_wbr *wbr;
21359 + struct dentry *h_parent;
21360 + struct inode *h_dir;
21361 + char a[PLINK_NAME_LEN];
21362 + struct qstr tgtname = {
21366 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
21367 + h_parent = wbr->wbr_plink;
21368 + h_dir = h_parent->d_inode;
21369 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
21371 + /* always superio. */
21372 + if (current_fsuid()) {
21373 + struct do_whplink_args args = {
21376 + .h_parent = h_parent,
21377 + .h_dentry = h_dentry,
21380 + wkq_err = au_wkq_wait(call_do_whplink, &args);
21381 + if (unlikely(wkq_err))
21384 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
21389 +/* free a single plink */
21390 +static void do_put_plink(struct pseudo_link *plink, int do_del)
21393 + list_del(&plink->list);
21394 + iput(plink->inode);
21398 +static void do_put_plink_rcu(struct rcu_head *rcu)
21400 + struct pseudo_link *plink;
21402 + plink = container_of(rcu, struct pseudo_link, rcu);
21403 + iput(plink->inode);
21408 + * create a new pseudo-link for @h_dentry on @bindex.
21409 + * the linked inode is held in aufs @inode.
21411 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
21412 + struct dentry *h_dentry)
21414 + struct super_block *sb;
21415 + struct au_sbinfo *sbinfo;
21416 + struct list_head *plink_list;
21417 + struct pseudo_link *plink, *tmp;
21418 + int found, err, cnt;
21420 + sb = inode->i_sb;
21421 + sbinfo = au_sbi(sb);
21422 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
21423 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
21427 + plink_list = &sbinfo->si_plink.head;
21429 + list_for_each_entry_rcu(plink, plink_list, list) {
21431 + if (plink->inode == inode) {
21436 + rcu_read_unlock();
21440 + tmp = kmalloc(sizeof(*plink), GFP_NOFS);
21442 + tmp->inode = au_igrab(inode);
21448 + spin_lock(&sbinfo->si_plink.spin);
21449 + list_for_each_entry(plink, plink_list, list) {
21450 + if (plink->inode == inode) {
21456 + list_add_rcu(&tmp->list, plink_list);
21457 + spin_unlock(&sbinfo->si_plink.spin);
21460 + WARN_ONCE(cnt > AUFS_PLINK_WARN,
21461 + "unexpectedly many pseudo links, %d\n", cnt);
21462 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
21464 + do_put_plink(tmp, 0);
21469 + if (unlikely(err)) {
21470 + pr_warning("err %d, damaged pseudo link.\n", err);
21472 + au_spl_del_rcu(&tmp->list, &sbinfo->si_plink);
21473 + call_rcu(&tmp->rcu, do_put_plink_rcu);
21478 +/* free all plinks */
21479 +void au_plink_put(struct super_block *sb, int verbose)
21481 + struct au_sbinfo *sbinfo;
21482 + struct list_head *plink_list;
21483 + struct pseudo_link *plink, *tmp;
21485 + SiMustWriteLock(sb);
21487 + sbinfo = au_sbi(sb);
21488 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
21489 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
21491 + plink_list = &sbinfo->si_plink.head;
21492 + /* no spin_lock since sbinfo is write-locked */
21493 + WARN(verbose && !list_empty(plink_list), "pseudo-link is not flushed");
21494 + list_for_each_entry_safe(plink, tmp, plink_list, list)
21495 + do_put_plink(plink, 0);
21496 + INIT_LIST_HEAD(plink_list);
21499 +void au_plink_clean(struct super_block *sb, int verbose)
21501 + struct dentry *root;
21503 + root = sb->s_root;
21504 + aufs_write_lock(root);
21505 + if (au_opt_test(au_mntflags(sb), PLINK))
21506 + au_plink_put(sb, verbose);
21507 + aufs_write_unlock(root);
21510 +/* free the plinks on a branch specified by @br_id */
21511 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
21513 + struct au_sbinfo *sbinfo;
21514 + struct list_head *plink_list;
21515 + struct pseudo_link *plink, *tmp;
21516 + struct inode *inode;
21517 + aufs_bindex_t bstart, bend, bindex;
21518 + unsigned char do_put;
21520 + SiMustWriteLock(sb);
21522 + sbinfo = au_sbi(sb);
21523 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
21524 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
21526 + plink_list = &sbinfo->si_plink.head;
21527 + /* no spin_lock since sbinfo is write-locked */
21528 + list_for_each_entry_safe(plink, tmp, plink_list, list) {
21530 + inode = au_igrab(plink->inode);
21531 + ii_write_lock_child(inode);
21532 + bstart = au_ibstart(inode);
21533 + bend = au_ibend(inode);
21534 + if (bstart >= 0) {
21535 + for (bindex = bstart; bindex <= bend; bindex++) {
21536 + if (!au_h_iptr(inode, bindex)
21537 + || au_ii_br_id(inode, bindex) != br_id)
21539 + au_set_h_iptr(inode, bindex, NULL, 0);
21544 + do_put_plink(plink, 1);
21547 + for (bindex = bstart; bindex <= bend; bindex++)
21548 + if (au_h_iptr(inode, bindex)) {
21553 + do_put_plink(plink, 1);
21555 + ii_write_unlock(inode);
21559 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
21560 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
21561 +++ linux/fs/aufs/poll.c 2012-03-19 12:24:13.683134508 +0100
21564 + * Copyright (C) 2005-2012 Junjiro R. Okajima
21566 + * This program, aufs is free software; you can redistribute it and/or modify
21567 + * it under the terms of the GNU General Public License as published by
21568 + * the Free Software Foundation; either version 2 of the License, or
21569 + * (at your option) any later version.
21571 + * This program is distributed in the hope that it will be useful,
21572 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21573 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21574 + * GNU General Public License for more details.
21576 + * You should have received a copy of the GNU General Public License
21577 + * along with this program; if not, write to the Free Software
21578 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21583 + * There is only one filesystem which implements ->poll operation, currently.
21588 +unsigned int aufs_poll(struct file *file, poll_table *wait)
21590 + unsigned int mask;
21592 + struct file *h_file;
21593 + struct dentry *dentry;
21594 + struct super_block *sb;
21596 + /* We should pretend an error happened. */
21597 + mask = POLLERR /* | POLLIN | POLLOUT */;
21598 + dentry = file->f_dentry;
21599 + sb = dentry->d_sb;
21600 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
21601 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
21602 + if (unlikely(err))
21605 + /* it is not an error if h_file has no operation */
21606 + mask = DEFAULT_POLLMASK;
21607 + h_file = au_hf_top(file);
21608 + if (h_file->f_op && h_file->f_op->poll)
21609 + mask = h_file->f_op->poll(h_file, wait);
21611 + di_read_unlock(dentry, AuLock_IR);
21612 + fi_read_unlock(file);
21615 + si_read_unlock(sb);
21616 + AuTraceErr((int)mask);
21619 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
21620 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
21621 +++ linux/fs/aufs/procfs.c 2012-03-19 12:24:13.683134508 +0100
21624 + * Copyright (C) 2010-2012 Junjiro R. Okajima
21626 + * This program, aufs is free software; you can redistribute it and/or modify
21627 + * it under the terms of the GNU General Public License as published by
21628 + * the Free Software Foundation; either version 2 of the License, or
21629 + * (at your option) any later version.
21631 + * This program is distributed in the hope that it will be useful,
21632 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21633 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21634 + * GNU General Public License for more details.
21636 + * You should have received a copy of the GNU General Public License
21637 + * along with this program; if not, write to the Free Software
21638 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21642 + * procfs interfaces
21645 +#include <linux/proc_fs.h>
21648 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
21650 + struct au_sbinfo *sbinfo;
21652 + sbinfo = file->private_data;
21654 + au_plink_maint_leave(sbinfo);
21655 + kobject_put(&sbinfo->si_kobj);
21661 +static void au_procfs_plm_write_clean(struct file *file)
21663 + struct au_sbinfo *sbinfo;
21665 + sbinfo = file->private_data;
21667 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
21670 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
21673 + struct super_block *sb;
21674 + struct au_sbinfo *sbinfo;
21677 + if (unlikely(file->private_data))
21681 + /* don't use au_sbilist_lock() here */
21682 + spin_lock(&au_sbilist.spin);
21683 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
21684 + if (id == sysaufs_si_id(sbinfo)) {
21685 + kobject_get(&sbinfo->si_kobj);
21686 + sb = sbinfo->si_sb;
21689 + spin_unlock(&au_sbilist.spin);
21692 + if (unlikely(!sb))
21695 + err = au_plink_maint_enter(sb);
21697 + /* keep kobject_get() */
21698 + file->private_data = sbinfo;
21700 + kobject_put(&sbinfo->si_kobj);
21706 + * Accept a valid "si=xxxx" only.
21707 + * Once it is accepted successfully, accept "clean" too.
21709 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
21710 + size_t count, loff_t *ppos)
21713 + unsigned long id;
21714 + /* last newline is allowed */
21715 + char buf[3 + sizeof(unsigned long) * 2 + 1];
21718 + if (unlikely(!capable(CAP_SYS_ADMIN)))
21722 + if (unlikely(count > sizeof(buf)))
21725 + err = copy_from_user(buf, ubuf, count);
21726 + if (unlikely(err)) {
21733 + if (!strcmp("clean", buf)) {
21734 + au_procfs_plm_write_clean(file);
21735 + goto out_success;
21736 + } else if (unlikely(strncmp("si=", buf, 3)))
21739 + err = kstrtoul(buf + 3, 16, &id);
21740 + if (unlikely(err))
21743 + err = au_procfs_plm_write_si(file, id);
21744 + if (unlikely(err))
21748 + err = count; /* success */
21753 +static const struct file_operations au_procfs_plm_fop = {
21754 + .write = au_procfs_plm_write,
21755 + .release = au_procfs_plm_release,
21756 + .owner = THIS_MODULE
21759 +/* ---------------------------------------------------------------------- */
21761 +static struct proc_dir_entry *au_procfs_dir;
21763 +void au_procfs_fin(void)
21765 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
21766 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
21769 +int __init au_procfs_init(void)
21772 + struct proc_dir_entry *entry;
21775 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
21776 + if (unlikely(!au_procfs_dir))
21779 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR,
21780 + au_procfs_dir, &au_procfs_plm_fop);
21781 + if (unlikely(!entry))
21785 + goto out; /* success */
21789 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
21793 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
21794 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
21795 +++ linux/fs/aufs/rdu.c 2012-03-19 12:24:13.683134508 +0100
21798 + * Copyright (C) 2005-2012 Junjiro R. Okajima
21800 + * This program, aufs is free software; you can redistribute it and/or modify
21801 + * it under the terms of the GNU General Public License as published by
21802 + * the Free Software Foundation; either version 2 of the License, or
21803 + * (at your option) any later version.
21805 + * This program is distributed in the hope that it will be useful,
21806 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21807 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21808 + * GNU General Public License for more details.
21810 + * You should have received a copy of the GNU General Public License
21811 + * along with this program; if not, write to the Free Software
21812 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21816 + * readdir in userspace.
21819 +#include <linux/compat.h>
21820 +#include <linux/fs_stack.h>
21821 +#include <linux/security.h>
21824 +/* bits for struct aufs_rdu.flags */
21825 +#define AuRdu_CALLED 1
21826 +#define AuRdu_CONT (1 << 1)
21827 +#define AuRdu_FULL (1 << 2)
21828 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
21829 +#define au_fset_rdu(flags, name) \
21830 + do { (flags) |= AuRdu_##name; } while (0)
21831 +#define au_fclr_rdu(flags, name) \
21832 + do { (flags) &= ~AuRdu_##name; } while (0)
21834 +struct au_rdu_arg {
21835 + struct aufs_rdu *rdu;
21836 + union au_rdu_ent_ul ent;
21837 + unsigned long end;
21839 + struct super_block *sb;
21843 +static int au_rdu_fill(void *__arg, const char *name, int nlen,
21844 + loff_t offset, u64 h_ino, unsigned int d_type)
21847 + struct au_rdu_arg *arg = __arg;
21848 + struct aufs_rdu *rdu = arg->rdu;
21849 + struct au_rdu_ent ent;
21853 + au_fset_rdu(rdu->cookie.flags, CALLED);
21854 + len = au_rdu_len(nlen);
21855 + if (arg->ent.ul + len < arg->end) {
21857 + ent.bindex = rdu->cookie.bindex;
21858 + ent.type = d_type;
21860 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
21861 + ent.type = DT_UNKNOWN;
21863 + /* unnecessary to support mmap_sem since this is a dir */
21865 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
21867 + if (copy_to_user(arg->ent.e->name, name, nlen))
21869 + /* the terminating NULL */
21870 + if (__put_user(0, arg->ent.e->name + nlen))
21873 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
21874 + arg->ent.ul += len;
21878 + au_fset_rdu(rdu->cookie.flags, FULL);
21880 + rdu->tail = arg->ent;
21884 + /* AuTraceErr(err); */
21888 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
21892 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
21894 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
21896 + if (unlikely(offset != cookie->h_pos))
21902 + au_fclr_rdu(cookie->flags, CALLED);
21904 + err = vfsub_readdir(h_file, au_rdu_fill, arg);
21908 + && au_ftest_rdu(cookie->flags, CALLED)
21909 + && !au_ftest_rdu(cookie->flags, FULL));
21910 + cookie->h_pos = h_file->f_pos;
21917 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
21920 + aufs_bindex_t bend;
21921 + struct au_rdu_arg arg;
21922 + struct dentry *dentry;
21923 + struct inode *inode;
21924 + struct file *h_file;
21925 + struct au_rdu_cookie *cookie = &rdu->cookie;
21927 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
21928 + if (unlikely(err)) {
21934 + rdu->tail = rdu->ent;
21937 + arg.ent = rdu->ent;
21938 + arg.end = arg.ent.ul;
21939 + arg.end += rdu->sz;
21942 + if (unlikely(!file->f_op || !file->f_op->readdir))
21945 + err = security_file_permission(file, MAY_READ);
21947 + if (unlikely(err))
21950 + dentry = file->f_dentry;
21951 + inode = dentry->d_inode;
21953 + mutex_lock(&inode->i_mutex);
21955 + err = mutex_lock_killable(&inode->i_mutex);
21957 + if (unlikely(err))
21961 + arg.sb = inode->i_sb;
21962 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
21963 + if (unlikely(err))
21965 + err = au_alive_dir(dentry);
21966 + if (unlikely(err))
21968 + /* todo: reval? */
21969 + fi_read_lock(file);
21972 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
21973 + && cookie->generation != au_figen(file)))
21978 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
21980 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
21982 + bend = au_fbstart(file);
21983 + if (cookie->bindex < bend)
21984 + cookie->bindex = bend;
21985 + bend = au_fbend_dir(file);
21986 + /* AuDbg("b%d, b%d\n", cookie->bindex, bend); */
21987 + for (; !err && cookie->bindex <= bend;
21988 + cookie->bindex++, cookie->h_pos = 0) {
21989 + h_file = au_hf_dir(file, cookie->bindex);
21993 + au_fclr_rdu(cookie->flags, FULL);
21994 + err = au_rdu_do(h_file, &arg);
21996 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
21999 + AuDbg("rent %llu\n", rdu->rent);
22001 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
22002 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
22003 + au_fset_rdu(cookie->flags, CONT);
22004 + cookie->generation = au_figen(file);
22007 + ii_read_lock_child(inode);
22008 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibstart(inode)));
22009 + ii_read_unlock(inode);
22012 + fi_read_unlock(file);
22014 + si_read_unlock(arg.sb);
22016 + mutex_unlock(&inode->i_mutex);
22022 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
22026 + unsigned long long nent;
22027 + union au_rdu_ent_ul *u;
22028 + struct au_rdu_ent ent;
22029 + struct super_block *sb;
22032 + nent = rdu->nent;
22034 + sb = file->f_dentry->d_sb;
22035 + si_read_lock(sb, AuLock_FLUSH);
22036 + while (nent-- > 0) {
22037 + /* unnecessary to support mmap_sem since this is a dir */
22038 + err = copy_from_user(&ent, u->e, sizeof(ent));
22040 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
22041 + if (unlikely(err)) {
22047 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
22049 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
22051 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
22053 + if (unlikely(err)) {
22058 + err = __put_user(ino, &u->e->ino);
22059 + if (unlikely(err)) {
22064 + u->ul += au_rdu_len(ent.nlen);
22066 + si_read_unlock(sb);
22071 +/* ---------------------------------------------------------------------- */
22073 +static int au_rdu_verify(struct aufs_rdu *rdu)
22075 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
22076 + "%llu, b%d, 0x%x, g%u}\n",
22077 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
22079 + rdu->rent, rdu->shwh, rdu->full,
22080 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
22081 + rdu->cookie.generation);
22083 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
22087 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
22091 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
22094 + struct aufs_rdu rdu;
22095 + void __user *p = (void __user *)arg;
22097 + err = copy_from_user(&rdu, p, sizeof(rdu));
22098 + if (unlikely(err)) {
22103 + err = au_rdu_verify(&rdu);
22104 + if (unlikely(err))
22108 + case AUFS_CTL_RDU:
22109 + err = au_rdu(file, &rdu);
22110 + if (unlikely(err))
22113 + e = copy_to_user(p, &rdu, sizeof(rdu));
22114 + if (unlikely(e)) {
22119 + case AUFS_CTL_RDU_INO:
22120 + err = au_rdu_ino(file, &rdu);
22124 + /* err = -ENOTTY; */
22133 +#ifdef CONFIG_COMPAT
22134 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
22137 + struct aufs_rdu rdu;
22138 + void __user *p = compat_ptr(arg);
22140 + /* todo: get_user()? */
22141 + err = copy_from_user(&rdu, p, sizeof(rdu));
22142 + if (unlikely(err)) {
22147 + rdu.ent.e = compat_ptr(rdu.ent.ul);
22148 + err = au_rdu_verify(&rdu);
22149 + if (unlikely(err))
22153 + case AUFS_CTL_RDU:
22154 + err = au_rdu(file, &rdu);
22155 + if (unlikely(err))
22158 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
22159 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
22160 + e = copy_to_user(p, &rdu, sizeof(rdu));
22161 + if (unlikely(e)) {
22166 + case AUFS_CTL_RDU_INO:
22167 + err = au_rdu_ino(file, &rdu);
22171 + /* err = -ENOTTY; */
22180 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
22181 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
22182 +++ linux/fs/aufs/rwsem.h 2012-03-19 12:24:13.683134508 +0100
22185 + * Copyright (C) 2005-2012 Junjiro R. Okajima
22187 + * This program, aufs is free software; you can redistribute it and/or modify
22188 + * it under the terms of the GNU General Public License as published by
22189 + * the Free Software Foundation; either version 2 of the License, or
22190 + * (at your option) any later version.
22192 + * This program is distributed in the hope that it will be useful,
22193 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22194 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22195 + * GNU General Public License for more details.
22197 + * You should have received a copy of the GNU General Public License
22198 + * along with this program; if not, write to the Free Software
22199 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22203 + * simple read-write semaphore wrappers
22206 +#ifndef __AUFS_RWSEM_H__
22207 +#define __AUFS_RWSEM_H__
22211 +#include "debug.h"
22214 + struct rw_semaphore rwsem;
22215 +#ifdef CONFIG_AUFS_DEBUG
22216 + /* just for debugging, not almighty counter */
22217 + atomic_t rcnt, wcnt;
22221 +#ifdef CONFIG_AUFS_DEBUG
22222 +#define AuDbgCntInit(rw) do { \
22223 + atomic_set(&(rw)->rcnt, 0); \
22224 + atomic_set(&(rw)->wcnt, 0); \
22225 + smp_mb(); /* atomic set */ \
22228 +#define AuDbgRcntInc(rw) atomic_inc(&(rw)->rcnt)
22229 +#define AuDbgRcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->rcnt) < 0)
22230 +#define AuDbgWcntInc(rw) atomic_inc(&(rw)->wcnt)
22231 +#define AuDbgWcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->wcnt) < 0)
22233 +#define AuDbgCntInit(rw) do {} while (0)
22234 +#define AuDbgRcntInc(rw) do {} while (0)
22235 +#define AuDbgRcntDec(rw) do {} while (0)
22236 +#define AuDbgWcntInc(rw) do {} while (0)
22237 +#define AuDbgWcntDec(rw) do {} while (0)
22238 +#endif /* CONFIG_AUFS_DEBUG */
22240 +/* to debug easier, do not make them inlined functions */
22241 +#define AuRwMustNoWaiters(rw) AuDebugOn(!list_empty(&(rw)->rwsem.wait_list))
22242 +/* rwsem_is_locked() is unusable */
22243 +#define AuRwMustReadLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0)
22244 +#define AuRwMustWriteLock(rw) AuDebugOn(atomic_read(&(rw)->wcnt) <= 0)
22245 +#define AuRwMustAnyLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0 \
22246 + && atomic_read(&(rw)->wcnt) <= 0)
22247 +#define AuRwDestroy(rw) AuDebugOn(atomic_read(&(rw)->rcnt) \
22248 + || atomic_read(&(rw)->wcnt))
22250 +#define au_rw_class(rw, key) lockdep_set_class(&(rw)->rwsem, key)
22252 +static inline void au_rw_init(struct au_rwsem *rw)
22254 + AuDbgCntInit(rw);
22255 + init_rwsem(&rw->rwsem);
22258 +static inline void au_rw_init_wlock(struct au_rwsem *rw)
22261 + down_write(&rw->rwsem);
22262 + AuDbgWcntInc(rw);
22265 +static inline void au_rw_init_wlock_nested(struct au_rwsem *rw,
22266 + unsigned int lsc)
22269 + down_write_nested(&rw->rwsem, lsc);
22270 + AuDbgWcntInc(rw);
22273 +static inline void au_rw_read_lock(struct au_rwsem *rw)
22275 + down_read(&rw->rwsem);
22276 + AuDbgRcntInc(rw);
22279 +static inline void au_rw_read_lock_nested(struct au_rwsem *rw, unsigned int lsc)
22281 + down_read_nested(&rw->rwsem, lsc);
22282 + AuDbgRcntInc(rw);
22285 +static inline void au_rw_read_unlock(struct au_rwsem *rw)
22287 + AuRwMustReadLock(rw);
22288 + AuDbgRcntDec(rw);
22289 + up_read(&rw->rwsem);
22292 +static inline void au_rw_dgrade_lock(struct au_rwsem *rw)
22294 + AuRwMustWriteLock(rw);
22295 + AuDbgRcntInc(rw);
22296 + AuDbgWcntDec(rw);
22297 + downgrade_write(&rw->rwsem);
22300 +static inline void au_rw_write_lock(struct au_rwsem *rw)
22302 + down_write(&rw->rwsem);
22303 + AuDbgWcntInc(rw);
22306 +static inline void au_rw_write_lock_nested(struct au_rwsem *rw,
22307 + unsigned int lsc)
22309 + down_write_nested(&rw->rwsem, lsc);
22310 + AuDbgWcntInc(rw);
22313 +static inline void au_rw_write_unlock(struct au_rwsem *rw)
22315 + AuRwMustWriteLock(rw);
22316 + AuDbgWcntDec(rw);
22317 + up_write(&rw->rwsem);
22320 +/* why is not _nested version defined */
22321 +static inline int au_rw_read_trylock(struct au_rwsem *rw)
22323 + int ret = down_read_trylock(&rw->rwsem);
22325 + AuDbgRcntInc(rw);
22329 +static inline int au_rw_write_trylock(struct au_rwsem *rw)
22331 + int ret = down_write_trylock(&rw->rwsem);
22333 + AuDbgWcntInc(rw);
22337 +#undef AuDbgCntInit
22338 +#undef AuDbgRcntInc
22339 +#undef AuDbgRcntDec
22340 +#undef AuDbgWcntInc
22341 +#undef AuDbgWcntDec
22343 +#define AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
22344 +static inline void prefix##_read_lock(param) \
22345 +{ au_rw_read_lock(rwsem); } \
22346 +static inline void prefix##_write_lock(param) \
22347 +{ au_rw_write_lock(rwsem); } \
22348 +static inline int prefix##_read_trylock(param) \
22349 +{ return au_rw_read_trylock(rwsem); } \
22350 +static inline int prefix##_write_trylock(param) \
22351 +{ return au_rw_write_trylock(rwsem); }
22352 +/* why is not _nested version defined */
22353 +/* static inline void prefix##_read_trylock_nested(param, lsc)
22354 +{ au_rw_read_trylock_nested(rwsem, lsc)); }
22355 +static inline void prefix##_write_trylock_nestd(param, lsc)
22356 +{ au_rw_write_trylock_nested(rwsem, lsc); } */
22358 +#define AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) \
22359 +static inline void prefix##_read_unlock(param) \
22360 +{ au_rw_read_unlock(rwsem); } \
22361 +static inline void prefix##_write_unlock(param) \
22362 +{ au_rw_write_unlock(rwsem); } \
22363 +static inline void prefix##_downgrade_lock(param) \
22364 +{ au_rw_dgrade_lock(rwsem); }
22366 +#define AuSimpleRwsemFuncs(prefix, param, rwsem) \
22367 + AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
22368 + AuSimpleUnlockRwsemFuncs(prefix, param, rwsem)
22370 +#endif /* __KERNEL__ */
22371 +#endif /* __AUFS_RWSEM_H__ */
22372 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
22373 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
22374 +++ linux/fs/aufs/sbinfo.c 2012-03-19 12:24:13.683134508 +0100
22377 + * Copyright (C) 2005-2012 Junjiro R. Okajima
22379 + * This program, aufs is free software; you can redistribute it and/or modify
22380 + * it under the terms of the GNU General Public License as published by
22381 + * the Free Software Foundation; either version 2 of the License, or
22382 + * (at your option) any later version.
22384 + * This program is distributed in the hope that it will be useful,
22385 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22386 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22387 + * GNU General Public License for more details.
22389 + * You should have received a copy of the GNU General Public License
22390 + * along with this program; if not, write to the Free Software
22391 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22395 + * superblock private data
22401 + * they are necessary regardless sysfs is disabled.
22403 +void au_si_free(struct kobject *kobj)
22405 + struct au_sbinfo *sbinfo;
22406 + char *locked __maybe_unused; /* debug only */
22408 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
22409 + AuDebugOn(!list_empty(&sbinfo->si_plink.head));
22410 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
22412 + au_rw_write_lock(&sbinfo->si_rwsem);
22413 + au_br_free(sbinfo);
22414 + au_rw_write_unlock(&sbinfo->si_rwsem);
22416 + AuDebugOn(radix_tree_gang_lookup
22417 + (&sbinfo->au_si_pid.tree, (void **)&locked,
22418 + /*first_index*/PID_MAX_DEFAULT - 1,
22419 + /*max_items*/sizeof(locked)/sizeof(*locked)));
22421 + kfree(sbinfo->si_branch);
22422 + kfree(sbinfo->au_si_pid.bitmap);
22423 + mutex_destroy(&sbinfo->si_xib_mtx);
22424 + AuRwDestroy(&sbinfo->si_rwsem);
22429 +int au_si_alloc(struct super_block *sb)
22432 + struct au_sbinfo *sbinfo;
22433 + static struct lock_class_key aufs_si;
22436 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
22437 + if (unlikely(!sbinfo))
22440 + BUILD_BUG_ON(sizeof(unsigned long) !=
22441 + sizeof(*sbinfo->au_si_pid.bitmap));
22442 + sbinfo->au_si_pid.bitmap = kcalloc(BITS_TO_LONGS(PID_MAX_DEFAULT),
22443 + sizeof(*sbinfo->au_si_pid.bitmap),
22445 + if (unlikely(!sbinfo->au_si_pid.bitmap))
22448 + /* will be reallocated separately */
22449 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
22450 + if (unlikely(!sbinfo->si_branch))
22453 + err = sysaufs_si_init(sbinfo);
22454 + if (unlikely(err))
22457 + au_nwt_init(&sbinfo->si_nowait);
22458 + au_rw_init_wlock(&sbinfo->si_rwsem);
22459 + au_rw_class(&sbinfo->si_rwsem, &aufs_si);
22460 + spin_lock_init(&sbinfo->au_si_pid.tree_lock);
22461 + INIT_RADIX_TREE(&sbinfo->au_si_pid.tree, GFP_ATOMIC | __GFP_NOFAIL);
22463 + atomic_long_set(&sbinfo->si_ninodes, 0);
22464 + atomic_long_set(&sbinfo->si_nfiles, 0);
22466 + sbinfo->si_bend = -1;
22468 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
22469 + sbinfo->si_wbr_create = AuWbrCreate_Def;
22470 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
22471 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
22473 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
22475 + mutex_init(&sbinfo->si_xib_mtx);
22476 + sbinfo->si_xino_brid = -1;
22477 + /* leave si_xib_last_pindex and si_xib_next_bit */
22479 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
22480 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
22481 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
22482 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
22484 + au_spl_init(&sbinfo->si_plink);
22485 + init_waitqueue_head(&sbinfo->si_plink_wq);
22486 + spin_lock_init(&sbinfo->si_plink_maint_lock);
22488 + /* leave other members for sysaufs and si_mnt. */
22489 + sbinfo->si_sb = sb;
22490 + sb->s_fs_info = sbinfo;
22492 + au_debug_sbinfo_init(sbinfo);
22493 + return 0; /* success */
22496 + kfree(sbinfo->si_branch);
22498 + kfree(sbinfo->au_si_pid.bitmap);
22505 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr)
22508 + struct au_branch **brp;
22510 + AuRwMustWriteLock(&sbinfo->si_rwsem);
22513 + sz = sizeof(*brp) * (sbinfo->si_bend + 1);
22514 + if (unlikely(!sz))
22515 + sz = sizeof(*brp);
22516 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS);
22518 + sbinfo->si_branch = brp;
22525 +/* ---------------------------------------------------------------------- */
22527 +unsigned int au_sigen_inc(struct super_block *sb)
22529 + unsigned int gen;
22531 + SiMustWriteLock(sb);
22533 + gen = ++au_sbi(sb)->si_generation;
22534 + au_update_digen(sb->s_root);
22535 + au_update_iigen(sb->s_root->d_inode);
22536 + sb->s_root->d_inode->i_version++;
22540 +aufs_bindex_t au_new_br_id(struct super_block *sb)
22542 + aufs_bindex_t br_id;
22544 + struct au_sbinfo *sbinfo;
22546 + SiMustWriteLock(sb);
22548 + sbinfo = au_sbi(sb);
22549 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
22550 + br_id = ++sbinfo->si_last_br_id;
22551 + AuDebugOn(br_id < 0);
22552 + if (br_id && au_br_index(sb, br_id) < 0)
22559 +/* ---------------------------------------------------------------------- */
22561 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
22562 +int si_read_lock(struct super_block *sb, int flags)
22567 + if (au_ftest_lock(flags, FLUSH))
22568 + au_nwt_flush(&au_sbi(sb)->si_nowait);
22570 + si_noflush_read_lock(sb);
22571 + err = au_plink_maint(sb, flags);
22572 + if (unlikely(err))
22573 + si_read_unlock(sb);
22578 +int si_write_lock(struct super_block *sb, int flags)
22582 + if (au_ftest_lock(flags, FLUSH))
22583 + au_nwt_flush(&au_sbi(sb)->si_nowait);
22585 + si_noflush_write_lock(sb);
22586 + err = au_plink_maint(sb, flags);
22587 + if (unlikely(err))
22588 + si_write_unlock(sb);
22593 +/* dentry and super_block lock. call at entry point */
22594 +int aufs_read_lock(struct dentry *dentry, int flags)
22597 + struct super_block *sb;
22599 + sb = dentry->d_sb;
22600 + err = si_read_lock(sb, flags);
22601 + if (unlikely(err))
22604 + if (au_ftest_lock(flags, DW))
22605 + di_write_lock_child(dentry);
22607 + di_read_lock_child(dentry, flags);
22609 + if (au_ftest_lock(flags, GEN)) {
22610 + err = au_digen_test(dentry, au_sigen(sb));
22611 + AuDebugOn(!err && au_dbrange_test(dentry));
22612 + if (unlikely(err))
22613 + aufs_read_unlock(dentry, flags);
22620 +void aufs_read_unlock(struct dentry *dentry, int flags)
22622 + if (au_ftest_lock(flags, DW))
22623 + di_write_unlock(dentry);
22625 + di_read_unlock(dentry, flags);
22626 + si_read_unlock(dentry->d_sb);
22629 +void aufs_write_lock(struct dentry *dentry)
22631 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
22632 + di_write_lock_child(dentry);
22635 +void aufs_write_unlock(struct dentry *dentry)
22637 + di_write_unlock(dentry);
22638 + si_write_unlock(dentry->d_sb);
22641 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
22644 + unsigned int sigen;
22645 + struct super_block *sb;
22648 + err = si_read_lock(sb, flags);
22649 + if (unlikely(err))
22652 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIR));
22654 + if (au_ftest_lock(flags, GEN)) {
22655 + sigen = au_sigen(sb);
22656 + err = au_digen_test(d1, sigen);
22657 + AuDebugOn(!err && au_dbrange_test(d1));
22659 + err = au_digen_test(d2, sigen);
22660 + AuDebugOn(!err && au_dbrange_test(d2));
22662 + if (unlikely(err))
22663 + aufs_read_and_write_unlock2(d1, d2);
22670 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
22672 + di_write_unlock2(d1, d2);
22673 + si_read_unlock(d1->d_sb);
22676 +/* ---------------------------------------------------------------------- */
22678 +int si_pid_test_slow(struct super_block *sb)
22683 + p = radix_tree_lookup(&au_sbi(sb)->au_si_pid.tree, current->pid);
22684 + rcu_read_unlock();
22686 + return (long)!!p;
22689 +void si_pid_set_slow(struct super_block *sb)
22692 + struct au_sbinfo *sbinfo;
22694 + AuDebugOn(si_pid_test_slow(sb));
22696 + sbinfo = au_sbi(sb);
22697 + err = radix_tree_preload(GFP_NOFS | __GFP_NOFAIL);
22699 + spin_lock(&sbinfo->au_si_pid.tree_lock);
22700 + err = radix_tree_insert(&sbinfo->au_si_pid.tree, current->pid,
22701 + /*any valid ptr*/sb);
22702 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
22704 + radix_tree_preload_end();
22707 +void si_pid_clr_slow(struct super_block *sb)
22710 + struct au_sbinfo *sbinfo;
22712 + AuDebugOn(!si_pid_test_slow(sb));
22714 + sbinfo = au_sbi(sb);
22715 + spin_lock(&sbinfo->au_si_pid.tree_lock);
22716 + p = radix_tree_delete(&sbinfo->au_si_pid.tree, current->pid);
22717 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
22719 diff -urN /usr/share/empty/fs/aufs/spl.h linux/fs/aufs/spl.h
22720 --- /usr/share/empty/fs/aufs/spl.h 1970-01-01 01:00:00.000000000 +0100
22721 +++ linux/fs/aufs/spl.h 2012-03-19 12:24:13.683134508 +0100
22724 + * Copyright (C) 2005-2012 Junjiro R. Okajima
22726 + * This program, aufs is free software; you can redistribute it and/or modify
22727 + * it under the terms of the GNU General Public License as published by
22728 + * the Free Software Foundation; either version 2 of the License, or
22729 + * (at your option) any later version.
22731 + * This program is distributed in the hope that it will be useful,
22732 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22733 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22734 + * GNU General Public License for more details.
22736 + * You should have received a copy of the GNU General Public License
22737 + * along with this program; if not, write to the Free Software
22738 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22742 + * simple list protected by a spinlock
22745 +#ifndef __AUFS_SPL_H__
22746 +#define __AUFS_SPL_H__
22750 +struct au_splhead {
22752 + struct list_head head;
22755 +static inline void au_spl_init(struct au_splhead *spl)
22757 + spin_lock_init(&spl->spin);
22758 + INIT_LIST_HEAD(&spl->head);
22761 +static inline void au_spl_add(struct list_head *list, struct au_splhead *spl)
22763 + spin_lock(&spl->spin);
22764 + list_add(list, &spl->head);
22765 + spin_unlock(&spl->spin);
22768 +static inline void au_spl_del(struct list_head *list, struct au_splhead *spl)
22770 + spin_lock(&spl->spin);
22772 + spin_unlock(&spl->spin);
22775 +static inline void au_spl_del_rcu(struct list_head *list,
22776 + struct au_splhead *spl)
22778 + spin_lock(&spl->spin);
22779 + list_del_rcu(list);
22780 + spin_unlock(&spl->spin);
22783 +#endif /* __KERNEL__ */
22784 +#endif /* __AUFS_SPL_H__ */
22785 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
22786 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
22787 +++ linux/fs/aufs/super.c 2012-03-19 12:24:13.683134508 +0100
22790 + * Copyright (C) 2005-2012 Junjiro R. Okajima
22792 + * This program, aufs is free software; you can redistribute it and/or modify
22793 + * it under the terms of the GNU General Public License as published by
22794 + * the Free Software Foundation; either version 2 of the License, or
22795 + * (at your option) any later version.
22797 + * This program is distributed in the hope that it will be useful,
22798 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22799 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22800 + * GNU General Public License for more details.
22802 + * You should have received a copy of the GNU General Public License
22803 + * along with this program; if not, write to the Free Software
22804 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22808 + * mount and super_block operations
22811 +#include <linux/mm.h>
22812 +#include <linux/module.h>
22813 +#include <linux/seq_file.h>
22814 +#include <linux/statfs.h>
22815 +#include <linux/vmalloc.h>
22816 +#include <linux/writeback.h>
22820 + * super_operations
22822 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
22824 + struct au_icntnr *c;
22826 + c = au_cache_alloc_icntnr();
22828 + au_icntnr_init(c);
22829 + c->vfs_inode.i_version = 1; /* sigen(sb); */
22830 + c->iinfo.ii_hinode = NULL;
22831 + return &c->vfs_inode;
22836 +static void aufs_destroy_inode_cb(struct rcu_head *head)
22838 + struct inode *inode = container_of(head, struct inode, i_rcu);
22840 + INIT_LIST_HEAD(&inode->i_dentry);
22841 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
22844 +static void aufs_destroy_inode(struct inode *inode)
22846 + au_iinfo_fin(inode);
22847 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
22850 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
22852 + struct inode *inode;
22855 + inode = iget_locked(sb, ino);
22856 + if (unlikely(!inode)) {
22857 + inode = ERR_PTR(-ENOMEM);
22860 + if (!(inode->i_state & I_NEW))
22863 + err = au_xigen_new(inode);
22865 + err = au_iinfo_init(inode);
22867 + inode->i_version++;
22869 + iget_failed(inode);
22870 + inode = ERR_PTR(err);
22874 + /* never return NULL */
22875 + AuDebugOn(!inode);
22876 + AuTraceErrPtr(inode);
22880 +/* lock free root dinfo */
22881 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
22884 + aufs_bindex_t bindex, bend;
22885 + struct path path;
22886 + struct au_hdentry *hdp;
22887 + struct au_branch *br;
22891 + bend = au_sbend(sb);
22892 + hdp = au_di(sb->s_root)->di_hdentry;
22893 + for (bindex = 0; !err && bindex <= bend; bindex++) {
22894 + br = au_sbr(sb, bindex);
22895 + path.mnt = br->br_mnt;
22896 + path.dentry = hdp[bindex].hd_dentry;
22897 + err = au_seq_path(seq, &path);
22899 + perm = au_optstr_br_perm(br->br_perm);
22901 + err = seq_printf(seq, "=%s", perm);
22908 + if (!err && bindex != bend)
22909 + err = seq_putc(seq, ':');
22915 +static void au_show_wbr_create(struct seq_file *m, int v,
22916 + struct au_sbinfo *sbinfo)
22920 + AuRwMustAnyLock(&sbinfo->si_rwsem);
22922 + seq_printf(m, ",create=");
22923 + pat = au_optstr_wbr_create(v);
22925 + case AuWbrCreate_TDP:
22926 + case AuWbrCreate_RR:
22927 + case AuWbrCreate_MFS:
22928 + case AuWbrCreate_PMFS:
22929 + seq_printf(m, pat);
22931 + case AuWbrCreate_MFSV:
22932 + seq_printf(m, /*pat*/"mfs:%lu",
22933 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
22936 + case AuWbrCreate_PMFSV:
22937 + seq_printf(m, /*pat*/"pmfs:%lu",
22938 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
22941 + case AuWbrCreate_MFSRR:
22942 + seq_printf(m, /*pat*/"mfsrr:%llu",
22943 + sbinfo->si_wbr_mfs.mfsrr_watermark);
22945 + case AuWbrCreate_MFSRRV:
22946 + seq_printf(m, /*pat*/"mfsrr:%llu:%lu",
22947 + sbinfo->si_wbr_mfs.mfsrr_watermark,
22948 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
22954 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
22956 +#ifdef CONFIG_SYSFS
22960 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
22961 + aufs_bindex_t bindex, brid;
22962 + struct qstr *name;
22964 + struct dentry *d, *h_root;
22965 + struct au_hdentry *hdp;
22967 + AuRwMustAnyLock(&sbinfo->si_rwsem);
22970 + f = au_sbi(sb)->si_xib;
22974 + /* stop printing the default xino path on the first writable branch */
22976 + brid = au_xino_brid(sb);
22978 + bindex = au_br_index(sb, brid);
22979 + hdp = au_di(sb->s_root)->di_hdentry;
22980 + h_root = hdp[0 + bindex].hd_dentry;
22983 + name = &d->d_name;
22984 + /* safe ->d_parent because the file is unlinked */
22985 + if (d->d_parent == h_root
22986 + && name->len == len
22987 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
22990 + seq_puts(seq, ",xino=");
22991 + err = au_xino_path(seq, f);
22998 +/* seq_file will re-call me in case of too long string */
22999 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
23002 + unsigned int mnt_flags, v;
23003 + struct super_block *sb;
23004 + struct au_sbinfo *sbinfo;
23006 +#define AuBool(name, str) do { \
23007 + v = au_opt_test(mnt_flags, name); \
23008 + if (v != au_opt_test(AuOpt_Def, name)) \
23009 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
23012 +#define AuStr(name, str) do { \
23013 + v = mnt_flags & AuOptMask_##name; \
23014 + if (v != (AuOpt_Def & AuOptMask_##name)) \
23015 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
23018 +#define AuUInt(name, str, val) do { \
23019 + if (val != AUFS_##name##_DEF) \
23020 + seq_printf(m, "," #str "=%u", val); \
23023 + /* lock free root dinfo */
23024 + sb = dentry->d_sb;
23025 + si_noflush_read_lock(sb);
23026 + sbinfo = au_sbi(sb);
23027 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
23029 + mnt_flags = au_mntflags(sb);
23030 + if (au_opt_test(mnt_flags, XINO)) {
23031 + err = au_show_xino(m, sb);
23032 + if (unlikely(err))
23035 + seq_puts(m, ",noxino");
23037 + AuBool(TRUNC_XINO, trunc_xino);
23038 + AuStr(UDBA, udba);
23039 + AuBool(SHWH, shwh);
23040 + AuBool(PLINK, plink);
23041 + AuBool(DIO, dio);
23042 + /* AuBool(DIRPERM1, dirperm1); */
23043 + /* AuBool(REFROF, refrof); */
23045 + v = sbinfo->si_wbr_create;
23046 + if (v != AuWbrCreate_Def)
23047 + au_show_wbr_create(m, v, sbinfo);
23049 + v = sbinfo->si_wbr_copyup;
23050 + if (v != AuWbrCopyup_Def)
23051 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
23053 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
23054 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
23055 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
23057 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
23059 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
23060 + AuUInt(RDCACHE, rdcache, v);
23062 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
23063 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
23065 + AuBool(SUM, sum);
23066 + /* AuBool(SUM_W, wsum); */
23067 + AuBool(WARN_PERM, warn_perm);
23068 + AuBool(VERBOSE, verbose);
23071 + /* be sure to print "br:" last */
23072 + if (!sysaufs_brs) {
23073 + seq_puts(m, ",br:");
23074 + au_show_brs(m, sb);
23076 + si_read_unlock(sb);
23084 +/* ---------------------------------------------------------------------- */
23086 +/* sum mode which returns the summation for statfs(2) */
23088 +static u64 au_add_till_max(u64 a, u64 b)
23096 + return ULLONG_MAX;
23099 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
23102 + u64 blocks, bfree, bavail, files, ffree;
23103 + aufs_bindex_t bend, bindex, i;
23104 + unsigned char shared;
23105 + struct path h_path;
23106 + struct super_block *h_sb;
23115 + bend = au_sbend(sb);
23116 + for (bindex = bend; bindex >= 0; bindex--) {
23117 + h_path.mnt = au_sbr_mnt(sb, bindex);
23118 + h_sb = h_path.mnt->mnt_sb;
23120 + for (i = bindex + 1; !shared && i <= bend; i++)
23121 + shared = (au_sbr_sb(sb, i) == h_sb);
23125 + /* sb->s_root for NFS is unreliable */
23126 + h_path.dentry = h_path.mnt->mnt_root;
23127 + err = vfs_statfs(&h_path, buf);
23128 + if (unlikely(err))
23131 + blocks = au_add_till_max(blocks, buf->f_blocks);
23132 + bfree = au_add_till_max(bfree, buf->f_bfree);
23133 + bavail = au_add_till_max(bavail, buf->f_bavail);
23134 + files = au_add_till_max(files, buf->f_files);
23135 + ffree = au_add_till_max(ffree, buf->f_ffree);
23138 + buf->f_blocks = blocks;
23139 + buf->f_bfree = bfree;
23140 + buf->f_bavail = bavail;
23141 + buf->f_files = files;
23142 + buf->f_ffree = ffree;
23148 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
23151 + struct path h_path;
23152 + struct super_block *sb;
23154 + /* lock free root dinfo */
23155 + sb = dentry->d_sb;
23156 + si_noflush_read_lock(sb);
23157 + if (!au_opt_test(au_mntflags(sb), SUM)) {
23158 + /* sb->s_root for NFS is unreliable */
23159 + h_path.mnt = au_sbr_mnt(sb, 0);
23160 + h_path.dentry = h_path.mnt->mnt_root;
23161 + err = vfs_statfs(&h_path, buf);
23163 + err = au_statfs_sum(sb, buf);
23164 + si_read_unlock(sb);
23167 + buf->f_type = AUFS_SUPER_MAGIC;
23168 + buf->f_namelen = AUFS_MAX_NAMELEN;
23169 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
23171 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
23176 +/* ---------------------------------------------------------------------- */
23178 +/* final actions when unmounting a file system */
23179 +static void aufs_put_super(struct super_block *sb)
23181 + struct au_sbinfo *sbinfo;
23183 + sbinfo = au_sbi(sb);
23187 + dbgaufs_si_fin(sbinfo);
23188 + kobject_put(&sbinfo->si_kobj);
23191 +/* ---------------------------------------------------------------------- */
23193 +void au_array_free(void *array)
23196 + if (!is_vmalloc_addr(array))
23203 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg)
23206 + unsigned long long n;
23213 + if (*hint > ULLONG_MAX / sizeof(array)) {
23214 + array = ERR_PTR(-EMFILE);
23215 + pr_err("hint %llu\n", *hint);
23219 + array = kmalloc(sizeof(array) * *hint, GFP_NOFS);
23220 + if (unlikely(!array))
23221 + array = vmalloc(sizeof(array) * *hint);
23222 + if (unlikely(!array)) {
23223 + array = ERR_PTR(-ENOMEM);
23227 + n = cb(array, *hint, arg);
23228 + AuDebugOn(n > *hint);
23235 +static unsigned long long au_iarray_cb(void *a,
23236 + unsigned long long max __maybe_unused,
23239 + unsigned long long n;
23240 + struct inode **p, *inode;
23241 + struct list_head *head;
23246 + spin_lock(&inode_sb_list_lock);
23247 + list_for_each_entry(inode, head, i_sb_list) {
23248 + if (!is_bad_inode(inode)
23249 + && au_ii(inode)->ii_bstart >= 0) {
23250 + spin_lock(&inode->i_lock);
23251 + if (atomic_read(&inode->i_count)) {
23255 + AuDebugOn(n > max);
23257 + spin_unlock(&inode->i_lock);
23260 + spin_unlock(&inode_sb_list_lock);
23265 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
23267 + *max = atomic_long_read(&au_sbi(sb)->si_ninodes);
23268 + return au_array_alloc(max, au_iarray_cb, &sb->s_inodes);
23271 +void au_iarray_free(struct inode **a, unsigned long long max)
23273 + unsigned long long ull;
23275 + for (ull = 0; ull < max; ull++)
23277 + au_array_free(a);
23280 +/* ---------------------------------------------------------------------- */
23283 + * refresh dentry and inode at remount time.
23285 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
23286 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
23287 + struct dentry *parent)
23291 + di_write_lock_child(dentry);
23292 + di_read_lock_parent(parent, AuLock_IR);
23293 + err = au_refresh_dentry(dentry, parent);
23294 + if (!err && dir_flags)
23295 + au_hn_reset(dentry->d_inode, dir_flags);
23296 + di_read_unlock(parent, AuLock_IR);
23297 + di_write_unlock(dentry);
23302 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
23303 + struct au_sbinfo *sbinfo,
23304 + const unsigned int dir_flags)
23307 + struct dentry *parent;
23308 + struct inode *inode;
23311 + parent = dget_parent(dentry);
23312 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
23313 + inode = dentry->d_inode;
23315 + if (!S_ISDIR(inode->i_mode))
23316 + err = au_do_refresh(dentry, /*dir_flags*/0,
23319 + err = au_do_refresh(dentry, dir_flags, parent);
23320 + if (unlikely(err))
23321 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
23324 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
23325 + AuDbgDentry(dentry);
23333 +static int au_refresh_d(struct super_block *sb)
23335 + int err, i, j, ndentry, e;
23336 + unsigned int sigen;
23337 + struct au_dcsub_pages dpages;
23338 + struct au_dpage *dpage;
23339 + struct dentry **dentries, *d;
23340 + struct au_sbinfo *sbinfo;
23341 + struct dentry *root = sb->s_root;
23342 + const unsigned int dir_flags = au_hi_flags(root->d_inode, /*isdir*/1);
23344 + err = au_dpages_init(&dpages, GFP_NOFS);
23345 + if (unlikely(err))
23347 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
23348 + if (unlikely(err))
23351 + sigen = au_sigen(sb);
23352 + sbinfo = au_sbi(sb);
23353 + for (i = 0; i < dpages.ndpage; i++) {
23354 + dpage = dpages.dpages + i;
23355 + dentries = dpage->dentries;
23356 + ndentry = dpage->ndentry;
23357 + for (j = 0; j < ndentry; j++) {
23359 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags);
23360 + if (unlikely(e && !err))
23362 + /* go on even err */
23367 + au_dpages_free(&dpages);
23372 +static int au_refresh_i(struct super_block *sb)
23375 + unsigned int sigen;
23376 + unsigned long long max, ull;
23377 + struct inode *inode, **array;
23379 + array = au_iarray_alloc(sb, &max);
23380 + err = PTR_ERR(array);
23381 + if (IS_ERR(array))
23385 + sigen = au_sigen(sb);
23386 + for (ull = 0; ull < max; ull++) {
23387 + inode = array[ull];
23388 + if (au_iigen(inode) != sigen) {
23389 + ii_write_lock_child(inode);
23390 + e = au_refresh_hinode_self(inode);
23391 + ii_write_unlock(inode);
23392 + if (unlikely(e)) {
23393 + pr_err("error %d, i%lu\n", e, inode->i_ino);
23396 + /* go on even if err */
23401 + au_iarray_free(array, max);
23407 +static void au_remount_refresh(struct super_block *sb)
23410 + unsigned int udba;
23411 + aufs_bindex_t bindex, bend;
23412 + struct dentry *root;
23413 + struct inode *inode;
23414 + struct au_branch *br;
23416 + au_sigen_inc(sb);
23417 + au_fclr_si(au_sbi(sb), FAILED_REFRESH_DIR);
23419 + root = sb->s_root;
23420 + DiMustNoWaiters(root);
23421 + inode = root->d_inode;
23422 + IiMustNoWaiters(inode);
23424 + udba = au_opt_udba(sb);
23425 + bend = au_sbend(sb);
23426 + for (bindex = 0; bindex <= bend; bindex++) {
23427 + br = au_sbr(sb, bindex);
23428 + err = au_hnotify_reset_br(udba, br, br->br_perm);
23429 + if (unlikely(err))
23430 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
23432 + /* go on even if err */
23434 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
23436 + di_write_unlock(root);
23437 + err = au_refresh_d(sb);
23438 + e = au_refresh_i(sb);
23439 + if (unlikely(e && !err))
23441 + /* aufs_write_lock() calls ..._child() */
23442 + di_write_lock_child(root);
23444 + au_cpup_attr_all(inode, /*force*/1);
23446 + if (unlikely(err))
23447 + AuIOErr("refresh failed, ignored, %d\n", err);
23450 +/* stop extra interpretation of errno in mount(8), and strange error messages */
23451 +static int cvt_err(int err)
23465 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
23468 + unsigned int mntflags;
23469 + struct au_opts opts;
23470 + struct dentry *root;
23471 + struct inode *inode;
23472 + struct au_sbinfo *sbinfo;
23475 + root = sb->s_root;
23476 + if (!data || !*data) {
23477 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
23479 + di_write_lock_child(root);
23480 + err = au_opts_verify(sb, *flags, /*pending*/0);
23481 + aufs_write_unlock(root);
23487 + memset(&opts, 0, sizeof(opts));
23488 + opts.opt = (void *)__get_free_page(GFP_NOFS);
23489 + if (unlikely(!opts.opt))
23491 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
23492 + opts.flags = AuOpts_REMOUNT;
23493 + opts.sb_flags = *flags;
23495 + /* parse it before aufs lock */
23496 + err = au_opts_parse(sb, data, &opts);
23497 + if (unlikely(err))
23500 + sbinfo = au_sbi(sb);
23501 + inode = root->d_inode;
23502 + mutex_lock(&inode->i_mutex);
23503 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
23504 + if (unlikely(err))
23506 + di_write_lock_child(root);
23508 + /* au_opts_remount() may return an error */
23509 + err = au_opts_remount(sb, &opts);
23510 + au_opts_free(&opts);
23512 + if (au_ftest_opts(opts.flags, REFRESH))
23513 + au_remount_refresh(sb);
23515 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
23516 + mntflags = au_mntflags(sb);
23517 + do_dx = !!au_opt_test(mntflags, DIO);
23518 + au_dy_arefresh(do_dx);
23521 + aufs_write_unlock(root);
23524 + mutex_unlock(&inode->i_mutex);
23526 + free_page((unsigned long)opts.opt);
23528 + err = cvt_err(err);
23533 +static const struct super_operations aufs_sop = {
23534 + .alloc_inode = aufs_alloc_inode,
23535 + .destroy_inode = aufs_destroy_inode,
23536 + /* always deleting, no clearing */
23537 + .drop_inode = generic_delete_inode,
23538 + .show_options = aufs_show_options,
23539 + .statfs = aufs_statfs,
23540 + .put_super = aufs_put_super,
23541 + .remount_fs = aufs_remount_fs
23544 +/* ---------------------------------------------------------------------- */
23546 +static int alloc_root(struct super_block *sb)
23549 + struct inode *inode;
23550 + struct dentry *root;
23553 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
23554 + err = PTR_ERR(inode);
23555 + if (IS_ERR(inode))
23558 + inode->i_op = &aufs_dir_iop;
23559 + inode->i_fop = &aufs_dir_fop;
23560 + inode->i_mode = S_IFDIR;
23561 + set_nlink(inode, 2);
23562 + unlock_new_inode(inode);
23564 + root = d_alloc_root(inode);
23565 + if (unlikely(!root))
23567 + err = PTR_ERR(root);
23568 + if (IS_ERR(root))
23571 + err = au_di_init(root);
23573 + sb->s_root = root;
23574 + return 0; /* success */
23577 + goto out; /* do not iput */
23580 + iget_failed(inode);
23586 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
23587 + int silent __maybe_unused)
23590 + struct au_opts opts;
23591 + struct dentry *root;
23592 + struct inode *inode;
23593 + char *arg = raw_data;
23595 + if (unlikely(!arg || !*arg)) {
23597 + pr_err("no arg\n");
23602 + memset(&opts, 0, sizeof(opts));
23603 + opts.opt = (void *)__get_free_page(GFP_NOFS);
23604 + if (unlikely(!opts.opt))
23606 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
23607 + opts.sb_flags = sb->s_flags;
23609 + err = au_si_alloc(sb);
23610 + if (unlikely(err))
23613 + /* all timestamps always follow the ones on the branch */
23614 + sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
23615 + sb->s_op = &aufs_sop;
23616 + sb->s_d_op = &aufs_dop;
23617 + sb->s_magic = AUFS_SUPER_MAGIC;
23618 + sb->s_maxbytes = 0;
23619 + au_export_init(sb);
23621 + err = alloc_root(sb);
23622 + if (unlikely(err)) {
23623 + si_write_unlock(sb);
23626 + root = sb->s_root;
23627 + inode = root->d_inode;
23630 + * actually we can parse options regardless aufs lock here.
23631 + * but at remount time, parsing must be done before aufs lock.
23632 + * so we follow the same rule.
23634 + ii_write_lock_parent(inode);
23635 + aufs_write_unlock(root);
23636 + err = au_opts_parse(sb, arg, &opts);
23637 + if (unlikely(err))
23640 + /* lock vfs_inode first, then aufs. */
23641 + mutex_lock(&inode->i_mutex);
23642 + aufs_write_lock(root);
23643 + err = au_opts_mount(sb, &opts);
23644 + au_opts_free(&opts);
23645 + aufs_write_unlock(root);
23646 + mutex_unlock(&inode->i_mutex);
23648 + goto out_opts; /* success */
23652 + sb->s_root = NULL;
23654 + dbgaufs_si_fin(au_sbi(sb));
23655 + kobject_put(&au_sbi(sb)->si_kobj);
23656 + sb->s_fs_info = NULL;
23658 + free_page((unsigned long)opts.opt);
23661 + err = cvt_err(err);
23666 +/* ---------------------------------------------------------------------- */
23668 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
23669 + const char *dev_name __maybe_unused,
23672 + struct dentry *root;
23673 + struct super_block *sb;
23675 + /* all timestamps always follow the ones on the branch */
23676 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
23677 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
23678 + if (IS_ERR(root))
23682 + si_write_lock(sb, !AuLock_FLUSH);
23683 + sysaufs_brs_add(sb, 0);
23684 + si_write_unlock(sb);
23685 + au_sbilist_add(sb);
23691 +static void aufs_kill_sb(struct super_block *sb)
23693 + struct au_sbinfo *sbinfo;
23695 + sbinfo = au_sbi(sb);
23697 + au_sbilist_del(sb);
23698 + aufs_write_lock(sb->s_root);
23699 + if (sbinfo->si_wbr_create_ops->fin)
23700 + sbinfo->si_wbr_create_ops->fin(sb);
23701 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
23702 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
23703 + au_remount_refresh(sb);
23705 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
23706 + au_plink_put(sb, /*verbose*/1);
23708 + sbinfo->si_sb = NULL;
23709 + aufs_write_unlock(sb->s_root);
23710 + au_nwt_flush(&sbinfo->si_nowait);
23712 + generic_shutdown_super(sb);
23715 +struct file_system_type aufs_fs_type = {
23716 + .name = AUFS_FSTYPE,
23718 + FS_RENAME_DOES_D_MOVE /* a race between rename and others */
23719 + | FS_REVAL_DOT, /* for NFS branch and udba */
23720 + .mount = aufs_mount,
23721 + .kill_sb = aufs_kill_sb,
23722 + /* no need to __module_get() and module_put(). */
23723 + .owner = THIS_MODULE,
23725 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
23726 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
23727 +++ linux/fs/aufs/super.h 2012-03-19 12:24:13.686467926 +0100
23730 + * Copyright (C) 2005-2012 Junjiro R. Okajima
23732 + * This program, aufs is free software; you can redistribute it and/or modify
23733 + * it under the terms of the GNU General Public License as published by
23734 + * the Free Software Foundation; either version 2 of the License, or
23735 + * (at your option) any later version.
23737 + * This program is distributed in the hope that it will be useful,
23738 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23739 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23740 + * GNU General Public License for more details.
23742 + * You should have received a copy of the GNU General Public License
23743 + * along with this program; if not, write to the Free Software
23744 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23748 + * super_block operations
23751 +#ifndef __AUFS_SUPER_H__
23752 +#define __AUFS_SUPER_H__
23756 +#include <linux/fs.h>
23757 +#include "rwsem.h"
23761 +typedef ssize_t (*au_readf_t)(struct file *, char __user *, size_t, loff_t *);
23762 +typedef ssize_t (*au_writef_t)(struct file *, const char __user *, size_t,
23765 +/* policies to select one among multiple writable branches */
23766 +struct au_wbr_copyup_operations {
23767 + int (*copyup)(struct dentry *dentry);
23770 +struct au_wbr_create_operations {
23771 + int (*create)(struct dentry *dentry, int isdir);
23772 + int (*init)(struct super_block *sb);
23773 + int (*fin)(struct super_block *sb);
23776 +struct au_wbr_mfs {
23777 + struct mutex mfs_lock; /* protect this structure */
23778 + unsigned long mfs_jiffy;
23779 + unsigned long mfs_expire;
23780 + aufs_bindex_t mfs_bindex;
23782 + unsigned long long mfsrr_bytes;
23783 + unsigned long long mfsrr_watermark;
23787 +struct au_sbinfo {
23788 + /* nowait tasks in the system-wide workqueue */
23789 + struct au_nowait_tasks si_nowait;
23792 + * tried sb->s_umount, but failed due to the dependecy between i_mutex.
23793 + * rwsem for au_sbinfo is necessary.
23795 + struct au_rwsem si_rwsem;
23797 + /* prevent recursive locking in deleting inode */
23799 + unsigned long *bitmap;
23800 + spinlock_t tree_lock;
23801 + struct radix_tree_root tree;
23805 + * dirty approach to protect sb->sb_inodes and ->s_files from remount.
23807 + atomic_long_t si_ninodes, si_nfiles;
23809 + /* branch management */
23810 + unsigned int si_generation;
23812 + /* see above flags */
23813 + unsigned char au_si_status;
23815 + aufs_bindex_t si_bend;
23817 + /* dirty trick to keep br_id plus */
23818 + unsigned int si_last_br_id :
23819 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
23820 + struct au_branch **si_branch;
23822 + /* policy to select a writable branch */
23823 + unsigned char si_wbr_copyup;
23824 + unsigned char si_wbr_create;
23825 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
23826 + struct au_wbr_create_operations *si_wbr_create_ops;
23828 + /* round robin */
23829 + atomic_t si_wbr_rr_next;
23831 + /* most free space */
23832 + struct au_wbr_mfs si_wbr_mfs;
23834 + /* mount flags */
23835 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
23836 + unsigned int si_mntflags;
23838 + /* external inode number (bitmap and translation table) */
23839 + au_readf_t si_xread;
23840 + au_writef_t si_xwrite;
23841 + struct file *si_xib;
23842 + struct mutex si_xib_mtx; /* protect xib members */
23843 + unsigned long *si_xib_buf;
23844 + unsigned long si_xib_last_pindex;
23845 + int si_xib_next_bit;
23846 + aufs_bindex_t si_xino_brid;
23847 + /* reserved for future use */
23848 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
23850 +#ifdef CONFIG_AUFS_EXPORT
23851 + /* i_generation */
23852 + struct file *si_xigen;
23853 + atomic_t si_xigen_next;
23856 + /* vdir parameters */
23857 + unsigned long si_rdcache; /* max cache time in jiffies */
23858 + unsigned int si_rdblk; /* deblk size */
23859 + unsigned int si_rdhash; /* hash size */
23862 + * If the number of whiteouts are larger than si_dirwh, leave all of
23863 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
23864 + * future fsck.aufs or kernel thread will remove them later.
23865 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
23867 + unsigned int si_dirwh;
23870 + * rename(2) a directory with all children.
23872 + /* reserved for future use */
23873 + /* int si_rendir; */
23875 + /* pseudo_link list */
23876 + struct au_splhead si_plink;
23877 + wait_queue_head_t si_plink_wq;
23878 + spinlock_t si_plink_maint_lock;
23879 + pid_t si_plink_maint_pid;
23882 + * sysfs and lifetime management.
23883 + * this is not a small structure and it may be a waste of memory in case
23884 + * of sysfs is disabled, particulary when many aufs-es are mounted.
23885 + * but using sysfs is majority.
23887 + struct kobject si_kobj;
23888 +#ifdef CONFIG_DEBUG_FS
23889 + struct dentry *si_dbgaufs, *si_dbgaufs_xib;
23890 +#ifdef CONFIG_AUFS_EXPORT
23891 + struct dentry *si_dbgaufs_xigen;
23895 +#ifdef CONFIG_AUFS_SBILIST
23896 + struct list_head si_list;
23899 + /* dirty, necessary for unmounting, sysfs and sysrq */
23900 + struct super_block *si_sb;
23903 +/* sbinfo status flags */
23905 + * set true when refresh_dirs() failed at remount time.
23906 + * then try refreshing dirs at access time again.
23907 + * if it is false, refreshing dirs at access time is unnecesary
23909 +#define AuSi_FAILED_REFRESH_DIR 1
23910 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
23911 + unsigned int flag)
23913 + AuRwMustAnyLock(&sbi->si_rwsem);
23914 + return sbi->au_si_status & flag;
23916 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
23917 +#define au_fset_si(sbinfo, name) do { \
23918 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
23919 + (sbinfo)->au_si_status |= AuSi_##name; \
23921 +#define au_fclr_si(sbinfo, name) do { \
23922 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
23923 + (sbinfo)->au_si_status &= ~AuSi_##name; \
23926 +/* ---------------------------------------------------------------------- */
23928 +/* policy to select one among writable branches */
23929 +#define AuWbrCopyup(sbinfo, ...) \
23930 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
23931 +#define AuWbrCreate(sbinfo, ...) \
23932 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
23934 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
23935 +#define AuLock_DW 1 /* write-lock dentry */
23936 +#define AuLock_IR (1 << 1) /* read-lock inode */
23937 +#define AuLock_IW (1 << 2) /* write-lock inode */
23938 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
23939 +#define AuLock_DIR (1 << 4) /* target is a dir */
23940 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
23941 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
23942 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
23943 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
23944 +#define au_fset_lock(flags, name) \
23945 + do { (flags) |= AuLock_##name; } while (0)
23946 +#define au_fclr_lock(flags, name) \
23947 + do { (flags) &= ~AuLock_##name; } while (0)
23949 +/* ---------------------------------------------------------------------- */
23952 +extern struct file_system_type aufs_fs_type;
23953 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
23954 +typedef unsigned long long (*au_arraycb_t)(void *array, unsigned long long max,
23956 +void au_array_free(void *array);
23957 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg);
23958 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
23959 +void au_iarray_free(struct inode **a, unsigned long long max);
23962 +void au_si_free(struct kobject *kobj);
23963 +int au_si_alloc(struct super_block *sb);
23964 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr);
23966 +unsigned int au_sigen_inc(struct super_block *sb);
23967 +aufs_bindex_t au_new_br_id(struct super_block *sb);
23969 +int si_read_lock(struct super_block *sb, int flags);
23970 +int si_write_lock(struct super_block *sb, int flags);
23971 +int aufs_read_lock(struct dentry *dentry, int flags);
23972 +void aufs_read_unlock(struct dentry *dentry, int flags);
23973 +void aufs_write_lock(struct dentry *dentry);
23974 +void aufs_write_unlock(struct dentry *dentry);
23975 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
23976 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
23978 +int si_pid_test_slow(struct super_block *sb);
23979 +void si_pid_set_slow(struct super_block *sb);
23980 +void si_pid_clr_slow(struct super_block *sb);
23982 +/* wbr_policy.c */
23983 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
23984 +extern struct au_wbr_create_operations au_wbr_create_ops[];
23985 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
23987 +/* ---------------------------------------------------------------------- */
23989 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
23991 + return sb->s_fs_info;
23994 +/* ---------------------------------------------------------------------- */
23996 +#ifdef CONFIG_AUFS_EXPORT
23997 +void au_export_init(struct super_block *sb);
23999 +static inline int au_test_nfsd(void)
24001 + struct task_struct *tsk = current;
24003 + return (tsk->flags & PF_KTHREAD)
24004 + && !strcmp(tsk->comm, "nfsd");
24007 +void au_xigen_inc(struct inode *inode);
24008 +int au_xigen_new(struct inode *inode);
24009 +int au_xigen_set(struct super_block *sb, struct file *base);
24010 +void au_xigen_clr(struct super_block *sb);
24012 +static inline int au_busy_or_stale(void)
24014 + if (!au_test_nfsd())
24019 +AuStubVoid(au_export_init, struct super_block *sb)
24020 +AuStubInt0(au_test_nfsd, void)
24021 +AuStubVoid(au_xigen_inc, struct inode *inode)
24022 +AuStubInt0(au_xigen_new, struct inode *inode)
24023 +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base)
24024 +AuStubVoid(au_xigen_clr, struct super_block *sb)
24025 +static inline int au_busy_or_stale(void)
24029 +#endif /* CONFIG_AUFS_EXPORT */
24031 +/* ---------------------------------------------------------------------- */
24033 +#ifdef CONFIG_AUFS_SBILIST
24035 +extern struct au_splhead au_sbilist;
24037 +static inline void au_sbilist_init(void)
24039 + au_spl_init(&au_sbilist);
24042 +static inline void au_sbilist_add(struct super_block *sb)
24044 + au_spl_add(&au_sbi(sb)->si_list, &au_sbilist);
24047 +static inline void au_sbilist_del(struct super_block *sb)
24049 + au_spl_del(&au_sbi(sb)->si_list, &au_sbilist);
24052 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
24053 +static inline void au_sbilist_lock(void)
24055 + spin_lock(&au_sbilist.spin);
24058 +static inline void au_sbilist_unlock(void)
24060 + spin_unlock(&au_sbilist.spin);
24062 +#define AuGFP_SBILIST GFP_ATOMIC
24064 +AuStubVoid(au_sbilist_lock, void)
24065 +AuStubVoid(au_sbilist_unlock, void)
24066 +#define AuGFP_SBILIST GFP_NOFS
24067 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
24069 +AuStubVoid(au_sbilist_init, void)
24070 +AuStubVoid(au_sbilist_add, struct super_block*)
24071 +AuStubVoid(au_sbilist_del, struct super_block*)
24072 +AuStubVoid(au_sbilist_lock, void)
24073 +AuStubVoid(au_sbilist_unlock, void)
24074 +#define AuGFP_SBILIST GFP_NOFS
24077 +/* ---------------------------------------------------------------------- */
24079 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
24082 + * This function is a dynamic '__init' fucntion actually,
24083 + * so the tiny check for si_rwsem is unnecessary.
24085 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
24086 +#ifdef CONFIG_DEBUG_FS
24087 + sbinfo->si_dbgaufs = NULL;
24088 + sbinfo->si_dbgaufs_xib = NULL;
24089 +#ifdef CONFIG_AUFS_EXPORT
24090 + sbinfo->si_dbgaufs_xigen = NULL;
24095 +/* ---------------------------------------------------------------------- */
24097 +static inline pid_t si_pid_bit(void)
24099 + /* the origin of pid is 1, but the bitmap's is 0 */
24100 + return current->pid - 1;
24103 +static inline int si_pid_test(struct super_block *sb)
24105 + pid_t bit = si_pid_bit();
24106 + if (bit < PID_MAX_DEFAULT)
24107 + return test_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
24109 + return si_pid_test_slow(sb);
24112 +static inline void si_pid_set(struct super_block *sb)
24114 + pid_t bit = si_pid_bit();
24115 + if (bit < PID_MAX_DEFAULT) {
24116 + AuDebugOn(test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
24117 + set_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
24120 + si_pid_set_slow(sb);
24123 +static inline void si_pid_clr(struct super_block *sb)
24125 + pid_t bit = si_pid_bit();
24126 + if (bit < PID_MAX_DEFAULT) {
24127 + AuDebugOn(!test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
24128 + clear_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
24131 + si_pid_clr_slow(sb);
24134 +/* ---------------------------------------------------------------------- */
24136 +/* lock superblock. mainly for entry point functions */
24138 + * __si_read_lock, __si_write_lock,
24139 + * __si_read_unlock, __si_write_unlock, __si_downgrade_lock
24141 +AuSimpleRwsemFuncs(__si, struct super_block *sb, &au_sbi(sb)->si_rwsem);
24143 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
24144 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
24145 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
24147 +static inline void si_noflush_read_lock(struct super_block *sb)
24149 + __si_read_lock(sb);
24153 +static inline int si_noflush_read_trylock(struct super_block *sb)
24155 + int locked = __si_read_trylock(sb);
24161 +static inline void si_noflush_write_lock(struct super_block *sb)
24163 + __si_write_lock(sb);
24167 +static inline int si_noflush_write_trylock(struct super_block *sb)
24169 + int locked = __si_write_trylock(sb);
24175 +#if 0 /* unused */
24176 +static inline int si_read_trylock(struct super_block *sb, int flags)
24178 + if (au_ftest_lock(flags, FLUSH))
24179 + au_nwt_flush(&au_sbi(sb)->si_nowait);
24180 + return si_noflush_read_trylock(sb);
24184 +static inline void si_read_unlock(struct super_block *sb)
24187 + __si_read_unlock(sb);
24190 +#if 0 /* unused */
24191 +static inline int si_write_trylock(struct super_block *sb, int flags)
24193 + if (au_ftest_lock(flags, FLUSH))
24194 + au_nwt_flush(&au_sbi(sb)->si_nowait);
24195 + return si_noflush_write_trylock(sb);
24199 +static inline void si_write_unlock(struct super_block *sb)
24202 + __si_write_unlock(sb);
24205 +#if 0 /* unused */
24206 +static inline void si_downgrade_lock(struct super_block *sb)
24208 + __si_downgrade_lock(sb);
24212 +/* ---------------------------------------------------------------------- */
24214 +static inline aufs_bindex_t au_sbend(struct super_block *sb)
24216 + SiMustAnyLock(sb);
24217 + return au_sbi(sb)->si_bend;
24220 +static inline unsigned int au_mntflags(struct super_block *sb)
24222 + SiMustAnyLock(sb);
24223 + return au_sbi(sb)->si_mntflags;
24226 +static inline unsigned int au_sigen(struct super_block *sb)
24228 + SiMustAnyLock(sb);
24229 + return au_sbi(sb)->si_generation;
24232 +static inline void au_ninodes_inc(struct super_block *sb)
24234 + atomic_long_inc(&au_sbi(sb)->si_ninodes);
24237 +static inline void au_ninodes_dec(struct super_block *sb)
24239 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_ninodes));
24240 + atomic_long_dec(&au_sbi(sb)->si_ninodes);
24243 +static inline void au_nfiles_inc(struct super_block *sb)
24245 + atomic_long_inc(&au_sbi(sb)->si_nfiles);
24248 +static inline void au_nfiles_dec(struct super_block *sb)
24250 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_nfiles));
24251 + atomic_long_dec(&au_sbi(sb)->si_nfiles);
24254 +static inline struct au_branch *au_sbr(struct super_block *sb,
24255 + aufs_bindex_t bindex)
24257 + SiMustAnyLock(sb);
24258 + return au_sbi(sb)->si_branch[0 + bindex];
24261 +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid)
24263 + SiMustWriteLock(sb);
24264 + au_sbi(sb)->si_xino_brid = brid;
24267 +static inline aufs_bindex_t au_xino_brid(struct super_block *sb)
24269 + SiMustAnyLock(sb);
24270 + return au_sbi(sb)->si_xino_brid;
24273 +#endif /* __KERNEL__ */
24274 +#endif /* __AUFS_SUPER_H__ */
24275 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
24276 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
24277 +++ linux/fs/aufs/sysaufs.c 2012-03-19 12:24:13.686467926 +0100
24280 + * Copyright (C) 2005-2012 Junjiro R. Okajima
24282 + * This program, aufs is free software; you can redistribute it and/or modify
24283 + * it under the terms of the GNU General Public License as published by
24284 + * the Free Software Foundation; either version 2 of the License, or
24285 + * (at your option) any later version.
24287 + * This program is distributed in the hope that it will be useful,
24288 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24289 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24290 + * GNU General Public License for more details.
24292 + * You should have received a copy of the GNU General Public License
24293 + * along with this program; if not, write to the Free Software
24294 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24298 + * sysfs interface and lifetime management
24299 + * they are necessary regardless sysfs is disabled.
24302 +#include <linux/random.h>
24305 +unsigned long sysaufs_si_mask;
24306 +struct kset *sysaufs_kset;
24308 +#define AuSiAttr(_name) { \
24309 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
24310 + .show = sysaufs_si_##_name, \
24313 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
24314 +struct attribute *sysaufs_si_attrs[] = {
24315 + &sysaufs_si_attr_xi_path.attr,
24319 +static const struct sysfs_ops au_sbi_ops = {
24320 + .show = sysaufs_si_show
24323 +static struct kobj_type au_sbi_ktype = {
24324 + .release = au_si_free,
24325 + .sysfs_ops = &au_sbi_ops,
24326 + .default_attrs = sysaufs_si_attrs
24329 +/* ---------------------------------------------------------------------- */
24331 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
24335 + sbinfo->si_kobj.kset = sysaufs_kset;
24336 + /* cf. sysaufs_name() */
24337 + err = kobject_init_and_add
24338 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
24339 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
24341 + dbgaufs_si_null(sbinfo);
24343 + err = dbgaufs_si_init(sbinfo);
24344 + if (unlikely(err))
24345 + kobject_put(&sbinfo->si_kobj);
24350 +void sysaufs_fin(void)
24353 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
24354 + kset_unregister(sysaufs_kset);
24357 +int __init sysaufs_init(void)
24362 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
24363 + } while (!sysaufs_si_mask);
24366 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
24367 + if (unlikely(!sysaufs_kset))
24369 + err = PTR_ERR(sysaufs_kset);
24370 + if (IS_ERR(sysaufs_kset))
24372 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
24373 + if (unlikely(err)) {
24374 + kset_unregister(sysaufs_kset);
24378 + err = dbgaufs_init();
24379 + if (unlikely(err))
24384 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
24385 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
24386 +++ linux/fs/aufs/sysaufs.h 2012-03-19 12:24:13.686467926 +0100
24389 + * Copyright (C) 2005-2012 Junjiro R. Okajima
24391 + * This program, aufs is free software; you can redistribute it and/or modify
24392 + * it under the terms of the GNU General Public License as published by
24393 + * the Free Software Foundation; either version 2 of the License, or
24394 + * (at your option) any later version.
24396 + * This program is distributed in the hope that it will be useful,
24397 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24398 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24399 + * GNU General Public License for more details.
24401 + * You should have received a copy of the GNU General Public License
24402 + * along with this program; if not, write to the Free Software
24403 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24407 + * sysfs interface and mount lifetime management
24410 +#ifndef __SYSAUFS_H__
24411 +#define __SYSAUFS_H__
24415 +#include <linux/sysfs.h>
24416 +#include "module.h"
24418 +struct super_block;
24421 +struct sysaufs_si_attr {
24422 + struct attribute attr;
24423 + int (*show)(struct seq_file *seq, struct super_block *sb);
24426 +/* ---------------------------------------------------------------------- */
24429 +extern unsigned long sysaufs_si_mask;
24430 +extern struct kset *sysaufs_kset;
24431 +extern struct attribute *sysaufs_si_attrs[];
24432 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
24433 +int __init sysaufs_init(void);
24434 +void sysaufs_fin(void);
24436 +/* ---------------------------------------------------------------------- */
24438 +/* some people doesn't like to show a pointer in kernel */
24439 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
24441 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
24444 +#define SysaufsSiNamePrefix "si_"
24445 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
24446 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
24448 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
24449 + sysaufs_si_id(sbinfo));
24453 +#ifdef CONFIG_SYSFS
24455 +extern struct attribute_group *sysaufs_attr_group;
24457 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
24458 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
24461 +void sysaufs_br_init(struct au_branch *br);
24462 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
24463 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
24465 +#define sysaufs_brs_init() do {} while (0)
24468 +#define sysaufs_attr_group NULL
24470 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
24473 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
24479 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
24480 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
24481 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
24483 +static inline void sysaufs_brs_init(void)
24488 +#endif /* CONFIG_SYSFS */
24490 +#endif /* __KERNEL__ */
24491 +#endif /* __SYSAUFS_H__ */
24492 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
24493 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
24494 +++ linux/fs/aufs/sysfs.c 2012-03-19 12:24:13.686467926 +0100
24497 + * Copyright (C) 2005-2012 Junjiro R. Okajima
24499 + * This program, aufs is free software; you can redistribute it and/or modify
24500 + * it under the terms of the GNU General Public License as published by
24501 + * the Free Software Foundation; either version 2 of the License, or
24502 + * (at your option) any later version.
24504 + * This program is distributed in the hope that it will be useful,
24505 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24506 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24507 + * GNU General Public License for more details.
24509 + * You should have received a copy of the GNU General Public License
24510 + * along with this program; if not, write to the Free Software
24511 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24515 + * sysfs interface
24518 +#include <linux/seq_file.h>
24521 +#ifdef CONFIG_AUFS_FS_MODULE
24522 +/* this entry violates the "one line per file" policy of sysfs */
24523 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
24527 + static char *conf =
24528 +/* this file is generated at compiling */
24529 +#include "conf.str"
24532 + err = snprintf(buf, PAGE_SIZE, conf);
24533 + if (unlikely(err >= PAGE_SIZE))
24538 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
24541 +static struct attribute *au_attr[] = {
24542 +#ifdef CONFIG_AUFS_FS_MODULE
24543 + &au_config_attr.attr,
24545 + NULL, /* need to NULL terminate the list of attributes */
24548 +static struct attribute_group sysaufs_attr_group_body = {
24552 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
24554 +/* ---------------------------------------------------------------------- */
24556 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
24560 + SiMustAnyLock(sb);
24563 + if (au_opt_test(au_mntflags(sb), XINO)) {
24564 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
24565 + seq_putc(seq, '\n');
24571 + * the lifetime of branch is independent from the entry under sysfs.
24572 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
24575 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
24576 + aufs_bindex_t bindex)
24579 + struct path path;
24580 + struct dentry *root;
24581 + struct au_branch *br;
24584 + AuDbg("b%d\n", bindex);
24587 + root = sb->s_root;
24588 + di_read_lock_parent(root, !AuLock_IR);
24589 + br = au_sbr(sb, bindex);
24590 + path.mnt = br->br_mnt;
24591 + path.dentry = au_h_dptr(root, bindex);
24592 + au_seq_path(seq, &path);
24593 + di_read_unlock(root, !AuLock_IR);
24594 + perm = au_optstr_br_perm(br->br_perm);
24596 + err = seq_printf(seq, "=%s\n", perm);
24605 +/* ---------------------------------------------------------------------- */
24607 +static struct seq_file *au_seq(char *p, ssize_t len)
24609 + struct seq_file *seq;
24611 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
24613 + /* mutex_init(&seq.lock); */
24616 + return seq; /* success */
24619 + seq = ERR_PTR(-ENOMEM);
24623 +#define SysaufsBr_PREFIX "br"
24625 +/* todo: file size may exceed PAGE_SIZE */
24626 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
24631 + aufs_bindex_t bend;
24632 + struct au_sbinfo *sbinfo;
24633 + struct super_block *sb;
24634 + struct seq_file *seq;
24636 + struct attribute **cattr;
24638 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
24639 + sb = sbinfo->si_sb;
24642 + * prevent a race condition between sysfs and aufs.
24643 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
24644 + * prohibits maintaining the sysfs entries.
24645 + * hew we acquire read lock after sysfs_get_active_two().
24646 + * on the other hand, the remount process may maintain the sysfs/aufs
24647 + * entries after acquiring write lock.
24648 + * it can cause a deadlock.
24649 + * simply we gave up processing read here.
24652 + if (unlikely(!si_noflush_read_trylock(sb)))
24655 + seq = au_seq(buf, PAGE_SIZE);
24656 + err = PTR_ERR(seq);
24660 + name = (void *)attr->name;
24661 + cattr = sysaufs_si_attrs;
24663 + if (!strcmp(name, (*cattr)->name)) {
24664 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
24671 + bend = au_sbend(sb);
24672 + if (!strncmp(name, SysaufsBr_PREFIX, sizeof(SysaufsBr_PREFIX) - 1)) {
24673 + name += sizeof(SysaufsBr_PREFIX) - 1;
24674 + err = kstrtol(name, 10, &l);
24677 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l);
24687 + err = seq->count;
24688 + /* sysfs limit */
24689 + if (unlikely(err == PAGE_SIZE))
24694 + si_read_unlock(sb);
24699 +/* ---------------------------------------------------------------------- */
24701 +void sysaufs_br_init(struct au_branch *br)
24703 + struct attribute *attr = &br->br_attr;
24705 + sysfs_attr_init(attr);
24706 + attr->name = br->br_name;
24707 + attr->mode = S_IRUGO;
24710 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
24712 + struct au_branch *br;
24713 + struct kobject *kobj;
24714 + aufs_bindex_t bend;
24716 + dbgaufs_brs_del(sb, bindex);
24718 + if (!sysaufs_brs)
24721 + kobj = &au_sbi(sb)->si_kobj;
24722 + bend = au_sbend(sb);
24723 + for (; bindex <= bend; bindex++) {
24724 + br = au_sbr(sb, bindex);
24725 + sysfs_remove_file(kobj, &br->br_attr);
24729 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
24732 + aufs_bindex_t bend;
24733 + struct kobject *kobj;
24734 + struct au_branch *br;
24736 + dbgaufs_brs_add(sb, bindex);
24738 + if (!sysaufs_brs)
24741 + kobj = &au_sbi(sb)->si_kobj;
24742 + bend = au_sbend(sb);
24743 + for (; bindex <= bend; bindex++) {
24744 + br = au_sbr(sb, bindex);
24745 + snprintf(br->br_name, sizeof(br->br_name), SysaufsBr_PREFIX
24747 + err = sysfs_create_file(kobj, &br->br_attr);
24748 + if (unlikely(err))
24749 + pr_warning("failed %s under sysfs(%d)\n",
24750 + br->br_name, err);
24753 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
24754 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
24755 +++ linux/fs/aufs/sysrq.c 2012-03-19 12:24:13.686467926 +0100
24758 + * Copyright (C) 2005-2012 Junjiro R. Okajima
24760 + * This program, aufs is free software; you can redistribute it and/or modify
24761 + * it under the terms of the GNU General Public License as published by
24762 + * the Free Software Foundation; either version 2 of the License, or
24763 + * (at your option) any later version.
24765 + * This program is distributed in the hope that it will be useful,
24766 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24767 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24768 + * GNU General Public License for more details.
24770 + * You should have received a copy of the GNU General Public License
24771 + * along with this program; if not, write to the Free Software
24772 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24776 + * magic sysrq hanlder
24779 +/* #include <linux/sysrq.h> */
24780 +#include <linux/writeback.h>
24783 +/* ---------------------------------------------------------------------- */
24785 +static void sysrq_sb(struct super_block *sb)
24788 + struct au_sbinfo *sbinfo;
24789 + struct file *file;
24791 + plevel = au_plevel;
24792 + au_plevel = KERN_WARNING;
24794 + sbinfo = au_sbi(sb);
24795 + /* since we define pr_fmt, call printk directly */
24796 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
24797 + printk(KERN_WARNING AUFS_NAME ": superblock\n");
24801 + printk(KERN_WARNING AUFS_NAME ": root dentry\n");
24802 + au_dpri_dentry(sb->s_root);
24803 + printk(KERN_WARNING AUFS_NAME ": root inode\n");
24804 + au_dpri_inode(sb->s_root->d_inode);
24809 + int err, i, j, ndentry;
24810 + struct au_dcsub_pages dpages;
24811 + struct au_dpage *dpage;
24813 + err = au_dpages_init(&dpages, GFP_ATOMIC);
24814 + if (unlikely(err))
24816 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
24818 + for (i = 0; i < dpages.ndpage; i++) {
24819 + dpage = dpages.dpages + i;
24820 + ndentry = dpage->ndentry;
24821 + for (j = 0; j < ndentry; j++)
24822 + au_dpri_dentry(dpage->dentries[j]);
24824 + au_dpages_free(&dpages);
24831 + printk(KERN_WARNING AUFS_NAME ": isolated inode\n");
24832 + spin_lock(&inode_sb_list_lock);
24833 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
24834 + spin_lock(&i->i_lock);
24835 + if (1 || list_empty(&i->i_dentry))
24836 + au_dpri_inode(i);
24837 + spin_unlock(&i->i_lock);
24839 + spin_unlock(&inode_sb_list_lock);
24842 + printk(KERN_WARNING AUFS_NAME ": files\n");
24843 + lg_global_lock(files_lglock);
24844 + do_file_list_for_each_entry(sb, file) {
24846 + mode = file->f_dentry->d_inode->i_mode;
24847 + if (!special_file(mode) || au_special_file(mode))
24848 + au_dpri_file(file);
24849 + } while_file_list_for_each_entry;
24850 + lg_global_unlock(files_lglock);
24851 + printk(KERN_WARNING AUFS_NAME ": done\n");
24853 + au_plevel = plevel;
24856 +/* ---------------------------------------------------------------------- */
24858 +/* module parameter */
24859 +static char *aufs_sysrq_key = "a";
24860 +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO);
24861 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
24863 +static void au_sysrq(int key __maybe_unused)
24865 + struct au_sbinfo *sbinfo;
24868 + au_sbilist_lock();
24869 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
24870 + sysrq_sb(sbinfo->si_sb);
24871 + au_sbilist_unlock();
24875 +static struct sysrq_key_op au_sysrq_op = {
24876 + .handler = au_sysrq,
24877 + .help_msg = "Aufs",
24878 + .action_msg = "Aufs",
24879 + .enable_mask = SYSRQ_ENABLE_DUMP
24882 +/* ---------------------------------------------------------------------- */
24884 +int __init au_sysrq_init(void)
24890 + key = *aufs_sysrq_key;
24891 + if ('a' <= key && key <= 'z')
24892 + err = register_sysrq_key(key, &au_sysrq_op);
24893 + if (unlikely(err))
24894 + pr_err("err %d, sysrq=%c\n", err, key);
24898 +void au_sysrq_fin(void)
24901 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
24902 + if (unlikely(err))
24903 + pr_err("err %d (ignored)\n", err);
24905 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
24906 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
24907 +++ linux/fs/aufs/vdir.c 2012-03-19 12:24:13.686467926 +0100
24910 + * Copyright (C) 2005-2012 Junjiro R. Okajima
24912 + * This program, aufs is free software; you can redistribute it and/or modify
24913 + * it under the terms of the GNU General Public License as published by
24914 + * the Free Software Foundation; either version 2 of the License, or
24915 + * (at your option) any later version.
24917 + * This program is distributed in the hope that it will be useful,
24918 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24919 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24920 + * GNU General Public License for more details.
24922 + * You should have received a copy of the GNU General Public License
24923 + * along with this program; if not, write to the Free Software
24924 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24928 + * virtual or vertical directory
24933 +static unsigned int calc_size(int nlen)
24935 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
24938 +static int set_deblk_end(union au_vdir_deblk_p *p,
24939 + union au_vdir_deblk_p *deblk_end)
24941 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
24942 + p->de->de_str.len = 0;
24946 + return -1; /* error */
24949 +/* returns true or false */
24950 +static int is_deblk_end(union au_vdir_deblk_p *p,
24951 + union au_vdir_deblk_p *deblk_end)
24953 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
24954 + return !p->de->de_str.len;
24958 +static unsigned char *last_deblk(struct au_vdir *vdir)
24960 + return vdir->vd_deblk[vdir->vd_nblk - 1];
24963 +/* ---------------------------------------------------------------------- */
24965 +/* estimate the apropriate size for name hash table */
24966 +unsigned int au_rdhash_est(loff_t sz)
24974 + if (sz < AUFS_RDHASH_DEF)
24975 + n = AUFS_RDHASH_DEF;
24976 + /* pr_info("n %u\n", n); */
24981 + * the allocated memory has to be freed by
24982 + * au_nhash_wh_free() or au_nhash_de_free().
24984 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
24986 + struct hlist_head *head;
24989 + head = kmalloc(sizeof(*nhash->nh_head) * num_hash, gfp);
24991 + nhash->nh_num = num_hash;
24992 + nhash->nh_head = head;
24993 + for (u = 0; u < num_hash; u++)
24994 + INIT_HLIST_HEAD(head++);
24995 + return 0; /* success */
25001 +static void nhash_count(struct hlist_head *head)
25005 + struct hlist_node *pos;
25008 + hlist_for_each(pos, head)
25010 + pr_info("%lu\n", n);
25014 +static void au_nhash_wh_do_free(struct hlist_head *head)
25016 + struct au_vdir_wh *tpos;
25017 + struct hlist_node *pos, *node;
25019 + hlist_for_each_entry_safe(tpos, pos, node, head, wh_hash) {
25020 + /* hlist_del(pos); */
25025 +static void au_nhash_de_do_free(struct hlist_head *head)
25027 + struct au_vdir_dehstr *tpos;
25028 + struct hlist_node *pos, *node;
25030 + hlist_for_each_entry_safe(tpos, pos, node, head, hash) {
25031 + /* hlist_del(pos); */
25032 + au_cache_free_vdir_dehstr(tpos);
25036 +static void au_nhash_do_free(struct au_nhash *nhash,
25037 + void (*free)(struct hlist_head *head))
25040 + struct hlist_head *head;
25042 + n = nhash->nh_num;
25046 + head = nhash->nh_head;
25047 + while (n-- > 0) {
25048 + nhash_count(head);
25051 + kfree(nhash->nh_head);
25054 +void au_nhash_wh_free(struct au_nhash *whlist)
25056 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
25059 +static void au_nhash_de_free(struct au_nhash *delist)
25061 + au_nhash_do_free(delist, au_nhash_de_do_free);
25064 +/* ---------------------------------------------------------------------- */
25066 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
25070 + unsigned int u, n;
25071 + struct hlist_head *head;
25072 + struct au_vdir_wh *tpos;
25073 + struct hlist_node *pos;
25076 + n = whlist->nh_num;
25077 + head = whlist->nh_head;
25078 + for (u = 0; u < n; u++, head++)
25079 + hlist_for_each_entry(tpos, pos, head, wh_hash)
25080 + if (tpos->wh_bindex == btgt && ++num > limit)
25085 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
25086 + unsigned char *name,
25087 + unsigned int len)
25090 + /* const unsigned int magic_bit = 12; */
25092 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
25097 + /* v = hash_long(v, magic_bit); */
25098 + v %= nhash->nh_num;
25099 + return nhash->nh_head + v;
25102 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
25105 + return str->len == nlen && !memcmp(str->name, name, nlen);
25108 +/* returns found or not */
25109 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
25111 + struct hlist_head *head;
25112 + struct au_vdir_wh *tpos;
25113 + struct hlist_node *pos;
25114 + struct au_vdir_destr *str;
25116 + head = au_name_hash(whlist, name, nlen);
25117 + hlist_for_each_entry(tpos, pos, head, wh_hash) {
25118 + str = &tpos->wh_str;
25119 + AuDbg("%.*s\n", str->len, str->name);
25120 + if (au_nhash_test_name(str, name, nlen))
25126 +/* returns found(true) or not */
25127 +static int test_known(struct au_nhash *delist, char *name, int nlen)
25129 + struct hlist_head *head;
25130 + struct au_vdir_dehstr *tpos;
25131 + struct hlist_node *pos;
25132 + struct au_vdir_destr *str;
25134 + head = au_name_hash(delist, name, nlen);
25135 + hlist_for_each_entry(tpos, pos, head, hash) {
25137 + AuDbg("%.*s\n", str->len, str->name);
25138 + if (au_nhash_test_name(str, name, nlen))
25144 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
25145 + unsigned char d_type)
25147 +#ifdef CONFIG_AUFS_SHWH
25148 + wh->wh_ino = ino;
25149 + wh->wh_type = d_type;
25153 +/* ---------------------------------------------------------------------- */
25155 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
25156 + unsigned int d_type, aufs_bindex_t bindex,
25157 + unsigned char shwh)
25160 + struct au_vdir_destr *str;
25161 + struct au_vdir_wh *wh;
25163 + AuDbg("%.*s\n", nlen, name);
25164 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
25167 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
25168 + if (unlikely(!wh))
25172 + wh->wh_bindex = bindex;
25174 + au_shwh_init_wh(wh, ino, d_type);
25175 + str = &wh->wh_str;
25177 + memcpy(str->name, name, nlen);
25178 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
25185 +static int append_deblk(struct au_vdir *vdir)
25188 + unsigned long ul;
25189 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
25190 + union au_vdir_deblk_p p, deblk_end;
25191 + unsigned char **o;
25194 + o = krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
25196 + if (unlikely(!o))
25199 + vdir->vd_deblk = o;
25200 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
25202 + ul = vdir->vd_nblk++;
25203 + vdir->vd_deblk[ul] = p.deblk;
25204 + vdir->vd_last.ul = ul;
25205 + vdir->vd_last.p.deblk = p.deblk;
25206 + deblk_end.deblk = p.deblk + deblk_sz;
25207 + err = set_deblk_end(&p, &deblk_end);
25214 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
25215 + unsigned int d_type, struct au_nhash *delist)
25219 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
25220 + union au_vdir_deblk_p p, *room, deblk_end;
25221 + struct au_vdir_dehstr *dehstr;
25223 + p.deblk = last_deblk(vdir);
25224 + deblk_end.deblk = p.deblk + deblk_sz;
25225 + room = &vdir->vd_last.p;
25226 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
25227 + || !is_deblk_end(room, &deblk_end));
25229 + sz = calc_size(nlen);
25230 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
25231 + err = append_deblk(vdir);
25232 + if (unlikely(err))
25235 + p.deblk = last_deblk(vdir);
25236 + deblk_end.deblk = p.deblk + deblk_sz;
25238 + AuDebugOn(room->deblk != p.deblk);
25242 + dehstr = au_cache_alloc_vdir_dehstr();
25243 + if (unlikely(!dehstr))
25246 + dehstr->str = &room->de->de_str;
25247 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
25248 + room->de->de_ino = ino;
25249 + room->de->de_type = d_type;
25250 + room->de->de_str.len = nlen;
25251 + memcpy(room->de->de_str.name, name, nlen);
25254 + room->deblk += sz;
25255 + if (unlikely(set_deblk_end(room, &deblk_end)))
25256 + err = append_deblk(vdir);
25263 +/* ---------------------------------------------------------------------- */
25265 +void au_vdir_free(struct au_vdir *vdir)
25267 + unsigned char **deblk;
25269 + deblk = vdir->vd_deblk;
25270 + while (vdir->vd_nblk--)
25272 + kfree(vdir->vd_deblk);
25273 + au_cache_free_vdir(vdir);
25276 +static struct au_vdir *alloc_vdir(struct file *file)
25278 + struct au_vdir *vdir;
25279 + struct super_block *sb;
25282 + sb = file->f_dentry->d_sb;
25283 + SiMustAnyLock(sb);
25286 + vdir = au_cache_alloc_vdir();
25287 + if (unlikely(!vdir))
25290 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
25291 + if (unlikely(!vdir->vd_deblk))
25294 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
25295 + if (!vdir->vd_deblk_sz) {
25296 + /* estimate the apropriate size for deblk */
25297 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
25298 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
25300 + vdir->vd_nblk = 0;
25301 + vdir->vd_version = 0;
25302 + vdir->vd_jiffy = 0;
25303 + err = append_deblk(vdir);
25305 + return vdir; /* success */
25307 + kfree(vdir->vd_deblk);
25310 + au_cache_free_vdir(vdir);
25312 + vdir = ERR_PTR(err);
25316 +static int reinit_vdir(struct au_vdir *vdir)
25319 + union au_vdir_deblk_p p, deblk_end;
25321 + while (vdir->vd_nblk > 1) {
25322 + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
25323 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
25326 + p.deblk = vdir->vd_deblk[0];
25327 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
25328 + err = set_deblk_end(&p, &deblk_end);
25329 + /* keep vd_dblk_sz */
25330 + vdir->vd_last.ul = 0;
25331 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
25332 + vdir->vd_version = 0;
25333 + vdir->vd_jiffy = 0;
25338 +/* ---------------------------------------------------------------------- */
25340 +#define AuFillVdir_CALLED 1
25341 +#define AuFillVdir_WHABLE (1 << 1)
25342 +#define AuFillVdir_SHWH (1 << 2)
25343 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
25344 +#define au_fset_fillvdir(flags, name) \
25345 + do { (flags) |= AuFillVdir_##name; } while (0)
25346 +#define au_fclr_fillvdir(flags, name) \
25347 + do { (flags) &= ~AuFillVdir_##name; } while (0)
25349 +#ifndef CONFIG_AUFS_SHWH
25350 +#undef AuFillVdir_SHWH
25351 +#define AuFillVdir_SHWH 0
25354 +struct fillvdir_arg {
25355 + struct file *file;
25356 + struct au_vdir *vdir;
25357 + struct au_nhash delist;
25358 + struct au_nhash whlist;
25359 + aufs_bindex_t bindex;
25360 + unsigned int flags;
25364 +static int fillvdir(void *__arg, const char *__name, int nlen,
25365 + loff_t offset __maybe_unused, u64 h_ino,
25366 + unsigned int d_type)
25368 + struct fillvdir_arg *arg = __arg;
25369 + char *name = (void *)__name;
25370 + struct super_block *sb;
25372 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
25375 + sb = arg->file->f_dentry->d_sb;
25376 + au_fset_fillvdir(arg->flags, CALLED);
25378 + if (nlen <= AUFS_WH_PFX_LEN
25379 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
25380 + if (test_known(&arg->delist, name, nlen)
25381 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
25382 + goto out; /* already exists or whiteouted */
25384 + sb = arg->file->f_dentry->d_sb;
25385 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
25387 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
25388 + d_type = DT_UNKNOWN;
25389 + arg->err = append_de(arg->vdir, name, nlen, ino,
25390 + d_type, &arg->delist);
25392 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
25393 + name += AUFS_WH_PFX_LEN;
25394 + nlen -= AUFS_WH_PFX_LEN;
25395 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
25396 + goto out; /* already whiteouted */
25399 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
25402 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
25403 + d_type = DT_UNKNOWN;
25404 + arg->err = au_nhash_append_wh
25405 + (&arg->whlist, name, nlen, ino, d_type,
25406 + arg->bindex, shwh);
25412 + arg->vdir->vd_jiffy = jiffies;
25414 + AuTraceErr(arg->err);
25418 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
25419 + struct au_nhash *whlist, struct au_nhash *delist)
25421 +#ifdef CONFIG_AUFS_SHWH
25423 + unsigned int nh, u;
25424 + struct hlist_head *head;
25425 + struct au_vdir_wh *tpos;
25426 + struct hlist_node *pos, *n;
25428 + struct au_vdir_destr *destr;
25430 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
25433 + o = p = __getname_gfp(GFP_NOFS);
25434 + if (unlikely(!p))
25438 + nh = whlist->nh_num;
25439 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
25440 + p += AUFS_WH_PFX_LEN;
25441 + for (u = 0; u < nh; u++) {
25442 + head = whlist->nh_head + u;
25443 + hlist_for_each_entry_safe(tpos, pos, n, head, wh_hash) {
25444 + destr = &tpos->wh_str;
25445 + memcpy(p, destr->name, destr->len);
25446 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
25447 + tpos->wh_ino, tpos->wh_type, delist);
25448 + if (unlikely(err))
25463 +static int au_do_read_vdir(struct fillvdir_arg *arg)
25466 + unsigned int rdhash;
25468 + aufs_bindex_t bend, bindex, bstart;
25469 + unsigned char shwh;
25470 + struct file *hf, *file;
25471 + struct super_block *sb;
25473 + file = arg->file;
25474 + sb = file->f_dentry->d_sb;
25475 + SiMustAnyLock(sb);
25477 + rdhash = au_sbi(sb)->si_rdhash;
25479 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
25480 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
25481 + if (unlikely(err))
25483 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
25484 + if (unlikely(err))
25490 + if (au_opt_test(au_mntflags(sb), SHWH)) {
25492 + au_fset_fillvdir(arg->flags, SHWH);
25494 + bstart = au_fbstart(file);
25495 + bend = au_fbend_dir(file);
25496 + for (bindex = bstart; !err && bindex <= bend; bindex++) {
25497 + hf = au_hf_dir(file, bindex);
25501 + offset = vfsub_llseek(hf, 0, SEEK_SET);
25503 + if (unlikely(offset))
25506 + arg->bindex = bindex;
25507 + au_fclr_fillvdir(arg->flags, WHABLE);
25509 + || (bindex != bend
25510 + && au_br_whable(au_sbr_perm(sb, bindex))))
25511 + au_fset_fillvdir(arg->flags, WHABLE);
25514 + au_fclr_fillvdir(arg->flags, CALLED);
25516 + err = vfsub_readdir(hf, fillvdir, arg);
25519 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
25522 + if (!err && shwh)
25523 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
25525 + au_nhash_wh_free(&arg->whlist);
25528 + au_nhash_de_free(&arg->delist);
25533 +static int read_vdir(struct file *file, int may_read)
25536 + unsigned long expire;
25537 + unsigned char do_read;
25538 + struct fillvdir_arg arg;
25539 + struct inode *inode;
25540 + struct au_vdir *vdir, *allocated;
25543 + inode = file->f_dentry->d_inode;
25544 + IMustLock(inode);
25545 + SiMustAnyLock(inode->i_sb);
25547 + allocated = NULL;
25549 + expire = au_sbi(inode->i_sb)->si_rdcache;
25550 + vdir = au_ivdir(inode);
25553 + vdir = alloc_vdir(file);
25554 + err = PTR_ERR(vdir);
25555 + if (IS_ERR(vdir))
25558 + allocated = vdir;
25559 + } else if (may_read
25560 + && (inode->i_version != vdir->vd_version
25561 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
25563 + err = reinit_vdir(vdir);
25564 + if (unlikely(err))
25569 + return 0; /* success */
25573 + err = au_do_read_vdir(&arg);
25575 + /* file->f_pos = 0; */
25576 + vdir->vd_version = inode->i_version;
25577 + vdir->vd_last.ul = 0;
25578 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
25580 + au_set_ivdir(inode, allocated);
25581 + } else if (allocated)
25582 + au_vdir_free(allocated);
25588 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
25591 + unsigned long ul, n;
25592 + const unsigned int deblk_sz = src->vd_deblk_sz;
25594 + AuDebugOn(tgt->vd_nblk != 1);
25597 + if (tgt->vd_nblk < src->vd_nblk) {
25598 + unsigned char **p;
25600 + p = krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
25602 + if (unlikely(!p))
25604 + tgt->vd_deblk = p;
25607 + if (tgt->vd_deblk_sz != deblk_sz) {
25608 + unsigned char *p;
25610 + tgt->vd_deblk_sz = deblk_sz;
25611 + p = krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS);
25612 + if (unlikely(!p))
25614 + tgt->vd_deblk[0] = p;
25616 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
25617 + tgt->vd_version = src->vd_version;
25618 + tgt->vd_jiffy = src->vd_jiffy;
25620 + n = src->vd_nblk;
25621 + for (ul = 1; ul < n; ul++) {
25622 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
25624 + if (unlikely(!tgt->vd_deblk[ul]))
25628 + tgt->vd_nblk = n;
25629 + tgt->vd_last.ul = tgt->vd_last.ul;
25630 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
25631 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
25632 + - src->vd_deblk[src->vd_last.ul];
25634 + return 0; /* success */
25637 + rerr = reinit_vdir(tgt);
25642 +int au_vdir_init(struct file *file)
25645 + struct inode *inode;
25646 + struct au_vdir *vdir_cache, *allocated;
25648 + err = read_vdir(file, !file->f_pos);
25649 + if (unlikely(err))
25652 + allocated = NULL;
25653 + vdir_cache = au_fvdir_cache(file);
25654 + if (!vdir_cache) {
25655 + vdir_cache = alloc_vdir(file);
25656 + err = PTR_ERR(vdir_cache);
25657 + if (IS_ERR(vdir_cache))
25659 + allocated = vdir_cache;
25660 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
25661 + err = reinit_vdir(vdir_cache);
25662 + if (unlikely(err))
25665 + return 0; /* success */
25667 + inode = file->f_dentry->d_inode;
25668 + err = copy_vdir(vdir_cache, au_ivdir(inode));
25670 + file->f_version = inode->i_version;
25672 + au_set_fvdir_cache(file, allocated);
25673 + } else if (allocated)
25674 + au_vdir_free(allocated);
25680 +static loff_t calc_offset(struct au_vdir *vdir)
25683 + union au_vdir_deblk_p p;
25685 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
25686 + offset = vdir->vd_last.p.deblk - p.deblk;
25687 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
25691 +/* returns true or false */
25692 +static int seek_vdir(struct file *file)
25695 + unsigned int deblk_sz;
25696 + unsigned long ul, n;
25698 + union au_vdir_deblk_p p, deblk_end;
25699 + struct au_vdir *vdir_cache;
25702 + vdir_cache = au_fvdir_cache(file);
25703 + offset = calc_offset(vdir_cache);
25704 + AuDbg("offset %lld\n", offset);
25705 + if (file->f_pos == offset)
25708 + vdir_cache->vd_last.ul = 0;
25709 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
25710 + if (!file->f_pos)
25714 + deblk_sz = vdir_cache->vd_deblk_sz;
25715 + ul = div64_u64(file->f_pos, deblk_sz);
25716 + AuDbg("ul %lu\n", ul);
25717 + if (ul >= vdir_cache->vd_nblk)
25720 + n = vdir_cache->vd_nblk;
25721 + for (; ul < n; ul++) {
25722 + p.deblk = vdir_cache->vd_deblk[ul];
25723 + deblk_end.deblk = p.deblk + deblk_sz;
25725 + offset *= deblk_sz;
25726 + while (!is_deblk_end(&p, &deblk_end) && offset < file->f_pos) {
25729 + l = calc_size(p.de->de_str.len);
25733 + if (!is_deblk_end(&p, &deblk_end)) {
25735 + vdir_cache->vd_last.ul = ul;
25736 + vdir_cache->vd_last.p = p;
25743 + AuTraceErr(!valid);
25747 +int au_vdir_fill_de(struct file *file, void *dirent, filldir_t filldir)
25750 + unsigned int l, deblk_sz;
25751 + union au_vdir_deblk_p deblk_end;
25752 + struct au_vdir *vdir_cache;
25753 + struct au_vdir_de *de;
25755 + vdir_cache = au_fvdir_cache(file);
25756 + if (!seek_vdir(file))
25759 + deblk_sz = vdir_cache->vd_deblk_sz;
25761 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
25762 + deblk_end.deblk += deblk_sz;
25763 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
25764 + de = vdir_cache->vd_last.p.de;
25765 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
25766 + de->de_str.len, de->de_str.name, file->f_pos,
25767 + (unsigned long)de->de_ino, de->de_type);
25768 + err = filldir(dirent, de->de_str.name, de->de_str.len,
25769 + file->f_pos, de->de_ino, de->de_type);
25770 + if (unlikely(err)) {
25772 + /* todo: ignore the error caused by udba? */
25773 + /* return err; */
25777 + l = calc_size(de->de_str.len);
25778 + vdir_cache->vd_last.p.deblk += l;
25779 + file->f_pos += l;
25781 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
25782 + vdir_cache->vd_last.ul++;
25783 + vdir_cache->vd_last.p.deblk
25784 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
25785 + file->f_pos = deblk_sz * vdir_cache->vd_last.ul;
25794 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
25795 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
25796 +++ linux/fs/aufs/vfsub.c 2012-03-19 12:24:13.686467926 +0100
25799 + * Copyright (C) 2005-2012 Junjiro R. Okajima
25801 + * This program, aufs is free software; you can redistribute it and/or modify
25802 + * it under the terms of the GNU General Public License as published by
25803 + * the Free Software Foundation; either version 2 of the License, or
25804 + * (at your option) any later version.
25806 + * This program is distributed in the hope that it will be useful,
25807 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25808 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25809 + * GNU General Public License for more details.
25811 + * You should have received a copy of the GNU General Public License
25812 + * along with this program; if not, write to the Free Software
25813 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25817 + * sub-routines for VFS
25820 +#include <linux/ima.h>
25821 +#include <linux/namei.h>
25822 +#include <linux/security.h>
25823 +#include <linux/splice.h>
25826 +int vfsub_update_h_iattr(struct path *h_path, int *did)
25830 + struct super_block *h_sb;
25832 + /* for remote fs, leave work for its getattr or d_revalidate */
25833 + /* for bad i_attr fs, handle them in aufs_getattr() */
25834 + /* still some fs may acquire i_mutex. we need to skip them */
25838 + h_sb = h_path->dentry->d_sb;
25839 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
25841 + err = vfs_getattr(h_path->mnt, h_path->dentry, &st);
25846 +/* ---------------------------------------------------------------------- */
25848 +struct file *vfsub_dentry_open(struct path *path, int flags)
25850 + struct file *file;
25853 + file = dentry_open(path->dentry, path->mnt,
25854 + flags /* | __FMODE_NONOTIFY */,
25856 + if (!IS_ERR_OR_NULL(file)
25857 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
25858 + i_readcount_inc(path->dentry->d_inode);
25863 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
25865 + struct file *file;
25868 + file = filp_open(path,
25869 + oflags /* | __FMODE_NONOTIFY */,
25872 + if (IS_ERR(file))
25874 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
25880 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
25884 + err = kern_path(name, flags, path);
25885 + if (!err && path->dentry->d_inode)
25886 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
25890 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
25893 + struct path path = {
25897 + /* VFS checks it too, but by WARN_ON_ONCE() */
25898 + IMustLock(parent->d_inode);
25900 + path.dentry = lookup_one_len(name, parent, len);
25901 + if (IS_ERR(path.dentry))
25903 + if (path.dentry->d_inode)
25904 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
25907 + AuTraceErrPtr(path.dentry);
25908 + return path.dentry;
25911 +struct dentry *vfsub_lookup_hash(struct nameidata *nd)
25913 + struct path path = {
25914 + .mnt = nd->path.mnt
25917 + IMustLock(nd->path.dentry->d_inode);
25919 + path.dentry = lookup_hash(nd);
25920 + if (IS_ERR(path.dentry))
25922 + if (path.dentry->d_inode)
25923 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
25926 + AuTraceErrPtr(path.dentry);
25927 + return path.dentry;
25931 + * this is "VFS:__lookup_one_len()" which was removed and merged into
25932 + * VFS:lookup_one_len() by the commit.
25933 + * 6a96ba5 2011-03-14 kill __lookup_one_len()
25934 + * this function should always be equivalent to the corresponding part in
25935 + * VFS:lookup_one_len().
25937 +int vfsub_name_hash(const char *name, struct qstr *this, int len)
25941 + this->name = name;
25943 + this->hash = full_name_hash(name, len);
25948 + c = *(const unsigned char *)name++;
25949 + if (c == '/' || c == '\0')
25955 +/* ---------------------------------------------------------------------- */
25957 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
25958 + struct dentry *d2, struct au_hinode *hdir2)
25960 + struct dentry *d;
25963 + d = lock_rename(d1, d2);
25965 + au_hn_suspend(hdir1);
25966 + if (hdir1 != hdir2)
25967 + au_hn_suspend(hdir2);
25972 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
25973 + struct dentry *d2, struct au_hinode *hdir2)
25975 + au_hn_resume(hdir1);
25976 + if (hdir1 != hdir2)
25977 + au_hn_resume(hdir2);
25979 + unlock_rename(d1, d2);
25983 +/* ---------------------------------------------------------------------- */
25985 +int vfsub_create(struct inode *dir, struct path *path, int mode)
25988 + struct dentry *d;
25992 + d = path->dentry;
25993 + path->dentry = d->d_parent;
25994 + err = security_path_mknod(path, d, mode, 0);
25995 + path->dentry = d;
25996 + if (unlikely(err))
25999 + if (au_test_fs_null_nd(dir->i_sb))
26000 + err = vfs_create(dir, path->dentry, mode, NULL);
26002 + struct nameidata h_nd;
26004 + memset(&h_nd, 0, sizeof(h_nd));
26005 + h_nd.flags = LOOKUP_CREATE;
26006 + h_nd.intent.open.flags = O_CREAT
26007 + | vfsub_fmode_to_uint(FMODE_READ);
26008 + h_nd.intent.open.create_mode = mode;
26009 + h_nd.path.dentry = path->dentry->d_parent;
26010 + h_nd.path.mnt = path->mnt;
26011 + path_get(&h_nd.path);
26012 + err = vfs_create(dir, path->dentry, mode, &h_nd);
26013 + path_put(&h_nd.path);
26017 + struct path tmp = *path;
26020 + vfsub_update_h_iattr(&tmp, &did);
26022 + tmp.dentry = path->dentry->d_parent;
26023 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
26032 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
26035 + struct dentry *d;
26039 + d = path->dentry;
26040 + path->dentry = d->d_parent;
26041 + err = security_path_symlink(path, d, symname);
26042 + path->dentry = d;
26043 + if (unlikely(err))
26046 + err = vfs_symlink(dir, path->dentry, symname);
26048 + struct path tmp = *path;
26051 + vfsub_update_h_iattr(&tmp, &did);
26053 + tmp.dentry = path->dentry->d_parent;
26054 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
26063 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
26066 + struct dentry *d;
26070 + d = path->dentry;
26071 + path->dentry = d->d_parent;
26072 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
26073 + path->dentry = d;
26074 + if (unlikely(err))
26077 + err = vfs_mknod(dir, path->dentry, mode, dev);
26079 + struct path tmp = *path;
26082 + vfsub_update_h_iattr(&tmp, &did);
26084 + tmp.dentry = path->dentry->d_parent;
26085 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
26094 +static int au_test_nlink(struct inode *inode)
26096 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
26098 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
26099 + || inode->i_nlink < link_max)
26104 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path)
26107 + struct dentry *d;
26111 + err = au_test_nlink(src_dentry->d_inode);
26112 + if (unlikely(err))
26115 + d = path->dentry;
26116 + path->dentry = d->d_parent;
26117 + err = security_path_link(src_dentry, path, d);
26118 + path->dentry = d;
26119 + if (unlikely(err))
26123 + err = vfs_link(src_dentry, dir, path->dentry);
26126 + struct path tmp = *path;
26129 + /* fuse has different memory inode for the same inumber */
26130 + vfsub_update_h_iattr(&tmp, &did);
26132 + tmp.dentry = path->dentry->d_parent;
26133 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
26134 + tmp.dentry = src_dentry;
26135 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
26144 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
26145 + struct inode *dir, struct path *path)
26148 + struct path tmp = {
26151 + struct dentry *d;
26154 + IMustLock(src_dir);
26156 + d = path->dentry;
26157 + path->dentry = d->d_parent;
26158 + tmp.dentry = src_dentry->d_parent;
26159 + err = security_path_rename(&tmp, src_dentry, path, d);
26160 + path->dentry = d;
26161 + if (unlikely(err))
26165 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry);
26170 + tmp.dentry = d->d_parent;
26171 + vfsub_update_h_iattr(&tmp, &did);
26173 + tmp.dentry = src_dentry;
26174 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
26175 + tmp.dentry = src_dentry->d_parent;
26176 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
26185 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
26188 + struct dentry *d;
26192 + d = path->dentry;
26193 + path->dentry = d->d_parent;
26194 + err = security_path_mkdir(path, d, mode);
26195 + path->dentry = d;
26196 + if (unlikely(err))
26199 + err = vfs_mkdir(dir, path->dentry, mode);
26201 + struct path tmp = *path;
26204 + vfsub_update_h_iattr(&tmp, &did);
26206 + tmp.dentry = path->dentry->d_parent;
26207 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
26216 +int vfsub_rmdir(struct inode *dir, struct path *path)
26219 + struct dentry *d;
26223 + d = path->dentry;
26224 + path->dentry = d->d_parent;
26225 + err = security_path_rmdir(path, d);
26226 + path->dentry = d;
26227 + if (unlikely(err))
26231 + err = vfs_rmdir(dir, path->dentry);
26234 + struct path tmp = {
26235 + .dentry = path->dentry->d_parent,
26239 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
26246 +/* ---------------------------------------------------------------------- */
26248 +/* todo: support mmap_sem? */
26249 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
26255 + err = vfs_read(file, ubuf, count, ppos);
26258 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
26262 +/* todo: kernel_read()? */
26263 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
26267 + mm_segment_t oldfs;
26274 + oldfs = get_fs();
26275 + set_fs(KERNEL_DS);
26276 + err = vfsub_read_u(file, buf.u, count, ppos);
26281 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
26287 + err = vfs_write(file, ubuf, count, ppos);
26290 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
26294 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
26297 + mm_segment_t oldfs;
26300 + const char __user *u;
26304 + oldfs = get_fs();
26305 + set_fs(KERNEL_DS);
26306 + err = vfsub_write_u(file, buf.u, count, ppos);
26311 +int vfsub_flush(struct file *file, fl_owner_t id)
26316 + if (file->f_op && file->f_op->flush) {
26317 + if (!au_test_nfs(file->f_dentry->d_sb))
26318 + err = file->f_op->flush(file, id);
26321 + err = file->f_op->flush(file, id);
26325 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
26331 +int vfsub_readdir(struct file *file, filldir_t filldir, void *arg)
26336 + err = vfs_readdir(file, filldir, arg);
26339 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
26343 +long vfsub_splice_to(struct file *in, loff_t *ppos,
26344 + struct pipe_inode_info *pipe, size_t len,
26345 + unsigned int flags)
26350 + err = do_splice_to(in, ppos, pipe, len, flags);
26352 + file_accessed(in);
26354 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
26358 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
26359 + loff_t *ppos, size_t len, unsigned int flags)
26364 + err = do_splice_from(pipe, out, ppos, len, flags);
26367 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
26371 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
26375 + /* file can be NULL */
26377 + err = vfs_fsync(file, datasync);
26381 + AuDebugOn(!file);
26382 + path = &file->f_path;
26384 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
26389 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
26390 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
26391 + struct file *h_file)
26394 + struct inode *h_inode;
26396 + h_inode = h_path->dentry->d_inode;
26398 + err = mnt_want_write(h_path->mnt);
26401 + err = inode_permission(h_inode, MAY_WRITE);
26404 + err = get_write_access(h_inode);
26407 + err = break_lease(h_inode, O_WRONLY);
26412 + err = locks_verify_truncate(h_inode, h_file, length);
26414 + err = security_path_truncate(h_path);
26417 + err = do_truncate(h_path->dentry, length, attr, h_file);
26423 + put_write_access(h_inode);
26426 + mnt_drop_write(h_path->mnt);
26431 +/* ---------------------------------------------------------------------- */
26433 +struct au_vfsub_mkdir_args {
26435 + struct inode *dir;
26436 + struct path *path;
26440 +static void au_call_vfsub_mkdir(void *args)
26442 + struct au_vfsub_mkdir_args *a = args;
26443 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
26446 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
26448 + int err, do_sio, wkq_err;
26450 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
26452 + err = vfsub_mkdir(dir, path, mode);
26454 + struct au_vfsub_mkdir_args args = {
26460 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
26461 + if (unlikely(wkq_err))
26468 +struct au_vfsub_rmdir_args {
26470 + struct inode *dir;
26471 + struct path *path;
26474 +static void au_call_vfsub_rmdir(void *args)
26476 + struct au_vfsub_rmdir_args *a = args;
26477 + *a->errp = vfsub_rmdir(a->dir, a->path);
26480 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
26482 + int err, do_sio, wkq_err;
26484 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
26486 + err = vfsub_rmdir(dir, path);
26488 + struct au_vfsub_rmdir_args args = {
26493 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
26494 + if (unlikely(wkq_err))
26501 +/* ---------------------------------------------------------------------- */
26503 +struct notify_change_args {
26505 + struct path *path;
26506 + struct iattr *ia;
26509 +static void call_notify_change(void *args)
26511 + struct notify_change_args *a = args;
26512 + struct inode *h_inode;
26514 + h_inode = a->path->dentry->d_inode;
26515 + IMustLock(h_inode);
26517 + *a->errp = -EPERM;
26518 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
26519 + *a->errp = notify_change(a->path->dentry, a->ia);
26521 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
26523 + AuTraceErr(*a->errp);
26526 +int vfsub_notify_change(struct path *path, struct iattr *ia)
26529 + struct notify_change_args args = {
26535 + call_notify_change(&args);
26540 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia)
26542 + int err, wkq_err;
26543 + struct notify_change_args args = {
26549 + wkq_err = au_wkq_wait(call_notify_change, &args);
26550 + if (unlikely(wkq_err))
26556 +/* ---------------------------------------------------------------------- */
26558 +struct unlink_args {
26560 + struct inode *dir;
26561 + struct path *path;
26564 +static void call_unlink(void *args)
26566 + struct unlink_args *a = args;
26567 + struct dentry *d = a->path->dentry;
26568 + struct inode *h_inode;
26569 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
26570 + && d->d_count == 1);
26572 + IMustLock(a->dir);
26574 + a->path->dentry = d->d_parent;
26575 + *a->errp = security_path_unlink(a->path, d);
26576 + a->path->dentry = d;
26577 + if (unlikely(*a->errp))
26580 + if (!stop_sillyrename)
26582 + h_inode = d->d_inode;
26587 + *a->errp = vfs_unlink(a->dir, d);
26590 + struct path tmp = {
26591 + .dentry = d->d_parent,
26592 + .mnt = a->path->mnt
26594 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
26597 + if (!stop_sillyrename)
26602 + AuTraceErr(*a->errp);
26606 + * @dir: must be locked.
26607 + * @dentry: target dentry.
26609 +int vfsub_unlink(struct inode *dir, struct path *path, int force)
26612 + struct unlink_args args = {
26619 + call_unlink(&args);
26623 + wkq_err = au_wkq_wait(call_unlink, &args);
26624 + if (unlikely(wkq_err))
26630 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
26631 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
26632 +++ linux/fs/aufs/vfsub.h 2012-03-19 12:24:13.686467926 +0100
26635 + * Copyright (C) 2005-2012 Junjiro R. Okajima
26637 + * This program, aufs is free software; you can redistribute it and/or modify
26638 + * it under the terms of the GNU General Public License as published by
26639 + * the Free Software Foundation; either version 2 of the License, or
26640 + * (at your option) any later version.
26642 + * This program is distributed in the hope that it will be useful,
26643 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26644 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26645 + * GNU General Public License for more details.
26647 + * You should have received a copy of the GNU General Public License
26648 + * along with this program; if not, write to the Free Software
26649 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26653 + * sub-routines for VFS
26656 +#ifndef __AUFS_VFSUB_H__
26657 +#define __AUFS_VFSUB_H__
26661 +#include <linux/fs.h>
26662 +#include <linux/lglock.h>
26663 +#include "debug.h"
26665 +/* copied from linux/fs/internal.h */
26666 +/* todo: BAD approach!! */
26667 +DECLARE_BRLOCK(vfsmount_lock);
26668 +extern void file_sb_list_del(struct file *f);
26669 +extern spinlock_t inode_sb_list_lock;
26671 +/* copied from linux/fs/file_table.c */
26672 +DECLARE_LGLOCK(files_lglock);
26675 + * These macros iterate all files on all CPUs for a given superblock.
26676 + * files_lglock must be held globally.
26678 +#define do_file_list_for_each_entry(__sb, __file) \
26681 + for_each_possible_cpu(i) { \
26682 + struct list_head *list; \
26683 + list = per_cpu_ptr((__sb)->s_files, i); \
26684 + list_for_each_entry((__file), list, f_u.fu_list)
26686 +#define while_file_list_for_each_entry \
26692 +#define do_file_list_for_each_entry(__sb, __file) \
26694 + struct list_head *list; \
26695 + list = &(sb)->s_files; \
26696 + list_for_each_entry((__file), list, f_u.fu_list)
26698 +#define while_file_list_for_each_entry \
26702 +/* ---------------------------------------------------------------------- */
26704 +/* lock subclass for lower inode */
26705 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
26706 +/* reduce? gave up. */
26708 + AuLsc_I_Begin = I_MUTEX_QUOTA, /* 4 */
26709 + AuLsc_I_PARENT, /* lower inode, parent first */
26710 + AuLsc_I_PARENT2, /* copyup dirs */
26711 + AuLsc_I_PARENT3, /* copyup wh */
26717 +/* to debug easier, do not make them inlined functions */
26718 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
26719 +#define IMustLock(i) MtxMustLock(&(i)->i_mutex)
26721 +/* ---------------------------------------------------------------------- */
26723 +static inline void vfsub_drop_nlink(struct inode *inode)
26725 + AuDebugOn(!inode->i_nlink);
26726 + drop_nlink(inode);
26729 +static inline void vfsub_dead_dir(struct inode *inode)
26731 + AuDebugOn(!S_ISDIR(inode->i_mode));
26732 + inode->i_flags |= S_DEAD;
26733 + clear_nlink(inode);
26736 +static inline void vfsub_set_nlink(struct inode *inode, unsigned int nlink)
26739 + set_nlink(inode, nlink);
26741 + clear_nlink(inode);
26744 +/* ---------------------------------------------------------------------- */
26746 +int vfsub_update_h_iattr(struct path *h_path, int *did);
26747 +struct file *vfsub_dentry_open(struct path *path, int flags);
26748 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
26749 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
26750 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
26752 +struct dentry *vfsub_lookup_hash(struct nameidata *nd);
26753 +int vfsub_name_hash(const char *name, struct qstr *this, int len);
26755 +/* ---------------------------------------------------------------------- */
26758 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
26759 + struct dentry *d2, struct au_hinode *hdir2);
26760 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
26761 + struct dentry *d2, struct au_hinode *hdir2);
26763 +int vfsub_create(struct inode *dir, struct path *path, int mode);
26764 +int vfsub_symlink(struct inode *dir, struct path *path,
26765 + const char *symname);
26766 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
26767 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
26768 + struct path *path);
26769 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
26770 + struct inode *hdir, struct path *path);
26771 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
26772 +int vfsub_rmdir(struct inode *dir, struct path *path);
26774 +/* ---------------------------------------------------------------------- */
26776 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
26778 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
26780 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
26782 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
26784 +int vfsub_flush(struct file *file, fl_owner_t id);
26785 +int vfsub_readdir(struct file *file, filldir_t filldir, void *arg);
26787 +static inline unsigned int vfsub_file_flags(struct file *file)
26789 + unsigned int flags;
26791 + spin_lock(&file->f_lock);
26792 + flags = file->f_flags;
26793 + spin_unlock(&file->f_lock);
26798 +static inline void vfsub_file_accessed(struct file *h_file)
26800 + file_accessed(h_file);
26801 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
26804 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
26805 + struct dentry *h_dentry)
26807 + struct path h_path = {
26808 + .dentry = h_dentry,
26811 + touch_atime(h_mnt, h_dentry);
26812 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
26815 +long vfsub_splice_to(struct file *in, loff_t *ppos,
26816 + struct pipe_inode_info *pipe, size_t len,
26817 + unsigned int flags);
26818 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
26819 + loff_t *ppos, size_t len, unsigned int flags);
26820 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
26821 + struct file *h_file);
26822 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
26824 +/* ---------------------------------------------------------------------- */
26826 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
26831 + err = vfs_llseek(file, offset, origin);
26836 +/* ---------------------------------------------------------------------- */
26838 +/* dirty workaround for strict type of fmode_t */
26844 +static inline unsigned int vfsub_fmode_to_uint(fmode_t fm)
26846 + union vfsub_fmu u = {
26850 + BUILD_BUG_ON(sizeof(u.fm) != sizeof(u.ui));
26855 +static inline fmode_t vfsub_uint_to_fmode(unsigned int ui)
26857 + union vfsub_fmu u = {
26864 +/* ---------------------------------------------------------------------- */
26866 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
26867 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
26868 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia);
26869 +int vfsub_notify_change(struct path *path, struct iattr *ia);
26870 +int vfsub_unlink(struct inode *dir, struct path *path, int force);
26872 +#endif /* __KERNEL__ */
26873 +#endif /* __AUFS_VFSUB_H__ */
26874 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
26875 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
26876 +++ linux/fs/aufs/wbr_policy.c 2012-03-19 12:24:13.686467926 +0100
26879 + * Copyright (C) 2005-2012 Junjiro R. Okajima
26881 + * This program, aufs is free software; you can redistribute it and/or modify
26882 + * it under the terms of the GNU General Public License as published by
26883 + * the Free Software Foundation; either version 2 of the License, or
26884 + * (at your option) any later version.
26886 + * This program is distributed in the hope that it will be useful,
26887 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26888 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26889 + * GNU General Public License for more details.
26891 + * You should have received a copy of the GNU General Public License
26892 + * along with this program; if not, write to the Free Software
26893 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26897 + * policies for selecting one among multiple writable branches
26900 +#include <linux/statfs.h>
26903 +/* subset of cpup_attr() */
26904 +static noinline_for_stack
26905 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
26909 + struct inode *h_isrc;
26911 + h_isrc = h_src->d_inode;
26912 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
26913 + ia.ia_mode = h_isrc->i_mode;
26914 + ia.ia_uid = h_isrc->i_uid;
26915 + ia.ia_gid = h_isrc->i_gid;
26916 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
26917 + au_cpup_attr_flags(h_path->dentry->d_inode, h_isrc);
26918 + err = vfsub_sio_notify_change(h_path, &ia);
26920 + /* is this nfs only? */
26921 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
26922 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
26923 + ia.ia_mode = h_isrc->i_mode;
26924 + err = vfsub_sio_notify_change(h_path, &ia);
26930 +#define AuCpdown_PARENT_OPQ 1
26931 +#define AuCpdown_WHED (1 << 1)
26932 +#define AuCpdown_MADE_DIR (1 << 2)
26933 +#define AuCpdown_DIROPQ (1 << 3)
26934 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
26935 +#define au_fset_cpdown(flags, name) \
26936 + do { (flags) |= AuCpdown_##name; } while (0)
26937 +#define au_fclr_cpdown(flags, name) \
26938 + do { (flags) &= ~AuCpdown_##name; } while (0)
26940 +struct au_cpdown_dir_args {
26941 + struct dentry *parent;
26942 + unsigned int flags;
26945 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
26946 + struct au_cpdown_dir_args *a)
26949 + struct dentry *opq_dentry;
26951 + opq_dentry = au_diropq_create(dentry, bdst);
26952 + err = PTR_ERR(opq_dentry);
26953 + if (IS_ERR(opq_dentry))
26955 + dput(opq_dentry);
26956 + au_fset_cpdown(a->flags, DIROPQ);
26962 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
26963 + struct inode *dir, aufs_bindex_t bdst)
26966 + struct path h_path;
26967 + struct au_branch *br;
26969 + br = au_sbr(dentry->d_sb, bdst);
26970 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
26971 + err = PTR_ERR(h_path.dentry);
26972 + if (IS_ERR(h_path.dentry))
26976 + if (h_path.dentry->d_inode) {
26977 + h_path.mnt = br->br_mnt;
26978 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
26981 + dput(h_path.dentry);
26987 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
26988 + struct dentry *h_parent, void *arg)
26991 + aufs_bindex_t bopq, bstart;
26992 + struct path h_path;
26993 + struct dentry *parent;
26994 + struct inode *h_dir, *h_inode, *inode, *dir;
26995 + struct au_cpdown_dir_args *args = arg;
26997 + bstart = au_dbstart(dentry);
26998 + /* dentry is di-locked */
26999 + parent = dget_parent(dentry);
27000 + dir = parent->d_inode;
27001 + h_dir = h_parent->d_inode;
27002 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
27003 + IMustLock(h_dir);
27005 + err = au_lkup_neg(dentry, bdst);
27006 + if (unlikely(err < 0))
27008 + h_path.dentry = au_h_dptr(dentry, bdst);
27009 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
27010 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path,
27011 + S_IRWXU | S_IRUGO | S_IXUGO);
27012 + if (unlikely(err))
27014 + au_fset_cpdown(args->flags, MADE_DIR);
27016 + bopq = au_dbdiropq(dentry);
27017 + au_fclr_cpdown(args->flags, WHED);
27018 + au_fclr_cpdown(args->flags, DIROPQ);
27019 + if (au_dbwh(dentry) == bdst)
27020 + au_fset_cpdown(args->flags, WHED);
27021 + if (!au_ftest_cpdown(args->flags, PARENT_OPQ) && bopq <= bdst)
27022 + au_fset_cpdown(args->flags, PARENT_OPQ);
27023 + h_inode = h_path.dentry->d_inode;
27024 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
27025 + if (au_ftest_cpdown(args->flags, WHED)) {
27026 + err = au_cpdown_dir_opq(dentry, bdst, args);
27027 + if (unlikely(err)) {
27028 + mutex_unlock(&h_inode->i_mutex);
27033 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, bstart));
27034 + mutex_unlock(&h_inode->i_mutex);
27035 + if (unlikely(err))
27038 + if (au_ftest_cpdown(args->flags, WHED)) {
27039 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
27040 + if (unlikely(err))
27044 + inode = dentry->d_inode;
27045 + if (au_ibend(inode) < bdst)
27046 + au_set_ibend(inode, bdst);
27047 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
27048 + au_hi_flags(inode, /*isdir*/1));
27049 + goto out; /* success */
27053 + if (au_ftest_cpdown(args->flags, DIROPQ)) {
27054 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
27055 + rerr = au_diropq_remove(dentry, bdst);
27056 + mutex_unlock(&h_inode->i_mutex);
27057 + if (unlikely(rerr)) {
27058 + AuIOErr("failed removing diropq for %.*s b%d (%d)\n",
27059 + AuDLNPair(dentry), bdst, rerr);
27065 + if (au_ftest_cpdown(args->flags, MADE_DIR)) {
27066 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
27067 + if (unlikely(rerr)) {
27068 + AuIOErr("failed removing %.*s b%d (%d)\n",
27069 + AuDLNPair(dentry), bdst, rerr);
27074 + au_set_h_dptr(dentry, bdst, NULL);
27075 + if (au_dbend(dentry) == bdst)
27076 + au_update_dbend(dentry);
27082 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
27085 + struct au_cpdown_dir_args args = {
27086 + .parent = dget_parent(dentry),
27090 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &args);
27091 + dput(args.parent);
27096 +/* ---------------------------------------------------------------------- */
27098 +/* policies for create */
27100 +static int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
27102 + int err, i, j, ndentry;
27103 + aufs_bindex_t bopq;
27104 + struct au_dcsub_pages dpages;
27105 + struct au_dpage *dpage;
27106 + struct dentry **dentries, *parent, *d;
27108 + err = au_dpages_init(&dpages, GFP_NOFS);
27109 + if (unlikely(err))
27111 + parent = dget_parent(dentry);
27112 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
27113 + if (unlikely(err))
27117 + for (i = 0; i < dpages.ndpage; i++) {
27118 + dpage = dpages.dpages + i;
27119 + dentries = dpage->dentries;
27120 + ndentry = dpage->ndentry;
27121 + for (j = 0; j < ndentry; j++) {
27123 + di_read_lock_parent2(d, !AuLock_IR);
27124 + bopq = au_dbdiropq(d);
27125 + di_read_unlock(d, !AuLock_IR);
27126 + if (bopq >= 0 && bopq < err)
27133 + au_dpages_free(&dpages);
27138 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
27140 + for (; bindex >= 0; bindex--)
27141 + if (!au_br_rdonly(au_sbr(sb, bindex)))
27146 +/* top down parent */
27147 +static int au_wbr_create_tdp(struct dentry *dentry, int isdir __maybe_unused)
27150 + aufs_bindex_t bstart, bindex;
27151 + struct super_block *sb;
27152 + struct dentry *parent, *h_parent;
27154 + sb = dentry->d_sb;
27155 + bstart = au_dbstart(dentry);
27157 + if (!au_br_rdonly(au_sbr(sb, bstart)))
27161 + parent = dget_parent(dentry);
27162 + for (bindex = au_dbstart(parent); bindex < bstart; bindex++) {
27163 + h_parent = au_h_dptr(parent, bindex);
27164 + if (!h_parent || !h_parent->d_inode)
27167 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
27174 + /* bottom up here */
27175 + if (unlikely(err < 0)) {
27176 + err = au_wbr_bu(sb, bstart - 1);
27178 + err = au_wbr_nonopq(dentry, err);
27182 + AuDbg("b%d\n", err);
27186 +/* ---------------------------------------------------------------------- */
27188 +/* an exception for the policy other than tdp */
27189 +static int au_wbr_create_exp(struct dentry *dentry)
27192 + aufs_bindex_t bwh, bdiropq;
27193 + struct dentry *parent;
27196 + bwh = au_dbwh(dentry);
27197 + parent = dget_parent(dentry);
27198 + bdiropq = au_dbdiropq(parent);
27200 + if (bdiropq >= 0)
27201 + err = min(bdiropq, bwh);
27204 + AuDbg("%d\n", err);
27205 + } else if (bdiropq >= 0) {
27207 + AuDbg("%d\n", err);
27212 + err = au_wbr_nonopq(dentry, err);
27214 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
27217 + AuDbg("%d\n", err);
27221 +/* ---------------------------------------------------------------------- */
27224 +static int au_wbr_create_init_rr(struct super_block *sb)
27228 + err = au_wbr_bu(sb, au_sbend(sb));
27229 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
27232 + AuDbg("b%d\n", err);
27236 +static int au_wbr_create_rr(struct dentry *dentry, int isdir)
27240 + aufs_bindex_t bindex, bend;
27241 + struct super_block *sb;
27244 + err = au_wbr_create_exp(dentry);
27248 + sb = dentry->d_sb;
27249 + next = &au_sbi(sb)->si_wbr_rr_next;
27250 + bend = au_sbend(sb);
27252 + for (bindex = 0; bindex <= bend; bindex++) {
27254 + err = atomic_dec_return(next) + 1;
27255 + /* modulo for 0 is meaningless */
27256 + if (unlikely(!err))
27257 + err = atomic_dec_return(next) + 1;
27259 + err = atomic_read(next);
27260 + AuDbg("%d\n", err);
27263 + AuDbg("%d\n", err);
27264 + if (!au_br_rdonly(au_sbr(sb, err)))
27270 + err = au_wbr_nonopq(dentry, err);
27273 + AuDbg("%d\n", err);
27277 +/* ---------------------------------------------------------------------- */
27279 +/* most free space */
27280 +static void au_mfs(struct dentry *dentry)
27282 + struct super_block *sb;
27283 + struct au_branch *br;
27284 + struct au_wbr_mfs *mfs;
27285 + aufs_bindex_t bindex, bend;
27287 + unsigned long long b, bavail;
27288 + struct path h_path;
27289 + /* reduce the stack usage */
27290 + struct kstatfs *st;
27292 + st = kmalloc(sizeof(*st), GFP_NOFS);
27293 + if (unlikely(!st)) {
27294 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
27299 + sb = dentry->d_sb;
27300 + mfs = &au_sbi(sb)->si_wbr_mfs;
27301 + MtxMustLock(&mfs->mfs_lock);
27302 + mfs->mfs_bindex = -EROFS;
27303 + mfs->mfsrr_bytes = 0;
27304 + bend = au_sbend(sb);
27305 + for (bindex = 0; bindex <= bend; bindex++) {
27306 + br = au_sbr(sb, bindex);
27307 + if (au_br_rdonly(br))
27310 + /* sb->s_root for NFS is unreliable */
27311 + h_path.mnt = br->br_mnt;
27312 + h_path.dentry = h_path.mnt->mnt_root;
27313 + err = vfs_statfs(&h_path, st);
27314 + if (unlikely(err)) {
27315 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
27319 + /* when the available size is equal, select the lower one */
27320 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
27321 + || sizeof(b) < sizeof(st->f_bsize));
27322 + b = st->f_bavail * st->f_bsize;
27323 + br->br_wbr->wbr_bytes = b;
27324 + if (b >= bavail) {
27326 + mfs->mfs_bindex = bindex;
27327 + mfs->mfs_jiffy = jiffies;
27331 + mfs->mfsrr_bytes = bavail;
27332 + AuDbg("b%d\n", mfs->mfs_bindex);
27336 +static int au_wbr_create_mfs(struct dentry *dentry, int isdir __maybe_unused)
27339 + struct super_block *sb;
27340 + struct au_wbr_mfs *mfs;
27342 + err = au_wbr_create_exp(dentry);
27346 + sb = dentry->d_sb;
27347 + mfs = &au_sbi(sb)->si_wbr_mfs;
27348 + mutex_lock(&mfs->mfs_lock);
27349 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
27350 + || mfs->mfs_bindex < 0
27351 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
27353 + mutex_unlock(&mfs->mfs_lock);
27354 + err = mfs->mfs_bindex;
27357 + err = au_wbr_nonopq(dentry, err);
27360 + AuDbg("b%d\n", err);
27364 +static int au_wbr_create_init_mfs(struct super_block *sb)
27366 + struct au_wbr_mfs *mfs;
27368 + mfs = &au_sbi(sb)->si_wbr_mfs;
27369 + mutex_init(&mfs->mfs_lock);
27370 + mfs->mfs_jiffy = 0;
27371 + mfs->mfs_bindex = -EROFS;
27376 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
27378 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
27382 +/* ---------------------------------------------------------------------- */
27384 +/* most free space and then round robin */
27385 +static int au_wbr_create_mfsrr(struct dentry *dentry, int isdir)
27388 + struct au_wbr_mfs *mfs;
27390 + err = au_wbr_create_mfs(dentry, isdir);
27392 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
27393 + mutex_lock(&mfs->mfs_lock);
27394 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
27395 + err = au_wbr_create_rr(dentry, isdir);
27396 + mutex_unlock(&mfs->mfs_lock);
27399 + AuDbg("b%d\n", err);
27403 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
27407 + au_wbr_create_init_mfs(sb); /* ignore */
27408 + err = au_wbr_create_init_rr(sb);
27413 +/* ---------------------------------------------------------------------- */
27415 +/* top down parent and most free space */
27416 +static int au_wbr_create_pmfs(struct dentry *dentry, int isdir)
27419 + unsigned long long b;
27420 + aufs_bindex_t bindex, bstart, bend;
27421 + struct super_block *sb;
27422 + struct dentry *parent, *h_parent;
27423 + struct au_branch *br;
27425 + err = au_wbr_create_tdp(dentry, isdir);
27426 + if (unlikely(err < 0))
27428 + parent = dget_parent(dentry);
27429 + bstart = au_dbstart(parent);
27430 + bend = au_dbtaildir(parent);
27431 + if (bstart == bend)
27432 + goto out_parent; /* success */
27434 + e2 = au_wbr_create_mfs(dentry, isdir);
27436 + goto out_parent; /* success */
27438 + /* when the available size is equal, select upper one */
27439 + sb = dentry->d_sb;
27440 + br = au_sbr(sb, err);
27441 + b = br->br_wbr->wbr_bytes;
27442 + AuDbg("b%d, %llu\n", err, b);
27444 + for (bindex = bstart; bindex <= bend; bindex++) {
27445 + h_parent = au_h_dptr(parent, bindex);
27446 + if (!h_parent || !h_parent->d_inode)
27449 + br = au_sbr(sb, bindex);
27450 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
27451 + b = br->br_wbr->wbr_bytes;
27453 + AuDbg("b%d, %llu\n", err, b);
27458 + err = au_wbr_nonopq(dentry, err);
27463 + AuDbg("b%d\n", err);
27467 +/* ---------------------------------------------------------------------- */
27469 +/* policies for copyup */
27471 +/* top down parent */
27472 +static int au_wbr_copyup_tdp(struct dentry *dentry)
27474 + return au_wbr_create_tdp(dentry, /*isdir, anything is ok*/0);
27477 +/* bottom up parent */
27478 +static int au_wbr_copyup_bup(struct dentry *dentry)
27481 + aufs_bindex_t bindex, bstart;
27482 + struct dentry *parent, *h_parent;
27483 + struct super_block *sb;
27486 + sb = dentry->d_sb;
27487 + parent = dget_parent(dentry);
27488 + bstart = au_dbstart(parent);
27489 + for (bindex = au_dbstart(dentry); bindex >= bstart; bindex--) {
27490 + h_parent = au_h_dptr(parent, bindex);
27491 + if (!h_parent || !h_parent->d_inode)
27494 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
27501 + /* bottom up here */
27502 + if (unlikely(err < 0))
27503 + err = au_wbr_bu(sb, bstart - 1);
27505 + AuDbg("b%d\n", err);
27510 +static int au_wbr_copyup_bu(struct dentry *dentry)
27513 + aufs_bindex_t bstart;
27515 + bstart = au_dbstart(dentry);
27516 + err = au_wbr_bu(dentry->d_sb, bstart);
27517 + AuDbg("b%d\n", err);
27518 + if (err > bstart)
27519 + err = au_wbr_nonopq(dentry, err);
27521 + AuDbg("b%d\n", err);
27525 +/* ---------------------------------------------------------------------- */
27527 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
27528 + [AuWbrCopyup_TDP] = {
27529 + .copyup = au_wbr_copyup_tdp
27531 + [AuWbrCopyup_BUP] = {
27532 + .copyup = au_wbr_copyup_bup
27534 + [AuWbrCopyup_BU] = {
27535 + .copyup = au_wbr_copyup_bu
27539 +struct au_wbr_create_operations au_wbr_create_ops[] = {
27540 + [AuWbrCreate_TDP] = {
27541 + .create = au_wbr_create_tdp
27543 + [AuWbrCreate_RR] = {
27544 + .create = au_wbr_create_rr,
27545 + .init = au_wbr_create_init_rr
27547 + [AuWbrCreate_MFS] = {
27548 + .create = au_wbr_create_mfs,
27549 + .init = au_wbr_create_init_mfs,
27550 + .fin = au_wbr_create_fin_mfs
27552 + [AuWbrCreate_MFSV] = {
27553 + .create = au_wbr_create_mfs,
27554 + .init = au_wbr_create_init_mfs,
27555 + .fin = au_wbr_create_fin_mfs
27557 + [AuWbrCreate_MFSRR] = {
27558 + .create = au_wbr_create_mfsrr,
27559 + .init = au_wbr_create_init_mfsrr,
27560 + .fin = au_wbr_create_fin_mfs
27562 + [AuWbrCreate_MFSRRV] = {
27563 + .create = au_wbr_create_mfsrr,
27564 + .init = au_wbr_create_init_mfsrr,
27565 + .fin = au_wbr_create_fin_mfs
27567 + [AuWbrCreate_PMFS] = {
27568 + .create = au_wbr_create_pmfs,
27569 + .init = au_wbr_create_init_mfs,
27570 + .fin = au_wbr_create_fin_mfs
27572 + [AuWbrCreate_PMFSV] = {
27573 + .create = au_wbr_create_pmfs,
27574 + .init = au_wbr_create_init_mfs,
27575 + .fin = au_wbr_create_fin_mfs
27578 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
27579 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
27580 +++ linux/fs/aufs/whout.c 2012-03-19 12:24:13.686467926 +0100
27583 + * Copyright (C) 2005-2012 Junjiro R. Okajima
27585 + * This program, aufs is free software; you can redistribute it and/or modify
27586 + * it under the terms of the GNU General Public License as published by
27587 + * the Free Software Foundation; either version 2 of the License, or
27588 + * (at your option) any later version.
27590 + * This program is distributed in the hope that it will be useful,
27591 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27592 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27593 + * GNU General Public License for more details.
27595 + * You should have received a copy of the GNU General Public License
27596 + * along with this program; if not, write to the Free Software
27597 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27601 + * whiteout for logical deletion and opaque directory
27606 +#define WH_MASK S_IRUGO
27609 + * If a directory contains this file, then it is opaque. We start with the
27610 + * .wh. flag so that it is blocked by lookup.
27612 +static struct qstr diropq_name = {
27613 + .name = AUFS_WH_DIROPQ,
27614 + .len = sizeof(AUFS_WH_DIROPQ) - 1
27618 + * generate whiteout name, which is NOT terminated by NULL.
27619 + * @name: original d_name.name
27620 + * @len: original d_name.len
27621 + * @wh: whiteout qstr
27622 + * returns zero when succeeds, otherwise error.
27623 + * succeeded value as wh->name should be freed by kfree().
27625 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
27629 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
27630 + return -ENAMETOOLONG;
27632 + wh->len = name->len + AUFS_WH_PFX_LEN;
27633 + p = kmalloc(wh->len, GFP_NOFS);
27636 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
27637 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
27644 +/* ---------------------------------------------------------------------- */
27647 + * test if the @wh_name exists under @h_parent.
27648 + * @try_sio specifies the necessary of super-io.
27650 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name,
27651 + struct au_branch *br, int try_sio)
27654 + struct dentry *wh_dentry;
27657 + wh_dentry = au_lkup_one(wh_name, h_parent, br, /*nd*/NULL);
27659 + wh_dentry = au_sio_lkup_one(wh_name, h_parent, br);
27660 + err = PTR_ERR(wh_dentry);
27661 + if (IS_ERR(wh_dentry))
27665 + if (!wh_dentry->d_inode)
27666 + goto out_wh; /* success */
27669 + if (S_ISREG(wh_dentry->d_inode->i_mode))
27670 + goto out_wh; /* success */
27673 + AuIOErr("%.*s Invalid whiteout entry type 0%o.\n",
27674 + AuDLNPair(wh_dentry), wh_dentry->d_inode->i_mode);
27683 + * test if the @h_dentry sets opaque or not.
27685 +int au_diropq_test(struct dentry *h_dentry, struct au_branch *br)
27688 + struct inode *h_dir;
27690 + h_dir = h_dentry->d_inode;
27691 + err = au_wh_test(h_dentry, &diropq_name, br,
27692 + au_test_h_perm_sio(h_dir, MAY_EXEC));
27697 + * returns a negative dentry whose name is unique and temporary.
27699 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
27700 + struct qstr *prefix)
27702 + struct dentry *dentry;
27704 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
27706 + /* strict atomic_t is unnecessary here */
27707 + static unsigned short cnt;
27710 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
27713 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
27714 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
27715 + dentry = ERR_PTR(-ENAMETOOLONG);
27716 + if (unlikely(qs.len > NAME_MAX))
27718 + dentry = ERR_PTR(-ENOMEM);
27719 + name = kmalloc(qs.len + 1, GFP_NOFS);
27720 + if (unlikely(!name))
27724 + /* doubly whiteout-ed */
27725 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
27726 + p = name + AUFS_WH_PFX_LEN * 2;
27727 + memcpy(p, prefix->name, prefix->len);
27728 + p += prefix->len;
27730 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
27733 + for (i = 0; i < 3; i++) {
27734 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
27735 + dentry = au_sio_lkup_one(&qs, h_parent, br);
27736 + if (IS_ERR(dentry) || !dentry->d_inode)
27740 + /* pr_warning("could not get random name\n"); */
27741 + dentry = ERR_PTR(-EEXIST);
27742 + AuDbg("%.*s\n", AuLNPair(&qs));
27746 + if (name != defname)
27749 + AuTraceErrPtr(dentry);
27754 + * rename the @h_dentry on @br to the whiteouted temporary name.
27756 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
27759 + struct path h_path = {
27760 + .mnt = br->br_mnt
27762 + struct inode *h_dir;
27763 + struct dentry *h_parent;
27765 + h_parent = h_dentry->d_parent; /* dir inode is locked */
27766 + h_dir = h_parent->d_inode;
27767 + IMustLock(h_dir);
27769 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
27770 + err = PTR_ERR(h_path.dentry);
27771 + if (IS_ERR(h_path.dentry))
27774 + /* under the same dir, no need to lock_rename() */
27775 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path);
27777 + dput(h_path.dentry);
27784 +/* ---------------------------------------------------------------------- */
27786 + * functions for removing a whiteout
27789 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
27794 + * forces superio when the dir has a sticky bit.
27795 + * this may be a violation of unix fs semantics.
27797 + force = (h_dir->i_mode & S_ISVTX)
27798 + && h_path->dentry->d_inode->i_uid != current_fsuid();
27799 + return vfsub_unlink(h_dir, h_path, force);
27802 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
27803 + struct dentry *dentry)
27807 + err = do_unlink_wh(h_dir, h_path);
27808 + if (!err && dentry)
27809 + au_set_dbwh(dentry, -1);
27814 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
27815 + struct au_branch *br)
27818 + struct path h_path = {
27819 + .mnt = br->br_mnt
27823 + h_path.dentry = au_lkup_one(wh, h_parent, br, /*nd*/NULL);
27824 + if (IS_ERR(h_path.dentry))
27825 + err = PTR_ERR(h_path.dentry);
27827 + if (h_path.dentry->d_inode
27828 + && S_ISREG(h_path.dentry->d_inode->i_mode))
27829 + err = do_unlink_wh(h_parent->d_inode, &h_path);
27830 + dput(h_path.dentry);
27836 +/* ---------------------------------------------------------------------- */
27838 + * initialize/clean whiteout for a branch
27841 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
27846 + if (!whpath->dentry->d_inode)
27849 + err = mnt_want_write(whpath->mnt);
27852 + err = vfsub_rmdir(h_dir, whpath);
27854 + err = vfsub_unlink(h_dir, whpath, /*force*/0);
27855 + mnt_drop_write(whpath->mnt);
27857 + if (unlikely(err))
27858 + pr_warning("failed removing %.*s (%d), ignored.\n",
27859 + AuDLNPair(whpath->dentry), err);
27862 +static int test_linkable(struct dentry *h_root)
27864 + struct inode *h_dir = h_root->d_inode;
27866 + if (h_dir->i_op->link)
27869 + pr_err("%.*s (%s) doesn't support link(2), use noplink and rw+nolwh\n",
27870 + AuDLNPair(h_root), au_sbtype(h_root->d_sb));
27874 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
27875 +static int au_whdir(struct inode *h_dir, struct path *path)
27880 + if (!path->dentry->d_inode) {
27881 + int mode = S_IRWXU;
27883 + if (au_test_nfs(path->dentry->d_sb))
27885 + err = mnt_want_write(path->mnt);
27887 + err = vfsub_mkdir(h_dir, path, mode);
27888 + mnt_drop_write(path->mnt);
27890 + } else if (S_ISDIR(path->dentry->d_inode->i_mode))
27893 + pr_err("unknown %.*s exists\n", AuDLNPair(path->dentry));
27898 +struct au_wh_base {
27899 + const struct qstr *name;
27900 + struct dentry *dentry;
27903 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
27904 + struct path *h_path)
27906 + h_path->dentry = base[AuBrWh_BASE].dentry;
27907 + au_wh_clean(h_dir, h_path, /*isdir*/0);
27908 + h_path->dentry = base[AuBrWh_PLINK].dentry;
27909 + au_wh_clean(h_dir, h_path, /*isdir*/1);
27910 + h_path->dentry = base[AuBrWh_ORPH].dentry;
27911 + au_wh_clean(h_dir, h_path, /*isdir*/1);
27915 + * returns tri-state,
27916 + * minus: error, caller should print the mesage
27918 + * plus: error, caller should NOT print the mesage
27920 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
27921 + int do_plink, struct au_wh_base base[],
27922 + struct path *h_path)
27925 + struct inode *h_dir;
27927 + h_dir = h_root->d_inode;
27928 + h_path->dentry = base[AuBrWh_BASE].dentry;
27929 + au_wh_clean(h_dir, h_path, /*isdir*/0);
27930 + h_path->dentry = base[AuBrWh_PLINK].dentry;
27932 + err = test_linkable(h_root);
27933 + if (unlikely(err)) {
27938 + err = au_whdir(h_dir, h_path);
27939 + if (unlikely(err))
27941 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
27943 + au_wh_clean(h_dir, h_path, /*isdir*/1);
27944 + h_path->dentry = base[AuBrWh_ORPH].dentry;
27945 + err = au_whdir(h_dir, h_path);
27946 + if (unlikely(err))
27948 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
27955 + * for the moment, aufs supports the branch filesystem which does not support
27956 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
27957 + * copyup failed. finally, such filesystem will not be used as the writable
27960 + * returns tri-state, see above.
27962 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
27963 + int do_plink, struct au_wh_base base[],
27964 + struct path *h_path)
27967 + struct inode *h_dir;
27969 + WbrWhMustWriteLock(wbr);
27971 + err = test_linkable(h_root);
27972 + if (unlikely(err)) {
27978 + * todo: should this create be done in /sbin/mount.aufs helper?
27981 + h_dir = h_root->d_inode;
27982 + if (!base[AuBrWh_BASE].dentry->d_inode) {
27983 + err = mnt_want_write(h_path->mnt);
27985 + h_path->dentry = base[AuBrWh_BASE].dentry;
27986 + err = vfsub_create(h_dir, h_path, WH_MASK);
27987 + mnt_drop_write(h_path->mnt);
27989 + } else if (S_ISREG(base[AuBrWh_BASE].dentry->d_inode->i_mode))
27992 + pr_err("unknown %.*s/%.*s exists\n",
27993 + AuDLNPair(h_root), AuDLNPair(base[AuBrWh_BASE].dentry));
27994 + if (unlikely(err))
27997 + h_path->dentry = base[AuBrWh_PLINK].dentry;
27999 + err = au_whdir(h_dir, h_path);
28000 + if (unlikely(err))
28002 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
28004 + au_wh_clean(h_dir, h_path, /*isdir*/1);
28005 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
28007 + h_path->dentry = base[AuBrWh_ORPH].dentry;
28008 + err = au_whdir(h_dir, h_path);
28009 + if (unlikely(err))
28011 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
28018 + * initialize the whiteout base file/dir for @br.
28020 +int au_wh_init(struct dentry *h_root, struct au_branch *br,
28021 + struct super_block *sb)
28024 + const unsigned char do_plink
28025 + = !!au_opt_test(au_mntflags(sb), PLINK);
28026 + struct path path = {
28027 + .mnt = br->br_mnt
28029 + struct inode *h_dir;
28030 + struct au_wbr *wbr = br->br_wbr;
28031 + static const struct qstr base_name[] = {
28032 + [AuBrWh_BASE] = {
28033 + .name = AUFS_BASE_NAME,
28034 + .len = sizeof(AUFS_BASE_NAME) - 1
28036 + [AuBrWh_PLINK] = {
28037 + .name = AUFS_PLINKDIR_NAME,
28038 + .len = sizeof(AUFS_PLINKDIR_NAME) - 1
28040 + [AuBrWh_ORPH] = {
28041 + .name = AUFS_ORPHDIR_NAME,
28042 + .len = sizeof(AUFS_ORPHDIR_NAME) - 1
28045 + struct au_wh_base base[] = {
28046 + [AuBrWh_BASE] = {
28047 + .name = base_name + AuBrWh_BASE,
28050 + [AuBrWh_PLINK] = {
28051 + .name = base_name + AuBrWh_PLINK,
28054 + [AuBrWh_ORPH] = {
28055 + .name = base_name + AuBrWh_ORPH,
28061 + WbrWhMustWriteLock(wbr);
28063 + for (i = 0; i < AuBrWh_Last; i++) {
28064 + /* doubly whiteouted */
28065 + struct dentry *d;
28067 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
28068 + err = PTR_ERR(d);
28072 + base[i].dentry = d;
28074 + && wbr->wbr_wh[i]
28075 + && wbr->wbr_wh[i] != base[i].dentry);
28079 + for (i = 0; i < AuBrWh_Last; i++) {
28080 + dput(wbr->wbr_wh[i]);
28081 + wbr->wbr_wh[i] = NULL;
28085 + if (!au_br_writable(br->br_perm)) {
28086 + h_dir = h_root->d_inode;
28087 + au_wh_init_ro(h_dir, base, &path);
28088 + } else if (!au_br_wh_linkable(br->br_perm)) {
28089 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
28095 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
28101 + goto out; /* success */
28104 + pr_err("an error(%d) on the writable branch %.*s(%s)\n",
28105 + err, AuDLNPair(h_root), au_sbtype(h_root->d_sb));
28107 + for (i = 0; i < AuBrWh_Last; i++)
28108 + dput(base[i].dentry);
28112 +/* ---------------------------------------------------------------------- */
28114 + * whiteouts are all hard-linked usually.
28115 + * when its link count reaches a ceiling, we create a new whiteout base
28116 + * asynchronously.
28119 +struct reinit_br_wh {
28120 + struct super_block *sb;
28121 + struct au_branch *br;
28124 +static void reinit_br_wh(void *arg)
28127 + aufs_bindex_t bindex;
28128 + struct path h_path;
28129 + struct reinit_br_wh *a = arg;
28130 + struct au_wbr *wbr;
28131 + struct inode *dir;
28132 + struct dentry *h_root;
28133 + struct au_hinode *hdir;
28136 + wbr = a->br->br_wbr;
28137 + /* big aufs lock */
28138 + si_noflush_write_lock(a->sb);
28139 + if (!au_br_writable(a->br->br_perm))
28141 + bindex = au_br_index(a->sb, a->br->br_id);
28142 + if (unlikely(bindex < 0))
28145 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
28146 + dir = a->sb->s_root->d_inode;
28147 + hdir = au_hi(dir, bindex);
28148 + h_root = au_h_dptr(a->sb->s_root, bindex);
28150 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
28151 + wbr_wh_write_lock(wbr);
28152 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
28155 + err = mnt_want_write(a->br->br_mnt);
28157 + h_path.dentry = wbr->wbr_whbase;
28158 + h_path.mnt = a->br->br_mnt;
28159 + err = vfsub_unlink(hdir->hi_inode, &h_path, /*force*/0);
28160 + mnt_drop_write(a->br->br_mnt);
28163 + pr_warning("%.*s is moved, ignored\n",
28164 + AuDLNPair(wbr->wbr_whbase));
28167 + dput(wbr->wbr_whbase);
28168 + wbr->wbr_whbase = NULL;
28170 + err = au_wh_init(h_root, a->br, a->sb);
28171 + wbr_wh_write_unlock(wbr);
28172 + au_hn_imtx_unlock(hdir);
28173 + di_read_unlock(a->sb->s_root, AuLock_IR);
28177 + atomic_dec(&wbr->wbr_wh_running);
28178 + atomic_dec(&a->br->br_count);
28179 + si_write_unlock(a->sb);
28180 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
28182 + if (unlikely(err))
28183 + AuIOErr("err %d\n", err);
28186 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
28188 + int do_dec, wkq_err;
28189 + struct reinit_br_wh *arg;
28192 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
28195 + /* ignore ENOMEM */
28196 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
28199 + * dec(wh_running), kfree(arg) and dec(br_count)
28200 + * in reinit function
28204 + atomic_inc(&br->br_count);
28205 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
28206 + if (unlikely(wkq_err)) {
28207 + atomic_dec(&br->br_wbr->wbr_wh_running);
28208 + atomic_dec(&br->br_count);
28216 + atomic_dec(&br->br_wbr->wbr_wh_running);
28219 +/* ---------------------------------------------------------------------- */
28222 + * create the whiteout @wh.
28224 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
28225 + struct dentry *wh)
28228 + struct path h_path = {
28231 + struct au_branch *br;
28232 + struct au_wbr *wbr;
28233 + struct dentry *h_parent;
28234 + struct inode *h_dir;
28236 + h_parent = wh->d_parent; /* dir inode is locked */
28237 + h_dir = h_parent->d_inode;
28238 + IMustLock(h_dir);
28240 + br = au_sbr(sb, bindex);
28241 + h_path.mnt = br->br_mnt;
28242 + wbr = br->br_wbr;
28243 + wbr_wh_read_lock(wbr);
28244 + if (wbr->wbr_whbase) {
28245 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path);
28246 + if (!err || err != -EMLINK)
28249 + /* link count full. re-initialize br_whbase. */
28250 + kick_reinit_br_wh(sb, br);
28253 + /* return this error in this context */
28254 + err = vfsub_create(h_dir, &h_path, WH_MASK);
28257 + wbr_wh_read_unlock(wbr);
28261 +/* ---------------------------------------------------------------------- */
28264 + * create or remove the diropq.
28266 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
28267 + unsigned int flags)
28269 + struct dentry *opq_dentry, *h_dentry;
28270 + struct super_block *sb;
28271 + struct au_branch *br;
28274 + sb = dentry->d_sb;
28275 + br = au_sbr(sb, bindex);
28276 + h_dentry = au_h_dptr(dentry, bindex);
28277 + opq_dentry = au_lkup_one(&diropq_name, h_dentry, br, /*nd*/NULL);
28278 + if (IS_ERR(opq_dentry))
28281 + if (au_ftest_diropq(flags, CREATE)) {
28282 + err = link_or_create_wh(sb, bindex, opq_dentry);
28284 + au_set_dbdiropq(dentry, bindex);
28285 + goto out; /* success */
28288 + struct path tmp = {
28289 + .dentry = opq_dentry,
28290 + .mnt = br->br_mnt
28292 + err = do_unlink_wh(au_h_iptr(dentry->d_inode, bindex), &tmp);
28294 + au_set_dbdiropq(dentry, -1);
28296 + dput(opq_dentry);
28297 + opq_dentry = ERR_PTR(err);
28300 + return opq_dentry;
28303 +struct do_diropq_args {
28304 + struct dentry **errp;
28305 + struct dentry *dentry;
28306 + aufs_bindex_t bindex;
28307 + unsigned int flags;
28310 +static void call_do_diropq(void *args)
28312 + struct do_diropq_args *a = args;
28313 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
28316 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
28317 + unsigned int flags)
28319 + struct dentry *diropq, *h_dentry;
28321 + h_dentry = au_h_dptr(dentry, bindex);
28322 + if (!au_test_h_perm_sio(h_dentry->d_inode, MAY_EXEC | MAY_WRITE))
28323 + diropq = do_diropq(dentry, bindex, flags);
28326 + struct do_diropq_args args = {
28328 + .dentry = dentry,
28329 + .bindex = bindex,
28333 + wkq_err = au_wkq_wait(call_do_diropq, &args);
28334 + if (unlikely(wkq_err))
28335 + diropq = ERR_PTR(wkq_err);
28341 +/* ---------------------------------------------------------------------- */
28344 + * lookup whiteout dentry.
28345 + * @h_parent: lower parent dentry which must exist and be locked
28346 + * @base_name: name of dentry which will be whiteouted
28347 + * returns dentry for whiteout.
28349 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
28350 + struct au_branch *br)
28353 + struct qstr wh_name;
28354 + struct dentry *wh_dentry;
28356 + err = au_wh_name_alloc(&wh_name, base_name);
28357 + wh_dentry = ERR_PTR(err);
28359 + wh_dentry = au_lkup_one(&wh_name, h_parent, br, /*nd*/NULL);
28360 + kfree(wh_name.name);
28362 + return wh_dentry;
28366 + * link/create a whiteout for @dentry on @bindex.
28368 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
28369 + struct dentry *h_parent)
28371 + struct dentry *wh_dentry;
28372 + struct super_block *sb;
28375 + sb = dentry->d_sb;
28376 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
28377 + if (!IS_ERR(wh_dentry) && !wh_dentry->d_inode) {
28378 + err = link_or_create_wh(sb, bindex, wh_dentry);
28380 + au_set_dbwh(dentry, bindex);
28383 + wh_dentry = ERR_PTR(err);
28387 + return wh_dentry;
28390 +/* ---------------------------------------------------------------------- */
28392 +/* Delete all whiteouts in this directory on branch bindex. */
28393 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
28394 + aufs_bindex_t bindex, struct au_branch *br)
28397 + unsigned long ul, n;
28398 + struct qstr wh_name;
28400 + struct hlist_head *head;
28401 + struct au_vdir_wh *tpos;
28402 + struct hlist_node *pos;
28403 + struct au_vdir_destr *str;
28406 + p = __getname_gfp(GFP_NOFS);
28407 + wh_name.name = p;
28408 + if (unlikely(!wh_name.name))
28412 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
28413 + p += AUFS_WH_PFX_LEN;
28414 + n = whlist->nh_num;
28415 + head = whlist->nh_head;
28416 + for (ul = 0; !err && ul < n; ul++, head++) {
28417 + hlist_for_each_entry(tpos, pos, head, wh_hash) {
28418 + if (tpos->wh_bindex != bindex)
28421 + str = &tpos->wh_str;
28422 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
28423 + memcpy(p, str->name, str->len);
28424 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
28425 + err = unlink_wh_name(h_dentry, &wh_name, br);
28430 + AuIOErr("whiteout name too long %.*s\n",
28431 + str->len, str->name);
28436 + __putname(wh_name.name);
28442 +struct del_wh_children_args {
28444 + struct dentry *h_dentry;
28445 + struct au_nhash *whlist;
28446 + aufs_bindex_t bindex;
28447 + struct au_branch *br;
28450 +static void call_del_wh_children(void *args)
28452 + struct del_wh_children_args *a = args;
28453 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
28456 +/* ---------------------------------------------------------------------- */
28458 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
28460 + struct au_whtmp_rmdir *whtmp;
28462 + unsigned int rdhash;
28464 + SiMustAnyLock(sb);
28466 + whtmp = kmalloc(sizeof(*whtmp), gfp);
28467 + if (unlikely(!whtmp)) {
28468 + whtmp = ERR_PTR(-ENOMEM);
28472 + whtmp->dir = NULL;
28473 + whtmp->br = NULL;
28474 + whtmp->wh_dentry = NULL;
28475 + /* no estimation for dir size */
28476 + rdhash = au_sbi(sb)->si_rdhash;
28478 + rdhash = AUFS_RDHASH_DEF;
28479 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
28480 + if (unlikely(err)) {
28482 + whtmp = ERR_PTR(err);
28489 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
28492 + atomic_dec(&whtmp->br->br_count);
28493 + dput(whtmp->wh_dentry);
28494 + iput(whtmp->dir);
28495 + au_nhash_wh_free(&whtmp->whlist);
28500 + * rmdir the whiteouted temporary named dir @h_dentry.
28501 + * @whlist: whiteouted children.
28503 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
28504 + struct dentry *wh_dentry, struct au_nhash *whlist)
28507 + struct path h_tmp;
28508 + struct inode *wh_inode, *h_dir;
28509 + struct au_branch *br;
28511 + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
28512 + IMustLock(h_dir);
28514 + br = au_sbr(dir->i_sb, bindex);
28515 + wh_inode = wh_dentry->d_inode;
28516 + mutex_lock_nested(&wh_inode->i_mutex, AuLsc_I_CHILD);
28519 + * someone else might change some whiteouts while we were sleeping.
28520 + * it means this whlist may have an obsoleted entry.
28522 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
28523 + err = del_wh_children(wh_dentry, whlist, bindex, br);
28526 + struct del_wh_children_args args = {
28528 + .h_dentry = wh_dentry,
28529 + .whlist = whlist,
28530 + .bindex = bindex,
28534 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
28535 + if (unlikely(wkq_err))
28538 + mutex_unlock(&wh_inode->i_mutex);
28541 + h_tmp.dentry = wh_dentry;
28542 + h_tmp.mnt = br->br_mnt;
28543 + err = vfsub_rmdir(h_dir, &h_tmp);
28547 + if (au_ibstart(dir) == bindex) {
28548 + /* todo: dir->i_mutex is necessary */
28549 + au_cpup_attr_timesizes(dir);
28550 + vfsub_drop_nlink(dir);
28552 + return 0; /* success */
28555 + pr_warning("failed removing %.*s(%d), ignored\n",
28556 + AuDLNPair(wh_dentry), err);
28560 +static void call_rmdir_whtmp(void *args)
28563 + aufs_bindex_t bindex;
28564 + struct au_whtmp_rmdir *a = args;
28565 + struct super_block *sb;
28566 + struct dentry *h_parent;
28567 + struct inode *h_dir;
28568 + struct au_hinode *hdir;
28570 + /* rmdir by nfsd may cause deadlock with this i_mutex */
28571 + /* mutex_lock(&a->dir->i_mutex); */
28573 + sb = a->dir->i_sb;
28574 + si_read_lock(sb, !AuLock_FLUSH);
28575 + if (!au_br_writable(a->br->br_perm))
28577 + bindex = au_br_index(sb, a->br->br_id);
28578 + if (unlikely(bindex < 0))
28582 + ii_write_lock_parent(a->dir);
28583 + h_parent = dget_parent(a->wh_dentry);
28584 + h_dir = h_parent->d_inode;
28585 + hdir = au_hi(a->dir, bindex);
28586 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
28587 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
28590 + err = mnt_want_write(a->br->br_mnt);
28592 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry,
28594 + mnt_drop_write(a->br->br_mnt);
28597 + au_hn_imtx_unlock(hdir);
28599 + ii_write_unlock(a->dir);
28602 + /* mutex_unlock(&a->dir->i_mutex); */
28603 + au_whtmp_rmdir_free(a);
28604 + si_read_unlock(sb);
28605 + au_nwt_done(&au_sbi(sb)->si_nowait);
28606 + if (unlikely(err))
28607 + AuIOErr("err %d\n", err);
28610 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
28611 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
28614 + struct super_block *sb;
28618 + /* all post-process will be done in do_rmdir_whtmp(). */
28620 + args->dir = au_igrab(dir);
28621 + args->br = au_sbr(sb, bindex);
28622 + atomic_inc(&args->br->br_count);
28623 + args->wh_dentry = dget(wh_dentry);
28624 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
28625 + if (unlikely(wkq_err)) {
28626 + pr_warning("rmdir error %.*s (%d), ignored\n",
28627 + AuDLNPair(wh_dentry), wkq_err);
28628 + au_whtmp_rmdir_free(args);
28631 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
28632 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
28633 +++ linux/fs/aufs/whout.h 2012-03-19 12:24:13.686467926 +0100
28636 + * Copyright (C) 2005-2012 Junjiro R. Okajima
28638 + * This program, aufs is free software; you can redistribute it and/or modify
28639 + * it under the terms of the GNU General Public License as published by
28640 + * the Free Software Foundation; either version 2 of the License, or
28641 + * (at your option) any later version.
28643 + * This program is distributed in the hope that it will be useful,
28644 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28645 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28646 + * GNU General Public License for more details.
28648 + * You should have received a copy of the GNU General Public License
28649 + * along with this program; if not, write to the Free Software
28650 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28654 + * whiteout for logical deletion and opaque directory
28657 +#ifndef __AUFS_WHOUT_H__
28658 +#define __AUFS_WHOUT_H__
28665 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
28667 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name,
28668 + struct au_branch *br, int try_sio);
28669 +int au_diropq_test(struct dentry *h_dentry, struct au_branch *br);
28670 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
28671 + struct qstr *prefix);
28672 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
28673 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
28674 + struct dentry *dentry);
28675 +int au_wh_init(struct dentry *h_parent, struct au_branch *br,
28676 + struct super_block *sb);
28678 +/* diropq flags */
28679 +#define AuDiropq_CREATE 1
28680 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
28681 +#define au_fset_diropq(flags, name) \
28682 + do { (flags) |= AuDiropq_##name; } while (0)
28683 +#define au_fclr_diropq(flags, name) \
28684 + do { (flags) &= ~AuDiropq_##name; } while (0)
28686 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
28687 + unsigned int flags);
28688 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
28689 + struct au_branch *br);
28690 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
28691 + struct dentry *h_parent);
28693 +/* real rmdir for the whiteout-ed dir */
28694 +struct au_whtmp_rmdir {
28695 + struct inode *dir;
28696 + struct au_branch *br;
28697 + struct dentry *wh_dentry;
28698 + struct au_nhash whlist;
28701 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
28702 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
28703 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
28704 + struct dentry *wh_dentry, struct au_nhash *whlist);
28705 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
28706 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
28708 +/* ---------------------------------------------------------------------- */
28710 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
28711 + aufs_bindex_t bindex)
28713 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
28716 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
28718 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
28721 +#endif /* __KERNEL__ */
28722 +#endif /* __AUFS_WHOUT_H__ */
28723 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
28724 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
28725 +++ linux/fs/aufs/wkq.c 2012-03-19 12:24:13.686467926 +0100
28728 + * Copyright (C) 2005-2012 Junjiro R. Okajima
28730 + * This program, aufs is free software; you can redistribute it and/or modify
28731 + * it under the terms of the GNU General Public License as published by
28732 + * the Free Software Foundation; either version 2 of the License, or
28733 + * (at your option) any later version.
28735 + * This program is distributed in the hope that it will be useful,
28736 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28737 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28738 + * GNU General Public License for more details.
28740 + * You should have received a copy of the GNU General Public License
28741 + * along with this program; if not, write to the Free Software
28742 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28746 + * workqueue for asynchronous/super-io operations
28747 + * todo: try new dredential scheme
28750 +#include <linux/module.h>
28753 +/* internal workqueue named AUFS_WKQ_NAME */
28755 +static struct workqueue_struct *au_wkq;
28757 +struct au_wkinfo {
28758 + struct work_struct wk;
28759 + struct kobject *kobj;
28761 + unsigned int flags; /* see wkq.h */
28763 + au_wkq_func_t func;
28766 + struct completion *comp;
28769 +/* ---------------------------------------------------------------------- */
28771 +static void wkq_func(struct work_struct *wk)
28773 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
28775 + AuDebugOn(current_fsuid());
28776 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
28778 + wkinfo->func(wkinfo->args);
28779 + if (au_ftest_wkq(wkinfo->flags, WAIT))
28780 + complete(wkinfo->comp);
28782 + kobject_put(wkinfo->kobj);
28783 + module_put(THIS_MODULE); /* todo: ?? */
28789 + * Since struct completion is large, try allocating it dynamically.
28791 +#if defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS)
28792 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
28794 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
28796 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
28798 + init_completion(*comp);
28799 + wkinfo->comp = *comp;
28805 +static void au_wkq_comp_free(struct completion *comp)
28813 +#define AuWkqCompDeclare(name) \
28814 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
28815 + struct completion *comp = &_ ## name
28817 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
28819 + wkinfo->comp = *comp;
28823 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
28827 +#endif /* 4KSTACKS */
28829 +static void au_wkq_run(struct au_wkinfo *wkinfo)
28831 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
28832 + if (au_wkq_test()) {
28833 + AuWarn1("wkq from wkq, due to a dead dir by UDBA?\n");
28834 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
28837 + au_dbg_verify_kthread();
28839 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
28840 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
28841 + queue_work(au_wkq, &wkinfo->wk);
28843 + INIT_WORK(&wkinfo->wk, wkq_func);
28844 + schedule_work(&wkinfo->wk);
28849 + * Be careful. It is easy to make deadlock happen.
28850 + * processA: lock, wkq and wait
28851 + * processB: wkq and wait, lock in wkq
28854 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
28857 + AuWkqCompDeclare(comp);
28858 + struct au_wkinfo wkinfo = {
28864 + err = au_wkq_comp_alloc(&wkinfo, &comp);
28866 + au_wkq_run(&wkinfo);
28867 + /* no timeout, no interrupt */
28868 + wait_for_completion(wkinfo.comp);
28869 + au_wkq_comp_free(comp);
28870 + destroy_work_on_stack(&wkinfo.wk);
28878 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
28879 + * problem in a concurrent umounting.
28881 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
28882 + unsigned int flags)
28885 + struct au_wkinfo *wkinfo;
28887 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
28890 + * wkq_func() must free this wkinfo.
28891 + * it highly depends upon the implementation of workqueue.
28894 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
28896 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
28897 + wkinfo->flags = flags & ~AuWkq_WAIT;
28898 + wkinfo->func = func;
28899 + wkinfo->args = args;
28900 + wkinfo->comp = NULL;
28901 + kobject_get(wkinfo->kobj);
28902 + __module_get(THIS_MODULE); /* todo: ?? */
28904 + au_wkq_run(wkinfo);
28907 + au_nwt_done(&au_sbi(sb)->si_nowait);
28913 +/* ---------------------------------------------------------------------- */
28915 +void au_nwt_init(struct au_nowait_tasks *nwt)
28917 + atomic_set(&nwt->nw_len, 0);
28918 + /* smp_mb(); */ /* atomic_set */
28919 + init_waitqueue_head(&nwt->nw_wq);
28922 +void au_wkq_fin(void)
28924 + destroy_workqueue(au_wkq);
28927 +int __init au_wkq_init(void)
28932 + BUILD_BUG_ON(!WQ_RESCUER);
28933 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, !WQ_RESCUER, WQ_DFL_ACTIVE);
28934 + if (IS_ERR(au_wkq))
28935 + err = PTR_ERR(au_wkq);
28936 + else if (!au_wkq)
28941 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
28942 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
28943 +++ linux/fs/aufs/wkq.h 2012-03-19 12:24:13.686467926 +0100
28946 + * Copyright (C) 2005-2012 Junjiro R. Okajima
28948 + * This program, aufs is free software; you can redistribute it and/or modify
28949 + * it under the terms of the GNU General Public License as published by
28950 + * the Free Software Foundation; either version 2 of the License, or
28951 + * (at your option) any later version.
28953 + * This program is distributed in the hope that it will be useful,
28954 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28955 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28956 + * GNU General Public License for more details.
28958 + * You should have received a copy of the GNU General Public License
28959 + * along with this program; if not, write to the Free Software
28960 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28964 + * workqueue for asynchronous/super-io operations
28965 + * todo: try new credentials management scheme
28968 +#ifndef __AUFS_WKQ_H__
28969 +#define __AUFS_WKQ_H__
28973 +struct super_block;
28975 +/* ---------------------------------------------------------------------- */
28978 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
28980 +struct au_nowait_tasks {
28982 + wait_queue_head_t nw_wq;
28985 +/* ---------------------------------------------------------------------- */
28987 +typedef void (*au_wkq_func_t)(void *args);
28990 +#define AuWkq_WAIT 1
28991 +#define AuWkq_NEST (1 << 1)
28992 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
28993 +#define au_fset_wkq(flags, name) \
28994 + do { (flags) |= AuWkq_##name; } while (0)
28995 +#define au_fclr_wkq(flags, name) \
28996 + do { (flags) &= ~AuWkq_##name; } while (0)
28998 +#ifndef CONFIG_AUFS_HNOTIFY
29000 +#define AuWkq_NEST 0
29004 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
29005 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
29006 + unsigned int flags);
29007 +void au_nwt_init(struct au_nowait_tasks *nwt);
29008 +int __init au_wkq_init(void);
29009 +void au_wkq_fin(void);
29011 +/* ---------------------------------------------------------------------- */
29013 +static inline int au_wkq_test(void)
29015 + return current->flags & PF_WQ_WORKER;
29018 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
29020 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
29023 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
29025 + if (atomic_dec_and_test(&nwt->nw_len))
29026 + wake_up_all(&nwt->nw_wq);
29029 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
29031 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
29035 +#endif /* __KERNEL__ */
29036 +#endif /* __AUFS_WKQ_H__ */
29037 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
29038 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
29039 +++ linux/fs/aufs/xino.c 2012-03-19 12:24:13.686467926 +0100
29042 + * Copyright (C) 2005-2012 Junjiro R. Okajima
29044 + * This program, aufs is free software; you can redistribute it and/or modify
29045 + * it under the terms of the GNU General Public License as published by
29046 + * the Free Software Foundation; either version 2 of the License, or
29047 + * (at your option) any later version.
29049 + * This program is distributed in the hope that it will be useful,
29050 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29051 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29052 + * GNU General Public License for more details.
29054 + * You should have received a copy of the GNU General Public License
29055 + * along with this program; if not, write to the Free Software
29056 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29060 + * external inode number translation table and bitmap
29063 +#include <linux/seq_file.h>
29066 +/* todo: unnecessary to support mmap_sem since kernel-space? */
29067 +ssize_t xino_fread(au_readf_t func, struct file *file, void *kbuf, size_t size,
29071 + mm_segment_t oldfs;
29078 + oldfs = get_fs();
29079 + set_fs(KERNEL_DS);
29081 + /* todo: signal_pending? */
29082 + err = func(file, buf.u, size, pos);
29083 + } while (err == -EAGAIN || err == -EINTR);
29086 +#if 0 /* reserved for future use */
29088 + fsnotify_access(file->f_dentry);
29094 +/* ---------------------------------------------------------------------- */
29096 +static ssize_t do_xino_fwrite(au_writef_t func, struct file *file, void *kbuf,
29097 + size_t size, loff_t *pos)
29100 + mm_segment_t oldfs;
29103 + const char __user *u;
29107 + oldfs = get_fs();
29108 + set_fs(KERNEL_DS);
29110 + /* todo: signal_pending? */
29111 + err = func(file, buf.u, size, pos);
29112 + } while (err == -EAGAIN || err == -EINTR);
29115 +#if 0 /* reserved for future use */
29117 + fsnotify_modify(file->f_dentry);
29123 +struct do_xino_fwrite_args {
29125 + au_writef_t func;
29126 + struct file *file;
29132 +static void call_do_xino_fwrite(void *args)
29134 + struct do_xino_fwrite_args *a = args;
29135 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
29138 +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size,
29143 + /* todo: signal block and no wkq? */
29144 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
29146 + err = do_xino_fwrite(func, file, buf, size, pos);
29150 + * it breaks RLIMIT_FSIZE and normal user's limit,
29151 + * users should care about quota and real 'filesystem full.'
29154 + struct do_xino_fwrite_args args = {
29163 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
29164 + if (unlikely(wkq_err))
29171 +/* ---------------------------------------------------------------------- */
29174 + * create a new xinofile at the same place/path as @base_file.
29176 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src)
29178 + struct file *file;
29179 + struct dentry *base, *parent;
29180 + struct inode *dir;
29181 + struct qstr *name;
29182 + struct path path;
29185 + base = base_file->f_dentry;
29186 + parent = base->d_parent; /* dir inode is locked */
29187 + dir = parent->d_inode;
29190 + file = ERR_PTR(-EINVAL);
29191 + name = &base->d_name;
29192 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
29193 + if (IS_ERR(path.dentry)) {
29194 + file = (void *)path.dentry;
29195 + pr_err("%.*s lookup err %ld\n",
29196 + AuLNPair(name), PTR_ERR(path.dentry));
29200 + /* no need to mnt_want_write() since we call dentry_open() later */
29201 + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL);
29202 + if (unlikely(err)) {
29203 + file = ERR_PTR(err);
29204 + pr_err("%.*s create err %d\n", AuLNPair(name), err);
29208 + path.mnt = base_file->f_vfsmnt;
29209 + file = vfsub_dentry_open(&path,
29210 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
29211 + /* | __FMODE_NONOTIFY */);
29212 + if (IS_ERR(file)) {
29213 + pr_err("%.*s open err %ld\n", AuLNPair(name), PTR_ERR(file));
29217 + err = vfsub_unlink(dir, &file->f_path, /*force*/0);
29218 + if (unlikely(err)) {
29219 + pr_err("%.*s unlink err %d\n", AuLNPair(name), err);
29224 + /* no one can touch copy_src xino */
29225 + err = au_copy_file(file, copy_src,
29226 + i_size_read(copy_src->f_dentry->d_inode));
29227 + if (unlikely(err)) {
29228 + pr_err("%.*s copy err %d\n", AuLNPair(name), err);
29232 + goto out_dput; /* success */
29236 + file = ERR_PTR(err);
29238 + dput(path.dentry);
29243 +struct au_xino_lock_dir {
29244 + struct au_hinode *hdir;
29245 + struct dentry *parent;
29246 + struct mutex *mtx;
29249 +static void au_xino_lock_dir(struct super_block *sb, struct file *xino,
29250 + struct au_xino_lock_dir *ldir)
29252 + aufs_bindex_t brid, bindex;
29254 + ldir->hdir = NULL;
29256 + brid = au_xino_brid(sb);
29258 + bindex = au_br_index(sb, brid);
29259 + if (bindex >= 0) {
29260 + ldir->hdir = au_hi(sb->s_root->d_inode, bindex);
29261 + au_hn_imtx_lock_nested(ldir->hdir, AuLsc_I_PARENT);
29263 + ldir->parent = dget_parent(xino->f_dentry);
29264 + ldir->mtx = &ldir->parent->d_inode->i_mutex;
29265 + mutex_lock_nested(ldir->mtx, AuLsc_I_PARENT);
29269 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
29272 + au_hn_imtx_unlock(ldir->hdir);
29274 + mutex_unlock(ldir->mtx);
29275 + dput(ldir->parent);
29279 +/* ---------------------------------------------------------------------- */
29281 +/* trucate xino files asynchronously */
29283 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
29286 + aufs_bindex_t bi, bend;
29287 + struct au_branch *br;
29288 + struct file *new_xino, *file;
29289 + struct super_block *h_sb;
29290 + struct au_xino_lock_dir ldir;
29293 + bend = au_sbend(sb);
29294 + if (unlikely(bindex < 0 || bend < bindex))
29296 + br = au_sbr(sb, bindex);
29297 + file = br->br_xino.xi_file;
29301 + au_xino_lock_dir(sb, file, &ldir);
29302 + /* mnt_want_write() is unnecessary here */
29303 + new_xino = au_xino_create2(file, file);
29304 + au_xino_unlock_dir(&ldir);
29305 + err = PTR_ERR(new_xino);
29306 + if (IS_ERR(new_xino))
29310 + br->br_xino.xi_file = new_xino;
29312 + h_sb = br->br_mnt->mnt_sb;
29313 + for (bi = 0; bi <= bend; bi++) {
29314 + if (unlikely(bi == bindex))
29316 + br = au_sbr(sb, bi);
29317 + if (br->br_mnt->mnt_sb != h_sb)
29320 + fput(br->br_xino.xi_file);
29321 + br->br_xino.xi_file = new_xino;
29322 + get_file(new_xino);
29329 +struct xino_do_trunc_args {
29330 + struct super_block *sb;
29331 + struct au_branch *br;
29334 +static void xino_do_trunc(void *_args)
29336 + struct xino_do_trunc_args *args = _args;
29337 + struct super_block *sb;
29338 + struct au_branch *br;
29339 + struct inode *dir;
29341 + aufs_bindex_t bindex;
29345 + dir = sb->s_root->d_inode;
29348 + si_noflush_write_lock(sb);
29349 + ii_read_lock_parent(dir);
29350 + bindex = au_br_index(sb, br->br_id);
29351 + err = au_xino_trunc(sb, bindex);
29353 + && br->br_xino.xi_file->f_dentry->d_inode->i_blocks
29354 + >= br->br_xino_upper)
29355 + br->br_xino_upper += AUFS_XINO_TRUNC_STEP;
29357 + ii_read_unlock(dir);
29358 + if (unlikely(err))
29359 + pr_warning("err b%d, (%d)\n", bindex, err);
29360 + atomic_dec(&br->br_xino_running);
29361 + atomic_dec(&br->br_count);
29362 + si_write_unlock(sb);
29363 + au_nwt_done(&au_sbi(sb)->si_nowait);
29367 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
29369 + struct xino_do_trunc_args *args;
29372 + if (br->br_xino.xi_file->f_dentry->d_inode->i_blocks
29373 + < br->br_xino_upper)
29376 + if (atomic_inc_return(&br->br_xino_running) > 1)
29379 + /* lock and kfree() will be called in trunc_xino() */
29380 + args = kmalloc(sizeof(*args), GFP_NOFS);
29381 + if (unlikely(!args)) {
29382 + AuErr1("no memory\n");
29386 + atomic_inc(&br->br_count);
29389 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
29391 + return; /* success */
29393 + pr_err("wkq %d\n", wkq_err);
29394 + atomic_dec(&br->br_count);
29399 + atomic_dec(&br->br_xino_running);
29402 +/* ---------------------------------------------------------------------- */
29404 +static int au_xino_do_write(au_writef_t write, struct file *file,
29405 + ino_t h_ino, ino_t ino)
29411 + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) {
29412 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
29415 + pos *= sizeof(ino);
29416 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos);
29417 + if (sz == sizeof(ino))
29418 + return 0; /* success */
29420 + AuIOErr("write failed (%zd)\n", sz);
29425 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
29426 + * at the position of @h_ino.
29427 + * even if @ino is zero, it is written to the xinofile and means no entry.
29428 + * if the size of the xino file on a specific filesystem exceeds the watermark,
29429 + * try truncating it.
29431 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
29435 + unsigned int mnt_flags;
29436 + struct au_branch *br;
29438 + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max)
29439 + || ((loff_t)-1) > 0);
29440 + SiMustAnyLock(sb);
29442 + mnt_flags = au_mntflags(sb);
29443 + if (!au_opt_test(mnt_flags, XINO))
29446 + br = au_sbr(sb, bindex);
29447 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
29450 + if (au_opt_test(mnt_flags, TRUNC_XINO)
29451 + && au_test_fs_trunc_xino(br->br_mnt->mnt_sb))
29452 + xino_try_trunc(sb, br);
29453 + return 0; /* success */
29456 + AuIOErr("write failed (%d)\n", err);
29460 +/* ---------------------------------------------------------------------- */
29462 +/* aufs inode number bitmap */
29464 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
29465 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
29469 + AuDebugOn(bit < 0 || page_bits <= bit);
29470 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
29474 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
29476 + AuDebugOn(ino < AUFS_FIRST_INO);
29477 + ino -= AUFS_FIRST_INO;
29478 + *pindex = ino / page_bits;
29479 + *bit = ino % page_bits;
29482 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
29487 + struct au_sbinfo *sbinfo;
29488 + struct file *xib;
29489 + unsigned long *p;
29491 + sbinfo = au_sbi(sb);
29492 + MtxMustLock(&sbinfo->si_xib_mtx);
29493 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
29494 + || !au_opt_test(sbinfo->si_mntflags, XINO));
29496 + if (pindex == sbinfo->si_xib_last_pindex)
29499 + xib = sbinfo->si_xib;
29500 + p = sbinfo->si_xib_buf;
29501 + pos = sbinfo->si_xib_last_pindex;
29502 + pos *= PAGE_SIZE;
29503 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
29504 + if (unlikely(sz != PAGE_SIZE))
29508 + pos *= PAGE_SIZE;
29509 + if (i_size_read(xib->f_dentry->d_inode) >= pos + PAGE_SIZE)
29510 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
29512 + memset(p, 0, PAGE_SIZE);
29513 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
29515 + if (sz == PAGE_SIZE) {
29516 + sbinfo->si_xib_last_pindex = pindex;
29517 + return 0; /* success */
29521 + AuIOErr1("write failed (%zd)\n", sz);
29528 +/* ---------------------------------------------------------------------- */
29530 +static void au_xib_clear_bit(struct inode *inode)
29533 + unsigned long pindex;
29534 + struct super_block *sb;
29535 + struct au_sbinfo *sbinfo;
29537 + AuDebugOn(inode->i_nlink);
29539 + sb = inode->i_sb;
29540 + xib_calc_bit(inode->i_ino, &pindex, &bit);
29541 + AuDebugOn(page_bits <= bit);
29542 + sbinfo = au_sbi(sb);
29543 + mutex_lock(&sbinfo->si_xib_mtx);
29544 + err = xib_pindex(sb, pindex);
29546 + clear_bit(bit, sbinfo->si_xib_buf);
29547 + sbinfo->si_xib_next_bit = bit;
29549 + mutex_unlock(&sbinfo->si_xib_mtx);
29552 +/* for s_op->delete_inode() */
29553 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
29556 + unsigned int mnt_flags;
29557 + aufs_bindex_t bindex, bend, bi;
29558 + unsigned char try_trunc;
29559 + struct au_iinfo *iinfo;
29560 + struct super_block *sb;
29561 + struct au_hinode *hi;
29562 + struct inode *h_inode;
29563 + struct au_branch *br;
29564 + au_writef_t xwrite;
29566 + sb = inode->i_sb;
29567 + mnt_flags = au_mntflags(sb);
29568 + if (!au_opt_test(mnt_flags, XINO)
29569 + || inode->i_ino == AUFS_ROOT_INO)
29573 + au_xigen_inc(inode);
29574 + au_xib_clear_bit(inode);
29577 + iinfo = au_ii(inode);
29581 + bindex = iinfo->ii_bstart;
29585 + xwrite = au_sbi(sb)->si_xwrite;
29586 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
29587 + hi = iinfo->ii_hinode + bindex;
29588 + bend = iinfo->ii_bend;
29589 + for (; bindex <= bend; bindex++, hi++) {
29590 + h_inode = hi->hi_inode;
29592 + || (!unlinked && h_inode->i_nlink))
29595 + /* inode may not be revalidated */
29596 + bi = au_br_index(sb, hi->hi_id);
29600 + br = au_sbr(sb, bi);
29601 + err = au_xino_do_write(xwrite, br->br_xino.xi_file,
29602 + h_inode->i_ino, /*ino*/0);
29603 + if (!err && try_trunc
29604 + && au_test_fs_trunc_xino(br->br_mnt->mnt_sb))
29605 + xino_try_trunc(sb, br);
29609 +/* get an unused inode number from bitmap */
29610 +ino_t au_xino_new_ino(struct super_block *sb)
29613 + unsigned long *p, pindex, ul, pend;
29614 + struct au_sbinfo *sbinfo;
29615 + struct file *file;
29616 + int free_bit, err;
29618 + if (!au_opt_test(au_mntflags(sb), XINO))
29619 + return iunique(sb, AUFS_FIRST_INO);
29621 + sbinfo = au_sbi(sb);
29622 + mutex_lock(&sbinfo->si_xib_mtx);
29623 + p = sbinfo->si_xib_buf;
29624 + free_bit = sbinfo->si_xib_next_bit;
29625 + if (free_bit < page_bits && !test_bit(free_bit, p))
29626 + goto out; /* success */
29627 + free_bit = find_first_zero_bit(p, page_bits);
29628 + if (free_bit < page_bits)
29629 + goto out; /* success */
29631 + pindex = sbinfo->si_xib_last_pindex;
29632 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
29633 + err = xib_pindex(sb, ul);
29634 + if (unlikely(err))
29636 + free_bit = find_first_zero_bit(p, page_bits);
29637 + if (free_bit < page_bits)
29638 + goto out; /* success */
29641 + file = sbinfo->si_xib;
29642 + pend = i_size_read(file->f_dentry->d_inode) / PAGE_SIZE;
29643 + for (ul = pindex + 1; ul <= pend; ul++) {
29644 + err = xib_pindex(sb, ul);
29645 + if (unlikely(err))
29647 + free_bit = find_first_zero_bit(p, page_bits);
29648 + if (free_bit < page_bits)
29649 + goto out; /* success */
29654 + set_bit(free_bit, p);
29655 + sbinfo->si_xib_next_bit = free_bit + 1;
29656 + pindex = sbinfo->si_xib_last_pindex;
29657 + mutex_unlock(&sbinfo->si_xib_mtx);
29658 + ino = xib_calc_ino(pindex, free_bit);
29659 + AuDbg("i%lu\n", (unsigned long)ino);
29662 + mutex_unlock(&sbinfo->si_xib_mtx);
29668 + * read @ino from xinofile for the specified branch{@sb, @bindex}
29669 + * at the position of @h_ino.
29670 + * if @ino does not exist and @do_new is true, get new one.
29672 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
29678 + struct file *file;
29679 + struct au_sbinfo *sbinfo;
29682 + if (!au_opt_test(au_mntflags(sb), XINO))
29683 + return 0; /* no xino */
29686 + sbinfo = au_sbi(sb);
29688 + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) {
29689 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
29692 + pos *= sizeof(*ino);
29694 + file = au_sbr(sb, bindex)->br_xino.xi_file;
29695 + if (i_size_read(file->f_dentry->d_inode) < pos + sizeof(*ino))
29696 + return 0; /* no ino */
29698 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
29699 + if (sz == sizeof(*ino))
29700 + return 0; /* success */
29703 + if (unlikely(sz >= 0)) {
29705 + AuIOErr("xino read error (%zd)\n", sz);
29711 +/* ---------------------------------------------------------------------- */
29713 +/* create and set a new xino file */
29715 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent)
29717 + struct file *file;
29718 + struct dentry *h_parent, *d;
29719 + struct inode *h_dir;
29723 + * at mount-time, and the xino file is the default path,
29724 + * hnotify is disabled so we have no notify events to ignore.
29725 + * when a user specified the xino, we cannot get au_hdir to be ignored.
29727 + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
29728 + /* | __FMODE_NONOTIFY */,
29729 + S_IRUGO | S_IWUGO);
29730 + if (IS_ERR(file)) {
29732 + pr_err("open %s(%ld)\n", fname, PTR_ERR(file));
29736 + /* keep file count */
29737 + h_parent = dget_parent(file->f_dentry);
29738 + h_dir = h_parent->d_inode;
29739 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
29740 + /* mnt_want_write() is unnecessary here */
29741 + err = vfsub_unlink(h_dir, &file->f_path, /*force*/0);
29742 + mutex_unlock(&h_dir->i_mutex);
29744 + if (unlikely(err)) {
29746 + pr_err("unlink %s(%d)\n", fname, err);
29751 + d = file->f_dentry;
29752 + if (unlikely(sb == d->d_sb)) {
29754 + pr_err("%s must be outside\n", fname);
29757 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
29759 + pr_err("xino doesn't support %s(%s)\n",
29760 + fname, au_sbtype(d->d_sb));
29763 + return file; /* success */
29767 + file = ERR_PTR(err);
29772 + * find another branch who is on the same filesystem of the specified
29773 + * branch{@btgt}. search until @bend.
29775 +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
29776 + aufs_bindex_t bend)
29778 + aufs_bindex_t bindex;
29779 + struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
29781 + for (bindex = 0; bindex < btgt; bindex++)
29782 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
29784 + for (bindex++; bindex <= bend; bindex++)
29785 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
29790 +/* ---------------------------------------------------------------------- */
29793 + * initialize the xinofile for the specified branch @br
29794 + * at the place/path where @base_file indicates.
29795 + * test whether another branch is on the same filesystem or not,
29796 + * if @do_test is true.
29798 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
29799 + struct file *base_file, int do_test)
29803 + aufs_bindex_t bend, bindex;
29804 + struct au_branch *shared_br, *b;
29805 + struct file *file;
29806 + struct super_block *tgt_sb;
29808 + shared_br = NULL;
29809 + bend = au_sbend(sb);
29811 + tgt_sb = br->br_mnt->mnt_sb;
29812 + for (bindex = 0; bindex <= bend; bindex++) {
29813 + b = au_sbr(sb, bindex);
29814 + if (tgt_sb == b->br_mnt->mnt_sb) {
29821 + if (!shared_br || !shared_br->br_xino.xi_file) {
29822 + struct au_xino_lock_dir ldir;
29824 + au_xino_lock_dir(sb, base_file, &ldir);
29825 + /* mnt_want_write() is unnecessary here */
29826 + file = au_xino_create2(base_file, NULL);
29827 + au_xino_unlock_dir(&ldir);
29828 + err = PTR_ERR(file);
29829 + if (IS_ERR(file))
29831 + br->br_xino.xi_file = file;
29833 + br->br_xino.xi_file = shared_br->br_xino.xi_file;
29834 + get_file(br->br_xino.xi_file);
29837 + ino = AUFS_ROOT_INO;
29838 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
29840 + if (unlikely(err)) {
29841 + fput(br->br_xino.xi_file);
29842 + br->br_xino.xi_file = NULL;
29849 +/* ---------------------------------------------------------------------- */
29851 +/* trucate a xino bitmap file */
29854 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
29858 + unsigned long pindex;
29859 + loff_t pos, pend;
29860 + struct au_sbinfo *sbinfo;
29863 + unsigned long *p;
29866 + sbinfo = au_sbi(sb);
29867 + MtxMustLock(&sbinfo->si_xib_mtx);
29868 + p = sbinfo->si_xib_buf;
29869 + func = sbinfo->si_xread;
29870 + pend = i_size_read(file->f_dentry->d_inode);
29872 + while (pos < pend) {
29873 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
29875 + if (unlikely(sz <= 0))
29879 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
29880 + if (unlikely(*ino < AUFS_FIRST_INO))
29883 + xib_calc_bit(*ino, &pindex, &bit);
29884 + AuDebugOn(page_bits <= bit);
29885 + err = xib_pindex(sb, pindex);
29897 +static int xib_restore(struct super_block *sb)
29900 + aufs_bindex_t bindex, bend;
29904 + page = (void *)__get_free_page(GFP_NOFS);
29905 + if (unlikely(!page))
29909 + bend = au_sbend(sb);
29910 + for (bindex = 0; !err && bindex <= bend; bindex++)
29911 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
29912 + err = do_xib_restore
29913 + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page);
29915 + AuDbg("b%d\n", bindex);
29916 + free_page((unsigned long)page);
29922 +int au_xib_trunc(struct super_block *sb)
29927 + struct au_xino_lock_dir ldir;
29928 + struct au_sbinfo *sbinfo;
29929 + unsigned long *p;
29930 + struct file *file;
29932 + SiMustWriteLock(sb);
29935 + sbinfo = au_sbi(sb);
29936 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
29939 + file = sbinfo->si_xib;
29940 + if (i_size_read(file->f_dentry->d_inode) <= PAGE_SIZE)
29943 + au_xino_lock_dir(sb, file, &ldir);
29944 + /* mnt_want_write() is unnecessary here */
29945 + file = au_xino_create2(sbinfo->si_xib, NULL);
29946 + au_xino_unlock_dir(&ldir);
29947 + err = PTR_ERR(file);
29948 + if (IS_ERR(file))
29950 + fput(sbinfo->si_xib);
29951 + sbinfo->si_xib = file;
29953 + p = sbinfo->si_xib_buf;
29954 + memset(p, 0, PAGE_SIZE);
29956 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
29957 + if (unlikely(sz != PAGE_SIZE)) {
29959 + AuIOErr("err %d\n", err);
29965 + mutex_lock(&sbinfo->si_xib_mtx);
29966 + /* mnt_want_write() is unnecessary here */
29967 + err = xib_restore(sb);
29968 + mutex_unlock(&sbinfo->si_xib_mtx);
29974 +/* ---------------------------------------------------------------------- */
29977 + * xino mount option handlers
29979 +static au_readf_t find_readf(struct file *h_file)
29981 + const struct file_operations *fop = h_file->f_op;
29985 + return fop->read;
29986 + if (fop->aio_read)
29987 + return do_sync_read;
29989 + return ERR_PTR(-ENOSYS);
29992 +static au_writef_t find_writef(struct file *h_file)
29994 + const struct file_operations *fop = h_file->f_op;
29998 + return fop->write;
29999 + if (fop->aio_write)
30000 + return do_sync_write;
30002 + return ERR_PTR(-ENOSYS);
30006 +static void xino_clear_xib(struct super_block *sb)
30008 + struct au_sbinfo *sbinfo;
30010 + SiMustWriteLock(sb);
30012 + sbinfo = au_sbi(sb);
30013 + sbinfo->si_xread = NULL;
30014 + sbinfo->si_xwrite = NULL;
30015 + if (sbinfo->si_xib)
30016 + fput(sbinfo->si_xib);
30017 + sbinfo->si_xib = NULL;
30018 + free_page((unsigned long)sbinfo->si_xib_buf);
30019 + sbinfo->si_xib_buf = NULL;
30022 +static int au_xino_set_xib(struct super_block *sb, struct file *base)
30026 + struct au_sbinfo *sbinfo;
30027 + struct file *file;
30029 + SiMustWriteLock(sb);
30031 + sbinfo = au_sbi(sb);
30032 + file = au_xino_create2(base, sbinfo->si_xib);
30033 + err = PTR_ERR(file);
30034 + if (IS_ERR(file))
30036 + if (sbinfo->si_xib)
30037 + fput(sbinfo->si_xib);
30038 + sbinfo->si_xib = file;
30039 + sbinfo->si_xread = find_readf(file);
30040 + sbinfo->si_xwrite = find_writef(file);
30043 + if (!sbinfo->si_xib_buf)
30044 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
30045 + if (unlikely(!sbinfo->si_xib_buf))
30048 + sbinfo->si_xib_last_pindex = 0;
30049 + sbinfo->si_xib_next_bit = 0;
30050 + if (i_size_read(file->f_dentry->d_inode) < PAGE_SIZE) {
30052 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
30053 + PAGE_SIZE, &pos);
30054 + if (unlikely(err != PAGE_SIZE))
30058 + goto out; /* success */
30061 + free_page((unsigned long)sbinfo->si_xib_buf);
30062 + sbinfo->si_xib_buf = NULL;
30066 + fput(sbinfo->si_xib);
30067 + sbinfo->si_xib = NULL;
30068 + sbinfo->si_xread = NULL;
30069 + sbinfo->si_xwrite = NULL;
30074 +/* xino for each branch */
30075 +static void xino_clear_br(struct super_block *sb)
30077 + aufs_bindex_t bindex, bend;
30078 + struct au_branch *br;
30080 + bend = au_sbend(sb);
30081 + for (bindex = 0; bindex <= bend; bindex++) {
30082 + br = au_sbr(sb, bindex);
30083 + if (!br || !br->br_xino.xi_file)
30086 + fput(br->br_xino.xi_file);
30087 + br->br_xino.xi_file = NULL;
30091 +static int au_xino_set_br(struct super_block *sb, struct file *base)
30095 + aufs_bindex_t bindex, bend, bshared;
30097 + struct file *old, *new;
30099 + struct au_branch *br;
30100 + struct inode *inode;
30101 + au_writef_t writef;
30103 + SiMustWriteLock(sb);
30106 + bend = au_sbend(sb);
30107 + fpair = kcalloc(bend + 1, sizeof(*fpair), GFP_NOFS);
30108 + if (unlikely(!fpair))
30111 + inode = sb->s_root->d_inode;
30112 + ino = AUFS_ROOT_INO;
30113 + writef = au_sbi(sb)->si_xwrite;
30114 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
30115 + br = au_sbr(sb, bindex);
30116 + bshared = is_sb_shared(sb, bindex, bindex - 1);
30117 + if (bshared >= 0) {
30118 + /* shared xino */
30119 + *p = fpair[bshared];
30120 + get_file(p->new);
30125 + p->old = br->br_xino.xi_file;
30126 + p->new = au_xino_create2(base, br->br_xino.xi_file);
30127 + err = PTR_ERR(p->new);
30128 + if (IS_ERR(p->new)) {
30134 + err = au_xino_do_write(writef, p->new,
30135 + au_h_iptr(inode, bindex)->i_ino, ino);
30136 + if (unlikely(err))
30140 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
30141 + br = au_sbr(sb, bindex);
30142 + if (br->br_xino.xi_file)
30143 + fput(br->br_xino.xi_file);
30144 + get_file(p->new);
30145 + br->br_xino.xi_file = p->new;
30149 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++)
30159 +void au_xino_clr(struct super_block *sb)
30161 + struct au_sbinfo *sbinfo;
30163 + au_xigen_clr(sb);
30164 + xino_clear_xib(sb);
30165 + xino_clear_br(sb);
30166 + sbinfo = au_sbi(sb);
30167 + /* lvalue, do not call au_mntflags() */
30168 + au_opt_clr(sbinfo->si_mntflags, XINO);
30171 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
30174 + struct dentry *parent, *cur_parent;
30175 + struct qstr *dname, *cur_name;
30176 + struct file *cur_xino;
30177 + struct inode *dir;
30178 + struct au_sbinfo *sbinfo;
30180 + SiMustWriteLock(sb);
30183 + sbinfo = au_sbi(sb);
30184 + parent = dget_parent(xino->file->f_dentry);
30187 + dname = &xino->file->f_dentry->d_name;
30188 + cur_xino = sbinfo->si_xib;
30190 + cur_parent = dget_parent(cur_xino->f_dentry);
30191 + cur_name = &cur_xino->f_dentry->d_name;
30192 + skip = (cur_parent == parent
30193 + && dname->len == cur_name->len
30194 + && !memcmp(dname->name, cur_name->name,
30196 + dput(cur_parent);
30202 + au_opt_set(sbinfo->si_mntflags, XINO);
30203 + dir = parent->d_inode;
30204 + mutex_lock_nested(&dir->i_mutex, AuLsc_I_PARENT);
30205 + /* mnt_want_write() is unnecessary here */
30206 + err = au_xino_set_xib(sb, xino->file);
30208 + err = au_xigen_set(sb, xino->file);
30210 + err = au_xino_set_br(sb, xino->file);
30211 + mutex_unlock(&dir->i_mutex);
30213 + goto out; /* success */
30216 + AuIOErr("failed creating xino(%d).\n", err);
30223 +/* ---------------------------------------------------------------------- */
30226 + * create a xinofile at the default place/path.
30228 +struct file *au_xino_def(struct super_block *sb)
30230 + struct file *file;
30232 + struct au_branch *br;
30233 + struct super_block *h_sb;
30234 + struct path path;
30235 + aufs_bindex_t bend, bindex, bwr;
30238 + bend = au_sbend(sb);
30240 + for (bindex = 0; bindex <= bend; bindex++) {
30241 + br = au_sbr(sb, bindex);
30242 + if (au_br_writable(br->br_perm)
30243 + && !au_test_fs_bad_xino(br->br_mnt->mnt_sb)) {
30250 + file = ERR_PTR(-ENOMEM);
30251 + page = __getname_gfp(GFP_NOFS);
30252 + if (unlikely(!page))
30254 + path.mnt = br->br_mnt;
30255 + path.dentry = au_h_dptr(sb->s_root, bwr);
30256 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
30257 + file = (void *)p;
30258 + if (!IS_ERR(p)) {
30259 + strcat(p, "/" AUFS_XINO_FNAME);
30260 + AuDbg("%s\n", p);
30261 + file = au_xino_create(sb, p, /*silent*/0);
30262 + if (!IS_ERR(file))
30263 + au_xino_brid_set(sb, br->br_id);
30267 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
30268 + if (IS_ERR(file))
30270 + h_sb = file->f_dentry->d_sb;
30271 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
30272 + pr_err("xino doesn't support %s(%s)\n",
30273 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
30275 + file = ERR_PTR(-EINVAL);
30277 + if (!IS_ERR(file))
30278 + au_xino_brid_set(sb, -1);
30285 +/* ---------------------------------------------------------------------- */
30287 +int au_xino_path(struct seq_file *seq, struct file *file)
30291 + err = au_seq_path(seq, &file->f_path);
30292 + if (unlikely(err < 0))
30296 +#define Deleted "\\040(deleted)"
30297 + seq->count -= sizeof(Deleted) - 1;
30298 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
30299 + sizeof(Deleted) - 1));
30305 diff -urN /usr/share/empty/include/linux/aufs_type.h linux/include/linux/aufs_type.h
30306 --- /usr/share/empty/include/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
30307 +++ linux/include/linux/aufs_type.h 2012-03-19 12:24:13.686467926 +0100
30310 + * Copyright (C) 2005-2012 Junjiro R. Okajima
30312 + * This program, aufs is free software; you can redistribute it and/or modify
30313 + * it under the terms of the GNU General Public License as published by
30314 + * the Free Software Foundation; either version 2 of the License, or
30315 + * (at your option) any later version.
30317 + * This program is distributed in the hope that it will be useful,
30318 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30319 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30320 + * GNU General Public License for more details.
30322 + * You should have received a copy of the GNU General Public License
30323 + * along with this program; if not, write to the Free Software
30324 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30327 +#ifndef __AUFS_TYPE_H__
30328 +#define __AUFS_TYPE_H__
30330 +#define AUFS_NAME "aufs"
30334 + * define it before including all other headers.
30335 + * sched.h may use pr_* macros before defining "current", so define the
30336 + * no-current version first, and re-define later.
30338 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
30339 +#include <linux/sched.h>
30341 +#define pr_fmt(fmt) AUFS_NAME " %s:%d:%s[%d]: " fmt, \
30342 + __func__, __LINE__, current->comm, current->pid
30344 +#include <stdint.h>
30345 +#include <sys/types.h>
30346 +#endif /* __KERNEL__ */
30348 +#include <linux/limits.h>
30350 +#define AUFS_VERSION "3.x-rcN-20120312"
30352 +/* todo? move this to linux-2.6.19/include/magic.h */
30353 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
30355 +/* ---------------------------------------------------------------------- */
30357 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
30358 +typedef int8_t aufs_bindex_t;
30359 +#define AUFS_BRANCH_MAX 127
30361 +typedef int16_t aufs_bindex_t;
30362 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
30363 +#define AUFS_BRANCH_MAX 511
30364 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
30365 +#define AUFS_BRANCH_MAX 1023
30366 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
30367 +#define AUFS_BRANCH_MAX 32767
30372 +#ifndef AUFS_BRANCH_MAX
30373 +#error unknown CONFIG_AUFS_BRANCH_MAX value
30375 +#endif /* __KERNEL__ */
30377 +/* ---------------------------------------------------------------------- */
30379 +#define AUFS_FSTYPE AUFS_NAME
30381 +#define AUFS_ROOT_INO 2
30382 +#define AUFS_FIRST_INO 11
30384 +#define AUFS_WH_PFX ".wh."
30385 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
30386 +#define AUFS_WH_TMP_LEN 4
30387 +/* a limit for rmdir/rename a dir */
30388 +#define AUFS_MAX_NAMELEN (NAME_MAX \
30389 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
30391 + - AUFS_WH_TMP_LEN) /* hex */
30392 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
30393 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
30394 +#define AUFS_XINO_TRUNC_INIT 64 /* blocks */
30395 +#define AUFS_XINO_TRUNC_STEP 4 /* blocks */
30396 +#define AUFS_DIRWH_DEF 3
30397 +#define AUFS_RDCACHE_DEF 10 /* seconds */
30398 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
30399 +#define AUFS_RDBLK_DEF 512 /* bytes */
30400 +#define AUFS_RDHASH_DEF 32
30401 +#define AUFS_WKQ_NAME AUFS_NAME "d"
30402 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
30403 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
30404 +#define AUFS_PLINK_WARN 100 /* number of plinks */
30406 +/* pseudo-link maintenace under /proc */
30407 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
30408 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
30409 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
30411 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
30412 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
30414 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
30415 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
30416 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
30418 +/* doubly whiteouted */
30419 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
30420 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
30421 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
30423 +/* branch permissions and attributes */
30424 +#define AUFS_BRPERM_RW "rw"
30425 +#define AUFS_BRPERM_RO "ro"
30426 +#define AUFS_BRPERM_RR "rr"
30427 +#define AUFS_BRRATTR_WH "wh"
30428 +#define AUFS_BRWATTR_NLWH "nolwh"
30430 +/* ---------------------------------------------------------------------- */
30434 + /* readdir in userspace */
30438 + /* pathconf wrapper */
30445 +/* borrowed from linux/include/linux/kernel.h */
30447 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
30448 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
30451 +/* borrowed from linux/include/linux/compiler-gcc3.h */
30453 +#define __aligned(x) __attribute__((aligned(x)))
30458 +#define __packed __attribute__((packed))
30462 +struct au_rdu_cookie {
30467 + uint32_t generation;
30470 +struct au_rdu_ent {
30479 +static inline int au_rdu_len(int nlen)
30481 + /* include the terminating NULL */
30482 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
30483 + sizeof(uint64_t));
30486 +union au_rdu_ent_ul {
30487 + struct au_rdu_ent __user *e;
30499 + uint64_t sz; /* AuCtl_RDU */
30500 + uint64_t nent; /* AuCtl_RDU_INO */
30502 + union au_rdu_ent_ul ent;
30503 + uint16_t verify[AufsCtlRduV_End];
30505 + /* input/output */
30509 + union au_rdu_ent_ul tail;
30510 + /* number of entries which were added in a single call */
30515 + struct au_rdu_cookie cookie;
30518 +/* ---------------------------------------------------------------------- */
30520 +struct aufs_wbr_fd {
30525 +/* ---------------------------------------------------------------------- */
30527 +struct aufs_ibusy {
30528 + uint64_t ino, h_ino;
30532 +/* ---------------------------------------------------------------------- */
30534 +#define AuCtlType 'A'
30535 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
30536 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
30537 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
30538 + struct aufs_wbr_fd)
30539 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
30541 +#endif /* __AUFS_TYPE_H__ */