1 aufs3.x-rcN kbuild patch
3 diff --git a/fs/Kconfig b/fs/Kconfig
4 index f95ae3a..6d8a9a5 100644
7 @@ -220,6 +220,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 2fb9779..abefac5 100644
19 @@ -125,3 +125,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 8760be3..a1b8446 100644
26 --- a/include/linux/Kbuild
27 +++ b/include/linux/Kbuild
28 @@ -66,6 +66,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/inode.c b/fs/inode.c
39 index c99163b..7f772fd 100644
42 @@ -1491,7 +1491,7 @@ static int relatime_need_update(struct vfsmount *mnt, struct inode *inode,
43 * This does the actual work of updating an inodes time or version. Must have
44 * had called mnt_want_write() before calling this.
46 -static int update_time(struct inode *inode, struct timespec *time, int flags)
47 +int update_time(struct inode *inode, struct timespec *time, int flags)
49 if (inode->i_op->update_time)
50 return inode->i_op->update_time(inode, time, flags);
51 diff --git a/fs/namei.c b/fs/namei.c
52 index 7d69419..18c9782 100644
55 @@ -1864,7 +1864,7 @@ int vfs_path_lookup(struct dentry *dentry, struct vfsmount *mnt,
56 * needs parent already locked. Doesn't follow mounts.
59 -static struct dentry *lookup_hash(struct nameidata *nd)
60 +struct dentry *lookup_hash(struct nameidata *nd)
62 return __lookup_hash(&nd->last, nd->path.dentry, nd);
64 diff --git a/fs/splice.c b/fs/splice.c
65 index c9f1318..490239f 100644
68 @@ -1086,8 +1086,8 @@ EXPORT_SYMBOL(generic_splice_sendpage);
70 * Attempt to initiate a splice from pipe to file.
72 -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
73 - loff_t *ppos, size_t len, unsigned int flags)
74 +long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
75 + loff_t *ppos, size_t len, unsigned int flags)
77 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
78 loff_t *, size_t, unsigned int);
79 @@ -1114,9 +1114,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
81 * Attempt to initiate a splice from a file to a pipe.
83 -static long do_splice_to(struct file *in, loff_t *ppos,
84 - struct pipe_inode_info *pipe, size_t len,
86 +long do_splice_to(struct file *in, loff_t *ppos,
87 + struct pipe_inode_info *pipe, size_t len,
90 ssize_t (*splice_read)(struct file *, loff_t *,
91 struct pipe_inode_info *, size_t, unsigned int);
92 diff --git a/include/linux/fs.h b/include/linux/fs.h
93 index 17fd887..9c75a47 100644
94 --- a/include/linux/fs.h
95 +++ b/include/linux/fs.h
96 @@ -2591,6 +2591,7 @@ extern int inode_change_ok(const struct inode *, struct iattr *);
97 extern int inode_newsize_ok(const struct inode *, loff_t offset);
98 extern void setattr_copy(struct inode *inode, const struct iattr *attr);
100 +extern int update_time(struct inode *, struct timespec *, int);
101 extern int file_update_time(struct file *file);
103 extern int generic_show_options(struct seq_file *m, struct dentry *root);
104 diff --git a/include/linux/namei.h b/include/linux/namei.h
105 index ffc0213..ef35a31 100644
106 --- a/include/linux/namei.h
107 +++ b/include/linux/namei.h
108 @@ -85,6 +85,7 @@ extern int vfs_path_lookup(struct dentry *, struct vfsmount *,
109 extern struct file *lookup_instantiate_filp(struct nameidata *nd, struct dentry *dentry,
110 int (*open)(struct inode *, struct file *));
112 +extern struct dentry *lookup_hash(struct nameidata *nd);
113 extern struct dentry *lookup_one_len(const char *, struct dentry *, int);
115 extern int follow_down_one(struct path *);
116 diff --git a/include/linux/splice.h b/include/linux/splice.h
117 index 26e5b61..3ffef2f 100644
118 --- a/include/linux/splice.h
119 +++ b/include/linux/splice.h
120 @@ -91,4 +91,10 @@ extern void splice_shrink_spd(struct pipe_inode_info *,
121 extern void spd_release_page(struct splice_pipe_desc *, unsigned int);
123 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
125 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
126 + loff_t *ppos, size_t len, unsigned int flags);
127 +extern long do_splice_to(struct file *in, loff_t *ppos,
128 + struct pipe_inode_info *pipe, size_t len,
129 + unsigned int flags);
131 aufs3.x-rcN standalone patch
133 diff --git a/fs/file_table.c b/fs/file_table.c
134 index a305d9e..6a768be 100644
135 --- a/fs/file_table.c
136 +++ b/fs/file_table.c
137 @@ -35,6 +35,7 @@ struct files_stat_struct files_stat = {
140 DEFINE_LGLOCK(files_lglock);
141 +EXPORT_SYMBOL(files_lglock);
143 /* SLAB cache for file structures */
144 static struct kmem_cache *filp_cachep __read_mostly;
145 @@ -441,6 +442,8 @@ void file_sb_list_del(struct file *file)
149 +EXPORT_SYMBOL(file_sb_list_del);
154 diff --git a/fs/inode.c b/fs/inode.c
155 index 7f772fd..e789d2f 100644
158 @@ -56,6 +56,7 @@ static struct hlist_head *inode_hashtable __read_mostly;
159 static __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_hash_lock);
161 __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_sb_list_lock);
162 +EXPORT_SYMBOL(inode_sb_list_lock);
165 * Empty aops. Can be used for the cases where the user does not
166 @@ -1507,6 +1508,7 @@ int update_time(struct inode *inode, struct timespec *time, int flags)
167 mark_inode_dirty_sync(inode);
170 +EXPORT_SYMBOL(update_time);
173 * touch_atime - update the access time
174 diff --git a/fs/namei.c b/fs/namei.c
175 index 18c9782..f09edf3 100644
178 @@ -1868,6 +1868,7 @@ struct dentry *lookup_hash(struct nameidata *nd)
180 return __lookup_hash(&nd->last, nd->path.dentry, nd);
182 +EXPORT_SYMBOL(lookup_hash);
185 * lookup_one_len - filesystem helper to lookup single pathname component
186 diff --git a/fs/namespace.c b/fs/namespace.c
187 index 1e4a5fe..06aa768 100644
190 @@ -50,6 +50,7 @@ EXPORT_SYMBOL_GPL(fs_kobj);
191 * tree or hash is modified or when a vfsmount structure is modified.
193 DEFINE_BRLOCK(vfsmount_lock);
194 +EXPORT_SYMBOL(vfsmount_lock);
196 static inline unsigned long hash(struct vfsmount *mnt, struct dentry *dentry)
198 @@ -1341,6 +1342,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
202 +EXPORT_SYMBOL(iterate_mounts);
204 static void cleanup_group_ids(struct mount *mnt, struct mount *end)
206 diff --git a/fs/notify/group.c b/fs/notify/group.c
207 index 63fc294..6f4adca 100644
208 --- a/fs/notify/group.c
209 +++ b/fs/notify/group.c
211 #include <linux/srcu.h>
212 #include <linux/rculist.h>
213 #include <linux/wait.h>
214 +#include <linux/module.h>
216 #include <linux/fsnotify_backend.h>
217 #include "fsnotify.h"
218 @@ -70,6 +71,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
219 if (atomic_dec_and_test(&group->refcnt))
220 fsnotify_destroy_group(group);
222 +EXPORT_SYMBOL(fsnotify_put_group);
225 * Create a new fsnotify_group and hold a reference for the group returned.
226 @@ -102,3 +104,4 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
230 +EXPORT_SYMBOL(fsnotify_alloc_group);
231 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
232 index f104d56..54f36db 100644
233 --- a/fs/notify/mark.c
234 +++ b/fs/notify/mark.c
235 @@ -112,6 +112,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
236 if (atomic_dec_and_test(&mark->refcnt))
237 mark->free_mark(mark);
239 +EXPORT_SYMBOL(fsnotify_put_mark);
242 * Any time a mark is getting freed we end up here.
243 @@ -191,6 +192,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark)
244 if (unlikely(atomic_dec_and_test(&group->num_marks)))
245 fsnotify_final_destroy_group(group);
247 +EXPORT_SYMBOL(fsnotify_destroy_mark);
249 void fsnotify_set_mark_mask_locked(struct fsnotify_mark *mark, __u32 mask)
251 @@ -278,6 +280,7 @@ err:
255 +EXPORT_SYMBOL(fsnotify_add_mark);
258 * clear any marks in a group in which mark->flags & flags is true
259 @@ -333,6 +336,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
260 atomic_set(&mark->refcnt, 1);
261 mark->free_mark = free_mark;
263 +EXPORT_SYMBOL(fsnotify_init_mark);
265 static int fsnotify_mark_destroy(void *ignored)
267 diff --git a/fs/open.c b/fs/open.c
268 index d6c79a0..9004a15 100644
271 @@ -60,6 +60,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
272 mutex_unlock(&dentry->d_inode->i_mutex);
275 +EXPORT_SYMBOL(do_truncate);
277 static long do_sys_truncate(const char __user *pathname, loff_t length)
279 diff --git a/fs/splice.c b/fs/splice.c
280 index 490239f..701d34a 100644
283 @@ -1110,6 +1110,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
285 return splice_write(pipe, out, ppos, len, flags);
287 +EXPORT_SYMBOL(do_splice_from);
290 * Attempt to initiate a splice from a file to a pipe.
291 @@ -1136,6 +1137,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
293 return splice_read(in, ppos, pipe, len, flags);
295 +EXPORT_SYMBOL(do_splice_to);
298 * splice_direct_to_actor - splices data directly between two non-pipes
299 diff --git a/security/commoncap.c b/security/commoncap.c
300 index 6dbae46..9f4f29a 100644
301 --- a/security/commoncap.c
302 +++ b/security/commoncap.c
303 @@ -979,9 +979,11 @@ int cap_mmap_addr(unsigned long addr)
307 +EXPORT_SYMBOL(cap_mmap_addr);
309 int cap_mmap_file(struct file *file, unsigned long reqprot,
310 unsigned long prot, unsigned long flags)
314 +EXPORT_SYMBOL(cap_mmap_file);
315 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
316 index 442204c..e644a1c 100644
317 --- a/security/device_cgroup.c
318 +++ b/security/device_cgroup.c
320 #include <linux/device_cgroup.h>
321 #include <linux/cgroup.h>
322 #include <linux/ctype.h>
323 +#include <linux/export.h>
324 #include <linux/list.h>
325 #include <linux/uaccess.h>
326 #include <linux/seq_file.h>
327 @@ -493,6 +494,7 @@ found:
331 +EXPORT_SYMBOL(__devcgroup_inode_permission);
333 int devcgroup_inode_mknod(int mode, dev_t dev)
335 diff --git a/security/security.c b/security/security.c
336 index 3efc9b1..c7afd35 100644
337 --- a/security/security.c
338 +++ b/security/security.c
339 @@ -383,6 +383,7 @@ int security_path_rmdir(struct path *dir, struct dentry *dentry)
341 return security_ops->path_rmdir(dir, dentry);
343 +EXPORT_SYMBOL(security_path_rmdir);
345 int security_path_unlink(struct path *dir, struct dentry *dentry)
347 @@ -399,6 +400,7 @@ int security_path_symlink(struct path *dir, struct dentry *dentry,
349 return security_ops->path_symlink(dir, dentry, old_name);
351 +EXPORT_SYMBOL(security_path_symlink);
353 int security_path_link(struct dentry *old_dentry, struct path *new_dir,
354 struct dentry *new_dentry)
355 @@ -407,6 +409,7 @@ int security_path_link(struct dentry *old_dentry, struct path *new_dir,
357 return security_ops->path_link(old_dentry, new_dir, new_dentry);
359 +EXPORT_SYMBOL(security_path_link);
361 int security_path_rename(struct path *old_dir, struct dentry *old_dentry,
362 struct path *new_dir, struct dentry *new_dentry)
363 @@ -425,6 +428,7 @@ int security_path_truncate(struct path *path)
365 return security_ops->path_truncate(path);
367 +EXPORT_SYMBOL(security_path_truncate);
369 int security_path_chmod(struct path *path, umode_t mode)
371 @@ -432,6 +436,7 @@ int security_path_chmod(struct path *path, umode_t mode)
373 return security_ops->path_chmod(path, mode);
375 +EXPORT_SYMBOL(security_path_chmod);
377 int security_path_chown(struct path *path, uid_t uid, gid_t gid)
379 @@ -439,6 +444,7 @@ int security_path_chown(struct path *path, uid_t uid, gid_t gid)
381 return security_ops->path_chown(path, uid, gid);
383 +EXPORT_SYMBOL(security_path_chown);
385 int security_path_chroot(struct path *path)
387 @@ -515,6 +521,7 @@ int security_inode_readlink(struct dentry *dentry)
389 return security_ops->inode_readlink(dentry);
391 +EXPORT_SYMBOL(security_inode_readlink);
393 int security_inode_follow_link(struct dentry *dentry, struct nameidata *nd)
395 @@ -529,6 +536,7 @@ int security_inode_permission(struct inode *inode, int mask)
397 return security_ops->inode_permission(inode, mask);
399 +EXPORT_SYMBOL(security_inode_permission);
401 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
403 @@ -644,6 +652,7 @@ int security_file_permission(struct file *file, int mask)
405 return fsnotify_perm(file, mask);
407 +EXPORT_SYMBOL(security_file_permission);
409 int security_file_alloc(struct file *file)
411 @@ -704,6 +713,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
413 return ima_file_mmap(file, prot);
415 +EXPORT_SYMBOL(security_mmap_file);
417 int security_mmap_addr(unsigned long addr)
419 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
420 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
421 +++ linux/Documentation/ABI/testing/debugfs-aufs 2012-07-22 19:57:03.161004529 +0200
423 +What: /debug/aufs/si_<id>/
425 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
427 + Under /debug/aufs, a directory named si_<id> is created
428 + per aufs mount, where <id> is a unique id generated
431 +What: /debug/aufs/si_<id>/xib
433 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
435 + It shows the consumed blocks by xib (External Inode Number
436 + Bitmap), its block size and file size.
437 + When the aufs mount option 'noxino' is specified, it
438 + will be empty. About XINO files, see the aufs manual.
440 +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN
442 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
444 + It shows the consumed blocks by xino (External Inode Number
445 + Translation Table), its link count, block size and file
447 + When the aufs mount option 'noxino' is specified, it
448 + will be empty. About XINO files, see the aufs manual.
450 +What: /debug/aufs/si_<id>/xigen
452 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
454 + It shows the consumed blocks by xigen (External Inode
455 + Generation Table), its block size and file size.
456 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
458 + When the aufs mount option 'noxino' is specified, it
459 + will be empty. About XINO files, see the aufs manual.
460 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
461 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
462 +++ linux/Documentation/ABI/testing/sysfs-aufs 2012-07-22 19:57:03.161004529 +0200
464 +What: /sys/fs/aufs/si_<id>/
466 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
468 + Under /sys/fs/aufs, a directory named si_<id> is created
469 + per aufs mount, where <id> is a unique id generated
472 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
474 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
476 + It shows the abolute path of a member directory (which
477 + is called branch) in aufs, and its permission.
479 +What: /sys/fs/aufs/si_<id>/xi_path
481 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
483 + It shows the abolute path of XINO (External Inode Number
484 + Bitmap, Translation Table and Generation Table) file
485 + even if it is the default path.
486 + When the aufs mount option 'noxino' is specified, it
487 + will be empty. About XINO files, see the aufs manual.
488 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
489 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
490 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2012-07-22 19:57:03.161004531 +0200
493 +# Copyright (C) 2005-2011 Junjiro R. Okajima
495 +# This program is free software; you can redistribute it and/or modify
496 +# it under the terms of the GNU General Public License as published by
497 +# the Free Software Foundation; either version 2 of the License, or
498 +# (at your option) any later version.
500 +# This program is distributed in the hope that it will be useful,
501 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
502 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
503 +# GNU General Public License for more details.
505 +# You should have received a copy of the GNU General Public License
506 +# along with this program; if not, write to the Free Software
507 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
510 +----------------------------------------
512 +aufs [ei ju: ef es] | [a u f s]
513 +1. abbrev. for "advanced multi-layered unification filesystem".
514 +2. abbrev. for "another unionfs".
515 +3. abbrev. for "auf das" in German which means "on the" in English.
516 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
517 + But "Filesystem aufs Filesystem" is hard to understand.
519 +AUFS is a filesystem with features:
520 +- multi layered stackable unification filesystem, the member directory
521 + is called as a branch.
522 +- branch permission and attribute, 'readonly', 'real-readonly',
523 + 'readwrite', 'whiteout-able', 'link-able whiteout' and their
525 +- internal "file copy-on-write".
526 +- logical deletion, whiteout.
527 +- dynamic branch manipulation, adding, deleting and changing permission.
528 +- allow bypassing aufs, user's direct branch access.
529 +- external inode number translation table and bitmap which maintains the
530 + persistent aufs inode number.
531 +- seekable directory, including NFS readdir.
532 +- file mapping, mmap and sharing pages.
533 +- pseudo-link, hardlink over branches.
534 +- loopback mounted filesystem as a branch.
535 +- several policies to select one among multiple writable branches.
536 +- revert a single systemcall when an error occurs in aufs.
540 +Multi Layered Stackable Unification Filesystem
541 +----------------------------------------------------------------------
542 +Most people already knows what it is.
543 +It is a filesystem which unifies several directories and provides a
544 +merged single directory. When users access a file, the access will be
545 +passed/re-directed/converted (sorry, I am not sure which English word is
546 +correct) to the real file on the member filesystem. The member
547 +filesystem is called 'lower filesystem' or 'branch' and has a mode
548 +'readonly' and 'readwrite.' And the deletion for a file on the lower
549 +readonly branch is handled by creating 'whiteout' on the upper writable
552 +On LKML, there have been discussions about UnionMount (Jan Blunck,
553 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
554 +different approaches to implement the merged-view.
555 +The former tries putting it into VFS, and the latter implements as a
556 +separate filesystem.
557 +(If I misunderstand about these implementations, please let me know and
558 +I shall correct it. Because it is a long time ago when I read their
559 +source files last time).
561 +UnionMount's approach will be able to small, but may be hard to share
562 +branches between several UnionMount since the whiteout in it is
563 +implemented in the inode on branch filesystem and always
564 +shared. According to Bharata's post, readdir does not seems to be
566 +There are several missing features known in this implementations such as
567 +- for users, the inode number may change silently. eg. copy-up.
568 +- link(2) may break by copy-up.
569 +- read(2) may get an obsoleted filedata (fstat(2) too).
570 +- fcntl(F_SETLK) may be broken by copy-up.
571 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
574 +Unionfs has a longer history. When I started implementing a stacking filesystem
575 +(Aug 2005), it already existed. It has virtual super_block, inode,
576 +dentry and file objects and they have an array pointing lower same kind
577 +objects. After contributing many patches for Unionfs, I re-started my
578 +project AUFS (Jun 2006).
580 +In AUFS, the structure of filesystem resembles to Unionfs, but I
581 +implemented my own ideas, approaches and enhancements and it became
582 +totally different one.
584 +Comparing DM snapshot and fs based implementation
585 +- the number of bytes to be copied between devices is much smaller.
586 +- the type of filesystem must be one and only.
587 +- the fs must be writable, no readonly fs, even for the lower original
588 + device. so the compression fs will not be usable. but if we use
589 + loopback mount, we may address this issue.
591 + mount /cdrom/squashfs.img /sq
592 + losetup /sq/ext2.img
593 + losetup /somewhere/cow
594 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
595 +- it will be difficult (or needs more operations) to extract the
596 + difference between the original device and COW.
597 +- DM snapshot-merge may help a lot when users try merging. in the
598 + fs-layer union, users will use rsync(1).
601 +Several characters/aspects of aufs
602 +----------------------------------------------------------------------
604 +Aufs has several characters or aspects.
605 +1. a filesystem, callee of VFS helper
606 +2. sub-VFS, caller of VFS helper for branches
607 +3. a virtual filesystem which maintains persistent inode number
608 +4. reader/writer of files on branches such like an application
610 +1. Callee of VFS Helper
611 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
612 +unlink(2) from an application reaches sys_unlink() kernel function and
613 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
614 +calls filesystem specific unlink operation. Actually aufs implements the
615 +unlink operation but it behaves like a redirector.
617 +2. Caller of VFS Helper for Branches
618 +aufs_unlink() passes the unlink request to the branch filesystem as if
619 +it were called from VFS. So the called unlink operation of the branch
620 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
621 +every necessary pre/post operation for the branch filesystem.
622 +- acquire the lock for the parent dir on a branch
623 +- lookup in a branch
624 +- revalidate dentry on a branch
625 +- mnt_want_write() for a branch
626 +- vfs_unlink() for a branch
627 +- mnt_drop_write() for a branch
628 +- release the lock on a branch
630 +3. Persistent Inode Number
631 +One of the most important issue for a filesystem is to maintain inode
632 +numbers. This is particularly important to support exporting a
633 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
634 +backend block device for its own. But some storage is necessary to
635 +maintain inode number. It may be a large space and may not suit to keep
636 +in memory. Aufs rents some space from its first writable branch
637 +filesystem (by default) and creates file(s) on it. These files are
638 +created by aufs internally and removed soon (currently) keeping opened.
639 +Note: Because these files are removed, they are totally gone after
640 + unmounting aufs. It means the inode numbers are not persistent
641 + across unmount or reboot. I have a plan to make them really
642 + persistent which will be important for aufs on NFS server.
644 +4. Read/Write Files Internally (copy-on-write)
645 +Because a branch can be readonly, when you write a file on it, aufs will
646 +"copy-up" it to the upper writable branch internally. And then write the
647 +originally requested thing to the file. Generally kernel doesn't
648 +open/read/write file actively. In aufs, even a single write may cause a
649 +internal "file copy". This behaviour is very similar to cp(1) command.
651 +Some people may think it is better to pass such work to user space
652 +helper, instead of doing in kernel space. Actually I am still thinking
653 +about it. But currently I have implemented it in kernel space.
654 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
655 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
656 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2012-07-22 19:57:03.161004531 +0200
659 +# Copyright (C) 2005-2011 Junjiro R. Okajima
661 +# This program is free software; you can redistribute it and/or modify
662 +# it under the terms of the GNU General Public License as published by
663 +# the Free Software Foundation; either version 2 of the License, or
664 +# (at your option) any later version.
666 +# This program is distributed in the hope that it will be useful,
667 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
668 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
669 +# GNU General Public License for more details.
671 +# You should have received a copy of the GNU General Public License
672 +# along with this program; if not, write to the Free Software
673 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
675 +Basic Aufs Internal Structure
677 +Superblock/Inode/Dentry/File Objects
678 +----------------------------------------------------------------------
679 +As like an ordinary filesystem, aufs has its own
680 +superblock/inode/dentry/file objects. All these objects have a
681 +dynamically allocated array and store the same kind of pointers to the
682 +lower filesystem, branch.
683 +For example, when you build a union with one readwrite branch and one
684 +readonly, mounted /au, /rw and /ro respectively.
686 +- /ro/fileA exists but /rw/fileA
688 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
689 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
693 +This style of an array is essentially same to the aufs
694 +superblock/inode/dentry/file objects.
696 +Because aufs supports manipulating branches, ie. add/delete/change
697 +dynamically, these objects has its own generation. When branches are
698 +changed, the generation in aufs superblock is incremented. And a
699 +generation in other object are compared when it is accessed.
700 +When a generation in other objects are obsoleted, aufs refreshes the
705 +----------------------------------------------------------------------
706 +Additionally aufs superblock has some data for policies to select one
707 +among multiple writable branches, XIB files, pseudo-links and kobject.
708 +See below in detail.
709 +About the policies which supports copy-down a directory, see policy.txt
713 +Branch and XINO(External Inode Number Translation Table)
714 +----------------------------------------------------------------------
715 +Every branch has its own xino (external inode number translation table)
716 +file. The xino file is created and unlinked by aufs internally. When two
717 +members of a union exist on the same filesystem, they share the single
719 +The struct of a xino file is simple, just a sequence of aufs inode
720 +numbers which is indexed by the lower inode number.
721 +In the above sample, assume the inode number of /ro/fileA is i111 and
722 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
723 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
725 +When the inode numbers are not contiguous, the xino file will be sparse
726 +which has a hole in it and doesn't consume as much disk space as it
727 +might appear. If your branch filesystem consumes disk space for such
728 +holes, then you should specify 'xino=' option at mounting aufs.
730 +Also a writable branch has three kinds of "whiteout bases". All these
731 +are existed when the branch is joined to aufs and the names are
732 +whiteout-ed doubly, so that users will never see their names in aufs
734 +1. a regular file which will be linked to all whiteouts.
735 +2. a directory to store a pseudo-link.
736 +3. a directory to store an "orphan-ed" file temporary.
739 + When you remove a file on a readonly branch, aufs handles it as a
740 + logical deletion and creates a whiteout on the upper writable branch
741 + as a hardlink of this file in order not to consume inode on the
744 + See below, Pseudo-link.
746 + When "fileC" exists on the lower readonly branch only and it is
747 + opened and removed with its parent dir, and then user writes
748 + something into it, then aufs copies-up fileC to this
749 + directory. Because there is no other dir to store fileC. After
750 + creating a file under this dir, the file is unlinked.
752 +Because aufs supports manipulating branches, ie. add/delete/change
753 +dynamically, a branch has its own id. When the branch order changes, aufs
754 +finds the new index by searching the branch id.
758 +----------------------------------------------------------------------
759 +Assume "fileA" exists on the lower readonly branch only and it is
760 +hardlinked to "fileB" on the branch. When you write something to fileA,
761 +aufs copies-up it to the upper writable branch. Additionally aufs
762 +creates a hardlink under the Pseudo-link Directory of the writable
763 +branch. The inode of a pseudo-link is kept in aufs super_block as a
764 +simple list. If fileB is read after unlinking fileA, aufs returns
765 +filedata from the pseudo-link instead of the lower readonly
766 +branch. Because the pseudo-link is based upon the inode, to keep the
767 +inode number by xino (see above) is important.
769 +All the hardlinks under the Pseudo-link Directory of the writable branch
770 +should be restored in a proper location later. Aufs provides a utility
771 +to do this. The userspace helpers executed at remounting and unmounting
773 +During this utility is running, it puts aufs into the pseudo-link
774 +maintenance mode. In this mode, only the process which began the
775 +maintenance mode (and its child processes) is allowed to operate in
776 +aufs. Some other processes which are not related to the pseudo-link will
777 +be allowed to run too, but the rest have to return an error or wait
778 +until the maintenance mode ends. If a process already acquires an inode
779 +mutex (in VFS), it has to return an error.
782 +XIB(external inode number bitmap)
783 +----------------------------------------------------------------------
784 +Addition to the xino file per a branch, aufs has an external inode number
785 +bitmap in a superblock object. It is also a file such like a xino file.
786 +It is a simple bitmap to mark whether the aufs inode number is in-use or
788 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
790 +Aufs implements a feature to truncate/refresh both of xino and xib to
791 +reduce the number of consumed disk blocks for these files.
794 +Virtual or Vertical Dir, and Readdir in Userspace
795 +----------------------------------------------------------------------
796 +In order to support multiple layers (branches), aufs readdir operation
797 +constructs a virtual dir block on memory. For readdir, aufs calls
798 +vfs_readdir() internally for each dir on branches, merges their entries
799 +with eliminating the whiteout-ed ones, and sets it to file (dir)
800 +object. So the file object has its entry list until it is closed. The
801 +entry list will be updated when the file position is zero and becomes
802 +old. This decision is made in aufs automatically.
804 +The dynamically allocated memory block for the name of entries has a
805 +unit of 512 bytes (by default) and stores the names contiguously (no
806 +padding). Another block for each entry is handled by kmem_cache too.
807 +During building dir blocks, aufs creates hash list and judging whether
808 +the entry is whiteouted by its upper branch or already listed.
809 +The merged result is cached in the corresponding inode object and
810 +maintained by a customizable life-time option.
812 +Some people may call it can be a security hole or invite DoS attack
813 +since the opened and once readdir-ed dir (file object) holds its entry
814 +list and becomes a pressure for system memory. But I'd say it is similar
815 +to files under /proc or /sys. The virtual files in them also holds a
816 +memory page (generally) while they are opened. When an idea to reduce
817 +memory for them is introduced, it will be applied to aufs too.
818 +For those who really hate this situation, I've developed readdir(3)
819 +library which operates this merging in userspace. You just need to set
820 +LD_PRELOAD environment variable, and aufs will not consume no memory in
821 +kernel space for readdir(3).
825 +----------------------------------------------------------------------
826 +Aufs sometimes requires privilege access to a branch. For instance,
827 +in copy-up/down operation. When a user process is going to make changes
828 +to a file which exists in the lower readonly branch only, and the mode
829 +of one of ancestor directories may not be writable by a user
830 +process. Here aufs copy-up the file with its ancestors and they may
831 +require privilege to set its owner/group/mode/etc.
832 +This is a typical case of a application character of aufs (see
835 +Aufs uses workqueue synchronously for this case. It creates its own
836 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
837 +passes the request to call mkdir or write (for example), and wait for
838 +its completion. This approach solves a problem of a signal handler
840 +If aufs didn't adopt the workqueue and changed the privilege of the
841 +process, and if the mkdir/write call arises SIGXFSZ or other signal,
842 +then the user process might gain a privilege or the generated core file
843 +was owned by a superuser.
845 +Also aufs uses the system global workqueue ("events" kernel thread) too
846 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
847 +whiteout base and etc. This is unrelated to a privilege.
848 +Most of aufs operation tries acquiring a rw_semaphore for aufs
849 +superblock at the beginning, at the same time waits for the completion
850 +of all queued asynchronous tasks.
854 +----------------------------------------------------------------------
855 +The whiteout in aufs is very similar to Unionfs's. That is represented
856 +by its filename. UnionMount takes an approach of a file mode, but I am
857 +afraid several utilities (find(1) or something) will have to support it.
859 +Basically the whiteout represents "logical deletion" which stops aufs to
860 +lookup further, but also it represents "dir is opaque" which also stop
863 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
864 +In order to make several functions in a single systemcall to be
865 +revertible, aufs adopts an approach to rename a directory to a temporary
866 +unique whiteouted name.
867 +For example, in rename(2) dir where the target dir already existed, aufs
868 +renames the target dir to a temporary unique whiteouted name before the
869 +actual rename on a branch and then handles other actions (make it opaque,
870 +update the attributes, etc). If an error happens in these actions, aufs
871 +simply renames the whiteouted name back and returns an error. If all are
872 +succeeded, aufs registers a function to remove the whiteouted unique
873 +temporary name completely and asynchronously to the system global
878 +----------------------------------------------------------------------
879 +It is a well-known feature or concept.
880 +When user modifies a file on a readonly branch, aufs operate "copy-up"
881 +internally and makes change to the new file on the upper writable branch.
882 +When the trigger systemcall does not update the timestamps of the parent
883 +dir, aufs reverts it after copy-up.
884 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
885 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
886 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2012-07-22 19:57:03.161004531 +0200
889 +# Copyright (C) 2005-2011 Junjiro R. Okajima
891 +# This program is free software; you can redistribute it and/or modify
892 +# it under the terms of the GNU General Public License as published by
893 +# the Free Software Foundation; either version 2 of the License, or
894 +# (at your option) any later version.
896 +# This program is distributed in the hope that it will be useful,
897 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
898 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
899 +# GNU General Public License for more details.
901 +# You should have received a copy of the GNU General Public License
902 +# along with this program; if not, write to the Free Software
903 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
906 +----------------------------------------------------------------------
907 +Since aufs has a character of sub-VFS (see Introduction), it operates
908 +lookup for branches as VFS does. It may be a heavy work. Generally
909 +speaking struct nameidata is a bigger structure and includes many
910 +information. But almost all lookup operation in aufs is the simplest
911 +case, ie. lookup only an entry directly connected to its parent. Digging
912 +down the directory hierarchy is unnecessary.
914 +VFS has a function lookup_one_len() for that use, but it is not usable
915 +for a branch filesystem which requires struct nameidata. So aufs
916 +implements a simple lookup wrapper function. When a branch filesystem
917 +allows NULL as nameidata, it calls lookup_one_len(). Otherwise it builds
918 +a simplest nameidata and calls lookup_hash().
919 +Here aufs applies "a principle in NFSD", ie. if the filesystem supports
920 +NFS-export, then it has to support NULL as a nameidata parameter for
921 +->create(), ->lookup() and ->d_revalidate(). So the lookup wrapper in
922 +aufs tests if ->s_export_op in the branch is NULL or not.
924 +When a branch is a remote filesystem, aufs basically trusts its
925 +->d_revalidate(), also aufs forces the hardest revalidate tests for
927 +For d_revalidate, aufs implements three levels of revalidate tests. See
928 +"Revalidate Dentry and UDBA" in detail.
932 +----------------------------------------------------------------------
933 +Basically aufs supports any type of filesystem and block device for a
934 +branch (actually there are some exceptions). But it is prohibited to add
935 +a loopback mounted one whose backend file exists in a filesystem which is
936 +already added to aufs. The reason is to protect aufs from a recursive
937 +lookup. If it was allowed, the aufs lookup operation might re-enter a
938 +lookup for the loopback mounted branch in the same context, and will
942 +Revalidate Dentry and UDBA (User's Direct Branch Access)
943 +----------------------------------------------------------------------
944 +Generally VFS helpers re-validate a dentry as a part of lookup.
945 +0. digging down the directory hierarchy.
946 +1. lock the parent dir by its i_mutex.
947 +2. lookup the final (child) entry.
949 +4. call the actual operation (create, unlink, etc.)
950 +5. unlock the parent dir
952 +If the filesystem implements its ->d_revalidate() (step 3), then it is
953 +called. Actually aufs implements it and checks the dentry on a branch is
955 +But it is not enough. Because aufs has to release the lock for the
956 +parent dir on a branch at the end of ->lookup() (step 2) and
957 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
959 +If the file on a branch is changed directly, eg. bypassing aufs, after
960 +aufs released the lock, then the subsequent operation may cause
961 +something unpleasant result.
963 +This situation is a result of VFS architecture, ->lookup() and
964 +->d_revalidate() is separated. But I never say it is wrong. It is a good
965 +design from VFS's point of view. It is just not suitable for sub-VFS
968 +Aufs supports such case by three level of revalidation which is
970 +1. Simple Revalidate
971 + Addition to the native flow in VFS's, confirm the child-parent
972 + relationship on the branch just after locking the parent dir on the
973 + branch in the "actual operation" (step 4). When this validation
974 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
975 + checks the validation of the dentry on branches.
976 +2. Monitor Changes Internally by Inotify/Fsnotify
977 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
978 + the dentry on the branch, and returns EBUSY if it finds different
980 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
981 + during it is in cache. When the event is notified, aufs registers a
982 + function to kernel 'events' thread by schedule_work(). And the
983 + function sets some special status to the cached aufs dentry and inode
984 + private data. If they are not cached, then aufs has nothing to
985 + do. When the same file is accessed through aufs (step 0-3) later,
986 + aufs will detect the status and refresh all necessary data.
987 + In this mode, aufs has to ignore the event which is fired by aufs
989 +3. No Extra Validation
990 + This is the simplest test and doesn't add any additional revalidation
991 + test, and skip therevalidatin in step 4. It is useful and improves
992 + aufs performance when system surely hide the aufs branches from user,
993 + by over-mounting something (or another method).
994 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
995 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
996 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2012-07-22 19:57:03.161004531 +0200
999 +# Copyright (C) 2005-2011 Junjiro R. Okajima
1001 +# This program is free software; you can redistribute it and/or modify
1002 +# it under the terms of the GNU General Public License as published by
1003 +# the Free Software Foundation; either version 2 of the License, or
1004 +# (at your option) any later version.
1006 +# This program is distributed in the hope that it will be useful,
1007 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1008 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1009 +# GNU General Public License for more details.
1011 +# You should have received a copy of the GNU General Public License
1012 +# along with this program; if not, write to the Free Software
1013 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1015 +Branch Manipulation
1017 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1018 +and changing its permission/attribute, there are a lot of works to do.
1022 +----------------------------------------------------------------------
1023 +o Confirm the adding dir exists outside of aufs, including loopback
1025 +- and other various attributes...
1026 +o Initialize the xino file and whiteout bases if necessary.
1029 +o Check the owner/group/mode of the directory
1030 + When the owner/group/mode of the adding directory differs from the
1031 + existing branch, aufs issues a warning because it may impose a
1033 + For example, when a upper writable branch has a world writable empty
1034 + top directory, a malicious user can create any files on the writable
1035 + branch directly, like copy-up and modify manually. If something like
1036 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1037 + writable branch, and the writable branch is world-writable, then a
1038 + malicious guy may create /etc/passwd on the writable branch directly
1039 + and the infected file will be valid in aufs.
1040 + I am afraid it can be a security issue, but nothing to do except
1041 + producing a warning.
1045 +----------------------------------------------------------------------
1046 +o Confirm the deleting branch is not busy
1047 + To be general, there is one merit to adopt "remount" interface to
1048 + manipulate branches. It is to discard caches. At deleting a branch,
1049 + aufs checks the still cached (and connected) dentries and inodes. If
1050 + there are any, then they are all in-use. An inode without its
1051 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1053 + For the cached one, aufs checks whether the same named entry exists on
1055 + If the cached one is a directory, because aufs provides a merged view
1056 + to users, as long as one dir is left on any branch aufs can show the
1057 + dir to users. In this case, the branch can be removed from aufs.
1058 + Otherwise aufs rejects deleting the branch.
1060 + If any file on the deleting branch is opened by aufs, then aufs
1064 +Modify the Permission of a Branch
1065 +----------------------------------------------------------------------
1066 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1069 +o rw --> ro: Confirm the modifying branch is not busy
1070 + Aufs rejects the request if any of these conditions are true.
1071 + - a file on the branch is mmap-ed.
1072 + - a regular file on the branch is opened for write and there is no
1073 + same named entry on the upper branch.
1074 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1075 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1076 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2012-07-22 19:57:03.161004531 +0200
1079 +# Copyright (C) 2005-2011 Junjiro R. Okajima
1081 +# This program is free software; you can redistribute it and/or modify
1082 +# it under the terms of the GNU General Public License as published by
1083 +# the Free Software Foundation; either version 2 of the License, or
1084 +# (at your option) any later version.
1086 +# This program is distributed in the hope that it will be useful,
1087 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1088 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1089 +# GNU General Public License for more details.
1091 +# You should have received a copy of the GNU General Public License
1092 +# along with this program; if not, write to the Free Software
1093 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1095 +Policies to Select One among Multiple Writable Branches
1096 +----------------------------------------------------------------------
1097 +When the number of writable branch is more than one, aufs has to decide
1098 +the target branch for file creation or copy-up. By default, the highest
1099 +writable branch which has the parent (or ancestor) dir of the target
1100 +file is chosen (top-down-parent policy).
1101 +By user's request, aufs implements some other policies to select the
1102 +writable branch, for file creation two policies, round-robin and
1103 +most-free-space policies. For copy-up three policies, top-down-parent,
1104 +bottom-up-parent and bottom-up policies.
1106 +As expected, the round-robin policy selects the branch in circular. When
1107 +you have two writable branches and creates 10 new files, 5 files will be
1108 +created for each branch. mkdir(2) systemcall is an exception. When you
1109 +create 10 new directories, all will be created on the same branch.
1110 +And the most-free-space policy selects the one which has most free
1111 +space among the writable branches. The amount of free space will be
1112 +checked by aufs internally, and users can specify its time interval.
1114 +The policies for copy-up is more simple,
1115 +top-down-parent is equivalent to the same named on in create policy,
1116 +bottom-up-parent selects the writable branch where the parent dir
1117 +exists and the nearest upper one from the copyup-source,
1118 +bottom-up selects the nearest upper writable branch from the
1119 +copyup-source, regardless the existence of the parent dir.
1121 +There are some rules or exceptions to apply these policies.
1122 +- If there is a readonly branch above the policy-selected branch and
1123 + the parent dir is marked as opaque (a variation of whiteout), or the
1124 + target (creating) file is whiteout-ed on the upper readonly branch,
1125 + then the result of the policy is ignored and the target file will be
1126 + created on the nearest upper writable branch than the readonly branch.
1127 +- If there is a writable branch above the policy-selected branch and
1128 + the parent dir is marked as opaque or the target file is whiteouted
1129 + on the branch, then the result of the policy is ignored and the target
1130 + file will be created on the highest one among the upper writable
1131 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1133 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1134 + They try selecting the branch where the source exists as possible
1135 + since copyup a large file will take long time. If it can't be,
1136 + ie. the branch where the source exists is readonly, then they will
1137 + follow the copyup policy.
1138 +- There is an exception for rename(2) when the target exists.
1139 + If the rename target exists, aufs compares the index of the branches
1140 + where the source and the target exists and selects the higher
1141 + one. If the selected branch is readonly, then aufs follows the
1143 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
1144 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
1145 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2012-07-22 19:57:03.161004531 +0200
1148 +# Copyright (C) 2005-2011 Junjiro R. Okajima
1150 +# This program is free software; you can redistribute it and/or modify
1151 +# it under the terms of the GNU General Public License as published by
1152 +# the Free Software Foundation; either version 2 of the License, or
1153 +# (at your option) any later version.
1155 +# This program is distributed in the hope that it will be useful,
1156 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1157 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1158 +# GNU General Public License for more details.
1160 +# You should have received a copy of the GNU General Public License
1161 +# along with this program; if not, write to the Free Software
1162 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1164 +mmap(2) -- File Memory Mapping
1165 +----------------------------------------------------------------------
1166 +In aufs, the file-mapped pages are handled by a branch fs directly, no
1167 +interaction with aufs. It means aufs_mmap() calls the branch fs's
1169 +This approach is simple and good, but there is one problem.
1170 +Under /proc, several entries show the mmap-ped files by its path (with
1171 +device and inode number), and the printed path will be the path on the
1172 +branch fs's instead of virtual aufs's.
1173 +This is not a problem in most cases, but some utilities lsof(1) (and its
1174 +user) may expect the path on aufs.
1176 +To address this issue, aufs adds a new member called vm_prfile in struct
1177 +vm_area_struct (and struct vm_region). The original vm_file points to
1178 +the file on the branch fs in order to handle everything correctly as
1179 +usual. The new vm_prfile points to a virtual file in aufs, and the
1180 +show-functions in procfs refers to vm_prfile if it is set.
1181 +Also we need to maintain several other places where touching vm_file
1183 +- fork()/clone() copies vma and the reference count of vm_file is
1185 +- merging vma maintains the ref count too.
1187 +This is not a good approach. It just faking the printed path. But it
1188 +leaves all behaviour around f_mapping unchanged. This is surely an
1190 +Actually aufs had adopted another complicated approach which calls
1191 +generic_file_mmap() and handles struct vm_operations_struct. In this
1192 +approach, aufs met a hard problem and I could not solve it without
1193 +switching the approach.
1194 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
1195 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
1196 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2012-07-22 19:57:03.161004531 +0200
1199 +# Copyright (C) 2005-2011 Junjiro R. Okajima
1201 +# This program is free software; you can redistribute it and/or modify
1202 +# it under the terms of the GNU General Public License as published by
1203 +# the Free Software Foundation; either version 2 of the License, or
1204 +# (at your option) any later version.
1206 +# This program is distributed in the hope that it will be useful,
1207 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1208 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1209 +# GNU General Public License for more details.
1211 +# You should have received a copy of the GNU General Public License
1212 +# along with this program; if not, write to the Free Software
1213 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1215 +Export Aufs via NFS
1216 +----------------------------------------------------------------------
1217 +Here is an approach.
1218 +- like xino/xib, add a new file 'xigen' which stores aufs inode
1220 +- iget_locked(): initialize aufs inode generation for a new inode, and
1221 + store it in xigen file.
1222 +- destroy_inode(): increment aufs inode generation and store it in xigen
1223 + file. it is necessary even if it is not unlinked, because any data of
1224 + inode may be changed by UDBA.
1225 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
1226 + build file handle by
1227 + + branch id (4 bytes)
1228 + + superblock generation (4 bytes)
1229 + + inode number (4 or 8 bytes)
1230 + + parent dir inode number (4 or 8 bytes)
1231 + + inode generation (4 bytes))
1232 + + return value of exportfs_encode_fh() for the parent on a branch (4
1234 + + file handle for a branch (by exportfs_encode_fh())
1236 + + find the index of a branch from its id in handle, and check it is
1237 + still exist in aufs.
1238 + + 1st level: get the inode number from handle and search it in cache.
1239 + + 2nd level: if not found, get the parent inode number from handle and
1240 + search it in cache. and then open the parent dir, find the matching
1241 + inode number by vfs_readdir() and get its name, and call
1242 + lookup_one_len() for the target dentry.
1243 + + 3rd level: if the parent dir is not cached, call
1244 + exportfs_decode_fh() for a branch and get the parent on a branch,
1245 + build a pathname of it, convert it a pathname in aufs, call
1246 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
1248 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
1249 + for every branch, but not itself. to get this, (currently) aufs
1250 + searches in current->nsproxy->mnt_ns list. it may not be a good
1251 + idea, but I didn't get other approach.
1252 + + test the generation of the gotten inode.
1253 +- every inode operation: they may get EBUSY due to UDBA. in this case,
1254 + convert it into ESTALE for NFSD.
1255 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
1256 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
1257 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
1258 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
1259 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2012-07-22 19:57:03.161004531 +0200
1262 +# Copyright (C) 2005-2011 Junjiro R. Okajima
1264 +# This program is free software; you can redistribute it and/or modify
1265 +# it under the terms of the GNU General Public License as published by
1266 +# the Free Software Foundation; either version 2 of the License, or
1267 +# (at your option) any later version.
1269 +# This program is distributed in the hope that it will be useful,
1270 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1271 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1272 +# GNU General Public License for more details.
1274 +# You should have received a copy of the GNU General Public License
1275 +# along with this program; if not, write to the Free Software
1276 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1278 +Show Whiteout Mode (shwh)
1279 +----------------------------------------------------------------------
1280 +Generally aufs hides the name of whiteouts. But in some cases, to show
1281 +them is very useful for users. For instance, creating a new middle layer
1282 +(branch) by merging existing layers.
1284 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
1285 +When you have three branches,
1286 +- Bottom: 'system', squashfs (underlying base system), read-only
1287 +- Middle: 'mods', squashfs, read-only
1288 +- Top: 'overlay', ram (tmpfs), read-write
1290 +The top layer is loaded at boot time and saved at shutdown, to preserve
1291 +the changes made to the system during the session.
1292 +When larger changes have been made, or smaller changes have accumulated,
1293 +the size of the saved top layer data grows. At this point, it would be
1294 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
1295 +and rewrite the 'mods' squashfs, clearing the top layer and thus
1296 +restoring save and load speed.
1298 +This merging is simplified by the use of another aufs mount, of just the
1299 +two overlay branches using the 'shwh' option.
1300 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
1301 + aufs /livesys/merge_union
1303 +A merged view of these two branches is then available at
1304 +/livesys/merge_union, and the new feature is that the whiteouts are
1306 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
1307 +writing to all branches. Also the default mode for all branches is 'ro'.
1308 +It is now possible to save the combined contents of the two overlay
1309 +branches to a new squashfs, e.g.:
1310 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
1312 +This new squashfs archive can be stored on the boot device and the
1313 +initramfs will use it to replace the old one at the next boot.
1314 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
1315 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
1316 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2012-07-22 19:57:03.161004531 +0200
1319 +# Copyright (C) 2010-2011 Junjiro R. Okajima
1321 +# This program is free software; you can redistribute it and/or modify
1322 +# it under the terms of the GNU General Public License as published by
1323 +# the Free Software Foundation; either version 2 of the License, or
1324 +# (at your option) any later version.
1326 +# This program is distributed in the hope that it will be useful,
1327 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1328 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1329 +# GNU General Public License for more details.
1331 +# You should have received a copy of the GNU General Public License
1332 +# along with this program; if not, write to the Free Software
1333 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1335 +Dynamically customizable FS operations
1336 +----------------------------------------------------------------------
1337 +Generally FS operations (struct inode_operations, struct
1338 +address_space_operations, struct file_operations, etc.) are defined as
1339 +"static const", but it never means that FS have only one set of
1340 +operation. Some FS have multiple sets of them. For instance, ext2 has
1341 +three sets, one for XIP, for NOBH, and for normal.
1342 +Since aufs overrides and redirects these operations, sometimes aufs has
1343 +to change its behaviour according to the branch FS type. More imporantly
1344 +VFS acts differently if a function (member in the struct) is set or
1345 +not. It means aufs should have several sets of operations and select one
1346 +among them according to the branch FS definition.
1348 +In order to solve this problem and not to affect the behavour of VFS,
1349 +aufs defines these operations dynamically. For instance, aufs defines
1350 +aio_read function for struct file_operations, but it may not be set to
1351 +the file_operations. When the branch FS doesn't have it, aufs doesn't
1352 +set it to its file_operations while the function definition itself is
1353 +still alive. So the behaviour of io_submit(2) will not change, and it
1354 +will return an error when aio_read is not defined.
1356 +The lifetime of these dynamically generated operation object is
1357 +maintained by aufs branch object. When the branch is removed from aufs,
1358 +the reference counter of the object is decremented. When it reaches
1359 +zero, the dynamically generated operation object will be freed.
1361 +This approach is designed to support AIO (io_submit), Direcit I/O and
1363 +Currently this approach is applied to file_operations and
1364 +vm_operations_struct for regular files only.
1365 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt linux/Documentation/filesystems/aufs/design/99plan.txt
1366 --- /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt 1970-01-01 01:00:00.000000000 +0100
1367 +++ linux/Documentation/filesystems/aufs/design/99plan.txt 2012-07-22 19:57:03.161004531 +0200
1370 +# Copyright (C) 2005-2011 Junjiro R. Okajima
1372 +# This program is free software; you can redistribute it and/or modify
1373 +# it under the terms of the GNU General Public License as published by
1374 +# the Free Software Foundation; either version 2 of the License, or
1375 +# (at your option) any later version.
1377 +# This program is distributed in the hope that it will be useful,
1378 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1379 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1380 +# GNU General Public License for more details.
1382 +# You should have received a copy of the GNU General Public License
1383 +# along with this program; if not, write to the Free Software
1384 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1388 +Restoring some features which was implemented in aufs1.
1389 +They were dropped in aufs2 in order to make source files simpler and
1390 +easier to be reviewed.
1393 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1394 +----------------------------------------------------------------------
1395 +Let's try case study.
1396 +- aufs has two branches, upper readwrite and lower readonly.
1398 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1399 +- user invoked "chmod a+rx /au/dirA"
1400 +- then "dirA" becomes world readable?
1402 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1403 +or it may be a natively readonly filesystem. If aufs respects the lower
1404 +branch, it should not respond readdir request from other users. But user
1405 +allowed it by chmod. Should really aufs rejects showing the entries
1408 +To be honest, I don't have a best solution for this case. So I
1409 +implemented 'dirperm1' and 'nodirperm1' option in aufs1, and leave it to
1411 +When dirperm1 is specified, aufs checks only the highest one for the
1412 +directory permission, and shows the entries. Otherwise, as usual, checks
1413 +every dir existing on all branches and rejects the request.
1415 +As a side effect, dirperm1 option improves the performance of aufs
1416 +because the number of permission check is reduced.
1419 +Being Another Aufs's Readonly Branch (robr)
1420 +----------------------------------------------------------------------
1421 +Aufs1 allows aufs to be another aufs's readonly branch.
1422 +This feature was developed by a user's request. But it may not be used
1426 +Copy-up on Open (coo=)
1427 +----------------------------------------------------------------------
1428 +By default the internal copy-up is executed when it is really necessary.
1429 +It is not done when a file is opened for writing, but when write(2) is
1430 +done. Users who have many (over 100) branches want to know and analyse
1431 +when and what file is copied-up. To insert a new upper branch which
1432 +contains such files only may improve the performance of aufs.
1434 +Aufs1 implemented "coo=none | leaf | all" option.
1437 +Refresh the Opened File (refrof)
1438 +----------------------------------------------------------------------
1439 +This option is implemented in aufs1 but incomplete.
1441 +When user reads from a file, he expects to get its latest filedata
1442 +generally. If the file is removed and a new same named file is created,
1443 +the content he gets is unchanged, ie. the unlinked filedata.
1445 +Let's try case study again.
1446 +- aufs has two branches.
1448 +- "fileA" exists under /ro, but /rw.
1449 +- user opened "/au/fileA".
1450 +- he or someone else inserts a branch (/new) between /rw and /ro.
1451 + /au = /rw + /new + /ro
1452 +- the new branch has "fileA".
1453 +- user reads from the opened "fileA"
1454 +- which filedata should aufs return, from /ro or /new?
1456 +Some people says it has to be "from /ro" and it is a semantics of Unix.
1457 +The others say it should be "from /new" because the file is not removed
1458 +and it is equivalent to the case of someone else modifies the file.
1460 +Here again I don't have a best and final answer. I got an idea to
1461 +implement 'refrof' and 'norefrof' option. When 'refrof' (REFResh the
1462 +Opened File) is specified (by default), aufs returns the filedata from
1464 +Otherwise from /new.
1465 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
1466 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
1467 +++ linux/Documentation/filesystems/aufs/README 2012-07-22 19:57:03.161004529 +0200
1470 +Aufs3 -- advanced multi layered unification filesystem version 3.x
1476 +----------------------------------------
1477 +In the early days, aufs was entirely re-designed and re-implemented
1478 +Unionfs Version 1.x series. After many original ideas, approaches,
1479 +improvements and implementations, it becomes totally different from
1480 +Unionfs while keeping the basic features.
1481 +Recently, Unionfs Version 2.x series begin taking some of the same
1482 +approaches to aufs1's.
1483 +Unionfs is being developed by Professor Erez Zadok at Stony Brook
1484 +University and his team.
1486 +Aufs3 supports linux-3.0 and later.
1487 +If you want older kernel version support, try aufs2-2.6.git or
1488 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
1490 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
1491 +According to Christoph Hellwig, linux rejects all union-type filesystems
1493 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
1497 +----------------------------------------
1498 +- unite several directories into a single virtual filesystem. The member
1499 + directory is called as a branch.
1500 +- you can specify the permission flags to the branch, which are 'readonly',
1501 + 'readwrite' and 'whiteout-able.'
1502 +- by upper writable branch, internal copyup and whiteout, files/dirs on
1503 + readonly branch are modifiable logically.
1504 +- dynamic branch manipulation, add, del.
1507 +Also there are many enhancements in aufs1, such as:
1508 +- readdir(3) in userspace.
1509 +- keep inode number by external inode number table
1510 +- keep the timestamps of file/dir in internal copyup operation
1511 +- seekable directory, supporting NFS readdir.
1512 +- whiteout is hardlinked in order to reduce the consumption of inodes
1514 +- do not copyup, nor create a whiteout when it is unnecessary
1515 +- revert a single systemcall when an error occurs in aufs
1516 +- remount interface instead of ioctl
1517 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
1518 +- loopback mounted filesystem as a branch
1519 +- kernel thread for removing the dir who has a plenty of whiteouts
1520 +- support copyup sparse file (a file which has a 'hole' in it)
1521 +- default permission flags for branches
1522 +- selectable permission flags for ro branch, whether whiteout can
1525 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
1526 +- support multiple writable branches, some policies to select one
1527 + among multiple writable branches.
1528 +- a new semantics for link(2) and rename(2) to support multiple
1529 + writable branches.
1530 +- no glibc changes are required.
1531 +- pseudo hardlink (hardlink over branches)
1532 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
1533 + including NFS or remote filesystem branch.
1534 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
1537 +Currently these features are dropped temporary from aufs3.
1538 +See design/08plan.txt in detail.
1539 +- test only the highest one for the directory permission (dirperm1)
1540 +- copyup on open (coo=)
1541 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
1543 +- statistics of aufs thread (/sys/fs/aufs/stat)
1544 +- delegation mode (dlgt)
1545 + a delegation of the internal branch access to support task I/O
1546 + accounting, which also supports Linux Security Modules (LSM) mainly
1547 + for Suse AppArmor.
1548 +- intent.open/create (file open in a single lookup)
1550 +Features or just an idea in the future (see also design/*.txt),
1551 +- reorder the branch index without del/re-add.
1552 +- permanent xino files for NFSD
1553 +- an option for refreshing the opened files after add/del branches
1554 +- 'move' policy for copy-up between two writable branches, after
1555 + checking free space.
1556 +- light version, without branch manipulation. (unnecessary?)
1557 +- copyup in userspace
1558 +- inotify in userspace
1564 +----------------------------------------
1565 +There were three GIT trees for aufs3, aufs3-linux.git,
1566 +aufs3-standalone.git, and aufs-util.git. Note that there is no "3" in
1568 +While the aufs-util is always necessary, you need either of aufs3-linux
1569 +or aufs3-standalone.
1571 +The aufs3-linux tree includes the whole linux mainline GIT tree,
1572 +git://git.kernel.org/.../torvalds/linux.git.
1573 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
1574 +build aufs3 as an externel kernel module.
1576 +On the other hand, the aufs3-standalone tree has only aufs source files
1577 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
1579 +You will find GIT branches whose name is in form of "aufs3.x" where "x"
1580 +represents the linux kernel version, "linux-3.x". For instance,
1581 +"aufs3.0" is for linux-3.0. For latest "linux-3.x-rcN", use
1582 +"aufs3.x-rcN" branch.
1585 +$ git clone --reference /your/linux/git/tree \
1586 + git://aufs.git.sourceforge.net/gitroot/aufs/aufs3-linux.git \
1588 +- if you don't have linux GIT tree, then remove "--reference ..."
1589 +$ cd aufs3-linux.git
1590 +$ git checkout origin/aufs3.0
1592 +o aufs3-standalone tree
1593 +$ git clone git://aufs.git.sourceforge.net/gitroot/aufs/aufs3-standalone.git \
1594 + aufs3-standalone.git
1595 +$ cd aufs3-standalone.git
1596 +$ git checkout origin/aufs3.0
1599 +$ git clone git://aufs.git.sourceforge.net/gitroot/aufs/aufs-util.git \
1602 +$ git checkout origin/aufs3.0
1604 +Note: The 3.x-rcN branch is to be used with `rc' kernel versions ONLY.
1605 +The minor version number, 'x' in '3.x', of aufs may not always
1606 +follow the minor version number of the kernel.
1607 +Because changes in the kernel that cause the use of a new
1608 +minor version number do not always require changes to aufs-util.
1610 +Since aufs-util has its own minor version number, you may not be
1611 +able to find a GIT branch in aufs-util for your kernel's
1612 +exact minor version number.
1613 +In this case, you should git-checkout the branch for the
1614 +nearest lower number.
1616 +For (an unreleased) example:
1617 +If you are using "linux-3.10" and the "aufs3.10" branch
1618 +does not exist in aufs-util repository, then "aufs3.9", "aufs3.8"
1619 +or something numerically smaller is the branch for your kernel.
1621 +Also you can view all branches by
1625 +3. Configuration and Compilation
1626 +----------------------------------------
1627 +Make sure you have git-checkout'ed the correct branch.
1629 +For aufs3-linux tree,
1630 +- enable CONFIG_EXPERIMENTAL and CONFIG_AUFS_FS.
1631 +- set other aufs configurations if necessary.
1633 +For aufs3-standalone tree,
1634 +There are several ways to build.
1637 +- apply ./aufs3-kbuild.patch to your kernel source files.
1638 +- apply ./aufs3-base.patch too.
1639 +- apply ./aufs3-proc_map.patch too, if you want to make /proc/PID/maps (and
1640 + others including lsof(1)) show the file path on aufs instead of the
1641 + path on the branch fs.
1642 +- apply ./aufs3-standalone.patch too, if you have a plan to set
1643 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs3-standalone.patch.
1644 +- copy ./{Documentation,fs,include/linux/aufs_type.h} files to your
1645 + kernel source tree. Never copy ./include/linux/Kbuild.
1646 +- enable CONFIG_EXPERIMENTAL and CONFIG_AUFS_FS, you can select either
1648 +- and build your kernel as usual.
1649 +- install the built kernel.
1650 +- install the header files too by "make headers_install" to the
1651 + directory where you specify. By default, it is $PWD/usr.
1652 +- and reboot your system.
1655 +- module only (CONFIG_AUFS_FS=m).
1656 +- apply ./aufs3-base.patch to your kernel source files.
1657 +- apply ./aufs3-proc_map.patch too to your kernel source files,
1658 + if you want to make /proc/PID/maps (and others including lsof(1)) show
1659 + the file path on aufs instead of the path on the branch fs.
1660 +- apply ./aufs3-standalone.patch too.
1661 +- build your kernel, don't forget "make headers_install", and reboot.
1662 +- edit ./config.mk and set other aufs configurations if necessary.
1663 + Note: You should read ./fs/aufs/Kconfig carefully which describes
1664 + every aufs configurations.
1665 +- build the module by simple "make".
1666 +- you can specify ${KDIR} make variable which points to your kernel
1668 +- install the files
1669 + + run "make install" to install the aufs module, or copy the built
1670 + ./aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
1671 + + run "make headers_install" to install the aufs header file (you can
1672 + specify DESTDIR), or copty ./usr/include/linux/aufs_type.h to
1673 + /usr/include/linux or wherever you like. By default, the target
1674 + directory is $PWD/usr.
1675 +- no need to apply aufs3-kbuild.patch, nor copying source files to your
1676 + kernel source tree.
1678 +Note: The haeder file aufs_type.h is necessary to build aufs-util
1679 + as well as "make headers_install" in the kernel source tree.
1680 + headers_install is subject to be forgotten, but it is essentially
1681 + necessary, not only for building aufs-util.
1682 + You may not meet problems without headers_install in some older
1686 +- read README in aufs-util, build and install it
1687 +- note that your distribution may contain an obsoleted version of
1688 + aufs_type.h in /usr/include/linux or something. When you build aufs
1689 + utilities, make sure that your compiler refers the correct aufs header
1690 + file which is built by "make headers_install."
1691 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
1692 + then run "make install_ulib" too. And refer to the aufs manual in
1697 +----------------------------------------
1698 +At first, make sure aufs-util are installed, and please read the aufs
1699 +manual, aufs.5 in aufs-util.git tree.
1703 +$ mkdir /tmp/rw /tmp/aufs
1704 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
1706 +Here is another example. The result is equivalent.
1707 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
1709 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
1710 +# mount -o remount,append:${HOME} /tmp/aufs
1712 +Then, you can see whole tree of your home dir through /tmp/aufs. If
1713 +you modify a file under /tmp/aufs, the one on your home directory is
1714 +not affected, instead the same named file will be newly created under
1715 +/tmp/rw. And all of your modification to a file will be applied to
1716 +the one under /tmp/rw. This is called the file based Copy on Write
1718 +Aufs mount options are described in aufs.5.
1719 +If you run chroot or something and make your aufs as a root directory,
1720 +then you need to customize the shutdown script. See the aufs manual in
1723 +Additionally, there are some sample usages of aufs which are a
1724 +diskless system with network booting, and LiveCD over NFS.
1725 +See sample dir in CVS tree on SourceForge.
1729 +----------------------------------------
1730 +When you have any problems or strange behaviour in aufs, please let me
1732 +- /proc/mounts (instead of the output of mount(8))
1733 +- /sys/module/aufs/*
1734 +- /sys/fs/aufs/* (if you have them)
1735 +- /debug/aufs/* (if you have them)
1736 +- linux kernel version
1737 + if your kernel is not plain, for example modified by distributor,
1738 + the url where i can download its source is necessary too.
1739 +- aufs version which was printed at loading the module or booting the
1740 + system, instead of the date you downloaded.
1741 +- configuration (define/undefine CONFIG_AUFS_xxx)
1742 +- kernel configuration or /proc/config.gz (if you have it)
1743 +- behaviour which you think to be incorrect
1744 +- actual operation, reproducible one is better
1745 +- mailto: aufs-users at lists.sourceforge.net
1747 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
1748 +and Feature Requests) on SourceForge. Please join and write to
1752 +6. Acknowledgements
1753 +----------------------------------------
1754 +Thanks to everyone who have tried and are using aufs, whoever
1755 +have reported a bug or any feedback.
1757 +Especially donators:
1758 +Tomas Matejicek(slax.org) made a donation (much more than once).
1759 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
1760 + scripts) is making "doubling" donations.
1761 + Unfortunately I cannot list all of the donators, but I really
1763 + It ends Aug 2010, but the ordinary donation URL is still available.
1764 + <http://sourceforge.net/donate/index.php?group_id=167503>
1765 +Dai Itasaka made a donation (2007/8).
1766 +Chuck Smith made a donation (2008/4, 10 and 12).
1767 +Henk Schoneveld made a donation (2008/9).
1768 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
1769 +Francois Dupoux made a donation (2008/11).
1770 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
1771 + aufs2 GIT tree (2009/2).
1772 +William Grant made a donation (2009/3).
1773 +Patrick Lane made a donation (2009/4).
1774 +The Mail Archive (mail-archive.com) made donations (2009/5).
1775 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
1776 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
1777 +Pavel Pronskiy made a donation (2011/2).
1778 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
1779 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
1780 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12 and 2012/3).
1781 +Sam Liddicott made a donation (2011/9).
1783 +Thank you very much.
1784 +Donations are always, including future donations, very important and
1785 +helpful for me to keep on developing aufs.
1789 +----------------------------------------
1790 +If you are an experienced user, no explanation is needed. Aufs is
1791 +just a linux filesystem.
1796 +# Local variables: ;
1799 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
1800 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
1801 +++ linux/fs/aufs/aufs.h 2012-07-22 19:57:03.161004531 +0200
1804 + * Copyright (C) 2005-2012 Junjiro R. Okajima
1806 + * This program, aufs is free software; you can redistribute it and/or modify
1807 + * it under the terms of the GNU General Public License as published by
1808 + * the Free Software Foundation; either version 2 of the License, or
1809 + * (at your option) any later version.
1811 + * This program is distributed in the hope that it will be useful,
1812 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1813 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1814 + * GNU General Public License for more details.
1816 + * You should have received a copy of the GNU General Public License
1817 + * along with this program; if not, write to the Free Software
1818 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1822 + * all header files
1830 +#define AuStub(type, name, body, ...) \
1831 + static inline type name(__VA_ARGS__) { body; }
1833 +#define AuStubVoid(name, ...) \
1834 + AuStub(void, name, , __VA_ARGS__)
1835 +#define AuStubInt0(name, ...) \
1836 + AuStub(int, name, return 0, __VA_ARGS__)
1840 +#include "branch.h"
1843 +#include "dbgaufs.h"
1844 +#include "dentry.h"
1848 +#include "fstype.h"
1851 +#include "module.h"
1856 +#include "sysaufs.h"
1861 +#endif /* __KERNEL__ */
1862 +#endif /* __AUFS_H__ */
1863 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
1864 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
1865 +++ linux/fs/aufs/branch.c 2012-07-22 19:57:03.161004531 +0200
1868 + * Copyright (C) 2005-2012 Junjiro R. Okajima
1870 + * This program, aufs is free software; you can redistribute it and/or modify
1871 + * it under the terms of the GNU General Public License as published by
1872 + * the Free Software Foundation; either version 2 of the License, or
1873 + * (at your option) any later version.
1875 + * This program is distributed in the hope that it will be useful,
1876 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1877 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1878 + * GNU General Public License for more details.
1880 + * You should have received a copy of the GNU General Public License
1881 + * along with this program; if not, write to the Free Software
1882 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1886 + * branch management
1889 +#include <linux/compat.h>
1890 +#include <linux/statfs.h>
1894 + * free a single branch
1896 +static void au_br_do_free(struct au_branch *br)
1899 + struct au_wbr *wbr;
1900 + struct au_dykey **key;
1902 + au_hnotify_fin_br(br);
1904 + if (br->br_xino.xi_file)
1905 + fput(br->br_xino.xi_file);
1906 + mutex_destroy(&br->br_xino.xi_nondir_mtx);
1908 + AuDebugOn(atomic_read(&br->br_count));
1912 + for (i = 0; i < AuBrWh_Last; i++)
1913 + dput(wbr->wbr_wh[i]);
1914 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
1915 + AuRwDestroy(&wbr->wbr_wh_rwsem);
1918 + key = br->br_dykey;
1919 + for (i = 0; i < AuBrDynOp; i++, key++)
1925 + mntput(br->br_mnt);
1931 + * frees all branches
1933 +void au_br_free(struct au_sbinfo *sbinfo)
1935 + aufs_bindex_t bmax;
1936 + struct au_branch **br;
1938 + AuRwMustWriteLock(&sbinfo->si_rwsem);
1940 + bmax = sbinfo->si_bend + 1;
1941 + br = sbinfo->si_branch;
1943 + au_br_do_free(*br++);
1947 + * find the index of a branch which is specified by @br_id.
1949 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
1951 + aufs_bindex_t bindex, bend;
1953 + bend = au_sbend(sb);
1954 + for (bindex = 0; bindex <= bend; bindex++)
1955 + if (au_sbr_id(sb, bindex) == br_id)
1960 +/* ---------------------------------------------------------------------- */
1966 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
1967 + struct dentry *h_root)
1969 + if (unlikely(h_adding == h_root
1970 + || au_test_loopback_overlap(sb, h_adding)))
1972 + if (h_adding->d_sb != h_root->d_sb)
1974 + return au_test_subdir(h_adding, h_root)
1975 + || au_test_subdir(h_root, h_adding);
1979 + * returns a newly allocated branch. @new_nbranch is a number of branches
1980 + * after adding a branch.
1982 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
1985 + struct au_branch *add_branch;
1986 + struct dentry *root;
1990 + root = sb->s_root;
1991 + add_branch = kmalloc(sizeof(*add_branch), GFP_NOFS);
1992 + if (unlikely(!add_branch))
1995 + err = au_hnotify_init_br(add_branch, perm);
1996 + if (unlikely(err))
1999 + add_branch->br_wbr = NULL;
2000 + if (au_br_writable(perm)) {
2001 + /* may be freed separately at changing the branch permission */
2002 + add_branch->br_wbr = kmalloc(sizeof(*add_branch->br_wbr),
2004 + if (unlikely(!add_branch->br_wbr))
2008 + err = au_sbr_realloc(au_sbi(sb), new_nbranch);
2010 + err = au_di_realloc(au_di(root), new_nbranch);
2012 + err = au_ii_realloc(au_ii(root->d_inode), new_nbranch);
2014 + return add_branch; /* success */
2016 + kfree(add_branch->br_wbr);
2019 + au_hnotify_fin_br(add_branch);
2021 + kfree(add_branch);
2023 + return ERR_PTR(err);
2027 + * test if the branch permission is legal or not.
2029 +static int test_br(struct inode *inode, int brperm, char *path)
2033 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
2038 + pr_err("write permission for readonly mount or inode, %s\n", path);
2046 + * 0: success, the caller will add it
2047 + * plus: success, it is already unified, the caller should ignore it
2050 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
2053 + aufs_bindex_t bend, bindex;
2054 + struct dentry *root;
2055 + struct inode *inode, *h_inode;
2057 + root = sb->s_root;
2058 + bend = au_sbend(sb);
2059 + if (unlikely(bend >= 0
2060 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
2064 + pr_err("%s duplicated\n", add->pathname);
2069 + err = -ENOSPC; /* -E2BIG; */
2070 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
2071 + || AUFS_BRANCH_MAX - 1 <= bend)) {
2072 + pr_err("number of branches exceeded %s\n", add->pathname);
2077 + if (unlikely(add->bindex < 0 || bend + 1 < add->bindex)) {
2078 + pr_err("bad index %d\n", add->bindex);
2082 + inode = add->path.dentry->d_inode;
2084 + if (unlikely(!inode->i_nlink)) {
2085 + pr_err("no existence %s\n", add->pathname);
2090 + if (unlikely(inode->i_sb == sb)) {
2091 + pr_err("%s must be outside\n", add->pathname);
2095 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
2096 + pr_err("unsupported filesystem, %s (%s)\n",
2097 + add->pathname, au_sbtype(inode->i_sb));
2101 + err = test_br(add->path.dentry->d_inode, add->perm, add->pathname);
2102 + if (unlikely(err))
2106 + return 0; /* success */
2109 + for (bindex = 0; bindex <= bend; bindex++)
2110 + if (unlikely(test_overlap(sb, add->path.dentry,
2111 + au_h_dptr(root, bindex)))) {
2112 + pr_err("%s is overlapped\n", add->pathname);
2117 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
2118 + h_inode = au_h_dptr(root, 0)->d_inode;
2119 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
2120 + || !uid_eq(h_inode->i_uid, inode->i_uid)
2121 + || !gid_eq(h_inode->i_gid, inode->i_gid))
2122 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
2124 + i_uid_read(inode), i_gid_read(inode),
2125 + (inode->i_mode & S_IALLUGO),
2126 + i_uid_read(h_inode), i_gid_read(h_inode),
2127 + (h_inode->i_mode & S_IALLUGO));
2135 + * initialize or clean the whiteouts for an adding branch
2137 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
2138 + int new_perm, struct dentry *h_root)
2140 + int err, old_perm;
2141 + aufs_bindex_t bindex;
2142 + struct mutex *h_mtx;
2143 + struct au_wbr *wbr;
2144 + struct au_hinode *hdir;
2147 + old_perm = br->br_perm;
2148 + br->br_perm = new_perm;
2151 + bindex = au_br_index(sb, br->br_id);
2152 + if (0 <= bindex) {
2153 + hdir = au_hi(sb->s_root->d_inode, bindex);
2154 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
2156 + h_mtx = &h_root->d_inode->i_mutex;
2157 + mutex_lock_nested(h_mtx, AuLsc_I_PARENT);
2160 + err = au_wh_init(h_root, br, sb);
2162 + wbr_wh_write_lock(wbr);
2163 + err = au_wh_init(h_root, br, sb);
2164 + wbr_wh_write_unlock(wbr);
2167 + au_hn_imtx_unlock(hdir);
2169 + mutex_unlock(h_mtx);
2170 + br->br_perm = old_perm;
2172 + if (!err && wbr && !au_br_writable(new_perm)) {
2174 + br->br_wbr = NULL;
2180 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
2181 + int perm, struct path *path)
2184 + struct kstatfs kst;
2185 + struct au_wbr *wbr;
2186 + struct dentry *h_dentry;
2189 + au_rw_init(&wbr->wbr_wh_rwsem);
2190 + memset(wbr->wbr_wh, 0, sizeof(wbr->wbr_wh));
2191 + atomic_set(&wbr->wbr_wh_running, 0);
2192 + wbr->wbr_bytes = 0;
2195 + * a limit for rmdir/rename a dir
2196 + * cf. AUFS_MAX_NAMELEN in include/linux/aufs_type.h
2198 + err = vfs_statfs(path, &kst);
2199 + if (unlikely(err))
2202 + h_dentry = path->dentry;
2203 + if (kst.f_namelen >= NAME_MAX)
2204 + err = au_br_init_wh(sb, br, perm, h_dentry);
2206 + pr_err("%.*s(%s), unsupported namelen %ld\n",
2207 + AuDLNPair(h_dentry), au_sbtype(h_dentry->d_sb),
2214 +/* intialize a new branch */
2215 +static int au_br_init(struct au_branch *br, struct super_block *sb,
2216 + struct au_opt_add *add)
2221 + memset(&br->br_xino, 0, sizeof(br->br_xino));
2222 + mutex_init(&br->br_xino.xi_nondir_mtx);
2223 + br->br_perm = add->perm;
2224 + br->br_mnt = add->path.mnt; /* set first, mntget() later */
2225 + spin_lock_init(&br->br_dykey_lock);
2226 + memset(br->br_dykey, 0, sizeof(br->br_dykey));
2227 + atomic_set(&br->br_count, 0);
2228 + br->br_xino_upper = AUFS_XINO_TRUNC_INIT;
2229 + atomic_set(&br->br_xino_running, 0);
2230 + br->br_id = au_new_br_id(sb);
2231 + AuDebugOn(br->br_id < 0);
2233 + if (au_br_writable(add->perm)) {
2234 + err = au_wbr_init(br, sb, add->perm, &add->path);
2235 + if (unlikely(err))
2239 + if (au_opt_test(au_mntflags(sb), XINO)) {
2240 + err = au_xino_br(sb, br, add->path.dentry->d_inode->i_ino,
2241 + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1);
2242 + if (unlikely(err)) {
2243 + AuDebugOn(br->br_xino.xi_file);
2248 + sysaufs_br_init(br);
2249 + mntget(add->path.mnt);
2250 + goto out; /* success */
2253 + br->br_mnt = NULL;
2258 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
2259 + struct au_branch *br, aufs_bindex_t bend,
2260 + aufs_bindex_t amount)
2262 + struct au_branch **brp;
2264 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2266 + brp = sbinfo->si_branch + bindex;
2267 + memmove(brp + 1, brp, sizeof(*brp) * amount);
2269 + sbinfo->si_bend++;
2270 + if (unlikely(bend < 0))
2271 + sbinfo->si_bend = 0;
2274 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
2275 + aufs_bindex_t bend, aufs_bindex_t amount)
2277 + struct au_hdentry *hdp;
2279 + AuRwMustWriteLock(&dinfo->di_rwsem);
2281 + hdp = dinfo->di_hdentry + bindex;
2282 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
2283 + au_h_dentry_init(hdp);
2285 + if (unlikely(bend < 0))
2286 + dinfo->di_bstart = 0;
2289 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
2290 + aufs_bindex_t bend, aufs_bindex_t amount)
2292 + struct au_hinode *hip;
2294 + AuRwMustWriteLock(&iinfo->ii_rwsem);
2296 + hip = iinfo->ii_hinode + bindex;
2297 + memmove(hip + 1, hip, sizeof(*hip) * amount);
2298 + hip->hi_inode = NULL;
2301 + if (unlikely(bend < 0))
2302 + iinfo->ii_bstart = 0;
2305 +static void au_br_do_add(struct super_block *sb, struct dentry *h_dentry,
2306 + struct au_branch *br, aufs_bindex_t bindex)
2308 + struct dentry *root;
2309 + struct inode *root_inode;
2310 + aufs_bindex_t bend, amount;
2312 + root = sb->s_root;
2313 + root_inode = root->d_inode;
2314 + bend = au_sbend(sb);
2315 + amount = bend + 1 - bindex;
2316 + au_sbilist_lock();
2317 + au_br_do_add_brp(au_sbi(sb), bindex, br, bend, amount);
2318 + au_br_do_add_hdp(au_di(root), bindex, bend, amount);
2319 + au_br_do_add_hip(au_ii(root_inode), bindex, bend, amount);
2320 + au_set_h_dptr(root, bindex, dget(h_dentry));
2321 + au_set_h_iptr(root_inode, bindex, au_igrab(h_dentry->d_inode),
2323 + au_sbilist_unlock();
2326 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
2329 + aufs_bindex_t bend, add_bindex;
2330 + struct dentry *root, *h_dentry;
2331 + struct inode *root_inode;
2332 + struct au_branch *add_branch;
2334 + root = sb->s_root;
2335 + root_inode = root->d_inode;
2336 + IMustLock(root_inode);
2337 + err = test_add(sb, add, remount);
2338 + if (unlikely(err < 0))
2342 + goto out; /* success */
2345 + bend = au_sbend(sb);
2346 + add_branch = au_br_alloc(sb, bend + 2, add->perm);
2347 + err = PTR_ERR(add_branch);
2348 + if (IS_ERR(add_branch))
2351 + err = au_br_init(add_branch, sb, add);
2352 + if (unlikely(err)) {
2353 + au_br_do_free(add_branch);
2357 + add_bindex = add->bindex;
2358 + h_dentry = add->path.dentry;
2360 + au_br_do_add(sb, h_dentry, add_branch, add_bindex);
2362 + sysaufs_brs_del(sb, add_bindex);
2363 + au_br_do_add(sb, h_dentry, add_branch, add_bindex);
2364 + sysaufs_brs_add(sb, add_bindex);
2367 + if (!add_bindex) {
2368 + au_cpup_attr_all(root_inode, /*force*/1);
2369 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
2371 + au_add_nlink(root_inode, h_dentry->d_inode);
2374 + * this test/set prevents aufs from handling unnecesary notify events
2375 + * of xino files, in case of re-adding a writable branch which was
2376 + * once detached from aufs.
2378 + if (au_xino_brid(sb) < 0
2379 + && au_br_writable(add_branch->br_perm)
2380 + && !au_test_fs_bad_xino(h_dentry->d_sb)
2381 + && add_branch->br_xino.xi_file
2382 + && add_branch->br_xino.xi_file->f_dentry->d_parent == h_dentry)
2383 + au_xino_brid_set(sb, add_branch->br_id);
2389 +/* ---------------------------------------------------------------------- */
2395 +/* to show the line number, do not make it inlined function */
2396 +#define AuVerbose(do_info, fmt, ...) do { \
2398 + pr_info(fmt, ##__VA_ARGS__); \
2401 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t bstart,
2402 + aufs_bindex_t bend)
2404 + return (inode && !S_ISDIR(inode->i_mode)) || bstart == bend;
2407 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t bstart,
2408 + aufs_bindex_t bend)
2410 + return au_test_ibusy(dentry->d_inode, bstart, bend);
2414 + * test if the branch is deletable or not.
2416 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
2417 + unsigned int sigen, const unsigned int verbose)
2419 + int err, i, j, ndentry;
2420 + aufs_bindex_t bstart, bend;
2421 + struct au_dcsub_pages dpages;
2422 + struct au_dpage *dpage;
2425 + err = au_dpages_init(&dpages, GFP_NOFS);
2426 + if (unlikely(err))
2428 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
2429 + if (unlikely(err))
2432 + for (i = 0; !err && i < dpages.ndpage; i++) {
2433 + dpage = dpages.dpages + i;
2434 + ndentry = dpage->ndentry;
2435 + for (j = 0; !err && j < ndentry; j++) {
2436 + d = dpage->dentries[j];
2437 + AuDebugOn(!d->d_count);
2438 + if (!au_digen_test(d, sigen)) {
2439 + di_read_lock_child(d, AuLock_IR);
2440 + if (unlikely(au_dbrange_test(d))) {
2441 + di_read_unlock(d, AuLock_IR);
2445 + di_write_lock_child(d);
2446 + if (unlikely(au_dbrange_test(d))) {
2447 + di_write_unlock(d);
2450 + err = au_reval_dpath(d, sigen);
2452 + di_downgrade_lock(d, AuLock_IR);
2454 + di_write_unlock(d);
2459 + /* AuDbgDentry(d); */
2460 + bstart = au_dbstart(d);
2461 + bend = au_dbend(d);
2462 + if (bstart <= bindex
2464 + && au_h_dptr(d, bindex)
2465 + && au_test_dbusy(d, bstart, bend)) {
2467 + AuVerbose(verbose, "busy %.*s\n", AuDLNPair(d));
2470 + di_read_unlock(d, AuLock_IR);
2475 + au_dpages_free(&dpages);
2480 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
2481 + unsigned int sigen, const unsigned int verbose)
2484 + unsigned long long max, ull;
2485 + struct inode *i, **array;
2486 + aufs_bindex_t bstart, bend;
2488 + array = au_iarray_alloc(sb, &max);
2489 + err = PTR_ERR(array);
2490 + if (IS_ERR(array))
2494 + AuDbg("b%d\n", bindex);
2495 + for (ull = 0; !err && ull < max; ull++) {
2497 + if (i->i_ino == AUFS_ROOT_INO)
2500 + /* AuDbgInode(i); */
2501 + if (au_iigen(i) == sigen)
2502 + ii_read_lock_child(i);
2504 + ii_write_lock_child(i);
2505 + err = au_refresh_hinode_self(i);
2508 + ii_downgrade_lock(i);
2510 + ii_write_unlock(i);
2515 + bstart = au_ibstart(i);
2516 + bend = au_ibend(i);
2517 + if (bstart <= bindex
2519 + && au_h_iptr(i, bindex)
2520 + && au_test_ibusy(i, bstart, bend)) {
2522 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
2525 + ii_read_unlock(i);
2527 + au_iarray_free(array, max);
2533 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
2534 + const unsigned int verbose)
2537 + unsigned int sigen;
2539 + sigen = au_sigen(root->d_sb);
2540 + DiMustNoWaiters(root);
2541 + IiMustNoWaiters(root->d_inode);
2542 + di_write_unlock(root);
2543 + err = test_dentry_busy(root, bindex, sigen, verbose);
2545 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
2546 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
2551 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
2552 + const aufs_bindex_t bindex,
2553 + const aufs_bindex_t bend)
2555 + struct au_branch **brp, **p;
2557 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2559 + brp = sbinfo->si_branch + bindex;
2560 + if (bindex < bend)
2561 + memmove(brp, brp + 1, sizeof(*brp) * (bend - bindex));
2562 + sbinfo->si_branch[0 + bend] = NULL;
2563 + sbinfo->si_bend--;
2565 + p = krealloc(sbinfo->si_branch, sizeof(*p) * bend, AuGFP_SBILIST);
2567 + sbinfo->si_branch = p;
2568 + /* harmless error */
2571 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
2572 + const aufs_bindex_t bend)
2574 + struct au_hdentry *hdp, *p;
2576 + AuRwMustWriteLock(&dinfo->di_rwsem);
2578 + hdp = dinfo->di_hdentry;
2579 + if (bindex < bend)
2580 + memmove(hdp + bindex, hdp + bindex + 1,
2581 + sizeof(*hdp) * (bend - bindex));
2582 + hdp[0 + bend].hd_dentry = NULL;
2585 + p = krealloc(hdp, sizeof(*p) * bend, AuGFP_SBILIST);
2587 + dinfo->di_hdentry = p;
2588 + /* harmless error */
2591 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
2592 + const aufs_bindex_t bend)
2594 + struct au_hinode *hip, *p;
2596 + AuRwMustWriteLock(&iinfo->ii_rwsem);
2598 + hip = iinfo->ii_hinode + bindex;
2599 + if (bindex < bend)
2600 + memmove(hip, hip + 1, sizeof(*hip) * (bend - bindex));
2601 + iinfo->ii_hinode[0 + bend].hi_inode = NULL;
2602 + au_hn_init(iinfo->ii_hinode + bend);
2605 + p = krealloc(iinfo->ii_hinode, sizeof(*p) * bend, AuGFP_SBILIST);
2607 + iinfo->ii_hinode = p;
2608 + /* harmless error */
2611 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
2612 + struct au_branch *br)
2614 + aufs_bindex_t bend;
2615 + struct au_sbinfo *sbinfo;
2616 + struct dentry *root, *h_root;
2617 + struct inode *inode, *h_inode;
2618 + struct au_hinode *hinode;
2620 + SiMustWriteLock(sb);
2622 + root = sb->s_root;
2623 + inode = root->d_inode;
2624 + sbinfo = au_sbi(sb);
2625 + bend = sbinfo->si_bend;
2627 + h_root = au_h_dptr(root, bindex);
2628 + hinode = au_hi(inode, bindex);
2629 + h_inode = au_igrab(hinode->hi_inode);
2632 + au_sbilist_lock();
2633 + au_br_do_del_brp(sbinfo, bindex, bend);
2634 + au_br_do_del_hdp(au_di(root), bindex, bend);
2635 + au_br_do_del_hip(au_ii(inode), bindex, bend);
2636 + au_sbilist_unlock();
2640 + au_br_do_free(br);
2643 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
2646 + unsigned int mnt_flags;
2647 + aufs_bindex_t bindex, bend, br_id;
2648 + unsigned char do_wh, verbose;
2649 + struct au_branch *br;
2650 + struct au_wbr *wbr;
2653 + bindex = au_find_dbindex(sb->s_root, del->h_path.dentry);
2656 + goto out; /* success */
2658 + pr_err("%s no such branch\n", del->pathname);
2661 + AuDbg("bindex b%d\n", bindex);
2664 + mnt_flags = au_mntflags(sb);
2665 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
2666 + bend = au_sbend(sb);
2667 + if (unlikely(!bend)) {
2668 + AuVerbose(verbose, "no more branches left\n");
2671 + br = au_sbr(sb, bindex);
2672 + i = atomic_read(&br->br_count);
2673 + if (unlikely(i)) {
2674 + AuVerbose(verbose, "%d file(s) opened\n", i);
2679 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
2681 + /* instead of WbrWhMustWriteLock(wbr) */
2682 + SiMustWriteLock(sb);
2683 + for (i = 0; i < AuBrWh_Last; i++) {
2684 + dput(wbr->wbr_wh[i]);
2685 + wbr->wbr_wh[i] = NULL;
2689 + err = test_children_busy(sb->s_root, bindex, verbose);
2690 + if (unlikely(err)) {
2697 + br_id = br->br_id;
2699 + au_br_do_del(sb, bindex, br);
2701 + sysaufs_brs_del(sb, bindex);
2702 + au_br_do_del(sb, bindex, br);
2703 + sysaufs_brs_add(sb, bindex);
2707 + au_cpup_attr_all(sb->s_root->d_inode, /*force*/1);
2708 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
2710 + au_sub_nlink(sb->s_root->d_inode, del->h_path.dentry->d_inode);
2711 + if (au_opt_test(mnt_flags, PLINK))
2712 + au_plink_half_refresh(sb, br_id);
2714 + if (au_xino_brid(sb) == br_id)
2715 + au_xino_brid_set(sb, -1);
2716 + goto out; /* success */
2720 + rerr = au_br_init_wh(sb, br, br->br_perm, del->h_path.dentry);
2722 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
2723 + del->pathname, rerr);
2728 +/* ---------------------------------------------------------------------- */
2730 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
2733 + aufs_bindex_t bstart, bend;
2734 + struct aufs_ibusy ibusy;
2735 + struct inode *inode, *h_inode;
2738 + if (unlikely(!capable(CAP_SYS_ADMIN)))
2741 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
2743 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
2744 + if (unlikely(err)) {
2751 + si_read_lock(sb, AuLock_FLUSH);
2752 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbend(sb)))
2756 + ibusy.h_ino = 0; /* invalid */
2757 + inode = ilookup(sb, ibusy.ino);
2759 + || inode->i_ino == AUFS_ROOT_INO
2760 + || is_bad_inode(inode))
2763 + ii_read_lock_child(inode);
2764 + bstart = au_ibstart(inode);
2765 + bend = au_ibend(inode);
2766 + if (bstart <= ibusy.bindex && ibusy.bindex <= bend) {
2767 + h_inode = au_h_iptr(inode, ibusy.bindex);
2768 + if (h_inode && au_test_ibusy(inode, bstart, bend))
2769 + ibusy.h_ino = h_inode->i_ino;
2771 + ii_read_unlock(inode);
2775 + si_read_unlock(sb);
2777 + err = __put_user(ibusy.h_ino, &arg->h_ino);
2778 + if (unlikely(err)) {
2787 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
2789 + return au_ibusy(file->f_dentry->d_sb, (void __user *)arg);
2792 +#ifdef CONFIG_COMPAT
2793 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
2795 + return au_ibusy(file->f_dentry->d_sb, compat_ptr(arg));
2799 +/* ---------------------------------------------------------------------- */
2802 + * change a branch permission
2805 +static void au_warn_ima(void)
2808 + /* since it doesn't support mark_files_ro() */
2809 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
2813 +static int do_need_sigen_inc(int a, int b)
2815 + return au_br_whable(a) && !au_br_whable(b);
2818 +static int need_sigen_inc(int old, int new)
2820 + return do_need_sigen_inc(old, new)
2821 + || do_need_sigen_inc(new, old);
2824 +static unsigned long long au_farray_cb(void *a,
2825 + unsigned long long max __maybe_unused,
2828 + unsigned long long n;
2829 + struct file **p, *f;
2830 + struct super_block *sb = arg;
2834 + lg_global_lock(&files_lglock);
2835 + do_file_list_for_each_entry(sb, f) {
2838 + && !special_file(f->f_dentry->d_inode->i_mode)) {
2842 + AuDebugOn(n > max);
2844 + } while_file_list_for_each_entry;
2845 + lg_global_unlock(&files_lglock);
2850 +static struct file **au_farray_alloc(struct super_block *sb,
2851 + unsigned long long *max)
2853 + *max = atomic_long_read(&au_sbi(sb)->si_nfiles);
2854 + return au_array_alloc(max, au_farray_cb, sb);
2857 +static void au_farray_free(struct file **a, unsigned long long max)
2859 + unsigned long long ull;
2861 + for (ull = 0; ull < max; ull++)
2867 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
2870 + unsigned int mnt_flags;
2871 + unsigned long long ull, max;
2872 + aufs_bindex_t br_id;
2873 + unsigned char verbose;
2874 + struct file *file, *hf, **array;
2875 + struct inode *inode;
2876 + struct au_hfile *hfile;
2878 + mnt_flags = au_mntflags(sb);
2879 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
2881 + array = au_farray_alloc(sb, &max);
2882 + err = PTR_ERR(array);
2883 + if (IS_ERR(array))
2887 + br_id = au_sbr_id(sb, bindex);
2888 + for (ull = 0; ull < max; ull++) {
2889 + file = array[ull];
2891 + /* AuDbg("%.*s\n", AuDLNPair(file->f_dentry)); */
2892 + fi_read_lock(file);
2893 + if (unlikely(au_test_mmapped(file))) {
2895 + AuVerbose(verbose, "mmapped %.*s\n",
2896 + AuDLNPair(file->f_dentry));
2898 + FiMustNoWaiters(file);
2899 + fi_read_unlock(file);
2903 + inode = file->f_dentry->d_inode;
2904 + hfile = &au_fi(file)->fi_htop;
2905 + hf = hfile->hf_file;
2906 + if (!S_ISREG(inode->i_mode)
2907 + || !(file->f_mode & FMODE_WRITE)
2908 + || hfile->hf_br->br_id != br_id
2909 + || !(hf->f_mode & FMODE_WRITE))
2910 + array[ull] = NULL;
2916 + FiMustNoWaiters(file);
2917 + fi_read_unlock(file);
2925 + for (ull = 0; ull < max; ull++) {
2926 + file = array[ull];
2930 + /* todo: already flushed? */
2931 + /* cf. fs/super.c:mark_files_ro() */
2932 + /* fi_read_lock(file); */
2933 + hfile = &au_fi(file)->fi_htop;
2934 + hf = hfile->hf_file;
2935 + /* fi_read_unlock(file); */
2936 + spin_lock(&hf->f_lock);
2937 + hf->f_mode &= ~FMODE_WRITE;
2938 + spin_unlock(&hf->f_lock);
2939 + if (!file_check_writeable(hf)) {
2940 + file_release_write(hf);
2941 + mnt_drop_write(hf->f_vfsmnt);
2946 + au_farray_free(array, max);
2952 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
2956 + aufs_bindex_t bindex;
2958 + struct dentry *root;
2959 + struct au_branch *br;
2961 + root = sb->s_root;
2962 + bindex = au_find_dbindex(root, mod->h_root);
2965 + return 0; /* success */
2967 + pr_err("%s no such branch\n", mod->path);
2970 + AuDbg("bindex b%d\n", bindex);
2972 + err = test_br(mod->h_root->d_inode, mod->perm, mod->path);
2973 + if (unlikely(err))
2976 + br = au_sbr(sb, bindex);
2977 + if (br->br_perm == mod->perm)
2978 + return 0; /* success */
2980 + if (au_br_writable(br->br_perm)) {
2981 + /* remove whiteout base */
2982 + err = au_br_init_wh(sb, br, mod->perm, mod->h_root);
2983 + if (unlikely(err))
2986 + if (!au_br_writable(mod->perm)) {
2987 + /* rw --> ro, file might be mmapped */
2988 + DiMustNoWaiters(root);
2989 + IiMustNoWaiters(root->d_inode);
2990 + di_write_unlock(root);
2991 + err = au_br_mod_files_ro(sb, bindex);
2992 + /* aufs_write_lock() calls ..._child() */
2993 + di_write_lock_child(root);
2995 + if (unlikely(err)) {
2997 + br->br_wbr = kmalloc(sizeof(*br->br_wbr),
3000 + path.mnt = br->br_mnt;
3001 + path.dentry = mod->h_root;
3002 + rerr = au_wbr_init(br, sb, br->br_perm,
3005 + if (unlikely(rerr)) {
3006 + AuIOErr("nested error %d (%d)\n",
3008 + br->br_perm = mod->perm;
3012 + } else if (au_br_writable(mod->perm)) {
3015 + br->br_wbr = kmalloc(sizeof(*br->br_wbr), GFP_NOFS);
3017 + path.mnt = br->br_mnt;
3018 + path.dentry = mod->h_root;
3019 + err = au_wbr_init(br, sb, mod->perm, &path);
3020 + if (unlikely(err)) {
3021 + kfree(br->br_wbr);
3022 + br->br_wbr = NULL;
3028 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
3029 + br->br_perm = mod->perm;
3036 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
3037 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
3038 +++ linux/fs/aufs/branch.h 2012-07-22 19:57:03.161004531 +0200
3041 + * Copyright (C) 2005-2012 Junjiro R. Okajima
3043 + * This program, aufs is free software; you can redistribute it and/or modify
3044 + * it under the terms of the GNU General Public License as published by
3045 + * the Free Software Foundation; either version 2 of the License, or
3046 + * (at your option) any later version.
3048 + * This program is distributed in the hope that it will be useful,
3049 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3050 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3051 + * GNU General Public License for more details.
3053 + * You should have received a copy of the GNU General Public License
3054 + * along with this program; if not, write to the Free Software
3055 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3059 + * branch filesystems and xino for them
3062 +#ifndef __AUFS_BRANCH_H__
3063 +#define __AUFS_BRANCH_H__
3067 +#include <linux/mount.h>
3072 +/* ---------------------------------------------------------------------- */
3075 +struct au_xino_file {
3076 + struct file *xi_file;
3077 + struct mutex xi_nondir_mtx;
3079 + /* todo: make xino files an array to support huge inode number */
3081 +#ifdef CONFIG_DEBUG_FS
3082 + struct dentry *xi_dbgaufs;
3086 +/* members for writable branch only */
3087 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
3089 + struct au_rwsem wbr_wh_rwsem;
3090 + struct dentry *wbr_wh[AuBrWh_Last];
3091 + atomic_t wbr_wh_running;
3092 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
3093 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
3094 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
3097 + unsigned long long wbr_bytes;
3100 +/* ext2 has 3 types of operations at least, ext3 has 4 */
3101 +#define AuBrDynOp (AuDyLast * 4)
3103 +/* protected by superblock rwsem */
3105 + struct au_xino_file br_xino;
3107 + aufs_bindex_t br_id;
3110 + struct vfsmount *br_mnt;
3111 + spinlock_t br_dykey_lock;
3112 + struct au_dykey *br_dykey[AuBrDynOp];
3113 + atomic_t br_count;
3115 + struct au_wbr *br_wbr;
3117 + /* xino truncation */
3118 + blkcnt_t br_xino_upper; /* watermark in blocks */
3119 + atomic_t br_xino_running;
3121 +#ifdef CONFIG_AUFS_HFSNOTIFY
3122 + struct fsnotify_group *br_hfsn_group;
3123 + struct fsnotify_ops br_hfsn_ops;
3126 +#ifdef CONFIG_SYSFS
3127 + /* an entry under sysfs per mount-point */
3129 + struct attribute br_attr;
3133 +/* ---------------------------------------------------------------------- */
3135 +/* branch permissions and attributes */
3136 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
3137 +#define AuBrPerm_RO (1 << 1) /* readonly */
3138 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
3139 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
3141 +#define AuBrRAttr_WH (1 << 3) /* whiteout-able */
3143 +#define AuBrWAttr_NoLinkWH (1 << 4) /* un-hardlinkable whiteouts */
3145 +static inline int au_br_writable(int brperm)
3147 + return brperm & AuBrPerm_RW;
3150 +static inline int au_br_whable(int brperm)
3152 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
3155 +static inline int au_br_wh_linkable(int brperm)
3157 + return !(brperm & AuBrWAttr_NoLinkWH);
3160 +static inline int au_br_rdonly(struct au_branch *br)
3162 + return ((br->br_mnt->mnt_sb->s_flags & MS_RDONLY)
3163 + || !au_br_writable(br->br_perm))
3167 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
3169 +#ifdef CONFIG_AUFS_HNOTIFY
3170 + return !(brperm & AuBrPerm_RR);
3176 +/* ---------------------------------------------------------------------- */
3180 +void au_br_free(struct au_sbinfo *sinfo);
3181 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
3183 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
3185 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
3186 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
3187 +#ifdef CONFIG_COMPAT
3188 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
3191 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
3195 +static const loff_t au_loff_max = LLONG_MAX;
3197 +int au_xib_trunc(struct super_block *sb);
3198 +ssize_t xino_fread(au_readf_t func, struct file *file, void *buf, size_t size,
3200 +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size,
3202 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src);
3203 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent);
3204 +ino_t au_xino_new_ino(struct super_block *sb);
3205 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
3206 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
3208 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
3210 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino,
3211 + struct file *base_file, int do_test);
3212 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex);
3214 +struct au_opt_xino;
3215 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount);
3216 +void au_xino_clr(struct super_block *sb);
3217 +struct file *au_xino_def(struct super_block *sb);
3218 +int au_xino_path(struct seq_file *seq, struct file *file);
3220 +/* ---------------------------------------------------------------------- */
3222 +/* Superblock to branch */
3224 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
3226 + return au_sbr(sb, bindex)->br_id;
3230 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
3232 + return au_sbr(sb, bindex)->br_mnt;
3236 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
3238 + return au_sbr_mnt(sb, bindex)->mnt_sb;
3241 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
3243 + atomic_dec(&au_sbr(sb, bindex)->br_count);
3246 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
3248 + return au_sbr(sb, bindex)->br_perm;
3251 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
3253 + return au_br_whable(au_sbr_perm(sb, bindex));
3256 +/* ---------------------------------------------------------------------- */
3259 + * wbr_wh_read_lock, wbr_wh_write_lock
3260 + * wbr_wh_read_unlock, wbr_wh_write_unlock, wbr_wh_downgrade_lock
3262 +AuSimpleRwsemFuncs(wbr_wh, struct au_wbr *wbr, &wbr->wbr_wh_rwsem);
3264 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&wbr->wbr_wh_rwsem)
3265 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&wbr->wbr_wh_rwsem)
3266 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&wbr->wbr_wh_rwsem)
3268 +#endif /* __KERNEL__ */
3269 +#endif /* __AUFS_BRANCH_H__ */
3270 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
3271 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
3272 +++ linux/fs/aufs/conf.mk 2012-07-22 19:57:03.161004531 +0200
3275 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
3279 +AuConfStr += ${1}=${${1}}
3283 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
3285 + HNOTIFY HFSNOTIFY \
3296 +$(foreach i, ${AuConfAll}, \
3297 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
3299 +AuConfName = ${obj}/conf.str
3300 +${AuConfName}.tmp: FORCE
3301 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
3302 +${AuConfName}: ${AuConfName}.tmp
3303 + @diff -q $< $@ > /dev/null 2>&1 || { \
3304 + echo ' GEN ' $@; \
3308 +clean-files += ${AuConfName} ${AuConfName}.tmp
3309 +${obj}/sysfs.o: ${AuConfName}
3311 +-include ${srctree}/${src}/conf_priv.mk
3312 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
3313 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
3314 +++ linux/fs/aufs/cpup.c 2012-07-22 19:57:03.161004531 +0200
3317 + * Copyright (C) 2005-2012 Junjiro R. Okajima
3319 + * This program, aufs is free software; you can redistribute it and/or modify
3320 + * it under the terms of the GNU General Public License as published by
3321 + * the Free Software Foundation; either version 2 of the License, or
3322 + * (at your option) any later version.
3324 + * This program is distributed in the hope that it will be useful,
3325 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3326 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3327 + * GNU General Public License for more details.
3329 + * You should have received a copy of the GNU General Public License
3330 + * along with this program; if not, write to the Free Software
3331 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3335 + * copy-up functions, see wbr_policy.c for copy-down
3338 +#include <linux/fs_stack.h>
3339 +#include <linux/mm.h>
3342 +void au_cpup_attr_flags(struct inode *dst, struct inode *src)
3344 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
3345 + | S_NOATIME | S_NOCMTIME;
3347 + dst->i_flags |= src->i_flags & ~mask;
3348 + if (au_test_fs_notime(dst->i_sb))
3349 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
3352 +void au_cpup_attr_timesizes(struct inode *inode)
3354 + struct inode *h_inode;
3356 + h_inode = au_h_iptr(inode, au_ibstart(inode));
3357 + fsstack_copy_attr_times(inode, h_inode);
3358 + fsstack_copy_inode_size(inode, h_inode);
3361 +void au_cpup_attr_nlink(struct inode *inode, int force)
3363 + struct inode *h_inode;
3364 + struct super_block *sb;
3365 + aufs_bindex_t bindex, bend;
3368 + bindex = au_ibstart(inode);
3369 + h_inode = au_h_iptr(inode, bindex);
3371 + && !S_ISDIR(h_inode->i_mode)
3372 + && au_opt_test(au_mntflags(sb), PLINK)
3373 + && au_plink_test(inode))
3377 + * 0 can happen in revalidating.
3378 + * h_inode->i_mutex is not held, but it is harmless since once i_nlink
3379 + * reaches 0, it will never become positive.
3381 + set_nlink(inode, h_inode->i_nlink);
3384 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
3385 + * it may includes whplink directory.
3387 + if (S_ISDIR(h_inode->i_mode)) {
3388 + bend = au_ibend(inode);
3389 + for (bindex++; bindex <= bend; bindex++) {
3390 + h_inode = au_h_iptr(inode, bindex);
3392 + au_add_nlink(inode, h_inode);
3397 +void au_cpup_attr_changeable(struct inode *inode)
3399 + struct inode *h_inode;
3401 + h_inode = au_h_iptr(inode, au_ibstart(inode));
3402 + inode->i_mode = h_inode->i_mode;
3403 + inode->i_uid = h_inode->i_uid;
3404 + inode->i_gid = h_inode->i_gid;
3405 + au_cpup_attr_timesizes(inode);
3406 + au_cpup_attr_flags(inode, h_inode);
3409 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
3411 + struct au_iinfo *iinfo = au_ii(inode);
3413 + IiMustWriteLock(inode);
3415 + iinfo->ii_higen = h_inode->i_generation;
3416 + iinfo->ii_hsb1 = h_inode->i_sb;
3419 +void au_cpup_attr_all(struct inode *inode, int force)
3421 + struct inode *h_inode;
3423 + h_inode = au_h_iptr(inode, au_ibstart(inode));
3424 + au_cpup_attr_changeable(inode);
3425 + if (inode->i_nlink > 0)
3426 + au_cpup_attr_nlink(inode, force);
3427 + inode->i_rdev = h_inode->i_rdev;
3428 + inode->i_blkbits = h_inode->i_blkbits;
3429 + au_cpup_igen(inode, h_inode);
3432 +/* ---------------------------------------------------------------------- */
3434 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
3436 +/* keep the timestamps of the parent dir when cpup */
3437 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
3438 + struct path *h_path)
3440 + struct inode *h_inode;
3442 + dt->dt_dentry = dentry;
3443 + dt->dt_h_path = *h_path;
3444 + h_inode = h_path->dentry->d_inode;
3445 + dt->dt_atime = h_inode->i_atime;
3446 + dt->dt_mtime = h_inode->i_mtime;
3450 +void au_dtime_revert(struct au_dtime *dt)
3452 + struct iattr attr;
3455 + attr.ia_atime = dt->dt_atime;
3456 + attr.ia_mtime = dt->dt_mtime;
3457 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
3458 + | ATTR_ATIME | ATTR_ATIME_SET;
3460 + err = vfsub_notify_change(&dt->dt_h_path, &attr);
3461 + if (unlikely(err))
3462 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
3465 +/* ---------------------------------------------------------------------- */
3467 +static noinline_for_stack
3468 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src)
3472 + struct path h_path;
3473 + struct inode *h_isrc, *h_idst;
3475 + h_path.dentry = au_h_dptr(dst, bindex);
3476 + h_idst = h_path.dentry->d_inode;
3477 + h_path.mnt = au_sbr_mnt(dst->d_sb, bindex);
3478 + h_isrc = h_src->d_inode;
3479 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
3480 + | ATTR_ATIME | ATTR_MTIME
3481 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
3482 + ia.ia_uid = h_isrc->i_uid;
3483 + ia.ia_gid = h_isrc->i_gid;
3484 + ia.ia_atime = h_isrc->i_atime;
3485 + ia.ia_mtime = h_isrc->i_mtime;
3486 + if (h_idst->i_mode != h_isrc->i_mode
3487 + && !S_ISLNK(h_idst->i_mode)) {
3488 + ia.ia_valid |= ATTR_MODE;
3489 + ia.ia_mode = h_isrc->i_mode;
3491 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
3492 + au_cpup_attr_flags(h_idst, h_isrc);
3493 + err = vfsub_notify_change(&h_path, &ia);
3495 + /* is this nfs only? */
3496 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
3497 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
3498 + ia.ia_mode = h_isrc->i_mode;
3499 + err = vfsub_notify_change(&h_path, &ia);
3505 +/* ---------------------------------------------------------------------- */
3507 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
3508 + char *buf, unsigned long blksize)
3511 + size_t sz, rbytes, wbytes;
3512 + unsigned char all_zero;
3514 + struct mutex *h_mtx;
3515 + /* reduce stack usage */
3518 + zp = page_address(ZERO_PAGE(0));
3519 + if (unlikely(!zp))
3520 + return -ENOMEM; /* possible? */
3525 + AuDbg("len %lld\n", len);
3527 + if (len < blksize)
3531 + /* todo: signal_pending? */
3532 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
3533 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
3536 + if (unlikely(err < 0))
3540 + if (len >= rbytes && rbytes == blksize)
3541 + all_zero = !memcmp(buf, zp, rbytes);
3548 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
3550 + /* todo: signal_pending? */
3551 + if (unlikely(err == -EAGAIN || err == -EINTR))
3553 + if (unlikely(err < 0))
3562 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
3564 + if (unlikely(res < 0))
3571 + /* the last block may be a hole */
3572 + if (!err && all_zero) {
3573 + AuLabel(last hole);
3576 + if (au_test_nfs(dst->f_dentry->d_sb)) {
3577 + /* nfs requires this step to make last hole */
3578 + /* is this only nfs? */
3580 + /* todo: signal_pending? */
3581 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
3582 + } while (err == -EAGAIN || err == -EINTR);
3589 + ia->ia_size = dst->f_pos;
3590 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
3591 + ia->ia_file = dst;
3592 + h_mtx = &dst->f_dentry->d_inode->i_mutex;
3593 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
3594 + err = vfsub_notify_change(&dst->f_path, ia);
3595 + mutex_unlock(h_mtx);
3602 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
3605 + unsigned long blksize;
3606 + unsigned char do_kfree;
3610 + blksize = dst->f_dentry->d_sb->s_blocksize;
3611 + if (!blksize || PAGE_SIZE < blksize)
3612 + blksize = PAGE_SIZE;
3613 + AuDbg("blksize %lu\n", blksize);
3614 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
3616 + buf = kmalloc(blksize, GFP_NOFS);
3618 + buf = (void *)__get_free_page(GFP_NOFS);
3619 + if (unlikely(!buf))
3622 + if (len > (1 << 22))
3623 + AuDbg("copying a large file %lld\n", (long long)len);
3627 + err = au_do_copy_file(dst, src, len, buf, blksize);
3631 + free_page((unsigned long)buf);
3638 + * to support a sparse file which is opened with O_APPEND,
3639 + * we need to close the file.
3641 +static int au_cp_regular(struct dentry *dentry, aufs_bindex_t bdst,
3642 + aufs_bindex_t bsrc, loff_t len)
3645 + enum { SRC, DST };
3647 + aufs_bindex_t bindex;
3648 + unsigned int flags;
3649 + struct dentry *dentry;
3650 + struct file *file;
3651 + void *label, *label_file;
3655 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
3658 + .label_file = &&out_src
3662 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
3664 + .label = &&out_src,
3665 + .label_file = &&out_dst
3668 + struct super_block *sb;
3670 + /* bsrc branch can be ro/rw. */
3671 + sb = dentry->d_sb;
3673 + for (i = 0; i < 2; i++, f++) {
3674 + f->dentry = au_h_dptr(dentry, f->bindex);
3675 + f->file = au_h_open(dentry, f->bindex, f->flags, /*file*/NULL);
3676 + err = PTR_ERR(f->file);
3677 + if (IS_ERR(f->file))
3680 + if (unlikely(!f->file->f_op))
3681 + goto *f->label_file;
3684 + /* try stopping to update while we copyup */
3685 + IMustLock(file[SRC].dentry->d_inode);
3686 + err = au_copy_file(file[DST].file, file[SRC].file, len);
3689 + fput(file[DST].file);
3690 + au_sbr_put(sb, file[DST].bindex);
3692 + fput(file[SRC].file);
3693 + au_sbr_put(sb, file[SRC].bindex);
3698 +static int au_do_cpup_regular(struct dentry *dentry, aufs_bindex_t bdst,
3699 + aufs_bindex_t bsrc, loff_t len,
3700 + struct inode *h_dir, struct path *h_path)
3706 + l = i_size_read(au_h_iptr(dentry->d_inode, bsrc));
3707 + if (len == -1 || l < len)
3710 + err = au_cp_regular(dentry, bdst, bsrc, len);
3712 + goto out; /* success */
3714 + rerr = vfsub_unlink(h_dir, h_path, /*force*/0);
3716 + AuIOErr("failed unlinking cpup-ed %.*s(%d, %d)\n",
3717 + AuDLNPair(h_path->dentry), err, rerr);
3725 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
3726 + struct inode *h_dir)
3729 + mm_segment_t old_fs;
3736 + if (unlikely(!h_src->d_inode->i_op->readlink))
3740 + sym.k = __getname_gfp(GFP_NOFS);
3741 + if (unlikely(!sym.k))
3744 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
3745 + old_fs = get_fs();
3746 + set_fs(KERNEL_DS);
3747 + symlen = h_src->d_inode->i_op->readlink(h_src, sym.u, PATH_MAX);
3752 + sym.k[symlen] = 0;
3753 + err = vfsub_symlink(h_dir, h_path, sym.k);
3761 +/* return with the lower dst inode is locked */
3762 +static noinline_for_stack
3763 +int cpup_entry(struct dentry *dentry, aufs_bindex_t bdst,
3764 + aufs_bindex_t bsrc, loff_t len, unsigned int flags,
3765 + struct dentry *dst_parent)
3769 + unsigned int mnt_flags;
3770 + unsigned char isdir;
3771 + const unsigned char do_dt = !!au_ftest_cpup(flags, DTIME);
3772 + struct au_dtime dt;
3773 + struct path h_path;
3774 + struct dentry *h_src, *h_dst, *h_parent;
3775 + struct inode *h_inode, *h_dir;
3776 + struct super_block *sb;
3778 + /* bsrc branch can be ro/rw. */
3779 + h_src = au_h_dptr(dentry, bsrc);
3780 + h_inode = h_src->d_inode;
3781 + AuDebugOn(h_inode != au_h_iptr(dentry->d_inode, bsrc));
3783 + /* try stopping to be referenced while we are creating */
3784 + h_dst = au_h_dptr(dentry, bdst);
3785 + h_parent = h_dst->d_parent; /* dir inode is locked */
3786 + h_dir = h_parent->d_inode;
3788 + AuDebugOn(h_parent != h_dst->d_parent);
3790 + sb = dentry->d_sb;
3791 + h_path.mnt = au_sbr_mnt(sb, bdst);
3793 + h_path.dentry = h_parent;
3794 + au_dtime_store(&dt, dst_parent, &h_path);
3796 + h_path.dentry = h_dst;
3799 + mode = h_inode->i_mode;
3800 + switch (mode & S_IFMT) {
3802 + /* try stopping to update while we are referencing */
3803 + IMustLock(h_inode);
3804 + err = vfsub_create(h_dir, &h_path, mode | S_IWUSR);
3806 + err = au_do_cpup_regular
3807 + (dentry, bdst, bsrc, len,
3808 + au_h_iptr(dst_parent->d_inode, bdst), &h_path);
3812 + err = vfsub_mkdir(h_dir, &h_path, mode);
3815 + * strange behaviour from the users view,
3816 + * particularry setattr case
3818 + if (au_ibstart(dst_parent->d_inode) == bdst)
3819 + au_cpup_attr_nlink(dst_parent->d_inode,
3821 + au_cpup_attr_nlink(dentry->d_inode, /*force*/1);
3825 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
3829 + AuDebugOn(!capable(CAP_MKNOD));
3833 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
3836 + AuIOErr("Unknown inode type 0%o\n", mode);
3840 + mnt_flags = au_mntflags(sb);
3841 + if (!au_opt_test(mnt_flags, UDBA_NONE)
3843 + && au_opt_test(mnt_flags, XINO)
3844 + && h_inode->i_nlink == 1
3845 + /* todo: unnecessary? */
3846 + /* && dentry->d_inode->i_nlink == 1 */
3848 + && !au_ftest_cpup(flags, KEEPLINO))
3849 + au_xino_write(sb, bsrc, h_inode->i_ino, /*ino*/0);
3850 + /* ignore this error */
3853 + au_dtime_revert(&dt);
3858 + * copyup the @dentry from @bsrc to @bdst.
3859 + * the caller must set the both of lower dentries.
3860 + * @len is for truncating when it is -1 copyup the entire file.
3861 + * in link/rename cases, @dst_parent may be different from the real one.
3863 +static int au_cpup_single(struct dentry *dentry, aufs_bindex_t bdst,
3864 + aufs_bindex_t bsrc, loff_t len, unsigned int flags,
3865 + struct dentry *dst_parent)
3868 + aufs_bindex_t old_ibstart;
3869 + unsigned char isdir, plink;
3870 + struct au_dtime dt;
3871 + struct path h_path;
3872 + struct dentry *h_src, *h_dst, *h_parent;
3873 + struct inode *dst_inode, *h_dir, *inode;
3874 + struct super_block *sb;
3876 + AuDebugOn(bsrc <= bdst);
3878 + sb = dentry->d_sb;
3879 + h_path.mnt = au_sbr_mnt(sb, bdst);
3880 + h_dst = au_h_dptr(dentry, bdst);
3881 + h_parent = h_dst->d_parent; /* dir inode is locked */
3882 + h_dir = h_parent->d_inode;
3885 + h_src = au_h_dptr(dentry, bsrc);
3886 + inode = dentry->d_inode;
3889 + dst_parent = dget_parent(dentry);
3893 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
3894 + dst_inode = au_h_iptr(inode, bdst);
3896 + if (unlikely(!plink)) {
3898 + AuIOErr("hi%lu(i%lu) exists on b%d "
3899 + "but plink is disabled\n",
3900 + dst_inode->i_ino, inode->i_ino, bdst);
3904 + if (dst_inode->i_nlink) {
3905 + const int do_dt = au_ftest_cpup(flags, DTIME);
3907 + h_src = au_plink_lkup(inode, bdst);
3908 + err = PTR_ERR(h_src);
3909 + if (IS_ERR(h_src))
3911 + if (unlikely(!h_src->d_inode)) {
3913 + AuIOErr("i%lu exists on a upper branch "
3914 + "but not pseudo-linked\n",
3921 + h_path.dentry = h_parent;
3922 + au_dtime_store(&dt, dst_parent, &h_path);
3924 + h_path.dentry = h_dst;
3925 + err = vfsub_link(h_src, h_dir, &h_path);
3927 + au_dtime_revert(&dt);
3931 + /* todo: cpup_wh_file? */
3933 + au_update_ibrange(inode, /*do_put_zero*/1);
3936 + old_ibstart = au_ibstart(inode);
3937 + err = cpup_entry(dentry, bdst, bsrc, len, flags, dst_parent);
3938 + if (unlikely(err))
3940 + dst_inode = h_dst->d_inode;
3941 + mutex_lock_nested(&dst_inode->i_mutex, AuLsc_I_CHILD2);
3943 + err = cpup_iattr(dentry, bdst, h_src);
3944 + isdir = S_ISDIR(dst_inode->i_mode);
3946 + if (bdst < old_ibstart) {
3947 + if (S_ISREG(inode->i_mode)) {
3948 + err = au_dy_iaop(inode, bdst, dst_inode);
3949 + if (unlikely(err))
3952 + au_set_ibstart(inode, bdst);
3954 + au_set_h_iptr(inode, bdst, au_igrab(dst_inode),
3955 + au_hi_flags(inode, isdir));
3956 + mutex_unlock(&dst_inode->i_mutex);
3958 + && h_src->d_inode->i_nlink > 1
3960 + au_plink_append(inode, bdst, h_dst);
3961 + goto out; /* success */
3966 + h_path.dentry = h_parent;
3967 + mutex_unlock(&dst_inode->i_mutex);
3968 + au_dtime_store(&dt, dst_parent, &h_path);
3969 + h_path.dentry = h_dst;
3971 + rerr = vfsub_unlink(h_dir, &h_path, /*force*/0);
3973 + rerr = vfsub_rmdir(h_dir, &h_path);
3974 + au_dtime_revert(&dt);
3976 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
3985 +struct au_cpup_single_args {
3987 + struct dentry *dentry;
3988 + aufs_bindex_t bdst, bsrc;
3990 + unsigned int flags;
3991 + struct dentry *dst_parent;
3994 +static void au_call_cpup_single(void *args)
3996 + struct au_cpup_single_args *a = args;
3997 + *a->errp = au_cpup_single(a->dentry, a->bdst, a->bsrc, a->len,
3998 + a->flags, a->dst_parent);
4002 + * prevent SIGXFSZ in copy-up.
4003 + * testing CAP_MKNOD is for generic fs,
4004 + * but CAP_FSETID is for xfs only, currently.
4006 +static int au_cpup_sio_test(struct super_block *sb, umode_t mode)
4011 + if (!au_wkq_test()
4012 + && (!au_sbi(sb)->si_plink_maint_pid
4013 + || au_plink_maint(sb, AuLock_NOPLM))) {
4014 + switch (mode & S_IFMT) {
4016 + /* no condition about RLIMIT_FSIZE and the file size */
4021 + do_sio = !capable(CAP_MKNOD);
4025 + do_sio = ((mode & (S_ISUID | S_ISGID))
4026 + && !capable(CAP_FSETID));
4032 +int au_sio_cpup_single(struct dentry *dentry, aufs_bindex_t bdst,
4033 + aufs_bindex_t bsrc, loff_t len, unsigned int flags,
4034 + struct dentry *dst_parent)
4037 + struct dentry *h_dentry;
4039 + h_dentry = au_h_dptr(dentry, bsrc);
4040 + if (!au_cpup_sio_test(dentry->d_sb, h_dentry->d_inode->i_mode))
4041 + err = au_cpup_single(dentry, bdst, bsrc, len, flags,
4044 + struct au_cpup_single_args args = {
4051 + .dst_parent = dst_parent
4053 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
4054 + if (unlikely(wkq_err))
4062 + * copyup the @dentry from the first active lower branch to @bdst,
4063 + * using au_cpup_single().
4065 +static int au_cpup_simple(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
4066 + unsigned int flags)
4069 + aufs_bindex_t bsrc, bend;
4071 + bend = au_dbend(dentry);
4072 + for (bsrc = bdst + 1; bsrc <= bend; bsrc++)
4073 + if (au_h_dptr(dentry, bsrc))
4076 + err = au_lkup_neg(dentry, bdst);
4078 + err = au_cpup_single(dentry, bdst, bsrc, len, flags, NULL);
4080 + return 0; /* success */
4083 + au_set_h_dptr(dentry, bdst, NULL);
4084 + au_set_dbstart(dentry, bsrc);
4090 +struct au_cpup_simple_args {
4092 + struct dentry *dentry;
4093 + aufs_bindex_t bdst;
4095 + unsigned int flags;
4098 +static void au_call_cpup_simple(void *args)
4100 + struct au_cpup_simple_args *a = args;
4101 + *a->errp = au_cpup_simple(a->dentry, a->bdst, a->len, a->flags);
4104 +int au_sio_cpup_simple(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
4105 + unsigned int flags)
4108 + struct dentry *parent;
4109 + struct inode *h_dir;
4111 + parent = dget_parent(dentry);
4112 + h_dir = au_h_iptr(parent->d_inode, bdst);
4113 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
4114 + && !au_cpup_sio_test(dentry->d_sb, dentry->d_inode->i_mode))
4115 + err = au_cpup_simple(dentry, bdst, len, flags);
4117 + struct au_cpup_simple_args args = {
4124 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
4125 + if (unlikely(wkq_err))
4133 +/* ---------------------------------------------------------------------- */
4136 + * copyup the deleted file for writing.
4138 +static int au_do_cpup_wh(struct dentry *dentry, aufs_bindex_t bdst,
4139 + struct dentry *wh_dentry, struct file *file,
4143 + aufs_bindex_t bstart;
4144 + struct au_dinfo *dinfo;
4145 + struct dentry *h_d_dst, *h_d_start;
4146 + struct au_hdentry *hdp;
4148 + dinfo = au_di(dentry);
4149 + AuRwMustWriteLock(&dinfo->di_rwsem);
4151 + bstart = dinfo->di_bstart;
4152 + hdp = dinfo->di_hdentry;
4153 + h_d_dst = hdp[0 + bdst].hd_dentry;
4154 + dinfo->di_bstart = bdst;
4155 + hdp[0 + bdst].hd_dentry = wh_dentry;
4157 + h_d_start = hdp[0 + bstart].hd_dentry;
4158 + hdp[0 + bstart].hd_dentry = au_hf_top(file)->f_dentry;
4160 + err = au_cpup_single(dentry, bdst, bstart, len, !AuCpup_DTIME,
4161 + /*h_parent*/NULL);
4164 + err = au_reopen_nondir(file);
4165 + hdp[0 + bstart].hd_dentry = h_d_start;
4167 + hdp[0 + bdst].hd_dentry = h_d_dst;
4168 + dinfo->di_bstart = bstart;
4173 +static int au_cpup_wh(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
4174 + struct file *file)
4177 + struct au_dtime dt;
4178 + struct dentry *parent, *h_parent, *wh_dentry;
4179 + struct au_branch *br;
4180 + struct path h_path;
4182 + br = au_sbr(dentry->d_sb, bdst);
4183 + parent = dget_parent(dentry);
4184 + h_parent = au_h_dptr(parent, bdst);
4185 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
4186 + err = PTR_ERR(wh_dentry);
4187 + if (IS_ERR(wh_dentry))
4190 + h_path.dentry = h_parent;
4191 + h_path.mnt = br->br_mnt;
4192 + au_dtime_store(&dt, parent, &h_path);
4193 + err = au_do_cpup_wh(dentry, bdst, wh_dentry, file, len);
4194 + if (unlikely(err))
4198 + h_path.dentry = wh_dentry;
4199 + if (!S_ISDIR(wh_dentry->d_inode->i_mode))
4200 + err = vfsub_unlink(h_parent->d_inode, &h_path, /*force*/0);
4202 + err = vfsub_rmdir(h_parent->d_inode, &h_path);
4203 + if (unlikely(err)) {
4204 + AuIOErr("failed remove copied-up tmp file %.*s(%d)\n",
4205 + AuDLNPair(wh_dentry), err);
4208 + au_dtime_revert(&dt);
4209 + au_set_hi_wh(dentry->d_inode, bdst, wh_dentry);
4218 +struct au_cpup_wh_args {
4220 + struct dentry *dentry;
4221 + aufs_bindex_t bdst;
4223 + struct file *file;
4226 +static void au_call_cpup_wh(void *args)
4228 + struct au_cpup_wh_args *a = args;
4229 + *a->errp = au_cpup_wh(a->dentry, a->bdst, a->len, a->file);
4232 +int au_sio_cpup_wh(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
4233 + struct file *file)
4236 + struct dentry *parent, *h_orph, *h_parent, *h_dentry;
4237 + struct inode *dir, *h_dir, *h_tmpdir, *h_inode;
4238 + struct au_wbr *wbr;
4240 + parent = dget_parent(dentry);
4241 + dir = parent->d_inode;
4244 + h_dir = au_igrab(au_h_iptr(dir, bdst));
4246 + if (!h_dir->i_nlink) {
4247 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
4248 + h_orph = wbr->wbr_orph;
4250 + h_parent = dget(au_h_dptr(parent, bdst));
4251 + au_set_h_dptr(parent, bdst, dget(h_orph));
4252 + h_tmpdir = h_orph->d_inode;
4253 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
4255 + /* this temporary unlock is safe */
4257 + h_dentry = au_hf_top(file)->f_dentry;
4259 + h_dentry = au_h_dptr(dentry, au_dbstart(dentry));
4260 + h_inode = h_dentry->d_inode;
4261 + IMustLock(h_inode);
4262 + mutex_unlock(&h_inode->i_mutex);
4263 + mutex_lock_nested(&h_tmpdir->i_mutex, AuLsc_I_PARENT3);
4264 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
4265 + /* todo: au_h_open_pre()? */
4268 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
4269 + && !au_cpup_sio_test(dentry->d_sb, dentry->d_inode->i_mode))
4270 + err = au_cpup_wh(dentry, bdst, len, file);
4272 + struct au_cpup_wh_args args = {
4279 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
4280 + if (unlikely(wkq_err))
4285 + mutex_unlock(&h_tmpdir->i_mutex);
4286 + /* todo: au_h_open_post()? */
4287 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
4288 + au_set_h_dptr(parent, bdst, h_parent);
4296 +/* ---------------------------------------------------------------------- */
4299 + * generic routine for both of copy-up and copy-down.
4301 +/* cf. revalidate function in file.c */
4302 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
4303 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
4304 + struct dentry *h_parent, void *arg),
4308 + struct au_pin pin;
4309 + struct dentry *d, *parent, *h_parent, *real_parent;
4312 + parent = dget_parent(dentry);
4313 + if (IS_ROOT(parent))
4316 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
4317 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
4319 + /* do not use au_dpage */
4320 + real_parent = parent;
4323 + parent = dget_parent(dentry);
4324 + h_parent = au_h_dptr(parent, bdst);
4326 + goto out; /* success */
4328 + /* find top dir which is necessary to cpup */
4332 + parent = dget_parent(d);
4333 + di_read_lock_parent3(parent, !AuLock_IR);
4334 + h_parent = au_h_dptr(parent, bdst);
4335 + di_read_unlock(parent, !AuLock_IR);
4336 + } while (!h_parent);
4338 + if (d != real_parent)
4339 + di_write_lock_child3(d);
4341 + /* somebody else might create while we were sleeping */
4342 + if (!au_h_dptr(d, bdst) || !au_h_dptr(d, bdst)->d_inode) {
4343 + if (au_h_dptr(d, bdst))
4344 + au_update_dbstart(d);
4346 + au_pin_set_dentry(&pin, d);
4347 + err = au_do_pin(&pin);
4349 + err = cp(d, bdst, h_parent, arg);
4354 + if (d != real_parent)
4355 + di_write_unlock(d);
4356 + if (unlikely(err))
4365 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
4366 + struct dentry *h_parent __maybe_unused ,
4367 + void *arg __maybe_unused)
4369 + return au_sio_cpup_simple(dentry, bdst, -1, AuCpup_DTIME);
4372 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
4374 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
4377 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
4380 + struct dentry *parent;
4381 + struct inode *dir;
4383 + parent = dget_parent(dentry);
4384 + dir = parent->d_inode;
4386 + if (au_h_iptr(dir, bdst))
4389 + di_read_unlock(parent, AuLock_IR);
4390 + di_write_lock_parent(parent);
4391 + /* someone else might change our inode while we were sleeping */
4392 + if (!au_h_iptr(dir, bdst))
4393 + err = au_cpup_dirs(dentry, bdst);
4394 + di_downgrade_lock(parent, AuLock_IR);
4400 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
4401 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
4402 +++ linux/fs/aufs/cpup.h 2012-07-22 19:57:03.161004531 +0200
4405 + * Copyright (C) 2005-2012 Junjiro R. Okajima
4407 + * This program, aufs is free software; you can redistribute it and/or modify
4408 + * it under the terms of the GNU General Public License as published by
4409 + * the Free Software Foundation; either version 2 of the License, or
4410 + * (at your option) any later version.
4412 + * This program is distributed in the hope that it will be useful,
4413 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4414 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4415 + * GNU General Public License for more details.
4417 + * You should have received a copy of the GNU General Public License
4418 + * along with this program; if not, write to the Free Software
4419 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
4423 + * copy-up/down functions
4426 +#ifndef __AUFS_CPUP_H__
4427 +#define __AUFS_CPUP_H__
4431 +#include <linux/path.h>
4436 +void au_cpup_attr_flags(struct inode *dst, struct inode *src);
4437 +void au_cpup_attr_timesizes(struct inode *inode);
4438 +void au_cpup_attr_nlink(struct inode *inode, int force);
4439 +void au_cpup_attr_changeable(struct inode *inode);
4440 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
4441 +void au_cpup_attr_all(struct inode *inode, int force);
4443 +/* ---------------------------------------------------------------------- */
4446 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
4447 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
4449 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
4450 +#define au_fset_cpup(flags, name) \
4451 + do { (flags) |= AuCpup_##name; } while (0)
4452 +#define au_fclr_cpup(flags, name) \
4453 + do { (flags) &= ~AuCpup_##name; } while (0)
4455 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
4456 +int au_sio_cpup_single(struct dentry *dentry, aufs_bindex_t bdst,
4457 + aufs_bindex_t bsrc, loff_t len, unsigned int flags,
4458 + struct dentry *dst_parent);
4459 +int au_sio_cpup_simple(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
4460 + unsigned int flags);
4461 +int au_sio_cpup_wh(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
4462 + struct file *file);
4464 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
4465 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
4466 + struct dentry *h_parent, void *arg),
4468 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
4469 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
4471 +/* ---------------------------------------------------------------------- */
4473 +/* keep timestamps when copyup */
4475 + struct dentry *dt_dentry;
4476 + struct path dt_h_path;
4477 + struct timespec dt_atime, dt_mtime;
4479 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4480 + struct path *h_path);
4481 +void au_dtime_revert(struct au_dtime *dt);
4483 +#endif /* __KERNEL__ */
4484 +#endif /* __AUFS_CPUP_H__ */
4485 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
4486 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
4487 +++ linux/fs/aufs/dbgaufs.c 2012-07-22 19:57:03.161004531 +0200
4490 + * Copyright (C) 2005-2012 Junjiro R. Okajima
4492 + * This program, aufs is free software; you can redistribute it and/or modify
4493 + * it under the terms of the GNU General Public License as published by
4494 + * the Free Software Foundation; either version 2 of the License, or
4495 + * (at your option) any later version.
4497 + * This program is distributed in the hope that it will be useful,
4498 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4499 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4500 + * GNU General Public License for more details.
4502 + * You should have received a copy of the GNU General Public License
4503 + * along with this program; if not, write to the Free Software
4504 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
4508 + * debugfs interface
4511 +#include <linux/debugfs.h>
4514 +#ifndef CONFIG_SYSFS
4515 +#error DEBUG_FS depends upon SYSFS
4518 +static struct dentry *dbgaufs;
4519 +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH;
4521 +/* 20 is max digits length of ulong 64 */
4522 +struct dbgaufs_arg {
4528 + * common function for all XINO files
4530 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
4531 + struct file *file)
4533 + kfree(file->private_data);
4537 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt)
4541 + struct dbgaufs_arg *p;
4544 + p = kmalloc(sizeof(*p), GFP_NOFS);
4550 + file->private_data = p;
4554 + err = vfs_getattr(xf->f_vfsmnt, xf->f_dentry, &st);
4558 + (p->a, sizeof(p->a), "%ld, %llux%lu %lld\n",
4559 + (long)file_count(xf), st.blocks, st.blksize,
4560 + (long long)st.size);
4562 + p->n = snprintf(p->a, sizeof(p->a), "%llux%lu %lld\n",
4563 + st.blocks, st.blksize,
4564 + (long long)st.size);
4565 + AuDebugOn(p->n >= sizeof(p->a));
4567 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
4576 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
4577 + size_t count, loff_t *ppos)
4579 + struct dbgaufs_arg *p;
4581 + p = file->private_data;
4582 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
4585 +/* ---------------------------------------------------------------------- */
4587 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
4590 + struct au_sbinfo *sbinfo;
4591 + struct super_block *sb;
4593 + sbinfo = inode->i_private;
4594 + sb = sbinfo->si_sb;
4595 + si_noflush_read_lock(sb);
4596 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
4597 + si_read_unlock(sb);
4601 +static const struct file_operations dbgaufs_xib_fop = {
4602 + .owner = THIS_MODULE,
4603 + .open = dbgaufs_xib_open,
4604 + .release = dbgaufs_xi_release,
4605 + .read = dbgaufs_xi_read
4608 +/* ---------------------------------------------------------------------- */
4610 +#define DbgaufsXi_PREFIX "xi"
4612 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
4616 + struct au_sbinfo *sbinfo;
4617 + struct super_block *sb;
4619 + struct qstr *name;
4623 + name = &file->f_dentry->d_name;
4624 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
4625 + || memcmp(name->name, DbgaufsXi_PREFIX,
4626 + sizeof(DbgaufsXi_PREFIX) - 1)))
4628 + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
4629 + if (unlikely(err))
4632 + sbinfo = inode->i_private;
4633 + sb = sbinfo->si_sb;
4634 + si_noflush_read_lock(sb);
4635 + if (l <= au_sbend(sb)) {
4636 + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file;
4637 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1);
4640 + si_read_unlock(sb);
4646 +static const struct file_operations dbgaufs_xino_fop = {
4647 + .owner = THIS_MODULE,
4648 + .open = dbgaufs_xino_open,
4649 + .release = dbgaufs_xi_release,
4650 + .read = dbgaufs_xi_read
4653 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
4655 + aufs_bindex_t bend;
4656 + struct au_branch *br;
4657 + struct au_xino_file *xi;
4659 + if (!au_sbi(sb)->si_dbgaufs)
4662 + bend = au_sbend(sb);
4663 + for (; bindex <= bend; bindex++) {
4664 + br = au_sbr(sb, bindex);
4665 + xi = &br->br_xino;
4666 + if (xi->xi_dbgaufs) {
4667 + debugfs_remove(xi->xi_dbgaufs);
4668 + xi->xi_dbgaufs = NULL;
4673 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
4675 + struct au_sbinfo *sbinfo;
4676 + struct dentry *parent;
4677 + struct au_branch *br;
4678 + struct au_xino_file *xi;
4679 + aufs_bindex_t bend;
4680 + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
4682 + sbinfo = au_sbi(sb);
4683 + parent = sbinfo->si_dbgaufs;
4687 + bend = au_sbend(sb);
4688 + for (; bindex <= bend; bindex++) {
4689 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
4690 + br = au_sbr(sb, bindex);
4691 + xi = &br->br_xino;
4692 + AuDebugOn(xi->xi_dbgaufs);
4693 + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
4694 + sbinfo, &dbgaufs_xino_fop);
4695 + /* ignore an error */
4696 + if (unlikely(!xi->xi_dbgaufs))
4697 + AuWarn1("failed %s under debugfs\n", name);
4701 +/* ---------------------------------------------------------------------- */
4703 +#ifdef CONFIG_AUFS_EXPORT
4704 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
4707 + struct au_sbinfo *sbinfo;
4708 + struct super_block *sb;
4710 + sbinfo = inode->i_private;
4711 + sb = sbinfo->si_sb;
4712 + si_noflush_read_lock(sb);
4713 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0);
4714 + si_read_unlock(sb);
4718 +static const struct file_operations dbgaufs_xigen_fop = {
4719 + .owner = THIS_MODULE,
4720 + .open = dbgaufs_xigen_open,
4721 + .release = dbgaufs_xi_release,
4722 + .read = dbgaufs_xi_read
4725 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
4730 + * This function is a dynamic '__init' fucntion actually,
4731 + * so the tiny check for si_rwsem is unnecessary.
4733 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
4736 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
4737 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
4738 + &dbgaufs_xigen_fop);
4739 + if (sbinfo->si_dbgaufs_xigen)
4745 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
4749 +#endif /* CONFIG_AUFS_EXPORT */
4751 +/* ---------------------------------------------------------------------- */
4753 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
4756 + * This function is a dynamic '__init' fucntion actually,
4757 + * so the tiny check for si_rwsem is unnecessary.
4759 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
4761 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
4762 + sbinfo->si_dbgaufs = NULL;
4763 + kobject_put(&sbinfo->si_kobj);
4766 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
4769 + char name[SysaufsSiNameLen];
4772 + * This function is a dynamic '__init' fucntion actually,
4773 + * so the tiny check for si_rwsem is unnecessary.
4775 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
4779 + AuErr1("/debug/aufs is uninitialized\n");
4784 + sysaufs_name(sbinfo, name);
4785 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
4786 + if (unlikely(!sbinfo->si_dbgaufs))
4788 + kobject_get(&sbinfo->si_kobj);
4790 + sbinfo->si_dbgaufs_xib = debugfs_create_file
4791 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
4792 + &dbgaufs_xib_fop);
4793 + if (unlikely(!sbinfo->si_dbgaufs_xib))
4796 + err = dbgaufs_xigen_init(sbinfo);
4798 + goto out; /* success */
4801 + dbgaufs_si_fin(sbinfo);
4806 +/* ---------------------------------------------------------------------- */
4808 +void dbgaufs_fin(void)
4810 + debugfs_remove(dbgaufs);
4813 +int __init dbgaufs_init(void)
4818 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
4823 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
4824 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
4825 +++ linux/fs/aufs/dbgaufs.h 2012-07-22 19:57:03.161004531 +0200
4828 + * Copyright (C) 2005-2012 Junjiro R. Okajima
4830 + * This program, aufs is free software; you can redistribute it and/or modify
4831 + * it under the terms of the GNU General Public License as published by
4832 + * the Free Software Foundation; either version 2 of the License, or
4833 + * (at your option) any later version.
4835 + * This program is distributed in the hope that it will be useful,
4836 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4837 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4838 + * GNU General Public License for more details.
4840 + * You should have received a copy of the GNU General Public License
4841 + * along with this program; if not, write to the Free Software
4842 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
4846 + * debugfs interface
4849 +#ifndef __DBGAUFS_H__
4850 +#define __DBGAUFS_H__
4854 +struct super_block;
4857 +#ifdef CONFIG_DEBUG_FS
4859 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
4860 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
4861 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
4862 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
4863 +void dbgaufs_fin(void);
4864 +int __init dbgaufs_init(void);
4866 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
4867 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
4868 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
4869 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
4870 +AuStubVoid(dbgaufs_fin, void)
4871 +AuStubInt0(__init dbgaufs_init, void)
4872 +#endif /* CONFIG_DEBUG_FS */
4874 +#endif /* __KERNEL__ */
4875 +#endif /* __DBGAUFS_H__ */
4876 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
4877 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
4878 +++ linux/fs/aufs/dcsub.c 2012-07-22 19:57:03.161004531 +0200
4881 + * Copyright (C) 2005-2012 Junjiro R. Okajima
4883 + * This program, aufs is free software; you can redistribute it and/or modify
4884 + * it under the terms of the GNU General Public License as published by
4885 + * the Free Software Foundation; either version 2 of the License, or
4886 + * (at your option) any later version.
4888 + * This program is distributed in the hope that it will be useful,
4889 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4890 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4891 + * GNU General Public License for more details.
4893 + * You should have received a copy of the GNU General Public License
4894 + * along with this program; if not, write to the Free Software
4895 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
4899 + * sub-routines for dentry cache
4904 +static void au_dpage_free(struct au_dpage *dpage)
4907 + struct dentry **p;
4909 + p = dpage->dentries;
4910 + for (i = 0; i < dpage->ndentry; i++)
4912 + free_page((unsigned long)dpage->dentries);
4915 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
4921 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
4922 + if (unlikely(!dpages->dpages))
4925 + p = (void *)__get_free_page(gfp);
4929 + dpages->dpages[0].ndentry = 0;
4930 + dpages->dpages[0].dentries = p;
4931 + dpages->ndpage = 1;
4932 + return 0; /* success */
4935 + kfree(dpages->dpages);
4940 +void au_dpages_free(struct au_dcsub_pages *dpages)
4943 + struct au_dpage *p;
4945 + p = dpages->dpages;
4946 + for (i = 0; i < dpages->ndpage; i++)
4947 + au_dpage_free(p++);
4948 + kfree(dpages->dpages);
4951 +static int au_dpages_append(struct au_dcsub_pages *dpages,
4952 + struct dentry *dentry, gfp_t gfp)
4955 + struct au_dpage *dpage;
4958 + dpage = dpages->dpages + dpages->ndpage - 1;
4959 + sz = PAGE_SIZE / sizeof(dentry);
4960 + if (unlikely(dpage->ndentry >= sz)) {
4961 + AuLabel(new dpage);
4963 + sz = dpages->ndpage * sizeof(*dpages->dpages);
4964 + p = au_kzrealloc(dpages->dpages, sz,
4965 + sz + sizeof(*dpages->dpages), gfp);
4969 + dpages->dpages = p;
4970 + dpage = dpages->dpages + dpages->ndpage;
4971 + p = (void *)__get_free_page(gfp);
4975 + dpage->ndentry = 0;
4976 + dpage->dentries = p;
4980 + AuDebugOn(!dentry->d_count);
4981 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
4982 + return 0; /* success */
4988 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
4989 + au_dpages_test test, void *arg)
4992 + struct dentry *this_parent;
4993 + struct list_head *next;
4994 + struct super_block *sb = root->d_sb;
4997 + write_seqlock(&rename_lock);
4998 + this_parent = root;
4999 + spin_lock(&this_parent->d_lock);
5001 + next = this_parent->d_subdirs.next;
5003 + if (this_parent->d_sb == sb
5004 + && !IS_ROOT(this_parent)
5005 + && au_di(this_parent)
5006 + && this_parent->d_count
5007 + && (!test || test(this_parent, arg))) {
5008 + err = au_dpages_append(dpages, this_parent, GFP_ATOMIC);
5009 + if (unlikely(err))
5013 + while (next != &this_parent->d_subdirs) {
5014 + struct list_head *tmp = next;
5015 + struct dentry *dentry = list_entry(tmp, struct dentry,
5019 + spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED);
5020 + if (dentry->d_count) {
5021 + if (!list_empty(&dentry->d_subdirs)) {
5022 + spin_unlock(&this_parent->d_lock);
5023 + spin_release(&dentry->d_lock.dep_map, 1,
5025 + this_parent = dentry;
5026 + spin_acquire(&this_parent->d_lock.dep_map, 0, 1,
5030 + if (dentry->d_sb == sb
5032 + && (!test || test(dentry, arg)))
5033 + err = au_dpages_append(dpages, dentry,
5036 + spin_unlock(&dentry->d_lock);
5037 + if (unlikely(err))
5041 + if (this_parent != root) {
5042 + struct dentry *tmp;
5043 + struct dentry *child;
5045 + tmp = this_parent->d_parent;
5047 + spin_unlock(&this_parent->d_lock);
5048 + child = this_parent;
5049 + this_parent = tmp;
5050 + spin_lock(&this_parent->d_lock);
5051 + rcu_read_unlock();
5052 + next = child->d_u.d_child.next;
5057 + spin_unlock(&this_parent->d_lock);
5058 + write_sequnlock(&rename_lock);
5062 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
5063 + int do_include, au_dpages_test test, void *arg)
5068 + write_seqlock(&rename_lock);
5069 + spin_lock(&dentry->d_lock);
5071 + && dentry->d_count
5072 + && (!test || test(dentry, arg)))
5073 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
5074 + spin_unlock(&dentry->d_lock);
5075 + if (unlikely(err))
5079 + * vfsmount_lock is unnecessary since this is a traverse in a single
5082 + while (!IS_ROOT(dentry)) {
5083 + dentry = dentry->d_parent; /* rename_lock is locked */
5084 + spin_lock(&dentry->d_lock);
5085 + if (dentry->d_count
5086 + && (!test || test(dentry, arg)))
5087 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
5088 + spin_unlock(&dentry->d_lock);
5089 + if (unlikely(err))
5094 + write_sequnlock(&rename_lock);
5098 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
5100 + return au_di(dentry) && dentry->d_sb == arg;
5103 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
5104 + struct dentry *dentry, int do_include)
5106 + return au_dcsub_pages_rev(dpages, dentry, do_include,
5107 + au_dcsub_dpages_aufs, dentry->d_sb);
5110 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
5112 + struct path path[2] = {
5121 + return path_is_under(path + 0, path + 1);
5123 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
5124 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
5125 +++ linux/fs/aufs/dcsub.h 2012-07-22 19:57:03.161004531 +0200
5128 + * Copyright (C) 2005-2012 Junjiro R. Okajima
5130 + * This program, aufs is free software; you can redistribute it and/or modify
5131 + * it under the terms of the GNU General Public License as published by
5132 + * the Free Software Foundation; either version 2 of the License, or
5133 + * (at your option) any later version.
5135 + * This program is distributed in the hope that it will be useful,
5136 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5137 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5138 + * GNU General Public License for more details.
5140 + * You should have received a copy of the GNU General Public License
5141 + * along with this program; if not, write to the Free Software
5142 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
5146 + * sub-routines for dentry cache
5149 +#ifndef __AUFS_DCSUB_H__
5150 +#define __AUFS_DCSUB_H__
5154 +#include <linux/dcache.h>
5155 +#include <linux/fs.h>
5161 + struct dentry **dentries;
5164 +struct au_dcsub_pages {
5166 + struct au_dpage *dpages;
5169 +/* ---------------------------------------------------------------------- */
5172 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
5173 +void au_dpages_free(struct au_dcsub_pages *dpages);
5174 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
5175 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
5176 + au_dpages_test test, void *arg);
5177 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
5178 + int do_include, au_dpages_test test, void *arg);
5179 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
5180 + struct dentry *dentry, int do_include);
5181 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
5183 +/* ---------------------------------------------------------------------- */
5185 +static inline int au_d_hashed_positive(struct dentry *d)
5188 + struct inode *inode = d->d_inode;
5190 + if (unlikely(d_unhashed(d) || !inode || !inode->i_nlink))
5195 +static inline int au_d_alive(struct dentry *d)
5198 + struct inode *inode;
5201 + err = au_d_hashed_positive(d);
5203 + inode = d->d_inode;
5204 + if (unlikely(d_unlinked(d) || !inode || !inode->i_nlink))
5210 +static inline int au_alive_dir(struct dentry *d)
5213 + err = au_d_alive(d);
5214 + if (unlikely(err || IS_DEADDIR(d->d_inode)))
5219 +#endif /* __KERNEL__ */
5220 +#endif /* __AUFS_DCSUB_H__ */
5221 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
5222 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
5223 +++ linux/fs/aufs/debug.c 2012-07-22 19:57:03.161004531 +0200
5226 + * Copyright (C) 2005-2012 Junjiro R. Okajima
5228 + * This program, aufs is free software; you can redistribute it and/or modify
5229 + * it under the terms of the GNU General Public License as published by
5230 + * the Free Software Foundation; either version 2 of the License, or
5231 + * (at your option) any later version.
5233 + * This program is distributed in the hope that it will be useful,
5234 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5235 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5236 + * GNU General Public License for more details.
5238 + * You should have received a copy of the GNU General Public License
5239 + * along with this program; if not, write to the Free Software
5240 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
5244 + * debug print functions
5247 +#include <linux/vt_kern.h>
5251 +MODULE_PARM_DESC(debug, "debug print");
5252 +module_param_named(debug, aufs_debug, int, S_IRUGO | S_IWUSR | S_IWGRP);
5254 +char *au_plevel = KERN_DEBUG;
5255 +#define dpri(fmt, ...) do { \
5257 + && strcmp(au_plevel, KERN_DEBUG)) \
5258 + || au_debug_test()) \
5259 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
5262 +/* ---------------------------------------------------------------------- */
5264 +void au_dpri_whlist(struct au_nhash *whlist)
5266 + unsigned long ul, n;
5267 + struct hlist_head *head;
5268 + struct au_vdir_wh *tpos;
5269 + struct hlist_node *pos;
5271 + n = whlist->nh_num;
5272 + head = whlist->nh_head;
5273 + for (ul = 0; ul < n; ul++) {
5274 + hlist_for_each_entry(tpos, pos, head, wh_hash)
5275 + dpri("b%d, %.*s, %d\n",
5277 + tpos->wh_str.len, tpos->wh_str.name,
5278 + tpos->wh_str.len);
5283 +void au_dpri_vdir(struct au_vdir *vdir)
5286 + union au_vdir_deblk_p p;
5289 + if (!vdir || IS_ERR(vdir)) {
5290 + dpri("err %ld\n", PTR_ERR(vdir));
5294 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n",
5295 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
5296 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
5297 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
5298 + p.deblk = vdir->vd_deblk[ul];
5300 + dpri("[%lu]: %p\n", ul, o);
5304 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
5305 + struct dentry *wh)
5310 + if (!inode || IS_ERR(inode)) {
5311 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
5315 + /* the type of i_blocks depends upon CONFIG_LSF */
5316 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
5317 + && sizeof(inode->i_blocks) != sizeof(u64));
5319 + n = (void *)wh->d_name.name;
5320 + l = wh->d_name.len;
5323 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
5324 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
5326 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
5327 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
5328 + i_size_read(inode), (unsigned long long)inode->i_blocks,
5329 + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
5330 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
5331 + inode->i_state, inode->i_flags, inode->i_version,
5332 + inode->i_generation,
5333 + l ? ", wh " : "", l, n);
5337 +void au_dpri_inode(struct inode *inode)
5339 + struct au_iinfo *iinfo;
5340 + aufs_bindex_t bindex;
5343 + err = do_pri_inode(-1, inode, -1, NULL);
5344 + if (err || !au_test_aufs(inode->i_sb))
5347 + iinfo = au_ii(inode);
5350 + dpri("i-1: bstart %d, bend %d, gen %d\n",
5351 + iinfo->ii_bstart, iinfo->ii_bend, au_iigen(inode));
5352 + if (iinfo->ii_bstart < 0)
5355 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend; bindex++) {
5356 + hn = !!au_hn(iinfo->ii_hinode + bindex);
5357 + do_pri_inode(bindex, iinfo->ii_hinode[0 + bindex].hi_inode, hn,
5358 + iinfo->ii_hinode[0 + bindex].hi_whdentry);
5362 +void au_dpri_dalias(struct inode *inode)
5366 + spin_lock(&inode->i_lock);
5367 + list_for_each_entry(d, &inode->i_dentry, d_alias)
5368 + au_dpri_dentry(d);
5369 + spin_unlock(&inode->i_lock);
5372 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
5374 + struct dentry *wh = NULL;
5377 + if (!dentry || IS_ERR(dentry)) {
5378 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
5381 + /* do not call dget_parent() here */
5382 + /* note: access d_xxx without d_lock */
5383 + dpri("d%d: %.*s?/%.*s, %s, cnt %d, flags 0x%x\n",
5385 + AuDLNPair(dentry->d_parent), AuDLNPair(dentry),
5386 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
5387 + dentry->d_count, dentry->d_flags);
5389 + if (bindex >= 0 && dentry->d_inode && au_test_aufs(dentry->d_sb)) {
5390 + struct au_iinfo *iinfo = au_ii(dentry->d_inode);
5392 + hn = !!au_hn(iinfo->ii_hinode + bindex);
5393 + wh = iinfo->ii_hinode[0 + bindex].hi_whdentry;
5396 + do_pri_inode(bindex, dentry->d_inode, hn, wh);
5400 +void au_dpri_dentry(struct dentry *dentry)
5402 + struct au_dinfo *dinfo;
5403 + aufs_bindex_t bindex;
5405 + struct au_hdentry *hdp;
5407 + err = do_pri_dentry(-1, dentry);
5408 + if (err || !au_test_aufs(dentry->d_sb))
5411 + dinfo = au_di(dentry);
5414 + dpri("d-1: bstart %d, bend %d, bwh %d, bdiropq %d, gen %d\n",
5415 + dinfo->di_bstart, dinfo->di_bend,
5416 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry));
5417 + if (dinfo->di_bstart < 0)
5419 + hdp = dinfo->di_hdentry;
5420 + for (bindex = dinfo->di_bstart; bindex <= dinfo->di_bend; bindex++)
5421 + do_pri_dentry(bindex, hdp[0 + bindex].hd_dentry);
5424 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
5428 + if (!file || IS_ERR(file)) {
5429 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
5435 + && au_test_aufs(file->f_dentry->d_sb)
5437 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
5438 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
5439 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
5440 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
5441 + file->f_version, file->f_pos, a);
5442 + if (file->f_dentry)
5443 + do_pri_dentry(bindex, file->f_dentry);
5447 +void au_dpri_file(struct file *file)
5449 + struct au_finfo *finfo;
5450 + struct au_fidir *fidir;
5451 + struct au_hfile *hfile;
5452 + aufs_bindex_t bindex;
5455 + err = do_pri_file(-1, file);
5456 + if (err || !file->f_dentry || !au_test_aufs(file->f_dentry->d_sb))
5459 + finfo = au_fi(file);
5462 + if (finfo->fi_btop < 0)
5464 + fidir = finfo->fi_hdir;
5466 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
5468 + for (bindex = finfo->fi_btop;
5469 + bindex >= 0 && bindex <= fidir->fd_bbot;
5471 + hfile = fidir->fd_hfile + bindex;
5472 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
5476 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
5478 + struct vfsmount *mnt;
5479 + struct super_block *sb;
5481 + if (!br || IS_ERR(br))
5484 + if (!mnt || IS_ERR(mnt))
5487 + if (!sb || IS_ERR(sb))
5490 + dpri("s%d: {perm 0x%x, id %d, cnt %d, wbr %p}, "
5491 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
5493 + bindex, br->br_perm, br->br_id, atomic_read(&br->br_count),
5494 + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
5495 + sb->s_flags, sb->s_count,
5496 + atomic_read(&sb->s_active), !!br->br_xino.xi_file);
5500 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
5504 +void au_dpri_sb(struct super_block *sb)
5506 + struct au_sbinfo *sbinfo;
5507 + aufs_bindex_t bindex;
5509 + /* to reuduce stack size */
5511 + struct vfsmount mnt;
5512 + struct au_branch fake;
5515 + /* this function can be called from magic sysrq */
5516 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
5517 + if (unlikely(!a)) {
5518 + dpri("no memory\n");
5522 + a->mnt.mnt_sb = sb;
5523 + a->fake.br_perm = 0;
5524 + a->fake.br_mnt = &a->mnt;
5525 + a->fake.br_xino.xi_file = NULL;
5526 + atomic_set(&a->fake.br_count, 0);
5527 + smp_mb(); /* atomic_set */
5528 + err = do_pri_br(-1, &a->fake);
5530 + dpri("dev 0x%x\n", sb->s_dev);
5531 + if (err || !au_test_aufs(sb))
5534 + sbinfo = au_sbi(sb);
5537 + dpri("nw %d, gen %u, kobj %d\n",
5538 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
5539 + atomic_read(&sbinfo->si_kobj.kref.refcount));
5540 + for (bindex = 0; bindex <= sbinfo->si_bend; bindex++)
5541 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
5544 +/* ---------------------------------------------------------------------- */
5546 +void au_dbg_sleep_jiffy(int jiffy)
5549 + jiffy = schedule_timeout_uninterruptible(jiffy);
5552 +void au_dbg_iattr(struct iattr *ia)
5554 +#define AuBit(name) if (ia->ia_valid & ATTR_ ## name) \
5574 + dpri("ia_file %p\n", ia->ia_file);
5577 +/* ---------------------------------------------------------------------- */
5579 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
5581 + struct inode *h_inode, *inode = dentry->d_inode;
5582 + struct dentry *h_dentry;
5583 + aufs_bindex_t bindex, bend, bi;
5585 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
5588 + bend = au_dbend(dentry);
5589 + bi = au_ibend(inode);
5592 + bindex = au_dbstart(dentry);
5593 + bi = au_ibstart(inode);
5597 + for (; bindex <= bend; bindex++) {
5598 + h_dentry = au_h_dptr(dentry, bindex);
5601 + h_inode = au_h_iptr(inode, bindex);
5602 + if (unlikely(h_inode != h_dentry->d_inode)) {
5603 + int old = au_debug_test();
5606 + AuDbg("b%d, %s:%d\n", bindex, func, line);
5607 + AuDbgDentry(dentry);
5608 + AuDbgInode(inode);
5616 +void au_dbg_verify_dir_parent(struct dentry *dentry, unsigned int sigen)
5618 + struct dentry *parent;
5620 + parent = dget_parent(dentry);
5621 + AuDebugOn(!S_ISDIR(dentry->d_inode->i_mode));
5622 + AuDebugOn(IS_ROOT(dentry));
5623 + AuDebugOn(au_digen_test(parent, sigen));
5627 +void au_dbg_verify_nondir_parent(struct dentry *dentry, unsigned int sigen)
5629 + struct dentry *parent;
5630 + struct inode *inode;
5632 + parent = dget_parent(dentry);
5633 + inode = dentry->d_inode;
5634 + AuDebugOn(inode && S_ISDIR(dentry->d_inode->i_mode));
5635 + AuDebugOn(au_digen_test(parent, sigen));
5639 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
5642 + struct au_dcsub_pages dpages;
5643 + struct au_dpage *dpage;
5644 + struct dentry **dentries;
5646 + err = au_dpages_init(&dpages, GFP_NOFS);
5648 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
5650 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
5651 + dpage = dpages.dpages + i;
5652 + dentries = dpage->dentries;
5653 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
5654 + AuDebugOn(au_digen_test(dentries[j], sigen));
5656 + au_dpages_free(&dpages);
5659 +void au_dbg_verify_kthread(void)
5661 + if (au_wkq_test()) {
5664 + * It may be recursive, but udba=notify between two aufs mounts,
5665 + * where a single ro branch is shared, is not a problem.
5671 +/* ---------------------------------------------------------------------- */
5673 +void au_debug_sbinfo_init(struct au_sbinfo *sbinfo __maybe_unused)
5675 +#ifdef AuForceNoPlink
5676 + au_opt_clr(sbinfo->si_mntflags, PLINK);
5678 +#ifdef AuForceNoXino
5679 + au_opt_clr(sbinfo->si_mntflags, XINO);
5681 +#ifdef AuForceNoRefrof
5682 + au_opt_clr(sbinfo->si_mntflags, REFROF);
5684 +#ifdef AuForceHnotify
5685 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_HNOTIFY);
5688 + sbinfo->si_rdblk = 0;
5689 + sbinfo->si_rdhash = 0;
5693 +int __init au_debug_init(void)
5695 + aufs_bindex_t bindex;
5696 + struct au_vdir_destr destr;
5699 + AuDebugOn(bindex >= 0);
5702 + AuDebugOn(destr.len < NAME_MAX);
5704 +#ifdef CONFIG_4KSTACKS
5705 + pr_warn("CONFIG_4KSTACKS is defined.\n");
5708 +#ifdef AuForceNoBrs
5714 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
5715 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
5716 +++ linux/fs/aufs/debug.h 2012-07-22 19:57:03.161004531 +0200
5719 + * Copyright (C) 2005-2012 Junjiro R. Okajima
5721 + * This program, aufs is free software; you can redistribute it and/or modify
5722 + * it under the terms of the GNU General Public License as published by
5723 + * the Free Software Foundation; either version 2 of the License, or
5724 + * (at your option) any later version.
5726 + * This program is distributed in the hope that it will be useful,
5727 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5728 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5729 + * GNU General Public License for more details.
5731 + * You should have received a copy of the GNU General Public License
5732 + * along with this program; if not, write to the Free Software
5733 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
5737 + * debug print functions
5740 +#ifndef __AUFS_DEBUG_H__
5741 +#define __AUFS_DEBUG_H__
5745 +#include <linux/module.h>
5746 +#include <linux/kallsyms.h>
5747 +#include <linux/sysrq.h>
5749 +#ifdef CONFIG_AUFS_DEBUG
5750 +#define AuDebugOn(a) BUG_ON(a)
5752 +/* module parameter */
5753 +extern int aufs_debug;
5754 +static inline void au_debug(int n)
5760 +static inline int au_debug_test(void)
5762 + return aufs_debug;
5765 +#define AuDebugOn(a) do {} while (0)
5766 +AuStubVoid(au_debug, int n)
5767 +AuStubInt0(au_debug_test, void)
5768 +#endif /* CONFIG_AUFS_DEBUG */
5770 +/* ---------------------------------------------------------------------- */
5774 +#define AuDbg(fmt, ...) do { \
5775 + if (au_debug_test()) \
5776 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
5778 +#define AuLabel(l) AuDbg(#l "\n")
5779 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
5780 +#define AuWarn1(fmt, ...) do { \
5781 + static unsigned char _c; \
5783 + pr_warn(fmt, ##__VA_ARGS__); \
5786 +#define AuErr1(fmt, ...) do { \
5787 + static unsigned char _c; \
5789 + pr_err(fmt, ##__VA_ARGS__); \
5792 +#define AuIOErr1(fmt, ...) do { \
5793 + static unsigned char _c; \
5795 + AuIOErr(fmt, ##__VA_ARGS__); \
5798 +#define AuUnsupportMsg "This operation is not supported." \
5799 + " Please report this application to aufs-users ML."
5800 +#define AuUnsupport(fmt, ...) do { \
5801 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
5805 +#define AuTraceErr(e) do { \
5806 + if (unlikely((e) < 0)) \
5807 + AuDbg("err %d\n", (int)(e)); \
5810 +#define AuTraceErrPtr(p) do { \
5812 + AuDbg("err %ld\n", PTR_ERR(p)); \
5815 +/* dirty macros for debug print, use with "%.*s" and caution */
5816 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
5817 +#define AuDLNPair(d) AuLNPair(&(d)->d_name)
5819 +/* ---------------------------------------------------------------------- */
5824 +#ifdef CONFIG_AUFS_DEBUG
5825 +extern char *au_plevel;
5827 +void au_dpri_whlist(struct au_nhash *whlist);
5829 +void au_dpri_vdir(struct au_vdir *vdir);
5831 +void au_dpri_inode(struct inode *inode);
5832 +void au_dpri_dalias(struct inode *inode);
5833 +void au_dpri_dentry(struct dentry *dentry);
5835 +void au_dpri_file(struct file *filp);
5836 +struct super_block;
5837 +void au_dpri_sb(struct super_block *sb);
5839 +void au_dbg_sleep_jiffy(int jiffy);
5841 +void au_dbg_iattr(struct iattr *ia);
5843 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
5844 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
5845 +void au_dbg_verify_dir_parent(struct dentry *dentry, unsigned int sigen);
5846 +void au_dbg_verify_nondir_parent(struct dentry *dentry, unsigned int sigen);
5847 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
5848 +void au_dbg_verify_kthread(void);
5850 +int __init au_debug_init(void);
5851 +void au_debug_sbinfo_init(struct au_sbinfo *sbinfo);
5852 +#define AuDbgWhlist(w) do { \
5854 + au_dpri_whlist(w); \
5857 +#define AuDbgVdir(v) do { \
5859 + au_dpri_vdir(v); \
5862 +#define AuDbgInode(i) do { \
5864 + au_dpri_inode(i); \
5867 +#define AuDbgDAlias(i) do { \
5869 + au_dpri_dalias(i); \
5872 +#define AuDbgDentry(d) do { \
5874 + au_dpri_dentry(d); \
5877 +#define AuDbgFile(f) do { \
5879 + au_dpri_file(f); \
5882 +#define AuDbgSb(sb) do { \
5883 + AuDbg(#sb "\n"); \
5887 +#define AuDbgSleep(sec) do { \
5888 + AuDbg("sleep %d sec\n", sec); \
5892 +#define AuDbgSleepJiffy(jiffy) do { \
5893 + AuDbg("sleep %d jiffies\n", jiffy); \
5894 + au_dbg_sleep_jiffy(jiffy); \
5897 +#define AuDbgIAttr(ia) do { \
5898 + AuDbg("ia_valid 0x%x\n", (ia)->ia_valid); \
5899 + au_dbg_iattr(ia); \
5902 +#define AuDbgSym(addr) do { \
5903 + char sym[KSYM_SYMBOL_LEN]; \
5904 + sprint_symbol(sym, (unsigned long)addr); \
5905 + AuDbg("%s\n", sym); \
5908 +#define AuInfoSym(addr) do { \
5909 + char sym[KSYM_SYMBOL_LEN]; \
5910 + sprint_symbol(sym, (unsigned long)addr); \
5911 + AuInfo("%s\n", sym); \
5914 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
5915 +AuStubVoid(au_dbg_verify_dir_parent, struct dentry *dentry, unsigned int sigen)
5916 +AuStubVoid(au_dbg_verify_nondir_parent, struct dentry *dentry,
5917 + unsigned int sigen)
5918 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
5919 +AuStubVoid(au_dbg_verify_kthread, void)
5920 +AuStubInt0(__init au_debug_init, void)
5921 +AuStubVoid(au_debug_sbinfo_init, struct au_sbinfo *sbinfo)
5923 +#define AuDbgWhlist(w) do {} while (0)
5924 +#define AuDbgVdir(v) do {} while (0)
5925 +#define AuDbgInode(i) do {} while (0)
5926 +#define AuDbgDAlias(i) do {} while (0)
5927 +#define AuDbgDentry(d) do {} while (0)
5928 +#define AuDbgFile(f) do {} while (0)
5929 +#define AuDbgSb(sb) do {} while (0)
5930 +#define AuDbgSleep(sec) do {} while (0)
5931 +#define AuDbgSleepJiffy(jiffy) do {} while (0)
5932 +#define AuDbgIAttr(ia) do {} while (0)
5933 +#define AuDbgSym(addr) do {} while (0)
5934 +#define AuInfoSym(addr) do {} while (0)
5935 +#endif /* CONFIG_AUFS_DEBUG */
5937 +/* ---------------------------------------------------------------------- */
5939 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
5940 +int __init au_sysrq_init(void);
5941 +void au_sysrq_fin(void);
5943 +#ifdef CONFIG_HW_CONSOLE
5944 +#define au_dbg_blocked() do { \
5946 + handle_sysrq('w'); \
5949 +AuStubVoid(au_dbg_blocked, void)
5953 +AuStubInt0(__init au_sysrq_init, void)
5954 +AuStubVoid(au_sysrq_fin, void)
5955 +AuStubVoid(au_dbg_blocked, void)
5956 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
5958 +#endif /* __KERNEL__ */
5959 +#endif /* __AUFS_DEBUG_H__ */
5960 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
5961 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
5962 +++ linux/fs/aufs/dentry.c 2012-07-22 19:57:03.161004531 +0200
5965 + * Copyright (C) 2005-2012 Junjiro R. Okajima
5967 + * This program, aufs is free software; you can redistribute it and/or modify
5968 + * it under the terms of the GNU General Public License as published by
5969 + * the Free Software Foundation; either version 2 of the License, or
5970 + * (at your option) any later version.
5972 + * This program is distributed in the hope that it will be useful,
5973 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5974 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5975 + * GNU General Public License for more details.
5977 + * You should have received a copy of the GNU General Public License
5978 + * along with this program; if not, write to the Free Software
5979 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
5983 + * lookup and dentry operations
5986 +#include <linux/namei.h>
5989 +static void au_h_nd(struct nameidata *h_nd, struct nameidata *nd)
5995 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
5996 + * due to whiteout and branch permission.
5998 + h_nd->flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
5999 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
6000 + /* unnecessary? */
6001 + h_nd->intent.open.file = NULL;
6003 + memset(h_nd, 0, sizeof(*h_nd));
6006 +struct au_lkup_one_args {
6007 + struct dentry **errp;
6008 + struct qstr *name;
6009 + struct dentry *h_parent;
6010 + struct au_branch *br;
6011 + struct nameidata *nd;
6014 +struct dentry *au_lkup_one(struct qstr *name, struct dentry *h_parent,
6015 + struct au_branch *br, struct nameidata *nd)
6017 + struct dentry *h_dentry;
6019 + struct nameidata h_nd;
6021 + if (au_test_fs_null_nd(h_parent->d_sb))
6022 + return vfsub_lookup_one_len(name->name, h_parent, name->len);
6024 + au_h_nd(&h_nd, nd);
6025 + h_nd.path.dentry = h_parent;
6026 + h_nd.path.mnt = br->br_mnt;
6028 + err = vfsub_name_hash(name->name, &h_nd.last, name->len);
6029 + h_dentry = ERR_PTR(err);
6031 + path_get(&h_nd.path);
6032 + h_dentry = vfsub_lookup_hash(&h_nd);
6033 + path_put(&h_nd.path);
6036 + AuTraceErrPtr(h_dentry);
6040 +static void au_call_lkup_one(void *args)
6042 + struct au_lkup_one_args *a = args;
6043 + *a->errp = au_lkup_one(a->name, a->h_parent, a->br, a->nd);
6046 +#define AuLkup_ALLOW_NEG 1
6047 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
6048 +#define au_fset_lkup(flags, name) \
6049 + do { (flags) |= AuLkup_##name; } while (0)
6050 +#define au_fclr_lkup(flags, name) \
6051 + do { (flags) &= ~AuLkup_##name; } while (0)
6053 +struct au_do_lookup_args {
6054 + unsigned int flags;
6056 + struct nameidata *nd;
6060 + * returns positive/negative dentry, NULL or an error.
6061 + * NULL means whiteout-ed or not-found.
6063 +static struct dentry*
6064 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
6065 + aufs_bindex_t bindex, struct qstr *wh_name,
6066 + struct au_do_lookup_args *args)
6068 + struct dentry *h_dentry;
6069 + struct inode *h_inode, *inode;
6070 + struct au_branch *br;
6071 + int wh_found, opq;
6072 + unsigned char wh_able;
6073 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
6076 + br = au_sbr(dentry->d_sb, bindex);
6077 + wh_able = !!au_br_whable(br->br_perm);
6079 + wh_found = au_wh_test(h_parent, wh_name, br, /*try_sio*/0);
6080 + h_dentry = ERR_PTR(wh_found);
6083 + if (unlikely(wh_found < 0))
6086 + /* We found a whiteout */
6087 + /* au_set_dbend(dentry, bindex); */
6088 + au_set_dbwh(dentry, bindex);
6090 + return NULL; /* success */
6093 + h_dentry = au_lkup_one(&dentry->d_name, h_parent, br, args->nd);
6094 + if (IS_ERR(h_dentry))
6097 + h_inode = h_dentry->d_inode;
6101 + } else if (wh_found
6102 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
6105 + if (au_dbend(dentry) <= bindex)
6106 + au_set_dbend(dentry, bindex);
6107 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
6108 + au_set_dbstart(dentry, bindex);
6109 + au_set_h_dptr(dentry, bindex, h_dentry);
6111 + inode = dentry->d_inode;
6112 + if (!h_inode || !S_ISDIR(h_inode->i_mode) || !wh_able
6113 + || (inode && !S_ISDIR(inode->i_mode)))
6114 + goto out; /* success */
6116 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
6117 + opq = au_diropq_test(h_dentry, br);
6118 + mutex_unlock(&h_inode->i_mutex);
6120 + au_set_dbdiropq(dentry, bindex);
6121 + else if (unlikely(opq < 0)) {
6122 + au_set_h_dptr(dentry, bindex, NULL);
6123 + h_dentry = ERR_PTR(opq);
6134 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
6136 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
6137 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
6143 + * returns the number of lower positive dentries,
6144 + * otherwise an error.
6145 + * can be called at unlinking with @type is zero.
6147 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type,
6148 + struct nameidata *nd)
6150 + int npositive, err;
6151 + aufs_bindex_t bindex, btail, bdiropq;
6152 + unsigned char isdir;
6153 + struct qstr whname;
6154 + struct au_do_lookup_args args = {
6159 + const struct qstr *name = &dentry->d_name;
6160 + struct dentry *parent;
6161 + struct inode *inode;
6163 + err = au_test_shwh(dentry->d_sb, name);
6164 + if (unlikely(err))
6167 + err = au_wh_name_alloc(&whname, name);
6168 + if (unlikely(err))
6171 + inode = dentry->d_inode;
6172 + isdir = !!(inode && S_ISDIR(inode->i_mode));
6174 + au_fset_lkup(args.flags, ALLOW_NEG);
6177 + parent = dget_parent(dentry);
6178 + btail = au_dbtaildir(parent);
6179 + for (bindex = bstart; bindex <= btail; bindex++) {
6180 + struct dentry *h_parent, *h_dentry;
6181 + struct inode *h_inode, *h_dir;
6183 + h_dentry = au_h_dptr(dentry, bindex);
6185 + if (h_dentry->d_inode)
6187 + if (type != S_IFDIR)
6191 + h_parent = au_h_dptr(parent, bindex);
6194 + h_dir = h_parent->d_inode;
6195 + if (!h_dir || !S_ISDIR(h_dir->i_mode))
6198 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
6199 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname,
6201 + mutex_unlock(&h_dir->i_mutex);
6202 + err = PTR_ERR(h_dentry);
6203 + if (IS_ERR(h_dentry))
6205 + au_fclr_lkup(args.flags, ALLOW_NEG);
6207 + if (au_dbwh(dentry) >= 0)
6211 + h_inode = h_dentry->d_inode;
6216 + args.type = h_inode->i_mode & S_IFMT;
6217 + if (args.type != S_IFDIR)
6220 + /* the type of lower may be different */
6221 + bdiropq = au_dbdiropq(dentry);
6222 + if (bdiropq >= 0 && bdiropq <= bindex)
6228 + AuLabel(positive);
6229 + au_update_dbstart(dentry);
6232 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
6233 + && au_dbstart(dentry) < 0)) {
6235 + AuIOErr("both of real entry and whiteout found, %.*s, err %d\n",
6236 + AuDLNPair(dentry), err);
6241 + kfree(whname.name);
6246 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent,
6247 + struct au_branch *br)
6249 + struct dentry *dentry;
6252 + if (!au_test_h_perm_sio(parent->d_inode, MAY_EXEC))
6253 + dentry = au_lkup_one(name, parent, br, /*nd*/NULL);
6255 + struct au_lkup_one_args args = {
6258 + .h_parent = parent,
6263 + wkq_err = au_wkq_wait(au_call_lkup_one, &args);
6264 + if (unlikely(wkq_err))
6265 + dentry = ERR_PTR(wkq_err);
6272 + * lookup @dentry on @bindex which should be negative.
6274 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex)
6277 + struct dentry *parent, *h_parent, *h_dentry;
6279 + parent = dget_parent(dentry);
6280 + h_parent = au_h_dptr(parent, bindex);
6281 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent,
6282 + au_sbr(dentry->d_sb, bindex));
6283 + err = PTR_ERR(h_dentry);
6284 + if (IS_ERR(h_dentry))
6286 + if (unlikely(h_dentry->d_inode)) {
6288 + AuIOErr("%.*s should be negative on b%d.\n",
6289 + AuDLNPair(h_dentry), bindex);
6295 + if (bindex < au_dbstart(dentry))
6296 + au_set_dbstart(dentry, bindex);
6297 + if (au_dbend(dentry) < bindex)
6298 + au_set_dbend(dentry, bindex);
6299 + au_set_h_dptr(dentry, bindex, h_dentry);
6306 +/* ---------------------------------------------------------------------- */
6308 +/* subset of struct inode */
6310 + unsigned long i_ino;
6311 + /* unsigned int i_nlink; */
6317 + blkcnt_t i_blocks;
6322 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
6324 + ia->i_ino = h_inode->i_ino;
6325 + /* ia->i_nlink = h_inode->i_nlink; */
6326 + ia->i_uid = h_inode->i_uid;
6327 + ia->i_gid = h_inode->i_gid;
6328 + ia->i_version = h_inode->i_version;
6330 + ia->i_size = h_inode->i_size;
6331 + ia->i_blocks = h_inode->i_blocks;
6333 + ia->i_mode = (h_inode->i_mode & S_IFMT);
6336 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
6338 + return ia->i_ino != h_inode->i_ino
6339 + /* || ia->i_nlink != h_inode->i_nlink */
6340 + || !uid_eq(ia->i_uid, h_inode->i_uid)
6341 + || !uid_eq(ia->i_gid, h_inode->i_gid)
6342 + || ia->i_version != h_inode->i_version
6344 + || ia->i_size != h_inode->i_size
6345 + || ia->i_blocks != h_inode->i_blocks
6347 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
6350 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
6351 + struct au_branch *br)
6354 + struct au_iattr ia;
6355 + struct inode *h_inode;
6356 + struct dentry *h_d;
6357 + struct super_block *h_sb;
6360 + memset(&ia, -1, sizeof(ia));
6361 + h_sb = h_dentry->d_sb;
6362 + h_inode = h_dentry->d_inode;
6364 + au_iattr_save(&ia, h_inode);
6365 + else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
6366 + /* nfs d_revalidate may return 0 for negative dentry */
6367 + /* fuse d_revalidate always return 0 for negative dentry */
6370 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
6371 + h_d = au_lkup_one(&h_dentry->d_name, h_parent, br, /*nd*/NULL);
6372 + err = PTR_ERR(h_d);
6377 + if (unlikely(h_d != h_dentry
6378 + || h_d->d_inode != h_inode
6379 + || (h_inode && au_iattr_test(&ia, h_inode))))
6380 + err = au_busy_or_stale();
6388 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
6389 + struct dentry *h_parent, struct au_branch *br)
6394 + if (udba == AuOpt_UDBA_REVAL
6395 + && !au_test_fs_remote(h_dentry->d_sb)) {
6397 + err = (h_dentry->d_parent->d_inode != h_dir);
6398 + } else if (udba != AuOpt_UDBA_NONE)
6399 + err = au_h_verify_dentry(h_dentry, h_parent, br);
6404 +/* ---------------------------------------------------------------------- */
6406 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
6409 + aufs_bindex_t new_bindex, bindex, bend, bwh, bdiropq;
6410 + struct au_hdentry tmp, *p, *q;
6411 + struct au_dinfo *dinfo;
6412 + struct super_block *sb;
6414 + DiMustWriteLock(dentry);
6416 + sb = dentry->d_sb;
6417 + dinfo = au_di(dentry);
6418 + bend = dinfo->di_bend;
6419 + bwh = dinfo->di_bwh;
6420 + bdiropq = dinfo->di_bdiropq;
6421 + p = dinfo->di_hdentry + dinfo->di_bstart;
6422 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++, p++) {
6423 + if (!p->hd_dentry)
6426 + new_bindex = au_br_index(sb, p->hd_id);
6427 + if (new_bindex == bindex)
6430 + if (dinfo->di_bwh == bindex)
6432 + if (dinfo->di_bdiropq == bindex)
6433 + bdiropq = new_bindex;
6434 + if (new_bindex < 0) {
6436 + p->hd_dentry = NULL;
6440 + /* swap two lower dentries, and loop again */
6441 + q = dinfo->di_hdentry + new_bindex;
6445 + if (tmp.hd_dentry) {
6451 + dinfo->di_bwh = -1;
6452 + if (bwh >= 0 && bwh <= au_sbend(sb) && au_sbr_whable(sb, bwh))
6453 + dinfo->di_bwh = bwh;
6455 + dinfo->di_bdiropq = -1;
6457 + && bdiropq <= au_sbend(sb)
6458 + && au_sbr_whable(sb, bdiropq))
6459 + dinfo->di_bdiropq = bdiropq;
6462 + dinfo->di_bstart = -1;
6463 + dinfo->di_bend = -1;
6464 + bend = au_dbend(parent);
6465 + p = dinfo->di_hdentry;
6466 + for (bindex = 0; bindex <= bend; bindex++, p++)
6467 + if (p->hd_dentry) {
6468 + dinfo->di_bstart = bindex;
6472 + if (dinfo->di_bstart >= 0) {
6473 + p = dinfo->di_hdentry + bend;
6474 + for (bindex = bend; bindex >= 0; bindex--, p--)
6475 + if (p->hd_dentry) {
6476 + dinfo->di_bend = bindex;
6485 +static void au_do_hide(struct dentry *dentry)
6487 + struct inode *inode;
6489 + inode = dentry->d_inode;
6491 + if (!S_ISDIR(inode->i_mode)) {
6492 + if (inode->i_nlink && !d_unhashed(dentry))
6493 + drop_nlink(inode);
6495 + clear_nlink(inode);
6496 + /* stop next lookup */
6497 + inode->i_flags |= S_DEAD;
6499 + smp_mb(); /* necessary? */
6504 +static int au_hide_children(struct dentry *parent)
6506 + int err, i, j, ndentry;
6507 + struct au_dcsub_pages dpages;
6508 + struct au_dpage *dpage;
6509 + struct dentry *dentry;
6511 + err = au_dpages_init(&dpages, GFP_NOFS);
6512 + if (unlikely(err))
6514 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
6515 + if (unlikely(err))
6518 + /* in reverse order */
6519 + for (i = dpages.ndpage - 1; i >= 0; i--) {
6520 + dpage = dpages.dpages + i;
6521 + ndentry = dpage->ndentry;
6522 + for (j = ndentry - 1; j >= 0; j--) {
6523 + dentry = dpage->dentries[j];
6524 + if (dentry != parent)
6525 + au_do_hide(dentry);
6530 + au_dpages_free(&dpages);
6535 +static void au_hide(struct dentry *dentry)
6538 + struct inode *inode;
6540 + AuDbgDentry(dentry);
6541 + inode = dentry->d_inode;
6542 + if (inode && S_ISDIR(inode->i_mode)) {
6543 + /* shrink_dcache_parent(dentry); */
6544 + err = au_hide_children(dentry);
6545 + if (unlikely(err))
6546 + AuIOErr("%.*s, failed hiding children, ignored %d\n",
6547 + AuDLNPair(dentry), err);
6549 + au_do_hide(dentry);
6553 + * By adding a dirty branch, a cached dentry may be affected in various ways.
6555 + * a dirty branch is added
6556 + * - on the top of layers
6557 + * - in the middle of layers
6558 + * - to the bottom of layers
6560 + * on the added branch there exists
6563 + * - a same named entry
6565 + * * negative --> positive
6566 + * * positive --> positive
6567 + * - type is unchanged
6568 + * - type is changed
6570 + * * negative --> negative
6571 + * * positive --> negative (rejected by au_br_del() for non-dir case)
6574 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
6575 + struct au_dinfo *tmp)
6578 + aufs_bindex_t bindex, bend;
6580 + struct dentry *dentry;
6581 + struct inode *inode;
6584 + struct au_hdentry *hd;
6585 + struct inode *inode, *h_inode;
6586 + struct dentry *h_dentry;
6589 + AuDebugOn(dinfo->di_bstart < 0);
6590 + orig_h.dentry = dinfo->di_hdentry[dinfo->di_bstart].hd_dentry;
6591 + orig_h.inode = orig_h.dentry->d_inode;
6594 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
6595 + memset(&tmp_h, 0, sizeof(tmp_h));
6596 + if (tmp->di_bstart >= 0) {
6597 + tmp_h.dentry = tmp->di_hdentry[tmp->di_bstart].hd_dentry;
6598 + tmp_h.inode = tmp_h.dentry->d_inode;
6600 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
6603 + inode = dentry->d_inode;
6604 + if (!orig_h.inode) {
6605 + AuDbg("nagative originally\n");
6611 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
6612 + AuDebugOn(dinfo->di_bdiropq != -1);
6614 + if (!tmp_h.inode) {
6615 + AuDbg("negative --> negative\n");
6616 + /* should have only one negative lower */
6617 + if (tmp->di_bstart >= 0
6618 + && tmp->di_bstart < dinfo->di_bstart) {
6619 + AuDebugOn(tmp->di_bstart != tmp->di_bend);
6620 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
6621 + au_set_h_dptr(dentry, dinfo->di_bstart, NULL);
6622 + au_di_cp(dinfo, tmp);
6623 + hd = tmp->di_hdentry + tmp->di_bstart;
6624 + au_set_h_dptr(dentry, tmp->di_bstart,
6625 + dget(hd->hd_dentry));
6627 + au_dbg_verify_dinode(dentry);
6629 + AuDbg("negative --> positive\n");
6631 + * similar to the behaviour of creating with bypassing
6633 + * unhash it in order to force an error in the
6634 + * succeeding create operation.
6635 + * we should not set S_DEAD here.
6638 + /* au_di_swap(tmp, dinfo); */
6639 + au_dbg_verify_dinode(dentry);
6642 + AuDbg("positive originally\n");
6643 + /* inode may be NULL */
6644 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
6645 + if (!tmp_h.inode) {
6646 + AuDbg("positive --> negative\n");
6647 + /* or bypassing aufs */
6649 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_bstart)
6650 + dinfo->di_bwh = tmp->di_bwh;
6652 + err = au_refresh_hinode_self(inode);
6653 + au_dbg_verify_dinode(dentry);
6654 + } else if (orig_h.mode == tmp_h.mode) {
6655 + AuDbg("positive --> positive, same type\n");
6656 + if (!S_ISDIR(orig_h.mode)
6657 + && dinfo->di_bstart > tmp->di_bstart) {
6659 + * similar to the behaviour of removing and
6664 + err = au_refresh_hinode_self(inode);
6665 + au_dbg_verify_dinode(dentry);
6667 + /* fill empty slots */
6668 + if (dinfo->di_bstart > tmp->di_bstart)
6669 + dinfo->di_bstart = tmp->di_bstart;
6670 + if (dinfo->di_bend < tmp->di_bend)
6671 + dinfo->di_bend = tmp->di_bend;
6672 + dinfo->di_bwh = tmp->di_bwh;
6673 + dinfo->di_bdiropq = tmp->di_bdiropq;
6674 + hd = tmp->di_hdentry;
6675 + bend = dinfo->di_bend;
6676 + for (bindex = tmp->di_bstart; bindex <= bend;
6678 + if (au_h_dptr(dentry, bindex))
6680 + h_dentry = hd[bindex].hd_dentry;
6683 + h_inode = h_dentry->d_inode;
6684 + AuDebugOn(!h_inode);
6685 + AuDebugOn(orig_h.mode
6686 + != (h_inode->i_mode
6688 + au_set_h_dptr(dentry, bindex,
6691 + err = au_refresh_hinode(inode, dentry);
6692 + au_dbg_verify_dinode(dentry);
6695 + AuDbg("positive --> positive, different type\n");
6696 + /* similar to the behaviour of removing and creating */
6699 + err = au_refresh_hinode_self(inode);
6700 + au_dbg_verify_dinode(dentry);
6708 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
6711 + unsigned int sigen;
6712 + struct au_dinfo *dinfo, *tmp;
6713 + struct super_block *sb;
6714 + struct inode *inode;
6716 + DiMustWriteLock(dentry);
6717 + AuDebugOn(IS_ROOT(dentry));
6718 + AuDebugOn(!parent->d_inode);
6720 + sb = dentry->d_sb;
6721 + inode = dentry->d_inode;
6722 + sigen = au_sigen(sb);
6723 + err = au_digen_test(parent, sigen);
6724 + if (unlikely(err))
6727 + dinfo = au_di(dentry);
6728 + err = au_di_realloc(dinfo, au_sbend(sb) + 1);
6729 + if (unlikely(err))
6731 + ebrange = au_dbrange_test(dentry);
6733 + ebrange = au_do_refresh_hdentry(dentry, parent);
6735 + if (d_unhashed(dentry) || ebrange) {
6736 + AuDebugOn(au_dbstart(dentry) < 0 && au_dbend(dentry) >= 0);
6738 + err = au_refresh_hinode_self(inode);
6739 + au_dbg_verify_dinode(dentry);
6741 + goto out_dgen; /* success */
6745 + /* temporary dinfo */
6746 + AuDbgDentry(dentry);
6748 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
6749 + if (unlikely(!tmp))
6751 + au_di_swap(tmp, dinfo);
6752 + /* returns the number of positive dentries */
6754 + * if current working dir is removed, it returns an error.
6755 + * but the dentry is legal.
6757 + err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0, /*nd*/NULL);
6758 + AuDbgDentry(dentry);
6759 + au_di_swap(tmp, dinfo);
6760 + if (err == -ENOENT)
6763 + /* compare/refresh by dinfo */
6764 + AuDbgDentry(dentry);
6765 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
6766 + au_dbg_verify_dinode(dentry);
6769 + au_rw_write_unlock(&tmp->di_rwsem);
6771 + if (unlikely(err))
6775 + au_update_digen(dentry);
6777 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
6778 + AuIOErr("failed refreshing %.*s, %d\n",
6779 + AuDLNPair(dentry), err);
6780 + AuDbgDentry(dentry);
6786 +static noinline_for_stack
6787 +int au_do_h_d_reval(struct dentry *h_dentry, struct nameidata *nd,
6788 + struct dentry *dentry, aufs_bindex_t bindex)
6791 + int (*reval)(struct dentry *, struct nameidata *);
6794 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
6796 + reval = h_dentry->d_op->d_revalidate;
6798 + AuDbg("b%d\n", bindex);
6799 + if (au_test_fs_null_nd(h_dentry->d_sb))
6800 + /* it may return tri-state */
6801 + valid = reval(h_dentry, NULL);
6803 + struct nameidata h_nd;
6805 + struct dentry *parent;
6807 + au_h_nd(&h_nd, nd);
6808 + parent = nd->path.dentry;
6809 + locked = (nd && nd->path.dentry != dentry);
6811 + di_read_lock_parent(parent, AuLock_IR);
6812 + BUG_ON(bindex > au_dbend(parent));
6813 + h_nd.path.dentry = au_h_dptr(parent, bindex);
6814 + BUG_ON(!h_nd.path.dentry);
6815 + h_nd.path.mnt = au_sbr(parent->d_sb, bindex)->br_mnt;
6816 + path_get(&h_nd.path);
6817 + valid = reval(h_dentry, &h_nd);
6818 + path_put(&h_nd.path);
6820 + di_read_unlock(parent, AuLock_IR);
6823 + if (unlikely(valid < 0))
6833 +/* todo: remove this */
6834 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
6835 + struct nameidata *nd, int do_udba)
6838 + umode_t mode, h_mode;
6839 + aufs_bindex_t bindex, btail, bstart, ibs, ibe;
6840 + unsigned char plus, unhashed, is_root, h_plus;
6841 + struct inode *h_inode, *h_cached_inode;
6842 + struct dentry *h_dentry;
6843 + struct qstr *name, *h_name;
6850 + unhashed = !!d_unhashed(dentry);
6851 + is_root = !!IS_ROOT(dentry);
6852 + name = &dentry->d_name;
6855 + * Theoretically, REVAL test should be unnecessary in case of
6857 + * But {fs,i}notify doesn't fire some necessary events,
6858 + * IN_ATTRIB for atime/nlink/pageio
6859 + * IN_DELETE for NFS dentry
6860 + * Let's do REVAL test too.
6862 + if (do_udba && inode) {
6863 + mode = (inode->i_mode & S_IFMT);
6864 + plus = (inode->i_nlink > 0);
6865 + ibs = au_ibstart(inode);
6866 + ibe = au_ibend(inode);
6869 + bstart = au_dbstart(dentry);
6871 + if (inode && S_ISDIR(inode->i_mode))
6872 + btail = au_dbtaildir(dentry);
6873 + for (bindex = bstart; bindex <= btail; bindex++) {
6874 + h_dentry = au_h_dptr(dentry, bindex);
6878 + AuDbg("b%d, %.*s\n", bindex, AuDLNPair(h_dentry));
6879 + spin_lock(&h_dentry->d_lock);
6880 + h_name = &h_dentry->d_name;
6881 + if (unlikely(do_udba
6883 + && (unhashed != !!d_unhashed(h_dentry)
6884 + || name->len != h_name->len
6885 + || memcmp(name->name, h_name->name, name->len))
6887 + AuDbg("unhash 0x%x 0x%x, %.*s %.*s\n",
6888 + unhashed, d_unhashed(h_dentry),
6889 + AuDLNPair(dentry), AuDLNPair(h_dentry));
6890 + spin_unlock(&h_dentry->d_lock);
6893 + spin_unlock(&h_dentry->d_lock);
6895 + err = au_do_h_d_reval(h_dentry, nd, dentry, bindex);
6896 + if (unlikely(err))
6897 + /* do not goto err, to keep the errno */
6900 + /* todo: plink too? */
6905 + h_inode = h_dentry->d_inode;
6906 + if (unlikely(!!inode != !!h_inode))
6911 + h_cached_inode = h_inode;
6913 + h_mode = (h_inode->i_mode & S_IFMT);
6914 + h_plus = (h_inode->i_nlink > 0);
6916 + if (inode && ibs <= bindex && bindex <= ibe)
6917 + h_cached_inode = au_h_iptr(inode, bindex);
6919 + if (unlikely(plus != h_plus
6921 + || h_cached_inode != h_inode))
6933 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
6934 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
6937 + struct dentry *parent;
6939 + if (!au_digen_test(dentry, sigen))
6942 + parent = dget_parent(dentry);
6943 + di_read_lock_parent(parent, AuLock_IR);
6944 + AuDebugOn(au_digen_test(parent, sigen));
6945 + au_dbg_verify_gen(parent, sigen);
6946 + err = au_refresh_dentry(dentry, parent);
6947 + di_read_unlock(parent, AuLock_IR);
6953 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
6956 + struct dentry *d, *parent;
6957 + struct inode *inode;
6959 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
6960 + return simple_reval_dpath(dentry, sigen);
6962 + /* slow loop, keep it simple and stupid */
6963 + /* cf: au_cpup_dirs() */
6966 + while (au_digen_test(dentry, sigen)) {
6970 + parent = dget_parent(d);
6971 + if (!au_digen_test(parent, sigen))
6976 + inode = d->d_inode;
6978 + di_write_lock_child2(d);
6980 + /* someone might update our dentry while we were sleeping */
6981 + if (au_digen_test(d, sigen)) {
6983 + * todo: consolidate with simple_reval_dpath(),
6984 + * do_refresh() and au_reval_for_attr().
6986 + di_read_lock_parent(parent, AuLock_IR);
6987 + err = au_refresh_dentry(d, parent);
6988 + di_read_unlock(parent, AuLock_IR);
6992 + di_write_unlock(d);
6994 + if (unlikely(err))
7002 + * if valid returns 1, otherwise 0.
7004 +static int aufs_d_revalidate(struct dentry *dentry, struct nameidata *nd)
7007 + unsigned int sigen;
7008 + unsigned char do_udba;
7009 + struct super_block *sb;
7010 + struct inode *inode;
7012 + /* todo: support rcu-walk? */
7013 + if (nd && (nd->flags & LOOKUP_RCU))
7017 + if (unlikely(!au_di(dentry)))
7020 + inode = dentry->d_inode;
7021 + if (inode && is_bad_inode(inode))
7025 + sb = dentry->d_sb;
7028 + * i_mutex of parent dir may be held,
7029 + * but we should not return 'invalid' due to busy.
7031 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
7032 + if (unlikely(err)) {
7037 + if (unlikely(au_dbrange_test(dentry))) {
7043 + sigen = au_sigen(sb);
7044 + if (au_digen_test(dentry, sigen)) {
7045 + AuDebugOn(IS_ROOT(dentry));
7046 + err = au_reval_dpath(dentry, sigen);
7047 + if (unlikely(err)) {
7052 + di_downgrade_lock(dentry, AuLock_IR);
7055 + if (inode && (IS_DEADDIR(inode) || !inode->i_nlink))
7058 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
7059 + if (do_udba && inode) {
7060 + aufs_bindex_t bstart = au_ibstart(inode);
7061 + struct inode *h_inode;
7063 + if (bstart >= 0) {
7064 + h_inode = au_h_iptr(inode, bstart);
7065 + if (h_inode && au_test_higen(inode, h_inode))
7070 + err = h_d_revalidate(dentry, inode, nd, do_udba);
7071 + if (unlikely(!err && do_udba && au_dbstart(dentry) < 0)) {
7073 + AuDbg("both of real entry and whiteout found, %.*s, err %d\n",
7074 + AuDLNPair(dentry), err);
7079 + di_downgrade_lock(dentry, AuLock_IR);
7081 + aufs_read_unlock(dentry, AuLock_IR);
7086 + AuDbg("%.*s invalid, %d\n", AuDLNPair(dentry), valid);
7092 +static void aufs_d_release(struct dentry *dentry)
7094 + if (au_di(dentry)) {
7095 + au_di_fin(dentry);
7096 + au_hn_di_reinit(dentry);
7100 +const struct dentry_operations aufs_dop = {
7101 + .d_revalidate = aufs_d_revalidate,
7102 + .d_release = aufs_d_release
7104 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
7105 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
7106 +++ linux/fs/aufs/dentry.h 2012-07-22 19:57:03.161004531 +0200
7109 + * Copyright (C) 2005-2012 Junjiro R. Okajima
7111 + * This program, aufs is free software; you can redistribute it and/or modify
7112 + * it under the terms of the GNU General Public License as published by
7113 + * the Free Software Foundation; either version 2 of the License, or
7114 + * (at your option) any later version.
7116 + * This program is distributed in the hope that it will be useful,
7117 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7118 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7119 + * GNU General Public License for more details.
7121 + * You should have received a copy of the GNU General Public License
7122 + * along with this program; if not, write to the Free Software
7123 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
7127 + * lookup and dentry operations
7130 +#ifndef __AUFS_DENTRY_H__
7131 +#define __AUFS_DENTRY_H__
7135 +#include <linux/dcache.h>
7138 +struct au_hdentry {
7139 + struct dentry *hd_dentry;
7140 + aufs_bindex_t hd_id;
7144 + atomic_t di_generation;
7146 + struct au_rwsem di_rwsem;
7147 + aufs_bindex_t di_bstart, di_bend, di_bwh, di_bdiropq;
7148 + struct au_hdentry *di_hdentry;
7149 +} ____cacheline_aligned_in_smp;
7151 +/* ---------------------------------------------------------------------- */
7154 +extern const struct dentry_operations aufs_dop;
7156 +struct dentry *au_lkup_one(struct qstr *name, struct dentry *h_parent,
7157 + struct au_branch *br, struct nameidata *nd);
7158 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent,
7159 + struct au_branch *br);
7160 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
7161 + struct dentry *h_parent, struct au_branch *br);
7163 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type,
7164 + struct nameidata *nd);
7165 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex);
7166 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
7167 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
7170 +void au_di_init_once(void *_di);
7171 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
7172 +void au_di_free(struct au_dinfo *dinfo);
7173 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
7174 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
7175 +int au_di_init(struct dentry *dentry);
7176 +void au_di_fin(struct dentry *dentry);
7177 +int au_di_realloc(struct au_dinfo *dinfo, int nbr);
7179 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
7180 +void di_read_unlock(struct dentry *d, int flags);
7181 +void di_downgrade_lock(struct dentry *d, int flags);
7182 +void di_write_lock(struct dentry *d, unsigned int lsc);
7183 +void di_write_unlock(struct dentry *d);
7184 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
7185 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
7186 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
7188 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
7189 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
7190 +aufs_bindex_t au_dbtail(struct dentry *dentry);
7191 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
7193 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
7194 + struct dentry *h_dentry);
7195 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
7196 +int au_dbrange_test(struct dentry *dentry);
7197 +void au_update_digen(struct dentry *dentry);
7198 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
7199 +void au_update_dbstart(struct dentry *dentry);
7200 +void au_update_dbend(struct dentry *dentry);
7201 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
7203 +/* ---------------------------------------------------------------------- */
7205 +static inline struct au_dinfo *au_di(struct dentry *dentry)
7207 + return dentry->d_fsdata;
7210 +/* ---------------------------------------------------------------------- */
7212 +/* lock subclass for dinfo */
7214 + AuLsc_DI_CHILD, /* child first */
7215 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
7216 + AuLsc_DI_CHILD3, /* copyup dirs */
7220 + AuLsc_DI_TMP /* temp for replacing dinfo */
7224 + * di_read_lock_child, di_write_lock_child,
7225 + * di_read_lock_child2, di_write_lock_child2,
7226 + * di_read_lock_child3, di_write_lock_child3,
7227 + * di_read_lock_parent, di_write_lock_parent,
7228 + * di_read_lock_parent2, di_write_lock_parent2,
7229 + * di_read_lock_parent3, di_write_lock_parent3,
7231 +#define AuReadLockFunc(name, lsc) \
7232 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
7233 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
7235 +#define AuWriteLockFunc(name, lsc) \
7236 +static inline void di_write_lock_##name(struct dentry *d) \
7237 +{ di_write_lock(d, AuLsc_DI_##lsc); }
7239 +#define AuRWLockFuncs(name, lsc) \
7240 + AuReadLockFunc(name, lsc) \
7241 + AuWriteLockFunc(name, lsc)
7243 +AuRWLockFuncs(child, CHILD);
7244 +AuRWLockFuncs(child2, CHILD2);
7245 +AuRWLockFuncs(child3, CHILD3);
7246 +AuRWLockFuncs(parent, PARENT);
7247 +AuRWLockFuncs(parent2, PARENT2);
7248 +AuRWLockFuncs(parent3, PARENT3);
7250 +#undef AuReadLockFunc
7251 +#undef AuWriteLockFunc
7252 +#undef AuRWLockFuncs
7254 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
7255 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
7256 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
7258 +/* ---------------------------------------------------------------------- */
7260 +/* todo: memory barrier? */
7261 +static inline unsigned int au_digen(struct dentry *d)
7263 + return atomic_read(&au_di(d)->di_generation);
7266 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
7268 + hdentry->hd_dentry = NULL;
7271 +static inline void au_hdput(struct au_hdentry *hd)
7274 + dput(hd->hd_dentry);
7277 +static inline aufs_bindex_t au_dbstart(struct dentry *dentry)
7279 + DiMustAnyLock(dentry);
7280 + return au_di(dentry)->di_bstart;
7283 +static inline aufs_bindex_t au_dbend(struct dentry *dentry)
7285 + DiMustAnyLock(dentry);
7286 + return au_di(dentry)->di_bend;
7289 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
7291 + DiMustAnyLock(dentry);
7292 + return au_di(dentry)->di_bwh;
7295 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
7297 + DiMustAnyLock(dentry);
7298 + return au_di(dentry)->di_bdiropq;
7301 +/* todo: hard/soft set? */
7302 +static inline void au_set_dbstart(struct dentry *dentry, aufs_bindex_t bindex)
7304 + DiMustWriteLock(dentry);
7305 + au_di(dentry)->di_bstart = bindex;
7308 +static inline void au_set_dbend(struct dentry *dentry, aufs_bindex_t bindex)
7310 + DiMustWriteLock(dentry);
7311 + au_di(dentry)->di_bend = bindex;
7314 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
7316 + DiMustWriteLock(dentry);
7317 + /* dbwh can be outside of bstart - bend range */
7318 + au_di(dentry)->di_bwh = bindex;
7321 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
7323 + DiMustWriteLock(dentry);
7324 + au_di(dentry)->di_bdiropq = bindex;
7327 +/* ---------------------------------------------------------------------- */
7329 +#ifdef CONFIG_AUFS_HNOTIFY
7330 +static inline void au_digen_dec(struct dentry *d)
7332 + atomic_dec(&au_di(d)->di_generation);
7335 +static inline void au_hn_di_reinit(struct dentry *dentry)
7337 + dentry->d_fsdata = NULL;
7340 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
7341 +#endif /* CONFIG_AUFS_HNOTIFY */
7343 +#endif /* __KERNEL__ */
7344 +#endif /* __AUFS_DENTRY_H__ */
7345 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
7346 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
7347 +++ linux/fs/aufs/dinfo.c 2012-07-22 19:57:03.161004531 +0200
7350 + * Copyright (C) 2005-2012 Junjiro R. Okajima
7352 + * This program, aufs is free software; you can redistribute it and/or modify
7353 + * it under the terms of the GNU General Public License as published by
7354 + * the Free Software Foundation; either version 2 of the License, or
7355 + * (at your option) any later version.
7357 + * This program is distributed in the hope that it will be useful,
7358 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7359 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7360 + * GNU General Public License for more details.
7362 + * You should have received a copy of the GNU General Public License
7363 + * along with this program; if not, write to the Free Software
7364 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
7368 + * dentry private data
7373 +void au_di_init_once(void *_dinfo)
7375 + struct au_dinfo *dinfo = _dinfo;
7376 + static struct lock_class_key aufs_di;
7378 + au_rw_init(&dinfo->di_rwsem);
7379 + au_rw_class(&dinfo->di_rwsem, &aufs_di);
7382 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
7384 + struct au_dinfo *dinfo;
7387 + dinfo = au_cache_alloc_dinfo();
7388 + if (unlikely(!dinfo))
7391 + nbr = au_sbend(sb) + 1;
7394 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
7395 + if (dinfo->di_hdentry) {
7396 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
7397 + dinfo->di_bstart = -1;
7398 + dinfo->di_bend = -1;
7399 + dinfo->di_bwh = -1;
7400 + dinfo->di_bdiropq = -1;
7401 + for (i = 0; i < nbr; i++)
7402 + dinfo->di_hdentry[i].hd_id = -1;
7406 + au_cache_free_dinfo(dinfo);
7413 +void au_di_free(struct au_dinfo *dinfo)
7415 + struct au_hdentry *p;
7416 + aufs_bindex_t bend, bindex;
7418 + /* dentry may not be revalidated */
7419 + bindex = dinfo->di_bstart;
7420 + if (bindex >= 0) {
7421 + bend = dinfo->di_bend;
7422 + p = dinfo->di_hdentry + bindex;
7423 + while (bindex++ <= bend)
7426 + kfree(dinfo->di_hdentry);
7427 + au_cache_free_dinfo(dinfo);
7430 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
7432 + struct au_hdentry *p;
7435 + AuRwMustWriteLock(&a->di_rwsem);
7436 + AuRwMustWriteLock(&b->di_rwsem);
7438 +#define DiSwap(v, name) \
7440 + v = a->di_##name; \
7441 + a->di_##name = b->di_##name; \
7442 + b->di_##name = v; \
7445 + DiSwap(p, hdentry);
7446 + DiSwap(bi, bstart);
7449 + DiSwap(bi, bdiropq);
7455 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
7457 + AuRwMustWriteLock(&dst->di_rwsem);
7458 + AuRwMustWriteLock(&src->di_rwsem);
7460 + dst->di_bstart = src->di_bstart;
7461 + dst->di_bend = src->di_bend;
7462 + dst->di_bwh = src->di_bwh;
7463 + dst->di_bdiropq = src->di_bdiropq;
7467 +int au_di_init(struct dentry *dentry)
7470 + struct super_block *sb;
7471 + struct au_dinfo *dinfo;
7474 + sb = dentry->d_sb;
7475 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
7477 + atomic_set(&dinfo->di_generation, au_sigen(sb));
7478 + /* smp_mb(); */ /* atomic_set */
7479 + dentry->d_fsdata = dinfo;
7486 +void au_di_fin(struct dentry *dentry)
7488 + struct au_dinfo *dinfo;
7490 + dinfo = au_di(dentry);
7491 + AuRwDestroy(&dinfo->di_rwsem);
7492 + au_di_free(dinfo);
7495 +int au_di_realloc(struct au_dinfo *dinfo, int nbr)
7498 + struct au_hdentry *hdp;
7500 + AuRwMustWriteLock(&dinfo->di_rwsem);
7503 + sz = sizeof(*hdp) * (dinfo->di_bend + 1);
7505 + sz = sizeof(*hdp);
7506 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS);
7508 + dinfo->di_hdentry = hdp;
7515 +/* ---------------------------------------------------------------------- */
7517 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
7520 + case AuLsc_DI_CHILD:
7521 + ii_write_lock_child(inode);
7523 + case AuLsc_DI_CHILD2:
7524 + ii_write_lock_child2(inode);
7526 + case AuLsc_DI_CHILD3:
7527 + ii_write_lock_child3(inode);
7529 + case AuLsc_DI_PARENT:
7530 + ii_write_lock_parent(inode);
7532 + case AuLsc_DI_PARENT2:
7533 + ii_write_lock_parent2(inode);
7535 + case AuLsc_DI_PARENT3:
7536 + ii_write_lock_parent3(inode);
7543 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
7546 + case AuLsc_DI_CHILD:
7547 + ii_read_lock_child(inode);
7549 + case AuLsc_DI_CHILD2:
7550 + ii_read_lock_child2(inode);
7552 + case AuLsc_DI_CHILD3:
7553 + ii_read_lock_child3(inode);
7555 + case AuLsc_DI_PARENT:
7556 + ii_read_lock_parent(inode);
7558 + case AuLsc_DI_PARENT2:
7559 + ii_read_lock_parent2(inode);
7561 + case AuLsc_DI_PARENT3:
7562 + ii_read_lock_parent3(inode);
7569 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
7571 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
7573 + if (au_ftest_lock(flags, IW))
7574 + do_ii_write_lock(d->d_inode, lsc);
7575 + else if (au_ftest_lock(flags, IR))
7576 + do_ii_read_lock(d->d_inode, lsc);
7580 +void di_read_unlock(struct dentry *d, int flags)
7583 + if (au_ftest_lock(flags, IW)) {
7584 + au_dbg_verify_dinode(d);
7585 + ii_write_unlock(d->d_inode);
7586 + } else if (au_ftest_lock(flags, IR)) {
7587 + au_dbg_verify_dinode(d);
7588 + ii_read_unlock(d->d_inode);
7591 + au_rw_read_unlock(&au_di(d)->di_rwsem);
7594 +void di_downgrade_lock(struct dentry *d, int flags)
7596 + if (d->d_inode && au_ftest_lock(flags, IR))
7597 + ii_downgrade_lock(d->d_inode);
7598 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
7601 +void di_write_lock(struct dentry *d, unsigned int lsc)
7603 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
7605 + do_ii_write_lock(d->d_inode, lsc);
7608 +void di_write_unlock(struct dentry *d)
7610 + au_dbg_verify_dinode(d);
7612 + ii_write_unlock(d->d_inode);
7613 + au_rw_write_unlock(&au_di(d)->di_rwsem);
7616 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
7618 + AuDebugOn(d1 == d2
7619 + || d1->d_inode == d2->d_inode
7620 + || d1->d_sb != d2->d_sb);
7622 + if (isdir && au_test_subdir(d1, d2)) {
7623 + di_write_lock_child(d1);
7624 + di_write_lock_child2(d2);
7626 + /* there should be no races */
7627 + di_write_lock_child(d2);
7628 + di_write_lock_child2(d1);
7632 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
7634 + AuDebugOn(d1 == d2
7635 + || d1->d_inode == d2->d_inode
7636 + || d1->d_sb != d2->d_sb);
7638 + if (isdir && au_test_subdir(d1, d2)) {
7639 + di_write_lock_parent(d1);
7640 + di_write_lock_parent2(d2);
7642 + /* there should be no races */
7643 + di_write_lock_parent(d2);
7644 + di_write_lock_parent2(d1);
7648 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
7650 + di_write_unlock(d1);
7651 + if (d1->d_inode == d2->d_inode)
7652 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
7654 + di_write_unlock(d2);
7657 +/* ---------------------------------------------------------------------- */
7659 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
7663 + DiMustAnyLock(dentry);
7665 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
7667 + AuDebugOn(bindex < 0);
7668 + d = au_di(dentry)->di_hdentry[0 + bindex].hd_dentry;
7669 + AuDebugOn(d && d->d_count <= 0);
7674 + * extended version of au_h_dptr().
7675 + * returns a hashed and positive h_dentry in bindex, NULL, or error.
7677 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
7679 + struct dentry *h_dentry;
7680 + struct inode *inode, *h_inode;
7682 + inode = dentry->d_inode;
7683 + AuDebugOn(!inode);
7686 + if (au_dbstart(dentry) <= bindex
7687 + && bindex <= au_dbend(dentry))
7688 + h_dentry = au_h_dptr(dentry, bindex);
7689 + if (h_dentry && !au_d_hashed_positive(h_dentry)) {
7691 + goto out; /* success */
7694 + AuDebugOn(bindex < au_ibstart(inode));
7695 + AuDebugOn(au_ibend(inode) < bindex);
7696 + h_inode = au_h_iptr(inode, bindex);
7697 + h_dentry = d_find_alias(h_inode);
7699 + if (!IS_ERR(h_dentry)) {
7700 + if (!au_d_hashed_positive(h_dentry))
7701 + goto out; /* success */
7707 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
7708 + h_dentry = au_plink_lkup(inode, bindex);
7709 + AuDebugOn(!h_dentry);
7710 + if (!IS_ERR(h_dentry)) {
7711 + if (!au_d_hashed_positive(h_dentry))
7712 + goto out; /* success */
7719 + AuDbgDentry(h_dentry);
7723 +aufs_bindex_t au_dbtail(struct dentry *dentry)
7725 + aufs_bindex_t bend, bwh;
7727 + bend = au_dbend(dentry);
7729 + bwh = au_dbwh(dentry);
7732 + if (0 < bwh && bwh < bend)
7738 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
7740 + aufs_bindex_t bend, bopq;
7742 + bend = au_dbtail(dentry);
7744 + bopq = au_dbdiropq(dentry);
7745 + if (0 <= bopq && bopq < bend)
7751 +/* ---------------------------------------------------------------------- */
7753 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
7754 + struct dentry *h_dentry)
7756 + struct au_hdentry *hd = au_di(dentry)->di_hdentry + bindex;
7757 + struct au_branch *br;
7759 + DiMustWriteLock(dentry);
7762 + hd->hd_dentry = h_dentry;
7764 + br = au_sbr(dentry->d_sb, bindex);
7765 + hd->hd_id = br->br_id;
7769 +int au_dbrange_test(struct dentry *dentry)
7772 + aufs_bindex_t bstart, bend;
7775 + bstart = au_dbstart(dentry);
7776 + bend = au_dbend(dentry);
7778 + AuDebugOn(bend < 0 && bstart > bend);
7781 + AuDebugOn(bend >= 0);
7787 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
7792 + if (unlikely(au_digen(dentry) != sigen
7793 + || au_iigen_test(dentry->d_inode, sigen)))
7799 +void au_update_digen(struct dentry *dentry)
7801 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
7802 + /* smp_mb(); */ /* atomic_set */
7805 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
7807 + struct au_dinfo *dinfo;
7808 + struct dentry *h_d;
7809 + struct au_hdentry *hdp;
7811 + DiMustWriteLock(dentry);
7813 + dinfo = au_di(dentry);
7814 + if (!dinfo || dinfo->di_bstart < 0)
7817 + hdp = dinfo->di_hdentry;
7818 + if (do_put_zero) {
7819 + aufs_bindex_t bindex, bend;
7821 + bend = dinfo->di_bend;
7822 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++) {
7823 + h_d = hdp[0 + bindex].hd_dentry;
7824 + if (h_d && !h_d->d_inode)
7825 + au_set_h_dptr(dentry, bindex, NULL);
7829 + dinfo->di_bstart = -1;
7830 + while (++dinfo->di_bstart <= dinfo->di_bend)
7831 + if (hdp[0 + dinfo->di_bstart].hd_dentry)
7833 + if (dinfo->di_bstart > dinfo->di_bend) {
7834 + dinfo->di_bstart = -1;
7835 + dinfo->di_bend = -1;
7840 + while (0 <= --dinfo->di_bend)
7841 + if (hdp[0 + dinfo->di_bend].hd_dentry)
7843 + AuDebugOn(dinfo->di_bstart > dinfo->di_bend || dinfo->di_bend < 0);
7846 +void au_update_dbstart(struct dentry *dentry)
7848 + aufs_bindex_t bindex, bend;
7849 + struct dentry *h_dentry;
7851 + bend = au_dbend(dentry);
7852 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
7853 + h_dentry = au_h_dptr(dentry, bindex);
7856 + if (h_dentry->d_inode) {
7857 + au_set_dbstart(dentry, bindex);
7860 + au_set_h_dptr(dentry, bindex, NULL);
7864 +void au_update_dbend(struct dentry *dentry)
7866 + aufs_bindex_t bindex, bstart;
7867 + struct dentry *h_dentry;
7869 + bstart = au_dbstart(dentry);
7870 + for (bindex = au_dbend(dentry); bindex >= bstart; bindex--) {
7871 + h_dentry = au_h_dptr(dentry, bindex);
7874 + if (h_dentry->d_inode) {
7875 + au_set_dbend(dentry, bindex);
7878 + au_set_h_dptr(dentry, bindex, NULL);
7882 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
7884 + aufs_bindex_t bindex, bend;
7886 + bend = au_dbend(dentry);
7887 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++)
7888 + if (au_h_dptr(dentry, bindex) == h_dentry)
7892 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
7893 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
7894 +++ linux/fs/aufs/dir.c 2012-07-22 19:57:03.161004531 +0200
7897 + * Copyright (C) 2005-2012 Junjiro R. Okajima
7899 + * This program, aufs is free software; you can redistribute it and/or modify
7900 + * it under the terms of the GNU General Public License as published by
7901 + * the Free Software Foundation; either version 2 of the License, or
7902 + * (at your option) any later version.
7904 + * This program is distributed in the hope that it will be useful,
7905 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7906 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7907 + * GNU General Public License for more details.
7909 + * You should have received a copy of the GNU General Public License
7910 + * along with this program; if not, write to the Free Software
7911 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
7915 + * directory operations
7918 +#include <linux/fs_stack.h>
7921 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
7923 + unsigned int nlink;
7925 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
7927 + nlink = dir->i_nlink;
7928 + nlink += h_dir->i_nlink - 2;
7929 + if (h_dir->i_nlink < 2)
7931 + /* 0 can happen in revaliding */
7932 + set_nlink(dir, nlink);
7935 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
7937 + unsigned int nlink;
7939 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
7941 + nlink = dir->i_nlink;
7942 + nlink -= h_dir->i_nlink - 2;
7943 + if (h_dir->i_nlink < 2)
7945 + /* nlink == 0 means the branch-fs is broken */
7946 + set_nlink(dir, nlink);
7949 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
7952 + aufs_bindex_t bindex, bend;
7953 + struct file *h_file;
7954 + struct dentry *h_dentry;
7958 + AuDebugOn(!file->f_dentry);
7959 + AuDebugOn(!file->f_dentry->d_inode);
7960 + AuDebugOn(!S_ISDIR(file->f_dentry->d_inode->i_mode));
7962 + bend = au_fbend_dir(file);
7963 + for (bindex = au_fbstart(file);
7964 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
7966 + h_file = au_hf_dir(file, bindex);
7968 + && h_file->f_dentry
7969 + && h_file->f_dentry->d_inode)
7970 + sz += i_size_read(h_file->f_dentry->d_inode);
7973 + AuDebugOn(!dentry);
7974 + AuDebugOn(!dentry->d_inode);
7975 + AuDebugOn(!S_ISDIR(dentry->d_inode->i_mode));
7977 + bend = au_dbtaildir(dentry);
7978 + for (bindex = au_dbstart(dentry);
7979 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
7981 + h_dentry = au_h_dptr(dentry, bindex);
7982 + if (h_dentry && h_dentry->d_inode)
7983 + sz += i_size_read(h_dentry->d_inode);
7986 + if (sz < KMALLOC_MAX_SIZE)
7987 + sz = roundup_pow_of_two(sz);
7988 + if (sz > KMALLOC_MAX_SIZE)
7989 + sz = KMALLOC_MAX_SIZE;
7990 + else if (sz < NAME_MAX) {
7991 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
7992 + sz = AUFS_RDBLK_DEF;
7997 +/* ---------------------------------------------------------------------- */
7999 +static int reopen_dir(struct file *file)
8002 + unsigned int flags;
8003 + aufs_bindex_t bindex, btail, bstart;
8004 + struct dentry *dentry, *h_dentry;
8005 + struct file *h_file;
8007 + /* open all lower dirs */
8008 + dentry = file->f_dentry;
8009 + bstart = au_dbstart(dentry);
8010 + for (bindex = au_fbstart(file); bindex < bstart; bindex++)
8011 + au_set_h_fptr(file, bindex, NULL);
8012 + au_set_fbstart(file, bstart);
8014 + btail = au_dbtaildir(dentry);
8015 + for (bindex = au_fbend_dir(file); btail < bindex; bindex--)
8016 + au_set_h_fptr(file, bindex, NULL);
8017 + au_set_fbend_dir(file, btail);
8019 + flags = vfsub_file_flags(file);
8020 + for (bindex = bstart; bindex <= btail; bindex++) {
8021 + h_dentry = au_h_dptr(dentry, bindex);
8024 + h_file = au_hf_dir(file, bindex);
8028 + h_file = au_h_open(dentry, bindex, flags, file);
8029 + err = PTR_ERR(h_file);
8030 + if (IS_ERR(h_file))
8031 + goto out; /* close all? */
8032 + au_set_h_fptr(file, bindex, h_file);
8034 + au_update_figen(file);
8035 + /* todo: necessary? */
8036 + /* file->f_ra = h_file->f_ra; */
8043 +static int do_open_dir(struct file *file, int flags)
8046 + aufs_bindex_t bindex, btail;
8047 + struct dentry *dentry, *h_dentry;
8048 + struct file *h_file;
8050 + FiMustWriteLock(file);
8052 + dentry = file->f_dentry;
8053 + err = au_alive_dir(dentry);
8054 + if (unlikely(err))
8057 + file->f_version = dentry->d_inode->i_version;
8058 + bindex = au_dbstart(dentry);
8059 + au_set_fbstart(file, bindex);
8060 + btail = au_dbtaildir(dentry);
8061 + au_set_fbend_dir(file, btail);
8062 + for (; !err && bindex <= btail; bindex++) {
8063 + h_dentry = au_h_dptr(dentry, bindex);
8067 + h_file = au_h_open(dentry, bindex, flags, file);
8068 + if (IS_ERR(h_file)) {
8069 + err = PTR_ERR(h_file);
8072 + au_set_h_fptr(file, bindex, h_file);
8074 + au_update_figen(file);
8075 + /* todo: necessary? */
8076 + /* file->f_ra = h_file->f_ra; */
8078 + return 0; /* success */
8081 + for (bindex = au_fbstart(file); bindex <= btail; bindex++)
8082 + au_set_h_fptr(file, bindex, NULL);
8083 + au_set_fbstart(file, -1);
8084 + au_set_fbend_dir(file, -1);
8090 +static int aufs_open_dir(struct inode *inode __maybe_unused,
8091 + struct file *file)
8094 + struct super_block *sb;
8095 + struct au_fidir *fidir;
8098 + sb = file->f_dentry->d_sb;
8099 + si_read_lock(sb, AuLock_FLUSH);
8100 + fidir = au_fidir_alloc(sb);
8102 + err = au_do_open(file, do_open_dir, fidir);
8103 + if (unlikely(err))
8106 + si_read_unlock(sb);
8110 +static int aufs_release_dir(struct inode *inode __maybe_unused,
8111 + struct file *file)
8113 + struct au_vdir *vdir_cache;
8114 + struct au_finfo *finfo;
8115 + struct au_fidir *fidir;
8116 + aufs_bindex_t bindex, bend;
8118 + finfo = au_fi(file);
8119 + fidir = finfo->fi_hdir;
8121 + /* remove me from sb->s_files */
8122 + file_sb_list_del(file);
8124 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
8126 + au_vdir_free(vdir_cache);
8128 + bindex = finfo->fi_btop;
8129 + if (bindex >= 0) {
8131 + * calls fput() instead of filp_close(),
8132 + * since no dnotify or lock for the lower file.
8134 + bend = fidir->fd_bbot;
8135 + for (; bindex <= bend; bindex++)
8136 + au_set_h_fptr(file, bindex, NULL);
8139 + finfo->fi_hdir = NULL;
8141 + au_finfo_fin(file);
8145 +/* ---------------------------------------------------------------------- */
8147 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
8150 + aufs_bindex_t bindex, bend;
8151 + struct file *h_file;
8154 + bend = au_fbend_dir(file);
8155 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
8156 + h_file = au_hf_dir(file, bindex);
8158 + err = vfsub_flush(h_file, id);
8163 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
8165 + return au_do_flush(file, id, au_do_flush_dir);
8168 +/* ---------------------------------------------------------------------- */
8170 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
8173 + aufs_bindex_t bend, bindex;
8174 + struct inode *inode;
8175 + struct super_block *sb;
8178 + sb = dentry->d_sb;
8179 + inode = dentry->d_inode;
8181 + bend = au_dbend(dentry);
8182 + for (bindex = au_dbstart(dentry); !err && bindex <= bend; bindex++) {
8183 + struct path h_path;
8185 + if (au_test_ro(sb, bindex, inode))
8187 + h_path.dentry = au_h_dptr(dentry, bindex);
8188 + if (!h_path.dentry)
8191 + h_path.mnt = au_sbr_mnt(sb, bindex);
8192 + err = vfsub_fsync(NULL, &h_path, datasync);
8198 +static int au_do_fsync_dir(struct file *file, int datasync)
8201 + aufs_bindex_t bend, bindex;
8202 + struct file *h_file;
8203 + struct super_block *sb;
8204 + struct inode *inode;
8206 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
8207 + if (unlikely(err))
8210 + sb = file->f_dentry->d_sb;
8211 + inode = file->f_dentry->d_inode;
8212 + bend = au_fbend_dir(file);
8213 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
8214 + h_file = au_hf_dir(file, bindex);
8215 + if (!h_file || au_test_ro(sb, bindex, inode))
8218 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
8226 + * @file may be NULL
8228 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
8232 + struct dentry *dentry;
8233 + struct super_block *sb;
8234 + struct mutex *mtx;
8237 + dentry = file->f_dentry;
8238 + mtx = &dentry->d_inode->i_mutex;
8240 + sb = dentry->d_sb;
8241 + si_noflush_read_lock(sb);
8243 + err = au_do_fsync_dir(file, datasync);
8245 + di_write_lock_child(dentry);
8246 + err = au_do_fsync_dir_no_file(dentry, datasync);
8248 + au_cpup_attr_timesizes(dentry->d_inode);
8249 + di_write_unlock(dentry);
8251 + fi_write_unlock(file);
8253 + si_read_unlock(sb);
8254 + mutex_unlock(mtx);
8258 +/* ---------------------------------------------------------------------- */
8260 +static int aufs_readdir(struct file *file, void *dirent, filldir_t filldir)
8263 + struct dentry *dentry;
8264 + struct inode *inode, *h_inode;
8265 + struct super_block *sb;
8267 + dentry = file->f_dentry;
8268 + inode = dentry->d_inode;
8271 + sb = dentry->d_sb;
8272 + si_read_lock(sb, AuLock_FLUSH);
8273 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
8274 + if (unlikely(err))
8276 + err = au_alive_dir(dentry);
8278 + err = au_vdir_init(file);
8279 + di_downgrade_lock(dentry, AuLock_IR);
8280 + if (unlikely(err))
8283 + h_inode = au_h_iptr(inode, au_ibstart(inode));
8284 + if (!au_test_nfsd()) {
8285 + err = au_vdir_fill_de(file, dirent, filldir);
8286 + fsstack_copy_attr_atime(inode, h_inode);
8289 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
8290 + * encode_fh() and others.
8292 + atomic_inc(&h_inode->i_count);
8293 + di_read_unlock(dentry, AuLock_IR);
8294 + si_read_unlock(sb);
8295 + err = au_vdir_fill_de(file, dirent, filldir);
8296 + fsstack_copy_attr_atime(inode, h_inode);
8297 + fi_write_unlock(file);
8305 + di_read_unlock(dentry, AuLock_IR);
8306 + fi_write_unlock(file);
8308 + si_read_unlock(sb);
8312 +/* ---------------------------------------------------------------------- */
8314 +#define AuTestEmpty_WHONLY 1
8315 +#define AuTestEmpty_CALLED (1 << 1)
8316 +#define AuTestEmpty_SHWH (1 << 2)
8317 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
8318 +#define au_fset_testempty(flags, name) \
8319 + do { (flags) |= AuTestEmpty_##name; } while (0)
8320 +#define au_fclr_testempty(flags, name) \
8321 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
8323 +#ifndef CONFIG_AUFS_SHWH
8324 +#undef AuTestEmpty_SHWH
8325 +#define AuTestEmpty_SHWH 0
8328 +struct test_empty_arg {
8329 + struct au_nhash *whlist;
8330 + unsigned int flags;
8332 + aufs_bindex_t bindex;
8335 +static int test_empty_cb(void *__arg, const char *__name, int namelen,
8336 + loff_t offset __maybe_unused, u64 ino,
8337 + unsigned int d_type)
8339 + struct test_empty_arg *arg = __arg;
8340 + char *name = (void *)__name;
8343 + au_fset_testempty(arg->flags, CALLED);
8345 + if (name[0] == '.'
8346 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
8347 + goto out; /* success */
8349 + if (namelen <= AUFS_WH_PFX_LEN
8350 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
8351 + if (au_ftest_testempty(arg->flags, WHONLY)
8352 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
8353 + arg->err = -ENOTEMPTY;
8357 + name += AUFS_WH_PFX_LEN;
8358 + namelen -= AUFS_WH_PFX_LEN;
8359 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
8360 + arg->err = au_nhash_append_wh
8361 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
8362 + au_ftest_testempty(arg->flags, SHWH));
8366 + AuTraceErr(arg->err);
8370 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
8373 + struct file *h_file;
8375 + h_file = au_h_open(dentry, arg->bindex,
8376 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
8378 + err = PTR_ERR(h_file);
8379 + if (IS_ERR(h_file))
8383 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
8384 + && !h_file->f_dentry->d_inode->i_nlink)
8389 + au_fclr_testempty(arg->flags, CALLED);
8391 + err = vfsub_readdir(h_file, test_empty_cb, arg);
8394 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
8398 + au_sbr_put(dentry->d_sb, arg->bindex);
8403 +struct do_test_empty_args {
8405 + struct dentry *dentry;
8406 + struct test_empty_arg *arg;
8409 +static void call_do_test_empty(void *args)
8411 + struct do_test_empty_args *a = args;
8412 + *a->errp = do_test_empty(a->dentry, a->arg);
8415 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
8418 + struct dentry *h_dentry;
8419 + struct inode *h_inode;
8421 + h_dentry = au_h_dptr(dentry, arg->bindex);
8422 + h_inode = h_dentry->d_inode;
8423 + /* todo: i_mode changes anytime? */
8424 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
8425 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
8426 + mutex_unlock(&h_inode->i_mutex);
8428 + err = do_test_empty(dentry, arg);
8430 + struct do_test_empty_args args = {
8435 + unsigned int flags = arg->flags;
8437 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
8438 + if (unlikely(wkq_err))
8440 + arg->flags = flags;
8446 +int au_test_empty_lower(struct dentry *dentry)
8449 + unsigned int rdhash;
8450 + aufs_bindex_t bindex, bstart, btail;
8451 + struct au_nhash whlist;
8452 + struct test_empty_arg arg;
8454 + SiMustAnyLock(dentry->d_sb);
8456 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
8458 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
8459 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
8460 + if (unlikely(err))
8464 + arg.whlist = &whlist;
8465 + bstart = au_dbstart(dentry);
8466 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
8467 + au_fset_testempty(arg.flags, SHWH);
8468 + arg.bindex = bstart;
8469 + err = do_test_empty(dentry, &arg);
8470 + if (unlikely(err))
8473 + au_fset_testempty(arg.flags, WHONLY);
8474 + btail = au_dbtaildir(dentry);
8475 + for (bindex = bstart + 1; !err && bindex <= btail; bindex++) {
8476 + struct dentry *h_dentry;
8478 + h_dentry = au_h_dptr(dentry, bindex);
8479 + if (h_dentry && h_dentry->d_inode) {
8480 + arg.bindex = bindex;
8481 + err = do_test_empty(dentry, &arg);
8486 + au_nhash_wh_free(&whlist);
8491 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
8494 + struct test_empty_arg arg;
8495 + aufs_bindex_t bindex, btail;
8498 + arg.whlist = whlist;
8499 + arg.flags = AuTestEmpty_WHONLY;
8500 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
8501 + au_fset_testempty(arg.flags, SHWH);
8502 + btail = au_dbtaildir(dentry);
8503 + for (bindex = au_dbstart(dentry); !err && bindex <= btail; bindex++) {
8504 + struct dentry *h_dentry;
8506 + h_dentry = au_h_dptr(dentry, bindex);
8507 + if (h_dentry && h_dentry->d_inode) {
8508 + arg.bindex = bindex;
8509 + err = sio_test_empty(dentry, &arg);
8516 +/* ---------------------------------------------------------------------- */
8518 +const struct file_operations aufs_dir_fop = {
8519 + .owner = THIS_MODULE,
8520 + .llseek = default_llseek,
8521 + .read = generic_read_dir,
8522 + .readdir = aufs_readdir,
8523 + .unlocked_ioctl = aufs_ioctl_dir,
8524 +#ifdef CONFIG_COMPAT
8525 + .compat_ioctl = aufs_compat_ioctl_dir,
8527 + .open = aufs_open_dir,
8528 + .release = aufs_release_dir,
8529 + .flush = aufs_flush_dir,
8530 + .fsync = aufs_fsync_dir
8532 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
8533 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
8534 +++ linux/fs/aufs/dir.h 2012-07-22 19:57:03.161004531 +0200
8537 + * Copyright (C) 2005-2012 Junjiro R. Okajima
8539 + * This program, aufs is free software; you can redistribute it and/or modify
8540 + * it under the terms of the GNU General Public License as published by
8541 + * the Free Software Foundation; either version 2 of the License, or
8542 + * (at your option) any later version.
8544 + * This program is distributed in the hope that it will be useful,
8545 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8546 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8547 + * GNU General Public License for more details.
8549 + * You should have received a copy of the GNU General Public License
8550 + * along with this program; if not, write to the Free Software
8551 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
8555 + * directory operations
8558 +#ifndef __AUFS_DIR_H__
8559 +#define __AUFS_DIR_H__
8563 +#include <linux/fs.h>
8565 +/* ---------------------------------------------------------------------- */
8567 +/* need to be faster and smaller */
8570 + unsigned int nh_num;
8571 + struct hlist_head *nh_head;
8574 +struct au_vdir_destr {
8575 + unsigned char len;
8576 + unsigned char name[0];
8579 +struct au_vdir_dehstr {
8580 + struct hlist_node hash;
8581 + struct au_vdir_destr *str;
8582 +} ____cacheline_aligned_in_smp;
8584 +struct au_vdir_de {
8586 + unsigned char de_type;
8587 + /* caution: packed */
8588 + struct au_vdir_destr de_str;
8591 +struct au_vdir_wh {
8592 + struct hlist_node wh_hash;
8593 +#ifdef CONFIG_AUFS_SHWH
8595 + aufs_bindex_t wh_bindex;
8596 + unsigned char wh_type;
8598 + aufs_bindex_t wh_bindex;
8600 + /* caution: packed */
8601 + struct au_vdir_destr wh_str;
8604 +union au_vdir_deblk_p {
8605 + unsigned char *deblk;
8606 + struct au_vdir_de *de;
8610 + unsigned char **vd_deblk;
8611 + unsigned long vd_nblk;
8614 + union au_vdir_deblk_p p;
8617 + unsigned long vd_version;
8618 + unsigned int vd_deblk_sz;
8619 + unsigned long vd_jiffy;
8620 +} ____cacheline_aligned_in_smp;
8622 +/* ---------------------------------------------------------------------- */
8625 +extern const struct file_operations aufs_dir_fop;
8626 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
8627 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
8628 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
8629 +int au_test_empty_lower(struct dentry *dentry);
8630 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
8633 +unsigned int au_rdhash_est(loff_t sz);
8634 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
8635 +void au_nhash_wh_free(struct au_nhash *whlist);
8636 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
8638 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
8639 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
8640 + unsigned int d_type, aufs_bindex_t bindex,
8641 + unsigned char shwh);
8642 +void au_vdir_free(struct au_vdir *vdir);
8643 +int au_vdir_init(struct file *file);
8644 +int au_vdir_fill_de(struct file *file, void *dirent, filldir_t filldir);
8647 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
8649 +#ifdef CONFIG_AUFS_RDU
8651 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
8652 +#ifdef CONFIG_COMPAT
8653 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
8654 + unsigned long arg);
8657 +static inline long au_rdu_ioctl(struct file *file, unsigned int cmd,
8658 + unsigned long arg)
8662 +#ifdef CONFIG_COMPAT
8663 +static inline long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
8664 + unsigned long arg)
8671 +#endif /* __KERNEL__ */
8672 +#endif /* __AUFS_DIR_H__ */
8673 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
8674 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
8675 +++ linux/fs/aufs/dynop.c 2012-07-22 19:57:03.161004531 +0200
8678 + * Copyright (C) 2010-2012 Junjiro R. Okajima
8680 + * This program, aufs is free software; you can redistribute it and/or modify
8681 + * it under the terms of the GNU General Public License as published by
8682 + * the Free Software Foundation; either version 2 of the License, or
8683 + * (at your option) any later version.
8685 + * This program is distributed in the hope that it will be useful,
8686 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8687 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8688 + * GNU General Public License for more details.
8690 + * You should have received a copy of the GNU General Public License
8691 + * along with this program; if not, write to the Free Software
8692 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
8696 + * dynamically customizable operations for regular files
8701 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
8704 + * How large will these lists be?
8705 + * Usually just a few elements, 20-30 at most for each, I guess.
8707 +static struct au_splhead dynop[AuDyLast];
8709 +static struct au_dykey *dy_gfind_get(struct au_splhead *spl, const void *h_op)
8711 + struct au_dykey *key, *tmp;
8712 + struct list_head *head;
8715 + head = &spl->head;
8717 + list_for_each_entry_rcu(tmp, head, dk_list)
8718 + if (tmp->dk_op.dy_hop == h_op) {
8720 + kref_get(&key->dk_kref);
8723 + rcu_read_unlock();
8728 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
8730 + struct au_dykey **k, *found;
8731 + const void *h_op = key->dk_op.dy_hop;
8736 + for (i = 0; i < AuBrDynOp; i++)
8738 + if (k[i]->dk_op.dy_hop == h_op) {
8745 + spin_lock(&br->br_dykey_lock);
8746 + for (; i < AuBrDynOp; i++)
8748 + if (k[i]->dk_op.dy_hop == h_op) {
8756 + spin_unlock(&br->br_dykey_lock);
8757 + BUG_ON(i == AuBrDynOp); /* expand the array */
8763 +/* kref_get() if @key is already added */
8764 +static struct au_dykey *dy_gadd(struct au_splhead *spl, struct au_dykey *key)
8766 + struct au_dykey *tmp, *found;
8767 + struct list_head *head;
8768 + const void *h_op = key->dk_op.dy_hop;
8771 + head = &spl->head;
8772 + spin_lock(&spl->spin);
8773 + list_for_each_entry(tmp, head, dk_list)
8774 + if (tmp->dk_op.dy_hop == h_op) {
8775 + kref_get(&tmp->dk_kref);
8780 + list_add_rcu(&key->dk_list, head);
8781 + spin_unlock(&spl->spin);
8788 +static void dy_free_rcu(struct rcu_head *rcu)
8790 + struct au_dykey *key;
8792 + key = container_of(rcu, struct au_dykey, dk_rcu);
8797 +static void dy_free(struct kref *kref)
8799 + struct au_dykey *key;
8800 + struct au_splhead *spl;
8802 + key = container_of(kref, struct au_dykey, dk_kref);
8803 + spl = dynop + key->dk_op.dy_type;
8804 + au_spl_del_rcu(&key->dk_list, spl);
8805 + call_rcu(&key->dk_rcu, dy_free_rcu);
8808 +void au_dy_put(struct au_dykey *key)
8810 + kref_put(&key->dk_kref, dy_free);
8813 +/* ---------------------------------------------------------------------- */
8815 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
8817 +#ifdef CONFIG_AUFS_DEBUG
8818 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
8819 +#define DyDbgInc(cnt) do { cnt++; } while (0)
8821 +#define DyDbgDeclare(cnt) do {} while (0)
8822 +#define DyDbgInc(cnt) do {} while (0)
8825 +#define DySet(func, dst, src, h_op, h_sb) do { \
8827 + if (h_op->func) { \
8829 + dst.func = src.func; \
8831 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
8835 +#define DySetForce(func, dst, src) do { \
8836 + AuDebugOn(!src.func); \
8838 + dst.func = src.func; \
8841 +#define DySetAop(func) \
8842 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
8843 +#define DySetAopForce(func) \
8844 + DySetForce(func, dyaop->da_op, aufs_aop)
8846 +static void dy_aop(struct au_dykey *key, const void *h_op,
8847 + struct super_block *h_sb __maybe_unused)
8849 + struct au_dyaop *dyaop = (void *)key;
8850 + const struct address_space_operations *h_aop = h_op;
8851 + DyDbgDeclare(cnt);
8853 + AuDbg("%s\n", au_sbtype(h_sb));
8855 + DySetAop(writepage);
8856 + DySetAopForce(readpage); /* force */
8857 + DySetAop(writepages);
8858 + DySetAop(set_page_dirty);
8859 + DySetAop(readpages);
8860 + DySetAop(write_begin);
8861 + DySetAop(write_end);
8863 + DySetAop(invalidatepage);
8864 + DySetAop(releasepage);
8865 + DySetAop(freepage);
8866 + /* these two will be changed according to an aufs mount option */
8867 + DySetAop(direct_IO);
8868 + DySetAop(get_xip_mem);
8869 + DySetAop(migratepage);
8870 + DySetAop(launder_page);
8871 + DySetAop(is_partially_uptodate);
8872 + DySetAop(error_remove_page);
8874 + DyDbgSize(cnt, *h_aop);
8875 + dyaop->da_get_xip_mem = h_aop->get_xip_mem;
8878 +/* ---------------------------------------------------------------------- */
8880 +static void dy_bug(struct kref *kref)
8885 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
8887 + struct au_dykey *key, *old;
8888 + struct au_splhead *spl;
8891 + void (*set)(struct au_dykey *key, const void *h_op,
8892 + struct super_block *h_sb __maybe_unused);
8894 + static const struct op a[] = {
8896 + .sz = sizeof(struct au_dyaop),
8900 + const struct op *p;
8902 + spl = dynop + op->dy_type;
8903 + key = dy_gfind_get(spl, op->dy_hop);
8905 + goto out_add; /* success */
8907 + p = a + op->dy_type;
8908 + key = kzalloc(p->sz, GFP_NOFS);
8909 + if (unlikely(!key)) {
8910 + key = ERR_PTR(-ENOMEM);
8914 + key->dk_op.dy_hop = op->dy_hop;
8915 + kref_init(&key->dk_kref);
8916 + p->set(key, op->dy_hop, br->br_mnt->mnt_sb);
8917 + old = dy_gadd(spl, key);
8924 + old = dy_bradd(br, key);
8926 + /* its ref-count should never be zero here */
8927 + kref_put(&key->dk_kref, dy_bug);
8932 +/* ---------------------------------------------------------------------- */
8934 + * Aufs prohibits O_DIRECT by defaut even if the branch supports it.
8935 + * This behaviour is neccessary to return an error from open(O_DIRECT) instead
8936 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
8937 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
8938 + * See the aufs manual in detail.
8940 + * To keep this behaviour, aufs has to set NULL to ->get_xip_mem too, and the
8941 + * performance of fadvise() and madvise() may be affected.
8943 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
8946 + dyaop->da_op.direct_IO = NULL;
8947 + dyaop->da_op.get_xip_mem = NULL;
8949 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
8950 + dyaop->da_op.get_xip_mem = aufs_aop.get_xip_mem;
8951 + if (!dyaop->da_get_xip_mem)
8952 + dyaop->da_op.get_xip_mem = NULL;
8956 +static struct au_dyaop *dy_aget(struct au_branch *br,
8957 + const struct address_space_operations *h_aop,
8960 + struct au_dyaop *dyaop;
8961 + struct au_dynop op;
8963 + op.dy_type = AuDy_AOP;
8964 + op.dy_haop = h_aop;
8965 + dyaop = (void *)dy_get(&op, br);
8966 + if (IS_ERR(dyaop))
8968 + dy_adx(dyaop, do_dx);
8974 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
8975 + struct inode *h_inode)
8978 + struct super_block *sb;
8979 + struct au_branch *br;
8980 + struct au_dyaop *dyaop;
8982 + AuDebugOn(!S_ISREG(h_inode->i_mode));
8983 + IiMustWriteLock(inode);
8986 + br = au_sbr(sb, bindex);
8987 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
8988 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
8989 + err = PTR_ERR(dyaop);
8990 + if (IS_ERR(dyaop))
8991 + /* unnecessary to call dy_fput() */
8995 + inode->i_mapping->a_ops = &dyaop->da_op;
9002 + * Is it safe to replace a_ops during the inode/file is in operation?
9005 +int au_dy_irefresh(struct inode *inode)
9008 + aufs_bindex_t bstart;
9009 + struct inode *h_inode;
9012 + if (S_ISREG(inode->i_mode)) {
9013 + bstart = au_ibstart(inode);
9014 + h_inode = au_h_iptr(inode, bstart);
9015 + err = au_dy_iaop(inode, bstart, h_inode);
9020 +void au_dy_arefresh(int do_dx)
9022 + struct au_splhead *spl;
9023 + struct list_head *head;
9024 + struct au_dykey *key;
9026 + spl = dynop + AuDy_AOP;
9027 + head = &spl->head;
9028 + spin_lock(&spl->spin);
9029 + list_for_each_entry(key, head, dk_list)
9030 + dy_adx((void *)key, do_dx);
9031 + spin_unlock(&spl->spin);
9034 +/* ---------------------------------------------------------------------- */
9036 +void __init au_dy_init(void)
9040 + /* make sure that 'struct au_dykey *' can be any type */
9041 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
9043 + for (i = 0; i < AuDyLast; i++)
9044 + au_spl_init(dynop + i);
9047 +void au_dy_fin(void)
9051 + for (i = 0; i < AuDyLast; i++)
9052 + WARN_ON(!list_empty(&dynop[i].head));
9054 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
9055 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
9056 +++ linux/fs/aufs/dynop.h 2012-07-22 19:57:03.161004531 +0200
9059 + * Copyright (C) 2010-2012 Junjiro R. Okajima
9061 + * This program, aufs is free software; you can redistribute it and/or modify
9062 + * it under the terms of the GNU General Public License as published by
9063 + * the Free Software Foundation; either version 2 of the License, or
9064 + * (at your option) any later version.
9066 + * This program is distributed in the hope that it will be useful,
9067 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9068 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9069 + * GNU General Public License for more details.
9071 + * You should have received a copy of the GNU General Public License
9072 + * along with this program; if not, write to the Free Software
9073 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
9077 + * dynamically customizable operations (for regular files only)
9080 +#ifndef __AUFS_DYNOP_H__
9081 +#define __AUFS_DYNOP_H__
9087 +enum {AuDy_AOP, AuDyLast};
9092 + const void *dy_hop;
9093 + const struct address_space_operations *dy_haop;
9099 + struct list_head dk_list;
9100 + struct rcu_head dk_rcu;
9102 + struct au_dynop dk_op;
9105 + * during I am in the branch local array, kref is gotten. when the
9106 + * branch is removed, kref is put.
9108 + struct kref dk_kref;
9111 +/* stop unioning since their sizes are very different from each other */
9113 + struct au_dykey da_key;
9114 + struct address_space_operations da_op; /* not const */
9115 + int (*da_get_xip_mem)(struct address_space *, pgoff_t, int,
9116 + void **, unsigned long *);
9119 +/* ---------------------------------------------------------------------- */
9123 +void au_dy_put(struct au_dykey *key);
9124 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
9125 + struct inode *h_inode);
9126 +int au_dy_irefresh(struct inode *inode);
9127 +void au_dy_arefresh(int do_dio);
9129 +void __init au_dy_init(void);
9130 +void au_dy_fin(void);
9132 +#endif /* __KERNEL__ */
9133 +#endif /* __AUFS_DYNOP_H__ */
9134 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
9135 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
9136 +++ linux/fs/aufs/export.c 2012-07-22 19:57:03.164337936 +0200
9139 + * Copyright (C) 2005-2012 Junjiro R. Okajima
9141 + * This program, aufs is free software; you can redistribute it and/or modify
9142 + * it under the terms of the GNU General Public License as published by
9143 + * the Free Software Foundation; either version 2 of the License, or
9144 + * (at your option) any later version.
9146 + * This program is distributed in the hope that it will be useful,
9147 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9148 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9149 + * GNU General Public License for more details.
9151 + * You should have received a copy of the GNU General Public License
9152 + * along with this program; if not, write to the Free Software
9153 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
9160 +#include <linux/exportfs.h>
9161 +#include <linux/fs_struct.h>
9162 +#include <linux/namei.h>
9163 +#include <linux/nsproxy.h>
9164 +#include <linux/random.h>
9165 +#include <linux/writeback.h>
9166 +#include "../fs/mount.h"
9170 +#ifdef CONFIG_AUFS_INO_T_64
9178 +static ino_t decode_ino(__u32 *a)
9182 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
9184 +#ifdef CONFIG_AUFS_INO_T_64
9190 +static void encode_ino(__u32 *a, ino_t ino)
9196 +#ifdef CONFIG_AUFS_INO_T_64
9201 +/* NFS file handle */
9205 +#ifdef CONFIG_AUFS_INO_T_64
9206 + /* support 64bit inode number */
9220 + Fh_dir_ino = Fh_dir_ino1
9223 +static int au_test_anon(struct dentry *dentry)
9225 + /* note: read d_flags without d_lock */
9226 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
9229 +/* ---------------------------------------------------------------------- */
9230 +/* inode generation external table */
9232 +void au_xigen_inc(struct inode *inode)
9237 + struct super_block *sb;
9238 + struct au_sbinfo *sbinfo;
9241 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
9243 + sbinfo = au_sbi(sb);
9244 + pos = inode->i_ino;
9245 + pos *= sizeof(igen);
9246 + igen = inode->i_generation + 1;
9247 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
9248 + sizeof(igen), &pos);
9249 + if (sz == sizeof(igen))
9250 + return; /* success */
9252 + if (unlikely(sz >= 0))
9253 + AuIOErr("xigen error (%zd)\n", sz);
9256 +int au_xigen_new(struct inode *inode)
9261 + struct super_block *sb;
9262 + struct au_sbinfo *sbinfo;
9263 + struct file *file;
9266 + /* todo: dirty, at mount time */
9267 + if (inode->i_ino == AUFS_ROOT_INO)
9270 + SiMustAnyLock(sb);
9271 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
9275 + pos = inode->i_ino;
9276 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
9277 + AuIOErr1("too large i%lld\n", pos);
9280 + pos *= sizeof(inode->i_generation);
9283 + sbinfo = au_sbi(sb);
9284 + file = sbinfo->si_xigen;
9287 + if (i_size_read(file->f_dentry->d_inode)
9288 + < pos + sizeof(inode->i_generation)) {
9289 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
9290 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
9291 + sizeof(inode->i_generation), &pos);
9293 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
9294 + sizeof(inode->i_generation), &pos);
9295 + if (sz == sizeof(inode->i_generation))
9296 + goto out; /* success */
9299 + if (unlikely(sz >= 0)) {
9301 + AuIOErr("xigen error (%zd)\n", sz);
9308 +int au_xigen_set(struct super_block *sb, struct file *base)
9311 + struct au_sbinfo *sbinfo;
9312 + struct file *file;
9314 + SiMustWriteLock(sb);
9316 + sbinfo = au_sbi(sb);
9317 + file = au_xino_create2(base, sbinfo->si_xigen);
9318 + err = PTR_ERR(file);
9322 + if (sbinfo->si_xigen)
9323 + fput(sbinfo->si_xigen);
9324 + sbinfo->si_xigen = file;
9330 +void au_xigen_clr(struct super_block *sb)
9332 + struct au_sbinfo *sbinfo;
9334 + SiMustWriteLock(sb);
9336 + sbinfo = au_sbi(sb);
9337 + if (sbinfo->si_xigen) {
9338 + fput(sbinfo->si_xigen);
9339 + sbinfo->si_xigen = NULL;
9343 +/* ---------------------------------------------------------------------- */
9345 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
9348 + struct dentry *dentry, *d;
9349 + struct inode *inode;
9350 + unsigned int sigen;
9353 + inode = ilookup(sb, ino);
9357 + dentry = ERR_PTR(-ESTALE);
9358 + sigen = au_sigen(sb);
9359 + if (unlikely(is_bad_inode(inode)
9360 + || IS_DEADDIR(inode)
9361 + || sigen != au_iigen(inode)))
9365 + if (!dir_ino || S_ISDIR(inode->i_mode))
9366 + dentry = d_find_alias(inode);
9368 + spin_lock(&inode->i_lock);
9369 + list_for_each_entry(d, &inode->i_dentry, d_alias) {
9370 + spin_lock(&d->d_lock);
9371 + if (!au_test_anon(d)
9372 + && d->d_parent->d_inode->i_ino == dir_ino) {
9373 + dentry = dget_dlock(d);
9374 + spin_unlock(&d->d_lock);
9377 + spin_unlock(&d->d_lock);
9379 + spin_unlock(&inode->i_lock);
9381 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
9382 + /* need to refresh */
9390 + AuTraceErrPtr(dentry);
9394 +/* ---------------------------------------------------------------------- */
9397 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
9399 +struct au_compare_mnt_args {
9401 + struct super_block *sb;
9404 + struct vfsmount *mnt;
9407 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
9409 + struct au_compare_mnt_args *a = arg;
9411 + if (mnt->mnt_sb != a->sb)
9413 + a->mnt = mntget(mnt);
9417 +static struct vfsmount *au_mnt_get(struct super_block *sb)
9421 + struct au_compare_mnt_args args = {
9425 + get_fs_root(current->fs, &root);
9426 + br_read_lock(&vfsmount_lock);
9427 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
9428 + br_read_unlock(&vfsmount_lock);
9431 + AuDebugOn(!args.mnt);
9435 +struct au_nfsd_si_lock {
9436 + unsigned int sigen;
9437 + aufs_bindex_t bindex, br_id;
9438 + unsigned char force_lock;
9441 +static int si_nfsd_read_lock(struct super_block *sb,
9442 + struct au_nfsd_si_lock *nsi_lock)
9445 + aufs_bindex_t bindex;
9447 + si_read_lock(sb, AuLock_FLUSH);
9449 + /* branch id may be wrapped around */
9451 + bindex = au_br_index(sb, nsi_lock->br_id);
9452 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
9453 + goto out; /* success */
9457 + if (!nsi_lock->force_lock)
9458 + si_read_unlock(sb);
9461 + nsi_lock->bindex = bindex;
9465 +struct find_name_by_ino {
9466 + int called, found;
9473 +find_name_by_ino(void *arg, const char *name, int namelen, loff_t offset,
9474 + u64 ino, unsigned int d_type)
9476 + struct find_name_by_ino *a = arg;
9479 + if (a->ino != ino)
9482 + memcpy(a->name, name, namelen);
9483 + a->namelen = namelen;
9488 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
9489 + struct au_nfsd_si_lock *nsi_lock)
9491 + struct dentry *dentry, *parent;
9492 + struct file *file;
9493 + struct inode *dir;
9494 + struct find_name_by_ino arg;
9497 + parent = path->dentry;
9499 + si_read_unlock(parent->d_sb);
9500 + file = vfsub_dentry_open(path, au_dir_roflags);
9501 + dentry = (void *)file;
9505 + dentry = ERR_PTR(-ENOMEM);
9506 + arg.name = __getname_gfp(GFP_NOFS);
9507 + if (unlikely(!arg.name))
9514 + err = vfsub_readdir(file, find_name_by_ino, &arg);
9515 + } while (!err && !arg.found && arg.called);
9516 + dentry = ERR_PTR(err);
9517 + if (unlikely(err))
9519 + dentry = ERR_PTR(-ENOENT);
9523 + /* do not call au_lkup_one() */
9524 + dir = parent->d_inode;
9525 + mutex_lock(&dir->i_mutex);
9526 + dentry = vfsub_lookup_one_len(arg.name, parent, arg.namelen);
9527 + mutex_unlock(&dir->i_mutex);
9528 + AuTraceErrPtr(dentry);
9529 + if (IS_ERR(dentry))
9531 + AuDebugOn(au_test_anon(dentry));
9532 + if (unlikely(!dentry->d_inode)) {
9534 + dentry = ERR_PTR(-ENOENT);
9538 + __putname(arg.name);
9542 + if (unlikely(nsi_lock
9543 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
9544 + if (!IS_ERR(dentry)) {
9546 + dentry = ERR_PTR(-ESTALE);
9548 + AuTraceErrPtr(dentry);
9552 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
9554 + struct au_nfsd_si_lock *nsi_lock)
9556 + struct dentry *dentry;
9559 + if (dir_ino != AUFS_ROOT_INO) {
9560 + path.dentry = decode_by_ino(sb, dir_ino, 0);
9561 + dentry = path.dentry;
9562 + if (!path.dentry || IS_ERR(path.dentry))
9564 + AuDebugOn(au_test_anon(path.dentry));
9566 + path.dentry = dget(sb->s_root);
9568 + path.mnt = au_mnt_get(sb);
9569 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
9573 + AuTraceErrPtr(dentry);
9577 +/* ---------------------------------------------------------------------- */
9579 +static int h_acceptable(void *expv, struct dentry *dentry)
9584 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
9585 + char *buf, int len, struct super_block *sb)
9591 + p = d_path(h_rootpath, buf, len);
9596 + path.mnt = h_rootpath->mnt;
9597 + path.dentry = h_parent;
9598 + p = d_path(&path, buf, len);
9604 + path.mnt = au_mnt_get(sb);
9605 + path.dentry = sb->s_root;
9606 + p = d_path(&path, buf, len - strlen(p));
9611 + p[strlen(p)] = '/';
9619 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
9620 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
9622 + struct dentry *dentry, *h_parent, *root;
9623 + struct super_block *h_sb;
9624 + char *pathname, *p;
9625 + struct vfsmount *h_mnt;
9626 + struct au_branch *br;
9630 + br = au_sbr(sb, nsi_lock->bindex);
9631 + h_mnt = br->br_mnt;
9632 + h_sb = h_mnt->mnt_sb;
9633 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
9634 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
9635 + fh_len - Fh_tail, fh[Fh_h_type],
9636 + h_acceptable, /*context*/NULL);
9637 + dentry = h_parent;
9638 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
9639 + AuWarn1("%s decode_fh failed, %ld\n",
9640 + au_sbtype(h_sb), PTR_ERR(h_parent));
9644 + if (unlikely(au_test_anon(h_parent))) {
9645 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
9647 + goto out_h_parent;
9650 + dentry = ERR_PTR(-ENOMEM);
9651 + pathname = (void *)__get_free_page(GFP_NOFS);
9652 + if (unlikely(!pathname))
9653 + goto out_h_parent;
9655 + root = sb->s_root;
9657 + di_read_lock_parent(root, !AuLock_IR);
9658 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
9659 + di_read_unlock(root, !AuLock_IR);
9660 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
9661 + dentry = (void *)p;
9663 + goto out_pathname;
9665 + si_read_unlock(sb);
9666 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
9667 + dentry = ERR_PTR(err);
9668 + if (unlikely(err))
9671 + dentry = ERR_PTR(-ENOENT);
9672 + AuDebugOn(au_test_anon(path.dentry));
9673 + if (unlikely(!path.dentry->d_inode))
9676 + if (ino != path.dentry->d_inode->i_ino)
9677 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
9679 + dentry = dget(path.dentry);
9684 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
9685 + if (!IS_ERR(dentry)) {
9687 + dentry = ERR_PTR(-ESTALE);
9690 + free_page((unsigned long)pathname);
9694 + AuTraceErrPtr(dentry);
9698 +/* ---------------------------------------------------------------------- */
9700 +static struct dentry *
9701 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
9704 + struct dentry *dentry;
9705 + __u32 *fh = fid->raw;
9706 + struct au_branch *br;
9707 + ino_t ino, dir_ino;
9708 + struct au_nfsd_si_lock nsi_lock = {
9712 + dentry = ERR_PTR(-ESTALE);
9713 + /* it should never happen, but the file handle is unreliable */
9714 + if (unlikely(fh_len < Fh_tail))
9716 + nsi_lock.sigen = fh[Fh_sigen];
9717 + nsi_lock.br_id = fh[Fh_br_id];
9719 + /* branch id may be wrapped around */
9721 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
9723 + nsi_lock.force_lock = 1;
9725 + /* is this inode still cached? */
9726 + ino = decode_ino(fh + Fh_ino);
9727 + /* it should never happen */
9728 + if (unlikely(ino == AUFS_ROOT_INO))
9731 + dir_ino = decode_ino(fh + Fh_dir_ino);
9732 + dentry = decode_by_ino(sb, ino, dir_ino);
9733 + if (IS_ERR(dentry))
9738 + /* is the parent dir cached? */
9739 + br = au_sbr(sb, nsi_lock.bindex);
9740 + atomic_inc(&br->br_count);
9741 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
9742 + if (IS_ERR(dentry))
9748 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
9749 + if (IS_ERR(dentry))
9751 + if (unlikely(!dentry))
9752 + /* todo?: make it ESTALE */
9756 + if (!au_digen_test(dentry, au_sigen(sb))
9757 + && dentry->d_inode->i_generation == fh[Fh_igen])
9758 + goto out_unlock; /* success */
9761 + dentry = ERR_PTR(-ESTALE);
9764 + atomic_dec(&br->br_count);
9765 + si_read_unlock(sb);
9767 + AuTraceErrPtr(dentry);
9771 +#if 0 /* reserved for future use */
9772 +/* support subtreecheck option */
9773 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
9774 + int fh_len, int fh_type)
9776 + struct dentry *parent;
9777 + __u32 *fh = fid->raw;
9780 + dir_ino = decode_ino(fh + Fh_dir_ino);
9781 + parent = decode_by_ino(sb, dir_ino, 0);
9782 + if (IS_ERR(parent))
9785 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
9786 + dir_ino, fh, fh_len);
9789 + AuTraceErrPtr(parent);
9794 +/* ---------------------------------------------------------------------- */
9796 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
9797 + struct inode *dir)
9800 + aufs_bindex_t bindex;
9801 + struct super_block *sb, *h_sb;
9802 + struct dentry *dentry, *parent, *h_parent;
9803 + struct inode *h_dir;
9804 + struct au_branch *br;
9807 + if (unlikely(*max_len <= Fh_tail)) {
9808 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
9812 + err = FILEID_ROOT;
9813 + if (inode->i_ino == AUFS_ROOT_INO) {
9814 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
9820 + err = si_read_lock(sb, AuLock_FLUSH);
9821 + if (unlikely(err))
9824 +#ifdef CONFIG_AUFS_DEBUG
9825 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
9826 + AuWarn1("NFS-exporting requires xino\n");
9830 + ii_read_lock_child(inode);
9831 + bindex = au_ibstart(inode);
9833 + dentry = d_find_alias(inode);
9834 + if (unlikely(!dentry))
9836 + AuDebugOn(au_test_anon(dentry));
9837 + parent = dget_parent(dentry);
9839 + if (unlikely(!parent))
9841 + dir = parent->d_inode;
9844 + ii_read_lock_parent(dir);
9845 + h_dir = au_h_iptr(dir, bindex);
9846 + ii_read_unlock(dir);
9847 + if (unlikely(!h_dir))
9849 + h_parent = d_find_alias(h_dir);
9850 + if (unlikely(!h_parent))
9854 + br = au_sbr(sb, bindex);
9855 + h_sb = br->br_mnt->mnt_sb;
9856 + if (unlikely(!h_sb->s_export_op)) {
9857 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
9861 + fh[Fh_br_id] = br->br_id;
9862 + fh[Fh_sigen] = au_sigen(sb);
9863 + encode_ino(fh + Fh_ino, inode->i_ino);
9864 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
9865 + fh[Fh_igen] = inode->i_generation;
9867 + *max_len -= Fh_tail;
9868 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
9870 + /*connectable or subtreecheck*/0);
9871 + err = fh[Fh_h_type];
9872 + *max_len += Fh_tail;
9873 + /* todo: macros? */
9877 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
9884 + ii_read_unlock(inode);
9885 + si_read_unlock(sb);
9887 + if (unlikely(err < 0))
9892 +/* ---------------------------------------------------------------------- */
9894 +static int aufs_commit_metadata(struct inode *inode)
9897 + aufs_bindex_t bindex;
9898 + struct super_block *sb;
9899 + struct inode *h_inode;
9900 + int (*f)(struct inode *inode);
9903 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
9904 + ii_write_lock_child(inode);
9905 + bindex = au_ibstart(inode);
9906 + AuDebugOn(bindex < 0);
9907 + h_inode = au_h_iptr(inode, bindex);
9909 + f = h_inode->i_sb->s_export_op->commit_metadata;
9913 + struct writeback_control wbc = {
9914 + .sync_mode = WB_SYNC_ALL,
9915 + .nr_to_write = 0 /* metadata only */
9918 + err = sync_inode(h_inode, &wbc);
9921 + au_cpup_attr_timesizes(inode);
9922 + ii_write_unlock(inode);
9923 + si_read_unlock(sb);
9927 +/* ---------------------------------------------------------------------- */
9929 +static struct export_operations aufs_export_op = {
9930 + .fh_to_dentry = aufs_fh_to_dentry,
9931 + /* .fh_to_parent = aufs_fh_to_parent, */
9932 + .encode_fh = aufs_encode_fh,
9933 + .commit_metadata = aufs_commit_metadata
9936 +void au_export_init(struct super_block *sb)
9938 + struct au_sbinfo *sbinfo;
9941 + sb->s_export_op = &aufs_export_op;
9942 + sbinfo = au_sbi(sb);
9943 + sbinfo->si_xigen = NULL;
9944 + get_random_bytes(&u, sizeof(u));
9945 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
9946 + atomic_set(&sbinfo->si_xigen_next, u);
9948 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
9949 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
9950 +++ linux/fs/aufs/file.c 2012-07-22 19:57:03.164337936 +0200
9953 + * Copyright (C) 2005-2012 Junjiro R. Okajima
9955 + * This program, aufs is free software; you can redistribute it and/or modify
9956 + * it under the terms of the GNU General Public License as published by
9957 + * the Free Software Foundation; either version 2 of the License, or
9958 + * (at your option) any later version.
9960 + * This program is distributed in the hope that it will be useful,
9961 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9962 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9963 + * GNU General Public License for more details.
9965 + * You should have received a copy of the GNU General Public License
9966 + * along with this program; if not, write to the Free Software
9967 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
9971 + * handling file/dir, and address_space operation
9974 +#ifdef CONFIG_AUFS_DEBUG
9975 +#include <linux/migrate.h>
9977 +#include <linux/pagemap.h>
9980 +/* drop flags for writing */
9981 +unsigned int au_file_roflags(unsigned int flags)
9983 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
9984 + flags |= O_RDONLY | O_NOATIME;
9988 +/* common functions to regular file and dir */
9989 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
9990 + struct file *file)
9992 + struct file *h_file;
9993 + struct dentry *h_dentry;
9994 + struct inode *h_inode;
9995 + struct super_block *sb;
9996 + struct au_branch *br;
9997 + struct path h_path;
9998 + int err, exec_flag;
10000 + /* a race condition can happen between open and unlink/rmdir */
10001 + h_file = ERR_PTR(-ENOENT);
10002 + h_dentry = au_h_dptr(dentry, bindex);
10003 + if (au_test_nfsd() && !h_dentry)
10005 + h_inode = h_dentry->d_inode;
10006 + if (au_test_nfsd() && !h_inode)
10008 + spin_lock(&h_dentry->d_lock);
10009 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
10011 + /* || !dentry->d_inode->i_nlink */
10013 + spin_unlock(&h_dentry->d_lock);
10014 + if (unlikely(err))
10017 + sb = dentry->d_sb;
10018 + br = au_sbr(sb, bindex);
10019 + h_file = ERR_PTR(-EACCES);
10020 + exec_flag = flags & __FMODE_EXEC;
10021 + if (exec_flag && (br->br_mnt->mnt_flags & MNT_NOEXEC))
10024 + /* drop flags for writing */
10025 + if (au_test_ro(sb, bindex, dentry->d_inode))
10026 + flags = au_file_roflags(flags);
10027 + flags &= ~O_CREAT;
10028 + atomic_inc(&br->br_count);
10029 + h_path.dentry = h_dentry;
10030 + h_path.mnt = br->br_mnt;
10031 + if (!au_special_file(h_inode->i_mode))
10032 + h_file = vfsub_dentry_open(&h_path, flags);
10034 + /* this block depends upon the configuration */
10035 + di_read_unlock(dentry, AuLock_IR);
10036 + fi_write_unlock(file);
10037 + si_read_unlock(sb);
10038 + h_file = vfsub_dentry_open(&h_path, flags);
10039 + si_noflush_read_lock(sb);
10040 + fi_write_lock(file);
10041 + di_read_lock_child(dentry, AuLock_IR);
10043 + if (IS_ERR(h_file))
10047 + err = deny_write_access(h_file);
10048 + if (unlikely(err)) {
10050 + h_file = ERR_PTR(err);
10054 + fsnotify_open(h_file);
10055 + goto out; /* success */
10058 + atomic_dec(&br->br_count);
10063 +int au_do_open(struct file *file, int (*open)(struct file *file, int flags),
10064 + struct au_fidir *fidir)
10067 + struct dentry *dentry;
10069 + err = au_finfo_init(file, fidir);
10070 + if (unlikely(err))
10073 + dentry = file->f_dentry;
10074 + di_read_lock_child(dentry, AuLock_IR);
10075 + err = open(file, vfsub_file_flags(file));
10076 + di_read_unlock(dentry, AuLock_IR);
10078 + fi_write_unlock(file);
10079 + if (unlikely(err)) {
10080 + au_fi(file)->fi_hdir = NULL;
10081 + au_finfo_fin(file);
10088 +int au_reopen_nondir(struct file *file)
10091 + aufs_bindex_t bstart;
10092 + struct dentry *dentry;
10093 + struct file *h_file, *h_file_tmp;
10095 + dentry = file->f_dentry;
10096 + AuDebugOn(au_special_file(dentry->d_inode->i_mode));
10097 + bstart = au_dbstart(dentry);
10098 + h_file_tmp = NULL;
10099 + if (au_fbstart(file) == bstart) {
10100 + h_file = au_hf_top(file);
10101 + if (file->f_mode == h_file->f_mode)
10102 + return 0; /* success */
10103 + h_file_tmp = h_file;
10104 + get_file(h_file_tmp);
10105 + au_set_h_fptr(file, bstart, NULL);
10107 + AuDebugOn(au_fi(file)->fi_hdir);
10108 + AuDebugOn(au_fbstart(file) < bstart);
10110 + h_file = au_h_open(dentry, bstart, vfsub_file_flags(file) & ~O_TRUNC,
10112 + err = PTR_ERR(h_file);
10113 + if (IS_ERR(h_file))
10114 + goto out; /* todo: close all? */
10117 + au_set_fbstart(file, bstart);
10118 + au_set_h_fptr(file, bstart, h_file);
10119 + au_update_figen(file);
10120 + /* todo: necessary? */
10121 + /* file->f_ra = h_file->f_ra; */
10125 + fput(h_file_tmp);
10129 +/* ---------------------------------------------------------------------- */
10131 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
10132 + struct dentry *hi_wh)
10135 + aufs_bindex_t bstart;
10136 + struct au_dinfo *dinfo;
10137 + struct dentry *h_dentry;
10138 + struct au_hdentry *hdp;
10140 + dinfo = au_di(file->f_dentry);
10141 + AuRwMustWriteLock(&dinfo->di_rwsem);
10143 + bstart = dinfo->di_bstart;
10144 + dinfo->di_bstart = btgt;
10145 + hdp = dinfo->di_hdentry;
10146 + h_dentry = hdp[0 + btgt].hd_dentry;
10147 + hdp[0 + btgt].hd_dentry = hi_wh;
10148 + err = au_reopen_nondir(file);
10149 + hdp[0 + btgt].hd_dentry = h_dentry;
10150 + dinfo->di_bstart = bstart;
10155 +static int au_ready_to_write_wh(struct file *file, loff_t len,
10156 + aufs_bindex_t bcpup)
10159 + struct inode *inode, *h_inode;
10160 + struct dentry *dentry, *h_dentry, *hi_wh;
10162 + dentry = file->f_dentry;
10163 + au_update_dbstart(dentry);
10164 + inode = dentry->d_inode;
10166 + if (au_dbstart(dentry) <= bcpup && au_dbend(dentry) >= bcpup) {
10167 + h_dentry = au_h_dptr(dentry, bcpup);
10169 + h_inode = h_dentry->d_inode;
10171 + hi_wh = au_hi_wh(inode, bcpup);
10172 + if (!hi_wh && !h_inode)
10173 + err = au_sio_cpup_wh(dentry, bcpup, len, file);
10175 + /* already copied-up after unlink */
10176 + err = au_reopen_wh(file, bcpup, hi_wh);
10179 + && inode->i_nlink > 1
10180 + && au_opt_test(au_mntflags(dentry->d_sb), PLINK))
10181 + au_plink_append(inode, bcpup, au_h_dptr(dentry, bcpup));
10187 + * prepare the @file for writing.
10189 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
10192 + aufs_bindex_t bstart, bcpup, dbstart;
10193 + struct dentry *dentry, *parent, *h_dentry;
10194 + struct inode *h_inode, *inode;
10195 + struct super_block *sb;
10196 + struct file *h_file;
10198 + dentry = file->f_dentry;
10199 + sb = dentry->d_sb;
10200 + inode = dentry->d_inode;
10201 + AuDebugOn(au_special_file(inode->i_mode));
10202 + bstart = au_fbstart(file);
10203 + err = au_test_ro(sb, bstart, inode);
10204 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
10205 + err = au_pin(pin, dentry, bstart, AuOpt_UDBA_NONE, /*flags*/0);
10209 + /* need to cpup or reopen */
10210 + parent = dget_parent(dentry);
10211 + di_write_lock_parent(parent);
10212 + err = AuWbrCopyup(au_sbi(sb), dentry);
10214 + if (unlikely(err < 0))
10218 + if (!d_unhashed(dentry) && !au_h_dptr(parent, bcpup)) {
10219 + err = au_cpup_dirs(dentry, bcpup);
10220 + if (unlikely(err))
10224 + err = au_pin(pin, dentry, bcpup, AuOpt_UDBA_NONE,
10225 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
10226 + if (unlikely(err))
10229 + h_dentry = au_hf_top(file)->f_dentry;
10230 + h_inode = h_dentry->d_inode;
10231 + dbstart = au_dbstart(dentry);
10232 + if (dbstart <= bcpup) {
10233 + h_dentry = au_h_dptr(dentry, bcpup);
10234 + AuDebugOn(!h_dentry);
10235 + h_inode = h_dentry->d_inode;
10236 + AuDebugOn(!h_inode);
10240 + if (dbstart <= bcpup /* just reopen */
10241 + || !d_unhashed(dentry) /* copyup and reopen */
10243 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
10244 + h_file = au_h_open_pre(dentry, bstart);
10245 + if (IS_ERR(h_file)) {
10246 + err = PTR_ERR(h_file);
10249 + di_downgrade_lock(parent, AuLock_IR);
10250 + if (dbstart > bcpup)
10251 + err = au_sio_cpup_simple(dentry, bcpup, len,
10254 + err = au_reopen_nondir(file);
10256 + mutex_unlock(&h_inode->i_mutex);
10257 + au_h_open_post(dentry, bstart, h_file);
10258 + } else { /* copyup as wh and reopen */
10260 + * since writable hfsplus branch is not supported,
10261 + * h_open_pre/post() are unnecessary.
10263 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
10264 + err = au_ready_to_write_wh(file, len, bcpup);
10265 + di_downgrade_lock(parent, AuLock_IR);
10266 + mutex_unlock(&h_inode->i_mutex);
10270 + au_pin_set_parent_lflag(pin, /*lflag*/0);
10271 + goto out_dput; /* success */
10277 + di_downgrade_lock(parent, AuLock_IR);
10279 + di_read_unlock(parent, AuLock_IR);
10286 +/* ---------------------------------------------------------------------- */
10288 +int au_do_flush(struct file *file, fl_owner_t id,
10289 + int (*flush)(struct file *file, fl_owner_t id))
10292 + struct dentry *dentry;
10293 + struct super_block *sb;
10294 + struct inode *inode;
10296 + dentry = file->f_dentry;
10297 + sb = dentry->d_sb;
10298 + inode = dentry->d_inode;
10299 + si_noflush_read_lock(sb);
10300 + fi_read_lock(file);
10301 + ii_read_lock_child(inode);
10303 + err = flush(file, id);
10304 + au_cpup_attr_timesizes(inode);
10306 + ii_read_unlock(inode);
10307 + fi_read_unlock(file);
10308 + si_read_unlock(sb);
10312 +/* ---------------------------------------------------------------------- */
10314 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
10317 + aufs_bindex_t bstart;
10318 + struct au_pin pin;
10319 + struct au_finfo *finfo;
10320 + struct dentry *dentry, *parent, *hi_wh;
10321 + struct inode *inode;
10322 + struct super_block *sb;
10324 + FiMustWriteLock(file);
10327 + finfo = au_fi(file);
10328 + dentry = file->f_dentry;
10329 + sb = dentry->d_sb;
10330 + inode = dentry->d_inode;
10331 + bstart = au_ibstart(inode);
10332 + if (bstart == finfo->fi_btop || IS_ROOT(dentry))
10335 + parent = dget_parent(dentry);
10336 + if (au_test_ro(sb, bstart, inode)) {
10337 + di_read_lock_parent(parent, !AuLock_IR);
10338 + err = AuWbrCopyup(au_sbi(sb), dentry);
10340 + di_read_unlock(parent, !AuLock_IR);
10341 + if (unlikely(err < 0))
10346 + di_read_lock_parent(parent, AuLock_IR);
10347 + hi_wh = au_hi_wh(inode, bstart);
10348 + if (!S_ISDIR(inode->i_mode)
10349 + && au_opt_test(au_mntflags(sb), PLINK)
10350 + && au_plink_test(inode)
10351 + && !d_unhashed(dentry)) {
10352 + err = au_test_and_cpup_dirs(dentry, bstart);
10353 + if (unlikely(err))
10356 + /* always superio. */
10357 + err = au_pin(&pin, dentry, bstart, AuOpt_UDBA_NONE,
10358 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
10360 + err = au_sio_cpup_simple(dentry, bstart, -1,
10363 + } else if (hi_wh) {
10364 + /* already copied-up after unlink */
10365 + err = au_reopen_wh(file, bstart, hi_wh);
10366 + *need_reopen = 0;
10370 + di_read_unlock(parent, AuLock_IR);
10377 +static void au_do_refresh_dir(struct file *file)
10379 + aufs_bindex_t bindex, bend, new_bindex, brid;
10380 + struct au_hfile *p, tmp, *q;
10381 + struct au_finfo *finfo;
10382 + struct super_block *sb;
10383 + struct au_fidir *fidir;
10385 + FiMustWriteLock(file);
10387 + sb = file->f_dentry->d_sb;
10388 + finfo = au_fi(file);
10389 + fidir = finfo->fi_hdir;
10390 + AuDebugOn(!fidir);
10391 + p = fidir->fd_hfile + finfo->fi_btop;
10392 + brid = p->hf_br->br_id;
10393 + bend = fidir->fd_bbot;
10394 + for (bindex = finfo->fi_btop; bindex <= bend; bindex++, p++) {
10398 + new_bindex = au_br_index(sb, p->hf_br->br_id);
10399 + if (new_bindex == bindex)
10401 + if (new_bindex < 0) {
10402 + au_set_h_fptr(file, bindex, NULL);
10406 + /* swap two lower inode, and loop again */
10407 + q = fidir->fd_hfile + new_bindex;
10411 + if (tmp.hf_file) {
10417 + p = fidir->fd_hfile;
10418 + if (!au_test_mmapped(file) && !d_unlinked(file->f_dentry)) {
10419 + bend = au_sbend(sb);
10420 + for (finfo->fi_btop = 0; finfo->fi_btop <= bend;
10421 + finfo->fi_btop++, p++)
10422 + if (p->hf_file) {
10423 + if (p->hf_file->f_dentry
10424 + && p->hf_file->f_dentry->d_inode)
10427 + au_hfput(p, file);
10430 + bend = au_br_index(sb, brid);
10431 + for (finfo->fi_btop = 0; finfo->fi_btop < bend;
10432 + finfo->fi_btop++, p++)
10434 + au_hfput(p, file);
10435 + bend = au_sbend(sb);
10438 + p = fidir->fd_hfile + bend;
10439 + for (fidir->fd_bbot = bend; fidir->fd_bbot >= finfo->fi_btop;
10440 + fidir->fd_bbot--, p--)
10441 + if (p->hf_file) {
10442 + if (p->hf_file->f_dentry
10443 + && p->hf_file->f_dentry->d_inode)
10446 + au_hfput(p, file);
10448 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
10452 + * after branch manipulating, refresh the file.
10454 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
10456 + int err, need_reopen;
10457 + aufs_bindex_t bend, bindex;
10458 + struct dentry *dentry;
10459 + struct au_finfo *finfo;
10460 + struct au_hfile *hfile;
10462 + dentry = file->f_dentry;
10463 + finfo = au_fi(file);
10464 + if (!finfo->fi_hdir) {
10465 + hfile = &finfo->fi_htop;
10466 + AuDebugOn(!hfile->hf_file);
10467 + bindex = au_br_index(dentry->d_sb, hfile->hf_br->br_id);
10468 + AuDebugOn(bindex < 0);
10469 + if (bindex != finfo->fi_btop)
10470 + au_set_fbstart(file, bindex);
10472 + err = au_fidir_realloc(finfo, au_sbend(dentry->d_sb) + 1);
10473 + if (unlikely(err))
10475 + au_do_refresh_dir(file);
10480 + if (!au_test_mmapped(file))
10481 + err = au_file_refresh_by_inode(file, &need_reopen);
10482 + if (!err && need_reopen && !d_unlinked(dentry))
10483 + err = reopen(file);
10485 + au_update_figen(file);
10486 + goto out; /* success */
10489 + /* error, close all lower files */
10490 + if (finfo->fi_hdir) {
10491 + bend = au_fbend_dir(file);
10492 + for (bindex = au_fbstart(file); bindex <= bend; bindex++)
10493 + au_set_h_fptr(file, bindex, NULL);
10500 +/* common function to regular file and dir */
10501 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
10505 + unsigned int sigen, figen;
10506 + aufs_bindex_t bstart;
10507 + unsigned char pseudo_link;
10508 + struct dentry *dentry;
10509 + struct inode *inode;
10512 + dentry = file->f_dentry;
10513 + inode = dentry->d_inode;
10514 + AuDebugOn(au_special_file(inode->i_mode));
10515 + sigen = au_sigen(dentry->d_sb);
10516 + fi_write_lock(file);
10517 + figen = au_figen(file);
10518 + di_write_lock_child(dentry);
10519 + bstart = au_dbstart(dentry);
10520 + pseudo_link = (bstart != au_ibstart(inode));
10521 + if (sigen == figen && !pseudo_link && au_fbstart(file) == bstart) {
10523 + di_downgrade_lock(dentry, AuLock_IR);
10524 + fi_downgrade_lock(file);
10526 + goto out; /* success */
10529 + AuDbg("sigen %d, figen %d\n", sigen, figen);
10530 + if (au_digen_test(dentry, sigen)) {
10531 + err = au_reval_dpath(dentry, sigen);
10532 + AuDebugOn(!err && au_digen_test(dentry, sigen));
10536 + err = refresh_file(file, reopen);
10539 + di_downgrade_lock(dentry, AuLock_IR);
10540 + fi_downgrade_lock(file);
10543 + di_write_unlock(dentry);
10544 + fi_write_unlock(file);
10551 +/* ---------------------------------------------------------------------- */
10553 +/* cf. aufs_nopage() */
10554 +/* for madvise(2) */
10555 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
10557 + unlock_page(page);
10561 +/* it will never be called, but necessary to support O_DIRECT */
10562 +static ssize_t aufs_direct_IO(int rw, struct kiocb *iocb,
10563 + const struct iovec *iov, loff_t offset,
10564 + unsigned long nr_segs)
10565 +{ BUG(); return 0; }
10568 + * it will never be called, but madvise and fadvise behaves differently
10569 + * when get_xip_mem is defined
10571 +static int aufs_get_xip_mem(struct address_space *mapping, pgoff_t pgoff,
10572 + int create, void **kmem, unsigned long *pfn)
10573 +{ BUG(); return 0; }
10575 +/* they will never be called. */
10576 +#ifdef CONFIG_AUFS_DEBUG
10577 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
10578 + loff_t pos, unsigned len, unsigned flags,
10579 + struct page **pagep, void **fsdata)
10580 +{ AuUnsupport(); return 0; }
10581 +static int aufs_write_end(struct file *file, struct address_space *mapping,
10582 + loff_t pos, unsigned len, unsigned copied,
10583 + struct page *page, void *fsdata)
10584 +{ AuUnsupport(); return 0; }
10585 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
10586 +{ AuUnsupport(); return 0; }
10588 +static int aufs_set_page_dirty(struct page *page)
10589 +{ AuUnsupport(); return 0; }
10590 +static void aufs_invalidatepage(struct page *page, unsigned long offset)
10591 +{ AuUnsupport(); }
10592 +static int aufs_releasepage(struct page *page, gfp_t gfp)
10593 +{ AuUnsupport(); return 0; }
10594 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
10595 + struct page *page, enum migrate_mode mode)
10596 +{ AuUnsupport(); return 0; }
10597 +static int aufs_launder_page(struct page *page)
10598 +{ AuUnsupport(); return 0; }
10599 +static int aufs_is_partially_uptodate(struct page *page,
10600 + read_descriptor_t *desc,
10601 + unsigned long from)
10602 +{ AuUnsupport(); return 0; }
10603 +static int aufs_error_remove_page(struct address_space *mapping,
10604 + struct page *page)
10605 +{ AuUnsupport(); return 0; }
10606 +#endif /* CONFIG_AUFS_DEBUG */
10608 +const struct address_space_operations aufs_aop = {
10609 + .readpage = aufs_readpage,
10610 + .direct_IO = aufs_direct_IO,
10611 + .get_xip_mem = aufs_get_xip_mem,
10612 +#ifdef CONFIG_AUFS_DEBUG
10613 + .writepage = aufs_writepage,
10614 + /* no writepages, because of writepage */
10615 + .set_page_dirty = aufs_set_page_dirty,
10616 + /* no readpages, because of readpage */
10617 + .write_begin = aufs_write_begin,
10618 + .write_end = aufs_write_end,
10619 + /* no bmap, no block device */
10620 + .invalidatepage = aufs_invalidatepage,
10621 + .releasepage = aufs_releasepage,
10622 + .migratepage = aufs_migratepage,
10623 + .launder_page = aufs_launder_page,
10624 + .is_partially_uptodate = aufs_is_partially_uptodate,
10625 + .error_remove_page = aufs_error_remove_page
10626 +#endif /* CONFIG_AUFS_DEBUG */
10628 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
10629 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
10630 +++ linux/fs/aufs/file.h 2012-07-22 19:57:03.164337936 +0200
10633 + * Copyright (C) 2005-2012 Junjiro R. Okajima
10635 + * This program, aufs is free software; you can redistribute it and/or modify
10636 + * it under the terms of the GNU General Public License as published by
10637 + * the Free Software Foundation; either version 2 of the License, or
10638 + * (at your option) any later version.
10640 + * This program is distributed in the hope that it will be useful,
10641 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10642 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10643 + * GNU General Public License for more details.
10645 + * You should have received a copy of the GNU General Public License
10646 + * along with this program; if not, write to the Free Software
10647 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
10651 + * file operations
10654 +#ifndef __AUFS_FILE_H__
10655 +#define __AUFS_FILE_H__
10659 +#include <linux/file.h>
10660 +#include <linux/fs.h>
10661 +#include <linux/poll.h>
10662 +#include "rwsem.h"
10666 + struct file *hf_file;
10667 + struct au_branch *hf_br;
10672 + aufs_bindex_t fd_bbot;
10673 + aufs_bindex_t fd_nent;
10674 + struct au_vdir *fd_vdir_cache;
10675 + struct au_hfile fd_hfile[];
10678 +static inline int au_fidir_sz(int nent)
10680 + AuDebugOn(nent < 0);
10681 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
10685 + atomic_t fi_generation;
10687 + struct au_rwsem fi_rwsem;
10688 + aufs_bindex_t fi_btop;
10690 + /* do not union them */
10691 + struct { /* for non-dir */
10692 + struct au_hfile fi_htop;
10693 + atomic_t fi_mmapped;
10695 + struct au_fidir *fi_hdir; /* for dir only */
10696 +} ____cacheline_aligned_in_smp;
10698 +/* ---------------------------------------------------------------------- */
10701 +extern const struct address_space_operations aufs_aop;
10702 +unsigned int au_file_roflags(unsigned int flags);
10703 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
10704 + struct file *file);
10705 +int au_do_open(struct file *file, int (*open)(struct file *file, int flags),
10706 + struct au_fidir *fidir);
10707 +int au_reopen_nondir(struct file *file);
10709 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
10710 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
10712 +int au_do_flush(struct file *file, fl_owner_t id,
10713 + int (*flush)(struct file *file, fl_owner_t id));
10715 +#if defined(CONFIG_SECURITY) && defined(CONFIG_MMU)
10717 +int au_security_mmap_file(struct file *h_file, struct vm_area_struct *vma);
10719 +AuStubInt0(au_security_mmap_file, struct file *h_file,
10720 + struct vm_area_struct *vma);
10724 +#ifdef CONFIG_AUFS_POLL
10725 +unsigned int aufs_poll(struct file *file, poll_table *wait);
10728 +#ifdef CONFIG_AUFS_BR_HFSPLUS
10730 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex);
10731 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
10732 + struct file *h_file);
10735 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex)
10740 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
10741 + struct file *h_file);
10745 +extern const struct file_operations aufs_file_fop;
10746 +int au_do_open_nondir(struct file *file, int flags);
10747 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
10749 +#ifdef CONFIG_AUFS_SP_IATTR
10751 +int au_special_file(umode_t mode);
10752 +void au_init_special_fop(struct inode *inode, umode_t mode, dev_t rdev);
10754 +AuStubInt0(au_special_file, umode_t mode)
10755 +static inline void au_init_special_fop(struct inode *inode, umode_t mode,
10758 + init_special_inode(inode, mode, rdev);
10763 +void au_hfput(struct au_hfile *hf, struct file *file);
10764 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
10765 + struct file *h_file);
10767 +void au_update_figen(struct file *file);
10768 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
10769 +int au_fidir_realloc(struct au_finfo *finfo, int nbr);
10771 +void au_fi_init_once(void *_fi);
10772 +void au_finfo_fin(struct file *file);
10773 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
10776 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
10777 +#ifdef CONFIG_COMPAT
10778 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
10779 + unsigned long arg);
10782 +/* ---------------------------------------------------------------------- */
10784 +static inline struct au_finfo *au_fi(struct file *file)
10786 + return file->private_data;
10789 +/* ---------------------------------------------------------------------- */
10792 + * fi_read_lock, fi_write_lock,
10793 + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock
10795 +AuSimpleRwsemFuncs(fi, struct file *f, &au_fi(f)->fi_rwsem);
10797 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
10798 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
10799 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
10801 +/* ---------------------------------------------------------------------- */
10803 +/* todo: hard/soft set? */
10804 +static inline aufs_bindex_t au_fbstart(struct file *file)
10806 + FiMustAnyLock(file);
10807 + return au_fi(file)->fi_btop;
10810 +static inline aufs_bindex_t au_fbend_dir(struct file *file)
10812 + FiMustAnyLock(file);
10813 + AuDebugOn(!au_fi(file)->fi_hdir);
10814 + return au_fi(file)->fi_hdir->fd_bbot;
10817 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
10819 + FiMustAnyLock(file);
10820 + AuDebugOn(!au_fi(file)->fi_hdir);
10821 + return au_fi(file)->fi_hdir->fd_vdir_cache;
10824 +static inline void au_set_fbstart(struct file *file, aufs_bindex_t bindex)
10826 + FiMustWriteLock(file);
10827 + au_fi(file)->fi_btop = bindex;
10830 +static inline void au_set_fbend_dir(struct file *file, aufs_bindex_t bindex)
10832 + FiMustWriteLock(file);
10833 + AuDebugOn(!au_fi(file)->fi_hdir);
10834 + au_fi(file)->fi_hdir->fd_bbot = bindex;
10837 +static inline void au_set_fvdir_cache(struct file *file,
10838 + struct au_vdir *vdir_cache)
10840 + FiMustWriteLock(file);
10841 + AuDebugOn(!au_fi(file)->fi_hdir);
10842 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
10845 +static inline struct file *au_hf_top(struct file *file)
10847 + FiMustAnyLock(file);
10848 + AuDebugOn(au_fi(file)->fi_hdir);
10849 + return au_fi(file)->fi_htop.hf_file;
10852 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
10854 + FiMustAnyLock(file);
10855 + AuDebugOn(!au_fi(file)->fi_hdir);
10856 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
10859 +/* todo: memory barrier? */
10860 +static inline unsigned int au_figen(struct file *f)
10862 + return atomic_read(&au_fi(f)->fi_generation);
10865 +static inline void au_set_mmapped(struct file *f)
10867 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
10869 + pr_warn("fi_mmapped wrapped around\n");
10870 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
10874 +static inline void au_unset_mmapped(struct file *f)
10876 + atomic_dec(&au_fi(f)->fi_mmapped);
10879 +static inline int au_test_mmapped(struct file *f)
10881 + return atomic_read(&au_fi(f)->fi_mmapped);
10884 +/* customize vma->vm_file */
10886 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
10887 + struct file *file)
10891 + f = vma->vm_file;
10893 + vma->vm_file = file;
10898 +#define AuDbgVmRegion(file, vma) do {} while (0)
10900 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
10901 + struct file *file)
10903 + au_do_vm_file_reset(vma, file);
10906 +#define AuDbgVmRegion(file, vma) \
10907 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
10909 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
10910 + struct file *file)
10914 + au_do_vm_file_reset(vma, file);
10915 + f = vma->vm_region->vm_file;
10917 + vma->vm_region->vm_file = file;
10920 +#endif /* CONFIG_MMU */
10922 +/* handle vma->vm_prfile */
10923 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
10924 + struct file *file)
10926 +#ifdef CONFIG_AUFS_PROC_MAP
10928 + vma->vm_prfile = file;
10929 +#ifndef CONFIG_MMU
10931 + vma->vm_region->vm_prfile = file;
10936 +#endif /* __KERNEL__ */
10937 +#endif /* __AUFS_FILE_H__ */
10938 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
10939 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
10940 +++ linux/fs/aufs/finfo.c 2012-07-22 19:57:03.164337936 +0200
10943 + * Copyright (C) 2005-2012 Junjiro R. Okajima
10945 + * This program, aufs is free software; you can redistribute it and/or modify
10946 + * it under the terms of the GNU General Public License as published by
10947 + * the Free Software Foundation; either version 2 of the License, or
10948 + * (at your option) any later version.
10950 + * This program is distributed in the hope that it will be useful,
10951 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10952 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10953 + * GNU General Public License for more details.
10955 + * You should have received a copy of the GNU General Public License
10956 + * along with this program; if not, write to the Free Software
10957 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
10961 + * file private data
10966 +void au_hfput(struct au_hfile *hf, struct file *file)
10968 + /* todo: direct access f_flags */
10969 + if (vfsub_file_flags(file) & __FMODE_EXEC)
10970 + allow_write_access(hf->hf_file);
10971 + fput(hf->hf_file);
10972 + hf->hf_file = NULL;
10973 + atomic_dec(&hf->hf_br->br_count);
10974 + hf->hf_br = NULL;
10977 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
10979 + struct au_finfo *finfo = au_fi(file);
10980 + struct au_hfile *hf;
10981 + struct au_fidir *fidir;
10983 + fidir = finfo->fi_hdir;
10985 + AuDebugOn(finfo->fi_btop != bindex);
10986 + hf = &finfo->fi_htop;
10988 + hf = fidir->fd_hfile + bindex;
10990 + if (hf && hf->hf_file)
10991 + au_hfput(hf, file);
10993 + FiMustWriteLock(file);
10994 + hf->hf_file = val;
10995 + hf->hf_br = au_sbr(file->f_dentry->d_sb, bindex);
10999 +void au_update_figen(struct file *file)
11001 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_dentry));
11002 + /* smp_mb(); */ /* atomic_set */
11005 +/* ---------------------------------------------------------------------- */
11007 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
11009 + struct au_fidir *fidir;
11012 + nbr = au_sbend(sb) + 1;
11014 + nbr = 2; /* initial allocate for 2 branches */
11015 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
11017 + fidir->fd_bbot = -1;
11018 + fidir->fd_nent = nbr;
11019 + fidir->fd_vdir_cache = NULL;
11025 +int au_fidir_realloc(struct au_finfo *finfo, int nbr)
11028 + struct au_fidir *fidir, *p;
11030 + AuRwMustWriteLock(&finfo->fi_rwsem);
11031 + fidir = finfo->fi_hdir;
11032 + AuDebugOn(!fidir);
11035 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
11038 + p->fd_nent = nbr;
11039 + finfo->fi_hdir = p;
11046 +/* ---------------------------------------------------------------------- */
11048 +void au_finfo_fin(struct file *file)
11050 + struct au_finfo *finfo;
11052 + au_nfiles_dec(file->f_dentry->d_sb);
11054 + finfo = au_fi(file);
11055 + AuDebugOn(finfo->fi_hdir);
11056 + AuRwDestroy(&finfo->fi_rwsem);
11057 + au_cache_free_finfo(finfo);
11060 +void au_fi_init_once(void *_finfo)
11062 + struct au_finfo *finfo = _finfo;
11063 + static struct lock_class_key aufs_fi;
11065 + au_rw_init(&finfo->fi_rwsem);
11066 + au_rw_class(&finfo->fi_rwsem, &aufs_fi);
11069 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
11072 + struct au_finfo *finfo;
11073 + struct dentry *dentry;
11076 + dentry = file->f_dentry;
11077 + finfo = au_cache_alloc_finfo();
11078 + if (unlikely(!finfo))
11082 + au_nfiles_inc(dentry->d_sb);
11083 + lc_idx = AuLcNonDir_FIINFO;
11085 + lc_idx = AuLcDir_FIINFO;
11086 + au_rw_class(&finfo->fi_rwsem, au_lc_key + lc_idx);
11087 + au_rw_write_lock(&finfo->fi_rwsem);
11088 + finfo->fi_btop = -1;
11089 + finfo->fi_hdir = fidir;
11090 + atomic_set(&finfo->fi_generation, au_digen(dentry));
11091 + /* smp_mb(); */ /* atomic_set */
11093 + file->private_data = finfo;
11098 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
11099 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
11100 +++ linux/fs/aufs/f_op.c 2012-07-22 19:57:03.164337936 +0200
11103 + * Copyright (C) 2005-2012 Junjiro R. Okajima
11105 + * This program, aufs is free software; you can redistribute it and/or modify
11106 + * it under the terms of the GNU General Public License as published by
11107 + * the Free Software Foundation; either version 2 of the License, or
11108 + * (at your option) any later version.
11110 + * This program is distributed in the hope that it will be useful,
11111 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11112 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11113 + * GNU General Public License for more details.
11115 + * You should have received a copy of the GNU General Public License
11116 + * along with this program; if not, write to the Free Software
11117 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11121 + * file and vm operations
11124 +#include <linux/fs_stack.h>
11125 +#include <linux/mman.h>
11126 +#include <linux/security.h>
11129 +int au_do_open_nondir(struct file *file, int flags)
11132 + aufs_bindex_t bindex;
11133 + struct file *h_file;
11134 + struct dentry *dentry;
11135 + struct au_finfo *finfo;
11137 + FiMustWriteLock(file);
11139 + dentry = file->f_dentry;
11140 + err = au_d_alive(dentry);
11141 + if (unlikely(err))
11144 + finfo = au_fi(file);
11145 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
11146 + atomic_set(&finfo->fi_mmapped, 0);
11147 + bindex = au_dbstart(dentry);
11148 + h_file = au_h_open(dentry, bindex, flags, file);
11149 + if (IS_ERR(h_file))
11150 + err = PTR_ERR(h_file);
11152 + au_set_fbstart(file, bindex);
11153 + au_set_h_fptr(file, bindex, h_file);
11154 + au_update_figen(file);
11155 + /* todo: necessary? */
11156 + /* file->f_ra = h_file->f_ra; */
11163 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
11164 + struct file *file)
11167 + struct super_block *sb;
11169 + AuDbg("%.*s, f_flags 0x%x, f_mode 0x%x\n",
11170 + AuDLNPair(file->f_dentry), vfsub_file_flags(file),
11173 + sb = file->f_dentry->d_sb;
11174 + si_read_lock(sb, AuLock_FLUSH);
11175 + err = au_do_open(file, au_do_open_nondir, /*fidir*/NULL);
11176 + si_read_unlock(sb);
11180 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
11182 + struct au_finfo *finfo;
11183 + aufs_bindex_t bindex;
11185 + finfo = au_fi(file);
11186 + bindex = finfo->fi_btop;
11187 + if (bindex >= 0) {
11188 + /* remove me from sb->s_files */
11189 + file_sb_list_del(file);
11190 + au_set_h_fptr(file, bindex, NULL);
11193 + au_finfo_fin(file);
11197 +/* ---------------------------------------------------------------------- */
11199 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
11202 + struct file *h_file;
11205 + h_file = au_hf_top(file);
11207 + err = vfsub_flush(h_file, id);
11211 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
11213 + return au_do_flush(file, id, au_do_flush_nondir);
11216 +/* ---------------------------------------------------------------------- */
11218 + * read and write functions acquire [fdi]_rwsem once, but release before
11219 + * mmap_sem. This is because to stop a race condition between mmap(2).
11220 + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping
11221 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
11222 + * read functions after [fdi]_rwsem are released, but it should be harmless.
11225 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
11229 + struct dentry *dentry;
11230 + struct file *h_file;
11231 + struct super_block *sb;
11233 + dentry = file->f_dentry;
11234 + sb = dentry->d_sb;
11235 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11236 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
11237 + if (unlikely(err))
11240 + h_file = au_hf_top(file);
11241 + get_file(h_file);
11242 + di_read_unlock(dentry, AuLock_IR);
11243 + fi_read_unlock(file);
11245 + /* filedata may be obsoleted by concurrent copyup, but no problem */
11246 + err = vfsub_read_u(h_file, buf, count, ppos);
11247 + /* todo: necessary? */
11248 + /* file->f_ra = h_file->f_ra; */
11249 + /* update without lock, I don't think it a problem */
11250 + fsstack_copy_attr_atime(dentry->d_inode, h_file->f_dentry->d_inode);
11254 + si_read_unlock(sb);
11259 + * todo: very ugly
11260 + * it locks both of i_mutex and si_rwsem for read in safe.
11261 + * if the plink maintenance mode continues forever (that is the problem),
11262 + * may loop forever.
11264 +static void au_mtx_and_read_lock(struct inode *inode)
11267 + struct super_block *sb = inode->i_sb;
11270 + mutex_lock(&inode->i_mutex);
11271 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
11274 + mutex_unlock(&inode->i_mutex);
11275 + si_read_lock(sb, AuLock_NOPLMW);
11276 + si_read_unlock(sb);
11280 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
11281 + size_t count, loff_t *ppos)
11284 + struct au_pin pin;
11285 + struct dentry *dentry;
11286 + struct super_block *sb;
11287 + struct inode *inode;
11288 + struct file *h_file;
11289 + char __user *buf = (char __user *)ubuf;
11291 + dentry = file->f_dentry;
11292 + sb = dentry->d_sb;
11293 + inode = dentry->d_inode;
11294 + au_mtx_and_read_lock(inode);
11296 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
11297 + if (unlikely(err))
11300 + err = au_ready_to_write(file, -1, &pin);
11301 + di_downgrade_lock(dentry, AuLock_IR);
11302 + if (unlikely(err)) {
11303 + di_read_unlock(dentry, AuLock_IR);
11304 + fi_write_unlock(file);
11308 + h_file = au_hf_top(file);
11309 + get_file(h_file);
11311 + di_read_unlock(dentry, AuLock_IR);
11312 + fi_write_unlock(file);
11314 + err = vfsub_write_u(h_file, buf, count, ppos);
11315 + ii_write_lock_child(inode);
11316 + au_cpup_attr_timesizes(inode);
11317 + inode->i_mode = h_file->f_dentry->d_inode->i_mode;
11318 + ii_write_unlock(inode);
11322 + si_read_unlock(sb);
11323 + mutex_unlock(&inode->i_mutex);
11327 +static ssize_t au_do_aio(struct file *h_file, int rw, struct kiocb *kio,
11328 + const struct iovec *iov, unsigned long nv, loff_t pos)
11331 + struct file *file;
11332 + ssize_t (*func)(struct kiocb *, const struct iovec *, unsigned long,
11335 + err = security_file_permission(h_file, rw);
11336 + if (unlikely(err))
11341 + if (rw == MAY_READ)
11342 + func = h_file->f_op->aio_read;
11343 + else if (rw == MAY_WRITE)
11344 + func = h_file->f_op->aio_write;
11346 + file = kio->ki_filp;
11347 + kio->ki_filp = h_file;
11349 + err = func(kio, iov, nv, pos);
11351 + kio->ki_filp = file;
11353 + /* currently there is no such fs */
11360 +static ssize_t aufs_aio_read(struct kiocb *kio, const struct iovec *iov,
11361 + unsigned long nv, loff_t pos)
11364 + struct file *file, *h_file;
11365 + struct dentry *dentry;
11366 + struct super_block *sb;
11368 + file = kio->ki_filp;
11369 + dentry = file->f_dentry;
11370 + sb = dentry->d_sb;
11371 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11372 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
11373 + if (unlikely(err))
11376 + h_file = au_hf_top(file);
11377 + get_file(h_file);
11378 + di_read_unlock(dentry, AuLock_IR);
11379 + fi_read_unlock(file);
11381 + err = au_do_aio(h_file, MAY_READ, kio, iov, nv, pos);
11382 + /* todo: necessary? */
11383 + /* file->f_ra = h_file->f_ra; */
11384 + /* update without lock, I don't think it a problem */
11385 + fsstack_copy_attr_atime(dentry->d_inode, h_file->f_dentry->d_inode);
11389 + si_read_unlock(sb);
11393 +static ssize_t aufs_aio_write(struct kiocb *kio, const struct iovec *iov,
11394 + unsigned long nv, loff_t pos)
11397 + struct au_pin pin;
11398 + struct dentry *dentry;
11399 + struct inode *inode;
11400 + struct file *file, *h_file;
11401 + struct super_block *sb;
11403 + file = kio->ki_filp;
11404 + dentry = file->f_dentry;
11405 + sb = dentry->d_sb;
11406 + inode = dentry->d_inode;
11407 + au_mtx_and_read_lock(inode);
11409 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
11410 + if (unlikely(err))
11413 + err = au_ready_to_write(file, -1, &pin);
11414 + di_downgrade_lock(dentry, AuLock_IR);
11415 + if (unlikely(err)) {
11416 + di_read_unlock(dentry, AuLock_IR);
11417 + fi_write_unlock(file);
11421 + h_file = au_hf_top(file);
11422 + get_file(h_file);
11424 + di_read_unlock(dentry, AuLock_IR);
11425 + fi_write_unlock(file);
11427 + err = au_do_aio(h_file, MAY_WRITE, kio, iov, nv, pos);
11428 + ii_write_lock_child(inode);
11429 + au_cpup_attr_timesizes(inode);
11430 + inode->i_mode = h_file->f_dentry->d_inode->i_mode;
11431 + ii_write_unlock(inode);
11435 + si_read_unlock(sb);
11436 + mutex_unlock(&inode->i_mutex);
11440 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
11441 + struct pipe_inode_info *pipe, size_t len,
11442 + unsigned int flags)
11445 + struct file *h_file;
11446 + struct dentry *dentry;
11447 + struct super_block *sb;
11449 + dentry = file->f_dentry;
11450 + sb = dentry->d_sb;
11451 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11452 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
11453 + if (unlikely(err))
11457 + h_file = au_hf_top(file);
11458 + get_file(h_file);
11459 + if (au_test_loopback_kthread()) {
11460 + au_warn_loopback(h_file->f_dentry->d_sb);
11461 + if (file->f_mapping != h_file->f_mapping) {
11462 + file->f_mapping = h_file->f_mapping;
11463 + smp_mb(); /* unnecessary? */
11466 + di_read_unlock(dentry, AuLock_IR);
11467 + fi_read_unlock(file);
11469 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
11470 + /* todo: necessasry? */
11471 + /* file->f_ra = h_file->f_ra; */
11472 + /* update without lock, I don't think it a problem */
11473 + fsstack_copy_attr_atime(dentry->d_inode, h_file->f_dentry->d_inode);
11477 + si_read_unlock(sb);
11482 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
11483 + size_t len, unsigned int flags)
11486 + struct au_pin pin;
11487 + struct dentry *dentry;
11488 + struct inode *inode;
11489 + struct file *h_file;
11490 + struct super_block *sb;
11492 + dentry = file->f_dentry;
11493 + sb = dentry->d_sb;
11494 + inode = dentry->d_inode;
11495 + au_mtx_and_read_lock(inode);
11497 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
11498 + if (unlikely(err))
11501 + err = au_ready_to_write(file, -1, &pin);
11502 + di_downgrade_lock(dentry, AuLock_IR);
11503 + if (unlikely(err)) {
11504 + di_read_unlock(dentry, AuLock_IR);
11505 + fi_write_unlock(file);
11509 + h_file = au_hf_top(file);
11510 + get_file(h_file);
11512 + di_read_unlock(dentry, AuLock_IR);
11513 + fi_write_unlock(file);
11515 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
11516 + ii_write_lock_child(inode);
11517 + au_cpup_attr_timesizes(inode);
11518 + inode->i_mode = h_file->f_dentry->d_inode->i_mode;
11519 + ii_write_unlock(inode);
11523 + si_read_unlock(sb);
11524 + mutex_unlock(&inode->i_mutex);
11528 +/* ---------------------------------------------------------------------- */
11531 + * The locking order around current->mmap_sem.
11532 + * - in most and regular cases
11533 + * file I/O syscall -- aufs_read() or something
11534 + * -- si_rwsem for read -- mmap_sem
11535 + * (Note that [fdi]i_rwsem are released before mmap_sem).
11537 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
11538 + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
11539 + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
11540 + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
11541 + * It means that when aufs acquires si_rwsem for write, the process should never
11542 + * acquire mmap_sem.
11544 + * Actually aufs_readdir() holds [fdi]i_rwsem before mmap_sem, but this is not a
11545 + * problem either since any directory is not able to be mmap-ed.
11546 + * The similar scenario is applied to aufs_readlink() too.
11549 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
11552 + aufs_bindex_t bstart;
11553 + const unsigned char wlock
11554 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
11555 + struct dentry *dentry;
11556 + struct super_block *sb;
11557 + struct file *h_file;
11558 + struct au_branch *br;
11559 + struct au_pin pin;
11561 + AuDbgVmRegion(file, vma);
11563 + dentry = file->f_dentry;
11564 + sb = dentry->d_sb;
11566 + si_read_lock(sb, AuLock_NOPLMW);
11567 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
11568 + if (unlikely(err))
11572 + err = au_ready_to_write(file, -1, &pin);
11573 + di_write_unlock(dentry);
11574 + if (unlikely(err)) {
11575 + fi_write_unlock(file);
11580 + di_write_unlock(dentry);
11582 + bstart = au_fbstart(file);
11583 + br = au_sbr(sb, bstart);
11584 + h_file = au_hf_top(file);
11585 + get_file(h_file);
11586 + au_set_mmapped(file);
11587 + fi_write_unlock(file);
11590 + au_vm_file_reset(vma, h_file);
11591 + /* todo: bad approach, I am not sure this is really necessary */
11592 + err = au_security_mmap_file(h_file, vma);
11594 + err = h_file->f_op->mmap(h_file, vma);
11595 + if (unlikely(err))
11598 + au_vm_prfile_set(vma, file);
11599 + /* update without lock, I don't think it a problem */
11600 + fsstack_copy_attr_atime(file->f_dentry->d_inode,
11601 + h_file->f_dentry->d_inode);
11602 + goto out_fput; /* success */
11605 + au_unset_mmapped(file);
11606 + au_vm_file_reset(vma, file);
11611 + si_read_unlock(sb);
11617 +/* ---------------------------------------------------------------------- */
11619 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
11623 + struct au_pin pin;
11624 + struct dentry *dentry;
11625 + struct inode *inode;
11626 + struct file *h_file;
11627 + struct super_block *sb;
11629 + dentry = file->f_dentry;
11630 + inode = dentry->d_inode;
11631 + sb = dentry->d_sb;
11632 + mutex_lock(&inode->i_mutex);
11633 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
11634 + if (unlikely(err))
11637 + err = 0; /* -EBADF; */ /* posix? */
11638 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
11640 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
11641 + if (unlikely(err))
11644 + err = au_ready_to_write(file, -1, &pin);
11645 + di_downgrade_lock(dentry, AuLock_IR);
11646 + if (unlikely(err))
11651 + h_file = au_hf_top(file);
11652 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
11653 + au_cpup_attr_timesizes(inode);
11656 + di_read_unlock(dentry, AuLock_IR);
11657 + fi_write_unlock(file);
11659 + si_read_unlock(sb);
11661 + mutex_unlock(&inode->i_mutex);
11665 +/* no one supports this operation, currently */
11667 +static int aufs_aio_fsync_nondir(struct kiocb *kio, int datasync)
11670 + struct au_pin pin;
11671 + struct dentry *dentry;
11672 + struct inode *inode;
11673 + struct file *file, *h_file;
11675 + file = kio->ki_filp;
11676 + dentry = file->f_dentry;
11677 + inode = dentry->d_inode;
11678 + au_mtx_and_read_lock(inode);
11680 + err = 0; /* -EBADF; */ /* posix? */
11681 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
11683 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
11684 + if (unlikely(err))
11687 + err = au_ready_to_write(file, -1, &pin);
11688 + di_downgrade_lock(dentry, AuLock_IR);
11689 + if (unlikely(err))
11694 + h_file = au_hf_top(file);
11695 + if (h_file->f_op && h_file->f_op->aio_fsync) {
11696 + struct dentry *h_d;
11697 + struct mutex *h_mtx;
11699 + h_d = h_file->f_dentry;
11700 + h_mtx = &h_d->d_inode->i_mutex;
11701 + if (!is_sync_kiocb(kio)) {
11702 + get_file(h_file);
11705 + kio->ki_filp = h_file;
11706 + err = h_file->f_op->aio_fsync(kio, datasync);
11707 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
11709 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL);
11711 + au_cpup_attr_timesizes(inode);
11712 + mutex_unlock(h_mtx);
11716 + di_read_unlock(dentry, AuLock_IR);
11717 + fi_write_unlock(file);
11719 + si_read_unlock(inode->sb);
11720 + mutex_unlock(&inode->i_mutex);
11725 +static int aufs_fasync(int fd, struct file *file, int flag)
11728 + struct file *h_file;
11729 + struct dentry *dentry;
11730 + struct super_block *sb;
11732 + dentry = file->f_dentry;
11733 + sb = dentry->d_sb;
11734 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11735 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
11736 + if (unlikely(err))
11739 + h_file = au_hf_top(file);
11740 + if (h_file->f_op && h_file->f_op->fasync)
11741 + err = h_file->f_op->fasync(fd, h_file, flag);
11743 + di_read_unlock(dentry, AuLock_IR);
11744 + fi_read_unlock(file);
11747 + si_read_unlock(sb);
11751 +/* ---------------------------------------------------------------------- */
11753 +/* no one supports this operation, currently */
11755 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
11756 + size_t len, loff_t *pos , int more)
11761 +/* ---------------------------------------------------------------------- */
11763 +const struct file_operations aufs_file_fop = {
11764 + .owner = THIS_MODULE,
11766 + .llseek = default_llseek,
11768 + .read = aufs_read,
11769 + .write = aufs_write,
11770 + .aio_read = aufs_aio_read,
11771 + .aio_write = aufs_aio_write,
11772 +#ifdef CONFIG_AUFS_POLL
11773 + .poll = aufs_poll,
11775 + .unlocked_ioctl = aufs_ioctl_nondir,
11776 +#ifdef CONFIG_COMPAT
11777 + .compat_ioctl = aufs_ioctl_nondir, /* same */
11779 + .mmap = aufs_mmap,
11780 + .open = aufs_open_nondir,
11781 + .flush = aufs_flush_nondir,
11782 + .release = aufs_release_nondir,
11783 + .fsync = aufs_fsync_nondir,
11784 + /* .aio_fsync = aufs_aio_fsync_nondir, */
11785 + .fasync = aufs_fasync,
11786 + /* .sendpage = aufs_sendpage, */
11787 + .splice_write = aufs_splice_write,
11788 + .splice_read = aufs_splice_read,
11790 + .aio_splice_write = aufs_aio_splice_write,
11791 + .aio_splice_read = aufs_aio_splice_read
11794 diff -urN /usr/share/empty/fs/aufs/f_op_sp.c linux/fs/aufs/f_op_sp.c
11795 --- /usr/share/empty/fs/aufs/f_op_sp.c 1970-01-01 01:00:00.000000000 +0100
11796 +++ linux/fs/aufs/f_op_sp.c 2012-07-22 19:57:03.164337936 +0200
11799 + * Copyright (C) 2005-2012 Junjiro R. Okajima
11801 + * This program, aufs is free software; you can redistribute it and/or modify
11802 + * it under the terms of the GNU General Public License as published by
11803 + * the Free Software Foundation; either version 2 of the License, or
11804 + * (at your option) any later version.
11806 + * This program is distributed in the hope that it will be useful,
11807 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11808 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11809 + * GNU General Public License for more details.
11811 + * You should have received a copy of the GNU General Public License
11812 + * along with this program; if not, write to the Free Software
11813 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11817 + * file operations for special files.
11818 + * while they exist in aufs virtually,
11819 + * their file I/O is handled out of aufs.
11824 +static ssize_t aufs_aio_read_sp(struct kiocb *kio, const struct iovec *iov,
11825 + unsigned long nv, loff_t pos)
11828 + aufs_bindex_t bstart;
11829 + unsigned char wbr;
11830 + struct file *file, *h_file;
11831 + struct super_block *sb;
11833 + file = kio->ki_filp;
11834 + sb = file->f_dentry->d_sb;
11835 + si_read_lock(sb, AuLock_FLUSH);
11836 + fi_read_lock(file);
11837 + bstart = au_fbstart(file);
11838 + h_file = au_hf_top(file);
11839 + fi_read_unlock(file);
11840 + wbr = !!au_br_writable(au_sbr(sb, bstart)->br_perm);
11841 + si_read_unlock(sb);
11843 + /* do not change the file in kio */
11844 + AuDebugOn(!h_file->f_op || !h_file->f_op->aio_read);
11845 + err = h_file->f_op->aio_read(kio, iov, nv, pos);
11846 + if (err > 0 && wbr)
11847 + file_accessed(h_file);
11852 +static ssize_t aufs_aio_write_sp(struct kiocb *kio, const struct iovec *iov,
11853 + unsigned long nv, loff_t pos)
11856 + aufs_bindex_t bstart;
11857 + unsigned char wbr;
11858 + struct super_block *sb;
11859 + struct file *file, *h_file;
11861 + file = kio->ki_filp;
11862 + sb = file->f_dentry->d_sb;
11863 + si_read_lock(sb, AuLock_FLUSH);
11864 + fi_read_lock(file);
11865 + bstart = au_fbstart(file);
11866 + h_file = au_hf_top(file);
11867 + fi_read_unlock(file);
11868 + wbr = !!au_br_writable(au_sbr(sb, bstart)->br_perm);
11869 + si_read_unlock(sb);
11871 + /* do not change the file in kio */
11872 + AuDebugOn(!h_file->f_op || !h_file->f_op->aio_write);
11873 + err = h_file->f_op->aio_write(kio, iov, nv, pos);
11877 +/* ---------------------------------------------------------------------- */
11879 +static int aufs_release_sp(struct inode *inode, struct file *file)
11882 + struct file *h_file;
11884 + fi_read_lock(file);
11885 + h_file = au_hf_top(file);
11886 + fi_read_unlock(file);
11887 + /* close this fifo in aufs */
11888 + err = h_file->f_op->release(inode, file); /* ignore */
11889 + aufs_release_nondir(inode, file); /* ignore */
11893 +/* ---------------------------------------------------------------------- */
11895 +/* currently, support only FIFO */
11897 + AuSp_FIFO, AuSp_FIFO_R, AuSp_FIFO_W, AuSp_FIFO_RW,
11898 + /* AuSp_SOCK, AuSp_CHR, AuSp_BLK, */
11901 +static int aufs_open_sp(struct inode *inode, struct file *file);
11902 +static struct au_sp_fop {
11904 + struct file_operations fop; /* not 'const' */
11906 +} au_sp_fop[AuSp_Last] = {
11909 + .owner = THIS_MODULE,
11910 + .open = aufs_open_sp
11915 +static void au_init_fop_sp(struct file *file)
11917 + struct au_sp_fop *p;
11919 + struct file *h_file;
11922 + if (unlikely(!p->done)) {
11923 + /* initialize first time only */
11924 + static DEFINE_SPINLOCK(spin);
11926 + spin_lock(&spin);
11928 + BUILD_BUG_ON(sizeof(au_sp_fop)/sizeof(*au_sp_fop)
11930 + for (i = 0; i < AuSp_Last; i++)
11931 + spin_lock_init(&p[i].spin);
11934 + spin_unlock(&spin);
11937 + switch (file->f_mode & (FMODE_READ | FMODE_WRITE)) {
11941 + case FMODE_WRITE:
11944 + case FMODE_READ | FMODE_WRITE:
11945 + i = AuSp_FIFO_RW;
11952 + if (unlikely(!p->done)) {
11953 + /* initialize first time only */
11954 + h_file = au_hf_top(file);
11955 + spin_lock(&p->spin);
11957 + p->fop = *h_file->f_op;
11958 + p->fop.owner = THIS_MODULE;
11959 + if (p->fop.aio_read)
11960 + p->fop.aio_read = aufs_aio_read_sp;
11961 + if (p->fop.aio_write)
11962 + p->fop.aio_write = aufs_aio_write_sp;
11963 + p->fop.release = aufs_release_sp;
11966 + spin_unlock(&p->spin);
11968 + file->f_op = &p->fop;
11971 +static int au_cpup_sp(struct dentry *dentry)
11974 + aufs_bindex_t bcpup;
11975 + struct au_pin pin;
11976 + struct au_wr_dir_args wr_dir_args = {
11977 + .force_btgt = -1,
11981 + AuDbg("%.*s\n", AuDLNPair(dentry));
11983 + di_read_unlock(dentry, AuLock_IR);
11984 + di_write_lock_child(dentry);
11985 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
11986 + if (unlikely(err < 0))
11990 + if (bcpup == au_dbstart(dentry))
11991 + goto out; /* success */
11993 + err = au_pin(&pin, dentry, bcpup, au_opt_udba(dentry->d_sb),
11994 + AuPin_MNT_WRITE);
11996 + err = au_sio_cpup_simple(dentry, bcpup, -1, AuCpup_DTIME);
12001 + di_downgrade_lock(dentry, AuLock_IR);
12005 +static int au_do_open_sp(struct file *file, int flags)
12008 + struct dentry *dentry;
12009 + struct super_block *sb;
12010 + struct file *h_file;
12011 + struct inode *h_inode;
12013 + dentry = file->f_dentry;
12014 + AuDbg("%.*s\n", AuDLNPair(dentry));
12017 + * try copying-up.
12018 + * operate on the ro branch is not an error.
12020 + au_cpup_sp(dentry); /* ignore */
12022 + /* prepare h_file */
12023 + err = au_do_open_nondir(file, vfsub_file_flags(file));
12024 + if (unlikely(err))
12027 + sb = dentry->d_sb;
12028 + h_file = au_hf_top(file);
12029 + h_inode = h_file->f_dentry->d_inode;
12030 + di_read_unlock(dentry, AuLock_IR);
12031 + fi_write_unlock(file);
12032 + si_read_unlock(sb);
12033 + /* open this fifo in aufs */
12034 + err = h_inode->i_fop->open(file->f_dentry->d_inode, file);
12035 + si_noflush_read_lock(sb);
12036 + fi_write_lock(file);
12037 + di_read_lock_child(dentry, AuLock_IR);
12039 + au_init_fop_sp(file);
12045 +static int aufs_open_sp(struct inode *inode, struct file *file)
12048 + struct super_block *sb;
12050 + sb = file->f_dentry->d_sb;
12051 + si_read_lock(sb, AuLock_FLUSH);
12052 + err = au_do_open(file, au_do_open_sp, /*fidir*/NULL);
12053 + si_read_unlock(sb);
12057 +/* ---------------------------------------------------------------------- */
12059 +void au_init_special_fop(struct inode *inode, umode_t mode, dev_t rdev)
12061 + init_special_inode(inode, mode, rdev);
12063 + switch (mode & S_IFMT) {
12065 + inode->i_fop = &au_sp_fop[AuSp_FIFO].fop;
12076 +int au_special_file(umode_t mode)
12081 + switch (mode & S_IFMT) {
12093 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
12094 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
12095 +++ linux/fs/aufs/fstype.h 2012-07-22 19:57:03.164337936 +0200
12098 + * Copyright (C) 2005-2012 Junjiro R. Okajima
12100 + * This program, aufs is free software; you can redistribute it and/or modify
12101 + * it under the terms of the GNU General Public License as published by
12102 + * the Free Software Foundation; either version 2 of the License, or
12103 + * (at your option) any later version.
12105 + * This program is distributed in the hope that it will be useful,
12106 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12107 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12108 + * GNU General Public License for more details.
12110 + * You should have received a copy of the GNU General Public License
12111 + * along with this program; if not, write to the Free Software
12112 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
12116 + * judging filesystem type
12119 +#ifndef __AUFS_FSTYPE_H__
12120 +#define __AUFS_FSTYPE_H__
12124 +#include <linux/fs.h>
12125 +#include <linux/magic.h>
12126 +#include <linux/romfs_fs.h>
12128 +static inline int au_test_aufs(struct super_block *sb)
12130 + return sb->s_magic == AUFS_SUPER_MAGIC;
12133 +static inline const char *au_sbtype(struct super_block *sb)
12135 + return sb->s_type->name;
12138 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
12140 +#if defined(CONFIG_ROMFS_FS) || defined(CONFIG_ROMFS_FS_MODULE)
12141 + return sb->s_magic == ROMFS_MAGIC;
12147 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
12149 +#if defined(CONFIG_ISO9660_FS) || defined(CONFIG_ISO9660_FS_MODULE)
12150 + return sb->s_magic == ISOFS_SUPER_MAGIC;
12156 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
12158 +#if defined(CONFIG_CRAMFS) || defined(CONFIG_CRAMFS_MODULE)
12159 + return sb->s_magic == CRAMFS_MAGIC;
12164 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
12166 +#if defined(CONFIG_NFS_FS) || defined(CONFIG_NFS_FS_MODULE)
12167 + return sb->s_magic == NFS_SUPER_MAGIC;
12173 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
12175 +#if defined(CONFIG_FUSE_FS) || defined(CONFIG_FUSE_FS_MODULE)
12176 + return sb->s_magic == FUSE_SUPER_MAGIC;
12182 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
12184 +#if defined(CONFIG_XFS_FS) || defined(CONFIG_XFS_FS_MODULE)
12185 + return sb->s_magic == XFS_SB_MAGIC;
12191 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
12193 +#ifdef CONFIG_TMPFS
12194 + return sb->s_magic == TMPFS_MAGIC;
12200 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
12202 +#if defined(CONFIG_ECRYPT_FS) || defined(CONFIG_ECRYPT_FS_MODULE)
12203 + return !strcmp(au_sbtype(sb), "ecryptfs");
12209 +static inline int au_test_smbfs(struct super_block *sb __maybe_unused)
12211 +#if defined(CONFIG_SMB_FS) || defined(CONFIG_SMB_FS_MODULE)
12212 + return sb->s_magic == SMB_SUPER_MAGIC;
12218 +static inline int au_test_ocfs2(struct super_block *sb __maybe_unused)
12220 +#if defined(CONFIG_OCFS2_FS) || defined(CONFIG_OCFS2_FS_MODULE)
12221 + return sb->s_magic == OCFS2_SUPER_MAGIC;
12227 +static inline int au_test_ocfs2_dlmfs(struct super_block *sb __maybe_unused)
12229 +#if defined(CONFIG_OCFS2_FS_O2CB) || defined(CONFIG_OCFS2_FS_O2CB_MODULE)
12230 + return sb->s_magic == DLMFS_MAGIC;
12236 +static inline int au_test_coda(struct super_block *sb __maybe_unused)
12238 +#if defined(CONFIG_CODA_FS) || defined(CONFIG_CODA_FS_MODULE)
12239 + return sb->s_magic == CODA_SUPER_MAGIC;
12245 +static inline int au_test_v9fs(struct super_block *sb __maybe_unused)
12247 +#if defined(CONFIG_9P_FS) || defined(CONFIG_9P_FS_MODULE)
12248 + return sb->s_magic == V9FS_MAGIC;
12254 +static inline int au_test_ext4(struct super_block *sb __maybe_unused)
12256 +#if defined(CONFIG_EXT4DEV_FS) || defined(CONFIG_EXT4DEV_FS_MODULE)
12257 + return sb->s_magic == EXT4_SUPER_MAGIC;
12263 +static inline int au_test_sysv(struct super_block *sb __maybe_unused)
12265 +#if defined(CONFIG_SYSV_FS) || defined(CONFIG_SYSV_FS_MODULE)
12266 + return !strcmp(au_sbtype(sb), "sysv");
12272 +static inline int au_test_ramfs(struct super_block *sb)
12274 + return sb->s_magic == RAMFS_MAGIC;
12277 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
12279 +#if defined(CONFIG_UBIFS_FS) || defined(CONFIG_UBIFS_FS_MODULE)
12280 + return sb->s_magic == UBIFS_SUPER_MAGIC;
12286 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
12288 +#ifdef CONFIG_PROC_FS
12289 + return sb->s_magic == PROC_SUPER_MAGIC;
12295 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
12297 +#ifdef CONFIG_SYSFS
12298 + return sb->s_magic == SYSFS_MAGIC;
12304 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
12306 +#if defined(CONFIG_CONFIGFS_FS) || defined(CONFIG_CONFIGFS_FS_MODULE)
12307 + return sb->s_magic == CONFIGFS_MAGIC;
12313 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
12315 +#if defined(CONFIG_MINIX_FS) || defined(CONFIG_MINIX_FS_MODULE)
12316 + return sb->s_magic == MINIX3_SUPER_MAGIC
12317 + || sb->s_magic == MINIX2_SUPER_MAGIC
12318 + || sb->s_magic == MINIX2_SUPER_MAGIC2
12319 + || sb->s_magic == MINIX_SUPER_MAGIC
12320 + || sb->s_magic == MINIX_SUPER_MAGIC2;
12326 +static inline int au_test_cifs(struct super_block *sb __maybe_unused)
12328 +#if defined(CONFIG_CIFS_FS) || defined(CONFIGCIFS_FS_MODULE)
12329 + return sb->s_magic == CIFS_MAGIC_NUMBER;
12335 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
12337 +#if defined(CONFIG_FAT_FS) || defined(CONFIG_FAT_FS_MODULE)
12338 + return sb->s_magic == MSDOS_SUPER_MAGIC;
12344 +static inline int au_test_msdos(struct super_block *sb)
12346 + return au_test_fat(sb);
12349 +static inline int au_test_vfat(struct super_block *sb)
12351 + return au_test_fat(sb);
12354 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
12356 +#ifdef CONFIG_SECURITYFS
12357 + return sb->s_magic == SECURITYFS_MAGIC;
12363 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
12365 +#if defined(CONFIG_SQUASHFS) || defined(CONFIG_SQUASHFS_MODULE)
12366 + return sb->s_magic == SQUASHFS_MAGIC;
12372 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
12374 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
12375 + return sb->s_magic == BTRFS_SUPER_MAGIC;
12381 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
12383 +#if defined(CONFIG_XENFS) || defined(CONFIG_XENFS_MODULE)
12384 + return sb->s_magic == XENFS_SUPER_MAGIC;
12390 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
12392 +#ifdef CONFIG_DEBUG_FS
12393 + return sb->s_magic == DEBUGFS_MAGIC;
12399 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
12401 +#if defined(CONFIG_NILFS) || defined(CONFIG_NILFS_MODULE)
12402 + return sb->s_magic == NILFS_SUPER_MAGIC;
12408 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
12410 +#if defined(CONFIG_HFSPLUS_FS) || defined(CONFIG_HFSPLUS_FS_MODULE)
12411 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
12417 +/* ---------------------------------------------------------------------- */
12419 + * they can't be an aufs branch.
12421 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
12424 +#ifndef CONFIG_AUFS_BR_RAMFS
12425 + au_test_ramfs(sb) ||
12427 + au_test_procfs(sb)
12428 + || au_test_sysfs(sb)
12429 + || au_test_configfs(sb)
12430 + || au_test_debugfs(sb)
12431 + || au_test_securityfs(sb)
12432 + || au_test_xenfs(sb)
12433 + || au_test_ecryptfs(sb)
12434 + /* || !strcmp(au_sbtype(sb), "unionfs") */
12435 + || au_test_aufs(sb); /* will be supported in next version */
12439 + * If the filesystem supports NFS-export, then it has to support NULL as
12440 + * a nameidata parameter for ->create(), ->lookup() and ->d_revalidate().
12441 + * We can apply this principle when we handle a lower filesystem.
12443 +static inline int au_test_fs_null_nd(struct super_block *sb)
12445 + return !!sb->s_export_op;
12448 +static inline int au_test_fs_remote(struct super_block *sb)
12450 + return !au_test_tmpfs(sb)
12451 +#ifdef CONFIG_AUFS_BR_RAMFS
12452 + && !au_test_ramfs(sb)
12454 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
12457 +/* ---------------------------------------------------------------------- */
12460 + * Note: these functions (below) are created after reading ->getattr() in all
12461 + * filesystems under linux/fs. it means we have to do so in every update...
12465 + * some filesystems require getattr to refresh the inode attributes before
12467 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
12468 + * and leave the work for d_revalidate()
12470 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
12472 + return au_test_nfs(sb)
12473 + || au_test_fuse(sb)
12474 + /* || au_test_smbfs(sb) */ /* untested */
12475 + /* || au_test_ocfs2(sb) */ /* untested */
12476 + /* || au_test_btrfs(sb) */ /* untested */
12477 + /* || au_test_coda(sb) */ /* untested */
12478 + /* || au_test_v9fs(sb) */ /* untested */
12483 + * filesystems which don't maintain i_size or i_blocks.
12485 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
12487 + return au_test_xfs(sb)
12488 + || au_test_btrfs(sb)
12489 + || au_test_ubifs(sb)
12490 + || au_test_hfsplus(sb) /* maintained, but incorrect */
12491 + /* || au_test_ext4(sb) */ /* untested */
12492 + /* || au_test_ocfs2(sb) */ /* untested */
12493 + /* || au_test_ocfs2_dlmfs(sb) */ /* untested */
12494 + /* || au_test_sysv(sb) */ /* untested */
12495 + /* || au_test_minix(sb) */ /* untested */
12500 + * filesystems which don't store the correct value in some of their inode
12503 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
12505 + return au_test_fs_bad_iattr_size(sb)
12506 + /* || au_test_cifs(sb) */ /* untested */
12507 + || au_test_fat(sb)
12508 + || au_test_msdos(sb)
12509 + || au_test_vfat(sb);
12512 +/* they don't check i_nlink in link(2) */
12513 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
12515 + return au_test_tmpfs(sb)
12516 +#ifdef CONFIG_AUFS_BR_RAMFS
12517 + || au_test_ramfs(sb)
12519 + || au_test_ubifs(sb)
12520 + || au_test_btrfs(sb)
12521 + || au_test_hfsplus(sb);
12525 + * filesystems which sets S_NOATIME and S_NOCMTIME.
12527 +static inline int au_test_fs_notime(struct super_block *sb)
12529 + return au_test_nfs(sb)
12530 + || au_test_fuse(sb)
12531 + || au_test_ubifs(sb)
12532 + /* || au_test_cifs(sb) */ /* untested */
12537 + * filesystems which requires replacing i_mapping.
12539 +static inline int au_test_fs_bad_mapping(struct super_block *sb)
12541 + return au_test_fuse(sb)
12542 + || au_test_ubifs(sb);
12545 +/* temporary support for i#1 in cramfs */
12546 +static inline int au_test_fs_unique_ino(struct inode *inode)
12548 + if (au_test_cramfs(inode->i_sb))
12549 + return inode->i_ino != 1;
12553 +/* ---------------------------------------------------------------------- */
12556 + * the filesystem where the xino files placed must support i/o after unlink and
12557 + * maintain i_size and i_blocks.
12559 +static inline int au_test_fs_bad_xino(struct super_block *sb)
12561 + return au_test_fs_remote(sb)
12562 + || au_test_fs_bad_iattr_size(sb)
12563 +#ifdef CONFIG_AUFS_BR_RAMFS
12564 + || !(au_test_ramfs(sb) || au_test_fs_null_nd(sb))
12566 + || !au_test_fs_null_nd(sb) /* to keep xino code simple */
12568 + /* don't want unnecessary work for xino */
12569 + || au_test_aufs(sb)
12570 + || au_test_ecryptfs(sb)
12571 + || au_test_nilfs(sb);
12574 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
12576 + return au_test_tmpfs(sb)
12577 + || au_test_ramfs(sb);
12581 + * test if the @sb is real-readonly.
12583 +static inline int au_test_fs_rr(struct super_block *sb)
12585 + return au_test_squashfs(sb)
12586 + || au_test_iso9660(sb)
12587 + || au_test_cramfs(sb)
12588 + || au_test_romfs(sb);
12591 +#endif /* __KERNEL__ */
12592 +#endif /* __AUFS_FSTYPE_H__ */
12593 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
12594 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
12595 +++ linux/fs/aufs/hfsnotify.c 2012-07-22 19:57:03.164337936 +0200
12598 + * Copyright (C) 2005-2012 Junjiro R. Okajima
12600 + * This program, aufs is free software; you can redistribute it and/or modify
12601 + * it under the terms of the GNU General Public License as published by
12602 + * the Free Software Foundation; either version 2 of the License, or
12603 + * (at your option) any later version.
12605 + * This program is distributed in the hope that it will be useful,
12606 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12607 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12608 + * GNU General Public License for more details.
12610 + * You should have received a copy of the GNU General Public License
12611 + * along with this program; if not, write to the Free Software
12612 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
12616 + * fsnotify for the lower directories
12621 +/* FS_IN_IGNORED is unnecessary */
12622 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
12623 + | FS_CREATE | FS_EVENT_ON_CHILD);
12624 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
12625 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
12627 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
12629 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
12632 + au_cache_free_hnotify(hn);
12633 + smp_mb__before_atomic_dec();
12634 + atomic64_dec(&au_hfsn_ifree);
12635 + wake_up(&au_hfsn_wq);
12638 +static int au_hfsn_alloc(struct au_hinode *hinode)
12640 + struct au_hnotify *hn;
12641 + struct super_block *sb;
12642 + struct au_branch *br;
12643 + struct fsnotify_mark *mark;
12644 + aufs_bindex_t bindex;
12646 + hn = hinode->hi_notify;
12647 + sb = hn->hn_aufs_inode->i_sb;
12648 + bindex = au_br_index(sb, hinode->hi_id);
12649 + br = au_sbr(sb, bindex);
12650 + mark = &hn->hn_mark;
12651 + fsnotify_init_mark(mark, au_hfsn_free_mark);
12652 + mark->mask = AuHfsnMask;
12654 + * by udba rename or rmdir, aufs assign a new inode to the known
12655 + * h_inode, so specify 1 to allow dups.
12657 + return fsnotify_add_mark(mark, br->br_hfsn_group, hinode->hi_inode,
12658 + /*mnt*/NULL, /*allow_dups*/1);
12661 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
12663 + struct fsnotify_mark *mark;
12664 + unsigned long long ull;
12666 + ull = atomic64_inc_return(&au_hfsn_ifree);
12669 + mark = &hn->hn_mark;
12670 + fsnotify_destroy_mark(mark);
12671 + fsnotify_put_mark(mark);
12673 + /* free hn by myself */
12677 +/* ---------------------------------------------------------------------- */
12679 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
12681 + struct fsnotify_mark *mark;
12683 + mark = &hinode->hi_notify->hn_mark;
12684 + spin_lock(&mark->lock);
12686 + AuDebugOn(mark->mask & AuHfsnMask);
12687 + mark->mask |= AuHfsnMask;
12689 + AuDebugOn(!(mark->mask & AuHfsnMask));
12690 + mark->mask &= ~AuHfsnMask;
12692 + spin_unlock(&mark->lock);
12693 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
12696 +/* ---------------------------------------------------------------------- */
12698 +/* #define AuDbgHnotify */
12699 +#ifdef AuDbgHnotify
12700 +static char *au_hfsn_name(u32 mask)
12702 +#ifdef CONFIG_AUFS_DEBUG
12703 +#define test_ret(flag) if (mask & flag) \
12705 + test_ret(FS_ACCESS);
12706 + test_ret(FS_MODIFY);
12707 + test_ret(FS_ATTRIB);
12708 + test_ret(FS_CLOSE_WRITE);
12709 + test_ret(FS_CLOSE_NOWRITE);
12710 + test_ret(FS_OPEN);
12711 + test_ret(FS_MOVED_FROM);
12712 + test_ret(FS_MOVED_TO);
12713 + test_ret(FS_CREATE);
12714 + test_ret(FS_DELETE);
12715 + test_ret(FS_DELETE_SELF);
12716 + test_ret(FS_MOVE_SELF);
12717 + test_ret(FS_UNMOUNT);
12718 + test_ret(FS_Q_OVERFLOW);
12719 + test_ret(FS_IN_IGNORED);
12720 + test_ret(FS_IN_ISDIR);
12721 + test_ret(FS_IN_ONESHOT);
12722 + test_ret(FS_EVENT_ON_CHILD);
12731 +/* ---------------------------------------------------------------------- */
12733 +static int au_hfsn_handle_event(struct fsnotify_group *group,
12734 + struct fsnotify_mark *inode_mark,
12735 + struct fsnotify_mark *vfsmount_mark,
12736 + struct fsnotify_event *event)
12739 + struct au_hnotify *hnotify;
12740 + struct inode *h_dir, *h_inode;
12742 + struct qstr h_child_qstr = QSTR_INIT(event->file_name, event->name_len);
12744 + AuDebugOn(event->data_type != FSNOTIFY_EVENT_INODE);
12747 + /* if FS_UNMOUNT happens, there must be another bug */
12748 + mask = event->mask;
12749 + AuDebugOn(mask & FS_UNMOUNT);
12750 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
12753 + h_dir = event->to_tell;
12754 + h_inode = event->inode;
12755 +#ifdef AuDbgHnotify
12757 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
12758 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
12759 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
12760 + h_dir->i_ino, mask, au_hfsn_name(mask),
12761 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
12762 + /* WARN_ON(1); */
12767 + AuDebugOn(!inode_mark);
12768 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
12769 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
12775 +/* isn't it waste to ask every registered 'group'? */
12776 +/* copied from linux/fs/notify/inotify/inotify_fsnotiry.c */
12777 +/* it should be exported to modules */
12778 +static bool au_hfsn_should_send_event(struct fsnotify_group *group,
12779 + struct inode *h_inode,
12780 + struct fsnotify_mark *inode_mark,
12781 + struct fsnotify_mark *vfsmount_mark,
12782 + __u32 mask, void *data, int data_type)
12784 + mask = (mask & ~FS_EVENT_ON_CHILD);
12785 + return inode_mark->mask & mask;
12788 +static struct fsnotify_ops au_hfsn_ops = {
12789 + .should_send_event = au_hfsn_should_send_event,
12790 + .handle_event = au_hfsn_handle_event
12793 +/* ---------------------------------------------------------------------- */
12795 +static void au_hfsn_fin_br(struct au_branch *br)
12797 + if (br->br_hfsn_group)
12798 + fsnotify_put_group(br->br_hfsn_group);
12801 +static int au_hfsn_init_br(struct au_branch *br, int perm)
12803 + br->br_hfsn_group = NULL;
12804 + br->br_hfsn_ops = au_hfsn_ops;
12808 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
12813 + if (udba != AuOpt_UDBA_HNOTIFY
12814 + || !au_br_hnotifyable(perm)) {
12815 + au_hfsn_fin_br(br);
12816 + br->br_hfsn_group = NULL;
12820 + if (br->br_hfsn_group)
12823 + br->br_hfsn_group = fsnotify_alloc_group(&br->br_hfsn_ops);
12824 + if (IS_ERR(br->br_hfsn_group)) {
12825 + err = PTR_ERR(br->br_hfsn_group);
12826 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
12827 + br->br_hfsn_group = NULL;
12835 +/* ---------------------------------------------------------------------- */
12837 +static void au_hfsn_fin(void)
12839 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
12840 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
12843 +const struct au_hnotify_op au_hnotify_op = {
12844 + .ctl = au_hfsn_ctl,
12845 + .alloc = au_hfsn_alloc,
12846 + .free = au_hfsn_free,
12848 + .fin = au_hfsn_fin,
12850 + .reset_br = au_hfsn_reset_br,
12851 + .fin_br = au_hfsn_fin_br,
12852 + .init_br = au_hfsn_init_br
12854 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
12855 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
12856 +++ linux/fs/aufs/hfsplus.c 2012-07-22 19:57:03.164337936 +0200
12859 + * Copyright (C) 2010-2012 Junjiro R. Okajima
12861 + * This program, aufs is free software; you can redistribute it and/or modify
12862 + * it under the terms of the GNU General Public License as published by
12863 + * the Free Software Foundation; either version 2 of the License, or
12864 + * (at your option) any later version.
12866 + * This program is distributed in the hope that it will be useful,
12867 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12868 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12869 + * GNU General Public License for more details.
12871 + * You should have received a copy of the GNU General Public License
12872 + * along with this program; if not, write to the Free Software
12873 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
12877 + * special support for filesystems which aqucires an inode mutex
12878 + * at final closing a file, eg, hfsplus.
12880 + * This trick is very simple and stupid, just to open the file before really
12881 + * neceeary open to tell hfsplus that this is not the final closing.
12882 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
12883 + * and au_h_open_post() after releasing it.
12888 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex)
12890 + struct file *h_file;
12891 + struct dentry *h_dentry;
12893 + h_dentry = au_h_dptr(dentry, bindex);
12894 + AuDebugOn(!h_dentry);
12895 + AuDebugOn(!h_dentry->d_inode);
12896 + IMustLock(h_dentry->d_inode);
12899 + if (au_test_hfsplus(h_dentry->d_sb)
12900 + && S_ISREG(h_dentry->d_inode->i_mode))
12901 + h_file = au_h_open(dentry, bindex,
12902 + O_RDONLY | O_NOATIME | O_LARGEFILE,
12907 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
12908 + struct file *h_file)
12912 + au_sbr_put(dentry->d_sb, bindex);
12915 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
12916 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
12917 +++ linux/fs/aufs/hnotify.c 2012-07-22 19:57:03.164337936 +0200
12920 + * Copyright (C) 2005-2012 Junjiro R. Okajima
12922 + * This program, aufs is free software; you can redistribute it and/or modify
12923 + * it under the terms of the GNU General Public License as published by
12924 + * the Free Software Foundation; either version 2 of the License, or
12925 + * (at your option) any later version.
12927 + * This program is distributed in the hope that it will be useful,
12928 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12929 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12930 + * GNU General Public License for more details.
12932 + * You should have received a copy of the GNU General Public License
12933 + * along with this program; if not, write to the Free Software
12934 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
12938 + * abstraction to notify the direct changes on lower directories
12943 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
12946 + struct au_hnotify *hn;
12949 + hn = au_cache_alloc_hnotify();
12951 + hn->hn_aufs_inode = inode;
12952 + hinode->hi_notify = hn;
12953 + err = au_hnotify_op.alloc(hinode);
12955 + if (unlikely(err)) {
12956 + hinode->hi_notify = NULL;
12957 + au_cache_free_hnotify(hn);
12959 + * The upper dir was removed by udba, but the same named
12960 + * dir left. In this case, aufs assignes a new inode
12961 + * number and set the monitor again.
12962 + * For the lower dir, the old monitnor is still left.
12964 + if (err == -EEXIST)
12973 +void au_hn_free(struct au_hinode *hinode)
12975 + struct au_hnotify *hn;
12977 + hn = hinode->hi_notify;
12979 + hinode->hi_notify = NULL;
12980 + if (au_hnotify_op.free(hinode, hn))
12981 + au_cache_free_hnotify(hn);
12985 +/* ---------------------------------------------------------------------- */
12987 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
12989 + if (hinode->hi_notify)
12990 + au_hnotify_op.ctl(hinode, do_set);
12993 +void au_hn_reset(struct inode *inode, unsigned int flags)
12995 + aufs_bindex_t bindex, bend;
12996 + struct inode *hi;
12997 + struct dentry *iwhdentry;
12999 + bend = au_ibend(inode);
13000 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
13001 + hi = au_h_iptr(inode, bindex);
13005 + /* mutex_lock_nested(&hi->i_mutex, AuLsc_I_CHILD); */
13006 + iwhdentry = au_hi_wh(inode, bindex);
13010 + au_set_h_iptr(inode, bindex, NULL, 0);
13011 + au_set_h_iptr(inode, bindex, au_igrab(hi),
13012 + flags & ~AuHi_XINO);
13015 + /* mutex_unlock(&hi->i_mutex); */
13019 +/* ---------------------------------------------------------------------- */
13021 +static int hn_xino(struct inode *inode, struct inode *h_inode)
13024 + aufs_bindex_t bindex, bend, bfound, bstart;
13025 + struct inode *h_i;
13028 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
13029 + pr_warn("branch root dir was changed\n");
13034 + bend = au_ibend(inode);
13035 + bstart = au_ibstart(inode);
13036 +#if 0 /* reserved for future use */
13037 + if (bindex == bend) {
13038 + /* keep this ino in rename case */
13042 + for (bindex = bstart; bindex <= bend; bindex++)
13043 + if (au_h_iptr(inode, bindex) == h_inode) {
13050 + for (bindex = bstart; bindex <= bend; bindex++) {
13051 + h_i = au_h_iptr(inode, bindex);
13055 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
13056 + /* ignore this error */
13057 + /* bad action? */
13060 + /* children inode number will be broken */
13067 +static int hn_gen_tree(struct dentry *dentry)
13069 + int err, i, j, ndentry;
13070 + struct au_dcsub_pages dpages;
13071 + struct au_dpage *dpage;
13072 + struct dentry **dentries;
13074 + err = au_dpages_init(&dpages, GFP_NOFS);
13075 + if (unlikely(err))
13077 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
13078 + if (unlikely(err))
13081 + for (i = 0; i < dpages.ndpage; i++) {
13082 + dpage = dpages.dpages + i;
13083 + dentries = dpage->dentries;
13084 + ndentry = dpage->ndentry;
13085 + for (j = 0; j < ndentry; j++) {
13086 + struct dentry *d;
13094 + /* todo: reset children xino?
13095 + cached children only? */
13096 + au_iigen_dec(d->d_inode);
13101 + au_dpages_free(&dpages);
13104 + /* discard children */
13105 + dentry_unhash(dentry);
13113 + * return 0 if processed.
13115 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
13116 + const unsigned int isdir)
13119 + struct dentry *d;
13120 + struct qstr *dname;
13123 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
13124 + pr_warn("branch root dir was changed\n");
13130 + AuDebugOn(!name);
13131 + au_iigen_dec(inode);
13132 + spin_lock(&inode->i_lock);
13133 + list_for_each_entry(d, &inode->i_dentry, d_alias) {
13134 + spin_lock(&d->d_lock);
13135 + dname = &d->d_name;
13136 + if (dname->len != nlen
13137 + && memcmp(dname->name, name, nlen)) {
13138 + spin_unlock(&d->d_lock);
13143 + spin_unlock(&d->d_lock);
13146 + spin_unlock(&inode->i_lock);
13148 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
13149 + d = d_find_alias(inode);
13151 + au_iigen_dec(inode);
13155 + spin_lock(&d->d_lock);
13156 + dname = &d->d_name;
13157 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
13158 + spin_unlock(&d->d_lock);
13159 + err = hn_gen_tree(d);
13160 + spin_lock(&d->d_lock);
13162 + spin_unlock(&d->d_lock);
13171 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
13174 + struct inode *inode;
13176 + inode = dentry->d_inode;
13177 + if (IS_ROOT(dentry)
13178 + /* || (inode && inode->i_ino == AUFS_ROOT_INO) */
13180 + pr_warn("branch root dir was changed\n");
13186 + au_digen_dec(dentry);
13188 + au_iigen_dec(inode);
13190 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
13192 + err = hn_gen_tree(dentry);
13199 +/* ---------------------------------------------------------------------- */
13201 +/* hnotify job flags */
13202 +#define AuHnJob_XINO0 1
13203 +#define AuHnJob_GEN (1 << 1)
13204 +#define AuHnJob_DIRENT (1 << 2)
13205 +#define AuHnJob_ISDIR (1 << 3)
13206 +#define AuHnJob_TRYXINO0 (1 << 4)
13207 +#define AuHnJob_MNTPNT (1 << 5)
13208 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
13209 +#define au_fset_hnjob(flags, name) \
13210 + do { (flags) |= AuHnJob_##name; } while (0)
13211 +#define au_fclr_hnjob(flags, name) \
13212 + do { (flags) &= ~AuHnJob_##name; } while (0)
13220 +struct au_hnotify_args {
13221 + struct inode *h_dir, *dir, *h_child_inode;
13223 + unsigned int flags[AuHnLast];
13224 + unsigned int h_child_nlen;
13225 + char h_child_name[];
13228 +struct hn_job_args {
13229 + unsigned int flags;
13230 + struct inode *inode, *h_inode, *dir, *h_dir;
13231 + struct dentry *dentry;
13236 +static int hn_job(struct hn_job_args *a)
13238 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
13241 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
13242 + hn_xino(a->inode, a->h_inode); /* ignore this error */
13244 + if (au_ftest_hnjob(a->flags, TRYXINO0)
13247 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
13248 + if (!a->h_inode->i_nlink)
13249 + hn_xino(a->inode, a->h_inode); /* ignore this error */
13250 + mutex_unlock(&a->h_inode->i_mutex);
13253 + /* make the generation obsolete */
13254 + if (au_ftest_hnjob(a->flags, GEN)) {
13257 + err = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
13259 + if (err && a->dentry)
13260 + hn_gen_by_name(a->dentry, isdir);
13261 + /* ignore this error */
13264 + /* make dir entries obsolete */
13265 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
13266 + struct au_vdir *vdir;
13268 + vdir = au_ivdir(a->inode);
13270 + vdir->vd_jiffy = 0;
13271 + /* IMustLock(a->inode); */
13272 + /* a->inode->i_version++; */
13275 + /* can do nothing but warn */
13276 + if (au_ftest_hnjob(a->flags, MNTPNT)
13278 + && d_mountpoint(a->dentry))
13279 + pr_warn("mount-point %.*s is removed or renamed\n",
13280 + AuDLNPair(a->dentry));
13285 +/* ---------------------------------------------------------------------- */
13287 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
13288 + struct inode *dir)
13290 + struct dentry *dentry, *d, *parent;
13291 + struct qstr *dname;
13293 + parent = d_find_alias(dir);
13298 + spin_lock(&parent->d_lock);
13299 + list_for_each_entry(d, &parent->d_subdirs, d_u.d_child) {
13300 + /* AuDbg("%.*s\n", AuDLNPair(d)); */
13301 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
13302 + dname = &d->d_name;
13303 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
13304 + goto cont_unlock;
13308 + goto cont_unlock;
13309 + if (d->d_count) {
13310 + dentry = dget_dlock(d);
13311 + spin_unlock(&d->d_lock);
13316 + spin_unlock(&d->d_lock);
13318 + spin_unlock(&parent->d_lock);
13322 + di_write_lock_child(dentry);
13327 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
13328 + aufs_bindex_t bindex, ino_t h_ino)
13330 + struct inode *inode;
13335 + err = au_xino_read(sb, bindex, h_ino, &ino);
13337 + inode = ilookup(sb, ino);
13341 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
13342 + pr_warn("wrong root branch\n");
13348 + ii_write_lock_child(inode);
13354 +static void au_hn_bh(void *_args)
13356 + struct au_hnotify_args *a = _args;
13357 + struct super_block *sb;
13358 + aufs_bindex_t bindex, bend, bfound;
13359 + unsigned char xino, try_iput;
13361 + struct inode *inode;
13363 + struct hn_job_args args;
13364 + struct dentry *dentry;
13365 + struct au_sbinfo *sbinfo;
13367 + AuDebugOn(!_args);
13368 + AuDebugOn(!a->h_dir);
13369 + AuDebugOn(!a->dir);
13370 + AuDebugOn(!a->mask);
13371 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
13372 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
13373 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
13378 + * do not lock a->dir->i_mutex here
13379 + * because of d_revalidate() may cause a deadlock.
13381 + sb = a->dir->i_sb;
13383 + sbinfo = au_sbi(sb);
13384 + AuDebugOn(!sbinfo);
13385 + si_write_lock(sb, AuLock_NOPLMW);
13387 + ii_read_lock_parent(a->dir);
13389 + bend = au_ibend(a->dir);
13390 + for (bindex = au_ibstart(a->dir); bindex <= bend; bindex++)
13391 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
13395 + ii_read_unlock(a->dir);
13396 + if (unlikely(bfound < 0))
13399 + xino = !!au_opt_test(au_mntflags(sb), XINO);
13401 + if (a->h_child_inode)
13402 + h_ino = a->h_child_inode->i_ino;
13404 + if (a->h_child_nlen
13405 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
13406 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
13407 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
13411 + inode = dentry->d_inode;
13412 + if (xino && !inode && h_ino
13413 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
13414 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
13415 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
13416 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
13420 + args.flags = a->flags[AuHn_CHILD];
13421 + args.dentry = dentry;
13422 + args.inode = inode;
13423 + args.h_inode = a->h_child_inode;
13424 + args.dir = a->dir;
13425 + args.h_dir = a->h_dir;
13426 + args.h_name = a->h_child_name;
13427 + args.h_nlen = a->h_child_nlen;
13428 + err = hn_job(&args);
13430 + if (au_di(dentry))
13431 + di_write_unlock(dentry);
13434 + if (inode && try_iput) {
13435 + ii_write_unlock(inode);
13439 + ii_write_lock_parent(a->dir);
13440 + args.flags = a->flags[AuHn_PARENT];
13441 + args.dentry = NULL;
13442 + args.inode = a->dir;
13443 + args.h_inode = a->h_dir;
13445 + args.h_dir = NULL;
13446 + args.h_name = NULL;
13448 + err = hn_job(&args);
13449 + ii_write_unlock(a->dir);
13452 + iput(a->h_child_inode);
13455 + si_write_unlock(sb);
13456 + au_nwt_done(&sbinfo->si_nowait);
13460 +/* ---------------------------------------------------------------------- */
13462 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
13463 + struct qstr *h_child_qstr, struct inode *h_child_inode)
13466 + unsigned int flags[AuHnLast], f;
13467 + unsigned char isdir, isroot, wh;
13468 + struct inode *dir;
13469 + struct au_hnotify_args *args;
13470 + char *p, *h_child_name;
13473 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
13474 + dir = igrab(hnotify->hn_aufs_inode);
13478 + isroot = (dir->i_ino == AUFS_ROOT_INO);
13480 + h_child_name = (void *)h_child_qstr->name;
13481 + len = h_child_qstr->len;
13482 + if (h_child_name) {
13483 + if (len > AUFS_WH_PFX_LEN
13484 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
13485 + h_child_name += AUFS_WH_PFX_LEN;
13486 + len -= AUFS_WH_PFX_LEN;
13492 + if (h_child_inode)
13493 + isdir = !!S_ISDIR(h_child_inode->i_mode);
13494 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
13495 + flags[AuHn_CHILD] = 0;
13497 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
13498 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
13499 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
13500 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
13501 + case FS_MOVED_FROM:
13502 + case FS_MOVED_TO:
13503 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
13504 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
13507 + AuDebugOn(!h_child_name || !h_child_inode);
13512 + * aufs never be able to get this child inode.
13513 + * revalidation should be in d_revalidate()
13514 + * by checking i_nlink, i_generation or d_unhashed().
13516 + AuDebugOn(!h_child_name);
13517 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
13518 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
13526 + h_child_inode = NULL;
13529 + /* iput() and kfree() will be called in au_hnotify() */
13530 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
13531 + if (unlikely(!args)) {
13532 + AuErr1("no memory\n");
13536 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
13537 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
13538 + args->mask = mask;
13540 + args->h_dir = igrab(h_dir);
13541 + if (h_child_inode)
13542 + h_child_inode = igrab(h_child_inode); /* can be NULL */
13543 + args->h_child_inode = h_child_inode;
13544 + args->h_child_nlen = len;
13546 + p = (void *)args;
13547 + p += sizeof(*args);
13548 + memcpy(p, h_child_name, len);
13553 + if (!dir->i_nlink)
13555 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
13556 + if (unlikely(err)) {
13557 + pr_err("wkq %d\n", err);
13558 + iput(args->h_child_inode);
13559 + iput(args->h_dir);
13568 +/* ---------------------------------------------------------------------- */
13570 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
13574 + AuDebugOn(!(udba & AuOptMask_UDBA));
13577 + if (au_hnotify_op.reset_br)
13578 + err = au_hnotify_op.reset_br(udba, br, perm);
13583 +int au_hnotify_init_br(struct au_branch *br, int perm)
13588 + if (au_hnotify_op.init_br)
13589 + err = au_hnotify_op.init_br(br, perm);
13594 +void au_hnotify_fin_br(struct au_branch *br)
13596 + if (au_hnotify_op.fin_br)
13597 + au_hnotify_op.fin_br(br);
13600 +static void au_hn_destroy_cache(void)
13602 + kmem_cache_destroy(au_cachep[AuCache_HNOTIFY]);
13603 + au_cachep[AuCache_HNOTIFY] = NULL;
13606 +int __init au_hnotify_init(void)
13611 + au_cachep[AuCache_HNOTIFY] = AuCache(au_hnotify);
13612 + if (au_cachep[AuCache_HNOTIFY]) {
13614 + if (au_hnotify_op.init)
13615 + err = au_hnotify_op.init();
13616 + if (unlikely(err))
13617 + au_hn_destroy_cache();
13623 +void au_hnotify_fin(void)
13625 + if (au_hnotify_op.fin)
13626 + au_hnotify_op.fin();
13627 + /* cf. au_cache_fin() */
13628 + if (au_cachep[AuCache_HNOTIFY])
13629 + au_hn_destroy_cache();
13631 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
13632 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
13633 +++ linux/fs/aufs/iinfo.c 2012-07-22 19:57:03.164337936 +0200
13636 + * Copyright (C) 2005-2012 Junjiro R. Okajima
13638 + * This program, aufs is free software; you can redistribute it and/or modify
13639 + * it under the terms of the GNU General Public License as published by
13640 + * the Free Software Foundation; either version 2 of the License, or
13641 + * (at your option) any later version.
13643 + * This program is distributed in the hope that it will be useful,
13644 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13645 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13646 + * GNU General Public License for more details.
13648 + * You should have received a copy of the GNU General Public License
13649 + * along with this program; if not, write to the Free Software
13650 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13654 + * inode private data
13659 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
13661 + struct inode *h_inode;
13663 + IiMustAnyLock(inode);
13665 + h_inode = au_ii(inode)->ii_hinode[0 + bindex].hi_inode;
13666 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
13670 +/* todo: hard/soft set? */
13671 +void au_hiput(struct au_hinode *hinode)
13673 + au_hn_free(hinode);
13674 + dput(hinode->hi_whdentry);
13675 + iput(hinode->hi_inode);
13678 +unsigned int au_hi_flags(struct inode *inode, int isdir)
13680 + unsigned int flags;
13681 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
13684 + if (au_opt_test(mnt_flags, XINO))
13685 + au_fset_hi(flags, XINO);
13686 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
13687 + au_fset_hi(flags, HNOTIFY);
13691 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
13692 + struct inode *h_inode, unsigned int flags)
13694 + struct au_hinode *hinode;
13695 + struct inode *hi;
13696 + struct au_iinfo *iinfo = au_ii(inode);
13698 + IiMustWriteLock(inode);
13700 + hinode = iinfo->ii_hinode + bindex;
13701 + hi = hinode->hi_inode;
13702 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
13705 + au_hiput(hinode);
13706 + hinode->hi_inode = h_inode;
13709 + struct super_block *sb = inode->i_sb;
13710 + struct au_branch *br;
13712 + AuDebugOn(inode->i_mode
13713 + && (h_inode->i_mode & S_IFMT)
13714 + != (inode->i_mode & S_IFMT));
13715 + if (bindex == iinfo->ii_bstart)
13716 + au_cpup_igen(inode, h_inode);
13717 + br = au_sbr(sb, bindex);
13718 + hinode->hi_id = br->br_id;
13719 + if (au_ftest_hi(flags, XINO)) {
13720 + err = au_xino_write(sb, bindex, h_inode->i_ino,
13722 + if (unlikely(err))
13723 + AuIOErr1("failed au_xino_write() %d\n", err);
13726 + if (au_ftest_hi(flags, HNOTIFY)
13727 + && au_br_hnotifyable(br->br_perm)) {
13728 + err = au_hn_alloc(hinode, inode);
13729 + if (unlikely(err))
13730 + AuIOErr1("au_hn_alloc() %d\n", err);
13735 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
13736 + struct dentry *h_wh)
13738 + struct au_hinode *hinode;
13740 + IiMustWriteLock(inode);
13742 + hinode = au_ii(inode)->ii_hinode + bindex;
13743 + AuDebugOn(hinode->hi_whdentry);
13744 + hinode->hi_whdentry = h_wh;
13747 +void au_update_iigen(struct inode *inode)
13749 + atomic_set(&au_ii(inode)->ii_generation, au_sigen(inode->i_sb));
13750 + /* smp_mb(); */ /* atomic_set */
13753 +/* it may be called at remount time, too */
13754 +void au_update_ibrange(struct inode *inode, int do_put_zero)
13756 + struct au_iinfo *iinfo;
13757 + aufs_bindex_t bindex, bend;
13759 + iinfo = au_ii(inode);
13763 + IiMustWriteLock(inode);
13765 + if (do_put_zero && iinfo->ii_bstart >= 0) {
13766 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
13768 + struct inode *h_i;
13770 + h_i = iinfo->ii_hinode[0 + bindex].hi_inode;
13771 + if (h_i && !h_i->i_nlink)
13772 + au_set_h_iptr(inode, bindex, NULL, 0);
13776 + iinfo->ii_bstart = -1;
13777 + iinfo->ii_bend = -1;
13778 + bend = au_sbend(inode->i_sb);
13779 + for (bindex = 0; bindex <= bend; bindex++)
13780 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
13781 + iinfo->ii_bstart = bindex;
13784 + if (iinfo->ii_bstart >= 0)
13785 + for (bindex = bend; bindex >= iinfo->ii_bstart; bindex--)
13786 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
13787 + iinfo->ii_bend = bindex;
13790 + AuDebugOn(iinfo->ii_bstart > iinfo->ii_bend);
13793 +/* ---------------------------------------------------------------------- */
13795 +void au_icntnr_init_once(void *_c)
13797 + struct au_icntnr *c = _c;
13798 + struct au_iinfo *iinfo = &c->iinfo;
13799 + static struct lock_class_key aufs_ii;
13801 + au_rw_init(&iinfo->ii_rwsem);
13802 + au_rw_class(&iinfo->ii_rwsem, &aufs_ii);
13803 + inode_init_once(&c->vfs_inode);
13806 +int au_iinfo_init(struct inode *inode)
13808 + struct au_iinfo *iinfo;
13809 + struct super_block *sb;
13812 + sb = inode->i_sb;
13813 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
13814 + nbr = au_sbend(sb) + 1;
13815 + if (unlikely(nbr <= 0))
13817 + iinfo->ii_hinode = kcalloc(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
13818 + if (iinfo->ii_hinode) {
13819 + au_ninodes_inc(sb);
13820 + for (i = 0; i < nbr; i++)
13821 + iinfo->ii_hinode[i].hi_id = -1;
13823 + atomic_set(&iinfo->ii_generation, au_sigen(sb));
13824 + /* smp_mb(); */ /* atomic_set */
13825 + iinfo->ii_bstart = -1;
13826 + iinfo->ii_bend = -1;
13827 + iinfo->ii_vdir = NULL;
13833 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr)
13836 + struct au_hinode *hip;
13838 + AuRwMustWriteLock(&iinfo->ii_rwsem);
13841 + sz = sizeof(*hip) * (iinfo->ii_bend + 1);
13843 + sz = sizeof(*hip);
13844 + hip = au_kzrealloc(iinfo->ii_hinode, sz, sizeof(*hip) * nbr, GFP_NOFS);
13846 + iinfo->ii_hinode = hip;
13853 +void au_iinfo_fin(struct inode *inode)
13855 + struct au_iinfo *iinfo;
13856 + struct au_hinode *hi;
13857 + struct super_block *sb;
13858 + aufs_bindex_t bindex, bend;
13859 + const unsigned char unlinked = !inode->i_nlink;
13861 + iinfo = au_ii(inode);
13862 + /* bad_inode case */
13866 + sb = inode->i_sb;
13867 + au_ninodes_dec(sb);
13868 + if (si_pid_test(sb))
13869 + au_xino_delete_inode(inode, unlinked);
13872 + * it is safe to hide the dependency between sbinfo and
13876 + si_noflush_read_lock(sb);
13877 + au_xino_delete_inode(inode, unlinked);
13878 + si_read_unlock(sb);
13882 + if (iinfo->ii_vdir)
13883 + au_vdir_free(iinfo->ii_vdir);
13885 + bindex = iinfo->ii_bstart;
13886 + if (bindex >= 0) {
13887 + hi = iinfo->ii_hinode + bindex;
13888 + bend = iinfo->ii_bend;
13889 + while (bindex++ <= bend) {
13890 + if (hi->hi_inode)
13895 + kfree(iinfo->ii_hinode);
13896 + iinfo->ii_hinode = NULL;
13897 + AuRwDestroy(&iinfo->ii_rwsem);
13899 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
13900 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
13901 +++ linux/fs/aufs/inode.c 2012-07-22 19:57:03.164337936 +0200
13904 + * Copyright (C) 2005-2012 Junjiro R. Okajima
13906 + * This program, aufs is free software; you can redistribute it and/or modify
13907 + * it under the terms of the GNU General Public License as published by
13908 + * the Free Software Foundation; either version 2 of the License, or
13909 + * (at your option) any later version.
13911 + * This program is distributed in the hope that it will be useful,
13912 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13913 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13914 + * GNU General Public License for more details.
13916 + * You should have received a copy of the GNU General Public License
13917 + * along with this program; if not, write to the Free Software
13918 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13922 + * inode functions
13927 +struct inode *au_igrab(struct inode *inode)
13930 + AuDebugOn(!atomic_read(&inode->i_count));
13936 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
13938 + au_cpup_attr_all(inode, /*force*/0);
13939 + au_update_iigen(inode);
13941 + inode->i_version++;
13944 +static int au_ii_refresh(struct inode *inode, int *update)
13948 + aufs_bindex_t bindex, new_bindex;
13949 + struct super_block *sb;
13950 + struct au_iinfo *iinfo;
13951 + struct au_hinode *p, *q, tmp;
13953 + IiMustWriteLock(inode);
13956 + sb = inode->i_sb;
13957 + type = inode->i_mode & S_IFMT;
13958 + iinfo = au_ii(inode);
13959 + err = au_ii_realloc(iinfo, au_sbend(sb) + 1);
13960 + if (unlikely(err))
13963 + AuDebugOn(iinfo->ii_bstart < 0);
13964 + p = iinfo->ii_hinode + iinfo->ii_bstart;
13965 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
13967 + if (!p->hi_inode)
13970 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
13971 + new_bindex = au_br_index(sb, p->hi_id);
13972 + if (new_bindex == bindex)
13975 + if (new_bindex < 0) {
13978 + p->hi_inode = NULL;
13982 + if (new_bindex < iinfo->ii_bstart)
13983 + iinfo->ii_bstart = new_bindex;
13984 + if (iinfo->ii_bend < new_bindex)
13985 + iinfo->ii_bend = new_bindex;
13986 + /* swap two lower inode, and loop again */
13987 + q = iinfo->ii_hinode + new_bindex;
13991 + if (tmp.hi_inode) {
13996 + au_update_ibrange(inode, /*do_put_zero*/0);
13997 + e = au_dy_irefresh(inode);
13998 + if (unlikely(e && !err))
14006 +int au_refresh_hinode_self(struct inode *inode)
14010 + err = au_ii_refresh(inode, &update);
14012 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
14018 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
14020 + int err, e, update;
14021 + unsigned int flags;
14023 + aufs_bindex_t bindex, bend;
14024 + unsigned char isdir;
14025 + struct au_hinode *p;
14026 + struct au_iinfo *iinfo;
14028 + err = au_ii_refresh(inode, &update);
14029 + if (unlikely(err))
14033 + iinfo = au_ii(inode);
14034 + p = iinfo->ii_hinode + iinfo->ii_bstart;
14035 + mode = (inode->i_mode & S_IFMT);
14036 + isdir = S_ISDIR(mode);
14037 + flags = au_hi_flags(inode, isdir);
14038 + bend = au_dbend(dentry);
14039 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
14040 + struct inode *h_i;
14041 + struct dentry *h_d;
14043 + h_d = au_h_dptr(dentry, bindex);
14044 + if (!h_d || !h_d->d_inode)
14047 + AuDebugOn(mode != (h_d->d_inode->i_mode & S_IFMT));
14048 + if (iinfo->ii_bstart <= bindex && bindex <= iinfo->ii_bend) {
14049 + h_i = au_h_iptr(inode, bindex);
14051 + if (h_i == h_d->d_inode)
14057 + if (bindex < iinfo->ii_bstart)
14058 + iinfo->ii_bstart = bindex;
14059 + if (iinfo->ii_bend < bindex)
14060 + iinfo->ii_bend = bindex;
14061 + au_set_h_iptr(inode, bindex, au_igrab(h_d->d_inode), flags);
14064 + au_update_ibrange(inode, /*do_put_zero*/0);
14065 + e = au_dy_irefresh(inode);
14066 + if (unlikely(e && !err))
14069 + au_refresh_hinode_attr(inode, update && isdir);
14076 +static int set_inode(struct inode *inode, struct dentry *dentry)
14079 + unsigned int flags;
14081 + aufs_bindex_t bindex, bstart, btail;
14082 + unsigned char isdir;
14083 + struct dentry *h_dentry;
14084 + struct inode *h_inode;
14085 + struct au_iinfo *iinfo;
14087 + IiMustWriteLock(inode);
14091 + bstart = au_dbstart(dentry);
14092 + h_inode = au_h_dptr(dentry, bstart)->d_inode;
14093 + mode = h_inode->i_mode;
14094 + switch (mode & S_IFMT) {
14096 + btail = au_dbtail(dentry);
14097 + inode->i_op = &aufs_iop;
14098 + inode->i_fop = &aufs_file_fop;
14099 + err = au_dy_iaop(inode, bstart, h_inode);
14100 + if (unlikely(err))
14105 + btail = au_dbtaildir(dentry);
14106 + inode->i_op = &aufs_dir_iop;
14107 + inode->i_fop = &aufs_dir_fop;
14110 + btail = au_dbtail(dentry);
14111 + inode->i_op = &aufs_symlink_iop;
14117 + btail = au_dbtail(dentry);
14118 + inode->i_op = &aufs_iop;
14119 + au_init_special_fop(inode, mode, h_inode->i_rdev);
14122 + AuIOErr("Unknown file type 0%o\n", mode);
14127 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
14128 + flags = au_hi_flags(inode, isdir);
14129 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
14130 + && au_ftest_hi(flags, HNOTIFY)
14131 + && dentry->d_name.len > AUFS_WH_PFX_LEN
14132 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
14133 + au_fclr_hi(flags, HNOTIFY);
14134 + iinfo = au_ii(inode);
14135 + iinfo->ii_bstart = bstart;
14136 + iinfo->ii_bend = btail;
14137 + for (bindex = bstart; bindex <= btail; bindex++) {
14138 + h_dentry = au_h_dptr(dentry, bindex);
14140 + au_set_h_iptr(inode, bindex,
14141 + au_igrab(h_dentry->d_inode), flags);
14143 + au_cpup_attr_all(inode, /*force*/1);
14150 + * successful returns with iinfo write_locked
14152 + * zero: success, matched
14153 + * plus: no error, but unmatched
14155 +static int reval_inode(struct inode *inode, struct dentry *dentry)
14158 + aufs_bindex_t bindex, bend;
14159 + struct inode *h_inode, *h_dinode;
14162 + * before this function, if aufs got any iinfo lock, it must be only
14163 + * one, the parent dir.
14164 + * it can happen by UDBA and the obsoleted inode number.
14167 + if (unlikely(inode->i_ino == parent_ino(dentry)))
14171 + ii_write_lock_new_child(inode);
14172 + h_dinode = au_h_dptr(dentry, au_dbstart(dentry))->d_inode;
14173 + bend = au_ibend(inode);
14174 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
14175 + h_inode = au_h_iptr(inode, bindex);
14176 + if (h_inode && h_inode == h_dinode) {
14178 + if (au_iigen_test(inode, au_digen(dentry)))
14179 + err = au_refresh_hinode(inode, dentry);
14184 + if (unlikely(err))
14185 + ii_write_unlock(inode);
14190 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
14191 + unsigned int d_type, ino_t *ino)
14194 + struct mutex *mtx;
14196 + /* prevent hardlinked inode number from race condition */
14198 + if (d_type != DT_DIR) {
14199 + mtx = &au_sbr(sb, bindex)->br_xino.xi_nondir_mtx;
14202 + err = au_xino_read(sb, bindex, h_ino, ino);
14203 + if (unlikely(err))
14208 + *ino = au_xino_new_ino(sb);
14209 + if (unlikely(!*ino))
14211 + err = au_xino_write(sb, bindex, h_ino, *ino);
14212 + if (unlikely(err))
14218 + mutex_unlock(mtx);
14222 +/* successful returns with iinfo write_locked */
14223 +/* todo: return with unlocked? */
14224 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
14226 + struct inode *inode, *h_inode;
14227 + struct dentry *h_dentry;
14228 + struct super_block *sb;
14229 + struct mutex *mtx;
14230 + ino_t h_ino, ino;
14232 + aufs_bindex_t bstart;
14234 + sb = dentry->d_sb;
14235 + bstart = au_dbstart(dentry);
14236 + h_dentry = au_h_dptr(dentry, bstart);
14237 + h_inode = h_dentry->d_inode;
14238 + h_ino = h_inode->i_ino;
14241 + * stop 'race'-ing between hardlinks under different
14245 + if (!S_ISDIR(h_inode->i_mode))
14246 + mtx = &au_sbr(sb, bstart)->br_xino.xi_nondir_mtx;
14251 + err = au_xino_read(sb, bstart, h_ino, &ino);
14252 + inode = ERR_PTR(err);
14253 + if (unlikely(err))
14257 + ino = au_xino_new_ino(sb);
14258 + if (unlikely(!ino)) {
14259 + inode = ERR_PTR(-EIO);
14264 + AuDbg("i%lu\n", (unsigned long)ino);
14265 + inode = au_iget_locked(sb, ino);
14266 + err = PTR_ERR(inode);
14267 + if (IS_ERR(inode))
14270 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
14271 + if (inode->i_state & I_NEW) {
14272 + ii_write_lock_new_child(inode);
14273 + err = set_inode(inode, dentry);
14275 + unlock_new_inode(inode);
14276 + goto out; /* success */
14280 + * iget_failed() calls iput(), but we need to call
14281 + * ii_write_unlock() after iget_failed(). so dirty hack for
14284 + atomic_inc(&inode->i_count);
14285 + iget_failed(inode);
14286 + ii_write_unlock(inode);
14287 + au_xino_write(sb, bstart, h_ino, /*ino*/0);
14288 + /* ignore this error */
14290 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
14292 + * horrible race condition between lookup, readdir and copyup
14293 + * (or something).
14296 + mutex_unlock(mtx);
14297 + err = reval_inode(inode, dentry);
14298 + if (unlikely(err < 0)) {
14305 + goto out; /* success */
14310 + if (unlikely(au_test_fs_unique_ino(h_dentry->d_inode)))
14311 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
14312 + " b%d, %s, %.*s, hi%lu, i%lu.\n",
14313 + bstart, au_sbtype(h_dentry->d_sb), AuDLNPair(dentry),
14314 + (unsigned long)h_ino, (unsigned long)ino);
14316 + err = au_xino_write(sb, bstart, h_ino, /*ino*/0);
14320 + mutex_unlock(mtx);
14326 + inode = ERR_PTR(err);
14329 + mutex_unlock(mtx);
14333 +/* ---------------------------------------------------------------------- */
14335 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
14336 + struct inode *inode)
14340 + err = au_br_rdonly(au_sbr(sb, bindex));
14342 + /* pseudo-link after flushed may happen out of bounds */
14345 + && au_ibstart(inode) <= bindex
14346 + && bindex <= au_ibend(inode)) {
14348 + * permission check is unnecessary since vfsub routine
14349 + * will be called later
14351 + struct inode *hi = au_h_iptr(inode, bindex);
14353 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
14359 +int au_test_h_perm(struct inode *h_inode, int mask)
14361 + if (current_fsuid() == GLOBAL_ROOT_GID)
14363 + return inode_permission(h_inode, mask);
14366 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
14368 + if (au_test_nfs(h_inode->i_sb)
14369 + && (mask & MAY_WRITE)
14370 + && S_ISDIR(h_inode->i_mode))
14371 + mask |= MAY_READ; /* force permission check */
14372 + return au_test_h_perm(h_inode, mask);
14374 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
14375 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
14376 +++ linux/fs/aufs/inode.h 2012-07-22 19:57:03.164337936 +0200
14379 + * Copyright (C) 2005-2012 Junjiro R. Okajima
14381 + * This program, aufs is free software; you can redistribute it and/or modify
14382 + * it under the terms of the GNU General Public License as published by
14383 + * the Free Software Foundation; either version 2 of the License, or
14384 + * (at your option) any later version.
14386 + * This program is distributed in the hope that it will be useful,
14387 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14388 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14389 + * GNU General Public License for more details.
14391 + * You should have received a copy of the GNU General Public License
14392 + * along with this program; if not, write to the Free Software
14393 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14397 + * inode operations
14400 +#ifndef __AUFS_INODE_H__
14401 +#define __AUFS_INODE_H__
14405 +#include <linux/fsnotify.h>
14406 +#include "rwsem.h"
14410 +struct au_hnotify {
14411 +#ifdef CONFIG_AUFS_HNOTIFY
14412 +#ifdef CONFIG_AUFS_HFSNOTIFY
14413 + /* never use fsnotify_add_vfsmount_mark() */
14414 + struct fsnotify_mark hn_mark;
14416 + struct inode *hn_aufs_inode; /* no get/put */
14418 +} ____cacheline_aligned_in_smp;
14420 +struct au_hinode {
14421 + struct inode *hi_inode;
14422 + aufs_bindex_t hi_id;
14423 +#ifdef CONFIG_AUFS_HNOTIFY
14424 + struct au_hnotify *hi_notify;
14427 + /* reference to the copied-up whiteout with get/put */
14428 + struct dentry *hi_whdentry;
14433 + atomic_t ii_generation;
14434 + struct super_block *ii_hsb1; /* no get/put */
14436 + struct au_rwsem ii_rwsem;
14437 + aufs_bindex_t ii_bstart, ii_bend;
14439 + struct au_hinode *ii_hinode;
14440 + struct au_vdir *ii_vdir;
14443 +struct au_icntnr {
14444 + struct au_iinfo iinfo;
14445 + struct inode vfs_inode;
14446 +} ____cacheline_aligned_in_smp;
14448 +/* au_pin flags */
14449 +#define AuPin_DI_LOCKED 1
14450 +#define AuPin_MNT_WRITE (1 << 1)
14451 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
14452 +#define au_fset_pin(flags, name) \
14453 + do { (flags) |= AuPin_##name; } while (0)
14454 +#define au_fclr_pin(flags, name) \
14455 + do { (flags) &= ~AuPin_##name; } while (0)
14459 + struct dentry *dentry;
14460 + unsigned int udba;
14461 + unsigned char lsc_di, lsc_hi, flags;
14462 + aufs_bindex_t bindex;
14465 + struct dentry *parent;
14466 + struct au_hinode *hdir;
14467 + struct vfsmount *h_mnt;
14470 +/* ---------------------------------------------------------------------- */
14472 +static inline struct au_iinfo *au_ii(struct inode *inode)
14474 + struct au_iinfo *iinfo;
14476 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
14477 + if (iinfo->ii_hinode)
14479 + return NULL; /* debugging bad_inode case */
14482 +/* ---------------------------------------------------------------------- */
14485 +struct inode *au_igrab(struct inode *inode);
14486 +int au_refresh_hinode_self(struct inode *inode);
14487 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
14488 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
14489 + unsigned int d_type, ino_t *ino);
14490 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
14491 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
14492 + struct inode *inode);
14493 +int au_test_h_perm(struct inode *h_inode, int mask);
14494 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
14496 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
14497 + ino_t h_ino, unsigned int d_type, ino_t *ino)
14499 +#ifdef CONFIG_AUFS_SHWH
14500 + return au_ino(sb, bindex, h_ino, d_type, ino);
14507 +extern struct inode_operations aufs_iop, aufs_symlink_iop, aufs_dir_iop;
14509 +/* au_wr_dir flags */
14510 +#define AuWrDir_ADD_ENTRY 1
14511 +#define AuWrDir_ISDIR (1 << 1)
14512 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
14513 +#define au_fset_wrdir(flags, name) \
14514 + do { (flags) |= AuWrDir_##name; } while (0)
14515 +#define au_fclr_wrdir(flags, name) \
14516 + do { (flags) &= ~AuWrDir_##name; } while (0)
14518 +struct au_wr_dir_args {
14519 + aufs_bindex_t force_btgt;
14520 + unsigned char flags;
14522 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
14523 + struct au_wr_dir_args *args);
14525 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
14526 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
14527 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
14528 + unsigned int udba, unsigned char flags);
14529 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
14530 + unsigned int udba, unsigned char flags) __must_check;
14531 +int au_do_pin(struct au_pin *pin) __must_check;
14532 +void au_unpin(struct au_pin *pin);
14535 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
14536 + struct dentry *h_parent, int isdir);
14537 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
14539 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
14540 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
14541 + struct nameidata *nd);
14542 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
14543 + struct dentry *dentry);
14544 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
14547 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
14548 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
14549 + struct dentry *h_parent, int isdir);
14550 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
14551 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
14554 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
14555 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
14556 + struct inode *dir, struct dentry *dentry);
14559 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
14560 +void au_hiput(struct au_hinode *hinode);
14561 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
14562 + struct dentry *h_wh);
14563 +unsigned int au_hi_flags(struct inode *inode, int isdir);
14565 +/* hinode flags */
14566 +#define AuHi_XINO 1
14567 +#define AuHi_HNOTIFY (1 << 1)
14568 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
14569 +#define au_fset_hi(flags, name) \
14570 + do { (flags) |= AuHi_##name; } while (0)
14571 +#define au_fclr_hi(flags, name) \
14572 + do { (flags) &= ~AuHi_##name; } while (0)
14574 +#ifndef CONFIG_AUFS_HNOTIFY
14575 +#undef AuHi_HNOTIFY
14576 +#define AuHi_HNOTIFY 0
14579 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
14580 + struct inode *h_inode, unsigned int flags);
14582 +void au_update_iigen(struct inode *inode);
14583 +void au_update_ibrange(struct inode *inode, int do_put_zero);
14585 +void au_icntnr_init_once(void *_c);
14586 +int au_iinfo_init(struct inode *inode);
14587 +void au_iinfo_fin(struct inode *inode);
14588 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr);
14590 +#ifdef CONFIG_PROC_FS
14592 +int au_plink_maint(struct super_block *sb, int flags);
14593 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
14594 +int au_plink_maint_enter(struct super_block *sb);
14595 +#ifdef CONFIG_AUFS_DEBUG
14596 +void au_plink_list(struct super_block *sb);
14598 +AuStubVoid(au_plink_list, struct super_block *sb)
14600 +int au_plink_test(struct inode *inode);
14601 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
14602 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
14603 + struct dentry *h_dentry);
14604 +void au_plink_put(struct super_block *sb, int verbose);
14605 +void au_plink_clean(struct super_block *sb, int verbose);
14606 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
14608 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
14609 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
14610 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
14611 +AuStubVoid(au_plink_list, struct super_block *sb);
14612 +AuStubInt0(au_plink_test, struct inode *inode);
14613 +AuStub(struct dentry *, au_plink_lkup, return NULL,
14614 + struct inode *inode, aufs_bindex_t bindex);
14615 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
14616 + struct dentry *h_dentry);
14617 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
14618 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
14619 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
14620 +#endif /* CONFIG_PROC_FS */
14622 +/* ---------------------------------------------------------------------- */
14624 +/* lock subclass for iinfo */
14626 + AuLsc_II_CHILD, /* child first */
14627 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
14628 + AuLsc_II_CHILD3, /* copyup dirs */
14629 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
14630 + AuLsc_II_PARENT2,
14631 + AuLsc_II_PARENT3, /* copyup dirs */
14632 + AuLsc_II_NEW_CHILD
14636 + * ii_read_lock_child, ii_write_lock_child,
14637 + * ii_read_lock_child2, ii_write_lock_child2,
14638 + * ii_read_lock_child3, ii_write_lock_child3,
14639 + * ii_read_lock_parent, ii_write_lock_parent,
14640 + * ii_read_lock_parent2, ii_write_lock_parent2,
14641 + * ii_read_lock_parent3, ii_write_lock_parent3,
14642 + * ii_read_lock_new_child, ii_write_lock_new_child,
14644 +#define AuReadLockFunc(name, lsc) \
14645 +static inline void ii_read_lock_##name(struct inode *i) \
14647 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
14650 +#define AuWriteLockFunc(name, lsc) \
14651 +static inline void ii_write_lock_##name(struct inode *i) \
14653 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
14656 +#define AuRWLockFuncs(name, lsc) \
14657 + AuReadLockFunc(name, lsc) \
14658 + AuWriteLockFunc(name, lsc)
14660 +AuRWLockFuncs(child, CHILD);
14661 +AuRWLockFuncs(child2, CHILD2);
14662 +AuRWLockFuncs(child3, CHILD3);
14663 +AuRWLockFuncs(parent, PARENT);
14664 +AuRWLockFuncs(parent2, PARENT2);
14665 +AuRWLockFuncs(parent3, PARENT3);
14666 +AuRWLockFuncs(new_child, NEW_CHILD);
14668 +#undef AuReadLockFunc
14669 +#undef AuWriteLockFunc
14670 +#undef AuRWLockFuncs
14673 + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock
14675 +AuSimpleUnlockRwsemFuncs(ii, struct inode *i, &au_ii(i)->ii_rwsem);
14677 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
14678 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
14679 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
14681 +/* ---------------------------------------------------------------------- */
14683 +static inline void au_icntnr_init(struct au_icntnr *c)
14685 +#ifdef CONFIG_AUFS_DEBUG
14686 + c->vfs_inode.i_mode = 0;
14690 +static inline unsigned int au_iigen(struct inode *inode)
14692 + return atomic_read(&au_ii(inode)->ii_generation);
14695 +/* tiny test for inode number */
14696 +/* tmpfs generation is too rough */
14697 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
14699 + struct au_iinfo *iinfo;
14701 + iinfo = au_ii(inode);
14702 + AuRwMustAnyLock(&iinfo->ii_rwsem);
14703 + return !(iinfo->ii_hsb1 == h_inode->i_sb
14704 + && iinfo->ii_higen == h_inode->i_generation);
14707 +static inline void au_iigen_dec(struct inode *inode)
14709 + atomic_dec(&au_ii(inode)->ii_generation);
14712 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
14717 + if (unlikely(inode && au_iigen(inode) != sigen))
14723 +/* ---------------------------------------------------------------------- */
14725 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
14726 + aufs_bindex_t bindex)
14728 + IiMustAnyLock(inode);
14729 + return au_ii(inode)->ii_hinode[0 + bindex].hi_id;
14732 +static inline aufs_bindex_t au_ibstart(struct inode *inode)
14734 + IiMustAnyLock(inode);
14735 + return au_ii(inode)->ii_bstart;
14738 +static inline aufs_bindex_t au_ibend(struct inode *inode)
14740 + IiMustAnyLock(inode);
14741 + return au_ii(inode)->ii_bend;
14744 +static inline struct au_vdir *au_ivdir(struct inode *inode)
14746 + IiMustAnyLock(inode);
14747 + return au_ii(inode)->ii_vdir;
14750 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
14752 + IiMustAnyLock(inode);
14753 + return au_ii(inode)->ii_hinode[0 + bindex].hi_whdentry;
14756 +static inline void au_set_ibstart(struct inode *inode, aufs_bindex_t bindex)
14758 + IiMustWriteLock(inode);
14759 + au_ii(inode)->ii_bstart = bindex;
14762 +static inline void au_set_ibend(struct inode *inode, aufs_bindex_t bindex)
14764 + IiMustWriteLock(inode);
14765 + au_ii(inode)->ii_bend = bindex;
14768 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
14770 + IiMustWriteLock(inode);
14771 + au_ii(inode)->ii_vdir = vdir;
14774 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
14776 + IiMustAnyLock(inode);
14777 + return au_ii(inode)->ii_hinode + bindex;
14780 +/* ---------------------------------------------------------------------- */
14782 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
14785 + return pin->parent;
14789 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
14791 + if (pin && pin->hdir)
14792 + return pin->hdir->hi_inode;
14796 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
14799 + return pin->hdir;
14803 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
14806 + pin->dentry = dentry;
14809 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
14810 + unsigned char lflag)
14814 + au_fset_pin(pin->flags, DI_LOCKED);
14816 + au_fclr_pin(pin->flags, DI_LOCKED);
14820 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
14823 + dput(pin->parent);
14824 + pin->parent = dget(parent);
14828 +/* ---------------------------------------------------------------------- */
14831 +#ifdef CONFIG_AUFS_HNOTIFY
14832 +struct au_hnotify_op {
14833 + void (*ctl)(struct au_hinode *hinode, int do_set);
14834 + int (*alloc)(struct au_hinode *hinode);
14837 + * if it returns true, the the caller should free hinode->hi_notify,
14838 + * otherwise ->free() frees it.
14840 + int (*free)(struct au_hinode *hinode,
14841 + struct au_hnotify *hn) __must_check;
14843 + void (*fin)(void);
14844 + int (*init)(void);
14846 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
14847 + void (*fin_br)(struct au_branch *br);
14848 + int (*init_br)(struct au_branch *br, int perm);
14852 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
14853 +void au_hn_free(struct au_hinode *hinode);
14854 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
14855 +void au_hn_reset(struct inode *inode, unsigned int flags);
14856 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
14857 + struct qstr *h_child_qstr, struct inode *h_child_inode);
14858 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
14859 +int au_hnotify_init_br(struct au_branch *br, int perm);
14860 +void au_hnotify_fin_br(struct au_branch *br);
14861 +int __init au_hnotify_init(void);
14862 +void au_hnotify_fin(void);
14865 +extern const struct au_hnotify_op au_hnotify_op;
14868 +void au_hn_init(struct au_hinode *hinode)
14870 + hinode->hi_notify = NULL;
14873 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
14875 + return hinode->hi_notify;
14880 +int au_hn_alloc(struct au_hinode *hinode __maybe_unused,
14881 + struct inode *inode __maybe_unused)
14883 + return -EOPNOTSUPP;
14886 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
14891 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
14892 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
14893 + int do_set __maybe_unused)
14894 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
14895 + unsigned int flags __maybe_unused)
14896 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
14897 + struct au_branch *br __maybe_unused,
14898 + int perm __maybe_unused)
14899 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
14900 + int perm __maybe_unused)
14901 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
14902 +AuStubInt0(__init au_hnotify_init, void)
14903 +AuStubVoid(au_hnotify_fin, void)
14904 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
14905 +#endif /* CONFIG_AUFS_HNOTIFY */
14907 +static inline void au_hn_suspend(struct au_hinode *hdir)
14909 + au_hn_ctl(hdir, /*do_set*/0);
14912 +static inline void au_hn_resume(struct au_hinode *hdir)
14914 + au_hn_ctl(hdir, /*do_set*/1);
14917 +static inline void au_hn_imtx_lock(struct au_hinode *hdir)
14919 + mutex_lock(&hdir->hi_inode->i_mutex);
14920 + au_hn_suspend(hdir);
14923 +static inline void au_hn_imtx_lock_nested(struct au_hinode *hdir,
14924 + unsigned int sc __maybe_unused)
14926 + mutex_lock_nested(&hdir->hi_inode->i_mutex, sc);
14927 + au_hn_suspend(hdir);
14930 +static inline void au_hn_imtx_unlock(struct au_hinode *hdir)
14932 + au_hn_resume(hdir);
14933 + mutex_unlock(&hdir->hi_inode->i_mutex);
14936 +#endif /* __KERNEL__ */
14937 +#endif /* __AUFS_INODE_H__ */
14938 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
14939 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
14940 +++ linux/fs/aufs/ioctl.c 2012-07-22 19:57:03.164337936 +0200
14943 + * Copyright (C) 2005-2012 Junjiro R. Okajima
14945 + * This program, aufs is free software; you can redistribute it and/or modify
14946 + * it under the terms of the GNU General Public License as published by
14947 + * the Free Software Foundation; either version 2 of the License, or
14948 + * (at your option) any later version.
14950 + * This program is distributed in the hope that it will be useful,
14951 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14952 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14953 + * GNU General Public License for more details.
14955 + * You should have received a copy of the GNU General Public License
14956 + * along with this program; if not, write to the Free Software
14957 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14962 + * plink-management and readdir in userspace.
14963 + * assist the pathconf(3) wrapper library.
14968 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
14971 + aufs_bindex_t wbi, bindex, bend;
14972 + struct file *h_file;
14973 + struct super_block *sb;
14974 + struct dentry *root;
14975 + struct au_branch *br;
14976 + struct aufs_wbr_fd wbrfd = {
14977 + .oflags = au_dir_roflags,
14980 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
14981 + | O_NOATIME | O_CLOEXEC;
14983 + AuDebugOn(wbrfd.oflags & ~valid);
14986 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
14987 + if (unlikely(err)) {
14993 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
14994 + wbrfd.oflags |= au_dir_roflags;
14995 + AuDbg("0%o\n", wbrfd.oflags);
14996 + if (unlikely(wbrfd.oflags & ~valid))
15000 + fd = get_unused_fd();
15002 + if (unlikely(fd < 0))
15005 + h_file = ERR_PTR(-EINVAL);
15008 + sb = path->dentry->d_sb;
15009 + root = sb->s_root;
15010 + aufs_read_lock(root, AuLock_IR);
15011 + bend = au_sbend(sb);
15012 + if (wbrfd.brid >= 0) {
15013 + wbi = au_br_index(sb, wbrfd.brid);
15014 + if (unlikely(wbi < 0 || wbi > bend))
15018 + h_file = ERR_PTR(-ENOENT);
15019 + br = au_sbr(sb, wbi);
15020 + if (!au_br_writable(br->br_perm)) {
15024 + bindex = wbi + 1;
15026 + for (; bindex <= bend; bindex++) {
15027 + br = au_sbr(sb, bindex);
15028 + if (au_br_writable(br->br_perm)) {
15030 + br = au_sbr(sb, wbi);
15035 + AuDbg("wbi %d\n", wbi);
15037 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL);
15040 + aufs_read_unlock(root, AuLock_IR);
15041 + err = PTR_ERR(h_file);
15042 + if (IS_ERR(h_file))
15045 + atomic_dec(&br->br_count); /* cf. au_h_open() */
15046 + fd_install(fd, h_file);
15048 + goto out; /* success */
15051 + put_unused_fd(fd);
15057 +/* ---------------------------------------------------------------------- */
15059 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
15064 + case AUFS_CTL_RDU:
15065 + case AUFS_CTL_RDU_INO:
15066 + err = au_rdu_ioctl(file, cmd, arg);
15069 + case AUFS_CTL_WBR_FD:
15070 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
15073 + case AUFS_CTL_IBUSY:
15074 + err = au_ibusy_ioctl(file, arg);
15078 + /* do not call the lower */
15079 + AuDbg("0x%x\n", cmd);
15087 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
15092 + case AUFS_CTL_WBR_FD:
15093 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
15097 + /* do not call the lower */
15098 + AuDbg("0x%x\n", cmd);
15106 +#ifdef CONFIG_COMPAT
15107 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15108 + unsigned long arg)
15113 + case AUFS_CTL_RDU:
15114 + case AUFS_CTL_RDU_INO:
15115 + err = au_rdu_compat_ioctl(file, cmd, arg);
15118 + case AUFS_CTL_IBUSY:
15119 + err = au_ibusy_compat_ioctl(file, arg);
15123 + err = aufs_ioctl_dir(file, cmd, arg);
15130 +#if 0 /* unused yet */
15131 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15132 + unsigned long arg)
15134 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
15138 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
15139 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
15140 +++ linux/fs/aufs/i_op_add.c 2012-07-22 19:57:03.164337936 +0200
15143 + * Copyright (C) 2005-2012 Junjiro R. Okajima
15145 + * This program, aufs is free software; you can redistribute it and/or modify
15146 + * it under the terms of the GNU General Public License as published by
15147 + * the Free Software Foundation; either version 2 of the License, or
15148 + * (at your option) any later version.
15150 + * This program is distributed in the hope that it will be useful,
15151 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15152 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15153 + * GNU General Public License for more details.
15155 + * You should have received a copy of the GNU General Public License
15156 + * along with this program; if not, write to the Free Software
15157 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15161 + * inode operations (add entry)
15167 + * final procedure of adding a new entry, except link(2).
15168 + * remove whiteout, instantiate, copyup the parent dir's times and size
15169 + * and update version.
15170 + * if it failed, re-create the removed whiteout.
15172 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
15173 + struct dentry *wh_dentry, struct dentry *dentry)
15176 + aufs_bindex_t bwh;
15177 + struct path h_path;
15178 + struct inode *inode, *h_dir;
15179 + struct dentry *wh;
15183 + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
15184 + IMustLock(h_dir);
15185 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
15186 + bwh = au_dbwh(dentry);
15187 + h_path.dentry = wh_dentry;
15188 + h_path.mnt = au_sbr_mnt(dir->i_sb, bindex);
15189 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
15191 + if (unlikely(err))
15195 + inode = au_new_inode(dentry, /*must_new*/1);
15196 + if (!IS_ERR(inode)) {
15197 + d_instantiate(dentry, inode);
15198 + dir = dentry->d_parent->d_inode; /* dir inode is locked */
15200 + if (au_ibstart(dir) == au_dbstart(dentry))
15201 + au_cpup_attr_timesizes(dir);
15202 + dir->i_version++;
15203 + return 0; /* success */
15206 + err = PTR_ERR(inode);
15211 + /* dir inode is locked */
15212 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
15213 + rerr = PTR_ERR(wh);
15214 + if (IS_ERR(wh)) {
15215 + AuIOErr("%.*s reverting whiteout failed(%d, %d)\n",
15216 + AuDLNPair(dentry), err, rerr);
15225 +static int au_d_may_add(struct dentry *dentry)
15230 + if (unlikely(d_unhashed(dentry)))
15232 + if (unlikely(dentry->d_inode))
15238 + * simple tests for the adding inode operations.
15239 + * following the checks in vfs, plus the parent-child relationship.
15241 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
15242 + struct dentry *h_parent, int isdir)
15246 + struct dentry *h_dentry;
15247 + struct inode *h_inode;
15249 + err = -ENAMETOOLONG;
15250 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
15253 + h_dentry = au_h_dptr(dentry, bindex);
15254 + h_inode = h_dentry->d_inode;
15255 + if (!dentry->d_inode) {
15257 + if (unlikely(h_inode))
15260 + /* rename(2) case */
15262 + if (unlikely(!h_inode || !h_inode->i_nlink))
15265 + h_mode = h_inode->i_mode;
15268 + if (unlikely(S_ISDIR(h_mode)))
15270 + } else if (unlikely(!S_ISDIR(h_mode))) {
15277 + /* expected parent dir is locked */
15278 + if (unlikely(h_parent != h_dentry->d_parent))
15287 + * initial procedure of adding a new entry.
15288 + * prepare writable branch and the parent dir, lock it,
15289 + * and lookup whiteout for the new entry.
15291 +static struct dentry*
15292 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
15293 + struct dentry *src_dentry, struct au_pin *pin,
15294 + struct au_wr_dir_args *wr_dir_args)
15296 + struct dentry *wh_dentry, *h_parent;
15297 + struct super_block *sb;
15298 + struct au_branch *br;
15300 + unsigned int udba;
15301 + aufs_bindex_t bcpup;
15303 + AuDbg("%.*s\n", AuDLNPair(dentry));
15305 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
15307 + wh_dentry = ERR_PTR(err);
15308 + if (unlikely(err < 0))
15311 + sb = dentry->d_sb;
15312 + udba = au_opt_udba(sb);
15313 + err = au_pin(pin, dentry, bcpup, udba,
15314 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
15315 + wh_dentry = ERR_PTR(err);
15316 + if (unlikely(err))
15319 + h_parent = au_pinned_h_parent(pin);
15320 + if (udba != AuOpt_UDBA_NONE
15321 + && au_dbstart(dentry) == bcpup)
15322 + err = au_may_add(dentry, bcpup, h_parent,
15323 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
15324 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
15325 + err = -ENAMETOOLONG;
15326 + wh_dentry = ERR_PTR(err);
15327 + if (unlikely(err))
15330 + br = au_sbr(sb, bcpup);
15332 + struct path tmp = {
15333 + .dentry = h_parent,
15334 + .mnt = br->br_mnt
15336 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
15339 + wh_dentry = NULL;
15340 + if (bcpup != au_dbwh(dentry))
15341 + goto out; /* success */
15343 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
15346 + if (IS_ERR(wh_dentry))
15349 + return wh_dentry;
15352 +/* ---------------------------------------------------------------------- */
15354 +enum { Mknod, Symlink, Creat };
15355 +struct simple_arg {
15360 + struct nameidata *nd;
15363 + const char *symname;
15372 +static int add_simple(struct inode *dir, struct dentry *dentry,
15373 + struct simple_arg *arg)
15376 + aufs_bindex_t bstart;
15377 + unsigned char created;
15378 + struct au_dtime dt;
15379 + struct au_pin pin;
15380 + struct path h_path;
15381 + struct dentry *wh_dentry, *parent;
15382 + struct inode *h_dir;
15383 + struct au_wr_dir_args wr_dir_args = {
15384 + .force_btgt = -1,
15385 + .flags = AuWrDir_ADD_ENTRY
15388 + AuDbg("%.*s\n", AuDLNPair(dentry));
15391 + parent = dentry->d_parent; /* dir inode is locked */
15392 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
15393 + if (unlikely(err))
15395 + err = au_d_may_add(dentry);
15396 + if (unlikely(err))
15398 + di_write_lock_parent(parent);
15399 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, /*src_dentry*/NULL, &pin,
15401 + err = PTR_ERR(wh_dentry);
15402 + if (IS_ERR(wh_dentry))
15405 + bstart = au_dbstart(dentry);
15406 + h_path.dentry = au_h_dptr(dentry, bstart);
15407 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
15408 + h_dir = au_pinned_h_dir(&pin);
15409 + switch (arg->type) {
15411 + err = vfsub_create(h_dir, &h_path, arg->u.c.mode);
15414 + err = vfsub_symlink(h_dir, &h_path, arg->u.s.symname);
15417 + err = vfsub_mknod(h_dir, &h_path, arg->u.m.mode, arg->u.m.dev);
15424 + err = epilog(dir, bstart, wh_dentry, dentry);
15427 + if (unlikely(created && err && h_path.dentry->d_inode)) {
15429 + rerr = vfsub_unlink(h_dir, &h_path, /*force*/0);
15431 + AuIOErr("%.*s revert failure(%d, %d)\n",
15432 + AuDLNPair(dentry), err, rerr);
15435 + au_dtime_revert(&dt);
15442 + di_write_unlock(parent);
15444 + if (unlikely(err)) {
15445 + au_update_dbstart(dentry);
15448 + aufs_read_unlock(dentry, AuLock_DW);
15453 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
15456 + struct simple_arg arg = {
15463 + return add_simple(dir, dentry, &arg);
15466 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
15468 + struct simple_arg arg = {
15470 + .u.s.symname = symname
15472 + return add_simple(dir, dentry, &arg);
15475 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
15476 + struct nameidata *nd)
15478 + struct simple_arg arg = {
15485 + return add_simple(dir, dentry, &arg);
15488 +/* ---------------------------------------------------------------------- */
15490 +struct au_link_args {
15491 + aufs_bindex_t bdst, bsrc;
15492 + struct au_pin pin;
15493 + struct path h_path;
15494 + struct dentry *src_parent, *parent;
15497 +static int au_cpup_before_link(struct dentry *src_dentry,
15498 + struct au_link_args *a)
15501 + struct dentry *h_src_dentry;
15502 + struct mutex *h_mtx;
15503 + struct file *h_file;
15505 + di_read_lock_parent(a->src_parent, AuLock_IR);
15506 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
15507 + if (unlikely(err))
15510 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
15511 + h_mtx = &h_src_dentry->d_inode->i_mutex;
15512 + err = au_pin(&a->pin, src_dentry, a->bdst,
15513 + au_opt_udba(src_dentry->d_sb),
15514 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
15515 + if (unlikely(err))
15517 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
15518 + h_file = au_h_open_pre(src_dentry, a->bsrc);
15519 + if (IS_ERR(h_file)) {
15520 + err = PTR_ERR(h_file);
15523 + err = au_sio_cpup_simple(src_dentry, a->bdst, -1,
15524 + AuCpup_DTIME /* | AuCpup_KEEPLINO */);
15525 + mutex_unlock(h_mtx);
15526 + au_h_open_post(src_dentry, a->bsrc, h_file);
15527 + au_unpin(&a->pin);
15530 + di_read_unlock(a->src_parent, AuLock_IR);
15534 +static int au_cpup_or_link(struct dentry *src_dentry, struct au_link_args *a)
15537 + unsigned char plink;
15538 + struct inode *h_inode, *inode;
15539 + struct dentry *h_src_dentry;
15540 + struct super_block *sb;
15541 + struct file *h_file;
15545 + sb = src_dentry->d_sb;
15546 + inode = src_dentry->d_inode;
15547 + if (au_ibstart(inode) <= a->bdst)
15548 + h_inode = au_h_iptr(inode, a->bdst);
15549 + if (!h_inode || !h_inode->i_nlink) {
15550 + /* copyup src_dentry as the name of dentry. */
15551 + au_set_dbstart(src_dentry, a->bdst);
15552 + au_set_h_dptr(src_dentry, a->bdst, dget(a->h_path.dentry));
15553 + h_inode = au_h_dptr(src_dentry, a->bsrc)->d_inode;
15554 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
15555 + h_file = au_h_open_pre(src_dentry, a->bsrc);
15556 + if (IS_ERR(h_file)) {
15557 + err = PTR_ERR(h_file);
15560 + err = au_sio_cpup_single(src_dentry, a->bdst, a->bsrc,
15561 + -1, AuCpup_KEEPLINO,
15563 + mutex_unlock(&h_inode->i_mutex);
15564 + au_h_open_post(src_dentry, a->bsrc, h_file);
15565 + au_set_h_dptr(src_dentry, a->bdst, NULL);
15566 + au_set_dbstart(src_dentry, a->bsrc);
15568 + /* the inode of src_dentry already exists on a.bdst branch */
15569 + h_src_dentry = d_find_alias(h_inode);
15570 + if (!h_src_dentry && au_plink_test(inode)) {
15572 + h_src_dentry = au_plink_lkup(inode, a->bdst);
15573 + err = PTR_ERR(h_src_dentry);
15574 + if (IS_ERR(h_src_dentry))
15577 + if (unlikely(!h_src_dentry->d_inode)) {
15578 + dput(h_src_dentry);
15579 + h_src_dentry = NULL;
15583 + if (h_src_dentry) {
15584 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
15586 + dput(h_src_dentry);
15588 + AuIOErr("no dentry found for hi%lu on b%d\n",
15589 + h_inode->i_ino, a->bdst);
15594 + if (!err && !plink)
15595 + au_plink_append(inode, a->bdst, a->h_path.dentry);
15602 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
15603 + struct dentry *dentry)
15606 + struct au_dtime dt;
15607 + struct au_link_args *a;
15608 + struct dentry *wh_dentry, *h_src_dentry;
15609 + struct inode *inode;
15610 + struct super_block *sb;
15611 + struct au_wr_dir_args wr_dir_args = {
15612 + /* .force_btgt = -1, */
15613 + .flags = AuWrDir_ADD_ENTRY
15617 + inode = src_dentry->d_inode;
15618 + IMustLock(inode);
15621 + a = kzalloc(sizeof(*a), GFP_NOFS);
15622 + if (unlikely(!a))
15625 + a->parent = dentry->d_parent; /* dir inode is locked */
15626 + err = aufs_read_and_write_lock2(dentry, src_dentry,
15627 + AuLock_NOPLM | AuLock_GEN);
15628 + if (unlikely(err))
15630 + err = au_d_hashed_positive(src_dentry);
15631 + if (unlikely(err))
15633 + err = au_d_may_add(dentry);
15634 + if (unlikely(err))
15637 + a->src_parent = dget_parent(src_dentry);
15638 + wr_dir_args.force_btgt = au_ibstart(inode);
15640 + di_write_lock_parent(a->parent);
15641 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
15642 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
15644 + err = PTR_ERR(wh_dentry);
15645 + if (IS_ERR(wh_dentry))
15649 + sb = dentry->d_sb;
15650 + a->bdst = au_dbstart(dentry);
15651 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
15652 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
15653 + a->bsrc = au_ibstart(inode);
15654 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
15655 + if (!h_src_dentry) {
15656 + a->bsrc = au_dbstart(src_dentry);
15657 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
15658 + AuDebugOn(!h_src_dentry);
15659 + } else if (IS_ERR(h_src_dentry))
15662 + if (au_opt_test(au_mntflags(sb), PLINK)) {
15663 + if (a->bdst < a->bsrc
15664 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
15665 + err = au_cpup_or_link(src_dentry, a);
15667 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
15669 + dput(h_src_dentry);
15672 + * copyup src_dentry to the branch we process,
15673 + * and then link(2) to it.
15675 + dput(h_src_dentry);
15676 + if (a->bdst < a->bsrc
15677 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
15678 + au_unpin(&a->pin);
15679 + di_write_unlock(a->parent);
15680 + err = au_cpup_before_link(src_dentry, a);
15681 + di_write_lock_parent(a->parent);
15683 + err = au_pin(&a->pin, dentry, a->bdst,
15685 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
15686 + if (unlikely(err))
15690 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
15692 + if (h_src_dentry && h_src_dentry->d_inode)
15693 + err = vfsub_link(h_src_dentry,
15694 + au_pinned_h_dir(&a->pin),
15698 + if (unlikely(err))
15702 + a->h_path.dentry = wh_dentry;
15703 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
15705 + if (unlikely(err))
15709 + dir->i_version++;
15710 + if (au_ibstart(dir) == au_dbstart(dentry))
15711 + au_cpup_attr_timesizes(dir);
15712 + inc_nlink(inode);
15713 + inode->i_ctime = dir->i_ctime;
15714 + d_instantiate(dentry, au_igrab(inode));
15715 + if (d_unhashed(a->h_path.dentry))
15716 + /* some filesystem calls d_drop() */
15718 + goto out_unpin; /* success */
15721 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path, /*force*/0);
15722 + if (unlikely(rerr)) {
15723 + AuIOErr("%.*s reverting failed(%d, %d)\n",
15724 + AuDLNPair(dentry), err, rerr);
15727 + au_dtime_revert(&dt);
15729 + au_unpin(&a->pin);
15733 + di_write_unlock(a->parent);
15734 + dput(a->src_parent);
15736 + if (unlikely(err)) {
15737 + au_update_dbstart(dentry);
15740 + aufs_read_and_write_unlock2(dentry, src_dentry);
15747 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
15750 + aufs_bindex_t bindex;
15751 + unsigned char diropq;
15752 + struct path h_path;
15753 + struct dentry *wh_dentry, *parent, *opq_dentry;
15754 + struct mutex *h_mtx;
15755 + struct super_block *sb;
15757 + struct au_pin pin;
15758 + struct au_dtime dt;
15759 + } *a; /* reduce the stack usage */
15760 + struct au_wr_dir_args wr_dir_args = {
15761 + .force_btgt = -1,
15762 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
15768 + a = kmalloc(sizeof(*a), GFP_NOFS);
15769 + if (unlikely(!a))
15772 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
15773 + if (unlikely(err))
15775 + err = au_d_may_add(dentry);
15776 + if (unlikely(err))
15779 + parent = dentry->d_parent; /* dir inode is locked */
15780 + di_write_lock_parent(parent);
15781 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
15782 + &a->pin, &wr_dir_args);
15783 + err = PTR_ERR(wh_dentry);
15784 + if (IS_ERR(wh_dentry))
15787 + sb = dentry->d_sb;
15788 + bindex = au_dbstart(dentry);
15789 + h_path.dentry = au_h_dptr(dentry, bindex);
15790 + h_path.mnt = au_sbr_mnt(sb, bindex);
15791 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
15792 + if (unlikely(err))
15795 + /* make the dir opaque */
15797 + h_mtx = &h_path.dentry->d_inode->i_mutex;
15799 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
15800 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
15801 + opq_dentry = au_diropq_create(dentry, bindex);
15802 + mutex_unlock(h_mtx);
15803 + err = PTR_ERR(opq_dentry);
15804 + if (IS_ERR(opq_dentry))
15806 + dput(opq_dentry);
15810 + err = epilog(dir, bindex, wh_dentry, dentry);
15813 + goto out_unpin; /* success */
15818 + AuLabel(revert opq);
15819 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
15820 + rerr = au_diropq_remove(dentry, bindex);
15821 + mutex_unlock(h_mtx);
15823 + AuIOErr("%.*s reverting diropq failed(%d, %d)\n",
15824 + AuDLNPair(dentry), err, rerr);
15830 + AuLabel(revert dir);
15831 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
15833 + AuIOErr("%.*s reverting dir failed(%d, %d)\n",
15834 + AuDLNPair(dentry), err, rerr);
15837 + au_dtime_revert(&a->dt);
15839 + au_unpin(&a->pin);
15842 + di_write_unlock(parent);
15844 + if (unlikely(err)) {
15845 + au_update_dbstart(dentry);
15848 + aufs_read_unlock(dentry, AuLock_DW);
15854 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
15855 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
15856 +++ linux/fs/aufs/i_op.c 2012-07-22 19:57:03.164337936 +0200
15859 + * Copyright (C) 2005-2012 Junjiro R. Okajima
15861 + * This program, aufs is free software; you can redistribute it and/or modify
15862 + * it under the terms of the GNU General Public License as published by
15863 + * the Free Software Foundation; either version 2 of the License, or
15864 + * (at your option) any later version.
15866 + * This program is distributed in the hope that it will be useful,
15867 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15868 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15869 + * GNU General Public License for more details.
15871 + * You should have received a copy of the GNU General Public License
15872 + * along with this program; if not, write to the Free Software
15873 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15877 + * inode operations (except add/del/rename)
15880 +#include <linux/device_cgroup.h>
15881 +#include <linux/fs_stack.h>
15882 +#include <linux/mm.h>
15883 +#include <linux/namei.h>
15884 +#include <linux/security.h>
15887 +static int h_permission(struct inode *h_inode, int mask,
15888 + struct vfsmount *h_mnt, int brperm)
15891 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
15894 + if ((write_mask && IS_IMMUTABLE(h_inode))
15895 + || ((mask & MAY_EXEC)
15896 + && S_ISREG(h_inode->i_mode)
15897 + && ((h_mnt->mnt_flags & MNT_NOEXEC)
15898 + || !(h_inode->i_mode & S_IXUGO))))
15902 + * - skip the lower fs test in the case of write to ro branch.
15903 + * - nfs dir permission write check is optimized, but a policy for
15904 + * link/rename requires a real check.
15906 + if ((write_mask && !au_br_writable(brperm))
15907 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
15908 + && write_mask && !(mask & MAY_READ))
15909 + || !h_inode->i_op->permission) {
15910 + /* AuLabel(generic_permission); */
15911 + err = generic_permission(h_inode, mask);
15913 + /* AuLabel(h_inode->permission); */
15914 + err = h_inode->i_op->permission(h_inode, mask);
15919 + err = devcgroup_inode_permission(h_inode, mask);
15921 + err = security_inode_permission(h_inode, mask);
15925 + /* todo: do we need to call ima_path_check()? */
15926 + struct path h_path = {
15930 + err = ima_path_check(&h_path,
15931 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
15932 + IMA_COUNT_LEAVE);
15940 +static int aufs_permission(struct inode *inode, int mask)
15943 + aufs_bindex_t bindex, bend;
15944 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
15945 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
15946 + struct inode *h_inode;
15947 + struct super_block *sb;
15948 + struct au_branch *br;
15950 + /* todo: support rcu-walk? */
15951 + if (mask & MAY_NOT_BLOCK)
15954 + sb = inode->i_sb;
15955 + si_read_lock(sb, AuLock_FLUSH);
15956 + ii_read_lock_child(inode);
15958 + err = au_iigen_test(inode, au_sigen(sb));
15959 + if (unlikely(err))
15963 + if (!isdir || write_mask) {
15964 + err = au_busy_or_stale();
15965 + h_inode = au_h_iptr(inode, au_ibstart(inode));
15966 + if (unlikely(!h_inode
15967 + || (h_inode->i_mode & S_IFMT)
15968 + != (inode->i_mode & S_IFMT)))
15972 + bindex = au_ibstart(inode);
15973 + br = au_sbr(sb, bindex);
15974 + err = h_permission(h_inode, mask, br->br_mnt, br->br_perm);
15977 + && !special_file(h_inode->i_mode)) {
15978 + /* test whether the upper writable branch exists */
15980 + for (; bindex >= 0; bindex--)
15981 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
15989 + /* non-write to dir */
15991 + bend = au_ibend(inode);
15992 + for (bindex = au_ibstart(inode); !err && bindex <= bend; bindex++) {
15993 + h_inode = au_h_iptr(inode, bindex);
15995 + err = au_busy_or_stale();
15996 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
15999 + br = au_sbr(sb, bindex);
16000 + err = h_permission(h_inode, mask, br->br_mnt,
16006 + ii_read_unlock(inode);
16007 + si_read_unlock(sb);
16011 +/* ---------------------------------------------------------------------- */
16013 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
16014 + struct nameidata *nd)
16016 + struct dentry *ret, *parent;
16017 + struct inode *inode;
16018 + struct super_block *sb;
16019 + int err, npositive, lc_idx;
16024 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16025 + ret = ERR_PTR(err);
16026 + if (unlikely(err))
16029 + ret = ERR_PTR(-ENAMETOOLONG);
16030 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
16032 + err = au_di_init(dentry);
16033 + ret = ERR_PTR(err);
16034 + if (unlikely(err))
16038 + npositive = 0; /* suppress a warning */
16039 + parent = dentry->d_parent; /* dir inode is locked */
16040 + di_read_lock_parent(parent, AuLock_IR);
16041 + err = au_alive_dir(parent);
16043 + err = au_digen_test(parent, au_sigen(sb));
16045 + npositive = au_lkup_dentry(dentry, au_dbstart(parent),
16049 + di_read_unlock(parent, AuLock_IR);
16050 + ret = ERR_PTR(err);
16051 + if (unlikely(err < 0))
16055 + inode = au_new_inode(dentry, /*must_new*/0);
16056 + ret = (void *)inode;
16058 + if (IS_ERR(inode)) {
16063 + ret = d_splice_alias(inode, dentry);
16064 + if (unlikely(IS_ERR(ret) && inode)) {
16065 + ii_write_unlock(inode);
16066 + lc_idx = AuLcNonDir_IIINFO;
16067 + if (S_ISLNK(inode->i_mode))
16068 + lc_idx = AuLcSymlink_IIINFO;
16069 + else if (S_ISDIR(inode->i_mode))
16070 + lc_idx = AuLcDir_IIINFO;
16071 + au_rw_class(&au_ii(inode)->ii_rwsem, au_lc_key + lc_idx);
16076 + di_write_unlock(dentry);
16077 + if (unlikely(IS_ERR(ret) && inode)) {
16078 + lc_idx = AuLcNonDir_DIINFO;
16079 + if (S_ISLNK(inode->i_mode))
16080 + lc_idx = AuLcSymlink_DIINFO;
16081 + else if (S_ISDIR(inode->i_mode))
16082 + lc_idx = AuLcDir_DIINFO;
16083 + au_rw_class(&au_di(dentry)->di_rwsem, au_lc_key + lc_idx);
16086 + si_read_unlock(sb);
16091 +/* ---------------------------------------------------------------------- */
16093 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
16094 + const unsigned char add_entry, aufs_bindex_t bcpup,
16095 + aufs_bindex_t bstart)
16098 + struct dentry *h_parent;
16099 + struct inode *h_dir;
16102 + IMustLock(parent->d_inode);
16104 + di_write_lock_parent(parent);
16107 + if (!au_h_dptr(parent, bcpup)) {
16108 + if (bstart < bcpup)
16109 + err = au_cpdown_dirs(dentry, bcpup);
16111 + err = au_cpup_dirs(dentry, bcpup);
16113 + if (!err && add_entry) {
16114 + h_parent = au_h_dptr(parent, bcpup);
16115 + h_dir = h_parent->d_inode;
16116 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
16117 + err = au_lkup_neg(dentry, bcpup);
16118 + /* todo: no unlock here */
16119 + mutex_unlock(&h_dir->i_mutex);
16121 + AuDbg("bcpup %d\n", bcpup);
16123 + if (!dentry->d_inode)
16124 + au_set_h_dptr(dentry, bstart, NULL);
16125 + au_update_dbrange(dentry, /*do_put_zero*/0);
16130 + di_write_unlock(parent);
16132 + err = bcpup; /* success */
16139 + * decide the branch and the parent dir where we will create a new entry.
16140 + * returns new bindex or an error.
16141 + * copyup the parent dir if needed.
16143 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
16144 + struct au_wr_dir_args *args)
16147 + aufs_bindex_t bcpup, bstart, src_bstart;
16148 + const unsigned char add_entry = !!au_ftest_wrdir(args->flags,
16150 + struct super_block *sb;
16151 + struct dentry *parent;
16152 + struct au_sbinfo *sbinfo;
16154 + sb = dentry->d_sb;
16155 + sbinfo = au_sbi(sb);
16156 + parent = dget_parent(dentry);
16157 + bstart = au_dbstart(dentry);
16159 + if (args->force_btgt < 0) {
16160 + if (src_dentry) {
16161 + src_bstart = au_dbstart(src_dentry);
16162 + if (src_bstart < bstart)
16163 + bcpup = src_bstart;
16164 + } else if (add_entry) {
16165 + err = AuWbrCreate(sbinfo, dentry,
16166 + au_ftest_wrdir(args->flags, ISDIR));
16170 + if (bcpup < 0 || au_test_ro(sb, bcpup, dentry->d_inode)) {
16172 + err = AuWbrCopyup(sbinfo, dentry);
16174 + if (!IS_ROOT(dentry)) {
16175 + di_read_lock_parent(parent, !AuLock_IR);
16176 + err = AuWbrCopyup(sbinfo, dentry);
16177 + di_read_unlock(parent, !AuLock_IR);
16179 + err = AuWbrCopyup(sbinfo, dentry);
16182 + if (unlikely(err < 0))
16186 + bcpup = args->force_btgt;
16187 + AuDebugOn(au_test_ro(sb, bcpup, dentry->d_inode));
16190 + AuDbg("bstart %d, bcpup %d\n", bstart, bcpup);
16192 + if (bcpup == bstart)
16193 + goto out; /* success */
16195 + /* copyup the new parent into the branch we process */
16196 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, bstart);
16198 + if (!dentry->d_inode) {
16199 + au_set_h_dptr(dentry, bstart, NULL);
16200 + au_set_dbstart(dentry, bcpup);
16201 + au_set_dbend(dentry, bcpup);
16203 + AuDebugOn(add_entry && !au_h_dptr(dentry, bcpup));
16211 +/* ---------------------------------------------------------------------- */
16213 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
16215 + if (pin && pin->parent)
16216 + return au_h_dptr(pin->parent, pin->bindex);
16220 +void au_unpin(struct au_pin *p)
16222 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
16223 + mnt_drop_write(p->h_mnt);
16227 + au_hn_imtx_unlock(p->hdir);
16228 + if (!au_ftest_pin(p->flags, DI_LOCKED))
16229 + di_read_unlock(p->parent, AuLock_IR);
16230 + iput(p->hdir->hi_inode);
16232 + p->parent = NULL;
16237 +int au_do_pin(struct au_pin *p)
16240 + struct super_block *sb;
16241 + struct dentry *h_dentry, *h_parent;
16242 + struct au_branch *br;
16243 + struct inode *h_dir;
16246 + sb = p->dentry->d_sb;
16247 + br = au_sbr(sb, p->bindex);
16248 + if (IS_ROOT(p->dentry)) {
16249 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
16250 + p->h_mnt = br->br_mnt;
16251 + err = mnt_want_write(p->h_mnt);
16252 + if (unlikely(err)) {
16253 + au_fclr_pin(p->flags, MNT_WRITE);
16261 + if (p->bindex <= au_dbend(p->dentry))
16262 + h_dentry = au_h_dptr(p->dentry, p->bindex);
16264 + p->parent = dget_parent(p->dentry);
16265 + if (!au_ftest_pin(p->flags, DI_LOCKED))
16266 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
16269 + h_parent = au_h_dptr(p->parent, p->bindex);
16270 + p->hdir = au_hi(p->parent->d_inode, p->bindex);
16272 + h_dir = p->hdir->hi_inode;
16276 + * if DI_LOCKED is not set, then p->parent may be different
16277 + * and h_parent can be NULL.
16279 + if (unlikely(!p->hdir || !h_dir || !h_parent)) {
16281 + if (!au_ftest_pin(p->flags, DI_LOCKED))
16282 + di_read_unlock(p->parent, AuLock_IR);
16284 + p->parent = NULL;
16289 + au_hn_imtx_lock_nested(p->hdir, p->lsc_hi);
16291 + if (unlikely(p->hdir->hi_inode != h_parent->d_inode)) {
16296 + err = au_h_verify(h_dentry, p->udba, h_dir, h_parent, br);
16297 + if (unlikely(err)) {
16298 + au_fclr_pin(p->flags, MNT_WRITE);
16303 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
16304 + p->h_mnt = br->br_mnt;
16305 + err = mnt_want_write(p->h_mnt);
16306 + if (unlikely(err)) {
16307 + au_fclr_pin(p->flags, MNT_WRITE);
16311 + goto out; /* success */
16316 + pr_err("err %d\n", err);
16317 + err = au_busy_or_stale();
16322 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
16323 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
16324 + unsigned int udba, unsigned char flags)
16326 + p->dentry = dentry;
16328 + p->lsc_di = lsc_di;
16329 + p->lsc_hi = lsc_hi;
16330 + p->flags = flags;
16331 + p->bindex = bindex;
16333 + p->parent = NULL;
16338 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
16339 + unsigned int udba, unsigned char flags)
16341 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
16343 + return au_do_pin(pin);
16346 +/* ---------------------------------------------------------------------- */
16349 + * ->setattr() and ->getattr() are called in various cases.
16350 + * chmod, stat: dentry is revalidated.
16351 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
16353 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
16355 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
16356 +static int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
16359 + struct inode *inode;
16360 + struct dentry *parent;
16363 + inode = dentry->d_inode;
16364 + if (au_digen_test(dentry, sigen)) {
16365 + parent = dget_parent(dentry);
16366 + di_read_lock_parent(parent, AuLock_IR);
16367 + err = au_refresh_dentry(dentry, parent);
16368 + di_read_unlock(parent, AuLock_IR);
16376 +#define AuIcpup_DID_CPUP 1
16377 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
16378 +#define au_fset_icpup(flags, name) \
16379 + do { (flags) |= AuIcpup_##name; } while (0)
16380 +#define au_fclr_icpup(flags, name) \
16381 + do { (flags) &= ~AuIcpup_##name; } while (0)
16383 +struct au_icpup_args {
16384 + unsigned char flags;
16385 + unsigned char pin_flags;
16386 + aufs_bindex_t btgt;
16387 + unsigned int udba;
16388 + struct au_pin pin;
16389 + struct path h_path;
16390 + struct inode *h_inode;
16393 +static int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
16394 + struct au_icpup_args *a)
16398 + aufs_bindex_t bstart, ibstart;
16399 + struct dentry *hi_wh, *parent;
16400 + struct inode *inode;
16401 + struct file *h_file;
16402 + struct au_wr_dir_args wr_dir_args = {
16403 + .force_btgt = -1,
16407 + bstart = au_dbstart(dentry);
16408 + inode = dentry->d_inode;
16409 + if (S_ISDIR(inode->i_mode))
16410 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
16411 + /* plink or hi_wh() case */
16412 + ibstart = au_ibstart(inode);
16413 + if (bstart != ibstart && !au_test_ro(inode->i_sb, ibstart, inode))
16414 + wr_dir_args.force_btgt = ibstart;
16415 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
16416 + if (unlikely(err < 0))
16419 + if (err != bstart)
16420 + au_fset_icpup(a->flags, DID_CPUP);
16423 + a->pin_flags = AuPin_MNT_WRITE;
16425 + if (!IS_ROOT(dentry)) {
16426 + au_fset_pin(a->pin_flags, DI_LOCKED);
16427 + parent = dget_parent(dentry);
16428 + di_write_lock_parent(parent);
16431 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
16432 + if (unlikely(err))
16435 + a->h_path.dentry = au_h_dptr(dentry, bstart);
16436 + a->h_inode = a->h_path.dentry->d_inode;
16437 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
16439 + if ((ia->ia_valid & ATTR_SIZE) && ia->ia_size < i_size_read(a->h_inode))
16440 + sz = ia->ia_size;
16444 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
16445 + hi_wh = au_hi_wh(inode, a->btgt);
16447 + err = au_sio_cpup_wh(dentry, a->btgt, sz, /*file*/NULL);
16448 + if (unlikely(err))
16450 + hi_wh = au_hi_wh(inode, a->btgt);
16451 + /* todo: revalidate hi_wh? */
16456 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
16457 + di_downgrade_lock(parent, AuLock_IR);
16461 + if (!au_ftest_icpup(a->flags, DID_CPUP))
16462 + goto out; /* success */
16464 + if (!d_unhashed(dentry)) {
16465 + h_file = au_h_open_pre(dentry, bstart);
16466 + if (IS_ERR(h_file)) {
16467 + err = PTR_ERR(h_file);
16470 + err = au_sio_cpup_simple(dentry, a->btgt, sz,
16473 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
16474 + } else if (!hi_wh)
16475 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
16477 + a->h_path.dentry = hi_wh; /* do not dget here */
16480 + mutex_unlock(&a->h_inode->i_mutex);
16481 + au_h_open_post(dentry, bstart, h_file);
16482 + a->h_inode = a->h_path.dentry->d_inode;
16484 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
16485 + goto out; /* success */
16488 + au_unpin(&a->pin);
16491 + di_write_unlock(parent);
16498 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
16501 + struct inode *inode;
16502 + struct super_block *sb;
16503 + struct file *file;
16504 + struct au_icpup_args *a;
16506 + inode = dentry->d_inode;
16507 + IMustLock(inode);
16510 + a = kzalloc(sizeof(*a), GFP_NOFS);
16511 + if (unlikely(!a))
16514 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
16515 + ia->ia_valid &= ~ATTR_MODE;
16518 + sb = dentry->d_sb;
16519 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16520 + if (unlikely(err))
16523 + if (ia->ia_valid & ATTR_FILE) {
16524 + /* currently ftruncate(2) only */
16525 + AuDebugOn(!S_ISREG(inode->i_mode));
16526 + file = ia->ia_file;
16527 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
16528 + if (unlikely(err))
16530 + ia->ia_file = au_hf_top(file);
16531 + a->udba = AuOpt_UDBA_NONE;
16533 + /* fchmod() doesn't pass ia_file */
16534 + a->udba = au_opt_udba(sb);
16535 + di_write_lock_child(dentry);
16536 + /* no d_unlinked(), to set UDBA_NONE for root */
16537 + if (d_unhashed(dentry))
16538 + a->udba = AuOpt_UDBA_NONE;
16539 + if (a->udba != AuOpt_UDBA_NONE) {
16540 + AuDebugOn(IS_ROOT(dentry));
16541 + err = au_reval_for_attr(dentry, au_sigen(sb));
16542 + if (unlikely(err))
16547 + err = au_pin_and_icpup(dentry, ia, a);
16548 + if (unlikely(err < 0))
16550 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
16551 + ia->ia_file = NULL;
16552 + ia->ia_valid &= ~ATTR_FILE;
16555 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
16556 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
16557 + == (ATTR_MODE | ATTR_CTIME)) {
16558 + err = security_path_chmod(&a->h_path, ia->ia_mode);
16559 + if (unlikely(err))
16561 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
16562 + && (ia->ia_valid & ATTR_CTIME)) {
16563 + err = security_path_chown(&a->h_path, vfsub_ia_uid(ia),
16564 + vfsub_ia_gid(ia));
16565 + if (unlikely(err))
16569 + if (ia->ia_valid & ATTR_SIZE) {
16572 + if (ia->ia_size < i_size_read(inode))
16574 + truncate_setsize(inode, ia->ia_size);
16577 + if (ia->ia_valid & ATTR_FILE)
16579 + mutex_unlock(&a->h_inode->i_mutex);
16580 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
16581 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
16583 + err = vfsub_notify_change(&a->h_path, ia);
16585 + au_cpup_attr_changeable(inode);
16588 + mutex_unlock(&a->h_inode->i_mutex);
16589 + au_unpin(&a->pin);
16590 + if (unlikely(err))
16591 + au_update_dbstart(dentry);
16593 + di_write_unlock(dentry);
16595 + fi_write_unlock(file);
16596 + ia->ia_file = file;
16597 + ia->ia_valid |= ATTR_FILE;
16600 + si_read_unlock(sb);
16608 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
16609 + unsigned int nlink)
16613 + inode->i_mode = st->mode;
16614 + i_uid_write(inode, st->uid);
16615 + i_gid_write(inode, st->gid);
16616 + inode->i_atime = st->atime;
16617 + inode->i_mtime = st->mtime;
16618 + inode->i_ctime = st->ctime;
16620 + au_cpup_attr_nlink(inode, /*force*/0);
16621 + if (S_ISDIR(inode->i_mode)) {
16622 + n = inode->i_nlink;
16625 + /* 0 can happen */
16626 + set_nlink(inode, n);
16629 + spin_lock(&inode->i_lock);
16630 + inode->i_blocks = st->blocks;
16631 + i_size_write(inode, st->size);
16632 + spin_unlock(&inode->i_lock);
16635 +static int aufs_getattr(struct vfsmount *mnt __maybe_unused,
16636 + struct dentry *dentry, struct kstat *st)
16639 + unsigned int mnt_flags;
16640 + aufs_bindex_t bindex;
16641 + unsigned char udba_none, positive;
16642 + struct super_block *sb, *h_sb;
16643 + struct inode *inode;
16644 + struct vfsmount *h_mnt;
16645 + struct dentry *h_dentry;
16647 + sb = dentry->d_sb;
16648 + inode = dentry->d_inode;
16649 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16650 + if (unlikely(err))
16652 + mnt_flags = au_mntflags(sb);
16653 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
16655 + /* support fstat(2) */
16656 + if (!d_unlinked(dentry) && !udba_none) {
16657 + unsigned int sigen = au_sigen(sb);
16658 + err = au_digen_test(dentry, sigen);
16660 + di_read_lock_child(dentry, AuLock_IR);
16661 + err = au_dbrange_test(dentry);
16662 + if (unlikely(err))
16665 + AuDebugOn(IS_ROOT(dentry));
16666 + di_write_lock_child(dentry);
16667 + err = au_dbrange_test(dentry);
16669 + err = au_reval_for_attr(dentry, sigen);
16670 + di_downgrade_lock(dentry, AuLock_IR);
16671 + if (unlikely(err))
16675 + di_read_lock_child(dentry, AuLock_IR);
16677 + bindex = au_ibstart(inode);
16678 + h_mnt = au_sbr_mnt(sb, bindex);
16679 + h_sb = h_mnt->mnt_sb;
16680 + if (!au_test_fs_bad_iattr(h_sb) && udba_none)
16681 + goto out_fill; /* success */
16684 + if (au_dbstart(dentry) == bindex)
16685 + h_dentry = dget(au_h_dptr(dentry, bindex));
16686 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
16687 + h_dentry = au_plink_lkup(inode, bindex);
16688 + if (IS_ERR(h_dentry))
16689 + goto out_fill; /* pretending success */
16691 + /* illegally overlapped or something */
16692 + if (unlikely(!h_dentry))
16693 + goto out_fill; /* pretending success */
16695 + positive = !!h_dentry->d_inode;
16697 + err = vfs_getattr(h_mnt, h_dentry, st);
16701 + au_refresh_iattr(inode, st, h_dentry->d_inode->i_nlink);
16702 + goto out_fill; /* success */
16708 + generic_fillattr(inode, st);
16710 + di_read_unlock(dentry, AuLock_IR);
16711 + si_read_unlock(sb);
16717 +/* ---------------------------------------------------------------------- */
16719 +static int h_readlink(struct dentry *dentry, int bindex, char __user *buf,
16723 + struct super_block *sb;
16724 + struct dentry *h_dentry;
16727 + h_dentry = au_h_dptr(dentry, bindex);
16728 + if (unlikely(!h_dentry->d_inode->i_op->readlink))
16731 + err = security_inode_readlink(h_dentry);
16732 + if (unlikely(err))
16735 + sb = dentry->d_sb;
16736 + if (!au_test_ro(sb, bindex, dentry->d_inode)) {
16737 + vfsub_touch_atime(au_sbr_mnt(sb, bindex), h_dentry);
16738 + fsstack_copy_attr_atime(dentry->d_inode, h_dentry->d_inode);
16740 + err = h_dentry->d_inode->i_op->readlink(h_dentry, buf, bufsiz);
16746 +static int aufs_readlink(struct dentry *dentry, char __user *buf, int bufsiz)
16750 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
16751 + if (unlikely(err))
16753 + err = au_d_hashed_positive(dentry);
16755 + err = h_readlink(dentry, au_dbstart(dentry), buf, bufsiz);
16756 + aufs_read_unlock(dentry, AuLock_IR);
16762 +static void *aufs_follow_link(struct dentry *dentry, struct nameidata *nd)
16765 + mm_segment_t old_fs;
16772 + buf.k = __getname_gfp(GFP_NOFS);
16773 + if (unlikely(!buf.k))
16776 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
16777 + if (unlikely(err))
16780 + err = au_d_hashed_positive(dentry);
16782 + old_fs = get_fs();
16783 + set_fs(KERNEL_DS);
16784 + err = h_readlink(dentry, au_dbstart(dentry), buf.u, PATH_MAX);
16787 + aufs_read_unlock(dentry, AuLock_IR);
16791 + /* will be freed by put_link */
16792 + nd_set_link(nd, buf.k);
16793 + return NULL; /* success */
16797 + __putname(buf.k);
16799 + path_put(&nd->path);
16801 + return ERR_PTR(err);
16804 +static void aufs_put_link(struct dentry *dentry __maybe_unused,
16805 + struct nameidata *nd, void *cookie __maybe_unused)
16807 + __putname(nd_get_link(nd));
16810 +/* ---------------------------------------------------------------------- */
16812 +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags)
16815 + struct super_block *sb;
16816 + struct inode *h_inode;
16818 + sb = inode->i_sb;
16819 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
16821 + si_read_lock(sb, AuLock_FLUSH);
16822 + ii_write_lock_child(inode);
16824 + h_inode = au_h_iptr(inode, au_ibstart(inode));
16825 + err = vfsub_update_time(h_inode, ts, flags);
16827 + ii_write_unlock(inode);
16828 + si_read_unlock(sb);
16833 +/* ---------------------------------------------------------------------- */
16835 +struct inode_operations aufs_symlink_iop = {
16836 + .permission = aufs_permission,
16837 + .setattr = aufs_setattr,
16838 + .getattr = aufs_getattr,
16840 + .readlink = aufs_readlink,
16841 + .follow_link = aufs_follow_link,
16842 + .put_link = aufs_put_link,
16844 + /* .update_time = aufs_update_time */
16847 +struct inode_operations aufs_dir_iop = {
16848 + .create = aufs_create,
16849 + .lookup = aufs_lookup,
16850 + .link = aufs_link,
16851 + .unlink = aufs_unlink,
16852 + .symlink = aufs_symlink,
16853 + .mkdir = aufs_mkdir,
16854 + .rmdir = aufs_rmdir,
16855 + .mknod = aufs_mknod,
16856 + .rename = aufs_rename,
16858 + .permission = aufs_permission,
16859 + .setattr = aufs_setattr,
16860 + .getattr = aufs_getattr,
16862 + .update_time = aufs_update_time
16865 +struct inode_operations aufs_iop = {
16866 + .permission = aufs_permission,
16867 + .setattr = aufs_setattr,
16868 + .getattr = aufs_getattr,
16870 + .update_time = aufs_update_time
16872 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
16873 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
16874 +++ linux/fs/aufs/i_op_del.c 2012-07-22 19:57:03.164337936 +0200
16877 + * Copyright (C) 2005-2012 Junjiro R. Okajima
16879 + * This program, aufs is free software; you can redistribute it and/or modify
16880 + * it under the terms of the GNU General Public License as published by
16881 + * the Free Software Foundation; either version 2 of the License, or
16882 + * (at your option) any later version.
16884 + * This program is distributed in the hope that it will be useful,
16885 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16886 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16887 + * GNU General Public License for more details.
16889 + * You should have received a copy of the GNU General Public License
16890 + * along with this program; if not, write to the Free Software
16891 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16895 + * inode operations (del entry)
16901 + * decide if a new whiteout for @dentry is necessary or not.
16902 + * when it is necessary, prepare the parent dir for the upper branch whose
16903 + * branch index is @bcpup for creation. the actual creation of the whiteout will
16904 + * be done by caller.
16906 + * 0: wh is unnecessary
16907 + * plus: wh is necessary
16910 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
16912 + int need_wh, err;
16913 + aufs_bindex_t bstart;
16914 + struct super_block *sb;
16916 + sb = dentry->d_sb;
16917 + bstart = au_dbstart(dentry);
16918 + if (*bcpup < 0) {
16920 + if (au_test_ro(sb, bstart, dentry->d_inode)) {
16921 + err = AuWbrCopyup(au_sbi(sb), dentry);
16923 + if (unlikely(err < 0))
16927 + AuDebugOn(bstart < *bcpup
16928 + || au_test_ro(sb, *bcpup, dentry->d_inode));
16929 + AuDbg("bcpup %d, bstart %d\n", *bcpup, bstart);
16931 + if (*bcpup != bstart) {
16932 + err = au_cpup_dirs(dentry, *bcpup);
16933 + if (unlikely(err))
16937 + struct au_dinfo *dinfo, *tmp;
16939 + need_wh = -ENOMEM;
16940 + dinfo = au_di(dentry);
16941 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
16943 + au_di_cp(tmp, dinfo);
16944 + au_di_swap(tmp, dinfo);
16945 + /* returns the number of positive dentries */
16946 + need_wh = au_lkup_dentry(dentry, bstart + 1, /*type*/0,
16948 + au_di_swap(tmp, dinfo);
16949 + au_rw_write_unlock(&tmp->di_rwsem);
16953 + AuDbg("need_wh %d\n", need_wh);
16961 + * simple tests for the del-entry operations.
16962 + * following the checks in vfs, plus the parent-child relationship.
16964 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
16965 + struct dentry *h_parent, int isdir)
16969 + struct dentry *h_dentry, *h_latest;
16970 + struct inode *h_inode;
16972 + h_dentry = au_h_dptr(dentry, bindex);
16973 + h_inode = h_dentry->d_inode;
16974 + if (dentry->d_inode) {
16976 + if (unlikely(!h_inode || !h_inode->i_nlink))
16979 + h_mode = h_inode->i_mode;
16982 + if (unlikely(S_ISDIR(h_mode)))
16984 + } else if (unlikely(!S_ISDIR(h_mode))) {
16989 + /* rename(2) case */
16991 + if (unlikely(h_inode))
16996 + /* expected parent dir is locked */
16997 + if (unlikely(h_parent != h_dentry->d_parent))
17002 + * rmdir a dir may break the consistency on some filesystem.
17003 + * let's try heavy test.
17006 + if (unlikely(au_test_h_perm(h_parent->d_inode, MAY_EXEC | MAY_WRITE)))
17009 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent,
17010 + au_sbr(dentry->d_sb, bindex));
17012 + if (IS_ERR(h_latest))
17014 + if (h_latest == h_dentry)
17023 + * decide the branch where we operate for @dentry. the branch index will be set
17024 + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent
17025 + * dir for reverting.
17026 + * when a new whiteout is necessary, create it.
17028 +static struct dentry*
17029 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
17030 + struct au_dtime *dt, struct au_pin *pin)
17032 + struct dentry *wh_dentry;
17033 + struct super_block *sb;
17034 + struct path h_path;
17035 + int err, need_wh;
17036 + unsigned int udba;
17037 + aufs_bindex_t bcpup;
17039 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
17040 + wh_dentry = ERR_PTR(need_wh);
17041 + if (unlikely(need_wh < 0))
17044 + sb = dentry->d_sb;
17045 + udba = au_opt_udba(sb);
17047 + err = au_pin(pin, dentry, bcpup, udba,
17048 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17049 + wh_dentry = ERR_PTR(err);
17050 + if (unlikely(err))
17053 + h_path.dentry = au_pinned_h_parent(pin);
17054 + if (udba != AuOpt_UDBA_NONE
17055 + && au_dbstart(dentry) == bcpup) {
17056 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
17057 + wh_dentry = ERR_PTR(err);
17058 + if (unlikely(err))
17062 + h_path.mnt = au_sbr_mnt(sb, bcpup);
17063 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
17064 + wh_dentry = NULL;
17066 + goto out; /* success, no need to create whiteout */
17068 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
17069 + if (IS_ERR(wh_dentry))
17072 + /* returns with the parent is locked and wh_dentry is dget-ed */
17073 + goto out; /* success */
17078 + return wh_dentry;
17082 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
17083 + * in order to be revertible and save time for removing many child whiteouts
17085 + * returns 1 when there are too many child whiteout and caller should remove
17086 + * them asynchronously. returns 0 when the number of children is enough small to
17087 + * remove now or the branch fs is a remote fs.
17088 + * otherwise return an error.
17090 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
17091 + struct au_nhash *whlist, struct inode *dir)
17093 + int rmdir_later, err, dirwh;
17094 + struct dentry *h_dentry;
17095 + struct super_block *sb;
17097 + sb = dentry->d_sb;
17098 + SiMustAnyLock(sb);
17099 + h_dentry = au_h_dptr(dentry, bindex);
17100 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
17101 + if (unlikely(err))
17104 + /* stop monitoring */
17105 + au_hn_free(au_hi(dentry->d_inode, bindex));
17107 + if (!au_test_fs_remote(h_dentry->d_sb)) {
17108 + dirwh = au_sbi(sb)->si_dirwh;
17109 + rmdir_later = (dirwh <= 1);
17110 + if (!rmdir_later)
17111 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
17114 + return rmdir_later;
17117 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
17118 + if (unlikely(err)) {
17119 + AuIOErr("rmdir %.*s, b%d failed, %d. ignored\n",
17120 + AuDLNPair(h_dentry), bindex, err);
17130 + * final procedure for deleting a entry.
17131 + * maintain dentry and iattr.
17133 +static void epilog(struct inode *dir, struct dentry *dentry,
17134 + aufs_bindex_t bindex)
17136 + struct inode *inode;
17138 + inode = dentry->d_inode;
17140 + inode->i_ctime = dir->i_ctime;
17142 + if (au_ibstart(dir) == bindex)
17143 + au_cpup_attr_timesizes(dir);
17144 + dir->i_version++;
17148 + * when an error happened, remove the created whiteout and revert everything.
17150 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
17151 + aufs_bindex_t bwh, struct dentry *wh_dentry,
17152 + struct dentry *dentry, struct au_dtime *dt)
17155 + struct path h_path = {
17156 + .dentry = wh_dentry,
17157 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
17160 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
17162 + au_set_dbwh(dentry, bwh);
17163 + au_dtime_revert(dt);
17167 + AuIOErr("%.*s reverting whiteout failed(%d, %d)\n",
17168 + AuDLNPair(dentry), err, rerr);
17172 +/* ---------------------------------------------------------------------- */
17174 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
17177 + aufs_bindex_t bwh, bindex, bstart;
17178 + struct au_dtime dt;
17179 + struct au_pin pin;
17180 + struct path h_path;
17181 + struct inode *inode, *h_dir;
17182 + struct dentry *parent, *wh_dentry;
17186 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
17187 + if (unlikely(err))
17189 + err = au_d_hashed_positive(dentry);
17190 + if (unlikely(err))
17192 + inode = dentry->d_inode;
17193 + IMustLock(inode);
17195 + if (unlikely(S_ISDIR(inode->i_mode)))
17196 + goto out_unlock; /* possible? */
17198 + bstart = au_dbstart(dentry);
17199 + bwh = au_dbwh(dentry);
17201 + parent = dentry->d_parent; /* dir inode is locked */
17202 + di_write_lock_parent(parent);
17203 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &dt, &pin);
17204 + err = PTR_ERR(wh_dentry);
17205 + if (IS_ERR(wh_dentry))
17208 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
17209 + h_path.dentry = au_h_dptr(dentry, bstart);
17210 + dget(h_path.dentry);
17211 + if (bindex == bstart) {
17212 + h_dir = au_pinned_h_dir(&pin);
17213 + err = vfsub_unlink(h_dir, &h_path, /*force*/0);
17215 + /* dir inode is locked */
17216 + h_dir = wh_dentry->d_parent->d_inode;
17217 + IMustLock(h_dir);
17222 + vfsub_drop_nlink(inode);
17223 + epilog(dir, dentry, bindex);
17225 + /* update target timestamps */
17226 + if (bindex == bstart) {
17227 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
17228 + inode->i_ctime = h_path.dentry->d_inode->i_ctime;
17230 + /* todo: this timestamp may be reverted later */
17231 + inode->i_ctime = h_dir->i_ctime;
17232 + goto out_unpin; /* success */
17239 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry, &dt);
17247 + dput(h_path.dentry);
17249 + di_write_unlock(parent);
17251 + aufs_read_unlock(dentry, AuLock_DW);
17256 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
17258 + int err, rmdir_later;
17259 + aufs_bindex_t bwh, bindex, bstart;
17260 + struct au_dtime dt;
17261 + struct au_pin pin;
17262 + struct inode *inode;
17263 + struct dentry *parent, *wh_dentry, *h_dentry;
17264 + struct au_whtmp_rmdir *args;
17268 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
17269 + if (unlikely(err))
17271 + err = au_alive_dir(dentry);
17272 + if (unlikely(err))
17274 + inode = dentry->d_inode;
17275 + IMustLock(inode);
17277 + if (unlikely(!S_ISDIR(inode->i_mode)))
17278 + goto out_unlock; /* possible? */
17281 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
17282 + if (unlikely(!args))
17285 + parent = dentry->d_parent; /* dir inode is locked */
17286 + di_write_lock_parent(parent);
17287 + err = au_test_empty(dentry, &args->whlist);
17288 + if (unlikely(err))
17291 + bstart = au_dbstart(dentry);
17292 + bwh = au_dbwh(dentry);
17294 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &dt, &pin);
17295 + err = PTR_ERR(wh_dentry);
17296 + if (IS_ERR(wh_dentry))
17299 + h_dentry = au_h_dptr(dentry, bstart);
17302 + if (bindex == bstart) {
17303 + err = renwh_and_rmdir(dentry, bstart, &args->whlist, dir);
17305 + rmdir_later = err;
17309 + /* stop monitoring */
17310 + au_hn_free(au_hi(inode, bstart));
17312 + /* dir inode is locked */
17313 + IMustLock(wh_dentry->d_parent->d_inode);
17318 + vfsub_dead_dir(inode);
17319 + au_set_dbdiropq(dentry, -1);
17320 + epilog(dir, dentry, bindex);
17322 + if (rmdir_later) {
17323 + au_whtmp_kick_rmdir(dir, bstart, h_dentry, args);
17327 + goto out_unpin; /* success */
17335 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry, &dt);
17345 + di_write_unlock(parent);
17347 + au_whtmp_rmdir_free(args);
17349 + aufs_read_unlock(dentry, AuLock_DW);
17354 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
17355 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
17356 +++ linux/fs/aufs/i_op_ren.c 2012-07-22 19:57:03.164337936 +0200
17359 + * Copyright (C) 2005-2012 Junjiro R. Okajima
17361 + * This program, aufs is free software; you can redistribute it and/or modify
17362 + * it under the terms of the GNU General Public License as published by
17363 + * the Free Software Foundation; either version 2 of the License, or
17364 + * (at your option) any later version.
17366 + * This program is distributed in the hope that it will be useful,
17367 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17368 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17369 + * GNU General Public License for more details.
17371 + * You should have received a copy of the GNU General Public License
17372 + * along with this program; if not, write to the Free Software
17373 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17377 + * inode operation (rename entry)
17378 + * todo: this is crazy monster
17383 +enum { AuSRC, AuDST, AuSrcDst };
17384 +enum { AuPARENT, AuCHILD, AuParentChild };
17386 +#define AuRen_ISDIR 1
17387 +#define AuRen_ISSAMEDIR (1 << 1)
17388 +#define AuRen_WHSRC (1 << 2)
17389 +#define AuRen_WHDST (1 << 3)
17390 +#define AuRen_MNT_WRITE (1 << 4)
17391 +#define AuRen_DT_DSTDIR (1 << 5)
17392 +#define AuRen_DIROPQ (1 << 6)
17393 +#define AuRen_CPUP (1 << 7)
17394 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
17395 +#define au_fset_ren(flags, name) \
17396 + do { (flags) |= AuRen_##name; } while (0)
17397 +#define au_fclr_ren(flags, name) \
17398 + do { (flags) &= ~AuRen_##name; } while (0)
17400 +struct au_ren_args {
17402 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
17404 + struct inode *dir, *inode;
17405 + struct au_hinode *hdir;
17406 + struct au_dtime dt[AuParentChild];
17407 + aufs_bindex_t bstart;
17410 +#define src_dentry sd[AuSRC].dentry
17411 +#define src_dir sd[AuSRC].dir
17412 +#define src_inode sd[AuSRC].inode
17413 +#define src_h_dentry sd[AuSRC].h_dentry
17414 +#define src_parent sd[AuSRC].parent
17415 +#define src_h_parent sd[AuSRC].h_parent
17416 +#define src_wh_dentry sd[AuSRC].wh_dentry
17417 +#define src_hdir sd[AuSRC].hdir
17418 +#define src_h_dir sd[AuSRC].hdir->hi_inode
17419 +#define src_dt sd[AuSRC].dt
17420 +#define src_bstart sd[AuSRC].bstart
17422 +#define dst_dentry sd[AuDST].dentry
17423 +#define dst_dir sd[AuDST].dir
17424 +#define dst_inode sd[AuDST].inode
17425 +#define dst_h_dentry sd[AuDST].h_dentry
17426 +#define dst_parent sd[AuDST].parent
17427 +#define dst_h_parent sd[AuDST].h_parent
17428 +#define dst_wh_dentry sd[AuDST].wh_dentry
17429 +#define dst_hdir sd[AuDST].hdir
17430 +#define dst_h_dir sd[AuDST].hdir->hi_inode
17431 +#define dst_dt sd[AuDST].dt
17432 +#define dst_bstart sd[AuDST].bstart
17434 + struct dentry *h_trap;
17435 + struct au_branch *br;
17436 + struct au_hinode *src_hinode;
17437 + struct path h_path;
17438 + struct au_nhash whlist;
17439 + aufs_bindex_t btgt, src_bwh, src_bdiropq;
17441 + unsigned int flags;
17443 + struct au_whtmp_rmdir *thargs;
17444 + struct dentry *h_dst;
17447 +/* ---------------------------------------------------------------------- */
17450 + * functions for reverting.
17451 + * when an error happened in a single rename systemcall, we should revert
17452 + * everything as if nothing happend.
17453 + * we don't need to revert the copied-up/down the parent dir since they are
17457 +#define RevertFailure(fmt, ...) do { \
17458 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
17459 + ##__VA_ARGS__, err, rerr); \
17463 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
17467 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
17468 + rerr = au_diropq_remove(a->src_dentry, a->btgt);
17469 + au_hn_imtx_unlock(a->src_hinode);
17470 + au_set_dbdiropq(a->src_dentry, a->src_bdiropq);
17472 + RevertFailure("remove diropq %.*s", AuDLNPair(a->src_dentry));
17475 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
17479 + a->h_path.dentry = au_lkup_one(&a->src_dentry->d_name, a->src_h_parent,
17480 + a->br, /*nd*/NULL);
17481 + rerr = PTR_ERR(a->h_path.dentry);
17482 + if (IS_ERR(a->h_path.dentry)) {
17483 + RevertFailure("au_lkup_one %.*s", AuDLNPair(a->src_dentry));
17487 + rerr = vfsub_rename(a->dst_h_dir,
17488 + au_h_dptr(a->src_dentry, a->btgt),
17489 + a->src_h_dir, &a->h_path);
17490 + d_drop(a->h_path.dentry);
17491 + dput(a->h_path.dentry);
17492 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
17494 + RevertFailure("rename %.*s", AuDLNPair(a->src_dentry));
17497 +static void au_ren_rev_cpup(int err, struct au_ren_args *a)
17501 + a->h_path.dentry = a->dst_h_dentry;
17502 + rerr = vfsub_unlink(a->dst_h_dir, &a->h_path, /*force*/0);
17503 + au_set_h_dptr(a->src_dentry, a->btgt, NULL);
17504 + au_set_dbstart(a->src_dentry, a->src_bstart);
17506 + RevertFailure("unlink %.*s", AuDLNPair(a->dst_h_dentry));
17509 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
17513 + a->h_path.dentry = au_lkup_one(&a->dst_dentry->d_name, a->dst_h_parent,
17514 + a->br, /*nd*/NULL);
17515 + rerr = PTR_ERR(a->h_path.dentry);
17516 + if (IS_ERR(a->h_path.dentry)) {
17517 + RevertFailure("lookup %.*s", AuDLNPair(a->dst_dentry));
17520 + if (a->h_path.dentry->d_inode) {
17521 + d_drop(a->h_path.dentry);
17522 + dput(a->h_path.dentry);
17526 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path);
17527 + d_drop(a->h_path.dentry);
17528 + dput(a->h_path.dentry);
17530 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
17532 + RevertFailure("rename %.*s", AuDLNPair(a->h_dst));
17535 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
17539 + a->h_path.dentry = a->src_wh_dentry;
17540 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
17541 + au_set_dbwh(a->src_dentry, a->src_bwh);
17543 + RevertFailure("unlink %.*s", AuDLNPair(a->src_wh_dentry));
17545 +#undef RevertFailure
17547 +/* ---------------------------------------------------------------------- */
17550 + * when we have to copyup the renaming entry, do it with the rename-target name
17551 + * in order to minimize the cost (the later actual rename is unnecessary).
17552 + * otherwise rename it on the target branch.
17554 +static int au_ren_or_cpup(struct au_ren_args *a)
17557 + struct dentry *d;
17559 + d = a->src_dentry;
17560 + if (au_dbstart(d) == a->btgt) {
17561 + a->h_path.dentry = a->dst_h_dentry;
17562 + if (au_ftest_ren(a->flags, DIROPQ)
17563 + && au_dbdiropq(d) == a->btgt)
17564 + au_fclr_ren(a->flags, DIROPQ);
17565 + AuDebugOn(au_dbstart(d) != a->btgt);
17566 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
17567 + a->dst_h_dir, &a->h_path);
17569 + struct mutex *h_mtx = &a->src_h_dentry->d_inode->i_mutex;
17570 + struct file *h_file;
17572 + au_fset_ren(a->flags, CPUP);
17573 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
17574 + au_set_dbstart(d, a->btgt);
17575 + au_set_h_dptr(d, a->btgt, dget(a->dst_h_dentry));
17576 + h_file = au_h_open_pre(d, a->src_bstart);
17577 + if (IS_ERR(h_file)) {
17578 + err = PTR_ERR(h_file);
17581 + err = au_sio_cpup_single(d, a->btgt, a->src_bstart, -1,
17582 + !AuCpup_DTIME, a->dst_parent);
17583 + mutex_unlock(h_mtx);
17584 + au_h_open_post(d, a->src_bstart, h_file);
17586 + d = a->dst_dentry;
17587 + au_set_h_dptr(d, a->btgt, NULL);
17588 + au_update_dbstart(d);
17590 + au_set_h_dptr(d, a->btgt, NULL);
17591 + au_set_dbstart(d, a->src_bstart);
17594 + if (!err && a->h_dst)
17595 + /* it will be set to dinfo later */
17601 +/* cf. aufs_rmdir() */
17602 +static int au_ren_del_whtmp(struct au_ren_args *a)
17605 + struct inode *dir;
17607 + dir = a->dst_dir;
17608 + SiMustAnyLock(dir->i_sb);
17609 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
17610 + au_sbi(dir->i_sb)->si_dirwh)
17611 + || au_test_fs_remote(a->h_dst->d_sb)) {
17612 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
17613 + if (unlikely(err))
17614 + pr_warn("failed removing whtmp dir %.*s (%d), "
17615 + "ignored.\n", AuDLNPair(a->h_dst), err);
17617 + au_nhash_wh_free(&a->thargs->whlist);
17618 + a->thargs->whlist = a->whlist;
17619 + a->whlist.nh_num = 0;
17620 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
17622 + a->thargs = NULL;
17628 +/* make it 'opaque' dir. */
17629 +static int au_ren_diropq(struct au_ren_args *a)
17632 + struct dentry *diropq;
17635 + a->src_bdiropq = au_dbdiropq(a->src_dentry);
17636 + a->src_hinode = au_hi(a->src_inode, a->btgt);
17637 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
17638 + diropq = au_diropq_create(a->src_dentry, a->btgt);
17639 + au_hn_imtx_unlock(a->src_hinode);
17640 + if (IS_ERR(diropq))
17641 + err = PTR_ERR(diropq);
17647 +static int do_rename(struct au_ren_args *a)
17650 + struct dentry *d, *h_d;
17652 + /* prepare workqueue args for asynchronous rmdir */
17653 + h_d = a->dst_h_dentry;
17654 + if (au_ftest_ren(a->flags, ISDIR) && h_d->d_inode) {
17656 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb, GFP_NOFS);
17657 + if (unlikely(!a->thargs))
17659 + a->h_dst = dget(h_d);
17662 + /* create whiteout for src_dentry */
17663 + if (au_ftest_ren(a->flags, WHSRC)) {
17664 + a->src_bwh = au_dbwh(a->src_dentry);
17665 + AuDebugOn(a->src_bwh >= 0);
17667 + = au_wh_create(a->src_dentry, a->btgt, a->src_h_parent);
17668 + err = PTR_ERR(a->src_wh_dentry);
17669 + if (IS_ERR(a->src_wh_dentry))
17673 + /* lookup whiteout for dentry */
17674 + if (au_ftest_ren(a->flags, WHDST)) {
17675 + h_d = au_wh_lkup(a->dst_h_parent, &a->dst_dentry->d_name,
17677 + err = PTR_ERR(h_d);
17680 + if (!h_d->d_inode)
17683 + a->dst_wh_dentry = h_d;
17686 + /* rename dentry to tmpwh */
17688 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
17689 + if (unlikely(err))
17692 + d = a->dst_dentry;
17693 + au_set_h_dptr(d, a->btgt, NULL);
17694 + err = au_lkup_neg(d, a->btgt);
17695 + if (unlikely(err))
17697 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
17701 + if (a->dst_h_dentry->d_inode && a->src_bstart != a->btgt) {
17702 + struct mutex *h_mtx = &a->src_h_dentry->d_inode->i_mutex;
17703 + struct file *h_file;
17705 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
17706 + AuDebugOn(au_dbstart(a->src_dentry) != a->src_bstart);
17707 + h_file = au_h_open_pre(a->src_dentry, a->src_bstart);
17708 + if (IS_ERR(h_file)) {
17709 + err = PTR_ERR(h_file);
17712 + err = au_sio_cpup_simple(a->src_dentry, a->btgt, -1,
17714 + mutex_unlock(h_mtx);
17715 + au_h_open_post(a->src_dentry, a->src_bstart, h_file);
17716 + if (unlikely(err))
17720 + /* rename by vfs_rename or cpup */
17721 + d = a->dst_dentry;
17722 + if (au_ftest_ren(a->flags, ISDIR)
17723 + && (a->dst_wh_dentry
17724 + || au_dbdiropq(d) == a->btgt
17725 + /* hide the lower to keep xino */
17726 + || a->btgt < au_dbend(d)
17727 + || au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ)))
17728 + au_fset_ren(a->flags, DIROPQ);
17729 + err = au_ren_or_cpup(a);
17730 + if (unlikely(err))
17731 + /* leave the copied-up one */
17734 + /* make dir opaque */
17735 + if (au_ftest_ren(a->flags, DIROPQ)) {
17736 + err = au_ren_diropq(a);
17737 + if (unlikely(err))
17741 + /* update target timestamps */
17742 + AuDebugOn(au_dbstart(a->src_dentry) != a->btgt);
17743 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
17744 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
17745 + a->src_inode->i_ctime = a->h_path.dentry->d_inode->i_ctime;
17747 + /* remove whiteout for dentry */
17748 + if (a->dst_wh_dentry) {
17749 + a->h_path.dentry = a->dst_wh_dentry;
17750 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
17752 + if (unlikely(err))
17756 + /* remove whtmp */
17758 + au_ren_del_whtmp(a); /* ignore this error */
17761 + goto out_success;
17764 + if (au_ftest_ren(a->flags, DIROPQ))
17765 + au_ren_rev_diropq(err, a);
17767 + if (!au_ftest_ren(a->flags, CPUP))
17768 + au_ren_rev_rename(err, a);
17770 + au_ren_rev_cpup(err, a);
17774 + au_ren_rev_whtmp(err, a);
17776 + dput(a->dst_wh_dentry);
17777 + a->dst_wh_dentry = NULL;
17779 + if (a->src_wh_dentry)
17780 + au_ren_rev_whsrc(err, a);
17782 + dput(a->src_wh_dentry);
17783 + dput(a->dst_wh_dentry);
17787 + au_whtmp_rmdir_free(a->thargs);
17788 + a->thargs = NULL;
17794 +/* ---------------------------------------------------------------------- */
17797 + * test if @dentry dir can be rename destination or not.
17798 + * success means, it is a logically empty dir.
17800 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
17802 + return au_test_empty(dentry, whlist);
17806 + * test if @dentry dir can be rename source or not.
17807 + * if it can, return 0 and @children is filled.
17809 + * - it is a logically empty dir.
17810 + * - or, it exists on writable branch and has no children including whiteouts
17811 + * on the lower branch.
17813 +static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt)
17816 + unsigned int rdhash;
17817 + aufs_bindex_t bstart;
17819 + bstart = au_dbstart(dentry);
17820 + if (bstart != btgt) {
17821 + struct au_nhash whlist;
17823 + SiMustAnyLock(dentry->d_sb);
17824 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
17826 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
17828 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
17829 + if (unlikely(err))
17831 + err = au_test_empty(dentry, &whlist);
17832 + au_nhash_wh_free(&whlist);
17836 + if (bstart == au_dbtaildir(dentry))
17837 + return 0; /* success */
17839 + err = au_test_empty_lower(dentry);
17842 + if (err == -ENOTEMPTY) {
17843 + AuWarn1("renaming dir who has child(ren) on multiple branches,"
17844 + " is not supported\n");
17850 +/* side effect: sets whlist and h_dentry */
17851 +static int au_ren_may_dir(struct au_ren_args *a)
17854 + unsigned int rdhash;
17855 + struct dentry *d;
17857 + d = a->dst_dentry;
17858 + SiMustAnyLock(d->d_sb);
17861 + if (au_ftest_ren(a->flags, ISDIR) && a->dst_inode) {
17862 + rdhash = au_sbi(d->d_sb)->si_rdhash;
17864 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
17865 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
17866 + if (unlikely(err))
17869 + au_set_dbstart(d, a->dst_bstart);
17870 + err = may_rename_dstdir(d, &a->whlist);
17871 + au_set_dbstart(d, a->btgt);
17873 + a->dst_h_dentry = au_h_dptr(d, au_dbstart(d));
17874 + if (unlikely(err))
17877 + d = a->src_dentry;
17878 + a->src_h_dentry = au_h_dptr(d, au_dbstart(d));
17879 + if (au_ftest_ren(a->flags, ISDIR)) {
17880 + err = may_rename_srcdir(d, a->btgt);
17881 + if (unlikely(err)) {
17882 + au_nhash_wh_free(&a->whlist);
17883 + a->whlist.nh_num = 0;
17890 +/* ---------------------------------------------------------------------- */
17893 + * simple tests for rename.
17894 + * following the checks in vfs, plus the parent-child relationship.
17896 +static int au_may_ren(struct au_ren_args *a)
17899 + struct inode *h_inode;
17901 + if (a->src_bstart == a->btgt) {
17902 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
17903 + au_ftest_ren(a->flags, ISDIR));
17904 + if (unlikely(err))
17907 + if (unlikely(a->src_h_dentry == a->h_trap))
17912 + if (a->dst_bstart != a->btgt)
17915 + err = -ENOTEMPTY;
17916 + if (unlikely(a->dst_h_dentry == a->h_trap))
17920 + h_inode = a->dst_h_dentry->d_inode;
17921 + isdir = !!au_ftest_ren(a->flags, ISDIR);
17922 + if (!a->dst_dentry->d_inode) {
17923 + if (unlikely(h_inode))
17925 + err = au_may_add(a->dst_dentry, a->btgt, a->dst_h_parent,
17928 + if (unlikely(!h_inode || !h_inode->i_nlink))
17930 + err = au_may_del(a->dst_dentry, a->btgt, a->dst_h_parent,
17932 + if (unlikely(err))
17937 + if (unlikely(err == -ENOENT || err == -EEXIST))
17943 +/* ---------------------------------------------------------------------- */
17948 + * - src_dir and dir by lock_rename()
17949 + * - inode if exitsts
17952 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
17954 + * + di_write_lock2_child()
17955 + * + di_write_lock_child()
17956 + * + ii_write_lock_child()
17957 + * + di_write_lock_child2()
17958 + * + ii_write_lock_child2()
17959 + * + src_parent and parent
17960 + * + di_write_lock_parent()
17961 + * + ii_write_lock_parent()
17962 + * + di_write_lock_parent2()
17963 + * + ii_write_lock_parent2()
17964 + * + lower src_dir and dir by vfsub_lock_rename()
17965 + * + verify the every relationships between child and parent. if any
17966 + * of them failed, unlock all and return -EBUSY.
17968 +static void au_ren_unlock(struct au_ren_args *a)
17970 + struct super_block *sb;
17972 + sb = a->dst_dentry->d_sb;
17973 + if (au_ftest_ren(a->flags, MNT_WRITE))
17974 + mnt_drop_write(a->br->br_mnt);
17975 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
17976 + a->dst_h_parent, a->dst_hdir);
17979 +static int au_ren_lock(struct au_ren_args *a)
17982 + unsigned int udba;
17985 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
17986 + a->src_hdir = au_hi(a->src_dir, a->btgt);
17987 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
17988 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
17989 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
17990 + a->dst_h_parent, a->dst_hdir);
17991 + udba = au_opt_udba(a->src_dentry->d_sb);
17992 + if (unlikely(a->src_hdir->hi_inode != a->src_h_parent->d_inode
17993 + || a->dst_hdir->hi_inode != a->dst_h_parent->d_inode))
17994 + err = au_busy_or_stale();
17995 + if (!err && au_dbstart(a->src_dentry) == a->btgt)
17996 + err = au_h_verify(a->src_h_dentry, udba,
17997 + a->src_h_parent->d_inode, a->src_h_parent,
17999 + if (!err && au_dbstart(a->dst_dentry) == a->btgt)
18000 + err = au_h_verify(a->dst_h_dentry, udba,
18001 + a->dst_h_parent->d_inode, a->dst_h_parent,
18004 + err = mnt_want_write(a->br->br_mnt);
18005 + if (unlikely(err))
18007 + au_fset_ren(a->flags, MNT_WRITE);
18008 + goto out; /* success */
18011 + err = au_busy_or_stale();
18014 + au_ren_unlock(a);
18019 +/* ---------------------------------------------------------------------- */
18021 +static void au_ren_refresh_dir(struct au_ren_args *a)
18023 + struct inode *dir;
18025 + dir = a->dst_dir;
18026 + dir->i_version++;
18027 + if (au_ftest_ren(a->flags, ISDIR)) {
18028 + /* is this updating defined in POSIX? */
18029 + au_cpup_attr_timesizes(a->src_inode);
18030 + au_cpup_attr_nlink(dir, /*force*/1);
18033 + if (au_ibstart(dir) == a->btgt)
18034 + au_cpup_attr_timesizes(dir);
18036 + if (au_ftest_ren(a->flags, ISSAMEDIR))
18039 + dir = a->src_dir;
18040 + dir->i_version++;
18041 + if (au_ftest_ren(a->flags, ISDIR))
18042 + au_cpup_attr_nlink(dir, /*force*/1);
18043 + if (au_ibstart(dir) == a->btgt)
18044 + au_cpup_attr_timesizes(dir);
18047 +static void au_ren_refresh(struct au_ren_args *a)
18049 + aufs_bindex_t bend, bindex;
18050 + struct dentry *d, *h_d;
18051 + struct inode *i, *h_i;
18052 + struct super_block *sb;
18054 + d = a->dst_dentry;
18057 + /* already dget-ed by au_ren_or_cpup() */
18058 + au_set_h_dptr(d, a->btgt, a->h_dst);
18060 + i = a->dst_inode;
18062 + if (!au_ftest_ren(a->flags, ISDIR))
18063 + vfsub_drop_nlink(i);
18065 + vfsub_dead_dir(i);
18066 + au_cpup_attr_timesizes(i);
18068 + au_update_dbrange(d, /*do_put_zero*/1);
18071 + for (bindex = au_dbstart(d); bindex < bend; bindex++)
18072 + au_set_h_dptr(d, bindex, NULL);
18073 + bend = au_dbend(d);
18074 + for (bindex = a->btgt + 1; bindex <= bend; bindex++)
18075 + au_set_h_dptr(d, bindex, NULL);
18076 + au_update_dbrange(d, /*do_put_zero*/0);
18079 + d = a->src_dentry;
18080 + au_set_dbwh(d, -1);
18081 + bend = au_dbend(d);
18082 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
18083 + h_d = au_h_dptr(d, bindex);
18085 + au_set_h_dptr(d, bindex, NULL);
18087 + au_set_dbend(d, a->btgt);
18090 + i = a->src_inode;
18091 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
18092 + return; /* success */
18094 + bend = au_ibend(i);
18095 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
18096 + h_i = au_h_iptr(i, bindex);
18098 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
18099 + /* ignore this error */
18100 + au_set_h_iptr(i, bindex, NULL, 0);
18103 + au_set_ibend(i, a->btgt);
18106 +/* ---------------------------------------------------------------------- */
18108 +/* mainly for link(2) and rename(2) */
18109 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
18111 + aufs_bindex_t bdiropq, bwh;
18112 + struct dentry *parent;
18113 + struct au_branch *br;
18115 + parent = dentry->d_parent;
18116 + IMustLock(parent->d_inode); /* dir is locked */
18118 + bdiropq = au_dbdiropq(parent);
18119 + bwh = au_dbwh(dentry);
18120 + br = au_sbr(dentry->d_sb, btgt);
18121 + if (au_br_rdonly(br)
18122 + || (0 <= bdiropq && bdiropq < btgt)
18123 + || (0 <= bwh && bwh < btgt))
18126 + AuDbg("btgt %d\n", btgt);
18130 +/* sets src_bstart, dst_bstart and btgt */
18131 +static int au_ren_wbr(struct au_ren_args *a)
18134 + struct au_wr_dir_args wr_dir_args = {
18135 + /* .force_btgt = -1, */
18136 + .flags = AuWrDir_ADD_ENTRY
18139 + a->src_bstart = au_dbstart(a->src_dentry);
18140 + a->dst_bstart = au_dbstart(a->dst_dentry);
18141 + if (au_ftest_ren(a->flags, ISDIR))
18142 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
18143 + wr_dir_args.force_btgt = a->src_bstart;
18144 + if (a->dst_inode && a->dst_bstart < a->src_bstart)
18145 + wr_dir_args.force_btgt = a->dst_bstart;
18146 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
18147 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
18153 +static void au_ren_dt(struct au_ren_args *a)
18155 + a->h_path.dentry = a->src_h_parent;
18156 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
18157 + if (!au_ftest_ren(a->flags, ISSAMEDIR)) {
18158 + a->h_path.dentry = a->dst_h_parent;
18159 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
18162 + au_fclr_ren(a->flags, DT_DSTDIR);
18163 + if (!au_ftest_ren(a->flags, ISDIR))
18166 + a->h_path.dentry = a->src_h_dentry;
18167 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
18168 + if (a->dst_h_dentry->d_inode) {
18169 + au_fset_ren(a->flags, DT_DSTDIR);
18170 + a->h_path.dentry = a->dst_h_dentry;
18171 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
18175 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
18177 + struct dentry *h_d;
18178 + struct mutex *h_mtx;
18180 + au_dtime_revert(a->src_dt + AuPARENT);
18181 + if (!au_ftest_ren(a->flags, ISSAMEDIR))
18182 + au_dtime_revert(a->dst_dt + AuPARENT);
18184 + if (au_ftest_ren(a->flags, ISDIR) && err != -EIO) {
18185 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
18186 + h_mtx = &h_d->d_inode->i_mutex;
18187 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
18188 + au_dtime_revert(a->src_dt + AuCHILD);
18189 + mutex_unlock(h_mtx);
18191 + if (au_ftest_ren(a->flags, DT_DSTDIR)) {
18192 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
18193 + h_mtx = &h_d->d_inode->i_mutex;
18194 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
18195 + au_dtime_revert(a->dst_dt + AuCHILD);
18196 + mutex_unlock(h_mtx);
18201 +/* ---------------------------------------------------------------------- */
18203 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
18204 + struct inode *_dst_dir, struct dentry *_dst_dentry)
18207 + /* reduce stack space */
18208 + struct au_ren_args *a;
18210 + AuDbg("%.*s, %.*s\n", AuDLNPair(_src_dentry), AuDLNPair(_dst_dentry));
18211 + IMustLock(_src_dir);
18212 + IMustLock(_dst_dir);
18215 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
18216 + a = kzalloc(sizeof(*a), GFP_NOFS);
18217 + if (unlikely(!a))
18220 + a->src_dir = _src_dir;
18221 + a->src_dentry = _src_dentry;
18222 + a->src_inode = a->src_dentry->d_inode;
18223 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
18224 + a->dst_dir = _dst_dir;
18225 + a->dst_dentry = _dst_dentry;
18226 + a->dst_inode = a->dst_dentry->d_inode;
18227 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
18228 + if (a->dst_inode) {
18229 + IMustLock(a->dst_inode);
18230 + au_igrab(a->dst_inode);
18234 + flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
18235 + if (S_ISDIR(a->src_inode->i_mode)) {
18236 + au_fset_ren(a->flags, ISDIR);
18237 + if (unlikely(a->dst_inode && !S_ISDIR(a->dst_inode->i_mode)))
18239 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
18240 + AuLock_DIR | flags);
18242 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
18244 + if (unlikely(err))
18247 + err = au_d_hashed_positive(a->src_dentry);
18248 + if (unlikely(err))
18251 + if (a->dst_inode) {
18253 + * If it is a dir, VFS unhash dst_dentry before this
18254 + * function. It means we cannot rely upon d_unhashed().
18256 + if (unlikely(!a->dst_inode->i_nlink))
18258 + if (!S_ISDIR(a->dst_inode->i_mode)) {
18259 + err = au_d_hashed_positive(a->dst_dentry);
18260 + if (unlikely(err))
18262 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
18264 + } else if (unlikely(d_unhashed(a->dst_dentry)))
18268 + * is it possible?
18269 + * yes, it happend (in linux-3.3-rcN) but I don't know why.
18270 + * there may exist a problem somewhere else.
18273 + if (unlikely(a->dst_parent->d_inode == a->src_dentry->d_inode))
18276 + au_fset_ren(a->flags, ISSAMEDIR); /* temporary */
18277 + di_write_lock_parent(a->dst_parent);
18279 + /* which branch we process */
18280 + err = au_ren_wbr(a);
18281 + if (unlikely(err < 0))
18283 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
18284 + a->h_path.mnt = a->br->br_mnt;
18286 + /* are they available to be renamed */
18287 + err = au_ren_may_dir(a);
18288 + if (unlikely(err))
18289 + goto out_children;
18291 + /* prepare the writable parent dir on the same branch */
18292 + if (a->dst_bstart == a->btgt) {
18293 + au_fset_ren(a->flags, WHDST);
18295 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
18296 + if (unlikely(err))
18297 + goto out_children;
18300 + if (a->src_dir != a->dst_dir) {
18302 + * this temporary unlock is safe,
18303 + * because both dir->i_mutex are locked.
18305 + di_write_unlock(a->dst_parent);
18306 + di_write_lock_parent(a->src_parent);
18307 + err = au_wr_dir_need_wh(a->src_dentry,
18308 + au_ftest_ren(a->flags, ISDIR),
18310 + di_write_unlock(a->src_parent);
18311 + di_write_lock2_parent(a->src_parent, a->dst_parent, /*isdir*/1);
18312 + au_fclr_ren(a->flags, ISSAMEDIR);
18314 + err = au_wr_dir_need_wh(a->src_dentry,
18315 + au_ftest_ren(a->flags, ISDIR),
18317 + if (unlikely(err < 0))
18318 + goto out_children;
18320 + au_fset_ren(a->flags, WHSRC);
18322 + /* lock them all */
18323 + err = au_ren_lock(a);
18324 + if (unlikely(err))
18325 + goto out_children;
18327 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
18328 + err = au_may_ren(a);
18329 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
18330 + err = -ENAMETOOLONG;
18331 + if (unlikely(err))
18334 + /* store timestamps to be revertible */
18338 + err = do_rename(a);
18339 + if (unlikely(err))
18342 + /* update dir attributes */
18343 + au_ren_refresh_dir(a);
18345 + /* dput/iput all lower dentries */
18346 + au_ren_refresh(a);
18348 + goto out_hdir; /* success */
18351 + au_ren_rev_dt(err, a);
18353 + au_ren_unlock(a);
18355 + au_nhash_wh_free(&a->whlist);
18356 + if (err && a->dst_inode && a->dst_bstart != a->btgt) {
18357 + AuDbg("bstart %d, btgt %d\n", a->dst_bstart, a->btgt);
18358 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
18359 + au_set_dbstart(a->dst_dentry, a->dst_bstart);
18363 + d_move(a->src_dentry, a->dst_dentry);
18365 + au_update_dbstart(a->dst_dentry);
18366 + if (!a->dst_inode)
18367 + d_drop(a->dst_dentry);
18369 + if (au_ftest_ren(a->flags, ISSAMEDIR))
18370 + di_write_unlock(a->dst_parent);
18372 + di_write_unlock2(a->src_parent, a->dst_parent);
18374 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
18376 + iput(a->dst_inode);
18378 + au_whtmp_rmdir_free(a->thargs);
18384 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
18385 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
18386 +++ linux/fs/aufs/Kconfig 2012-07-22 19:57:03.161004531 +0200
18389 + tristate "Aufs (Advanced multi layered unification filesystem) support"
18390 + depends on EXPERIMENTAL
18392 + Aufs is a stackable unification filesystem such as Unionfs,
18393 + which unifies several directories and provides a merged single
18395 + In the early days, aufs was entirely re-designed and
18396 + re-implemented Unionfs Version 1.x series. Introducing many
18397 + original ideas, approaches and improvements, it becomes totally
18398 + different from Unionfs while keeping the basic features.
18402 + prompt "Maximum number of branches"
18403 + default AUFS_BRANCH_MAX_127
18405 + Specifies the maximum number of branches (or member directories)
18406 + in a single aufs. The larger value consumes more system
18407 + resources and has a minor impact to performance.
18408 +config AUFS_BRANCH_MAX_127
18411 + Specifies the maximum number of branches (or member directories)
18412 + in a single aufs. The larger value consumes more system
18413 + resources and has a minor impact to performance.
18414 +config AUFS_BRANCH_MAX_511
18417 + Specifies the maximum number of branches (or member directories)
18418 + in a single aufs. The larger value consumes more system
18419 + resources and has a minor impact to performance.
18420 +config AUFS_BRANCH_MAX_1023
18423 + Specifies the maximum number of branches (or member directories)
18424 + in a single aufs. The larger value consumes more system
18425 + resources and has a minor impact to performance.
18426 +config AUFS_BRANCH_MAX_32767
18429 + Specifies the maximum number of branches (or member directories)
18430 + in a single aufs. The larger value consumes more system
18431 + resources and has a minor impact to performance.
18434 +config AUFS_SBILIST
18436 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
18439 + Automatic configuration for internal use.
18440 + When aufs supports Magic SysRq or /proc, enabled automatically.
18442 +config AUFS_HNOTIFY
18443 + bool "Detect direct branch access (bypassing aufs)"
18445 + If you want to modify files on branches directly, eg. bypassing aufs,
18446 + and want aufs to detect the changes of them fully, then enable this
18447 + option and use 'udba=notify' mount option.
18448 + Currently there is only one available configuration, "fsnotify".
18449 + It will have a negative impact to the performance.
18450 + See detail in aufs.5.
18453 + prompt "method" if AUFS_HNOTIFY
18454 + default AUFS_HFSNOTIFY
18455 +config AUFS_HFSNOTIFY
18460 +config AUFS_EXPORT
18461 + bool "NFS-exportable aufs"
18462 + depends on EXPORTFS
18464 + If you want to export your mounted aufs via NFS, then enable this
18465 + option. There are several requirements for this configuration.
18466 + See detail in aufs.5.
18468 +config AUFS_INO_T_64
18470 + depends on AUFS_EXPORT
18471 + depends on 64BIT && !(ALPHA || S390)
18474 + Automatic configuration for internal use.
18475 + /* typedef unsigned long/int __kernel_ino_t */
18476 + /* alpha and s390x are int */
18479 + bool "Readdir in userspace"
18481 + Aufs has two methods to provide a merged view for a directory,
18482 + by a user-space library and by kernel-space natively. The latter
18483 + is always enabled but sometimes large and slow.
18484 + If you enable this option, install the library in aufs2-util
18485 + package, and set some environment variables for your readdir(3),
18486 + then the work will be handled in user-space which generally
18487 + shows better performance in most cases.
18488 + See detail in aufs.5.
18490 +config AUFS_PROC_MAP
18491 + bool "support for /proc/maps and lsof(1)"
18492 + depends on PROC_FS
18494 + When you issue mmap(2) in aufs, it is actually a direct mmap(2)
18495 + call to the file on the branch fs since the file in aufs is
18496 + purely virtual. And the file path printed in /proc/maps (and
18497 + others) will be the path on the branch fs. In most cases, it
18498 + does no harm. But some utilities like lsof(1) may confuse since
18499 + the utility or user may expect the file path in aufs to be
18501 + To address this issue, aufs provides a patch which introduces a
18502 + new member called vm_prfile into struct vm_are_struct. The patch
18503 + is meaningless without enabling this configuration since nobody
18504 + sets the new vm_prfile member.
18505 + If you don't apply the patch, then enabling this configuration
18506 + will cause a compile error.
18507 + This approach is fragile since if someone else make some changes
18508 + around vm_file, then vm_prfile may not work anymore. As a
18509 + workaround such case, aufs provides this configuration. If you
18510 + disable it, then lsof(1) may produce incorrect result but the
18511 + problem will be gone even if the aufs patch is applied (I hope).
18513 +config AUFS_SP_IATTR
18514 + bool "Respect the attributes (mtime/ctime mainly) of special files"
18516 + When you write something to a special file, some attributes of it
18517 + (mtime/ctime mainly) may be updated. Generally such updates are
18518 + less important (actually some device drivers and NFS ignore
18519 + it). But some applications (such like test program) requires
18520 + such updates. If you need these updates, then enable this
18521 + configuration which introduces some overhead.
18522 + Currently this configuration handles FIFO only.
18525 + bool "Show whiteouts"
18527 + If you want to make the whiteouts in aufs visible, then enable
18528 + this option and specify 'shwh' mount option. Although it may
18529 + sounds like philosophy or something, but in technically it
18530 + simply shows the name of whiteout with keeping its behaviour.
18532 +config AUFS_BR_RAMFS
18533 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
18535 + If you want to use ramfs as an aufs branch fs, then enable this
18536 + option. Generally tmpfs is recommended.
18537 + Aufs prohibited them to be a branch fs by default, because
18538 + initramfs becomes unusable after switch_root or something
18539 + generally. If you sets initramfs as an aufs branch and boot your
18540 + system by switch_root, you will meet a problem easily since the
18541 + files in initramfs may be inaccessible.
18542 + Unless you are going to use ramfs as an aufs branch fs without
18543 + switch_root or something, leave it N.
18545 +config AUFS_BR_FUSE
18546 + bool "Fuse fs as an aufs branch"
18547 + depends on FUSE_FS
18550 + If you want to use fuse-based userspace filesystem as an aufs
18551 + branch fs, then enable this option.
18552 + It implements the internal poll(2) operation which is
18553 + implemented by fuse only (curretnly).
18558 + Automatic configuration for internal use.
18560 +config AUFS_BR_HFSPLUS
18561 + bool "Hfsplus as an aufs branch"
18562 + depends on HFSPLUS_FS
18565 + If you want to use hfsplus fs as an aufs branch fs, then enable
18566 + this option. This option introduces a small overhead at
18567 + copying-up a file on hfsplus.
18569 +config AUFS_BDEV_LOOP
18571 + depends on BLK_DEV_LOOP
18574 + Automatic configuration for internal use.
18575 + Convert =[ym] into =y.
18578 + bool "Debug aufs"
18580 + Enable this to compile aufs internal debug code.
18581 + It will have a negative impact to the performance.
18583 +config AUFS_MAGIC_SYSRQ
18585 + depends on AUFS_DEBUG && MAGIC_SYSRQ
18588 + Automatic configuration for internal use.
18589 + When aufs supports Magic SysRq, enabled automatically.
18591 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
18592 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
18593 +++ linux/fs/aufs/loop.c 2012-07-22 19:57:03.164337936 +0200
18596 + * Copyright (C) 2005-2012 Junjiro R. Okajima
18598 + * This program, aufs is free software; you can redistribute it and/or modify
18599 + * it under the terms of the GNU General Public License as published by
18600 + * the Free Software Foundation; either version 2 of the License, or
18601 + * (at your option) any later version.
18603 + * This program is distributed in the hope that it will be useful,
18604 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18605 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18606 + * GNU General Public License for more details.
18608 + * You should have received a copy of the GNU General Public License
18609 + * along with this program; if not, write to the Free Software
18610 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18614 + * support for loopback block device as a branch
18617 +#include <linux/loop.h>
18621 + * test if two lower dentries have overlapping branches.
18623 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
18625 + struct super_block *h_sb;
18626 + struct loop_device *l;
18628 + h_sb = h_adding->d_sb;
18629 + if (MAJOR(h_sb->s_dev) != LOOP_MAJOR)
18632 + l = h_sb->s_bdev->bd_disk->private_data;
18633 + h_adding = l->lo_backing_file->f_dentry;
18635 + * h_adding can be local NFS.
18636 + * in this case aufs cannot detect the loop.
18638 + if (unlikely(h_adding->d_sb == sb))
18640 + return !!au_test_subdir(h_adding, sb->s_root);
18643 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
18644 +int au_test_loopback_kthread(void)
18647 + struct task_struct *tsk = current;
18650 + if (tsk->flags & PF_KTHREAD) {
18651 + const char c = tsk->comm[4];
18652 + ret = ('0' <= c && c <= '9'
18653 + && !strncmp(tsk->comm, "loop", 4));
18659 +/* ---------------------------------------------------------------------- */
18661 +#define au_warn_loopback_step 16
18662 +static int au_warn_loopback_nelem = au_warn_loopback_step;
18663 +static unsigned long *au_warn_loopback_array;
18665 +void au_warn_loopback(struct super_block *h_sb)
18667 + int i, new_nelem;
18668 + unsigned long *a, magic;
18669 + static DEFINE_SPINLOCK(spin);
18671 + magic = h_sb->s_magic;
18672 + spin_lock(&spin);
18673 + a = au_warn_loopback_array;
18674 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
18675 + if (a[i] == magic) {
18676 + spin_unlock(&spin);
18680 + /* h_sb is new to us, print it */
18681 + if (i < au_warn_loopback_nelem) {
18686 + /* expand the array */
18687 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
18688 + a = au_kzrealloc(au_warn_loopback_array,
18689 + au_warn_loopback_nelem * sizeof(unsigned long),
18690 + new_nelem * sizeof(unsigned long), GFP_ATOMIC);
18692 + au_warn_loopback_nelem = new_nelem;
18693 + au_warn_loopback_array = a;
18698 + spin_unlock(&spin);
18699 + AuWarn1("realloc failed, ignored\n");
18703 + spin_unlock(&spin);
18704 + pr_warn("you may want to try another patch for loopback file "
18705 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
18708 +int au_loopback_init(void)
18711 + struct super_block *sb __maybe_unused;
18713 + AuDebugOn(sizeof(sb->s_magic) != sizeof(unsigned long));
18716 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
18717 + sizeof(unsigned long), GFP_NOFS);
18718 + if (unlikely(!au_warn_loopback_array))
18724 +void au_loopback_fin(void)
18726 + kfree(au_warn_loopback_array);
18728 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
18729 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
18730 +++ linux/fs/aufs/loop.h 2012-07-22 19:57:03.164337936 +0200
18733 + * Copyright (C) 2005-2012 Junjiro R. Okajima
18735 + * This program, aufs is free software; you can redistribute it and/or modify
18736 + * it under the terms of the GNU General Public License as published by
18737 + * the Free Software Foundation; either version 2 of the License, or
18738 + * (at your option) any later version.
18740 + * This program is distributed in the hope that it will be useful,
18741 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18742 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18743 + * GNU General Public License for more details.
18745 + * You should have received a copy of the GNU General Public License
18746 + * along with this program; if not, write to the Free Software
18747 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18751 + * support for loopback mount as a branch
18754 +#ifndef __AUFS_LOOP_H__
18755 +#define __AUFS_LOOP_H__
18760 +struct super_block;
18762 +#ifdef CONFIG_AUFS_BDEV_LOOP
18764 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
18765 +int au_test_loopback_kthread(void);
18766 +void au_warn_loopback(struct super_block *h_sb);
18768 +int au_loopback_init(void);
18769 +void au_loopback_fin(void);
18771 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
18772 + struct dentry *h_adding)
18773 +AuStubInt0(au_test_loopback_kthread, void)
18774 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
18776 +AuStubInt0(au_loopback_init, void)
18777 +AuStubVoid(au_loopback_fin, void)
18778 +#endif /* BLK_DEV_LOOP */
18780 +#endif /* __KERNEL__ */
18781 +#endif /* __AUFS_LOOP_H__ */
18782 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
18783 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
18784 +++ linux/fs/aufs/magic.mk 2012-07-22 19:57:03.164337936 +0200
18787 +# defined in ${srctree}/fs/fuse/inode.c
18789 +ifdef CONFIG_FUSE_FS
18790 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
18793 +# defined in ${srctree}/fs/ocfs2/ocfs2_fs.h
18795 +ifdef CONFIG_OCFS2_FS
18796 +ccflags-y += -DOCFS2_SUPER_MAGIC=0x7461636f
18799 +# defined in ${srctree}/fs/ocfs2/dlm/userdlm.h
18801 +ifdef CONFIG_OCFS2_FS_O2CB
18802 +ccflags-y += -DDLMFS_MAGIC=0x76a9f425
18805 +# defined in ${srctree}/fs/cifs/cifsfs.c
18807 +ifdef CONFIG_CIFS_FS
18808 +ccflags-y += -DCIFS_MAGIC_NUMBER=0xFF534D42
18811 +# defined in ${srctree}/fs/xfs/xfs_sb.h
18813 +ifdef CONFIG_XFS_FS
18814 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
18817 +# defined in ${srctree}/fs/configfs/mount.c
18819 +ifdef CONFIG_CONFIGFS_FS
18820 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
18823 +# defined in ${srctree}/fs/9p/v9fs.h
18825 +ifdef CONFIG_9P_FS
18826 +ccflags-y += -DV9FS_MAGIC=0x01021997
18829 +# defined in ${srctree}/fs/ubifs/ubifs.h
18831 +ifdef CONFIG_UBIFS_FS
18832 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
18835 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
18837 +ifdef CONFIG_HFSPLUS_FS
18838 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
18840 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
18841 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
18842 +++ linux/fs/aufs/Makefile 2012-07-22 19:57:03.161004531 +0200
18845 +include ${src}/magic.mk
18846 +ifeq (${CONFIG_AUFS_FS},m)
18847 +include ${src}/conf.mk
18849 +-include ${src}/priv_def.mk
18851 +# cf. include/linux/kernel.h
18853 +ccflags-y += -DDEBUG
18854 +# sparse requires the full pathname
18856 +ccflags-y += -include ${M}/../../include/linux/aufs_type.h
18858 +ccflags-y += -include ${srctree}/include/linux/aufs_type.h
18861 +obj-$(CONFIG_AUFS_FS) += aufs.o
18862 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
18863 + wkq.o vfsub.o dcsub.o \
18864 + cpup.o whout.o wbr_policy.o \
18865 + dinfo.o dentry.o \
18867 + finfo.o file.o f_op.o \
18869 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
18873 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
18874 +aufs-$(CONFIG_SYSFS) += sysfs.o
18875 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
18876 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
18877 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
18878 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
18879 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
18880 +aufs-$(CONFIG_AUFS_POLL) += poll.o
18881 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
18882 +aufs-$(CONFIG_AUFS_SP_IATTR) += f_op_sp.o
18884 +aufs-$(CONFIG_SECURITY) += security.o
18886 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
18887 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
18888 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
18889 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
18890 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
18891 +++ linux/fs/aufs/module.c 2012-07-22 19:57:03.164337936 +0200
18894 + * Copyright (C) 2005-2012 Junjiro R. Okajima
18896 + * This program, aufs is free software; you can redistribute it and/or modify
18897 + * it under the terms of the GNU General Public License as published by
18898 + * the Free Software Foundation; either version 2 of the License, or
18899 + * (at your option) any later version.
18901 + * This program is distributed in the hope that it will be useful,
18902 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18903 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18904 + * GNU General Public License for more details.
18906 + * You should have received a copy of the GNU General Public License
18907 + * along with this program; if not, write to the Free Software
18908 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18912 + * module global variables and operations
18915 +#include <linux/module.h>
18916 +#include <linux/seq_file.h>
18919 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp)
18921 + if (new_sz <= nused)
18924 + p = krealloc(p, new_sz, gfp);
18926 + memset(p + nused, 0, new_sz - nused);
18930 +/* ---------------------------------------------------------------------- */
18935 +struct kmem_cache *au_cachep[AuCache_Last];
18936 +static int __init au_cache_init(void)
18938 + au_cachep[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
18939 + if (au_cachep[AuCache_DINFO])
18940 + /* SLAB_DESTROY_BY_RCU */
18941 + au_cachep[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
18942 + au_icntnr_init_once);
18943 + if (au_cachep[AuCache_ICNTNR])
18944 + au_cachep[AuCache_FINFO] = AuCacheCtor(au_finfo,
18945 + au_fi_init_once);
18946 + if (au_cachep[AuCache_FINFO])
18947 + au_cachep[AuCache_VDIR] = AuCache(au_vdir);
18948 + if (au_cachep[AuCache_VDIR])
18949 + au_cachep[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
18950 + if (au_cachep[AuCache_DEHSTR])
18956 +static void au_cache_fin(void)
18960 + /* excluding AuCache_HNOTIFY */
18961 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
18962 + for (i = 0; i < AuCache_HNOTIFY; i++)
18963 + if (au_cachep[i]) {
18964 + kmem_cache_destroy(au_cachep[i]);
18965 + au_cachep[i] = NULL;
18969 +/* ---------------------------------------------------------------------- */
18971 +int au_dir_roflags;
18973 +#ifdef CONFIG_AUFS_SBILIST
18975 + * iterate_supers_type() doesn't protect us from
18976 + * remounting (branch management)
18978 +struct au_splhead au_sbilist;
18981 +struct lock_class_key au_lc_key[AuLcKey_Last];
18984 + * functions for module interface.
18986 +MODULE_LICENSE("GPL");
18987 +/* MODULE_LICENSE("GPL v2"); */
18988 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
18989 +MODULE_DESCRIPTION(AUFS_NAME
18990 + " -- Advanced multi layered unification filesystem");
18991 +MODULE_VERSION(AUFS_VERSION);
18993 +/* this module parameter has no meaning when SYSFS is disabled */
18994 +int sysaufs_brs = 1;
18995 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
18996 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
18998 +/* ---------------------------------------------------------------------- */
19000 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
19002 +int au_seq_path(struct seq_file *seq, struct path *path)
19004 + return seq_path(seq, path, au_esc_chars);
19007 +/* ---------------------------------------------------------------------- */
19009 +static int __init aufs_init(void)
19014 + p = au_esc_chars;
19015 + for (i = 1; i <= ' '; i++)
19021 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
19023 + au_sbilist_init();
19024 + sysaufs_brs_init();
19027 + err = sysaufs_init();
19028 + if (unlikely(err))
19030 + err = au_procfs_init();
19031 + if (unlikely(err))
19032 + goto out_sysaufs;
19033 + err = au_wkq_init();
19034 + if (unlikely(err))
19036 + err = au_loopback_init();
19037 + if (unlikely(err))
19039 + err = au_hnotify_init();
19040 + if (unlikely(err))
19041 + goto out_loopback;
19042 + err = au_sysrq_init();
19043 + if (unlikely(err))
19045 + err = au_cache_init();
19046 + if (unlikely(err))
19048 + err = register_filesystem(&aufs_fs_type);
19049 + if (unlikely(err))
19051 + /* since we define pr_fmt, call printk directly */
19052 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
19053 + goto out; /* success */
19060 + au_hnotify_fin();
19062 + au_loopback_fin();
19074 +static void __exit aufs_exit(void)
19076 + unregister_filesystem(&aufs_fs_type);
19079 + au_hnotify_fin();
19080 + au_loopback_fin();
19087 +module_init(aufs_init);
19088 +module_exit(aufs_exit);
19089 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
19090 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
19091 +++ linux/fs/aufs/module.h 2012-07-22 19:57:03.164337936 +0200
19094 + * Copyright (C) 2005-2012 Junjiro R. Okajima
19096 + * This program, aufs is free software; you can redistribute it and/or modify
19097 + * it under the terms of the GNU General Public License as published by
19098 + * the Free Software Foundation; either version 2 of the License, or
19099 + * (at your option) any later version.
19101 + * This program is distributed in the hope that it will be useful,
19102 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19103 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19104 + * GNU General Public License for more details.
19106 + * You should have received a copy of the GNU General Public License
19107 + * along with this program; if not, write to the Free Software
19108 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19112 + * module initialization and module-global
19115 +#ifndef __AUFS_MODULE_H__
19116 +#define __AUFS_MODULE_H__
19120 +#include <linux/slab.h>
19125 +/* module parameters */
19126 +extern int sysaufs_brs;
19128 +/* ---------------------------------------------------------------------- */
19130 +extern int au_dir_roflags;
19133 + AuLcNonDir_FIINFO,
19134 + AuLcNonDir_DIINFO,
19135 + AuLcNonDir_IIINFO,
19141 + AuLcSymlink_DIINFO,
19142 + AuLcSymlink_IIINFO,
19146 +extern struct lock_class_key au_lc_key[AuLcKey_Last];
19148 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp);
19149 +int au_seq_path(struct seq_file *seq, struct path *path);
19151 +#ifdef CONFIG_PROC_FS
19153 +int __init au_procfs_init(void);
19154 +void au_procfs_fin(void);
19156 +AuStubInt0(au_procfs_init, void);
19157 +AuStubVoid(au_procfs_fin, void);
19160 +/* ---------------------------------------------------------------------- */
19169 + AuCache_HNOTIFY, /* must be last */
19173 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
19174 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
19175 +#define AuCacheCtor(type, ctor) \
19176 + kmem_cache_create(#type, sizeof(struct type), \
19177 + __alignof__(struct type), AuCacheFlags, ctor)
19179 +extern struct kmem_cache *au_cachep[];
19181 +#define AuCacheFuncs(name, index) \
19182 +static inline struct au_##name *au_cache_alloc_##name(void) \
19183 +{ return kmem_cache_alloc(au_cachep[AuCache_##index], GFP_NOFS); } \
19184 +static inline void au_cache_free_##name(struct au_##name *p) \
19185 +{ kmem_cache_free(au_cachep[AuCache_##index], p); }
19187 +AuCacheFuncs(dinfo, DINFO);
19188 +AuCacheFuncs(icntnr, ICNTNR);
19189 +AuCacheFuncs(finfo, FINFO);
19190 +AuCacheFuncs(vdir, VDIR);
19191 +AuCacheFuncs(vdir_dehstr, DEHSTR);
19192 +#ifdef CONFIG_AUFS_HNOTIFY
19193 +AuCacheFuncs(hnotify, HNOTIFY);
19196 +#endif /* __KERNEL__ */
19197 +#endif /* __AUFS_MODULE_H__ */
19198 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
19199 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
19200 +++ linux/fs/aufs/opts.c 2012-07-22 19:57:03.164337936 +0200
19203 + * Copyright (C) 2005-2012 Junjiro R. Okajima
19205 + * This program, aufs is free software; you can redistribute it and/or modify
19206 + * it under the terms of the GNU General Public License as published by
19207 + * the Free Software Foundation; either version 2 of the License, or
19208 + * (at your option) any later version.
19210 + * This program is distributed in the hope that it will be useful,
19211 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19212 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19213 + * GNU General Public License for more details.
19215 + * You should have received a copy of the GNU General Public License
19216 + * along with this program; if not, write to the Free Software
19217 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19221 + * mount options/flags
19224 +#include <linux/namei.h>
19225 +#include <linux/types.h> /* a distribution requires */
19226 +#include <linux/parser.h>
19229 +/* ---------------------------------------------------------------------- */
19233 + Opt_add, Opt_del, Opt_mod, Opt_reorder, Opt_append, Opt_prepend,
19234 + Opt_idel, Opt_imod, Opt_ireorder,
19235 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash, Opt_rendir,
19236 + Opt_rdblk_def, Opt_rdhash_def,
19237 + Opt_xino, Opt_zxino, Opt_noxino,
19238 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
19239 + Opt_trunc_xino_path, Opt_itrunc_xino,
19240 + Opt_trunc_xib, Opt_notrunc_xib,
19241 + Opt_shwh, Opt_noshwh,
19242 + Opt_plink, Opt_noplink, Opt_list_plink,
19244 + Opt_dio, Opt_nodio,
19245 + /* Opt_lock, Opt_unlock, */
19246 + Opt_cmd, Opt_cmd_args,
19247 + Opt_diropq_a, Opt_diropq_w,
19248 + Opt_warn_perm, Opt_nowarn_perm,
19249 + Opt_wbr_copyup, Opt_wbr_create,
19250 + Opt_refrof, Opt_norefrof,
19251 + Opt_verbose, Opt_noverbose,
19252 + Opt_sum, Opt_nosum, Opt_wsum,
19253 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
19256 +static match_table_t options = {
19257 + {Opt_br, "br=%s"},
19258 + {Opt_br, "br:%s"},
19260 + {Opt_add, "add=%d:%s"},
19261 + {Opt_add, "add:%d:%s"},
19262 + {Opt_add, "ins=%d:%s"},
19263 + {Opt_add, "ins:%d:%s"},
19264 + {Opt_append, "append=%s"},
19265 + {Opt_append, "append:%s"},
19266 + {Opt_prepend, "prepend=%s"},
19267 + {Opt_prepend, "prepend:%s"},
19269 + {Opt_del, "del=%s"},
19270 + {Opt_del, "del:%s"},
19271 + /* {Opt_idel, "idel:%d"}, */
19272 + {Opt_mod, "mod=%s"},
19273 + {Opt_mod, "mod:%s"},
19274 + /* {Opt_imod, "imod:%d:%s"}, */
19276 + {Opt_dirwh, "dirwh=%d"},
19278 + {Opt_xino, "xino=%s"},
19279 + {Opt_noxino, "noxino"},
19280 + {Opt_trunc_xino, "trunc_xino"},
19281 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
19282 + {Opt_notrunc_xino, "notrunc_xino"},
19283 + {Opt_trunc_xino_path, "trunc_xino=%s"},
19284 + {Opt_itrunc_xino, "itrunc_xino=%d"},
19285 + /* {Opt_zxino, "zxino=%s"}, */
19286 + {Opt_trunc_xib, "trunc_xib"},
19287 + {Opt_notrunc_xib, "notrunc_xib"},
19289 +#ifdef CONFIG_PROC_FS
19290 + {Opt_plink, "plink"},
19292 + {Opt_ignore_silent, "plink"},
19295 + {Opt_noplink, "noplink"},
19297 +#ifdef CONFIG_AUFS_DEBUG
19298 + {Opt_list_plink, "list_plink"},
19301 + {Opt_udba, "udba=%s"},
19303 + {Opt_dio, "dio"},
19304 + {Opt_nodio, "nodio"},
19306 + {Opt_diropq_a, "diropq=always"},
19307 + {Opt_diropq_a, "diropq=a"},
19308 + {Opt_diropq_w, "diropq=whiteouted"},
19309 + {Opt_diropq_w, "diropq=w"},
19311 + {Opt_warn_perm, "warn_perm"},
19312 + {Opt_nowarn_perm, "nowarn_perm"},
19314 + /* keep them temporary */
19315 + {Opt_ignore_silent, "coo=%s"},
19316 + {Opt_ignore_silent, "nodlgt"},
19317 + {Opt_ignore_silent, "nodirperm1"},
19318 + {Opt_ignore_silent, "clean_plink"},
19320 +#ifdef CONFIG_AUFS_SHWH
19321 + {Opt_shwh, "shwh"},
19323 + {Opt_noshwh, "noshwh"},
19325 + {Opt_rendir, "rendir=%d"},
19327 + {Opt_refrof, "refrof"},
19328 + {Opt_norefrof, "norefrof"},
19330 + {Opt_verbose, "verbose"},
19331 + {Opt_verbose, "v"},
19332 + {Opt_noverbose, "noverbose"},
19333 + {Opt_noverbose, "quiet"},
19334 + {Opt_noverbose, "q"},
19335 + {Opt_noverbose, "silent"},
19337 + {Opt_sum, "sum"},
19338 + {Opt_nosum, "nosum"},
19339 + {Opt_wsum, "wsum"},
19341 + {Opt_rdcache, "rdcache=%d"},
19342 + {Opt_rdblk, "rdblk=%d"},
19343 + {Opt_rdblk_def, "rdblk=def"},
19344 + {Opt_rdhash, "rdhash=%d"},
19345 + {Opt_rdhash_def, "rdhash=def"},
19347 + {Opt_wbr_create, "create=%s"},
19348 + {Opt_wbr_create, "create_policy=%s"},
19349 + {Opt_wbr_copyup, "cpup=%s"},
19350 + {Opt_wbr_copyup, "copyup=%s"},
19351 + {Opt_wbr_copyup, "copyup_policy=%s"},
19353 + /* internal use for the scripts */
19354 + {Opt_ignore_silent, "si=%s"},
19356 + {Opt_br, "dirs=%s"},
19357 + {Opt_ignore, "debug=%d"},
19358 + {Opt_ignore, "delete=whiteout"},
19359 + {Opt_ignore, "delete=all"},
19360 + {Opt_ignore, "imap=%s"},
19362 + /* temporary workaround, due to old mount(8)? */
19363 + {Opt_ignore_silent, "relatime"},
19368 +/* ---------------------------------------------------------------------- */
19370 +static const char *au_parser_pattern(int val, struct match_token *token)
19372 + while (token->pattern) {
19373 + if (token->token == val)
19374 + return token->pattern;
19381 +/* ---------------------------------------------------------------------- */
19383 +static match_table_t brperm = {
19384 + {AuBrPerm_RO, AUFS_BRPERM_RO},
19385 + {AuBrPerm_RR, AUFS_BRPERM_RR},
19386 + {AuBrPerm_RW, AUFS_BRPERM_RW},
19390 +static match_table_t brrattr = {
19391 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
19395 +static match_table_t brwattr = {
19396 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
19400 +#define AuBrStr_LONGEST AUFS_BRPERM_RW "+" AUFS_BRWATTR_NLWH
19402 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
19409 + p = strchr(str, '+');
19412 + v = match_token(str, table, args);
19418 + pr_warn("ignored branch attribute %s\n", str);
19428 +static int noinline_for_stack br_perm_val(char *perm)
19432 + substring_t args[MAX_OPT_ARGS];
19434 + p = strchr(perm, '+');
19437 + val = match_token(perm, brperm, args);
19441 + pr_warn("ignored branch permission %s\n", perm);
19442 + val = AuBrPerm_RO;
19449 + case AuBrPerm_RO:
19450 + case AuBrPerm_RR:
19451 + val |= br_attr_val(p + 1, brrattr, args);
19453 + case AuBrPerm_RW:
19454 + val |= br_attr_val(p + 1, brwattr, args);
19462 +/* Caller should free the return value */
19463 +char *au_optstr_br_perm(int brperm)
19465 + char *p, a[sizeof(AuBrStr_LONGEST)];
19468 +#define SetPerm(str) do { \
19469 + sz = sizeof(str); \
19470 + memcpy(a, str, sz); \
19471 + p = a + sz - 1; \
19474 +#define AppendAttr(flag, str) do { \
19475 + if (brperm & flag) { \
19476 + sz = sizeof(str); \
19478 + memcpy(p, str, sz); \
19483 + switch (brperm & AuBrPerm_Mask) {
19484 + case AuBrPerm_RO:
19485 + SetPerm(AUFS_BRPERM_RO);
19487 + case AuBrPerm_RR:
19488 + SetPerm(AUFS_BRPERM_RR);
19490 + case AuBrPerm_RW:
19491 + SetPerm(AUFS_BRPERM_RW);
19497 + AppendAttr(AuBrRAttr_WH, AUFS_BRRATTR_WH);
19498 + AppendAttr(AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH);
19500 + AuDebugOn(strlen(a) >= sizeof(a));
19501 + return kstrdup(a, GFP_NOFS);
19506 +/* ---------------------------------------------------------------------- */
19508 +static match_table_t udbalevel = {
19509 + {AuOpt_UDBA_REVAL, "reval"},
19510 + {AuOpt_UDBA_NONE, "none"},
19511 +#ifdef CONFIG_AUFS_HNOTIFY
19512 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
19513 +#ifdef CONFIG_AUFS_HFSNOTIFY
19514 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
19520 +static int noinline_for_stack udba_val(char *str)
19522 + substring_t args[MAX_OPT_ARGS];
19524 + return match_token(str, udbalevel, args);
19527 +const char *au_optstr_udba(int udba)
19529 + return au_parser_pattern(udba, (void *)udbalevel);
19532 +/* ---------------------------------------------------------------------- */
19534 +static match_table_t au_wbr_create_policy = {
19535 + {AuWbrCreate_TDP, "tdp"},
19536 + {AuWbrCreate_TDP, "top-down-parent"},
19537 + {AuWbrCreate_RR, "rr"},
19538 + {AuWbrCreate_RR, "round-robin"},
19539 + {AuWbrCreate_MFS, "mfs"},
19540 + {AuWbrCreate_MFS, "most-free-space"},
19541 + {AuWbrCreate_MFSV, "mfs:%d"},
19542 + {AuWbrCreate_MFSV, "most-free-space:%d"},
19544 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
19545 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
19546 + {AuWbrCreate_PMFS, "pmfs"},
19547 + {AuWbrCreate_PMFSV, "pmfs:%d"},
19553 + * cf. linux/lib/parser.c and cmdline.c
19554 + * gave up calling memparse() since it uses simple_strtoull() instead of
19557 +static int noinline_for_stack
19558 +au_match_ull(substring_t *s, unsigned long long *result)
19561 + unsigned int len;
19565 + len = s->to - s->from;
19566 + if (len + 1 <= sizeof(a)) {
19567 + memcpy(a, s->from, len);
19569 + err = kstrtoull(a, 0, result);
19574 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
19575 + struct au_opt_wbr_create *create)
19578 + unsigned long long ull;
19581 + if (!au_match_ull(arg, &ull))
19582 + create->mfsrr_watermark = ull;
19584 + pr_err("bad integer in %s\n", str);
19591 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
19592 + struct au_opt_wbr_create *create)
19597 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
19598 + create->mfs_second = n;
19600 + pr_err("bad integer in %s\n", str);
19607 +static int noinline_for_stack
19608 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
19611 + substring_t args[MAX_OPT_ARGS];
19613 + err = match_token(str, au_wbr_create_policy, args);
19614 + create->wbr_create = err;
19616 + case AuWbrCreate_MFSRRV:
19617 + e = au_wbr_mfs_wmark(&args[0], str, create);
19619 + e = au_wbr_mfs_sec(&args[1], str, create);
19623 + case AuWbrCreate_MFSRR:
19624 + e = au_wbr_mfs_wmark(&args[0], str, create);
19625 + if (unlikely(e)) {
19630 + case AuWbrCreate_MFS:
19631 + case AuWbrCreate_PMFS:
19632 + create->mfs_second = AUFS_MFS_DEF_SEC;
19634 + case AuWbrCreate_MFSV:
19635 + case AuWbrCreate_PMFSV:
19636 + e = au_wbr_mfs_sec(&args[0], str, create);
19645 +const char *au_optstr_wbr_create(int wbr_create)
19647 + return au_parser_pattern(wbr_create, (void *)au_wbr_create_policy);
19650 +static match_table_t au_wbr_copyup_policy = {
19651 + {AuWbrCopyup_TDP, "tdp"},
19652 + {AuWbrCopyup_TDP, "top-down-parent"},
19653 + {AuWbrCopyup_BUP, "bup"},
19654 + {AuWbrCopyup_BUP, "bottom-up-parent"},
19655 + {AuWbrCopyup_BU, "bu"},
19656 + {AuWbrCopyup_BU, "bottom-up"},
19660 +static int noinline_for_stack au_wbr_copyup_val(char *str)
19662 + substring_t args[MAX_OPT_ARGS];
19664 + return match_token(str, au_wbr_copyup_policy, args);
19667 +const char *au_optstr_wbr_copyup(int wbr_copyup)
19669 + return au_parser_pattern(wbr_copyup, (void *)au_wbr_copyup_policy);
19672 +/* ---------------------------------------------------------------------- */
19674 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
19676 +static void dump_opts(struct au_opts *opts)
19678 +#ifdef CONFIG_AUFS_DEBUG
19679 + /* reduce stack space */
19681 + struct au_opt_add *add;
19682 + struct au_opt_del *del;
19683 + struct au_opt_mod *mod;
19684 + struct au_opt_xino *xino;
19685 + struct au_opt_xino_itrunc *xino_itrunc;
19686 + struct au_opt_wbr_create *create;
19688 + struct au_opt *opt;
19691 + while (opt->type != Opt_tail) {
19692 + switch (opt->type) {
19694 + u.add = &opt->add;
19695 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
19696 + u.add->bindex, u.add->pathname, u.add->perm,
19697 + u.add->path.dentry);
19701 + u.del = &opt->del;
19702 + AuDbg("del {%s, %p}\n",
19703 + u.del->pathname, u.del->h_path.dentry);
19707 + u.mod = &opt->mod;
19708 + AuDbg("mod {%s, 0x%x, %p}\n",
19709 + u.mod->path, u.mod->perm, u.mod->h_root);
19712 + u.add = &opt->add;
19713 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
19714 + u.add->bindex, u.add->pathname, u.add->perm,
19715 + u.add->path.dentry);
19717 + case Opt_prepend:
19718 + u.add = &opt->add;
19719 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
19720 + u.add->bindex, u.add->pathname, u.add->perm,
19721 + u.add->path.dentry);
19724 + AuDbg("dirwh %d\n", opt->dirwh);
19726 + case Opt_rdcache:
19727 + AuDbg("rdcache %d\n", opt->rdcache);
19730 + AuDbg("rdblk %u\n", opt->rdblk);
19732 + case Opt_rdblk_def:
19733 + AuDbg("rdblk_def\n");
19736 + AuDbg("rdhash %u\n", opt->rdhash);
19738 + case Opt_rdhash_def:
19739 + AuDbg("rdhash_def\n");
19742 + u.xino = &opt->xino;
19743 + AuDbg("xino {%s %.*s}\n",
19745 + AuDLNPair(u.xino->file->f_dentry));
19747 + case Opt_trunc_xino:
19748 + AuLabel(trunc_xino);
19750 + case Opt_notrunc_xino:
19751 + AuLabel(notrunc_xino);
19753 + case Opt_trunc_xino_path:
19754 + case Opt_itrunc_xino:
19755 + u.xino_itrunc = &opt->xino_itrunc;
19756 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
19762 + case Opt_trunc_xib:
19763 + AuLabel(trunc_xib);
19765 + case Opt_notrunc_xib:
19766 + AuLabel(notrunc_xib);
19777 + case Opt_noplink:
19778 + AuLabel(noplink);
19780 + case Opt_list_plink:
19781 + AuLabel(list_plink);
19784 + AuDbg("udba %d, %s\n",
19785 + opt->udba, au_optstr_udba(opt->udba));
19793 + case Opt_diropq_a:
19794 + AuLabel(diropq_a);
19796 + case Opt_diropq_w:
19797 + AuLabel(diropq_w);
19799 + case Opt_warn_perm:
19800 + AuLabel(warn_perm);
19802 + case Opt_nowarn_perm:
19803 + AuLabel(nowarn_perm);
19808 + case Opt_norefrof:
19809 + AuLabel(norefrof);
19811 + case Opt_verbose:
19812 + AuLabel(verbose);
19814 + case Opt_noverbose:
19815 + AuLabel(noverbose);
19826 + case Opt_wbr_create:
19827 + u.create = &opt->wbr_create;
19828 + AuDbg("create %d, %s\n", u.create->wbr_create,
19829 + au_optstr_wbr_create(u.create->wbr_create));
19830 + switch (u.create->wbr_create) {
19831 + case AuWbrCreate_MFSV:
19832 + case AuWbrCreate_PMFSV:
19833 + AuDbg("%d sec\n", u.create->mfs_second);
19835 + case AuWbrCreate_MFSRR:
19836 + AuDbg("%llu watermark\n",
19837 + u.create->mfsrr_watermark);
19839 + case AuWbrCreate_MFSRRV:
19840 + AuDbg("%llu watermark, %d sec\n",
19841 + u.create->mfsrr_watermark,
19842 + u.create->mfs_second);
19846 + case Opt_wbr_copyup:
19847 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
19848 + au_optstr_wbr_copyup(opt->wbr_copyup));
19858 +void au_opts_free(struct au_opts *opts)
19860 + struct au_opt *opt;
19863 + while (opt->type != Opt_tail) {
19864 + switch (opt->type) {
19867 + case Opt_prepend:
19868 + path_put(&opt->add.path);
19872 + path_put(&opt->del.h_path);
19876 + dput(opt->mod.h_root);
19879 + fput(opt->xino.file);
19886 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
19887 + aufs_bindex_t bindex)
19890 + struct au_opt_add *add = &opt->add;
19893 + add->bindex = bindex;
19894 + add->perm = AuBrPerm_RO;
19895 + add->pathname = opt_str;
19896 + p = strchr(opt_str, '=');
19900 + add->perm = br_perm_val(p);
19903 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
19906 + add->perm = AuBrPerm_RO;
19907 + if (au_test_fs_rr(add->path.dentry->d_sb))
19908 + add->perm = AuBrPerm_RR;
19909 + else if (!bindex && !(sb_flags & MS_RDONLY))
19910 + add->perm = AuBrPerm_RW;
19912 + opt->type = Opt_add;
19915 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
19922 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
19926 + del->pathname = args[0].from;
19927 + AuDbg("del path %s\n", del->pathname);
19929 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
19930 + if (unlikely(err))
19931 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
19936 +#if 0 /* reserved for future use */
19937 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
19938 + struct au_opt_del *del, substring_t args[])
19941 + struct dentry *root;
19944 + root = sb->s_root;
19945 + aufs_read_lock(root, AuLock_FLUSH);
19946 + if (bindex < 0 || au_sbend(sb) < bindex) {
19947 + pr_err("out of bounds, %d\n", bindex);
19952 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
19953 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
19956 + aufs_read_unlock(root, !AuLock_IR);
19961 +static int noinline_for_stack
19962 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
19965 + struct path path;
19969 + mod->path = args[0].from;
19970 + p = strchr(mod->path, '=');
19971 + if (unlikely(!p)) {
19972 + pr_err("no permssion %s\n", args[0].from);
19977 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
19978 + if (unlikely(err)) {
19979 + pr_err("lookup failed %s (%d)\n", mod->path, err);
19983 + mod->perm = br_perm_val(p);
19984 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
19985 + mod->h_root = dget(path.dentry);
19992 +#if 0 /* reserved for future use */
19993 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
19994 + struct au_opt_mod *mod, substring_t args[])
19997 + struct dentry *root;
20000 + root = sb->s_root;
20001 + aufs_read_lock(root, AuLock_FLUSH);
20002 + if (bindex < 0 || au_sbend(sb) < bindex) {
20003 + pr_err("out of bounds, %d\n", bindex);
20008 + mod->perm = br_perm_val(args[1].from);
20009 + AuDbg("mod path %s, perm 0x%x, %s\n",
20010 + mod->path, mod->perm, args[1].from);
20011 + mod->h_root = dget(au_h_dptr(root, bindex));
20014 + aufs_read_unlock(root, !AuLock_IR);
20019 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
20020 + substring_t args[])
20023 + struct file *file;
20025 + file = au_xino_create(sb, args[0].from, /*silent*/0);
20026 + err = PTR_ERR(file);
20027 + if (IS_ERR(file))
20031 + if (unlikely(file->f_dentry->d_sb == sb)) {
20033 + pr_err("%s must be outside\n", args[0].from);
20038 + xino->file = file;
20039 + xino->path = args[0].from;
20045 +static int noinline_for_stack
20046 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
20047 + struct au_opt_xino_itrunc *xino_itrunc,
20048 + substring_t args[])
20051 + aufs_bindex_t bend, bindex;
20052 + struct path path;
20053 + struct dentry *root;
20055 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
20056 + if (unlikely(err)) {
20057 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
20061 + xino_itrunc->bindex = -1;
20062 + root = sb->s_root;
20063 + aufs_read_lock(root, AuLock_FLUSH);
20064 + bend = au_sbend(sb);
20065 + for (bindex = 0; bindex <= bend; bindex++) {
20066 + if (au_h_dptr(root, bindex) == path.dentry) {
20067 + xino_itrunc->bindex = bindex;
20071 + aufs_read_unlock(root, !AuLock_IR);
20074 + if (unlikely(xino_itrunc->bindex < 0)) {
20075 + pr_err("no such branch %s\n", args[0].from);
20083 +/* called without aufs lock */
20084 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
20086 + int err, n, token;
20087 + aufs_bindex_t bindex;
20088 + unsigned char skipped;
20089 + struct dentry *root;
20090 + struct au_opt *opt, *opt_tail;
20092 + /* reduce the stack space */
20094 + struct au_opt_xino_itrunc *xino_itrunc;
20095 + struct au_opt_wbr_create *create;
20098 + substring_t args[MAX_OPT_ARGS];
20102 + a = kmalloc(sizeof(*a), GFP_NOFS);
20103 + if (unlikely(!a))
20106 + root = sb->s_root;
20110 + opt_tail = opt + opts->max_opt - 1;
20111 + opt->type = Opt_tail;
20112 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
20115 + token = match_token(opt_str, options, a->args);
20119 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
20121 + err = opt_add(opt, opt_str, opts->sb_flags,
20123 + if (unlikely(!err && ++opt > opt_tail)) {
20127 + opt->type = Opt_tail;
20132 + if (unlikely(match_int(&a->args[0], &n))) {
20133 + pr_err("bad integer in %s\n", opt_str);
20137 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
20140 + opt->type = token;
20143 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
20144 + /*dummy bindex*/1);
20146 + opt->type = token;
20148 + case Opt_prepend:
20149 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
20152 + opt->type = token;
20155 + err = au_opts_parse_del(&opt->del, a->args);
20157 + opt->type = token;
20159 +#if 0 /* reserved for future use */
20161 + del->pathname = "(indexed)";
20162 + if (unlikely(match_int(&args[0], &n))) {
20163 + pr_err("bad integer in %s\n", opt_str);
20166 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
20168 + opt->type = token;
20172 + err = au_opts_parse_mod(&opt->mod, a->args);
20174 + opt->type = token;
20176 +#ifdef IMOD /* reserved for future use */
20178 + u.mod->path = "(indexed)";
20179 + if (unlikely(match_int(&a->args[0], &n))) {
20180 + pr_err("bad integer in %s\n", opt_str);
20183 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
20185 + opt->type = token;
20189 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
20191 + opt->type = token;
20194 + case Opt_trunc_xino_path:
20195 + err = au_opts_parse_xino_itrunc_path
20196 + (sb, &opt->xino_itrunc, a->args);
20198 + opt->type = token;
20201 + case Opt_itrunc_xino:
20202 + u.xino_itrunc = &opt->xino_itrunc;
20203 + if (unlikely(match_int(&a->args[0], &n))) {
20204 + pr_err("bad integer in %s\n", opt_str);
20207 + u.xino_itrunc->bindex = n;
20208 + aufs_read_lock(root, AuLock_FLUSH);
20209 + if (n < 0 || au_sbend(sb) < n) {
20210 + pr_err("out of bounds, %d\n", n);
20211 + aufs_read_unlock(root, !AuLock_IR);
20214 + aufs_read_unlock(root, !AuLock_IR);
20216 + opt->type = token;
20220 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
20223 + opt->type = token;
20226 + case Opt_rdcache:
20227 + if (unlikely(match_int(&a->args[0], &n))) {
20228 + pr_err("bad integer in %s\n", opt_str);
20231 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
20232 + pr_err("rdcache must be smaller than %d\n",
20233 + AUFS_RDCACHE_MAX);
20236 + opt->rdcache = n;
20238 + opt->type = token;
20241 + if (unlikely(match_int(&a->args[0], &n)
20243 + || n > KMALLOC_MAX_SIZE)) {
20244 + pr_err("bad integer in %s\n", opt_str);
20247 + if (unlikely(n && n < NAME_MAX)) {
20248 + pr_err("rdblk must be larger than %d\n",
20254 + opt->type = token;
20257 + if (unlikely(match_int(&a->args[0], &n)
20259 + || n * sizeof(struct hlist_head)
20260 + > KMALLOC_MAX_SIZE)) {
20261 + pr_err("bad integer in %s\n", opt_str);
20266 + opt->type = token;
20269 + case Opt_trunc_xino:
20270 + case Opt_notrunc_xino:
20272 + case Opt_trunc_xib:
20273 + case Opt_notrunc_xib:
20277 + case Opt_noplink:
20278 + case Opt_list_plink:
20281 + case Opt_diropq_a:
20282 + case Opt_diropq_w:
20283 + case Opt_warn_perm:
20284 + case Opt_nowarn_perm:
20286 + case Opt_norefrof:
20287 + case Opt_verbose:
20288 + case Opt_noverbose:
20292 + case Opt_rdblk_def:
20293 + case Opt_rdhash_def:
20295 + opt->type = token;
20299 + opt->udba = udba_val(a->args[0].from);
20300 + if (opt->udba >= 0) {
20302 + opt->type = token;
20304 + pr_err("wrong value, %s\n", opt_str);
20307 + case Opt_wbr_create:
20308 + u.create = &opt->wbr_create;
20309 + u.create->wbr_create
20310 + = au_wbr_create_val(a->args[0].from, u.create);
20311 + if (u.create->wbr_create >= 0) {
20313 + opt->type = token;
20315 + pr_err("wrong value, %s\n", opt_str);
20317 + case Opt_wbr_copyup:
20318 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
20319 + if (opt->wbr_copyup >= 0) {
20321 + opt->type = token;
20323 + pr_err("wrong value, %s\n", opt_str);
20327 + pr_warn("ignored %s\n", opt_str);
20329 + case Opt_ignore_silent:
20334 + pr_err("unknown option %s\n", opt_str);
20338 + if (!err && !skipped) {
20339 + if (unlikely(++opt > opt_tail)) {
20342 + opt->type = Opt_tail;
20345 + opt->type = Opt_tail;
20351 + if (unlikely(err))
20352 + au_opts_free(opts);
20358 +static int au_opt_wbr_create(struct super_block *sb,
20359 + struct au_opt_wbr_create *create)
20362 + struct au_sbinfo *sbinfo;
20364 + SiMustWriteLock(sb);
20366 + err = 1; /* handled */
20367 + sbinfo = au_sbi(sb);
20368 + if (sbinfo->si_wbr_create_ops->fin) {
20369 + err = sbinfo->si_wbr_create_ops->fin(sb);
20374 + sbinfo->si_wbr_create = create->wbr_create;
20375 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
20376 + switch (create->wbr_create) {
20377 + case AuWbrCreate_MFSRRV:
20378 + case AuWbrCreate_MFSRR:
20379 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
20381 + case AuWbrCreate_MFS:
20382 + case AuWbrCreate_MFSV:
20383 + case AuWbrCreate_PMFS:
20384 + case AuWbrCreate_PMFSV:
20385 + sbinfo->si_wbr_mfs.mfs_expire
20386 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
20390 + if (sbinfo->si_wbr_create_ops->init)
20391 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
20398 + * plus: processed without an error
20399 + * zero: unprocessed
20401 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
20402 + struct au_opts *opts)
20405 + struct au_sbinfo *sbinfo;
20407 + SiMustWriteLock(sb);
20409 + err = 1; /* handled */
20410 + sbinfo = au_sbi(sb);
20411 + switch (opt->type) {
20413 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
20414 + sbinfo->si_mntflags |= opt->udba;
20415 + opts->given_udba |= opt->udba;
20419 + au_opt_set(sbinfo->si_mntflags, PLINK);
20421 + case Opt_noplink:
20422 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
20423 + au_plink_put(sb, /*verbose*/1);
20424 + au_opt_clr(sbinfo->si_mntflags, PLINK);
20426 + case Opt_list_plink:
20427 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
20428 + au_plink_list(sb);
20432 + au_opt_set(sbinfo->si_mntflags, DIO);
20433 + au_fset_opts(opts->flags, REFRESH_DYAOP);
20436 + au_opt_clr(sbinfo->si_mntflags, DIO);
20437 + au_fset_opts(opts->flags, REFRESH_DYAOP);
20440 + case Opt_diropq_a:
20441 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
20443 + case Opt_diropq_w:
20444 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
20447 + case Opt_warn_perm:
20448 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
20450 + case Opt_nowarn_perm:
20451 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
20455 + au_opt_set(sbinfo->si_mntflags, REFROF);
20457 + case Opt_norefrof:
20458 + au_opt_clr(sbinfo->si_mntflags, REFROF);
20461 + case Opt_verbose:
20462 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
20464 + case Opt_noverbose:
20465 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
20469 + au_opt_set(sbinfo->si_mntflags, SUM);
20472 + au_opt_clr(sbinfo->si_mntflags, SUM);
20473 + au_opt_set(sbinfo->si_mntflags, SUM_W);
20475 + au_opt_clr(sbinfo->si_mntflags, SUM);
20476 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
20479 + case Opt_wbr_create:
20480 + err = au_opt_wbr_create(sb, &opt->wbr_create);
20482 + case Opt_wbr_copyup:
20483 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
20484 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
20488 + sbinfo->si_dirwh = opt->dirwh;
20491 + case Opt_rdcache:
20492 + sbinfo->si_rdcache
20493 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
20496 + sbinfo->si_rdblk = opt->rdblk;
20498 + case Opt_rdblk_def:
20499 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
20502 + sbinfo->si_rdhash = opt->rdhash;
20504 + case Opt_rdhash_def:
20505 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
20509 + au_opt_set(sbinfo->si_mntflags, SHWH);
20512 + au_opt_clr(sbinfo->si_mntflags, SHWH);
20515 + case Opt_trunc_xino:
20516 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
20518 + case Opt_notrunc_xino:
20519 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
20522 + case Opt_trunc_xino_path:
20523 + case Opt_itrunc_xino:
20524 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
20529 + case Opt_trunc_xib:
20530 + au_fset_opts(opts->flags, TRUNC_XIB);
20532 + case Opt_notrunc_xib:
20533 + au_fclr_opts(opts->flags, TRUNC_XIB);
20545 + * returns tri-state.
20546 + * plus: processed without an error
20547 + * zero: unprocessed
20550 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
20551 + struct au_opts *opts)
20553 + int err, do_refresh;
20556 + switch (opt->type) {
20558 + opt->add.bindex = au_sbend(sb) + 1;
20559 + if (opt->add.bindex < 0)
20560 + opt->add.bindex = 0;
20562 + case Opt_prepend:
20563 + opt->add.bindex = 0;
20566 + err = au_br_add(sb, &opt->add,
20567 + au_ftest_opts(opts->flags, REMOUNT));
20570 + au_fset_opts(opts->flags, REFRESH);
20576 + err = au_br_del(sb, &opt->del,
20577 + au_ftest_opts(opts->flags, REMOUNT));
20580 + au_fset_opts(opts->flags, TRUNC_XIB);
20581 + au_fset_opts(opts->flags, REFRESH);
20587 + err = au_br_mod(sb, &opt->mod,
20588 + au_ftest_opts(opts->flags, REMOUNT),
20593 + au_fset_opts(opts->flags, REFRESH);
20601 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
20602 + struct au_opt_xino **opt_xino,
20603 + struct au_opts *opts)
20606 + aufs_bindex_t bend, bindex;
20607 + struct dentry *root, *parent, *h_root;
20610 + switch (opt->type) {
20612 + err = au_xino_set(sb, &opt->xino,
20613 + !!au_ftest_opts(opts->flags, REMOUNT));
20614 + if (unlikely(err))
20617 + *opt_xino = &opt->xino;
20618 + au_xino_brid_set(sb, -1);
20620 + /* safe d_parent access */
20621 + parent = opt->xino.file->f_dentry->d_parent;
20622 + root = sb->s_root;
20623 + bend = au_sbend(sb);
20624 + for (bindex = 0; bindex <= bend; bindex++) {
20625 + h_root = au_h_dptr(root, bindex);
20626 + if (h_root == parent) {
20627 + au_xino_brid_set(sb, au_sbr_id(sb, bindex));
20635 + au_xino_brid_set(sb, -1);
20636 + *opt_xino = (void *)-1;
20643 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
20644 + unsigned int pending)
20647 + aufs_bindex_t bindex, bend;
20648 + unsigned char do_plink, skip, do_free;
20649 + struct au_branch *br;
20650 + struct au_wbr *wbr;
20651 + struct dentry *root;
20652 + struct inode *dir, *h_dir;
20653 + struct au_sbinfo *sbinfo;
20654 + struct au_hinode *hdir;
20656 + SiMustAnyLock(sb);
20658 + sbinfo = au_sbi(sb);
20659 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
20661 + if (!(sb_flags & MS_RDONLY)) {
20662 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
20663 + pr_warn("first branch should be rw\n");
20664 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
20665 + pr_warn("shwh should be used with ro\n");
20668 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
20669 + && !au_opt_test(sbinfo->si_mntflags, XINO))
20670 + pr_warn("udba=*notify requires xino\n");
20673 + root = sb->s_root;
20674 + dir = root->d_inode;
20675 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
20676 + bend = au_sbend(sb);
20677 + for (bindex = 0; !err && bindex <= bend; bindex++) {
20679 + h_dir = au_h_iptr(dir, bindex);
20680 + br = au_sbr(sb, bindex);
20683 + wbr = br->br_wbr;
20685 + wbr_wh_read_lock(wbr);
20687 + if (!au_br_writable(br->br_perm)) {
20690 + || (!wbr->wbr_whbase
20691 + && !wbr->wbr_plink
20692 + && !wbr->wbr_orph));
20693 + } else if (!au_br_wh_linkable(br->br_perm)) {
20694 + /* skip = (!br->br_whbase && !br->br_orph); */
20695 + skip = (!wbr || !wbr->wbr_whbase);
20696 + if (skip && wbr) {
20698 + skip = !!wbr->wbr_plink;
20700 + skip = !wbr->wbr_plink;
20703 + /* skip = (br->br_whbase && br->br_ohph); */
20704 + skip = (wbr && wbr->wbr_whbase);
20707 + skip = !!wbr->wbr_plink;
20709 + skip = !wbr->wbr_plink;
20713 + wbr_wh_read_unlock(wbr);
20718 + hdir = au_hi(dir, bindex);
20719 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
20721 + wbr_wh_write_lock(wbr);
20722 + err = au_wh_init(au_h_dptr(root, bindex), br, sb);
20724 + wbr_wh_write_unlock(wbr);
20725 + au_hn_imtx_unlock(hdir);
20727 + if (!err && do_free) {
20729 + br->br_wbr = NULL;
20736 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
20739 + unsigned int tmp;
20740 + aufs_bindex_t bindex, bend;
20741 + struct au_opt *opt;
20742 + struct au_opt_xino *opt_xino, xino;
20743 + struct au_sbinfo *sbinfo;
20744 + struct au_branch *br;
20746 + SiMustWriteLock(sb);
20751 + while (err >= 0 && opt->type != Opt_tail)
20752 + err = au_opt_simple(sb, opt++, opts);
20755 + else if (unlikely(err < 0))
20758 + /* disable xino and udba temporary */
20759 + sbinfo = au_sbi(sb);
20760 + tmp = sbinfo->si_mntflags;
20761 + au_opt_clr(sbinfo->si_mntflags, XINO);
20762 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
20765 + while (err >= 0 && opt->type != Opt_tail)
20766 + err = au_opt_br(sb, opt++, opts);
20769 + else if (unlikely(err < 0))
20772 + bend = au_sbend(sb);
20773 + if (unlikely(bend < 0)) {
20775 + pr_err("no branches\n");
20779 + if (au_opt_test(tmp, XINO))
20780 + au_opt_set(sbinfo->si_mntflags, XINO);
20782 + while (!err && opt->type != Opt_tail)
20783 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
20784 + if (unlikely(err))
20787 + err = au_opts_verify(sb, sb->s_flags, tmp);
20788 + if (unlikely(err))
20791 + /* restore xino */
20792 + if (au_opt_test(tmp, XINO) && !opt_xino) {
20793 + xino.file = au_xino_def(sb);
20794 + err = PTR_ERR(xino.file);
20795 + if (IS_ERR(xino.file))
20798 + err = au_xino_set(sb, &xino, /*remount*/0);
20800 + if (unlikely(err))
20804 + /* restore udba */
20805 + tmp &= AuOptMask_UDBA;
20806 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
20807 + sbinfo->si_mntflags |= tmp;
20808 + bend = au_sbend(sb);
20809 + for (bindex = 0; bindex <= bend; bindex++) {
20810 + br = au_sbr(sb, bindex);
20811 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
20812 + if (unlikely(err))
20813 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
20815 + /* go on even if err */
20817 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
20818 + struct inode *dir = sb->s_root->d_inode;
20819 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
20826 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
20829 + struct inode *dir;
20830 + struct au_opt_xino *opt_xino;
20831 + struct au_opt *opt;
20832 + struct au_sbinfo *sbinfo;
20834 + SiMustWriteLock(sb);
20836 + dir = sb->s_root->d_inode;
20837 + sbinfo = au_sbi(sb);
20841 + while (err >= 0 && opt->type != Opt_tail) {
20842 + err = au_opt_simple(sb, opt, opts);
20844 + err = au_opt_br(sb, opt, opts);
20846 + err = au_opt_xino(sb, opt, &opt_xino, opts);
20852 + /* go on even err */
20854 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
20855 + if (unlikely(rerr && !err))
20858 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
20859 + rerr = au_xib_trunc(sb);
20860 + if (unlikely(rerr && !err))
20864 + /* will be handled by the caller */
20865 + if (!au_ftest_opts(opts->flags, REFRESH)
20866 + && (opts->given_udba || au_opt_test(sbinfo->si_mntflags, XINO)))
20867 + au_fset_opts(opts->flags, REFRESH);
20869 + AuDbg("status 0x%x\n", opts->flags);
20873 +/* ---------------------------------------------------------------------- */
20875 +unsigned int au_opt_udba(struct super_block *sb)
20877 + return au_mntflags(sb) & AuOptMask_UDBA;
20879 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
20880 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
20881 +++ linux/fs/aufs/opts.h 2012-07-22 19:57:03.164337936 +0200
20884 + * Copyright (C) 2005-2012 Junjiro R. Okajima
20886 + * This program, aufs is free software; you can redistribute it and/or modify
20887 + * it under the terms of the GNU General Public License as published by
20888 + * the Free Software Foundation; either version 2 of the License, or
20889 + * (at your option) any later version.
20891 + * This program is distributed in the hope that it will be useful,
20892 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20893 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20894 + * GNU General Public License for more details.
20896 + * You should have received a copy of the GNU General Public License
20897 + * along with this program; if not, write to the Free Software
20898 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20902 + * mount options/flags
20905 +#ifndef __AUFS_OPTS_H__
20906 +#define __AUFS_OPTS_H__
20910 +#include <linux/path.h>
20913 +struct super_block;
20915 +/* ---------------------------------------------------------------------- */
20918 +#define AuOpt_XINO 1 /* external inode number bitmap
20919 + and translation table */
20920 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
20921 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
20922 +#define AuOpt_UDBA_REVAL (1 << 3)
20923 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
20924 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
20925 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
20926 +#define AuOpt_DIRPERM1 (1 << 7) /* unimplemented */
20927 +#define AuOpt_REFROF (1 << 8) /* unimplemented */
20928 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
20929 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
20930 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
20931 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
20932 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
20933 +#define AuOpt_DIO (1 << 14) /* direct io */
20935 +#ifndef CONFIG_AUFS_HNOTIFY
20936 +#undef AuOpt_UDBA_HNOTIFY
20937 +#define AuOpt_UDBA_HNOTIFY 0
20939 +#ifndef CONFIG_AUFS_SHWH
20941 +#define AuOpt_SHWH 0
20944 +#define AuOpt_Def (AuOpt_XINO \
20945 + | AuOpt_UDBA_REVAL \
20947 + /* | AuOpt_DIRPERM1 */ \
20948 + | AuOpt_WARN_PERM)
20949 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
20950 + | AuOpt_UDBA_REVAL \
20951 + | AuOpt_UDBA_HNOTIFY)
20953 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
20954 +#define au_opt_set(flags, name) do { \
20955 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
20956 + ((flags) |= AuOpt_##name); \
20958 +#define au_opt_set_udba(flags, name) do { \
20959 + (flags) &= ~AuOptMask_UDBA; \
20960 + ((flags) |= AuOpt_##name); \
20962 +#define au_opt_clr(flags, name) do { \
20963 + ((flags) &= ~AuOpt_##name); \
20966 +static inline unsigned int au_opts_plink(unsigned int mntflags)
20968 +#ifdef CONFIG_PROC_FS
20971 + return mntflags & ~AuOpt_PLINK;
20975 +/* ---------------------------------------------------------------------- */
20977 +/* policies to select one among multiple writable branches */
20979 + AuWbrCreate_TDP, /* top down parent */
20980 + AuWbrCreate_RR, /* round robin */
20981 + AuWbrCreate_MFS, /* most free space */
20982 + AuWbrCreate_MFSV, /* mfs with seconds */
20983 + AuWbrCreate_MFSRR, /* mfs then rr */
20984 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
20985 + AuWbrCreate_PMFS, /* parent and mfs */
20986 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
20988 + AuWbrCreate_Def = AuWbrCreate_TDP
20992 + AuWbrCopyup_TDP, /* top down parent */
20993 + AuWbrCopyup_BUP, /* bottom up parent */
20994 + AuWbrCopyup_BU, /* bottom up */
20996 + AuWbrCopyup_Def = AuWbrCopyup_TDP
20999 +/* ---------------------------------------------------------------------- */
21001 +struct au_opt_add {
21002 + aufs_bindex_t bindex;
21005 + struct path path;
21008 +struct au_opt_del {
21010 + struct path h_path;
21013 +struct au_opt_mod {
21016 + struct dentry *h_root;
21019 +struct au_opt_xino {
21021 + struct file *file;
21024 +struct au_opt_xino_itrunc {
21025 + aufs_bindex_t bindex;
21028 +struct au_opt_wbr_create {
21031 + unsigned long long mfsrr_watermark;
21037 + struct au_opt_xino xino;
21038 + struct au_opt_xino_itrunc xino_itrunc;
21039 + struct au_opt_add add;
21040 + struct au_opt_del del;
21041 + struct au_opt_mod mod;
21044 + unsigned int rdblk;
21045 + unsigned int rdhash;
21047 + struct au_opt_wbr_create wbr_create;
21053 +#define AuOpts_REMOUNT 1
21054 +#define AuOpts_REFRESH (1 << 1)
21055 +#define AuOpts_TRUNC_XIB (1 << 2)
21056 +#define AuOpts_REFRESH_DYAOP (1 << 3)
21057 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
21058 +#define au_fset_opts(flags, name) \
21059 + do { (flags) |= AuOpts_##name; } while (0)
21060 +#define au_fclr_opts(flags, name) \
21061 + do { (flags) &= ~AuOpts_##name; } while (0)
21064 + struct au_opt *opt;
21067 + unsigned int given_udba;
21068 + unsigned int flags;
21069 + unsigned long sb_flags;
21072 +/* ---------------------------------------------------------------------- */
21074 +char *au_optstr_br_perm(int brperm);
21075 +const char *au_optstr_udba(int udba);
21076 +const char *au_optstr_wbr_copyup(int wbr_copyup);
21077 +const char *au_optstr_wbr_create(int wbr_create);
21079 +void au_opts_free(struct au_opts *opts);
21080 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
21081 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
21082 + unsigned int pending);
21083 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
21084 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
21086 +unsigned int au_opt_udba(struct super_block *sb);
21088 +/* ---------------------------------------------------------------------- */
21090 +#endif /* __KERNEL__ */
21091 +#endif /* __AUFS_OPTS_H__ */
21092 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
21093 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
21094 +++ linux/fs/aufs/plink.c 2012-07-22 19:57:03.164337936 +0200
21097 + * Copyright (C) 2005-2012 Junjiro R. Okajima
21099 + * This program, aufs is free software; you can redistribute it and/or modify
21100 + * it under the terms of the GNU General Public License as published by
21101 + * the Free Software Foundation; either version 2 of the License, or
21102 + * (at your option) any later version.
21104 + * This program is distributed in the hope that it will be useful,
21105 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21106 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21107 + * GNU General Public License for more details.
21109 + * You should have received a copy of the GNU General Public License
21110 + * along with this program; if not, write to the Free Software
21111 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21121 + * the pseudo-link maintenance mode.
21122 + * during a user process maintains the pseudo-links,
21123 + * prohibit adding a new plink and branch manipulation.
21127 + * For entry functions which will handle plink, and i_mutex is already held
21129 + * They cannot wait and should return an error at once.
21130 + * Callers has to check the error.
21132 + * For entry functions which will handle plink, but i_mutex is not held
21134 + * They can wait the plink maintenance mode to finish.
21136 + * They behave like F_SETLK and F_SETLKW.
21137 + * If the caller never handle plink, then both flags are unnecessary.
21140 +int au_plink_maint(struct super_block *sb, int flags)
21144 + struct au_sbinfo *sbi;
21146 + SiMustAnyLock(sb);
21149 + if (!au_opt_test(au_mntflags(sb), PLINK))
21152 + sbi = au_sbi(sb);
21153 + pid = sbi->si_plink_maint_pid;
21154 + if (!pid || pid == current->pid)
21157 + /* todo: it highly depends upon /sbin/mount.aufs */
21159 + ppid = task_pid_vnr(rcu_dereference(current->real_parent));
21160 + rcu_read_unlock();
21164 + if (au_ftest_lock(flags, NOPLMW)) {
21165 + /* if there is no i_mutex lock in VFS, we don't need to wait */
21166 + /* AuDebugOn(!lockdep_depth(current)); */
21167 + while (sbi->si_plink_maint_pid) {
21168 + si_read_unlock(sb);
21169 + /* gave up wake_up_bit() */
21170 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
21172 + if (au_ftest_lock(flags, FLUSH))
21173 + au_nwt_flush(&sbi->si_nowait);
21174 + si_noflush_read_lock(sb);
21176 + } else if (au_ftest_lock(flags, NOPLM)) {
21177 + AuDbg("ppid %d, pid %d\n", ppid, pid);
21185 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
21187 + spin_lock(&sbinfo->si_plink_maint_lock);
21188 + sbinfo->si_plink_maint_pid = 0;
21189 + spin_unlock(&sbinfo->si_plink_maint_lock);
21190 + wake_up_all(&sbinfo->si_plink_wq);
21193 +int au_plink_maint_enter(struct super_block *sb)
21196 + struct au_sbinfo *sbinfo;
21199 + sbinfo = au_sbi(sb);
21200 + /* make sure i am the only one in this fs */
21201 + si_write_lock(sb, AuLock_FLUSH);
21202 + if (au_opt_test(au_mntflags(sb), PLINK)) {
21203 + spin_lock(&sbinfo->si_plink_maint_lock);
21204 + if (!sbinfo->si_plink_maint_pid)
21205 + sbinfo->si_plink_maint_pid = current->pid;
21208 + spin_unlock(&sbinfo->si_plink_maint_lock);
21210 + si_write_unlock(sb);
21215 +/* ---------------------------------------------------------------------- */
21217 +struct pseudo_link {
21219 + struct list_head list;
21220 + struct rcu_head rcu;
21222 + struct inode *inode;
21225 +#ifdef CONFIG_AUFS_DEBUG
21226 +void au_plink_list(struct super_block *sb)
21228 + struct au_sbinfo *sbinfo;
21229 + struct list_head *plink_list;
21230 + struct pseudo_link *plink;
21232 + SiMustAnyLock(sb);
21234 + sbinfo = au_sbi(sb);
21235 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
21236 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
21238 + plink_list = &sbinfo->si_plink.head;
21240 + list_for_each_entry_rcu(plink, plink_list, list)
21241 + AuDbg("%lu\n", plink->inode->i_ino);
21242 + rcu_read_unlock();
21246 +/* is the inode pseudo-linked? */
21247 +int au_plink_test(struct inode *inode)
21250 + struct au_sbinfo *sbinfo;
21251 + struct list_head *plink_list;
21252 + struct pseudo_link *plink;
21254 + sbinfo = au_sbi(inode->i_sb);
21255 + AuRwMustAnyLock(&sbinfo->si_rwsem);
21256 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
21257 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
21260 + plink_list = &sbinfo->si_plink.head;
21262 + list_for_each_entry_rcu(plink, plink_list, list)
21263 + if (plink->inode == inode) {
21267 + rcu_read_unlock();
21271 +/* ---------------------------------------------------------------------- */
21274 + * generate a name for plink.
21275 + * the file will be stored under AUFS_WH_PLINKDIR.
21277 +/* 20 is max digits length of ulong 64 */
21278 +#define PLINK_NAME_LEN ((20 + 1) * 2)
21280 +static int plink_name(char *name, int len, struct inode *inode,
21281 + aufs_bindex_t bindex)
21284 + struct inode *h_inode;
21286 + h_inode = au_h_iptr(inode, bindex);
21287 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
21291 +struct au_do_plink_lkup_args {
21292 + struct dentry **errp;
21293 + struct qstr *tgtname;
21294 + struct dentry *h_parent;
21295 + struct au_branch *br;
21298 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
21299 + struct dentry *h_parent,
21300 + struct au_branch *br)
21302 + struct dentry *h_dentry;
21303 + struct mutex *h_mtx;
21305 + h_mtx = &h_parent->d_inode->i_mutex;
21306 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
21307 + h_dentry = au_lkup_one(tgtname, h_parent, br, /*nd*/NULL);
21308 + mutex_unlock(h_mtx);
21312 +static void au_call_do_plink_lkup(void *args)
21314 + struct au_do_plink_lkup_args *a = args;
21315 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
21318 +/* lookup the plink-ed @inode under the branch at @bindex */
21319 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
21321 + struct dentry *h_dentry, *h_parent;
21322 + struct au_branch *br;
21323 + struct inode *h_dir;
21325 + char a[PLINK_NAME_LEN];
21326 + struct qstr tgtname = QSTR_INIT(a, 0);
21328 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
21330 + br = au_sbr(inode->i_sb, bindex);
21331 + h_parent = br->br_wbr->wbr_plink;
21332 + h_dir = h_parent->d_inode;
21333 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
21335 + if (current_fsuid() != GLOBAL_ROOT_GID) {
21336 + struct au_do_plink_lkup_args args = {
21337 + .errp = &h_dentry,
21338 + .tgtname = &tgtname,
21339 + .h_parent = h_parent,
21343 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
21344 + if (unlikely(wkq_err))
21345 + h_dentry = ERR_PTR(wkq_err);
21347 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
21352 +/* create a pseudo-link */
21353 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
21354 + struct dentry *h_dentry, struct au_branch *br)
21357 + struct path h_path = {
21358 + .mnt = br->br_mnt
21360 + struct inode *h_dir;
21362 + h_dir = h_parent->d_inode;
21363 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_CHILD2);
21365 + h_path.dentry = au_lkup_one(tgt, h_parent, br, /*nd*/NULL);
21366 + err = PTR_ERR(h_path.dentry);
21367 + if (IS_ERR(h_path.dentry))
21371 + /* wh.plink dir is not monitored */
21372 + /* todo: is it really safe? */
21373 + if (h_path.dentry->d_inode
21374 + && h_path.dentry->d_inode != h_dentry->d_inode) {
21375 + err = vfsub_unlink(h_dir, &h_path, /*force*/0);
21376 + dput(h_path.dentry);
21377 + h_path.dentry = NULL;
21381 + if (!err && !h_path.dentry->d_inode)
21382 + err = vfsub_link(h_dentry, h_dir, &h_path);
21383 + dput(h_path.dentry);
21386 + mutex_unlock(&h_dir->i_mutex);
21390 +struct do_whplink_args {
21392 + struct qstr *tgt;
21393 + struct dentry *h_parent;
21394 + struct dentry *h_dentry;
21395 + struct au_branch *br;
21398 +static void call_do_whplink(void *args)
21400 + struct do_whplink_args *a = args;
21401 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
21404 +static int whplink(struct dentry *h_dentry, struct inode *inode,
21405 + aufs_bindex_t bindex, struct au_branch *br)
21407 + int err, wkq_err;
21408 + struct au_wbr *wbr;
21409 + struct dentry *h_parent;
21410 + struct inode *h_dir;
21411 + char a[PLINK_NAME_LEN];
21412 + struct qstr tgtname = QSTR_INIT(a, 0);
21414 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
21415 + h_parent = wbr->wbr_plink;
21416 + h_dir = h_parent->d_inode;
21417 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
21419 + /* always superio. */
21420 + if (current_fsuid() != GLOBAL_ROOT_GID) {
21421 + struct do_whplink_args args = {
21424 + .h_parent = h_parent,
21425 + .h_dentry = h_dentry,
21428 + wkq_err = au_wkq_wait(call_do_whplink, &args);
21429 + if (unlikely(wkq_err))
21432 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
21437 +/* free a single plink */
21438 +static void do_put_plink(struct pseudo_link *plink, int do_del)
21441 + list_del(&plink->list);
21442 + iput(plink->inode);
21446 +static void do_put_plink_rcu(struct rcu_head *rcu)
21448 + struct pseudo_link *plink;
21450 + plink = container_of(rcu, struct pseudo_link, rcu);
21451 + iput(plink->inode);
21456 + * create a new pseudo-link for @h_dentry on @bindex.
21457 + * the linked inode is held in aufs @inode.
21459 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
21460 + struct dentry *h_dentry)
21462 + struct super_block *sb;
21463 + struct au_sbinfo *sbinfo;
21464 + struct list_head *plink_list;
21465 + struct pseudo_link *plink, *tmp;
21466 + int found, err, cnt;
21468 + sb = inode->i_sb;
21469 + sbinfo = au_sbi(sb);
21470 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
21471 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
21475 + plink_list = &sbinfo->si_plink.head;
21477 + list_for_each_entry_rcu(plink, plink_list, list) {
21479 + if (plink->inode == inode) {
21484 + rcu_read_unlock();
21488 + tmp = kmalloc(sizeof(*plink), GFP_NOFS);
21490 + tmp->inode = au_igrab(inode);
21496 + spin_lock(&sbinfo->si_plink.spin);
21497 + list_for_each_entry(plink, plink_list, list) {
21498 + if (plink->inode == inode) {
21504 + list_add_rcu(&tmp->list, plink_list);
21505 + spin_unlock(&sbinfo->si_plink.spin);
21508 + WARN_ONCE(cnt > AUFS_PLINK_WARN,
21509 + "unexpectedly many pseudo links, %d\n", cnt);
21510 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
21512 + do_put_plink(tmp, 0);
21517 + if (unlikely(err)) {
21518 + pr_warn("err %d, damaged pseudo link.\n", err);
21520 + au_spl_del_rcu(&tmp->list, &sbinfo->si_plink);
21521 + call_rcu(&tmp->rcu, do_put_plink_rcu);
21526 +/* free all plinks */
21527 +void au_plink_put(struct super_block *sb, int verbose)
21529 + struct au_sbinfo *sbinfo;
21530 + struct list_head *plink_list;
21531 + struct pseudo_link *plink, *tmp;
21533 + SiMustWriteLock(sb);
21535 + sbinfo = au_sbi(sb);
21536 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
21537 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
21539 + plink_list = &sbinfo->si_plink.head;
21540 + /* no spin_lock since sbinfo is write-locked */
21541 + WARN(verbose && !list_empty(plink_list), "pseudo-link is not flushed");
21542 + list_for_each_entry_safe(plink, tmp, plink_list, list)
21543 + do_put_plink(plink, 0);
21544 + INIT_LIST_HEAD(plink_list);
21547 +void au_plink_clean(struct super_block *sb, int verbose)
21549 + struct dentry *root;
21551 + root = sb->s_root;
21552 + aufs_write_lock(root);
21553 + if (au_opt_test(au_mntflags(sb), PLINK))
21554 + au_plink_put(sb, verbose);
21555 + aufs_write_unlock(root);
21558 +/* free the plinks on a branch specified by @br_id */
21559 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
21561 + struct au_sbinfo *sbinfo;
21562 + struct list_head *plink_list;
21563 + struct pseudo_link *plink, *tmp;
21564 + struct inode *inode;
21565 + aufs_bindex_t bstart, bend, bindex;
21566 + unsigned char do_put;
21568 + SiMustWriteLock(sb);
21570 + sbinfo = au_sbi(sb);
21571 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
21572 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
21574 + plink_list = &sbinfo->si_plink.head;
21575 + /* no spin_lock since sbinfo is write-locked */
21576 + list_for_each_entry_safe(plink, tmp, plink_list, list) {
21578 + inode = au_igrab(plink->inode);
21579 + ii_write_lock_child(inode);
21580 + bstart = au_ibstart(inode);
21581 + bend = au_ibend(inode);
21582 + if (bstart >= 0) {
21583 + for (bindex = bstart; bindex <= bend; bindex++) {
21584 + if (!au_h_iptr(inode, bindex)
21585 + || au_ii_br_id(inode, bindex) != br_id)
21587 + au_set_h_iptr(inode, bindex, NULL, 0);
21592 + do_put_plink(plink, 1);
21595 + for (bindex = bstart; bindex <= bend; bindex++)
21596 + if (au_h_iptr(inode, bindex)) {
21601 + do_put_plink(plink, 1);
21603 + ii_write_unlock(inode);
21607 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
21608 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
21609 +++ linux/fs/aufs/poll.c 2012-07-22 19:57:03.164337936 +0200
21612 + * Copyright (C) 2005-2012 Junjiro R. Okajima
21614 + * This program, aufs is free software; you can redistribute it and/or modify
21615 + * it under the terms of the GNU General Public License as published by
21616 + * the Free Software Foundation; either version 2 of the License, or
21617 + * (at your option) any later version.
21619 + * This program is distributed in the hope that it will be useful,
21620 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21621 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21622 + * GNU General Public License for more details.
21624 + * You should have received a copy of the GNU General Public License
21625 + * along with this program; if not, write to the Free Software
21626 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21631 + * There is only one filesystem which implements ->poll operation, currently.
21636 +unsigned int aufs_poll(struct file *file, poll_table *wait)
21638 + unsigned int mask;
21640 + struct file *h_file;
21641 + struct dentry *dentry;
21642 + struct super_block *sb;
21644 + /* We should pretend an error happened. */
21645 + mask = POLLERR /* | POLLIN | POLLOUT */;
21646 + dentry = file->f_dentry;
21647 + sb = dentry->d_sb;
21648 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
21649 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
21650 + if (unlikely(err))
21653 + /* it is not an error if h_file has no operation */
21654 + mask = DEFAULT_POLLMASK;
21655 + h_file = au_hf_top(file);
21656 + if (h_file->f_op && h_file->f_op->poll)
21657 + mask = h_file->f_op->poll(h_file, wait);
21659 + di_read_unlock(dentry, AuLock_IR);
21660 + fi_read_unlock(file);
21663 + si_read_unlock(sb);
21664 + AuTraceErr((int)mask);
21667 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
21668 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
21669 +++ linux/fs/aufs/procfs.c 2012-07-22 19:57:03.164337936 +0200
21672 + * Copyright (C) 2010-2012 Junjiro R. Okajima
21674 + * This program, aufs is free software; you can redistribute it and/or modify
21675 + * it under the terms of the GNU General Public License as published by
21676 + * the Free Software Foundation; either version 2 of the License, or
21677 + * (at your option) any later version.
21679 + * This program is distributed in the hope that it will be useful,
21680 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21681 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21682 + * GNU General Public License for more details.
21684 + * You should have received a copy of the GNU General Public License
21685 + * along with this program; if not, write to the Free Software
21686 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21690 + * procfs interfaces
21693 +#include <linux/proc_fs.h>
21696 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
21698 + struct au_sbinfo *sbinfo;
21700 + sbinfo = file->private_data;
21702 + au_plink_maint_leave(sbinfo);
21703 + kobject_put(&sbinfo->si_kobj);
21709 +static void au_procfs_plm_write_clean(struct file *file)
21711 + struct au_sbinfo *sbinfo;
21713 + sbinfo = file->private_data;
21715 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
21718 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
21721 + struct super_block *sb;
21722 + struct au_sbinfo *sbinfo;
21725 + if (unlikely(file->private_data))
21729 + /* don't use au_sbilist_lock() here */
21730 + spin_lock(&au_sbilist.spin);
21731 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
21732 + if (id == sysaufs_si_id(sbinfo)) {
21733 + kobject_get(&sbinfo->si_kobj);
21734 + sb = sbinfo->si_sb;
21737 + spin_unlock(&au_sbilist.spin);
21740 + if (unlikely(!sb))
21743 + err = au_plink_maint_enter(sb);
21745 + /* keep kobject_get() */
21746 + file->private_data = sbinfo;
21748 + kobject_put(&sbinfo->si_kobj);
21754 + * Accept a valid "si=xxxx" only.
21755 + * Once it is accepted successfully, accept "clean" too.
21757 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
21758 + size_t count, loff_t *ppos)
21761 + unsigned long id;
21762 + /* last newline is allowed */
21763 + char buf[3 + sizeof(unsigned long) * 2 + 1];
21766 + if (unlikely(!capable(CAP_SYS_ADMIN)))
21770 + if (unlikely(count > sizeof(buf)))
21773 + err = copy_from_user(buf, ubuf, count);
21774 + if (unlikely(err)) {
21781 + if (!strcmp("clean", buf)) {
21782 + au_procfs_plm_write_clean(file);
21783 + goto out_success;
21784 + } else if (unlikely(strncmp("si=", buf, 3)))
21787 + err = kstrtoul(buf + 3, 16, &id);
21788 + if (unlikely(err))
21791 + err = au_procfs_plm_write_si(file, id);
21792 + if (unlikely(err))
21796 + err = count; /* success */
21801 +static const struct file_operations au_procfs_plm_fop = {
21802 + .write = au_procfs_plm_write,
21803 + .release = au_procfs_plm_release,
21804 + .owner = THIS_MODULE
21807 +/* ---------------------------------------------------------------------- */
21809 +static struct proc_dir_entry *au_procfs_dir;
21811 +void au_procfs_fin(void)
21813 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
21814 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
21817 +int __init au_procfs_init(void)
21820 + struct proc_dir_entry *entry;
21823 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
21824 + if (unlikely(!au_procfs_dir))
21827 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR,
21828 + au_procfs_dir, &au_procfs_plm_fop);
21829 + if (unlikely(!entry))
21833 + goto out; /* success */
21837 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
21841 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
21842 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
21843 +++ linux/fs/aufs/rdu.c 2012-07-22 19:57:03.164337936 +0200
21846 + * Copyright (C) 2005-2012 Junjiro R. Okajima
21848 + * This program, aufs is free software; you can redistribute it and/or modify
21849 + * it under the terms of the GNU General Public License as published by
21850 + * the Free Software Foundation; either version 2 of the License, or
21851 + * (at your option) any later version.
21853 + * This program is distributed in the hope that it will be useful,
21854 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21855 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21856 + * GNU General Public License for more details.
21858 + * You should have received a copy of the GNU General Public License
21859 + * along with this program; if not, write to the Free Software
21860 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21864 + * readdir in userspace.
21867 +#include <linux/compat.h>
21868 +#include <linux/fs_stack.h>
21869 +#include <linux/security.h>
21872 +/* bits for struct aufs_rdu.flags */
21873 +#define AuRdu_CALLED 1
21874 +#define AuRdu_CONT (1 << 1)
21875 +#define AuRdu_FULL (1 << 2)
21876 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
21877 +#define au_fset_rdu(flags, name) \
21878 + do { (flags) |= AuRdu_##name; } while (0)
21879 +#define au_fclr_rdu(flags, name) \
21880 + do { (flags) &= ~AuRdu_##name; } while (0)
21882 +struct au_rdu_arg {
21883 + struct aufs_rdu *rdu;
21884 + union au_rdu_ent_ul ent;
21885 + unsigned long end;
21887 + struct super_block *sb;
21891 +static int au_rdu_fill(void *__arg, const char *name, int nlen,
21892 + loff_t offset, u64 h_ino, unsigned int d_type)
21895 + struct au_rdu_arg *arg = __arg;
21896 + struct aufs_rdu *rdu = arg->rdu;
21897 + struct au_rdu_ent ent;
21901 + au_fset_rdu(rdu->cookie.flags, CALLED);
21902 + len = au_rdu_len(nlen);
21903 + if (arg->ent.ul + len < arg->end) {
21905 + ent.bindex = rdu->cookie.bindex;
21906 + ent.type = d_type;
21908 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
21909 + ent.type = DT_UNKNOWN;
21911 + /* unnecessary to support mmap_sem since this is a dir */
21913 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
21915 + if (copy_to_user(arg->ent.e->name, name, nlen))
21917 + /* the terminating NULL */
21918 + if (__put_user(0, arg->ent.e->name + nlen))
21921 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
21922 + arg->ent.ul += len;
21926 + au_fset_rdu(rdu->cookie.flags, FULL);
21928 + rdu->tail = arg->ent;
21932 + /* AuTraceErr(err); */
21936 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
21940 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
21942 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
21943 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
21945 + if (unlikely(offset != cookie->h_pos))
21951 + au_fclr_rdu(cookie->flags, CALLED);
21953 + err = vfsub_readdir(h_file, au_rdu_fill, arg);
21957 + && au_ftest_rdu(cookie->flags, CALLED)
21958 + && !au_ftest_rdu(cookie->flags, FULL));
21959 + cookie->h_pos = h_file->f_pos;
21966 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
21969 + aufs_bindex_t bend;
21970 + struct au_rdu_arg arg;
21971 + struct dentry *dentry;
21972 + struct inode *inode;
21973 + struct file *h_file;
21974 + struct au_rdu_cookie *cookie = &rdu->cookie;
21976 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
21977 + if (unlikely(err)) {
21983 + rdu->tail = rdu->ent;
21986 + arg.ent = rdu->ent;
21987 + arg.end = arg.ent.ul;
21988 + arg.end += rdu->sz;
21991 + if (unlikely(!file->f_op || !file->f_op->readdir))
21994 + err = security_file_permission(file, MAY_READ);
21996 + if (unlikely(err))
21999 + dentry = file->f_dentry;
22000 + inode = dentry->d_inode;
22002 + mutex_lock(&inode->i_mutex);
22004 + err = mutex_lock_killable(&inode->i_mutex);
22006 + if (unlikely(err))
22010 + arg.sb = inode->i_sb;
22011 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
22012 + if (unlikely(err))
22014 + err = au_alive_dir(dentry);
22015 + if (unlikely(err))
22017 + /* todo: reval? */
22018 + fi_read_lock(file);
22021 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
22022 + && cookie->generation != au_figen(file)))
22027 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
22029 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
22031 + bend = au_fbstart(file);
22032 + if (cookie->bindex < bend)
22033 + cookie->bindex = bend;
22034 + bend = au_fbend_dir(file);
22035 + /* AuDbg("b%d, b%d\n", cookie->bindex, bend); */
22036 + for (; !err && cookie->bindex <= bend;
22037 + cookie->bindex++, cookie->h_pos = 0) {
22038 + h_file = au_hf_dir(file, cookie->bindex);
22042 + au_fclr_rdu(cookie->flags, FULL);
22043 + err = au_rdu_do(h_file, &arg);
22045 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
22048 + AuDbg("rent %llu\n", rdu->rent);
22050 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
22051 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
22052 + au_fset_rdu(cookie->flags, CONT);
22053 + cookie->generation = au_figen(file);
22056 + ii_read_lock_child(inode);
22057 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibstart(inode)));
22058 + ii_read_unlock(inode);
22061 + fi_read_unlock(file);
22063 + si_read_unlock(arg.sb);
22065 + mutex_unlock(&inode->i_mutex);
22071 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
22075 + unsigned long long nent;
22076 + union au_rdu_ent_ul *u;
22077 + struct au_rdu_ent ent;
22078 + struct super_block *sb;
22081 + nent = rdu->nent;
22083 + sb = file->f_dentry->d_sb;
22084 + si_read_lock(sb, AuLock_FLUSH);
22085 + while (nent-- > 0) {
22086 + /* unnecessary to support mmap_sem since this is a dir */
22087 + err = copy_from_user(&ent, u->e, sizeof(ent));
22089 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
22090 + if (unlikely(err)) {
22096 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
22098 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
22100 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
22102 + if (unlikely(err)) {
22107 + err = __put_user(ino, &u->e->ino);
22108 + if (unlikely(err)) {
22113 + u->ul += au_rdu_len(ent.nlen);
22115 + si_read_unlock(sb);
22120 +/* ---------------------------------------------------------------------- */
22122 +static int au_rdu_verify(struct aufs_rdu *rdu)
22124 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
22125 + "%llu, b%d, 0x%x, g%u}\n",
22126 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
22128 + rdu->rent, rdu->shwh, rdu->full,
22129 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
22130 + rdu->cookie.generation);
22132 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
22136 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
22140 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
22143 + struct aufs_rdu rdu;
22144 + void __user *p = (void __user *)arg;
22146 + err = copy_from_user(&rdu, p, sizeof(rdu));
22147 + if (unlikely(err)) {
22152 + err = au_rdu_verify(&rdu);
22153 + if (unlikely(err))
22157 + case AUFS_CTL_RDU:
22158 + err = au_rdu(file, &rdu);
22159 + if (unlikely(err))
22162 + e = copy_to_user(p, &rdu, sizeof(rdu));
22163 + if (unlikely(e)) {
22168 + case AUFS_CTL_RDU_INO:
22169 + err = au_rdu_ino(file, &rdu);
22173 + /* err = -ENOTTY; */
22182 +#ifdef CONFIG_COMPAT
22183 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
22186 + struct aufs_rdu rdu;
22187 + void __user *p = compat_ptr(arg);
22189 + /* todo: get_user()? */
22190 + err = copy_from_user(&rdu, p, sizeof(rdu));
22191 + if (unlikely(err)) {
22196 + rdu.ent.e = compat_ptr(rdu.ent.ul);
22197 + err = au_rdu_verify(&rdu);
22198 + if (unlikely(err))
22202 + case AUFS_CTL_RDU:
22203 + err = au_rdu(file, &rdu);
22204 + if (unlikely(err))
22207 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
22208 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
22209 + e = copy_to_user(p, &rdu, sizeof(rdu));
22210 + if (unlikely(e)) {
22215 + case AUFS_CTL_RDU_INO:
22216 + err = au_rdu_ino(file, &rdu);
22220 + /* err = -ENOTTY; */
22229 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
22230 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
22231 +++ linux/fs/aufs/rwsem.h 2012-07-22 19:57:03.164337936 +0200
22234 + * Copyright (C) 2005-2012 Junjiro R. Okajima
22236 + * This program, aufs is free software; you can redistribute it and/or modify
22237 + * it under the terms of the GNU General Public License as published by
22238 + * the Free Software Foundation; either version 2 of the License, or
22239 + * (at your option) any later version.
22241 + * This program is distributed in the hope that it will be useful,
22242 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22243 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22244 + * GNU General Public License for more details.
22246 + * You should have received a copy of the GNU General Public License
22247 + * along with this program; if not, write to the Free Software
22248 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22252 + * simple read-write semaphore wrappers
22255 +#ifndef __AUFS_RWSEM_H__
22256 +#define __AUFS_RWSEM_H__
22260 +#include "debug.h"
22263 + struct rw_semaphore rwsem;
22264 +#ifdef CONFIG_AUFS_DEBUG
22265 + /* just for debugging, not almighty counter */
22266 + atomic_t rcnt, wcnt;
22270 +#ifdef CONFIG_AUFS_DEBUG
22271 +#define AuDbgCntInit(rw) do { \
22272 + atomic_set(&(rw)->rcnt, 0); \
22273 + atomic_set(&(rw)->wcnt, 0); \
22274 + smp_mb(); /* atomic set */ \
22277 +#define AuDbgRcntInc(rw) atomic_inc(&(rw)->rcnt)
22278 +#define AuDbgRcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->rcnt) < 0)
22279 +#define AuDbgWcntInc(rw) atomic_inc(&(rw)->wcnt)
22280 +#define AuDbgWcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->wcnt) < 0)
22282 +#define AuDbgCntInit(rw) do {} while (0)
22283 +#define AuDbgRcntInc(rw) do {} while (0)
22284 +#define AuDbgRcntDec(rw) do {} while (0)
22285 +#define AuDbgWcntInc(rw) do {} while (0)
22286 +#define AuDbgWcntDec(rw) do {} while (0)
22287 +#endif /* CONFIG_AUFS_DEBUG */
22289 +/* to debug easier, do not make them inlined functions */
22290 +#define AuRwMustNoWaiters(rw) AuDebugOn(!list_empty(&(rw)->rwsem.wait_list))
22291 +/* rwsem_is_locked() is unusable */
22292 +#define AuRwMustReadLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0)
22293 +#define AuRwMustWriteLock(rw) AuDebugOn(atomic_read(&(rw)->wcnt) <= 0)
22294 +#define AuRwMustAnyLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0 \
22295 + && atomic_read(&(rw)->wcnt) <= 0)
22296 +#define AuRwDestroy(rw) AuDebugOn(atomic_read(&(rw)->rcnt) \
22297 + || atomic_read(&(rw)->wcnt))
22299 +#define au_rw_class(rw, key) lockdep_set_class(&(rw)->rwsem, key)
22301 +static inline void au_rw_init(struct au_rwsem *rw)
22303 + AuDbgCntInit(rw);
22304 + init_rwsem(&rw->rwsem);
22307 +static inline void au_rw_init_wlock(struct au_rwsem *rw)
22310 + down_write(&rw->rwsem);
22311 + AuDbgWcntInc(rw);
22314 +static inline void au_rw_init_wlock_nested(struct au_rwsem *rw,
22315 + unsigned int lsc)
22318 + down_write_nested(&rw->rwsem, lsc);
22319 + AuDbgWcntInc(rw);
22322 +static inline void au_rw_read_lock(struct au_rwsem *rw)
22324 + down_read(&rw->rwsem);
22325 + AuDbgRcntInc(rw);
22328 +static inline void au_rw_read_lock_nested(struct au_rwsem *rw, unsigned int lsc)
22330 + down_read_nested(&rw->rwsem, lsc);
22331 + AuDbgRcntInc(rw);
22334 +static inline void au_rw_read_unlock(struct au_rwsem *rw)
22336 + AuRwMustReadLock(rw);
22337 + AuDbgRcntDec(rw);
22338 + up_read(&rw->rwsem);
22341 +static inline void au_rw_dgrade_lock(struct au_rwsem *rw)
22343 + AuRwMustWriteLock(rw);
22344 + AuDbgRcntInc(rw);
22345 + AuDbgWcntDec(rw);
22346 + downgrade_write(&rw->rwsem);
22349 +static inline void au_rw_write_lock(struct au_rwsem *rw)
22351 + down_write(&rw->rwsem);
22352 + AuDbgWcntInc(rw);
22355 +static inline void au_rw_write_lock_nested(struct au_rwsem *rw,
22356 + unsigned int lsc)
22358 + down_write_nested(&rw->rwsem, lsc);
22359 + AuDbgWcntInc(rw);
22362 +static inline void au_rw_write_unlock(struct au_rwsem *rw)
22364 + AuRwMustWriteLock(rw);
22365 + AuDbgWcntDec(rw);
22366 + up_write(&rw->rwsem);
22369 +/* why is not _nested version defined */
22370 +static inline int au_rw_read_trylock(struct au_rwsem *rw)
22372 + int ret = down_read_trylock(&rw->rwsem);
22374 + AuDbgRcntInc(rw);
22378 +static inline int au_rw_write_trylock(struct au_rwsem *rw)
22380 + int ret = down_write_trylock(&rw->rwsem);
22382 + AuDbgWcntInc(rw);
22386 +#undef AuDbgCntInit
22387 +#undef AuDbgRcntInc
22388 +#undef AuDbgRcntDec
22389 +#undef AuDbgWcntInc
22390 +#undef AuDbgWcntDec
22392 +#define AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
22393 +static inline void prefix##_read_lock(param) \
22394 +{ au_rw_read_lock(rwsem); } \
22395 +static inline void prefix##_write_lock(param) \
22396 +{ au_rw_write_lock(rwsem); } \
22397 +static inline int prefix##_read_trylock(param) \
22398 +{ return au_rw_read_trylock(rwsem); } \
22399 +static inline int prefix##_write_trylock(param) \
22400 +{ return au_rw_write_trylock(rwsem); }
22401 +/* why is not _nested version defined */
22402 +/* static inline void prefix##_read_trylock_nested(param, lsc)
22403 +{ au_rw_read_trylock_nested(rwsem, lsc)); }
22404 +static inline void prefix##_write_trylock_nestd(param, lsc)
22405 +{ au_rw_write_trylock_nested(rwsem, lsc); } */
22407 +#define AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) \
22408 +static inline void prefix##_read_unlock(param) \
22409 +{ au_rw_read_unlock(rwsem); } \
22410 +static inline void prefix##_write_unlock(param) \
22411 +{ au_rw_write_unlock(rwsem); } \
22412 +static inline void prefix##_downgrade_lock(param) \
22413 +{ au_rw_dgrade_lock(rwsem); }
22415 +#define AuSimpleRwsemFuncs(prefix, param, rwsem) \
22416 + AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
22417 + AuSimpleUnlockRwsemFuncs(prefix, param, rwsem)
22419 +#endif /* __KERNEL__ */
22420 +#endif /* __AUFS_RWSEM_H__ */
22421 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
22422 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
22423 +++ linux/fs/aufs/sbinfo.c 2012-07-22 19:57:03.164337936 +0200
22426 + * Copyright (C) 2005-2012 Junjiro R. Okajima
22428 + * This program, aufs is free software; you can redistribute it and/or modify
22429 + * it under the terms of the GNU General Public License as published by
22430 + * the Free Software Foundation; either version 2 of the License, or
22431 + * (at your option) any later version.
22433 + * This program is distributed in the hope that it will be useful,
22434 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22435 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22436 + * GNU General Public License for more details.
22438 + * You should have received a copy of the GNU General Public License
22439 + * along with this program; if not, write to the Free Software
22440 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22444 + * superblock private data
22450 + * they are necessary regardless sysfs is disabled.
22452 +void au_si_free(struct kobject *kobj)
22454 + struct au_sbinfo *sbinfo;
22455 + char *locked __maybe_unused; /* debug only */
22457 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
22458 + AuDebugOn(!list_empty(&sbinfo->si_plink.head));
22459 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
22461 + au_rw_write_lock(&sbinfo->si_rwsem);
22462 + au_br_free(sbinfo);
22463 + au_rw_write_unlock(&sbinfo->si_rwsem);
22465 + AuDebugOn(radix_tree_gang_lookup
22466 + (&sbinfo->au_si_pid.tree, (void **)&locked,
22467 + /*first_index*/PID_MAX_DEFAULT - 1,
22468 + /*max_items*/sizeof(locked)/sizeof(*locked)));
22470 + kfree(sbinfo->si_branch);
22471 + kfree(sbinfo->au_si_pid.bitmap);
22472 + mutex_destroy(&sbinfo->si_xib_mtx);
22473 + AuRwDestroy(&sbinfo->si_rwsem);
22478 +int au_si_alloc(struct super_block *sb)
22481 + struct au_sbinfo *sbinfo;
22482 + static struct lock_class_key aufs_si;
22485 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
22486 + if (unlikely(!sbinfo))
22489 + BUILD_BUG_ON(sizeof(unsigned long) !=
22490 + sizeof(*sbinfo->au_si_pid.bitmap));
22491 + sbinfo->au_si_pid.bitmap = kcalloc(BITS_TO_LONGS(PID_MAX_DEFAULT),
22492 + sizeof(*sbinfo->au_si_pid.bitmap),
22494 + if (unlikely(!sbinfo->au_si_pid.bitmap))
22497 + /* will be reallocated separately */
22498 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
22499 + if (unlikely(!sbinfo->si_branch))
22502 + err = sysaufs_si_init(sbinfo);
22503 + if (unlikely(err))
22506 + au_nwt_init(&sbinfo->si_nowait);
22507 + au_rw_init_wlock(&sbinfo->si_rwsem);
22508 + au_rw_class(&sbinfo->si_rwsem, &aufs_si);
22509 + spin_lock_init(&sbinfo->au_si_pid.tree_lock);
22510 + INIT_RADIX_TREE(&sbinfo->au_si_pid.tree, GFP_ATOMIC | __GFP_NOFAIL);
22512 + atomic_long_set(&sbinfo->si_ninodes, 0);
22513 + atomic_long_set(&sbinfo->si_nfiles, 0);
22515 + sbinfo->si_bend = -1;
22517 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
22518 + sbinfo->si_wbr_create = AuWbrCreate_Def;
22519 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
22520 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
22522 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
22524 + mutex_init(&sbinfo->si_xib_mtx);
22525 + sbinfo->si_xino_brid = -1;
22526 + /* leave si_xib_last_pindex and si_xib_next_bit */
22528 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
22529 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
22530 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
22531 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
22533 + au_spl_init(&sbinfo->si_plink);
22534 + init_waitqueue_head(&sbinfo->si_plink_wq);
22535 + spin_lock_init(&sbinfo->si_plink_maint_lock);
22537 + /* leave other members for sysaufs and si_mnt. */
22538 + sbinfo->si_sb = sb;
22539 + sb->s_fs_info = sbinfo;
22541 + au_debug_sbinfo_init(sbinfo);
22542 + return 0; /* success */
22545 + kfree(sbinfo->si_branch);
22547 + kfree(sbinfo->au_si_pid.bitmap);
22554 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr)
22557 + struct au_branch **brp;
22559 + AuRwMustWriteLock(&sbinfo->si_rwsem);
22562 + sz = sizeof(*brp) * (sbinfo->si_bend + 1);
22563 + if (unlikely(!sz))
22564 + sz = sizeof(*brp);
22565 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS);
22567 + sbinfo->si_branch = brp;
22574 +/* ---------------------------------------------------------------------- */
22576 +unsigned int au_sigen_inc(struct super_block *sb)
22578 + unsigned int gen;
22580 + SiMustWriteLock(sb);
22582 + gen = ++au_sbi(sb)->si_generation;
22583 + au_update_digen(sb->s_root);
22584 + au_update_iigen(sb->s_root->d_inode);
22585 + sb->s_root->d_inode->i_version++;
22589 +aufs_bindex_t au_new_br_id(struct super_block *sb)
22591 + aufs_bindex_t br_id;
22593 + struct au_sbinfo *sbinfo;
22595 + SiMustWriteLock(sb);
22597 + sbinfo = au_sbi(sb);
22598 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
22599 + br_id = ++sbinfo->si_last_br_id;
22600 + AuDebugOn(br_id < 0);
22601 + if (br_id && au_br_index(sb, br_id) < 0)
22608 +/* ---------------------------------------------------------------------- */
22610 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
22611 +int si_read_lock(struct super_block *sb, int flags)
22616 + if (au_ftest_lock(flags, FLUSH))
22617 + au_nwt_flush(&au_sbi(sb)->si_nowait);
22619 + si_noflush_read_lock(sb);
22620 + err = au_plink_maint(sb, flags);
22621 + if (unlikely(err))
22622 + si_read_unlock(sb);
22627 +int si_write_lock(struct super_block *sb, int flags)
22631 + if (au_ftest_lock(flags, FLUSH))
22632 + au_nwt_flush(&au_sbi(sb)->si_nowait);
22634 + si_noflush_write_lock(sb);
22635 + err = au_plink_maint(sb, flags);
22636 + if (unlikely(err))
22637 + si_write_unlock(sb);
22642 +/* dentry and super_block lock. call at entry point */
22643 +int aufs_read_lock(struct dentry *dentry, int flags)
22646 + struct super_block *sb;
22648 + sb = dentry->d_sb;
22649 + err = si_read_lock(sb, flags);
22650 + if (unlikely(err))
22653 + if (au_ftest_lock(flags, DW))
22654 + di_write_lock_child(dentry);
22656 + di_read_lock_child(dentry, flags);
22658 + if (au_ftest_lock(flags, GEN)) {
22659 + err = au_digen_test(dentry, au_sigen(sb));
22660 + AuDebugOn(!err && au_dbrange_test(dentry));
22661 + if (unlikely(err))
22662 + aufs_read_unlock(dentry, flags);
22669 +void aufs_read_unlock(struct dentry *dentry, int flags)
22671 + if (au_ftest_lock(flags, DW))
22672 + di_write_unlock(dentry);
22674 + di_read_unlock(dentry, flags);
22675 + si_read_unlock(dentry->d_sb);
22678 +void aufs_write_lock(struct dentry *dentry)
22680 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
22681 + di_write_lock_child(dentry);
22684 +void aufs_write_unlock(struct dentry *dentry)
22686 + di_write_unlock(dentry);
22687 + si_write_unlock(dentry->d_sb);
22690 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
22693 + unsigned int sigen;
22694 + struct super_block *sb;
22697 + err = si_read_lock(sb, flags);
22698 + if (unlikely(err))
22701 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIR));
22703 + if (au_ftest_lock(flags, GEN)) {
22704 + sigen = au_sigen(sb);
22705 + err = au_digen_test(d1, sigen);
22706 + AuDebugOn(!err && au_dbrange_test(d1));
22708 + err = au_digen_test(d2, sigen);
22709 + AuDebugOn(!err && au_dbrange_test(d2));
22711 + if (unlikely(err))
22712 + aufs_read_and_write_unlock2(d1, d2);
22719 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
22721 + di_write_unlock2(d1, d2);
22722 + si_read_unlock(d1->d_sb);
22725 +/* ---------------------------------------------------------------------- */
22727 +int si_pid_test_slow(struct super_block *sb)
22732 + p = radix_tree_lookup(&au_sbi(sb)->au_si_pid.tree, current->pid);
22733 + rcu_read_unlock();
22735 + return (long)!!p;
22738 +void si_pid_set_slow(struct super_block *sb)
22741 + struct au_sbinfo *sbinfo;
22743 + AuDebugOn(si_pid_test_slow(sb));
22745 + sbinfo = au_sbi(sb);
22746 + err = radix_tree_preload(GFP_NOFS | __GFP_NOFAIL);
22748 + spin_lock(&sbinfo->au_si_pid.tree_lock);
22749 + err = radix_tree_insert(&sbinfo->au_si_pid.tree, current->pid,
22750 + /*any valid ptr*/sb);
22751 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
22753 + radix_tree_preload_end();
22756 +void si_pid_clr_slow(struct super_block *sb)
22759 + struct au_sbinfo *sbinfo;
22761 + AuDebugOn(!si_pid_test_slow(sb));
22763 + sbinfo = au_sbi(sb);
22764 + spin_lock(&sbinfo->au_si_pid.tree_lock);
22765 + p = radix_tree_delete(&sbinfo->au_si_pid.tree, current->pid);
22766 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
22768 diff -urN /usr/share/empty/fs/aufs/security.c linux/fs/aufs/security.c
22769 --- /usr/share/empty/fs/aufs/security.c 1970-01-01 01:00:00.000000000 +0100
22770 +++ linux/fs/aufs/security.c 2012-07-22 19:57:03.164337936 +0200
22773 + * Copyright (C) 2012 Junjiro R. Okajima
22775 + * This program, aufs is free software; you can redistribute it and/or modify
22776 + * it under the terms of the GNU General Public License as published by
22777 + * the Free Software Foundation; either version 2 of the License, or
22778 + * (at your option) any later version.
22780 + * This program is distributed in the hope that it will be useful,
22781 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22782 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22783 + * GNU General Public License for more details.
22785 + * You should have received a copy of the GNU General Public License
22786 + * along with this program; if not, write to the Free Software
22787 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22791 + * securityf_file_mmap
22794 +#include <linux/mman.h>
22795 +#include <linux/security.h>
22798 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
22799 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
22801 +static unsigned long au_arch_prot_conv(unsigned long flags)
22803 + /* currently ppc64 only */
22804 +#ifdef CONFIG_PPC64
22805 + /* cf. linux/arch/powerpc/include/asm/mman.h */
22806 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
22807 + return AuConv_VM_PROT(flags, SAO);
22809 + AuDebugOn(arch_calc_vm_prot_bits(-1));
22814 +static unsigned long au_prot_conv(unsigned long flags)
22816 + return AuConv_VM_PROT(flags, READ)
22817 + | AuConv_VM_PROT(flags, WRITE)
22818 + | AuConv_VM_PROT(flags, EXEC)
22819 + | au_arch_prot_conv(flags);
22822 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
22823 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
22825 +static unsigned long au_flag_conv(unsigned long flags)
22827 + return AuConv_VM_MAP(flags, GROWSDOWN)
22828 + | AuConv_VM_MAP(flags, DENYWRITE)
22829 + | AuConv_VM_MAP(flags, EXECUTABLE)
22830 + | AuConv_VM_MAP(flags, LOCKED);
22833 +struct au_security_mmap_file_args {
22835 + struct file *h_file;
22836 + struct vm_area_struct *vma;
22840 + * unnecessary to call security_mmap_file() since it doesn't have file as its
22843 +static void au_call_security_mmap_file(void *args)
22845 + struct au_security_mmap_file_args *a = args;
22846 + *a->errp = security_mmap_file(a->h_file, au_prot_conv(a->vma->vm_flags),
22847 + au_flag_conv(a->vma->vm_flags));
22850 +int au_security_mmap_file(struct file *h_file, struct vm_area_struct *vma)
22852 + int err, wkq_err;
22853 + struct au_security_mmap_file_args args = {
22855 + .h_file = h_file,
22859 + wkq_err = au_wkq_wait(au_call_security_mmap_file, &args);
22860 + if (unlikely(wkq_err))
22864 diff -urN /usr/share/empty/fs/aufs/spl.h linux/fs/aufs/spl.h
22865 --- /usr/share/empty/fs/aufs/spl.h 1970-01-01 01:00:00.000000000 +0100
22866 +++ linux/fs/aufs/spl.h 2012-07-22 19:57:03.164337936 +0200
22869 + * Copyright (C) 2005-2012 Junjiro R. Okajima
22871 + * This program, aufs is free software; you can redistribute it and/or modify
22872 + * it under the terms of the GNU General Public License as published by
22873 + * the Free Software Foundation; either version 2 of the License, or
22874 + * (at your option) any later version.
22876 + * This program is distributed in the hope that it will be useful,
22877 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22878 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22879 + * GNU General Public License for more details.
22881 + * You should have received a copy of the GNU General Public License
22882 + * along with this program; if not, write to the Free Software
22883 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22887 + * simple list protected by a spinlock
22890 +#ifndef __AUFS_SPL_H__
22891 +#define __AUFS_SPL_H__
22895 +struct au_splhead {
22897 + struct list_head head;
22900 +static inline void au_spl_init(struct au_splhead *spl)
22902 + spin_lock_init(&spl->spin);
22903 + INIT_LIST_HEAD(&spl->head);
22906 +static inline void au_spl_add(struct list_head *list, struct au_splhead *spl)
22908 + spin_lock(&spl->spin);
22909 + list_add(list, &spl->head);
22910 + spin_unlock(&spl->spin);
22913 +static inline void au_spl_del(struct list_head *list, struct au_splhead *spl)
22915 + spin_lock(&spl->spin);
22917 + spin_unlock(&spl->spin);
22920 +static inline void au_spl_del_rcu(struct list_head *list,
22921 + struct au_splhead *spl)
22923 + spin_lock(&spl->spin);
22924 + list_del_rcu(list);
22925 + spin_unlock(&spl->spin);
22928 +#endif /* __KERNEL__ */
22929 +#endif /* __AUFS_SPL_H__ */
22930 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
22931 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
22932 +++ linux/fs/aufs/super.c 2012-07-22 19:57:03.164337936 +0200
22935 + * Copyright (C) 2005-2012 Junjiro R. Okajima
22937 + * This program, aufs is free software; you can redistribute it and/or modify
22938 + * it under the terms of the GNU General Public License as published by
22939 + * the Free Software Foundation; either version 2 of the License, or
22940 + * (at your option) any later version.
22942 + * This program is distributed in the hope that it will be useful,
22943 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22944 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22945 + * GNU General Public License for more details.
22947 + * You should have received a copy of the GNU General Public License
22948 + * along with this program; if not, write to the Free Software
22949 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22953 + * mount and super_block operations
22956 +#include <linux/mm.h>
22957 +#include <linux/module.h>
22958 +#include <linux/seq_file.h>
22959 +#include <linux/statfs.h>
22960 +#include <linux/vmalloc.h>
22961 +#include <linux/writeback.h>
22965 + * super_operations
22967 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
22969 + struct au_icntnr *c;
22971 + c = au_cache_alloc_icntnr();
22973 + au_icntnr_init(c);
22974 + c->vfs_inode.i_version = 1; /* sigen(sb); */
22975 + c->iinfo.ii_hinode = NULL;
22976 + return &c->vfs_inode;
22981 +static void aufs_destroy_inode_cb(struct rcu_head *head)
22983 + struct inode *inode = container_of(head, struct inode, i_rcu);
22985 + INIT_LIST_HEAD(&inode->i_dentry);
22986 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
22989 +static void aufs_destroy_inode(struct inode *inode)
22991 + au_iinfo_fin(inode);
22992 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
22995 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
22997 + struct inode *inode;
23000 + inode = iget_locked(sb, ino);
23001 + if (unlikely(!inode)) {
23002 + inode = ERR_PTR(-ENOMEM);
23005 + if (!(inode->i_state & I_NEW))
23008 + err = au_xigen_new(inode);
23010 + err = au_iinfo_init(inode);
23012 + inode->i_version++;
23014 + iget_failed(inode);
23015 + inode = ERR_PTR(err);
23019 + /* never return NULL */
23020 + AuDebugOn(!inode);
23021 + AuTraceErrPtr(inode);
23025 +/* lock free root dinfo */
23026 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
23029 + aufs_bindex_t bindex, bend;
23030 + struct path path;
23031 + struct au_hdentry *hdp;
23032 + struct au_branch *br;
23036 + bend = au_sbend(sb);
23037 + hdp = au_di(sb->s_root)->di_hdentry;
23038 + for (bindex = 0; !err && bindex <= bend; bindex++) {
23039 + br = au_sbr(sb, bindex);
23040 + path.mnt = br->br_mnt;
23041 + path.dentry = hdp[bindex].hd_dentry;
23042 + err = au_seq_path(seq, &path);
23044 + perm = au_optstr_br_perm(br->br_perm);
23046 + err = seq_printf(seq, "=%s", perm);
23053 + if (!err && bindex != bend)
23054 + err = seq_putc(seq, ':');
23060 +static void au_show_wbr_create(struct seq_file *m, int v,
23061 + struct au_sbinfo *sbinfo)
23065 + AuRwMustAnyLock(&sbinfo->si_rwsem);
23067 + seq_printf(m, ",create=");
23068 + pat = au_optstr_wbr_create(v);
23070 + case AuWbrCreate_TDP:
23071 + case AuWbrCreate_RR:
23072 + case AuWbrCreate_MFS:
23073 + case AuWbrCreate_PMFS:
23074 + seq_printf(m, pat);
23076 + case AuWbrCreate_MFSV:
23077 + seq_printf(m, /*pat*/"mfs:%lu",
23078 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
23081 + case AuWbrCreate_PMFSV:
23082 + seq_printf(m, /*pat*/"pmfs:%lu",
23083 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
23086 + case AuWbrCreate_MFSRR:
23087 + seq_printf(m, /*pat*/"mfsrr:%llu",
23088 + sbinfo->si_wbr_mfs.mfsrr_watermark);
23090 + case AuWbrCreate_MFSRRV:
23091 + seq_printf(m, /*pat*/"mfsrr:%llu:%lu",
23092 + sbinfo->si_wbr_mfs.mfsrr_watermark,
23093 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
23099 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
23101 +#ifdef CONFIG_SYSFS
23105 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
23106 + aufs_bindex_t bindex, brid;
23107 + struct qstr *name;
23109 + struct dentry *d, *h_root;
23110 + struct au_hdentry *hdp;
23112 + AuRwMustAnyLock(&sbinfo->si_rwsem);
23115 + f = au_sbi(sb)->si_xib;
23119 + /* stop printing the default xino path on the first writable branch */
23121 + brid = au_xino_brid(sb);
23123 + bindex = au_br_index(sb, brid);
23124 + hdp = au_di(sb->s_root)->di_hdentry;
23125 + h_root = hdp[0 + bindex].hd_dentry;
23128 + name = &d->d_name;
23129 + /* safe ->d_parent because the file is unlinked */
23130 + if (d->d_parent == h_root
23131 + && name->len == len
23132 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
23135 + seq_puts(seq, ",xino=");
23136 + err = au_xino_path(seq, f);
23143 +/* seq_file will re-call me in case of too long string */
23144 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
23147 + unsigned int mnt_flags, v;
23148 + struct super_block *sb;
23149 + struct au_sbinfo *sbinfo;
23151 +#define AuBool(name, str) do { \
23152 + v = au_opt_test(mnt_flags, name); \
23153 + if (v != au_opt_test(AuOpt_Def, name)) \
23154 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
23157 +#define AuStr(name, str) do { \
23158 + v = mnt_flags & AuOptMask_##name; \
23159 + if (v != (AuOpt_Def & AuOptMask_##name)) \
23160 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
23163 +#define AuUInt(name, str, val) do { \
23164 + if (val != AUFS_##name##_DEF) \
23165 + seq_printf(m, "," #str "=%u", val); \
23168 + /* lock free root dinfo */
23169 + sb = dentry->d_sb;
23170 + si_noflush_read_lock(sb);
23171 + sbinfo = au_sbi(sb);
23172 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
23174 + mnt_flags = au_mntflags(sb);
23175 + if (au_opt_test(mnt_flags, XINO)) {
23176 + err = au_show_xino(m, sb);
23177 + if (unlikely(err))
23180 + seq_puts(m, ",noxino");
23182 + AuBool(TRUNC_XINO, trunc_xino);
23183 + AuStr(UDBA, udba);
23184 + AuBool(SHWH, shwh);
23185 + AuBool(PLINK, plink);
23186 + AuBool(DIO, dio);
23187 + /* AuBool(DIRPERM1, dirperm1); */
23188 + /* AuBool(REFROF, refrof); */
23190 + v = sbinfo->si_wbr_create;
23191 + if (v != AuWbrCreate_Def)
23192 + au_show_wbr_create(m, v, sbinfo);
23194 + v = sbinfo->si_wbr_copyup;
23195 + if (v != AuWbrCopyup_Def)
23196 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
23198 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
23199 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
23200 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
23202 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
23204 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
23205 + AuUInt(RDCACHE, rdcache, v);
23207 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
23208 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
23210 + AuBool(SUM, sum);
23211 + /* AuBool(SUM_W, wsum); */
23212 + AuBool(WARN_PERM, warn_perm);
23213 + AuBool(VERBOSE, verbose);
23216 + /* be sure to print "br:" last */
23217 + if (!sysaufs_brs) {
23218 + seq_puts(m, ",br:");
23219 + au_show_brs(m, sb);
23221 + si_read_unlock(sb);
23229 +/* ---------------------------------------------------------------------- */
23231 +/* sum mode which returns the summation for statfs(2) */
23233 +static u64 au_add_till_max(u64 a, u64 b)
23241 + return ULLONG_MAX;
23244 +static u64 au_mul_till_max(u64 a, long mul)
23252 + return ULLONG_MAX;
23255 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
23258 + long bsize, factor;
23259 + u64 blocks, bfree, bavail, files, ffree;
23260 + aufs_bindex_t bend, bindex, i;
23261 + unsigned char shared;
23262 + struct path h_path;
23263 + struct super_block *h_sb;
23266 + bsize = LONG_MAX;
23272 + bend = au_sbend(sb);
23273 + for (bindex = 0; bindex <= bend; bindex++) {
23274 + h_path.mnt = au_sbr_mnt(sb, bindex);
23275 + h_sb = h_path.mnt->mnt_sb;
23277 + for (i = 0; !shared && i < bindex; i++)
23278 + shared = (au_sbr_sb(sb, i) == h_sb);
23282 + /* sb->s_root for NFS is unreliable */
23283 + h_path.dentry = h_path.mnt->mnt_root;
23284 + err = vfs_statfs(&h_path, buf);
23285 + if (unlikely(err))
23288 + if (bsize > buf->f_bsize) {
23290 + * we will reduce bsize, so we have to expand blocks
23291 + * etc. to match them again
23293 + factor = (bsize / buf->f_bsize);
23294 + blocks = au_mul_till_max(blocks, factor);
23295 + bfree = au_mul_till_max(bfree, factor);
23296 + bavail = au_mul_till_max(bavail, factor);
23297 + bsize = buf->f_bsize;
23300 + factor = (buf->f_bsize / bsize);
23301 + blocks = au_add_till_max(blocks,
23302 + au_mul_till_max(buf->f_blocks, factor));
23303 + bfree = au_add_till_max(bfree,
23304 + au_mul_till_max(buf->f_bfree, factor));
23305 + bavail = au_add_till_max(bavail,
23306 + au_mul_till_max(buf->f_bavail, factor));
23307 + files = au_add_till_max(files, buf->f_files);
23308 + ffree = au_add_till_max(ffree, buf->f_ffree);
23311 + buf->f_bsize = bsize;
23312 + buf->f_blocks = blocks;
23313 + buf->f_bfree = bfree;
23314 + buf->f_bavail = bavail;
23315 + buf->f_files = files;
23316 + buf->f_ffree = ffree;
23317 + buf->f_frsize = 0;
23323 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
23326 + struct path h_path;
23327 + struct super_block *sb;
23329 + /* lock free root dinfo */
23330 + sb = dentry->d_sb;
23331 + si_noflush_read_lock(sb);
23332 + if (!au_opt_test(au_mntflags(sb), SUM)) {
23333 + /* sb->s_root for NFS is unreliable */
23334 + h_path.mnt = au_sbr_mnt(sb, 0);
23335 + h_path.dentry = h_path.mnt->mnt_root;
23336 + err = vfs_statfs(&h_path, buf);
23338 + err = au_statfs_sum(sb, buf);
23339 + si_read_unlock(sb);
23342 + buf->f_type = AUFS_SUPER_MAGIC;
23343 + buf->f_namelen = AUFS_MAX_NAMELEN;
23344 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
23346 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
23351 +/* ---------------------------------------------------------------------- */
23353 +/* final actions when unmounting a file system */
23354 +static void aufs_put_super(struct super_block *sb)
23356 + struct au_sbinfo *sbinfo;
23358 + sbinfo = au_sbi(sb);
23362 + dbgaufs_si_fin(sbinfo);
23363 + kobject_put(&sbinfo->si_kobj);
23366 +/* ---------------------------------------------------------------------- */
23368 +void au_array_free(void *array)
23371 + if (!is_vmalloc_addr(array))
23378 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg)
23381 + unsigned long long n;
23388 + if (*hint > ULLONG_MAX / sizeof(array)) {
23389 + array = ERR_PTR(-EMFILE);
23390 + pr_err("hint %llu\n", *hint);
23394 + array = kmalloc(sizeof(array) * *hint, GFP_NOFS);
23395 + if (unlikely(!array))
23396 + array = vmalloc(sizeof(array) * *hint);
23397 + if (unlikely(!array)) {
23398 + array = ERR_PTR(-ENOMEM);
23402 + n = cb(array, *hint, arg);
23403 + AuDebugOn(n > *hint);
23410 +static unsigned long long au_iarray_cb(void *a,
23411 + unsigned long long max __maybe_unused,
23414 + unsigned long long n;
23415 + struct inode **p, *inode;
23416 + struct list_head *head;
23421 + spin_lock(&inode_sb_list_lock);
23422 + list_for_each_entry(inode, head, i_sb_list) {
23423 + if (!is_bad_inode(inode)
23424 + && au_ii(inode)->ii_bstart >= 0) {
23425 + spin_lock(&inode->i_lock);
23426 + if (atomic_read(&inode->i_count)) {
23430 + AuDebugOn(n > max);
23432 + spin_unlock(&inode->i_lock);
23435 + spin_unlock(&inode_sb_list_lock);
23440 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
23442 + *max = atomic_long_read(&au_sbi(sb)->si_ninodes);
23443 + return au_array_alloc(max, au_iarray_cb, &sb->s_inodes);
23446 +void au_iarray_free(struct inode **a, unsigned long long max)
23448 + unsigned long long ull;
23450 + for (ull = 0; ull < max; ull++)
23452 + au_array_free(a);
23455 +/* ---------------------------------------------------------------------- */
23458 + * refresh dentry and inode at remount time.
23460 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
23461 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
23462 + struct dentry *parent)
23466 + di_write_lock_child(dentry);
23467 + di_read_lock_parent(parent, AuLock_IR);
23468 + err = au_refresh_dentry(dentry, parent);
23469 + if (!err && dir_flags)
23470 + au_hn_reset(dentry->d_inode, dir_flags);
23471 + di_read_unlock(parent, AuLock_IR);
23472 + di_write_unlock(dentry);
23477 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
23478 + struct au_sbinfo *sbinfo,
23479 + const unsigned int dir_flags)
23482 + struct dentry *parent;
23483 + struct inode *inode;
23486 + parent = dget_parent(dentry);
23487 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
23488 + inode = dentry->d_inode;
23490 + if (!S_ISDIR(inode->i_mode))
23491 + err = au_do_refresh(dentry, /*dir_flags*/0,
23494 + err = au_do_refresh(dentry, dir_flags, parent);
23495 + if (unlikely(err))
23496 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
23499 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
23500 + AuDbgDentry(dentry);
23508 +static int au_refresh_d(struct super_block *sb)
23510 + int err, i, j, ndentry, e;
23511 + unsigned int sigen;
23512 + struct au_dcsub_pages dpages;
23513 + struct au_dpage *dpage;
23514 + struct dentry **dentries, *d;
23515 + struct au_sbinfo *sbinfo;
23516 + struct dentry *root = sb->s_root;
23517 + const unsigned int dir_flags = au_hi_flags(root->d_inode, /*isdir*/1);
23519 + err = au_dpages_init(&dpages, GFP_NOFS);
23520 + if (unlikely(err))
23522 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
23523 + if (unlikely(err))
23526 + sigen = au_sigen(sb);
23527 + sbinfo = au_sbi(sb);
23528 + for (i = 0; i < dpages.ndpage; i++) {
23529 + dpage = dpages.dpages + i;
23530 + dentries = dpage->dentries;
23531 + ndentry = dpage->ndentry;
23532 + for (j = 0; j < ndentry; j++) {
23534 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags);
23535 + if (unlikely(e && !err))
23537 + /* go on even err */
23542 + au_dpages_free(&dpages);
23547 +static int au_refresh_i(struct super_block *sb)
23550 + unsigned int sigen;
23551 + unsigned long long max, ull;
23552 + struct inode *inode, **array;
23554 + array = au_iarray_alloc(sb, &max);
23555 + err = PTR_ERR(array);
23556 + if (IS_ERR(array))
23560 + sigen = au_sigen(sb);
23561 + for (ull = 0; ull < max; ull++) {
23562 + inode = array[ull];
23563 + if (au_iigen(inode) != sigen) {
23564 + ii_write_lock_child(inode);
23565 + e = au_refresh_hinode_self(inode);
23566 + ii_write_unlock(inode);
23567 + if (unlikely(e)) {
23568 + pr_err("error %d, i%lu\n", e, inode->i_ino);
23571 + /* go on even if err */
23576 + au_iarray_free(array, max);
23582 +static void au_remount_refresh(struct super_block *sb)
23585 + unsigned int udba;
23586 + aufs_bindex_t bindex, bend;
23587 + struct dentry *root;
23588 + struct inode *inode;
23589 + struct au_branch *br;
23591 + au_sigen_inc(sb);
23592 + au_fclr_si(au_sbi(sb), FAILED_REFRESH_DIR);
23594 + root = sb->s_root;
23595 + DiMustNoWaiters(root);
23596 + inode = root->d_inode;
23597 + IiMustNoWaiters(inode);
23599 + udba = au_opt_udba(sb);
23600 + bend = au_sbend(sb);
23601 + for (bindex = 0; bindex <= bend; bindex++) {
23602 + br = au_sbr(sb, bindex);
23603 + err = au_hnotify_reset_br(udba, br, br->br_perm);
23604 + if (unlikely(err))
23605 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
23607 + /* go on even if err */
23609 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
23611 + di_write_unlock(root);
23612 + err = au_refresh_d(sb);
23613 + e = au_refresh_i(sb);
23614 + if (unlikely(e && !err))
23616 + /* aufs_write_lock() calls ..._child() */
23617 + di_write_lock_child(root);
23619 + au_cpup_attr_all(inode, /*force*/1);
23621 + if (unlikely(err))
23622 + AuIOErr("refresh failed, ignored, %d\n", err);
23625 +/* stop extra interpretation of errno in mount(8), and strange error messages */
23626 +static int cvt_err(int err)
23640 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
23643 + unsigned int mntflags;
23644 + struct au_opts opts;
23645 + struct dentry *root;
23646 + struct inode *inode;
23647 + struct au_sbinfo *sbinfo;
23650 + root = sb->s_root;
23651 + if (!data || !*data) {
23652 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
23654 + di_write_lock_child(root);
23655 + err = au_opts_verify(sb, *flags, /*pending*/0);
23656 + aufs_write_unlock(root);
23662 + memset(&opts, 0, sizeof(opts));
23663 + opts.opt = (void *)__get_free_page(GFP_NOFS);
23664 + if (unlikely(!opts.opt))
23666 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
23667 + opts.flags = AuOpts_REMOUNT;
23668 + opts.sb_flags = *flags;
23670 + /* parse it before aufs lock */
23671 + err = au_opts_parse(sb, data, &opts);
23672 + if (unlikely(err))
23675 + sbinfo = au_sbi(sb);
23676 + inode = root->d_inode;
23677 + mutex_lock(&inode->i_mutex);
23678 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
23679 + if (unlikely(err))
23681 + di_write_lock_child(root);
23683 + /* au_opts_remount() may return an error */
23684 + err = au_opts_remount(sb, &opts);
23685 + au_opts_free(&opts);
23687 + if (au_ftest_opts(opts.flags, REFRESH))
23688 + au_remount_refresh(sb);
23690 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
23691 + mntflags = au_mntflags(sb);
23692 + do_dx = !!au_opt_test(mntflags, DIO);
23693 + au_dy_arefresh(do_dx);
23696 + aufs_write_unlock(root);
23699 + mutex_unlock(&inode->i_mutex);
23701 + free_page((unsigned long)opts.opt);
23703 + err = cvt_err(err);
23708 +static const struct super_operations aufs_sop = {
23709 + .alloc_inode = aufs_alloc_inode,
23710 + .destroy_inode = aufs_destroy_inode,
23711 + /* always deleting, no clearing */
23712 + .drop_inode = generic_delete_inode,
23713 + .show_options = aufs_show_options,
23714 + .statfs = aufs_statfs,
23715 + .put_super = aufs_put_super,
23716 + .remount_fs = aufs_remount_fs
23719 +/* ---------------------------------------------------------------------- */
23721 +static int alloc_root(struct super_block *sb)
23724 + struct inode *inode;
23725 + struct dentry *root;
23728 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
23729 + err = PTR_ERR(inode);
23730 + if (IS_ERR(inode))
23733 + inode->i_op = &aufs_dir_iop;
23734 + inode->i_fop = &aufs_dir_fop;
23735 + inode->i_mode = S_IFDIR;
23736 + set_nlink(inode, 2);
23737 + unlock_new_inode(inode);
23739 + root = d_make_root(inode);
23740 + if (unlikely(!root))
23742 + err = PTR_ERR(root);
23743 + if (IS_ERR(root))
23746 + err = au_di_init(root);
23748 + sb->s_root = root;
23749 + return 0; /* success */
23757 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
23758 + int silent __maybe_unused)
23761 + struct au_opts opts;
23762 + struct dentry *root;
23763 + struct inode *inode;
23764 + char *arg = raw_data;
23766 + if (unlikely(!arg || !*arg)) {
23768 + pr_err("no arg\n");
23773 + memset(&opts, 0, sizeof(opts));
23774 + opts.opt = (void *)__get_free_page(GFP_NOFS);
23775 + if (unlikely(!opts.opt))
23777 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
23778 + opts.sb_flags = sb->s_flags;
23780 + err = au_si_alloc(sb);
23781 + if (unlikely(err))
23784 + /* all timestamps always follow the ones on the branch */
23785 + sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
23786 + sb->s_op = &aufs_sop;
23787 + sb->s_d_op = &aufs_dop;
23788 + sb->s_magic = AUFS_SUPER_MAGIC;
23789 + sb->s_maxbytes = 0;
23790 + au_export_init(sb);
23792 + err = alloc_root(sb);
23793 + if (unlikely(err)) {
23794 + si_write_unlock(sb);
23797 + root = sb->s_root;
23798 + inode = root->d_inode;
23801 + * actually we can parse options regardless aufs lock here.
23802 + * but at remount time, parsing must be done before aufs lock.
23803 + * so we follow the same rule.
23805 + ii_write_lock_parent(inode);
23806 + aufs_write_unlock(root);
23807 + err = au_opts_parse(sb, arg, &opts);
23808 + if (unlikely(err))
23811 + /* lock vfs_inode first, then aufs. */
23812 + mutex_lock(&inode->i_mutex);
23813 + aufs_write_lock(root);
23814 + err = au_opts_mount(sb, &opts);
23815 + au_opts_free(&opts);
23816 + aufs_write_unlock(root);
23817 + mutex_unlock(&inode->i_mutex);
23819 + goto out_opts; /* success */
23823 + sb->s_root = NULL;
23825 + dbgaufs_si_fin(au_sbi(sb));
23826 + kobject_put(&au_sbi(sb)->si_kobj);
23827 + sb->s_fs_info = NULL;
23829 + free_page((unsigned long)opts.opt);
23832 + err = cvt_err(err);
23837 +/* ---------------------------------------------------------------------- */
23839 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
23840 + const char *dev_name __maybe_unused,
23843 + struct dentry *root;
23844 + struct super_block *sb;
23846 + /* all timestamps always follow the ones on the branch */
23847 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
23848 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
23849 + if (IS_ERR(root))
23853 + si_write_lock(sb, !AuLock_FLUSH);
23854 + sysaufs_brs_add(sb, 0);
23855 + si_write_unlock(sb);
23856 + au_sbilist_add(sb);
23862 +static void aufs_kill_sb(struct super_block *sb)
23864 + struct au_sbinfo *sbinfo;
23866 + sbinfo = au_sbi(sb);
23868 + au_sbilist_del(sb);
23869 + aufs_write_lock(sb->s_root);
23870 + if (sbinfo->si_wbr_create_ops->fin)
23871 + sbinfo->si_wbr_create_ops->fin(sb);
23872 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
23873 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
23874 + au_remount_refresh(sb);
23876 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
23877 + au_plink_put(sb, /*verbose*/1);
23879 + sbinfo->si_sb = NULL;
23880 + aufs_write_unlock(sb->s_root);
23881 + au_nwt_flush(&sbinfo->si_nowait);
23883 + generic_shutdown_super(sb);
23886 +struct file_system_type aufs_fs_type = {
23887 + .name = AUFS_FSTYPE,
23889 + FS_RENAME_DOES_D_MOVE /* a race between rename and others */
23890 + | FS_REVAL_DOT, /* for NFS branch and udba */
23891 + .mount = aufs_mount,
23892 + .kill_sb = aufs_kill_sb,
23893 + /* no need to __module_get() and module_put(). */
23894 + .owner = THIS_MODULE,
23896 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
23897 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
23898 +++ linux/fs/aufs/super.h 2012-07-22 19:57:03.164337936 +0200
23901 + * Copyright (C) 2005-2012 Junjiro R. Okajima
23903 + * This program, aufs is free software; you can redistribute it and/or modify
23904 + * it under the terms of the GNU General Public License as published by
23905 + * the Free Software Foundation; either version 2 of the License, or
23906 + * (at your option) any later version.
23908 + * This program is distributed in the hope that it will be useful,
23909 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23910 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23911 + * GNU General Public License for more details.
23913 + * You should have received a copy of the GNU General Public License
23914 + * along with this program; if not, write to the Free Software
23915 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23919 + * super_block operations
23922 +#ifndef __AUFS_SUPER_H__
23923 +#define __AUFS_SUPER_H__
23927 +#include <linux/fs.h>
23928 +#include "rwsem.h"
23932 +typedef ssize_t (*au_readf_t)(struct file *, char __user *, size_t, loff_t *);
23933 +typedef ssize_t (*au_writef_t)(struct file *, const char __user *, size_t,
23936 +/* policies to select one among multiple writable branches */
23937 +struct au_wbr_copyup_operations {
23938 + int (*copyup)(struct dentry *dentry);
23941 +struct au_wbr_create_operations {
23942 + int (*create)(struct dentry *dentry, int isdir);
23943 + int (*init)(struct super_block *sb);
23944 + int (*fin)(struct super_block *sb);
23947 +struct au_wbr_mfs {
23948 + struct mutex mfs_lock; /* protect this structure */
23949 + unsigned long mfs_jiffy;
23950 + unsigned long mfs_expire;
23951 + aufs_bindex_t mfs_bindex;
23953 + unsigned long long mfsrr_bytes;
23954 + unsigned long long mfsrr_watermark;
23958 +struct au_sbinfo {
23959 + /* nowait tasks in the system-wide workqueue */
23960 + struct au_nowait_tasks si_nowait;
23963 + * tried sb->s_umount, but failed due to the dependecy between i_mutex.
23964 + * rwsem for au_sbinfo is necessary.
23966 + struct au_rwsem si_rwsem;
23968 + /* prevent recursive locking in deleting inode */
23970 + unsigned long *bitmap;
23971 + spinlock_t tree_lock;
23972 + struct radix_tree_root tree;
23976 + * dirty approach to protect sb->sb_inodes and ->s_files from remount.
23978 + atomic_long_t si_ninodes, si_nfiles;
23980 + /* branch management */
23981 + unsigned int si_generation;
23983 + /* see above flags */
23984 + unsigned char au_si_status;
23986 + aufs_bindex_t si_bend;
23988 + /* dirty trick to keep br_id plus */
23989 + unsigned int si_last_br_id :
23990 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
23991 + struct au_branch **si_branch;
23993 + /* policy to select a writable branch */
23994 + unsigned char si_wbr_copyup;
23995 + unsigned char si_wbr_create;
23996 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
23997 + struct au_wbr_create_operations *si_wbr_create_ops;
23999 + /* round robin */
24000 + atomic_t si_wbr_rr_next;
24002 + /* most free space */
24003 + struct au_wbr_mfs si_wbr_mfs;
24005 + /* mount flags */
24006 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
24007 + unsigned int si_mntflags;
24009 + /* external inode number (bitmap and translation table) */
24010 + au_readf_t si_xread;
24011 + au_writef_t si_xwrite;
24012 + struct file *si_xib;
24013 + struct mutex si_xib_mtx; /* protect xib members */
24014 + unsigned long *si_xib_buf;
24015 + unsigned long si_xib_last_pindex;
24016 + int si_xib_next_bit;
24017 + aufs_bindex_t si_xino_brid;
24018 + /* reserved for future use */
24019 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
24021 +#ifdef CONFIG_AUFS_EXPORT
24022 + /* i_generation */
24023 + struct file *si_xigen;
24024 + atomic_t si_xigen_next;
24027 + /* vdir parameters */
24028 + unsigned long si_rdcache; /* max cache time in jiffies */
24029 + unsigned int si_rdblk; /* deblk size */
24030 + unsigned int si_rdhash; /* hash size */
24033 + * If the number of whiteouts are larger than si_dirwh, leave all of
24034 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
24035 + * future fsck.aufs or kernel thread will remove them later.
24036 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
24038 + unsigned int si_dirwh;
24041 + * rename(2) a directory with all children.
24043 + /* reserved for future use */
24044 + /* int si_rendir; */
24046 + /* pseudo_link list */
24047 + struct au_splhead si_plink;
24048 + wait_queue_head_t si_plink_wq;
24049 + spinlock_t si_plink_maint_lock;
24050 + pid_t si_plink_maint_pid;
24053 + * sysfs and lifetime management.
24054 + * this is not a small structure and it may be a waste of memory in case
24055 + * of sysfs is disabled, particulary when many aufs-es are mounted.
24056 + * but using sysfs is majority.
24058 + struct kobject si_kobj;
24059 +#ifdef CONFIG_DEBUG_FS
24060 + struct dentry *si_dbgaufs, *si_dbgaufs_xib;
24061 +#ifdef CONFIG_AUFS_EXPORT
24062 + struct dentry *si_dbgaufs_xigen;
24066 +#ifdef CONFIG_AUFS_SBILIST
24067 + struct list_head si_list;
24070 + /* dirty, necessary for unmounting, sysfs and sysrq */
24071 + struct super_block *si_sb;
24074 +/* sbinfo status flags */
24076 + * set true when refresh_dirs() failed at remount time.
24077 + * then try refreshing dirs at access time again.
24078 + * if it is false, refreshing dirs at access time is unnecesary
24080 +#define AuSi_FAILED_REFRESH_DIR 1
24081 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
24082 + unsigned int flag)
24084 + AuRwMustAnyLock(&sbi->si_rwsem);
24085 + return sbi->au_si_status & flag;
24087 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
24088 +#define au_fset_si(sbinfo, name) do { \
24089 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
24090 + (sbinfo)->au_si_status |= AuSi_##name; \
24092 +#define au_fclr_si(sbinfo, name) do { \
24093 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
24094 + (sbinfo)->au_si_status &= ~AuSi_##name; \
24097 +/* ---------------------------------------------------------------------- */
24099 +/* policy to select one among writable branches */
24100 +#define AuWbrCopyup(sbinfo, ...) \
24101 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
24102 +#define AuWbrCreate(sbinfo, ...) \
24103 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
24105 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
24106 +#define AuLock_DW 1 /* write-lock dentry */
24107 +#define AuLock_IR (1 << 1) /* read-lock inode */
24108 +#define AuLock_IW (1 << 2) /* write-lock inode */
24109 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
24110 +#define AuLock_DIR (1 << 4) /* target is a dir */
24111 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
24112 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
24113 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
24114 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
24115 +#define au_fset_lock(flags, name) \
24116 + do { (flags) |= AuLock_##name; } while (0)
24117 +#define au_fclr_lock(flags, name) \
24118 + do { (flags) &= ~AuLock_##name; } while (0)
24120 +/* ---------------------------------------------------------------------- */
24123 +extern struct file_system_type aufs_fs_type;
24124 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
24125 +typedef unsigned long long (*au_arraycb_t)(void *array, unsigned long long max,
24127 +void au_array_free(void *array);
24128 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg);
24129 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
24130 +void au_iarray_free(struct inode **a, unsigned long long max);
24133 +void au_si_free(struct kobject *kobj);
24134 +int au_si_alloc(struct super_block *sb);
24135 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr);
24137 +unsigned int au_sigen_inc(struct super_block *sb);
24138 +aufs_bindex_t au_new_br_id(struct super_block *sb);
24140 +int si_read_lock(struct super_block *sb, int flags);
24141 +int si_write_lock(struct super_block *sb, int flags);
24142 +int aufs_read_lock(struct dentry *dentry, int flags);
24143 +void aufs_read_unlock(struct dentry *dentry, int flags);
24144 +void aufs_write_lock(struct dentry *dentry);
24145 +void aufs_write_unlock(struct dentry *dentry);
24146 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
24147 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
24149 +int si_pid_test_slow(struct super_block *sb);
24150 +void si_pid_set_slow(struct super_block *sb);
24151 +void si_pid_clr_slow(struct super_block *sb);
24153 +/* wbr_policy.c */
24154 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
24155 +extern struct au_wbr_create_operations au_wbr_create_ops[];
24156 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
24158 +/* ---------------------------------------------------------------------- */
24160 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
24162 + return sb->s_fs_info;
24165 +/* ---------------------------------------------------------------------- */
24167 +#ifdef CONFIG_AUFS_EXPORT
24168 +void au_export_init(struct super_block *sb);
24170 +static inline int au_test_nfsd(void)
24172 + struct task_struct *tsk = current;
24174 + return (tsk->flags & PF_KTHREAD)
24175 + && !strcmp(tsk->comm, "nfsd");
24178 +void au_xigen_inc(struct inode *inode);
24179 +int au_xigen_new(struct inode *inode);
24180 +int au_xigen_set(struct super_block *sb, struct file *base);
24181 +void au_xigen_clr(struct super_block *sb);
24183 +static inline int au_busy_or_stale(void)
24185 + if (!au_test_nfsd())
24190 +AuStubVoid(au_export_init, struct super_block *sb)
24191 +AuStubInt0(au_test_nfsd, void)
24192 +AuStubVoid(au_xigen_inc, struct inode *inode)
24193 +AuStubInt0(au_xigen_new, struct inode *inode)
24194 +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base)
24195 +AuStubVoid(au_xigen_clr, struct super_block *sb)
24196 +static inline int au_busy_or_stale(void)
24200 +#endif /* CONFIG_AUFS_EXPORT */
24202 +/* ---------------------------------------------------------------------- */
24204 +#ifdef CONFIG_AUFS_SBILIST
24206 +extern struct au_splhead au_sbilist;
24208 +static inline void au_sbilist_init(void)
24210 + au_spl_init(&au_sbilist);
24213 +static inline void au_sbilist_add(struct super_block *sb)
24215 + au_spl_add(&au_sbi(sb)->si_list, &au_sbilist);
24218 +static inline void au_sbilist_del(struct super_block *sb)
24220 + au_spl_del(&au_sbi(sb)->si_list, &au_sbilist);
24223 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
24224 +static inline void au_sbilist_lock(void)
24226 + spin_lock(&au_sbilist.spin);
24229 +static inline void au_sbilist_unlock(void)
24231 + spin_unlock(&au_sbilist.spin);
24233 +#define AuGFP_SBILIST GFP_ATOMIC
24235 +AuStubVoid(au_sbilist_lock, void)
24236 +AuStubVoid(au_sbilist_unlock, void)
24237 +#define AuGFP_SBILIST GFP_NOFS
24238 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
24240 +AuStubVoid(au_sbilist_init, void)
24241 +AuStubVoid(au_sbilist_add, struct super_block*)
24242 +AuStubVoid(au_sbilist_del, struct super_block*)
24243 +AuStubVoid(au_sbilist_lock, void)
24244 +AuStubVoid(au_sbilist_unlock, void)
24245 +#define AuGFP_SBILIST GFP_NOFS
24248 +/* ---------------------------------------------------------------------- */
24250 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
24253 + * This function is a dynamic '__init' fucntion actually,
24254 + * so the tiny check for si_rwsem is unnecessary.
24256 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
24257 +#ifdef CONFIG_DEBUG_FS
24258 + sbinfo->si_dbgaufs = NULL;
24259 + sbinfo->si_dbgaufs_xib = NULL;
24260 +#ifdef CONFIG_AUFS_EXPORT
24261 + sbinfo->si_dbgaufs_xigen = NULL;
24266 +/* ---------------------------------------------------------------------- */
24268 +static inline pid_t si_pid_bit(void)
24270 + /* the origin of pid is 1, but the bitmap's is 0 */
24271 + return current->pid - 1;
24274 +static inline int si_pid_test(struct super_block *sb)
24276 + pid_t bit = si_pid_bit();
24277 + if (bit < PID_MAX_DEFAULT)
24278 + return test_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
24280 + return si_pid_test_slow(sb);
24283 +static inline void si_pid_set(struct super_block *sb)
24285 + pid_t bit = si_pid_bit();
24286 + if (bit < PID_MAX_DEFAULT) {
24287 + AuDebugOn(test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
24288 + set_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
24291 + si_pid_set_slow(sb);
24294 +static inline void si_pid_clr(struct super_block *sb)
24296 + pid_t bit = si_pid_bit();
24297 + if (bit < PID_MAX_DEFAULT) {
24298 + AuDebugOn(!test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
24299 + clear_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
24302 + si_pid_clr_slow(sb);
24305 +/* ---------------------------------------------------------------------- */
24307 +/* lock superblock. mainly for entry point functions */
24309 + * __si_read_lock, __si_write_lock,
24310 + * __si_read_unlock, __si_write_unlock, __si_downgrade_lock
24312 +AuSimpleRwsemFuncs(__si, struct super_block *sb, &au_sbi(sb)->si_rwsem);
24314 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
24315 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
24316 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
24318 +static inline void si_noflush_read_lock(struct super_block *sb)
24320 + __si_read_lock(sb);
24324 +static inline int si_noflush_read_trylock(struct super_block *sb)
24326 + int locked = __si_read_trylock(sb);
24332 +static inline void si_noflush_write_lock(struct super_block *sb)
24334 + __si_write_lock(sb);
24338 +static inline int si_noflush_write_trylock(struct super_block *sb)
24340 + int locked = __si_write_trylock(sb);
24346 +#if 0 /* unused */
24347 +static inline int si_read_trylock(struct super_block *sb, int flags)
24349 + if (au_ftest_lock(flags, FLUSH))
24350 + au_nwt_flush(&au_sbi(sb)->si_nowait);
24351 + return si_noflush_read_trylock(sb);
24355 +static inline void si_read_unlock(struct super_block *sb)
24358 + __si_read_unlock(sb);
24361 +#if 0 /* unused */
24362 +static inline int si_write_trylock(struct super_block *sb, int flags)
24364 + if (au_ftest_lock(flags, FLUSH))
24365 + au_nwt_flush(&au_sbi(sb)->si_nowait);
24366 + return si_noflush_write_trylock(sb);
24370 +static inline void si_write_unlock(struct super_block *sb)
24373 + __si_write_unlock(sb);
24376 +#if 0 /* unused */
24377 +static inline void si_downgrade_lock(struct super_block *sb)
24379 + __si_downgrade_lock(sb);
24383 +/* ---------------------------------------------------------------------- */
24385 +static inline aufs_bindex_t au_sbend(struct super_block *sb)
24387 + SiMustAnyLock(sb);
24388 + return au_sbi(sb)->si_bend;
24391 +static inline unsigned int au_mntflags(struct super_block *sb)
24393 + SiMustAnyLock(sb);
24394 + return au_sbi(sb)->si_mntflags;
24397 +static inline unsigned int au_sigen(struct super_block *sb)
24399 + SiMustAnyLock(sb);
24400 + return au_sbi(sb)->si_generation;
24403 +static inline void au_ninodes_inc(struct super_block *sb)
24405 + atomic_long_inc(&au_sbi(sb)->si_ninodes);
24408 +static inline void au_ninodes_dec(struct super_block *sb)
24410 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_ninodes));
24411 + atomic_long_dec(&au_sbi(sb)->si_ninodes);
24414 +static inline void au_nfiles_inc(struct super_block *sb)
24416 + atomic_long_inc(&au_sbi(sb)->si_nfiles);
24419 +static inline void au_nfiles_dec(struct super_block *sb)
24421 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_nfiles));
24422 + atomic_long_dec(&au_sbi(sb)->si_nfiles);
24425 +static inline struct au_branch *au_sbr(struct super_block *sb,
24426 + aufs_bindex_t bindex)
24428 + SiMustAnyLock(sb);
24429 + return au_sbi(sb)->si_branch[0 + bindex];
24432 +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid)
24434 + SiMustWriteLock(sb);
24435 + au_sbi(sb)->si_xino_brid = brid;
24438 +static inline aufs_bindex_t au_xino_brid(struct super_block *sb)
24440 + SiMustAnyLock(sb);
24441 + return au_sbi(sb)->si_xino_brid;
24444 +#endif /* __KERNEL__ */
24445 +#endif /* __AUFS_SUPER_H__ */
24446 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
24447 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
24448 +++ linux/fs/aufs/sysaufs.c 2012-07-22 19:57:03.167671344 +0200
24451 + * Copyright (C) 2005-2012 Junjiro R. Okajima
24453 + * This program, aufs is free software; you can redistribute it and/or modify
24454 + * it under the terms of the GNU General Public License as published by
24455 + * the Free Software Foundation; either version 2 of the License, or
24456 + * (at your option) any later version.
24458 + * This program is distributed in the hope that it will be useful,
24459 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24460 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24461 + * GNU General Public License for more details.
24463 + * You should have received a copy of the GNU General Public License
24464 + * along with this program; if not, write to the Free Software
24465 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24469 + * sysfs interface and lifetime management
24470 + * they are necessary regardless sysfs is disabled.
24473 +#include <linux/random.h>
24476 +unsigned long sysaufs_si_mask;
24477 +struct kset *sysaufs_kset;
24479 +#define AuSiAttr(_name) { \
24480 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
24481 + .show = sysaufs_si_##_name, \
24484 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
24485 +struct attribute *sysaufs_si_attrs[] = {
24486 + &sysaufs_si_attr_xi_path.attr,
24490 +static const struct sysfs_ops au_sbi_ops = {
24491 + .show = sysaufs_si_show
24494 +static struct kobj_type au_sbi_ktype = {
24495 + .release = au_si_free,
24496 + .sysfs_ops = &au_sbi_ops,
24497 + .default_attrs = sysaufs_si_attrs
24500 +/* ---------------------------------------------------------------------- */
24502 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
24506 + sbinfo->si_kobj.kset = sysaufs_kset;
24507 + /* cf. sysaufs_name() */
24508 + err = kobject_init_and_add
24509 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
24510 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
24512 + dbgaufs_si_null(sbinfo);
24514 + err = dbgaufs_si_init(sbinfo);
24515 + if (unlikely(err))
24516 + kobject_put(&sbinfo->si_kobj);
24521 +void sysaufs_fin(void)
24524 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
24525 + kset_unregister(sysaufs_kset);
24528 +int __init sysaufs_init(void)
24533 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
24534 + } while (!sysaufs_si_mask);
24537 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
24538 + if (unlikely(!sysaufs_kset))
24540 + err = PTR_ERR(sysaufs_kset);
24541 + if (IS_ERR(sysaufs_kset))
24543 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
24544 + if (unlikely(err)) {
24545 + kset_unregister(sysaufs_kset);
24549 + err = dbgaufs_init();
24550 + if (unlikely(err))
24555 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
24556 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
24557 +++ linux/fs/aufs/sysaufs.h 2012-07-22 19:57:03.167671344 +0200
24560 + * Copyright (C) 2005-2012 Junjiro R. Okajima
24562 + * This program, aufs is free software; you can redistribute it and/or modify
24563 + * it under the terms of the GNU General Public License as published by
24564 + * the Free Software Foundation; either version 2 of the License, or
24565 + * (at your option) any later version.
24567 + * This program is distributed in the hope that it will be useful,
24568 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24569 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24570 + * GNU General Public License for more details.
24572 + * You should have received a copy of the GNU General Public License
24573 + * along with this program; if not, write to the Free Software
24574 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24578 + * sysfs interface and mount lifetime management
24581 +#ifndef __SYSAUFS_H__
24582 +#define __SYSAUFS_H__
24586 +#include <linux/sysfs.h>
24587 +#include "module.h"
24589 +struct super_block;
24592 +struct sysaufs_si_attr {
24593 + struct attribute attr;
24594 + int (*show)(struct seq_file *seq, struct super_block *sb);
24597 +/* ---------------------------------------------------------------------- */
24600 +extern unsigned long sysaufs_si_mask;
24601 +extern struct kset *sysaufs_kset;
24602 +extern struct attribute *sysaufs_si_attrs[];
24603 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
24604 +int __init sysaufs_init(void);
24605 +void sysaufs_fin(void);
24607 +/* ---------------------------------------------------------------------- */
24609 +/* some people doesn't like to show a pointer in kernel */
24610 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
24612 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
24615 +#define SysaufsSiNamePrefix "si_"
24616 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
24617 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
24619 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
24620 + sysaufs_si_id(sbinfo));
24624 +#ifdef CONFIG_SYSFS
24626 +extern struct attribute_group *sysaufs_attr_group;
24628 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
24629 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
24632 +void sysaufs_br_init(struct au_branch *br);
24633 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
24634 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
24636 +#define sysaufs_brs_init() do {} while (0)
24639 +#define sysaufs_attr_group NULL
24641 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
24644 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
24650 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
24651 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
24652 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
24654 +static inline void sysaufs_brs_init(void)
24659 +#endif /* CONFIG_SYSFS */
24661 +#endif /* __KERNEL__ */
24662 +#endif /* __SYSAUFS_H__ */
24663 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
24664 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
24665 +++ linux/fs/aufs/sysfs.c 2012-07-22 19:57:03.167671344 +0200
24668 + * Copyright (C) 2005-2012 Junjiro R. Okajima
24670 + * This program, aufs is free software; you can redistribute it and/or modify
24671 + * it under the terms of the GNU General Public License as published by
24672 + * the Free Software Foundation; either version 2 of the License, or
24673 + * (at your option) any later version.
24675 + * This program is distributed in the hope that it will be useful,
24676 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24677 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24678 + * GNU General Public License for more details.
24680 + * You should have received a copy of the GNU General Public License
24681 + * along with this program; if not, write to the Free Software
24682 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24686 + * sysfs interface
24689 +#include <linux/seq_file.h>
24692 +#ifdef CONFIG_AUFS_FS_MODULE
24693 +/* this entry violates the "one line per file" policy of sysfs */
24694 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
24698 + static char *conf =
24699 +/* this file is generated at compiling */
24700 +#include "conf.str"
24703 + err = snprintf(buf, PAGE_SIZE, conf);
24704 + if (unlikely(err >= PAGE_SIZE))
24709 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
24712 +static struct attribute *au_attr[] = {
24713 +#ifdef CONFIG_AUFS_FS_MODULE
24714 + &au_config_attr.attr,
24716 + NULL, /* need to NULL terminate the list of attributes */
24719 +static struct attribute_group sysaufs_attr_group_body = {
24723 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
24725 +/* ---------------------------------------------------------------------- */
24727 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
24731 + SiMustAnyLock(sb);
24734 + if (au_opt_test(au_mntflags(sb), XINO)) {
24735 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
24736 + seq_putc(seq, '\n');
24742 + * the lifetime of branch is independent from the entry under sysfs.
24743 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
24746 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
24747 + aufs_bindex_t bindex)
24750 + struct path path;
24751 + struct dentry *root;
24752 + struct au_branch *br;
24755 + AuDbg("b%d\n", bindex);
24758 + root = sb->s_root;
24759 + di_read_lock_parent(root, !AuLock_IR);
24760 + br = au_sbr(sb, bindex);
24761 + path.mnt = br->br_mnt;
24762 + path.dentry = au_h_dptr(root, bindex);
24763 + au_seq_path(seq, &path);
24764 + di_read_unlock(root, !AuLock_IR);
24765 + perm = au_optstr_br_perm(br->br_perm);
24767 + err = seq_printf(seq, "=%s\n", perm);
24776 +/* ---------------------------------------------------------------------- */
24778 +static struct seq_file *au_seq(char *p, ssize_t len)
24780 + struct seq_file *seq;
24782 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
24784 + /* mutex_init(&seq.lock); */
24787 + return seq; /* success */
24790 + seq = ERR_PTR(-ENOMEM);
24794 +#define SysaufsBr_PREFIX "br"
24796 +/* todo: file size may exceed PAGE_SIZE */
24797 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
24802 + aufs_bindex_t bend;
24803 + struct au_sbinfo *sbinfo;
24804 + struct super_block *sb;
24805 + struct seq_file *seq;
24807 + struct attribute **cattr;
24809 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
24810 + sb = sbinfo->si_sb;
24813 + * prevent a race condition between sysfs and aufs.
24814 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
24815 + * prohibits maintaining the sysfs entries.
24816 + * hew we acquire read lock after sysfs_get_active_two().
24817 + * on the other hand, the remount process may maintain the sysfs/aufs
24818 + * entries after acquiring write lock.
24819 + * it can cause a deadlock.
24820 + * simply we gave up processing read here.
24823 + if (unlikely(!si_noflush_read_trylock(sb)))
24826 + seq = au_seq(buf, PAGE_SIZE);
24827 + err = PTR_ERR(seq);
24831 + name = (void *)attr->name;
24832 + cattr = sysaufs_si_attrs;
24834 + if (!strcmp(name, (*cattr)->name)) {
24835 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
24842 + bend = au_sbend(sb);
24843 + if (!strncmp(name, SysaufsBr_PREFIX, sizeof(SysaufsBr_PREFIX) - 1)) {
24844 + name += sizeof(SysaufsBr_PREFIX) - 1;
24845 + err = kstrtol(name, 10, &l);
24848 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l);
24858 + err = seq->count;
24859 + /* sysfs limit */
24860 + if (unlikely(err == PAGE_SIZE))
24865 + si_read_unlock(sb);
24870 +/* ---------------------------------------------------------------------- */
24872 +void sysaufs_br_init(struct au_branch *br)
24874 + struct attribute *attr = &br->br_attr;
24876 + sysfs_attr_init(attr);
24877 + attr->name = br->br_name;
24878 + attr->mode = S_IRUGO;
24881 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
24883 + struct au_branch *br;
24884 + struct kobject *kobj;
24885 + aufs_bindex_t bend;
24887 + dbgaufs_brs_del(sb, bindex);
24889 + if (!sysaufs_brs)
24892 + kobj = &au_sbi(sb)->si_kobj;
24893 + bend = au_sbend(sb);
24894 + for (; bindex <= bend; bindex++) {
24895 + br = au_sbr(sb, bindex);
24896 + sysfs_remove_file(kobj, &br->br_attr);
24900 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
24903 + aufs_bindex_t bend;
24904 + struct kobject *kobj;
24905 + struct au_branch *br;
24907 + dbgaufs_brs_add(sb, bindex);
24909 + if (!sysaufs_brs)
24912 + kobj = &au_sbi(sb)->si_kobj;
24913 + bend = au_sbend(sb);
24914 + for (; bindex <= bend; bindex++) {
24915 + br = au_sbr(sb, bindex);
24916 + snprintf(br->br_name, sizeof(br->br_name), SysaufsBr_PREFIX
24918 + err = sysfs_create_file(kobj, &br->br_attr);
24919 + if (unlikely(err))
24920 + pr_warn("failed %s under sysfs(%d)\n",
24921 + br->br_name, err);
24924 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
24925 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
24926 +++ linux/fs/aufs/sysrq.c 2012-07-22 19:57:03.167671344 +0200
24929 + * Copyright (C) 2005-2012 Junjiro R. Okajima
24931 + * This program, aufs is free software; you can redistribute it and/or modify
24932 + * it under the terms of the GNU General Public License as published by
24933 + * the Free Software Foundation; either version 2 of the License, or
24934 + * (at your option) any later version.
24936 + * This program is distributed in the hope that it will be useful,
24937 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24938 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24939 + * GNU General Public License for more details.
24941 + * You should have received a copy of the GNU General Public License
24942 + * along with this program; if not, write to the Free Software
24943 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24947 + * magic sysrq hanlder
24950 +/* #include <linux/sysrq.h> */
24951 +#include <linux/writeback.h>
24954 +/* ---------------------------------------------------------------------- */
24956 +static void sysrq_sb(struct super_block *sb)
24959 + struct au_sbinfo *sbinfo;
24960 + struct file *file;
24962 + plevel = au_plevel;
24963 + au_plevel = KERN_WARNING;
24965 + sbinfo = au_sbi(sb);
24966 + /* since we define pr_fmt, call printk directly */
24967 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
24968 + printk(KERN_WARNING AUFS_NAME ": superblock\n");
24972 + printk(KERN_WARNING AUFS_NAME ": root dentry\n");
24973 + au_dpri_dentry(sb->s_root);
24974 + printk(KERN_WARNING AUFS_NAME ": root inode\n");
24975 + au_dpri_inode(sb->s_root->d_inode);
24980 + int err, i, j, ndentry;
24981 + struct au_dcsub_pages dpages;
24982 + struct au_dpage *dpage;
24984 + err = au_dpages_init(&dpages, GFP_ATOMIC);
24985 + if (unlikely(err))
24987 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
24989 + for (i = 0; i < dpages.ndpage; i++) {
24990 + dpage = dpages.dpages + i;
24991 + ndentry = dpage->ndentry;
24992 + for (j = 0; j < ndentry; j++)
24993 + au_dpri_dentry(dpage->dentries[j]);
24995 + au_dpages_free(&dpages);
25002 + printk(KERN_WARNING AUFS_NAME ": isolated inode\n");
25003 + spin_lock(&inode_sb_list_lock);
25004 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
25005 + spin_lock(&i->i_lock);
25006 + if (1 || list_empty(&i->i_dentry))
25007 + au_dpri_inode(i);
25008 + spin_unlock(&i->i_lock);
25010 + spin_unlock(&inode_sb_list_lock);
25013 + printk(KERN_WARNING AUFS_NAME ": files\n");
25014 + lg_global_lock(&files_lglock);
25015 + do_file_list_for_each_entry(sb, file) {
25017 + mode = file->f_dentry->d_inode->i_mode;
25018 + if (!special_file(mode) || au_special_file(mode))
25019 + au_dpri_file(file);
25020 + } while_file_list_for_each_entry;
25021 + lg_global_unlock(&files_lglock);
25022 + printk(KERN_WARNING AUFS_NAME ": done\n");
25024 + au_plevel = plevel;
25027 +/* ---------------------------------------------------------------------- */
25029 +/* module parameter */
25030 +static char *aufs_sysrq_key = "a";
25031 +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO);
25032 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
25034 +static void au_sysrq(int key __maybe_unused)
25036 + struct au_sbinfo *sbinfo;
25039 + au_sbilist_lock();
25040 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
25041 + sysrq_sb(sbinfo->si_sb);
25042 + au_sbilist_unlock();
25046 +static struct sysrq_key_op au_sysrq_op = {
25047 + .handler = au_sysrq,
25048 + .help_msg = "Aufs",
25049 + .action_msg = "Aufs",
25050 + .enable_mask = SYSRQ_ENABLE_DUMP
25053 +/* ---------------------------------------------------------------------- */
25055 +int __init au_sysrq_init(void)
25061 + key = *aufs_sysrq_key;
25062 + if ('a' <= key && key <= 'z')
25063 + err = register_sysrq_key(key, &au_sysrq_op);
25064 + if (unlikely(err))
25065 + pr_err("err %d, sysrq=%c\n", err, key);
25069 +void au_sysrq_fin(void)
25072 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
25073 + if (unlikely(err))
25074 + pr_err("err %d (ignored)\n", err);
25076 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
25077 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
25078 +++ linux/fs/aufs/vdir.c 2012-07-22 19:57:03.167671344 +0200
25081 + * Copyright (C) 2005-2012 Junjiro R. Okajima
25083 + * This program, aufs is free software; you can redistribute it and/or modify
25084 + * it under the terms of the GNU General Public License as published by
25085 + * the Free Software Foundation; either version 2 of the License, or
25086 + * (at your option) any later version.
25088 + * This program is distributed in the hope that it will be useful,
25089 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25090 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25091 + * GNU General Public License for more details.
25093 + * You should have received a copy of the GNU General Public License
25094 + * along with this program; if not, write to the Free Software
25095 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25099 + * virtual or vertical directory
25104 +static unsigned int calc_size(int nlen)
25106 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
25109 +static int set_deblk_end(union au_vdir_deblk_p *p,
25110 + union au_vdir_deblk_p *deblk_end)
25112 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
25113 + p->de->de_str.len = 0;
25117 + return -1; /* error */
25120 +/* returns true or false */
25121 +static int is_deblk_end(union au_vdir_deblk_p *p,
25122 + union au_vdir_deblk_p *deblk_end)
25124 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
25125 + return !p->de->de_str.len;
25129 +static unsigned char *last_deblk(struct au_vdir *vdir)
25131 + return vdir->vd_deblk[vdir->vd_nblk - 1];
25134 +/* ---------------------------------------------------------------------- */
25136 +/* estimate the apropriate size for name hash table */
25137 +unsigned int au_rdhash_est(loff_t sz)
25145 + if (sz < AUFS_RDHASH_DEF)
25146 + n = AUFS_RDHASH_DEF;
25147 + /* pr_info("n %u\n", n); */
25152 + * the allocated memory has to be freed by
25153 + * au_nhash_wh_free() or au_nhash_de_free().
25155 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
25157 + struct hlist_head *head;
25160 + head = kmalloc(sizeof(*nhash->nh_head) * num_hash, gfp);
25162 + nhash->nh_num = num_hash;
25163 + nhash->nh_head = head;
25164 + for (u = 0; u < num_hash; u++)
25165 + INIT_HLIST_HEAD(head++);
25166 + return 0; /* success */
25172 +static void nhash_count(struct hlist_head *head)
25176 + struct hlist_node *pos;
25179 + hlist_for_each(pos, head)
25181 + pr_info("%lu\n", n);
25185 +static void au_nhash_wh_do_free(struct hlist_head *head)
25187 + struct au_vdir_wh *tpos;
25188 + struct hlist_node *pos, *node;
25190 + hlist_for_each_entry_safe(tpos, pos, node, head, wh_hash) {
25191 + /* hlist_del(pos); */
25196 +static void au_nhash_de_do_free(struct hlist_head *head)
25198 + struct au_vdir_dehstr *tpos;
25199 + struct hlist_node *pos, *node;
25201 + hlist_for_each_entry_safe(tpos, pos, node, head, hash) {
25202 + /* hlist_del(pos); */
25203 + au_cache_free_vdir_dehstr(tpos);
25207 +static void au_nhash_do_free(struct au_nhash *nhash,
25208 + void (*free)(struct hlist_head *head))
25211 + struct hlist_head *head;
25213 + n = nhash->nh_num;
25217 + head = nhash->nh_head;
25218 + while (n-- > 0) {
25219 + nhash_count(head);
25222 + kfree(nhash->nh_head);
25225 +void au_nhash_wh_free(struct au_nhash *whlist)
25227 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
25230 +static void au_nhash_de_free(struct au_nhash *delist)
25232 + au_nhash_do_free(delist, au_nhash_de_do_free);
25235 +/* ---------------------------------------------------------------------- */
25237 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
25241 + unsigned int u, n;
25242 + struct hlist_head *head;
25243 + struct au_vdir_wh *tpos;
25244 + struct hlist_node *pos;
25247 + n = whlist->nh_num;
25248 + head = whlist->nh_head;
25249 + for (u = 0; u < n; u++, head++)
25250 + hlist_for_each_entry(tpos, pos, head, wh_hash)
25251 + if (tpos->wh_bindex == btgt && ++num > limit)
25256 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
25257 + unsigned char *name,
25258 + unsigned int len)
25261 + /* const unsigned int magic_bit = 12; */
25263 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
25268 + /* v = hash_long(v, magic_bit); */
25269 + v %= nhash->nh_num;
25270 + return nhash->nh_head + v;
25273 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
25276 + return str->len == nlen && !memcmp(str->name, name, nlen);
25279 +/* returns found or not */
25280 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
25282 + struct hlist_head *head;
25283 + struct au_vdir_wh *tpos;
25284 + struct hlist_node *pos;
25285 + struct au_vdir_destr *str;
25287 + head = au_name_hash(whlist, name, nlen);
25288 + hlist_for_each_entry(tpos, pos, head, wh_hash) {
25289 + str = &tpos->wh_str;
25290 + AuDbg("%.*s\n", str->len, str->name);
25291 + if (au_nhash_test_name(str, name, nlen))
25297 +/* returns found(true) or not */
25298 +static int test_known(struct au_nhash *delist, char *name, int nlen)
25300 + struct hlist_head *head;
25301 + struct au_vdir_dehstr *tpos;
25302 + struct hlist_node *pos;
25303 + struct au_vdir_destr *str;
25305 + head = au_name_hash(delist, name, nlen);
25306 + hlist_for_each_entry(tpos, pos, head, hash) {
25308 + AuDbg("%.*s\n", str->len, str->name);
25309 + if (au_nhash_test_name(str, name, nlen))
25315 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
25316 + unsigned char d_type)
25318 +#ifdef CONFIG_AUFS_SHWH
25319 + wh->wh_ino = ino;
25320 + wh->wh_type = d_type;
25324 +/* ---------------------------------------------------------------------- */
25326 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
25327 + unsigned int d_type, aufs_bindex_t bindex,
25328 + unsigned char shwh)
25331 + struct au_vdir_destr *str;
25332 + struct au_vdir_wh *wh;
25334 + AuDbg("%.*s\n", nlen, name);
25335 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
25338 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
25339 + if (unlikely(!wh))
25343 + wh->wh_bindex = bindex;
25345 + au_shwh_init_wh(wh, ino, d_type);
25346 + str = &wh->wh_str;
25348 + memcpy(str->name, name, nlen);
25349 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
25356 +static int append_deblk(struct au_vdir *vdir)
25359 + unsigned long ul;
25360 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
25361 + union au_vdir_deblk_p p, deblk_end;
25362 + unsigned char **o;
25365 + o = krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
25367 + if (unlikely(!o))
25370 + vdir->vd_deblk = o;
25371 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
25373 + ul = vdir->vd_nblk++;
25374 + vdir->vd_deblk[ul] = p.deblk;
25375 + vdir->vd_last.ul = ul;
25376 + vdir->vd_last.p.deblk = p.deblk;
25377 + deblk_end.deblk = p.deblk + deblk_sz;
25378 + err = set_deblk_end(&p, &deblk_end);
25385 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
25386 + unsigned int d_type, struct au_nhash *delist)
25390 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
25391 + union au_vdir_deblk_p p, *room, deblk_end;
25392 + struct au_vdir_dehstr *dehstr;
25394 + p.deblk = last_deblk(vdir);
25395 + deblk_end.deblk = p.deblk + deblk_sz;
25396 + room = &vdir->vd_last.p;
25397 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
25398 + || !is_deblk_end(room, &deblk_end));
25400 + sz = calc_size(nlen);
25401 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
25402 + err = append_deblk(vdir);
25403 + if (unlikely(err))
25406 + p.deblk = last_deblk(vdir);
25407 + deblk_end.deblk = p.deblk + deblk_sz;
25409 + AuDebugOn(room->deblk != p.deblk);
25413 + dehstr = au_cache_alloc_vdir_dehstr();
25414 + if (unlikely(!dehstr))
25417 + dehstr->str = &room->de->de_str;
25418 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
25419 + room->de->de_ino = ino;
25420 + room->de->de_type = d_type;
25421 + room->de->de_str.len = nlen;
25422 + memcpy(room->de->de_str.name, name, nlen);
25425 + room->deblk += sz;
25426 + if (unlikely(set_deblk_end(room, &deblk_end)))
25427 + err = append_deblk(vdir);
25434 +/* ---------------------------------------------------------------------- */
25436 +void au_vdir_free(struct au_vdir *vdir)
25438 + unsigned char **deblk;
25440 + deblk = vdir->vd_deblk;
25441 + while (vdir->vd_nblk--)
25443 + kfree(vdir->vd_deblk);
25444 + au_cache_free_vdir(vdir);
25447 +static struct au_vdir *alloc_vdir(struct file *file)
25449 + struct au_vdir *vdir;
25450 + struct super_block *sb;
25453 + sb = file->f_dentry->d_sb;
25454 + SiMustAnyLock(sb);
25457 + vdir = au_cache_alloc_vdir();
25458 + if (unlikely(!vdir))
25461 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
25462 + if (unlikely(!vdir->vd_deblk))
25465 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
25466 + if (!vdir->vd_deblk_sz) {
25467 + /* estimate the apropriate size for deblk */
25468 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
25469 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
25471 + vdir->vd_nblk = 0;
25472 + vdir->vd_version = 0;
25473 + vdir->vd_jiffy = 0;
25474 + err = append_deblk(vdir);
25476 + return vdir; /* success */
25478 + kfree(vdir->vd_deblk);
25481 + au_cache_free_vdir(vdir);
25483 + vdir = ERR_PTR(err);
25487 +static int reinit_vdir(struct au_vdir *vdir)
25490 + union au_vdir_deblk_p p, deblk_end;
25492 + while (vdir->vd_nblk > 1) {
25493 + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
25494 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
25497 + p.deblk = vdir->vd_deblk[0];
25498 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
25499 + err = set_deblk_end(&p, &deblk_end);
25500 + /* keep vd_dblk_sz */
25501 + vdir->vd_last.ul = 0;
25502 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
25503 + vdir->vd_version = 0;
25504 + vdir->vd_jiffy = 0;
25509 +/* ---------------------------------------------------------------------- */
25511 +#define AuFillVdir_CALLED 1
25512 +#define AuFillVdir_WHABLE (1 << 1)
25513 +#define AuFillVdir_SHWH (1 << 2)
25514 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
25515 +#define au_fset_fillvdir(flags, name) \
25516 + do { (flags) |= AuFillVdir_##name; } while (0)
25517 +#define au_fclr_fillvdir(flags, name) \
25518 + do { (flags) &= ~AuFillVdir_##name; } while (0)
25520 +#ifndef CONFIG_AUFS_SHWH
25521 +#undef AuFillVdir_SHWH
25522 +#define AuFillVdir_SHWH 0
25525 +struct fillvdir_arg {
25526 + struct file *file;
25527 + struct au_vdir *vdir;
25528 + struct au_nhash delist;
25529 + struct au_nhash whlist;
25530 + aufs_bindex_t bindex;
25531 + unsigned int flags;
25535 +static int fillvdir(void *__arg, const char *__name, int nlen,
25536 + loff_t offset __maybe_unused, u64 h_ino,
25537 + unsigned int d_type)
25539 + struct fillvdir_arg *arg = __arg;
25540 + char *name = (void *)__name;
25541 + struct super_block *sb;
25543 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
25546 + sb = arg->file->f_dentry->d_sb;
25547 + au_fset_fillvdir(arg->flags, CALLED);
25549 + if (nlen <= AUFS_WH_PFX_LEN
25550 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
25551 + if (test_known(&arg->delist, name, nlen)
25552 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
25553 + goto out; /* already exists or whiteouted */
25555 + sb = arg->file->f_dentry->d_sb;
25556 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
25558 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
25559 + d_type = DT_UNKNOWN;
25560 + arg->err = append_de(arg->vdir, name, nlen, ino,
25561 + d_type, &arg->delist);
25563 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
25564 + name += AUFS_WH_PFX_LEN;
25565 + nlen -= AUFS_WH_PFX_LEN;
25566 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
25567 + goto out; /* already whiteouted */
25570 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
25573 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
25574 + d_type = DT_UNKNOWN;
25575 + arg->err = au_nhash_append_wh
25576 + (&arg->whlist, name, nlen, ino, d_type,
25577 + arg->bindex, shwh);
25583 + arg->vdir->vd_jiffy = jiffies;
25585 + AuTraceErr(arg->err);
25589 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
25590 + struct au_nhash *whlist, struct au_nhash *delist)
25592 +#ifdef CONFIG_AUFS_SHWH
25594 + unsigned int nh, u;
25595 + struct hlist_head *head;
25596 + struct au_vdir_wh *tpos;
25597 + struct hlist_node *pos, *n;
25599 + struct au_vdir_destr *destr;
25601 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
25604 + o = p = __getname_gfp(GFP_NOFS);
25605 + if (unlikely(!p))
25609 + nh = whlist->nh_num;
25610 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
25611 + p += AUFS_WH_PFX_LEN;
25612 + for (u = 0; u < nh; u++) {
25613 + head = whlist->nh_head + u;
25614 + hlist_for_each_entry_safe(tpos, pos, n, head, wh_hash) {
25615 + destr = &tpos->wh_str;
25616 + memcpy(p, destr->name, destr->len);
25617 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
25618 + tpos->wh_ino, tpos->wh_type, delist);
25619 + if (unlikely(err))
25634 +static int au_do_read_vdir(struct fillvdir_arg *arg)
25637 + unsigned int rdhash;
25639 + aufs_bindex_t bend, bindex, bstart;
25640 + unsigned char shwh;
25641 + struct file *hf, *file;
25642 + struct super_block *sb;
25644 + file = arg->file;
25645 + sb = file->f_dentry->d_sb;
25646 + SiMustAnyLock(sb);
25648 + rdhash = au_sbi(sb)->si_rdhash;
25650 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
25651 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
25652 + if (unlikely(err))
25654 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
25655 + if (unlikely(err))
25661 + if (au_opt_test(au_mntflags(sb), SHWH)) {
25663 + au_fset_fillvdir(arg->flags, SHWH);
25665 + bstart = au_fbstart(file);
25666 + bend = au_fbend_dir(file);
25667 + for (bindex = bstart; !err && bindex <= bend; bindex++) {
25668 + hf = au_hf_dir(file, bindex);
25672 + offset = vfsub_llseek(hf, 0, SEEK_SET);
25674 + if (unlikely(offset))
25677 + arg->bindex = bindex;
25678 + au_fclr_fillvdir(arg->flags, WHABLE);
25680 + || (bindex != bend
25681 + && au_br_whable(au_sbr_perm(sb, bindex))))
25682 + au_fset_fillvdir(arg->flags, WHABLE);
25685 + au_fclr_fillvdir(arg->flags, CALLED);
25687 + err = vfsub_readdir(hf, fillvdir, arg);
25690 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
25693 + if (!err && shwh)
25694 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
25696 + au_nhash_wh_free(&arg->whlist);
25699 + au_nhash_de_free(&arg->delist);
25704 +static int read_vdir(struct file *file, int may_read)
25707 + unsigned long expire;
25708 + unsigned char do_read;
25709 + struct fillvdir_arg arg;
25710 + struct inode *inode;
25711 + struct au_vdir *vdir, *allocated;
25714 + inode = file->f_dentry->d_inode;
25715 + IMustLock(inode);
25716 + SiMustAnyLock(inode->i_sb);
25718 + allocated = NULL;
25720 + expire = au_sbi(inode->i_sb)->si_rdcache;
25721 + vdir = au_ivdir(inode);
25724 + vdir = alloc_vdir(file);
25725 + err = PTR_ERR(vdir);
25726 + if (IS_ERR(vdir))
25729 + allocated = vdir;
25730 + } else if (may_read
25731 + && (inode->i_version != vdir->vd_version
25732 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
25734 + err = reinit_vdir(vdir);
25735 + if (unlikely(err))
25740 + return 0; /* success */
25744 + err = au_do_read_vdir(&arg);
25746 + /* file->f_pos = 0; */
25747 + vdir->vd_version = inode->i_version;
25748 + vdir->vd_last.ul = 0;
25749 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
25751 + au_set_ivdir(inode, allocated);
25752 + } else if (allocated)
25753 + au_vdir_free(allocated);
25759 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
25762 + unsigned long ul, n;
25763 + const unsigned int deblk_sz = src->vd_deblk_sz;
25765 + AuDebugOn(tgt->vd_nblk != 1);
25768 + if (tgt->vd_nblk < src->vd_nblk) {
25769 + unsigned char **p;
25771 + p = krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
25773 + if (unlikely(!p))
25775 + tgt->vd_deblk = p;
25778 + if (tgt->vd_deblk_sz != deblk_sz) {
25779 + unsigned char *p;
25781 + tgt->vd_deblk_sz = deblk_sz;
25782 + p = krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS);
25783 + if (unlikely(!p))
25785 + tgt->vd_deblk[0] = p;
25787 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
25788 + tgt->vd_version = src->vd_version;
25789 + tgt->vd_jiffy = src->vd_jiffy;
25791 + n = src->vd_nblk;
25792 + for (ul = 1; ul < n; ul++) {
25793 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
25795 + if (unlikely(!tgt->vd_deblk[ul]))
25799 + tgt->vd_nblk = n;
25800 + tgt->vd_last.ul = tgt->vd_last.ul;
25801 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
25802 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
25803 + - src->vd_deblk[src->vd_last.ul];
25805 + return 0; /* success */
25808 + rerr = reinit_vdir(tgt);
25813 +int au_vdir_init(struct file *file)
25816 + struct inode *inode;
25817 + struct au_vdir *vdir_cache, *allocated;
25819 + err = read_vdir(file, !file->f_pos);
25820 + if (unlikely(err))
25823 + allocated = NULL;
25824 + vdir_cache = au_fvdir_cache(file);
25825 + if (!vdir_cache) {
25826 + vdir_cache = alloc_vdir(file);
25827 + err = PTR_ERR(vdir_cache);
25828 + if (IS_ERR(vdir_cache))
25830 + allocated = vdir_cache;
25831 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
25832 + err = reinit_vdir(vdir_cache);
25833 + if (unlikely(err))
25836 + return 0; /* success */
25838 + inode = file->f_dentry->d_inode;
25839 + err = copy_vdir(vdir_cache, au_ivdir(inode));
25841 + file->f_version = inode->i_version;
25843 + au_set_fvdir_cache(file, allocated);
25844 + } else if (allocated)
25845 + au_vdir_free(allocated);
25851 +static loff_t calc_offset(struct au_vdir *vdir)
25854 + union au_vdir_deblk_p p;
25856 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
25857 + offset = vdir->vd_last.p.deblk - p.deblk;
25858 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
25862 +/* returns true or false */
25863 +static int seek_vdir(struct file *file)
25866 + unsigned int deblk_sz;
25867 + unsigned long ul, n;
25869 + union au_vdir_deblk_p p, deblk_end;
25870 + struct au_vdir *vdir_cache;
25873 + vdir_cache = au_fvdir_cache(file);
25874 + offset = calc_offset(vdir_cache);
25875 + AuDbg("offset %lld\n", offset);
25876 + if (file->f_pos == offset)
25879 + vdir_cache->vd_last.ul = 0;
25880 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
25881 + if (!file->f_pos)
25885 + deblk_sz = vdir_cache->vd_deblk_sz;
25886 + ul = div64_u64(file->f_pos, deblk_sz);
25887 + AuDbg("ul %lu\n", ul);
25888 + if (ul >= vdir_cache->vd_nblk)
25891 + n = vdir_cache->vd_nblk;
25892 + for (; ul < n; ul++) {
25893 + p.deblk = vdir_cache->vd_deblk[ul];
25894 + deblk_end.deblk = p.deblk + deblk_sz;
25896 + offset *= deblk_sz;
25897 + while (!is_deblk_end(&p, &deblk_end) && offset < file->f_pos) {
25900 + l = calc_size(p.de->de_str.len);
25904 + if (!is_deblk_end(&p, &deblk_end)) {
25906 + vdir_cache->vd_last.ul = ul;
25907 + vdir_cache->vd_last.p = p;
25914 + AuTraceErr(!valid);
25918 +int au_vdir_fill_de(struct file *file, void *dirent, filldir_t filldir)
25921 + unsigned int l, deblk_sz;
25922 + union au_vdir_deblk_p deblk_end;
25923 + struct au_vdir *vdir_cache;
25924 + struct au_vdir_de *de;
25926 + vdir_cache = au_fvdir_cache(file);
25927 + if (!seek_vdir(file))
25930 + deblk_sz = vdir_cache->vd_deblk_sz;
25932 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
25933 + deblk_end.deblk += deblk_sz;
25934 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
25935 + de = vdir_cache->vd_last.p.de;
25936 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
25937 + de->de_str.len, de->de_str.name, file->f_pos,
25938 + (unsigned long)de->de_ino, de->de_type);
25939 + err = filldir(dirent, de->de_str.name, de->de_str.len,
25940 + file->f_pos, de->de_ino, de->de_type);
25941 + if (unlikely(err)) {
25943 + /* todo: ignore the error caused by udba? */
25944 + /* return err; */
25948 + l = calc_size(de->de_str.len);
25949 + vdir_cache->vd_last.p.deblk += l;
25950 + file->f_pos += l;
25952 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
25953 + vdir_cache->vd_last.ul++;
25954 + vdir_cache->vd_last.p.deblk
25955 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
25956 + file->f_pos = deblk_sz * vdir_cache->vd_last.ul;
25965 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
25966 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
25967 +++ linux/fs/aufs/vfsub.c 2012-07-22 19:57:03.167671344 +0200
25970 + * Copyright (C) 2005-2012 Junjiro R. Okajima
25972 + * This program, aufs is free software; you can redistribute it and/or modify
25973 + * it under the terms of the GNU General Public License as published by
25974 + * the Free Software Foundation; either version 2 of the License, or
25975 + * (at your option) any later version.
25977 + * This program is distributed in the hope that it will be useful,
25978 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25979 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25980 + * GNU General Public License for more details.
25982 + * You should have received a copy of the GNU General Public License
25983 + * along with this program; if not, write to the Free Software
25984 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25988 + * sub-routines for VFS
25991 +#include <linux/ima.h>
25992 +#include <linux/namei.h>
25993 +#include <linux/security.h>
25994 +#include <linux/splice.h>
25997 +int vfsub_update_h_iattr(struct path *h_path, int *did)
26001 + struct super_block *h_sb;
26003 + /* for remote fs, leave work for its getattr or d_revalidate */
26004 + /* for bad i_attr fs, handle them in aufs_getattr() */
26005 + /* still some fs may acquire i_mutex. we need to skip them */
26009 + h_sb = h_path->dentry->d_sb;
26010 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
26012 + err = vfs_getattr(h_path->mnt, h_path->dentry, &st);
26017 +/* ---------------------------------------------------------------------- */
26019 +struct file *vfsub_dentry_open(struct path *path, int flags)
26021 + struct file *file;
26024 + file = dentry_open(path->dentry, path->mnt,
26025 + flags /* | __FMODE_NONOTIFY */,
26027 + if (!IS_ERR_OR_NULL(file)
26028 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
26029 + i_readcount_inc(path->dentry->d_inode);
26034 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
26036 + struct file *file;
26039 + file = filp_open(path,
26040 + oflags /* | __FMODE_NONOTIFY */,
26043 + if (IS_ERR(file))
26045 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
26051 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
26055 + err = kern_path(name, flags, path);
26056 + if (!err && path->dentry->d_inode)
26057 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
26061 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
26064 + struct path path = {
26068 + /* VFS checks it too, but by WARN_ON_ONCE() */
26069 + IMustLock(parent->d_inode);
26071 + path.dentry = lookup_one_len(name, parent, len);
26072 + if (IS_ERR(path.dentry))
26074 + if (path.dentry->d_inode)
26075 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
26078 + AuTraceErrPtr(path.dentry);
26079 + return path.dentry;
26082 +struct dentry *vfsub_lookup_hash(struct nameidata *nd)
26084 + struct path path = {
26085 + .mnt = nd->path.mnt
26088 + IMustLock(nd->path.dentry->d_inode);
26090 + path.dentry = lookup_hash(nd);
26091 + if (IS_ERR(path.dentry))
26093 + if (path.dentry->d_inode)
26094 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
26097 + AuTraceErrPtr(path.dentry);
26098 + return path.dentry;
26102 + * this is "VFS:__lookup_one_len()" which was removed and merged into
26103 + * VFS:lookup_one_len() by the commit.
26104 + * 6a96ba5 2011-03-14 kill __lookup_one_len()
26105 + * this function should always be equivalent to the corresponding part in
26106 + * VFS:lookup_one_len().
26108 +int vfsub_name_hash(const char *name, struct qstr *this, int len)
26112 + this->name = name;
26114 + this->hash = full_name_hash(name, len);
26119 + c = *(const unsigned char *)name++;
26120 + if (c == '/' || c == '\0')
26126 +/* ---------------------------------------------------------------------- */
26128 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
26129 + struct dentry *d2, struct au_hinode *hdir2)
26131 + struct dentry *d;
26134 + d = lock_rename(d1, d2);
26136 + au_hn_suspend(hdir1);
26137 + if (hdir1 != hdir2)
26138 + au_hn_suspend(hdir2);
26143 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
26144 + struct dentry *d2, struct au_hinode *hdir2)
26146 + au_hn_resume(hdir1);
26147 + if (hdir1 != hdir2)
26148 + au_hn_resume(hdir2);
26150 + unlock_rename(d1, d2);
26154 +/* ---------------------------------------------------------------------- */
26156 +int vfsub_create(struct inode *dir, struct path *path, int mode)
26159 + struct dentry *d;
26163 + d = path->dentry;
26164 + path->dentry = d->d_parent;
26165 + err = security_path_mknod(path, d, mode, 0);
26166 + path->dentry = d;
26167 + if (unlikely(err))
26170 + if (au_test_fs_null_nd(dir->i_sb))
26171 + err = vfs_create(dir, path->dentry, mode, NULL);
26173 + struct nameidata h_nd;
26175 + memset(&h_nd, 0, sizeof(h_nd));
26176 + h_nd.flags = LOOKUP_CREATE;
26177 + h_nd.intent.open.flags = O_CREAT
26178 + | vfsub_fmode_to_uint(FMODE_READ);
26179 + h_nd.intent.open.create_mode = mode;
26180 + h_nd.path.dentry = path->dentry->d_parent;
26181 + h_nd.path.mnt = path->mnt;
26182 + path_get(&h_nd.path);
26183 + err = vfs_create(dir, path->dentry, mode, &h_nd);
26184 + path_put(&h_nd.path);
26188 + struct path tmp = *path;
26191 + vfsub_update_h_iattr(&tmp, &did);
26193 + tmp.dentry = path->dentry->d_parent;
26194 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
26203 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
26206 + struct dentry *d;
26210 + d = path->dentry;
26211 + path->dentry = d->d_parent;
26212 + err = security_path_symlink(path, d, symname);
26213 + path->dentry = d;
26214 + if (unlikely(err))
26217 + err = vfs_symlink(dir, path->dentry, symname);
26219 + struct path tmp = *path;
26222 + vfsub_update_h_iattr(&tmp, &did);
26224 + tmp.dentry = path->dentry->d_parent;
26225 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
26234 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
26237 + struct dentry *d;
26241 + d = path->dentry;
26242 + path->dentry = d->d_parent;
26243 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
26244 + path->dentry = d;
26245 + if (unlikely(err))
26248 + err = vfs_mknod(dir, path->dentry, mode, dev);
26250 + struct path tmp = *path;
26253 + vfsub_update_h_iattr(&tmp, &did);
26255 + tmp.dentry = path->dentry->d_parent;
26256 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
26265 +static int au_test_nlink(struct inode *inode)
26267 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
26269 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
26270 + || inode->i_nlink < link_max)
26275 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path)
26278 + struct dentry *d;
26282 + err = au_test_nlink(src_dentry->d_inode);
26283 + if (unlikely(err))
26286 + d = path->dentry;
26287 + path->dentry = d->d_parent;
26288 + err = security_path_link(src_dentry, path, d);
26289 + path->dentry = d;
26290 + if (unlikely(err))
26294 + err = vfs_link(src_dentry, dir, path->dentry);
26297 + struct path tmp = *path;
26300 + /* fuse has different memory inode for the same inumber */
26301 + vfsub_update_h_iattr(&tmp, &did);
26303 + tmp.dentry = path->dentry->d_parent;
26304 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
26305 + tmp.dentry = src_dentry;
26306 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
26315 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
26316 + struct inode *dir, struct path *path)
26319 + struct path tmp = {
26322 + struct dentry *d;
26325 + IMustLock(src_dir);
26327 + d = path->dentry;
26328 + path->dentry = d->d_parent;
26329 + tmp.dentry = src_dentry->d_parent;
26330 + err = security_path_rename(&tmp, src_dentry, path, d);
26331 + path->dentry = d;
26332 + if (unlikely(err))
26336 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry);
26341 + tmp.dentry = d->d_parent;
26342 + vfsub_update_h_iattr(&tmp, &did);
26344 + tmp.dentry = src_dentry;
26345 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
26346 + tmp.dentry = src_dentry->d_parent;
26347 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
26356 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
26359 + struct dentry *d;
26363 + d = path->dentry;
26364 + path->dentry = d->d_parent;
26365 + err = security_path_mkdir(path, d, mode);
26366 + path->dentry = d;
26367 + if (unlikely(err))
26370 + err = vfs_mkdir(dir, path->dentry, mode);
26372 + struct path tmp = *path;
26375 + vfsub_update_h_iattr(&tmp, &did);
26377 + tmp.dentry = path->dentry->d_parent;
26378 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
26387 +int vfsub_rmdir(struct inode *dir, struct path *path)
26390 + struct dentry *d;
26394 + d = path->dentry;
26395 + path->dentry = d->d_parent;
26396 + err = security_path_rmdir(path, d);
26397 + path->dentry = d;
26398 + if (unlikely(err))
26402 + err = vfs_rmdir(dir, path->dentry);
26405 + struct path tmp = {
26406 + .dentry = path->dentry->d_parent,
26410 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
26417 +/* ---------------------------------------------------------------------- */
26419 +/* todo: support mmap_sem? */
26420 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
26426 + err = vfs_read(file, ubuf, count, ppos);
26429 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
26433 +/* todo: kernel_read()? */
26434 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
26438 + mm_segment_t oldfs;
26445 + oldfs = get_fs();
26446 + set_fs(KERNEL_DS);
26447 + err = vfsub_read_u(file, buf.u, count, ppos);
26452 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
26458 + err = vfs_write(file, ubuf, count, ppos);
26461 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
26465 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
26468 + mm_segment_t oldfs;
26471 + const char __user *u;
26475 + oldfs = get_fs();
26476 + set_fs(KERNEL_DS);
26477 + err = vfsub_write_u(file, buf.u, count, ppos);
26482 +int vfsub_flush(struct file *file, fl_owner_t id)
26487 + if (file->f_op && file->f_op->flush) {
26488 + if (!au_test_nfs(file->f_dentry->d_sb))
26489 + err = file->f_op->flush(file, id);
26492 + err = file->f_op->flush(file, id);
26496 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
26502 +int vfsub_readdir(struct file *file, filldir_t filldir, void *arg)
26507 + err = vfs_readdir(file, filldir, arg);
26510 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
26514 +long vfsub_splice_to(struct file *in, loff_t *ppos,
26515 + struct pipe_inode_info *pipe, size_t len,
26516 + unsigned int flags)
26521 + err = do_splice_to(in, ppos, pipe, len, flags);
26523 + file_accessed(in);
26525 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
26529 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
26530 + loff_t *ppos, size_t len, unsigned int flags)
26535 + err = do_splice_from(pipe, out, ppos, len, flags);
26538 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
26542 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
26546 + /* file can be NULL */
26548 + err = vfs_fsync(file, datasync);
26552 + AuDebugOn(!file);
26553 + path = &file->f_path;
26555 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
26560 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
26561 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
26562 + struct file *h_file)
26565 + struct inode *h_inode;
26567 + h_inode = h_path->dentry->d_inode;
26569 + err = mnt_want_write(h_path->mnt);
26572 + err = inode_permission(h_inode, MAY_WRITE);
26575 + err = get_write_access(h_inode);
26578 + err = break_lease(h_inode, O_WRONLY);
26583 + err = locks_verify_truncate(h_inode, h_file, length);
26585 + err = security_path_truncate(h_path);
26588 + err = do_truncate(h_path->dentry, length, attr, h_file);
26594 + put_write_access(h_inode);
26597 + mnt_drop_write(h_path->mnt);
26602 +/* ---------------------------------------------------------------------- */
26604 +struct au_vfsub_mkdir_args {
26606 + struct inode *dir;
26607 + struct path *path;
26611 +static void au_call_vfsub_mkdir(void *args)
26613 + struct au_vfsub_mkdir_args *a = args;
26614 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
26617 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
26619 + int err, do_sio, wkq_err;
26621 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
26623 + err = vfsub_mkdir(dir, path, mode);
26625 + struct au_vfsub_mkdir_args args = {
26631 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
26632 + if (unlikely(wkq_err))
26639 +struct au_vfsub_rmdir_args {
26641 + struct inode *dir;
26642 + struct path *path;
26645 +static void au_call_vfsub_rmdir(void *args)
26647 + struct au_vfsub_rmdir_args *a = args;
26648 + *a->errp = vfsub_rmdir(a->dir, a->path);
26651 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
26653 + int err, do_sio, wkq_err;
26655 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
26657 + err = vfsub_rmdir(dir, path);
26659 + struct au_vfsub_rmdir_args args = {
26664 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
26665 + if (unlikely(wkq_err))
26672 +/* ---------------------------------------------------------------------- */
26674 +struct notify_change_args {
26676 + struct path *path;
26677 + struct iattr *ia;
26680 +static void call_notify_change(void *args)
26682 + struct notify_change_args *a = args;
26683 + struct inode *h_inode;
26685 + h_inode = a->path->dentry->d_inode;
26686 + IMustLock(h_inode);
26688 + *a->errp = -EPERM;
26689 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
26690 + *a->errp = notify_change(a->path->dentry, a->ia);
26692 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
26694 + AuTraceErr(*a->errp);
26697 +int vfsub_notify_change(struct path *path, struct iattr *ia)
26700 + struct notify_change_args args = {
26706 + call_notify_change(&args);
26711 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia)
26713 + int err, wkq_err;
26714 + struct notify_change_args args = {
26720 + wkq_err = au_wkq_wait(call_notify_change, &args);
26721 + if (unlikely(wkq_err))
26727 +/* ---------------------------------------------------------------------- */
26729 +struct unlink_args {
26731 + struct inode *dir;
26732 + struct path *path;
26735 +static void call_unlink(void *args)
26737 + struct unlink_args *a = args;
26738 + struct dentry *d = a->path->dentry;
26739 + struct inode *h_inode;
26740 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
26741 + && d->d_count == 1);
26743 + IMustLock(a->dir);
26745 + a->path->dentry = d->d_parent;
26746 + *a->errp = security_path_unlink(a->path, d);
26747 + a->path->dentry = d;
26748 + if (unlikely(*a->errp))
26751 + if (!stop_sillyrename)
26753 + h_inode = d->d_inode;
26758 + *a->errp = vfs_unlink(a->dir, d);
26761 + struct path tmp = {
26762 + .dentry = d->d_parent,
26763 + .mnt = a->path->mnt
26765 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
26768 + if (!stop_sillyrename)
26773 + AuTraceErr(*a->errp);
26777 + * @dir: must be locked.
26778 + * @dentry: target dentry.
26780 +int vfsub_unlink(struct inode *dir, struct path *path, int force)
26783 + struct unlink_args args = {
26790 + call_unlink(&args);
26794 + wkq_err = au_wkq_wait(call_unlink, &args);
26795 + if (unlikely(wkq_err))
26801 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
26802 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
26803 +++ linux/fs/aufs/vfsub.h 2012-07-22 19:57:03.167671344 +0200
26806 + * Copyright (C) 2005-2012 Junjiro R. Okajima
26808 + * This program, aufs is free software; you can redistribute it and/or modify
26809 + * it under the terms of the GNU General Public License as published by
26810 + * the Free Software Foundation; either version 2 of the License, or
26811 + * (at your option) any later version.
26813 + * This program is distributed in the hope that it will be useful,
26814 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26815 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26816 + * GNU General Public License for more details.
26818 + * You should have received a copy of the GNU General Public License
26819 + * along with this program; if not, write to the Free Software
26820 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26824 + * sub-routines for VFS
26827 +#ifndef __AUFS_VFSUB_H__
26828 +#define __AUFS_VFSUB_H__
26832 +#include <linux/fs.h>
26833 +#include <linux/lglock.h>
26834 +#include "debug.h"
26836 +/* copied from linux/fs/internal.h */
26837 +/* todo: BAD approach!! */
26838 +extern struct lglock vfsmount_lock;
26839 +extern void file_sb_list_del(struct file *f);
26840 +extern spinlock_t inode_sb_list_lock;
26842 +/* copied from linux/fs/file_table.c */
26843 +extern struct lglock files_lglock;
26846 + * These macros iterate all files on all CPUs for a given superblock.
26847 + * files_lglock must be held globally.
26849 +#define do_file_list_for_each_entry(__sb, __file) \
26852 + for_each_possible_cpu(i) { \
26853 + struct list_head *list; \
26854 + list = per_cpu_ptr((__sb)->s_files, i); \
26855 + list_for_each_entry((__file), list, f_u.fu_list)
26857 +#define while_file_list_for_each_entry \
26863 +#define do_file_list_for_each_entry(__sb, __file) \
26865 + struct list_head *list; \
26866 + list = &(sb)->s_files; \
26867 + list_for_each_entry((__file), list, f_u.fu_list)
26869 +#define while_file_list_for_each_entry \
26873 +/* ---------------------------------------------------------------------- */
26875 +/* lock subclass for lower inode */
26876 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
26877 +/* reduce? gave up. */
26879 + AuLsc_I_Begin = I_MUTEX_QUOTA, /* 4 */
26880 + AuLsc_I_PARENT, /* lower inode, parent first */
26881 + AuLsc_I_PARENT2, /* copyup dirs */
26882 + AuLsc_I_PARENT3, /* copyup wh */
26888 +/* to debug easier, do not make them inlined functions */
26889 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
26890 +#define IMustLock(i) MtxMustLock(&(i)->i_mutex)
26892 +/* ---------------------------------------------------------------------- */
26894 +static inline void vfsub_drop_nlink(struct inode *inode)
26896 + AuDebugOn(!inode->i_nlink);
26897 + drop_nlink(inode);
26900 +static inline void vfsub_dead_dir(struct inode *inode)
26902 + AuDebugOn(!S_ISDIR(inode->i_mode));
26903 + inode->i_flags |= S_DEAD;
26904 + clear_nlink(inode);
26907 +/* ---------------------------------------------------------------------- */
26909 +/* cf. i_[ug]id_read() in linux/include/fs.h */
26910 +static inline uid_t vfsub_ia_uid(struct iattr *ia)
26912 + return from_kuid(&init_user_ns, ia->ia_uid);
26915 +static inline gid_t vfsub_ia_gid(struct iattr *ia)
26917 + return from_kgid(&init_user_ns, ia->ia_gid);
26920 +/* ---------------------------------------------------------------------- */
26922 +int vfsub_update_h_iattr(struct path *h_path, int *did);
26923 +struct file *vfsub_dentry_open(struct path *path, int flags);
26924 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
26925 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
26926 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
26928 +struct dentry *vfsub_lookup_hash(struct nameidata *nd);
26929 +int vfsub_name_hash(const char *name, struct qstr *this, int len);
26931 +/* ---------------------------------------------------------------------- */
26934 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
26935 + struct dentry *d2, struct au_hinode *hdir2);
26936 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
26937 + struct dentry *d2, struct au_hinode *hdir2);
26939 +int vfsub_create(struct inode *dir, struct path *path, int mode);
26940 +int vfsub_symlink(struct inode *dir, struct path *path,
26941 + const char *symname);
26942 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
26943 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
26944 + struct path *path);
26945 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
26946 + struct inode *hdir, struct path *path);
26947 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
26948 +int vfsub_rmdir(struct inode *dir, struct path *path);
26950 +/* ---------------------------------------------------------------------- */
26952 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
26954 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
26956 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
26958 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
26960 +int vfsub_flush(struct file *file, fl_owner_t id);
26961 +int vfsub_readdir(struct file *file, filldir_t filldir, void *arg);
26963 +static inline unsigned int vfsub_file_flags(struct file *file)
26965 + unsigned int flags;
26967 + spin_lock(&file->f_lock);
26968 + flags = file->f_flags;
26969 + spin_unlock(&file->f_lock);
26974 +static inline void vfsub_file_accessed(struct file *h_file)
26976 + file_accessed(h_file);
26977 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
26980 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
26981 + struct dentry *h_dentry)
26983 + struct path h_path = {
26984 + .dentry = h_dentry,
26987 + touch_atime(&h_path);
26988 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
26991 +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts,
26994 + return update_time(h_inode, ts, flags);
26995 + /* no vfsub_update_h_iattr() since we don't have struct path */
26998 +long vfsub_splice_to(struct file *in, loff_t *ppos,
26999 + struct pipe_inode_info *pipe, size_t len,
27000 + unsigned int flags);
27001 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
27002 + loff_t *ppos, size_t len, unsigned int flags);
27003 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
27004 + struct file *h_file);
27005 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
27007 +/* ---------------------------------------------------------------------- */
27009 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
27014 + err = vfs_llseek(file, offset, origin);
27019 +/* ---------------------------------------------------------------------- */
27021 +/* dirty workaround for strict type of fmode_t */
27027 +static inline unsigned int vfsub_fmode_to_uint(fmode_t fm)
27029 + union vfsub_fmu u = {
27033 + BUILD_BUG_ON(sizeof(u.fm) != sizeof(u.ui));
27038 +static inline fmode_t vfsub_uint_to_fmode(unsigned int ui)
27040 + union vfsub_fmu u = {
27047 +/* ---------------------------------------------------------------------- */
27049 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
27050 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
27051 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia);
27052 +int vfsub_notify_change(struct path *path, struct iattr *ia);
27053 +int vfsub_unlink(struct inode *dir, struct path *path, int force);
27055 +#endif /* __KERNEL__ */
27056 +#endif /* __AUFS_VFSUB_H__ */
27057 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
27058 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
27059 +++ linux/fs/aufs/wbr_policy.c 2012-07-22 19:57:03.167671344 +0200
27062 + * Copyright (C) 2005-2012 Junjiro R. Okajima
27064 + * This program, aufs is free software; you can redistribute it and/or modify
27065 + * it under the terms of the GNU General Public License as published by
27066 + * the Free Software Foundation; either version 2 of the License, or
27067 + * (at your option) any later version.
27069 + * This program is distributed in the hope that it will be useful,
27070 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27071 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27072 + * GNU General Public License for more details.
27074 + * You should have received a copy of the GNU General Public License
27075 + * along with this program; if not, write to the Free Software
27076 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27080 + * policies for selecting one among multiple writable branches
27083 +#include <linux/statfs.h>
27086 +/* subset of cpup_attr() */
27087 +static noinline_for_stack
27088 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
27092 + struct inode *h_isrc;
27094 + h_isrc = h_src->d_inode;
27095 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
27096 + ia.ia_mode = h_isrc->i_mode;
27097 + ia.ia_uid = h_isrc->i_uid;
27098 + ia.ia_gid = h_isrc->i_gid;
27099 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
27100 + au_cpup_attr_flags(h_path->dentry->d_inode, h_isrc);
27101 + err = vfsub_sio_notify_change(h_path, &ia);
27103 + /* is this nfs only? */
27104 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
27105 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
27106 + ia.ia_mode = h_isrc->i_mode;
27107 + err = vfsub_sio_notify_change(h_path, &ia);
27113 +#define AuCpdown_PARENT_OPQ 1
27114 +#define AuCpdown_WHED (1 << 1)
27115 +#define AuCpdown_MADE_DIR (1 << 2)
27116 +#define AuCpdown_DIROPQ (1 << 3)
27117 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
27118 +#define au_fset_cpdown(flags, name) \
27119 + do { (flags) |= AuCpdown_##name; } while (0)
27120 +#define au_fclr_cpdown(flags, name) \
27121 + do { (flags) &= ~AuCpdown_##name; } while (0)
27123 +struct au_cpdown_dir_args {
27124 + struct dentry *parent;
27125 + unsigned int flags;
27128 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
27129 + struct au_cpdown_dir_args *a)
27132 + struct dentry *opq_dentry;
27134 + opq_dentry = au_diropq_create(dentry, bdst);
27135 + err = PTR_ERR(opq_dentry);
27136 + if (IS_ERR(opq_dentry))
27138 + dput(opq_dentry);
27139 + au_fset_cpdown(a->flags, DIROPQ);
27145 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
27146 + struct inode *dir, aufs_bindex_t bdst)
27149 + struct path h_path;
27150 + struct au_branch *br;
27152 + br = au_sbr(dentry->d_sb, bdst);
27153 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
27154 + err = PTR_ERR(h_path.dentry);
27155 + if (IS_ERR(h_path.dentry))
27159 + if (h_path.dentry->d_inode) {
27160 + h_path.mnt = br->br_mnt;
27161 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
27164 + dput(h_path.dentry);
27170 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
27171 + struct dentry *h_parent, void *arg)
27174 + aufs_bindex_t bopq, bstart;
27175 + struct path h_path;
27176 + struct dentry *parent;
27177 + struct inode *h_dir, *h_inode, *inode, *dir;
27178 + struct au_cpdown_dir_args *args = arg;
27180 + bstart = au_dbstart(dentry);
27181 + /* dentry is di-locked */
27182 + parent = dget_parent(dentry);
27183 + dir = parent->d_inode;
27184 + h_dir = h_parent->d_inode;
27185 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
27186 + IMustLock(h_dir);
27188 + err = au_lkup_neg(dentry, bdst);
27189 + if (unlikely(err < 0))
27191 + h_path.dentry = au_h_dptr(dentry, bdst);
27192 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
27193 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path,
27194 + S_IRWXU | S_IRUGO | S_IXUGO);
27195 + if (unlikely(err))
27197 + au_fset_cpdown(args->flags, MADE_DIR);
27199 + bopq = au_dbdiropq(dentry);
27200 + au_fclr_cpdown(args->flags, WHED);
27201 + au_fclr_cpdown(args->flags, DIROPQ);
27202 + if (au_dbwh(dentry) == bdst)
27203 + au_fset_cpdown(args->flags, WHED);
27204 + if (!au_ftest_cpdown(args->flags, PARENT_OPQ) && bopq <= bdst)
27205 + au_fset_cpdown(args->flags, PARENT_OPQ);
27206 + h_inode = h_path.dentry->d_inode;
27207 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
27208 + if (au_ftest_cpdown(args->flags, WHED)) {
27209 + err = au_cpdown_dir_opq(dentry, bdst, args);
27210 + if (unlikely(err)) {
27211 + mutex_unlock(&h_inode->i_mutex);
27216 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, bstart));
27217 + mutex_unlock(&h_inode->i_mutex);
27218 + if (unlikely(err))
27221 + if (au_ftest_cpdown(args->flags, WHED)) {
27222 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
27223 + if (unlikely(err))
27227 + inode = dentry->d_inode;
27228 + if (au_ibend(inode) < bdst)
27229 + au_set_ibend(inode, bdst);
27230 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
27231 + au_hi_flags(inode, /*isdir*/1));
27232 + goto out; /* success */
27236 + if (au_ftest_cpdown(args->flags, DIROPQ)) {
27237 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
27238 + rerr = au_diropq_remove(dentry, bdst);
27239 + mutex_unlock(&h_inode->i_mutex);
27240 + if (unlikely(rerr)) {
27241 + AuIOErr("failed removing diropq for %.*s b%d (%d)\n",
27242 + AuDLNPair(dentry), bdst, rerr);
27248 + if (au_ftest_cpdown(args->flags, MADE_DIR)) {
27249 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
27250 + if (unlikely(rerr)) {
27251 + AuIOErr("failed removing %.*s b%d (%d)\n",
27252 + AuDLNPair(dentry), bdst, rerr);
27257 + au_set_h_dptr(dentry, bdst, NULL);
27258 + if (au_dbend(dentry) == bdst)
27259 + au_update_dbend(dentry);
27265 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
27268 + struct au_cpdown_dir_args args = {
27269 + .parent = dget_parent(dentry),
27273 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &args);
27274 + dput(args.parent);
27279 +/* ---------------------------------------------------------------------- */
27281 +/* policies for create */
27283 +static int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
27285 + int err, i, j, ndentry;
27286 + aufs_bindex_t bopq;
27287 + struct au_dcsub_pages dpages;
27288 + struct au_dpage *dpage;
27289 + struct dentry **dentries, *parent, *d;
27291 + err = au_dpages_init(&dpages, GFP_NOFS);
27292 + if (unlikely(err))
27294 + parent = dget_parent(dentry);
27295 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
27296 + if (unlikely(err))
27300 + for (i = 0; i < dpages.ndpage; i++) {
27301 + dpage = dpages.dpages + i;
27302 + dentries = dpage->dentries;
27303 + ndentry = dpage->ndentry;
27304 + for (j = 0; j < ndentry; j++) {
27306 + di_read_lock_parent2(d, !AuLock_IR);
27307 + bopq = au_dbdiropq(d);
27308 + di_read_unlock(d, !AuLock_IR);
27309 + if (bopq >= 0 && bopq < err)
27316 + au_dpages_free(&dpages);
27321 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
27323 + for (; bindex >= 0; bindex--)
27324 + if (!au_br_rdonly(au_sbr(sb, bindex)))
27329 +/* top down parent */
27330 +static int au_wbr_create_tdp(struct dentry *dentry, int isdir __maybe_unused)
27333 + aufs_bindex_t bstart, bindex;
27334 + struct super_block *sb;
27335 + struct dentry *parent, *h_parent;
27337 + sb = dentry->d_sb;
27338 + bstart = au_dbstart(dentry);
27340 + if (!au_br_rdonly(au_sbr(sb, bstart)))
27344 + parent = dget_parent(dentry);
27345 + for (bindex = au_dbstart(parent); bindex < bstart; bindex++) {
27346 + h_parent = au_h_dptr(parent, bindex);
27347 + if (!h_parent || !h_parent->d_inode)
27350 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
27357 + /* bottom up here */
27358 + if (unlikely(err < 0)) {
27359 + err = au_wbr_bu(sb, bstart - 1);
27361 + err = au_wbr_nonopq(dentry, err);
27365 + AuDbg("b%d\n", err);
27369 +/* ---------------------------------------------------------------------- */
27371 +/* an exception for the policy other than tdp */
27372 +static int au_wbr_create_exp(struct dentry *dentry)
27375 + aufs_bindex_t bwh, bdiropq;
27376 + struct dentry *parent;
27379 + bwh = au_dbwh(dentry);
27380 + parent = dget_parent(dentry);
27381 + bdiropq = au_dbdiropq(parent);
27383 + if (bdiropq >= 0)
27384 + err = min(bdiropq, bwh);
27387 + AuDbg("%d\n", err);
27388 + } else if (bdiropq >= 0) {
27390 + AuDbg("%d\n", err);
27395 + err = au_wbr_nonopq(dentry, err);
27397 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
27400 + AuDbg("%d\n", err);
27404 +/* ---------------------------------------------------------------------- */
27407 +static int au_wbr_create_init_rr(struct super_block *sb)
27411 + err = au_wbr_bu(sb, au_sbend(sb));
27412 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
27415 + AuDbg("b%d\n", err);
27419 +static int au_wbr_create_rr(struct dentry *dentry, int isdir)
27423 + aufs_bindex_t bindex, bend;
27424 + struct super_block *sb;
27427 + err = au_wbr_create_exp(dentry);
27431 + sb = dentry->d_sb;
27432 + next = &au_sbi(sb)->si_wbr_rr_next;
27433 + bend = au_sbend(sb);
27435 + for (bindex = 0; bindex <= bend; bindex++) {
27437 + err = atomic_dec_return(next) + 1;
27438 + /* modulo for 0 is meaningless */
27439 + if (unlikely(!err))
27440 + err = atomic_dec_return(next) + 1;
27442 + err = atomic_read(next);
27443 + AuDbg("%d\n", err);
27446 + AuDbg("%d\n", err);
27447 + if (!au_br_rdonly(au_sbr(sb, err)))
27453 + err = au_wbr_nonopq(dentry, err);
27456 + AuDbg("%d\n", err);
27460 +/* ---------------------------------------------------------------------- */
27462 +/* most free space */
27463 +static void au_mfs(struct dentry *dentry)
27465 + struct super_block *sb;
27466 + struct au_branch *br;
27467 + struct au_wbr_mfs *mfs;
27468 + aufs_bindex_t bindex, bend;
27470 + unsigned long long b, bavail;
27471 + struct path h_path;
27472 + /* reduce the stack usage */
27473 + struct kstatfs *st;
27475 + st = kmalloc(sizeof(*st), GFP_NOFS);
27476 + if (unlikely(!st)) {
27477 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
27482 + sb = dentry->d_sb;
27483 + mfs = &au_sbi(sb)->si_wbr_mfs;
27484 + MtxMustLock(&mfs->mfs_lock);
27485 + mfs->mfs_bindex = -EROFS;
27486 + mfs->mfsrr_bytes = 0;
27487 + bend = au_sbend(sb);
27488 + for (bindex = 0; bindex <= bend; bindex++) {
27489 + br = au_sbr(sb, bindex);
27490 + if (au_br_rdonly(br))
27493 + /* sb->s_root for NFS is unreliable */
27494 + h_path.mnt = br->br_mnt;
27495 + h_path.dentry = h_path.mnt->mnt_root;
27496 + err = vfs_statfs(&h_path, st);
27497 + if (unlikely(err)) {
27498 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
27502 + /* when the available size is equal, select the lower one */
27503 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
27504 + || sizeof(b) < sizeof(st->f_bsize));
27505 + b = st->f_bavail * st->f_bsize;
27506 + br->br_wbr->wbr_bytes = b;
27507 + if (b >= bavail) {
27509 + mfs->mfs_bindex = bindex;
27510 + mfs->mfs_jiffy = jiffies;
27514 + mfs->mfsrr_bytes = bavail;
27515 + AuDbg("b%d\n", mfs->mfs_bindex);
27519 +static int au_wbr_create_mfs(struct dentry *dentry, int isdir __maybe_unused)
27522 + struct super_block *sb;
27523 + struct au_wbr_mfs *mfs;
27525 + err = au_wbr_create_exp(dentry);
27529 + sb = dentry->d_sb;
27530 + mfs = &au_sbi(sb)->si_wbr_mfs;
27531 + mutex_lock(&mfs->mfs_lock);
27532 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
27533 + || mfs->mfs_bindex < 0
27534 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
27536 + mutex_unlock(&mfs->mfs_lock);
27537 + err = mfs->mfs_bindex;
27540 + err = au_wbr_nonopq(dentry, err);
27543 + AuDbg("b%d\n", err);
27547 +static int au_wbr_create_init_mfs(struct super_block *sb)
27549 + struct au_wbr_mfs *mfs;
27551 + mfs = &au_sbi(sb)->si_wbr_mfs;
27552 + mutex_init(&mfs->mfs_lock);
27553 + mfs->mfs_jiffy = 0;
27554 + mfs->mfs_bindex = -EROFS;
27559 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
27561 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
27565 +/* ---------------------------------------------------------------------- */
27567 +/* most free space and then round robin */
27568 +static int au_wbr_create_mfsrr(struct dentry *dentry, int isdir)
27571 + struct au_wbr_mfs *mfs;
27573 + err = au_wbr_create_mfs(dentry, isdir);
27575 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
27576 + mutex_lock(&mfs->mfs_lock);
27577 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
27578 + err = au_wbr_create_rr(dentry, isdir);
27579 + mutex_unlock(&mfs->mfs_lock);
27582 + AuDbg("b%d\n", err);
27586 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
27590 + au_wbr_create_init_mfs(sb); /* ignore */
27591 + err = au_wbr_create_init_rr(sb);
27596 +/* ---------------------------------------------------------------------- */
27598 +/* top down parent and most free space */
27599 +static int au_wbr_create_pmfs(struct dentry *dentry, int isdir)
27602 + unsigned long long b;
27603 + aufs_bindex_t bindex, bstart, bend;
27604 + struct super_block *sb;
27605 + struct dentry *parent, *h_parent;
27606 + struct au_branch *br;
27608 + err = au_wbr_create_tdp(dentry, isdir);
27609 + if (unlikely(err < 0))
27611 + parent = dget_parent(dentry);
27612 + bstart = au_dbstart(parent);
27613 + bend = au_dbtaildir(parent);
27614 + if (bstart == bend)
27615 + goto out_parent; /* success */
27617 + e2 = au_wbr_create_mfs(dentry, isdir);
27619 + goto out_parent; /* success */
27621 + /* when the available size is equal, select upper one */
27622 + sb = dentry->d_sb;
27623 + br = au_sbr(sb, err);
27624 + b = br->br_wbr->wbr_bytes;
27625 + AuDbg("b%d, %llu\n", err, b);
27627 + for (bindex = bstart; bindex <= bend; bindex++) {
27628 + h_parent = au_h_dptr(parent, bindex);
27629 + if (!h_parent || !h_parent->d_inode)
27632 + br = au_sbr(sb, bindex);
27633 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
27634 + b = br->br_wbr->wbr_bytes;
27636 + AuDbg("b%d, %llu\n", err, b);
27641 + err = au_wbr_nonopq(dentry, err);
27646 + AuDbg("b%d\n", err);
27650 +/* ---------------------------------------------------------------------- */
27652 +/* policies for copyup */
27654 +/* top down parent */
27655 +static int au_wbr_copyup_tdp(struct dentry *dentry)
27657 + return au_wbr_create_tdp(dentry, /*isdir, anything is ok*/0);
27660 +/* bottom up parent */
27661 +static int au_wbr_copyup_bup(struct dentry *dentry)
27664 + aufs_bindex_t bindex, bstart;
27665 + struct dentry *parent, *h_parent;
27666 + struct super_block *sb;
27669 + sb = dentry->d_sb;
27670 + parent = dget_parent(dentry);
27671 + bstart = au_dbstart(parent);
27672 + for (bindex = au_dbstart(dentry); bindex >= bstart; bindex--) {
27673 + h_parent = au_h_dptr(parent, bindex);
27674 + if (!h_parent || !h_parent->d_inode)
27677 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
27684 + /* bottom up here */
27685 + if (unlikely(err < 0))
27686 + err = au_wbr_bu(sb, bstart - 1);
27688 + AuDbg("b%d\n", err);
27693 +static int au_wbr_copyup_bu(struct dentry *dentry)
27696 + aufs_bindex_t bstart;
27698 + bstart = au_dbstart(dentry);
27699 + err = au_wbr_bu(dentry->d_sb, bstart);
27700 + AuDbg("b%d\n", err);
27701 + if (err > bstart)
27702 + err = au_wbr_nonopq(dentry, err);
27704 + AuDbg("b%d\n", err);
27708 +/* ---------------------------------------------------------------------- */
27710 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
27711 + [AuWbrCopyup_TDP] = {
27712 + .copyup = au_wbr_copyup_tdp
27714 + [AuWbrCopyup_BUP] = {
27715 + .copyup = au_wbr_copyup_bup
27717 + [AuWbrCopyup_BU] = {
27718 + .copyup = au_wbr_copyup_bu
27722 +struct au_wbr_create_operations au_wbr_create_ops[] = {
27723 + [AuWbrCreate_TDP] = {
27724 + .create = au_wbr_create_tdp
27726 + [AuWbrCreate_RR] = {
27727 + .create = au_wbr_create_rr,
27728 + .init = au_wbr_create_init_rr
27730 + [AuWbrCreate_MFS] = {
27731 + .create = au_wbr_create_mfs,
27732 + .init = au_wbr_create_init_mfs,
27733 + .fin = au_wbr_create_fin_mfs
27735 + [AuWbrCreate_MFSV] = {
27736 + .create = au_wbr_create_mfs,
27737 + .init = au_wbr_create_init_mfs,
27738 + .fin = au_wbr_create_fin_mfs
27740 + [AuWbrCreate_MFSRR] = {
27741 + .create = au_wbr_create_mfsrr,
27742 + .init = au_wbr_create_init_mfsrr,
27743 + .fin = au_wbr_create_fin_mfs
27745 + [AuWbrCreate_MFSRRV] = {
27746 + .create = au_wbr_create_mfsrr,
27747 + .init = au_wbr_create_init_mfsrr,
27748 + .fin = au_wbr_create_fin_mfs
27750 + [AuWbrCreate_PMFS] = {
27751 + .create = au_wbr_create_pmfs,
27752 + .init = au_wbr_create_init_mfs,
27753 + .fin = au_wbr_create_fin_mfs
27755 + [AuWbrCreate_PMFSV] = {
27756 + .create = au_wbr_create_pmfs,
27757 + .init = au_wbr_create_init_mfs,
27758 + .fin = au_wbr_create_fin_mfs
27761 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
27762 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
27763 +++ linux/fs/aufs/whout.c 2012-07-22 19:57:03.167671344 +0200
27766 + * Copyright (C) 2005-2012 Junjiro R. Okajima
27768 + * This program, aufs is free software; you can redistribute it and/or modify
27769 + * it under the terms of the GNU General Public License as published by
27770 + * the Free Software Foundation; either version 2 of the License, or
27771 + * (at your option) any later version.
27773 + * This program is distributed in the hope that it will be useful,
27774 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27775 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27776 + * GNU General Public License for more details.
27778 + * You should have received a copy of the GNU General Public License
27779 + * along with this program; if not, write to the Free Software
27780 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27784 + * whiteout for logical deletion and opaque directory
27789 +#define WH_MASK S_IRUGO
27792 + * If a directory contains this file, then it is opaque. We start with the
27793 + * .wh. flag so that it is blocked by lookup.
27795 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
27796 + sizeof(AUFS_WH_DIROPQ) - 1);
27799 + * generate whiteout name, which is NOT terminated by NULL.
27800 + * @name: original d_name.name
27801 + * @len: original d_name.len
27802 + * @wh: whiteout qstr
27803 + * returns zero when succeeds, otherwise error.
27804 + * succeeded value as wh->name should be freed by kfree().
27806 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
27810 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
27811 + return -ENAMETOOLONG;
27813 + wh->len = name->len + AUFS_WH_PFX_LEN;
27814 + p = kmalloc(wh->len, GFP_NOFS);
27817 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
27818 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
27825 +/* ---------------------------------------------------------------------- */
27828 + * test if the @wh_name exists under @h_parent.
27829 + * @try_sio specifies the necessary of super-io.
27831 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name,
27832 + struct au_branch *br, int try_sio)
27835 + struct dentry *wh_dentry;
27838 + wh_dentry = au_lkup_one(wh_name, h_parent, br, /*nd*/NULL);
27840 + wh_dentry = au_sio_lkup_one(wh_name, h_parent, br);
27841 + err = PTR_ERR(wh_dentry);
27842 + if (IS_ERR(wh_dentry))
27846 + if (!wh_dentry->d_inode)
27847 + goto out_wh; /* success */
27850 + if (S_ISREG(wh_dentry->d_inode->i_mode))
27851 + goto out_wh; /* success */
27854 + AuIOErr("%.*s Invalid whiteout entry type 0%o.\n",
27855 + AuDLNPair(wh_dentry), wh_dentry->d_inode->i_mode);
27864 + * test if the @h_dentry sets opaque or not.
27866 +int au_diropq_test(struct dentry *h_dentry, struct au_branch *br)
27869 + struct inode *h_dir;
27871 + h_dir = h_dentry->d_inode;
27872 + err = au_wh_test(h_dentry, &diropq_name, br,
27873 + au_test_h_perm_sio(h_dir, MAY_EXEC));
27878 + * returns a negative dentry whose name is unique and temporary.
27880 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
27881 + struct qstr *prefix)
27883 + struct dentry *dentry;
27885 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
27887 + /* strict atomic_t is unnecessary here */
27888 + static unsigned short cnt;
27891 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
27894 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
27895 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
27896 + dentry = ERR_PTR(-ENAMETOOLONG);
27897 + if (unlikely(qs.len > NAME_MAX))
27899 + dentry = ERR_PTR(-ENOMEM);
27900 + name = kmalloc(qs.len + 1, GFP_NOFS);
27901 + if (unlikely(!name))
27905 + /* doubly whiteout-ed */
27906 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
27907 + p = name + AUFS_WH_PFX_LEN * 2;
27908 + memcpy(p, prefix->name, prefix->len);
27909 + p += prefix->len;
27911 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
27914 + for (i = 0; i < 3; i++) {
27915 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
27916 + dentry = au_sio_lkup_one(&qs, h_parent, br);
27917 + if (IS_ERR(dentry) || !dentry->d_inode)
27921 + /* pr_warn("could not get random name\n"); */
27922 + dentry = ERR_PTR(-EEXIST);
27923 + AuDbg("%.*s\n", AuLNPair(&qs));
27927 + if (name != defname)
27930 + AuTraceErrPtr(dentry);
27935 + * rename the @h_dentry on @br to the whiteouted temporary name.
27937 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
27940 + struct path h_path = {
27941 + .mnt = br->br_mnt
27943 + struct inode *h_dir;
27944 + struct dentry *h_parent;
27946 + h_parent = h_dentry->d_parent; /* dir inode is locked */
27947 + h_dir = h_parent->d_inode;
27948 + IMustLock(h_dir);
27950 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
27951 + err = PTR_ERR(h_path.dentry);
27952 + if (IS_ERR(h_path.dentry))
27955 + /* under the same dir, no need to lock_rename() */
27956 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path);
27958 + dput(h_path.dentry);
27965 +/* ---------------------------------------------------------------------- */
27967 + * functions for removing a whiteout
27970 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
27975 + * forces superio when the dir has a sticky bit.
27976 + * this may be a violation of unix fs semantics.
27978 + force = (h_dir->i_mode & S_ISVTX)
27979 + && !uid_eq(current_fsuid(), h_path->dentry->d_inode->i_uid);
27980 + return vfsub_unlink(h_dir, h_path, force);
27983 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
27984 + struct dentry *dentry)
27988 + err = do_unlink_wh(h_dir, h_path);
27989 + if (!err && dentry)
27990 + au_set_dbwh(dentry, -1);
27995 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
27996 + struct au_branch *br)
27999 + struct path h_path = {
28000 + .mnt = br->br_mnt
28004 + h_path.dentry = au_lkup_one(wh, h_parent, br, /*nd*/NULL);
28005 + if (IS_ERR(h_path.dentry))
28006 + err = PTR_ERR(h_path.dentry);
28008 + if (h_path.dentry->d_inode
28009 + && S_ISREG(h_path.dentry->d_inode->i_mode))
28010 + err = do_unlink_wh(h_parent->d_inode, &h_path);
28011 + dput(h_path.dentry);
28017 +/* ---------------------------------------------------------------------- */
28019 + * initialize/clean whiteout for a branch
28022 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
28027 + if (!whpath->dentry->d_inode)
28030 + err = mnt_want_write(whpath->mnt);
28033 + err = vfsub_rmdir(h_dir, whpath);
28035 + err = vfsub_unlink(h_dir, whpath, /*force*/0);
28036 + mnt_drop_write(whpath->mnt);
28038 + if (unlikely(err))
28039 + pr_warn("failed removing %.*s (%d), ignored.\n",
28040 + AuDLNPair(whpath->dentry), err);
28043 +static int test_linkable(struct dentry *h_root)
28045 + struct inode *h_dir = h_root->d_inode;
28047 + if (h_dir->i_op->link)
28050 + pr_err("%.*s (%s) doesn't support link(2), use noplink and rw+nolwh\n",
28051 + AuDLNPair(h_root), au_sbtype(h_root->d_sb));
28055 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
28056 +static int au_whdir(struct inode *h_dir, struct path *path)
28061 + if (!path->dentry->d_inode) {
28062 + int mode = S_IRWXU;
28064 + if (au_test_nfs(path->dentry->d_sb))
28066 + err = mnt_want_write(path->mnt);
28068 + err = vfsub_mkdir(h_dir, path, mode);
28069 + mnt_drop_write(path->mnt);
28071 + } else if (S_ISDIR(path->dentry->d_inode->i_mode))
28074 + pr_err("unknown %.*s exists\n", AuDLNPair(path->dentry));
28079 +struct au_wh_base {
28080 + const struct qstr *name;
28081 + struct dentry *dentry;
28084 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
28085 + struct path *h_path)
28087 + h_path->dentry = base[AuBrWh_BASE].dentry;
28088 + au_wh_clean(h_dir, h_path, /*isdir*/0);
28089 + h_path->dentry = base[AuBrWh_PLINK].dentry;
28090 + au_wh_clean(h_dir, h_path, /*isdir*/1);
28091 + h_path->dentry = base[AuBrWh_ORPH].dentry;
28092 + au_wh_clean(h_dir, h_path, /*isdir*/1);
28096 + * returns tri-state,
28097 + * minus: error, caller should print the mesage
28099 + * plus: error, caller should NOT print the mesage
28101 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
28102 + int do_plink, struct au_wh_base base[],
28103 + struct path *h_path)
28106 + struct inode *h_dir;
28108 + h_dir = h_root->d_inode;
28109 + h_path->dentry = base[AuBrWh_BASE].dentry;
28110 + au_wh_clean(h_dir, h_path, /*isdir*/0);
28111 + h_path->dentry = base[AuBrWh_PLINK].dentry;
28113 + err = test_linkable(h_root);
28114 + if (unlikely(err)) {
28119 + err = au_whdir(h_dir, h_path);
28120 + if (unlikely(err))
28122 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
28124 + au_wh_clean(h_dir, h_path, /*isdir*/1);
28125 + h_path->dentry = base[AuBrWh_ORPH].dentry;
28126 + err = au_whdir(h_dir, h_path);
28127 + if (unlikely(err))
28129 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
28136 + * for the moment, aufs supports the branch filesystem which does not support
28137 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
28138 + * copyup failed. finally, such filesystem will not be used as the writable
28141 + * returns tri-state, see above.
28143 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
28144 + int do_plink, struct au_wh_base base[],
28145 + struct path *h_path)
28148 + struct inode *h_dir;
28150 + WbrWhMustWriteLock(wbr);
28152 + err = test_linkable(h_root);
28153 + if (unlikely(err)) {
28159 + * todo: should this create be done in /sbin/mount.aufs helper?
28162 + h_dir = h_root->d_inode;
28163 + if (!base[AuBrWh_BASE].dentry->d_inode) {
28164 + err = mnt_want_write(h_path->mnt);
28166 + h_path->dentry = base[AuBrWh_BASE].dentry;
28167 + err = vfsub_create(h_dir, h_path, WH_MASK);
28168 + mnt_drop_write(h_path->mnt);
28170 + } else if (S_ISREG(base[AuBrWh_BASE].dentry->d_inode->i_mode))
28173 + pr_err("unknown %.*s/%.*s exists\n",
28174 + AuDLNPair(h_root), AuDLNPair(base[AuBrWh_BASE].dentry));
28175 + if (unlikely(err))
28178 + h_path->dentry = base[AuBrWh_PLINK].dentry;
28180 + err = au_whdir(h_dir, h_path);
28181 + if (unlikely(err))
28183 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
28185 + au_wh_clean(h_dir, h_path, /*isdir*/1);
28186 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
28188 + h_path->dentry = base[AuBrWh_ORPH].dentry;
28189 + err = au_whdir(h_dir, h_path);
28190 + if (unlikely(err))
28192 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
28199 + * initialize the whiteout base file/dir for @br.
28201 +int au_wh_init(struct dentry *h_root, struct au_branch *br,
28202 + struct super_block *sb)
28205 + const unsigned char do_plink
28206 + = !!au_opt_test(au_mntflags(sb), PLINK);
28207 + struct path path = {
28208 + .mnt = br->br_mnt
28210 + struct inode *h_dir;
28211 + struct au_wbr *wbr = br->br_wbr;
28212 + static const struct qstr base_name[] = {
28213 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
28214 + sizeof(AUFS_BASE_NAME) - 1),
28215 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
28216 + sizeof(AUFS_PLINKDIR_NAME) - 1),
28217 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
28218 + sizeof(AUFS_ORPHDIR_NAME) - 1)
28220 + struct au_wh_base base[] = {
28221 + [AuBrWh_BASE] = {
28222 + .name = base_name + AuBrWh_BASE,
28225 + [AuBrWh_PLINK] = {
28226 + .name = base_name + AuBrWh_PLINK,
28229 + [AuBrWh_ORPH] = {
28230 + .name = base_name + AuBrWh_ORPH,
28236 + WbrWhMustWriteLock(wbr);
28238 + for (i = 0; i < AuBrWh_Last; i++) {
28239 + /* doubly whiteouted */
28240 + struct dentry *d;
28242 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
28243 + err = PTR_ERR(d);
28247 + base[i].dentry = d;
28249 + && wbr->wbr_wh[i]
28250 + && wbr->wbr_wh[i] != base[i].dentry);
28254 + for (i = 0; i < AuBrWh_Last; i++) {
28255 + dput(wbr->wbr_wh[i]);
28256 + wbr->wbr_wh[i] = NULL;
28260 + if (!au_br_writable(br->br_perm)) {
28261 + h_dir = h_root->d_inode;
28262 + au_wh_init_ro(h_dir, base, &path);
28263 + } else if (!au_br_wh_linkable(br->br_perm)) {
28264 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
28270 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
28276 + goto out; /* success */
28279 + pr_err("an error(%d) on the writable branch %.*s(%s)\n",
28280 + err, AuDLNPair(h_root), au_sbtype(h_root->d_sb));
28282 + for (i = 0; i < AuBrWh_Last; i++)
28283 + dput(base[i].dentry);
28287 +/* ---------------------------------------------------------------------- */
28289 + * whiteouts are all hard-linked usually.
28290 + * when its link count reaches a ceiling, we create a new whiteout base
28291 + * asynchronously.
28294 +struct reinit_br_wh {
28295 + struct super_block *sb;
28296 + struct au_branch *br;
28299 +static void reinit_br_wh(void *arg)
28302 + aufs_bindex_t bindex;
28303 + struct path h_path;
28304 + struct reinit_br_wh *a = arg;
28305 + struct au_wbr *wbr;
28306 + struct inode *dir;
28307 + struct dentry *h_root;
28308 + struct au_hinode *hdir;
28311 + wbr = a->br->br_wbr;
28312 + /* big aufs lock */
28313 + si_noflush_write_lock(a->sb);
28314 + if (!au_br_writable(a->br->br_perm))
28316 + bindex = au_br_index(a->sb, a->br->br_id);
28317 + if (unlikely(bindex < 0))
28320 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
28321 + dir = a->sb->s_root->d_inode;
28322 + hdir = au_hi(dir, bindex);
28323 + h_root = au_h_dptr(a->sb->s_root, bindex);
28325 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
28326 + wbr_wh_write_lock(wbr);
28327 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
28330 + err = mnt_want_write(a->br->br_mnt);
28332 + h_path.dentry = wbr->wbr_whbase;
28333 + h_path.mnt = a->br->br_mnt;
28334 + err = vfsub_unlink(hdir->hi_inode, &h_path, /*force*/0);
28335 + mnt_drop_write(a->br->br_mnt);
28338 + pr_warn("%.*s is moved, ignored\n",
28339 + AuDLNPair(wbr->wbr_whbase));
28342 + dput(wbr->wbr_whbase);
28343 + wbr->wbr_whbase = NULL;
28345 + err = au_wh_init(h_root, a->br, a->sb);
28346 + wbr_wh_write_unlock(wbr);
28347 + au_hn_imtx_unlock(hdir);
28348 + di_read_unlock(a->sb->s_root, AuLock_IR);
28352 + atomic_dec(&wbr->wbr_wh_running);
28353 + atomic_dec(&a->br->br_count);
28354 + si_write_unlock(a->sb);
28355 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
28357 + if (unlikely(err))
28358 + AuIOErr("err %d\n", err);
28361 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
28363 + int do_dec, wkq_err;
28364 + struct reinit_br_wh *arg;
28367 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
28370 + /* ignore ENOMEM */
28371 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
28374 + * dec(wh_running), kfree(arg) and dec(br_count)
28375 + * in reinit function
28379 + atomic_inc(&br->br_count);
28380 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
28381 + if (unlikely(wkq_err)) {
28382 + atomic_dec(&br->br_wbr->wbr_wh_running);
28383 + atomic_dec(&br->br_count);
28391 + atomic_dec(&br->br_wbr->wbr_wh_running);
28394 +/* ---------------------------------------------------------------------- */
28397 + * create the whiteout @wh.
28399 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
28400 + struct dentry *wh)
28403 + struct path h_path = {
28406 + struct au_branch *br;
28407 + struct au_wbr *wbr;
28408 + struct dentry *h_parent;
28409 + struct inode *h_dir;
28411 + h_parent = wh->d_parent; /* dir inode is locked */
28412 + h_dir = h_parent->d_inode;
28413 + IMustLock(h_dir);
28415 + br = au_sbr(sb, bindex);
28416 + h_path.mnt = br->br_mnt;
28417 + wbr = br->br_wbr;
28418 + wbr_wh_read_lock(wbr);
28419 + if (wbr->wbr_whbase) {
28420 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path);
28421 + if (!err || err != -EMLINK)
28424 + /* link count full. re-initialize br_whbase. */
28425 + kick_reinit_br_wh(sb, br);
28428 + /* return this error in this context */
28429 + err = vfsub_create(h_dir, &h_path, WH_MASK);
28432 + wbr_wh_read_unlock(wbr);
28436 +/* ---------------------------------------------------------------------- */
28439 + * create or remove the diropq.
28441 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
28442 + unsigned int flags)
28444 + struct dentry *opq_dentry, *h_dentry;
28445 + struct super_block *sb;
28446 + struct au_branch *br;
28449 + sb = dentry->d_sb;
28450 + br = au_sbr(sb, bindex);
28451 + h_dentry = au_h_dptr(dentry, bindex);
28452 + opq_dentry = au_lkup_one(&diropq_name, h_dentry, br, /*nd*/NULL);
28453 + if (IS_ERR(opq_dentry))
28456 + if (au_ftest_diropq(flags, CREATE)) {
28457 + err = link_or_create_wh(sb, bindex, opq_dentry);
28459 + au_set_dbdiropq(dentry, bindex);
28460 + goto out; /* success */
28463 + struct path tmp = {
28464 + .dentry = opq_dentry,
28465 + .mnt = br->br_mnt
28467 + err = do_unlink_wh(au_h_iptr(dentry->d_inode, bindex), &tmp);
28469 + au_set_dbdiropq(dentry, -1);
28471 + dput(opq_dentry);
28472 + opq_dentry = ERR_PTR(err);
28475 + return opq_dentry;
28478 +struct do_diropq_args {
28479 + struct dentry **errp;
28480 + struct dentry *dentry;
28481 + aufs_bindex_t bindex;
28482 + unsigned int flags;
28485 +static void call_do_diropq(void *args)
28487 + struct do_diropq_args *a = args;
28488 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
28491 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
28492 + unsigned int flags)
28494 + struct dentry *diropq, *h_dentry;
28496 + h_dentry = au_h_dptr(dentry, bindex);
28497 + if (!au_test_h_perm_sio(h_dentry->d_inode, MAY_EXEC | MAY_WRITE))
28498 + diropq = do_diropq(dentry, bindex, flags);
28501 + struct do_diropq_args args = {
28503 + .dentry = dentry,
28504 + .bindex = bindex,
28508 + wkq_err = au_wkq_wait(call_do_diropq, &args);
28509 + if (unlikely(wkq_err))
28510 + diropq = ERR_PTR(wkq_err);
28516 +/* ---------------------------------------------------------------------- */
28519 + * lookup whiteout dentry.
28520 + * @h_parent: lower parent dentry which must exist and be locked
28521 + * @base_name: name of dentry which will be whiteouted
28522 + * returns dentry for whiteout.
28524 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
28525 + struct au_branch *br)
28528 + struct qstr wh_name;
28529 + struct dentry *wh_dentry;
28531 + err = au_wh_name_alloc(&wh_name, base_name);
28532 + wh_dentry = ERR_PTR(err);
28534 + wh_dentry = au_lkup_one(&wh_name, h_parent, br, /*nd*/NULL);
28535 + kfree(wh_name.name);
28537 + return wh_dentry;
28541 + * link/create a whiteout for @dentry on @bindex.
28543 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
28544 + struct dentry *h_parent)
28546 + struct dentry *wh_dentry;
28547 + struct super_block *sb;
28550 + sb = dentry->d_sb;
28551 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
28552 + if (!IS_ERR(wh_dentry) && !wh_dentry->d_inode) {
28553 + err = link_or_create_wh(sb, bindex, wh_dentry);
28555 + au_set_dbwh(dentry, bindex);
28558 + wh_dentry = ERR_PTR(err);
28562 + return wh_dentry;
28565 +/* ---------------------------------------------------------------------- */
28567 +/* Delete all whiteouts in this directory on branch bindex. */
28568 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
28569 + aufs_bindex_t bindex, struct au_branch *br)
28572 + unsigned long ul, n;
28573 + struct qstr wh_name;
28575 + struct hlist_head *head;
28576 + struct au_vdir_wh *tpos;
28577 + struct hlist_node *pos;
28578 + struct au_vdir_destr *str;
28581 + p = __getname_gfp(GFP_NOFS);
28582 + wh_name.name = p;
28583 + if (unlikely(!wh_name.name))
28587 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
28588 + p += AUFS_WH_PFX_LEN;
28589 + n = whlist->nh_num;
28590 + head = whlist->nh_head;
28591 + for (ul = 0; !err && ul < n; ul++, head++) {
28592 + hlist_for_each_entry(tpos, pos, head, wh_hash) {
28593 + if (tpos->wh_bindex != bindex)
28596 + str = &tpos->wh_str;
28597 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
28598 + memcpy(p, str->name, str->len);
28599 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
28600 + err = unlink_wh_name(h_dentry, &wh_name, br);
28605 + AuIOErr("whiteout name too long %.*s\n",
28606 + str->len, str->name);
28611 + __putname(wh_name.name);
28617 +struct del_wh_children_args {
28619 + struct dentry *h_dentry;
28620 + struct au_nhash *whlist;
28621 + aufs_bindex_t bindex;
28622 + struct au_branch *br;
28625 +static void call_del_wh_children(void *args)
28627 + struct del_wh_children_args *a = args;
28628 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
28631 +/* ---------------------------------------------------------------------- */
28633 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
28635 + struct au_whtmp_rmdir *whtmp;
28637 + unsigned int rdhash;
28639 + SiMustAnyLock(sb);
28641 + whtmp = kmalloc(sizeof(*whtmp), gfp);
28642 + if (unlikely(!whtmp)) {
28643 + whtmp = ERR_PTR(-ENOMEM);
28647 + whtmp->dir = NULL;
28648 + whtmp->br = NULL;
28649 + whtmp->wh_dentry = NULL;
28650 + /* no estimation for dir size */
28651 + rdhash = au_sbi(sb)->si_rdhash;
28653 + rdhash = AUFS_RDHASH_DEF;
28654 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
28655 + if (unlikely(err)) {
28657 + whtmp = ERR_PTR(err);
28664 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
28667 + atomic_dec(&whtmp->br->br_count);
28668 + dput(whtmp->wh_dentry);
28669 + iput(whtmp->dir);
28670 + au_nhash_wh_free(&whtmp->whlist);
28675 + * rmdir the whiteouted temporary named dir @h_dentry.
28676 + * @whlist: whiteouted children.
28678 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
28679 + struct dentry *wh_dentry, struct au_nhash *whlist)
28682 + struct path h_tmp;
28683 + struct inode *wh_inode, *h_dir;
28684 + struct au_branch *br;
28686 + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
28687 + IMustLock(h_dir);
28689 + br = au_sbr(dir->i_sb, bindex);
28690 + wh_inode = wh_dentry->d_inode;
28691 + mutex_lock_nested(&wh_inode->i_mutex, AuLsc_I_CHILD);
28694 + * someone else might change some whiteouts while we were sleeping.
28695 + * it means this whlist may have an obsoleted entry.
28697 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
28698 + err = del_wh_children(wh_dentry, whlist, bindex, br);
28701 + struct del_wh_children_args args = {
28703 + .h_dentry = wh_dentry,
28704 + .whlist = whlist,
28705 + .bindex = bindex,
28709 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
28710 + if (unlikely(wkq_err))
28713 + mutex_unlock(&wh_inode->i_mutex);
28716 + h_tmp.dentry = wh_dentry;
28717 + h_tmp.mnt = br->br_mnt;
28718 + err = vfsub_rmdir(h_dir, &h_tmp);
28722 + if (au_ibstart(dir) == bindex) {
28723 + /* todo: dir->i_mutex is necessary */
28724 + au_cpup_attr_timesizes(dir);
28725 + vfsub_drop_nlink(dir);
28727 + return 0; /* success */
28730 + pr_warn("failed removing %.*s(%d), ignored\n",
28731 + AuDLNPair(wh_dentry), err);
28735 +static void call_rmdir_whtmp(void *args)
28738 + aufs_bindex_t bindex;
28739 + struct au_whtmp_rmdir *a = args;
28740 + struct super_block *sb;
28741 + struct dentry *h_parent;
28742 + struct inode *h_dir;
28743 + struct au_hinode *hdir;
28745 + /* rmdir by nfsd may cause deadlock with this i_mutex */
28746 + /* mutex_lock(&a->dir->i_mutex); */
28748 + sb = a->dir->i_sb;
28749 + si_read_lock(sb, !AuLock_FLUSH);
28750 + if (!au_br_writable(a->br->br_perm))
28752 + bindex = au_br_index(sb, a->br->br_id);
28753 + if (unlikely(bindex < 0))
28757 + ii_write_lock_parent(a->dir);
28758 + h_parent = dget_parent(a->wh_dentry);
28759 + h_dir = h_parent->d_inode;
28760 + hdir = au_hi(a->dir, bindex);
28761 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
28762 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
28765 + err = mnt_want_write(a->br->br_mnt);
28767 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry,
28769 + mnt_drop_write(a->br->br_mnt);
28772 + au_hn_imtx_unlock(hdir);
28774 + ii_write_unlock(a->dir);
28777 + /* mutex_unlock(&a->dir->i_mutex); */
28778 + au_whtmp_rmdir_free(a);
28779 + si_read_unlock(sb);
28780 + au_nwt_done(&au_sbi(sb)->si_nowait);
28781 + if (unlikely(err))
28782 + AuIOErr("err %d\n", err);
28785 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
28786 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
28789 + struct super_block *sb;
28793 + /* all post-process will be done in do_rmdir_whtmp(). */
28795 + args->dir = au_igrab(dir);
28796 + args->br = au_sbr(sb, bindex);
28797 + atomic_inc(&args->br->br_count);
28798 + args->wh_dentry = dget(wh_dentry);
28799 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
28800 + if (unlikely(wkq_err)) {
28801 + pr_warn("rmdir error %.*s (%d), ignored\n",
28802 + AuDLNPair(wh_dentry), wkq_err);
28803 + au_whtmp_rmdir_free(args);
28806 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
28807 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
28808 +++ linux/fs/aufs/whout.h 2012-07-22 19:57:03.167671344 +0200
28811 + * Copyright (C) 2005-2012 Junjiro R. Okajima
28813 + * This program, aufs is free software; you can redistribute it and/or modify
28814 + * it under the terms of the GNU General Public License as published by
28815 + * the Free Software Foundation; either version 2 of the License, or
28816 + * (at your option) any later version.
28818 + * This program is distributed in the hope that it will be useful,
28819 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28820 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28821 + * GNU General Public License for more details.
28823 + * You should have received a copy of the GNU General Public License
28824 + * along with this program; if not, write to the Free Software
28825 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28829 + * whiteout for logical deletion and opaque directory
28832 +#ifndef __AUFS_WHOUT_H__
28833 +#define __AUFS_WHOUT_H__
28840 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
28842 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name,
28843 + struct au_branch *br, int try_sio);
28844 +int au_diropq_test(struct dentry *h_dentry, struct au_branch *br);
28845 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
28846 + struct qstr *prefix);
28847 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
28848 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
28849 + struct dentry *dentry);
28850 +int au_wh_init(struct dentry *h_parent, struct au_branch *br,
28851 + struct super_block *sb);
28853 +/* diropq flags */
28854 +#define AuDiropq_CREATE 1
28855 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
28856 +#define au_fset_diropq(flags, name) \
28857 + do { (flags) |= AuDiropq_##name; } while (0)
28858 +#define au_fclr_diropq(flags, name) \
28859 + do { (flags) &= ~AuDiropq_##name; } while (0)
28861 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
28862 + unsigned int flags);
28863 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
28864 + struct au_branch *br);
28865 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
28866 + struct dentry *h_parent);
28868 +/* real rmdir for the whiteout-ed dir */
28869 +struct au_whtmp_rmdir {
28870 + struct inode *dir;
28871 + struct au_branch *br;
28872 + struct dentry *wh_dentry;
28873 + struct au_nhash whlist;
28876 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
28877 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
28878 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
28879 + struct dentry *wh_dentry, struct au_nhash *whlist);
28880 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
28881 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
28883 +/* ---------------------------------------------------------------------- */
28885 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
28886 + aufs_bindex_t bindex)
28888 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
28891 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
28893 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
28896 +#endif /* __KERNEL__ */
28897 +#endif /* __AUFS_WHOUT_H__ */
28898 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
28899 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
28900 +++ linux/fs/aufs/wkq.c 2012-07-22 19:57:03.167671344 +0200
28903 + * Copyright (C) 2005-2012 Junjiro R. Okajima
28905 + * This program, aufs is free software; you can redistribute it and/or modify
28906 + * it under the terms of the GNU General Public License as published by
28907 + * the Free Software Foundation; either version 2 of the License, or
28908 + * (at your option) any later version.
28910 + * This program is distributed in the hope that it will be useful,
28911 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28912 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28913 + * GNU General Public License for more details.
28915 + * You should have received a copy of the GNU General Public License
28916 + * along with this program; if not, write to the Free Software
28917 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28921 + * workqueue for asynchronous/super-io operations
28922 + * todo: try new dredential scheme
28925 +#include <linux/module.h>
28928 +/* internal workqueue named AUFS_WKQ_NAME */
28930 +static struct workqueue_struct *au_wkq;
28932 +struct au_wkinfo {
28933 + struct work_struct wk;
28934 + struct kobject *kobj;
28936 + unsigned int flags; /* see wkq.h */
28938 + au_wkq_func_t func;
28941 + struct completion *comp;
28944 +/* ---------------------------------------------------------------------- */
28946 +static void wkq_func(struct work_struct *wk)
28948 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
28950 + AuDebugOn(current_fsuid() != GLOBAL_ROOT_GID);
28951 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
28953 + wkinfo->func(wkinfo->args);
28954 + if (au_ftest_wkq(wkinfo->flags, WAIT))
28955 + complete(wkinfo->comp);
28957 + kobject_put(wkinfo->kobj);
28958 + module_put(THIS_MODULE); /* todo: ?? */
28964 + * Since struct completion is large, try allocating it dynamically.
28966 +#if defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS)
28967 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
28969 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
28971 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
28973 + init_completion(*comp);
28974 + wkinfo->comp = *comp;
28980 +static void au_wkq_comp_free(struct completion *comp)
28988 +#define AuWkqCompDeclare(name) \
28989 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
28990 + struct completion *comp = &_ ## name
28992 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
28994 + wkinfo->comp = *comp;
28998 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
29002 +#endif /* 4KSTACKS */
29004 +static void au_wkq_run(struct au_wkinfo *wkinfo)
29006 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
29007 + if (au_wkq_test()) {
29008 + AuWarn1("wkq from wkq, due to a dead dir by UDBA?\n");
29009 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
29012 + au_dbg_verify_kthread();
29014 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
29015 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
29016 + queue_work(au_wkq, &wkinfo->wk);
29018 + INIT_WORK(&wkinfo->wk, wkq_func);
29019 + schedule_work(&wkinfo->wk);
29024 + * Be careful. It is easy to make deadlock happen.
29025 + * processA: lock, wkq and wait
29026 + * processB: wkq and wait, lock in wkq
29029 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
29032 + AuWkqCompDeclare(comp);
29033 + struct au_wkinfo wkinfo = {
29039 + err = au_wkq_comp_alloc(&wkinfo, &comp);
29041 + au_wkq_run(&wkinfo);
29042 + /* no timeout, no interrupt */
29043 + wait_for_completion(wkinfo.comp);
29044 + au_wkq_comp_free(comp);
29045 + destroy_work_on_stack(&wkinfo.wk);
29053 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
29054 + * problem in a concurrent umounting.
29056 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
29057 + unsigned int flags)
29060 + struct au_wkinfo *wkinfo;
29062 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
29065 + * wkq_func() must free this wkinfo.
29066 + * it highly depends upon the implementation of workqueue.
29069 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
29071 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
29072 + wkinfo->flags = flags & ~AuWkq_WAIT;
29073 + wkinfo->func = func;
29074 + wkinfo->args = args;
29075 + wkinfo->comp = NULL;
29076 + kobject_get(wkinfo->kobj);
29077 + __module_get(THIS_MODULE); /* todo: ?? */
29079 + au_wkq_run(wkinfo);
29082 + au_nwt_done(&au_sbi(sb)->si_nowait);
29088 +/* ---------------------------------------------------------------------- */
29090 +void au_nwt_init(struct au_nowait_tasks *nwt)
29092 + atomic_set(&nwt->nw_len, 0);
29093 + /* smp_mb(); */ /* atomic_set */
29094 + init_waitqueue_head(&nwt->nw_wq);
29097 +void au_wkq_fin(void)
29099 + destroy_workqueue(au_wkq);
29102 +int __init au_wkq_init(void)
29107 + BUILD_BUG_ON(!WQ_RESCUER);
29108 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, !WQ_RESCUER, WQ_DFL_ACTIVE);
29109 + if (IS_ERR(au_wkq))
29110 + err = PTR_ERR(au_wkq);
29111 + else if (!au_wkq)
29116 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
29117 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
29118 +++ linux/fs/aufs/wkq.h 2012-07-22 19:57:03.167671344 +0200
29121 + * Copyright (C) 2005-2012 Junjiro R. Okajima
29123 + * This program, aufs is free software; you can redistribute it and/or modify
29124 + * it under the terms of the GNU General Public License as published by
29125 + * the Free Software Foundation; either version 2 of the License, or
29126 + * (at your option) any later version.
29128 + * This program is distributed in the hope that it will be useful,
29129 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29130 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29131 + * GNU General Public License for more details.
29133 + * You should have received a copy of the GNU General Public License
29134 + * along with this program; if not, write to the Free Software
29135 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29139 + * workqueue for asynchronous/super-io operations
29140 + * todo: try new credentials management scheme
29143 +#ifndef __AUFS_WKQ_H__
29144 +#define __AUFS_WKQ_H__
29148 +struct super_block;
29150 +/* ---------------------------------------------------------------------- */
29153 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
29155 +struct au_nowait_tasks {
29157 + wait_queue_head_t nw_wq;
29160 +/* ---------------------------------------------------------------------- */
29162 +typedef void (*au_wkq_func_t)(void *args);
29165 +#define AuWkq_WAIT 1
29166 +#define AuWkq_NEST (1 << 1)
29167 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
29168 +#define au_fset_wkq(flags, name) \
29169 + do { (flags) |= AuWkq_##name; } while (0)
29170 +#define au_fclr_wkq(flags, name) \
29171 + do { (flags) &= ~AuWkq_##name; } while (0)
29173 +#ifndef CONFIG_AUFS_HNOTIFY
29175 +#define AuWkq_NEST 0
29179 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
29180 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
29181 + unsigned int flags);
29182 +void au_nwt_init(struct au_nowait_tasks *nwt);
29183 +int __init au_wkq_init(void);
29184 +void au_wkq_fin(void);
29186 +/* ---------------------------------------------------------------------- */
29188 +static inline int au_wkq_test(void)
29190 + return current->flags & PF_WQ_WORKER;
29193 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
29195 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
29198 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
29200 + if (atomic_dec_and_test(&nwt->nw_len))
29201 + wake_up_all(&nwt->nw_wq);
29204 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
29206 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
29210 +#endif /* __KERNEL__ */
29211 +#endif /* __AUFS_WKQ_H__ */
29212 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
29213 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
29214 +++ linux/fs/aufs/xino.c 2012-07-22 19:57:03.167671344 +0200
29217 + * Copyright (C) 2005-2012 Junjiro R. Okajima
29219 + * This program, aufs is free software; you can redistribute it and/or modify
29220 + * it under the terms of the GNU General Public License as published by
29221 + * the Free Software Foundation; either version 2 of the License, or
29222 + * (at your option) any later version.
29224 + * This program is distributed in the hope that it will be useful,
29225 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29226 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29227 + * GNU General Public License for more details.
29229 + * You should have received a copy of the GNU General Public License
29230 + * along with this program; if not, write to the Free Software
29231 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29235 + * external inode number translation table and bitmap
29238 +#include <linux/seq_file.h>
29241 +/* todo: unnecessary to support mmap_sem since kernel-space? */
29242 +ssize_t xino_fread(au_readf_t func, struct file *file, void *kbuf, size_t size,
29246 + mm_segment_t oldfs;
29253 + oldfs = get_fs();
29254 + set_fs(KERNEL_DS);
29256 + /* todo: signal_pending? */
29257 + err = func(file, buf.u, size, pos);
29258 + } while (err == -EAGAIN || err == -EINTR);
29261 +#if 0 /* reserved for future use */
29263 + fsnotify_access(file->f_dentry);
29269 +/* ---------------------------------------------------------------------- */
29271 +static ssize_t do_xino_fwrite(au_writef_t func, struct file *file, void *kbuf,
29272 + size_t size, loff_t *pos)
29275 + mm_segment_t oldfs;
29278 + const char __user *u;
29282 + oldfs = get_fs();
29283 + set_fs(KERNEL_DS);
29285 + /* todo: signal_pending? */
29286 + err = func(file, buf.u, size, pos);
29287 + } while (err == -EAGAIN || err == -EINTR);
29290 +#if 0 /* reserved for future use */
29292 + fsnotify_modify(file->f_dentry);
29298 +struct do_xino_fwrite_args {
29300 + au_writef_t func;
29301 + struct file *file;
29307 +static void call_do_xino_fwrite(void *args)
29309 + struct do_xino_fwrite_args *a = args;
29310 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
29313 +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size,
29318 + /* todo: signal block and no wkq? */
29319 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
29321 + err = do_xino_fwrite(func, file, buf, size, pos);
29325 + * it breaks RLIMIT_FSIZE and normal user's limit,
29326 + * users should care about quota and real 'filesystem full.'
29329 + struct do_xino_fwrite_args args = {
29338 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
29339 + if (unlikely(wkq_err))
29346 +/* ---------------------------------------------------------------------- */
29349 + * create a new xinofile at the same place/path as @base_file.
29351 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src)
29353 + struct file *file;
29354 + struct dentry *base, *parent;
29355 + struct inode *dir;
29356 + struct qstr *name;
29357 + struct path path;
29360 + base = base_file->f_dentry;
29361 + parent = base->d_parent; /* dir inode is locked */
29362 + dir = parent->d_inode;
29365 + file = ERR_PTR(-EINVAL);
29366 + name = &base->d_name;
29367 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
29368 + if (IS_ERR(path.dentry)) {
29369 + file = (void *)path.dentry;
29370 + pr_err("%.*s lookup err %ld\n",
29371 + AuLNPair(name), PTR_ERR(path.dentry));
29375 + /* no need to mnt_want_write() since we call dentry_open() later */
29376 + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL);
29377 + if (unlikely(err)) {
29378 + file = ERR_PTR(err);
29379 + pr_err("%.*s create err %d\n", AuLNPair(name), err);
29383 + path.mnt = base_file->f_vfsmnt;
29384 + file = vfsub_dentry_open(&path,
29385 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
29386 + /* | __FMODE_NONOTIFY */);
29387 + if (IS_ERR(file)) {
29388 + pr_err("%.*s open err %ld\n", AuLNPair(name), PTR_ERR(file));
29392 + err = vfsub_unlink(dir, &file->f_path, /*force*/0);
29393 + if (unlikely(err)) {
29394 + pr_err("%.*s unlink err %d\n", AuLNPair(name), err);
29399 + /* no one can touch copy_src xino */
29400 + err = au_copy_file(file, copy_src,
29401 + i_size_read(copy_src->f_dentry->d_inode));
29402 + if (unlikely(err)) {
29403 + pr_err("%.*s copy err %d\n", AuLNPair(name), err);
29407 + goto out_dput; /* success */
29411 + file = ERR_PTR(err);
29413 + dput(path.dentry);
29418 +struct au_xino_lock_dir {
29419 + struct au_hinode *hdir;
29420 + struct dentry *parent;
29421 + struct mutex *mtx;
29424 +static void au_xino_lock_dir(struct super_block *sb, struct file *xino,
29425 + struct au_xino_lock_dir *ldir)
29427 + aufs_bindex_t brid, bindex;
29429 + ldir->hdir = NULL;
29431 + brid = au_xino_brid(sb);
29433 + bindex = au_br_index(sb, brid);
29434 + if (bindex >= 0) {
29435 + ldir->hdir = au_hi(sb->s_root->d_inode, bindex);
29436 + au_hn_imtx_lock_nested(ldir->hdir, AuLsc_I_PARENT);
29438 + ldir->parent = dget_parent(xino->f_dentry);
29439 + ldir->mtx = &ldir->parent->d_inode->i_mutex;
29440 + mutex_lock_nested(ldir->mtx, AuLsc_I_PARENT);
29444 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
29447 + au_hn_imtx_unlock(ldir->hdir);
29449 + mutex_unlock(ldir->mtx);
29450 + dput(ldir->parent);
29454 +/* ---------------------------------------------------------------------- */
29456 +/* trucate xino files asynchronously */
29458 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
29461 + aufs_bindex_t bi, bend;
29462 + struct au_branch *br;
29463 + struct file *new_xino, *file;
29464 + struct super_block *h_sb;
29465 + struct au_xino_lock_dir ldir;
29468 + bend = au_sbend(sb);
29469 + if (unlikely(bindex < 0 || bend < bindex))
29471 + br = au_sbr(sb, bindex);
29472 + file = br->br_xino.xi_file;
29476 + au_xino_lock_dir(sb, file, &ldir);
29477 + /* mnt_want_write() is unnecessary here */
29478 + new_xino = au_xino_create2(file, file);
29479 + au_xino_unlock_dir(&ldir);
29480 + err = PTR_ERR(new_xino);
29481 + if (IS_ERR(new_xino))
29485 + br->br_xino.xi_file = new_xino;
29487 + h_sb = br->br_mnt->mnt_sb;
29488 + for (bi = 0; bi <= bend; bi++) {
29489 + if (unlikely(bi == bindex))
29491 + br = au_sbr(sb, bi);
29492 + if (br->br_mnt->mnt_sb != h_sb)
29495 + fput(br->br_xino.xi_file);
29496 + br->br_xino.xi_file = new_xino;
29497 + get_file(new_xino);
29504 +struct xino_do_trunc_args {
29505 + struct super_block *sb;
29506 + struct au_branch *br;
29509 +static void xino_do_trunc(void *_args)
29511 + struct xino_do_trunc_args *args = _args;
29512 + struct super_block *sb;
29513 + struct au_branch *br;
29514 + struct inode *dir;
29516 + aufs_bindex_t bindex;
29520 + dir = sb->s_root->d_inode;
29523 + si_noflush_write_lock(sb);
29524 + ii_read_lock_parent(dir);
29525 + bindex = au_br_index(sb, br->br_id);
29526 + err = au_xino_trunc(sb, bindex);
29528 + && br->br_xino.xi_file->f_dentry->d_inode->i_blocks
29529 + >= br->br_xino_upper)
29530 + br->br_xino_upper += AUFS_XINO_TRUNC_STEP;
29532 + ii_read_unlock(dir);
29533 + if (unlikely(err))
29534 + pr_warn("err b%d, (%d)\n", bindex, err);
29535 + atomic_dec(&br->br_xino_running);
29536 + atomic_dec(&br->br_count);
29537 + si_write_unlock(sb);
29538 + au_nwt_done(&au_sbi(sb)->si_nowait);
29542 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
29544 + struct xino_do_trunc_args *args;
29547 + if (br->br_xino.xi_file->f_dentry->d_inode->i_blocks
29548 + < br->br_xino_upper)
29551 + if (atomic_inc_return(&br->br_xino_running) > 1)
29554 + /* lock and kfree() will be called in trunc_xino() */
29555 + args = kmalloc(sizeof(*args), GFP_NOFS);
29556 + if (unlikely(!args)) {
29557 + AuErr1("no memory\n");
29561 + atomic_inc(&br->br_count);
29564 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
29566 + return; /* success */
29568 + pr_err("wkq %d\n", wkq_err);
29569 + atomic_dec(&br->br_count);
29574 + atomic_dec(&br->br_xino_running);
29577 +/* ---------------------------------------------------------------------- */
29579 +static int au_xino_do_write(au_writef_t write, struct file *file,
29580 + ino_t h_ino, ino_t ino)
29586 + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) {
29587 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
29590 + pos *= sizeof(ino);
29591 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos);
29592 + if (sz == sizeof(ino))
29593 + return 0; /* success */
29595 + AuIOErr("write failed (%zd)\n", sz);
29600 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
29601 + * at the position of @h_ino.
29602 + * even if @ino is zero, it is written to the xinofile and means no entry.
29603 + * if the size of the xino file on a specific filesystem exceeds the watermark,
29604 + * try truncating it.
29606 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
29610 + unsigned int mnt_flags;
29611 + struct au_branch *br;
29613 + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max)
29614 + || ((loff_t)-1) > 0);
29615 + SiMustAnyLock(sb);
29617 + mnt_flags = au_mntflags(sb);
29618 + if (!au_opt_test(mnt_flags, XINO))
29621 + br = au_sbr(sb, bindex);
29622 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
29625 + if (au_opt_test(mnt_flags, TRUNC_XINO)
29626 + && au_test_fs_trunc_xino(br->br_mnt->mnt_sb))
29627 + xino_try_trunc(sb, br);
29628 + return 0; /* success */
29631 + AuIOErr("write failed (%d)\n", err);
29635 +/* ---------------------------------------------------------------------- */
29637 +/* aufs inode number bitmap */
29639 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
29640 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
29644 + AuDebugOn(bit < 0 || page_bits <= bit);
29645 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
29649 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
29651 + AuDebugOn(ino < AUFS_FIRST_INO);
29652 + ino -= AUFS_FIRST_INO;
29653 + *pindex = ino / page_bits;
29654 + *bit = ino % page_bits;
29657 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
29662 + struct au_sbinfo *sbinfo;
29663 + struct file *xib;
29664 + unsigned long *p;
29666 + sbinfo = au_sbi(sb);
29667 + MtxMustLock(&sbinfo->si_xib_mtx);
29668 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
29669 + || !au_opt_test(sbinfo->si_mntflags, XINO));
29671 + if (pindex == sbinfo->si_xib_last_pindex)
29674 + xib = sbinfo->si_xib;
29675 + p = sbinfo->si_xib_buf;
29676 + pos = sbinfo->si_xib_last_pindex;
29677 + pos *= PAGE_SIZE;
29678 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
29679 + if (unlikely(sz != PAGE_SIZE))
29683 + pos *= PAGE_SIZE;
29684 + if (i_size_read(xib->f_dentry->d_inode) >= pos + PAGE_SIZE)
29685 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
29687 + memset(p, 0, PAGE_SIZE);
29688 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
29690 + if (sz == PAGE_SIZE) {
29691 + sbinfo->si_xib_last_pindex = pindex;
29692 + return 0; /* success */
29696 + AuIOErr1("write failed (%zd)\n", sz);
29703 +/* ---------------------------------------------------------------------- */
29705 +static void au_xib_clear_bit(struct inode *inode)
29708 + unsigned long pindex;
29709 + struct super_block *sb;
29710 + struct au_sbinfo *sbinfo;
29712 + AuDebugOn(inode->i_nlink);
29714 + sb = inode->i_sb;
29715 + xib_calc_bit(inode->i_ino, &pindex, &bit);
29716 + AuDebugOn(page_bits <= bit);
29717 + sbinfo = au_sbi(sb);
29718 + mutex_lock(&sbinfo->si_xib_mtx);
29719 + err = xib_pindex(sb, pindex);
29721 + clear_bit(bit, sbinfo->si_xib_buf);
29722 + sbinfo->si_xib_next_bit = bit;
29724 + mutex_unlock(&sbinfo->si_xib_mtx);
29727 +/* for s_op->delete_inode() */
29728 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
29731 + unsigned int mnt_flags;
29732 + aufs_bindex_t bindex, bend, bi;
29733 + unsigned char try_trunc;
29734 + struct au_iinfo *iinfo;
29735 + struct super_block *sb;
29736 + struct au_hinode *hi;
29737 + struct inode *h_inode;
29738 + struct au_branch *br;
29739 + au_writef_t xwrite;
29741 + sb = inode->i_sb;
29742 + mnt_flags = au_mntflags(sb);
29743 + if (!au_opt_test(mnt_flags, XINO)
29744 + || inode->i_ino == AUFS_ROOT_INO)
29748 + au_xigen_inc(inode);
29749 + au_xib_clear_bit(inode);
29752 + iinfo = au_ii(inode);
29756 + bindex = iinfo->ii_bstart;
29760 + xwrite = au_sbi(sb)->si_xwrite;
29761 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
29762 + hi = iinfo->ii_hinode + bindex;
29763 + bend = iinfo->ii_bend;
29764 + for (; bindex <= bend; bindex++, hi++) {
29765 + h_inode = hi->hi_inode;
29767 + || (!unlinked && h_inode->i_nlink))
29770 + /* inode may not be revalidated */
29771 + bi = au_br_index(sb, hi->hi_id);
29775 + br = au_sbr(sb, bi);
29776 + err = au_xino_do_write(xwrite, br->br_xino.xi_file,
29777 + h_inode->i_ino, /*ino*/0);
29778 + if (!err && try_trunc
29779 + && au_test_fs_trunc_xino(br->br_mnt->mnt_sb))
29780 + xino_try_trunc(sb, br);
29784 +/* get an unused inode number from bitmap */
29785 +ino_t au_xino_new_ino(struct super_block *sb)
29788 + unsigned long *p, pindex, ul, pend;
29789 + struct au_sbinfo *sbinfo;
29790 + struct file *file;
29791 + int free_bit, err;
29793 + if (!au_opt_test(au_mntflags(sb), XINO))
29794 + return iunique(sb, AUFS_FIRST_INO);
29796 + sbinfo = au_sbi(sb);
29797 + mutex_lock(&sbinfo->si_xib_mtx);
29798 + p = sbinfo->si_xib_buf;
29799 + free_bit = sbinfo->si_xib_next_bit;
29800 + if (free_bit < page_bits && !test_bit(free_bit, p))
29801 + goto out; /* success */
29802 + free_bit = find_first_zero_bit(p, page_bits);
29803 + if (free_bit < page_bits)
29804 + goto out; /* success */
29806 + pindex = sbinfo->si_xib_last_pindex;
29807 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
29808 + err = xib_pindex(sb, ul);
29809 + if (unlikely(err))
29811 + free_bit = find_first_zero_bit(p, page_bits);
29812 + if (free_bit < page_bits)
29813 + goto out; /* success */
29816 + file = sbinfo->si_xib;
29817 + pend = i_size_read(file->f_dentry->d_inode) / PAGE_SIZE;
29818 + for (ul = pindex + 1; ul <= pend; ul++) {
29819 + err = xib_pindex(sb, ul);
29820 + if (unlikely(err))
29822 + free_bit = find_first_zero_bit(p, page_bits);
29823 + if (free_bit < page_bits)
29824 + goto out; /* success */
29829 + set_bit(free_bit, p);
29830 + sbinfo->si_xib_next_bit = free_bit + 1;
29831 + pindex = sbinfo->si_xib_last_pindex;
29832 + mutex_unlock(&sbinfo->si_xib_mtx);
29833 + ino = xib_calc_ino(pindex, free_bit);
29834 + AuDbg("i%lu\n", (unsigned long)ino);
29837 + mutex_unlock(&sbinfo->si_xib_mtx);
29843 + * read @ino from xinofile for the specified branch{@sb, @bindex}
29844 + * at the position of @h_ino.
29845 + * if @ino does not exist and @do_new is true, get new one.
29847 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
29853 + struct file *file;
29854 + struct au_sbinfo *sbinfo;
29857 + if (!au_opt_test(au_mntflags(sb), XINO))
29858 + return 0; /* no xino */
29861 + sbinfo = au_sbi(sb);
29863 + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) {
29864 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
29867 + pos *= sizeof(*ino);
29869 + file = au_sbr(sb, bindex)->br_xino.xi_file;
29870 + if (i_size_read(file->f_dentry->d_inode) < pos + sizeof(*ino))
29871 + return 0; /* no ino */
29873 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
29874 + if (sz == sizeof(*ino))
29875 + return 0; /* success */
29878 + if (unlikely(sz >= 0)) {
29880 + AuIOErr("xino read error (%zd)\n", sz);
29886 +/* ---------------------------------------------------------------------- */
29888 +/* create and set a new xino file */
29890 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent)
29892 + struct file *file;
29893 + struct dentry *h_parent, *d;
29894 + struct inode *h_dir;
29898 + * at mount-time, and the xino file is the default path,
29899 + * hnotify is disabled so we have no notify events to ignore.
29900 + * when a user specified the xino, we cannot get au_hdir to be ignored.
29902 + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
29903 + /* | __FMODE_NONOTIFY */,
29904 + S_IRUGO | S_IWUGO);
29905 + if (IS_ERR(file)) {
29907 + pr_err("open %s(%ld)\n", fname, PTR_ERR(file));
29911 + /* keep file count */
29912 + h_parent = dget_parent(file->f_dentry);
29913 + h_dir = h_parent->d_inode;
29914 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
29915 + /* mnt_want_write() is unnecessary here */
29916 + err = vfsub_unlink(h_dir, &file->f_path, /*force*/0);
29917 + mutex_unlock(&h_dir->i_mutex);
29919 + if (unlikely(err)) {
29921 + pr_err("unlink %s(%d)\n", fname, err);
29926 + d = file->f_dentry;
29927 + if (unlikely(sb == d->d_sb)) {
29929 + pr_err("%s must be outside\n", fname);
29932 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
29934 + pr_err("xino doesn't support %s(%s)\n",
29935 + fname, au_sbtype(d->d_sb));
29938 + return file; /* success */
29942 + file = ERR_PTR(err);
29947 + * find another branch who is on the same filesystem of the specified
29948 + * branch{@btgt}. search until @bend.
29950 +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
29951 + aufs_bindex_t bend)
29953 + aufs_bindex_t bindex;
29954 + struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
29956 + for (bindex = 0; bindex < btgt; bindex++)
29957 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
29959 + for (bindex++; bindex <= bend; bindex++)
29960 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
29965 +/* ---------------------------------------------------------------------- */
29968 + * initialize the xinofile for the specified branch @br
29969 + * at the place/path where @base_file indicates.
29970 + * test whether another branch is on the same filesystem or not,
29971 + * if @do_test is true.
29973 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
29974 + struct file *base_file, int do_test)
29978 + aufs_bindex_t bend, bindex;
29979 + struct au_branch *shared_br, *b;
29980 + struct file *file;
29981 + struct super_block *tgt_sb;
29983 + shared_br = NULL;
29984 + bend = au_sbend(sb);
29986 + tgt_sb = br->br_mnt->mnt_sb;
29987 + for (bindex = 0; bindex <= bend; bindex++) {
29988 + b = au_sbr(sb, bindex);
29989 + if (tgt_sb == b->br_mnt->mnt_sb) {
29996 + if (!shared_br || !shared_br->br_xino.xi_file) {
29997 + struct au_xino_lock_dir ldir;
29999 + au_xino_lock_dir(sb, base_file, &ldir);
30000 + /* mnt_want_write() is unnecessary here */
30001 + file = au_xino_create2(base_file, NULL);
30002 + au_xino_unlock_dir(&ldir);
30003 + err = PTR_ERR(file);
30004 + if (IS_ERR(file))
30006 + br->br_xino.xi_file = file;
30008 + br->br_xino.xi_file = shared_br->br_xino.xi_file;
30009 + get_file(br->br_xino.xi_file);
30012 + ino = AUFS_ROOT_INO;
30013 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
30015 + if (unlikely(err)) {
30016 + fput(br->br_xino.xi_file);
30017 + br->br_xino.xi_file = NULL;
30024 +/* ---------------------------------------------------------------------- */
30026 +/* trucate a xino bitmap file */
30029 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
30033 + unsigned long pindex;
30034 + loff_t pos, pend;
30035 + struct au_sbinfo *sbinfo;
30038 + unsigned long *p;
30041 + sbinfo = au_sbi(sb);
30042 + MtxMustLock(&sbinfo->si_xib_mtx);
30043 + p = sbinfo->si_xib_buf;
30044 + func = sbinfo->si_xread;
30045 + pend = i_size_read(file->f_dentry->d_inode);
30047 + while (pos < pend) {
30048 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
30050 + if (unlikely(sz <= 0))
30054 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
30055 + if (unlikely(*ino < AUFS_FIRST_INO))
30058 + xib_calc_bit(*ino, &pindex, &bit);
30059 + AuDebugOn(page_bits <= bit);
30060 + err = xib_pindex(sb, pindex);
30072 +static int xib_restore(struct super_block *sb)
30075 + aufs_bindex_t bindex, bend;
30079 + page = (void *)__get_free_page(GFP_NOFS);
30080 + if (unlikely(!page))
30084 + bend = au_sbend(sb);
30085 + for (bindex = 0; !err && bindex <= bend; bindex++)
30086 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
30087 + err = do_xib_restore
30088 + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page);
30090 + AuDbg("b%d\n", bindex);
30091 + free_page((unsigned long)page);
30097 +int au_xib_trunc(struct super_block *sb)
30102 + struct au_xino_lock_dir ldir;
30103 + struct au_sbinfo *sbinfo;
30104 + unsigned long *p;
30105 + struct file *file;
30107 + SiMustWriteLock(sb);
30110 + sbinfo = au_sbi(sb);
30111 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
30114 + file = sbinfo->si_xib;
30115 + if (i_size_read(file->f_dentry->d_inode) <= PAGE_SIZE)
30118 + au_xino_lock_dir(sb, file, &ldir);
30119 + /* mnt_want_write() is unnecessary here */
30120 + file = au_xino_create2(sbinfo->si_xib, NULL);
30121 + au_xino_unlock_dir(&ldir);
30122 + err = PTR_ERR(file);
30123 + if (IS_ERR(file))
30125 + fput(sbinfo->si_xib);
30126 + sbinfo->si_xib = file;
30128 + p = sbinfo->si_xib_buf;
30129 + memset(p, 0, PAGE_SIZE);
30131 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
30132 + if (unlikely(sz != PAGE_SIZE)) {
30134 + AuIOErr("err %d\n", err);
30140 + mutex_lock(&sbinfo->si_xib_mtx);
30141 + /* mnt_want_write() is unnecessary here */
30142 + err = xib_restore(sb);
30143 + mutex_unlock(&sbinfo->si_xib_mtx);
30149 +/* ---------------------------------------------------------------------- */
30152 + * xino mount option handlers
30154 +static au_readf_t find_readf(struct file *h_file)
30156 + const struct file_operations *fop = h_file->f_op;
30160 + return fop->read;
30161 + if (fop->aio_read)
30162 + return do_sync_read;
30164 + return ERR_PTR(-ENOSYS);
30167 +static au_writef_t find_writef(struct file *h_file)
30169 + const struct file_operations *fop = h_file->f_op;
30173 + return fop->write;
30174 + if (fop->aio_write)
30175 + return do_sync_write;
30177 + return ERR_PTR(-ENOSYS);
30181 +static void xino_clear_xib(struct super_block *sb)
30183 + struct au_sbinfo *sbinfo;
30185 + SiMustWriteLock(sb);
30187 + sbinfo = au_sbi(sb);
30188 + sbinfo->si_xread = NULL;
30189 + sbinfo->si_xwrite = NULL;
30190 + if (sbinfo->si_xib)
30191 + fput(sbinfo->si_xib);
30192 + sbinfo->si_xib = NULL;
30193 + free_page((unsigned long)sbinfo->si_xib_buf);
30194 + sbinfo->si_xib_buf = NULL;
30197 +static int au_xino_set_xib(struct super_block *sb, struct file *base)
30201 + struct au_sbinfo *sbinfo;
30202 + struct file *file;
30204 + SiMustWriteLock(sb);
30206 + sbinfo = au_sbi(sb);
30207 + file = au_xino_create2(base, sbinfo->si_xib);
30208 + err = PTR_ERR(file);
30209 + if (IS_ERR(file))
30211 + if (sbinfo->si_xib)
30212 + fput(sbinfo->si_xib);
30213 + sbinfo->si_xib = file;
30214 + sbinfo->si_xread = find_readf(file);
30215 + sbinfo->si_xwrite = find_writef(file);
30218 + if (!sbinfo->si_xib_buf)
30219 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
30220 + if (unlikely(!sbinfo->si_xib_buf))
30223 + sbinfo->si_xib_last_pindex = 0;
30224 + sbinfo->si_xib_next_bit = 0;
30225 + if (i_size_read(file->f_dentry->d_inode) < PAGE_SIZE) {
30227 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
30228 + PAGE_SIZE, &pos);
30229 + if (unlikely(err != PAGE_SIZE))
30233 + goto out; /* success */
30236 + free_page((unsigned long)sbinfo->si_xib_buf);
30237 + sbinfo->si_xib_buf = NULL;
30241 + fput(sbinfo->si_xib);
30242 + sbinfo->si_xib = NULL;
30243 + sbinfo->si_xread = NULL;
30244 + sbinfo->si_xwrite = NULL;
30249 +/* xino for each branch */
30250 +static void xino_clear_br(struct super_block *sb)
30252 + aufs_bindex_t bindex, bend;
30253 + struct au_branch *br;
30255 + bend = au_sbend(sb);
30256 + for (bindex = 0; bindex <= bend; bindex++) {
30257 + br = au_sbr(sb, bindex);
30258 + if (!br || !br->br_xino.xi_file)
30261 + fput(br->br_xino.xi_file);
30262 + br->br_xino.xi_file = NULL;
30266 +static int au_xino_set_br(struct super_block *sb, struct file *base)
30270 + aufs_bindex_t bindex, bend, bshared;
30272 + struct file *old, *new;
30274 + struct au_branch *br;
30275 + struct inode *inode;
30276 + au_writef_t writef;
30278 + SiMustWriteLock(sb);
30281 + bend = au_sbend(sb);
30282 + fpair = kcalloc(bend + 1, sizeof(*fpair), GFP_NOFS);
30283 + if (unlikely(!fpair))
30286 + inode = sb->s_root->d_inode;
30287 + ino = AUFS_ROOT_INO;
30288 + writef = au_sbi(sb)->si_xwrite;
30289 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
30290 + br = au_sbr(sb, bindex);
30291 + bshared = is_sb_shared(sb, bindex, bindex - 1);
30292 + if (bshared >= 0) {
30293 + /* shared xino */
30294 + *p = fpair[bshared];
30295 + get_file(p->new);
30300 + p->old = br->br_xino.xi_file;
30301 + p->new = au_xino_create2(base, br->br_xino.xi_file);
30302 + err = PTR_ERR(p->new);
30303 + if (IS_ERR(p->new)) {
30309 + err = au_xino_do_write(writef, p->new,
30310 + au_h_iptr(inode, bindex)->i_ino, ino);
30311 + if (unlikely(err))
30315 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
30316 + br = au_sbr(sb, bindex);
30317 + if (br->br_xino.xi_file)
30318 + fput(br->br_xino.xi_file);
30319 + get_file(p->new);
30320 + br->br_xino.xi_file = p->new;
30324 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++)
30334 +void au_xino_clr(struct super_block *sb)
30336 + struct au_sbinfo *sbinfo;
30338 + au_xigen_clr(sb);
30339 + xino_clear_xib(sb);
30340 + xino_clear_br(sb);
30341 + sbinfo = au_sbi(sb);
30342 + /* lvalue, do not call au_mntflags() */
30343 + au_opt_clr(sbinfo->si_mntflags, XINO);
30346 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
30349 + struct dentry *parent, *cur_parent;
30350 + struct qstr *dname, *cur_name;
30351 + struct file *cur_xino;
30352 + struct inode *dir;
30353 + struct au_sbinfo *sbinfo;
30355 + SiMustWriteLock(sb);
30358 + sbinfo = au_sbi(sb);
30359 + parent = dget_parent(xino->file->f_dentry);
30362 + dname = &xino->file->f_dentry->d_name;
30363 + cur_xino = sbinfo->si_xib;
30365 + cur_parent = dget_parent(cur_xino->f_dentry);
30366 + cur_name = &cur_xino->f_dentry->d_name;
30367 + skip = (cur_parent == parent
30368 + && dname->len == cur_name->len
30369 + && !memcmp(dname->name, cur_name->name,
30371 + dput(cur_parent);
30377 + au_opt_set(sbinfo->si_mntflags, XINO);
30378 + dir = parent->d_inode;
30379 + mutex_lock_nested(&dir->i_mutex, AuLsc_I_PARENT);
30380 + /* mnt_want_write() is unnecessary here */
30381 + err = au_xino_set_xib(sb, xino->file);
30383 + err = au_xigen_set(sb, xino->file);
30385 + err = au_xino_set_br(sb, xino->file);
30386 + mutex_unlock(&dir->i_mutex);
30388 + goto out; /* success */
30391 + AuIOErr("failed creating xino(%d).\n", err);
30398 +/* ---------------------------------------------------------------------- */
30401 + * create a xinofile at the default place/path.
30403 +struct file *au_xino_def(struct super_block *sb)
30405 + struct file *file;
30407 + struct au_branch *br;
30408 + struct super_block *h_sb;
30409 + struct path path;
30410 + aufs_bindex_t bend, bindex, bwr;
30413 + bend = au_sbend(sb);
30415 + for (bindex = 0; bindex <= bend; bindex++) {
30416 + br = au_sbr(sb, bindex);
30417 + if (au_br_writable(br->br_perm)
30418 + && !au_test_fs_bad_xino(br->br_mnt->mnt_sb)) {
30425 + file = ERR_PTR(-ENOMEM);
30426 + page = __getname_gfp(GFP_NOFS);
30427 + if (unlikely(!page))
30429 + path.mnt = br->br_mnt;
30430 + path.dentry = au_h_dptr(sb->s_root, bwr);
30431 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
30432 + file = (void *)p;
30433 + if (!IS_ERR(p)) {
30434 + strcat(p, "/" AUFS_XINO_FNAME);
30435 + AuDbg("%s\n", p);
30436 + file = au_xino_create(sb, p, /*silent*/0);
30437 + if (!IS_ERR(file))
30438 + au_xino_brid_set(sb, br->br_id);
30442 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
30443 + if (IS_ERR(file))
30445 + h_sb = file->f_dentry->d_sb;
30446 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
30447 + pr_err("xino doesn't support %s(%s)\n",
30448 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
30450 + file = ERR_PTR(-EINVAL);
30452 + if (!IS_ERR(file))
30453 + au_xino_brid_set(sb, -1);
30460 +/* ---------------------------------------------------------------------- */
30462 +int au_xino_path(struct seq_file *seq, struct file *file)
30466 + err = au_seq_path(seq, &file->f_path);
30467 + if (unlikely(err < 0))
30471 +#define Deleted "\\040(deleted)"
30472 + seq->count -= sizeof(Deleted) - 1;
30473 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
30474 + sizeof(Deleted) - 1));
30480 diff -urN /usr/share/empty/include/linux/aufs_type.h linux/include/linux/aufs_type.h
30481 --- /usr/share/empty/include/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
30482 +++ linux/include/linux/aufs_type.h 2012-07-22 19:57:03.167671344 +0200
30485 + * Copyright (C) 2005-2012 Junjiro R. Okajima
30487 + * This program, aufs is free software; you can redistribute it and/or modify
30488 + * it under the terms of the GNU General Public License as published by
30489 + * the Free Software Foundation; either version 2 of the License, or
30490 + * (at your option) any later version.
30492 + * This program is distributed in the hope that it will be useful,
30493 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30494 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30495 + * GNU General Public License for more details.
30497 + * You should have received a copy of the GNU General Public License
30498 + * along with this program; if not, write to the Free Software
30499 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30502 +#ifndef __AUFS_TYPE_H__
30503 +#define __AUFS_TYPE_H__
30505 +#define AUFS_NAME "aufs"
30509 + * define it before including all other headers.
30510 + * sched.h may use pr_* macros before defining "current", so define the
30511 + * no-current version first, and re-define later.
30513 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
30514 +#include <linux/sched.h>
30516 +#define pr_fmt(fmt) AUFS_NAME " %s:%d:%s[%d]: " fmt, \
30517 + __func__, __LINE__, current->comm, current->pid
30519 +#include <stdint.h>
30520 +#include <sys/types.h>
30521 +#endif /* __KERNEL__ */
30523 +#include <linux/limits.h>
30525 +#define AUFS_VERSION "3.x-rcN-20120618"
30527 +/* todo? move this to linux-2.6.19/include/magic.h */
30528 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
30530 +/* ---------------------------------------------------------------------- */
30532 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
30533 +typedef int8_t aufs_bindex_t;
30534 +#define AUFS_BRANCH_MAX 127
30536 +typedef int16_t aufs_bindex_t;
30537 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
30538 +#define AUFS_BRANCH_MAX 511
30539 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
30540 +#define AUFS_BRANCH_MAX 1023
30541 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
30542 +#define AUFS_BRANCH_MAX 32767
30547 +#ifndef AUFS_BRANCH_MAX
30548 +#error unknown CONFIG_AUFS_BRANCH_MAX value
30550 +#endif /* __KERNEL__ */
30552 +/* ---------------------------------------------------------------------- */
30554 +#define AUFS_FSTYPE AUFS_NAME
30556 +#define AUFS_ROOT_INO 2
30557 +#define AUFS_FIRST_INO 11
30559 +#define AUFS_WH_PFX ".wh."
30560 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
30561 +#define AUFS_WH_TMP_LEN 4
30562 +/* a limit for rmdir/rename a dir */
30563 +#define AUFS_MAX_NAMELEN (NAME_MAX \
30564 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
30566 + - AUFS_WH_TMP_LEN) /* hex */
30567 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
30568 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
30569 +#define AUFS_XINO_TRUNC_INIT 64 /* blocks */
30570 +#define AUFS_XINO_TRUNC_STEP 4 /* blocks */
30571 +#define AUFS_DIRWH_DEF 3
30572 +#define AUFS_RDCACHE_DEF 10 /* seconds */
30573 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
30574 +#define AUFS_RDBLK_DEF 512 /* bytes */
30575 +#define AUFS_RDHASH_DEF 32
30576 +#define AUFS_WKQ_NAME AUFS_NAME "d"
30577 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
30578 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
30579 +#define AUFS_PLINK_WARN 100 /* number of plinks */
30581 +/* pseudo-link maintenace under /proc */
30582 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
30583 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
30584 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
30586 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
30587 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
30589 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
30590 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
30591 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
30593 +/* doubly whiteouted */
30594 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
30595 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
30596 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
30598 +/* branch permissions and attributes */
30599 +#define AUFS_BRPERM_RW "rw"
30600 +#define AUFS_BRPERM_RO "ro"
30601 +#define AUFS_BRPERM_RR "rr"
30602 +#define AUFS_BRRATTR_WH "wh"
30603 +#define AUFS_BRWATTR_NLWH "nolwh"
30605 +/* ---------------------------------------------------------------------- */
30609 + /* readdir in userspace */
30613 + /* pathconf wrapper */
30620 +/* borrowed from linux/include/linux/kernel.h */
30622 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
30623 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
30626 +/* borrowed from linux/include/linux/compiler-gcc3.h */
30628 +#define __aligned(x) __attribute__((aligned(x)))
30633 +#define __packed __attribute__((packed))
30637 +struct au_rdu_cookie {
30642 + uint32_t generation;
30645 +struct au_rdu_ent {
30654 +static inline int au_rdu_len(int nlen)
30656 + /* include the terminating NULL */
30657 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
30658 + sizeof(uint64_t));
30661 +union au_rdu_ent_ul {
30662 + struct au_rdu_ent __user *e;
30674 + uint64_t sz; /* AuCtl_RDU */
30675 + uint64_t nent; /* AuCtl_RDU_INO */
30677 + union au_rdu_ent_ul ent;
30678 + uint16_t verify[AufsCtlRduV_End];
30680 + /* input/output */
30684 + union au_rdu_ent_ul tail;
30685 + /* number of entries which were added in a single call */
30690 + struct au_rdu_cookie cookie;
30693 +/* ---------------------------------------------------------------------- */
30695 +struct aufs_wbr_fd {
30700 +/* ---------------------------------------------------------------------- */
30702 +struct aufs_ibusy {
30703 + uint64_t ino, h_ino;
30707 +/* ---------------------------------------------------------------------- */
30709 +#define AuCtlType 'A'
30710 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
30711 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
30712 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
30713 + struct aufs_wbr_fd)
30714 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
30716 +#endif /* __AUFS_TYPE_H__ */