1 aufs3.x-rcN kbuild patch
3 diff --git a/fs/Kconfig b/fs/Kconfig
4 index c229f82..397b473 100644
7 @@ -212,6 +212,7 @@ source "fs/ufs/Kconfig"
8 source "fs/exofs/Kconfig"
9 source "fs/f2fs/Kconfig"
10 source "fs/efivarfs/Kconfig"
11 +source "fs/aufs/Kconfig"
13 endif # MISC_FILESYSTEMS
15 diff --git a/fs/Makefile b/fs/Makefile
16 index 4fe6df3..4a57676 100644
19 @@ -126,3 +126,4 @@ obj-y += exofs/ # Multiple modules
20 obj-$(CONFIG_CEPH_FS) += ceph/
21 obj-$(CONFIG_PSTORE) += pstore/
22 obj-$(CONFIG_EFIVAR_FS) += efivarfs/
23 +obj-$(CONFIG_AUFS_FS) += aufs/
24 diff --git a/include/uapi/linux/Kbuild b/include/uapi/linux/Kbuild
25 index 115add2..ce305b3 100644
26 --- a/include/uapi/linux/Kbuild
27 +++ b/include/uapi/linux/Kbuild
28 @@ -56,6 +56,7 @@ header-y += atmppp.h
32 +header-y += aufs_type.h
34 header-y += auto_fs4.h
36 aufs3.x-rcN base patch
38 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39 index 40e7155..6e43ab0 100644
40 --- a/drivers/block/loop.c
41 +++ b/drivers/block/loop.c
42 @@ -691,6 +691,24 @@ static inline int is_loop_device(struct file *file)
43 return i && S_ISBLK(i->i_mode) && MAJOR(i->i_rdev) == LOOP_MAJOR;
48 + * no get/put for file.
50 +struct file *loop_backing_file(struct super_block *sb)
53 + struct loop_device *l;
56 + if (MAJOR(sb->s_dev) == LOOP_MAJOR) {
57 + l = sb->s_bdev->bd_disk->private_data;
58 + ret = l->lo_backing_file;
62 +EXPORT_SYMBOL(loop_backing_file);
64 /* loop sysfs attributes */
66 static ssize_t loop_attr_show(struct device *dev, char *page,
67 diff --git a/fs/file_table.c b/fs/file_table.c
68 index abdd15a..da0ee1e 100644
71 @@ -36,7 +36,7 @@ struct files_stat_struct files_stat = {
75 -DEFINE_STATIC_LGLOCK(files_lglock);
76 +DEFINE_LGLOCK(files_lglock);
78 /* SLAB cache for file structures */
79 static struct kmem_cache *filp_cachep __read_mostly;
80 @@ -360,7 +360,7 @@ static inline int file_list_cpu(struct file *file)
83 /* helper for file_sb_list_add to reduce ifdefs */
84 -static inline void __file_sb_list_add(struct file *file, struct super_block *sb)
85 +inline void __file_sb_list_add(struct file *file, struct super_block *sb)
87 struct list_head *list;
89 @@ -373,6 +373,7 @@ static inline void __file_sb_list_add(struct file *file, struct super_block *sb)
91 list_add(&file->f_u.fu_list, list);
93 +EXPORT_SYMBOL(__file_sb_list_add);
96 * file_sb_list_add - add a file to the sb's file list
97 diff --git a/fs/inode.c b/fs/inode.c
98 index b33ba8e..9b24434 100644
101 @@ -1469,7 +1469,7 @@ static int relatime_need_update(struct vfsmount *mnt, struct inode *inode,
102 * This does the actual work of updating an inodes time or version. Must have
103 * had called mnt_want_write() before calling this.
105 -static int update_time(struct inode *inode, struct timespec *time, int flags)
106 +int update_time(struct inode *inode, struct timespec *time, int flags)
108 if (inode->i_op->update_time)
109 return inode->i_op->update_time(inode, time, flags);
110 diff --git a/fs/splice.c b/fs/splice.c
111 index 3b7ee65..e147583 100644
114 @@ -1093,8 +1093,8 @@ EXPORT_SYMBOL(generic_splice_sendpage);
116 * Attempt to initiate a splice from pipe to file.
118 -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
119 - loff_t *ppos, size_t len, unsigned int flags)
120 +long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
121 + loff_t *ppos, size_t len, unsigned int flags)
123 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
124 loff_t *, size_t, unsigned int);
125 @@ -1110,9 +1110,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
127 * Attempt to initiate a splice from a file to a pipe.
129 -static long do_splice_to(struct file *in, loff_t *ppos,
130 - struct pipe_inode_info *pipe, size_t len,
131 - unsigned int flags)
132 +long do_splice_to(struct file *in, loff_t *ppos,
133 + struct pipe_inode_info *pipe, size_t len,
134 + unsigned int flags)
136 ssize_t (*splice_read)(struct file *, loff_t *,
137 struct pipe_inode_info *, size_t, unsigned int);
138 diff --git a/include/linux/fs.h b/include/linux/fs.h
139 index 3f40547..36b235e 100644
140 --- a/include/linux/fs.h
141 +++ b/include/linux/fs.h
142 @@ -2594,6 +2594,7 @@ extern int inode_change_ok(const struct inode *, struct iattr *);
143 extern int inode_newsize_ok(const struct inode *, loff_t offset);
144 extern void setattr_copy(struct inode *inode, const struct iattr *attr);
146 +extern int update_time(struct inode *, struct timespec *, int);
147 extern int file_update_time(struct file *file);
149 extern int generic_show_options(struct seq_file *m, struct dentry *root);
150 diff --git a/include/linux/splice.h b/include/linux/splice.h
151 index 74575cb..bfc6fb6 100644
152 --- a/include/linux/splice.h
153 +++ b/include/linux/splice.h
154 @@ -92,4 +92,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
155 extern void spd_release_page(struct splice_pipe_desc *, unsigned int);
157 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
159 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
160 + loff_t *ppos, size_t len, unsigned int flags);
161 +extern long do_splice_to(struct file *in, loff_t *ppos,
162 + struct pipe_inode_info *pipe, size_t len,
163 + unsigned int flags);
165 aufs3.x-rcN standalone patch
167 diff --git a/fs/file_table.c b/fs/file_table.c
168 index da0ee1e..0a02e12 100644
169 --- a/fs/file_table.c
170 +++ b/fs/file_table.c
171 @@ -37,6 +37,7 @@ struct files_stat_struct files_stat = {
174 DEFINE_LGLOCK(files_lglock);
175 +EXPORT_SYMBOL(files_lglock);
177 /* SLAB cache for file structures */
178 static struct kmem_cache *filp_cachep __read_mostly;
179 @@ -410,6 +411,8 @@ void file_sb_list_del(struct file *file)
183 +EXPORT_SYMBOL(file_sb_list_del);
188 diff --git a/fs/inode.c b/fs/inode.c
189 index 9b24434..6ee4b0b 100644
192 @@ -57,6 +57,7 @@ static struct hlist_head *inode_hashtable __read_mostly;
193 static __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_hash_lock);
195 __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_sb_list_lock);
196 +EXPORT_SYMBOL(inode_sb_list_lock);
199 * Empty aops. Can be used for the cases where the user does not
200 @@ -1485,6 +1486,7 @@ int update_time(struct inode *inode, struct timespec *time, int flags)
201 mark_inode_dirty_sync(inode);
204 +EXPORT_SYMBOL(update_time);
207 * touch_atime - update the access time
208 diff --git a/fs/namespace.c b/fs/namespace.c
209 index da5c494..f40ae6f 100644
212 @@ -54,6 +54,7 @@ EXPORT_SYMBOL_GPL(fs_kobj);
213 * tree or hash is modified or when a vfsmount structure is modified.
215 DEFINE_BRLOCK(vfsmount_lock);
216 +EXPORT_SYMBOL(vfsmount_lock);
218 static inline unsigned long hash(struct vfsmount *mnt, struct dentry *dentry)
220 @@ -427,6 +428,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
221 mnt_dec_writers(real_mount(mnt));
224 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
227 * mnt_drop_write - give up write access to a mount
228 @@ -1480,6 +1482,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
232 +EXPORT_SYMBOL(iterate_mounts);
234 static void cleanup_group_ids(struct mount *mnt, struct mount *end)
236 diff --git a/fs/notify/group.c b/fs/notify/group.c
237 index bd2625b..2ff2a0f 100644
238 --- a/fs/notify/group.c
239 +++ b/fs/notify/group.c
241 #include <linux/srcu.h>
242 #include <linux/rculist.h>
243 #include <linux/wait.h>
244 +#include <linux/module.h>
246 #include <linux/fsnotify_backend.h>
247 #include "fsnotify.h"
248 @@ -65,6 +66,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
250 atomic_inc(&group->refcnt);
252 +EXPORT_SYMBOL(fsnotify_get_group);
255 * Drop a reference to a group. Free it if it's through.
256 @@ -74,6 +76,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
257 if (atomic_dec_and_test(&group->refcnt))
258 fsnotify_final_destroy_group(group);
260 +EXPORT_SYMBOL(fsnotify_put_group);
263 * Create a new fsnotify_group and hold a reference for the group returned.
264 @@ -102,6 +105,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
268 +EXPORT_SYMBOL(fsnotify_alloc_group);
270 int fsnotify_fasync(int fd, struct file *file, int on)
272 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
273 index 923fe4a..176b435 100644
274 --- a/fs/notify/mark.c
275 +++ b/fs/notify/mark.c
276 @@ -109,6 +109,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
277 mark->free_mark(mark);
280 +EXPORT_SYMBOL(fsnotify_put_mark);
283 * Any time a mark is getting freed we end up here.
284 @@ -191,6 +192,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
285 fsnotify_destroy_mark_locked(mark, group);
286 mutex_unlock(&group->mark_mutex);
288 +EXPORT_SYMBOL(fsnotify_destroy_mark);
290 void fsnotify_set_mark_mask_locked(struct fsnotify_mark *mark, __u32 mask)
292 @@ -275,6 +277,7 @@ err:
296 +EXPORT_SYMBOL(fsnotify_add_mark);
298 int fsnotify_add_mark(struct fsnotify_mark *mark, struct fsnotify_group *group,
299 struct inode *inode, struct vfsmount *mnt, int allow_dups)
300 @@ -336,6 +339,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
301 atomic_set(&mark->refcnt, 1);
302 mark->free_mark = free_mark;
304 +EXPORT_SYMBOL(fsnotify_init_mark);
306 static int fsnotify_mark_destroy(void *ignored)
308 diff --git a/fs/open.c b/fs/open.c
309 index d420331..6dd3b03 100644
312 @@ -61,6 +61,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
313 mutex_unlock(&dentry->d_inode->i_mutex);
316 +EXPORT_SYMBOL(do_truncate);
318 long vfs_truncate(struct path *path, loff_t length)
320 diff --git a/fs/splice.c b/fs/splice.c
321 index e147583..789f6b2 100644
324 @@ -1106,6 +1106,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
326 return splice_write(pipe, out, ppos, len, flags);
328 +EXPORT_SYMBOL(do_splice_from);
331 * Attempt to initiate a splice from a file to a pipe.
332 @@ -1132,6 +1133,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
334 return splice_read(in, ppos, pipe, len, flags);
336 +EXPORT_SYMBOL(do_splice_to);
339 * splice_direct_to_actor - splices data directly between two non-pipes
340 diff --git a/security/commoncap.c b/security/commoncap.c
341 index b9d613e..ba3b618 100644
342 --- a/security/commoncap.c
343 +++ b/security/commoncap.c
344 @@ -988,9 +988,11 @@ int cap_mmap_addr(unsigned long addr)
348 +EXPORT_SYMBOL(cap_mmap_addr);
350 int cap_mmap_file(struct file *file, unsigned long reqprot,
351 unsigned long prot, unsigned long flags)
355 +EXPORT_SYMBOL(cap_mmap_file);
356 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
357 index c123628..efc6f68 100644
358 --- a/security/device_cgroup.c
359 +++ b/security/device_cgroup.c
361 #include <linux/device_cgroup.h>
362 #include <linux/cgroup.h>
363 #include <linux/ctype.h>
364 +#include <linux/export.h>
365 #include <linux/list.h>
366 #include <linux/uaccess.h>
367 #include <linux/seq_file.h>
368 @@ -756,6 +757,7 @@ int __devcgroup_inode_permission(struct inode *inode, int mask)
369 return __devcgroup_check_permission(type, imajor(inode), iminor(inode),
372 +EXPORT_SYMBOL(__devcgroup_inode_permission);
374 int devcgroup_inode_mknod(int mode, dev_t dev)
376 diff --git a/security/security.c b/security/security.c
377 index 4dc31f4..1f272bc 100644
378 --- a/security/security.c
379 +++ b/security/security.c
380 @@ -407,6 +407,7 @@ int security_path_rmdir(struct path *dir, struct dentry *dentry)
382 return security_ops->path_rmdir(dir, dentry);
384 +EXPORT_SYMBOL(security_path_rmdir);
386 int security_path_unlink(struct path *dir, struct dentry *dentry)
388 @@ -423,6 +424,7 @@ int security_path_symlink(struct path *dir, struct dentry *dentry,
390 return security_ops->path_symlink(dir, dentry, old_name);
392 +EXPORT_SYMBOL(security_path_symlink);
394 int security_path_link(struct dentry *old_dentry, struct path *new_dir,
395 struct dentry *new_dentry)
396 @@ -431,6 +433,7 @@ int security_path_link(struct dentry *old_dentry, struct path *new_dir,
398 return security_ops->path_link(old_dentry, new_dir, new_dentry);
400 +EXPORT_SYMBOL(security_path_link);
402 int security_path_rename(struct path *old_dir, struct dentry *old_dentry,
403 struct path *new_dir, struct dentry *new_dentry)
404 @@ -449,6 +452,7 @@ int security_path_truncate(struct path *path)
406 return security_ops->path_truncate(path);
408 +EXPORT_SYMBOL(security_path_truncate);
410 int security_path_chmod(struct path *path, umode_t mode)
412 @@ -456,6 +460,7 @@ int security_path_chmod(struct path *path, umode_t mode)
414 return security_ops->path_chmod(path, mode);
416 +EXPORT_SYMBOL(security_path_chmod);
418 int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
420 @@ -463,6 +468,7 @@ int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
422 return security_ops->path_chown(path, uid, gid);
424 +EXPORT_SYMBOL(security_path_chown);
426 int security_path_chroot(struct path *path)
428 @@ -539,6 +545,7 @@ int security_inode_readlink(struct dentry *dentry)
430 return security_ops->inode_readlink(dentry);
432 +EXPORT_SYMBOL(security_inode_readlink);
434 int security_inode_follow_link(struct dentry *dentry, struct nameidata *nd)
436 @@ -553,6 +560,7 @@ int security_inode_permission(struct inode *inode, int mask)
438 return security_ops->inode_permission(inode, mask);
440 +EXPORT_SYMBOL(security_inode_permission);
442 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
444 @@ -675,6 +683,7 @@ int security_file_permission(struct file *file, int mask)
446 return fsnotify_perm(file, mask);
448 +EXPORT_SYMBOL(security_file_permission);
450 int security_file_alloc(struct file *file)
452 @@ -735,6 +744,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
454 return ima_file_mmap(file, prot);
456 +EXPORT_SYMBOL(security_mmap_file);
458 int security_mmap_addr(unsigned long addr)
460 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
461 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
462 +++ linux/Documentation/ABI/testing/debugfs-aufs 2013-07-06 13:20:47.716863966 +0200
464 +What: /debug/aufs/si_<id>/
466 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
468 + Under /debug/aufs, a directory named si_<id> is created
469 + per aufs mount, where <id> is a unique id generated
472 +What: /debug/aufs/si_<id>/plink
474 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
476 + It has three lines and shows the information about the
477 + pseudo-link. The first line is a single number
478 + representing a number of buckets. The second line is a
479 + number of pseudo-links per buckets (separated by a
480 + blank). The last line is a single number representing a
481 + total number of psedo-links.
482 + When the aufs mount option 'noplink' is specified, it
483 + will show "1\n0\n0\n".
485 +What: /debug/aufs/si_<id>/xib
487 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
489 + It shows the consumed blocks by xib (External Inode Number
490 + Bitmap), its block size and file size.
491 + When the aufs mount option 'noxino' is specified, it
492 + will be empty. About XINO files, see the aufs manual.
494 +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN
496 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
498 + It shows the consumed blocks by xino (External Inode Number
499 + Translation Table), its link count, block size and file
501 + When the aufs mount option 'noxino' is specified, it
502 + will be empty. About XINO files, see the aufs manual.
504 +What: /debug/aufs/si_<id>/xigen
506 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
508 + It shows the consumed blocks by xigen (External Inode
509 + Generation Table), its block size and file size.
510 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
512 + When the aufs mount option 'noxino' is specified, it
513 + will be empty. About XINO files, see the aufs manual.
514 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
515 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
516 +++ linux/Documentation/ABI/testing/sysfs-aufs 2013-10-26 16:51:32.269706994 +0200
518 +What: /sys/fs/aufs/si_<id>/
520 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
522 + Under /sys/fs/aufs, a directory named si_<id> is created
523 + per aufs mount, where <id> is a unique id generated
526 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
528 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
530 + It shows the abolute path of a member directory (which
531 + is called branch) in aufs, and its permission.
533 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
535 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
537 + It shows the id of a member directory (which is called
540 +What: /sys/fs/aufs/si_<id>/xi_path
542 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
544 + It shows the abolute path of XINO (External Inode Number
545 + Bitmap, Translation Table and Generation Table) file
546 + even if it is the default path.
547 + When the aufs mount option 'noxino' is specified, it
548 + will be empty. About XINO files, see the aufs manual.
549 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
550 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
551 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2013-07-06 13:20:47.730197761 +0200
554 +# Copyright (C) 2005-2013 Junjiro R. Okajima
556 +# This program is free software; you can redistribute it and/or modify
557 +# it under the terms of the GNU General Public License as published by
558 +# the Free Software Foundation; either version 2 of the License, or
559 +# (at your option) any later version.
561 +# This program is distributed in the hope that it will be useful,
562 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
563 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
564 +# GNU General Public License for more details.
566 +# You should have received a copy of the GNU General Public License
567 +# along with this program; if not, write to the Free Software
568 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
571 +----------------------------------------
573 +aufs [ei ju: ef es] | [a u f s]
574 +1. abbrev. for "advanced multi-layered unification filesystem".
575 +2. abbrev. for "another unionfs".
576 +3. abbrev. for "auf das" in German which means "on the" in English.
577 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
578 + But "Filesystem aufs Filesystem" is hard to understand.
580 +AUFS is a filesystem with features:
581 +- multi layered stackable unification filesystem, the member directory
582 + is called as a branch.
583 +- branch permission and attribute, 'readonly', 'real-readonly',
584 + 'readwrite', 'whiteout-able', 'link-able whiteout' and their
586 +- internal "file copy-on-write".
587 +- logical deletion, whiteout.
588 +- dynamic branch manipulation, adding, deleting and changing permission.
589 +- allow bypassing aufs, user's direct branch access.
590 +- external inode number translation table and bitmap which maintains the
591 + persistent aufs inode number.
592 +- seekable directory, including NFS readdir.
593 +- file mapping, mmap and sharing pages.
594 +- pseudo-link, hardlink over branches.
595 +- loopback mounted filesystem as a branch.
596 +- several policies to select one among multiple writable branches.
597 +- revert a single systemcall when an error occurs in aufs.
601 +Multi Layered Stackable Unification Filesystem
602 +----------------------------------------------------------------------
603 +Most people already knows what it is.
604 +It is a filesystem which unifies several directories and provides a
605 +merged single directory. When users access a file, the access will be
606 +passed/re-directed/converted (sorry, I am not sure which English word is
607 +correct) to the real file on the member filesystem. The member
608 +filesystem is called 'lower filesystem' or 'branch' and has a mode
609 +'readonly' and 'readwrite.' And the deletion for a file on the lower
610 +readonly branch is handled by creating 'whiteout' on the upper writable
613 +On LKML, there have been discussions about UnionMount (Jan Blunck,
614 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
615 +different approaches to implement the merged-view.
616 +The former tries putting it into VFS, and the latter implements as a
617 +separate filesystem.
618 +(If I misunderstand about these implementations, please let me know and
619 +I shall correct it. Because it is a long time ago when I read their
620 +source files last time).
622 +UnionMount's approach will be able to small, but may be hard to share
623 +branches between several UnionMount since the whiteout in it is
624 +implemented in the inode on branch filesystem and always
625 +shared. According to Bharata's post, readdir does not seems to be
627 +There are several missing features known in this implementations such as
628 +- for users, the inode number may change silently. eg. copy-up.
629 +- link(2) may break by copy-up.
630 +- read(2) may get an obsoleted filedata (fstat(2) too).
631 +- fcntl(F_SETLK) may be broken by copy-up.
632 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
635 +Unionfs has a longer history. When I started implementing a stacking filesystem
636 +(Aug 2005), it already existed. It has virtual super_block, inode,
637 +dentry and file objects and they have an array pointing lower same kind
638 +objects. After contributing many patches for Unionfs, I re-started my
639 +project AUFS (Jun 2006).
641 +In AUFS, the structure of filesystem resembles to Unionfs, but I
642 +implemented my own ideas, approaches and enhancements and it became
643 +totally different one.
645 +Comparing DM snapshot and fs based implementation
646 +- the number of bytes to be copied between devices is much smaller.
647 +- the type of filesystem must be one and only.
648 +- the fs must be writable, no readonly fs, even for the lower original
649 + device. so the compression fs will not be usable. but if we use
650 + loopback mount, we may address this issue.
652 + mount /cdrom/squashfs.img /sq
653 + losetup /sq/ext2.img
654 + losetup /somewhere/cow
655 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
656 +- it will be difficult (or needs more operations) to extract the
657 + difference between the original device and COW.
658 +- DM snapshot-merge may help a lot when users try merging. in the
659 + fs-layer union, users will use rsync(1).
662 +Several characters/aspects of aufs
663 +----------------------------------------------------------------------
665 +Aufs has several characters or aspects.
666 +1. a filesystem, callee of VFS helper
667 +2. sub-VFS, caller of VFS helper for branches
668 +3. a virtual filesystem which maintains persistent inode number
669 +4. reader/writer of files on branches such like an application
671 +1. Callee of VFS Helper
672 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
673 +unlink(2) from an application reaches sys_unlink() kernel function and
674 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
675 +calls filesystem specific unlink operation. Actually aufs implements the
676 +unlink operation but it behaves like a redirector.
678 +2. Caller of VFS Helper for Branches
679 +aufs_unlink() passes the unlink request to the branch filesystem as if
680 +it were called from VFS. So the called unlink operation of the branch
681 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
682 +every necessary pre/post operation for the branch filesystem.
683 +- acquire the lock for the parent dir on a branch
684 +- lookup in a branch
685 +- revalidate dentry on a branch
686 +- mnt_want_write() for a branch
687 +- vfs_unlink() for a branch
688 +- mnt_drop_write() for a branch
689 +- release the lock on a branch
691 +3. Persistent Inode Number
692 +One of the most important issue for a filesystem is to maintain inode
693 +numbers. This is particularly important to support exporting a
694 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
695 +backend block device for its own. But some storage is necessary to
696 +maintain inode number. It may be a large space and may not suit to keep
697 +in memory. Aufs rents some space from its first writable branch
698 +filesystem (by default) and creates file(s) on it. These files are
699 +created by aufs internally and removed soon (currently) keeping opened.
700 +Note: Because these files are removed, they are totally gone after
701 + unmounting aufs. It means the inode numbers are not persistent
702 + across unmount or reboot. I have a plan to make them really
703 + persistent which will be important for aufs on NFS server.
705 +4. Read/Write Files Internally (copy-on-write)
706 +Because a branch can be readonly, when you write a file on it, aufs will
707 +"copy-up" it to the upper writable branch internally. And then write the
708 +originally requested thing to the file. Generally kernel doesn't
709 +open/read/write file actively. In aufs, even a single write may cause a
710 +internal "file copy". This behaviour is very similar to cp(1) command.
712 +Some people may think it is better to pass such work to user space
713 +helper, instead of doing in kernel space. Actually I am still thinking
714 +about it. But currently I have implemented it in kernel space.
715 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
716 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
717 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2013-10-26 16:51:32.273040419 +0200
720 +# Copyright (C) 2005-2013 Junjiro R. Okajima
722 +# This program is free software; you can redistribute it and/or modify
723 +# it under the terms of the GNU General Public License as published by
724 +# the Free Software Foundation; either version 2 of the License, or
725 +# (at your option) any later version.
727 +# This program is distributed in the hope that it will be useful,
728 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
729 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
730 +# GNU General Public License for more details.
732 +# You should have received a copy of the GNU General Public License
733 +# along with this program; if not, write to the Free Software
734 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
736 +Basic Aufs Internal Structure
738 +Superblock/Inode/Dentry/File Objects
739 +----------------------------------------------------------------------
740 +As like an ordinary filesystem, aufs has its own
741 +superblock/inode/dentry/file objects. All these objects have a
742 +dynamically allocated array and store the same kind of pointers to the
743 +lower filesystem, branch.
744 +For example, when you build a union with one readwrite branch and one
745 +readonly, mounted /au, /rw and /ro respectively.
747 +- /ro/fileA exists but /rw/fileA
749 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
750 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
754 +This style of an array is essentially same to the aufs
755 +superblock/inode/dentry/file objects.
757 +Because aufs supports manipulating branches, ie. add/delete/change
758 +dynamically, these objects has its own generation. When branches are
759 +changed, the generation in aufs superblock is incremented. And a
760 +generation in other object are compared when it is accessed.
761 +When a generation in other objects are obsoleted, aufs refreshes the
766 +----------------------------------------------------------------------
767 +Additionally aufs superblock has some data for policies to select one
768 +among multiple writable branches, XIB files, pseudo-links and kobject.
769 +See below in detail.
770 +About the policies which supports copy-down a directory, see policy.txt
774 +Branch and XINO(External Inode Number Translation Table)
775 +----------------------------------------------------------------------
776 +Every branch has its own xino (external inode number translation table)
777 +file. The xino file is created and unlinked by aufs internally. When two
778 +members of a union exist on the same filesystem, they share the single
780 +The struct of a xino file is simple, just a sequence of aufs inode
781 +numbers which is indexed by the lower inode number.
782 +In the above sample, assume the inode number of /ro/fileA is i111 and
783 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
784 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
786 +When the inode numbers are not contiguous, the xino file will be sparse
787 +which has a hole in it and doesn't consume as much disk space as it
788 +might appear. If your branch filesystem consumes disk space for such
789 +holes, then you should specify 'xino=' option at mounting aufs.
791 +Also a writable branch has three kinds of "whiteout bases". All these
792 +are existed when the branch is joined to aufs and the names are
793 +whiteout-ed doubly, so that users will never see their names in aufs
795 +1. a regular file which will be linked to all whiteouts.
796 +2. a directory to store a pseudo-link.
797 +3. a directory to store an "orphan-ed" file temporary.
800 + When you remove a file on a readonly branch, aufs handles it as a
801 + logical deletion and creates a whiteout on the upper writable branch
802 + as a hardlink of this file in order not to consume inode on the
805 + See below, Pseudo-link.
807 + When "fileC" exists on the lower readonly branch only and it is
808 + opened and removed with its parent dir, and then user writes
809 + something into it, then aufs copies-up fileC to this
810 + directory. Because there is no other dir to store fileC. After
811 + creating a file under this dir, the file is unlinked.
813 +Because aufs supports manipulating branches, ie. add/delete/change
814 +dynamically, a branch has its own id. When the branch order changes, aufs
815 +finds the new index by searching the branch id.
819 +----------------------------------------------------------------------
820 +Assume "fileA" exists on the lower readonly branch only and it is
821 +hardlinked to "fileB" on the branch. When you write something to fileA,
822 +aufs copies-up it to the upper writable branch. Additionally aufs
823 +creates a hardlink under the Pseudo-link Directory of the writable
824 +branch. The inode of a pseudo-link is kept in aufs super_block as a
825 +simple list. If fileB is read after unlinking fileA, aufs returns
826 +filedata from the pseudo-link instead of the lower readonly
827 +branch. Because the pseudo-link is based upon the inode, to keep the
828 +inode number by xino (see above) is important.
830 +All the hardlinks under the Pseudo-link Directory of the writable branch
831 +should be restored in a proper location later. Aufs provides a utility
832 +to do this. The userspace helpers executed at remounting and unmounting
834 +During this utility is running, it puts aufs into the pseudo-link
835 +maintenance mode. In this mode, only the process which began the
836 +maintenance mode (and its child processes) is allowed to operate in
837 +aufs. Some other processes which are not related to the pseudo-link will
838 +be allowed to run too, but the rest have to return an error or wait
839 +until the maintenance mode ends. If a process already acquires an inode
840 +mutex (in VFS), it has to return an error.
843 +XIB(external inode number bitmap)
844 +----------------------------------------------------------------------
845 +Addition to the xino file per a branch, aufs has an external inode number
846 +bitmap in a superblock object. It is also a file such like a xino file.
847 +It is a simple bitmap to mark whether the aufs inode number is in-use or
849 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
851 +Aufs implements a feature to truncate/refresh both of xino and xib to
852 +reduce the number of consumed disk blocks for these files.
855 +Virtual or Vertical Dir, and Readdir in Userspace
856 +----------------------------------------------------------------------
857 +In order to support multiple layers (branches), aufs readdir operation
858 +constructs a virtual dir block on memory. For readdir, aufs calls
859 +vfs_readdir() internally for each dir on branches, merges their entries
860 +with eliminating the whiteout-ed ones, and sets it to file (dir)
861 +object. So the file object has its entry list until it is closed. The
862 +entry list will be updated when the file position is zero and becomes
863 +old. This decision is made in aufs automatically.
865 +The dynamically allocated memory block for the name of entries has a
866 +unit of 512 bytes (by default) and stores the names contiguously (no
867 +padding). Another block for each entry is handled by kmem_cache too.
868 +During building dir blocks, aufs creates hash list and judging whether
869 +the entry is whiteouted by its upper branch or already listed.
870 +The merged result is cached in the corresponding inode object and
871 +maintained by a customizable life-time option.
873 +Some people may call it can be a security hole or invite DoS attack
874 +since the opened and once readdir-ed dir (file object) holds its entry
875 +list and becomes a pressure for system memory. But I'd say it is similar
876 +to files under /proc or /sys. The virtual files in them also holds a
877 +memory page (generally) while they are opened. When an idea to reduce
878 +memory for them is introduced, it will be applied to aufs too.
879 +For those who really hate this situation, I've developed readdir(3)
880 +library which operates this merging in userspace. You just need to set
881 +LD_PRELOAD environment variable, and aufs will not consume no memory in
882 +kernel space for readdir(3).
886 +----------------------------------------------------------------------
887 +Aufs sometimes requires privilege access to a branch. For instance,
888 +in copy-up/down operation. When a user process is going to make changes
889 +to a file which exists in the lower readonly branch only, and the mode
890 +of one of ancestor directories may not be writable by a user
891 +process. Here aufs copy-up the file with its ancestors and they may
892 +require privilege to set its owner/group/mode/etc.
893 +This is a typical case of a application character of aufs (see
896 +Aufs uses workqueue synchronously for this case. It creates its own
897 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
898 +passes the request to call mkdir or write (for example), and wait for
899 +its completion. This approach solves a problem of a signal handler
901 +If aufs didn't adopt the workqueue and changed the privilege of the
902 +process, and if the mkdir/write call arises SIGXFSZ or other signal,
903 +then the user process might gain a privilege or the generated core file
904 +was owned by a superuser.
906 +Also aufs uses the system global workqueue ("events" kernel thread) too
907 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
908 +whiteout base and etc. This is unrelated to a privilege.
909 +Most of aufs operation tries acquiring a rw_semaphore for aufs
910 +superblock at the beginning, at the same time waits for the completion
911 +of all queued asynchronous tasks.
915 +----------------------------------------------------------------------
916 +The whiteout in aufs is very similar to Unionfs's. That is represented
917 +by its filename. UnionMount takes an approach of a file mode, but I am
918 +afraid several utilities (find(1) or something) will have to support it.
920 +Basically the whiteout represents "logical deletion" which stops aufs to
921 +lookup further, but also it represents "dir is opaque" which also stop
924 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
925 +In order to make several functions in a single systemcall to be
926 +revertible, aufs adopts an approach to rename a directory to a temporary
927 +unique whiteouted name.
928 +For example, in rename(2) dir where the target dir already existed, aufs
929 +renames the target dir to a temporary unique whiteouted name before the
930 +actual rename on a branch and then handles other actions (make it opaque,
931 +update the attributes, etc). If an error happens in these actions, aufs
932 +simply renames the whiteouted name back and returns an error. If all are
933 +succeeded, aufs registers a function to remove the whiteouted unique
934 +temporary name completely and asynchronously to the system global
939 +----------------------------------------------------------------------
940 +It is a well-known feature or concept.
941 +When user modifies a file on a readonly branch, aufs operate "copy-up"
942 +internally and makes change to the new file on the upper writable branch.
943 +When the trigger systemcall does not update the timestamps of the parent
944 +dir, aufs reverts it after copy-up.
947 +Move-down (aufs3.9 and later)
948 +----------------------------------------------------------------------
949 +"Copy-up" is one of the essential feature in aufs. It copies a file from
950 +the lower readonly branch to the upper writable branch when a user
951 +changes something about the file.
952 +"Move-down" is an opposite action of copy-up. Basically this action is
953 +ran manually instead of automatically and internally.
955 +Sometimes users want to move-down a file from the upper writable branch
956 +to the lower readonly or writable branch. For instance,
957 +- the free space of the upper writable branch is going to run out.
958 +- create a new intermediate branch between the upper and lower branch.
961 +For this purpose, use "aumvdown" command in aufs-util.git.
962 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
963 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
964 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2013-07-06 13:20:47.730197761 +0200
967 +# Copyright (C) 2005-2013 Junjiro R. Okajima
969 +# This program is free software; you can redistribute it and/or modify
970 +# it under the terms of the GNU General Public License as published by
971 +# the Free Software Foundation; either version 2 of the License, or
972 +# (at your option) any later version.
974 +# This program is distributed in the hope that it will be useful,
975 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
976 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
977 +# GNU General Public License for more details.
979 +# You should have received a copy of the GNU General Public License
980 +# along with this program; if not, write to the Free Software
981 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
984 +----------------------------------------------------------------------
985 +Since aufs has a character of sub-VFS (see Introduction), it operates
986 +lookup for branches as VFS does. It may be a heavy work. Generally
987 +speaking struct nameidata is a bigger structure and includes many
988 +information. But almost all lookup operation in aufs is the simplest
989 +case, ie. lookup only an entry directly connected to its parent. Digging
990 +down the directory hierarchy is unnecessary.
992 +VFS has a function lookup_one_len() for that use, but it is not usable
993 +for a branch filesystem which requires struct nameidata. So aufs
994 +implements a simple lookup wrapper function. When a branch filesystem
995 +allows NULL as nameidata, it calls lookup_one_len(). Otherwise it builds
996 +a simplest nameidata and calls lookup_hash().
997 +Here aufs applies "a principle in NFSD", ie. if the filesystem supports
998 +NFS-export, then it has to support NULL as a nameidata parameter for
999 +->create(), ->lookup() and ->d_revalidate(). So the lookup wrapper in
1000 +aufs tests if ->s_export_op in the branch is NULL or not.
1002 +When a branch is a remote filesystem, aufs basically trusts its
1003 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1005 +For d_revalidate, aufs implements three levels of revalidate tests. See
1006 +"Revalidate Dentry and UDBA" in detail.
1010 +----------------------------------------------------------------------
1011 +Basically aufs supports any type of filesystem and block device for a
1012 +branch (actually there are some exceptions). But it is prohibited to add
1013 +a loopback mounted one whose backend file exists in a filesystem which is
1014 +already added to aufs. The reason is to protect aufs from a recursive
1015 +lookup. If it was allowed, the aufs lookup operation might re-enter a
1016 +lookup for the loopback mounted branch in the same context, and will
1020 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1021 +----------------------------------------------------------------------
1022 +Generally VFS helpers re-validate a dentry as a part of lookup.
1023 +0. digging down the directory hierarchy.
1024 +1. lock the parent dir by its i_mutex.
1025 +2. lookup the final (child) entry.
1027 +4. call the actual operation (create, unlink, etc.)
1028 +5. unlock the parent dir
1030 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1031 +called. Actually aufs implements it and checks the dentry on a branch is
1033 +But it is not enough. Because aufs has to release the lock for the
1034 +parent dir on a branch at the end of ->lookup() (step 2) and
1035 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1037 +If the file on a branch is changed directly, eg. bypassing aufs, after
1038 +aufs released the lock, then the subsequent operation may cause
1039 +something unpleasant result.
1041 +This situation is a result of VFS architecture, ->lookup() and
1042 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1043 +design from VFS's point of view. It is just not suitable for sub-VFS
1046 +Aufs supports such case by three level of revalidation which is
1047 +selectable by user.
1048 +1. Simple Revalidate
1049 + Addition to the native flow in VFS's, confirm the child-parent
1050 + relationship on the branch just after locking the parent dir on the
1051 + branch in the "actual operation" (step 4). When this validation
1052 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1053 + checks the validation of the dentry on branches.
1054 +2. Monitor Changes Internally by Inotify/Fsnotify
1055 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1056 + the dentry on the branch, and returns EBUSY if it finds different
1058 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1059 + during it is in cache. When the event is notified, aufs registers a
1060 + function to kernel 'events' thread by schedule_work(). And the
1061 + function sets some special status to the cached aufs dentry and inode
1062 + private data. If they are not cached, then aufs has nothing to
1063 + do. When the same file is accessed through aufs (step 0-3) later,
1064 + aufs will detect the status and refresh all necessary data.
1065 + In this mode, aufs has to ignore the event which is fired by aufs
1067 +3. No Extra Validation
1068 + This is the simplest test and doesn't add any additional revalidation
1069 + test, and skip therevalidatin in step 4. It is useful and improves
1070 + aufs performance when system surely hide the aufs branches from user,
1071 + by over-mounting something (or another method).
1072 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1073 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1074 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2013-07-06 13:20:47.730197761 +0200
1077 +# Copyright (C) 2005-2013 Junjiro R. Okajima
1079 +# This program is free software; you can redistribute it and/or modify
1080 +# it under the terms of the GNU General Public License as published by
1081 +# the Free Software Foundation; either version 2 of the License, or
1082 +# (at your option) any later version.
1084 +# This program is distributed in the hope that it will be useful,
1085 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1086 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1087 +# GNU General Public License for more details.
1089 +# You should have received a copy of the GNU General Public License
1090 +# along with this program; if not, write to the Free Software
1091 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1093 +Branch Manipulation
1095 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1096 +and changing its permission/attribute, there are a lot of works to do.
1100 +----------------------------------------------------------------------
1101 +o Confirm the adding dir exists outside of aufs, including loopback
1103 +- and other various attributes...
1104 +o Initialize the xino file and whiteout bases if necessary.
1107 +o Check the owner/group/mode of the directory
1108 + When the owner/group/mode of the adding directory differs from the
1109 + existing branch, aufs issues a warning because it may impose a
1111 + For example, when a upper writable branch has a world writable empty
1112 + top directory, a malicious user can create any files on the writable
1113 + branch directly, like copy-up and modify manually. If something like
1114 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1115 + writable branch, and the writable branch is world-writable, then a
1116 + malicious guy may create /etc/passwd on the writable branch directly
1117 + and the infected file will be valid in aufs.
1118 + I am afraid it can be a security issue, but nothing to do except
1119 + producing a warning.
1123 +----------------------------------------------------------------------
1124 +o Confirm the deleting branch is not busy
1125 + To be general, there is one merit to adopt "remount" interface to
1126 + manipulate branches. It is to discard caches. At deleting a branch,
1127 + aufs checks the still cached (and connected) dentries and inodes. If
1128 + there are any, then they are all in-use. An inode without its
1129 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1131 + For the cached one, aufs checks whether the same named entry exists on
1133 + If the cached one is a directory, because aufs provides a merged view
1134 + to users, as long as one dir is left on any branch aufs can show the
1135 + dir to users. In this case, the branch can be removed from aufs.
1136 + Otherwise aufs rejects deleting the branch.
1138 + If any file on the deleting branch is opened by aufs, then aufs
1142 +Modify the Permission of a Branch
1143 +----------------------------------------------------------------------
1144 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1147 +o rw --> ro: Confirm the modifying branch is not busy
1148 + Aufs rejects the request if any of these conditions are true.
1149 + - a file on the branch is mmap-ed.
1150 + - a regular file on the branch is opened for write and there is no
1151 + same named entry on the upper branch.
1152 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1153 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1154 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2013-07-06 13:20:47.730197761 +0200
1157 +# Copyright (C) 2005-2013 Junjiro R. Okajima
1159 +# This program is free software; you can redistribute it and/or modify
1160 +# it under the terms of the GNU General Public License as published by
1161 +# the Free Software Foundation; either version 2 of the License, or
1162 +# (at your option) any later version.
1164 +# This program is distributed in the hope that it will be useful,
1165 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1166 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1167 +# GNU General Public License for more details.
1169 +# You should have received a copy of the GNU General Public License
1170 +# along with this program; if not, write to the Free Software
1171 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1173 +Policies to Select One among Multiple Writable Branches
1174 +----------------------------------------------------------------------
1175 +When the number of writable branch is more than one, aufs has to decide
1176 +the target branch for file creation or copy-up. By default, the highest
1177 +writable branch which has the parent (or ancestor) dir of the target
1178 +file is chosen (top-down-parent policy).
1179 +By user's request, aufs implements some other policies to select the
1180 +writable branch, for file creation two policies, round-robin and
1181 +most-free-space policies. For copy-up three policies, top-down-parent,
1182 +bottom-up-parent and bottom-up policies.
1184 +As expected, the round-robin policy selects the branch in circular. When
1185 +you have two writable branches and creates 10 new files, 5 files will be
1186 +created for each branch. mkdir(2) systemcall is an exception. When you
1187 +create 10 new directories, all will be created on the same branch.
1188 +And the most-free-space policy selects the one which has most free
1189 +space among the writable branches. The amount of free space will be
1190 +checked by aufs internally, and users can specify its time interval.
1192 +The policies for copy-up is more simple,
1193 +top-down-parent is equivalent to the same named on in create policy,
1194 +bottom-up-parent selects the writable branch where the parent dir
1195 +exists and the nearest upper one from the copyup-source,
1196 +bottom-up selects the nearest upper writable branch from the
1197 +copyup-source, regardless the existence of the parent dir.
1199 +There are some rules or exceptions to apply these policies.
1200 +- If there is a readonly branch above the policy-selected branch and
1201 + the parent dir is marked as opaque (a variation of whiteout), or the
1202 + target (creating) file is whiteout-ed on the upper readonly branch,
1203 + then the result of the policy is ignored and the target file will be
1204 + created on the nearest upper writable branch than the readonly branch.
1205 +- If there is a writable branch above the policy-selected branch and
1206 + the parent dir is marked as opaque or the target file is whiteouted
1207 + on the branch, then the result of the policy is ignored and the target
1208 + file will be created on the highest one among the upper writable
1209 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1211 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1212 + They try selecting the branch where the source exists as possible
1213 + since copyup a large file will take long time. If it can't be,
1214 + ie. the branch where the source exists is readonly, then they will
1215 + follow the copyup policy.
1216 +- There is an exception for rename(2) when the target exists.
1217 + If the rename target exists, aufs compares the index of the branches
1218 + where the source and the target exists and selects the higher
1219 + one. If the selected branch is readonly, then aufs follows the
1221 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
1222 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
1223 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2013-07-06 13:20:47.730197761 +0200
1226 +# Copyright (C) 2005-2013 Junjiro R. Okajima
1228 +# This program is free software; you can redistribute it and/or modify
1229 +# it under the terms of the GNU General Public License as published by
1230 +# the Free Software Foundation; either version 2 of the License, or
1231 +# (at your option) any later version.
1233 +# This program is distributed in the hope that it will be useful,
1234 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1235 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1236 +# GNU General Public License for more details.
1238 +# You should have received a copy of the GNU General Public License
1239 +# along with this program; if not, write to the Free Software
1240 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1242 +mmap(2) -- File Memory Mapping
1243 +----------------------------------------------------------------------
1244 +In aufs, the file-mapped pages are handled by a branch fs directly, no
1245 +interaction with aufs. It means aufs_mmap() calls the branch fs's
1247 +This approach is simple and good, but there is one problem.
1248 +Under /proc, several entries show the mmap-ped files by its path (with
1249 +device and inode number), and the printed path will be the path on the
1250 +branch fs's instead of virtual aufs's.
1251 +This is not a problem in most cases, but some utilities lsof(1) (and its
1252 +user) may expect the path on aufs.
1254 +To address this issue, aufs adds a new member called vm_prfile in struct
1255 +vm_area_struct (and struct vm_region). The original vm_file points to
1256 +the file on the branch fs in order to handle everything correctly as
1257 +usual. The new vm_prfile points to a virtual file in aufs, and the
1258 +show-functions in procfs refers to vm_prfile if it is set.
1259 +Also we need to maintain several other places where touching vm_file
1261 +- fork()/clone() copies vma and the reference count of vm_file is
1263 +- merging vma maintains the ref count too.
1265 +This is not a good approach. It just faking the printed path. But it
1266 +leaves all behaviour around f_mapping unchanged. This is surely an
1268 +Actually aufs had adopted another complicated approach which calls
1269 +generic_file_mmap() and handles struct vm_operations_struct. In this
1270 +approach, aufs met a hard problem and I could not solve it without
1271 +switching the approach.
1272 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
1273 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
1274 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2013-07-06 13:20:47.736864659 +0200
1277 +# Copyright (C) 2005-2013 Junjiro R. Okajima
1279 +# This program is free software; you can redistribute it and/or modify
1280 +# it under the terms of the GNU General Public License as published by
1281 +# the Free Software Foundation; either version 2 of the License, or
1282 +# (at your option) any later version.
1284 +# This program is distributed in the hope that it will be useful,
1285 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1286 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1287 +# GNU General Public License for more details.
1289 +# You should have received a copy of the GNU General Public License
1290 +# along with this program; if not, write to the Free Software
1291 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1293 +Export Aufs via NFS
1294 +----------------------------------------------------------------------
1295 +Here is an approach.
1296 +- like xino/xib, add a new file 'xigen' which stores aufs inode
1298 +- iget_locked(): initialize aufs inode generation for a new inode, and
1299 + store it in xigen file.
1300 +- destroy_inode(): increment aufs inode generation and store it in xigen
1301 + file. it is necessary even if it is not unlinked, because any data of
1302 + inode may be changed by UDBA.
1303 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
1304 + build file handle by
1305 + + branch id (4 bytes)
1306 + + superblock generation (4 bytes)
1307 + + inode number (4 or 8 bytes)
1308 + + parent dir inode number (4 or 8 bytes)
1309 + + inode generation (4 bytes))
1310 + + return value of exportfs_encode_fh() for the parent on a branch (4
1312 + + file handle for a branch (by exportfs_encode_fh())
1314 + + find the index of a branch from its id in handle, and check it is
1315 + still exist in aufs.
1316 + + 1st level: get the inode number from handle and search it in cache.
1317 + + 2nd level: if not found, get the parent inode number from handle and
1318 + search it in cache. and then open the parent dir, find the matching
1319 + inode number by vfs_readdir() and get its name, and call
1320 + lookup_one_len() for the target dentry.
1321 + + 3rd level: if the parent dir is not cached, call
1322 + exportfs_decode_fh() for a branch and get the parent on a branch,
1323 + build a pathname of it, convert it a pathname in aufs, call
1324 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
1326 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
1327 + for every branch, but not itself. to get this, (currently) aufs
1328 + searches in current->nsproxy->mnt_ns list. it may not be a good
1329 + idea, but I didn't get other approach.
1330 + + test the generation of the gotten inode.
1331 +- every inode operation: they may get EBUSY due to UDBA. in this case,
1332 + convert it into ESTALE for NFSD.
1333 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
1334 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
1335 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
1336 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
1337 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2013-07-06 13:20:47.736864659 +0200
1340 +# Copyright (C) 2005-2013 Junjiro R. Okajima
1342 +# This program is free software; you can redistribute it and/or modify
1343 +# it under the terms of the GNU General Public License as published by
1344 +# the Free Software Foundation; either version 2 of the License, or
1345 +# (at your option) any later version.
1347 +# This program is distributed in the hope that it will be useful,
1348 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1349 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1350 +# GNU General Public License for more details.
1352 +# You should have received a copy of the GNU General Public License
1353 +# along with this program; if not, write to the Free Software
1354 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1356 +Show Whiteout Mode (shwh)
1357 +----------------------------------------------------------------------
1358 +Generally aufs hides the name of whiteouts. But in some cases, to show
1359 +them is very useful for users. For instance, creating a new middle layer
1360 +(branch) by merging existing layers.
1362 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
1363 +When you have three branches,
1364 +- Bottom: 'system', squashfs (underlying base system), read-only
1365 +- Middle: 'mods', squashfs, read-only
1366 +- Top: 'overlay', ram (tmpfs), read-write
1368 +The top layer is loaded at boot time and saved at shutdown, to preserve
1369 +the changes made to the system during the session.
1370 +When larger changes have been made, or smaller changes have accumulated,
1371 +the size of the saved top layer data grows. At this point, it would be
1372 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
1373 +and rewrite the 'mods' squashfs, clearing the top layer and thus
1374 +restoring save and load speed.
1376 +This merging is simplified by the use of another aufs mount, of just the
1377 +two overlay branches using the 'shwh' option.
1378 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
1379 + aufs /livesys/merge_union
1381 +A merged view of these two branches is then available at
1382 +/livesys/merge_union, and the new feature is that the whiteouts are
1384 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
1385 +writing to all branches. Also the default mode for all branches is 'ro'.
1386 +It is now possible to save the combined contents of the two overlay
1387 +branches to a new squashfs, e.g.:
1388 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
1390 +This new squashfs archive can be stored on the boot device and the
1391 +initramfs will use it to replace the old one at the next boot.
1392 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
1393 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
1394 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2013-07-06 13:20:47.736864659 +0200
1397 +# Copyright (C) 2010-2013 Junjiro R. Okajima
1399 +# This program is free software; you can redistribute it and/or modify
1400 +# it under the terms of the GNU General Public License as published by
1401 +# the Free Software Foundation; either version 2 of the License, or
1402 +# (at your option) any later version.
1404 +# This program is distributed in the hope that it will be useful,
1405 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1406 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1407 +# GNU General Public License for more details.
1409 +# You should have received a copy of the GNU General Public License
1410 +# along with this program; if not, write to the Free Software
1411 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1413 +Dynamically customizable FS operations
1414 +----------------------------------------------------------------------
1415 +Generally FS operations (struct inode_operations, struct
1416 +address_space_operations, struct file_operations, etc.) are defined as
1417 +"static const", but it never means that FS have only one set of
1418 +operation. Some FS have multiple sets of them. For instance, ext2 has
1419 +three sets, one for XIP, for NOBH, and for normal.
1420 +Since aufs overrides and redirects these operations, sometimes aufs has
1421 +to change its behaviour according to the branch FS type. More imporantly
1422 +VFS acts differently if a function (member in the struct) is set or
1423 +not. It means aufs should have several sets of operations and select one
1424 +among them according to the branch FS definition.
1426 +In order to solve this problem and not to affect the behavour of VFS,
1427 +aufs defines these operations dynamically. For instance, aufs defines
1428 +aio_read function for struct file_operations, but it may not be set to
1429 +the file_operations. When the branch FS doesn't have it, aufs doesn't
1430 +set it to its file_operations while the function definition itself is
1431 +still alive. So the behaviour of io_submit(2) will not change, and it
1432 +will return an error when aio_read is not defined.
1434 +The lifetime of these dynamically generated operation object is
1435 +maintained by aufs branch object. When the branch is removed from aufs,
1436 +the reference counter of the object is decremented. When it reaches
1437 +zero, the dynamically generated operation object will be freed.
1439 +This approach is designed to support AIO (io_submit), Direcit I/O and
1441 +Currently this approach is applied to file_operations and
1442 +vm_operations_struct for regular files only.
1443 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt linux/Documentation/filesystems/aufs/design/99plan.txt
1444 --- /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt 1970-01-01 01:00:00.000000000 +0100
1445 +++ linux/Documentation/filesystems/aufs/design/99plan.txt 2013-07-06 13:20:47.736864659 +0200
1448 +# Copyright (C) 2005-2013 Junjiro R. Okajima
1450 +# This program is free software; you can redistribute it and/or modify
1451 +# it under the terms of the GNU General Public License as published by
1452 +# the Free Software Foundation; either version 2 of the License, or
1453 +# (at your option) any later version.
1455 +# This program is distributed in the hope that it will be useful,
1456 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1457 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1458 +# GNU General Public License for more details.
1460 +# You should have received a copy of the GNU General Public License
1461 +# along with this program; if not, write to the Free Software
1462 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1466 +Restoring some features which was implemented in aufs1.
1467 +They were dropped in aufs2 in order to make source files simpler and
1468 +easier to be reviewed.
1471 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1472 +----------------------------------------------------------------------
1473 +Let's try case study.
1474 +- aufs has two branches, upper readwrite and lower readonly.
1476 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1477 +- user invoked "chmod a+rx /au/dirA"
1478 +- then "dirA" becomes world readable?
1480 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1481 +or it may be a natively readonly filesystem. If aufs respects the lower
1482 +branch, it should not respond readdir request from other users. But user
1483 +allowed it by chmod. Should really aufs rejects showing the entries
1486 +To be honest, I don't have a best solution for this case. So I
1487 +implemented 'dirperm1' and 'nodirperm1' option in aufs1, and leave it to
1489 +When dirperm1 is specified, aufs checks only the highest one for the
1490 +directory permission, and shows the entries. Otherwise, as usual, checks
1491 +every dir existing on all branches and rejects the request.
1493 +As a side effect, dirperm1 option improves the performance of aufs
1494 +because the number of permission check is reduced.
1497 +Being Another Aufs's Readonly Branch (robr)
1498 +----------------------------------------------------------------------
1499 +Aufs1 allows aufs to be another aufs's readonly branch.
1500 +This feature was developed by a user's request. But it may not be used
1504 +Copy-up on Open (coo=)
1505 +----------------------------------------------------------------------
1506 +By default the internal copy-up is executed when it is really necessary.
1507 +It is not done when a file is opened for writing, but when write(2) is
1508 +done. Users who have many (over 100) branches want to know and analyse
1509 +when and what file is copied-up. To insert a new upper branch which
1510 +contains such files only may improve the performance of aufs.
1512 +Aufs1 implemented "coo=none | leaf | all" option.
1515 +Refresh the Opened File (refrof)
1516 +----------------------------------------------------------------------
1517 +This option is implemented in aufs1 but incomplete.
1519 +When user reads from a file, he expects to get its latest filedata
1520 +generally. If the file is removed and a new same named file is created,
1521 +the content he gets is unchanged, ie. the unlinked filedata.
1523 +Let's try case study again.
1524 +- aufs has two branches.
1526 +- "fileA" exists under /ro, but /rw.
1527 +- user opened "/au/fileA".
1528 +- he or someone else inserts a branch (/new) between /rw and /ro.
1529 + /au = /rw + /new + /ro
1530 +- the new branch has "fileA".
1531 +- user reads from the opened "fileA"
1532 +- which filedata should aufs return, from /ro or /new?
1534 +Some people says it has to be "from /ro" and it is a semantics of Unix.
1535 +The others say it should be "from /new" because the file is not removed
1536 +and it is equivalent to the case of someone else modifies the file.
1538 +Here again I don't have a best and final answer. I got an idea to
1539 +implement 'refrof' and 'norefrof' option. When 'refrof' (REFResh the
1540 +Opened File) is specified (by default), aufs returns the filedata from
1542 +Otherwise from /new.
1543 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
1544 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
1545 +++ linux/Documentation/filesystems/aufs/README 2013-10-26 16:51:32.273040419 +0200
1548 +Aufs3 -- advanced multi layered unification filesystem version 3.x
1554 +----------------------------------------
1555 +In the early days, aufs was entirely re-designed and re-implemented
1556 +Unionfs Version 1.x series. After many original ideas, approaches,
1557 +improvements and implementations, it becomes totally different from
1558 +Unionfs while keeping the basic features.
1559 +Recently, Unionfs Version 2.x series begin taking some of the same
1560 +approaches to aufs1's.
1561 +Unionfs is being developed by Professor Erez Zadok at Stony Brook
1562 +University and his team.
1564 +Aufs3 supports linux-3.0 and later.
1565 +If you want older kernel version support, try aufs2-2.6.git or
1566 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
1568 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
1569 +According to Christoph Hellwig, linux rejects all union-type filesystems
1571 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
1575 +----------------------------------------
1576 +- unite several directories into a single virtual filesystem. The member
1577 + directory is called as a branch.
1578 +- you can specify the permission flags to the branch, which are 'readonly',
1579 + 'readwrite' and 'whiteout-able.'
1580 +- by upper writable branch, internal copyup and whiteout, files/dirs on
1581 + readonly branch are modifiable logically.
1582 +- dynamic branch manipulation, add, del.
1585 +Also there are many enhancements in aufs1, such as:
1586 +- readdir(3) in userspace.
1587 +- keep inode number by external inode number table
1588 +- keep the timestamps of file/dir in internal copyup operation
1589 +- seekable directory, supporting NFS readdir.
1590 +- whiteout is hardlinked in order to reduce the consumption of inodes
1592 +- do not copyup, nor create a whiteout when it is unnecessary
1593 +- revert a single systemcall when an error occurs in aufs
1594 +- remount interface instead of ioctl
1595 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
1596 +- loopback mounted filesystem as a branch
1597 +- kernel thread for removing the dir who has a plenty of whiteouts
1598 +- support copyup sparse file (a file which has a 'hole' in it)
1599 +- default permission flags for branches
1600 +- selectable permission flags for ro branch, whether whiteout can
1603 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
1604 +- support multiple writable branches, some policies to select one
1605 + among multiple writable branches.
1606 +- a new semantics for link(2) and rename(2) to support multiple
1607 + writable branches.
1608 +- no glibc changes are required.
1609 +- pseudo hardlink (hardlink over branches)
1610 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
1611 + including NFS or remote filesystem branch.
1612 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
1615 +Currently these features are dropped temporary from aufs3.
1616 +See design/08plan.txt in detail.
1617 +- test only the highest one for the directory permission (dirperm1)
1618 +- copyup on open (coo=)
1619 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
1621 +- statistics of aufs thread (/sys/fs/aufs/stat)
1622 +- delegation mode (dlgt)
1623 + a delegation of the internal branch access to support task I/O
1624 + accounting, which also supports Linux Security Modules (LSM) mainly
1625 + for Suse AppArmor.
1626 +- intent.open/create (file open in a single lookup)
1628 +Features or just an idea in the future (see also design/*.txt),
1629 +- reorder the branch index without del/re-add.
1630 +- permanent xino files for NFSD
1631 +- an option for refreshing the opened files after add/del branches
1632 +- 'move' policy for copy-up between two writable branches, after
1633 + checking free space.
1634 +- light version, without branch manipulation. (unnecessary?)
1635 +- copyup in userspace
1636 +- inotify in userspace
1642 +----------------------------------------
1643 +There were three GIT trees for aufs3, aufs3-linux.git,
1644 +aufs3-standalone.git, and aufs-util.git. Note that there is no "3" in
1646 +While the aufs-util is always necessary, you need either of aufs3-linux
1647 +or aufs3-standalone.
1649 +The aufs3-linux tree includes the whole linux mainline GIT tree,
1650 +git://git.kernel.org/.../torvalds/linux.git.
1651 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
1652 +build aufs3 as an external kernel module.
1654 +On the other hand, the aufs3-standalone tree has only aufs source files
1655 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
1657 +You will find GIT branches whose name is in form of "aufs3.x" where "x"
1658 +represents the linux kernel version, "linux-3.x". For instance,
1659 +"aufs3.0" is for linux-3.0. For latest "linux-3.x-rcN", use
1660 +"aufs3.x-rcN" branch.
1663 +$ git clone --reference /your/linux/git/tree \
1664 + git://git.code.sf.net/p/aufs/aufs3-linux aufs-aufs3-linux \
1666 +- if you don't have linux GIT tree, then remove "--reference ..."
1667 +$ cd aufs3-linux.git
1668 +$ git checkout origin/aufs3.0
1670 +o aufs3-standalone tree
1671 +$ git clone git://git.code.sf.net/p/aufs/aufs3-standalone \
1672 + aufs3-standalone.git
1673 +$ cd aufs3-standalone.git
1674 +$ git checkout origin/aufs3.0
1677 +$ git clone git://git.code.sf.net/p/aufs/aufs-util \
1680 +$ git checkout origin/aufs3.0
1682 +Note: The 3.x-rcN branch is to be used with `rc' kernel versions ONLY.
1683 +The minor version number, 'x' in '3.x', of aufs may not always
1684 +follow the minor version number of the kernel.
1685 +Because changes in the kernel that cause the use of a new
1686 +minor version number do not always require changes to aufs-util.
1688 +Since aufs-util has its own minor version number, you may not be
1689 +able to find a GIT branch in aufs-util for your kernel's
1690 +exact minor version number.
1691 +In this case, you should git-checkout the branch for the
1692 +nearest lower number.
1694 +For (an unreleased) example:
1695 +If you are using "linux-3.10" and the "aufs3.10" branch
1696 +does not exist in aufs-util repository, then "aufs3.9", "aufs3.8"
1697 +or something numerically smaller is the branch for your kernel.
1699 +Also you can view all branches by
1703 +3. Configuration and Compilation
1704 +----------------------------------------
1705 +Make sure you have git-checkout'ed the correct branch.
1707 +For aufs3-linux tree,
1708 +- enable CONFIG_AUFS_FS.
1709 +- set other aufs configurations if necessary.
1711 +For aufs3-standalone tree,
1712 +There are several ways to build.
1715 +- apply ./aufs3-kbuild.patch to your kernel source files.
1716 +- apply ./aufs3-base.patch too.
1717 +- apply ./aufs3-proc_map.patch too, if you want to make /proc/PID/maps (and
1718 + others including lsof(1)) show the file path on aufs instead of the
1719 + path on the branch fs.
1720 +- apply ./aufs3-standalone.patch too, if you have a plan to set
1721 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs3-standalone.patch.
1722 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
1723 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
1724 +- enable CONFIG_AUFS_FS, you can select either
1726 +- and build your kernel as usual.
1727 +- install the built kernel.
1728 + Note: Since linux-3.9, every filesystem module requires an alias
1729 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
1730 + modules.aliases file if you set CONFIG_AUFS_FS=m.
1731 +- install the header files too by "make headers_install" to the
1732 + directory where you specify. By default, it is $PWD/usr.
1733 + "make help" shows a brief note for headers_install.
1734 +- and reboot your system.
1737 +- module only (CONFIG_AUFS_FS=m).
1738 +- apply ./aufs3-base.patch to your kernel source files.
1739 +- apply ./aufs3-proc_map.patch too to your kernel source files,
1740 + if you want to make /proc/PID/maps (and others including lsof(1)) show
1741 + the file path on aufs instead of the path on the branch fs.
1742 +- apply ./aufs3-standalone.patch too.
1743 +- build your kernel, don't forget "make headers_install", and reboot.
1744 +- edit ./config.mk and set other aufs configurations if necessary.
1745 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
1746 + every aufs configurations.
1747 +- build the module by simple "make".
1748 + Note: Since linux-3.9, every filesystem module requires an alias
1749 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
1750 + modules.aliases file.
1751 +- you can specify ${KDIR} make variable which points to your kernel
1753 +- install the files
1754 + + run "make install" to install the aufs module, or copy the built
1755 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
1756 + + run "make install_headers" (instead of headers_install) to install
1757 + the modified aufs header file (you can specify DESTDIR which is
1758 + available in aufs standalone version's Makefile only), or copy
1759 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
1760 + you like manually. By default, the target directory is $PWD/usr.
1761 +- no need to apply aufs3-kbuild.patch, nor copying source files to your
1762 + kernel source tree.
1764 +Note: The header file aufs_type.h is necessary to build aufs-util
1765 + as well as "make headers_install" in the kernel source tree.
1766 + headers_install is subject to be forgotten, but it is essentially
1767 + necessary, not only for building aufs-util.
1768 + You may not meet problems without headers_install in some older
1772 +- read README in aufs-util, build and install it
1773 +- note that your distribution may contain an obsoleted version of
1774 + aufs_type.h in /usr/include/linux or something. When you build aufs
1775 + utilities, make sure that your compiler refers the correct aufs header
1776 + file which is built by "make headers_install."
1777 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
1778 + then run "make install_ulib" too. And refer to the aufs manual in
1783 +----------------------------------------
1784 +At first, make sure aufs-util are installed, and please read the aufs
1785 +manual, aufs.5 in aufs-util.git tree.
1789 +$ mkdir /tmp/rw /tmp/aufs
1790 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
1792 +Here is another example. The result is equivalent.
1793 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
1795 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
1796 +# mount -o remount,append:${HOME} /tmp/aufs
1798 +Then, you can see whole tree of your home dir through /tmp/aufs. If
1799 +you modify a file under /tmp/aufs, the one on your home directory is
1800 +not affected, instead the same named file will be newly created under
1801 +/tmp/rw. And all of your modification to a file will be applied to
1802 +the one under /tmp/rw. This is called the file based Copy on Write
1804 +Aufs mount options are described in aufs.5.
1805 +If you run chroot or something and make your aufs as a root directory,
1806 +then you need to customize the shutdown script. See the aufs manual in
1809 +Additionally, there are some sample usages of aufs which are a
1810 +diskless system with network booting, and LiveCD over NFS.
1811 +See sample dir in CVS tree on SourceForge.
1815 +----------------------------------------
1816 +When you have any problems or strange behaviour in aufs, please let me
1818 +- /proc/mounts (instead of the output of mount(8))
1819 +- /sys/module/aufs/*
1820 +- /sys/fs/aufs/* (if you have them)
1821 +- /debug/aufs/* (if you have them)
1822 +- linux kernel version
1823 + if your kernel is not plain, for example modified by distributor,
1824 + the url where i can download its source is necessary too.
1825 +- aufs version which was printed at loading the module or booting the
1826 + system, instead of the date you downloaded.
1827 +- configuration (define/undefine CONFIG_AUFS_xxx)
1828 +- kernel configuration or /proc/config.gz (if you have it)
1829 +- behaviour which you think to be incorrect
1830 +- actual operation, reproducible one is better
1831 +- mailto: aufs-users at lists.sourceforge.net
1833 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
1834 +and Feature Requests) on SourceForge. Please join and write to
1838 +6. Acknowledgements
1839 +----------------------------------------
1840 +Thanks to everyone who have tried and are using aufs, whoever
1841 +have reported a bug or any feedback.
1843 +Especially donators:
1844 +Tomas Matejicek(slax.org) made a donation (much more than once).
1845 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
1846 + scripts) is making "doubling" donations.
1847 + Unfortunately I cannot list all of the donators, but I really
1849 + It ends Aug 2010, but the ordinary donation URL is still available.
1850 + <http://sourceforge.net/donate/index.php?group_id=167503>
1851 +Dai Itasaka made a donation (2007/8).
1852 +Chuck Smith made a donation (2008/4, 10 and 12).
1853 +Henk Schoneveld made a donation (2008/9).
1854 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
1855 +Francois Dupoux made a donation (2008/11).
1856 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
1857 + aufs2 GIT tree (2009/2).
1858 +William Grant made a donation (2009/3).
1859 +Patrick Lane made a donation (2009/4).
1860 +The Mail Archive (mail-archive.com) made donations (2009/5).
1861 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
1862 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
1863 +Pavel Pronskiy made a donation (2011/2).
1864 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
1865 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
1866 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
1868 +Sam Liddicott made a donation (2011/9).
1869 +Era Scarecrow made a donation (2013/4).
1870 +Bor Ratajc made a donation (2013/4).
1871 +Alessandro Gorreta made a donation (2013/4).
1872 +POIRETTE Marc made a donation (2013/4).
1873 +Alessandro Gorreta made a donation (2013/4).
1874 +lauri kasvandik made a donation (2013/5).
1875 +"pemasu from Finland" made a donation (2013/7).
1876 +The Parted Magic Project made a donation (2013/9).
1878 +Thank you very much.
1879 +Donations are always, including future donations, very important and
1880 +helpful for me to keep on developing aufs.
1884 +----------------------------------------
1885 +If you are an experienced user, no explanation is needed. Aufs is
1886 +just a linux filesystem.
1891 +# Local variables: ;
1894 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
1895 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
1896 +++ linux/fs/aufs/aufs.h 2013-07-06 13:20:47.736864659 +0200
1899 + * Copyright (C) 2005-2013 Junjiro R. Okajima
1901 + * This program, aufs is free software; you can redistribute it and/or modify
1902 + * it under the terms of the GNU General Public License as published by
1903 + * the Free Software Foundation; either version 2 of the License, or
1904 + * (at your option) any later version.
1906 + * This program is distributed in the hope that it will be useful,
1907 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1908 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1909 + * GNU General Public License for more details.
1911 + * You should have received a copy of the GNU General Public License
1912 + * along with this program; if not, write to the Free Software
1913 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1917 + * all header files
1925 +#define AuStub(type, name, body, ...) \
1926 + static inline type name(__VA_ARGS__) { body; }
1928 +#define AuStubVoid(name, ...) \
1929 + AuStub(void, name, , __VA_ARGS__)
1930 +#define AuStubInt0(name, ...) \
1931 + AuStub(int, name, return 0, __VA_ARGS__)
1935 +#include "branch.h"
1938 +#include "dbgaufs.h"
1939 +#include "dentry.h"
1943 +#include "fstype.h"
1946 +#include "module.h"
1951 +#include "sysaufs.h"
1956 +#endif /* __KERNEL__ */
1957 +#endif /* __AUFS_H__ */
1958 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
1959 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
1960 +++ linux/fs/aufs/branch.c 2013-10-26 16:51:32.273040419 +0200
1963 + * Copyright (C) 2005-2013 Junjiro R. Okajima
1965 + * This program, aufs is free software; you can redistribute it and/or modify
1966 + * it under the terms of the GNU General Public License as published by
1967 + * the Free Software Foundation; either version 2 of the License, or
1968 + * (at your option) any later version.
1970 + * This program is distributed in the hope that it will be useful,
1971 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1972 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1973 + * GNU General Public License for more details.
1975 + * You should have received a copy of the GNU General Public License
1976 + * along with this program; if not, write to the Free Software
1977 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1981 + * branch management
1984 +#include <linux/compat.h>
1985 +#include <linux/statfs.h>
1989 + * free a single branch
1992 +/* prohibit rmdir to the root of the branch */
1993 +/* todo: another new flag? */
1994 +static void au_br_dflags_force(struct au_branch *br)
1996 + struct dentry *h_dentry;
1998 + h_dentry = au_br_dentry(br);
1999 + spin_lock(&h_dentry->d_lock);
2000 + br->br_dflags = h_dentry->d_flags & DCACHE_MOUNTED;
2001 + h_dentry->d_flags |= DCACHE_MOUNTED;
2002 + spin_unlock(&h_dentry->d_lock);
2005 +/* restore its d_flags */
2006 +static void au_br_dflags_restore(struct au_branch *br)
2008 + struct dentry *h_dentry;
2010 + if (br->br_dflags)
2013 + h_dentry = au_br_dentry(br);
2014 + spin_lock(&h_dentry->d_lock);
2015 + h_dentry->d_flags &= ~DCACHE_MOUNTED;
2016 + spin_unlock(&h_dentry->d_lock);
2019 +static void au_br_do_free(struct au_branch *br)
2022 + struct au_wbr *wbr;
2023 + struct au_dykey **key;
2025 + au_hnotify_fin_br(br);
2027 + if (br->br_xino.xi_file)
2028 + fput(br->br_xino.xi_file);
2029 + mutex_destroy(&br->br_xino.xi_nondir_mtx);
2031 + AuDebugOn(atomic_read(&br->br_count));
2035 + for (i = 0; i < AuBrWh_Last; i++)
2036 + dput(wbr->wbr_wh[i]);
2037 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2038 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2041 + key = br->br_dykey;
2042 + for (i = 0; i < AuBrDynOp; i++, key++)
2048 + au_br_dflags_restore(br);
2050 + /* recursive lock, s_umount of branch's */
2052 + path_put(&br->br_path);
2059 + * frees all branches
2061 +void au_br_free(struct au_sbinfo *sbinfo)
2063 + aufs_bindex_t bmax;
2064 + struct au_branch **br;
2066 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2068 + bmax = sbinfo->si_bend + 1;
2069 + br = sbinfo->si_branch;
2071 + au_br_do_free(*br++);
2075 + * find the index of a branch which is specified by @br_id.
2077 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
2079 + aufs_bindex_t bindex, bend;
2081 + bend = au_sbend(sb);
2082 + for (bindex = 0; bindex <= bend; bindex++)
2083 + if (au_sbr_id(sb, bindex) == br_id)
2088 +/* ---------------------------------------------------------------------- */
2094 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
2095 + struct dentry *h_root)
2097 + if (unlikely(h_adding == h_root
2098 + || au_test_loopback_overlap(sb, h_adding)))
2100 + if (h_adding->d_sb != h_root->d_sb)
2102 + return au_test_subdir(h_adding, h_root)
2103 + || au_test_subdir(h_root, h_adding);
2107 + * returns a newly allocated branch. @new_nbranch is a number of branches
2108 + * after adding a branch.
2110 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
2113 + struct au_branch *add_branch;
2114 + struct dentry *root;
2118 + root = sb->s_root;
2119 + add_branch = kmalloc(sizeof(*add_branch), GFP_NOFS);
2120 + if (unlikely(!add_branch))
2123 + err = au_hnotify_init_br(add_branch, perm);
2124 + if (unlikely(err))
2127 + add_branch->br_wbr = NULL;
2128 + if (au_br_writable(perm)) {
2129 + /* may be freed separately at changing the branch permission */
2130 + add_branch->br_wbr = kmalloc(sizeof(*add_branch->br_wbr),
2132 + if (unlikely(!add_branch->br_wbr))
2136 + err = au_sbr_realloc(au_sbi(sb), new_nbranch);
2138 + err = au_di_realloc(au_di(root), new_nbranch);
2140 + err = au_ii_realloc(au_ii(root->d_inode), new_nbranch);
2142 + return add_branch; /* success */
2144 + kfree(add_branch->br_wbr);
2147 + au_hnotify_fin_br(add_branch);
2149 + kfree(add_branch);
2151 + return ERR_PTR(err);
2155 + * test if the branch permission is legal or not.
2157 +static int test_br(struct inode *inode, int brperm, char *path)
2161 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
2166 + pr_err("write permission for readonly mount or inode, %s\n", path);
2174 + * 0: success, the caller will add it
2175 + * plus: success, it is already unified, the caller should ignore it
2178 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
2181 + aufs_bindex_t bend, bindex;
2182 + struct dentry *root;
2183 + struct inode *inode, *h_inode;
2185 + root = sb->s_root;
2186 + bend = au_sbend(sb);
2187 + if (unlikely(bend >= 0
2188 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
2192 + pr_err("%s duplicated\n", add->pathname);
2197 + err = -ENOSPC; /* -E2BIG; */
2198 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
2199 + || AUFS_BRANCH_MAX - 1 <= bend)) {
2200 + pr_err("number of branches exceeded %s\n", add->pathname);
2205 + if (unlikely(add->bindex < 0 || bend + 1 < add->bindex)) {
2206 + pr_err("bad index %d\n", add->bindex);
2210 + inode = add->path.dentry->d_inode;
2212 + if (unlikely(!inode->i_nlink)) {
2213 + pr_err("no existence %s\n", add->pathname);
2218 + if (unlikely(inode->i_sb == sb)) {
2219 + pr_err("%s must be outside\n", add->pathname);
2223 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
2224 + pr_err("unsupported filesystem, %s (%s)\n",
2225 + add->pathname, au_sbtype(inode->i_sb));
2229 + err = test_br(add->path.dentry->d_inode, add->perm, add->pathname);
2230 + if (unlikely(err))
2234 + return 0; /* success */
2237 + for (bindex = 0; bindex <= bend; bindex++)
2238 + if (unlikely(test_overlap(sb, add->path.dentry,
2239 + au_h_dptr(root, bindex)))) {
2240 + pr_err("%s is overlapped\n", add->pathname);
2245 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
2246 + h_inode = au_h_dptr(root, 0)->d_inode;
2247 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
2248 + || !uid_eq(h_inode->i_uid, inode->i_uid)
2249 + || !gid_eq(h_inode->i_gid, inode->i_gid))
2250 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
2252 + i_uid_read(inode), i_gid_read(inode),
2253 + (inode->i_mode & S_IALLUGO),
2254 + i_uid_read(h_inode), i_gid_read(h_inode),
2255 + (h_inode->i_mode & S_IALLUGO));
2263 + * initialize or clean the whiteouts for an adding branch
2265 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
2268 + int err, old_perm;
2269 + aufs_bindex_t bindex;
2270 + struct mutex *h_mtx;
2271 + struct au_wbr *wbr;
2272 + struct au_hinode *hdir;
2274 + err = vfsub_mnt_want_write(au_br_mnt(br));
2275 + if (unlikely(err))
2279 + old_perm = br->br_perm;
2280 + br->br_perm = new_perm;
2283 + bindex = au_br_index(sb, br->br_id);
2284 + if (0 <= bindex) {
2285 + hdir = au_hi(sb->s_root->d_inode, bindex);
2286 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
2288 + h_mtx = &au_br_dentry(br)->d_inode->i_mutex;
2289 + mutex_lock_nested(h_mtx, AuLsc_I_PARENT);
2292 + err = au_wh_init(br, sb);
2294 + wbr_wh_write_lock(wbr);
2295 + err = au_wh_init(br, sb);
2296 + wbr_wh_write_unlock(wbr);
2299 + au_hn_imtx_unlock(hdir);
2301 + mutex_unlock(h_mtx);
2302 + vfsub_mnt_drop_write(au_br_mnt(br));
2303 + br->br_perm = old_perm;
2305 + if (!err && wbr && !au_br_writable(new_perm)) {
2307 + br->br_wbr = NULL;
2314 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
2318 + struct kstatfs kst;
2319 + struct au_wbr *wbr;
2322 + au_rw_init(&wbr->wbr_wh_rwsem);
2323 + memset(wbr->wbr_wh, 0, sizeof(wbr->wbr_wh));
2324 + atomic_set(&wbr->wbr_wh_running, 0);
2325 + wbr->wbr_bytes = 0;
2328 + * a limit for rmdir/rename a dir
2329 + * cf. AUFS_MAX_NAMELEN in include/linux/aufs_type.h
2331 + err = vfs_statfs(&br->br_path, &kst);
2332 + if (unlikely(err))
2335 + if (kst.f_namelen >= NAME_MAX)
2336 + err = au_br_init_wh(sb, br, perm);
2338 + pr_err("%.*s(%s), unsupported namelen %ld\n",
2339 + AuDLNPair(au_br_dentry(br)),
2340 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
2346 +/* intialize a new branch */
2347 +static int au_br_init(struct au_branch *br, struct super_block *sb,
2348 + struct au_opt_add *add)
2353 + memset(&br->br_xino, 0, sizeof(br->br_xino));
2354 + mutex_init(&br->br_xino.xi_nondir_mtx);
2355 + br->br_perm = add->perm;
2356 + BUILD_BUG_ON(sizeof(br->br_dflags)
2357 + != sizeof(br->br_path.dentry->d_flags));
2358 + br->br_dflags = DCACHE_MOUNTED;
2359 + br->br_path = add->path; /* set first, path_get() later */
2360 + spin_lock_init(&br->br_dykey_lock);
2361 + memset(br->br_dykey, 0, sizeof(br->br_dykey));
2362 + atomic_set(&br->br_count, 0);
2363 + atomic_set(&br->br_xino_running, 0);
2364 + br->br_id = au_new_br_id(sb);
2365 + AuDebugOn(br->br_id < 0);
2367 + if (au_br_writable(add->perm)) {
2368 + err = au_wbr_init(br, sb, add->perm);
2369 + if (unlikely(err))
2373 + if (au_opt_test(au_mntflags(sb), XINO)) {
2374 + err = au_xino_br(sb, br, add->path.dentry->d_inode->i_ino,
2375 + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1);
2376 + if (unlikely(err)) {
2377 + AuDebugOn(br->br_xino.xi_file);
2382 + sysaufs_br_init(br);
2383 + path_get(&br->br_path);
2384 + goto out; /* success */
2387 + memset(&br->br_path, 0, sizeof(br->br_path));
2392 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
2393 + struct au_branch *br, aufs_bindex_t bend,
2394 + aufs_bindex_t amount)
2396 + struct au_branch **brp;
2398 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2400 + brp = sbinfo->si_branch + bindex;
2401 + memmove(brp + 1, brp, sizeof(*brp) * amount);
2403 + sbinfo->si_bend++;
2404 + if (unlikely(bend < 0))
2405 + sbinfo->si_bend = 0;
2408 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
2409 + aufs_bindex_t bend, aufs_bindex_t amount)
2411 + struct au_hdentry *hdp;
2413 + AuRwMustWriteLock(&dinfo->di_rwsem);
2415 + hdp = dinfo->di_hdentry + bindex;
2416 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
2417 + au_h_dentry_init(hdp);
2419 + if (unlikely(bend < 0))
2420 + dinfo->di_bstart = 0;
2423 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
2424 + aufs_bindex_t bend, aufs_bindex_t amount)
2426 + struct au_hinode *hip;
2428 + AuRwMustWriteLock(&iinfo->ii_rwsem);
2430 + hip = iinfo->ii_hinode + bindex;
2431 + memmove(hip + 1, hip, sizeof(*hip) * amount);
2432 + hip->hi_inode = NULL;
2435 + if (unlikely(bend < 0))
2436 + iinfo->ii_bstart = 0;
2439 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
2440 + aufs_bindex_t bindex)
2442 + struct dentry *root, *h_dentry;
2443 + struct inode *root_inode;
2444 + aufs_bindex_t bend, amount;
2446 + au_br_dflags_force(br);
2448 + root = sb->s_root;
2449 + root_inode = root->d_inode;
2450 + bend = au_sbend(sb);
2451 + amount = bend + 1 - bindex;
2452 + h_dentry = au_br_dentry(br);
2453 + au_sbilist_lock();
2454 + au_br_do_add_brp(au_sbi(sb), bindex, br, bend, amount);
2455 + au_br_do_add_hdp(au_di(root), bindex, bend, amount);
2456 + au_br_do_add_hip(au_ii(root_inode), bindex, bend, amount);
2457 + au_set_h_dptr(root, bindex, dget(h_dentry));
2458 + au_set_h_iptr(root_inode, bindex, au_igrab(h_dentry->d_inode),
2460 + au_sbilist_unlock();
2463 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
2466 + aufs_bindex_t bend, add_bindex;
2467 + struct dentry *root, *h_dentry;
2468 + struct inode *root_inode;
2469 + struct au_branch *add_branch;
2471 + root = sb->s_root;
2472 + root_inode = root->d_inode;
2473 + IMustLock(root_inode);
2474 + err = test_add(sb, add, remount);
2475 + if (unlikely(err < 0))
2479 + goto out; /* success */
2482 + bend = au_sbend(sb);
2483 + add_branch = au_br_alloc(sb, bend + 2, add->perm);
2484 + err = PTR_ERR(add_branch);
2485 + if (IS_ERR(add_branch))
2488 + err = au_br_init(add_branch, sb, add);
2489 + if (unlikely(err)) {
2490 + au_br_do_free(add_branch);
2494 + add_bindex = add->bindex;
2496 + au_br_do_add(sb, add_branch, add_bindex);
2498 + sysaufs_brs_del(sb, add_bindex);
2499 + au_br_do_add(sb, add_branch, add_bindex);
2500 + sysaufs_brs_add(sb, add_bindex);
2503 + h_dentry = add->path.dentry;
2504 + if (!add_bindex) {
2505 + au_cpup_attr_all(root_inode, /*force*/1);
2506 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
2508 + au_add_nlink(root_inode, h_dentry->d_inode);
2511 + * this test/set prevents aufs from handling unnecesary notify events
2512 + * of xino files, in case of re-adding a writable branch which was
2513 + * once detached from aufs.
2515 + if (au_xino_brid(sb) < 0
2516 + && au_br_writable(add_branch->br_perm)
2517 + && !au_test_fs_bad_xino(h_dentry->d_sb)
2518 + && add_branch->br_xino.xi_file
2519 + && add_branch->br_xino.xi_file->f_dentry->d_parent == h_dentry)
2520 + au_xino_brid_set(sb, add_branch->br_id);
2526 +/* ---------------------------------------------------------------------- */
2532 +/* to show the line number, do not make it inlined function */
2533 +#define AuVerbose(do_info, fmt, ...) do { \
2535 + pr_info(fmt, ##__VA_ARGS__); \
2538 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t bstart,
2539 + aufs_bindex_t bend)
2541 + return (inode && !S_ISDIR(inode->i_mode)) || bstart == bend;
2544 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t bstart,
2545 + aufs_bindex_t bend)
2547 + return au_test_ibusy(dentry->d_inode, bstart, bend);
2551 + * test if the branch is deletable or not.
2553 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
2554 + unsigned int sigen, const unsigned int verbose)
2556 + int err, i, j, ndentry;
2557 + aufs_bindex_t bstart, bend;
2558 + struct au_dcsub_pages dpages;
2559 + struct au_dpage *dpage;
2562 + err = au_dpages_init(&dpages, GFP_NOFS);
2563 + if (unlikely(err))
2565 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
2566 + if (unlikely(err))
2569 + for (i = 0; !err && i < dpages.ndpage; i++) {
2570 + dpage = dpages.dpages + i;
2571 + ndentry = dpage->ndentry;
2572 + for (j = 0; !err && j < ndentry; j++) {
2573 + d = dpage->dentries[j];
2574 + AuDebugOn(!d_count(d));
2575 + if (!au_digen_test(d, sigen)) {
2576 + di_read_lock_child(d, AuLock_IR);
2577 + if (unlikely(au_dbrange_test(d))) {
2578 + di_read_unlock(d, AuLock_IR);
2582 + di_write_lock_child(d);
2583 + if (unlikely(au_dbrange_test(d))) {
2584 + di_write_unlock(d);
2587 + err = au_reval_dpath(d, sigen);
2589 + di_downgrade_lock(d, AuLock_IR);
2591 + di_write_unlock(d);
2596 + /* AuDbgDentry(d); */
2597 + bstart = au_dbstart(d);
2598 + bend = au_dbend(d);
2599 + if (bstart <= bindex
2601 + && au_h_dptr(d, bindex)
2602 + && au_test_dbusy(d, bstart, bend)) {
2604 + AuVerbose(verbose, "busy %.*s\n", AuDLNPair(d));
2607 + di_read_unlock(d, AuLock_IR);
2612 + au_dpages_free(&dpages);
2617 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
2618 + unsigned int sigen, const unsigned int verbose)
2621 + unsigned long long max, ull;
2622 + struct inode *i, **array;
2623 + aufs_bindex_t bstart, bend;
2625 + array = au_iarray_alloc(sb, &max);
2626 + err = PTR_ERR(array);
2627 + if (IS_ERR(array))
2631 + AuDbg("b%d\n", bindex);
2632 + for (ull = 0; !err && ull < max; ull++) {
2634 + if (i->i_ino == AUFS_ROOT_INO)
2637 + /* AuDbgInode(i); */
2638 + if (au_iigen(i, NULL) == sigen)
2639 + ii_read_lock_child(i);
2641 + ii_write_lock_child(i);
2642 + err = au_refresh_hinode_self(i);
2645 + ii_downgrade_lock(i);
2647 + ii_write_unlock(i);
2652 + bstart = au_ibstart(i);
2653 + bend = au_ibend(i);
2654 + if (bstart <= bindex
2656 + && au_h_iptr(i, bindex)
2657 + && au_test_ibusy(i, bstart, bend)) {
2659 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
2662 + ii_read_unlock(i);
2664 + au_iarray_free(array, max);
2670 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
2671 + const unsigned int verbose)
2674 + unsigned int sigen;
2676 + sigen = au_sigen(root->d_sb);
2677 + DiMustNoWaiters(root);
2678 + IiMustNoWaiters(root->d_inode);
2679 + di_write_unlock(root);
2680 + err = test_dentry_busy(root, bindex, sigen, verbose);
2682 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
2683 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
2688 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
2689 + const aufs_bindex_t bindex,
2690 + const aufs_bindex_t bend)
2692 + struct au_branch **brp, **p;
2694 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2696 + brp = sbinfo->si_branch + bindex;
2697 + if (bindex < bend)
2698 + memmove(brp, brp + 1, sizeof(*brp) * (bend - bindex));
2699 + sbinfo->si_branch[0 + bend] = NULL;
2700 + sbinfo->si_bend--;
2702 + p = krealloc(sbinfo->si_branch, sizeof(*p) * bend, AuGFP_SBILIST);
2704 + sbinfo->si_branch = p;
2705 + /* harmless error */
2708 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
2709 + const aufs_bindex_t bend)
2711 + struct au_hdentry *hdp, *p;
2713 + AuRwMustWriteLock(&dinfo->di_rwsem);
2715 + hdp = dinfo->di_hdentry;
2716 + if (bindex < bend)
2717 + memmove(hdp + bindex, hdp + bindex + 1,
2718 + sizeof(*hdp) * (bend - bindex));
2719 + hdp[0 + bend].hd_dentry = NULL;
2722 + p = krealloc(hdp, sizeof(*p) * bend, AuGFP_SBILIST);
2724 + dinfo->di_hdentry = p;
2725 + /* harmless error */
2728 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
2729 + const aufs_bindex_t bend)
2731 + struct au_hinode *hip, *p;
2733 + AuRwMustWriteLock(&iinfo->ii_rwsem);
2735 + hip = iinfo->ii_hinode + bindex;
2736 + if (bindex < bend)
2737 + memmove(hip, hip + 1, sizeof(*hip) * (bend - bindex));
2738 + iinfo->ii_hinode[0 + bend].hi_inode = NULL;
2739 + au_hn_init(iinfo->ii_hinode + bend);
2742 + p = krealloc(iinfo->ii_hinode, sizeof(*p) * bend, AuGFP_SBILIST);
2744 + iinfo->ii_hinode = p;
2745 + /* harmless error */
2748 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
2749 + struct au_branch *br)
2751 + aufs_bindex_t bend;
2752 + struct au_sbinfo *sbinfo;
2753 + struct dentry *root, *h_root;
2754 + struct inode *inode, *h_inode;
2755 + struct au_hinode *hinode;
2757 + SiMustWriteLock(sb);
2759 + root = sb->s_root;
2760 + inode = root->d_inode;
2761 + sbinfo = au_sbi(sb);
2762 + bend = sbinfo->si_bend;
2764 + h_root = au_h_dptr(root, bindex);
2765 + hinode = au_hi(inode, bindex);
2766 + h_inode = au_igrab(hinode->hi_inode);
2769 + au_sbilist_lock();
2770 + au_br_do_del_brp(sbinfo, bindex, bend);
2771 + au_br_do_del_hdp(au_di(root), bindex, bend);
2772 + au_br_do_del_hip(au_ii(inode), bindex, bend);
2773 + au_sbilist_unlock();
2777 + au_br_do_free(br);
2780 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
2783 + unsigned int mnt_flags;
2784 + aufs_bindex_t bindex, bend, br_id;
2785 + unsigned char do_wh, verbose;
2786 + struct au_branch *br;
2787 + struct au_wbr *wbr;
2790 + bindex = au_find_dbindex(sb->s_root, del->h_path.dentry);
2793 + goto out; /* success */
2795 + pr_err("%s no such branch\n", del->pathname);
2798 + AuDbg("bindex b%d\n", bindex);
2801 + mnt_flags = au_mntflags(sb);
2802 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
2803 + bend = au_sbend(sb);
2804 + if (unlikely(!bend)) {
2805 + AuVerbose(verbose, "no more branches left\n");
2808 + br = au_sbr(sb, bindex);
2809 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
2810 + i = atomic_read(&br->br_count);
2811 + if (unlikely(i)) {
2812 + AuVerbose(verbose, "%d file(s) opened\n", i);
2817 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
2819 + /* instead of WbrWhMustWriteLock(wbr) */
2820 + SiMustWriteLock(sb);
2821 + for (i = 0; i < AuBrWh_Last; i++) {
2822 + dput(wbr->wbr_wh[i]);
2823 + wbr->wbr_wh[i] = NULL;
2827 + err = test_children_busy(sb->s_root, bindex, verbose);
2828 + if (unlikely(err)) {
2835 + br_id = br->br_id;
2837 + au_br_do_del(sb, bindex, br);
2839 + sysaufs_brs_del(sb, bindex);
2840 + au_br_do_del(sb, bindex, br);
2841 + sysaufs_brs_add(sb, bindex);
2845 + au_cpup_attr_all(sb->s_root->d_inode, /*force*/1);
2846 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
2848 + au_sub_nlink(sb->s_root->d_inode, del->h_path.dentry->d_inode);
2849 + if (au_opt_test(mnt_flags, PLINK))
2850 + au_plink_half_refresh(sb, br_id);
2852 + if (au_xino_brid(sb) == br_id)
2853 + au_xino_brid_set(sb, -1);
2854 + goto out; /* success */
2858 + rerr = au_br_init_wh(sb, br, br->br_perm);
2860 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
2861 + del->pathname, rerr);
2866 +/* ---------------------------------------------------------------------- */
2868 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
2871 + aufs_bindex_t bstart, bend;
2872 + struct aufs_ibusy ibusy;
2873 + struct inode *inode, *h_inode;
2876 + if (unlikely(!capable(CAP_SYS_ADMIN)))
2879 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
2881 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
2882 + if (unlikely(err)) {
2889 + si_read_lock(sb, AuLock_FLUSH);
2890 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbend(sb)))
2894 + ibusy.h_ino = 0; /* invalid */
2895 + inode = ilookup(sb, ibusy.ino);
2897 + || inode->i_ino == AUFS_ROOT_INO
2898 + || is_bad_inode(inode))
2901 + ii_read_lock_child(inode);
2902 + bstart = au_ibstart(inode);
2903 + bend = au_ibend(inode);
2904 + if (bstart <= ibusy.bindex && ibusy.bindex <= bend) {
2905 + h_inode = au_h_iptr(inode, ibusy.bindex);
2906 + if (h_inode && au_test_ibusy(inode, bstart, bend))
2907 + ibusy.h_ino = h_inode->i_ino;
2909 + ii_read_unlock(inode);
2913 + si_read_unlock(sb);
2915 + err = __put_user(ibusy.h_ino, &arg->h_ino);
2916 + if (unlikely(err)) {
2925 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
2927 + return au_ibusy(file->f_dentry->d_sb, (void __user *)arg);
2930 +#ifdef CONFIG_COMPAT
2931 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
2933 + return au_ibusy(file->f_dentry->d_sb, compat_ptr(arg));
2937 +/* ---------------------------------------------------------------------- */
2940 + * change a branch permission
2943 +static void au_warn_ima(void)
2946 + /* since it doesn't support mark_files_ro() */
2947 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
2951 +static int do_need_sigen_inc(int a, int b)
2953 + return au_br_whable(a) && !au_br_whable(b);
2956 +static int need_sigen_inc(int old, int new)
2958 + return do_need_sigen_inc(old, new)
2959 + || do_need_sigen_inc(new, old);
2962 +static unsigned long long au_farray_cb(void *a,
2963 + unsigned long long max __maybe_unused,
2966 + unsigned long long n;
2967 + struct file **p, *f;
2968 + struct super_block *sb = arg;
2972 + lg_global_lock(&files_lglock);
2973 + do_file_list_for_each_entry(sb, f) {
2976 + && !special_file(file_inode(f)->i_mode)) {
2980 + AuDebugOn(n > max);
2982 + } while_file_list_for_each_entry;
2983 + lg_global_unlock(&files_lglock);
2988 +static struct file **au_farray_alloc(struct super_block *sb,
2989 + unsigned long long *max)
2991 + *max = atomic_long_read(&au_sbi(sb)->si_nfiles);
2992 + return au_array_alloc(max, au_farray_cb, sb);
2995 +static void au_farray_free(struct file **a, unsigned long long max)
2997 + unsigned long long ull;
2999 + for (ull = 0; ull < max; ull++)
3005 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
3008 + unsigned int mnt_flags;
3009 + unsigned long long ull, max;
3010 + aufs_bindex_t br_id;
3011 + unsigned char verbose;
3012 + struct file *file, *hf, **array;
3013 + struct inode *inode;
3014 + struct au_hfile *hfile;
3016 + mnt_flags = au_mntflags(sb);
3017 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3019 + array = au_farray_alloc(sb, &max);
3020 + err = PTR_ERR(array);
3021 + if (IS_ERR(array))
3025 + br_id = au_sbr_id(sb, bindex);
3026 + for (ull = 0; ull < max; ull++) {
3027 + file = array[ull];
3029 + /* AuDbg("%.*s\n", AuDLNPair(file->f_dentry)); */
3030 + fi_read_lock(file);
3031 + if (unlikely(au_test_mmapped(file))) {
3033 + AuVerbose(verbose, "mmapped %.*s\n",
3034 + AuDLNPair(file->f_dentry));
3036 + FiMustNoWaiters(file);
3037 + fi_read_unlock(file);
3041 + inode = file_inode(file);
3042 + hfile = &au_fi(file)->fi_htop;
3043 + hf = hfile->hf_file;
3044 + if (!S_ISREG(inode->i_mode)
3045 + || !(file->f_mode & FMODE_WRITE)
3046 + || hfile->hf_br->br_id != br_id
3047 + || !(hf->f_mode & FMODE_WRITE))
3048 + array[ull] = NULL;
3054 + FiMustNoWaiters(file);
3055 + fi_read_unlock(file);
3063 + for (ull = 0; ull < max; ull++) {
3064 + file = array[ull];
3068 + /* todo: already flushed? */
3069 + /* cf. fs/super.c:mark_files_ro() */
3070 + /* fi_read_lock(file); */
3071 + hfile = &au_fi(file)->fi_htop;
3072 + hf = hfile->hf_file;
3073 + /* fi_read_unlock(file); */
3074 + spin_lock(&hf->f_lock);
3075 + hf->f_mode &= ~FMODE_WRITE;
3076 + spin_unlock(&hf->f_lock);
3077 + if (!file_check_writeable(hf)) {
3078 + __mnt_drop_write(hf->f_path.mnt);
3079 + file_release_write(hf);
3084 + au_farray_free(array, max);
3090 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
3094 + aufs_bindex_t bindex;
3095 + struct dentry *root;
3096 + struct au_branch *br;
3098 + root = sb->s_root;
3099 + bindex = au_find_dbindex(root, mod->h_root);
3102 + return 0; /* success */
3104 + pr_err("%s no such branch\n", mod->path);
3107 + AuDbg("bindex b%d\n", bindex);
3109 + err = test_br(mod->h_root->d_inode, mod->perm, mod->path);
3110 + if (unlikely(err))
3113 + br = au_sbr(sb, bindex);
3114 + AuDebugOn(mod->h_root != au_br_dentry(br));
3115 + if (br->br_perm == mod->perm)
3116 + return 0; /* success */
3118 + if (au_br_writable(br->br_perm)) {
3119 + /* remove whiteout base */
3120 + err = au_br_init_wh(sb, br, mod->perm);
3121 + if (unlikely(err))
3124 + if (!au_br_writable(mod->perm)) {
3125 + /* rw --> ro, file might be mmapped */
3126 + DiMustNoWaiters(root);
3127 + IiMustNoWaiters(root->d_inode);
3128 + di_write_unlock(root);
3129 + err = au_br_mod_files_ro(sb, bindex);
3130 + /* aufs_write_lock() calls ..._child() */
3131 + di_write_lock_child(root);
3133 + if (unlikely(err)) {
3135 + br->br_wbr = kmalloc(sizeof(*br->br_wbr),
3138 + rerr = au_wbr_init(br, sb, br->br_perm);
3139 + if (unlikely(rerr)) {
3140 + AuIOErr("nested error %d (%d)\n",
3142 + br->br_perm = mod->perm;
3146 + } else if (au_br_writable(mod->perm)) {
3149 + br->br_wbr = kmalloc(sizeof(*br->br_wbr), GFP_NOFS);
3151 + err = au_wbr_init(br, sb, mod->perm);
3152 + if (unlikely(err)) {
3153 + kfree(br->br_wbr);
3154 + br->br_wbr = NULL;
3160 + if ((br->br_perm & AuBrAttr_UNPIN)
3161 + && !(mod->perm & AuBrAttr_UNPIN))
3162 + au_br_dflags_force(br);
3163 + else if (!(br->br_perm & AuBrAttr_UNPIN)
3164 + && (mod->perm & AuBrAttr_UNPIN))
3165 + au_br_dflags_restore(br);
3166 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
3167 + br->br_perm = mod->perm;
3174 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
3175 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
3176 +++ linux/fs/aufs/branch.h 2013-10-26 16:51:32.273040419 +0200
3179 + * Copyright (C) 2005-2013 Junjiro R. Okajima
3181 + * This program, aufs is free software; you can redistribute it and/or modify
3182 + * it under the terms of the GNU General Public License as published by
3183 + * the Free Software Foundation; either version 2 of the License, or
3184 + * (at your option) any later version.
3186 + * This program is distributed in the hope that it will be useful,
3187 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3188 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3189 + * GNU General Public License for more details.
3191 + * You should have received a copy of the GNU General Public License
3192 + * along with this program; if not, write to the Free Software
3193 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3197 + * branch filesystems and xino for them
3200 +#ifndef __AUFS_BRANCH_H__
3201 +#define __AUFS_BRANCH_H__
3205 +#include <linux/mount.h>
3210 +/* ---------------------------------------------------------------------- */
3213 +struct au_xino_file {
3214 + struct file *xi_file;
3215 + struct mutex xi_nondir_mtx;
3217 + /* todo: make xino files an array to support huge inode number */
3219 +#ifdef CONFIG_DEBUG_FS
3220 + struct dentry *xi_dbgaufs;
3224 +/* members for writable branch only */
3225 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
3227 + struct au_rwsem wbr_wh_rwsem;
3228 + struct dentry *wbr_wh[AuBrWh_Last];
3229 + atomic_t wbr_wh_running;
3230 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
3231 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
3232 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
3235 + unsigned long long wbr_bytes;
3238 +/* ext2 has 3 types of operations at least, ext3 has 4 */
3239 +#define AuBrDynOp (AuDyLast * 4)
3241 +#ifdef CONFIG_AUFS_HFSNOTIFY
3242 +/* support for asynchronous destruction */
3243 +struct au_br_hfsnotify {
3244 + struct fsnotify_group *hfsn_group;
3248 +/* sysfs entries */
3249 +struct au_brsysfs {
3251 + struct attribute attr;
3260 +/* protected by superblock rwsem */
3262 + struct au_xino_file br_xino;
3264 + aufs_bindex_t br_id;
3267 + unsigned int br_dflags;
3268 + struct path br_path;
3269 + spinlock_t br_dykey_lock;
3270 + struct au_dykey *br_dykey[AuBrDynOp];
3271 + atomic_t br_count;
3273 + struct au_wbr *br_wbr;
3275 + /* xino truncation */
3276 + atomic_t br_xino_running;
3278 +#ifdef CONFIG_AUFS_HFSNOTIFY
3279 + struct au_br_hfsnotify *br_hfsn;
3282 +#ifdef CONFIG_SYSFS
3283 + /* entries under sysfs per mount-point */
3284 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
3288 +/* ---------------------------------------------------------------------- */
3290 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
3292 + return br->br_path.mnt;
3295 +static inline struct dentry *au_br_dentry(struct au_branch *br)
3297 + return br->br_path.dentry;
3300 +static inline struct super_block *au_br_sb(struct au_branch *br)
3302 + return au_br_mnt(br)->mnt_sb;
3305 +/* branch permissions and attributes */
3306 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
3307 +#define AuBrPerm_RO (1 << 1) /* readonly */
3308 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
3309 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
3311 +#define AuBrRAttr_WH (1 << 3) /* whiteout-able */
3313 +#define AuBrWAttr_NoLinkWH (1 << 4) /* un-hardlinkable whiteouts */
3315 +#define AuBrAttr_UNPIN (1 << 5) /* rename-able top dir of
3318 +static inline int au_br_writable(int brperm)
3320 + return brperm & AuBrPerm_RW;
3323 +static inline int au_br_whable(int brperm)
3325 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
3328 +static inline int au_br_wh_linkable(int brperm)
3330 + return !(brperm & AuBrWAttr_NoLinkWH);
3333 +static inline int au_br_rdonly(struct au_branch *br)
3335 + return ((au_br_sb(br)->s_flags & MS_RDONLY)
3336 + || !au_br_writable(br->br_perm))
3340 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
3342 +#ifdef CONFIG_AUFS_HNOTIFY
3343 + return !(brperm & AuBrPerm_RR);
3349 +/* ---------------------------------------------------------------------- */
3353 +void au_br_free(struct au_sbinfo *sinfo);
3354 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
3356 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
3358 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
3359 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
3360 +#ifdef CONFIG_COMPAT
3361 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
3364 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
3368 +static const loff_t au_loff_max = LLONG_MAX;
3370 +int au_xib_trunc(struct super_block *sb);
3371 +ssize_t xino_fread(au_readf_t func, struct file *file, void *buf, size_t size,
3373 +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size,
3375 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src);
3376 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent);
3377 +ino_t au_xino_new_ino(struct super_block *sb);
3378 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
3379 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
3381 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
3383 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino,
3384 + struct file *base_file, int do_test);
3385 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex);
3387 +struct au_opt_xino;
3388 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount);
3389 +void au_xino_clr(struct super_block *sb);
3390 +struct file *au_xino_def(struct super_block *sb);
3391 +int au_xino_path(struct seq_file *seq, struct file *file);
3393 +/* ---------------------------------------------------------------------- */
3395 +/* Superblock to branch */
3397 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
3399 + return au_sbr(sb, bindex)->br_id;
3403 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
3405 + return au_br_mnt(au_sbr(sb, bindex));
3409 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
3411 + return au_br_sb(au_sbr(sb, bindex));
3414 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
3416 + atomic_dec(&au_sbr(sb, bindex)->br_count);
3419 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
3421 + return au_sbr(sb, bindex)->br_perm;
3424 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
3426 + return au_br_whable(au_sbr_perm(sb, bindex));
3429 +/* ---------------------------------------------------------------------- */
3432 + * wbr_wh_read_lock, wbr_wh_write_lock
3433 + * wbr_wh_read_unlock, wbr_wh_write_unlock, wbr_wh_downgrade_lock
3435 +AuSimpleRwsemFuncs(wbr_wh, struct au_wbr *wbr, &wbr->wbr_wh_rwsem);
3437 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&wbr->wbr_wh_rwsem)
3438 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&wbr->wbr_wh_rwsem)
3439 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&wbr->wbr_wh_rwsem)
3441 +#endif /* __KERNEL__ */
3442 +#endif /* __AUFS_BRANCH_H__ */
3443 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
3444 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
3445 +++ linux/fs/aufs/conf.mk 2013-07-06 13:20:47.740198107 +0200
3448 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
3452 +AuConfStr += ${1}=${${1}}
3456 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
3458 + HNOTIFY HFSNOTIFY \
3469 +$(foreach i, ${AuConfAll}, \
3470 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
3472 +AuConfName = ${obj}/conf.str
3473 +${AuConfName}.tmp: FORCE
3474 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
3475 +${AuConfName}: ${AuConfName}.tmp
3476 + @diff -q $< $@ > /dev/null 2>&1 || { \
3477 + echo ' GEN ' $@; \
3481 +clean-files += ${AuConfName} ${AuConfName}.tmp
3482 +${obj}/sysfs.o: ${AuConfName}
3484 +-include ${srctree}/${src}/conf_priv.mk
3485 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
3486 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
3487 +++ linux/fs/aufs/cpup.c 2013-10-26 16:51:32.273040419 +0200
3490 + * Copyright (C) 2005-2013 Junjiro R. Okajima
3492 + * This program, aufs is free software; you can redistribute it and/or modify
3493 + * it under the terms of the GNU General Public License as published by
3494 + * the Free Software Foundation; either version 2 of the License, or
3495 + * (at your option) any later version.
3497 + * This program is distributed in the hope that it will be useful,
3498 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3499 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3500 + * GNU General Public License for more details.
3502 + * You should have received a copy of the GNU General Public License
3503 + * along with this program; if not, write to the Free Software
3504 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3508 + * copy-up functions, see wbr_policy.c for copy-down
3511 +#include <linux/fs_stack.h>
3512 +#include <linux/mm.h>
3515 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
3517 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
3518 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
3520 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
3522 + dst->i_flags |= iflags & ~mask;
3523 + if (au_test_fs_notime(dst->i_sb))
3524 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
3527 +void au_cpup_attr_timesizes(struct inode *inode)
3529 + struct inode *h_inode;
3531 + h_inode = au_h_iptr(inode, au_ibstart(inode));
3532 + fsstack_copy_attr_times(inode, h_inode);
3533 + fsstack_copy_inode_size(inode, h_inode);
3536 +void au_cpup_attr_nlink(struct inode *inode, int force)
3538 + struct inode *h_inode;
3539 + struct super_block *sb;
3540 + aufs_bindex_t bindex, bend;
3543 + bindex = au_ibstart(inode);
3544 + h_inode = au_h_iptr(inode, bindex);
3546 + && !S_ISDIR(h_inode->i_mode)
3547 + && au_opt_test(au_mntflags(sb), PLINK)
3548 + && au_plink_test(inode))
3552 + * 0 can happen in revalidating.
3553 + * h_inode->i_mutex is not held, but it is harmless since once i_nlink
3554 + * reaches 0, it will never become positive.
3556 + set_nlink(inode, h_inode->i_nlink);
3559 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
3560 + * it may includes whplink directory.
3562 + if (S_ISDIR(h_inode->i_mode)) {
3563 + bend = au_ibend(inode);
3564 + for (bindex++; bindex <= bend; bindex++) {
3565 + h_inode = au_h_iptr(inode, bindex);
3567 + au_add_nlink(inode, h_inode);
3572 +void au_cpup_attr_changeable(struct inode *inode)
3574 + struct inode *h_inode;
3576 + h_inode = au_h_iptr(inode, au_ibstart(inode));
3577 + inode->i_mode = h_inode->i_mode;
3578 + inode->i_uid = h_inode->i_uid;
3579 + inode->i_gid = h_inode->i_gid;
3580 + au_cpup_attr_timesizes(inode);
3581 + au_cpup_attr_flags(inode, h_inode->i_flags);
3584 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
3586 + struct au_iinfo *iinfo = au_ii(inode);
3588 + IiMustWriteLock(inode);
3590 + iinfo->ii_higen = h_inode->i_generation;
3591 + iinfo->ii_hsb1 = h_inode->i_sb;
3594 +void au_cpup_attr_all(struct inode *inode, int force)
3596 + struct inode *h_inode;
3598 + h_inode = au_h_iptr(inode, au_ibstart(inode));
3599 + au_cpup_attr_changeable(inode);
3600 + if (inode->i_nlink > 0)
3601 + au_cpup_attr_nlink(inode, force);
3602 + inode->i_rdev = h_inode->i_rdev;
3603 + inode->i_blkbits = h_inode->i_blkbits;
3604 + au_cpup_igen(inode, h_inode);
3607 +/* ---------------------------------------------------------------------- */
3609 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
3611 +/* keep the timestamps of the parent dir when cpup */
3612 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
3613 + struct path *h_path)
3615 + struct inode *h_inode;
3617 + dt->dt_dentry = dentry;
3618 + dt->dt_h_path = *h_path;
3619 + h_inode = h_path->dentry->d_inode;
3620 + dt->dt_atime = h_inode->i_atime;
3621 + dt->dt_mtime = h_inode->i_mtime;
3625 +void au_dtime_revert(struct au_dtime *dt)
3627 + struct iattr attr;
3630 + attr.ia_atime = dt->dt_atime;
3631 + attr.ia_mtime = dt->dt_mtime;
3632 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
3633 + | ATTR_ATIME | ATTR_ATIME_SET;
3635 + err = vfsub_notify_change(&dt->dt_h_path, &attr);
3636 + if (unlikely(err))
3637 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
3640 +/* ---------------------------------------------------------------------- */
3642 +/* internal use only */
3643 +struct au_cpup_reg_attr {
3646 + unsigned int iflags; /* inode->i_flags */
3649 +static noinline_for_stack
3650 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
3651 + struct au_cpup_reg_attr *h_src_attr)
3655 + struct path h_path;
3656 + struct inode *h_isrc, *h_idst;
3657 + struct kstat *h_st;
3659 + h_path.dentry = au_h_dptr(dst, bindex);
3660 + h_idst = h_path.dentry->d_inode;
3661 + h_path.mnt = au_sbr_mnt(dst->d_sb, bindex);
3662 + h_isrc = h_src->d_inode;
3663 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
3664 + | ATTR_ATIME | ATTR_MTIME
3665 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
3666 + if (h_src_attr && h_src_attr->valid) {
3667 + h_st = &h_src_attr->st;
3668 + ia.ia_uid = h_st->uid;
3669 + ia.ia_gid = h_st->gid;
3670 + ia.ia_atime = h_st->atime;
3671 + ia.ia_mtime = h_st->mtime;
3672 + if (h_idst->i_mode != h_st->mode
3673 + && !S_ISLNK(h_idst->i_mode)) {
3674 + ia.ia_valid |= ATTR_MODE;
3675 + ia.ia_mode = h_st->mode;
3677 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
3678 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
3680 + ia.ia_uid = h_isrc->i_uid;
3681 + ia.ia_gid = h_isrc->i_gid;
3682 + ia.ia_atime = h_isrc->i_atime;
3683 + ia.ia_mtime = h_isrc->i_mtime;
3684 + if (h_idst->i_mode != h_isrc->i_mode
3685 + && !S_ISLNK(h_idst->i_mode)) {
3686 + ia.ia_valid |= ATTR_MODE;
3687 + ia.ia_mode = h_isrc->i_mode;
3689 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
3690 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
3692 + err = vfsub_notify_change(&h_path, &ia);
3694 + /* is this nfs only? */
3695 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
3696 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
3697 + ia.ia_mode = h_isrc->i_mode;
3698 + err = vfsub_notify_change(&h_path, &ia);
3704 +/* ---------------------------------------------------------------------- */
3706 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
3707 + char *buf, unsigned long blksize)
3710 + size_t sz, rbytes, wbytes;
3711 + unsigned char all_zero;
3713 + struct mutex *h_mtx;
3714 + /* reduce stack usage */
3717 + zp = page_address(ZERO_PAGE(0));
3718 + if (unlikely(!zp))
3719 + return -ENOMEM; /* possible? */
3724 + AuDbg("len %lld\n", len);
3726 + if (len < blksize)
3730 + /* todo: signal_pending? */
3731 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
3732 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
3735 + if (unlikely(err < 0))
3739 + if (len >= rbytes && rbytes == blksize)
3740 + all_zero = !memcmp(buf, zp, rbytes);
3747 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
3749 + /* todo: signal_pending? */
3750 + if (unlikely(err == -EAGAIN || err == -EINTR))
3752 + if (unlikely(err < 0))
3757 + if (unlikely(err < 0))
3763 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
3765 + if (unlikely(res < 0))
3772 + /* the last block may be a hole */
3773 + if (!err && all_zero) {
3774 + AuLabel(last hole);
3777 + if (au_test_nfs(dst->f_dentry->d_sb)) {
3778 + /* nfs requires this step to make last hole */
3779 + /* is this only nfs? */
3781 + /* todo: signal_pending? */
3782 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
3783 + } while (err == -EAGAIN || err == -EINTR);
3790 + ia->ia_size = dst->f_pos;
3791 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
3792 + ia->ia_file = dst;
3793 + h_mtx = &file_inode(dst)->i_mutex;
3794 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
3795 + err = vfsub_notify_change(&dst->f_path, ia);
3796 + mutex_unlock(h_mtx);
3803 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
3806 + unsigned long blksize;
3807 + unsigned char do_kfree;
3811 + blksize = dst->f_dentry->d_sb->s_blocksize;
3812 + if (!blksize || PAGE_SIZE < blksize)
3813 + blksize = PAGE_SIZE;
3814 + AuDbg("blksize %lu\n", blksize);
3815 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
3817 + buf = kmalloc(blksize, GFP_NOFS);
3819 + buf = (void *)__get_free_page(GFP_NOFS);
3820 + if (unlikely(!buf))
3823 + if (len > (1 << 22))
3824 + AuDbg("copying a large file %lld\n", (long long)len);
3828 + err = au_do_copy_file(dst, src, len, buf, blksize);
3832 + free_page((unsigned long)buf);
3839 + * to support a sparse file which is opened with O_APPEND,
3840 + * we need to close the file.
3842 +static int au_cp_regular(struct au_cp_generic *cpg)
3845 + enum { SRC, DST };
3847 + aufs_bindex_t bindex;
3848 + unsigned int flags;
3849 + struct dentry *dentry;
3851 + struct file *file;
3852 + void *label, *label_file;
3855 + .bindex = cpg->bsrc,
3856 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
3858 + .label_file = &&out_src
3861 + .bindex = cpg->bdst,
3862 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
3863 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
3864 + .label = &&out_src,
3865 + .label_file = &&out_dst
3868 + struct super_block *sb;
3870 + /* bsrc branch can be ro/rw. */
3871 + sb = cpg->dentry->d_sb;
3873 + for (i = 0; i < 2; i++, f++) {
3874 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
3875 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
3876 + /*file*/NULL, f->force_wr);
3877 + err = PTR_ERR(f->file);
3878 + if (IS_ERR(f->file))
3881 + if (unlikely(!f->file->f_op))
3882 + goto *f->label_file;
3885 + /* try stopping to update while we copyup */
3886 + IMustLock(file[SRC].dentry->d_inode);
3887 + err = au_copy_file(file[DST].file, file[SRC].file, cpg->len);
3890 + fput(file[DST].file);
3891 + au_sbr_put(sb, file[DST].bindex);
3893 + fput(file[SRC].file);
3894 + au_sbr_put(sb, file[SRC].bindex);
3899 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
3900 + struct au_cpup_reg_attr *h_src_attr)
3904 + struct path h_path;
3905 + struct inode *h_src_inode;
3908 + h_src_inode = au_h_iptr(cpg->dentry->d_inode, cpg->bsrc);
3909 + l = i_size_read(h_src_inode);
3910 + if (cpg->len == -1 || l < cpg->len)
3913 + /* try stopping to update while we are referencing */
3914 + mutex_lock_nested(&h_src_inode->i_mutex, AuLsc_I_CHILD);
3915 + au_pin_hdir_unlock(cpg->pin);
3917 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
3918 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
3919 + h_src_attr->iflags = h_src_inode->i_flags;
3920 + err = vfs_getattr(&h_path, &h_src_attr->st);
3921 + if (unlikely(err)) {
3922 + mutex_unlock(&h_src_inode->i_mutex);
3925 + h_src_attr->valid = 1;
3926 + err = au_cp_regular(cpg);
3927 + mutex_unlock(&h_src_inode->i_mutex);
3928 + rerr = au_pin_hdir_relock(cpg->pin);
3937 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
3938 + struct inode *h_dir)
3941 + mm_segment_t old_fs;
3948 + if (unlikely(!h_src->d_inode->i_op->readlink))
3952 + sym.k = (void *)__get_free_page(GFP_NOFS);
3953 + if (unlikely(!sym.k))
3956 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
3957 + old_fs = get_fs();
3958 + set_fs(KERNEL_DS);
3959 + symlen = h_src->d_inode->i_op->readlink(h_src, sym.u, PATH_MAX);
3964 + sym.k[symlen] = 0;
3965 + err = vfsub_symlink(h_dir, h_path, sym.k);
3967 + free_page((unsigned long)sym.k);
3973 +static noinline_for_stack
3974 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
3975 + struct au_cpup_reg_attr *h_src_attr)
3979 + unsigned int mnt_flags;
3980 + unsigned char isdir;
3981 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
3982 + struct au_dtime dt;
3983 + struct path h_path;
3984 + struct dentry *h_src, *h_dst, *h_parent;
3985 + struct inode *h_inode, *h_dir;
3986 + struct super_block *sb;
3988 + /* bsrc branch can be ro/rw. */
3989 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
3990 + h_inode = h_src->d_inode;
3991 + AuDebugOn(h_inode != au_h_iptr(cpg->dentry->d_inode, cpg->bsrc));
3993 + /* try stopping to be referenced while we are creating */
3994 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
3995 + if (au_ftest_cpup(cpg->flags, RENAME))
3996 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
3997 + AUFS_WH_PFX_LEN));
3998 + h_parent = h_dst->d_parent; /* dir inode is locked */
3999 + h_dir = h_parent->d_inode;
4001 + AuDebugOn(h_parent != h_dst->d_parent);
4003 + sb = cpg->dentry->d_sb;
4004 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
4006 + h_path.dentry = h_parent;
4007 + au_dtime_store(&dt, dst_parent, &h_path);
4009 + h_path.dentry = h_dst;
4012 + mode = h_inode->i_mode;
4013 + switch (mode & S_IFMT) {
4015 + err = vfsub_create(h_dir, &h_path, mode | S_IWUSR,
4016 + /*want_excl*/true);
4018 + err = au_do_cpup_regular(cpg, h_src_attr);
4022 + err = vfsub_mkdir(h_dir, &h_path, mode);
4025 + * strange behaviour from the users view,
4026 + * particularry setattr case
4028 + if (au_ibstart(dst_parent->d_inode) == cpg->bdst)
4029 + au_cpup_attr_nlink(dst_parent->d_inode,
4031 + au_cpup_attr_nlink(cpg->dentry->d_inode, /*force*/1);
4035 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
4039 + AuDebugOn(!capable(CAP_MKNOD));
4043 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
4046 + AuIOErr("Unknown inode type 0%o\n", mode);
4050 + mnt_flags = au_mntflags(sb);
4051 + if (!au_opt_test(mnt_flags, UDBA_NONE)
4053 + && au_opt_test(mnt_flags, XINO)
4054 + && h_inode->i_nlink == 1
4055 + /* todo: unnecessary? */
4056 + /* && cpg->dentry->d_inode->i_nlink == 1 */
4057 + && cpg->bdst < cpg->bsrc
4058 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
4059 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
4060 + /* ignore this error */
4063 + au_dtime_revert(&dt);
4067 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
4070 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
4071 + struct inode *h_dir;
4072 + aufs_bindex_t bdst;
4074 + dentry = cpg->dentry;
4076 + h_dentry = au_h_dptr(dentry, bdst);
4077 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
4079 + au_set_h_dptr(dentry, bdst, NULL);
4080 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
4082 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
4083 + au_set_h_dptr(dentry, bdst, h_dentry);
4086 + parent = dget_parent(dentry);
4087 + h_parent = au_h_dptr(parent, bdst);
4089 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
4090 + if (IS_ERR(h_path->dentry))
4091 + err = PTR_ERR(h_path->dentry);
4093 + if (unlikely(err))
4096 + h_parent = h_dentry->d_parent; /* dir inode is locked */
4097 + h_dir = h_parent->d_inode;
4099 + AuDbg("%.*s %.*s\n", AuDLNPair(h_dentry), AuDLNPair(h_path->dentry));
4100 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path);
4101 + dput(h_path->dentry);
4108 + * copyup the @dentry from @bsrc to @bdst.
4109 + * the caller must set the both of lower dentries.
4110 + * @len is for truncating when it is -1 copyup the entire file.
4111 + * in link/rename cases, @dst_parent may be different from the real one.
4112 + * basic->bsrc can be larger than basic->bdst.
4114 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
4117 + aufs_bindex_t old_ibstart;
4118 + unsigned char isdir, plink;
4119 + struct dentry *h_src, *h_dst, *h_parent;
4120 + struct inode *dst_inode, *h_dir, *inode;
4121 + struct super_block *sb;
4122 + struct au_branch *br;
4123 + /* to reuduce stack size */
4125 + struct au_dtime dt;
4126 + struct path h_path;
4127 + struct au_cpup_reg_attr h_src_attr;
4131 + a = kmalloc(sizeof(*a), GFP_NOFS);
4134 + a->h_src_attr.valid = 0;
4136 + sb = cpg->dentry->d_sb;
4137 + br = au_sbr(sb, cpg->bdst);
4138 + a->h_path.mnt = au_br_mnt(br);
4139 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
4140 + h_parent = h_dst->d_parent; /* dir inode is locked */
4141 + h_dir = h_parent->d_inode;
4144 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
4145 + inode = cpg->dentry->d_inode;
4148 + dst_parent = dget_parent(cpg->dentry);
4152 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
4153 + dst_inode = au_h_iptr(inode, cpg->bdst);
4155 + if (unlikely(!plink)) {
4157 + AuIOErr("hi%lu(i%lu) exists on b%d "
4158 + "but plink is disabled\n",
4159 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
4163 + if (dst_inode->i_nlink) {
4164 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
4166 + h_src = au_plink_lkup(inode, cpg->bdst);
4167 + err = PTR_ERR(h_src);
4168 + if (IS_ERR(h_src))
4170 + if (unlikely(!h_src->d_inode)) {
4172 + AuIOErr("i%lu exists on a upper branch "
4173 + "but not pseudo-linked\n",
4180 + a->h_path.dentry = h_parent;
4181 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
4184 + a->h_path.dentry = h_dst;
4185 + err = vfsub_link(h_src, h_dir, &a->h_path);
4186 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
4187 + err = au_do_ren_after_cpup(cpg, &a->h_path);
4189 + au_dtime_revert(&a->dt);
4193 + /* todo: cpup_wh_file? */
4195 + au_update_ibrange(inode, /*do_put_zero*/1);
4198 + isdir = S_ISDIR(inode->i_mode);
4199 + old_ibstart = au_ibstart(inode);
4200 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
4201 + if (unlikely(err))
4203 + dst_inode = h_dst->d_inode;
4204 + mutex_lock_nested(&dst_inode->i_mutex, AuLsc_I_CHILD2);
4205 + /* todo: necessary? */
4206 + /* au_pin_hdir_unlock(cpg->pin); */
4208 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
4209 + if (unlikely(err)) {
4210 + /* todo: necessary? */
4211 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
4212 + mutex_unlock(&dst_inode->i_mutex);
4216 + if (cpg->bdst < old_ibstart) {
4217 + if (S_ISREG(inode->i_mode)) {
4218 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
4219 + if (unlikely(err)) {
4220 + /* ignore an error */
4221 + /* au_pin_hdir_relock(cpg->pin); */
4222 + mutex_unlock(&dst_inode->i_mutex);
4226 + au_set_ibstart(inode, cpg->bdst);
4228 + au_set_ibend(inode, cpg->bdst);
4229 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
4230 + au_hi_flags(inode, isdir));
4232 + /* todo: necessary? */
4233 + /* err = au_pin_hdir_relock(cpg->pin); */
4234 + mutex_unlock(&dst_inode->i_mutex);
4235 + if (unlikely(err))
4239 + && h_src->d_inode->i_nlink > 1
4241 + au_plink_append(inode, cpg->bdst, h_dst);
4243 + if (au_ftest_cpup(cpg->flags, RENAME)) {
4244 + a->h_path.dentry = h_dst;
4245 + err = au_do_ren_after_cpup(cpg, &a->h_path);
4248 + goto out_parent; /* success */
4252 + a->h_path.dentry = h_parent;
4253 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
4254 + a->h_path.dentry = h_dst;
4256 + if (h_dst->d_inode) {
4258 + rerr = vfsub_unlink(h_dir, &a->h_path, /*force*/0);
4260 + rerr = vfsub_rmdir(h_dir, &a->h_path);
4262 + au_dtime_revert(&a->dt);
4264 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
4275 +struct au_cpup_single_args {
4277 + struct au_cp_generic *cpg;
4278 + struct dentry *dst_parent;
4281 +static void au_call_cpup_single(void *args)
4283 + struct au_cpup_single_args *a = args;
4285 + au_pin_hdir_acquire_nest(a->cpg->pin);
4286 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
4287 + au_pin_hdir_release(a->cpg->pin);
4292 + * prevent SIGXFSZ in copy-up.
4293 + * testing CAP_MKNOD is for generic fs,
4294 + * but CAP_FSETID is for xfs only, currently.
4296 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
4299 + struct super_block *sb;
4300 + struct inode *h_dir;
4303 + sb = au_pinned_parent(pin)->d_sb;
4304 + if (!au_wkq_test()
4305 + && (!au_sbi(sb)->si_plink_maint_pid
4306 + || au_plink_maint(sb, AuLock_NOPLM))) {
4307 + switch (mode & S_IFMT) {
4309 + /* no condition about RLIMIT_FSIZE and the file size */
4314 + do_sio = !capable(CAP_MKNOD);
4318 + do_sio = ((mode & (S_ISUID | S_ISGID))
4319 + && !capable(CAP_FSETID));
4320 + /* this workaround may be removed in the future */
4322 + h_dir = au_pinned_h_dir(pin);
4323 + do_sio = h_dir->i_mode & S_ISVTX;
4331 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
4334 + struct dentry *h_dentry;
4336 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
4337 + if (!au_cpup_sio_test(pin, h_dentry->d_inode->i_mode))
4338 + err = au_cpup_single(cpg, dst_parent);
4340 + struct au_cpup_single_args args = {
4343 + .dst_parent = dst_parent
4345 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
4346 + if (unlikely(wkq_err))
4355 + * copyup the @dentry from the first active lower branch to @bdst,
4356 + * using au_cpup_single().
4358 +static int au_cpup_simple(struct au_cp_generic *cpg)
4361 + unsigned int flags_orig;
4362 + struct dentry *dentry;
4364 + AuDebugOn(cpg->bsrc < 0);
4366 + dentry = cpg->dentry;
4367 + DiMustWriteLock(dentry);
4369 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
4371 + flags_orig = cpg->flags;
4372 + au_fset_cpup(cpg->flags, RENAME);
4373 + err = au_cpup_single(cpg, NULL);
4374 + cpg->flags = flags_orig;
4376 + return 0; /* success */
4379 + au_set_h_dptr(dentry, cpg->bdst, NULL);
4380 + au_set_dbstart(dentry, cpg->bsrc);
4386 +struct au_cpup_simple_args {
4388 + struct au_cp_generic *cpg;
4391 +static void au_call_cpup_simple(void *args)
4393 + struct au_cpup_simple_args *a = args;
4395 + au_pin_hdir_acquire_nest(a->cpg->pin);
4396 + *a->errp = au_cpup_simple(a->cpg);
4397 + au_pin_hdir_release(a->cpg->pin);
4400 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
4403 + struct dentry *dentry, *parent;
4404 + struct file *h_file;
4405 + struct inode *h_dir;
4407 + dentry = cpg->dentry;
4409 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
4410 + AuDebugOn(cpg->bsrc < 0);
4411 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
4412 + err = PTR_ERR(h_file);
4413 + if (IS_ERR(h_file))
4417 + parent = dget_parent(dentry);
4418 + h_dir = au_h_iptr(parent->d_inode, cpg->bdst);
4419 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
4420 + && !au_cpup_sio_test(cpg->pin, dentry->d_inode->i_mode))
4421 + err = au_cpup_simple(cpg);
4423 + struct au_cpup_simple_args args = {
4427 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
4428 + if (unlikely(wkq_err))
4434 + au_h_open_post(dentry, cpg->bsrc, h_file);
4440 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
4442 + aufs_bindex_t bsrc, bend;
4443 + struct dentry *dentry, *h_dentry;
4445 + if (cpg->bsrc < 0) {
4446 + dentry = cpg->dentry;
4447 + bend = au_dbend(dentry);
4448 + for (bsrc = cpg->bdst + 1; bsrc <= bend; bsrc++) {
4449 + h_dentry = au_h_dptr(dentry, bsrc);
4451 + AuDebugOn(!h_dentry->d_inode);
4455 + AuDebugOn(bsrc > bend);
4458 + AuDebugOn(cpg->bsrc <= cpg->bdst);
4459 + return au_do_sio_cpup_simple(cpg);
4462 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
4464 + AuDebugOn(cpg->bdst <= cpg->bsrc);
4465 + return au_do_sio_cpup_simple(cpg);
4468 +/* ---------------------------------------------------------------------- */
4471 + * copyup the deleted file for writing.
4473 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
4474 + struct file *file)
4477 + unsigned int flags_orig;
4478 + aufs_bindex_t bsrc_orig;
4479 + struct dentry *h_d_dst, *h_d_start;
4480 + struct au_dinfo *dinfo;
4481 + struct au_hdentry *hdp;
4483 + dinfo = au_di(cpg->dentry);
4484 + AuRwMustWriteLock(&dinfo->di_rwsem);
4486 + bsrc_orig = cpg->bsrc;
4487 + cpg->bsrc = dinfo->di_bstart;
4488 + hdp = dinfo->di_hdentry;
4489 + h_d_dst = hdp[0 + cpg->bdst].hd_dentry;
4490 + dinfo->di_bstart = cpg->bdst;
4491 + hdp[0 + cpg->bdst].hd_dentry = wh_dentry;
4494 + h_d_start = hdp[0 + cpg->bsrc].hd_dentry;
4495 + hdp[0 + cpg->bsrc].hd_dentry = au_hf_top(file)->f_dentry;
4497 + flags_orig = cpg->flags;
4498 + cpg->flags = !AuCpup_DTIME;
4499 + err = au_cpup_single(cpg, /*h_parent*/NULL);
4500 + cpg->flags = flags_orig;
4503 + err = au_reopen_nondir(file);
4504 + hdp[0 + cpg->bsrc].hd_dentry = h_d_start;
4506 + hdp[0 + cpg->bdst].hd_dentry = h_d_dst;
4507 + dinfo->di_bstart = cpg->bsrc;
4508 + cpg->bsrc = bsrc_orig;
4513 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
4516 + aufs_bindex_t bdst;
4517 + struct au_dtime dt;
4518 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
4519 + struct au_branch *br;
4520 + struct path h_path;
4522 + dentry = cpg->dentry;
4524 + br = au_sbr(dentry->d_sb, bdst);
4525 + parent = dget_parent(dentry);
4526 + h_parent = au_h_dptr(parent, bdst);
4527 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
4528 + err = PTR_ERR(wh_dentry);
4529 + if (IS_ERR(wh_dentry))
4532 + h_path.dentry = h_parent;
4533 + h_path.mnt = au_br_mnt(br);
4534 + au_dtime_store(&dt, parent, &h_path);
4535 + err = au_do_cpup_wh(cpg, wh_dentry, file);
4536 + if (unlikely(err))
4540 + h_path.dentry = wh_dentry;
4541 + if (!S_ISDIR(wh_dentry->d_inode->i_mode))
4542 + err = vfsub_unlink(h_parent->d_inode, &h_path, /*force*/0);
4544 + err = vfsub_rmdir(h_parent->d_inode, &h_path);
4545 + if (unlikely(err)) {
4546 + AuIOErr("failed remove copied-up tmp file %.*s(%d)\n",
4547 + AuDLNPair(wh_dentry), err);
4550 + au_dtime_revert(&dt);
4551 + au_set_hi_wh(dentry->d_inode, bdst, wh_dentry);
4560 +struct au_cpup_wh_args {
4562 + struct au_cp_generic *cpg;
4563 + struct file *file;
4566 +static void au_call_cpup_wh(void *args)
4568 + struct au_cpup_wh_args *a = args;
4570 + au_pin_hdir_acquire_nest(a->cpg->pin);
4571 + *a->errp = au_cpup_wh(a->cpg, a->file);
4572 + au_pin_hdir_release(a->cpg->pin);
4575 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
4578 + aufs_bindex_t bdst;
4579 + struct dentry *dentry, *parent, *h_orph, *h_parent, *h_dentry;
4580 + struct inode *dir, *h_dir, *h_tmpdir;
4581 + struct au_wbr *wbr;
4582 + struct au_pin wh_pin, *pin_orig;
4584 + dentry = cpg->dentry;
4586 + parent = dget_parent(dentry);
4587 + dir = parent->d_inode;
4590 + h_dir = au_igrab(au_h_iptr(dir, bdst));
4593 + if (!h_dir->i_nlink) {
4594 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
4595 + h_orph = wbr->wbr_orph;
4597 + h_parent = dget(au_h_dptr(parent, bdst));
4598 + au_set_h_dptr(parent, bdst, dget(h_orph));
4599 + h_tmpdir = h_orph->d_inode;
4600 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
4603 + h_dentry = au_hf_top(file)->f_dentry;
4605 + h_dentry = au_h_dptr(dentry, au_dbstart(dentry));
4606 + mutex_lock_nested(&h_tmpdir->i_mutex, AuLsc_I_PARENT3);
4607 + /* todo: au_h_open_pre()? */
4609 + pin_orig = cpg->pin;
4610 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
4611 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
4612 + cpg->pin = &wh_pin;
4615 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
4616 + && !au_cpup_sio_test(cpg->pin, dentry->d_inode->i_mode))
4617 + err = au_cpup_wh(cpg, file);
4619 + struct au_cpup_wh_args args = {
4624 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
4625 + if (unlikely(wkq_err))
4630 + mutex_unlock(&h_tmpdir->i_mutex);
4631 + /* todo: au_h_open_post()? */
4632 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
4633 + au_set_h_dptr(parent, bdst, h_parent);
4634 + AuDebugOn(!pin_orig);
4635 + cpg->pin = pin_orig;
4643 +/* ---------------------------------------------------------------------- */
4646 + * generic routine for both of copy-up and copy-down.
4648 +/* cf. revalidate function in file.c */
4649 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
4650 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
4651 + struct au_pin *pin,
4652 + struct dentry *h_parent, void *arg),
4656 + struct au_pin pin;
4657 + struct dentry *d, *parent, *h_parent, *real_parent;
4660 + parent = dget_parent(dentry);
4661 + if (IS_ROOT(parent))
4664 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
4665 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
4667 + /* do not use au_dpage */
4668 + real_parent = parent;
4671 + parent = dget_parent(dentry);
4672 + h_parent = au_h_dptr(parent, bdst);
4674 + goto out; /* success */
4676 + /* find top dir which is necessary to cpup */
4680 + parent = dget_parent(d);
4681 + di_read_lock_parent3(parent, !AuLock_IR);
4682 + h_parent = au_h_dptr(parent, bdst);
4683 + di_read_unlock(parent, !AuLock_IR);
4684 + } while (!h_parent);
4686 + if (d != real_parent)
4687 + di_write_lock_child3(d);
4689 + /* somebody else might create while we were sleeping */
4690 + if (!au_h_dptr(d, bdst) || !au_h_dptr(d, bdst)->d_inode) {
4691 + if (au_h_dptr(d, bdst))
4692 + au_update_dbstart(d);
4694 + au_pin_set_dentry(&pin, d);
4695 + err = au_do_pin(&pin);
4697 + err = cp(d, bdst, &pin, h_parent, arg);
4702 + if (d != real_parent)
4703 + di_write_unlock(d);
4704 + if (unlikely(err))
4713 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
4714 + struct au_pin *pin,
4715 + struct dentry *h_parent __maybe_unused ,
4716 + void *arg __maybe_unused)
4718 + struct au_cp_generic cpg = {
4724 + .flags = AuCpup_DTIME
4726 + return au_sio_cpup_simple(&cpg);
4729 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
4731 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
4734 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
4737 + struct dentry *parent;
4738 + struct inode *dir;
4740 + parent = dget_parent(dentry);
4741 + dir = parent->d_inode;
4743 + if (au_h_iptr(dir, bdst))
4746 + di_read_unlock(parent, AuLock_IR);
4747 + di_write_lock_parent(parent);
4748 + /* someone else might change our inode while we were sleeping */
4749 + if (!au_h_iptr(dir, bdst))
4750 + err = au_cpup_dirs(dentry, bdst);
4751 + di_downgrade_lock(parent, AuLock_IR);
4757 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
4758 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
4759 +++ linux/fs/aufs/cpup.h 2013-10-26 16:51:32.273040419 +0200
4762 + * Copyright (C) 2005-2013 Junjiro R. Okajima
4764 + * This program, aufs is free software; you can redistribute it and/or modify
4765 + * it under the terms of the GNU General Public License as published by
4766 + * the Free Software Foundation; either version 2 of the License, or
4767 + * (at your option) any later version.
4769 + * This program is distributed in the hope that it will be useful,
4770 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4771 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4772 + * GNU General Public License for more details.
4774 + * You should have received a copy of the GNU General Public License
4775 + * along with this program; if not, write to the Free Software
4776 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
4780 + * copy-up/down functions
4783 +#ifndef __AUFS_CPUP_H__
4784 +#define __AUFS_CPUP_H__
4788 +#include <linux/path.h>
4794 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
4795 +void au_cpup_attr_timesizes(struct inode *inode);
4796 +void au_cpup_attr_nlink(struct inode *inode, int force);
4797 +void au_cpup_attr_changeable(struct inode *inode);
4798 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
4799 +void au_cpup_attr_all(struct inode *inode, int force);
4801 +/* ---------------------------------------------------------------------- */
4803 +struct au_cp_generic {
4804 + struct dentry *dentry;
4805 + aufs_bindex_t bdst, bsrc;
4807 + struct au_pin *pin;
4808 + unsigned int flags;
4812 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
4813 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
4815 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
4816 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
4818 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
4820 +#define AuCpup_RWDST (1 << 5) /* force write target even if
4821 + the branch is marked as RO */
4823 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
4824 +#define au_fset_cpup(flags, name) \
4825 + do { (flags) |= AuCpup_##name; } while (0)
4826 +#define au_fclr_cpup(flags, name) \
4827 + do { (flags) &= ~AuCpup_##name; } while (0)
4829 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
4830 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
4831 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
4832 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
4834 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
4835 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
4836 + struct au_pin *pin,
4837 + struct dentry *h_parent, void *arg),
4839 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
4840 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
4842 +/* ---------------------------------------------------------------------- */
4844 +/* keep timestamps when copyup */
4846 + struct dentry *dt_dentry;
4847 + struct path dt_h_path;
4848 + struct timespec dt_atime, dt_mtime;
4850 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4851 + struct path *h_path);
4852 +void au_dtime_revert(struct au_dtime *dt);
4854 +#endif /* __KERNEL__ */
4855 +#endif /* __AUFS_CPUP_H__ */
4856 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
4857 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
4858 +++ linux/fs/aufs/dbgaufs.c 2013-07-06 13:20:47.740198107 +0200
4861 + * Copyright (C) 2005-2013 Junjiro R. Okajima
4863 + * This program, aufs is free software; you can redistribute it and/or modify
4864 + * it under the terms of the GNU General Public License as published by
4865 + * the Free Software Foundation; either version 2 of the License, or
4866 + * (at your option) any later version.
4868 + * This program is distributed in the hope that it will be useful,
4869 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4870 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4871 + * GNU General Public License for more details.
4873 + * You should have received a copy of the GNU General Public License
4874 + * along with this program; if not, write to the Free Software
4875 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
4879 + * debugfs interface
4882 +#include <linux/debugfs.h>
4885 +#ifndef CONFIG_SYSFS
4886 +#error DEBUG_FS depends upon SYSFS
4889 +static struct dentry *dbgaufs;
4890 +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH;
4892 +/* 20 is max digits length of ulong 64 */
4893 +struct dbgaufs_arg {
4899 + * common function for all XINO files
4901 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
4902 + struct file *file)
4904 + kfree(file->private_data);
4908 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt)
4912 + struct dbgaufs_arg *p;
4915 + p = kmalloc(sizeof(*p), GFP_NOFS);
4921 + file->private_data = p;
4925 + err = vfs_getattr(&xf->f_path, &st);
4929 + (p->a, sizeof(p->a), "%ld, %llux%lu %lld\n",
4930 + (long)file_count(xf), st.blocks, st.blksize,
4931 + (long long)st.size);
4933 + p->n = snprintf(p->a, sizeof(p->a), "%llux%lu %lld\n",
4934 + st.blocks, st.blksize,
4935 + (long long)st.size);
4936 + AuDebugOn(p->n >= sizeof(p->a));
4938 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
4947 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
4948 + size_t count, loff_t *ppos)
4950 + struct dbgaufs_arg *p;
4952 + p = file->private_data;
4953 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
4956 +/* ---------------------------------------------------------------------- */
4958 +struct dbgaufs_plink_arg {
4963 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
4964 + struct file *file)
4966 + free_page((unsigned long)file->private_data);
4970 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
4972 + int err, i, limit;
4973 + unsigned long n, sum;
4974 + struct dbgaufs_plink_arg *p;
4975 + struct au_sbinfo *sbinfo;
4976 + struct super_block *sb;
4977 + struct au_sphlhead *sphl;
4980 + p = (void *)get_zeroed_page(GFP_NOFS);
4985 + sbinfo = inode->i_private;
4986 + sb = sbinfo->si_sb;
4987 + si_noflush_read_lock(sb);
4988 + if (au_opt_test(au_mntflags(sb), PLINK)) {
4989 + limit = PAGE_SIZE - sizeof(p->n);
4991 + /* the number of buckets */
4992 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
4997 + for (i = 0, sphl = sbinfo->si_plink;
4998 + i < AuPlink_NHASH;
5000 + n = au_sphl_count(sphl);
5003 + n = snprintf(p->a + p->n, limit, "%lu ", n);
5006 + if (unlikely(limit <= 0))
5009 + p->a[p->n - 1] = '\n';
5011 + /* the sum of plinks */
5012 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
5015 + if (unlikely(limit <= 0))
5018 +#define str "1\n0\n0\n"
5019 + p->n = sizeof(str) - 1;
5020 + strcpy(p->a, str);
5023 + si_read_unlock(sb);
5026 + file->private_data = p;
5027 + goto out; /* success */
5030 + free_page((unsigned long)p);
5035 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
5036 + size_t count, loff_t *ppos)
5038 + struct dbgaufs_plink_arg *p;
5040 + p = file->private_data;
5041 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
5044 +static const struct file_operations dbgaufs_plink_fop = {
5045 + .owner = THIS_MODULE,
5046 + .open = dbgaufs_plink_open,
5047 + .release = dbgaufs_plink_release,
5048 + .read = dbgaufs_plink_read
5051 +/* ---------------------------------------------------------------------- */
5053 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
5056 + struct au_sbinfo *sbinfo;
5057 + struct super_block *sb;
5059 + sbinfo = inode->i_private;
5060 + sb = sbinfo->si_sb;
5061 + si_noflush_read_lock(sb);
5062 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
5063 + si_read_unlock(sb);
5067 +static const struct file_operations dbgaufs_xib_fop = {
5068 + .owner = THIS_MODULE,
5069 + .open = dbgaufs_xib_open,
5070 + .release = dbgaufs_xi_release,
5071 + .read = dbgaufs_xi_read
5074 +/* ---------------------------------------------------------------------- */
5076 +#define DbgaufsXi_PREFIX "xi"
5078 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
5082 + struct au_sbinfo *sbinfo;
5083 + struct super_block *sb;
5085 + struct qstr *name;
5089 + name = &file->f_dentry->d_name;
5090 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
5091 + || memcmp(name->name, DbgaufsXi_PREFIX,
5092 + sizeof(DbgaufsXi_PREFIX) - 1)))
5094 + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
5095 + if (unlikely(err))
5098 + sbinfo = inode->i_private;
5099 + sb = sbinfo->si_sb;
5100 + si_noflush_read_lock(sb);
5101 + if (l <= au_sbend(sb)) {
5102 + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file;
5103 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1);
5106 + si_read_unlock(sb);
5112 +static const struct file_operations dbgaufs_xino_fop = {
5113 + .owner = THIS_MODULE,
5114 + .open = dbgaufs_xino_open,
5115 + .release = dbgaufs_xi_release,
5116 + .read = dbgaufs_xi_read
5119 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
5121 + aufs_bindex_t bend;
5122 + struct au_branch *br;
5123 + struct au_xino_file *xi;
5125 + if (!au_sbi(sb)->si_dbgaufs)
5128 + bend = au_sbend(sb);
5129 + for (; bindex <= bend; bindex++) {
5130 + br = au_sbr(sb, bindex);
5131 + xi = &br->br_xino;
5132 + debugfs_remove(xi->xi_dbgaufs);
5133 + xi->xi_dbgaufs = NULL;
5137 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
5139 + struct au_sbinfo *sbinfo;
5140 + struct dentry *parent;
5141 + struct au_branch *br;
5142 + struct au_xino_file *xi;
5143 + aufs_bindex_t bend;
5144 + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
5146 + sbinfo = au_sbi(sb);
5147 + parent = sbinfo->si_dbgaufs;
5151 + bend = au_sbend(sb);
5152 + for (; bindex <= bend; bindex++) {
5153 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
5154 + br = au_sbr(sb, bindex);
5155 + xi = &br->br_xino;
5156 + AuDebugOn(xi->xi_dbgaufs);
5157 + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
5158 + sbinfo, &dbgaufs_xino_fop);
5159 + /* ignore an error */
5160 + if (unlikely(!xi->xi_dbgaufs))
5161 + AuWarn1("failed %s under debugfs\n", name);
5165 +/* ---------------------------------------------------------------------- */
5167 +#ifdef CONFIG_AUFS_EXPORT
5168 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
5171 + struct au_sbinfo *sbinfo;
5172 + struct super_block *sb;
5174 + sbinfo = inode->i_private;
5175 + sb = sbinfo->si_sb;
5176 + si_noflush_read_lock(sb);
5177 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0);
5178 + si_read_unlock(sb);
5182 +static const struct file_operations dbgaufs_xigen_fop = {
5183 + .owner = THIS_MODULE,
5184 + .open = dbgaufs_xigen_open,
5185 + .release = dbgaufs_xi_release,
5186 + .read = dbgaufs_xi_read
5189 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
5194 + * This function is a dynamic '__init' fucntion actually,
5195 + * so the tiny check for si_rwsem is unnecessary.
5197 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
5200 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
5201 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
5202 + &dbgaufs_xigen_fop);
5203 + if (sbinfo->si_dbgaufs_xigen)
5209 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
5213 +#endif /* CONFIG_AUFS_EXPORT */
5215 +/* ---------------------------------------------------------------------- */
5217 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
5220 + * This function is a dynamic '__init' fucntion actually,
5221 + * so the tiny check for si_rwsem is unnecessary.
5223 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
5225 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
5226 + sbinfo->si_dbgaufs = NULL;
5227 + kobject_put(&sbinfo->si_kobj);
5230 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
5233 + char name[SysaufsSiNameLen];
5236 + * This function is a dynamic '__init' fucntion actually,
5237 + * so the tiny check for si_rwsem is unnecessary.
5239 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
5243 + AuErr1("/debug/aufs is uninitialized\n");
5248 + sysaufs_name(sbinfo, name);
5249 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
5250 + if (unlikely(!sbinfo->si_dbgaufs))
5252 + kobject_get(&sbinfo->si_kobj);
5254 + sbinfo->si_dbgaufs_xib = debugfs_create_file
5255 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
5256 + &dbgaufs_xib_fop);
5257 + if (unlikely(!sbinfo->si_dbgaufs_xib))
5260 + sbinfo->si_dbgaufs_plink = debugfs_create_file
5261 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
5262 + &dbgaufs_plink_fop);
5263 + if (unlikely(!sbinfo->si_dbgaufs_plink))
5266 + err = dbgaufs_xigen_init(sbinfo);
5268 + goto out; /* success */
5271 + dbgaufs_si_fin(sbinfo);
5276 +/* ---------------------------------------------------------------------- */
5278 +void dbgaufs_fin(void)
5280 + debugfs_remove(dbgaufs);
5283 +int __init dbgaufs_init(void)
5288 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
5293 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
5294 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
5295 +++ linux/fs/aufs/dbgaufs.h 2013-07-06 13:20:47.740198107 +0200
5298 + * Copyright (C) 2005-2013 Junjiro R. Okajima
5300 + * This program, aufs is free software; you can redistribute it and/or modify
5301 + * it under the terms of the GNU General Public License as published by
5302 + * the Free Software Foundation; either version 2 of the License, or
5303 + * (at your option) any later version.
5305 + * This program is distributed in the hope that it will be useful,
5306 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5307 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5308 + * GNU General Public License for more details.
5310 + * You should have received a copy of the GNU General Public License
5311 + * along with this program; if not, write to the Free Software
5312 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
5316 + * debugfs interface
5319 +#ifndef __DBGAUFS_H__
5320 +#define __DBGAUFS_H__
5324 +struct super_block;
5327 +#ifdef CONFIG_DEBUG_FS
5329 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
5330 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
5331 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
5332 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
5333 +void dbgaufs_fin(void);
5334 +int __init dbgaufs_init(void);
5336 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
5337 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
5338 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
5339 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
5340 +AuStubVoid(dbgaufs_fin, void)
5341 +AuStubInt0(__init dbgaufs_init, void)
5342 +#endif /* CONFIG_DEBUG_FS */
5344 +#endif /* __KERNEL__ */
5345 +#endif /* __DBGAUFS_H__ */
5346 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
5347 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
5348 +++ linux/fs/aufs/dcsub.c 2013-10-26 16:51:29.579631476 +0200
5351 + * Copyright (C) 2005-2013 Junjiro R. Okajima
5353 + * This program, aufs is free software; you can redistribute it and/or modify
5354 + * it under the terms of the GNU General Public License as published by
5355 + * the Free Software Foundation; either version 2 of the License, or
5356 + * (at your option) any later version.
5358 + * This program is distributed in the hope that it will be useful,
5359 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5360 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5361 + * GNU General Public License for more details.
5363 + * You should have received a copy of the GNU General Public License
5364 + * along with this program; if not, write to the Free Software
5365 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
5369 + * sub-routines for dentry cache
5374 +static void au_dpage_free(struct au_dpage *dpage)
5377 + struct dentry **p;
5379 + p = dpage->dentries;
5380 + for (i = 0; i < dpage->ndentry; i++)
5382 + free_page((unsigned long)dpage->dentries);
5385 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
5391 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
5392 + if (unlikely(!dpages->dpages))
5395 + p = (void *)__get_free_page(gfp);
5399 + dpages->dpages[0].ndentry = 0;
5400 + dpages->dpages[0].dentries = p;
5401 + dpages->ndpage = 1;
5402 + return 0; /* success */
5405 + kfree(dpages->dpages);
5410 +void au_dpages_free(struct au_dcsub_pages *dpages)
5413 + struct au_dpage *p;
5415 + p = dpages->dpages;
5416 + for (i = 0; i < dpages->ndpage; i++)
5417 + au_dpage_free(p++);
5418 + kfree(dpages->dpages);
5421 +static int au_dpages_append(struct au_dcsub_pages *dpages,
5422 + struct dentry *dentry, gfp_t gfp)
5425 + struct au_dpage *dpage;
5428 + dpage = dpages->dpages + dpages->ndpage - 1;
5429 + sz = PAGE_SIZE / sizeof(dentry);
5430 + if (unlikely(dpage->ndentry >= sz)) {
5431 + AuLabel(new dpage);
5433 + sz = dpages->ndpage * sizeof(*dpages->dpages);
5434 + p = au_kzrealloc(dpages->dpages, sz,
5435 + sz + sizeof(*dpages->dpages), gfp);
5439 + dpages->dpages = p;
5440 + dpage = dpages->dpages + dpages->ndpage;
5441 + p = (void *)__get_free_page(gfp);
5445 + dpage->ndentry = 0;
5446 + dpage->dentries = p;
5450 + AuDebugOn(!d_count(dentry));
5451 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
5452 + return 0; /* success */
5458 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
5459 + au_dpages_test test, void *arg)
5462 + struct dentry *this_parent;
5463 + struct list_head *next;
5464 + struct super_block *sb = root->d_sb;
5467 + write_seqlock(&rename_lock);
5468 + this_parent = root;
5469 + spin_lock(&this_parent->d_lock);
5471 + next = this_parent->d_subdirs.next;
5473 + if (this_parent->d_sb == sb
5474 + && !IS_ROOT(this_parent)
5475 + && au_di(this_parent)
5476 + && d_count(this_parent)
5477 + && (!test || test(this_parent, arg))) {
5478 + err = au_dpages_append(dpages, this_parent, GFP_ATOMIC);
5479 + if (unlikely(err))
5483 + while (next != &this_parent->d_subdirs) {
5484 + struct list_head *tmp = next;
5485 + struct dentry *dentry = list_entry(tmp, struct dentry,
5489 + spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED);
5490 + if (d_count(dentry)) {
5491 + if (!list_empty(&dentry->d_subdirs)) {
5492 + spin_unlock(&this_parent->d_lock);
5493 + spin_release(&dentry->d_lock.dep_map, 1,
5495 + this_parent = dentry;
5496 + spin_acquire(&this_parent->d_lock.dep_map, 0, 1,
5500 + if (dentry->d_sb == sb
5502 + && (!test || test(dentry, arg)))
5503 + err = au_dpages_append(dpages, dentry,
5506 + spin_unlock(&dentry->d_lock);
5507 + if (unlikely(err))
5511 + if (this_parent != root) {
5512 + struct dentry *tmp;
5513 + struct dentry *child;
5515 + tmp = this_parent->d_parent;
5517 + spin_unlock(&this_parent->d_lock);
5518 + child = this_parent;
5519 + this_parent = tmp;
5520 + spin_lock(&this_parent->d_lock);
5521 + rcu_read_unlock();
5522 + next = child->d_u.d_child.next;
5527 + spin_unlock(&this_parent->d_lock);
5528 + write_sequnlock(&rename_lock);
5532 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
5533 + int do_include, au_dpages_test test, void *arg)
5538 + write_seqlock(&rename_lock);
5539 + spin_lock(&dentry->d_lock);
5541 + && d_count(dentry)
5542 + && (!test || test(dentry, arg)))
5543 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
5544 + spin_unlock(&dentry->d_lock);
5545 + if (unlikely(err))
5549 + * vfsmount_lock is unnecessary since this is a traverse in a single
5552 + while (!IS_ROOT(dentry)) {
5553 + dentry = dentry->d_parent; /* rename_lock is locked */
5554 + spin_lock(&dentry->d_lock);
5555 + if (d_count(dentry)
5556 + && (!test || test(dentry, arg)))
5557 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
5558 + spin_unlock(&dentry->d_lock);
5559 + if (unlikely(err))
5564 + write_sequnlock(&rename_lock);
5568 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
5570 + return au_di(dentry) && dentry->d_sb == arg;
5573 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
5574 + struct dentry *dentry, int do_include)
5576 + return au_dcsub_pages_rev(dpages, dentry, do_include,
5577 + au_dcsub_dpages_aufs, dentry->d_sb);
5580 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
5582 + struct path path[2] = {
5591 + return path_is_under(path + 0, path + 1);
5593 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
5594 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
5595 +++ linux/fs/aufs/dcsub.h 2013-07-06 13:20:47.740198107 +0200
5598 + * Copyright (C) 2005-2013 Junjiro R. Okajima
5600 + * This program, aufs is free software; you can redistribute it and/or modify
5601 + * it under the terms of the GNU General Public License as published by
5602 + * the Free Software Foundation; either version 2 of the License, or
5603 + * (at your option) any later version.
5605 + * This program is distributed in the hope that it will be useful,
5606 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5607 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5608 + * GNU General Public License for more details.
5610 + * You should have received a copy of the GNU General Public License
5611 + * along with this program; if not, write to the Free Software
5612 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
5616 + * sub-routines for dentry cache
5619 +#ifndef __AUFS_DCSUB_H__
5620 +#define __AUFS_DCSUB_H__
5624 +#include <linux/dcache.h>
5625 +#include <linux/fs.h>
5631 + struct dentry **dentries;
5634 +struct au_dcsub_pages {
5636 + struct au_dpage *dpages;
5639 +/* ---------------------------------------------------------------------- */
5642 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
5643 +void au_dpages_free(struct au_dcsub_pages *dpages);
5644 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
5645 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
5646 + au_dpages_test test, void *arg);
5647 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
5648 + int do_include, au_dpages_test test, void *arg);
5649 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
5650 + struct dentry *dentry, int do_include);
5651 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
5653 +/* ---------------------------------------------------------------------- */
5655 +static inline int au_d_hashed_positive(struct dentry *d)
5658 + struct inode *inode = d->d_inode;
5660 + if (unlikely(d_unhashed(d) || !inode || !inode->i_nlink))
5665 +static inline int au_d_alive(struct dentry *d)
5668 + struct inode *inode;
5671 + err = au_d_hashed_positive(d);
5673 + inode = d->d_inode;
5674 + if (unlikely(d_unlinked(d) || !inode || !inode->i_nlink))
5680 +static inline int au_alive_dir(struct dentry *d)
5683 + err = au_d_alive(d);
5684 + if (unlikely(err || IS_DEADDIR(d->d_inode)))
5689 +#endif /* __KERNEL__ */
5690 +#endif /* __AUFS_DCSUB_H__ */
5691 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
5692 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
5693 +++ linux/fs/aufs/debug.c 2013-10-26 16:51:32.273040419 +0200
5696 + * Copyright (C) 2005-2013 Junjiro R. Okajima
5698 + * This program, aufs is free software; you can redistribute it and/or modify
5699 + * it under the terms of the GNU General Public License as published by
5700 + * the Free Software Foundation; either version 2 of the License, or
5701 + * (at your option) any later version.
5703 + * This program is distributed in the hope that it will be useful,
5704 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5705 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5706 + * GNU General Public License for more details.
5708 + * You should have received a copy of the GNU General Public License
5709 + * along with this program; if not, write to the Free Software
5710 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
5714 + * debug print functions
5717 +#include <linux/vt_kern.h>
5720 +/* Returns 0, or -errno. arg is in kp->arg. */
5721 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
5725 + err = kstrtoint(val, 0, &n);
5735 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
5736 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
5741 + return sprintf(buffer, "%d", atomic_read(a));
5744 +static struct kernel_param_ops param_ops_atomic_t = {
5745 + .set = param_atomic_t_set,
5746 + .get = param_atomic_t_get
5747 + /* void (*free)(void *arg) */
5750 +atomic_t aufs_debug = ATOMIC_INIT(0);
5751 +MODULE_PARM_DESC(debug, "debug print");
5752 +module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP);
5754 +char *au_plevel = KERN_DEBUG;
5755 +#define dpri(fmt, ...) do { \
5757 + && strcmp(au_plevel, KERN_DEBUG)) \
5758 + || au_debug_test()) \
5759 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
5762 +/* ---------------------------------------------------------------------- */
5764 +void au_dpri_whlist(struct au_nhash *whlist)
5766 + unsigned long ul, n;
5767 + struct hlist_head *head;
5768 + struct au_vdir_wh *pos;
5770 + n = whlist->nh_num;
5771 + head = whlist->nh_head;
5772 + for (ul = 0; ul < n; ul++) {
5773 + hlist_for_each_entry(pos, head, wh_hash)
5774 + dpri("b%d, %.*s, %d\n",
5776 + pos->wh_str.len, pos->wh_str.name,
5782 +void au_dpri_vdir(struct au_vdir *vdir)
5785 + union au_vdir_deblk_p p;
5788 + if (!vdir || IS_ERR(vdir)) {
5789 + dpri("err %ld\n", PTR_ERR(vdir));
5793 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n",
5794 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
5795 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
5796 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
5797 + p.deblk = vdir->vd_deblk[ul];
5799 + dpri("[%lu]: %p\n", ul, o);
5803 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
5804 + struct dentry *wh)
5809 + if (!inode || IS_ERR(inode)) {
5810 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
5814 + /* the type of i_blocks depends upon CONFIG_LBDAF */
5815 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
5816 + && sizeof(inode->i_blocks) != sizeof(u64));
5818 + n = (void *)wh->d_name.name;
5819 + l = wh->d_name.len;
5822 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
5823 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
5825 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
5826 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
5827 + i_size_read(inode), (unsigned long long)inode->i_blocks,
5828 + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
5829 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
5830 + inode->i_state, inode->i_flags, inode->i_version,
5831 + inode->i_generation,
5832 + l ? ", wh " : "", l, n);
5836 +void au_dpri_inode(struct inode *inode)
5838 + struct au_iinfo *iinfo;
5839 + aufs_bindex_t bindex;
5842 + err = do_pri_inode(-1, inode, -1, NULL);
5843 + if (err || !au_test_aufs(inode->i_sb))
5846 + iinfo = au_ii(inode);
5849 + dpri("i-1: bstart %d, bend %d, gen %d\n",
5850 + iinfo->ii_bstart, iinfo->ii_bend, au_iigen(inode, NULL));
5851 + if (iinfo->ii_bstart < 0)
5854 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend; bindex++) {
5855 + hn = !!au_hn(iinfo->ii_hinode + bindex);
5856 + do_pri_inode(bindex, iinfo->ii_hinode[0 + bindex].hi_inode, hn,
5857 + iinfo->ii_hinode[0 + bindex].hi_whdentry);
5861 +void au_dpri_dalias(struct inode *inode)
5865 + spin_lock(&inode->i_lock);
5866 + hlist_for_each_entry(d, &inode->i_dentry, d_alias)
5867 + au_dpri_dentry(d);
5868 + spin_unlock(&inode->i_lock);
5871 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
5873 + struct dentry *wh = NULL;
5876 + if (!dentry || IS_ERR(dentry)) {
5877 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
5880 + /* do not call dget_parent() here */
5881 + /* note: access d_xxx without d_lock */
5882 + dpri("d%d: %.*s?/%.*s, %s, cnt %d, flags 0x%x\n",
5884 + AuDLNPair(dentry->d_parent), AuDLNPair(dentry),
5885 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
5886 + d_count(dentry), dentry->d_flags);
5888 + if (bindex >= 0 && dentry->d_inode && au_test_aufs(dentry->d_sb)) {
5889 + struct au_iinfo *iinfo = au_ii(dentry->d_inode);
5891 + hn = !!au_hn(iinfo->ii_hinode + bindex);
5892 + wh = iinfo->ii_hinode[0 + bindex].hi_whdentry;
5895 + do_pri_inode(bindex, dentry->d_inode, hn, wh);
5899 +void au_dpri_dentry(struct dentry *dentry)
5901 + struct au_dinfo *dinfo;
5902 + aufs_bindex_t bindex;
5904 + struct au_hdentry *hdp;
5906 + err = do_pri_dentry(-1, dentry);
5907 + if (err || !au_test_aufs(dentry->d_sb))
5910 + dinfo = au_di(dentry);
5913 + dpri("d-1: bstart %d, bend %d, bwh %d, bdiropq %d, gen %d\n",
5914 + dinfo->di_bstart, dinfo->di_bend,
5915 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry));
5916 + if (dinfo->di_bstart < 0)
5918 + hdp = dinfo->di_hdentry;
5919 + for (bindex = dinfo->di_bstart; bindex <= dinfo->di_bend; bindex++)
5920 + do_pri_dentry(bindex, hdp[0 + bindex].hd_dentry);
5923 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
5927 + if (!file || IS_ERR(file)) {
5928 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
5934 + && au_test_aufs(file->f_dentry->d_sb)
5936 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
5937 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
5938 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
5939 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
5940 + file->f_version, file->f_pos, a);
5941 + if (file->f_dentry)
5942 + do_pri_dentry(bindex, file->f_dentry);
5946 +void au_dpri_file(struct file *file)
5948 + struct au_finfo *finfo;
5949 + struct au_fidir *fidir;
5950 + struct au_hfile *hfile;
5951 + aufs_bindex_t bindex;
5954 + err = do_pri_file(-1, file);
5955 + if (err || !file->f_dentry || !au_test_aufs(file->f_dentry->d_sb))
5958 + finfo = au_fi(file);
5961 + if (finfo->fi_btop < 0)
5963 + fidir = finfo->fi_hdir;
5965 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
5967 + for (bindex = finfo->fi_btop;
5968 + bindex >= 0 && bindex <= fidir->fd_bbot;
5970 + hfile = fidir->fd_hfile + bindex;
5971 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
5975 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
5977 + struct vfsmount *mnt;
5978 + struct super_block *sb;
5980 + if (!br || IS_ERR(br))
5982 + mnt = au_br_mnt(br);
5983 + if (!mnt || IS_ERR(mnt))
5986 + if (!sb || IS_ERR(sb))
5989 + dpri("s%d: {perm 0x%x, id %d, cnt %d, wbr %p}, "
5990 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
5992 + bindex, br->br_perm, br->br_id, atomic_read(&br->br_count),
5993 + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
5994 + sb->s_flags, sb->s_count,
5995 + atomic_read(&sb->s_active), !!br->br_xino.xi_file);
5999 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
6003 +void au_dpri_sb(struct super_block *sb)
6005 + struct au_sbinfo *sbinfo;
6006 + aufs_bindex_t bindex;
6008 + /* to reuduce stack size */
6010 + struct vfsmount mnt;
6011 + struct au_branch fake;
6014 + /* this function can be called from magic sysrq */
6015 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
6016 + if (unlikely(!a)) {
6017 + dpri("no memory\n");
6021 + a->mnt.mnt_sb = sb;
6022 + a->fake.br_perm = 0;
6023 + a->fake.br_path.mnt = &a->mnt;
6024 + a->fake.br_xino.xi_file = NULL;
6025 + atomic_set(&a->fake.br_count, 0);
6026 + smp_mb(); /* atomic_set */
6027 + err = do_pri_br(-1, &a->fake);
6029 + dpri("dev 0x%x\n", sb->s_dev);
6030 + if (err || !au_test_aufs(sb))
6033 + sbinfo = au_sbi(sb);
6036 + dpri("nw %d, gen %u, kobj %d\n",
6037 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
6038 + atomic_read(&sbinfo->si_kobj.kref.refcount));
6039 + for (bindex = 0; bindex <= sbinfo->si_bend; bindex++)
6040 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
6043 +/* ---------------------------------------------------------------------- */
6045 +void au_dbg_sleep_jiffy(int jiffy)
6048 + jiffy = schedule_timeout_uninterruptible(jiffy);
6051 +void au_dbg_iattr(struct iattr *ia)
6053 +#define AuBit(name) \
6055 + if (ia->ia_valid & ATTR_ ## name) \
6056 + dpri(#name "\n"); \
6076 + dpri("ia_file %p\n", ia->ia_file);
6079 +/* ---------------------------------------------------------------------- */
6081 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
6083 + struct inode *h_inode, *inode = dentry->d_inode;
6084 + struct dentry *h_dentry;
6085 + aufs_bindex_t bindex, bend, bi;
6087 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
6090 + bend = au_dbend(dentry);
6091 + bi = au_ibend(inode);
6094 + bindex = au_dbstart(dentry);
6095 + bi = au_ibstart(inode);
6099 + for (; bindex <= bend; bindex++) {
6100 + h_dentry = au_h_dptr(dentry, bindex);
6103 + h_inode = au_h_iptr(inode, bindex);
6104 + if (unlikely(h_inode != h_dentry->d_inode)) {
6106 + AuDbg("b%d, %s:%d\n", bindex, func, line);
6107 + AuDbgDentry(dentry);
6108 + AuDbgInode(inode);
6115 +void au_dbg_verify_dir_parent(struct dentry *dentry, unsigned int sigen)
6117 + struct dentry *parent;
6119 + parent = dget_parent(dentry);
6120 + AuDebugOn(!S_ISDIR(dentry->d_inode->i_mode));
6121 + AuDebugOn(IS_ROOT(dentry));
6122 + AuDebugOn(au_digen_test(parent, sigen));
6126 +void au_dbg_verify_nondir_parent(struct dentry *dentry, unsigned int sigen)
6128 + struct dentry *parent;
6129 + struct inode *inode;
6131 + parent = dget_parent(dentry);
6132 + inode = dentry->d_inode;
6133 + AuDebugOn(inode && S_ISDIR(dentry->d_inode->i_mode));
6134 + AuDebugOn(au_digen_test(parent, sigen));
6138 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
6141 + struct au_dcsub_pages dpages;
6142 + struct au_dpage *dpage;
6143 + struct dentry **dentries;
6145 + err = au_dpages_init(&dpages, GFP_NOFS);
6147 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
6149 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
6150 + dpage = dpages.dpages + i;
6151 + dentries = dpage->dentries;
6152 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
6153 + AuDebugOn(au_digen_test(dentries[j], sigen));
6155 + au_dpages_free(&dpages);
6158 +void au_dbg_verify_kthread(void)
6160 + if (au_wkq_test()) {
6163 + * It may be recursive, but udba=notify between two aufs mounts,
6164 + * where a single ro branch is shared, is not a problem.
6170 +/* ---------------------------------------------------------------------- */
6172 +void au_debug_sbinfo_init(struct au_sbinfo *sbinfo __maybe_unused)
6174 +#ifdef AuForceNoPlink
6175 + au_opt_clr(sbinfo->si_mntflags, PLINK);
6177 +#ifdef AuForceNoXino
6178 + au_opt_clr(sbinfo->si_mntflags, XINO);
6180 +#ifdef AuForceNoRefrof
6181 + au_opt_clr(sbinfo->si_mntflags, REFROF);
6183 +#ifdef AuForceHnotify
6184 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_HNOTIFY);
6187 + sbinfo->si_rdblk = 0;
6188 + sbinfo->si_rdhash = 0;
6192 +int __init au_debug_init(void)
6194 + aufs_bindex_t bindex;
6195 + struct au_vdir_destr destr;
6198 + AuDebugOn(bindex >= 0);
6201 + AuDebugOn(destr.len < NAME_MAX);
6203 +#ifdef CONFIG_4KSTACKS
6204 + pr_warn("CONFIG_4KSTACKS is defined.\n");
6207 +#ifdef AuForceNoBrs
6213 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
6214 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
6215 +++ linux/fs/aufs/debug.h 2013-10-26 16:51:32.273040419 +0200
6218 + * Copyright (C) 2005-2013 Junjiro R. Okajima
6220 + * This program, aufs is free software; you can redistribute it and/or modify
6221 + * it under the terms of the GNU General Public License as published by
6222 + * the Free Software Foundation; either version 2 of the License, or
6223 + * (at your option) any later version.
6225 + * This program is distributed in the hope that it will be useful,
6226 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6227 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6228 + * GNU General Public License for more details.
6230 + * You should have received a copy of the GNU General Public License
6231 + * along with this program; if not, write to the Free Software
6232 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
6236 + * debug print functions
6239 +#ifndef __AUFS_DEBUG_H__
6240 +#define __AUFS_DEBUG_H__
6244 +#include <linux/atomic.h>
6245 +#include <linux/module.h>
6246 +#include <linux/kallsyms.h>
6247 +#include <linux/sysrq.h>
6249 +#ifdef CONFIG_AUFS_DEBUG
6250 +#define AuDebugOn(a) BUG_ON(a)
6252 +/* module parameter */
6253 +extern atomic_t aufs_debug;
6254 +static inline void au_debug_on(void)
6256 + atomic_inc(&aufs_debug);
6258 +static inline void au_debug_off(void)
6260 + atomic_dec_if_positive(&aufs_debug);
6263 +static inline int au_debug_test(void)
6265 + return atomic_read(&aufs_debug) > 0;
6268 +#define AuDebugOn(a) do {} while (0)
6269 +AuStubVoid(au_debug_on, void)
6270 +AuStubVoid(au_debug_off, void)
6271 +AuStubInt0(au_debug_test, void)
6272 +#endif /* CONFIG_AUFS_DEBUG */
6274 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
6276 +/* ---------------------------------------------------------------------- */
6280 +#define AuDbg(fmt, ...) do { \
6281 + if (au_debug_test()) \
6282 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
6284 +#define AuLabel(l) AuDbg(#l "\n")
6285 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
6286 +#define AuWarn1(fmt, ...) do { \
6287 + static unsigned char _c; \
6289 + pr_warn(fmt, ##__VA_ARGS__); \
6292 +#define AuErr1(fmt, ...) do { \
6293 + static unsigned char _c; \
6295 + pr_err(fmt, ##__VA_ARGS__); \
6298 +#define AuIOErr1(fmt, ...) do { \
6299 + static unsigned char _c; \
6301 + AuIOErr(fmt, ##__VA_ARGS__); \
6304 +#define AuUnsupportMsg "This operation is not supported." \
6305 + " Please report this application to aufs-users ML."
6306 +#define AuUnsupport(fmt, ...) do { \
6307 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
6311 +#define AuTraceErr(e) do { \
6312 + if (unlikely((e) < 0)) \
6313 + AuDbg("err %d\n", (int)(e)); \
6316 +#define AuTraceErrPtr(p) do { \
6318 + AuDbg("err %ld\n", PTR_ERR(p)); \
6321 +/* dirty macros for debug print, use with "%.*s" and caution */
6322 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
6323 +#define AuDLNPair(d) AuLNPair(&(d)->d_name)
6325 +/* ---------------------------------------------------------------------- */
6330 +#ifdef CONFIG_AUFS_DEBUG
6331 +extern char *au_plevel;
6333 +void au_dpri_whlist(struct au_nhash *whlist);
6335 +void au_dpri_vdir(struct au_vdir *vdir);
6337 +void au_dpri_inode(struct inode *inode);
6338 +void au_dpri_dalias(struct inode *inode);
6339 +void au_dpri_dentry(struct dentry *dentry);
6341 +void au_dpri_file(struct file *filp);
6342 +struct super_block;
6343 +void au_dpri_sb(struct super_block *sb);
6345 +void au_dbg_sleep_jiffy(int jiffy);
6347 +void au_dbg_iattr(struct iattr *ia);
6349 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
6350 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
6351 +void au_dbg_verify_dir_parent(struct dentry *dentry, unsigned int sigen);
6352 +void au_dbg_verify_nondir_parent(struct dentry *dentry, unsigned int sigen);
6353 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
6354 +void au_dbg_verify_kthread(void);
6356 +int __init au_debug_init(void);
6357 +void au_debug_sbinfo_init(struct au_sbinfo *sbinfo);
6358 +#define AuDbgWhlist(w) do { \
6360 + au_dpri_whlist(w); \
6363 +#define AuDbgVdir(v) do { \
6365 + au_dpri_vdir(v); \
6368 +#define AuDbgInode(i) do { \
6370 + au_dpri_inode(i); \
6373 +#define AuDbgDAlias(i) do { \
6375 + au_dpri_dalias(i); \
6378 +#define AuDbgDentry(d) do { \
6380 + au_dpri_dentry(d); \
6383 +#define AuDbgFile(f) do { \
6385 + au_dpri_file(f); \
6388 +#define AuDbgSb(sb) do { \
6389 + AuDbg(#sb "\n"); \
6393 +#define AuDbgSleep(sec) do { \
6394 + AuDbg("sleep %d sec\n", sec); \
6398 +#define AuDbgSleepJiffy(jiffy) do { \
6399 + AuDbg("sleep %d jiffies\n", jiffy); \
6400 + au_dbg_sleep_jiffy(jiffy); \
6403 +#define AuDbgIAttr(ia) do { \
6404 + AuDbg("ia_valid 0x%x\n", (ia)->ia_valid); \
6405 + au_dbg_iattr(ia); \
6408 +#define AuDbgSym(addr) do { \
6409 + char sym[KSYM_SYMBOL_LEN]; \
6410 + sprint_symbol(sym, (unsigned long)addr); \
6411 + AuDbg("%s\n", sym); \
6414 +#define AuInfoSym(addr) do { \
6415 + char sym[KSYM_SYMBOL_LEN]; \
6416 + sprint_symbol(sym, (unsigned long)addr); \
6417 + AuInfo("%s\n", sym); \
6420 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
6421 +AuStubVoid(au_dbg_verify_dir_parent, struct dentry *dentry, unsigned int sigen)
6422 +AuStubVoid(au_dbg_verify_nondir_parent, struct dentry *dentry,
6423 + unsigned int sigen)
6424 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
6425 +AuStubVoid(au_dbg_verify_kthread, void)
6426 +AuStubInt0(__init au_debug_init, void)
6427 +AuStubVoid(au_debug_sbinfo_init, struct au_sbinfo *sbinfo)
6429 +#define AuDbgWhlist(w) do {} while (0)
6430 +#define AuDbgVdir(v) do {} while (0)
6431 +#define AuDbgInode(i) do {} while (0)
6432 +#define AuDbgDAlias(i) do {} while (0)
6433 +#define AuDbgDentry(d) do {} while (0)
6434 +#define AuDbgFile(f) do {} while (0)
6435 +#define AuDbgSb(sb) do {} while (0)
6436 +#define AuDbgSleep(sec) do {} while (0)
6437 +#define AuDbgSleepJiffy(jiffy) do {} while (0)
6438 +#define AuDbgIAttr(ia) do {} while (0)
6439 +#define AuDbgSym(addr) do {} while (0)
6440 +#define AuInfoSym(addr) do {} while (0)
6441 +#endif /* CONFIG_AUFS_DEBUG */
6443 +/* ---------------------------------------------------------------------- */
6445 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
6446 +int __init au_sysrq_init(void);
6447 +void au_sysrq_fin(void);
6449 +#ifdef CONFIG_HW_CONSOLE
6450 +#define au_dbg_blocked() do { \
6452 + handle_sysrq('w'); \
6455 +AuStubVoid(au_dbg_blocked, void)
6459 +AuStubInt0(__init au_sysrq_init, void)
6460 +AuStubVoid(au_sysrq_fin, void)
6461 +AuStubVoid(au_dbg_blocked, void)
6462 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
6464 +#endif /* __KERNEL__ */
6465 +#endif /* __AUFS_DEBUG_H__ */
6466 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
6467 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
6468 +++ linux/fs/aufs/dentry.c 2013-07-06 13:20:47.740198107 +0200
6471 + * Copyright (C) 2005-2013 Junjiro R. Okajima
6473 + * This program, aufs is free software; you can redistribute it and/or modify
6474 + * it under the terms of the GNU General Public License as published by
6475 + * the Free Software Foundation; either version 2 of the License, or
6476 + * (at your option) any later version.
6478 + * This program is distributed in the hope that it will be useful,
6479 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6480 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6481 + * GNU General Public License for more details.
6483 + * You should have received a copy of the GNU General Public License
6484 + * along with this program; if not, write to the Free Software
6485 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
6489 + * lookup and dentry operations
6492 +#include <linux/namei.h>
6495 +#define AuLkup_ALLOW_NEG 1
6496 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
6497 +#define au_fset_lkup(flags, name) \
6498 + do { (flags) |= AuLkup_##name; } while (0)
6499 +#define au_fclr_lkup(flags, name) \
6500 + do { (flags) &= ~AuLkup_##name; } while (0)
6502 +struct au_do_lookup_args {
6503 + unsigned int flags;
6508 + * returns positive/negative dentry, NULL or an error.
6509 + * NULL means whiteout-ed or not-found.
6511 +static struct dentry*
6512 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
6513 + aufs_bindex_t bindex, struct qstr *wh_name,
6514 + struct au_do_lookup_args *args)
6516 + struct dentry *h_dentry;
6517 + struct inode *h_inode, *inode;
6518 + struct au_branch *br;
6519 + int wh_found, opq;
6520 + unsigned char wh_able;
6521 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
6524 + br = au_sbr(dentry->d_sb, bindex);
6525 + wh_able = !!au_br_whable(br->br_perm);
6527 + wh_found = au_wh_test(h_parent, wh_name, br, /*try_sio*/0);
6528 + h_dentry = ERR_PTR(wh_found);
6531 + if (unlikely(wh_found < 0))
6534 + /* We found a whiteout */
6535 + /* au_set_dbend(dentry, bindex); */
6536 + au_set_dbwh(dentry, bindex);
6538 + return NULL; /* success */
6541 + h_dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
6542 + if (IS_ERR(h_dentry))
6545 + h_inode = h_dentry->d_inode;
6549 + } else if (wh_found
6550 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
6553 + if (au_dbend(dentry) <= bindex)
6554 + au_set_dbend(dentry, bindex);
6555 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
6556 + au_set_dbstart(dentry, bindex);
6557 + au_set_h_dptr(dentry, bindex, h_dentry);
6559 + inode = dentry->d_inode;
6560 + if (!h_inode || !S_ISDIR(h_inode->i_mode) || !wh_able
6561 + || (inode && !S_ISDIR(inode->i_mode)))
6562 + goto out; /* success */
6564 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
6565 + opq = au_diropq_test(h_dentry, br);
6566 + mutex_unlock(&h_inode->i_mutex);
6568 + au_set_dbdiropq(dentry, bindex);
6569 + else if (unlikely(opq < 0)) {
6570 + au_set_h_dptr(dentry, bindex, NULL);
6571 + h_dentry = ERR_PTR(opq);
6582 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
6584 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
6585 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
6591 + * returns the number of lower positive dentries,
6592 + * otherwise an error.
6593 + * can be called at unlinking with @type is zero.
6595 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type)
6597 + int npositive, err;
6598 + aufs_bindex_t bindex, btail, bdiropq;
6599 + unsigned char isdir;
6600 + struct qstr whname;
6601 + struct au_do_lookup_args args = {
6605 + const struct qstr *name = &dentry->d_name;
6606 + struct dentry *parent;
6607 + struct inode *inode;
6609 + err = au_test_shwh(dentry->d_sb, name);
6610 + if (unlikely(err))
6613 + err = au_wh_name_alloc(&whname, name);
6614 + if (unlikely(err))
6617 + inode = dentry->d_inode;
6618 + isdir = !!(inode && S_ISDIR(inode->i_mode));
6620 + au_fset_lkup(args.flags, ALLOW_NEG);
6623 + parent = dget_parent(dentry);
6624 + btail = au_dbtaildir(parent);
6625 + for (bindex = bstart; bindex <= btail; bindex++) {
6626 + struct dentry *h_parent, *h_dentry;
6627 + struct inode *h_inode, *h_dir;
6629 + h_dentry = au_h_dptr(dentry, bindex);
6631 + if (h_dentry->d_inode)
6633 + if (type != S_IFDIR)
6637 + h_parent = au_h_dptr(parent, bindex);
6640 + h_dir = h_parent->d_inode;
6641 + if (!h_dir || !S_ISDIR(h_dir->i_mode))
6644 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
6645 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname,
6647 + mutex_unlock(&h_dir->i_mutex);
6648 + err = PTR_ERR(h_dentry);
6649 + if (IS_ERR(h_dentry))
6651 + au_fclr_lkup(args.flags, ALLOW_NEG);
6653 + if (au_dbwh(dentry) >= 0)
6657 + h_inode = h_dentry->d_inode;
6662 + args.type = h_inode->i_mode & S_IFMT;
6663 + if (args.type != S_IFDIR)
6666 + /* the type of lower may be different */
6667 + bdiropq = au_dbdiropq(dentry);
6668 + if (bdiropq >= 0 && bdiropq <= bindex)
6674 + AuLabel(positive);
6675 + au_update_dbstart(dentry);
6678 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
6679 + && au_dbstart(dentry) < 0)) {
6681 + AuIOErr("both of real entry and whiteout found, %.*s, err %d\n",
6682 + AuDLNPair(dentry), err);
6687 + kfree(whname.name);
6692 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent,
6693 + struct au_branch *br)
6695 + struct dentry *dentry;
6698 + if (!au_test_h_perm_sio(parent->d_inode, MAY_EXEC))
6699 + dentry = vfsub_lkup_one(name, parent);
6701 + struct vfsub_lkup_one_args args = {
6707 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
6708 + if (unlikely(wkq_err))
6709 + dentry = ERR_PTR(wkq_err);
6716 + * lookup @dentry on @bindex which should be negative.
6718 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
6721 + struct dentry *parent, *h_parent, *h_dentry;
6722 + struct au_branch *br;
6724 + parent = dget_parent(dentry);
6725 + h_parent = au_h_dptr(parent, bindex);
6726 + br = au_sbr(dentry->d_sb, bindex);
6728 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
6730 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent, br);
6731 + err = PTR_ERR(h_dentry);
6732 + if (IS_ERR(h_dentry))
6734 + if (unlikely(h_dentry->d_inode)) {
6736 + AuIOErr("%.*s should be negative on b%d.\n",
6737 + AuDLNPair(h_dentry), bindex);
6743 + if (bindex < au_dbstart(dentry))
6744 + au_set_dbstart(dentry, bindex);
6745 + if (au_dbend(dentry) < bindex)
6746 + au_set_dbend(dentry, bindex);
6747 + au_set_h_dptr(dentry, bindex, h_dentry);
6754 +/* ---------------------------------------------------------------------- */
6756 +/* subset of struct inode */
6758 + unsigned long i_ino;
6759 + /* unsigned int i_nlink; */
6765 + blkcnt_t i_blocks;
6770 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
6772 + ia->i_ino = h_inode->i_ino;
6773 + /* ia->i_nlink = h_inode->i_nlink; */
6774 + ia->i_uid = h_inode->i_uid;
6775 + ia->i_gid = h_inode->i_gid;
6776 + ia->i_version = h_inode->i_version;
6778 + ia->i_size = h_inode->i_size;
6779 + ia->i_blocks = h_inode->i_blocks;
6781 + ia->i_mode = (h_inode->i_mode & S_IFMT);
6784 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
6786 + return ia->i_ino != h_inode->i_ino
6787 + /* || ia->i_nlink != h_inode->i_nlink */
6788 + || !uid_eq(ia->i_uid, h_inode->i_uid)
6789 + || !gid_eq(ia->i_gid, h_inode->i_gid)
6790 + || ia->i_version != h_inode->i_version
6792 + || ia->i_size != h_inode->i_size
6793 + || ia->i_blocks != h_inode->i_blocks
6795 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
6798 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
6799 + struct au_branch *br)
6802 + struct au_iattr ia;
6803 + struct inode *h_inode;
6804 + struct dentry *h_d;
6805 + struct super_block *h_sb;
6808 + memset(&ia, -1, sizeof(ia));
6809 + h_sb = h_dentry->d_sb;
6810 + h_inode = h_dentry->d_inode;
6812 + au_iattr_save(&ia, h_inode);
6813 + else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
6814 + /* nfs d_revalidate may return 0 for negative dentry */
6815 + /* fuse d_revalidate always return 0 for negative dentry */
6818 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
6819 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
6820 + err = PTR_ERR(h_d);
6825 + if (unlikely(h_d != h_dentry
6826 + || h_d->d_inode != h_inode
6827 + || (h_inode && au_iattr_test(&ia, h_inode))))
6828 + err = au_busy_or_stale();
6836 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
6837 + struct dentry *h_parent, struct au_branch *br)
6842 + if (udba == AuOpt_UDBA_REVAL
6843 + && !au_test_fs_remote(h_dentry->d_sb)) {
6845 + err = (h_dentry->d_parent->d_inode != h_dir);
6846 + } else if (udba != AuOpt_UDBA_NONE)
6847 + err = au_h_verify_dentry(h_dentry, h_parent, br);
6852 +/* ---------------------------------------------------------------------- */
6854 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
6857 + aufs_bindex_t new_bindex, bindex, bend, bwh, bdiropq;
6858 + struct au_hdentry tmp, *p, *q;
6859 + struct au_dinfo *dinfo;
6860 + struct super_block *sb;
6862 + DiMustWriteLock(dentry);
6864 + sb = dentry->d_sb;
6865 + dinfo = au_di(dentry);
6866 + bend = dinfo->di_bend;
6867 + bwh = dinfo->di_bwh;
6868 + bdiropq = dinfo->di_bdiropq;
6869 + p = dinfo->di_hdentry + dinfo->di_bstart;
6870 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++, p++) {
6871 + if (!p->hd_dentry)
6874 + new_bindex = au_br_index(sb, p->hd_id);
6875 + if (new_bindex == bindex)
6878 + if (dinfo->di_bwh == bindex)
6880 + if (dinfo->di_bdiropq == bindex)
6881 + bdiropq = new_bindex;
6882 + if (new_bindex < 0) {
6884 + p->hd_dentry = NULL;
6888 + /* swap two lower dentries, and loop again */
6889 + q = dinfo->di_hdentry + new_bindex;
6893 + if (tmp.hd_dentry) {
6899 + dinfo->di_bwh = -1;
6900 + if (bwh >= 0 && bwh <= au_sbend(sb) && au_sbr_whable(sb, bwh))
6901 + dinfo->di_bwh = bwh;
6903 + dinfo->di_bdiropq = -1;
6905 + && bdiropq <= au_sbend(sb)
6906 + && au_sbr_whable(sb, bdiropq))
6907 + dinfo->di_bdiropq = bdiropq;
6910 + dinfo->di_bstart = -1;
6911 + dinfo->di_bend = -1;
6912 + bend = au_dbend(parent);
6913 + p = dinfo->di_hdentry;
6914 + for (bindex = 0; bindex <= bend; bindex++, p++)
6915 + if (p->hd_dentry) {
6916 + dinfo->di_bstart = bindex;
6920 + if (dinfo->di_bstart >= 0) {
6921 + p = dinfo->di_hdentry + bend;
6922 + for (bindex = bend; bindex >= 0; bindex--, p--)
6923 + if (p->hd_dentry) {
6924 + dinfo->di_bend = bindex;
6933 +static void au_do_hide(struct dentry *dentry)
6935 + struct inode *inode;
6937 + inode = dentry->d_inode;
6939 + if (!S_ISDIR(inode->i_mode)) {
6940 + if (inode->i_nlink && !d_unhashed(dentry))
6941 + drop_nlink(inode);
6943 + clear_nlink(inode);
6944 + /* stop next lookup */
6945 + inode->i_flags |= S_DEAD;
6947 + smp_mb(); /* necessary? */
6952 +static int au_hide_children(struct dentry *parent)
6954 + int err, i, j, ndentry;
6955 + struct au_dcsub_pages dpages;
6956 + struct au_dpage *dpage;
6957 + struct dentry *dentry;
6959 + err = au_dpages_init(&dpages, GFP_NOFS);
6960 + if (unlikely(err))
6962 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
6963 + if (unlikely(err))
6966 + /* in reverse order */
6967 + for (i = dpages.ndpage - 1; i >= 0; i--) {
6968 + dpage = dpages.dpages + i;
6969 + ndentry = dpage->ndentry;
6970 + for (j = ndentry - 1; j >= 0; j--) {
6971 + dentry = dpage->dentries[j];
6972 + if (dentry != parent)
6973 + au_do_hide(dentry);
6978 + au_dpages_free(&dpages);
6983 +static void au_hide(struct dentry *dentry)
6986 + struct inode *inode;
6988 + AuDbgDentry(dentry);
6989 + inode = dentry->d_inode;
6990 + if (inode && S_ISDIR(inode->i_mode)) {
6991 + /* shrink_dcache_parent(dentry); */
6992 + err = au_hide_children(dentry);
6993 + if (unlikely(err))
6994 + AuIOErr("%.*s, failed hiding children, ignored %d\n",
6995 + AuDLNPair(dentry), err);
6997 + au_do_hide(dentry);
7001 + * By adding a dirty branch, a cached dentry may be affected in various ways.
7003 + * a dirty branch is added
7004 + * - on the top of layers
7005 + * - in the middle of layers
7006 + * - to the bottom of layers
7008 + * on the added branch there exists
7011 + * - a same named entry
7013 + * * negative --> positive
7014 + * * positive --> positive
7015 + * - type is unchanged
7016 + * - type is changed
7018 + * * negative --> negative
7019 + * * positive --> negative (rejected by au_br_del() for non-dir case)
7022 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
7023 + struct au_dinfo *tmp)
7026 + aufs_bindex_t bindex, bend;
7028 + struct dentry *dentry;
7029 + struct inode *inode;
7032 + struct au_hdentry *hd;
7033 + struct inode *inode, *h_inode;
7034 + struct dentry *h_dentry;
7037 + AuDebugOn(dinfo->di_bstart < 0);
7038 + orig_h.dentry = dinfo->di_hdentry[dinfo->di_bstart].hd_dentry;
7039 + orig_h.inode = orig_h.dentry->d_inode;
7042 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
7043 + memset(&tmp_h, 0, sizeof(tmp_h));
7044 + if (tmp->di_bstart >= 0) {
7045 + tmp_h.dentry = tmp->di_hdentry[tmp->di_bstart].hd_dentry;
7046 + tmp_h.inode = tmp_h.dentry->d_inode;
7048 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
7051 + inode = dentry->d_inode;
7052 + if (!orig_h.inode) {
7053 + AuDbg("nagative originally\n");
7059 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
7060 + AuDebugOn(dinfo->di_bdiropq != -1);
7062 + if (!tmp_h.inode) {
7063 + AuDbg("negative --> negative\n");
7064 + /* should have only one negative lower */
7065 + if (tmp->di_bstart >= 0
7066 + && tmp->di_bstart < dinfo->di_bstart) {
7067 + AuDebugOn(tmp->di_bstart != tmp->di_bend);
7068 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
7069 + au_set_h_dptr(dentry, dinfo->di_bstart, NULL);
7070 + au_di_cp(dinfo, tmp);
7071 + hd = tmp->di_hdentry + tmp->di_bstart;
7072 + au_set_h_dptr(dentry, tmp->di_bstart,
7073 + dget(hd->hd_dentry));
7075 + au_dbg_verify_dinode(dentry);
7077 + AuDbg("negative --> positive\n");
7079 + * similar to the behaviour of creating with bypassing
7081 + * unhash it in order to force an error in the
7082 + * succeeding create operation.
7083 + * we should not set S_DEAD here.
7086 + /* au_di_swap(tmp, dinfo); */
7087 + au_dbg_verify_dinode(dentry);
7090 + AuDbg("positive originally\n");
7091 + /* inode may be NULL */
7092 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
7093 + if (!tmp_h.inode) {
7094 + AuDbg("positive --> negative\n");
7095 + /* or bypassing aufs */
7097 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_bstart)
7098 + dinfo->di_bwh = tmp->di_bwh;
7100 + err = au_refresh_hinode_self(inode);
7101 + au_dbg_verify_dinode(dentry);
7102 + } else if (orig_h.mode == tmp_h.mode) {
7103 + AuDbg("positive --> positive, same type\n");
7104 + if (!S_ISDIR(orig_h.mode)
7105 + && dinfo->di_bstart > tmp->di_bstart) {
7107 + * similar to the behaviour of removing and
7112 + err = au_refresh_hinode_self(inode);
7113 + au_dbg_verify_dinode(dentry);
7115 + /* fill empty slots */
7116 + if (dinfo->di_bstart > tmp->di_bstart)
7117 + dinfo->di_bstart = tmp->di_bstart;
7118 + if (dinfo->di_bend < tmp->di_bend)
7119 + dinfo->di_bend = tmp->di_bend;
7120 + dinfo->di_bwh = tmp->di_bwh;
7121 + dinfo->di_bdiropq = tmp->di_bdiropq;
7122 + hd = tmp->di_hdentry;
7123 + bend = dinfo->di_bend;
7124 + for (bindex = tmp->di_bstart; bindex <= bend;
7126 + if (au_h_dptr(dentry, bindex))
7128 + h_dentry = hd[bindex].hd_dentry;
7131 + h_inode = h_dentry->d_inode;
7132 + AuDebugOn(!h_inode);
7133 + AuDebugOn(orig_h.mode
7134 + != (h_inode->i_mode
7136 + au_set_h_dptr(dentry, bindex,
7139 + err = au_refresh_hinode(inode, dentry);
7140 + au_dbg_verify_dinode(dentry);
7143 + AuDbg("positive --> positive, different type\n");
7144 + /* similar to the behaviour of removing and creating */
7147 + err = au_refresh_hinode_self(inode);
7148 + au_dbg_verify_dinode(dentry);
7156 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
7159 + unsigned int sigen;
7160 + struct au_dinfo *dinfo, *tmp;
7161 + struct super_block *sb;
7162 + struct inode *inode;
7164 + DiMustWriteLock(dentry);
7165 + AuDebugOn(IS_ROOT(dentry));
7166 + AuDebugOn(!parent->d_inode);
7168 + sb = dentry->d_sb;
7169 + inode = dentry->d_inode;
7170 + sigen = au_sigen(sb);
7171 + err = au_digen_test(parent, sigen);
7172 + if (unlikely(err))
7175 + dinfo = au_di(dentry);
7176 + err = au_di_realloc(dinfo, au_sbend(sb) + 1);
7177 + if (unlikely(err))
7179 + ebrange = au_dbrange_test(dentry);
7181 + ebrange = au_do_refresh_hdentry(dentry, parent);
7183 + if (d_unhashed(dentry) || ebrange) {
7184 + AuDebugOn(au_dbstart(dentry) < 0 && au_dbend(dentry) >= 0);
7186 + err = au_refresh_hinode_self(inode);
7187 + au_dbg_verify_dinode(dentry);
7189 + goto out_dgen; /* success */
7193 + /* temporary dinfo */
7194 + AuDbgDentry(dentry);
7196 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
7197 + if (unlikely(!tmp))
7199 + au_di_swap(tmp, dinfo);
7200 + /* returns the number of positive dentries */
7202 + * if current working dir is removed, it returns an error.
7203 + * but the dentry is legal.
7205 + err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0);
7206 + AuDbgDentry(dentry);
7207 + au_di_swap(tmp, dinfo);
7208 + if (err == -ENOENT)
7211 + /* compare/refresh by dinfo */
7212 + AuDbgDentry(dentry);
7213 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
7214 + au_dbg_verify_dinode(dentry);
7217 + au_rw_write_unlock(&tmp->di_rwsem);
7219 + if (unlikely(err))
7223 + au_update_digen(dentry);
7225 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
7226 + AuIOErr("failed refreshing %.*s, %d\n",
7227 + AuDLNPair(dentry), err);
7228 + AuDbgDentry(dentry);
7234 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
7235 + struct dentry *dentry, aufs_bindex_t bindex)
7240 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
7243 + AuDbg("b%d\n", bindex);
7245 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
7246 + * due to whiteout and branch permission.
7248 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
7249 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
7250 + /* it may return tri-state */
7251 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
7253 + if (unlikely(valid < 0))
7263 +/* todo: remove this */
7264 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
7265 + unsigned int flags, int do_udba)
7268 + umode_t mode, h_mode;
7269 + aufs_bindex_t bindex, btail, bstart, ibs, ibe;
7270 + unsigned char plus, unhashed, is_root, h_plus;
7271 + struct inode *h_inode, *h_cached_inode;
7272 + struct dentry *h_dentry;
7273 + struct qstr *name, *h_name;
7280 + unhashed = !!d_unhashed(dentry);
7281 + is_root = !!IS_ROOT(dentry);
7282 + name = &dentry->d_name;
7285 + * Theoretically, REVAL test should be unnecessary in case of
7287 + * But {fs,i}notify doesn't fire some necessary events,
7288 + * IN_ATTRIB for atime/nlink/pageio
7289 + * IN_DELETE for NFS dentry
7290 + * Let's do REVAL test too.
7292 + if (do_udba && inode) {
7293 + mode = (inode->i_mode & S_IFMT);
7294 + plus = (inode->i_nlink > 0);
7295 + ibs = au_ibstart(inode);
7296 + ibe = au_ibend(inode);
7299 + bstart = au_dbstart(dentry);
7301 + if (inode && S_ISDIR(inode->i_mode))
7302 + btail = au_dbtaildir(dentry);
7303 + for (bindex = bstart; bindex <= btail; bindex++) {
7304 + h_dentry = au_h_dptr(dentry, bindex);
7308 + AuDbg("b%d, %.*s\n", bindex, AuDLNPair(h_dentry));
7309 + spin_lock(&h_dentry->d_lock);
7310 + h_name = &h_dentry->d_name;
7311 + if (unlikely(do_udba
7313 + && (unhashed != !!d_unhashed(h_dentry)
7314 + || name->len != h_name->len
7315 + || memcmp(name->name, h_name->name, name->len))
7317 + AuDbg("unhash 0x%x 0x%x, %.*s %.*s\n",
7318 + unhashed, d_unhashed(h_dentry),
7319 + AuDLNPair(dentry), AuDLNPair(h_dentry));
7320 + spin_unlock(&h_dentry->d_lock);
7323 + spin_unlock(&h_dentry->d_lock);
7325 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
7326 + if (unlikely(err))
7327 + /* do not goto err, to keep the errno */
7330 + /* todo: plink too? */
7335 + h_inode = h_dentry->d_inode;
7336 + if (unlikely(!!inode != !!h_inode))
7341 + h_cached_inode = h_inode;
7343 + h_mode = (h_inode->i_mode & S_IFMT);
7344 + h_plus = (h_inode->i_nlink > 0);
7346 + if (inode && ibs <= bindex && bindex <= ibe)
7347 + h_cached_inode = au_h_iptr(inode, bindex);
7349 + if (unlikely(plus != h_plus
7351 + || h_cached_inode != h_inode))
7363 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
7364 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
7367 + struct dentry *parent;
7369 + if (!au_digen_test(dentry, sigen))
7372 + parent = dget_parent(dentry);
7373 + di_read_lock_parent(parent, AuLock_IR);
7374 + AuDebugOn(au_digen_test(parent, sigen));
7375 + au_dbg_verify_gen(parent, sigen);
7376 + err = au_refresh_dentry(dentry, parent);
7377 + di_read_unlock(parent, AuLock_IR);
7383 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
7386 + struct dentry *d, *parent;
7387 + struct inode *inode;
7389 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
7390 + return simple_reval_dpath(dentry, sigen);
7392 + /* slow loop, keep it simple and stupid */
7393 + /* cf: au_cpup_dirs() */
7396 + while (au_digen_test(dentry, sigen)) {
7400 + parent = dget_parent(d);
7401 + if (!au_digen_test(parent, sigen))
7406 + inode = d->d_inode;
7408 + di_write_lock_child2(d);
7410 + /* someone might update our dentry while we were sleeping */
7411 + if (au_digen_test(d, sigen)) {
7413 + * todo: consolidate with simple_reval_dpath(),
7414 + * do_refresh() and au_reval_for_attr().
7416 + di_read_lock_parent(parent, AuLock_IR);
7417 + err = au_refresh_dentry(d, parent);
7418 + di_read_unlock(parent, AuLock_IR);
7422 + di_write_unlock(d);
7424 + if (unlikely(err))
7432 + * if valid returns 1, otherwise 0.
7434 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
7437 + unsigned int sigen;
7438 + unsigned char do_udba;
7439 + struct super_block *sb;
7440 + struct inode *inode;
7442 + /* todo: support rcu-walk? */
7443 + if (flags & LOOKUP_RCU)
7447 + if (unlikely(!au_di(dentry)))
7450 + inode = dentry->d_inode;
7451 + if (inode && is_bad_inode(inode))
7455 + sb = dentry->d_sb;
7458 + * i_mutex of parent dir may be held,
7459 + * but we should not return 'invalid' due to busy.
7461 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
7462 + if (unlikely(err)) {
7467 + if (unlikely(au_dbrange_test(dentry))) {
7473 + sigen = au_sigen(sb);
7474 + if (au_digen_test(dentry, sigen)) {
7475 + AuDebugOn(IS_ROOT(dentry));
7476 + err = au_reval_dpath(dentry, sigen);
7477 + if (unlikely(err)) {
7482 + di_downgrade_lock(dentry, AuLock_IR);
7485 + if (inode && (IS_DEADDIR(inode) || !inode->i_nlink))
7488 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
7489 + if (do_udba && inode) {
7490 + aufs_bindex_t bstart = au_ibstart(inode);
7491 + struct inode *h_inode;
7493 + if (bstart >= 0) {
7494 + h_inode = au_h_iptr(inode, bstart);
7495 + if (h_inode && au_test_higen(inode, h_inode))
7500 + err = h_d_revalidate(dentry, inode, flags, do_udba);
7501 + if (unlikely(!err && do_udba && au_dbstart(dentry) < 0)) {
7503 + AuDbg("both of real entry and whiteout found, %.*s, err %d\n",
7504 + AuDLNPair(dentry), err);
7509 + di_downgrade_lock(dentry, AuLock_IR);
7511 + aufs_read_unlock(dentry, AuLock_IR);
7516 + AuDbg("%.*s invalid, %d\n", AuDLNPair(dentry), valid);
7522 +static void aufs_d_release(struct dentry *dentry)
7524 + if (au_di(dentry)) {
7525 + au_di_fin(dentry);
7526 + au_hn_di_reinit(dentry);
7530 +const struct dentry_operations aufs_dop = {
7531 + .d_revalidate = aufs_d_revalidate,
7532 + .d_weak_revalidate = aufs_d_revalidate,
7533 + .d_release = aufs_d_release
7535 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
7536 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
7537 +++ linux/fs/aufs/dentry.h 2013-07-06 13:20:47.740198107 +0200
7540 + * Copyright (C) 2005-2013 Junjiro R. Okajima
7542 + * This program, aufs is free software; you can redistribute it and/or modify
7543 + * it under the terms of the GNU General Public License as published by
7544 + * the Free Software Foundation; either version 2 of the License, or
7545 + * (at your option) any later version.
7547 + * This program is distributed in the hope that it will be useful,
7548 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7549 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7550 + * GNU General Public License for more details.
7552 + * You should have received a copy of the GNU General Public License
7553 + * along with this program; if not, write to the Free Software
7554 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
7558 + * lookup and dentry operations
7561 +#ifndef __AUFS_DENTRY_H__
7562 +#define __AUFS_DENTRY_H__
7566 +#include <linux/dcache.h>
7569 +struct au_hdentry {
7570 + struct dentry *hd_dentry;
7571 + aufs_bindex_t hd_id;
7575 + atomic_t di_generation;
7577 + struct au_rwsem di_rwsem;
7578 + aufs_bindex_t di_bstart, di_bend, di_bwh, di_bdiropq;
7579 + struct au_hdentry *di_hdentry;
7580 +} ____cacheline_aligned_in_smp;
7582 +/* ---------------------------------------------------------------------- */
7585 +extern const struct dentry_operations aufs_dop;
7587 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent,
7588 + struct au_branch *br);
7589 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
7590 + struct dentry *h_parent, struct au_branch *br);
7592 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type);
7593 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
7594 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
7595 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
7598 +void au_di_init_once(void *_di);
7599 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
7600 +void au_di_free(struct au_dinfo *dinfo);
7601 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
7602 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
7603 +int au_di_init(struct dentry *dentry);
7604 +void au_di_fin(struct dentry *dentry);
7605 +int au_di_realloc(struct au_dinfo *dinfo, int nbr);
7607 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
7608 +void di_read_unlock(struct dentry *d, int flags);
7609 +void di_downgrade_lock(struct dentry *d, int flags);
7610 +void di_write_lock(struct dentry *d, unsigned int lsc);
7611 +void di_write_unlock(struct dentry *d);
7612 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
7613 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
7614 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
7616 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
7617 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
7618 +aufs_bindex_t au_dbtail(struct dentry *dentry);
7619 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
7621 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
7622 + struct dentry *h_dentry);
7623 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
7624 +int au_dbrange_test(struct dentry *dentry);
7625 +void au_update_digen(struct dentry *dentry);
7626 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
7627 +void au_update_dbstart(struct dentry *dentry);
7628 +void au_update_dbend(struct dentry *dentry);
7629 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
7631 +/* ---------------------------------------------------------------------- */
7633 +static inline struct au_dinfo *au_di(struct dentry *dentry)
7635 + return dentry->d_fsdata;
7638 +/* ---------------------------------------------------------------------- */
7640 +/* lock subclass for dinfo */
7642 + AuLsc_DI_CHILD, /* child first */
7643 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
7644 + AuLsc_DI_CHILD3, /* copyup dirs */
7648 + AuLsc_DI_TMP /* temp for replacing dinfo */
7652 + * di_read_lock_child, di_write_lock_child,
7653 + * di_read_lock_child2, di_write_lock_child2,
7654 + * di_read_lock_child3, di_write_lock_child3,
7655 + * di_read_lock_parent, di_write_lock_parent,
7656 + * di_read_lock_parent2, di_write_lock_parent2,
7657 + * di_read_lock_parent3, di_write_lock_parent3,
7659 +#define AuReadLockFunc(name, lsc) \
7660 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
7661 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
7663 +#define AuWriteLockFunc(name, lsc) \
7664 +static inline void di_write_lock_##name(struct dentry *d) \
7665 +{ di_write_lock(d, AuLsc_DI_##lsc); }
7667 +#define AuRWLockFuncs(name, lsc) \
7668 + AuReadLockFunc(name, lsc) \
7669 + AuWriteLockFunc(name, lsc)
7671 +AuRWLockFuncs(child, CHILD);
7672 +AuRWLockFuncs(child2, CHILD2);
7673 +AuRWLockFuncs(child3, CHILD3);
7674 +AuRWLockFuncs(parent, PARENT);
7675 +AuRWLockFuncs(parent2, PARENT2);
7676 +AuRWLockFuncs(parent3, PARENT3);
7678 +#undef AuReadLockFunc
7679 +#undef AuWriteLockFunc
7680 +#undef AuRWLockFuncs
7682 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
7683 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
7684 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
7686 +/* ---------------------------------------------------------------------- */
7688 +/* todo: memory barrier? */
7689 +static inline unsigned int au_digen(struct dentry *d)
7691 + return atomic_read(&au_di(d)->di_generation);
7694 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
7696 + hdentry->hd_dentry = NULL;
7699 +static inline void au_hdput(struct au_hdentry *hd)
7702 + dput(hd->hd_dentry);
7705 +static inline aufs_bindex_t au_dbstart(struct dentry *dentry)
7707 + DiMustAnyLock(dentry);
7708 + return au_di(dentry)->di_bstart;
7711 +static inline aufs_bindex_t au_dbend(struct dentry *dentry)
7713 + DiMustAnyLock(dentry);
7714 + return au_di(dentry)->di_bend;
7717 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
7719 + DiMustAnyLock(dentry);
7720 + return au_di(dentry)->di_bwh;
7723 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
7725 + DiMustAnyLock(dentry);
7726 + return au_di(dentry)->di_bdiropq;
7729 +/* todo: hard/soft set? */
7730 +static inline void au_set_dbstart(struct dentry *dentry, aufs_bindex_t bindex)
7732 + DiMustWriteLock(dentry);
7733 + au_di(dentry)->di_bstart = bindex;
7736 +static inline void au_set_dbend(struct dentry *dentry, aufs_bindex_t bindex)
7738 + DiMustWriteLock(dentry);
7739 + au_di(dentry)->di_bend = bindex;
7742 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
7744 + DiMustWriteLock(dentry);
7745 + /* dbwh can be outside of bstart - bend range */
7746 + au_di(dentry)->di_bwh = bindex;
7749 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
7751 + DiMustWriteLock(dentry);
7752 + au_di(dentry)->di_bdiropq = bindex;
7755 +/* ---------------------------------------------------------------------- */
7757 +#ifdef CONFIG_AUFS_HNOTIFY
7758 +static inline void au_digen_dec(struct dentry *d)
7760 + atomic_dec(&au_di(d)->di_generation);
7763 +static inline void au_hn_di_reinit(struct dentry *dentry)
7765 + dentry->d_fsdata = NULL;
7768 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
7769 +#endif /* CONFIG_AUFS_HNOTIFY */
7771 +#endif /* __KERNEL__ */
7772 +#endif /* __AUFS_DENTRY_H__ */
7773 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
7774 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
7775 +++ linux/fs/aufs/dinfo.c 2013-10-26 16:51:29.579631476 +0200
7778 + * Copyright (C) 2005-2013 Junjiro R. Okajima
7780 + * This program, aufs is free software; you can redistribute it and/or modify
7781 + * it under the terms of the GNU General Public License as published by
7782 + * the Free Software Foundation; either version 2 of the License, or
7783 + * (at your option) any later version.
7785 + * This program is distributed in the hope that it will be useful,
7786 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7787 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7788 + * GNU General Public License for more details.
7790 + * You should have received a copy of the GNU General Public License
7791 + * along with this program; if not, write to the Free Software
7792 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
7796 + * dentry private data
7801 +void au_di_init_once(void *_dinfo)
7803 + struct au_dinfo *dinfo = _dinfo;
7804 + static struct lock_class_key aufs_di;
7806 + au_rw_init(&dinfo->di_rwsem);
7807 + au_rw_class(&dinfo->di_rwsem, &aufs_di);
7810 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
7812 + struct au_dinfo *dinfo;
7815 + dinfo = au_cache_alloc_dinfo();
7816 + if (unlikely(!dinfo))
7819 + nbr = au_sbend(sb) + 1;
7822 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
7823 + if (dinfo->di_hdentry) {
7824 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
7825 + dinfo->di_bstart = -1;
7826 + dinfo->di_bend = -1;
7827 + dinfo->di_bwh = -1;
7828 + dinfo->di_bdiropq = -1;
7829 + for (i = 0; i < nbr; i++)
7830 + dinfo->di_hdentry[i].hd_id = -1;
7834 + au_cache_free_dinfo(dinfo);
7841 +void au_di_free(struct au_dinfo *dinfo)
7843 + struct au_hdentry *p;
7844 + aufs_bindex_t bend, bindex;
7846 + /* dentry may not be revalidated */
7847 + bindex = dinfo->di_bstart;
7848 + if (bindex >= 0) {
7849 + bend = dinfo->di_bend;
7850 + p = dinfo->di_hdentry + bindex;
7851 + while (bindex++ <= bend)
7854 + kfree(dinfo->di_hdentry);
7855 + au_cache_free_dinfo(dinfo);
7858 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
7860 + struct au_hdentry *p;
7863 + AuRwMustWriteLock(&a->di_rwsem);
7864 + AuRwMustWriteLock(&b->di_rwsem);
7866 +#define DiSwap(v, name) \
7868 + v = a->di_##name; \
7869 + a->di_##name = b->di_##name; \
7870 + b->di_##name = v; \
7873 + DiSwap(p, hdentry);
7874 + DiSwap(bi, bstart);
7877 + DiSwap(bi, bdiropq);
7883 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
7885 + AuRwMustWriteLock(&dst->di_rwsem);
7886 + AuRwMustWriteLock(&src->di_rwsem);
7888 + dst->di_bstart = src->di_bstart;
7889 + dst->di_bend = src->di_bend;
7890 + dst->di_bwh = src->di_bwh;
7891 + dst->di_bdiropq = src->di_bdiropq;
7895 +int au_di_init(struct dentry *dentry)
7898 + struct super_block *sb;
7899 + struct au_dinfo *dinfo;
7902 + sb = dentry->d_sb;
7903 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
7905 + atomic_set(&dinfo->di_generation, au_sigen(sb));
7906 + /* smp_mb(); */ /* atomic_set */
7907 + dentry->d_fsdata = dinfo;
7914 +void au_di_fin(struct dentry *dentry)
7916 + struct au_dinfo *dinfo;
7918 + dinfo = au_di(dentry);
7919 + AuRwDestroy(&dinfo->di_rwsem);
7920 + au_di_free(dinfo);
7923 +int au_di_realloc(struct au_dinfo *dinfo, int nbr)
7926 + struct au_hdentry *hdp;
7928 + AuRwMustWriteLock(&dinfo->di_rwsem);
7931 + sz = sizeof(*hdp) * (dinfo->di_bend + 1);
7933 + sz = sizeof(*hdp);
7934 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS);
7936 + dinfo->di_hdentry = hdp;
7943 +/* ---------------------------------------------------------------------- */
7945 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
7948 + case AuLsc_DI_CHILD:
7949 + ii_write_lock_child(inode);
7951 + case AuLsc_DI_CHILD2:
7952 + ii_write_lock_child2(inode);
7954 + case AuLsc_DI_CHILD3:
7955 + ii_write_lock_child3(inode);
7957 + case AuLsc_DI_PARENT:
7958 + ii_write_lock_parent(inode);
7960 + case AuLsc_DI_PARENT2:
7961 + ii_write_lock_parent2(inode);
7963 + case AuLsc_DI_PARENT3:
7964 + ii_write_lock_parent3(inode);
7971 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
7974 + case AuLsc_DI_CHILD:
7975 + ii_read_lock_child(inode);
7977 + case AuLsc_DI_CHILD2:
7978 + ii_read_lock_child2(inode);
7980 + case AuLsc_DI_CHILD3:
7981 + ii_read_lock_child3(inode);
7983 + case AuLsc_DI_PARENT:
7984 + ii_read_lock_parent(inode);
7986 + case AuLsc_DI_PARENT2:
7987 + ii_read_lock_parent2(inode);
7989 + case AuLsc_DI_PARENT3:
7990 + ii_read_lock_parent3(inode);
7997 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
7999 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
8001 + if (au_ftest_lock(flags, IW))
8002 + do_ii_write_lock(d->d_inode, lsc);
8003 + else if (au_ftest_lock(flags, IR))
8004 + do_ii_read_lock(d->d_inode, lsc);
8008 +void di_read_unlock(struct dentry *d, int flags)
8011 + if (au_ftest_lock(flags, IW)) {
8012 + au_dbg_verify_dinode(d);
8013 + ii_write_unlock(d->d_inode);
8014 + } else if (au_ftest_lock(flags, IR)) {
8015 + au_dbg_verify_dinode(d);
8016 + ii_read_unlock(d->d_inode);
8019 + au_rw_read_unlock(&au_di(d)->di_rwsem);
8022 +void di_downgrade_lock(struct dentry *d, int flags)
8024 + if (d->d_inode && au_ftest_lock(flags, IR))
8025 + ii_downgrade_lock(d->d_inode);
8026 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
8029 +void di_write_lock(struct dentry *d, unsigned int lsc)
8031 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
8033 + do_ii_write_lock(d->d_inode, lsc);
8036 +void di_write_unlock(struct dentry *d)
8038 + au_dbg_verify_dinode(d);
8040 + ii_write_unlock(d->d_inode);
8041 + au_rw_write_unlock(&au_di(d)->di_rwsem);
8044 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
8046 + AuDebugOn(d1 == d2
8047 + || d1->d_inode == d2->d_inode
8048 + || d1->d_sb != d2->d_sb);
8050 + if (isdir && au_test_subdir(d1, d2)) {
8051 + di_write_lock_child(d1);
8052 + di_write_lock_child2(d2);
8054 + /* there should be no races */
8055 + di_write_lock_child(d2);
8056 + di_write_lock_child2(d1);
8060 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
8062 + AuDebugOn(d1 == d2
8063 + || d1->d_inode == d2->d_inode
8064 + || d1->d_sb != d2->d_sb);
8066 + if (isdir && au_test_subdir(d1, d2)) {
8067 + di_write_lock_parent(d1);
8068 + di_write_lock_parent2(d2);
8070 + /* there should be no races */
8071 + di_write_lock_parent(d2);
8072 + di_write_lock_parent2(d1);
8076 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
8078 + di_write_unlock(d1);
8079 + if (d1->d_inode == d2->d_inode)
8080 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
8082 + di_write_unlock(d2);
8085 +/* ---------------------------------------------------------------------- */
8087 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
8091 + DiMustAnyLock(dentry);
8093 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
8095 + AuDebugOn(bindex < 0);
8096 + d = au_di(dentry)->di_hdentry[0 + bindex].hd_dentry;
8097 + AuDebugOn(d && d_count(d) <= 0);
8102 + * extended version of au_h_dptr().
8103 + * returns a hashed and positive h_dentry in bindex, NULL, or error.
8105 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
8107 + struct dentry *h_dentry;
8108 + struct inode *inode, *h_inode;
8110 + inode = dentry->d_inode;
8111 + AuDebugOn(!inode);
8114 + if (au_dbstart(dentry) <= bindex
8115 + && bindex <= au_dbend(dentry))
8116 + h_dentry = au_h_dptr(dentry, bindex);
8117 + if (h_dentry && !au_d_hashed_positive(h_dentry)) {
8119 + goto out; /* success */
8122 + AuDebugOn(bindex < au_ibstart(inode));
8123 + AuDebugOn(au_ibend(inode) < bindex);
8124 + h_inode = au_h_iptr(inode, bindex);
8125 + h_dentry = d_find_alias(h_inode);
8127 + if (!IS_ERR(h_dentry)) {
8128 + if (!au_d_hashed_positive(h_dentry))
8129 + goto out; /* success */
8135 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
8136 + h_dentry = au_plink_lkup(inode, bindex);
8137 + AuDebugOn(!h_dentry);
8138 + if (!IS_ERR(h_dentry)) {
8139 + if (!au_d_hashed_positive(h_dentry))
8140 + goto out; /* success */
8147 + AuDbgDentry(h_dentry);
8151 +aufs_bindex_t au_dbtail(struct dentry *dentry)
8153 + aufs_bindex_t bend, bwh;
8155 + bend = au_dbend(dentry);
8157 + bwh = au_dbwh(dentry);
8160 + if (0 < bwh && bwh < bend)
8166 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
8168 + aufs_bindex_t bend, bopq;
8170 + bend = au_dbtail(dentry);
8172 + bopq = au_dbdiropq(dentry);
8173 + if (0 <= bopq && bopq < bend)
8179 +/* ---------------------------------------------------------------------- */
8181 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
8182 + struct dentry *h_dentry)
8184 + struct au_hdentry *hd = au_di(dentry)->di_hdentry + bindex;
8185 + struct au_branch *br;
8187 + DiMustWriteLock(dentry);
8190 + hd->hd_dentry = h_dentry;
8192 + br = au_sbr(dentry->d_sb, bindex);
8193 + hd->hd_id = br->br_id;
8197 +int au_dbrange_test(struct dentry *dentry)
8200 + aufs_bindex_t bstart, bend;
8203 + bstart = au_dbstart(dentry);
8204 + bend = au_dbend(dentry);
8206 + AuDebugOn(bend < 0 && bstart > bend);
8209 + AuDebugOn(bend >= 0);
8215 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
8220 + if (unlikely(au_digen(dentry) != sigen
8221 + || au_iigen_test(dentry->d_inode, sigen)))
8227 +void au_update_digen(struct dentry *dentry)
8229 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
8230 + /* smp_mb(); */ /* atomic_set */
8233 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
8235 + struct au_dinfo *dinfo;
8236 + struct dentry *h_d;
8237 + struct au_hdentry *hdp;
8239 + DiMustWriteLock(dentry);
8241 + dinfo = au_di(dentry);
8242 + if (!dinfo || dinfo->di_bstart < 0)
8245 + hdp = dinfo->di_hdentry;
8246 + if (do_put_zero) {
8247 + aufs_bindex_t bindex, bend;
8249 + bend = dinfo->di_bend;
8250 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++) {
8251 + h_d = hdp[0 + bindex].hd_dentry;
8252 + if (h_d && !h_d->d_inode)
8253 + au_set_h_dptr(dentry, bindex, NULL);
8257 + dinfo->di_bstart = -1;
8258 + while (++dinfo->di_bstart <= dinfo->di_bend)
8259 + if (hdp[0 + dinfo->di_bstart].hd_dentry)
8261 + if (dinfo->di_bstart > dinfo->di_bend) {
8262 + dinfo->di_bstart = -1;
8263 + dinfo->di_bend = -1;
8268 + while (0 <= --dinfo->di_bend)
8269 + if (hdp[0 + dinfo->di_bend].hd_dentry)
8271 + AuDebugOn(dinfo->di_bstart > dinfo->di_bend || dinfo->di_bend < 0);
8274 +void au_update_dbstart(struct dentry *dentry)
8276 + aufs_bindex_t bindex, bend;
8277 + struct dentry *h_dentry;
8279 + bend = au_dbend(dentry);
8280 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
8281 + h_dentry = au_h_dptr(dentry, bindex);
8284 + if (h_dentry->d_inode) {
8285 + au_set_dbstart(dentry, bindex);
8288 + au_set_h_dptr(dentry, bindex, NULL);
8292 +void au_update_dbend(struct dentry *dentry)
8294 + aufs_bindex_t bindex, bstart;
8295 + struct dentry *h_dentry;
8297 + bstart = au_dbstart(dentry);
8298 + for (bindex = au_dbend(dentry); bindex >= bstart; bindex--) {
8299 + h_dentry = au_h_dptr(dentry, bindex);
8302 + if (h_dentry->d_inode) {
8303 + au_set_dbend(dentry, bindex);
8306 + au_set_h_dptr(dentry, bindex, NULL);
8310 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
8312 + aufs_bindex_t bindex, bend;
8314 + bend = au_dbend(dentry);
8315 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++)
8316 + if (au_h_dptr(dentry, bindex) == h_dentry)
8320 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
8321 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
8322 +++ linux/fs/aufs/dir.c 2013-10-26 16:51:32.273040419 +0200
8325 + * Copyright (C) 2005-2013 Junjiro R. Okajima
8327 + * This program, aufs is free software; you can redistribute it and/or modify
8328 + * it under the terms of the GNU General Public License as published by
8329 + * the Free Software Foundation; either version 2 of the License, or
8330 + * (at your option) any later version.
8332 + * This program is distributed in the hope that it will be useful,
8333 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8334 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8335 + * GNU General Public License for more details.
8337 + * You should have received a copy of the GNU General Public License
8338 + * along with this program; if not, write to the Free Software
8339 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
8343 + * directory operations
8346 +#include <linux/fs_stack.h>
8349 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
8351 + unsigned int nlink;
8353 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
8355 + nlink = dir->i_nlink;
8356 + nlink += h_dir->i_nlink - 2;
8357 + if (h_dir->i_nlink < 2)
8360 + /* 0 can happen in revaliding */
8361 + set_nlink(dir, nlink);
8364 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
8366 + unsigned int nlink;
8368 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
8370 + nlink = dir->i_nlink;
8371 + nlink -= h_dir->i_nlink - 2;
8372 + if (h_dir->i_nlink < 2)
8375 + /* nlink == 0 means the branch-fs is broken */
8376 + set_nlink(dir, nlink);
8379 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
8382 + aufs_bindex_t bindex, bend;
8383 + struct file *h_file;
8384 + struct dentry *h_dentry;
8388 + AuDebugOn(!file_inode(file));
8389 + AuDebugOn(!S_ISDIR(file_inode(file)->i_mode));
8391 + bend = au_fbend_dir(file);
8392 + for (bindex = au_fbstart(file);
8393 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
8395 + h_file = au_hf_dir(file, bindex);
8396 + if (h_file && file_inode(h_file))
8397 + sz += vfsub_f_size_read(h_file);
8400 + AuDebugOn(!dentry);
8401 + AuDebugOn(!dentry->d_inode);
8402 + AuDebugOn(!S_ISDIR(dentry->d_inode->i_mode));
8404 + bend = au_dbtaildir(dentry);
8405 + for (bindex = au_dbstart(dentry);
8406 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
8408 + h_dentry = au_h_dptr(dentry, bindex);
8409 + if (h_dentry && h_dentry->d_inode)
8410 + sz += i_size_read(h_dentry->d_inode);
8413 + if (sz < KMALLOC_MAX_SIZE)
8414 + sz = roundup_pow_of_two(sz);
8415 + if (sz > KMALLOC_MAX_SIZE)
8416 + sz = KMALLOC_MAX_SIZE;
8417 + else if (sz < NAME_MAX) {
8418 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
8419 + sz = AUFS_RDBLK_DEF;
8424 +/* ---------------------------------------------------------------------- */
8426 +static int reopen_dir(struct file *file)
8429 + unsigned int flags;
8430 + aufs_bindex_t bindex, btail, bstart;
8431 + struct dentry *dentry, *h_dentry;
8432 + struct file *h_file;
8434 + /* open all lower dirs */
8435 + dentry = file->f_dentry;
8436 + bstart = au_dbstart(dentry);
8437 + for (bindex = au_fbstart(file); bindex < bstart; bindex++)
8438 + au_set_h_fptr(file, bindex, NULL);
8439 + au_set_fbstart(file, bstart);
8441 + btail = au_dbtaildir(dentry);
8442 + for (bindex = au_fbend_dir(file); btail < bindex; bindex--)
8443 + au_set_h_fptr(file, bindex, NULL);
8444 + au_set_fbend_dir(file, btail);
8446 + flags = vfsub_file_flags(file);
8447 + for (bindex = bstart; bindex <= btail; bindex++) {
8448 + h_dentry = au_h_dptr(dentry, bindex);
8451 + h_file = au_hf_dir(file, bindex);
8455 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
8456 + err = PTR_ERR(h_file);
8457 + if (IS_ERR(h_file))
8458 + goto out; /* close all? */
8459 + au_set_h_fptr(file, bindex, h_file);
8461 + au_update_figen(file);
8462 + /* todo: necessary? */
8463 + /* file->f_ra = h_file->f_ra; */
8470 +static int do_open_dir(struct file *file, int flags)
8473 + aufs_bindex_t bindex, btail;
8474 + struct dentry *dentry, *h_dentry;
8475 + struct file *h_file;
8477 + FiMustWriteLock(file);
8479 + dentry = file->f_dentry;
8480 + err = au_alive_dir(dentry);
8481 + if (unlikely(err))
8484 + file->f_version = dentry->d_inode->i_version;
8485 + bindex = au_dbstart(dentry);
8486 + au_set_fbstart(file, bindex);
8487 + btail = au_dbtaildir(dentry);
8488 + au_set_fbend_dir(file, btail);
8489 + for (; !err && bindex <= btail; bindex++) {
8490 + h_dentry = au_h_dptr(dentry, bindex);
8494 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
8495 + if (IS_ERR(h_file)) {
8496 + err = PTR_ERR(h_file);
8499 + au_set_h_fptr(file, bindex, h_file);
8501 + au_update_figen(file);
8502 + /* todo: necessary? */
8503 + /* file->f_ra = h_file->f_ra; */
8505 + return 0; /* success */
8508 + for (bindex = au_fbstart(file); bindex <= btail; bindex++)
8509 + au_set_h_fptr(file, bindex, NULL);
8510 + au_set_fbstart(file, -1);
8511 + au_set_fbend_dir(file, -1);
8517 +static int aufs_open_dir(struct inode *inode __maybe_unused,
8518 + struct file *file)
8521 + struct super_block *sb;
8522 + struct au_fidir *fidir;
8525 + sb = file->f_dentry->d_sb;
8526 + si_read_lock(sb, AuLock_FLUSH);
8527 + fidir = au_fidir_alloc(sb);
8529 + err = au_do_open(file, do_open_dir, fidir);
8530 + if (unlikely(err))
8533 + si_read_unlock(sb);
8537 +static int aufs_release_dir(struct inode *inode __maybe_unused,
8538 + struct file *file)
8540 + struct au_vdir *vdir_cache;
8541 + struct au_finfo *finfo;
8542 + struct au_fidir *fidir;
8543 + aufs_bindex_t bindex, bend;
8545 + finfo = au_fi(file);
8546 + fidir = finfo->fi_hdir;
8548 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
8550 + au_vdir_free(vdir_cache);
8552 + bindex = finfo->fi_btop;
8553 + if (bindex >= 0) {
8555 + * calls fput() instead of filp_close(),
8556 + * since no dnotify or lock for the lower file.
8558 + bend = fidir->fd_bbot;
8559 + for (; bindex <= bend; bindex++)
8560 + au_set_h_fptr(file, bindex, NULL);
8563 + finfo->fi_hdir = NULL;
8565 + au_finfo_fin(file);
8569 +/* ---------------------------------------------------------------------- */
8571 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
8574 + aufs_bindex_t bindex, bend;
8575 + struct file *h_file;
8578 + bend = au_fbend_dir(file);
8579 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
8580 + h_file = au_hf_dir(file, bindex);
8582 + err = vfsub_flush(h_file, id);
8587 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
8589 + return au_do_flush(file, id, au_do_flush_dir);
8592 +/* ---------------------------------------------------------------------- */
8594 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
8597 + aufs_bindex_t bend, bindex;
8598 + struct inode *inode;
8599 + struct super_block *sb;
8602 + sb = dentry->d_sb;
8603 + inode = dentry->d_inode;
8605 + bend = au_dbend(dentry);
8606 + for (bindex = au_dbstart(dentry); !err && bindex <= bend; bindex++) {
8607 + struct path h_path;
8609 + if (au_test_ro(sb, bindex, inode))
8611 + h_path.dentry = au_h_dptr(dentry, bindex);
8612 + if (!h_path.dentry)
8615 + h_path.mnt = au_sbr_mnt(sb, bindex);
8616 + err = vfsub_fsync(NULL, &h_path, datasync);
8622 +static int au_do_fsync_dir(struct file *file, int datasync)
8625 + aufs_bindex_t bend, bindex;
8626 + struct file *h_file;
8627 + struct super_block *sb;
8628 + struct inode *inode;
8630 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
8631 + if (unlikely(err))
8634 + sb = file->f_dentry->d_sb;
8635 + inode = file_inode(file);
8636 + bend = au_fbend_dir(file);
8637 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
8638 + h_file = au_hf_dir(file, bindex);
8639 + if (!h_file || au_test_ro(sb, bindex, inode))
8642 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
8650 + * @file may be NULL
8652 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
8656 + struct dentry *dentry;
8657 + struct super_block *sb;
8658 + struct mutex *mtx;
8661 + dentry = file->f_dentry;
8662 + mtx = &dentry->d_inode->i_mutex;
8664 + sb = dentry->d_sb;
8665 + si_noflush_read_lock(sb);
8667 + err = au_do_fsync_dir(file, datasync);
8669 + di_write_lock_child(dentry);
8670 + err = au_do_fsync_dir_no_file(dentry, datasync);
8672 + au_cpup_attr_timesizes(dentry->d_inode);
8673 + di_write_unlock(dentry);
8675 + fi_write_unlock(file);
8677 + si_read_unlock(sb);
8678 + mutex_unlock(mtx);
8682 +/* ---------------------------------------------------------------------- */
8684 +static int aufs_iterate(struct file *file, struct dir_context *ctx)
8687 + struct dentry *dentry;
8688 + struct inode *inode, *h_inode;
8689 + struct super_block *sb;
8691 + AuDbg("%.*s, ctx{%pf, %llu}\n",
8692 + AuDLNPair(file->f_dentry), ctx->actor, ctx->pos);
8694 + dentry = file->f_dentry;
8695 + inode = dentry->d_inode;
8698 + sb = dentry->d_sb;
8699 + si_read_lock(sb, AuLock_FLUSH);
8700 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
8701 + if (unlikely(err))
8703 + err = au_alive_dir(dentry);
8705 + err = au_vdir_init(file);
8706 + di_downgrade_lock(dentry, AuLock_IR);
8707 + if (unlikely(err))
8710 + h_inode = au_h_iptr(inode, au_ibstart(inode));
8711 + if (!au_test_nfsd()) {
8712 + err = au_vdir_fill_de(file, ctx);
8713 + fsstack_copy_attr_atime(inode, h_inode);
8716 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
8717 + * encode_fh() and others.
8719 + atomic_inc(&h_inode->i_count);
8720 + di_read_unlock(dentry, AuLock_IR);
8721 + si_read_unlock(sb);
8722 + err = au_vdir_fill_de(file, ctx);
8723 + fsstack_copy_attr_atime(inode, h_inode);
8724 + fi_write_unlock(file);
8732 + di_read_unlock(dentry, AuLock_IR);
8733 + fi_write_unlock(file);
8735 + si_read_unlock(sb);
8739 +/* ---------------------------------------------------------------------- */
8741 +#define AuTestEmpty_WHONLY 1
8742 +#define AuTestEmpty_CALLED (1 << 1)
8743 +#define AuTestEmpty_SHWH (1 << 2)
8744 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
8745 +#define au_fset_testempty(flags, name) \
8746 + do { (flags) |= AuTestEmpty_##name; } while (0)
8747 +#define au_fclr_testempty(flags, name) \
8748 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
8750 +#ifndef CONFIG_AUFS_SHWH
8751 +#undef AuTestEmpty_SHWH
8752 +#define AuTestEmpty_SHWH 0
8755 +struct test_empty_arg {
8756 + struct dir_context ctx;
8757 + struct au_nhash *whlist;
8758 + unsigned int flags;
8760 + aufs_bindex_t bindex;
8763 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
8764 + int namelen, loff_t offset __maybe_unused, u64 ino,
8765 + unsigned int d_type)
8767 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
8769 + char *name = (void *)__name;
8772 + au_fset_testempty(arg->flags, CALLED);
8774 + if (name[0] == '.'
8775 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
8776 + goto out; /* success */
8778 + if (namelen <= AUFS_WH_PFX_LEN
8779 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
8780 + if (au_ftest_testempty(arg->flags, WHONLY)
8781 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
8782 + arg->err = -ENOTEMPTY;
8786 + name += AUFS_WH_PFX_LEN;
8787 + namelen -= AUFS_WH_PFX_LEN;
8788 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
8789 + arg->err = au_nhash_append_wh
8790 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
8791 + au_ftest_testempty(arg->flags, SHWH));
8795 + AuTraceErr(arg->err);
8799 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
8802 + struct file *h_file;
8804 + h_file = au_h_open(dentry, arg->bindex,
8805 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
8806 + /*file*/NULL, /*force_wr*/0);
8807 + err = PTR_ERR(h_file);
8808 + if (IS_ERR(h_file))
8812 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
8813 + && !file_inode(h_file)->i_nlink)
8818 + au_fclr_testempty(arg->flags, CALLED);
8820 + err = vfsub_iterate_dir(h_file, &arg->ctx);
8823 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
8827 + au_sbr_put(dentry->d_sb, arg->bindex);
8832 +struct do_test_empty_args {
8834 + struct dentry *dentry;
8835 + struct test_empty_arg *arg;
8838 +static void call_do_test_empty(void *args)
8840 + struct do_test_empty_args *a = args;
8841 + *a->errp = do_test_empty(a->dentry, a->arg);
8844 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
8847 + struct dentry *h_dentry;
8848 + struct inode *h_inode;
8850 + h_dentry = au_h_dptr(dentry, arg->bindex);
8851 + h_inode = h_dentry->d_inode;
8852 + /* todo: i_mode changes anytime? */
8853 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
8854 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
8855 + mutex_unlock(&h_inode->i_mutex);
8857 + err = do_test_empty(dentry, arg);
8859 + struct do_test_empty_args args = {
8864 + unsigned int flags = arg->flags;
8866 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
8867 + if (unlikely(wkq_err))
8869 + arg->flags = flags;
8875 +int au_test_empty_lower(struct dentry *dentry)
8878 + unsigned int rdhash;
8879 + aufs_bindex_t bindex, bstart, btail;
8880 + struct au_nhash whlist;
8881 + struct test_empty_arg arg = {
8883 + .actor = au_diractor(test_empty_cb)
8887 + SiMustAnyLock(dentry->d_sb);
8889 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
8891 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
8892 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
8893 + if (unlikely(err))
8897 + arg.whlist = &whlist;
8898 + bstart = au_dbstart(dentry);
8899 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
8900 + au_fset_testempty(arg.flags, SHWH);
8901 + arg.bindex = bstart;
8902 + err = do_test_empty(dentry, &arg);
8903 + if (unlikely(err))
8906 + au_fset_testempty(arg.flags, WHONLY);
8907 + btail = au_dbtaildir(dentry);
8908 + for (bindex = bstart + 1; !err && bindex <= btail; bindex++) {
8909 + struct dentry *h_dentry;
8911 + h_dentry = au_h_dptr(dentry, bindex);
8912 + if (h_dentry && h_dentry->d_inode) {
8913 + arg.bindex = bindex;
8914 + err = do_test_empty(dentry, &arg);
8919 + au_nhash_wh_free(&whlist);
8924 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
8927 + struct test_empty_arg arg = {
8929 + .actor = au_diractor(test_empty_cb)
8932 + aufs_bindex_t bindex, btail;
8935 + arg.whlist = whlist;
8936 + arg.flags = AuTestEmpty_WHONLY;
8937 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
8938 + au_fset_testempty(arg.flags, SHWH);
8939 + btail = au_dbtaildir(dentry);
8940 + for (bindex = au_dbstart(dentry); !err && bindex <= btail; bindex++) {
8941 + struct dentry *h_dentry;
8943 + h_dentry = au_h_dptr(dentry, bindex);
8944 + if (h_dentry && h_dentry->d_inode) {
8945 + arg.bindex = bindex;
8946 + err = sio_test_empty(dentry, &arg);
8953 +/* ---------------------------------------------------------------------- */
8955 +const struct file_operations aufs_dir_fop = {
8956 + .owner = THIS_MODULE,
8957 + .llseek = default_llseek,
8958 + .read = generic_read_dir,
8959 + .iterate = aufs_iterate,
8960 + .unlocked_ioctl = aufs_ioctl_dir,
8961 +#ifdef CONFIG_COMPAT
8962 + .compat_ioctl = aufs_compat_ioctl_dir,
8964 + .open = aufs_open_dir,
8965 + .release = aufs_release_dir,
8966 + .flush = aufs_flush_dir,
8967 + .fsync = aufs_fsync_dir
8969 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
8970 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
8971 +++ linux/fs/aufs/dir.h 2013-10-26 16:51:29.582964925 +0200
8974 + * Copyright (C) 2005-2013 Junjiro R. Okajima
8976 + * This program, aufs is free software; you can redistribute it and/or modify
8977 + * it under the terms of the GNU General Public License as published by
8978 + * the Free Software Foundation; either version 2 of the License, or
8979 + * (at your option) any later version.
8981 + * This program is distributed in the hope that it will be useful,
8982 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8983 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8984 + * GNU General Public License for more details.
8986 + * You should have received a copy of the GNU General Public License
8987 + * along with this program; if not, write to the Free Software
8988 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
8992 + * directory operations
8995 +#ifndef __AUFS_DIR_H__
8996 +#define __AUFS_DIR_H__
9000 +#include <linux/fs.h>
9002 +/* ---------------------------------------------------------------------- */
9004 +/* need to be faster and smaller */
9007 + unsigned int nh_num;
9008 + struct hlist_head *nh_head;
9011 +struct au_vdir_destr {
9012 + unsigned char len;
9013 + unsigned char name[0];
9016 +struct au_vdir_dehstr {
9017 + struct hlist_node hash;
9018 + struct au_vdir_destr *str;
9019 +} ____cacheline_aligned_in_smp;
9021 +struct au_vdir_de {
9023 + unsigned char de_type;
9024 + /* caution: packed */
9025 + struct au_vdir_destr de_str;
9028 +struct au_vdir_wh {
9029 + struct hlist_node wh_hash;
9030 +#ifdef CONFIG_AUFS_SHWH
9032 + aufs_bindex_t wh_bindex;
9033 + unsigned char wh_type;
9035 + aufs_bindex_t wh_bindex;
9037 + /* caution: packed */
9038 + struct au_vdir_destr wh_str;
9041 +union au_vdir_deblk_p {
9042 + unsigned char *deblk;
9043 + struct au_vdir_de *de;
9047 + unsigned char **vd_deblk;
9048 + unsigned long vd_nblk;
9051 + union au_vdir_deblk_p p;
9054 + unsigned long vd_version;
9055 + unsigned int vd_deblk_sz;
9056 + unsigned long vd_jiffy;
9057 +} ____cacheline_aligned_in_smp;
9059 +/* ---------------------------------------------------------------------- */
9062 +extern const struct file_operations aufs_dir_fop;
9063 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
9064 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
9065 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
9066 +int au_test_empty_lower(struct dentry *dentry);
9067 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
9070 +unsigned int au_rdhash_est(loff_t sz);
9071 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
9072 +void au_nhash_wh_free(struct au_nhash *whlist);
9073 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
9075 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
9076 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
9077 + unsigned int d_type, aufs_bindex_t bindex,
9078 + unsigned char shwh);
9079 +void au_vdir_free(struct au_vdir *vdir);
9080 +int au_vdir_init(struct file *file);
9081 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
9084 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
9086 +#ifdef CONFIG_AUFS_RDU
9088 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
9089 +#ifdef CONFIG_COMPAT
9090 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
9091 + unsigned long arg);
9094 +static inline long au_rdu_ioctl(struct file *file, unsigned int cmd,
9095 + unsigned long arg)
9099 +#ifdef CONFIG_COMPAT
9100 +static inline long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
9101 + unsigned long arg)
9108 +#endif /* __KERNEL__ */
9109 +#endif /* __AUFS_DIR_H__ */
9110 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
9111 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
9112 +++ linux/fs/aufs/dynop.c 2013-10-26 16:51:29.582964925 +0200
9115 + * Copyright (C) 2010-2013 Junjiro R. Okajima
9117 + * This program, aufs is free software; you can redistribute it and/or modify
9118 + * it under the terms of the GNU General Public License as published by
9119 + * the Free Software Foundation; either version 2 of the License, or
9120 + * (at your option) any later version.
9122 + * This program is distributed in the hope that it will be useful,
9123 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9124 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9125 + * GNU General Public License for more details.
9127 + * You should have received a copy of the GNU General Public License
9128 + * along with this program; if not, write to the Free Software
9129 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
9133 + * dynamically customizable operations for regular files
9138 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
9141 + * How large will these lists be?
9142 + * Usually just a few elements, 20-30 at most for each, I guess.
9144 +static struct au_splhead dynop[AuDyLast];
9146 +static struct au_dykey *dy_gfind_get(struct au_splhead *spl, const void *h_op)
9148 + struct au_dykey *key, *tmp;
9149 + struct list_head *head;
9152 + head = &spl->head;
9154 + list_for_each_entry_rcu(tmp, head, dk_list)
9155 + if (tmp->dk_op.dy_hop == h_op) {
9157 + kref_get(&key->dk_kref);
9160 + rcu_read_unlock();
9165 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
9167 + struct au_dykey **k, *found;
9168 + const void *h_op = key->dk_op.dy_hop;
9173 + for (i = 0; i < AuBrDynOp; i++)
9175 + if (k[i]->dk_op.dy_hop == h_op) {
9182 + spin_lock(&br->br_dykey_lock);
9183 + for (; i < AuBrDynOp; i++)
9185 + if (k[i]->dk_op.dy_hop == h_op) {
9193 + spin_unlock(&br->br_dykey_lock);
9194 + BUG_ON(i == AuBrDynOp); /* expand the array */
9200 +/* kref_get() if @key is already added */
9201 +static struct au_dykey *dy_gadd(struct au_splhead *spl, struct au_dykey *key)
9203 + struct au_dykey *tmp, *found;
9204 + struct list_head *head;
9205 + const void *h_op = key->dk_op.dy_hop;
9208 + head = &spl->head;
9209 + spin_lock(&spl->spin);
9210 + list_for_each_entry(tmp, head, dk_list)
9211 + if (tmp->dk_op.dy_hop == h_op) {
9212 + kref_get(&tmp->dk_kref);
9217 + list_add_rcu(&key->dk_list, head);
9218 + spin_unlock(&spl->spin);
9225 +static void dy_free_rcu(struct rcu_head *rcu)
9227 + struct au_dykey *key;
9229 + key = container_of(rcu, struct au_dykey, dk_rcu);
9234 +static void dy_free(struct kref *kref)
9236 + struct au_dykey *key;
9237 + struct au_splhead *spl;
9239 + key = container_of(kref, struct au_dykey, dk_kref);
9240 + spl = dynop + key->dk_op.dy_type;
9241 + au_spl_del_rcu(&key->dk_list, spl);
9242 + call_rcu(&key->dk_rcu, dy_free_rcu);
9245 +void au_dy_put(struct au_dykey *key)
9247 + kref_put(&key->dk_kref, dy_free);
9250 +/* ---------------------------------------------------------------------- */
9252 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
9254 +#ifdef CONFIG_AUFS_DEBUG
9255 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
9256 +#define DyDbgInc(cnt) do { cnt++; } while (0)
9258 +#define DyDbgDeclare(cnt) do {} while (0)
9259 +#define DyDbgInc(cnt) do {} while (0)
9262 +#define DySet(func, dst, src, h_op, h_sb) do { \
9264 + if (h_op->func) { \
9266 + dst.func = src.func; \
9268 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
9272 +#define DySetForce(func, dst, src) do { \
9273 + AuDebugOn(!src.func); \
9275 + dst.func = src.func; \
9278 +#define DySetAop(func) \
9279 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
9280 +#define DySetAopForce(func) \
9281 + DySetForce(func, dyaop->da_op, aufs_aop)
9283 +static void dy_aop(struct au_dykey *key, const void *h_op,
9284 + struct super_block *h_sb __maybe_unused)
9286 + struct au_dyaop *dyaop = (void *)key;
9287 + const struct address_space_operations *h_aop = h_op;
9288 + DyDbgDeclare(cnt);
9290 + AuDbg("%s\n", au_sbtype(h_sb));
9292 + DySetAop(writepage);
9293 + DySetAopForce(readpage); /* force */
9294 + DySetAop(writepages);
9295 + DySetAop(set_page_dirty);
9296 + DySetAop(readpages);
9297 + DySetAop(write_begin);
9298 + DySetAop(write_end);
9300 + DySetAop(invalidatepage);
9301 + DySetAop(releasepage);
9302 + DySetAop(freepage);
9303 + /* these two will be changed according to an aufs mount option */
9304 + DySetAop(direct_IO);
9305 + DySetAop(get_xip_mem);
9306 + DySetAop(migratepage);
9307 + DySetAop(launder_page);
9308 + DySetAop(is_partially_uptodate);
9309 + DySetAop(is_dirty_writeback);
9310 + DySetAop(error_remove_page);
9311 + DySetAop(swap_activate);
9312 + DySetAop(swap_deactivate);
9314 + DyDbgSize(cnt, *h_aop);
9315 + dyaop->da_get_xip_mem = h_aop->get_xip_mem;
9318 +/* ---------------------------------------------------------------------- */
9320 +static void dy_bug(struct kref *kref)
9325 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
9327 + struct au_dykey *key, *old;
9328 + struct au_splhead *spl;
9331 + void (*set)(struct au_dykey *key, const void *h_op,
9332 + struct super_block *h_sb __maybe_unused);
9334 + static const struct op a[] = {
9336 + .sz = sizeof(struct au_dyaop),
9340 + const struct op *p;
9342 + spl = dynop + op->dy_type;
9343 + key = dy_gfind_get(spl, op->dy_hop);
9345 + goto out_add; /* success */
9347 + p = a + op->dy_type;
9348 + key = kzalloc(p->sz, GFP_NOFS);
9349 + if (unlikely(!key)) {
9350 + key = ERR_PTR(-ENOMEM);
9354 + key->dk_op.dy_hop = op->dy_hop;
9355 + kref_init(&key->dk_kref);
9356 + p->set(key, op->dy_hop, au_br_sb(br));
9357 + old = dy_gadd(spl, key);
9364 + old = dy_bradd(br, key);
9366 + /* its ref-count should never be zero here */
9367 + kref_put(&key->dk_kref, dy_bug);
9372 +/* ---------------------------------------------------------------------- */
9374 + * Aufs prohibits O_DIRECT by defaut even if the branch supports it.
9375 + * This behaviour is neccessary to return an error from open(O_DIRECT) instead
9376 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
9377 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
9378 + * See the aufs manual in detail.
9380 + * To keep this behaviour, aufs has to set NULL to ->get_xip_mem too, and the
9381 + * performance of fadvise() and madvise() may be affected.
9383 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
9386 + dyaop->da_op.direct_IO = NULL;
9387 + dyaop->da_op.get_xip_mem = NULL;
9389 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
9390 + dyaop->da_op.get_xip_mem = aufs_aop.get_xip_mem;
9391 + if (!dyaop->da_get_xip_mem)
9392 + dyaop->da_op.get_xip_mem = NULL;
9396 +static struct au_dyaop *dy_aget(struct au_branch *br,
9397 + const struct address_space_operations *h_aop,
9400 + struct au_dyaop *dyaop;
9401 + struct au_dynop op;
9403 + op.dy_type = AuDy_AOP;
9404 + op.dy_haop = h_aop;
9405 + dyaop = (void *)dy_get(&op, br);
9406 + if (IS_ERR(dyaop))
9408 + dy_adx(dyaop, do_dx);
9414 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
9415 + struct inode *h_inode)
9418 + struct super_block *sb;
9419 + struct au_branch *br;
9420 + struct au_dyaop *dyaop;
9422 + AuDebugOn(!S_ISREG(h_inode->i_mode));
9423 + IiMustWriteLock(inode);
9426 + br = au_sbr(sb, bindex);
9427 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
9428 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
9429 + err = PTR_ERR(dyaop);
9430 + if (IS_ERR(dyaop))
9431 + /* unnecessary to call dy_fput() */
9435 + inode->i_mapping->a_ops = &dyaop->da_op;
9442 + * Is it safe to replace a_ops during the inode/file is in operation?
9445 +int au_dy_irefresh(struct inode *inode)
9448 + aufs_bindex_t bstart;
9449 + struct inode *h_inode;
9452 + if (S_ISREG(inode->i_mode)) {
9453 + bstart = au_ibstart(inode);
9454 + h_inode = au_h_iptr(inode, bstart);
9455 + err = au_dy_iaop(inode, bstart, h_inode);
9460 +void au_dy_arefresh(int do_dx)
9462 + struct au_splhead *spl;
9463 + struct list_head *head;
9464 + struct au_dykey *key;
9466 + spl = dynop + AuDy_AOP;
9467 + head = &spl->head;
9468 + spin_lock(&spl->spin);
9469 + list_for_each_entry(key, head, dk_list)
9470 + dy_adx((void *)key, do_dx);
9471 + spin_unlock(&spl->spin);
9474 +/* ---------------------------------------------------------------------- */
9476 +void __init au_dy_init(void)
9480 + /* make sure that 'struct au_dykey *' can be any type */
9481 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
9483 + for (i = 0; i < AuDyLast; i++)
9484 + au_spl_init(dynop + i);
9487 +void au_dy_fin(void)
9491 + for (i = 0; i < AuDyLast; i++)
9492 + WARN_ON(!list_empty(&dynop[i].head));
9494 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
9495 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
9496 +++ linux/fs/aufs/dynop.h 2013-07-06 13:20:47.740198107 +0200
9499 + * Copyright (C) 2010-2013 Junjiro R. Okajima
9501 + * This program, aufs is free software; you can redistribute it and/or modify
9502 + * it under the terms of the GNU General Public License as published by
9503 + * the Free Software Foundation; either version 2 of the License, or
9504 + * (at your option) any later version.
9506 + * This program is distributed in the hope that it will be useful,
9507 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9508 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9509 + * GNU General Public License for more details.
9511 + * You should have received a copy of the GNU General Public License
9512 + * along with this program; if not, write to the Free Software
9513 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
9517 + * dynamically customizable operations (for regular files only)
9520 +#ifndef __AUFS_DYNOP_H__
9521 +#define __AUFS_DYNOP_H__
9527 +enum {AuDy_AOP, AuDyLast};
9532 + const void *dy_hop;
9533 + const struct address_space_operations *dy_haop;
9539 + struct list_head dk_list;
9540 + struct rcu_head dk_rcu;
9542 + struct au_dynop dk_op;
9545 + * during I am in the branch local array, kref is gotten. when the
9546 + * branch is removed, kref is put.
9548 + struct kref dk_kref;
9551 +/* stop unioning since their sizes are very different from each other */
9553 + struct au_dykey da_key;
9554 + struct address_space_operations da_op; /* not const */
9555 + int (*da_get_xip_mem)(struct address_space *, pgoff_t, int,
9556 + void **, unsigned long *);
9559 +/* ---------------------------------------------------------------------- */
9563 +void au_dy_put(struct au_dykey *key);
9564 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
9565 + struct inode *h_inode);
9566 +int au_dy_irefresh(struct inode *inode);
9567 +void au_dy_arefresh(int do_dio);
9569 +void __init au_dy_init(void);
9570 +void au_dy_fin(void);
9572 +#endif /* __KERNEL__ */
9573 +#endif /* __AUFS_DYNOP_H__ */
9574 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
9575 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
9576 +++ linux/fs/aufs/export.c 2013-10-26 16:51:29.582964925 +0200
9579 + * Copyright (C) 2005-2013 Junjiro R. Okajima
9581 + * This program, aufs is free software; you can redistribute it and/or modify
9582 + * it under the terms of the GNU General Public License as published by
9583 + * the Free Software Foundation; either version 2 of the License, or
9584 + * (at your option) any later version.
9586 + * This program is distributed in the hope that it will be useful,
9587 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9588 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9589 + * GNU General Public License for more details.
9591 + * You should have received a copy of the GNU General Public License
9592 + * along with this program; if not, write to the Free Software
9593 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
9600 +#include <linux/exportfs.h>
9601 +#include <linux/fs_struct.h>
9602 +#include <linux/namei.h>
9603 +#include <linux/nsproxy.h>
9604 +#include <linux/random.h>
9605 +#include <linux/writeback.h>
9606 +#include "../fs/mount.h"
9610 +#ifdef CONFIG_AUFS_INO_T_64
9618 +static ino_t decode_ino(__u32 *a)
9622 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
9624 +#ifdef CONFIG_AUFS_INO_T_64
9630 +static void encode_ino(__u32 *a, ino_t ino)
9636 +#ifdef CONFIG_AUFS_INO_T_64
9641 +/* NFS file handle */
9645 +#ifdef CONFIG_AUFS_INO_T_64
9646 + /* support 64bit inode number */
9660 + Fh_dir_ino = Fh_dir_ino1
9663 +static int au_test_anon(struct dentry *dentry)
9665 + /* note: read d_flags without d_lock */
9666 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
9669 +int au_test_nfsd(void)
9672 + struct task_struct *tsk = current;
9673 + char comm[sizeof(tsk->comm)];
9676 + if (tsk->flags & PF_KTHREAD) {
9677 + get_task_comm(comm, tsk);
9678 + ret = !strcmp(comm, "nfsd");
9684 +/* ---------------------------------------------------------------------- */
9685 +/* inode generation external table */
9687 +void au_xigen_inc(struct inode *inode)
9692 + struct super_block *sb;
9693 + struct au_sbinfo *sbinfo;
9696 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
9698 + sbinfo = au_sbi(sb);
9699 + pos = inode->i_ino;
9700 + pos *= sizeof(igen);
9701 + igen = inode->i_generation + 1;
9702 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
9703 + sizeof(igen), &pos);
9704 + if (sz == sizeof(igen))
9705 + return; /* success */
9707 + if (unlikely(sz >= 0))
9708 + AuIOErr("xigen error (%zd)\n", sz);
9711 +int au_xigen_new(struct inode *inode)
9716 + struct super_block *sb;
9717 + struct au_sbinfo *sbinfo;
9718 + struct file *file;
9721 + /* todo: dirty, at mount time */
9722 + if (inode->i_ino == AUFS_ROOT_INO)
9725 + SiMustAnyLock(sb);
9726 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
9730 + pos = inode->i_ino;
9731 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
9732 + AuIOErr1("too large i%lld\n", pos);
9735 + pos *= sizeof(inode->i_generation);
9738 + sbinfo = au_sbi(sb);
9739 + file = sbinfo->si_xigen;
9742 + if (vfsub_f_size_read(file)
9743 + < pos + sizeof(inode->i_generation)) {
9744 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
9745 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
9746 + sizeof(inode->i_generation), &pos);
9748 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
9749 + sizeof(inode->i_generation), &pos);
9750 + if (sz == sizeof(inode->i_generation))
9751 + goto out; /* success */
9754 + if (unlikely(sz >= 0)) {
9756 + AuIOErr("xigen error (%zd)\n", sz);
9763 +int au_xigen_set(struct super_block *sb, struct file *base)
9766 + struct au_sbinfo *sbinfo;
9767 + struct file *file;
9769 + SiMustWriteLock(sb);
9771 + sbinfo = au_sbi(sb);
9772 + file = au_xino_create2(base, sbinfo->si_xigen);
9773 + err = PTR_ERR(file);
9777 + if (sbinfo->si_xigen)
9778 + fput(sbinfo->si_xigen);
9779 + sbinfo->si_xigen = file;
9785 +void au_xigen_clr(struct super_block *sb)
9787 + struct au_sbinfo *sbinfo;
9789 + SiMustWriteLock(sb);
9791 + sbinfo = au_sbi(sb);
9792 + if (sbinfo->si_xigen) {
9793 + fput(sbinfo->si_xigen);
9794 + sbinfo->si_xigen = NULL;
9798 +/* ---------------------------------------------------------------------- */
9800 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
9803 + struct dentry *dentry, *d;
9804 + struct inode *inode;
9805 + unsigned int sigen;
9808 + inode = ilookup(sb, ino);
9812 + dentry = ERR_PTR(-ESTALE);
9813 + sigen = au_sigen(sb);
9814 + if (unlikely(is_bad_inode(inode)
9815 + || IS_DEADDIR(inode)
9816 + || sigen != au_iigen(inode, NULL)))
9820 + if (!dir_ino || S_ISDIR(inode->i_mode))
9821 + dentry = d_find_alias(inode);
9823 + spin_lock(&inode->i_lock);
9824 + hlist_for_each_entry(d, &inode->i_dentry, d_alias) {
9825 + spin_lock(&d->d_lock);
9826 + if (!au_test_anon(d)
9827 + && d->d_parent->d_inode->i_ino == dir_ino) {
9828 + dentry = dget_dlock(d);
9829 + spin_unlock(&d->d_lock);
9832 + spin_unlock(&d->d_lock);
9834 + spin_unlock(&inode->i_lock);
9836 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
9837 + /* need to refresh */
9845 + AuTraceErrPtr(dentry);
9849 +/* ---------------------------------------------------------------------- */
9852 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
9854 +struct au_compare_mnt_args {
9856 + struct super_block *sb;
9859 + struct vfsmount *mnt;
9862 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
9864 + struct au_compare_mnt_args *a = arg;
9866 + if (mnt->mnt_sb != a->sb)
9868 + a->mnt = mntget(mnt);
9872 +static struct vfsmount *au_mnt_get(struct super_block *sb)
9876 + struct au_compare_mnt_args args = {
9880 + get_fs_root(current->fs, &root);
9881 + br_read_lock(&vfsmount_lock);
9882 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
9883 + br_read_unlock(&vfsmount_lock);
9886 + AuDebugOn(!args.mnt);
9890 +struct au_nfsd_si_lock {
9891 + unsigned int sigen;
9892 + aufs_bindex_t bindex, br_id;
9893 + unsigned char force_lock;
9896 +static int si_nfsd_read_lock(struct super_block *sb,
9897 + struct au_nfsd_si_lock *nsi_lock)
9900 + aufs_bindex_t bindex;
9902 + si_read_lock(sb, AuLock_FLUSH);
9904 + /* branch id may be wrapped around */
9906 + bindex = au_br_index(sb, nsi_lock->br_id);
9907 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
9908 + goto out; /* success */
9912 + if (!nsi_lock->force_lock)
9913 + si_read_unlock(sb);
9916 + nsi_lock->bindex = bindex;
9920 +struct find_name_by_ino {
9921 + struct dir_context ctx;
9922 + int called, found;
9929 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
9930 + loff_t offset, u64 ino, unsigned int d_type)
9932 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
9936 + if (a->ino != ino)
9939 + memcpy(a->name, name, namelen);
9940 + a->namelen = namelen;
9945 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
9946 + struct au_nfsd_si_lock *nsi_lock)
9948 + struct dentry *dentry, *parent;
9949 + struct file *file;
9950 + struct inode *dir;
9951 + struct find_name_by_ino arg = {
9953 + .actor = au_diractor(find_name_by_ino)
9958 + parent = path->dentry;
9960 + si_read_unlock(parent->d_sb);
9961 + file = vfsub_dentry_open(path, au_dir_roflags);
9962 + dentry = (void *)file;
9966 + dentry = ERR_PTR(-ENOMEM);
9967 + arg.name = (void *)__get_free_page(GFP_NOFS);
9968 + if (unlikely(!arg.name))
9975 + err = vfsub_iterate_dir(file, &arg.ctx);
9976 + } while (!err && !arg.found && arg.called);
9977 + dentry = ERR_PTR(err);
9978 + if (unlikely(err))
9980 + /* instead of ENOENT */
9981 + dentry = ERR_PTR(-ESTALE);
9985 + /* do not call vfsub_lkup_one() */
9986 + dir = parent->d_inode;
9987 + mutex_lock(&dir->i_mutex);
9988 + dentry = vfsub_lookup_one_len(arg.name, parent, arg.namelen);
9989 + mutex_unlock(&dir->i_mutex);
9990 + AuTraceErrPtr(dentry);
9991 + if (IS_ERR(dentry))
9993 + AuDebugOn(au_test_anon(dentry));
9994 + if (unlikely(!dentry->d_inode)) {
9996 + dentry = ERR_PTR(-ENOENT);
10000 + free_page((unsigned long)arg.name);
10004 + if (unlikely(nsi_lock
10005 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
10006 + if (!IS_ERR(dentry)) {
10008 + dentry = ERR_PTR(-ESTALE);
10010 + AuTraceErrPtr(dentry);
10014 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
10016 + struct au_nfsd_si_lock *nsi_lock)
10018 + struct dentry *dentry;
10019 + struct path path;
10021 + if (dir_ino != AUFS_ROOT_INO) {
10022 + path.dentry = decode_by_ino(sb, dir_ino, 0);
10023 + dentry = path.dentry;
10024 + if (!path.dentry || IS_ERR(path.dentry))
10026 + AuDebugOn(au_test_anon(path.dentry));
10028 + path.dentry = dget(sb->s_root);
10030 + path.mnt = au_mnt_get(sb);
10031 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
10035 + AuTraceErrPtr(dentry);
10039 +/* ---------------------------------------------------------------------- */
10041 +static int h_acceptable(void *expv, struct dentry *dentry)
10046 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
10047 + char *buf, int len, struct super_block *sb)
10051 + struct path path;
10053 + p = d_path(h_rootpath, buf, len);
10058 + path.mnt = h_rootpath->mnt;
10059 + path.dentry = h_parent;
10060 + p = d_path(&path, buf, len);
10066 + path.mnt = au_mnt_get(sb);
10067 + path.dentry = sb->s_root;
10068 + p = d_path(&path, buf, len - strlen(p));
10069 + mntput(path.mnt);
10073 + p[strlen(p)] = '/';
10076 + AuTraceErrPtr(p);
10081 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
10082 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
10084 + struct dentry *dentry, *h_parent, *root;
10085 + struct super_block *h_sb;
10086 + char *pathname, *p;
10087 + struct vfsmount *h_mnt;
10088 + struct au_branch *br;
10090 + struct path path;
10092 + br = au_sbr(sb, nsi_lock->bindex);
10093 + h_mnt = au_br_mnt(br);
10094 + h_sb = h_mnt->mnt_sb;
10095 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
10096 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
10097 + fh_len - Fh_tail, fh[Fh_h_type],
10098 + h_acceptable, /*context*/NULL);
10099 + dentry = h_parent;
10100 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
10101 + AuWarn1("%s decode_fh failed, %ld\n",
10102 + au_sbtype(h_sb), PTR_ERR(h_parent));
10106 + if (unlikely(au_test_anon(h_parent))) {
10107 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
10108 + au_sbtype(h_sb));
10109 + goto out_h_parent;
10112 + dentry = ERR_PTR(-ENOMEM);
10113 + pathname = (void *)__get_free_page(GFP_NOFS);
10114 + if (unlikely(!pathname))
10115 + goto out_h_parent;
10117 + root = sb->s_root;
10118 + path.mnt = h_mnt;
10119 + di_read_lock_parent(root, !AuLock_IR);
10120 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
10121 + di_read_unlock(root, !AuLock_IR);
10122 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
10123 + dentry = (void *)p;
10125 + goto out_pathname;
10127 + si_read_unlock(sb);
10128 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
10129 + dentry = ERR_PTR(err);
10130 + if (unlikely(err))
10133 + dentry = ERR_PTR(-ENOENT);
10134 + AuDebugOn(au_test_anon(path.dentry));
10135 + if (unlikely(!path.dentry->d_inode))
10138 + if (ino != path.dentry->d_inode->i_ino)
10139 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
10141 + dentry = dget(path.dentry);
10146 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
10147 + if (!IS_ERR(dentry)) {
10149 + dentry = ERR_PTR(-ESTALE);
10152 + free_page((unsigned long)pathname);
10156 + AuTraceErrPtr(dentry);
10160 +/* ---------------------------------------------------------------------- */
10162 +static struct dentry *
10163 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
10166 + struct dentry *dentry;
10167 + __u32 *fh = fid->raw;
10168 + struct au_branch *br;
10169 + ino_t ino, dir_ino;
10170 + struct au_nfsd_si_lock nsi_lock = {
10174 + dentry = ERR_PTR(-ESTALE);
10175 + /* it should never happen, but the file handle is unreliable */
10176 + if (unlikely(fh_len < Fh_tail))
10178 + nsi_lock.sigen = fh[Fh_sigen];
10179 + nsi_lock.br_id = fh[Fh_br_id];
10181 + /* branch id may be wrapped around */
10183 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
10185 + nsi_lock.force_lock = 1;
10187 + /* is this inode still cached? */
10188 + ino = decode_ino(fh + Fh_ino);
10189 + /* it should never happen */
10190 + if (unlikely(ino == AUFS_ROOT_INO))
10193 + dir_ino = decode_ino(fh + Fh_dir_ino);
10194 + dentry = decode_by_ino(sb, ino, dir_ino);
10195 + if (IS_ERR(dentry))
10200 + /* is the parent dir cached? */
10201 + br = au_sbr(sb, nsi_lock.bindex);
10202 + atomic_inc(&br->br_count);
10203 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
10204 + if (IS_ERR(dentry))
10209 + /* lookup path */
10210 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
10211 + if (IS_ERR(dentry))
10213 + if (unlikely(!dentry))
10214 + /* todo?: make it ESTALE */
10218 + if (!au_digen_test(dentry, au_sigen(sb))
10219 + && dentry->d_inode->i_generation == fh[Fh_igen])
10220 + goto out_unlock; /* success */
10223 + dentry = ERR_PTR(-ESTALE);
10226 + atomic_dec(&br->br_count);
10227 + si_read_unlock(sb);
10229 + AuTraceErrPtr(dentry);
10233 +#if 0 /* reserved for future use */
10234 +/* support subtreecheck option */
10235 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
10236 + int fh_len, int fh_type)
10238 + struct dentry *parent;
10239 + __u32 *fh = fid->raw;
10242 + dir_ino = decode_ino(fh + Fh_dir_ino);
10243 + parent = decode_by_ino(sb, dir_ino, 0);
10244 + if (IS_ERR(parent))
10247 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
10248 + dir_ino, fh, fh_len);
10251 + AuTraceErrPtr(parent);
10256 +/* ---------------------------------------------------------------------- */
10258 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
10259 + struct inode *dir)
10262 + aufs_bindex_t bindex;
10263 + struct super_block *sb, *h_sb;
10264 + struct dentry *dentry, *parent, *h_parent;
10265 + struct inode *h_dir;
10266 + struct au_branch *br;
10269 + if (unlikely(*max_len <= Fh_tail)) {
10270 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
10274 + err = FILEID_ROOT;
10275 + if (inode->i_ino == AUFS_ROOT_INO) {
10276 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
10281 + sb = inode->i_sb;
10282 + err = si_read_lock(sb, AuLock_FLUSH);
10283 + if (unlikely(err))
10286 +#ifdef CONFIG_AUFS_DEBUG
10287 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
10288 + AuWarn1("NFS-exporting requires xino\n");
10292 + ii_read_lock_child(inode);
10293 + bindex = au_ibstart(inode);
10295 + dentry = d_find_alias(inode);
10296 + if (unlikely(!dentry))
10298 + AuDebugOn(au_test_anon(dentry));
10299 + parent = dget_parent(dentry);
10301 + if (unlikely(!parent))
10303 + dir = parent->d_inode;
10306 + ii_read_lock_parent(dir);
10307 + h_dir = au_h_iptr(dir, bindex);
10308 + ii_read_unlock(dir);
10309 + if (unlikely(!h_dir))
10311 + h_parent = d_find_alias(h_dir);
10312 + if (unlikely(!h_parent))
10313 + goto out_hparent;
10316 + br = au_sbr(sb, bindex);
10317 + h_sb = au_br_sb(br);
10318 + if (unlikely(!h_sb->s_export_op)) {
10319 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
10320 + goto out_hparent;
10323 + fh[Fh_br_id] = br->br_id;
10324 + fh[Fh_sigen] = au_sigen(sb);
10325 + encode_ino(fh + Fh_ino, inode->i_ino);
10326 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
10327 + fh[Fh_igen] = inode->i_generation;
10329 + *max_len -= Fh_tail;
10330 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
10332 + /*connectable or subtreecheck*/0);
10333 + err = fh[Fh_h_type];
10334 + *max_len += Fh_tail;
10335 + /* todo: macros? */
10336 + if (err != FILEID_INVALID)
10339 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
10346 + ii_read_unlock(inode);
10347 + si_read_unlock(sb);
10349 + if (unlikely(err < 0))
10350 + err = FILEID_INVALID;
10354 +/* ---------------------------------------------------------------------- */
10356 +static int aufs_commit_metadata(struct inode *inode)
10359 + aufs_bindex_t bindex;
10360 + struct super_block *sb;
10361 + struct inode *h_inode;
10362 + int (*f)(struct inode *inode);
10364 + sb = inode->i_sb;
10365 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
10366 + ii_write_lock_child(inode);
10367 + bindex = au_ibstart(inode);
10368 + AuDebugOn(bindex < 0);
10369 + h_inode = au_h_iptr(inode, bindex);
10371 + f = h_inode->i_sb->s_export_op->commit_metadata;
10373 + err = f(h_inode);
10375 + struct writeback_control wbc = {
10376 + .sync_mode = WB_SYNC_ALL,
10377 + .nr_to_write = 0 /* metadata only */
10380 + err = sync_inode(h_inode, &wbc);
10383 + au_cpup_attr_timesizes(inode);
10384 + ii_write_unlock(inode);
10385 + si_read_unlock(sb);
10389 +/* ---------------------------------------------------------------------- */
10391 +static struct export_operations aufs_export_op = {
10392 + .fh_to_dentry = aufs_fh_to_dentry,
10393 + /* .fh_to_parent = aufs_fh_to_parent, */
10394 + .encode_fh = aufs_encode_fh,
10395 + .commit_metadata = aufs_commit_metadata
10398 +void au_export_init(struct super_block *sb)
10400 + struct au_sbinfo *sbinfo;
10403 + sb->s_export_op = &aufs_export_op;
10404 + sbinfo = au_sbi(sb);
10405 + sbinfo->si_xigen = NULL;
10406 + get_random_bytes(&u, sizeof(u));
10407 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
10408 + atomic_set(&sbinfo->si_xigen_next, u);
10410 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
10411 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
10412 +++ linux/fs/aufs/file.c 2013-10-26 16:51:32.273040419 +0200
10415 + * Copyright (C) 2005-2013 Junjiro R. Okajima
10417 + * This program, aufs is free software; you can redistribute it and/or modify
10418 + * it under the terms of the GNU General Public License as published by
10419 + * the Free Software Foundation; either version 2 of the License, or
10420 + * (at your option) any later version.
10422 + * This program is distributed in the hope that it will be useful,
10423 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10424 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10425 + * GNU General Public License for more details.
10427 + * You should have received a copy of the GNU General Public License
10428 + * along with this program; if not, write to the Free Software
10429 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
10433 + * handling file/dir, and address_space operation
10436 +#ifdef CONFIG_AUFS_DEBUG
10437 +#include <linux/migrate.h>
10439 +#include <linux/pagemap.h>
10442 +/* drop flags for writing */
10443 +unsigned int au_file_roflags(unsigned int flags)
10445 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
10446 + flags |= O_RDONLY | O_NOATIME;
10450 +/* common functions to regular file and dir */
10451 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
10452 + struct file *file, int force_wr)
10454 + struct file *h_file;
10455 + struct dentry *h_dentry;
10456 + struct inode *h_inode;
10457 + struct super_block *sb;
10458 + struct au_branch *br;
10459 + struct path h_path;
10460 + int err, exec_flag;
10462 + /* a race condition can happen between open and unlink/rmdir */
10463 + h_file = ERR_PTR(-ENOENT);
10464 + h_dentry = au_h_dptr(dentry, bindex);
10465 + if (au_test_nfsd() && !h_dentry)
10467 + h_inode = h_dentry->d_inode;
10468 + if (au_test_nfsd() && !h_inode)
10470 + spin_lock(&h_dentry->d_lock);
10471 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
10473 + /* || !dentry->d_inode->i_nlink */
10475 + spin_unlock(&h_dentry->d_lock);
10476 + if (unlikely(err))
10479 + sb = dentry->d_sb;
10480 + br = au_sbr(sb, bindex);
10481 + h_file = ERR_PTR(-EACCES);
10482 + exec_flag = flags & __FMODE_EXEC;
10483 + if (exec_flag && (au_br_mnt(br)->mnt_flags & MNT_NOEXEC))
10486 + /* drop flags for writing */
10487 + if (au_test_ro(sb, bindex, dentry->d_inode)) {
10488 + if (force_wr && !(flags & O_WRONLY))
10490 + flags = au_file_roflags(flags);
10492 + h_file = ERR_PTR(-EROFS);
10493 + flags = au_file_roflags(flags);
10494 + if (unlikely(vfsub_native_ro(h_inode)
10495 + || IS_APPEND(h_inode)))
10497 + flags &= ~O_ACCMODE;
10498 + flags |= O_WRONLY;
10501 + flags &= ~O_CREAT;
10502 + atomic_inc(&br->br_count);
10503 + h_path.dentry = h_dentry;
10504 + h_path.mnt = au_br_mnt(br);
10505 + if (!au_special_file(h_inode->i_mode))
10506 + h_file = vfsub_dentry_open(&h_path, flags);
10508 + /* this block depends upon the configuration */
10509 + di_read_unlock(dentry, AuLock_IR);
10510 + fi_write_unlock(file);
10511 + si_read_unlock(sb);
10512 + h_file = vfsub_dentry_open(&h_path, flags);
10513 + si_noflush_read_lock(sb);
10514 + fi_write_lock(file);
10515 + di_read_lock_child(dentry, AuLock_IR);
10517 + if (IS_ERR(h_file))
10521 + err = deny_write_access(h_file);
10522 + if (unlikely(err)) {
10524 + h_file = ERR_PTR(err);
10528 + fsnotify_open(h_file);
10529 + goto out; /* success */
10532 + atomic_dec(&br->br_count);
10537 +int au_do_open(struct file *file, int (*open)(struct file *file, int flags),
10538 + struct au_fidir *fidir)
10541 + struct dentry *dentry;
10543 + err = au_finfo_init(file, fidir);
10544 + if (unlikely(err))
10547 + dentry = file->f_dentry;
10548 + di_read_lock_child(dentry, AuLock_IR);
10549 + err = open(file, vfsub_file_flags(file));
10550 + di_read_unlock(dentry, AuLock_IR);
10552 + fi_write_unlock(file);
10553 + if (unlikely(err)) {
10554 + au_fi(file)->fi_hdir = NULL;
10555 + au_finfo_fin(file);
10562 +int au_reopen_nondir(struct file *file)
10565 + aufs_bindex_t bstart;
10566 + struct dentry *dentry;
10567 + struct file *h_file, *h_file_tmp;
10569 + dentry = file->f_dentry;
10570 + AuDebugOn(au_special_file(dentry->d_inode->i_mode));
10571 + bstart = au_dbstart(dentry);
10572 + h_file_tmp = NULL;
10573 + if (au_fbstart(file) == bstart) {
10574 + h_file = au_hf_top(file);
10575 + if (file->f_mode == h_file->f_mode)
10576 + return 0; /* success */
10577 + h_file_tmp = h_file;
10578 + get_file(h_file_tmp);
10579 + au_set_h_fptr(file, bstart, NULL);
10581 + AuDebugOn(au_fi(file)->fi_hdir);
10584 + * file exists on both of rw and ro
10585 + * open --> dbstart and fbstart are both 0
10586 + * prepend a branch as rw, "rw" become ro
10588 + * delete the top branch, "rw" becomes rw again
10589 + * --> dbstart is 1, fbstart is still 0
10590 + * write --> fbstart is 0 but dbstart is 1
10592 + /* AuDebugOn(au_fbstart(file) < bstart); */
10594 + h_file = au_h_open(dentry, bstart, vfsub_file_flags(file) & ~O_TRUNC,
10595 + file, /*force_wr*/0);
10596 + err = PTR_ERR(h_file);
10597 + if (IS_ERR(h_file)) {
10598 + if (h_file_tmp) {
10599 + atomic_inc(&au_sbr(dentry->d_sb, bstart)->br_count);
10600 + au_set_h_fptr(file, bstart, h_file_tmp);
10601 + h_file_tmp = NULL;
10603 + goto out; /* todo: close all? */
10607 + au_set_fbstart(file, bstart);
10608 + au_set_h_fptr(file, bstart, h_file);
10609 + au_update_figen(file);
10610 + /* todo: necessary? */
10611 + /* file->f_ra = h_file->f_ra; */
10615 + fput(h_file_tmp);
10619 +/* ---------------------------------------------------------------------- */
10621 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
10622 + struct dentry *hi_wh)
10625 + aufs_bindex_t bstart;
10626 + struct au_dinfo *dinfo;
10627 + struct dentry *h_dentry;
10628 + struct au_hdentry *hdp;
10630 + dinfo = au_di(file->f_dentry);
10631 + AuRwMustWriteLock(&dinfo->di_rwsem);
10633 + bstart = dinfo->di_bstart;
10634 + dinfo->di_bstart = btgt;
10635 + hdp = dinfo->di_hdentry;
10636 + h_dentry = hdp[0 + btgt].hd_dentry;
10637 + hdp[0 + btgt].hd_dentry = hi_wh;
10638 + err = au_reopen_nondir(file);
10639 + hdp[0 + btgt].hd_dentry = h_dentry;
10640 + dinfo->di_bstart = bstart;
10645 +static int au_ready_to_write_wh(struct file *file, loff_t len,
10646 + aufs_bindex_t bcpup, struct au_pin *pin)
10649 + struct inode *inode, *h_inode;
10650 + struct dentry *h_dentry, *hi_wh;
10651 + struct au_cp_generic cpg = {
10652 + .dentry = file->f_dentry,
10659 + au_update_dbstart(cpg.dentry);
10660 + inode = cpg.dentry->d_inode;
10662 + if (au_dbstart(cpg.dentry) <= bcpup
10663 + && au_dbend(cpg.dentry) >= bcpup) {
10664 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
10666 + h_inode = h_dentry->d_inode;
10668 + hi_wh = au_hi_wh(inode, bcpup);
10669 + if (!hi_wh && !h_inode)
10670 + err = au_sio_cpup_wh(&cpg, file);
10672 + /* already copied-up after unlink */
10673 + err = au_reopen_wh(file, bcpup, hi_wh);
10676 + && inode->i_nlink > 1
10677 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
10678 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
10684 + * prepare the @file for writing.
10686 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
10689 + aufs_bindex_t dbstart;
10690 + struct dentry *parent, *h_dentry;
10691 + struct inode *inode;
10692 + struct super_block *sb;
10693 + struct file *h_file;
10694 + struct au_cp_generic cpg = {
10695 + .dentry = file->f_dentry,
10700 + .flags = AuCpup_DTIME
10703 + sb = cpg.dentry->d_sb;
10704 + inode = cpg.dentry->d_inode;
10705 + AuDebugOn(au_special_file(inode->i_mode));
10706 + cpg.bsrc = au_fbstart(file);
10707 + err = au_test_ro(sb, cpg.bsrc, inode);
10708 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
10709 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
10714 + /* need to cpup or reopen */
10715 + parent = dget_parent(cpg.dentry);
10716 + di_write_lock_parent(parent);
10717 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
10719 + if (unlikely(err < 0))
10723 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
10724 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
10725 + if (unlikely(err))
10729 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
10730 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
10731 + if (unlikely(err))
10734 + h_dentry = au_hf_top(file)->f_dentry;
10735 + dbstart = au_dbstart(cpg.dentry);
10736 + if (dbstart <= cpg.bdst) {
10737 + h_dentry = au_h_dptr(cpg.dentry, cpg.bdst);
10738 + AuDebugOn(!h_dentry);
10739 + cpg.bsrc = cpg.bdst;
10742 + if (dbstart <= cpg.bdst /* just reopen */
10743 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
10745 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
10746 + if (IS_ERR(h_file))
10747 + err = PTR_ERR(h_file);
10749 + di_downgrade_lock(parent, AuLock_IR);
10750 + if (dbstart > cpg.bdst)
10751 + err = au_sio_cpup_simple(&cpg);
10753 + err = au_reopen_nondir(file);
10754 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
10756 + } else { /* copyup as wh and reopen */
10758 + * since writable hfsplus branch is not supported,
10759 + * h_open_pre/post() are unnecessary.
10761 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
10762 + di_downgrade_lock(parent, AuLock_IR);
10766 + au_pin_set_parent_lflag(pin, /*lflag*/0);
10767 + goto out_dput; /* success */
10773 + di_downgrade_lock(parent, AuLock_IR);
10775 + di_read_unlock(parent, AuLock_IR);
10782 +/* ---------------------------------------------------------------------- */
10784 +int au_do_flush(struct file *file, fl_owner_t id,
10785 + int (*flush)(struct file *file, fl_owner_t id))
10788 + struct super_block *sb;
10789 + struct inode *inode;
10791 + inode = file_inode(file);
10792 + sb = inode->i_sb;
10793 + si_noflush_read_lock(sb);
10794 + fi_read_lock(file);
10795 + ii_read_lock_child(inode);
10797 + err = flush(file, id);
10798 + au_cpup_attr_timesizes(inode);
10800 + ii_read_unlock(inode);
10801 + fi_read_unlock(file);
10802 + si_read_unlock(sb);
10806 +/* ---------------------------------------------------------------------- */
10808 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
10811 + struct au_pin pin;
10812 + struct au_finfo *finfo;
10813 + struct dentry *parent, *hi_wh;
10814 + struct inode *inode;
10815 + struct super_block *sb;
10816 + struct au_cp_generic cpg = {
10817 + .dentry = file->f_dentry,
10822 + .flags = AuCpup_DTIME
10825 + FiMustWriteLock(file);
10828 + finfo = au_fi(file);
10829 + sb = cpg.dentry->d_sb;
10830 + inode = cpg.dentry->d_inode;
10831 + cpg.bdst = au_ibstart(inode);
10832 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
10835 + parent = dget_parent(cpg.dentry);
10836 + if (au_test_ro(sb, cpg.bdst, inode)) {
10837 + di_read_lock_parent(parent, !AuLock_IR);
10838 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
10840 + di_read_unlock(parent, !AuLock_IR);
10841 + if (unlikely(err < 0))
10846 + di_read_lock_parent(parent, AuLock_IR);
10847 + hi_wh = au_hi_wh(inode, cpg.bdst);
10848 + if (!S_ISDIR(inode->i_mode)
10849 + && au_opt_test(au_mntflags(sb), PLINK)
10850 + && au_plink_test(inode)
10851 + && !d_unhashed(cpg.dentry)
10852 + && cpg.bdst < au_dbstart(cpg.dentry)) {
10853 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
10854 + if (unlikely(err))
10857 + /* always superio. */
10858 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
10859 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
10861 + err = au_sio_cpup_simple(&cpg);
10864 + } else if (hi_wh) {
10865 + /* already copied-up after unlink */
10866 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
10867 + *need_reopen = 0;
10871 + di_read_unlock(parent, AuLock_IR);
10878 +static void au_do_refresh_dir(struct file *file)
10880 + aufs_bindex_t bindex, bend, new_bindex, brid;
10881 + struct au_hfile *p, tmp, *q;
10882 + struct au_finfo *finfo;
10883 + struct super_block *sb;
10884 + struct au_fidir *fidir;
10886 + FiMustWriteLock(file);
10888 + sb = file->f_dentry->d_sb;
10889 + finfo = au_fi(file);
10890 + fidir = finfo->fi_hdir;
10891 + AuDebugOn(!fidir);
10892 + p = fidir->fd_hfile + finfo->fi_btop;
10893 + brid = p->hf_br->br_id;
10894 + bend = fidir->fd_bbot;
10895 + for (bindex = finfo->fi_btop; bindex <= bend; bindex++, p++) {
10899 + new_bindex = au_br_index(sb, p->hf_br->br_id);
10900 + if (new_bindex == bindex)
10902 + if (new_bindex < 0) {
10903 + au_set_h_fptr(file, bindex, NULL);
10907 + /* swap two lower inode, and loop again */
10908 + q = fidir->fd_hfile + new_bindex;
10912 + if (tmp.hf_file) {
10918 + p = fidir->fd_hfile;
10919 + if (!au_test_mmapped(file) && !d_unlinked(file->f_dentry)) {
10920 + bend = au_sbend(sb);
10921 + for (finfo->fi_btop = 0; finfo->fi_btop <= bend;
10922 + finfo->fi_btop++, p++)
10923 + if (p->hf_file) {
10924 + if (file_inode(p->hf_file))
10927 + au_hfput(p, file);
10930 + bend = au_br_index(sb, brid);
10931 + for (finfo->fi_btop = 0; finfo->fi_btop < bend;
10932 + finfo->fi_btop++, p++)
10934 + au_hfput(p, file);
10935 + bend = au_sbend(sb);
10938 + p = fidir->fd_hfile + bend;
10939 + for (fidir->fd_bbot = bend; fidir->fd_bbot >= finfo->fi_btop;
10940 + fidir->fd_bbot--, p--)
10941 + if (p->hf_file) {
10942 + if (file_inode(p->hf_file))
10945 + au_hfput(p, file);
10947 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
10951 + * after branch manipulating, refresh the file.
10953 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
10955 + int err, need_reopen;
10956 + aufs_bindex_t bend, bindex;
10957 + struct dentry *dentry;
10958 + struct au_finfo *finfo;
10959 + struct au_hfile *hfile;
10961 + dentry = file->f_dentry;
10962 + finfo = au_fi(file);
10963 + if (!finfo->fi_hdir) {
10964 + hfile = &finfo->fi_htop;
10965 + AuDebugOn(!hfile->hf_file);
10966 + bindex = au_br_index(dentry->d_sb, hfile->hf_br->br_id);
10967 + AuDebugOn(bindex < 0);
10968 + if (bindex != finfo->fi_btop)
10969 + au_set_fbstart(file, bindex);
10971 + err = au_fidir_realloc(finfo, au_sbend(dentry->d_sb) + 1);
10972 + if (unlikely(err))
10974 + au_do_refresh_dir(file);
10979 + if (!au_test_mmapped(file))
10980 + err = au_file_refresh_by_inode(file, &need_reopen);
10981 + if (!err && need_reopen && !d_unlinked(dentry))
10982 + err = reopen(file);
10984 + au_update_figen(file);
10985 + goto out; /* success */
10988 + /* error, close all lower files */
10989 + if (finfo->fi_hdir) {
10990 + bend = au_fbend_dir(file);
10991 + for (bindex = au_fbstart(file); bindex <= bend; bindex++)
10992 + au_set_h_fptr(file, bindex, NULL);
10999 +/* common function to regular file and dir */
11000 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
11004 + unsigned int sigen, figen;
11005 + aufs_bindex_t bstart;
11006 + unsigned char pseudo_link;
11007 + struct dentry *dentry;
11008 + struct inode *inode;
11011 + dentry = file->f_dentry;
11012 + inode = dentry->d_inode;
11013 + AuDebugOn(au_special_file(inode->i_mode));
11014 + sigen = au_sigen(dentry->d_sb);
11015 + fi_write_lock(file);
11016 + figen = au_figen(file);
11017 + di_write_lock_child(dentry);
11018 + bstart = au_dbstart(dentry);
11019 + pseudo_link = (bstart != au_ibstart(inode));
11020 + if (sigen == figen && !pseudo_link && au_fbstart(file) == bstart) {
11022 + di_downgrade_lock(dentry, AuLock_IR);
11023 + fi_downgrade_lock(file);
11025 + goto out; /* success */
11028 + AuDbg("sigen %d, figen %d\n", sigen, figen);
11029 + if (au_digen_test(dentry, sigen)) {
11030 + err = au_reval_dpath(dentry, sigen);
11031 + AuDebugOn(!err && au_digen_test(dentry, sigen));
11035 + err = refresh_file(file, reopen);
11038 + di_downgrade_lock(dentry, AuLock_IR);
11039 + fi_downgrade_lock(file);
11042 + di_write_unlock(dentry);
11043 + fi_write_unlock(file);
11050 +/* ---------------------------------------------------------------------- */
11052 +/* cf. aufs_nopage() */
11053 +/* for madvise(2) */
11054 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
11056 + unlock_page(page);
11060 +/* it will never be called, but necessary to support O_DIRECT */
11061 +static ssize_t aufs_direct_IO(int rw, struct kiocb *iocb,
11062 + const struct iovec *iov, loff_t offset,
11063 + unsigned long nr_segs)
11064 +{ BUG(); return 0; }
11067 + * it will never be called, but madvise and fadvise behaves differently
11068 + * when get_xip_mem is defined
11070 +static int aufs_get_xip_mem(struct address_space *mapping, pgoff_t pgoff,
11071 + int create, void **kmem, unsigned long *pfn)
11072 +{ BUG(); return 0; }
11074 +/* they will never be called. */
11075 +#ifdef CONFIG_AUFS_DEBUG
11076 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
11077 + loff_t pos, unsigned len, unsigned flags,
11078 + struct page **pagep, void **fsdata)
11079 +{ AuUnsupport(); return 0; }
11080 +static int aufs_write_end(struct file *file, struct address_space *mapping,
11081 + loff_t pos, unsigned len, unsigned copied,
11082 + struct page *page, void *fsdata)
11083 +{ AuUnsupport(); return 0; }
11084 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
11085 +{ AuUnsupport(); return 0; }
11087 +static int aufs_set_page_dirty(struct page *page)
11088 +{ AuUnsupport(); return 0; }
11089 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
11090 + unsigned int length)
11091 +{ AuUnsupport(); }
11092 +static int aufs_releasepage(struct page *page, gfp_t gfp)
11093 +{ AuUnsupport(); return 0; }
11094 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
11095 + struct page *page, enum migrate_mode mode)
11096 +{ AuUnsupport(); return 0; }
11097 +static int aufs_launder_page(struct page *page)
11098 +{ AuUnsupport(); return 0; }
11099 +static int aufs_is_partially_uptodate(struct page *page,
11100 + read_descriptor_t *desc,
11101 + unsigned long from)
11102 +{ AuUnsupport(); return 0; }
11103 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
11105 +{ AuUnsupport(); }
11106 +static int aufs_error_remove_page(struct address_space *mapping,
11107 + struct page *page)
11108 +{ AuUnsupport(); return 0; }
11109 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
11111 +{ AuUnsupport(); return 0; }
11112 +static void aufs_swap_deactivate(struct file *file)
11113 +{ AuUnsupport(); }
11114 +#endif /* CONFIG_AUFS_DEBUG */
11116 +const struct address_space_operations aufs_aop = {
11117 + .readpage = aufs_readpage,
11118 + .direct_IO = aufs_direct_IO,
11119 + .get_xip_mem = aufs_get_xip_mem,
11120 +#ifdef CONFIG_AUFS_DEBUG
11121 + .writepage = aufs_writepage,
11122 + /* no writepages, because of writepage */
11123 + .set_page_dirty = aufs_set_page_dirty,
11124 + /* no readpages, because of readpage */
11125 + .write_begin = aufs_write_begin,
11126 + .write_end = aufs_write_end,
11127 + /* no bmap, no block device */
11128 + .invalidatepage = aufs_invalidatepage,
11129 + .releasepage = aufs_releasepage,
11130 + .migratepage = aufs_migratepage,
11131 + .launder_page = aufs_launder_page,
11132 + .is_partially_uptodate = aufs_is_partially_uptodate,
11133 + .is_dirty_writeback = aufs_is_dirty_writeback,
11134 + .error_remove_page = aufs_error_remove_page,
11135 + .swap_activate = aufs_swap_activate,
11136 + .swap_deactivate = aufs_swap_deactivate
11137 +#endif /* CONFIG_AUFS_DEBUG */
11139 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
11140 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
11141 +++ linux/fs/aufs/file.h 2013-10-26 16:51:32.273040419 +0200
11144 + * Copyright (C) 2005-2013 Junjiro R. Okajima
11146 + * This program, aufs is free software; you can redistribute it and/or modify
11147 + * it under the terms of the GNU General Public License as published by
11148 + * the Free Software Foundation; either version 2 of the License, or
11149 + * (at your option) any later version.
11151 + * This program is distributed in the hope that it will be useful,
11152 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11153 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11154 + * GNU General Public License for more details.
11156 + * You should have received a copy of the GNU General Public License
11157 + * along with this program; if not, write to the Free Software
11158 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11162 + * file operations
11165 +#ifndef __AUFS_FILE_H__
11166 +#define __AUFS_FILE_H__
11170 +#include <linux/file.h>
11171 +#include <linux/fs.h>
11172 +#include <linux/poll.h>
11173 +#include "rwsem.h"
11177 + struct file *hf_file;
11178 + struct au_branch *hf_br;
11183 + aufs_bindex_t fd_bbot;
11184 + aufs_bindex_t fd_nent;
11185 + struct au_vdir *fd_vdir_cache;
11186 + struct au_hfile fd_hfile[];
11189 +static inline int au_fidir_sz(int nent)
11191 + AuDebugOn(nent < 0);
11192 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
11196 + atomic_t fi_generation;
11198 + struct au_rwsem fi_rwsem;
11199 + aufs_bindex_t fi_btop;
11201 + /* do not union them */
11202 + struct { /* for non-dir */
11203 + struct au_hfile fi_htop;
11204 + atomic_t fi_mmapped;
11206 + struct au_fidir *fi_hdir; /* for dir only */
11207 +} ____cacheline_aligned_in_smp;
11209 +/* ---------------------------------------------------------------------- */
11212 +extern const struct address_space_operations aufs_aop;
11213 +unsigned int au_file_roflags(unsigned int flags);
11214 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
11215 + struct file *file, int force_wr);
11216 +int au_do_open(struct file *file, int (*open)(struct file *file, int flags),
11217 + struct au_fidir *fidir);
11218 +int au_reopen_nondir(struct file *file);
11220 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
11221 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
11223 +int au_do_flush(struct file *file, fl_owner_t id,
11224 + int (*flush)(struct file *file, fl_owner_t id));
11227 +#ifdef CONFIG_AUFS_POLL
11228 +unsigned int aufs_poll(struct file *file, poll_table *wait);
11231 +#ifdef CONFIG_AUFS_BR_HFSPLUS
11233 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
11235 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
11236 + struct file *h_file);
11239 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
11245 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
11246 + struct file *h_file);
11250 +extern const struct file_operations aufs_file_fop;
11251 +int au_do_open_nondir(struct file *file, int flags);
11252 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
11254 +#ifdef CONFIG_AUFS_SP_IATTR
11256 +struct au_finfo *au_fi_sp(struct file *file);
11257 +int au_special_file(umode_t mode);
11258 +void au_init_special_fop(struct inode *inode, umode_t mode, dev_t rdev);
11260 +static inline struct au_finfo *au_fi_sp(struct file *file)
11264 +AuStubInt0(au_special_file, umode_t mode)
11265 +static inline void au_init_special_fop(struct inode *inode, umode_t mode,
11268 + init_special_inode(inode, mode, rdev);
11273 +void au_hfput(struct au_hfile *hf, struct file *file);
11274 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
11275 + struct file *h_file);
11277 +void au_update_figen(struct file *file);
11278 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
11279 +int au_fidir_realloc(struct au_finfo *finfo, int nbr);
11281 +void au_fi_init_once(void *_fi);
11282 +void au_finfo_fin(struct file *file);
11283 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
11286 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
11287 +#ifdef CONFIG_COMPAT
11288 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
11289 + unsigned long arg);
11290 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
11291 + unsigned long arg);
11294 +/* ---------------------------------------------------------------------- */
11296 +static inline struct au_finfo *au_fi(struct file *file)
11298 + struct au_finfo *finfo;
11300 + finfo = au_fi_sp(file);
11302 + finfo = file->private_data;
11306 +/* ---------------------------------------------------------------------- */
11309 + * fi_read_lock, fi_write_lock,
11310 + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock
11312 +AuSimpleRwsemFuncs(fi, struct file *f, &au_fi(f)->fi_rwsem);
11314 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
11315 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
11316 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
11318 +/* ---------------------------------------------------------------------- */
11320 +/* todo: hard/soft set? */
11321 +static inline aufs_bindex_t au_fbstart(struct file *file)
11323 + FiMustAnyLock(file);
11324 + return au_fi(file)->fi_btop;
11327 +static inline aufs_bindex_t au_fbend_dir(struct file *file)
11329 + FiMustAnyLock(file);
11330 + AuDebugOn(!au_fi(file)->fi_hdir);
11331 + return au_fi(file)->fi_hdir->fd_bbot;
11334 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
11336 + FiMustAnyLock(file);
11337 + AuDebugOn(!au_fi(file)->fi_hdir);
11338 + return au_fi(file)->fi_hdir->fd_vdir_cache;
11341 +static inline void au_set_fbstart(struct file *file, aufs_bindex_t bindex)
11343 + FiMustWriteLock(file);
11344 + au_fi(file)->fi_btop = bindex;
11347 +static inline void au_set_fbend_dir(struct file *file, aufs_bindex_t bindex)
11349 + FiMustWriteLock(file);
11350 + AuDebugOn(!au_fi(file)->fi_hdir);
11351 + au_fi(file)->fi_hdir->fd_bbot = bindex;
11354 +static inline void au_set_fvdir_cache(struct file *file,
11355 + struct au_vdir *vdir_cache)
11357 + FiMustWriteLock(file);
11358 + AuDebugOn(!au_fi(file)->fi_hdir);
11359 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
11362 +static inline struct file *au_hf_top(struct file *file)
11364 + FiMustAnyLock(file);
11365 + AuDebugOn(au_fi(file)->fi_hdir);
11366 + return au_fi(file)->fi_htop.hf_file;
11369 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
11371 + FiMustAnyLock(file);
11372 + AuDebugOn(!au_fi(file)->fi_hdir);
11373 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
11376 +/* todo: memory barrier? */
11377 +static inline unsigned int au_figen(struct file *f)
11379 + return atomic_read(&au_fi(f)->fi_generation);
11382 +static inline void au_set_mmapped(struct file *f)
11384 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
11386 + pr_warn("fi_mmapped wrapped around\n");
11387 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
11391 +static inline void au_unset_mmapped(struct file *f)
11393 + atomic_dec(&au_fi(f)->fi_mmapped);
11396 +static inline int au_test_mmapped(struct file *f)
11398 + return atomic_read(&au_fi(f)->fi_mmapped);
11401 +/* customize vma->vm_file */
11403 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
11404 + struct file *file)
11408 + f = vma->vm_file;
11410 + vma->vm_file = file;
11415 +#define AuDbgVmRegion(file, vma) do {} while (0)
11417 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
11418 + struct file *file)
11420 + au_do_vm_file_reset(vma, file);
11423 +#define AuDbgVmRegion(file, vma) \
11424 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
11426 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
11427 + struct file *file)
11431 + au_do_vm_file_reset(vma, file);
11432 + f = vma->vm_region->vm_file;
11434 + vma->vm_region->vm_file = file;
11437 +#endif /* CONFIG_MMU */
11439 +/* handle vma->vm_prfile */
11440 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
11441 + struct file *file)
11443 +#ifdef CONFIG_AUFS_PROC_MAP
11445 + vma->vm_prfile = file;
11446 +#ifndef CONFIG_MMU
11448 + vma->vm_region->vm_prfile = file;
11453 +#endif /* __KERNEL__ */
11454 +#endif /* __AUFS_FILE_H__ */
11455 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
11456 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
11457 +++ linux/fs/aufs/finfo.c 2013-07-06 13:20:47.750198454 +0200
11460 + * Copyright (C) 2005-2013 Junjiro R. Okajima
11462 + * This program, aufs is free software; you can redistribute it and/or modify
11463 + * it under the terms of the GNU General Public License as published by
11464 + * the Free Software Foundation; either version 2 of the License, or
11465 + * (at your option) any later version.
11467 + * This program is distributed in the hope that it will be useful,
11468 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11469 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11470 + * GNU General Public License for more details.
11472 + * You should have received a copy of the GNU General Public License
11473 + * along with this program; if not, write to the Free Software
11474 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11478 + * file private data
11483 +void au_hfput(struct au_hfile *hf, struct file *file)
11485 + /* todo: direct access f_flags */
11486 + if (vfsub_file_flags(file) & __FMODE_EXEC)
11487 + allow_write_access(hf->hf_file);
11488 + fput(hf->hf_file);
11489 + hf->hf_file = NULL;
11490 + atomic_dec(&hf->hf_br->br_count);
11491 + hf->hf_br = NULL;
11494 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
11496 + struct au_finfo *finfo = au_fi(file);
11497 + struct au_hfile *hf;
11498 + struct au_fidir *fidir;
11500 + fidir = finfo->fi_hdir;
11502 + AuDebugOn(finfo->fi_btop != bindex);
11503 + hf = &finfo->fi_htop;
11505 + hf = fidir->fd_hfile + bindex;
11507 + if (hf && hf->hf_file)
11508 + au_hfput(hf, file);
11510 + FiMustWriteLock(file);
11511 + hf->hf_file = val;
11512 + hf->hf_br = au_sbr(file->f_dentry->d_sb, bindex);
11516 +void au_update_figen(struct file *file)
11518 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_dentry));
11519 + /* smp_mb(); */ /* atomic_set */
11522 +/* ---------------------------------------------------------------------- */
11524 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
11526 + struct au_fidir *fidir;
11529 + nbr = au_sbend(sb) + 1;
11531 + nbr = 2; /* initial allocate for 2 branches */
11532 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
11534 + fidir->fd_bbot = -1;
11535 + fidir->fd_nent = nbr;
11536 + fidir->fd_vdir_cache = NULL;
11542 +int au_fidir_realloc(struct au_finfo *finfo, int nbr)
11545 + struct au_fidir *fidir, *p;
11547 + AuRwMustWriteLock(&finfo->fi_rwsem);
11548 + fidir = finfo->fi_hdir;
11549 + AuDebugOn(!fidir);
11552 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
11555 + p->fd_nent = nbr;
11556 + finfo->fi_hdir = p;
11563 +/* ---------------------------------------------------------------------- */
11565 +void au_finfo_fin(struct file *file)
11567 + struct au_finfo *finfo;
11569 + au_nfiles_dec(file->f_dentry->d_sb);
11571 + finfo = au_fi(file);
11572 + AuDebugOn(finfo->fi_hdir);
11573 + AuRwDestroy(&finfo->fi_rwsem);
11574 + au_cache_free_finfo(finfo);
11577 +void au_fi_init_once(void *_finfo)
11579 + struct au_finfo *finfo = _finfo;
11580 + static struct lock_class_key aufs_fi;
11582 + au_rw_init(&finfo->fi_rwsem);
11583 + au_rw_class(&finfo->fi_rwsem, &aufs_fi);
11586 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
11589 + struct au_finfo *finfo;
11590 + struct dentry *dentry;
11593 + dentry = file->f_dentry;
11594 + finfo = au_cache_alloc_finfo();
11595 + if (unlikely(!finfo))
11599 + au_nfiles_inc(dentry->d_sb);
11600 + /* verbose coding for lock class name */
11602 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcNonDir_FIINFO);
11604 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcDir_FIINFO);
11605 + au_rw_write_lock(&finfo->fi_rwsem);
11606 + finfo->fi_btop = -1;
11607 + finfo->fi_hdir = fidir;
11608 + atomic_set(&finfo->fi_generation, au_digen(dentry));
11609 + /* smp_mb(); */ /* atomic_set */
11611 + file->private_data = finfo;
11616 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
11617 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
11618 +++ linux/fs/aufs/f_op.c 2013-10-26 16:51:32.273040419 +0200
11621 + * Copyright (C) 2005-2013 Junjiro R. Okajima
11623 + * This program, aufs is free software; you can redistribute it and/or modify
11624 + * it under the terms of the GNU General Public License as published by
11625 + * the Free Software Foundation; either version 2 of the License, or
11626 + * (at your option) any later version.
11628 + * This program is distributed in the hope that it will be useful,
11629 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11630 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11631 + * GNU General Public License for more details.
11633 + * You should have received a copy of the GNU General Public License
11634 + * along with this program; if not, write to the Free Software
11635 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11639 + * file and vm operations
11642 +#include <linux/aio.h>
11643 +#include <linux/fs_stack.h>
11644 +#include <linux/mman.h>
11645 +#include <linux/security.h>
11648 +int au_do_open_nondir(struct file *file, int flags)
11651 + aufs_bindex_t bindex;
11652 + struct file *h_file;
11653 + struct dentry *dentry;
11654 + struct au_finfo *finfo;
11656 + FiMustWriteLock(file);
11658 + dentry = file->f_dentry;
11659 + err = au_d_alive(dentry);
11660 + if (unlikely(err))
11663 + finfo = au_fi(file);
11664 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
11665 + atomic_set(&finfo->fi_mmapped, 0);
11666 + bindex = au_dbstart(dentry);
11667 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
11668 + if (IS_ERR(h_file))
11669 + err = PTR_ERR(h_file);
11671 + au_set_fbstart(file, bindex);
11672 + au_set_h_fptr(file, bindex, h_file);
11673 + au_update_figen(file);
11674 + if (!(file->f_mode & FMODE_WRITE)) {
11675 + lg_local_lock(&files_lglock);
11676 + __file_sb_list_add(file, dentry->d_sb);
11677 + lg_local_unlock(&files_lglock);
11679 + /* todo: necessary? */
11680 + /* file->f_ra = h_file->f_ra; */
11687 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
11688 + struct file *file)
11691 + struct super_block *sb;
11693 + AuDbg("%.*s, f_flags 0x%x, f_mode 0x%x\n",
11694 + AuDLNPair(file->f_dentry), vfsub_file_flags(file),
11697 + sb = file->f_dentry->d_sb;
11698 + si_read_lock(sb, AuLock_FLUSH);
11699 + err = au_do_open(file, au_do_open_nondir, /*fidir*/NULL);
11700 + si_read_unlock(sb);
11704 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
11706 + struct au_finfo *finfo;
11707 + aufs_bindex_t bindex;
11709 + finfo = au_fi(file);
11710 + bindex = finfo->fi_btop;
11712 + au_set_h_fptr(file, bindex, NULL);
11714 + au_finfo_fin(file);
11718 +/* ---------------------------------------------------------------------- */
11720 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
11723 + struct file *h_file;
11726 + h_file = au_hf_top(file);
11728 + err = vfsub_flush(h_file, id);
11732 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
11734 + return au_do_flush(file, id, au_do_flush_nondir);
11737 +/* ---------------------------------------------------------------------- */
11739 + * read and write functions acquire [fdi]_rwsem once, but release before
11740 + * mmap_sem. This is because to stop a race condition between mmap(2).
11741 + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping
11742 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
11743 + * read functions after [fdi]_rwsem are released, but it should be harmless.
11746 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
11750 + struct dentry *dentry;
11751 + struct file *h_file;
11752 + struct super_block *sb;
11754 + dentry = file->f_dentry;
11755 + sb = dentry->d_sb;
11756 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11757 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
11758 + if (unlikely(err))
11761 + h_file = au_hf_top(file);
11762 + get_file(h_file);
11763 + di_read_unlock(dentry, AuLock_IR);
11764 + fi_read_unlock(file);
11766 + /* filedata may be obsoleted by concurrent copyup, but no problem */
11767 + err = vfsub_read_u(h_file, buf, count, ppos);
11768 + /* todo: necessary? */
11769 + /* file->f_ra = h_file->f_ra; */
11770 + /* update without lock, I don't think it a problem */
11771 + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
11775 + si_read_unlock(sb);
11780 + * todo: very ugly
11781 + * it locks both of i_mutex and si_rwsem for read in safe.
11782 + * if the plink maintenance mode continues forever (that is the problem),
11783 + * may loop forever.
11785 +static void au_mtx_and_read_lock(struct inode *inode)
11788 + struct super_block *sb = inode->i_sb;
11791 + mutex_lock(&inode->i_mutex);
11792 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
11795 + mutex_unlock(&inode->i_mutex);
11796 + si_read_lock(sb, AuLock_NOPLMW);
11797 + si_read_unlock(sb);
11801 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
11802 + size_t count, loff_t *ppos)
11805 + struct au_pin pin;
11806 + struct dentry *dentry;
11807 + struct super_block *sb;
11808 + struct inode *inode;
11809 + struct file *h_file;
11810 + char __user *buf = (char __user *)ubuf;
11812 + dentry = file->f_dentry;
11813 + sb = dentry->d_sb;
11814 + inode = dentry->d_inode;
11815 + au_mtx_and_read_lock(inode);
11817 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
11818 + if (unlikely(err))
11821 + err = au_ready_to_write(file, -1, &pin);
11822 + di_downgrade_lock(dentry, AuLock_IR);
11823 + if (unlikely(err)) {
11824 + di_read_unlock(dentry, AuLock_IR);
11825 + fi_write_unlock(file);
11829 + h_file = au_hf_top(file);
11830 + get_file(h_file);
11832 + di_read_unlock(dentry, AuLock_IR);
11833 + fi_write_unlock(file);
11835 + err = vfsub_write_u(h_file, buf, count, ppos);
11836 + ii_write_lock_child(inode);
11837 + au_cpup_attr_timesizes(inode);
11838 + inode->i_mode = file_inode(h_file)->i_mode;
11839 + ii_write_unlock(inode);
11843 + si_read_unlock(sb);
11844 + mutex_unlock(&inode->i_mutex);
11848 +static ssize_t au_do_aio(struct file *h_file, int rw, struct kiocb *kio,
11849 + const struct iovec *iov, unsigned long nv, loff_t pos)
11852 + struct file *file;
11853 + ssize_t (*func)(struct kiocb *, const struct iovec *, unsigned long,
11856 + err = security_file_permission(h_file, rw);
11857 + if (unlikely(err))
11862 + if (rw == MAY_READ)
11863 + func = h_file->f_op->aio_read;
11864 + else if (rw == MAY_WRITE)
11865 + func = h_file->f_op->aio_write;
11867 + file = kio->ki_filp;
11868 + kio->ki_filp = h_file;
11870 + err = func(kio, iov, nv, pos);
11872 + kio->ki_filp = file;
11874 + /* currently there is no such fs */
11881 +static ssize_t aufs_aio_read(struct kiocb *kio, const struct iovec *iov,
11882 + unsigned long nv, loff_t pos)
11885 + struct file *file, *h_file;
11886 + struct dentry *dentry;
11887 + struct super_block *sb;
11889 + file = kio->ki_filp;
11890 + dentry = file->f_dentry;
11891 + sb = dentry->d_sb;
11892 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11893 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
11894 + if (unlikely(err))
11897 + h_file = au_hf_top(file);
11898 + get_file(h_file);
11899 + di_read_unlock(dentry, AuLock_IR);
11900 + fi_read_unlock(file);
11902 + err = au_do_aio(h_file, MAY_READ, kio, iov, nv, pos);
11903 + /* todo: necessary? */
11904 + /* file->f_ra = h_file->f_ra; */
11905 + /* update without lock, I don't think it a problem */
11906 + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
11910 + si_read_unlock(sb);
11914 +static ssize_t aufs_aio_write(struct kiocb *kio, const struct iovec *iov,
11915 + unsigned long nv, loff_t pos)
11918 + struct au_pin pin;
11919 + struct dentry *dentry;
11920 + struct inode *inode;
11921 + struct file *file, *h_file;
11922 + struct super_block *sb;
11924 + file = kio->ki_filp;
11925 + dentry = file->f_dentry;
11926 + sb = dentry->d_sb;
11927 + inode = dentry->d_inode;
11928 + au_mtx_and_read_lock(inode);
11930 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
11931 + if (unlikely(err))
11934 + err = au_ready_to_write(file, -1, &pin);
11935 + di_downgrade_lock(dentry, AuLock_IR);
11936 + if (unlikely(err)) {
11937 + di_read_unlock(dentry, AuLock_IR);
11938 + fi_write_unlock(file);
11942 + h_file = au_hf_top(file);
11943 + get_file(h_file);
11945 + di_read_unlock(dentry, AuLock_IR);
11946 + fi_write_unlock(file);
11948 + err = au_do_aio(h_file, MAY_WRITE, kio, iov, nv, pos);
11949 + ii_write_lock_child(inode);
11950 + au_cpup_attr_timesizes(inode);
11951 + inode->i_mode = file_inode(h_file)->i_mode;
11952 + ii_write_unlock(inode);
11956 + si_read_unlock(sb);
11957 + mutex_unlock(&inode->i_mutex);
11961 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
11962 + struct pipe_inode_info *pipe, size_t len,
11963 + unsigned int flags)
11966 + struct file *h_file;
11967 + struct dentry *dentry;
11968 + struct super_block *sb;
11970 + dentry = file->f_dentry;
11971 + sb = dentry->d_sb;
11972 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11973 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
11974 + if (unlikely(err))
11978 + h_file = au_hf_top(file);
11979 + get_file(h_file);
11980 + if (au_test_loopback_kthread()) {
11981 + au_warn_loopback(h_file->f_dentry->d_sb);
11982 + if (file->f_mapping != h_file->f_mapping) {
11983 + file->f_mapping = h_file->f_mapping;
11984 + smp_mb(); /* unnecessary? */
11987 + di_read_unlock(dentry, AuLock_IR);
11988 + fi_read_unlock(file);
11990 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
11991 + /* todo: necessasry? */
11992 + /* file->f_ra = h_file->f_ra; */
11993 + /* update without lock, I don't think it a problem */
11994 + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
11998 + si_read_unlock(sb);
12003 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
12004 + size_t len, unsigned int flags)
12007 + struct au_pin pin;
12008 + struct dentry *dentry;
12009 + struct inode *inode;
12010 + struct file *h_file;
12011 + struct super_block *sb;
12013 + dentry = file->f_dentry;
12014 + sb = dentry->d_sb;
12015 + inode = dentry->d_inode;
12016 + au_mtx_and_read_lock(inode);
12018 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
12019 + if (unlikely(err))
12022 + err = au_ready_to_write(file, -1, &pin);
12023 + di_downgrade_lock(dentry, AuLock_IR);
12024 + if (unlikely(err)) {
12025 + di_read_unlock(dentry, AuLock_IR);
12026 + fi_write_unlock(file);
12030 + h_file = au_hf_top(file);
12031 + get_file(h_file);
12033 + di_read_unlock(dentry, AuLock_IR);
12034 + fi_write_unlock(file);
12036 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
12037 + ii_write_lock_child(inode);
12038 + au_cpup_attr_timesizes(inode);
12039 + inode->i_mode = file_inode(h_file)->i_mode;
12040 + ii_write_unlock(inode);
12044 + si_read_unlock(sb);
12045 + mutex_unlock(&inode->i_mutex);
12049 +/* ---------------------------------------------------------------------- */
12052 + * The locking order around current->mmap_sem.
12053 + * - in most and regular cases
12054 + * file I/O syscall -- aufs_read() or something
12055 + * -- si_rwsem for read -- mmap_sem
12056 + * (Note that [fdi]i_rwsem are released before mmap_sem).
12058 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
12059 + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
12060 + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
12061 + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
12062 + * It means that when aufs acquires si_rwsem for write, the process should never
12063 + * acquire mmap_sem.
12065 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
12066 + * problem either since any directory is not able to be mmap-ed.
12067 + * The similar scenario is applied to aufs_readlink() too.
12070 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
12071 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
12073 +static unsigned long au_arch_prot_conv(unsigned long flags)
12075 + /* currently ppc64 only */
12076 +#ifdef CONFIG_PPC64
12077 + /* cf. linux/arch/powerpc/include/asm/mman.h */
12078 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
12079 + return AuConv_VM_PROT(flags, SAO);
12081 + AuDebugOn(arch_calc_vm_prot_bits(-1));
12086 +static unsigned long au_prot_conv(unsigned long flags)
12088 + return AuConv_VM_PROT(flags, READ)
12089 + | AuConv_VM_PROT(flags, WRITE)
12090 + | AuConv_VM_PROT(flags, EXEC)
12091 + | au_arch_prot_conv(flags);
12094 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
12095 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
12097 +static unsigned long au_flag_conv(unsigned long flags)
12099 + return AuConv_VM_MAP(flags, GROWSDOWN)
12100 + | AuConv_VM_MAP(flags, DENYWRITE)
12101 + | AuConv_VM_MAP(flags, LOCKED);
12104 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
12107 + aufs_bindex_t bstart;
12108 + const unsigned char wlock
12109 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
12110 + struct dentry *dentry;
12111 + struct super_block *sb;
12112 + struct file *h_file;
12113 + struct au_branch *br;
12114 + struct au_pin pin;
12116 + AuDbgVmRegion(file, vma);
12118 + dentry = file->f_dentry;
12119 + sb = dentry->d_sb;
12121 + si_read_lock(sb, AuLock_NOPLMW);
12122 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
12123 + if (unlikely(err))
12127 + err = au_ready_to_write(file, -1, &pin);
12128 + di_write_unlock(dentry);
12129 + if (unlikely(err)) {
12130 + fi_write_unlock(file);
12135 + di_write_unlock(dentry);
12137 + bstart = au_fbstart(file);
12138 + br = au_sbr(sb, bstart);
12139 + h_file = au_hf_top(file);
12140 + get_file(h_file);
12141 + au_set_mmapped(file);
12142 + fi_write_unlock(file);
12145 + au_vm_file_reset(vma, h_file);
12146 + err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
12147 + au_flag_conv(vma->vm_flags));
12149 + err = h_file->f_op->mmap(h_file, vma);
12150 + if (unlikely(err))
12153 + au_vm_prfile_set(vma, file);
12154 + /* update without lock, I don't think it a problem */
12155 + fsstack_copy_attr_atime(file_inode(file), file_inode(h_file));
12156 + goto out_fput; /* success */
12159 + au_unset_mmapped(file);
12160 + au_vm_file_reset(vma, file);
12165 + si_read_unlock(sb);
12171 +/* ---------------------------------------------------------------------- */
12173 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
12177 + struct au_pin pin;
12178 + struct dentry *dentry;
12179 + struct inode *inode;
12180 + struct file *h_file;
12181 + struct super_block *sb;
12183 + dentry = file->f_dentry;
12184 + inode = dentry->d_inode;
12185 + sb = dentry->d_sb;
12186 + mutex_lock(&inode->i_mutex);
12187 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
12188 + if (unlikely(err))
12191 + err = 0; /* -EBADF; */ /* posix? */
12192 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
12194 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
12195 + if (unlikely(err))
12198 + err = au_ready_to_write(file, -1, &pin);
12199 + di_downgrade_lock(dentry, AuLock_IR);
12200 + if (unlikely(err))
12205 + h_file = au_hf_top(file);
12206 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
12207 + au_cpup_attr_timesizes(inode);
12210 + di_read_unlock(dentry, AuLock_IR);
12211 + fi_write_unlock(file);
12213 + si_read_unlock(sb);
12215 + mutex_unlock(&inode->i_mutex);
12219 +/* no one supports this operation, currently */
12221 +static int aufs_aio_fsync_nondir(struct kiocb *kio, int datasync)
12224 + struct au_pin pin;
12225 + struct dentry *dentry;
12226 + struct inode *inode;
12227 + struct file *file, *h_file;
12229 + file = kio->ki_filp;
12230 + dentry = file->f_dentry;
12231 + inode = dentry->d_inode;
12232 + au_mtx_and_read_lock(inode);
12234 + err = 0; /* -EBADF; */ /* posix? */
12235 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
12237 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
12238 + if (unlikely(err))
12241 + err = au_ready_to_write(file, -1, &pin);
12242 + di_downgrade_lock(dentry, AuLock_IR);
12243 + if (unlikely(err))
12248 + h_file = au_hf_top(file);
12249 + if (h_file->f_op && h_file->f_op->aio_fsync) {
12250 + struct mutex *h_mtx;
12252 + h_mtx = &file_inode(h_file)->i_mutex;
12253 + if (!is_sync_kiocb(kio)) {
12254 + get_file(h_file);
12257 + kio->ki_filp = h_file;
12258 + err = h_file->f_op->aio_fsync(kio, datasync);
12259 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
12261 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL);
12263 + au_cpup_attr_timesizes(inode);
12264 + mutex_unlock(h_mtx);
12268 + di_read_unlock(dentry, AuLock_IR);
12269 + fi_write_unlock(file);
12271 + si_read_unlock(inode->sb);
12272 + mutex_unlock(&inode->i_mutex);
12277 +static int aufs_fasync(int fd, struct file *file, int flag)
12280 + struct file *h_file;
12281 + struct dentry *dentry;
12282 + struct super_block *sb;
12284 + dentry = file->f_dentry;
12285 + sb = dentry->d_sb;
12286 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
12287 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
12288 + if (unlikely(err))
12291 + h_file = au_hf_top(file);
12292 + if (h_file->f_op && h_file->f_op->fasync)
12293 + err = h_file->f_op->fasync(fd, h_file, flag);
12295 + di_read_unlock(dentry, AuLock_IR);
12296 + fi_read_unlock(file);
12299 + si_read_unlock(sb);
12303 +/* ---------------------------------------------------------------------- */
12305 +/* no one supports this operation, currently */
12307 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
12308 + size_t len, loff_t *pos , int more)
12313 +/* ---------------------------------------------------------------------- */
12315 +const struct file_operations aufs_file_fop = {
12316 + .owner = THIS_MODULE,
12318 + .llseek = default_llseek,
12320 + .read = aufs_read,
12321 + .write = aufs_write,
12322 + .aio_read = aufs_aio_read,
12323 + .aio_write = aufs_aio_write,
12324 +#ifdef CONFIG_AUFS_POLL
12325 + .poll = aufs_poll,
12327 + .unlocked_ioctl = aufs_ioctl_nondir,
12328 +#ifdef CONFIG_COMPAT
12329 + .compat_ioctl = aufs_compat_ioctl_nondir,
12331 + .mmap = aufs_mmap,
12332 + .open = aufs_open_nondir,
12333 + .flush = aufs_flush_nondir,
12334 + .release = aufs_release_nondir,
12335 + .fsync = aufs_fsync_nondir,
12336 + /* .aio_fsync = aufs_aio_fsync_nondir, */
12337 + .fasync = aufs_fasync,
12338 + /* .sendpage = aufs_sendpage, */
12339 + .splice_write = aufs_splice_write,
12340 + .splice_read = aufs_splice_read,
12342 + .aio_splice_write = aufs_aio_splice_write,
12343 + .aio_splice_read = aufs_aio_splice_read
12346 diff -urN /usr/share/empty/fs/aufs/f_op_sp.c linux/fs/aufs/f_op_sp.c
12347 --- /usr/share/empty/fs/aufs/f_op_sp.c 1970-01-01 01:00:00.000000000 +0100
12348 +++ linux/fs/aufs/f_op_sp.c 2013-10-26 16:51:32.273040419 +0200
12351 + * Copyright (C) 2005-2013 Junjiro R. Okajima
12353 + * This program, aufs is free software; you can redistribute it and/or modify
12354 + * it under the terms of the GNU General Public License as published by
12355 + * the Free Software Foundation; either version 2 of the License, or
12356 + * (at your option) any later version.
12358 + * This program is distributed in the hope that it will be useful,
12359 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12360 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12361 + * GNU General Public License for more details.
12363 + * You should have received a copy of the GNU General Public License
12364 + * along with this program; if not, write to the Free Software
12365 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
12369 + * file operations for special files.
12370 + * while they exist in aufs virtually,
12371 + * their file I/O is handled out of aufs.
12374 +#include <linux/aio.h>
12378 + * I don't think the size of this list grows much.
12379 + * so here is a very simple list implemented in order to find finfo matching a
12382 +static struct au_sphlhead au_finfo_sp = {
12383 + .spin = __SPIN_LOCK_INITIALIZER(au_finfo_sp.spin),
12384 + .head = HLIST_HEAD_INIT
12387 +struct au_finfo_sp {
12388 + struct hlist_node hlist;
12389 + struct file *file;
12390 + struct au_finfo *finfo;
12393 +struct au_finfo *au_fi_sp(struct file *file)
12395 + struct au_finfo *finfo;
12396 + struct au_finfo_sp *sp;
12399 + spin_lock(&au_finfo_sp.spin);
12400 + hlist_for_each_entry(sp, &au_finfo_sp.head, hlist) {
12401 + if (sp->file != file)
12403 + finfo = sp->finfo;
12406 + spin_unlock(&au_finfo_sp.spin);
12411 +static int au_fi_sp_add(struct file *file)
12414 + struct au_finfo_sp *sp;
12417 + sp = kmalloc(sizeof(*sp), GFP_NOFS);
12421 + sp->finfo = file->private_data;
12422 + spin_lock(&au_finfo_sp.spin);
12423 + hlist_add_head(&sp->hlist, &au_finfo_sp.head);
12424 + spin_unlock(&au_finfo_sp.spin);
12429 +static void au_fi_sp_del(struct file *file)
12431 + struct au_finfo_sp *sp, *do_free;
12434 + spin_lock(&au_finfo_sp.spin);
12435 + hlist_for_each_entry(sp, &au_finfo_sp.head, hlist) {
12436 + if (sp->file != file)
12438 + hlist_del(&sp->hlist);
12442 + spin_unlock(&au_finfo_sp.spin);
12446 +/* ---------------------------------------------------------------------- */
12448 +static ssize_t aufs_aio_read_sp(struct kiocb *kio, const struct iovec *iov,
12449 + unsigned long nv, loff_t pos)
12452 + aufs_bindex_t bstart;
12453 + unsigned char wbr;
12454 + struct file *file, *h_file;
12455 + struct super_block *sb;
12457 + file = kio->ki_filp;
12458 + sb = file->f_dentry->d_sb;
12459 + si_read_lock(sb, AuLock_FLUSH);
12460 + fi_read_lock(file);
12461 + bstart = au_fbstart(file);
12462 + h_file = au_hf_top(file);
12463 + fi_read_unlock(file);
12464 + wbr = !!au_br_writable(au_sbr(sb, bstart)->br_perm);
12465 + si_read_unlock(sb);
12467 + /* do not change the file in kio */
12468 + AuDebugOn(!h_file->f_op || !h_file->f_op->aio_read);
12469 + err = h_file->f_op->aio_read(kio, iov, nv, pos);
12470 + if (err > 0 && wbr)
12471 + file_accessed(h_file);
12476 +static ssize_t aufs_aio_write_sp(struct kiocb *kio, const struct iovec *iov,
12477 + unsigned long nv, loff_t pos)
12480 + aufs_bindex_t bstart;
12481 + unsigned char wbr;
12482 + struct super_block *sb;
12483 + struct file *file, *h_file;
12485 + file = kio->ki_filp;
12486 + sb = file->f_dentry->d_sb;
12487 + si_read_lock(sb, AuLock_FLUSH);
12488 + fi_read_lock(file);
12489 + bstart = au_fbstart(file);
12490 + h_file = au_hf_top(file);
12491 + fi_read_unlock(file);
12492 + wbr = !!au_br_writable(au_sbr(sb, bstart)->br_perm);
12493 + si_read_unlock(sb);
12495 + /* do not change the file in kio */
12496 + AuDebugOn(!h_file->f_op || !h_file->f_op->aio_write);
12497 + err = h_file->f_op->aio_write(kio, iov, nv, pos);
12501 +/* ---------------------------------------------------------------------- */
12503 +static int aufs_release_sp(struct inode *inode, struct file *file)
12506 + struct file *h_file;
12508 + fi_read_lock(file);
12509 + h_file = au_hf_top(file);
12510 + fi_read_unlock(file);
12511 + /* close this fifo in aufs */
12512 + err = h_file->f_op->release(inode, file); /* ignore */
12513 + aufs_release_nondir(inode, file); /* ignore */
12514 + au_fi_sp_del(file);
12518 +/* ---------------------------------------------------------------------- */
12520 +/* currently, support only FIFO */
12522 + AuSp_FIFO, AuSp_FIFO_R, AuSp_FIFO_W, AuSp_FIFO_RW,
12523 + /* AuSp_SOCK, AuSp_CHR, AuSp_BLK, */
12526 +static int aufs_open_sp(struct inode *inode, struct file *file);
12527 +static struct au_sp_fop {
12529 + struct file_operations fop; /* not 'const' */
12531 +} au_sp_fop[AuSp_Last] = {
12534 + .owner = THIS_MODULE,
12535 + .open = aufs_open_sp
12540 +static void au_init_fop_sp(struct file *file)
12542 + struct au_sp_fop *p;
12544 + struct file *h_file;
12547 + if (unlikely(!p->done)) {
12548 + /* initialize first time only */
12549 + static DEFINE_SPINLOCK(spin);
12551 + spin_lock(&spin);
12553 + BUILD_BUG_ON(sizeof(au_sp_fop)/sizeof(*au_sp_fop)
12555 + for (i = 0; i < AuSp_Last; i++)
12556 + spin_lock_init(&p[i].spin);
12559 + spin_unlock(&spin);
12562 + switch (file->f_mode & (FMODE_READ | FMODE_WRITE)) {
12566 + case FMODE_WRITE:
12569 + case FMODE_READ | FMODE_WRITE:
12570 + i = AuSp_FIFO_RW;
12577 + if (unlikely(!p->done)) {
12578 + /* initialize first time only */
12579 + h_file = au_hf_top(file);
12580 + spin_lock(&p->spin);
12582 + p->fop = *h_file->f_op;
12583 + p->fop.owner = THIS_MODULE;
12584 + if (p->fop.aio_read)
12585 + p->fop.aio_read = aufs_aio_read_sp;
12586 + if (p->fop.aio_write)
12587 + p->fop.aio_write = aufs_aio_write_sp;
12588 + p->fop.release = aufs_release_sp;
12591 + spin_unlock(&p->spin);
12593 + file->f_op = &p->fop;
12596 +static int au_cpup_sp(struct dentry *dentry)
12599 + struct au_pin pin;
12600 + struct au_wr_dir_args wr_dir_args = {
12601 + .force_btgt = -1,
12604 + struct au_cp_generic cpg = {
12605 + .dentry = dentry,
12610 + .flags = AuCpup_DTIME
12613 + AuDbg("%.*s\n", AuDLNPair(dentry));
12615 + di_read_unlock(dentry, AuLock_IR);
12616 + di_write_lock_child(dentry);
12617 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
12618 + if (unlikely(err < 0))
12622 + if (cpg.bdst == au_dbstart(dentry))
12623 + goto out; /* success */
12625 + err = au_pin(&pin, dentry, cpg.bdst, au_opt_udba(dentry->d_sb),
12626 + AuPin_MNT_WRITE);
12628 + err = au_sio_cpup_simple(&cpg);
12633 + di_downgrade_lock(dentry, AuLock_IR);
12637 +static int au_do_open_sp(struct file *file, int flags)
12640 + struct dentry *dentry;
12641 + struct super_block *sb;
12642 + struct file *h_file;
12643 + struct inode *h_inode;
12645 + err = au_fi_sp_add(file);
12646 + if (unlikely(err))
12649 + dentry = file->f_dentry;
12650 + AuDbg("%.*s\n", AuDLNPair(dentry));
12653 + * try copying-up.
12654 + * operate on the ro branch is not an error.
12656 + au_cpup_sp(dentry); /* ignore */
12658 + /* prepare h_file */
12659 + err = au_do_open_nondir(file, vfsub_file_flags(file));
12660 + if (unlikely(err))
12663 + sb = dentry->d_sb;
12664 + h_file = au_hf_top(file);
12665 + h_inode = file_inode(h_file);
12666 + di_read_unlock(dentry, AuLock_IR);
12667 + fi_write_unlock(file);
12668 + si_read_unlock(sb);
12669 + /* open this fifo in aufs */
12670 + err = h_inode->i_fop->open(file_inode(file), file);
12671 + si_noflush_read_lock(sb);
12672 + fi_write_lock(file);
12673 + di_read_lock_child(dentry, AuLock_IR);
12675 + au_init_fop_sp(file);
12676 + goto out; /* success */
12680 + au_fi_sp_del(file);
12685 +static int aufs_open_sp(struct inode *inode, struct file *file)
12688 + struct super_block *sb;
12690 + sb = file->f_dentry->d_sb;
12691 + si_read_lock(sb, AuLock_FLUSH);
12692 + err = au_do_open(file, au_do_open_sp, /*fidir*/NULL);
12693 + si_read_unlock(sb);
12697 +/* ---------------------------------------------------------------------- */
12699 +void au_init_special_fop(struct inode *inode, umode_t mode, dev_t rdev)
12701 + init_special_inode(inode, mode, rdev);
12703 + switch (mode & S_IFMT) {
12705 + inode->i_fop = &au_sp_fop[AuSp_FIFO].fop;
12716 +int au_special_file(umode_t mode)
12721 + switch (mode & S_IFMT) {
12733 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
12734 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
12735 +++ linux/fs/aufs/fstype.h 2013-10-26 16:51:32.273040419 +0200
12738 + * Copyright (C) 2005-2013 Junjiro R. Okajima
12740 + * This program, aufs is free software; you can redistribute it and/or modify
12741 + * it under the terms of the GNU General Public License as published by
12742 + * the Free Software Foundation; either version 2 of the License, or
12743 + * (at your option) any later version.
12745 + * This program is distributed in the hope that it will be useful,
12746 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12747 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12748 + * GNU General Public License for more details.
12750 + * You should have received a copy of the GNU General Public License
12751 + * along with this program; if not, write to the Free Software
12752 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
12756 + * judging filesystem type
12759 +#ifndef __AUFS_FSTYPE_H__
12760 +#define __AUFS_FSTYPE_H__
12764 +#include <linux/fs.h>
12765 +#include <linux/magic.h>
12766 +#include <linux/romfs_fs.h>
12768 +static inline int au_test_aufs(struct super_block *sb)
12770 + return sb->s_magic == AUFS_SUPER_MAGIC;
12773 +static inline const char *au_sbtype(struct super_block *sb)
12775 + return sb->s_type->name;
12778 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
12780 +#if defined(CONFIG_ROMFS_FS) || defined(CONFIG_ROMFS_FS_MODULE)
12781 + return sb->s_magic == ROMFS_MAGIC;
12787 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
12789 +#if defined(CONFIG_ISO9660_FS) || defined(CONFIG_ISO9660_FS_MODULE)
12790 + return sb->s_magic == ISOFS_SUPER_MAGIC;
12796 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
12798 +#if defined(CONFIG_CRAMFS) || defined(CONFIG_CRAMFS_MODULE)
12799 + return sb->s_magic == CRAMFS_MAGIC;
12804 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
12806 +#if defined(CONFIG_NFS_FS) || defined(CONFIG_NFS_FS_MODULE)
12807 + return sb->s_magic == NFS_SUPER_MAGIC;
12813 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
12815 +#if defined(CONFIG_FUSE_FS) || defined(CONFIG_FUSE_FS_MODULE)
12816 + return sb->s_magic == FUSE_SUPER_MAGIC;
12822 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
12824 +#if defined(CONFIG_XFS_FS) || defined(CONFIG_XFS_FS_MODULE)
12825 + return sb->s_magic == XFS_SB_MAGIC;
12831 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
12833 +#ifdef CONFIG_TMPFS
12834 + return sb->s_magic == TMPFS_MAGIC;
12840 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
12842 +#if defined(CONFIG_ECRYPT_FS) || defined(CONFIG_ECRYPT_FS_MODULE)
12843 + return !strcmp(au_sbtype(sb), "ecryptfs");
12849 +static inline int au_test_ocfs2(struct super_block *sb __maybe_unused)
12851 +#if defined(CONFIG_OCFS2_FS) || defined(CONFIG_OCFS2_FS_MODULE)
12852 + return sb->s_magic == OCFS2_SUPER_MAGIC;
12858 +static inline int au_test_ocfs2_dlmfs(struct super_block *sb __maybe_unused)
12860 +#if defined(CONFIG_OCFS2_FS_O2CB) || defined(CONFIG_OCFS2_FS_O2CB_MODULE)
12861 + return sb->s_magic == DLMFS_MAGIC;
12867 +static inline int au_test_coda(struct super_block *sb __maybe_unused)
12869 +#if defined(CONFIG_CODA_FS) || defined(CONFIG_CODA_FS_MODULE)
12870 + return sb->s_magic == CODA_SUPER_MAGIC;
12876 +static inline int au_test_v9fs(struct super_block *sb __maybe_unused)
12878 +#if defined(CONFIG_9P_FS) || defined(CONFIG_9P_FS_MODULE)
12879 + return sb->s_magic == V9FS_MAGIC;
12885 +static inline int au_test_ext4(struct super_block *sb __maybe_unused)
12887 +#if defined(CONFIG_EXT4_FS) || defined(CONFIG_EXT4_FS_MODULE)
12888 + return sb->s_magic == EXT4_SUPER_MAGIC;
12894 +static inline int au_test_sysv(struct super_block *sb __maybe_unused)
12896 +#if defined(CONFIG_SYSV_FS) || defined(CONFIG_SYSV_FS_MODULE)
12897 + return !strcmp(au_sbtype(sb), "sysv");
12903 +static inline int au_test_ramfs(struct super_block *sb)
12905 + return sb->s_magic == RAMFS_MAGIC;
12908 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
12910 +#if defined(CONFIG_UBIFS_FS) || defined(CONFIG_UBIFS_FS_MODULE)
12911 + return sb->s_magic == UBIFS_SUPER_MAGIC;
12917 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
12919 +#ifdef CONFIG_PROC_FS
12920 + return sb->s_magic == PROC_SUPER_MAGIC;
12926 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
12928 +#ifdef CONFIG_SYSFS
12929 + return sb->s_magic == SYSFS_MAGIC;
12935 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
12937 +#if defined(CONFIG_CONFIGFS_FS) || defined(CONFIG_CONFIGFS_FS_MODULE)
12938 + return sb->s_magic == CONFIGFS_MAGIC;
12944 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
12946 +#if defined(CONFIG_MINIX_FS) || defined(CONFIG_MINIX_FS_MODULE)
12947 + return sb->s_magic == MINIX3_SUPER_MAGIC
12948 + || sb->s_magic == MINIX2_SUPER_MAGIC
12949 + || sb->s_magic == MINIX2_SUPER_MAGIC2
12950 + || sb->s_magic == MINIX_SUPER_MAGIC
12951 + || sb->s_magic == MINIX_SUPER_MAGIC2;
12957 +static inline int au_test_cifs(struct super_block *sb __maybe_unused)
12959 +#if defined(CONFIG_CIFS_FS) || defined(CONFIGCIFS_FS_MODULE)
12960 + return sb->s_magic == CIFS_MAGIC_NUMBER;
12966 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
12968 +#if defined(CONFIG_FAT_FS) || defined(CONFIG_FAT_FS_MODULE)
12969 + return sb->s_magic == MSDOS_SUPER_MAGIC;
12975 +static inline int au_test_msdos(struct super_block *sb)
12977 + return au_test_fat(sb);
12980 +static inline int au_test_vfat(struct super_block *sb)
12982 + return au_test_fat(sb);
12985 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
12987 +#ifdef CONFIG_SECURITYFS
12988 + return sb->s_magic == SECURITYFS_MAGIC;
12994 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
12996 +#if defined(CONFIG_SQUASHFS) || defined(CONFIG_SQUASHFS_MODULE)
12997 + return sb->s_magic == SQUASHFS_MAGIC;
13003 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
13005 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
13006 + return sb->s_magic == BTRFS_SUPER_MAGIC;
13012 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
13014 +#if defined(CONFIG_XENFS) || defined(CONFIG_XENFS_MODULE)
13015 + return sb->s_magic == XENFS_SUPER_MAGIC;
13021 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
13023 +#ifdef CONFIG_DEBUG_FS
13024 + return sb->s_magic == DEBUGFS_MAGIC;
13030 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
13032 +#if defined(CONFIG_NILFS) || defined(CONFIG_NILFS_MODULE)
13033 + return sb->s_magic == NILFS_SUPER_MAGIC;
13039 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
13041 +#if defined(CONFIG_HFSPLUS_FS) || defined(CONFIG_HFSPLUS_FS_MODULE)
13042 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
13048 +/* ---------------------------------------------------------------------- */
13050 + * they can't be an aufs branch.
13052 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
13055 +#ifndef CONFIG_AUFS_BR_RAMFS
13056 + au_test_ramfs(sb) ||
13058 + au_test_procfs(sb)
13059 + || au_test_sysfs(sb)
13060 + || au_test_configfs(sb)
13061 + || au_test_debugfs(sb)
13062 + || au_test_securityfs(sb)
13063 + || au_test_xenfs(sb)
13064 + || au_test_ecryptfs(sb)
13065 + /* || !strcmp(au_sbtype(sb), "unionfs") */
13066 + || au_test_aufs(sb); /* will be supported in next version */
13069 +static inline int au_test_fs_remote(struct super_block *sb)
13071 + return !au_test_tmpfs(sb)
13072 +#ifdef CONFIG_AUFS_BR_RAMFS
13073 + && !au_test_ramfs(sb)
13075 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
13078 +/* ---------------------------------------------------------------------- */
13081 + * Note: these functions (below) are created after reading ->getattr() in all
13082 + * filesystems under linux/fs. it means we have to do so in every update...
13086 + * some filesystems require getattr to refresh the inode attributes before
13088 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
13089 + * and leave the work for d_revalidate()
13091 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
13093 + return au_test_nfs(sb)
13094 + || au_test_fuse(sb)
13095 + /* || au_test_ocfs2(sb) */ /* untested */
13096 + /* || au_test_btrfs(sb) */ /* untested */
13097 + /* || au_test_coda(sb) */ /* untested */
13098 + /* || au_test_v9fs(sb) */ /* untested */
13103 + * filesystems which don't maintain i_size or i_blocks.
13105 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
13107 + return au_test_xfs(sb)
13108 + || au_test_btrfs(sb)
13109 + || au_test_ubifs(sb)
13110 + || au_test_hfsplus(sb) /* maintained, but incorrect */
13111 + /* || au_test_ext4(sb) */ /* untested */
13112 + /* || au_test_ocfs2(sb) */ /* untested */
13113 + /* || au_test_ocfs2_dlmfs(sb) */ /* untested */
13114 + /* || au_test_sysv(sb) */ /* untested */
13115 + /* || au_test_minix(sb) */ /* untested */
13120 + * filesystems which don't store the correct value in some of their inode
13123 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
13125 + return au_test_fs_bad_iattr_size(sb)
13126 + /* || au_test_cifs(sb) */ /* untested */
13127 + || au_test_fat(sb)
13128 + || au_test_msdos(sb)
13129 + || au_test_vfat(sb);
13132 +/* they don't check i_nlink in link(2) */
13133 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
13135 + return au_test_tmpfs(sb)
13136 +#ifdef CONFIG_AUFS_BR_RAMFS
13137 + || au_test_ramfs(sb)
13139 + || au_test_ubifs(sb)
13140 + || au_test_hfsplus(sb);
13144 + * filesystems which sets S_NOATIME and S_NOCMTIME.
13146 +static inline int au_test_fs_notime(struct super_block *sb)
13148 + return au_test_nfs(sb)
13149 + || au_test_fuse(sb)
13150 + || au_test_ubifs(sb)
13151 + /* || au_test_cifs(sb) */ /* untested */
13156 + * filesystems which requires replacing i_mapping.
13158 +static inline int au_test_fs_bad_mapping(struct super_block *sb)
13160 + return au_test_fuse(sb)
13161 + || au_test_ubifs(sb);
13164 +/* temporary support for i#1 in cramfs */
13165 +static inline int au_test_fs_unique_ino(struct inode *inode)
13167 + if (au_test_cramfs(inode->i_sb))
13168 + return inode->i_ino != 1;
13172 +/* ---------------------------------------------------------------------- */
13175 + * the filesystem where the xino files placed must support i/o after unlink and
13176 + * maintain i_size and i_blocks.
13178 +static inline int au_test_fs_bad_xino(struct super_block *sb)
13180 + return au_test_fs_remote(sb)
13181 + || au_test_fs_bad_iattr_size(sb)
13182 + /* don't want unnecessary work for xino */
13183 + || au_test_aufs(sb)
13184 + || au_test_ecryptfs(sb)
13185 + || au_test_nilfs(sb);
13188 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
13190 + return au_test_tmpfs(sb)
13191 + || au_test_ramfs(sb);
13195 + * test if the @sb is real-readonly.
13197 +static inline int au_test_fs_rr(struct super_block *sb)
13199 + return au_test_squashfs(sb)
13200 + || au_test_iso9660(sb)
13201 + || au_test_cramfs(sb)
13202 + || au_test_romfs(sb);
13205 +#endif /* __KERNEL__ */
13206 +#endif /* __AUFS_FSTYPE_H__ */
13207 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
13208 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
13209 +++ linux/fs/aufs/hfsnotify.c 2013-10-26 16:51:32.273040419 +0200
13212 + * Copyright (C) 2005-2013 Junjiro R. Okajima
13214 + * This program, aufs is free software; you can redistribute it and/or modify
13215 + * it under the terms of the GNU General Public License as published by
13216 + * the Free Software Foundation; either version 2 of the License, or
13217 + * (at your option) any later version.
13219 + * This program is distributed in the hope that it will be useful,
13220 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13221 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13222 + * GNU General Public License for more details.
13224 + * You should have received a copy of the GNU General Public License
13225 + * along with this program; if not, write to the Free Software
13226 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13230 + * fsnotify for the lower directories
13235 +/* FS_IN_IGNORED is unnecessary */
13236 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
13237 + | FS_CREATE | FS_EVENT_ON_CHILD);
13238 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
13239 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
13241 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
13243 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
13246 + au_cache_free_hnotify(hn);
13247 + smp_mb__before_atomic_dec();
13248 + if (atomic64_dec_and_test(&au_hfsn_ifree))
13249 + wake_up(&au_hfsn_wq);
13252 +static int au_hfsn_alloc(struct au_hinode *hinode)
13255 + struct au_hnotify *hn;
13256 + struct super_block *sb;
13257 + struct au_branch *br;
13258 + struct fsnotify_mark *mark;
13259 + aufs_bindex_t bindex;
13261 + hn = hinode->hi_notify;
13262 + sb = hn->hn_aufs_inode->i_sb;
13263 + bindex = au_br_index(sb, hinode->hi_id);
13264 + br = au_sbr(sb, bindex);
13265 + AuDebugOn(!br->br_hfsn);
13267 + mark = &hn->hn_mark;
13268 + fsnotify_init_mark(mark, au_hfsn_free_mark);
13269 + mark->mask = AuHfsnMask;
13271 + * by udba rename or rmdir, aufs assign a new inode to the known
13272 + * h_inode, so specify 1 to allow dups.
13274 + err = fsnotify_add_mark(mark, br->br_hfsn->hfsn_group, hinode->hi_inode,
13275 + /*mnt*/NULL, /*allow_dups*/1);
13276 + /* even if err */
13277 + fsnotify_put_mark(mark);
13282 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
13284 + struct fsnotify_mark *mark;
13285 + unsigned long long ull;
13286 + struct fsnotify_group *group;
13288 + ull = atomic64_inc_return(&au_hfsn_ifree);
13291 + mark = &hn->hn_mark;
13292 + spin_lock(&mark->lock);
13293 + group = mark->group;
13294 + fsnotify_get_group(group);
13295 + spin_unlock(&mark->lock);
13296 + fsnotify_destroy_mark(mark, group);
13297 + fsnotify_put_group(group);
13299 + /* free hn by myself */
13303 +/* ---------------------------------------------------------------------- */
13305 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
13307 + struct fsnotify_mark *mark;
13309 + mark = &hinode->hi_notify->hn_mark;
13310 + spin_lock(&mark->lock);
13312 + AuDebugOn(mark->mask & AuHfsnMask);
13313 + mark->mask |= AuHfsnMask;
13315 + AuDebugOn(!(mark->mask & AuHfsnMask));
13316 + mark->mask &= ~AuHfsnMask;
13318 + spin_unlock(&mark->lock);
13319 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
13322 +/* ---------------------------------------------------------------------- */
13324 +/* #define AuDbgHnotify */
13325 +#ifdef AuDbgHnotify
13326 +static char *au_hfsn_name(u32 mask)
13328 +#ifdef CONFIG_AUFS_DEBUG
13329 +#define test_ret(flag) \
13331 + if (mask & flag) \
13334 + test_ret(FS_ACCESS);
13335 + test_ret(FS_MODIFY);
13336 + test_ret(FS_ATTRIB);
13337 + test_ret(FS_CLOSE_WRITE);
13338 + test_ret(FS_CLOSE_NOWRITE);
13339 + test_ret(FS_OPEN);
13340 + test_ret(FS_MOVED_FROM);
13341 + test_ret(FS_MOVED_TO);
13342 + test_ret(FS_CREATE);
13343 + test_ret(FS_DELETE);
13344 + test_ret(FS_DELETE_SELF);
13345 + test_ret(FS_MOVE_SELF);
13346 + test_ret(FS_UNMOUNT);
13347 + test_ret(FS_Q_OVERFLOW);
13348 + test_ret(FS_IN_IGNORED);
13349 + test_ret(FS_IN_ISDIR);
13350 + test_ret(FS_IN_ONESHOT);
13351 + test_ret(FS_EVENT_ON_CHILD);
13360 +/* ---------------------------------------------------------------------- */
13362 +static void au_hfsn_free_group(struct fsnotify_group *group)
13364 + struct au_br_hfsnotify *hfsn = group->private;
13370 +static int au_hfsn_handle_event(struct fsnotify_group *group,
13371 + struct fsnotify_mark *inode_mark,
13372 + struct fsnotify_mark *vfsmount_mark,
13373 + struct fsnotify_event *event)
13376 + struct au_hnotify *hnotify;
13377 + struct inode *h_dir, *h_inode;
13379 + struct qstr h_child_qstr = QSTR_INIT(event->file_name, event->name_len);
13381 + AuDebugOn(event->data_type != FSNOTIFY_EVENT_INODE);
13384 + /* if FS_UNMOUNT happens, there must be another bug */
13385 + mask = event->mask;
13386 + AuDebugOn(mask & FS_UNMOUNT);
13387 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
13390 + h_dir = event->to_tell;
13391 + h_inode = event->inode;
13392 +#ifdef AuDbgHnotify
13394 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
13395 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
13396 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
13397 + h_dir->i_ino, mask, au_hfsn_name(mask),
13398 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
13399 + /* WARN_ON(1); */
13404 + AuDebugOn(!inode_mark);
13405 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
13406 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
13412 +/* isn't it waste to ask every registered 'group'? */
13413 +/* copied from linux/fs/notify/inotify/inotify_fsnotiry.c */
13414 +/* it should be exported to modules */
13415 +static bool au_hfsn_should_send_event(struct fsnotify_group *group,
13416 + struct inode *h_inode,
13417 + struct fsnotify_mark *inode_mark,
13418 + struct fsnotify_mark *vfsmount_mark,
13419 + __u32 mask, void *data, int data_type)
13421 + mask = (mask & ~FS_EVENT_ON_CHILD);
13422 + return inode_mark->mask & mask;
13425 +static struct fsnotify_ops au_hfsn_ops = {
13426 + .should_send_event = au_hfsn_should_send_event,
13427 + .handle_event = au_hfsn_handle_event,
13428 + .free_group_priv = au_hfsn_free_group
13431 +/* ---------------------------------------------------------------------- */
13433 +static void au_hfsn_fin_br(struct au_branch *br)
13435 + struct au_br_hfsnotify *hfsn;
13437 + hfsn = br->br_hfsn;
13439 + fsnotify_put_group(hfsn->hfsn_group);
13442 +static int au_hfsn_init_br(struct au_branch *br, int perm)
13445 + struct fsnotify_group *group;
13446 + struct au_br_hfsnotify *hfsn;
13449 + br->br_hfsn = NULL;
13450 + if (!au_br_hnotifyable(perm))
13454 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
13455 + if (unlikely(!hfsn))
13459 + group = fsnotify_alloc_group(&au_hfsn_ops);
13460 + if (IS_ERR(group)) {
13461 + err = PTR_ERR(group);
13462 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
13466 + group->private = hfsn;
13467 + hfsn->hfsn_group = group;
13468 + br->br_hfsn = hfsn;
13469 + goto out; /* success */
13477 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
13482 + if (!br->br_hfsn)
13483 + err = au_hfsn_init_br(br, perm);
13488 +/* ---------------------------------------------------------------------- */
13490 +static void au_hfsn_fin(void)
13492 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
13493 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
13496 +const struct au_hnotify_op au_hnotify_op = {
13497 + .ctl = au_hfsn_ctl,
13498 + .alloc = au_hfsn_alloc,
13499 + .free = au_hfsn_free,
13501 + .fin = au_hfsn_fin,
13503 + .reset_br = au_hfsn_reset_br,
13504 + .fin_br = au_hfsn_fin_br,
13505 + .init_br = au_hfsn_init_br
13507 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
13508 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
13509 +++ linux/fs/aufs/hfsplus.c 2013-10-26 16:51:32.273040419 +0200
13512 + * Copyright (C) 2010-2013 Junjiro R. Okajima
13514 + * This program, aufs is free software; you can redistribute it and/or modify
13515 + * it under the terms of the GNU General Public License as published by
13516 + * the Free Software Foundation; either version 2 of the License, or
13517 + * (at your option) any later version.
13519 + * This program is distributed in the hope that it will be useful,
13520 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13521 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13522 + * GNU General Public License for more details.
13524 + * You should have received a copy of the GNU General Public License
13525 + * along with this program; if not, write to the Free Software
13526 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13530 + * special support for filesystems which aqucires an inode mutex
13531 + * at final closing a file, eg, hfsplus.
13533 + * This trick is very simple and stupid, just to open the file before really
13534 + * neceeary open to tell hfsplus that this is not the final closing.
13535 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
13536 + * and au_h_open_post() after releasing it.
13541 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
13544 + struct file *h_file;
13545 + struct dentry *h_dentry;
13547 + h_dentry = au_h_dptr(dentry, bindex);
13548 + AuDebugOn(!h_dentry);
13549 + AuDebugOn(!h_dentry->d_inode);
13552 + if (au_test_hfsplus(h_dentry->d_sb)
13553 + && S_ISREG(h_dentry->d_inode->i_mode))
13554 + h_file = au_h_open(dentry, bindex,
13555 + O_RDONLY | O_NOATIME | O_LARGEFILE,
13556 + /*file*/NULL, force_wr);
13560 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
13561 + struct file *h_file)
13565 + au_sbr_put(dentry->d_sb, bindex);
13568 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
13569 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
13570 +++ linux/fs/aufs/hnotify.c 2013-10-26 16:51:29.582964925 +0200
13573 + * Copyright (C) 2005-2013 Junjiro R. Okajima
13575 + * This program, aufs is free software; you can redistribute it and/or modify
13576 + * it under the terms of the GNU General Public License as published by
13577 + * the Free Software Foundation; either version 2 of the License, or
13578 + * (at your option) any later version.
13580 + * This program is distributed in the hope that it will be useful,
13581 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13582 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13583 + * GNU General Public License for more details.
13585 + * You should have received a copy of the GNU General Public License
13586 + * along with this program; if not, write to the Free Software
13587 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13591 + * abstraction to notify the direct changes on lower directories
13596 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
13599 + struct au_hnotify *hn;
13602 + hn = au_cache_alloc_hnotify();
13604 + hn->hn_aufs_inode = inode;
13605 + hinode->hi_notify = hn;
13606 + err = au_hnotify_op.alloc(hinode);
13608 + if (unlikely(err)) {
13609 + hinode->hi_notify = NULL;
13610 + au_cache_free_hnotify(hn);
13612 + * The upper dir was removed by udba, but the same named
13613 + * dir left. In this case, aufs assignes a new inode
13614 + * number and set the monitor again.
13615 + * For the lower dir, the old monitnor is still left.
13617 + if (err == -EEXIST)
13626 +void au_hn_free(struct au_hinode *hinode)
13628 + struct au_hnotify *hn;
13630 + hn = hinode->hi_notify;
13632 + hinode->hi_notify = NULL;
13633 + if (au_hnotify_op.free(hinode, hn))
13634 + au_cache_free_hnotify(hn);
13638 +/* ---------------------------------------------------------------------- */
13640 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
13642 + if (hinode->hi_notify)
13643 + au_hnotify_op.ctl(hinode, do_set);
13646 +void au_hn_reset(struct inode *inode, unsigned int flags)
13648 + aufs_bindex_t bindex, bend;
13649 + struct inode *hi;
13650 + struct dentry *iwhdentry;
13652 + bend = au_ibend(inode);
13653 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
13654 + hi = au_h_iptr(inode, bindex);
13658 + /* mutex_lock_nested(&hi->i_mutex, AuLsc_I_CHILD); */
13659 + iwhdentry = au_hi_wh(inode, bindex);
13663 + au_set_h_iptr(inode, bindex, NULL, 0);
13664 + au_set_h_iptr(inode, bindex, au_igrab(hi),
13665 + flags & ~AuHi_XINO);
13668 + /* mutex_unlock(&hi->i_mutex); */
13672 +/* ---------------------------------------------------------------------- */
13674 +static int hn_xino(struct inode *inode, struct inode *h_inode)
13677 + aufs_bindex_t bindex, bend, bfound, bstart;
13678 + struct inode *h_i;
13681 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
13682 + pr_warn("branch root dir was changed\n");
13687 + bend = au_ibend(inode);
13688 + bstart = au_ibstart(inode);
13689 +#if 0 /* reserved for future use */
13690 + if (bindex == bend) {
13691 + /* keep this ino in rename case */
13695 + for (bindex = bstart; bindex <= bend; bindex++)
13696 + if (au_h_iptr(inode, bindex) == h_inode) {
13703 + for (bindex = bstart; bindex <= bend; bindex++) {
13704 + h_i = au_h_iptr(inode, bindex);
13708 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
13709 + /* ignore this error */
13710 + /* bad action? */
13713 + /* children inode number will be broken */
13720 +static int hn_gen_tree(struct dentry *dentry)
13722 + int err, i, j, ndentry;
13723 + struct au_dcsub_pages dpages;
13724 + struct au_dpage *dpage;
13725 + struct dentry **dentries;
13727 + err = au_dpages_init(&dpages, GFP_NOFS);
13728 + if (unlikely(err))
13730 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
13731 + if (unlikely(err))
13734 + for (i = 0; i < dpages.ndpage; i++) {
13735 + dpage = dpages.dpages + i;
13736 + dentries = dpage->dentries;
13737 + ndentry = dpage->ndentry;
13738 + for (j = 0; j < ndentry; j++) {
13739 + struct dentry *d;
13747 + /* todo: reset children xino?
13748 + cached children only? */
13749 + au_iigen_dec(d->d_inode);
13754 + au_dpages_free(&dpages);
13757 + /* discard children */
13758 + dentry_unhash(dentry);
13766 + * return 0 if processed.
13768 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
13769 + const unsigned int isdir)
13772 + struct dentry *d;
13773 + struct qstr *dname;
13776 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
13777 + pr_warn("branch root dir was changed\n");
13783 + AuDebugOn(!name);
13784 + au_iigen_dec(inode);
13785 + spin_lock(&inode->i_lock);
13786 + hlist_for_each_entry(d, &inode->i_dentry, d_alias) {
13787 + spin_lock(&d->d_lock);
13788 + dname = &d->d_name;
13789 + if (dname->len != nlen
13790 + && memcmp(dname->name, name, nlen)) {
13791 + spin_unlock(&d->d_lock);
13796 + spin_unlock(&d->d_lock);
13799 + spin_unlock(&inode->i_lock);
13801 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
13802 + d = d_find_alias(inode);
13804 + au_iigen_dec(inode);
13808 + spin_lock(&d->d_lock);
13809 + dname = &d->d_name;
13810 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
13811 + spin_unlock(&d->d_lock);
13812 + err = hn_gen_tree(d);
13813 + spin_lock(&d->d_lock);
13815 + spin_unlock(&d->d_lock);
13824 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
13827 + struct inode *inode;
13829 + inode = dentry->d_inode;
13830 + if (IS_ROOT(dentry)
13831 + /* || (inode && inode->i_ino == AUFS_ROOT_INO) */
13833 + pr_warn("branch root dir was changed\n");
13839 + au_digen_dec(dentry);
13841 + au_iigen_dec(inode);
13843 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
13845 + err = hn_gen_tree(dentry);
13852 +/* ---------------------------------------------------------------------- */
13854 +/* hnotify job flags */
13855 +#define AuHnJob_XINO0 1
13856 +#define AuHnJob_GEN (1 << 1)
13857 +#define AuHnJob_DIRENT (1 << 2)
13858 +#define AuHnJob_ISDIR (1 << 3)
13859 +#define AuHnJob_TRYXINO0 (1 << 4)
13860 +#define AuHnJob_MNTPNT (1 << 5)
13861 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
13862 +#define au_fset_hnjob(flags, name) \
13863 + do { (flags) |= AuHnJob_##name; } while (0)
13864 +#define au_fclr_hnjob(flags, name) \
13865 + do { (flags) &= ~AuHnJob_##name; } while (0)
13873 +struct au_hnotify_args {
13874 + struct inode *h_dir, *dir, *h_child_inode;
13876 + unsigned int flags[AuHnLast];
13877 + unsigned int h_child_nlen;
13878 + char h_child_name[];
13881 +struct hn_job_args {
13882 + unsigned int flags;
13883 + struct inode *inode, *h_inode, *dir, *h_dir;
13884 + struct dentry *dentry;
13889 +static int hn_job(struct hn_job_args *a)
13891 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
13894 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
13895 + hn_xino(a->inode, a->h_inode); /* ignore this error */
13897 + if (au_ftest_hnjob(a->flags, TRYXINO0)
13900 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
13901 + if (!a->h_inode->i_nlink)
13902 + hn_xino(a->inode, a->h_inode); /* ignore this error */
13903 + mutex_unlock(&a->h_inode->i_mutex);
13906 + /* make the generation obsolete */
13907 + if (au_ftest_hnjob(a->flags, GEN)) {
13910 + err = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
13912 + if (err && a->dentry)
13913 + hn_gen_by_name(a->dentry, isdir);
13914 + /* ignore this error */
13917 + /* make dir entries obsolete */
13918 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
13919 + struct au_vdir *vdir;
13921 + vdir = au_ivdir(a->inode);
13923 + vdir->vd_jiffy = 0;
13924 + /* IMustLock(a->inode); */
13925 + /* a->inode->i_version++; */
13928 + /* can do nothing but warn */
13929 + if (au_ftest_hnjob(a->flags, MNTPNT)
13931 + && d_mountpoint(a->dentry))
13932 + pr_warn("mount-point %.*s is removed or renamed\n",
13933 + AuDLNPair(a->dentry));
13938 +/* ---------------------------------------------------------------------- */
13940 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
13941 + struct inode *dir)
13943 + struct dentry *dentry, *d, *parent;
13944 + struct qstr *dname;
13946 + parent = d_find_alias(dir);
13951 + spin_lock(&parent->d_lock);
13952 + list_for_each_entry(d, &parent->d_subdirs, d_u.d_child) {
13953 + /* AuDbg("%.*s\n", AuDLNPair(d)); */
13954 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
13955 + dname = &d->d_name;
13956 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
13957 + goto cont_unlock;
13961 + goto cont_unlock;
13962 + if (d_count(d)) {
13963 + dentry = dget_dlock(d);
13964 + spin_unlock(&d->d_lock);
13969 + spin_unlock(&d->d_lock);
13971 + spin_unlock(&parent->d_lock);
13975 + di_write_lock_child(dentry);
13980 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
13981 + aufs_bindex_t bindex, ino_t h_ino)
13983 + struct inode *inode;
13988 + err = au_xino_read(sb, bindex, h_ino, &ino);
13990 + inode = ilookup(sb, ino);
13994 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
13995 + pr_warn("wrong root branch\n");
14001 + ii_write_lock_child(inode);
14007 +static void au_hn_bh(void *_args)
14009 + struct au_hnotify_args *a = _args;
14010 + struct super_block *sb;
14011 + aufs_bindex_t bindex, bend, bfound;
14012 + unsigned char xino, try_iput;
14014 + struct inode *inode;
14016 + struct hn_job_args args;
14017 + struct dentry *dentry;
14018 + struct au_sbinfo *sbinfo;
14020 + AuDebugOn(!_args);
14021 + AuDebugOn(!a->h_dir);
14022 + AuDebugOn(!a->dir);
14023 + AuDebugOn(!a->mask);
14024 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
14025 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
14026 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
14031 + * do not lock a->dir->i_mutex here
14032 + * because of d_revalidate() may cause a deadlock.
14034 + sb = a->dir->i_sb;
14036 + sbinfo = au_sbi(sb);
14037 + AuDebugOn(!sbinfo);
14038 + si_write_lock(sb, AuLock_NOPLMW);
14040 + ii_read_lock_parent(a->dir);
14042 + bend = au_ibend(a->dir);
14043 + for (bindex = au_ibstart(a->dir); bindex <= bend; bindex++)
14044 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
14048 + ii_read_unlock(a->dir);
14049 + if (unlikely(bfound < 0))
14052 + xino = !!au_opt_test(au_mntflags(sb), XINO);
14054 + if (a->h_child_inode)
14055 + h_ino = a->h_child_inode->i_ino;
14057 + if (a->h_child_nlen
14058 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
14059 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
14060 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
14064 + inode = dentry->d_inode;
14065 + if (xino && !inode && h_ino
14066 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
14067 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
14068 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
14069 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
14073 + args.flags = a->flags[AuHn_CHILD];
14074 + args.dentry = dentry;
14075 + args.inode = inode;
14076 + args.h_inode = a->h_child_inode;
14077 + args.dir = a->dir;
14078 + args.h_dir = a->h_dir;
14079 + args.h_name = a->h_child_name;
14080 + args.h_nlen = a->h_child_nlen;
14081 + err = hn_job(&args);
14083 + if (au_di(dentry))
14084 + di_write_unlock(dentry);
14087 + if (inode && try_iput) {
14088 + ii_write_unlock(inode);
14092 + ii_write_lock_parent(a->dir);
14093 + args.flags = a->flags[AuHn_PARENT];
14094 + args.dentry = NULL;
14095 + args.inode = a->dir;
14096 + args.h_inode = a->h_dir;
14098 + args.h_dir = NULL;
14099 + args.h_name = NULL;
14101 + err = hn_job(&args);
14102 + ii_write_unlock(a->dir);
14105 + iput(a->h_child_inode);
14108 + si_write_unlock(sb);
14109 + au_nwt_done(&sbinfo->si_nowait);
14113 +/* ---------------------------------------------------------------------- */
14115 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
14116 + struct qstr *h_child_qstr, struct inode *h_child_inode)
14119 + unsigned int flags[AuHnLast], f;
14120 + unsigned char isdir, isroot, wh;
14121 + struct inode *dir;
14122 + struct au_hnotify_args *args;
14123 + char *p, *h_child_name;
14126 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
14127 + dir = igrab(hnotify->hn_aufs_inode);
14131 + isroot = (dir->i_ino == AUFS_ROOT_INO);
14133 + h_child_name = (void *)h_child_qstr->name;
14134 + len = h_child_qstr->len;
14135 + if (h_child_name) {
14136 + if (len > AUFS_WH_PFX_LEN
14137 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
14138 + h_child_name += AUFS_WH_PFX_LEN;
14139 + len -= AUFS_WH_PFX_LEN;
14145 + if (h_child_inode)
14146 + isdir = !!S_ISDIR(h_child_inode->i_mode);
14147 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
14148 + flags[AuHn_CHILD] = 0;
14150 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
14151 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
14152 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
14153 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
14154 + case FS_MOVED_FROM:
14155 + case FS_MOVED_TO:
14156 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
14157 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
14160 + AuDebugOn(!h_child_name || !h_child_inode);
14165 + * aufs never be able to get this child inode.
14166 + * revalidation should be in d_revalidate()
14167 + * by checking i_nlink, i_generation or d_unhashed().
14169 + AuDebugOn(!h_child_name);
14170 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
14171 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
14179 + h_child_inode = NULL;
14182 + /* iput() and kfree() will be called in au_hnotify() */
14183 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
14184 + if (unlikely(!args)) {
14185 + AuErr1("no memory\n");
14189 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
14190 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
14191 + args->mask = mask;
14193 + args->h_dir = igrab(h_dir);
14194 + if (h_child_inode)
14195 + h_child_inode = igrab(h_child_inode); /* can be NULL */
14196 + args->h_child_inode = h_child_inode;
14197 + args->h_child_nlen = len;
14199 + p = (void *)args;
14200 + p += sizeof(*args);
14201 + memcpy(p, h_child_name, len);
14206 + if (!dir->i_nlink)
14208 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
14209 + if (unlikely(err)) {
14210 + pr_err("wkq %d\n", err);
14211 + iput(args->h_child_inode);
14212 + iput(args->h_dir);
14221 +/* ---------------------------------------------------------------------- */
14223 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
14227 + AuDebugOn(!(udba & AuOptMask_UDBA));
14230 + if (au_hnotify_op.reset_br)
14231 + err = au_hnotify_op.reset_br(udba, br, perm);
14236 +int au_hnotify_init_br(struct au_branch *br, int perm)
14241 + if (au_hnotify_op.init_br)
14242 + err = au_hnotify_op.init_br(br, perm);
14247 +void au_hnotify_fin_br(struct au_branch *br)
14249 + if (au_hnotify_op.fin_br)
14250 + au_hnotify_op.fin_br(br);
14253 +static void au_hn_destroy_cache(void)
14255 + kmem_cache_destroy(au_cachep[AuCache_HNOTIFY]);
14256 + au_cachep[AuCache_HNOTIFY] = NULL;
14259 +int __init au_hnotify_init(void)
14264 + au_cachep[AuCache_HNOTIFY] = AuCache(au_hnotify);
14265 + if (au_cachep[AuCache_HNOTIFY]) {
14267 + if (au_hnotify_op.init)
14268 + err = au_hnotify_op.init();
14269 + if (unlikely(err))
14270 + au_hn_destroy_cache();
14276 +void au_hnotify_fin(void)
14278 + if (au_hnotify_op.fin)
14279 + au_hnotify_op.fin();
14280 + /* cf. au_cache_fin() */
14281 + if (au_cachep[AuCache_HNOTIFY])
14282 + au_hn_destroy_cache();
14284 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
14285 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
14286 +++ linux/fs/aufs/iinfo.c 2013-07-06 13:20:47.750198454 +0200
14289 + * Copyright (C) 2005-2013 Junjiro R. Okajima
14291 + * This program, aufs is free software; you can redistribute it and/or modify
14292 + * it under the terms of the GNU General Public License as published by
14293 + * the Free Software Foundation; either version 2 of the License, or
14294 + * (at your option) any later version.
14296 + * This program is distributed in the hope that it will be useful,
14297 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14298 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14299 + * GNU General Public License for more details.
14301 + * You should have received a copy of the GNU General Public License
14302 + * along with this program; if not, write to the Free Software
14303 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14307 + * inode private data
14312 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
14314 + struct inode *h_inode;
14316 + IiMustAnyLock(inode);
14318 + h_inode = au_ii(inode)->ii_hinode[0 + bindex].hi_inode;
14319 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
14323 +/* todo: hard/soft set? */
14324 +void au_hiput(struct au_hinode *hinode)
14326 + au_hn_free(hinode);
14327 + dput(hinode->hi_whdentry);
14328 + iput(hinode->hi_inode);
14331 +unsigned int au_hi_flags(struct inode *inode, int isdir)
14333 + unsigned int flags;
14334 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
14337 + if (au_opt_test(mnt_flags, XINO))
14338 + au_fset_hi(flags, XINO);
14339 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
14340 + au_fset_hi(flags, HNOTIFY);
14344 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
14345 + struct inode *h_inode, unsigned int flags)
14347 + struct au_hinode *hinode;
14348 + struct inode *hi;
14349 + struct au_iinfo *iinfo = au_ii(inode);
14351 + IiMustWriteLock(inode);
14353 + hinode = iinfo->ii_hinode + bindex;
14354 + hi = hinode->hi_inode;
14355 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
14358 + au_hiput(hinode);
14359 + hinode->hi_inode = h_inode;
14362 + struct super_block *sb = inode->i_sb;
14363 + struct au_branch *br;
14365 + AuDebugOn(inode->i_mode
14366 + && (h_inode->i_mode & S_IFMT)
14367 + != (inode->i_mode & S_IFMT));
14368 + if (bindex == iinfo->ii_bstart)
14369 + au_cpup_igen(inode, h_inode);
14370 + br = au_sbr(sb, bindex);
14371 + hinode->hi_id = br->br_id;
14372 + if (au_ftest_hi(flags, XINO)) {
14373 + err = au_xino_write(sb, bindex, h_inode->i_ino,
14375 + if (unlikely(err))
14376 + AuIOErr1("failed au_xino_write() %d\n", err);
14379 + if (au_ftest_hi(flags, HNOTIFY)
14380 + && au_br_hnotifyable(br->br_perm)) {
14381 + err = au_hn_alloc(hinode, inode);
14382 + if (unlikely(err))
14383 + AuIOErr1("au_hn_alloc() %d\n", err);
14388 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
14389 + struct dentry *h_wh)
14391 + struct au_hinode *hinode;
14393 + IiMustWriteLock(inode);
14395 + hinode = au_ii(inode)->ii_hinode + bindex;
14396 + AuDebugOn(hinode->hi_whdentry);
14397 + hinode->hi_whdentry = h_wh;
14400 +void au_update_iigen(struct inode *inode, int half)
14402 + struct au_iinfo *iinfo;
14403 + struct au_iigen *iigen;
14404 + unsigned int sigen;
14406 + sigen = au_sigen(inode->i_sb);
14407 + iinfo = au_ii(inode);
14408 + iigen = &iinfo->ii_generation;
14409 + spin_lock(&iinfo->ii_genspin);
14410 + iigen->ig_generation = sigen;
14412 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
14414 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
14415 + spin_unlock(&iinfo->ii_genspin);
14418 +/* it may be called at remount time, too */
14419 +void au_update_ibrange(struct inode *inode, int do_put_zero)
14421 + struct au_iinfo *iinfo;
14422 + aufs_bindex_t bindex, bend;
14424 + iinfo = au_ii(inode);
14428 + IiMustWriteLock(inode);
14430 + if (do_put_zero && iinfo->ii_bstart >= 0) {
14431 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
14433 + struct inode *h_i;
14435 + h_i = iinfo->ii_hinode[0 + bindex].hi_inode;
14436 + if (h_i && !h_i->i_nlink)
14437 + au_set_h_iptr(inode, bindex, NULL, 0);
14441 + iinfo->ii_bstart = -1;
14442 + iinfo->ii_bend = -1;
14443 + bend = au_sbend(inode->i_sb);
14444 + for (bindex = 0; bindex <= bend; bindex++)
14445 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
14446 + iinfo->ii_bstart = bindex;
14449 + if (iinfo->ii_bstart >= 0)
14450 + for (bindex = bend; bindex >= iinfo->ii_bstart; bindex--)
14451 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
14452 + iinfo->ii_bend = bindex;
14455 + AuDebugOn(iinfo->ii_bstart > iinfo->ii_bend);
14458 +/* ---------------------------------------------------------------------- */
14460 +void au_icntnr_init_once(void *_c)
14462 + struct au_icntnr *c = _c;
14463 + struct au_iinfo *iinfo = &c->iinfo;
14464 + static struct lock_class_key aufs_ii;
14466 + spin_lock_init(&iinfo->ii_genspin);
14467 + au_rw_init(&iinfo->ii_rwsem);
14468 + au_rw_class(&iinfo->ii_rwsem, &aufs_ii);
14469 + inode_init_once(&c->vfs_inode);
14472 +int au_iinfo_init(struct inode *inode)
14474 + struct au_iinfo *iinfo;
14475 + struct super_block *sb;
14478 + sb = inode->i_sb;
14479 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
14480 + nbr = au_sbend(sb) + 1;
14481 + if (unlikely(nbr <= 0))
14483 + iinfo->ii_hinode = kcalloc(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
14484 + if (iinfo->ii_hinode) {
14485 + au_ninodes_inc(sb);
14486 + for (i = 0; i < nbr; i++)
14487 + iinfo->ii_hinode[i].hi_id = -1;
14489 + iinfo->ii_generation.ig_generation = au_sigen(sb);
14490 + iinfo->ii_bstart = -1;
14491 + iinfo->ii_bend = -1;
14492 + iinfo->ii_vdir = NULL;
14498 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr)
14501 + struct au_hinode *hip;
14503 + AuRwMustWriteLock(&iinfo->ii_rwsem);
14506 + sz = sizeof(*hip) * (iinfo->ii_bend + 1);
14508 + sz = sizeof(*hip);
14509 + hip = au_kzrealloc(iinfo->ii_hinode, sz, sizeof(*hip) * nbr, GFP_NOFS);
14511 + iinfo->ii_hinode = hip;
14518 +void au_iinfo_fin(struct inode *inode)
14520 + struct au_iinfo *iinfo;
14521 + struct au_hinode *hi;
14522 + struct super_block *sb;
14523 + aufs_bindex_t bindex, bend;
14524 + const unsigned char unlinked = !inode->i_nlink;
14526 + iinfo = au_ii(inode);
14527 + /* bad_inode case */
14531 + sb = inode->i_sb;
14532 + au_ninodes_dec(sb);
14533 + if (si_pid_test(sb))
14534 + au_xino_delete_inode(inode, unlinked);
14537 + * it is safe to hide the dependency between sbinfo and
14541 + si_noflush_read_lock(sb);
14542 + au_xino_delete_inode(inode, unlinked);
14543 + si_read_unlock(sb);
14547 + if (iinfo->ii_vdir)
14548 + au_vdir_free(iinfo->ii_vdir);
14550 + bindex = iinfo->ii_bstart;
14551 + if (bindex >= 0) {
14552 + hi = iinfo->ii_hinode + bindex;
14553 + bend = iinfo->ii_bend;
14554 + while (bindex++ <= bend) {
14555 + if (hi->hi_inode)
14560 + kfree(iinfo->ii_hinode);
14561 + iinfo->ii_hinode = NULL;
14562 + AuRwDestroy(&iinfo->ii_rwsem);
14564 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
14565 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
14566 +++ linux/fs/aufs/inode.c 2013-07-06 13:20:47.750198454 +0200
14569 + * Copyright (C) 2005-2013 Junjiro R. Okajima
14571 + * This program, aufs is free software; you can redistribute it and/or modify
14572 + * it under the terms of the GNU General Public License as published by
14573 + * the Free Software Foundation; either version 2 of the License, or
14574 + * (at your option) any later version.
14576 + * This program is distributed in the hope that it will be useful,
14577 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14578 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14579 + * GNU General Public License for more details.
14581 + * You should have received a copy of the GNU General Public License
14582 + * along with this program; if not, write to the Free Software
14583 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14587 + * inode functions
14592 +struct inode *au_igrab(struct inode *inode)
14595 + AuDebugOn(!atomic_read(&inode->i_count));
14601 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
14603 + au_cpup_attr_all(inode, /*force*/0);
14604 + au_update_iigen(inode, /*half*/1);
14606 + inode->i_version++;
14609 +static int au_ii_refresh(struct inode *inode, int *update)
14613 + aufs_bindex_t bindex, new_bindex;
14614 + struct super_block *sb;
14615 + struct au_iinfo *iinfo;
14616 + struct au_hinode *p, *q, tmp;
14618 + IiMustWriteLock(inode);
14621 + sb = inode->i_sb;
14622 + type = inode->i_mode & S_IFMT;
14623 + iinfo = au_ii(inode);
14624 + err = au_ii_realloc(iinfo, au_sbend(sb) + 1);
14625 + if (unlikely(err))
14628 + AuDebugOn(iinfo->ii_bstart < 0);
14629 + p = iinfo->ii_hinode + iinfo->ii_bstart;
14630 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
14632 + if (!p->hi_inode)
14635 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
14636 + new_bindex = au_br_index(sb, p->hi_id);
14637 + if (new_bindex == bindex)
14640 + if (new_bindex < 0) {
14643 + p->hi_inode = NULL;
14647 + if (new_bindex < iinfo->ii_bstart)
14648 + iinfo->ii_bstart = new_bindex;
14649 + if (iinfo->ii_bend < new_bindex)
14650 + iinfo->ii_bend = new_bindex;
14651 + /* swap two lower inode, and loop again */
14652 + q = iinfo->ii_hinode + new_bindex;
14656 + if (tmp.hi_inode) {
14661 + au_update_ibrange(inode, /*do_put_zero*/0);
14662 + e = au_dy_irefresh(inode);
14663 + if (unlikely(e && !err))
14671 +int au_refresh_hinode_self(struct inode *inode)
14675 + err = au_ii_refresh(inode, &update);
14677 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
14683 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
14685 + int err, e, update;
14686 + unsigned int flags;
14688 + aufs_bindex_t bindex, bend;
14689 + unsigned char isdir;
14690 + struct au_hinode *p;
14691 + struct au_iinfo *iinfo;
14693 + err = au_ii_refresh(inode, &update);
14694 + if (unlikely(err))
14698 + iinfo = au_ii(inode);
14699 + p = iinfo->ii_hinode + iinfo->ii_bstart;
14700 + mode = (inode->i_mode & S_IFMT);
14701 + isdir = S_ISDIR(mode);
14702 + flags = au_hi_flags(inode, isdir);
14703 + bend = au_dbend(dentry);
14704 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
14705 + struct inode *h_i;
14706 + struct dentry *h_d;
14708 + h_d = au_h_dptr(dentry, bindex);
14709 + if (!h_d || !h_d->d_inode)
14712 + AuDebugOn(mode != (h_d->d_inode->i_mode & S_IFMT));
14713 + if (iinfo->ii_bstart <= bindex && bindex <= iinfo->ii_bend) {
14714 + h_i = au_h_iptr(inode, bindex);
14716 + if (h_i == h_d->d_inode)
14722 + if (bindex < iinfo->ii_bstart)
14723 + iinfo->ii_bstart = bindex;
14724 + if (iinfo->ii_bend < bindex)
14725 + iinfo->ii_bend = bindex;
14726 + au_set_h_iptr(inode, bindex, au_igrab(h_d->d_inode), flags);
14729 + au_update_ibrange(inode, /*do_put_zero*/0);
14730 + e = au_dy_irefresh(inode);
14731 + if (unlikely(e && !err))
14734 + au_refresh_hinode_attr(inode, update && isdir);
14741 +static int set_inode(struct inode *inode, struct dentry *dentry)
14744 + unsigned int flags;
14746 + aufs_bindex_t bindex, bstart, btail;
14747 + unsigned char isdir;
14748 + struct dentry *h_dentry;
14749 + struct inode *h_inode;
14750 + struct au_iinfo *iinfo;
14752 + IiMustWriteLock(inode);
14756 + bstart = au_dbstart(dentry);
14757 + h_inode = au_h_dptr(dentry, bstart)->d_inode;
14758 + mode = h_inode->i_mode;
14759 + switch (mode & S_IFMT) {
14761 + btail = au_dbtail(dentry);
14762 + inode->i_op = &aufs_iop;
14763 + inode->i_fop = &aufs_file_fop;
14764 + err = au_dy_iaop(inode, bstart, h_inode);
14765 + if (unlikely(err))
14770 + btail = au_dbtaildir(dentry);
14771 + inode->i_op = &aufs_dir_iop;
14772 + inode->i_fop = &aufs_dir_fop;
14775 + btail = au_dbtail(dentry);
14776 + inode->i_op = &aufs_symlink_iop;
14782 + btail = au_dbtail(dentry);
14783 + inode->i_op = &aufs_iop;
14784 + au_init_special_fop(inode, mode, h_inode->i_rdev);
14787 + AuIOErr("Unknown file type 0%o\n", mode);
14792 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
14793 + flags = au_hi_flags(inode, isdir);
14794 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
14795 + && au_ftest_hi(flags, HNOTIFY)
14796 + && dentry->d_name.len > AUFS_WH_PFX_LEN
14797 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
14798 + au_fclr_hi(flags, HNOTIFY);
14799 + iinfo = au_ii(inode);
14800 + iinfo->ii_bstart = bstart;
14801 + iinfo->ii_bend = btail;
14802 + for (bindex = bstart; bindex <= btail; bindex++) {
14803 + h_dentry = au_h_dptr(dentry, bindex);
14805 + au_set_h_iptr(inode, bindex,
14806 + au_igrab(h_dentry->d_inode), flags);
14808 + au_cpup_attr_all(inode, /*force*/1);
14815 + * successful returns with iinfo write_locked
14817 + * zero: success, matched
14818 + * plus: no error, but unmatched
14820 +static int reval_inode(struct inode *inode, struct dentry *dentry)
14823 + unsigned int gen;
14824 + struct au_iigen iigen;
14825 + aufs_bindex_t bindex, bend;
14826 + struct inode *h_inode, *h_dinode;
14829 + * before this function, if aufs got any iinfo lock, it must be only
14830 + * one, the parent dir.
14831 + * it can happen by UDBA and the obsoleted inode number.
14834 + if (unlikely(inode->i_ino == parent_ino(dentry)))
14838 + ii_write_lock_new_child(inode);
14839 + h_dinode = au_h_dptr(dentry, au_dbstart(dentry))->d_inode;
14840 + bend = au_ibend(inode);
14841 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
14842 + h_inode = au_h_iptr(inode, bindex);
14843 + if (!h_inode || h_inode != h_dinode)
14847 + gen = au_iigen(inode, &iigen);
14848 + if (gen == au_digen(dentry)
14849 + && !au_ig_ftest(iigen.ig_flags, HALF_REFRESHED))
14852 + /* fully refresh inode using dentry */
14853 + err = au_refresh_hinode(inode, dentry);
14855 + au_update_iigen(inode, /*half*/0);
14859 + if (unlikely(err))
14860 + ii_write_unlock(inode);
14865 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
14866 + unsigned int d_type, ino_t *ino)
14869 + struct mutex *mtx;
14871 + /* prevent hardlinked inode number from race condition */
14873 + if (d_type != DT_DIR) {
14874 + mtx = &au_sbr(sb, bindex)->br_xino.xi_nondir_mtx;
14877 + err = au_xino_read(sb, bindex, h_ino, ino);
14878 + if (unlikely(err))
14883 + *ino = au_xino_new_ino(sb);
14884 + if (unlikely(!*ino))
14886 + err = au_xino_write(sb, bindex, h_ino, *ino);
14887 + if (unlikely(err))
14893 + mutex_unlock(mtx);
14897 +/* successful returns with iinfo write_locked */
14898 +/* todo: return with unlocked? */
14899 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
14901 + struct inode *inode, *h_inode;
14902 + struct dentry *h_dentry;
14903 + struct super_block *sb;
14904 + struct mutex *mtx;
14905 + ino_t h_ino, ino;
14907 + aufs_bindex_t bstart;
14909 + sb = dentry->d_sb;
14910 + bstart = au_dbstart(dentry);
14911 + h_dentry = au_h_dptr(dentry, bstart);
14912 + h_inode = h_dentry->d_inode;
14913 + h_ino = h_inode->i_ino;
14916 + * stop 'race'-ing between hardlinks under different
14920 + if (!S_ISDIR(h_inode->i_mode))
14921 + mtx = &au_sbr(sb, bstart)->br_xino.xi_nondir_mtx;
14926 + err = au_xino_read(sb, bstart, h_ino, &ino);
14927 + inode = ERR_PTR(err);
14928 + if (unlikely(err))
14932 + ino = au_xino_new_ino(sb);
14933 + if (unlikely(!ino)) {
14934 + inode = ERR_PTR(-EIO);
14939 + AuDbg("i%lu\n", (unsigned long)ino);
14940 + inode = au_iget_locked(sb, ino);
14941 + err = PTR_ERR(inode);
14942 + if (IS_ERR(inode))
14945 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
14946 + if (inode->i_state & I_NEW) {
14947 + /* verbose coding for lock class name */
14948 + if (unlikely(S_ISLNK(h_inode->i_mode)))
14949 + au_rw_class(&au_ii(inode)->ii_rwsem,
14950 + au_lc_key + AuLcSymlink_IIINFO);
14951 + else if (unlikely(S_ISDIR(h_inode->i_mode)))
14952 + au_rw_class(&au_ii(inode)->ii_rwsem,
14953 + au_lc_key + AuLcDir_IIINFO);
14954 + else /* likely */
14955 + au_rw_class(&au_ii(inode)->ii_rwsem,
14956 + au_lc_key + AuLcNonDir_IIINFO);
14958 + ii_write_lock_new_child(inode);
14959 + err = set_inode(inode, dentry);
14961 + unlock_new_inode(inode);
14962 + goto out; /* success */
14966 + * iget_failed() calls iput(), but we need to call
14967 + * ii_write_unlock() after iget_failed(). so dirty hack for
14970 + atomic_inc(&inode->i_count);
14971 + iget_failed(inode);
14972 + ii_write_unlock(inode);
14973 + au_xino_write(sb, bstart, h_ino, /*ino*/0);
14974 + /* ignore this error */
14976 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
14978 + * horrible race condition between lookup, readdir and copyup
14979 + * (or something).
14982 + mutex_unlock(mtx);
14983 + err = reval_inode(inode, dentry);
14984 + if (unlikely(err < 0)) {
14991 + goto out; /* success */
14996 + if (unlikely(au_test_fs_unique_ino(h_dentry->d_inode)))
14997 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
14998 + " b%d, %s, %.*s, hi%lu, i%lu.\n",
14999 + bstart, au_sbtype(h_dentry->d_sb), AuDLNPair(dentry),
15000 + (unsigned long)h_ino, (unsigned long)ino);
15002 + err = au_xino_write(sb, bstart, h_ino, /*ino*/0);
15006 + mutex_unlock(mtx);
15012 + inode = ERR_PTR(err);
15015 + mutex_unlock(mtx);
15019 +/* ---------------------------------------------------------------------- */
15021 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
15022 + struct inode *inode)
15026 + err = au_br_rdonly(au_sbr(sb, bindex));
15028 + /* pseudo-link after flushed may happen out of bounds */
15031 + && au_ibstart(inode) <= bindex
15032 + && bindex <= au_ibend(inode)) {
15034 + * permission check is unnecessary since vfsub routine
15035 + * will be called later
15037 + struct inode *hi = au_h_iptr(inode, bindex);
15039 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
15045 +int au_test_h_perm(struct inode *h_inode, int mask)
15047 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
15049 + return inode_permission(h_inode, mask);
15052 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
15054 + if (au_test_nfs(h_inode->i_sb)
15055 + && (mask & MAY_WRITE)
15056 + && S_ISDIR(h_inode->i_mode))
15057 + mask |= MAY_READ; /* force permission check */
15058 + return au_test_h_perm(h_inode, mask);
15060 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
15061 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
15062 +++ linux/fs/aufs/inode.h 2013-07-06 13:20:47.750198454 +0200
15065 + * Copyright (C) 2005-2013 Junjiro R. Okajima
15067 + * This program, aufs is free software; you can redistribute it and/or modify
15068 + * it under the terms of the GNU General Public License as published by
15069 + * the Free Software Foundation; either version 2 of the License, or
15070 + * (at your option) any later version.
15072 + * This program is distributed in the hope that it will be useful,
15073 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15074 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15075 + * GNU General Public License for more details.
15077 + * You should have received a copy of the GNU General Public License
15078 + * along with this program; if not, write to the Free Software
15079 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15083 + * inode operations
15086 +#ifndef __AUFS_INODE_H__
15087 +#define __AUFS_INODE_H__
15091 +#include <linux/fsnotify.h>
15092 +#include "rwsem.h"
15096 +struct au_hnotify {
15097 +#ifdef CONFIG_AUFS_HNOTIFY
15098 +#ifdef CONFIG_AUFS_HFSNOTIFY
15099 + /* never use fsnotify_add_vfsmount_mark() */
15100 + struct fsnotify_mark hn_mark;
15102 + struct inode *hn_aufs_inode; /* no get/put */
15104 +} ____cacheline_aligned_in_smp;
15106 +struct au_hinode {
15107 + struct inode *hi_inode;
15108 + aufs_bindex_t hi_id;
15109 +#ifdef CONFIG_AUFS_HNOTIFY
15110 + struct au_hnotify *hi_notify;
15113 + /* reference to the copied-up whiteout with get/put */
15114 + struct dentry *hi_whdentry;
15118 +#define AuIG_HALF_REFRESHED 1
15119 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
15120 +#define au_ig_fset(flags, name) \
15121 + do { (flags) |= AuIG_##name; } while (0)
15122 +#define au_ig_fclr(flags, name) \
15123 + do { (flags) &= ~AuIG_##name; } while (0)
15126 + __u32 ig_generation, ig_flags;
15131 + spinlock_t ii_genspin;
15132 + struct au_iigen ii_generation;
15133 + struct super_block *ii_hsb1; /* no get/put */
15135 + struct au_rwsem ii_rwsem;
15136 + aufs_bindex_t ii_bstart, ii_bend;
15138 + struct au_hinode *ii_hinode;
15139 + struct au_vdir *ii_vdir;
15142 +struct au_icntnr {
15143 + struct au_iinfo iinfo;
15144 + struct inode vfs_inode;
15145 +} ____cacheline_aligned_in_smp;
15147 +/* au_pin flags */
15148 +#define AuPin_DI_LOCKED 1
15149 +#define AuPin_MNT_WRITE (1 << 1)
15150 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
15151 +#define au_fset_pin(flags, name) \
15152 + do { (flags) |= AuPin_##name; } while (0)
15153 +#define au_fclr_pin(flags, name) \
15154 + do { (flags) &= ~AuPin_##name; } while (0)
15158 + struct dentry *dentry;
15159 + unsigned int udba;
15160 + unsigned char lsc_di, lsc_hi, flags;
15161 + aufs_bindex_t bindex;
15164 + struct dentry *parent;
15165 + struct au_hinode *hdir;
15166 + struct vfsmount *h_mnt;
15168 + /* temporary unlock/relock for copyup */
15169 + struct dentry *h_dentry, *h_parent;
15170 + struct au_branch *br;
15171 + struct task_struct *task;
15174 +void au_pin_hdir_unlock(struct au_pin *p);
15175 +int au_pin_hdir_relock(struct au_pin *p);
15176 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task);
15177 +void au_pin_hdir_acquire_nest(struct au_pin *p);
15178 +void au_pin_hdir_release(struct au_pin *p);
15180 +/* ---------------------------------------------------------------------- */
15182 +static inline struct au_iinfo *au_ii(struct inode *inode)
15184 + struct au_iinfo *iinfo;
15186 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
15187 + if (iinfo->ii_hinode)
15189 + return NULL; /* debugging bad_inode case */
15192 +/* ---------------------------------------------------------------------- */
15195 +struct inode *au_igrab(struct inode *inode);
15196 +int au_refresh_hinode_self(struct inode *inode);
15197 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
15198 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
15199 + unsigned int d_type, ino_t *ino);
15200 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
15201 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
15202 + struct inode *inode);
15203 +int au_test_h_perm(struct inode *h_inode, int mask);
15204 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
15206 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
15207 + ino_t h_ino, unsigned int d_type, ino_t *ino)
15209 +#ifdef CONFIG_AUFS_SHWH
15210 + return au_ino(sb, bindex, h_ino, d_type, ino);
15217 +extern struct inode_operations aufs_iop, aufs_symlink_iop, aufs_dir_iop;
15219 +/* au_wr_dir flags */
15220 +#define AuWrDir_ADD_ENTRY 1
15221 +#define AuWrDir_TMP_WHENTRY (1 << 1)
15222 +#define AuWrDir_ISDIR (1 << 2)
15223 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
15224 +#define au_fset_wrdir(flags, name) \
15225 + do { (flags) |= AuWrDir_##name; } while (0)
15226 +#define au_fclr_wrdir(flags, name) \
15227 + do { (flags) &= ~AuWrDir_##name; } while (0)
15229 +struct au_wr_dir_args {
15230 + aufs_bindex_t force_btgt;
15231 + unsigned char flags;
15233 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
15234 + struct au_wr_dir_args *args);
15236 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
15237 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
15238 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
15239 + unsigned int udba, unsigned char flags);
15240 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
15241 + unsigned int udba, unsigned char flags) __must_check;
15242 +int au_do_pin(struct au_pin *pin) __must_check;
15243 +void au_unpin(struct au_pin *pin);
15246 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
15247 + struct dentry *h_parent, int isdir);
15248 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
15250 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
15251 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
15253 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
15254 + struct dentry *dentry);
15255 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
15258 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
15259 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
15260 + struct dentry *h_parent, int isdir);
15261 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
15262 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
15265 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
15266 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
15267 + struct inode *dir, struct dentry *dentry);
15270 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
15271 +void au_hiput(struct au_hinode *hinode);
15272 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
15273 + struct dentry *h_wh);
15274 +unsigned int au_hi_flags(struct inode *inode, int isdir);
15276 +/* hinode flags */
15277 +#define AuHi_XINO 1
15278 +#define AuHi_HNOTIFY (1 << 1)
15279 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
15280 +#define au_fset_hi(flags, name) \
15281 + do { (flags) |= AuHi_##name; } while (0)
15282 +#define au_fclr_hi(flags, name) \
15283 + do { (flags) &= ~AuHi_##name; } while (0)
15285 +#ifndef CONFIG_AUFS_HNOTIFY
15286 +#undef AuHi_HNOTIFY
15287 +#define AuHi_HNOTIFY 0
15290 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
15291 + struct inode *h_inode, unsigned int flags);
15293 +void au_update_iigen(struct inode *inode, int half);
15294 +void au_update_ibrange(struct inode *inode, int do_put_zero);
15296 +void au_icntnr_init_once(void *_c);
15297 +int au_iinfo_init(struct inode *inode);
15298 +void au_iinfo_fin(struct inode *inode);
15299 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr);
15301 +#ifdef CONFIG_PROC_FS
15303 +int au_plink_maint(struct super_block *sb, int flags);
15304 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
15305 +int au_plink_maint_enter(struct super_block *sb);
15306 +#ifdef CONFIG_AUFS_DEBUG
15307 +void au_plink_list(struct super_block *sb);
15309 +AuStubVoid(au_plink_list, struct super_block *sb)
15311 +int au_plink_test(struct inode *inode);
15312 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
15313 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
15314 + struct dentry *h_dentry);
15315 +void au_plink_put(struct super_block *sb, int verbose);
15316 +void au_plink_clean(struct super_block *sb, int verbose);
15317 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
15319 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
15320 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
15321 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
15322 +AuStubVoid(au_plink_list, struct super_block *sb);
15323 +AuStubInt0(au_plink_test, struct inode *inode);
15324 +AuStub(struct dentry *, au_plink_lkup, return NULL,
15325 + struct inode *inode, aufs_bindex_t bindex);
15326 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
15327 + struct dentry *h_dentry);
15328 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
15329 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
15330 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
15331 +#endif /* CONFIG_PROC_FS */
15333 +/* ---------------------------------------------------------------------- */
15335 +/* lock subclass for iinfo */
15337 + AuLsc_II_CHILD, /* child first */
15338 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
15339 + AuLsc_II_CHILD3, /* copyup dirs */
15340 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
15341 + AuLsc_II_PARENT2,
15342 + AuLsc_II_PARENT3, /* copyup dirs */
15343 + AuLsc_II_NEW_CHILD
15347 + * ii_read_lock_child, ii_write_lock_child,
15348 + * ii_read_lock_child2, ii_write_lock_child2,
15349 + * ii_read_lock_child3, ii_write_lock_child3,
15350 + * ii_read_lock_parent, ii_write_lock_parent,
15351 + * ii_read_lock_parent2, ii_write_lock_parent2,
15352 + * ii_read_lock_parent3, ii_write_lock_parent3,
15353 + * ii_read_lock_new_child, ii_write_lock_new_child,
15355 +#define AuReadLockFunc(name, lsc) \
15356 +static inline void ii_read_lock_##name(struct inode *i) \
15358 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
15361 +#define AuWriteLockFunc(name, lsc) \
15362 +static inline void ii_write_lock_##name(struct inode *i) \
15364 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
15367 +#define AuRWLockFuncs(name, lsc) \
15368 + AuReadLockFunc(name, lsc) \
15369 + AuWriteLockFunc(name, lsc)
15371 +AuRWLockFuncs(child, CHILD);
15372 +AuRWLockFuncs(child2, CHILD2);
15373 +AuRWLockFuncs(child3, CHILD3);
15374 +AuRWLockFuncs(parent, PARENT);
15375 +AuRWLockFuncs(parent2, PARENT2);
15376 +AuRWLockFuncs(parent3, PARENT3);
15377 +AuRWLockFuncs(new_child, NEW_CHILD);
15379 +#undef AuReadLockFunc
15380 +#undef AuWriteLockFunc
15381 +#undef AuRWLockFuncs
15384 + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock
15386 +AuSimpleUnlockRwsemFuncs(ii, struct inode *i, &au_ii(i)->ii_rwsem);
15388 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
15389 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
15390 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
15392 +/* ---------------------------------------------------------------------- */
15394 +static inline void au_icntnr_init(struct au_icntnr *c)
15396 +#ifdef CONFIG_AUFS_DEBUG
15397 + c->vfs_inode.i_mode = 0;
15401 +static inline unsigned int au_iigen(struct inode *inode, struct au_iigen *iigen)
15403 + unsigned int gen;
15404 + struct au_iinfo *iinfo;
15406 + iinfo = au_ii(inode);
15407 + spin_lock(&iinfo->ii_genspin);
15409 + *iigen = iinfo->ii_generation;
15410 + gen = iinfo->ii_generation.ig_generation;
15411 + spin_unlock(&iinfo->ii_genspin);
15416 +/* tiny test for inode number */
15417 +/* tmpfs generation is too rough */
15418 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
15420 + struct au_iinfo *iinfo;
15422 + iinfo = au_ii(inode);
15423 + AuRwMustAnyLock(&iinfo->ii_rwsem);
15424 + return !(iinfo->ii_hsb1 == h_inode->i_sb
15425 + && iinfo->ii_higen == h_inode->i_generation);
15428 +static inline void au_iigen_dec(struct inode *inode)
15430 + struct au_iinfo *iinfo;
15432 + iinfo = au_ii(inode);
15433 + spin_lock(&iinfo->ii_genspin);
15434 + iinfo->ii_generation.ig_generation--;
15435 + spin_unlock(&iinfo->ii_genspin);
15438 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
15443 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
15449 +/* ---------------------------------------------------------------------- */
15451 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
15452 + aufs_bindex_t bindex)
15454 + IiMustAnyLock(inode);
15455 + return au_ii(inode)->ii_hinode[0 + bindex].hi_id;
15458 +static inline aufs_bindex_t au_ibstart(struct inode *inode)
15460 + IiMustAnyLock(inode);
15461 + return au_ii(inode)->ii_bstart;
15464 +static inline aufs_bindex_t au_ibend(struct inode *inode)
15466 + IiMustAnyLock(inode);
15467 + return au_ii(inode)->ii_bend;
15470 +static inline struct au_vdir *au_ivdir(struct inode *inode)
15472 + IiMustAnyLock(inode);
15473 + return au_ii(inode)->ii_vdir;
15476 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
15478 + IiMustAnyLock(inode);
15479 + return au_ii(inode)->ii_hinode[0 + bindex].hi_whdentry;
15482 +static inline void au_set_ibstart(struct inode *inode, aufs_bindex_t bindex)
15484 + IiMustWriteLock(inode);
15485 + au_ii(inode)->ii_bstart = bindex;
15488 +static inline void au_set_ibend(struct inode *inode, aufs_bindex_t bindex)
15490 + IiMustWriteLock(inode);
15491 + au_ii(inode)->ii_bend = bindex;
15494 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
15496 + IiMustWriteLock(inode);
15497 + au_ii(inode)->ii_vdir = vdir;
15500 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
15502 + IiMustAnyLock(inode);
15503 + return au_ii(inode)->ii_hinode + bindex;
15506 +/* ---------------------------------------------------------------------- */
15508 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
15511 + return pin->parent;
15515 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
15517 + if (pin && pin->hdir)
15518 + return pin->hdir->hi_inode;
15522 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
15525 + return pin->hdir;
15529 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
15532 + pin->dentry = dentry;
15535 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
15536 + unsigned char lflag)
15540 + au_fset_pin(pin->flags, DI_LOCKED);
15542 + au_fclr_pin(pin->flags, DI_LOCKED);
15546 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
15549 + dput(pin->parent);
15550 + pin->parent = dget(parent);
15554 +/* ---------------------------------------------------------------------- */
15557 +#ifdef CONFIG_AUFS_HNOTIFY
15558 +struct au_hnotify_op {
15559 + void (*ctl)(struct au_hinode *hinode, int do_set);
15560 + int (*alloc)(struct au_hinode *hinode);
15563 + * if it returns true, the the caller should free hinode->hi_notify,
15564 + * otherwise ->free() frees it.
15566 + int (*free)(struct au_hinode *hinode,
15567 + struct au_hnotify *hn) __must_check;
15569 + void (*fin)(void);
15570 + int (*init)(void);
15572 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
15573 + void (*fin_br)(struct au_branch *br);
15574 + int (*init_br)(struct au_branch *br, int perm);
15578 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
15579 +void au_hn_free(struct au_hinode *hinode);
15580 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
15581 +void au_hn_reset(struct inode *inode, unsigned int flags);
15582 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
15583 + struct qstr *h_child_qstr, struct inode *h_child_inode);
15584 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
15585 +int au_hnotify_init_br(struct au_branch *br, int perm);
15586 +void au_hnotify_fin_br(struct au_branch *br);
15587 +int __init au_hnotify_init(void);
15588 +void au_hnotify_fin(void);
15591 +extern const struct au_hnotify_op au_hnotify_op;
15594 +void au_hn_init(struct au_hinode *hinode)
15596 + hinode->hi_notify = NULL;
15599 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
15601 + return hinode->hi_notify;
15606 +int au_hn_alloc(struct au_hinode *hinode __maybe_unused,
15607 + struct inode *inode __maybe_unused)
15609 + return -EOPNOTSUPP;
15612 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
15617 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
15618 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
15619 + int do_set __maybe_unused)
15620 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
15621 + unsigned int flags __maybe_unused)
15622 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
15623 + struct au_branch *br __maybe_unused,
15624 + int perm __maybe_unused)
15625 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
15626 + int perm __maybe_unused)
15627 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
15628 +AuStubInt0(__init au_hnotify_init, void)
15629 +AuStubVoid(au_hnotify_fin, void)
15630 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
15631 +#endif /* CONFIG_AUFS_HNOTIFY */
15633 +static inline void au_hn_suspend(struct au_hinode *hdir)
15635 + au_hn_ctl(hdir, /*do_set*/0);
15638 +static inline void au_hn_resume(struct au_hinode *hdir)
15640 + au_hn_ctl(hdir, /*do_set*/1);
15643 +static inline void au_hn_imtx_lock(struct au_hinode *hdir)
15645 + mutex_lock(&hdir->hi_inode->i_mutex);
15646 + au_hn_suspend(hdir);
15649 +static inline void au_hn_imtx_lock_nested(struct au_hinode *hdir,
15650 + unsigned int sc __maybe_unused)
15652 + mutex_lock_nested(&hdir->hi_inode->i_mutex, sc);
15653 + au_hn_suspend(hdir);
15656 +static inline void au_hn_imtx_unlock(struct au_hinode *hdir)
15658 + au_hn_resume(hdir);
15659 + mutex_unlock(&hdir->hi_inode->i_mutex);
15662 +#endif /* __KERNEL__ */
15663 +#endif /* __AUFS_INODE_H__ */
15664 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
15665 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
15666 +++ linux/fs/aufs/ioctl.c 2013-10-26 16:51:32.276373845 +0200
15669 + * Copyright (C) 2005-2013 Junjiro R. Okajima
15671 + * This program, aufs is free software; you can redistribute it and/or modify
15672 + * it under the terms of the GNU General Public License as published by
15673 + * the Free Software Foundation; either version 2 of the License, or
15674 + * (at your option) any later version.
15676 + * This program is distributed in the hope that it will be useful,
15677 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15678 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15679 + * GNU General Public License for more details.
15681 + * You should have received a copy of the GNU General Public License
15682 + * along with this program; if not, write to the Free Software
15683 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15688 + * plink-management and readdir in userspace.
15689 + * assist the pathconf(3) wrapper library.
15693 +#include <linux/compat.h>
15694 +#include <linux/file.h>
15697 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
15700 + aufs_bindex_t wbi, bindex, bend;
15701 + struct file *h_file;
15702 + struct super_block *sb;
15703 + struct dentry *root;
15704 + struct au_branch *br;
15705 + struct aufs_wbr_fd wbrfd = {
15706 + .oflags = au_dir_roflags,
15709 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
15710 + | O_NOATIME | O_CLOEXEC;
15712 + AuDebugOn(wbrfd.oflags & ~valid);
15715 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
15716 + if (unlikely(err)) {
15722 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
15723 + wbrfd.oflags |= au_dir_roflags;
15724 + AuDbg("0%o\n", wbrfd.oflags);
15725 + if (unlikely(wbrfd.oflags & ~valid))
15729 + fd = get_unused_fd();
15731 + if (unlikely(fd < 0))
15734 + h_file = ERR_PTR(-EINVAL);
15737 + sb = path->dentry->d_sb;
15738 + root = sb->s_root;
15739 + aufs_read_lock(root, AuLock_IR);
15740 + bend = au_sbend(sb);
15741 + if (wbrfd.brid >= 0) {
15742 + wbi = au_br_index(sb, wbrfd.brid);
15743 + if (unlikely(wbi < 0 || wbi > bend))
15747 + h_file = ERR_PTR(-ENOENT);
15748 + br = au_sbr(sb, wbi);
15749 + if (!au_br_writable(br->br_perm)) {
15753 + bindex = wbi + 1;
15755 + for (; bindex <= bend; bindex++) {
15756 + br = au_sbr(sb, bindex);
15757 + if (au_br_writable(br->br_perm)) {
15759 + br = au_sbr(sb, wbi);
15764 + AuDbg("wbi %d\n", wbi);
15766 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
15770 + aufs_read_unlock(root, AuLock_IR);
15771 + err = PTR_ERR(h_file);
15772 + if (IS_ERR(h_file))
15775 + atomic_dec(&br->br_count); /* cf. au_h_open() */
15776 + fd_install(fd, h_file);
15778 + goto out; /* success */
15781 + put_unused_fd(fd);
15787 +/* ---------------------------------------------------------------------- */
15789 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
15794 + case AUFS_CTL_RDU:
15795 + case AUFS_CTL_RDU_INO:
15796 + err = au_rdu_ioctl(file, cmd, arg);
15799 + case AUFS_CTL_WBR_FD:
15800 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
15803 + case AUFS_CTL_IBUSY:
15804 + err = au_ibusy_ioctl(file, arg);
15808 + /* do not call the lower */
15809 + AuDbg("0x%x\n", cmd);
15817 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
15822 + case AUFS_CTL_MVDOWN:
15823 + err = au_mvdown(file->f_dentry, (void __user *)arg);
15826 + case AUFS_CTL_WBR_FD:
15827 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
15831 + /* do not call the lower */
15832 + AuDbg("0x%x\n", cmd);
15840 +#ifdef CONFIG_COMPAT
15841 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15842 + unsigned long arg)
15847 + case AUFS_CTL_RDU:
15848 + case AUFS_CTL_RDU_INO:
15849 + err = au_rdu_compat_ioctl(file, cmd, arg);
15852 + case AUFS_CTL_IBUSY:
15853 + err = au_ibusy_compat_ioctl(file, arg);
15857 + err = aufs_ioctl_dir(file, cmd, arg);
15864 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15865 + unsigned long arg)
15867 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
15870 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
15871 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
15872 +++ linux/fs/aufs/i_op_add.c 2013-10-26 16:51:32.273040419 +0200
15875 + * Copyright (C) 2005-2013 Junjiro R. Okajima
15877 + * This program, aufs is free software; you can redistribute it and/or modify
15878 + * it under the terms of the GNU General Public License as published by
15879 + * the Free Software Foundation; either version 2 of the License, or
15880 + * (at your option) any later version.
15882 + * This program is distributed in the hope that it will be useful,
15883 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15884 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15885 + * GNU General Public License for more details.
15887 + * You should have received a copy of the GNU General Public License
15888 + * along with this program; if not, write to the Free Software
15889 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15893 + * inode operations (add entry)
15899 + * final procedure of adding a new entry, except link(2).
15900 + * remove whiteout, instantiate, copyup the parent dir's times and size
15901 + * and update version.
15902 + * if it failed, re-create the removed whiteout.
15904 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
15905 + struct dentry *wh_dentry, struct dentry *dentry)
15908 + aufs_bindex_t bwh;
15909 + struct path h_path;
15910 + struct inode *inode, *h_dir;
15911 + struct dentry *wh;
15915 + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
15916 + IMustLock(h_dir);
15917 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
15918 + bwh = au_dbwh(dentry);
15919 + h_path.dentry = wh_dentry;
15920 + h_path.mnt = au_sbr_mnt(dir->i_sb, bindex);
15921 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
15923 + if (unlikely(err))
15927 + inode = au_new_inode(dentry, /*must_new*/1);
15928 + if (!IS_ERR(inode)) {
15929 + d_instantiate(dentry, inode);
15930 + dir = dentry->d_parent->d_inode; /* dir inode is locked */
15932 + if (au_ibstart(dir) == au_dbstart(dentry))
15933 + au_cpup_attr_timesizes(dir);
15934 + dir->i_version++;
15935 + return 0; /* success */
15938 + err = PTR_ERR(inode);
15943 + /* dir inode is locked */
15944 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
15945 + rerr = PTR_ERR(wh);
15946 + if (IS_ERR(wh)) {
15947 + AuIOErr("%.*s reverting whiteout failed(%d, %d)\n",
15948 + AuDLNPair(dentry), err, rerr);
15957 +static int au_d_may_add(struct dentry *dentry)
15962 + if (unlikely(d_unhashed(dentry)))
15964 + if (unlikely(dentry->d_inode))
15970 + * simple tests for the adding inode operations.
15971 + * following the checks in vfs, plus the parent-child relationship.
15973 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
15974 + struct dentry *h_parent, int isdir)
15978 + struct dentry *h_dentry;
15979 + struct inode *h_inode;
15981 + err = -ENAMETOOLONG;
15982 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
15985 + h_dentry = au_h_dptr(dentry, bindex);
15986 + h_inode = h_dentry->d_inode;
15987 + if (!dentry->d_inode) {
15989 + if (unlikely(h_inode))
15992 + /* rename(2) case */
15994 + if (unlikely(!h_inode || !h_inode->i_nlink))
15997 + h_mode = h_inode->i_mode;
16000 + if (unlikely(S_ISDIR(h_mode)))
16002 + } else if (unlikely(!S_ISDIR(h_mode))) {
16009 + /* expected parent dir is locked */
16010 + if (unlikely(h_parent != h_dentry->d_parent))
16019 + * initial procedure of adding a new entry.
16020 + * prepare writable branch and the parent dir, lock it,
16021 + * and lookup whiteout for the new entry.
16023 +static struct dentry*
16024 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
16025 + struct dentry *src_dentry, struct au_pin *pin,
16026 + struct au_wr_dir_args *wr_dir_args)
16028 + struct dentry *wh_dentry, *h_parent;
16029 + struct super_block *sb;
16030 + struct au_branch *br;
16032 + unsigned int udba;
16033 + aufs_bindex_t bcpup;
16035 + AuDbg("%.*s\n", AuDLNPair(dentry));
16037 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
16039 + wh_dentry = ERR_PTR(err);
16040 + if (unlikely(err < 0))
16043 + sb = dentry->d_sb;
16044 + udba = au_opt_udba(sb);
16045 + err = au_pin(pin, dentry, bcpup, udba,
16046 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
16047 + wh_dentry = ERR_PTR(err);
16048 + if (unlikely(err))
16051 + h_parent = au_pinned_h_parent(pin);
16052 + if (udba != AuOpt_UDBA_NONE
16053 + && au_dbstart(dentry) == bcpup)
16054 + err = au_may_add(dentry, bcpup, h_parent,
16055 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
16056 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
16057 + err = -ENAMETOOLONG;
16058 + wh_dentry = ERR_PTR(err);
16059 + if (unlikely(err))
16062 + br = au_sbr(sb, bcpup);
16064 + struct path tmp = {
16065 + .dentry = h_parent,
16066 + .mnt = au_br_mnt(br)
16068 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
16071 + wh_dentry = NULL;
16072 + if (bcpup != au_dbwh(dentry))
16073 + goto out; /* success */
16075 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
16078 + if (IS_ERR(wh_dentry))
16081 + return wh_dentry;
16084 +/* ---------------------------------------------------------------------- */
16086 +enum { Mknod, Symlink, Creat };
16087 +struct simple_arg {
16095 + const char *symname;
16104 +static int add_simple(struct inode *dir, struct dentry *dentry,
16105 + struct simple_arg *arg)
16108 + aufs_bindex_t bstart;
16109 + unsigned char created;
16110 + struct dentry *wh_dentry, *parent;
16111 + struct inode *h_dir;
16112 + /* to reuduce stack size */
16114 + struct au_dtime dt;
16115 + struct au_pin pin;
16116 + struct path h_path;
16117 + struct au_wr_dir_args wr_dir_args;
16120 + AuDbg("%.*s\n", AuDLNPair(dentry));
16124 + a = kmalloc(sizeof(*a), GFP_NOFS);
16125 + if (unlikely(!a))
16127 + a->wr_dir_args.force_btgt = -1;
16128 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
16130 + parent = dentry->d_parent; /* dir inode is locked */
16131 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
16132 + if (unlikely(err))
16134 + err = au_d_may_add(dentry);
16135 + if (unlikely(err))
16137 + di_write_lock_parent(parent);
16138 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
16139 + &a->pin, &a->wr_dir_args);
16140 + err = PTR_ERR(wh_dentry);
16141 + if (IS_ERR(wh_dentry))
16144 + bstart = au_dbstart(dentry);
16145 + a->h_path.dentry = au_h_dptr(dentry, bstart);
16146 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
16147 + h_dir = au_pinned_h_dir(&a->pin);
16148 + switch (arg->type) {
16150 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
16151 + arg->u.c.want_excl);
16154 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
16157 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
16165 + err = epilog(dir, bstart, wh_dentry, dentry);
16168 + if (unlikely(created && err && a->h_path.dentry->d_inode)) {
16170 + rerr = vfsub_unlink(h_dir, &a->h_path, /*force*/0);
16172 + AuIOErr("%.*s revert failure(%d, %d)\n",
16173 + AuDLNPair(dentry), err, rerr);
16176 + au_dtime_revert(&a->dt);
16179 + au_unpin(&a->pin);
16183 + di_write_unlock(parent);
16185 + if (unlikely(err)) {
16186 + au_update_dbstart(dentry);
16189 + aufs_read_unlock(dentry, AuLock_DW);
16196 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
16199 + struct simple_arg arg = {
16206 + return add_simple(dir, dentry, &arg);
16209 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
16211 + struct simple_arg arg = {
16213 + .u.s.symname = symname
16215 + return add_simple(dir, dentry, &arg);
16218 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
16221 + struct simple_arg arg = {
16225 + .want_excl = want_excl
16228 + return add_simple(dir, dentry, &arg);
16231 +/* ---------------------------------------------------------------------- */
16233 +struct au_link_args {
16234 + aufs_bindex_t bdst, bsrc;
16235 + struct au_pin pin;
16236 + struct path h_path;
16237 + struct dentry *src_parent, *parent;
16240 +static int au_cpup_before_link(struct dentry *src_dentry,
16241 + struct au_link_args *a)
16244 + struct dentry *h_src_dentry;
16245 + struct au_cp_generic cpg = {
16246 + .dentry = src_dentry,
16251 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
16254 + di_read_lock_parent(a->src_parent, AuLock_IR);
16255 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
16256 + if (unlikely(err))
16259 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
16260 + err = au_pin(&a->pin, src_dentry, a->bdst,
16261 + au_opt_udba(src_dentry->d_sb),
16262 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
16263 + if (unlikely(err))
16266 + err = au_sio_cpup_simple(&cpg);
16267 + au_unpin(&a->pin);
16270 + di_read_unlock(a->src_parent, AuLock_IR);
16274 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
16275 + struct au_link_args *a)
16278 + unsigned char plink;
16279 + aufs_bindex_t bend;
16280 + struct dentry *h_src_dentry;
16281 + struct inode *h_inode, *inode;
16282 + struct super_block *sb;
16283 + struct file *h_file;
16287 + sb = src_dentry->d_sb;
16288 + inode = src_dentry->d_inode;
16289 + if (au_ibstart(inode) <= a->bdst)
16290 + h_inode = au_h_iptr(inode, a->bdst);
16291 + if (!h_inode || !h_inode->i_nlink) {
16292 + /* copyup src_dentry as the name of dentry. */
16293 + bend = au_dbend(dentry);
16294 + if (bend < a->bsrc)
16295 + au_set_dbend(dentry, a->bsrc);
16296 + au_set_h_dptr(dentry, a->bsrc,
16297 + dget(au_h_dptr(src_dentry, a->bsrc)));
16298 + dget(a->h_path.dentry);
16299 + au_set_h_dptr(dentry, a->bdst, NULL);
16300 + dentry->d_inode = src_dentry->d_inode; /* tmp */
16301 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
16302 + if (IS_ERR(h_file))
16303 + err = PTR_ERR(h_file);
16305 + struct au_cp_generic cpg = {
16306 + .dentry = dentry,
16311 + .flags = AuCpup_KEEPLINO
16313 + err = au_sio_cpup_simple(&cpg);
16314 + au_h_open_post(dentry, a->bsrc, h_file);
16316 + dput(a->h_path.dentry);
16317 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
16319 + au_set_h_dptr(dentry, a->bdst,
16320 + a->h_path.dentry);
16322 + dentry->d_inode = NULL; /* restore */
16323 + au_set_h_dptr(dentry, a->bsrc, NULL);
16324 + au_set_dbend(dentry, bend);
16326 + /* the inode of src_dentry already exists on a.bdst branch */
16327 + h_src_dentry = d_find_alias(h_inode);
16328 + if (!h_src_dentry && au_plink_test(inode)) {
16330 + h_src_dentry = au_plink_lkup(inode, a->bdst);
16331 + err = PTR_ERR(h_src_dentry);
16332 + if (IS_ERR(h_src_dentry))
16335 + if (unlikely(!h_src_dentry->d_inode)) {
16336 + dput(h_src_dentry);
16337 + h_src_dentry = NULL;
16341 + if (h_src_dentry) {
16342 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
16344 + dput(h_src_dentry);
16346 + AuIOErr("no dentry found for hi%lu on b%d\n",
16347 + h_inode->i_ino, a->bdst);
16352 + if (!err && !plink)
16353 + au_plink_append(inode, a->bdst, a->h_path.dentry);
16360 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
16361 + struct dentry *dentry)
16364 + struct au_dtime dt;
16365 + struct au_link_args *a;
16366 + struct dentry *wh_dentry, *h_src_dentry;
16367 + struct inode *inode;
16368 + struct super_block *sb;
16369 + struct au_wr_dir_args wr_dir_args = {
16370 + /* .force_btgt = -1, */
16371 + .flags = AuWrDir_ADD_ENTRY
16375 + inode = src_dentry->d_inode;
16376 + IMustLock(inode);
16379 + a = kzalloc(sizeof(*a), GFP_NOFS);
16380 + if (unlikely(!a))
16383 + a->parent = dentry->d_parent; /* dir inode is locked */
16384 + err = aufs_read_and_write_lock2(dentry, src_dentry,
16385 + AuLock_NOPLM | AuLock_GEN);
16386 + if (unlikely(err))
16388 + err = au_d_hashed_positive(src_dentry);
16389 + if (unlikely(err))
16391 + err = au_d_may_add(dentry);
16392 + if (unlikely(err))
16395 + a->src_parent = dget_parent(src_dentry);
16396 + wr_dir_args.force_btgt = au_ibstart(inode);
16398 + di_write_lock_parent(a->parent);
16399 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
16400 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
16402 + err = PTR_ERR(wh_dentry);
16403 + if (IS_ERR(wh_dentry))
16407 + sb = dentry->d_sb;
16408 + a->bdst = au_dbstart(dentry);
16409 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
16410 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
16411 + a->bsrc = au_ibstart(inode);
16412 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
16413 + if (!h_src_dentry) {
16414 + a->bsrc = au_dbstart(src_dentry);
16415 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
16416 + AuDebugOn(!h_src_dentry);
16417 + } else if (IS_ERR(h_src_dentry))
16420 + if (au_opt_test(au_mntflags(sb), PLINK)) {
16421 + if (a->bdst < a->bsrc
16422 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
16423 + err = au_cpup_or_link(src_dentry, dentry, a);
16425 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
16427 + dput(h_src_dentry);
16430 + * copyup src_dentry to the branch we process,
16431 + * and then link(2) to it.
16433 + dput(h_src_dentry);
16434 + if (a->bdst < a->bsrc
16435 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
16436 + au_unpin(&a->pin);
16437 + di_write_unlock(a->parent);
16438 + err = au_cpup_before_link(src_dentry, a);
16439 + di_write_lock_parent(a->parent);
16441 + err = au_pin(&a->pin, dentry, a->bdst,
16443 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
16444 + if (unlikely(err))
16448 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
16450 + if (h_src_dentry && h_src_dentry->d_inode)
16451 + err = vfsub_link(h_src_dentry,
16452 + au_pinned_h_dir(&a->pin),
16456 + if (unlikely(err))
16460 + a->h_path.dentry = wh_dentry;
16461 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
16463 + if (unlikely(err))
16467 + dir->i_version++;
16468 + if (au_ibstart(dir) == au_dbstart(dentry))
16469 + au_cpup_attr_timesizes(dir);
16470 + inc_nlink(inode);
16471 + inode->i_ctime = dir->i_ctime;
16472 + d_instantiate(dentry, au_igrab(inode));
16473 + if (d_unhashed(a->h_path.dentry))
16474 + /* some filesystem calls d_drop() */
16476 + goto out_unpin; /* success */
16479 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path, /*force*/0);
16480 + if (unlikely(rerr)) {
16481 + AuIOErr("%.*s reverting failed(%d, %d)\n",
16482 + AuDLNPair(dentry), err, rerr);
16485 + au_dtime_revert(&dt);
16487 + au_unpin(&a->pin);
16491 + di_write_unlock(a->parent);
16492 + dput(a->src_parent);
16494 + if (unlikely(err)) {
16495 + au_update_dbstart(dentry);
16498 + aufs_read_and_write_unlock2(dentry, src_dentry);
16506 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
16509 + aufs_bindex_t bindex;
16510 + unsigned char diropq;
16511 + struct path h_path;
16512 + struct dentry *wh_dentry, *parent, *opq_dentry;
16513 + struct mutex *h_mtx;
16514 + struct super_block *sb;
16516 + struct au_pin pin;
16517 + struct au_dtime dt;
16518 + } *a; /* reduce the stack usage */
16519 + struct au_wr_dir_args wr_dir_args = {
16520 + .force_btgt = -1,
16521 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
16527 + a = kmalloc(sizeof(*a), GFP_NOFS);
16528 + if (unlikely(!a))
16531 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
16532 + if (unlikely(err))
16534 + err = au_d_may_add(dentry);
16535 + if (unlikely(err))
16538 + parent = dentry->d_parent; /* dir inode is locked */
16539 + di_write_lock_parent(parent);
16540 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
16541 + &a->pin, &wr_dir_args);
16542 + err = PTR_ERR(wh_dentry);
16543 + if (IS_ERR(wh_dentry))
16546 + sb = dentry->d_sb;
16547 + bindex = au_dbstart(dentry);
16548 + h_path.dentry = au_h_dptr(dentry, bindex);
16549 + h_path.mnt = au_sbr_mnt(sb, bindex);
16550 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
16551 + if (unlikely(err))
16554 + /* make the dir opaque */
16556 + h_mtx = &h_path.dentry->d_inode->i_mutex;
16558 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
16559 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
16560 + opq_dentry = au_diropq_create(dentry, bindex);
16561 + mutex_unlock(h_mtx);
16562 + err = PTR_ERR(opq_dentry);
16563 + if (IS_ERR(opq_dentry))
16565 + dput(opq_dentry);
16569 + err = epilog(dir, bindex, wh_dentry, dentry);
16572 + goto out_unpin; /* success */
16577 + AuLabel(revert opq);
16578 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
16579 + rerr = au_diropq_remove(dentry, bindex);
16580 + mutex_unlock(h_mtx);
16582 + AuIOErr("%.*s reverting diropq failed(%d, %d)\n",
16583 + AuDLNPair(dentry), err, rerr);
16589 + AuLabel(revert dir);
16590 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
16592 + AuIOErr("%.*s reverting dir failed(%d, %d)\n",
16593 + AuDLNPair(dentry), err, rerr);
16596 + au_dtime_revert(&a->dt);
16598 + au_unpin(&a->pin);
16601 + di_write_unlock(parent);
16603 + if (unlikely(err)) {
16604 + au_update_dbstart(dentry);
16607 + aufs_read_unlock(dentry, AuLock_DW);
16613 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
16614 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
16615 +++ linux/fs/aufs/i_op.c 2013-10-26 16:51:32.273040419 +0200
16618 + * Copyright (C) 2005-2013 Junjiro R. Okajima
16620 + * This program, aufs is free software; you can redistribute it and/or modify
16621 + * it under the terms of the GNU General Public License as published by
16622 + * the Free Software Foundation; either version 2 of the License, or
16623 + * (at your option) any later version.
16625 + * This program is distributed in the hope that it will be useful,
16626 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16627 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16628 + * GNU General Public License for more details.
16630 + * You should have received a copy of the GNU General Public License
16631 + * along with this program; if not, write to the Free Software
16632 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16636 + * inode operations (except add/del/rename)
16639 +#include <linux/device_cgroup.h>
16640 +#include <linux/fs_stack.h>
16641 +#include <linux/mm.h>
16642 +#include <linux/namei.h>
16643 +#include <linux/security.h>
16646 +static int h_permission(struct inode *h_inode, int mask,
16647 + struct vfsmount *h_mnt, int brperm)
16650 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
16653 + if ((write_mask && IS_IMMUTABLE(h_inode))
16654 + || ((mask & MAY_EXEC)
16655 + && S_ISREG(h_inode->i_mode)
16656 + && ((h_mnt->mnt_flags & MNT_NOEXEC)
16657 + || !(h_inode->i_mode & S_IXUGO))))
16661 + * - skip the lower fs test in the case of write to ro branch.
16662 + * - nfs dir permission write check is optimized, but a policy for
16663 + * link/rename requires a real check.
16665 + if ((write_mask && !au_br_writable(brperm))
16666 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
16667 + && write_mask && !(mask & MAY_READ))
16668 + || !h_inode->i_op->permission) {
16669 + /* AuLabel(generic_permission); */
16670 + err = generic_permission(h_inode, mask);
16672 + /* AuLabel(h_inode->permission); */
16673 + err = h_inode->i_op->permission(h_inode, mask);
16678 + err = devcgroup_inode_permission(h_inode, mask);
16680 + err = security_inode_permission(h_inode, mask);
16684 + /* todo: do we need to call ima_path_check()? */
16685 + struct path h_path = {
16689 + err = ima_path_check(&h_path,
16690 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
16691 + IMA_COUNT_LEAVE);
16699 +static int aufs_permission(struct inode *inode, int mask)
16702 + aufs_bindex_t bindex, bend;
16703 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
16704 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
16705 + struct inode *h_inode;
16706 + struct super_block *sb;
16707 + struct au_branch *br;
16709 + /* todo: support rcu-walk? */
16710 + if (mask & MAY_NOT_BLOCK)
16713 + sb = inode->i_sb;
16714 + si_read_lock(sb, AuLock_FLUSH);
16715 + ii_read_lock_child(inode);
16717 + err = au_iigen_test(inode, au_sigen(sb));
16718 + if (unlikely(err))
16722 + if (!isdir || write_mask) {
16723 + err = au_busy_or_stale();
16724 + h_inode = au_h_iptr(inode, au_ibstart(inode));
16725 + if (unlikely(!h_inode
16726 + || (h_inode->i_mode & S_IFMT)
16727 + != (inode->i_mode & S_IFMT)))
16731 + bindex = au_ibstart(inode);
16732 + br = au_sbr(sb, bindex);
16733 + err = h_permission(h_inode, mask, au_br_mnt(br), br->br_perm);
16736 + && !special_file(h_inode->i_mode)) {
16737 + /* test whether the upper writable branch exists */
16739 + for (; bindex >= 0; bindex--)
16740 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
16748 + /* non-write to dir */
16750 + bend = au_ibend(inode);
16751 + for (bindex = au_ibstart(inode); !err && bindex <= bend; bindex++) {
16752 + h_inode = au_h_iptr(inode, bindex);
16754 + err = au_busy_or_stale();
16755 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
16758 + br = au_sbr(sb, bindex);
16759 + err = h_permission(h_inode, mask, au_br_mnt(br),
16765 + ii_read_unlock(inode);
16766 + si_read_unlock(sb);
16770 +/* ---------------------------------------------------------------------- */
16772 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
16773 + unsigned int flags)
16775 + struct dentry *ret, *parent;
16776 + struct inode *inode;
16777 + struct super_block *sb;
16778 + int err, npositive;
16782 + /* todo: support rcu-walk? */
16783 + ret = ERR_PTR(-ECHILD);
16784 + if (flags & LOOKUP_RCU)
16787 + ret = ERR_PTR(-ENAMETOOLONG);
16788 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
16792 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16793 + ret = ERR_PTR(err);
16794 + if (unlikely(err))
16797 + err = au_di_init(dentry);
16798 + ret = ERR_PTR(err);
16799 + if (unlikely(err))
16803 + npositive = 0; /* suppress a warning */
16804 + parent = dentry->d_parent; /* dir inode is locked */
16805 + di_read_lock_parent(parent, AuLock_IR);
16806 + err = au_alive_dir(parent);
16808 + err = au_digen_test(parent, au_sigen(sb));
16810 + npositive = au_lkup_dentry(dentry, au_dbstart(parent),
16814 + di_read_unlock(parent, AuLock_IR);
16815 + ret = ERR_PTR(err);
16816 + if (unlikely(err < 0))
16820 + inode = au_new_inode(dentry, /*must_new*/0);
16821 + ret = (void *)inode;
16823 + if (IS_ERR(inode)) {
16828 + ret = d_splice_alias(inode, dentry);
16830 + if (unlikely(d_need_lookup(dentry))) {
16831 + spin_lock(&dentry->d_lock);
16832 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
16833 + spin_unlock(&dentry->d_lock);
16836 + if (unlikely(IS_ERR(ret) && inode)) {
16837 + ii_write_unlock(inode);
16843 + di_write_unlock(dentry);
16845 + /* verbose coding for lock class name */
16846 + if (unlikely(S_ISLNK(inode->i_mode)))
16847 + au_rw_class(&au_di(dentry)->di_rwsem,
16848 + au_lc_key + AuLcSymlink_DIINFO);
16849 + else if (unlikely(S_ISDIR(inode->i_mode)))
16850 + au_rw_class(&au_di(dentry)->di_rwsem,
16851 + au_lc_key + AuLcDir_DIINFO);
16852 + else /* likely */
16853 + au_rw_class(&au_di(dentry)->di_rwsem,
16854 + au_lc_key + AuLcNonDir_DIINFO);
16857 + si_read_unlock(sb);
16862 +/* ---------------------------------------------------------------------- */
16864 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
16865 + const unsigned char add_entry, aufs_bindex_t bcpup,
16866 + aufs_bindex_t bstart)
16869 + struct dentry *h_parent;
16870 + struct inode *h_dir;
16873 + IMustLock(parent->d_inode);
16875 + di_write_lock_parent(parent);
16878 + if (!au_h_dptr(parent, bcpup)) {
16879 + if (bstart > bcpup)
16880 + err = au_cpup_dirs(dentry, bcpup);
16881 + else if (bstart < bcpup)
16882 + err = au_cpdown_dirs(dentry, bcpup);
16886 + if (!err && add_entry) {
16887 + h_parent = au_h_dptr(parent, bcpup);
16888 + h_dir = h_parent->d_inode;
16889 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
16890 + err = au_lkup_neg(dentry, bcpup,
16891 + au_ftest_wrdir(add_entry, TMP_WHENTRY));
16892 + /* todo: no unlock here */
16893 + mutex_unlock(&h_dir->i_mutex);
16895 + AuDbg("bcpup %d\n", bcpup);
16897 + if (!dentry->d_inode)
16898 + au_set_h_dptr(dentry, bstart, NULL);
16899 + au_update_dbrange(dentry, /*do_put_zero*/0);
16904 + di_write_unlock(parent);
16906 + err = bcpup; /* success */
16913 + * decide the branch and the parent dir where we will create a new entry.
16914 + * returns new bindex or an error.
16915 + * copyup the parent dir if needed.
16917 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
16918 + struct au_wr_dir_args *args)
16921 + unsigned int flags;
16922 + aufs_bindex_t bcpup, bstart, src_bstart;
16923 + const unsigned char add_entry
16924 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
16925 + | au_ftest_wrdir(args->flags, TMP_WHENTRY);
16926 + struct super_block *sb;
16927 + struct dentry *parent;
16928 + struct au_sbinfo *sbinfo;
16930 + sb = dentry->d_sb;
16931 + sbinfo = au_sbi(sb);
16932 + parent = dget_parent(dentry);
16933 + bstart = au_dbstart(dentry);
16935 + if (args->force_btgt < 0) {
16936 + if (src_dentry) {
16937 + src_bstart = au_dbstart(src_dentry);
16938 + if (src_bstart < bstart)
16939 + bcpup = src_bstart;
16940 + } else if (add_entry) {
16942 + if (au_ftest_wrdir(args->flags, ISDIR))
16943 + au_fset_wbr(flags, DIR);
16944 + err = AuWbrCreate(sbinfo, dentry, flags);
16948 + if (bcpup < 0 || au_test_ro(sb, bcpup, dentry->d_inode)) {
16950 + err = AuWbrCopyup(sbinfo, dentry);
16952 + if (!IS_ROOT(dentry)) {
16953 + di_read_lock_parent(parent, !AuLock_IR);
16954 + err = AuWbrCopyup(sbinfo, dentry);
16955 + di_read_unlock(parent, !AuLock_IR);
16957 + err = AuWbrCopyup(sbinfo, dentry);
16960 + if (unlikely(err < 0))
16964 + bcpup = args->force_btgt;
16965 + AuDebugOn(au_test_ro(sb, bcpup, dentry->d_inode));
16968 + AuDbg("bstart %d, bcpup %d\n", bstart, bcpup);
16970 + if (bcpup == bstart)
16971 + goto out; /* success */
16973 + /* copyup the new parent into the branch we process */
16974 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, bstart);
16976 + if (!dentry->d_inode) {
16977 + au_set_h_dptr(dentry, bstart, NULL);
16978 + au_set_dbstart(dentry, bcpup);
16979 + au_set_dbend(dentry, bcpup);
16981 + AuDebugOn(add_entry && !au_h_dptr(dentry, bcpup));
16989 +/* ---------------------------------------------------------------------- */
16991 +void au_pin_hdir_unlock(struct au_pin *p)
16994 + au_hn_imtx_unlock(p->hdir);
16997 +static int au_pin_hdir_lock(struct au_pin *p)
17005 + /* even if an error happens later, keep this lock */
17006 + au_hn_imtx_lock_nested(p->hdir, p->lsc_hi);
17009 + if (unlikely(p->hdir->hi_inode != p->h_parent->d_inode))
17014 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
17015 + p->h_parent, p->br);
17021 +int au_pin_hdir_relock(struct au_pin *p)
17024 + struct inode *h_i;
17025 + struct dentry *h_d[] = {
17030 + err = au_pin_hdir_lock(p);
17031 + if (unlikely(err))
17034 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
17037 + h_i = h_d[i]->d_inode;
17039 + err = !h_i->i_nlink;
17046 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
17048 +#if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
17049 + p->hdir->hi_inode->i_mutex.owner = task;
17053 +void au_pin_hdir_acquire_nest(struct au_pin *p)
17056 + mutex_acquire_nest(&p->hdir->hi_inode->i_mutex.dep_map,
17057 + p->lsc_hi, 0, NULL, _RET_IP_);
17058 + au_pin_hdir_set_owner(p, current);
17062 +void au_pin_hdir_release(struct au_pin *p)
17065 + au_pin_hdir_set_owner(p, p->task);
17066 + mutex_release(&p->hdir->hi_inode->i_mutex.dep_map, 1, _RET_IP_);
17070 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
17072 + if (pin && pin->parent)
17073 + return au_h_dptr(pin->parent, pin->bindex);
17077 +void au_unpin(struct au_pin *p)
17080 + au_pin_hdir_unlock(p);
17081 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
17082 + vfsub_mnt_drop_write(p->h_mnt);
17086 + if (!au_ftest_pin(p->flags, DI_LOCKED))
17087 + di_read_unlock(p->parent, AuLock_IR);
17088 + iput(p->hdir->hi_inode);
17090 + p->parent = NULL;
17093 + /* do not clear p->task */
17096 +int au_do_pin(struct au_pin *p)
17099 + struct super_block *sb;
17100 + struct inode *h_dir;
17103 + sb = p->dentry->d_sb;
17104 + p->br = au_sbr(sb, p->bindex);
17105 + if (IS_ROOT(p->dentry)) {
17106 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
17107 + p->h_mnt = au_br_mnt(p->br);
17108 + err = vfsub_mnt_want_write(p->h_mnt);
17109 + if (unlikely(err)) {
17110 + au_fclr_pin(p->flags, MNT_WRITE);
17117 + p->h_dentry = NULL;
17118 + if (p->bindex <= au_dbend(p->dentry))
17119 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
17121 + p->parent = dget_parent(p->dentry);
17122 + if (!au_ftest_pin(p->flags, DI_LOCKED))
17123 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
17126 + p->h_parent = au_h_dptr(p->parent, p->bindex);
17127 + p->hdir = au_hi(p->parent->d_inode, p->bindex);
17129 + h_dir = p->hdir->hi_inode;
17133 + * if DI_LOCKED is not set, then p->parent may be different
17134 + * and h_parent can be NULL.
17136 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
17138 + if (!au_ftest_pin(p->flags, DI_LOCKED))
17139 + di_read_unlock(p->parent, AuLock_IR);
17141 + p->parent = NULL;
17145 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
17146 + p->h_mnt = au_br_mnt(p->br);
17147 + err = vfsub_mnt_want_write(p->h_mnt);
17148 + if (unlikely(err)) {
17149 + au_fclr_pin(p->flags, MNT_WRITE);
17150 + if (!au_ftest_pin(p->flags, DI_LOCKED))
17151 + di_read_unlock(p->parent, AuLock_IR);
17153 + p->parent = NULL;
17159 + err = au_pin_hdir_lock(p);
17161 + goto out; /* success */
17164 + pr_err("err %d\n", err);
17165 + err = au_busy_or_stale();
17170 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
17171 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
17172 + unsigned int udba, unsigned char flags)
17174 + p->dentry = dentry;
17176 + p->lsc_di = lsc_di;
17177 + p->lsc_hi = lsc_hi;
17178 + p->flags = flags;
17179 + p->bindex = bindex;
17181 + p->parent = NULL;
17185 + p->h_dentry = NULL;
17186 + p->h_parent = NULL;
17188 + p->task = current;
17191 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
17192 + unsigned int udba, unsigned char flags)
17194 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
17196 + return au_do_pin(pin);
17199 +/* ---------------------------------------------------------------------- */
17202 + * ->setattr() and ->getattr() are called in various cases.
17203 + * chmod, stat: dentry is revalidated.
17204 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
17206 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
17208 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
17209 +static int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
17212 + struct inode *inode;
17213 + struct dentry *parent;
17216 + inode = dentry->d_inode;
17217 + if (au_digen_test(dentry, sigen)) {
17218 + parent = dget_parent(dentry);
17219 + di_read_lock_parent(parent, AuLock_IR);
17220 + err = au_refresh_dentry(dentry, parent);
17221 + di_read_unlock(parent, AuLock_IR);
17229 +#define AuIcpup_DID_CPUP 1
17230 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
17231 +#define au_fset_icpup(flags, name) \
17232 + do { (flags) |= AuIcpup_##name; } while (0)
17233 +#define au_fclr_icpup(flags, name) \
17234 + do { (flags) &= ~AuIcpup_##name; } while (0)
17236 +struct au_icpup_args {
17237 + unsigned char flags;
17238 + unsigned char pin_flags;
17239 + aufs_bindex_t btgt;
17240 + unsigned int udba;
17241 + struct au_pin pin;
17242 + struct path h_path;
17243 + struct inode *h_inode;
17246 +static int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
17247 + struct au_icpup_args *a)
17251 + aufs_bindex_t bstart, ibstart;
17252 + struct dentry *hi_wh, *parent;
17253 + struct inode *inode;
17254 + struct au_wr_dir_args wr_dir_args = {
17255 + .force_btgt = -1,
17259 + bstart = au_dbstart(dentry);
17260 + inode = dentry->d_inode;
17261 + if (S_ISDIR(inode->i_mode))
17262 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
17263 + /* plink or hi_wh() case */
17264 + ibstart = au_ibstart(inode);
17265 + if (bstart != ibstart && !au_test_ro(inode->i_sb, ibstart, inode))
17266 + wr_dir_args.force_btgt = ibstart;
17267 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
17268 + if (unlikely(err < 0))
17271 + if (err != bstart)
17272 + au_fset_icpup(a->flags, DID_CPUP);
17275 + a->pin_flags = AuPin_MNT_WRITE;
17277 + if (!IS_ROOT(dentry)) {
17278 + au_fset_pin(a->pin_flags, DI_LOCKED);
17279 + parent = dget_parent(dentry);
17280 + di_write_lock_parent(parent);
17283 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
17284 + if (unlikely(err))
17287 + a->h_path.dentry = au_h_dptr(dentry, bstart);
17288 + a->h_inode = a->h_path.dentry->d_inode;
17289 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
17291 + if ((ia->ia_valid & ATTR_SIZE) && ia->ia_size < i_size_read(a->h_inode))
17292 + sz = ia->ia_size;
17293 + mutex_unlock(&a->h_inode->i_mutex);
17296 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
17297 + hi_wh = au_hi_wh(inode, a->btgt);
17299 + struct au_cp_generic cpg = {
17300 + .dentry = dentry,
17306 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
17307 + if (unlikely(err))
17309 + hi_wh = au_hi_wh(inode, a->btgt);
17310 + /* todo: revalidate hi_wh? */
17315 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
17316 + di_downgrade_lock(parent, AuLock_IR);
17320 + if (!au_ftest_icpup(a->flags, DID_CPUP))
17321 + goto out; /* success */
17323 + if (!d_unhashed(dentry)) {
17324 + struct au_cp_generic cpg = {
17325 + .dentry = dentry,
17330 + .flags = AuCpup_DTIME | AuCpup_HOPEN
17332 + err = au_sio_cpup_simple(&cpg);
17334 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
17335 + } else if (!hi_wh)
17336 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
17338 + a->h_path.dentry = hi_wh; /* do not dget here */
17341 + a->h_inode = a->h_path.dentry->d_inode;
17343 + goto out; /* success */
17344 + au_unpin(&a->pin);
17347 + di_write_unlock(parent);
17352 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
17356 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
17359 + struct inode *inode;
17360 + struct super_block *sb;
17361 + struct file *file;
17362 + struct au_icpup_args *a;
17364 + inode = dentry->d_inode;
17365 + IMustLock(inode);
17368 + a = kzalloc(sizeof(*a), GFP_NOFS);
17369 + if (unlikely(!a))
17372 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
17373 + ia->ia_valid &= ~ATTR_MODE;
17376 + sb = dentry->d_sb;
17377 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
17378 + if (unlikely(err))
17381 + if (ia->ia_valid & ATTR_FILE) {
17382 + /* currently ftruncate(2) only */
17383 + AuDebugOn(!S_ISREG(inode->i_mode));
17384 + file = ia->ia_file;
17385 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
17386 + if (unlikely(err))
17388 + ia->ia_file = au_hf_top(file);
17389 + a->udba = AuOpt_UDBA_NONE;
17391 + /* fchmod() doesn't pass ia_file */
17392 + a->udba = au_opt_udba(sb);
17393 + di_write_lock_child(dentry);
17394 + /* no d_unlinked(), to set UDBA_NONE for root */
17395 + if (d_unhashed(dentry))
17396 + a->udba = AuOpt_UDBA_NONE;
17397 + if (a->udba != AuOpt_UDBA_NONE) {
17398 + AuDebugOn(IS_ROOT(dentry));
17399 + err = au_reval_for_attr(dentry, au_sigen(sb));
17400 + if (unlikely(err))
17405 + err = au_pin_and_icpup(dentry, ia, a);
17406 + if (unlikely(err < 0))
17408 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
17409 + ia->ia_file = NULL;
17410 + ia->ia_valid &= ~ATTR_FILE;
17413 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
17414 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
17415 + == (ATTR_MODE | ATTR_CTIME)) {
17416 + err = security_path_chmod(&a->h_path, ia->ia_mode);
17417 + if (unlikely(err))
17419 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
17420 + && (ia->ia_valid & ATTR_CTIME)) {
17421 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
17422 + if (unlikely(err))
17426 + if (ia->ia_valid & ATTR_SIZE) {
17429 + if (ia->ia_size < i_size_read(inode))
17431 + truncate_setsize(inode, ia->ia_size);
17434 + if (ia->ia_valid & ATTR_FILE)
17436 + mutex_unlock(&a->h_inode->i_mutex);
17437 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
17438 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
17440 + err = vfsub_notify_change(&a->h_path, ia);
17442 + au_cpup_attr_changeable(inode);
17445 + mutex_unlock(&a->h_inode->i_mutex);
17446 + au_unpin(&a->pin);
17447 + if (unlikely(err))
17448 + au_update_dbstart(dentry);
17450 + di_write_unlock(dentry);
17452 + fi_write_unlock(file);
17453 + ia->ia_file = file;
17454 + ia->ia_valid |= ATTR_FILE;
17457 + si_read_unlock(sb);
17465 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
17466 + unsigned int nlink)
17470 + inode->i_mode = st->mode;
17471 + /* don't i_[ug]id_write() here */
17472 + inode->i_uid = st->uid;
17473 + inode->i_gid = st->gid;
17474 + inode->i_atime = st->atime;
17475 + inode->i_mtime = st->mtime;
17476 + inode->i_ctime = st->ctime;
17478 + au_cpup_attr_nlink(inode, /*force*/0);
17479 + if (S_ISDIR(inode->i_mode)) {
17480 + n = inode->i_nlink;
17484 + /* 0 can happen */
17485 + set_nlink(inode, n);
17488 + spin_lock(&inode->i_lock);
17489 + inode->i_blocks = st->blocks;
17490 + i_size_write(inode, st->size);
17491 + spin_unlock(&inode->i_lock);
17494 +static int aufs_getattr(struct vfsmount *mnt __maybe_unused,
17495 + struct dentry *dentry, struct kstat *st)
17498 + unsigned int mnt_flags;
17499 + aufs_bindex_t bindex;
17500 + unsigned char udba_none, positive;
17501 + struct super_block *sb, *h_sb;
17502 + struct inode *inode;
17503 + struct path h_path;
17505 + sb = dentry->d_sb;
17506 + inode = dentry->d_inode;
17507 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
17508 + if (unlikely(err))
17510 + mnt_flags = au_mntflags(sb);
17511 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
17513 + /* support fstat(2) */
17514 + if (!d_unlinked(dentry) && !udba_none) {
17515 + unsigned int sigen = au_sigen(sb);
17516 + err = au_digen_test(dentry, sigen);
17518 + di_read_lock_child(dentry, AuLock_IR);
17519 + err = au_dbrange_test(dentry);
17520 + if (unlikely(err))
17523 + AuDebugOn(IS_ROOT(dentry));
17524 + di_write_lock_child(dentry);
17525 + err = au_dbrange_test(dentry);
17527 + err = au_reval_for_attr(dentry, sigen);
17528 + di_downgrade_lock(dentry, AuLock_IR);
17529 + if (unlikely(err))
17533 + di_read_lock_child(dentry, AuLock_IR);
17535 + bindex = au_ibstart(inode);
17536 + h_path.mnt = au_sbr_mnt(sb, bindex);
17537 + h_sb = h_path.mnt->mnt_sb;
17538 + if (!au_test_fs_bad_iattr(h_sb) && udba_none)
17539 + goto out_fill; /* success */
17541 + h_path.dentry = NULL;
17542 + if (au_dbstart(dentry) == bindex)
17543 + h_path.dentry = dget(au_h_dptr(dentry, bindex));
17544 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
17545 + h_path.dentry = au_plink_lkup(inode, bindex);
17546 + if (IS_ERR(h_path.dentry))
17547 + goto out_fill; /* pretending success */
17549 + /* illegally overlapped or something */
17550 + if (unlikely(!h_path.dentry))
17551 + goto out_fill; /* pretending success */
17553 + positive = !!h_path.dentry->d_inode;
17555 + err = vfs_getattr(&h_path, st);
17556 + dput(h_path.dentry);
17559 + au_refresh_iattr(inode, st,
17560 + h_path.dentry->d_inode->i_nlink);
17561 + goto out_fill; /* success */
17567 + generic_fillattr(inode, st);
17569 + di_read_unlock(dentry, AuLock_IR);
17570 + si_read_unlock(sb);
17576 +/* ---------------------------------------------------------------------- */
17578 +static int h_readlink(struct dentry *dentry, int bindex, char __user *buf,
17582 + struct super_block *sb;
17583 + struct dentry *h_dentry;
17586 + h_dentry = au_h_dptr(dentry, bindex);
17587 + if (unlikely(!h_dentry->d_inode->i_op->readlink))
17590 + err = security_inode_readlink(h_dentry);
17591 + if (unlikely(err))
17594 + sb = dentry->d_sb;
17595 + if (!au_test_ro(sb, bindex, dentry->d_inode)) {
17596 + vfsub_touch_atime(au_sbr_mnt(sb, bindex), h_dentry);
17597 + fsstack_copy_attr_atime(dentry->d_inode, h_dentry->d_inode);
17599 + err = h_dentry->d_inode->i_op->readlink(h_dentry, buf, bufsiz);
17605 +static int aufs_readlink(struct dentry *dentry, char __user *buf, int bufsiz)
17609 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
17610 + if (unlikely(err))
17612 + err = au_d_hashed_positive(dentry);
17614 + err = h_readlink(dentry, au_dbstart(dentry), buf, bufsiz);
17615 + aufs_read_unlock(dentry, AuLock_IR);
17621 +static void *aufs_follow_link(struct dentry *dentry, struct nameidata *nd)
17624 + mm_segment_t old_fs;
17631 + buf.k = (void *)__get_free_page(GFP_NOFS);
17632 + if (unlikely(!buf.k))
17635 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
17636 + if (unlikely(err))
17639 + err = au_d_hashed_positive(dentry);
17641 + old_fs = get_fs();
17642 + set_fs(KERNEL_DS);
17643 + err = h_readlink(dentry, au_dbstart(dentry), buf.u, PATH_MAX);
17646 + aufs_read_unlock(dentry, AuLock_IR);
17650 + /* will be freed by put_link */
17651 + nd_set_link(nd, buf.k);
17652 + return NULL; /* success */
17656 + free_page((unsigned long)buf.k);
17659 + return ERR_PTR(err);
17662 +static void aufs_put_link(struct dentry *dentry __maybe_unused,
17663 + struct nameidata *nd, void *cookie __maybe_unused)
17667 + p = nd_get_link(nd);
17668 + if (!IS_ERR_OR_NULL(p))
17669 + free_page((unsigned long)p);
17672 +/* ---------------------------------------------------------------------- */
17674 +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags)
17677 + struct super_block *sb;
17678 + struct inode *h_inode;
17680 + sb = inode->i_sb;
17681 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
17683 + si_read_lock(sb, AuLock_FLUSH);
17684 + ii_write_lock_child(inode);
17686 + h_inode = au_h_iptr(inode, au_ibstart(inode));
17687 + err = vfsub_update_time(h_inode, ts, flags);
17689 + ii_write_unlock(inode);
17690 + si_read_unlock(sb);
17695 +/* ---------------------------------------------------------------------- */
17697 +struct inode_operations aufs_symlink_iop = {
17698 + .permission = aufs_permission,
17699 + .setattr = aufs_setattr,
17700 + .getattr = aufs_getattr,
17702 + .readlink = aufs_readlink,
17703 + .follow_link = aufs_follow_link,
17704 + .put_link = aufs_put_link,
17706 + /* .update_time = aufs_update_time */
17709 +struct inode_operations aufs_dir_iop = {
17710 + .create = aufs_create,
17711 + .lookup = aufs_lookup,
17712 + .link = aufs_link,
17713 + .unlink = aufs_unlink,
17714 + .symlink = aufs_symlink,
17715 + .mkdir = aufs_mkdir,
17716 + .rmdir = aufs_rmdir,
17717 + .mknod = aufs_mknod,
17718 + .rename = aufs_rename,
17720 + .permission = aufs_permission,
17721 + .setattr = aufs_setattr,
17722 + .getattr = aufs_getattr,
17724 + .update_time = aufs_update_time
17725 + /* no support for atomic_open() */
17728 +struct inode_operations aufs_iop = {
17729 + .permission = aufs_permission,
17730 + .setattr = aufs_setattr,
17731 + .getattr = aufs_getattr,
17733 + .update_time = aufs_update_time
17735 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
17736 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
17737 +++ linux/fs/aufs/i_op_del.c 2013-10-26 16:51:32.276373845 +0200
17740 + * Copyright (C) 2005-2013 Junjiro R. Okajima
17742 + * This program, aufs is free software; you can redistribute it and/or modify
17743 + * it under the terms of the GNU General Public License as published by
17744 + * the Free Software Foundation; either version 2 of the License, or
17745 + * (at your option) any later version.
17747 + * This program is distributed in the hope that it will be useful,
17748 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17749 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17750 + * GNU General Public License for more details.
17752 + * You should have received a copy of the GNU General Public License
17753 + * along with this program; if not, write to the Free Software
17754 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17758 + * inode operations (del entry)
17764 + * decide if a new whiteout for @dentry is necessary or not.
17765 + * when it is necessary, prepare the parent dir for the upper branch whose
17766 + * branch index is @bcpup for creation. the actual creation of the whiteout will
17767 + * be done by caller.
17769 + * 0: wh is unnecessary
17770 + * plus: wh is necessary
17773 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
17775 + int need_wh, err;
17776 + aufs_bindex_t bstart;
17777 + struct super_block *sb;
17779 + sb = dentry->d_sb;
17780 + bstart = au_dbstart(dentry);
17781 + if (*bcpup < 0) {
17783 + if (au_test_ro(sb, bstart, dentry->d_inode)) {
17784 + err = AuWbrCopyup(au_sbi(sb), dentry);
17786 + if (unlikely(err < 0))
17790 + AuDebugOn(bstart < *bcpup
17791 + || au_test_ro(sb, *bcpup, dentry->d_inode));
17792 + AuDbg("bcpup %d, bstart %d\n", *bcpup, bstart);
17794 + if (*bcpup != bstart) {
17795 + err = au_cpup_dirs(dentry, *bcpup);
17796 + if (unlikely(err))
17800 + struct au_dinfo *dinfo, *tmp;
17802 + need_wh = -ENOMEM;
17803 + dinfo = au_di(dentry);
17804 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
17806 + au_di_cp(tmp, dinfo);
17807 + au_di_swap(tmp, dinfo);
17808 + /* returns the number of positive dentries */
17809 + need_wh = au_lkup_dentry(dentry, bstart + 1, /*type*/0);
17810 + au_di_swap(tmp, dinfo);
17811 + au_rw_write_unlock(&tmp->di_rwsem);
17815 + AuDbg("need_wh %d\n", need_wh);
17823 + * simple tests for the del-entry operations.
17824 + * following the checks in vfs, plus the parent-child relationship.
17826 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
17827 + struct dentry *h_parent, int isdir)
17831 + struct dentry *h_dentry, *h_latest;
17832 + struct inode *h_inode;
17834 + h_dentry = au_h_dptr(dentry, bindex);
17835 + h_inode = h_dentry->d_inode;
17836 + if (dentry->d_inode) {
17838 + if (unlikely(!h_inode || !h_inode->i_nlink))
17841 + h_mode = h_inode->i_mode;
17844 + if (unlikely(S_ISDIR(h_mode)))
17846 + } else if (unlikely(!S_ISDIR(h_mode))) {
17851 + /* rename(2) case */
17853 + if (unlikely(h_inode))
17858 + /* expected parent dir is locked */
17859 + if (unlikely(h_parent != h_dentry->d_parent))
17864 + * rmdir a dir may break the consistency on some filesystem.
17865 + * let's try heavy test.
17868 + if (unlikely(au_test_h_perm(h_parent->d_inode, MAY_EXEC | MAY_WRITE)))
17871 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent,
17872 + au_sbr(dentry->d_sb, bindex));
17874 + if (IS_ERR(h_latest))
17876 + if (h_latest == h_dentry)
17885 + * decide the branch where we operate for @dentry. the branch index will be set
17886 + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent
17887 + * dir for reverting.
17888 + * when a new whiteout is necessary, create it.
17890 +static struct dentry*
17891 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
17892 + struct au_dtime *dt, struct au_pin *pin)
17894 + struct dentry *wh_dentry;
17895 + struct super_block *sb;
17896 + struct path h_path;
17897 + int err, need_wh;
17898 + unsigned int udba;
17899 + aufs_bindex_t bcpup;
17901 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
17902 + wh_dentry = ERR_PTR(need_wh);
17903 + if (unlikely(need_wh < 0))
17906 + sb = dentry->d_sb;
17907 + udba = au_opt_udba(sb);
17909 + err = au_pin(pin, dentry, bcpup, udba,
17910 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17911 + wh_dentry = ERR_PTR(err);
17912 + if (unlikely(err))
17915 + h_path.dentry = au_pinned_h_parent(pin);
17916 + if (udba != AuOpt_UDBA_NONE
17917 + && au_dbstart(dentry) == bcpup) {
17918 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
17919 + wh_dentry = ERR_PTR(err);
17920 + if (unlikely(err))
17924 + h_path.mnt = au_sbr_mnt(sb, bcpup);
17925 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
17926 + wh_dentry = NULL;
17928 + goto out; /* success, no need to create whiteout */
17930 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
17931 + if (IS_ERR(wh_dentry))
17934 + /* returns with the parent is locked and wh_dentry is dget-ed */
17935 + goto out; /* success */
17940 + return wh_dentry;
17944 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
17945 + * in order to be revertible and save time for removing many child whiteouts
17947 + * returns 1 when there are too many child whiteout and caller should remove
17948 + * them asynchronously. returns 0 when the number of children is enough small to
17949 + * remove now or the branch fs is a remote fs.
17950 + * otherwise return an error.
17952 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
17953 + struct au_nhash *whlist, struct inode *dir)
17955 + int rmdir_later, err, dirwh;
17956 + struct dentry *h_dentry;
17957 + struct super_block *sb;
17959 + sb = dentry->d_sb;
17960 + SiMustAnyLock(sb);
17961 + h_dentry = au_h_dptr(dentry, bindex);
17962 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
17963 + if (unlikely(err))
17966 + /* stop monitoring */
17967 + au_hn_free(au_hi(dentry->d_inode, bindex));
17969 + if (!au_test_fs_remote(h_dentry->d_sb)) {
17970 + dirwh = au_sbi(sb)->si_dirwh;
17971 + rmdir_later = (dirwh <= 1);
17972 + if (!rmdir_later)
17973 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
17976 + return rmdir_later;
17979 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
17980 + if (unlikely(err)) {
17981 + AuIOErr("rmdir %.*s, b%d failed, %d. ignored\n",
17982 + AuDLNPair(h_dentry), bindex, err);
17992 + * final procedure for deleting a entry.
17993 + * maintain dentry and iattr.
17995 +static void epilog(struct inode *dir, struct dentry *dentry,
17996 + aufs_bindex_t bindex)
17998 + struct inode *inode;
18000 + inode = dentry->d_inode;
18002 + inode->i_ctime = dir->i_ctime;
18004 + if (au_ibstart(dir) == bindex)
18005 + au_cpup_attr_timesizes(dir);
18006 + dir->i_version++;
18010 + * when an error happened, remove the created whiteout and revert everything.
18012 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
18013 + aufs_bindex_t bwh, struct dentry *wh_dentry,
18014 + struct dentry *dentry, struct au_dtime *dt)
18017 + struct path h_path = {
18018 + .dentry = wh_dentry,
18019 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
18022 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
18024 + au_set_dbwh(dentry, bwh);
18025 + au_dtime_revert(dt);
18029 + AuIOErr("%.*s reverting whiteout failed(%d, %d)\n",
18030 + AuDLNPair(dentry), err, rerr);
18034 +/* ---------------------------------------------------------------------- */
18036 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
18039 + aufs_bindex_t bwh, bindex, bstart;
18040 + struct inode *inode, *h_dir;
18041 + struct dentry *parent, *wh_dentry;
18042 + /* to reuduce stack size */
18044 + struct au_dtime dt;
18045 + struct au_pin pin;
18046 + struct path h_path;
18052 + a = kmalloc(sizeof(*a), GFP_NOFS);
18053 + if (unlikely(!a))
18056 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
18057 + if (unlikely(err))
18059 + err = au_d_hashed_positive(dentry);
18060 + if (unlikely(err))
18062 + inode = dentry->d_inode;
18063 + IMustLock(inode);
18065 + if (unlikely(S_ISDIR(inode->i_mode)))
18066 + goto out_unlock; /* possible? */
18068 + bstart = au_dbstart(dentry);
18069 + bwh = au_dbwh(dentry);
18071 + parent = dentry->d_parent; /* dir inode is locked */
18072 + di_write_lock_parent(parent);
18073 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
18075 + err = PTR_ERR(wh_dentry);
18076 + if (IS_ERR(wh_dentry))
18079 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
18080 + a->h_path.dentry = au_h_dptr(dentry, bstart);
18081 + dget(a->h_path.dentry);
18082 + if (bindex == bstart) {
18083 + h_dir = au_pinned_h_dir(&a->pin);
18084 + err = vfsub_unlink(h_dir, &a->h_path, /*force*/0);
18086 + /* dir inode is locked */
18087 + h_dir = wh_dentry->d_parent->d_inode;
18088 + IMustLock(h_dir);
18093 + vfsub_drop_nlink(inode);
18094 + epilog(dir, dentry, bindex);
18096 + /* update target timestamps */
18097 + if (bindex == bstart) {
18098 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
18100 + inode->i_ctime = a->h_path.dentry->d_inode->i_ctime;
18102 + /* todo: this timestamp may be reverted later */
18103 + inode->i_ctime = h_dir->i_ctime;
18104 + goto out_unpin; /* success */
18111 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
18118 + au_unpin(&a->pin);
18120 + dput(a->h_path.dentry);
18122 + di_write_unlock(parent);
18124 + aufs_read_unlock(dentry, AuLock_DW);
18131 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
18133 + int err, rmdir_later;
18134 + aufs_bindex_t bwh, bindex, bstart;
18135 + struct inode *inode;
18136 + struct dentry *parent, *wh_dentry, *h_dentry;
18137 + struct au_whtmp_rmdir *args;
18138 + /* to reuduce stack size */
18140 + struct au_dtime dt;
18141 + struct au_pin pin;
18147 + a = kmalloc(sizeof(*a), GFP_NOFS);
18148 + if (unlikely(!a))
18151 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
18152 + if (unlikely(err))
18154 + err = au_alive_dir(dentry);
18155 + if (unlikely(err))
18157 + inode = dentry->d_inode;
18158 + IMustLock(inode);
18160 + if (unlikely(!S_ISDIR(inode->i_mode)))
18161 + goto out_unlock; /* possible? */
18164 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
18165 + if (unlikely(!args))
18168 + parent = dentry->d_parent; /* dir inode is locked */
18169 + di_write_lock_parent(parent);
18170 + err = au_test_empty(dentry, &args->whlist);
18171 + if (unlikely(err))
18174 + bstart = au_dbstart(dentry);
18175 + bwh = au_dbwh(dentry);
18177 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
18179 + err = PTR_ERR(wh_dentry);
18180 + if (IS_ERR(wh_dentry))
18183 + h_dentry = au_h_dptr(dentry, bstart);
18186 + if (bindex == bstart) {
18187 + err = renwh_and_rmdir(dentry, bstart, &args->whlist, dir);
18189 + rmdir_later = err;
18193 + /* stop monitoring */
18194 + au_hn_free(au_hi(inode, bstart));
18196 + /* dir inode is locked */
18197 + IMustLock(wh_dentry->d_parent->d_inode);
18202 + vfsub_dead_dir(inode);
18203 + au_set_dbdiropq(dentry, -1);
18204 + epilog(dir, dentry, bindex);
18206 + if (rmdir_later) {
18207 + au_whtmp_kick_rmdir(dir, bstart, h_dentry, args);
18211 + goto out_unpin; /* success */
18219 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
18226 + au_unpin(&a->pin);
18230 + di_write_unlock(parent);
18232 + au_whtmp_rmdir_free(args);
18234 + aufs_read_unlock(dentry, AuLock_DW);
18241 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
18242 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
18243 +++ linux/fs/aufs/i_op_ren.c 2013-10-26 16:51:32.276373845 +0200
18246 + * Copyright (C) 2005-2013 Junjiro R. Okajima
18248 + * This program, aufs is free software; you can redistribute it and/or modify
18249 + * it under the terms of the GNU General Public License as published by
18250 + * the Free Software Foundation; either version 2 of the License, or
18251 + * (at your option) any later version.
18253 + * This program is distributed in the hope that it will be useful,
18254 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18255 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18256 + * GNU General Public License for more details.
18258 + * You should have received a copy of the GNU General Public License
18259 + * along with this program; if not, write to the Free Software
18260 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18264 + * inode operation (rename entry)
18265 + * todo: this is crazy monster
18270 +enum { AuSRC, AuDST, AuSrcDst };
18271 +enum { AuPARENT, AuCHILD, AuParentChild };
18273 +#define AuRen_ISDIR 1
18274 +#define AuRen_ISSAMEDIR (1 << 1)
18275 +#define AuRen_WHSRC (1 << 2)
18276 +#define AuRen_WHDST (1 << 3)
18277 +#define AuRen_MNT_WRITE (1 << 4)
18278 +#define AuRen_DT_DSTDIR (1 << 5)
18279 +#define AuRen_DIROPQ (1 << 6)
18280 +#define AuRen_CPUP (1 << 7)
18281 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
18282 +#define au_fset_ren(flags, name) \
18283 + do { (flags) |= AuRen_##name; } while (0)
18284 +#define au_fclr_ren(flags, name) \
18285 + do { (flags) &= ~AuRen_##name; } while (0)
18287 +struct au_ren_args {
18289 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
18291 + struct inode *dir, *inode;
18292 + struct au_hinode *hdir;
18293 + struct au_dtime dt[AuParentChild];
18294 + aufs_bindex_t bstart;
18297 +#define src_dentry sd[AuSRC].dentry
18298 +#define src_dir sd[AuSRC].dir
18299 +#define src_inode sd[AuSRC].inode
18300 +#define src_h_dentry sd[AuSRC].h_dentry
18301 +#define src_parent sd[AuSRC].parent
18302 +#define src_h_parent sd[AuSRC].h_parent
18303 +#define src_wh_dentry sd[AuSRC].wh_dentry
18304 +#define src_hdir sd[AuSRC].hdir
18305 +#define src_h_dir sd[AuSRC].hdir->hi_inode
18306 +#define src_dt sd[AuSRC].dt
18307 +#define src_bstart sd[AuSRC].bstart
18309 +#define dst_dentry sd[AuDST].dentry
18310 +#define dst_dir sd[AuDST].dir
18311 +#define dst_inode sd[AuDST].inode
18312 +#define dst_h_dentry sd[AuDST].h_dentry
18313 +#define dst_parent sd[AuDST].parent
18314 +#define dst_h_parent sd[AuDST].h_parent
18315 +#define dst_wh_dentry sd[AuDST].wh_dentry
18316 +#define dst_hdir sd[AuDST].hdir
18317 +#define dst_h_dir sd[AuDST].hdir->hi_inode
18318 +#define dst_dt sd[AuDST].dt
18319 +#define dst_bstart sd[AuDST].bstart
18321 + struct dentry *h_trap;
18322 + struct au_branch *br;
18323 + struct au_hinode *src_hinode;
18324 + struct path h_path;
18325 + struct au_nhash whlist;
18326 + aufs_bindex_t btgt, src_bwh, src_bdiropq;
18328 + unsigned int flags;
18330 + struct au_whtmp_rmdir *thargs;
18331 + struct dentry *h_dst;
18334 +/* ---------------------------------------------------------------------- */
18337 + * functions for reverting.
18338 + * when an error happened in a single rename systemcall, we should revert
18339 + * everything as if nothing happend.
18340 + * we don't need to revert the copied-up/down the parent dir since they are
18344 +#define RevertFailure(fmt, ...) do { \
18345 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
18346 + ##__VA_ARGS__, err, rerr); \
18350 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
18354 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
18355 + rerr = au_diropq_remove(a->src_dentry, a->btgt);
18356 + au_hn_imtx_unlock(a->src_hinode);
18357 + au_set_dbdiropq(a->src_dentry, a->src_bdiropq);
18359 + RevertFailure("remove diropq %.*s", AuDLNPair(a->src_dentry));
18362 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
18366 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
18367 + a->src_h_parent);
18368 + rerr = PTR_ERR(a->h_path.dentry);
18369 + if (IS_ERR(a->h_path.dentry)) {
18370 + RevertFailure("lkup one %.*s", AuDLNPair(a->src_dentry));
18374 + rerr = vfsub_rename(a->dst_h_dir,
18375 + au_h_dptr(a->src_dentry, a->btgt),
18376 + a->src_h_dir, &a->h_path);
18377 + d_drop(a->h_path.dentry);
18378 + dput(a->h_path.dentry);
18379 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
18381 + RevertFailure("rename %.*s", AuDLNPair(a->src_dentry));
18384 +static void au_ren_rev_cpup(int err, struct au_ren_args *a)
18388 + a->h_path.dentry = a->dst_h_dentry;
18389 + rerr = vfsub_unlink(a->dst_h_dir, &a->h_path, /*force*/0);
18390 + au_set_h_dptr(a->src_dentry, a->btgt, NULL);
18391 + au_set_dbstart(a->src_dentry, a->src_bstart);
18393 + RevertFailure("unlink %.*s", AuDLNPair(a->dst_h_dentry));
18396 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
18400 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
18401 + a->dst_h_parent);
18402 + rerr = PTR_ERR(a->h_path.dentry);
18403 + if (IS_ERR(a->h_path.dentry)) {
18404 + RevertFailure("lkup one %.*s", AuDLNPair(a->dst_dentry));
18407 + if (a->h_path.dentry->d_inode) {
18408 + d_drop(a->h_path.dentry);
18409 + dput(a->h_path.dentry);
18413 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path);
18414 + d_drop(a->h_path.dentry);
18415 + dput(a->h_path.dentry);
18417 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
18419 + RevertFailure("rename %.*s", AuDLNPair(a->h_dst));
18422 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
18426 + a->h_path.dentry = a->src_wh_dentry;
18427 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
18428 + au_set_dbwh(a->src_dentry, a->src_bwh);
18430 + RevertFailure("unlink %.*s", AuDLNPair(a->src_wh_dentry));
18432 +#undef RevertFailure
18434 +/* ---------------------------------------------------------------------- */
18437 + * when we have to copyup the renaming entry, do it with the rename-target name
18438 + * in order to minimize the cost (the later actual rename is unnecessary).
18439 + * otherwise rename it on the target branch.
18441 +static int au_ren_or_cpup(struct au_ren_args *a)
18444 + struct dentry *d;
18446 + d = a->src_dentry;
18447 + if (au_dbstart(d) == a->btgt) {
18448 + a->h_path.dentry = a->dst_h_dentry;
18449 + if (au_ftest_ren(a->flags, DIROPQ)
18450 + && au_dbdiropq(d) == a->btgt)
18451 + au_fclr_ren(a->flags, DIROPQ);
18452 + AuDebugOn(au_dbstart(d) != a->btgt);
18453 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
18454 + a->dst_h_dir, &a->h_path);
18458 + if (!err && a->h_dst)
18459 + /* it will be set to dinfo later */
18465 +/* cf. aufs_rmdir() */
18466 +static int au_ren_del_whtmp(struct au_ren_args *a)
18469 + struct inode *dir;
18471 + dir = a->dst_dir;
18472 + SiMustAnyLock(dir->i_sb);
18473 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
18474 + au_sbi(dir->i_sb)->si_dirwh)
18475 + || au_test_fs_remote(a->h_dst->d_sb)) {
18476 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
18477 + if (unlikely(err))
18478 + pr_warn("failed removing whtmp dir %.*s (%d), "
18479 + "ignored.\n", AuDLNPair(a->h_dst), err);
18481 + au_nhash_wh_free(&a->thargs->whlist);
18482 + a->thargs->whlist = a->whlist;
18483 + a->whlist.nh_num = 0;
18484 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
18486 + a->thargs = NULL;
18492 +/* make it 'opaque' dir. */
18493 +static int au_ren_diropq(struct au_ren_args *a)
18496 + struct dentry *diropq;
18499 + a->src_bdiropq = au_dbdiropq(a->src_dentry);
18500 + a->src_hinode = au_hi(a->src_inode, a->btgt);
18501 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
18502 + diropq = au_diropq_create(a->src_dentry, a->btgt);
18503 + au_hn_imtx_unlock(a->src_hinode);
18504 + if (IS_ERR(diropq))
18505 + err = PTR_ERR(diropq);
18511 +static int do_rename(struct au_ren_args *a)
18514 + struct dentry *d, *h_d;
18516 + /* prepare workqueue args for asynchronous rmdir */
18517 + h_d = a->dst_h_dentry;
18518 + if (au_ftest_ren(a->flags, ISDIR) && h_d->d_inode) {
18520 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb, GFP_NOFS);
18521 + if (unlikely(!a->thargs))
18523 + a->h_dst = dget(h_d);
18526 + /* create whiteout for src_dentry */
18527 + if (au_ftest_ren(a->flags, WHSRC)) {
18528 + a->src_bwh = au_dbwh(a->src_dentry);
18529 + AuDebugOn(a->src_bwh >= 0);
18531 + = au_wh_create(a->src_dentry, a->btgt, a->src_h_parent);
18532 + err = PTR_ERR(a->src_wh_dentry);
18533 + if (IS_ERR(a->src_wh_dentry))
18537 + /* lookup whiteout for dentry */
18538 + if (au_ftest_ren(a->flags, WHDST)) {
18539 + h_d = au_wh_lkup(a->dst_h_parent, &a->dst_dentry->d_name,
18541 + err = PTR_ERR(h_d);
18544 + if (!h_d->d_inode)
18547 + a->dst_wh_dentry = h_d;
18550 + /* rename dentry to tmpwh */
18552 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
18553 + if (unlikely(err))
18556 + d = a->dst_dentry;
18557 + au_set_h_dptr(d, a->btgt, NULL);
18558 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
18559 + if (unlikely(err))
18561 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
18564 + BUG_ON(a->dst_h_dentry->d_inode && a->src_bstart != a->btgt);
18566 + /* rename by vfs_rename or cpup */
18567 + d = a->dst_dentry;
18568 + if (au_ftest_ren(a->flags, ISDIR)
18569 + && (a->dst_wh_dentry
18570 + || au_dbdiropq(d) == a->btgt
18571 + /* hide the lower to keep xino */
18572 + || a->btgt < au_dbend(d)
18573 + || au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ)))
18574 + au_fset_ren(a->flags, DIROPQ);
18575 + err = au_ren_or_cpup(a);
18576 + if (unlikely(err))
18577 + /* leave the copied-up one */
18580 + /* make dir opaque */
18581 + if (au_ftest_ren(a->flags, DIROPQ)) {
18582 + err = au_ren_diropq(a);
18583 + if (unlikely(err))
18587 + /* update target timestamps */
18588 + AuDebugOn(au_dbstart(a->src_dentry) != a->btgt);
18589 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
18590 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
18591 + a->src_inode->i_ctime = a->h_path.dentry->d_inode->i_ctime;
18593 + /* remove whiteout for dentry */
18594 + if (a->dst_wh_dentry) {
18595 + a->h_path.dentry = a->dst_wh_dentry;
18596 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
18598 + if (unlikely(err))
18602 + /* remove whtmp */
18604 + au_ren_del_whtmp(a); /* ignore this error */
18607 + goto out_success;
18610 + if (au_ftest_ren(a->flags, DIROPQ))
18611 + au_ren_rev_diropq(err, a);
18613 + if (!au_ftest_ren(a->flags, CPUP))
18614 + au_ren_rev_rename(err, a);
18616 + au_ren_rev_cpup(err, a);
18620 + au_ren_rev_whtmp(err, a);
18622 + dput(a->dst_wh_dentry);
18623 + a->dst_wh_dentry = NULL;
18625 + if (a->src_wh_dentry)
18626 + au_ren_rev_whsrc(err, a);
18628 + dput(a->src_wh_dentry);
18629 + dput(a->dst_wh_dentry);
18633 + au_whtmp_rmdir_free(a->thargs);
18634 + a->thargs = NULL;
18640 +/* ---------------------------------------------------------------------- */
18643 + * test if @dentry dir can be rename destination or not.
18644 + * success means, it is a logically empty dir.
18646 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
18648 + return au_test_empty(dentry, whlist);
18652 + * test if @dentry dir can be rename source or not.
18653 + * if it can, return 0 and @children is filled.
18655 + * - it is a logically empty dir.
18656 + * - or, it exists on writable branch and has no children including whiteouts
18657 + * on the lower branch.
18659 +static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt)
18662 + unsigned int rdhash;
18663 + aufs_bindex_t bstart;
18665 + bstart = au_dbstart(dentry);
18666 + if (bstart != btgt) {
18667 + struct au_nhash whlist;
18669 + SiMustAnyLock(dentry->d_sb);
18670 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
18672 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
18674 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
18675 + if (unlikely(err))
18677 + err = au_test_empty(dentry, &whlist);
18678 + au_nhash_wh_free(&whlist);
18682 + if (bstart == au_dbtaildir(dentry))
18683 + return 0; /* success */
18685 + err = au_test_empty_lower(dentry);
18688 + if (err == -ENOTEMPTY) {
18689 + AuWarn1("renaming dir who has child(ren) on multiple branches,"
18690 + " is not supported\n");
18696 +/* side effect: sets whlist and h_dentry */
18697 +static int au_ren_may_dir(struct au_ren_args *a)
18700 + unsigned int rdhash;
18701 + struct dentry *d;
18703 + d = a->dst_dentry;
18704 + SiMustAnyLock(d->d_sb);
18707 + if (au_ftest_ren(a->flags, ISDIR) && a->dst_inode) {
18708 + rdhash = au_sbi(d->d_sb)->si_rdhash;
18710 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
18711 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
18712 + if (unlikely(err))
18715 + au_set_dbstart(d, a->dst_bstart);
18716 + err = may_rename_dstdir(d, &a->whlist);
18717 + au_set_dbstart(d, a->btgt);
18719 + a->dst_h_dentry = au_h_dptr(d, au_dbstart(d));
18720 + if (unlikely(err))
18723 + d = a->src_dentry;
18724 + a->src_h_dentry = au_h_dptr(d, au_dbstart(d));
18725 + if (au_ftest_ren(a->flags, ISDIR)) {
18726 + err = may_rename_srcdir(d, a->btgt);
18727 + if (unlikely(err)) {
18728 + au_nhash_wh_free(&a->whlist);
18729 + a->whlist.nh_num = 0;
18736 +/* ---------------------------------------------------------------------- */
18739 + * simple tests for rename.
18740 + * following the checks in vfs, plus the parent-child relationship.
18742 +static int au_may_ren(struct au_ren_args *a)
18745 + struct inode *h_inode;
18747 + if (a->src_bstart == a->btgt) {
18748 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
18749 + au_ftest_ren(a->flags, ISDIR));
18750 + if (unlikely(err))
18753 + if (unlikely(a->src_h_dentry == a->h_trap))
18758 + if (a->dst_bstart != a->btgt)
18761 + err = -ENOTEMPTY;
18762 + if (unlikely(a->dst_h_dentry == a->h_trap))
18766 + h_inode = a->dst_h_dentry->d_inode;
18767 + isdir = !!au_ftest_ren(a->flags, ISDIR);
18768 + if (!a->dst_dentry->d_inode) {
18769 + if (unlikely(h_inode))
18771 + err = au_may_add(a->dst_dentry, a->btgt, a->dst_h_parent,
18774 + if (unlikely(!h_inode || !h_inode->i_nlink))
18776 + err = au_may_del(a->dst_dentry, a->btgt, a->dst_h_parent,
18778 + if (unlikely(err))
18783 + if (unlikely(err == -ENOENT || err == -EEXIST))
18789 +/* ---------------------------------------------------------------------- */
18794 + * - src_dir and dir by lock_rename()
18795 + * - inode if exitsts
18798 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
18800 + * + di_write_lock2_child()
18801 + * + di_write_lock_child()
18802 + * + ii_write_lock_child()
18803 + * + di_write_lock_child2()
18804 + * + ii_write_lock_child2()
18805 + * + src_parent and parent
18806 + * + di_write_lock_parent()
18807 + * + ii_write_lock_parent()
18808 + * + di_write_lock_parent2()
18809 + * + ii_write_lock_parent2()
18810 + * + lower src_dir and dir by vfsub_lock_rename()
18811 + * + verify the every relationships between child and parent. if any
18812 + * of them failed, unlock all and return -EBUSY.
18814 +static void au_ren_unlock(struct au_ren_args *a)
18816 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
18817 + a->dst_h_parent, a->dst_hdir);
18818 + if (au_ftest_ren(a->flags, MNT_WRITE))
18819 + vfsub_mnt_drop_write(au_br_mnt(a->br));
18822 +static int au_ren_lock(struct au_ren_args *a)
18825 + unsigned int udba;
18828 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
18829 + a->src_hdir = au_hi(a->src_dir, a->btgt);
18830 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
18831 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
18833 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
18834 + if (unlikely(err))
18836 + au_fset_ren(a->flags, MNT_WRITE);
18837 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
18838 + a->dst_h_parent, a->dst_hdir);
18839 + udba = au_opt_udba(a->src_dentry->d_sb);
18840 + if (unlikely(a->src_hdir->hi_inode != a->src_h_parent->d_inode
18841 + || a->dst_hdir->hi_inode != a->dst_h_parent->d_inode))
18842 + err = au_busy_or_stale();
18843 + if (!err && au_dbstart(a->src_dentry) == a->btgt)
18844 + err = au_h_verify(a->src_h_dentry, udba,
18845 + a->src_h_parent->d_inode, a->src_h_parent,
18847 + if (!err && au_dbstart(a->dst_dentry) == a->btgt)
18848 + err = au_h_verify(a->dst_h_dentry, udba,
18849 + a->dst_h_parent->d_inode, a->dst_h_parent,
18852 + goto out; /* success */
18854 + err = au_busy_or_stale();
18855 + au_ren_unlock(a);
18861 +/* ---------------------------------------------------------------------- */
18863 +static void au_ren_refresh_dir(struct au_ren_args *a)
18865 + struct inode *dir;
18867 + dir = a->dst_dir;
18868 + dir->i_version++;
18869 + if (au_ftest_ren(a->flags, ISDIR)) {
18870 + /* is this updating defined in POSIX? */
18871 + au_cpup_attr_timesizes(a->src_inode);
18872 + au_cpup_attr_nlink(dir, /*force*/1);
18875 + if (au_ibstart(dir) == a->btgt)
18876 + au_cpup_attr_timesizes(dir);
18878 + if (au_ftest_ren(a->flags, ISSAMEDIR))
18881 + dir = a->src_dir;
18882 + dir->i_version++;
18883 + if (au_ftest_ren(a->flags, ISDIR))
18884 + au_cpup_attr_nlink(dir, /*force*/1);
18885 + if (au_ibstart(dir) == a->btgt)
18886 + au_cpup_attr_timesizes(dir);
18889 +static void au_ren_refresh(struct au_ren_args *a)
18891 + aufs_bindex_t bend, bindex;
18892 + struct dentry *d, *h_d;
18893 + struct inode *i, *h_i;
18894 + struct super_block *sb;
18896 + d = a->dst_dentry;
18899 + /* already dget-ed by au_ren_or_cpup() */
18900 + au_set_h_dptr(d, a->btgt, a->h_dst);
18902 + i = a->dst_inode;
18904 + if (!au_ftest_ren(a->flags, ISDIR))
18905 + vfsub_drop_nlink(i);
18907 + vfsub_dead_dir(i);
18908 + au_cpup_attr_timesizes(i);
18910 + au_update_dbrange(d, /*do_put_zero*/1);
18913 + for (bindex = au_dbstart(d); bindex < bend; bindex++)
18914 + au_set_h_dptr(d, bindex, NULL);
18915 + bend = au_dbend(d);
18916 + for (bindex = a->btgt + 1; bindex <= bend; bindex++)
18917 + au_set_h_dptr(d, bindex, NULL);
18918 + au_update_dbrange(d, /*do_put_zero*/0);
18921 + d = a->src_dentry;
18922 + au_set_dbwh(d, -1);
18923 + bend = au_dbend(d);
18924 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
18925 + h_d = au_h_dptr(d, bindex);
18927 + au_set_h_dptr(d, bindex, NULL);
18929 + au_set_dbend(d, a->btgt);
18932 + i = a->src_inode;
18933 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
18934 + return; /* success */
18936 + bend = au_ibend(i);
18937 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
18938 + h_i = au_h_iptr(i, bindex);
18940 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
18941 + /* ignore this error */
18942 + au_set_h_iptr(i, bindex, NULL, 0);
18945 + au_set_ibend(i, a->btgt);
18948 +/* ---------------------------------------------------------------------- */
18950 +/* mainly for link(2) and rename(2) */
18951 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
18953 + aufs_bindex_t bdiropq, bwh;
18954 + struct dentry *parent;
18955 + struct au_branch *br;
18957 + parent = dentry->d_parent;
18958 + IMustLock(parent->d_inode); /* dir is locked */
18960 + bdiropq = au_dbdiropq(parent);
18961 + bwh = au_dbwh(dentry);
18962 + br = au_sbr(dentry->d_sb, btgt);
18963 + if (au_br_rdonly(br)
18964 + || (0 <= bdiropq && bdiropq < btgt)
18965 + || (0 <= bwh && bwh < btgt))
18968 + AuDbg("btgt %d\n", btgt);
18972 +/* sets src_bstart, dst_bstart and btgt */
18973 +static int au_ren_wbr(struct au_ren_args *a)
18976 + struct au_wr_dir_args wr_dir_args = {
18977 + /* .force_btgt = -1, */
18978 + .flags = AuWrDir_ADD_ENTRY
18981 + a->src_bstart = au_dbstart(a->src_dentry);
18982 + a->dst_bstart = au_dbstart(a->dst_dentry);
18983 + if (au_ftest_ren(a->flags, ISDIR))
18984 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
18985 + wr_dir_args.force_btgt = a->src_bstart;
18986 + if (a->dst_inode && a->dst_bstart < a->src_bstart)
18987 + wr_dir_args.force_btgt = a->dst_bstart;
18988 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
18989 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
18995 +static void au_ren_dt(struct au_ren_args *a)
18997 + a->h_path.dentry = a->src_h_parent;
18998 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
18999 + if (!au_ftest_ren(a->flags, ISSAMEDIR)) {
19000 + a->h_path.dentry = a->dst_h_parent;
19001 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
19004 + au_fclr_ren(a->flags, DT_DSTDIR);
19005 + if (!au_ftest_ren(a->flags, ISDIR))
19008 + a->h_path.dentry = a->src_h_dentry;
19009 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
19010 + if (a->dst_h_dentry->d_inode) {
19011 + au_fset_ren(a->flags, DT_DSTDIR);
19012 + a->h_path.dentry = a->dst_h_dentry;
19013 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
19017 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
19019 + struct dentry *h_d;
19020 + struct mutex *h_mtx;
19022 + au_dtime_revert(a->src_dt + AuPARENT);
19023 + if (!au_ftest_ren(a->flags, ISSAMEDIR))
19024 + au_dtime_revert(a->dst_dt + AuPARENT);
19026 + if (au_ftest_ren(a->flags, ISDIR) && err != -EIO) {
19027 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
19028 + h_mtx = &h_d->d_inode->i_mutex;
19029 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
19030 + au_dtime_revert(a->src_dt + AuCHILD);
19031 + mutex_unlock(h_mtx);
19033 + if (au_ftest_ren(a->flags, DT_DSTDIR)) {
19034 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
19035 + h_mtx = &h_d->d_inode->i_mutex;
19036 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
19037 + au_dtime_revert(a->dst_dt + AuCHILD);
19038 + mutex_unlock(h_mtx);
19043 +/* ---------------------------------------------------------------------- */
19045 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
19046 + struct inode *_dst_dir, struct dentry *_dst_dentry)
19049 + /* reduce stack space */
19050 + struct au_ren_args *a;
19052 + AuDbg("%.*s, %.*s\n", AuDLNPair(_src_dentry), AuDLNPair(_dst_dentry));
19053 + IMustLock(_src_dir);
19054 + IMustLock(_dst_dir);
19057 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
19058 + a = kzalloc(sizeof(*a), GFP_NOFS);
19059 + if (unlikely(!a))
19062 + a->src_dir = _src_dir;
19063 + a->src_dentry = _src_dentry;
19064 + a->src_inode = a->src_dentry->d_inode;
19065 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
19066 + a->dst_dir = _dst_dir;
19067 + a->dst_dentry = _dst_dentry;
19068 + a->dst_inode = a->dst_dentry->d_inode;
19069 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
19070 + if (a->dst_inode) {
19071 + IMustLock(a->dst_inode);
19072 + au_igrab(a->dst_inode);
19076 + flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
19077 + if (S_ISDIR(a->src_inode->i_mode)) {
19078 + au_fset_ren(a->flags, ISDIR);
19079 + if (unlikely(a->dst_inode && !S_ISDIR(a->dst_inode->i_mode)))
19081 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
19082 + AuLock_DIR | flags);
19084 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
19086 + if (unlikely(err))
19089 + err = au_d_hashed_positive(a->src_dentry);
19090 + if (unlikely(err))
19093 + if (a->dst_inode) {
19095 + * If it is a dir, VFS unhash dst_dentry before this
19096 + * function. It means we cannot rely upon d_unhashed().
19098 + if (unlikely(!a->dst_inode->i_nlink))
19100 + if (!S_ISDIR(a->dst_inode->i_mode)) {
19101 + err = au_d_hashed_positive(a->dst_dentry);
19102 + if (unlikely(err))
19104 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
19106 + } else if (unlikely(d_unhashed(a->dst_dentry)))
19110 + * is it possible?
19111 + * yes, it happend (in linux-3.3-rcN) but I don't know why.
19112 + * there may exist a problem somewhere else.
19115 + if (unlikely(a->dst_parent->d_inode == a->src_dentry->d_inode))
19118 + au_fset_ren(a->flags, ISSAMEDIR); /* temporary */
19119 + di_write_lock_parent(a->dst_parent);
19121 + /* which branch we process */
19122 + err = au_ren_wbr(a);
19123 + if (unlikely(err < 0))
19125 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
19126 + a->h_path.mnt = au_br_mnt(a->br);
19128 + /* are they available to be renamed */
19129 + err = au_ren_may_dir(a);
19130 + if (unlikely(err))
19131 + goto out_children;
19133 + /* prepare the writable parent dir on the same branch */
19134 + if (a->dst_bstart == a->btgt) {
19135 + au_fset_ren(a->flags, WHDST);
19137 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
19138 + if (unlikely(err))
19139 + goto out_children;
19142 + if (a->src_dir != a->dst_dir) {
19144 + * this temporary unlock is safe,
19145 + * because both dir->i_mutex are locked.
19147 + di_write_unlock(a->dst_parent);
19148 + di_write_lock_parent(a->src_parent);
19149 + err = au_wr_dir_need_wh(a->src_dentry,
19150 + au_ftest_ren(a->flags, ISDIR),
19152 + di_write_unlock(a->src_parent);
19153 + di_write_lock2_parent(a->src_parent, a->dst_parent, /*isdir*/1);
19154 + au_fclr_ren(a->flags, ISSAMEDIR);
19156 + err = au_wr_dir_need_wh(a->src_dentry,
19157 + au_ftest_ren(a->flags, ISDIR),
19159 + if (unlikely(err < 0))
19160 + goto out_children;
19162 + au_fset_ren(a->flags, WHSRC);
19165 + if (a->src_bstart != a->btgt) {
19166 + struct au_pin pin;
19168 + err = au_pin(&pin, a->src_dentry, a->btgt,
19169 + au_opt_udba(a->src_dentry->d_sb),
19170 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19172 + struct au_cp_generic cpg = {
19173 + .dentry = a->src_dentry,
19175 + .bsrc = a->src_bstart,
19178 + .flags = AuCpup_DTIME | AuCpup_HOPEN
19180 + AuDebugOn(au_dbstart(a->src_dentry) != a->src_bstart);
19181 + err = au_sio_cpup_simple(&cpg);
19184 + if (unlikely(err))
19185 + goto out_children;
19186 + a->src_bstart = a->btgt;
19187 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
19188 + au_fset_ren(a->flags, WHSRC);
19191 + /* lock them all */
19192 + err = au_ren_lock(a);
19193 + if (unlikely(err))
19194 + /* leave the copied-up one */
19195 + goto out_children;
19197 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
19198 + err = au_may_ren(a);
19199 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
19200 + err = -ENAMETOOLONG;
19201 + if (unlikely(err))
19204 + /* store timestamps to be revertible */
19208 + err = do_rename(a);
19209 + if (unlikely(err))
19212 + /* update dir attributes */
19213 + au_ren_refresh_dir(a);
19215 + /* dput/iput all lower dentries */
19216 + au_ren_refresh(a);
19218 + goto out_hdir; /* success */
19221 + au_ren_rev_dt(err, a);
19223 + au_ren_unlock(a);
19225 + au_nhash_wh_free(&a->whlist);
19226 + if (err && a->dst_inode && a->dst_bstart != a->btgt) {
19227 + AuDbg("bstart %d, btgt %d\n", a->dst_bstart, a->btgt);
19228 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
19229 + au_set_dbstart(a->dst_dentry, a->dst_bstart);
19233 + d_move(a->src_dentry, a->dst_dentry);
19235 + au_update_dbstart(a->dst_dentry);
19236 + if (!a->dst_inode)
19237 + d_drop(a->dst_dentry);
19239 + if (au_ftest_ren(a->flags, ISSAMEDIR))
19240 + di_write_unlock(a->dst_parent);
19242 + di_write_unlock2(a->src_parent, a->dst_parent);
19244 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
19246 + iput(a->dst_inode);
19248 + au_whtmp_rmdir_free(a->thargs);
19254 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
19255 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
19256 +++ linux/fs/aufs/Kconfig 2013-07-06 13:20:47.736864659 +0200
19259 + tristate "Aufs (Advanced multi layered unification filesystem) support"
19261 + Aufs is a stackable unification filesystem such as Unionfs,
19262 + which unifies several directories and provides a merged single
19264 + In the early days, aufs was entirely re-designed and
19265 + re-implemented Unionfs Version 1.x series. Introducing many
19266 + original ideas, approaches and improvements, it becomes totally
19267 + different from Unionfs while keeping the basic features.
19271 + prompt "Maximum number of branches"
19272 + default AUFS_BRANCH_MAX_127
19274 + Specifies the maximum number of branches (or member directories)
19275 + in a single aufs. The larger value consumes more system
19276 + resources and has a minor impact to performance.
19277 +config AUFS_BRANCH_MAX_127
19280 + Specifies the maximum number of branches (or member directories)
19281 + in a single aufs. The larger value consumes more system
19282 + resources and has a minor impact to performance.
19283 +config AUFS_BRANCH_MAX_511
19286 + Specifies the maximum number of branches (or member directories)
19287 + in a single aufs. The larger value consumes more system
19288 + resources and has a minor impact to performance.
19289 +config AUFS_BRANCH_MAX_1023
19292 + Specifies the maximum number of branches (or member directories)
19293 + in a single aufs. The larger value consumes more system
19294 + resources and has a minor impact to performance.
19295 +config AUFS_BRANCH_MAX_32767
19298 + Specifies the maximum number of branches (or member directories)
19299 + in a single aufs. The larger value consumes more system
19300 + resources and has a minor impact to performance.
19303 +config AUFS_SBILIST
19305 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
19308 + Automatic configuration for internal use.
19309 + When aufs supports Magic SysRq or /proc, enabled automatically.
19311 +config AUFS_HNOTIFY
19312 + bool "Detect direct branch access (bypassing aufs)"
19314 + If you want to modify files on branches directly, eg. bypassing aufs,
19315 + and want aufs to detect the changes of them fully, then enable this
19316 + option and use 'udba=notify' mount option.
19317 + Currently there is only one available configuration, "fsnotify".
19318 + It will have a negative impact to the performance.
19319 + See detail in aufs.5.
19322 + prompt "method" if AUFS_HNOTIFY
19323 + default AUFS_HFSNOTIFY
19324 +config AUFS_HFSNOTIFY
19329 +config AUFS_EXPORT
19330 + bool "NFS-exportable aufs"
19331 + depends on EXPORTFS
19333 + If you want to export your mounted aufs via NFS, then enable this
19334 + option. There are several requirements for this configuration.
19335 + See detail in aufs.5.
19337 +config AUFS_INO_T_64
19339 + depends on AUFS_EXPORT
19340 + depends on 64BIT && !(ALPHA || S390)
19343 + Automatic configuration for internal use.
19344 + /* typedef unsigned long/int __kernel_ino_t */
19345 + /* alpha and s390x are int */
19348 + bool "Readdir in userspace"
19350 + Aufs has two methods to provide a merged view for a directory,
19351 + by a user-space library and by kernel-space natively. The latter
19352 + is always enabled but sometimes large and slow.
19353 + If you enable this option, install the library in aufs2-util
19354 + package, and set some environment variables for your readdir(3),
19355 + then the work will be handled in user-space which generally
19356 + shows better performance in most cases.
19357 + See detail in aufs.5.
19359 +config AUFS_PROC_MAP
19360 + bool "support for /proc/maps and lsof(1)"
19361 + depends on PROC_FS
19363 + When you issue mmap(2) in aufs, it is actually a direct mmap(2)
19364 + call to the file on the branch fs since the file in aufs is
19365 + purely virtual. And the file path printed in /proc/maps (and
19366 + others) will be the path on the branch fs. In most cases, it
19367 + does no harm. But some utilities like lsof(1) may confuse since
19368 + the utility or user may expect the file path in aufs to be
19370 + To address this issue, aufs provides a patch which introduces a
19371 + new member called vm_prfile into struct vm_are_struct. The patch
19372 + is meaningless without enabling this configuration since nobody
19373 + sets the new vm_prfile member.
19374 + If you don't apply the patch, then enabling this configuration
19375 + will cause a compile error.
19376 + This approach is fragile since if someone else make some changes
19377 + around vm_file, then vm_prfile may not work anymore. As a
19378 + workaround such case, aufs provides this configuration. If you
19379 + disable it, then lsof(1) may produce incorrect result but the
19380 + problem will be gone even if the aufs patch is applied (I hope).
19382 +config AUFS_SP_IATTR
19383 + bool "Respect the attributes (mtime/ctime mainly) of special files"
19385 + When you write something to a special file, some attributes of it
19386 + (mtime/ctime mainly) may be updated. Generally such updates are
19387 + less important (actually some device drivers and NFS ignore
19388 + it). But some applications (such like test program) requires
19389 + such updates. If you need these updates, then enable this
19390 + configuration which introduces some overhead.
19391 + Currently this configuration handles FIFO only.
19394 + bool "Show whiteouts"
19396 + If you want to make the whiteouts in aufs visible, then enable
19397 + this option and specify 'shwh' mount option. Although it may
19398 + sounds like philosophy or something, but in technically it
19399 + simply shows the name of whiteout with keeping its behaviour.
19401 +config AUFS_BR_RAMFS
19402 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
19404 + If you want to use ramfs as an aufs branch fs, then enable this
19405 + option. Generally tmpfs is recommended.
19406 + Aufs prohibited them to be a branch fs by default, because
19407 + initramfs becomes unusable after switch_root or something
19408 + generally. If you sets initramfs as an aufs branch and boot your
19409 + system by switch_root, you will meet a problem easily since the
19410 + files in initramfs may be inaccessible.
19411 + Unless you are going to use ramfs as an aufs branch fs without
19412 + switch_root or something, leave it N.
19414 +config AUFS_BR_FUSE
19415 + bool "Fuse fs as an aufs branch"
19416 + depends on FUSE_FS
19419 + If you want to use fuse-based userspace filesystem as an aufs
19420 + branch fs, then enable this option.
19421 + It implements the internal poll(2) operation which is
19422 + implemented by fuse only (curretnly).
19427 + Automatic configuration for internal use.
19429 +config AUFS_BR_HFSPLUS
19430 + bool "Hfsplus as an aufs branch"
19431 + depends on HFSPLUS_FS
19434 + If you want to use hfsplus fs as an aufs branch fs, then enable
19435 + this option. This option introduces a small overhead at
19436 + copying-up a file on hfsplus.
19438 +config AUFS_BDEV_LOOP
19440 + depends on BLK_DEV_LOOP
19443 + Automatic configuration for internal use.
19444 + Convert =[ym] into =y.
19447 + bool "Debug aufs"
19449 + Enable this to compile aufs internal debug code.
19450 + It will have a negative impact to the performance.
19452 +config AUFS_MAGIC_SYSRQ
19454 + depends on AUFS_DEBUG && MAGIC_SYSRQ
19457 + Automatic configuration for internal use.
19458 + When aufs supports Magic SysRq, enabled automatically.
19460 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
19461 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
19462 +++ linux/fs/aufs/loop.c 2013-10-26 16:51:32.276373845 +0200
19465 + * Copyright (C) 2005-2013 Junjiro R. Okajima
19467 + * This program, aufs is free software; you can redistribute it and/or modify
19468 + * it under the terms of the GNU General Public License as published by
19469 + * the Free Software Foundation; either version 2 of the License, or
19470 + * (at your option) any later version.
19472 + * This program is distributed in the hope that it will be useful,
19473 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19474 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19475 + * GNU General Public License for more details.
19477 + * You should have received a copy of the GNU General Public License
19478 + * along with this program; if not, write to the Free Software
19479 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19483 + * support for loopback block device as a branch
19488 +/* added into drivers/block/loop.c */
19489 +static struct file *(*backing_file_func)(struct super_block *sb);
19492 + * test if two lower dentries have overlapping branches.
19494 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
19496 + struct super_block *h_sb;
19497 + struct file *backing_file;
19499 + if (unlikely(!backing_file_func)) {
19500 + /* don't load "loop" module here */
19501 + backing_file_func = symbol_get(loop_backing_file);
19502 + if (unlikely(!backing_file_func))
19503 + /* "loop" module is not loaded */
19507 + h_sb = h_adding->d_sb;
19508 + backing_file = backing_file_func(h_sb);
19509 + if (!backing_file)
19512 + h_adding = backing_file->f_dentry;
19514 + * h_adding can be local NFS.
19515 + * in this case aufs cannot detect the loop.
19517 + if (unlikely(h_adding->d_sb == sb))
19519 + return !!au_test_subdir(h_adding, sb->s_root);
19522 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
19523 +int au_test_loopback_kthread(void)
19526 + struct task_struct *tsk = current;
19527 + char c, comm[sizeof(tsk->comm)];
19530 + if (tsk->flags & PF_KTHREAD) {
19531 + get_task_comm(comm, tsk);
19533 + ret = ('0' <= c && c <= '9'
19534 + && !strncmp(comm, "loop", 4));
19540 +/* ---------------------------------------------------------------------- */
19542 +#define au_warn_loopback_step 16
19543 +static int au_warn_loopback_nelem = au_warn_loopback_step;
19544 +static unsigned long *au_warn_loopback_array;
19546 +void au_warn_loopback(struct super_block *h_sb)
19548 + int i, new_nelem;
19549 + unsigned long *a, magic;
19550 + static DEFINE_SPINLOCK(spin);
19552 + magic = h_sb->s_magic;
19553 + spin_lock(&spin);
19554 + a = au_warn_loopback_array;
19555 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
19556 + if (a[i] == magic) {
19557 + spin_unlock(&spin);
19561 + /* h_sb is new to us, print it */
19562 + if (i < au_warn_loopback_nelem) {
19567 + /* expand the array */
19568 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
19569 + a = au_kzrealloc(au_warn_loopback_array,
19570 + au_warn_loopback_nelem * sizeof(unsigned long),
19571 + new_nelem * sizeof(unsigned long), GFP_ATOMIC);
19573 + au_warn_loopback_nelem = new_nelem;
19574 + au_warn_loopback_array = a;
19579 + spin_unlock(&spin);
19580 + AuWarn1("realloc failed, ignored\n");
19584 + spin_unlock(&spin);
19585 + pr_warn("you may want to try another patch for loopback file "
19586 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
19589 +int au_loopback_init(void)
19592 + struct super_block *sb __maybe_unused;
19594 + AuDebugOn(sizeof(sb->s_magic) != sizeof(unsigned long));
19597 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
19598 + sizeof(unsigned long), GFP_NOFS);
19599 + if (unlikely(!au_warn_loopback_array))
19605 +void au_loopback_fin(void)
19607 + symbol_put(loop_backing_file);
19608 + kfree(au_warn_loopback_array);
19610 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
19611 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
19612 +++ linux/fs/aufs/loop.h 2013-10-26 16:51:29.586298347 +0200
19615 + * Copyright (C) 2005-2013 Junjiro R. Okajima
19617 + * This program, aufs is free software; you can redistribute it and/or modify
19618 + * it under the terms of the GNU General Public License as published by
19619 + * the Free Software Foundation; either version 2 of the License, or
19620 + * (at your option) any later version.
19622 + * This program is distributed in the hope that it will be useful,
19623 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19624 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19625 + * GNU General Public License for more details.
19627 + * You should have received a copy of the GNU General Public License
19628 + * along with this program; if not, write to the Free Software
19629 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19633 + * support for loopback mount as a branch
19636 +#ifndef __AUFS_LOOP_H__
19637 +#define __AUFS_LOOP_H__
19642 +struct super_block;
19644 +#ifdef CONFIG_AUFS_BDEV_LOOP
19645 +/* drivers/block/loop.c */
19646 +struct file *loop_backing_file(struct super_block *sb);
19649 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
19650 +int au_test_loopback_kthread(void);
19651 +void au_warn_loopback(struct super_block *h_sb);
19653 +int au_loopback_init(void);
19654 +void au_loopback_fin(void);
19656 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
19657 + struct dentry *h_adding)
19658 +AuStubInt0(au_test_loopback_kthread, void)
19659 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
19661 +AuStubInt0(au_loopback_init, void)
19662 +AuStubVoid(au_loopback_fin, void)
19663 +#endif /* BLK_DEV_LOOP */
19665 +#endif /* __KERNEL__ */
19666 +#endif /* __AUFS_LOOP_H__ */
19667 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
19668 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
19669 +++ linux/fs/aufs/magic.mk 2013-07-06 13:20:47.750198454 +0200
19672 +# defined in ${srctree}/fs/fuse/inode.c
19674 +ifdef CONFIG_FUSE_FS
19675 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
19678 +# defined in ${srctree}/fs/ocfs2/ocfs2_fs.h
19680 +ifdef CONFIG_OCFS2_FS
19681 +ccflags-y += -DOCFS2_SUPER_MAGIC=0x7461636f
19684 +# defined in ${srctree}/fs/ocfs2/dlm/userdlm.h
19686 +ifdef CONFIG_OCFS2_FS_O2CB
19687 +ccflags-y += -DDLMFS_MAGIC=0x76a9f425
19690 +# defined in ${srctree}/fs/cifs/cifsfs.c
19692 +ifdef CONFIG_CIFS_FS
19693 +ccflags-y += -DCIFS_MAGIC_NUMBER=0xFF534D42
19696 +# defined in ${srctree}/fs/xfs/xfs_sb.h
19698 +ifdef CONFIG_XFS_FS
19699 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
19702 +# defined in ${srctree}/fs/configfs/mount.c
19704 +ifdef CONFIG_CONFIGFS_FS
19705 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
19708 +# defined in ${srctree}/fs/9p/v9fs.h
19710 +ifdef CONFIG_9P_FS
19711 +ccflags-y += -DV9FS_MAGIC=0x01021997
19714 +# defined in ${srctree}/fs/ubifs/ubifs.h
19716 +ifdef CONFIG_UBIFS_FS
19717 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
19720 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
19722 +ifdef CONFIG_HFSPLUS_FS
19723 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
19725 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
19726 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
19727 +++ linux/fs/aufs/Makefile 2013-10-26 16:51:32.273040419 +0200
19730 +include ${src}/magic.mk
19731 +ifeq (${CONFIG_AUFS_FS},m)
19732 +include ${src}/conf.mk
19734 +-include ${src}/priv_def.mk
19736 +# cf. include/linux/kernel.h
19738 +ccflags-y += -DDEBUG
19739 +# sparse requires the full pathname
19741 +ccflags-y += -include ${M}/../../include/linux/aufs_type.h
19743 +ccflags-y += -include ${srctree}/include/linux/aufs_type.h
19746 +obj-$(CONFIG_AUFS_FS) += aufs.o
19747 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
19748 + wkq.o vfsub.o dcsub.o \
19749 + cpup.o whout.o wbr_policy.o \
19750 + dinfo.o dentry.o \
19752 + finfo.o file.o f_op.o \
19754 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
19758 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
19759 +aufs-$(CONFIG_SYSFS) += sysfs.o
19760 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
19761 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
19762 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
19763 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
19764 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
19765 +aufs-$(CONFIG_AUFS_POLL) += poll.o
19766 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
19767 +aufs-$(CONFIG_AUFS_SP_IATTR) += f_op_sp.o
19768 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
19769 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
19770 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
19771 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
19772 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
19773 +++ linux/fs/aufs/module.c 2013-07-06 13:20:47.750198454 +0200
19776 + * Copyright (C) 2005-2013 Junjiro R. Okajima
19778 + * This program, aufs is free software; you can redistribute it and/or modify
19779 + * it under the terms of the GNU General Public License as published by
19780 + * the Free Software Foundation; either version 2 of the License, or
19781 + * (at your option) any later version.
19783 + * This program is distributed in the hope that it will be useful,
19784 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19785 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19786 + * GNU General Public License for more details.
19788 + * You should have received a copy of the GNU General Public License
19789 + * along with this program; if not, write to the Free Software
19790 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19794 + * module global variables and operations
19797 +#include <linux/module.h>
19798 +#include <linux/seq_file.h>
19801 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp)
19803 + if (new_sz <= nused)
19806 + p = krealloc(p, new_sz, gfp);
19808 + memset(p + nused, 0, new_sz - nused);
19812 +/* ---------------------------------------------------------------------- */
19817 +struct kmem_cache *au_cachep[AuCache_Last];
19818 +static int __init au_cache_init(void)
19820 + au_cachep[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
19821 + if (au_cachep[AuCache_DINFO])
19822 + /* SLAB_DESTROY_BY_RCU */
19823 + au_cachep[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
19824 + au_icntnr_init_once);
19825 + if (au_cachep[AuCache_ICNTNR])
19826 + au_cachep[AuCache_FINFO] = AuCacheCtor(au_finfo,
19827 + au_fi_init_once);
19828 + if (au_cachep[AuCache_FINFO])
19829 + au_cachep[AuCache_VDIR] = AuCache(au_vdir);
19830 + if (au_cachep[AuCache_VDIR])
19831 + au_cachep[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
19832 + if (au_cachep[AuCache_DEHSTR])
19838 +static void au_cache_fin(void)
19843 + * Make sure all delayed rcu free inodes are flushed before we
19848 + /* excluding AuCache_HNOTIFY */
19849 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
19850 + for (i = 0; i < AuCache_HNOTIFY; i++)
19851 + if (au_cachep[i]) {
19852 + kmem_cache_destroy(au_cachep[i]);
19853 + au_cachep[i] = NULL;
19857 +/* ---------------------------------------------------------------------- */
19859 +int au_dir_roflags;
19861 +#ifdef CONFIG_AUFS_SBILIST
19863 + * iterate_supers_type() doesn't protect us from
19864 + * remounting (branch management)
19866 +struct au_splhead au_sbilist;
19869 +struct lock_class_key au_lc_key[AuLcKey_Last];
19872 + * functions for module interface.
19874 +MODULE_LICENSE("GPL");
19875 +/* MODULE_LICENSE("GPL v2"); */
19876 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
19877 +MODULE_DESCRIPTION(AUFS_NAME
19878 + " -- Advanced multi layered unification filesystem");
19879 +MODULE_VERSION(AUFS_VERSION);
19880 +MODULE_ALIAS_FS(AUFS_NAME);
19882 +/* this module parameter has no meaning when SYSFS is disabled */
19883 +int sysaufs_brs = 1;
19884 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
19885 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
19887 +/* ---------------------------------------------------------------------- */
19889 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
19891 +int au_seq_path(struct seq_file *seq, struct path *path)
19893 + return seq_path(seq, path, au_esc_chars);
19896 +/* ---------------------------------------------------------------------- */
19898 +static int __init aufs_init(void)
19903 + p = au_esc_chars;
19904 + for (i = 1; i <= ' '; i++)
19910 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
19912 + au_sbilist_init();
19913 + sysaufs_brs_init();
19916 + err = sysaufs_init();
19917 + if (unlikely(err))
19919 + err = au_procfs_init();
19920 + if (unlikely(err))
19921 + goto out_sysaufs;
19922 + err = au_wkq_init();
19923 + if (unlikely(err))
19925 + err = au_loopback_init();
19926 + if (unlikely(err))
19928 + err = au_hnotify_init();
19929 + if (unlikely(err))
19930 + goto out_loopback;
19931 + err = au_sysrq_init();
19932 + if (unlikely(err))
19934 + err = au_cache_init();
19935 + if (unlikely(err))
19937 + err = register_filesystem(&aufs_fs_type);
19938 + if (unlikely(err))
19940 + /* since we define pr_fmt, call printk directly */
19941 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
19942 + goto out; /* success */
19949 + au_hnotify_fin();
19951 + au_loopback_fin();
19963 +static void __exit aufs_exit(void)
19965 + unregister_filesystem(&aufs_fs_type);
19968 + au_hnotify_fin();
19969 + au_loopback_fin();
19976 +module_init(aufs_init);
19977 +module_exit(aufs_exit);
19978 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
19979 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
19980 +++ linux/fs/aufs/module.h 2013-07-06 13:20:47.750198454 +0200
19983 + * Copyright (C) 2005-2013 Junjiro R. Okajima
19985 + * This program, aufs is free software; you can redistribute it and/or modify
19986 + * it under the terms of the GNU General Public License as published by
19987 + * the Free Software Foundation; either version 2 of the License, or
19988 + * (at your option) any later version.
19990 + * This program is distributed in the hope that it will be useful,
19991 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19992 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19993 + * GNU General Public License for more details.
19995 + * You should have received a copy of the GNU General Public License
19996 + * along with this program; if not, write to the Free Software
19997 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20001 + * module initialization and module-global
20004 +#ifndef __AUFS_MODULE_H__
20005 +#define __AUFS_MODULE_H__
20009 +#include <linux/slab.h>
20014 +/* module parameters */
20015 +extern int sysaufs_brs;
20017 +/* ---------------------------------------------------------------------- */
20019 +extern int au_dir_roflags;
20022 + AuLcNonDir_FIINFO,
20023 + AuLcNonDir_DIINFO,
20024 + AuLcNonDir_IIINFO,
20030 + AuLcSymlink_DIINFO,
20031 + AuLcSymlink_IIINFO,
20035 +extern struct lock_class_key au_lc_key[AuLcKey_Last];
20037 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp);
20038 +int au_seq_path(struct seq_file *seq, struct path *path);
20040 +#ifdef CONFIG_PROC_FS
20042 +int __init au_procfs_init(void);
20043 +void au_procfs_fin(void);
20045 +AuStubInt0(au_procfs_init, void);
20046 +AuStubVoid(au_procfs_fin, void);
20049 +/* ---------------------------------------------------------------------- */
20058 + AuCache_HNOTIFY, /* must be last */
20062 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
20063 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
20064 +#define AuCacheCtor(type, ctor) \
20065 + kmem_cache_create(#type, sizeof(struct type), \
20066 + __alignof__(struct type), AuCacheFlags, ctor)
20068 +extern struct kmem_cache *au_cachep[];
20070 +#define AuCacheFuncs(name, index) \
20071 +static inline struct au_##name *au_cache_alloc_##name(void) \
20072 +{ return kmem_cache_alloc(au_cachep[AuCache_##index], GFP_NOFS); } \
20073 +static inline void au_cache_free_##name(struct au_##name *p) \
20074 +{ kmem_cache_free(au_cachep[AuCache_##index], p); }
20076 +AuCacheFuncs(dinfo, DINFO);
20077 +AuCacheFuncs(icntnr, ICNTNR);
20078 +AuCacheFuncs(finfo, FINFO);
20079 +AuCacheFuncs(vdir, VDIR);
20080 +AuCacheFuncs(vdir_dehstr, DEHSTR);
20081 +#ifdef CONFIG_AUFS_HNOTIFY
20082 +AuCacheFuncs(hnotify, HNOTIFY);
20085 +#endif /* __KERNEL__ */
20086 +#endif /* __AUFS_MODULE_H__ */
20087 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
20088 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
20089 +++ linux/fs/aufs/mvdown.c 2013-10-26 16:51:32.276373845 +0200
20092 + * Copyright (C) 2011-2013 Junjiro R. Okajima
20094 + * This program, aufs is free software; you can redistribute it and/or modify
20095 + * it under the terms of the GNU General Public License as published by
20096 + * the Free Software Foundation; either version 2 of the License, or
20097 + * (at your option) any later version.
20099 + * This program is distributed in the hope that it will be useful,
20100 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20101 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20102 + * GNU General Public License for more details.
20104 + * You should have received a copy of the GNU General Public License
20105 + * along with this program; if not, write to the Free Software
20106 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20111 +struct au_mvd_args {
20113 + struct super_block *h_sb;
20114 + struct dentry *h_parent;
20115 + struct au_hinode *hdir;
20116 + struct inode *h_dir, *h_inode;
20117 + } info[AUFS_MVDOWN_NARRAY];
20119 + struct aufs_mvdown mvdown;
20120 + struct dentry *dentry, *parent;
20121 + struct inode *inode, *dir;
20122 + struct super_block *sb;
20123 + aufs_bindex_t bopq, bwh, bfound;
20124 + unsigned char rename_lock;
20125 + struct au_pin pin;
20128 +#define mvd_errno mvdown.au_errno
20129 +#define mvd_bsrc mvdown.a[AUFS_MVDOWN_UPPER].bindex
20130 +#define mvd_src_brid mvdown.a[AUFS_MVDOWN_UPPER].brid
20131 +#define mvd_bdst mvdown.a[AUFS_MVDOWN_LOWER].bindex
20132 +#define mvd_dst_brid mvdown.a[AUFS_MVDOWN_LOWER].brid
20134 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
20135 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
20136 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
20137 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
20138 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
20140 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
20141 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
20142 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
20143 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
20144 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
20146 +#define AU_MVD_PR(flag, ...) do { \
20148 + pr_err(__VA_ARGS__); \
20151 +/* make the parent dir on bdst */
20152 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
20157 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
20158 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
20159 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
20160 + a->mvd_h_dst_parent = NULL;
20161 + if (au_dbend(a->parent) >= a->mvd_bdst)
20162 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
20163 + if (!a->mvd_h_dst_parent) {
20164 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
20165 + if (unlikely(err)) {
20166 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
20169 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
20177 +/* lock them all */
20178 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
20181 + struct dentry *h_trap;
20183 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
20184 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
20185 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
20186 + a->rename_lock = 0;
20187 + err = au_pin(&a->pin, a->dentry, a->mvd_bdst,
20188 + au_opt_udba(a->sb),
20189 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
20191 + a->mvd_h_src_dir = a->mvd_h_src_parent->d_inode;
20192 + mutex_lock_nested(&a->mvd_h_src_dir->i_mutex,
20193 + AuLsc_I_PARENT3);
20195 + AU_MVD_PR(dmsg, "pin failed\n");
20200 + a->rename_lock = 1;
20201 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
20202 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
20204 + err = (h_trap != a->mvd_h_src_parent);
20206 + err = (h_trap != a->mvd_h_dst_parent);
20208 + BUG_ON(err); /* it should never happen */
20215 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
20217 + if (!a->rename_lock) {
20218 + mutex_unlock(&a->mvd_h_src_dir->i_mutex);
20219 + au_unpin(&a->pin);
20221 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
20222 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
20225 +/* copy-down the file */
20226 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
20229 + struct au_cp_generic cpg = {
20230 + .dentry = a->dentry,
20231 + .bdst = a->mvd_bdst,
20232 + .bsrc = a->mvd_bsrc,
20235 + .flags = AuCpup_DTIME | AuCpup_HOPEN
20238 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
20239 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
20240 + au_fset_cpup(cpg.flags, OVERWRITE);
20241 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
20242 + au_fset_cpup(cpg.flags, RWDST);
20243 + err = au_sio_cpdown_simple(&cpg);
20244 + if (unlikely(err))
20245 + AU_MVD_PR(dmsg, "cpdown failed\n");
20252 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
20255 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
20258 + struct path h_path;
20259 + struct au_branch *br;
20261 + br = au_sbr(a->sb, a->mvd_bdst);
20262 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
20263 + err = PTR_ERR(h_path.dentry);
20264 + if (IS_ERR(h_path.dentry)) {
20265 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
20270 + if (h_path.dentry->d_inode) {
20271 + h_path.mnt = au_br_mnt(br);
20272 + err = vfsub_unlink(a->mvd_h_dst_parent->d_inode, &h_path,
20274 + if (unlikely(err))
20275 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
20277 + dput(h_path.dentry);
20285 + * unlink the topmost h_dentry
20286 + * Note: the target file MAY be modified by UDBA between this mutex_unlock() and
20287 + * mutex_lock() in vfs_unlink(). in this case, such changes may be lost.
20289 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
20292 + struct path h_path;
20294 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
20295 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
20296 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, /*force*/0);
20297 + if (unlikely(err))
20298 + AU_MVD_PR(dmsg, "unlink failed\n");
20305 + * copy-down the file and unlink the bsrc file.
20306 + * - unlink the bdst whout if exist
20307 + * - copy-down the file (with whtmp name and rename)
20308 + * - unlink the bsrc file
20310 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
20314 + err = au_do_mkdir(dmsg, a);
20316 + err = au_do_lock(dmsg, a);
20317 + if (unlikely(err))
20321 + * do not revert the activities we made on bdst since they should be
20322 + * harmless in aufs.
20325 + err = au_do_cpdown(dmsg, a);
20327 + err = au_do_unlink_wh(dmsg, a);
20328 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
20329 + err = au_do_unlink(dmsg, a);
20330 + if (unlikely(err))
20333 + /* maintain internal array */
20334 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
20335 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
20336 + au_set_dbstart(a->dentry, a->mvd_bdst);
20337 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
20338 + au_set_ibstart(a->inode, a->mvd_bdst);
20340 + if (au_dbend(a->dentry) < a->mvd_bdst)
20341 + au_set_dbend(a->dentry, a->mvd_bdst);
20342 + if (au_ibend(a->inode) < a->mvd_bdst)
20343 + au_set_ibend(a->inode, a->mvd_bdst);
20346 + au_do_unlock(dmsg, a);
20352 +/* ---------------------------------------------------------------------- */
20354 +static int find_lower_writable(struct au_mvd_args *a)
20356 + struct super_block *sb;
20357 + aufs_bindex_t bindex, bend;
20358 + struct au_branch *br;
20361 + bindex = a->mvd_bsrc;
20362 + bend = au_sbend(sb);
20363 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER)) {
20364 + for (bindex++; bindex <= bend; bindex++) {
20365 + br = au_sbr(sb, bindex);
20366 + if (!au_br_rdonly(br))
20370 + for (bindex++; bindex <= bend; bindex++) {
20371 + br = au_sbr(sb, bindex);
20372 + if (!(au_br_sb(br)->s_flags & MS_RDONLY)) {
20373 + if (au_br_rdonly(br))
20375 + |= AUFS_MVDOWN_ROLOWER_R;
20384 +/* make sure the file is idle */
20385 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
20387 + int err, plinked;
20390 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
20391 + if (au_dbstart(a->dentry) == a->mvd_bsrc
20392 + && d_count(a->dentry) == 1
20393 + && atomic_read(&a->inode->i_count) == 1
20394 + /* && a->mvd_h_src_inode->i_nlink == 1 */
20395 + && (!plinked || !au_plink_test(a->inode))
20396 + && a->inode->i_nlink == 1)
20401 + "b%d, d{b%d, c%u?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
20402 + a->mvd_bsrc, au_dbstart(a->dentry), d_count(a->dentry),
20403 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
20404 + a->mvd_h_src_inode->i_nlink,
20405 + plinked, plinked ? au_plink_test(a->inode) : 0);
20412 +/* make sure the parent dir is fine */
20413 +static int au_mvd_args_parent(const unsigned char dmsg,
20414 + struct au_mvd_args *a)
20417 + aufs_bindex_t bindex;
20420 + if (unlikely(au_alive_dir(a->parent))) {
20422 + AU_MVD_PR(dmsg, "parent dir is dead\n");
20426 + a->bopq = au_dbdiropq(a->parent);
20427 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
20428 + AuDbg("b%d\n", bindex);
20429 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
20430 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
20432 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
20433 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
20434 + a->bopq, a->mvd_bdst);
20442 +static int au_mvd_args_intermediate(const unsigned char dmsg,
20443 + struct au_mvd_args *a)
20446 + struct au_dinfo *dinfo, *tmp;
20448 + /* lookup the next lower positive entry */
20450 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
20451 + if (unlikely(!tmp))
20456 + dinfo = au_di(a->dentry);
20457 + au_di_cp(tmp, dinfo);
20458 + au_di_swap(tmp, dinfo);
20460 + /* returns the number of positive dentries */
20461 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1, /*type*/0);
20463 + a->bwh = au_dbwh(a->dentry);
20464 + else if (err > 0)
20465 + a->bfound = au_dbstart(a->dentry);
20467 + au_di_swap(tmp, dinfo);
20468 + au_rw_write_unlock(&tmp->di_rwsem);
20470 + if (unlikely(err < 0))
20471 + AU_MVD_PR(dmsg, "failed look-up lower\n");
20474 + * here, we have these cases.
20476 + * no positive dentry under bsrc. there are more sub-cases.
20478 + * there no whiteout, we can safely move-down.
20481 + * bsrc < bwh && bwh < bdst
20482 + * there is a whiteout on RO branch. cannot proceed.
20484 + * there is a whiteout on the RW target branch. it should
20487 + * there is a whiteout somewhere unrelated branch.
20488 + * -1 < bfound && bfound <= bsrc
20491 + * found, but it is on RO branch between bsrc and bdst. cannot
20494 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
20497 + * found, after we create the file on bdst, it will be hidden.
20500 + AuDebugOn(a->bfound == -1
20502 + && a->bwh <= a->mvd_bsrc);
20503 + AuDebugOn(-1 < a->bfound
20504 + && a->bfound <= a->mvd_bsrc);
20507 + if (a->bfound == -1
20508 + && a->mvd_bsrc < a->bwh
20510 + && a->bwh < a->mvd_bdst) {
20511 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
20512 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
20513 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
20515 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
20516 + a->mvd_errno = EAU_MVDOWN_UPPER;
20517 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
20518 + a->mvd_bdst, a->bfound);
20522 + err = 0; /* success */
20529 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
20534 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
20535 + && a->bfound == a->mvd_bdst)
20541 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
20544 + struct au_branch *br;
20547 + if (unlikely(S_ISDIR(a->inode->i_mode)))
20551 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
20552 + a->mvd_bsrc = au_ibstart(a->inode);
20554 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
20555 + if (unlikely(a->mvd_bsrc < 0
20556 + || (a->mvd_bsrc < au_dbstart(a->dentry)
20557 + || au_dbend(a->dentry) < a->mvd_bsrc
20558 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
20559 + || (a->mvd_bsrc < au_ibstart(a->inode)
20560 + || au_ibend(a->inode) < a->mvd_bsrc
20561 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
20562 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
20563 + AU_MVD_PR(dmsg, "no upper\n");
20567 + if (unlikely(a->mvd_bsrc == au_sbend(a->sb))) {
20568 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
20569 + AU_MVD_PR(dmsg, "on the bottom\n");
20572 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
20573 + br = au_sbr(a->sb, a->mvd_bsrc);
20574 + err = au_br_rdonly(br);
20575 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
20576 + if (unlikely(err))
20578 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
20579 + || IS_APPEND(a->mvd_h_src_inode))) {
20581 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
20587 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
20588 + a->mvd_bdst = find_lower_writable(a);
20589 + if (unlikely(a->mvd_bdst < 0)) {
20590 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
20591 + AU_MVD_PR(dmsg, "no writable lower branch\n");
20595 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
20596 + if (unlikely(a->mvd_bdst < 0
20597 + || au_sbend(a->sb) < a->mvd_bdst)) {
20598 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
20599 + AU_MVD_PR(dmsg, "no lower brid\n");
20604 + err = au_mvd_args_busy(dmsg, a);
20606 + err = au_mvd_args_parent(dmsg, a);
20608 + err = au_mvd_args_intermediate(dmsg, a);
20610 + err = au_mvd_args_exist(dmsg, a);
20612 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
20619 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
20622 + unsigned char dmsg;
20623 + struct au_mvd_args *args;
20626 + if (unlikely(!capable(CAP_SYS_ADMIN)))
20629 + WARN_ONCE(1, "move-down is still testing...\n");
20632 + args = kmalloc(sizeof(*args), GFP_NOFS);
20633 + if (unlikely(!args))
20636 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
20638 + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
20639 + if (unlikely(err)) {
20644 + AuDbg("flags 0x%x\n", args->mvdown.flags);
20645 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
20646 + args->mvdown.au_errno = 0;
20647 + args->dentry = dentry;
20648 + args->inode = dentry->d_inode;
20649 + args->sb = dentry->d_sb;
20652 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
20653 + args->parent = dget_parent(dentry);
20654 + args->dir = args->parent->d_inode;
20655 + mutex_lock_nested(&args->dir->i_mutex, I_MUTEX_PARENT);
20656 + dput(args->parent);
20657 + if (unlikely(args->parent != dentry->d_parent)) {
20658 + AU_MVD_PR(dmsg, "parent dir is moved\n");
20662 + mutex_lock_nested(&args->inode->i_mutex, I_MUTEX_CHILD);
20663 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH);
20664 + if (unlikely(err))
20667 + di_write_lock_parent(args->parent);
20668 + err = au_mvd_args(dmsg, args);
20669 + if (unlikely(err))
20672 + AuDbgDentry(dentry);
20673 + AuDbgInode(args->inode);
20674 + err = au_do_mvdown(dmsg, args);
20675 + if (unlikely(err))
20677 + AuDbgDentry(dentry);
20678 + AuDbgInode(args->inode);
20680 + au_cpup_attr_timesizes(args->dir);
20681 + au_cpup_attr_timesizes(args->inode);
20682 + au_cpup_igen(args->inode, au_h_iptr(args->inode, args->mvd_bdst));
20683 + /* au_digen_dec(dentry); */
20686 + di_write_unlock(args->parent);
20687 + aufs_read_unlock(dentry, AuLock_DW);
20689 + mutex_unlock(&args->inode->i_mutex);
20691 + mutex_unlock(&args->dir->i_mutex);
20693 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
20701 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
20702 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
20703 +++ linux/fs/aufs/opts.c 2013-10-26 16:51:32.276373845 +0200
20706 + * Copyright (C) 2005-2013 Junjiro R. Okajima
20708 + * This program, aufs is free software; you can redistribute it and/or modify
20709 + * it under the terms of the GNU General Public License as published by
20710 + * the Free Software Foundation; either version 2 of the License, or
20711 + * (at your option) any later version.
20713 + * This program is distributed in the hope that it will be useful,
20714 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20715 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20716 + * GNU General Public License for more details.
20718 + * You should have received a copy of the GNU General Public License
20719 + * along with this program; if not, write to the Free Software
20720 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20724 + * mount options/flags
20727 +#include <linux/namei.h>
20728 +#include <linux/types.h> /* a distribution requires */
20729 +#include <linux/parser.h>
20732 +/* ---------------------------------------------------------------------- */
20736 + Opt_add, Opt_del, Opt_mod, Opt_reorder, Opt_append, Opt_prepend,
20737 + Opt_idel, Opt_imod, Opt_ireorder,
20738 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash, Opt_rendir,
20739 + Opt_rdblk_def, Opt_rdhash_def,
20740 + Opt_xino, Opt_zxino, Opt_noxino,
20741 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
20742 + Opt_trunc_xino_path, Opt_itrunc_xino,
20743 + Opt_trunc_xib, Opt_notrunc_xib,
20744 + Opt_shwh, Opt_noshwh,
20745 + Opt_plink, Opt_noplink, Opt_list_plink,
20747 + Opt_dio, Opt_nodio,
20748 + /* Opt_lock, Opt_unlock, */
20749 + Opt_cmd, Opt_cmd_args,
20750 + Opt_diropq_a, Opt_diropq_w,
20751 + Opt_warn_perm, Opt_nowarn_perm,
20752 + Opt_wbr_copyup, Opt_wbr_create,
20753 + Opt_refrof, Opt_norefrof,
20754 + Opt_verbose, Opt_noverbose,
20755 + Opt_sum, Opt_nosum, Opt_wsum,
20756 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
20759 +static match_table_t options = {
20760 + {Opt_br, "br=%s"},
20761 + {Opt_br, "br:%s"},
20763 + {Opt_add, "add=%d:%s"},
20764 + {Opt_add, "add:%d:%s"},
20765 + {Opt_add, "ins=%d:%s"},
20766 + {Opt_add, "ins:%d:%s"},
20767 + {Opt_append, "append=%s"},
20768 + {Opt_append, "append:%s"},
20769 + {Opt_prepend, "prepend=%s"},
20770 + {Opt_prepend, "prepend:%s"},
20772 + {Opt_del, "del=%s"},
20773 + {Opt_del, "del:%s"},
20774 + /* {Opt_idel, "idel:%d"}, */
20775 + {Opt_mod, "mod=%s"},
20776 + {Opt_mod, "mod:%s"},
20777 + /* {Opt_imod, "imod:%d:%s"}, */
20779 + {Opt_dirwh, "dirwh=%d"},
20781 + {Opt_xino, "xino=%s"},
20782 + {Opt_noxino, "noxino"},
20783 + {Opt_trunc_xino, "trunc_xino"},
20784 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
20785 + {Opt_notrunc_xino, "notrunc_xino"},
20786 + {Opt_trunc_xino_path, "trunc_xino=%s"},
20787 + {Opt_itrunc_xino, "itrunc_xino=%d"},
20788 + /* {Opt_zxino, "zxino=%s"}, */
20789 + {Opt_trunc_xib, "trunc_xib"},
20790 + {Opt_notrunc_xib, "notrunc_xib"},
20792 +#ifdef CONFIG_PROC_FS
20793 + {Opt_plink, "plink"},
20795 + {Opt_ignore_silent, "plink"},
20798 + {Opt_noplink, "noplink"},
20800 +#ifdef CONFIG_AUFS_DEBUG
20801 + {Opt_list_plink, "list_plink"},
20804 + {Opt_udba, "udba=%s"},
20806 + {Opt_dio, "dio"},
20807 + {Opt_nodio, "nodio"},
20809 + {Opt_diropq_a, "diropq=always"},
20810 + {Opt_diropq_a, "diropq=a"},
20811 + {Opt_diropq_w, "diropq=whiteouted"},
20812 + {Opt_diropq_w, "diropq=w"},
20814 + {Opt_warn_perm, "warn_perm"},
20815 + {Opt_nowarn_perm, "nowarn_perm"},
20817 + /* keep them temporary */
20818 + {Opt_ignore_silent, "coo=%s"},
20819 + {Opt_ignore_silent, "nodlgt"},
20820 + {Opt_ignore_silent, "nodirperm1"},
20821 + {Opt_ignore_silent, "clean_plink"},
20823 +#ifdef CONFIG_AUFS_SHWH
20824 + {Opt_shwh, "shwh"},
20826 + {Opt_noshwh, "noshwh"},
20828 + {Opt_rendir, "rendir=%d"},
20830 + {Opt_refrof, "refrof"},
20831 + {Opt_norefrof, "norefrof"},
20833 + {Opt_verbose, "verbose"},
20834 + {Opt_verbose, "v"},
20835 + {Opt_noverbose, "noverbose"},
20836 + {Opt_noverbose, "quiet"},
20837 + {Opt_noverbose, "q"},
20838 + {Opt_noverbose, "silent"},
20840 + {Opt_sum, "sum"},
20841 + {Opt_nosum, "nosum"},
20842 + {Opt_wsum, "wsum"},
20844 + {Opt_rdcache, "rdcache=%d"},
20845 + {Opt_rdblk, "rdblk=%d"},
20846 + {Opt_rdblk_def, "rdblk=def"},
20847 + {Opt_rdhash, "rdhash=%d"},
20848 + {Opt_rdhash_def, "rdhash=def"},
20850 + {Opt_wbr_create, "create=%s"},
20851 + {Opt_wbr_create, "create_policy=%s"},
20852 + {Opt_wbr_copyup, "cpup=%s"},
20853 + {Opt_wbr_copyup, "copyup=%s"},
20854 + {Opt_wbr_copyup, "copyup_policy=%s"},
20856 + /* internal use for the scripts */
20857 + {Opt_ignore_silent, "si=%s"},
20859 + {Opt_br, "dirs=%s"},
20860 + {Opt_ignore, "debug=%d"},
20861 + {Opt_ignore, "delete=whiteout"},
20862 + {Opt_ignore, "delete=all"},
20863 + {Opt_ignore, "imap=%s"},
20865 + /* temporary workaround, due to old mount(8)? */
20866 + {Opt_ignore_silent, "relatime"},
20871 +/* ---------------------------------------------------------------------- */
20873 +static const char *au_parser_pattern(int val, struct match_token *token)
20875 + while (token->pattern) {
20876 + if (token->token == val)
20877 + return token->pattern;
20884 +/* ---------------------------------------------------------------------- */
20886 +static match_table_t brperm = {
20887 + {AuBrPerm_RO, AUFS_BRPERM_RO},
20888 + {AuBrPerm_RR, AUFS_BRPERM_RR},
20889 + {AuBrPerm_RW, AUFS_BRPERM_RW},
20893 +static match_table_t brattr = {
20894 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
20895 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
20896 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
20900 +#define AuBrStr_LONGEST AUFS_BRPERM_RW \
20901 + "+" AUFS_BRATTR_UNPIN \
20902 + "+" AUFS_BRWATTR_NLWH
20904 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
20911 + p = strchr(str, '+');
20914 + v = match_token(str, table, args);
20920 + pr_warn("ignored branch attribute %s\n", str);
20930 +static int noinline_for_stack br_perm_val(char *perm)
20934 + substring_t args[MAX_OPT_ARGS];
20936 + p = strchr(perm, '+');
20939 + val = match_token(perm, brperm, args);
20943 + pr_warn("ignored branch permission %s\n", perm);
20944 + val = AuBrPerm_RO;
20952 + q = strchr(p, '+');
20955 + val |= br_attr_val(p, brattr, args);
20962 + switch (val & AuBrPerm_Mask) {
20963 + case AuBrPerm_RO:
20964 + case AuBrPerm_RR:
20965 + if (unlikely(val & AuBrWAttr_NoLinkWH)) {
20966 + pr_warn("ignored branch attribute %s\n",
20967 + AUFS_BRWATTR_NLWH);
20968 + val &= ~AuBrWAttr_NoLinkWH;
20971 + case AuBrPerm_RW:
20972 + if (unlikely(val & AuBrRAttr_WH)) {
20973 + pr_warn("ignored branch attribute %s\n",
20974 + AUFS_BRRATTR_WH);
20975 + val &= ~AuBrRAttr_WH;
20984 +/* Caller should free the return value */
20985 +char *au_optstr_br_perm(int brperm)
20987 + char *p, a[sizeof(AuBrStr_LONGEST)];
20990 +#define SetPerm(str) do { \
20991 + sz = sizeof(str); \
20992 + memcpy(a, str, sz); \
20993 + p = a + sz - 1; \
20996 +#define AppendAttr(flag, str) do { \
20997 + if (brperm & flag) { \
20998 + sz = sizeof(str); \
21000 + memcpy(p, str, sz); \
21005 + switch (brperm & AuBrPerm_Mask) {
21006 + case AuBrPerm_RO:
21007 + SetPerm(AUFS_BRPERM_RO);
21009 + case AuBrPerm_RR:
21010 + SetPerm(AUFS_BRPERM_RR);
21012 + case AuBrPerm_RW:
21013 + SetPerm(AUFS_BRPERM_RW);
21019 + AppendAttr(AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN);
21020 + AppendAttr(AuBrRAttr_WH, AUFS_BRRATTR_WH);
21021 + AppendAttr(AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH);
21023 + AuDebugOn(strlen(a) >= sizeof(a));
21024 + return kstrdup(a, GFP_NOFS);
21029 +/* ---------------------------------------------------------------------- */
21031 +static match_table_t udbalevel = {
21032 + {AuOpt_UDBA_REVAL, "reval"},
21033 + {AuOpt_UDBA_NONE, "none"},
21034 +#ifdef CONFIG_AUFS_HNOTIFY
21035 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
21036 +#ifdef CONFIG_AUFS_HFSNOTIFY
21037 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
21043 +static int noinline_for_stack udba_val(char *str)
21045 + substring_t args[MAX_OPT_ARGS];
21047 + return match_token(str, udbalevel, args);
21050 +const char *au_optstr_udba(int udba)
21052 + return au_parser_pattern(udba, (void *)udbalevel);
21055 +/* ---------------------------------------------------------------------- */
21057 +static match_table_t au_wbr_create_policy = {
21058 + {AuWbrCreate_TDP, "tdp"},
21059 + {AuWbrCreate_TDP, "top-down-parent"},
21060 + {AuWbrCreate_RR, "rr"},
21061 + {AuWbrCreate_RR, "round-robin"},
21062 + {AuWbrCreate_MFS, "mfs"},
21063 + {AuWbrCreate_MFS, "most-free-space"},
21064 + {AuWbrCreate_MFSV, "mfs:%d"},
21065 + {AuWbrCreate_MFSV, "most-free-space:%d"},
21067 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
21068 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
21069 + {AuWbrCreate_PMFS, "pmfs"},
21070 + {AuWbrCreate_PMFSV, "pmfs:%d"},
21071 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
21072 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
21078 + * cf. linux/lib/parser.c and cmdline.c
21079 + * gave up calling memparse() since it uses simple_strtoull() instead of
21082 +static int noinline_for_stack
21083 +au_match_ull(substring_t *s, unsigned long long *result)
21086 + unsigned int len;
21090 + len = s->to - s->from;
21091 + if (len + 1 <= sizeof(a)) {
21092 + memcpy(a, s->from, len);
21094 + err = kstrtoull(a, 0, result);
21099 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
21100 + struct au_opt_wbr_create *create)
21103 + unsigned long long ull;
21106 + if (!au_match_ull(arg, &ull))
21107 + create->mfsrr_watermark = ull;
21109 + pr_err("bad integer in %s\n", str);
21116 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
21117 + struct au_opt_wbr_create *create)
21122 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
21123 + create->mfs_second = n;
21125 + pr_err("bad integer in %s\n", str);
21132 +static int noinline_for_stack
21133 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
21136 + substring_t args[MAX_OPT_ARGS];
21138 + err = match_token(str, au_wbr_create_policy, args);
21139 + create->wbr_create = err;
21141 + case AuWbrCreate_MFSRRV:
21142 + case AuWbrCreate_PMFSRRV:
21143 + e = au_wbr_mfs_wmark(&args[0], str, create);
21145 + e = au_wbr_mfs_sec(&args[1], str, create);
21149 + case AuWbrCreate_MFSRR:
21150 + case AuWbrCreate_PMFSRR:
21151 + e = au_wbr_mfs_wmark(&args[0], str, create);
21152 + if (unlikely(e)) {
21157 + case AuWbrCreate_MFS:
21158 + case AuWbrCreate_PMFS:
21159 + create->mfs_second = AUFS_MFS_DEF_SEC;
21161 + case AuWbrCreate_MFSV:
21162 + case AuWbrCreate_PMFSV:
21163 + e = au_wbr_mfs_sec(&args[0], str, create);
21172 +const char *au_optstr_wbr_create(int wbr_create)
21174 + return au_parser_pattern(wbr_create, (void *)au_wbr_create_policy);
21177 +static match_table_t au_wbr_copyup_policy = {
21178 + {AuWbrCopyup_TDP, "tdp"},
21179 + {AuWbrCopyup_TDP, "top-down-parent"},
21180 + {AuWbrCopyup_BUP, "bup"},
21181 + {AuWbrCopyup_BUP, "bottom-up-parent"},
21182 + {AuWbrCopyup_BU, "bu"},
21183 + {AuWbrCopyup_BU, "bottom-up"},
21187 +static int noinline_for_stack au_wbr_copyup_val(char *str)
21189 + substring_t args[MAX_OPT_ARGS];
21191 + return match_token(str, au_wbr_copyup_policy, args);
21194 +const char *au_optstr_wbr_copyup(int wbr_copyup)
21196 + return au_parser_pattern(wbr_copyup, (void *)au_wbr_copyup_policy);
21199 +/* ---------------------------------------------------------------------- */
21201 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
21203 +static void dump_opts(struct au_opts *opts)
21205 +#ifdef CONFIG_AUFS_DEBUG
21206 + /* reduce stack space */
21208 + struct au_opt_add *add;
21209 + struct au_opt_del *del;
21210 + struct au_opt_mod *mod;
21211 + struct au_opt_xino *xino;
21212 + struct au_opt_xino_itrunc *xino_itrunc;
21213 + struct au_opt_wbr_create *create;
21215 + struct au_opt *opt;
21218 + while (opt->type != Opt_tail) {
21219 + switch (opt->type) {
21221 + u.add = &opt->add;
21222 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
21223 + u.add->bindex, u.add->pathname, u.add->perm,
21224 + u.add->path.dentry);
21228 + u.del = &opt->del;
21229 + AuDbg("del {%s, %p}\n",
21230 + u.del->pathname, u.del->h_path.dentry);
21234 + u.mod = &opt->mod;
21235 + AuDbg("mod {%s, 0x%x, %p}\n",
21236 + u.mod->path, u.mod->perm, u.mod->h_root);
21239 + u.add = &opt->add;
21240 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
21241 + u.add->bindex, u.add->pathname, u.add->perm,
21242 + u.add->path.dentry);
21244 + case Opt_prepend:
21245 + u.add = &opt->add;
21246 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
21247 + u.add->bindex, u.add->pathname, u.add->perm,
21248 + u.add->path.dentry);
21251 + AuDbg("dirwh %d\n", opt->dirwh);
21253 + case Opt_rdcache:
21254 + AuDbg("rdcache %d\n", opt->rdcache);
21257 + AuDbg("rdblk %u\n", opt->rdblk);
21259 + case Opt_rdblk_def:
21260 + AuDbg("rdblk_def\n");
21263 + AuDbg("rdhash %u\n", opt->rdhash);
21265 + case Opt_rdhash_def:
21266 + AuDbg("rdhash_def\n");
21269 + u.xino = &opt->xino;
21270 + AuDbg("xino {%s %.*s}\n",
21272 + AuDLNPair(u.xino->file->f_dentry));
21274 + case Opt_trunc_xino:
21275 + AuLabel(trunc_xino);
21277 + case Opt_notrunc_xino:
21278 + AuLabel(notrunc_xino);
21280 + case Opt_trunc_xino_path:
21281 + case Opt_itrunc_xino:
21282 + u.xino_itrunc = &opt->xino_itrunc;
21283 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
21289 + case Opt_trunc_xib:
21290 + AuLabel(trunc_xib);
21292 + case Opt_notrunc_xib:
21293 + AuLabel(notrunc_xib);
21304 + case Opt_noplink:
21305 + AuLabel(noplink);
21307 + case Opt_list_plink:
21308 + AuLabel(list_plink);
21311 + AuDbg("udba %d, %s\n",
21312 + opt->udba, au_optstr_udba(opt->udba));
21320 + case Opt_diropq_a:
21321 + AuLabel(diropq_a);
21323 + case Opt_diropq_w:
21324 + AuLabel(diropq_w);
21326 + case Opt_warn_perm:
21327 + AuLabel(warn_perm);
21329 + case Opt_nowarn_perm:
21330 + AuLabel(nowarn_perm);
21335 + case Opt_norefrof:
21336 + AuLabel(norefrof);
21338 + case Opt_verbose:
21339 + AuLabel(verbose);
21341 + case Opt_noverbose:
21342 + AuLabel(noverbose);
21353 + case Opt_wbr_create:
21354 + u.create = &opt->wbr_create;
21355 + AuDbg("create %d, %s\n", u.create->wbr_create,
21356 + au_optstr_wbr_create(u.create->wbr_create));
21357 + switch (u.create->wbr_create) {
21358 + case AuWbrCreate_MFSV:
21359 + case AuWbrCreate_PMFSV:
21360 + AuDbg("%d sec\n", u.create->mfs_second);
21362 + case AuWbrCreate_MFSRR:
21363 + AuDbg("%llu watermark\n",
21364 + u.create->mfsrr_watermark);
21366 + case AuWbrCreate_MFSRRV:
21367 + case AuWbrCreate_PMFSRRV:
21368 + AuDbg("%llu watermark, %d sec\n",
21369 + u.create->mfsrr_watermark,
21370 + u.create->mfs_second);
21374 + case Opt_wbr_copyup:
21375 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
21376 + au_optstr_wbr_copyup(opt->wbr_copyup));
21386 +void au_opts_free(struct au_opts *opts)
21388 + struct au_opt *opt;
21391 + while (opt->type != Opt_tail) {
21392 + switch (opt->type) {
21395 + case Opt_prepend:
21396 + path_put(&opt->add.path);
21400 + path_put(&opt->del.h_path);
21404 + dput(opt->mod.h_root);
21407 + fput(opt->xino.file);
21414 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
21415 + aufs_bindex_t bindex)
21418 + struct au_opt_add *add = &opt->add;
21421 + add->bindex = bindex;
21422 + add->perm = AuBrPerm_RO;
21423 + add->pathname = opt_str;
21424 + p = strchr(opt_str, '=');
21428 + add->perm = br_perm_val(p);
21431 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
21434 + add->perm = AuBrPerm_RO;
21435 + if (au_test_fs_rr(add->path.dentry->d_sb))
21436 + add->perm = AuBrPerm_RR;
21437 + else if (!bindex && !(sb_flags & MS_RDONLY))
21438 + add->perm = AuBrPerm_RW;
21440 + opt->type = Opt_add;
21443 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
21450 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
21454 + del->pathname = args[0].from;
21455 + AuDbg("del path %s\n", del->pathname);
21457 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
21458 + if (unlikely(err))
21459 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
21464 +#if 0 /* reserved for future use */
21465 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
21466 + struct au_opt_del *del, substring_t args[])
21469 + struct dentry *root;
21472 + root = sb->s_root;
21473 + aufs_read_lock(root, AuLock_FLUSH);
21474 + if (bindex < 0 || au_sbend(sb) < bindex) {
21475 + pr_err("out of bounds, %d\n", bindex);
21480 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
21481 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
21484 + aufs_read_unlock(root, !AuLock_IR);
21489 +static int noinline_for_stack
21490 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
21493 + struct path path;
21497 + mod->path = args[0].from;
21498 + p = strchr(mod->path, '=');
21499 + if (unlikely(!p)) {
21500 + pr_err("no permssion %s\n", args[0].from);
21505 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
21506 + if (unlikely(err)) {
21507 + pr_err("lookup failed %s (%d)\n", mod->path, err);
21511 + mod->perm = br_perm_val(p);
21512 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
21513 + mod->h_root = dget(path.dentry);
21520 +#if 0 /* reserved for future use */
21521 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
21522 + struct au_opt_mod *mod, substring_t args[])
21525 + struct dentry *root;
21528 + root = sb->s_root;
21529 + aufs_read_lock(root, AuLock_FLUSH);
21530 + if (bindex < 0 || au_sbend(sb) < bindex) {
21531 + pr_err("out of bounds, %d\n", bindex);
21536 + mod->perm = br_perm_val(args[1].from);
21537 + AuDbg("mod path %s, perm 0x%x, %s\n",
21538 + mod->path, mod->perm, args[1].from);
21539 + mod->h_root = dget(au_h_dptr(root, bindex));
21542 + aufs_read_unlock(root, !AuLock_IR);
21547 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
21548 + substring_t args[])
21551 + struct file *file;
21553 + file = au_xino_create(sb, args[0].from, /*silent*/0);
21554 + err = PTR_ERR(file);
21555 + if (IS_ERR(file))
21559 + if (unlikely(file->f_dentry->d_sb == sb)) {
21561 + pr_err("%s must be outside\n", args[0].from);
21566 + xino->file = file;
21567 + xino->path = args[0].from;
21573 +static int noinline_for_stack
21574 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
21575 + struct au_opt_xino_itrunc *xino_itrunc,
21576 + substring_t args[])
21579 + aufs_bindex_t bend, bindex;
21580 + struct path path;
21581 + struct dentry *root;
21583 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
21584 + if (unlikely(err)) {
21585 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
21589 + xino_itrunc->bindex = -1;
21590 + root = sb->s_root;
21591 + aufs_read_lock(root, AuLock_FLUSH);
21592 + bend = au_sbend(sb);
21593 + for (bindex = 0; bindex <= bend; bindex++) {
21594 + if (au_h_dptr(root, bindex) == path.dentry) {
21595 + xino_itrunc->bindex = bindex;
21599 + aufs_read_unlock(root, !AuLock_IR);
21602 + if (unlikely(xino_itrunc->bindex < 0)) {
21603 + pr_err("no such branch %s\n", args[0].from);
21611 +/* called without aufs lock */
21612 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
21614 + int err, n, token;
21615 + aufs_bindex_t bindex;
21616 + unsigned char skipped;
21617 + struct dentry *root;
21618 + struct au_opt *opt, *opt_tail;
21620 + /* reduce the stack space */
21622 + struct au_opt_xino_itrunc *xino_itrunc;
21623 + struct au_opt_wbr_create *create;
21626 + substring_t args[MAX_OPT_ARGS];
21630 + a = kmalloc(sizeof(*a), GFP_NOFS);
21631 + if (unlikely(!a))
21634 + root = sb->s_root;
21638 + opt_tail = opt + opts->max_opt - 1;
21639 + opt->type = Opt_tail;
21640 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
21643 + token = match_token(opt_str, options, a->args);
21647 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
21649 + err = opt_add(opt, opt_str, opts->sb_flags,
21651 + if (unlikely(!err && ++opt > opt_tail)) {
21655 + opt->type = Opt_tail;
21660 + if (unlikely(match_int(&a->args[0], &n))) {
21661 + pr_err("bad integer in %s\n", opt_str);
21665 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
21668 + opt->type = token;
21671 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
21672 + /*dummy bindex*/1);
21674 + opt->type = token;
21676 + case Opt_prepend:
21677 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
21680 + opt->type = token;
21683 + err = au_opts_parse_del(&opt->del, a->args);
21685 + opt->type = token;
21687 +#if 0 /* reserved for future use */
21689 + del->pathname = "(indexed)";
21690 + if (unlikely(match_int(&args[0], &n))) {
21691 + pr_err("bad integer in %s\n", opt_str);
21694 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
21696 + opt->type = token;
21700 + err = au_opts_parse_mod(&opt->mod, a->args);
21702 + opt->type = token;
21704 +#ifdef IMOD /* reserved for future use */
21706 + u.mod->path = "(indexed)";
21707 + if (unlikely(match_int(&a->args[0], &n))) {
21708 + pr_err("bad integer in %s\n", opt_str);
21711 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
21713 + opt->type = token;
21717 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
21719 + opt->type = token;
21722 + case Opt_trunc_xino_path:
21723 + err = au_opts_parse_xino_itrunc_path
21724 + (sb, &opt->xino_itrunc, a->args);
21726 + opt->type = token;
21729 + case Opt_itrunc_xino:
21730 + u.xino_itrunc = &opt->xino_itrunc;
21731 + if (unlikely(match_int(&a->args[0], &n))) {
21732 + pr_err("bad integer in %s\n", opt_str);
21735 + u.xino_itrunc->bindex = n;
21736 + aufs_read_lock(root, AuLock_FLUSH);
21737 + if (n < 0 || au_sbend(sb) < n) {
21738 + pr_err("out of bounds, %d\n", n);
21739 + aufs_read_unlock(root, !AuLock_IR);
21742 + aufs_read_unlock(root, !AuLock_IR);
21744 + opt->type = token;
21748 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
21751 + opt->type = token;
21754 + case Opt_rdcache:
21755 + if (unlikely(match_int(&a->args[0], &n))) {
21756 + pr_err("bad integer in %s\n", opt_str);
21759 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
21760 + pr_err("rdcache must be smaller than %d\n",
21761 + AUFS_RDCACHE_MAX);
21764 + opt->rdcache = n;
21766 + opt->type = token;
21769 + if (unlikely(match_int(&a->args[0], &n)
21771 + || n > KMALLOC_MAX_SIZE)) {
21772 + pr_err("bad integer in %s\n", opt_str);
21775 + if (unlikely(n && n < NAME_MAX)) {
21776 + pr_err("rdblk must be larger than %d\n",
21782 + opt->type = token;
21785 + if (unlikely(match_int(&a->args[0], &n)
21787 + || n * sizeof(struct hlist_head)
21788 + > KMALLOC_MAX_SIZE)) {
21789 + pr_err("bad integer in %s\n", opt_str);
21794 + opt->type = token;
21797 + case Opt_trunc_xino:
21798 + case Opt_notrunc_xino:
21800 + case Opt_trunc_xib:
21801 + case Opt_notrunc_xib:
21805 + case Opt_noplink:
21806 + case Opt_list_plink:
21809 + case Opt_diropq_a:
21810 + case Opt_diropq_w:
21811 + case Opt_warn_perm:
21812 + case Opt_nowarn_perm:
21814 + case Opt_norefrof:
21815 + case Opt_verbose:
21816 + case Opt_noverbose:
21820 + case Opt_rdblk_def:
21821 + case Opt_rdhash_def:
21823 + opt->type = token;
21827 + opt->udba = udba_val(a->args[0].from);
21828 + if (opt->udba >= 0) {
21830 + opt->type = token;
21832 + pr_err("wrong value, %s\n", opt_str);
21835 + case Opt_wbr_create:
21836 + u.create = &opt->wbr_create;
21837 + u.create->wbr_create
21838 + = au_wbr_create_val(a->args[0].from, u.create);
21839 + if (u.create->wbr_create >= 0) {
21841 + opt->type = token;
21843 + pr_err("wrong value, %s\n", opt_str);
21845 + case Opt_wbr_copyup:
21846 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
21847 + if (opt->wbr_copyup >= 0) {
21849 + opt->type = token;
21851 + pr_err("wrong value, %s\n", opt_str);
21855 + pr_warn("ignored %s\n", opt_str);
21857 + case Opt_ignore_silent:
21862 + pr_err("unknown option %s\n", opt_str);
21866 + if (!err && !skipped) {
21867 + if (unlikely(++opt > opt_tail)) {
21870 + opt->type = Opt_tail;
21873 + opt->type = Opt_tail;
21879 + if (unlikely(err))
21880 + au_opts_free(opts);
21886 +static int au_opt_wbr_create(struct super_block *sb,
21887 + struct au_opt_wbr_create *create)
21890 + struct au_sbinfo *sbinfo;
21892 + SiMustWriteLock(sb);
21894 + err = 1; /* handled */
21895 + sbinfo = au_sbi(sb);
21896 + if (sbinfo->si_wbr_create_ops->fin) {
21897 + err = sbinfo->si_wbr_create_ops->fin(sb);
21902 + sbinfo->si_wbr_create = create->wbr_create;
21903 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
21904 + switch (create->wbr_create) {
21905 + case AuWbrCreate_MFSRRV:
21906 + case AuWbrCreate_MFSRR:
21907 + case AuWbrCreate_PMFSRR:
21908 + case AuWbrCreate_PMFSRRV:
21909 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
21911 + case AuWbrCreate_MFS:
21912 + case AuWbrCreate_MFSV:
21913 + case AuWbrCreate_PMFS:
21914 + case AuWbrCreate_PMFSV:
21915 + sbinfo->si_wbr_mfs.mfs_expire
21916 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
21920 + if (sbinfo->si_wbr_create_ops->init)
21921 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
21928 + * plus: processed without an error
21929 + * zero: unprocessed
21931 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
21932 + struct au_opts *opts)
21935 + struct au_sbinfo *sbinfo;
21937 + SiMustWriteLock(sb);
21939 + err = 1; /* handled */
21940 + sbinfo = au_sbi(sb);
21941 + switch (opt->type) {
21943 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
21944 + sbinfo->si_mntflags |= opt->udba;
21945 + opts->given_udba |= opt->udba;
21949 + au_opt_set(sbinfo->si_mntflags, PLINK);
21951 + case Opt_noplink:
21952 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
21953 + au_plink_put(sb, /*verbose*/1);
21954 + au_opt_clr(sbinfo->si_mntflags, PLINK);
21956 + case Opt_list_plink:
21957 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
21958 + au_plink_list(sb);
21962 + au_opt_set(sbinfo->si_mntflags, DIO);
21963 + au_fset_opts(opts->flags, REFRESH_DYAOP);
21966 + au_opt_clr(sbinfo->si_mntflags, DIO);
21967 + au_fset_opts(opts->flags, REFRESH_DYAOP);
21970 + case Opt_diropq_a:
21971 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
21973 + case Opt_diropq_w:
21974 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
21977 + case Opt_warn_perm:
21978 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
21980 + case Opt_nowarn_perm:
21981 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
21985 + au_opt_set(sbinfo->si_mntflags, REFROF);
21987 + case Opt_norefrof:
21988 + au_opt_clr(sbinfo->si_mntflags, REFROF);
21991 + case Opt_verbose:
21992 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
21994 + case Opt_noverbose:
21995 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
21999 + au_opt_set(sbinfo->si_mntflags, SUM);
22002 + au_opt_clr(sbinfo->si_mntflags, SUM);
22003 + au_opt_set(sbinfo->si_mntflags, SUM_W);
22005 + au_opt_clr(sbinfo->si_mntflags, SUM);
22006 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
22009 + case Opt_wbr_create:
22010 + err = au_opt_wbr_create(sb, &opt->wbr_create);
22012 + case Opt_wbr_copyup:
22013 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
22014 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
22018 + sbinfo->si_dirwh = opt->dirwh;
22021 + case Opt_rdcache:
22022 + sbinfo->si_rdcache
22023 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
22026 + sbinfo->si_rdblk = opt->rdblk;
22028 + case Opt_rdblk_def:
22029 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
22032 + sbinfo->si_rdhash = opt->rdhash;
22034 + case Opt_rdhash_def:
22035 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
22039 + au_opt_set(sbinfo->si_mntflags, SHWH);
22042 + au_opt_clr(sbinfo->si_mntflags, SHWH);
22045 + case Opt_trunc_xino:
22046 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
22048 + case Opt_notrunc_xino:
22049 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
22052 + case Opt_trunc_xino_path:
22053 + case Opt_itrunc_xino:
22054 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
22059 + case Opt_trunc_xib:
22060 + au_fset_opts(opts->flags, TRUNC_XIB);
22062 + case Opt_notrunc_xib:
22063 + au_fclr_opts(opts->flags, TRUNC_XIB);
22075 + * returns tri-state.
22076 + * plus: processed without an error
22077 + * zero: unprocessed
22080 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
22081 + struct au_opts *opts)
22083 + int err, do_refresh;
22086 + switch (opt->type) {
22088 + opt->add.bindex = au_sbend(sb) + 1;
22089 + if (opt->add.bindex < 0)
22090 + opt->add.bindex = 0;
22092 + case Opt_prepend:
22093 + opt->add.bindex = 0;
22096 + err = au_br_add(sb, &opt->add,
22097 + au_ftest_opts(opts->flags, REMOUNT));
22100 + au_fset_opts(opts->flags, REFRESH);
22106 + err = au_br_del(sb, &opt->del,
22107 + au_ftest_opts(opts->flags, REMOUNT));
22110 + au_fset_opts(opts->flags, TRUNC_XIB);
22111 + au_fset_opts(opts->flags, REFRESH);
22117 + err = au_br_mod(sb, &opt->mod,
22118 + au_ftest_opts(opts->flags, REMOUNT),
22123 + au_fset_opts(opts->flags, REFRESH);
22131 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
22132 + struct au_opt_xino **opt_xino,
22133 + struct au_opts *opts)
22136 + aufs_bindex_t bend, bindex;
22137 + struct dentry *root, *parent, *h_root;
22140 + switch (opt->type) {
22142 + err = au_xino_set(sb, &opt->xino,
22143 + !!au_ftest_opts(opts->flags, REMOUNT));
22144 + if (unlikely(err))
22147 + *opt_xino = &opt->xino;
22148 + au_xino_brid_set(sb, -1);
22150 + /* safe d_parent access */
22151 + parent = opt->xino.file->f_dentry->d_parent;
22152 + root = sb->s_root;
22153 + bend = au_sbend(sb);
22154 + for (bindex = 0; bindex <= bend; bindex++) {
22155 + h_root = au_h_dptr(root, bindex);
22156 + if (h_root == parent) {
22157 + au_xino_brid_set(sb, au_sbr_id(sb, bindex));
22165 + au_xino_brid_set(sb, -1);
22166 + *opt_xino = (void *)-1;
22173 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
22174 + unsigned int pending)
22177 + aufs_bindex_t bindex, bend;
22178 + unsigned char do_plink, skip, do_free;
22179 + struct au_branch *br;
22180 + struct au_wbr *wbr;
22181 + struct dentry *root;
22182 + struct inode *dir, *h_dir;
22183 + struct au_sbinfo *sbinfo;
22184 + struct au_hinode *hdir;
22186 + SiMustAnyLock(sb);
22188 + sbinfo = au_sbi(sb);
22189 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
22191 + if (!(sb_flags & MS_RDONLY)) {
22192 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
22193 + pr_warn("first branch should be rw\n");
22194 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
22195 + pr_warn("shwh should be used with ro\n");
22198 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
22199 + && !au_opt_test(sbinfo->si_mntflags, XINO))
22200 + pr_warn("udba=*notify requires xino\n");
22203 + root = sb->s_root;
22204 + dir = root->d_inode;
22205 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
22206 + bend = au_sbend(sb);
22207 + for (bindex = 0; !err && bindex <= bend; bindex++) {
22209 + h_dir = au_h_iptr(dir, bindex);
22210 + br = au_sbr(sb, bindex);
22213 + wbr = br->br_wbr;
22215 + wbr_wh_read_lock(wbr);
22217 + if (!au_br_writable(br->br_perm)) {
22220 + || (!wbr->wbr_whbase
22221 + && !wbr->wbr_plink
22222 + && !wbr->wbr_orph));
22223 + } else if (!au_br_wh_linkable(br->br_perm)) {
22224 + /* skip = (!br->br_whbase && !br->br_orph); */
22225 + skip = (!wbr || !wbr->wbr_whbase);
22226 + if (skip && wbr) {
22228 + skip = !!wbr->wbr_plink;
22230 + skip = !wbr->wbr_plink;
22233 + /* skip = (br->br_whbase && br->br_ohph); */
22234 + skip = (wbr && wbr->wbr_whbase);
22237 + skip = !!wbr->wbr_plink;
22239 + skip = !wbr->wbr_plink;
22243 + wbr_wh_read_unlock(wbr);
22248 + hdir = au_hi(dir, bindex);
22249 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
22251 + wbr_wh_write_lock(wbr);
22252 + err = au_wh_init(br, sb);
22254 + wbr_wh_write_unlock(wbr);
22255 + au_hn_imtx_unlock(hdir);
22257 + if (!err && do_free) {
22259 + br->br_wbr = NULL;
22266 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
22269 + unsigned int tmp;
22270 + aufs_bindex_t bindex, bend;
22271 + struct au_opt *opt;
22272 + struct au_opt_xino *opt_xino, xino;
22273 + struct au_sbinfo *sbinfo;
22274 + struct au_branch *br;
22276 + SiMustWriteLock(sb);
22281 + while (err >= 0 && opt->type != Opt_tail)
22282 + err = au_opt_simple(sb, opt++, opts);
22285 + else if (unlikely(err < 0))
22288 + /* disable xino and udba temporary */
22289 + sbinfo = au_sbi(sb);
22290 + tmp = sbinfo->si_mntflags;
22291 + au_opt_clr(sbinfo->si_mntflags, XINO);
22292 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
22295 + while (err >= 0 && opt->type != Opt_tail)
22296 + err = au_opt_br(sb, opt++, opts);
22299 + else if (unlikely(err < 0))
22302 + bend = au_sbend(sb);
22303 + if (unlikely(bend < 0)) {
22305 + pr_err("no branches\n");
22309 + if (au_opt_test(tmp, XINO))
22310 + au_opt_set(sbinfo->si_mntflags, XINO);
22312 + while (!err && opt->type != Opt_tail)
22313 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
22314 + if (unlikely(err))
22317 + err = au_opts_verify(sb, sb->s_flags, tmp);
22318 + if (unlikely(err))
22321 + /* restore xino */
22322 + if (au_opt_test(tmp, XINO) && !opt_xino) {
22323 + xino.file = au_xino_def(sb);
22324 + err = PTR_ERR(xino.file);
22325 + if (IS_ERR(xino.file))
22328 + err = au_xino_set(sb, &xino, /*remount*/0);
22330 + if (unlikely(err))
22334 + /* restore udba */
22335 + tmp &= AuOptMask_UDBA;
22336 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
22337 + sbinfo->si_mntflags |= tmp;
22338 + bend = au_sbend(sb);
22339 + for (bindex = 0; bindex <= bend; bindex++) {
22340 + br = au_sbr(sb, bindex);
22341 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
22342 + if (unlikely(err))
22343 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
22345 + /* go on even if err */
22347 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
22348 + struct inode *dir = sb->s_root->d_inode;
22349 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
22356 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
22359 + struct inode *dir;
22360 + struct au_opt_xino *opt_xino;
22361 + struct au_opt *opt;
22362 + struct au_sbinfo *sbinfo;
22364 + SiMustWriteLock(sb);
22366 + dir = sb->s_root->d_inode;
22367 + sbinfo = au_sbi(sb);
22371 + while (err >= 0 && opt->type != Opt_tail) {
22372 + err = au_opt_simple(sb, opt, opts);
22374 + err = au_opt_br(sb, opt, opts);
22376 + err = au_opt_xino(sb, opt, &opt_xino, opts);
22382 + /* go on even err */
22384 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
22385 + if (unlikely(rerr && !err))
22388 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
22389 + rerr = au_xib_trunc(sb);
22390 + if (unlikely(rerr && !err))
22394 + /* will be handled by the caller */
22395 + if (!au_ftest_opts(opts->flags, REFRESH)
22396 + && (opts->given_udba || au_opt_test(sbinfo->si_mntflags, XINO)))
22397 + au_fset_opts(opts->flags, REFRESH);
22399 + AuDbg("status 0x%x\n", opts->flags);
22403 +/* ---------------------------------------------------------------------- */
22405 +unsigned int au_opt_udba(struct super_block *sb)
22407 + return au_mntflags(sb) & AuOptMask_UDBA;
22409 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
22410 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
22411 +++ linux/fs/aufs/opts.h 2013-10-26 16:51:32.276373845 +0200
22414 + * Copyright (C) 2005-2013 Junjiro R. Okajima
22416 + * This program, aufs is free software; you can redistribute it and/or modify
22417 + * it under the terms of the GNU General Public License as published by
22418 + * the Free Software Foundation; either version 2 of the License, or
22419 + * (at your option) any later version.
22421 + * This program is distributed in the hope that it will be useful,
22422 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22423 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22424 + * GNU General Public License for more details.
22426 + * You should have received a copy of the GNU General Public License
22427 + * along with this program; if not, write to the Free Software
22428 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22432 + * mount options/flags
22435 +#ifndef __AUFS_OPTS_H__
22436 +#define __AUFS_OPTS_H__
22440 +#include <linux/path.h>
22443 +struct super_block;
22445 +/* ---------------------------------------------------------------------- */
22448 +#define AuOpt_XINO 1 /* external inode number bitmap
22449 + and translation table */
22450 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
22451 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
22452 +#define AuOpt_UDBA_REVAL (1 << 3)
22453 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
22454 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
22455 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
22456 +#define AuOpt_DIRPERM1 (1 << 7) /* unimplemented */
22457 +#define AuOpt_REFROF (1 << 8) /* unimplemented */
22458 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
22459 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
22460 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
22461 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
22462 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
22463 +#define AuOpt_DIO (1 << 14) /* direct io */
22465 +#ifndef CONFIG_AUFS_HNOTIFY
22466 +#undef AuOpt_UDBA_HNOTIFY
22467 +#define AuOpt_UDBA_HNOTIFY 0
22469 +#ifndef CONFIG_AUFS_SHWH
22471 +#define AuOpt_SHWH 0
22474 +#define AuOpt_Def (AuOpt_XINO \
22475 + | AuOpt_UDBA_REVAL \
22477 + /* | AuOpt_DIRPERM1 */ \
22478 + | AuOpt_WARN_PERM)
22479 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
22480 + | AuOpt_UDBA_REVAL \
22481 + | AuOpt_UDBA_HNOTIFY)
22483 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
22484 +#define au_opt_set(flags, name) do { \
22485 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
22486 + ((flags) |= AuOpt_##name); \
22488 +#define au_opt_set_udba(flags, name) do { \
22489 + (flags) &= ~AuOptMask_UDBA; \
22490 + ((flags) |= AuOpt_##name); \
22492 +#define au_opt_clr(flags, name) do { \
22493 + ((flags) &= ~AuOpt_##name); \
22496 +static inline unsigned int au_opts_plink(unsigned int mntflags)
22498 +#ifdef CONFIG_PROC_FS
22501 + return mntflags & ~AuOpt_PLINK;
22505 +/* ---------------------------------------------------------------------- */
22507 +/* policies to select one among multiple writable branches */
22509 + AuWbrCreate_TDP, /* top down parent */
22510 + AuWbrCreate_RR, /* round robin */
22511 + AuWbrCreate_MFS, /* most free space */
22512 + AuWbrCreate_MFSV, /* mfs with seconds */
22513 + AuWbrCreate_MFSRR, /* mfs then rr */
22514 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
22515 + AuWbrCreate_PMFS, /* parent and mfs */
22516 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
22517 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
22518 + AuWbrCreate_PMFSRRV, /* plus seconds */
22520 + AuWbrCreate_Def = AuWbrCreate_TDP
22524 + AuWbrCopyup_TDP, /* top down parent */
22525 + AuWbrCopyup_BUP, /* bottom up parent */
22526 + AuWbrCopyup_BU, /* bottom up */
22528 + AuWbrCopyup_Def = AuWbrCopyup_TDP
22531 +/* ---------------------------------------------------------------------- */
22533 +struct au_opt_add {
22534 + aufs_bindex_t bindex;
22537 + struct path path;
22540 +struct au_opt_del {
22542 + struct path h_path;
22545 +struct au_opt_mod {
22548 + struct dentry *h_root;
22551 +struct au_opt_xino {
22553 + struct file *file;
22556 +struct au_opt_xino_itrunc {
22557 + aufs_bindex_t bindex;
22560 +struct au_opt_wbr_create {
22563 + unsigned long long mfsrr_watermark;
22569 + struct au_opt_xino xino;
22570 + struct au_opt_xino_itrunc xino_itrunc;
22571 + struct au_opt_add add;
22572 + struct au_opt_del del;
22573 + struct au_opt_mod mod;
22576 + unsigned int rdblk;
22577 + unsigned int rdhash;
22579 + struct au_opt_wbr_create wbr_create;
22585 +#define AuOpts_REMOUNT 1
22586 +#define AuOpts_REFRESH (1 << 1)
22587 +#define AuOpts_TRUNC_XIB (1 << 2)
22588 +#define AuOpts_REFRESH_DYAOP (1 << 3)
22589 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
22590 +#define au_fset_opts(flags, name) \
22591 + do { (flags) |= AuOpts_##name; } while (0)
22592 +#define au_fclr_opts(flags, name) \
22593 + do { (flags) &= ~AuOpts_##name; } while (0)
22596 + struct au_opt *opt;
22599 + unsigned int given_udba;
22600 + unsigned int flags;
22601 + unsigned long sb_flags;
22604 +/* ---------------------------------------------------------------------- */
22606 +char *au_optstr_br_perm(int brperm);
22607 +const char *au_optstr_udba(int udba);
22608 +const char *au_optstr_wbr_copyup(int wbr_copyup);
22609 +const char *au_optstr_wbr_create(int wbr_create);
22611 +void au_opts_free(struct au_opts *opts);
22612 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
22613 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
22614 + unsigned int pending);
22615 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
22616 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
22618 +unsigned int au_opt_udba(struct super_block *sb);
22620 +/* ---------------------------------------------------------------------- */
22622 +#endif /* __KERNEL__ */
22623 +#endif /* __AUFS_OPTS_H__ */
22624 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
22625 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
22626 +++ linux/fs/aufs/plink.c 2013-07-06 13:20:47.753531903 +0200
22629 + * Copyright (C) 2005-2013 Junjiro R. Okajima
22631 + * This program, aufs is free software; you can redistribute it and/or modify
22632 + * it under the terms of the GNU General Public License as published by
22633 + * the Free Software Foundation; either version 2 of the License, or
22634 + * (at your option) any later version.
22636 + * This program is distributed in the hope that it will be useful,
22637 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22638 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22639 + * GNU General Public License for more details.
22641 + * You should have received a copy of the GNU General Public License
22642 + * along with this program; if not, write to the Free Software
22643 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22653 + * the pseudo-link maintenance mode.
22654 + * during a user process maintains the pseudo-links,
22655 + * prohibit adding a new plink and branch manipulation.
22659 + * For entry functions which will handle plink, and i_mutex is already held
22661 + * They cannot wait and should return an error at once.
22662 + * Callers has to check the error.
22664 + * For entry functions which will handle plink, but i_mutex is not held
22666 + * They can wait the plink maintenance mode to finish.
22668 + * They behave like F_SETLK and F_SETLKW.
22669 + * If the caller never handle plink, then both flags are unnecessary.
22672 +int au_plink_maint(struct super_block *sb, int flags)
22676 + struct au_sbinfo *sbi;
22678 + SiMustAnyLock(sb);
22681 + if (!au_opt_test(au_mntflags(sb), PLINK))
22684 + sbi = au_sbi(sb);
22685 + pid = sbi->si_plink_maint_pid;
22686 + if (!pid || pid == current->pid)
22689 + /* todo: it highly depends upon /sbin/mount.aufs */
22691 + ppid = task_pid_vnr(rcu_dereference(current->real_parent));
22692 + rcu_read_unlock();
22696 + if (au_ftest_lock(flags, NOPLMW)) {
22697 + /* if there is no i_mutex lock in VFS, we don't need to wait */
22698 + /* AuDebugOn(!lockdep_depth(current)); */
22699 + while (sbi->si_plink_maint_pid) {
22700 + si_read_unlock(sb);
22701 + /* gave up wake_up_bit() */
22702 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
22704 + if (au_ftest_lock(flags, FLUSH))
22705 + au_nwt_flush(&sbi->si_nowait);
22706 + si_noflush_read_lock(sb);
22708 + } else if (au_ftest_lock(flags, NOPLM)) {
22709 + AuDbg("ppid %d, pid %d\n", ppid, pid);
22717 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
22719 + spin_lock(&sbinfo->si_plink_maint_lock);
22720 + sbinfo->si_plink_maint_pid = 0;
22721 + spin_unlock(&sbinfo->si_plink_maint_lock);
22722 + wake_up_all(&sbinfo->si_plink_wq);
22725 +int au_plink_maint_enter(struct super_block *sb)
22728 + struct au_sbinfo *sbinfo;
22731 + sbinfo = au_sbi(sb);
22732 + /* make sure i am the only one in this fs */
22733 + si_write_lock(sb, AuLock_FLUSH);
22734 + if (au_opt_test(au_mntflags(sb), PLINK)) {
22735 + spin_lock(&sbinfo->si_plink_maint_lock);
22736 + if (!sbinfo->si_plink_maint_pid)
22737 + sbinfo->si_plink_maint_pid = current->pid;
22740 + spin_unlock(&sbinfo->si_plink_maint_lock);
22742 + si_write_unlock(sb);
22747 +/* ---------------------------------------------------------------------- */
22749 +#ifdef CONFIG_AUFS_DEBUG
22750 +void au_plink_list(struct super_block *sb)
22753 + struct au_sbinfo *sbinfo;
22754 + struct hlist_head *plink_hlist;
22755 + struct pseudo_link *plink;
22757 + SiMustAnyLock(sb);
22759 + sbinfo = au_sbi(sb);
22760 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
22761 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
22763 + for (i = 0; i < AuPlink_NHASH; i++) {
22764 + plink_hlist = &sbinfo->si_plink[i].head;
22766 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
22767 + AuDbg("%lu\n", plink->inode->i_ino);
22768 + rcu_read_unlock();
22773 +/* is the inode pseudo-linked? */
22774 +int au_plink_test(struct inode *inode)
22777 + struct au_sbinfo *sbinfo;
22778 + struct hlist_head *plink_hlist;
22779 + struct pseudo_link *plink;
22781 + sbinfo = au_sbi(inode->i_sb);
22782 + AuRwMustAnyLock(&sbinfo->si_rwsem);
22783 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
22784 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
22787 + i = au_plink_hash(inode->i_ino);
22788 + plink_hlist = &sbinfo->si_plink[i].head;
22790 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
22791 + if (plink->inode == inode) {
22795 + rcu_read_unlock();
22799 +/* ---------------------------------------------------------------------- */
22802 + * generate a name for plink.
22803 + * the file will be stored under AUFS_WH_PLINKDIR.
22805 +/* 20 is max digits length of ulong 64 */
22806 +#define PLINK_NAME_LEN ((20 + 1) * 2)
22808 +static int plink_name(char *name, int len, struct inode *inode,
22809 + aufs_bindex_t bindex)
22812 + struct inode *h_inode;
22814 + h_inode = au_h_iptr(inode, bindex);
22815 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
22819 +struct au_do_plink_lkup_args {
22820 + struct dentry **errp;
22821 + struct qstr *tgtname;
22822 + struct dentry *h_parent;
22823 + struct au_branch *br;
22826 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
22827 + struct dentry *h_parent,
22828 + struct au_branch *br)
22830 + struct dentry *h_dentry;
22831 + struct mutex *h_mtx;
22833 + h_mtx = &h_parent->d_inode->i_mutex;
22834 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
22835 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
22836 + mutex_unlock(h_mtx);
22840 +static void au_call_do_plink_lkup(void *args)
22842 + struct au_do_plink_lkup_args *a = args;
22843 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
22846 +/* lookup the plink-ed @inode under the branch at @bindex */
22847 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
22849 + struct dentry *h_dentry, *h_parent;
22850 + struct au_branch *br;
22851 + struct inode *h_dir;
22853 + char a[PLINK_NAME_LEN];
22854 + struct qstr tgtname = QSTR_INIT(a, 0);
22856 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
22858 + br = au_sbr(inode->i_sb, bindex);
22859 + h_parent = br->br_wbr->wbr_plink;
22860 + h_dir = h_parent->d_inode;
22861 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
22863 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
22864 + struct au_do_plink_lkup_args args = {
22865 + .errp = &h_dentry,
22866 + .tgtname = &tgtname,
22867 + .h_parent = h_parent,
22871 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
22872 + if (unlikely(wkq_err))
22873 + h_dentry = ERR_PTR(wkq_err);
22875 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
22880 +/* create a pseudo-link */
22881 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
22882 + struct dentry *h_dentry, struct au_branch *br)
22885 + struct path h_path = {
22886 + .mnt = au_br_mnt(br)
22888 + struct inode *h_dir;
22890 + h_dir = h_parent->d_inode;
22891 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_CHILD2);
22893 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
22894 + err = PTR_ERR(h_path.dentry);
22895 + if (IS_ERR(h_path.dentry))
22899 + /* wh.plink dir is not monitored */
22900 + /* todo: is it really safe? */
22901 + if (h_path.dentry->d_inode
22902 + && h_path.dentry->d_inode != h_dentry->d_inode) {
22903 + err = vfsub_unlink(h_dir, &h_path, /*force*/0);
22904 + dput(h_path.dentry);
22905 + h_path.dentry = NULL;
22909 + if (!err && !h_path.dentry->d_inode)
22910 + err = vfsub_link(h_dentry, h_dir, &h_path);
22911 + dput(h_path.dentry);
22914 + mutex_unlock(&h_dir->i_mutex);
22918 +struct do_whplink_args {
22920 + struct qstr *tgt;
22921 + struct dentry *h_parent;
22922 + struct dentry *h_dentry;
22923 + struct au_branch *br;
22926 +static void call_do_whplink(void *args)
22928 + struct do_whplink_args *a = args;
22929 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
22932 +static int whplink(struct dentry *h_dentry, struct inode *inode,
22933 + aufs_bindex_t bindex, struct au_branch *br)
22935 + int err, wkq_err;
22936 + struct au_wbr *wbr;
22937 + struct dentry *h_parent;
22938 + struct inode *h_dir;
22939 + char a[PLINK_NAME_LEN];
22940 + struct qstr tgtname = QSTR_INIT(a, 0);
22942 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
22943 + h_parent = wbr->wbr_plink;
22944 + h_dir = h_parent->d_inode;
22945 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
22947 + /* always superio. */
22948 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
22949 + struct do_whplink_args args = {
22952 + .h_parent = h_parent,
22953 + .h_dentry = h_dentry,
22956 + wkq_err = au_wkq_wait(call_do_whplink, &args);
22957 + if (unlikely(wkq_err))
22960 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
22965 +/* free a single plink */
22966 +static void do_put_plink(struct pseudo_link *plink, int do_del)
22969 + hlist_del(&plink->hlist);
22970 + iput(plink->inode);
22974 +static void do_put_plink_rcu(struct rcu_head *rcu)
22976 + struct pseudo_link *plink;
22978 + plink = container_of(rcu, struct pseudo_link, rcu);
22979 + iput(plink->inode);
22984 + * create a new pseudo-link for @h_dentry on @bindex.
22985 + * the linked inode is held in aufs @inode.
22987 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
22988 + struct dentry *h_dentry)
22990 + struct super_block *sb;
22991 + struct au_sbinfo *sbinfo;
22992 + struct hlist_head *plink_hlist;
22993 + struct pseudo_link *plink, *tmp;
22994 + struct au_sphlhead *sphl;
22995 + int found, err, cnt, i;
22997 + sb = inode->i_sb;
22998 + sbinfo = au_sbi(sb);
22999 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
23000 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
23002 + found = au_plink_test(inode);
23006 + i = au_plink_hash(inode->i_ino);
23007 + sphl = sbinfo->si_plink + i;
23008 + plink_hlist = &sphl->head;
23009 + tmp = kmalloc(sizeof(*plink), GFP_NOFS);
23011 + tmp->inode = au_igrab(inode);
23017 + spin_lock(&sphl->spin);
23018 + hlist_for_each_entry(plink, plink_hlist, hlist) {
23019 + if (plink->inode == inode) {
23025 + hlist_add_head_rcu(&tmp->hlist, plink_hlist);
23026 + spin_unlock(&sphl->spin);
23028 + cnt = au_sphl_count(sphl);
23029 +#define msg "unexpectedly unblanced or too many pseudo-links"
23030 + if (cnt > AUFS_PLINK_WARN)
23031 + AuWarn1(msg ", %d\n", cnt);
23033 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
23035 + do_put_plink(tmp, 0);
23040 + if (unlikely(err)) {
23041 + pr_warn("err %d, damaged pseudo link.\n", err);
23043 + au_sphl_del_rcu(&tmp->hlist, sphl);
23044 + call_rcu(&tmp->rcu, do_put_plink_rcu);
23049 +/* free all plinks */
23050 +void au_plink_put(struct super_block *sb, int verbose)
23053 + struct au_sbinfo *sbinfo;
23054 + struct hlist_head *plink_hlist;
23055 + struct hlist_node *tmp;
23056 + struct pseudo_link *plink;
23058 + SiMustWriteLock(sb);
23060 + sbinfo = au_sbi(sb);
23061 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
23062 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
23064 + /* no spin_lock since sbinfo is write-locked */
23066 + for (i = 0; i < AuPlink_NHASH; i++) {
23067 + plink_hlist = &sbinfo->si_plink[i].head;
23068 + if (!warned && verbose && !hlist_empty(plink_hlist)) {
23069 + pr_warn("pseudo-link is not flushed");
23072 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist)
23073 + do_put_plink(plink, 0);
23074 + INIT_HLIST_HEAD(plink_hlist);
23078 +void au_plink_clean(struct super_block *sb, int verbose)
23080 + struct dentry *root;
23082 + root = sb->s_root;
23083 + aufs_write_lock(root);
23084 + if (au_opt_test(au_mntflags(sb), PLINK))
23085 + au_plink_put(sb, verbose);
23086 + aufs_write_unlock(root);
23089 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
23092 + aufs_bindex_t bstart, bend, bindex;
23095 + bstart = au_ibstart(inode);
23096 + bend = au_ibend(inode);
23097 + if (bstart >= 0) {
23098 + for (bindex = bstart; bindex <= bend; bindex++) {
23099 + if (!au_h_iptr(inode, bindex)
23100 + || au_ii_br_id(inode, bindex) != br_id)
23102 + au_set_h_iptr(inode, bindex, NULL, 0);
23107 + for (bindex = bstart; bindex <= bend; bindex++)
23108 + if (au_h_iptr(inode, bindex)) {
23118 +/* free the plinks on a branch specified by @br_id */
23119 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
23121 + struct au_sbinfo *sbinfo;
23122 + struct hlist_head *plink_hlist;
23123 + struct hlist_node *tmp;
23124 + struct pseudo_link *plink;
23125 + struct inode *inode;
23128 + SiMustWriteLock(sb);
23130 + sbinfo = au_sbi(sb);
23131 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
23132 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
23134 + /* no spin_lock since sbinfo is write-locked */
23135 + for (i = 0; i < AuPlink_NHASH; i++) {
23136 + plink_hlist = &sbinfo->si_plink[i].head;
23137 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist) {
23138 + inode = au_igrab(plink->inode);
23139 + ii_write_lock_child(inode);
23140 + do_put = au_plink_do_half_refresh(inode, br_id);
23142 + do_put_plink(plink, 1);
23143 + ii_write_unlock(inode);
23148 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
23149 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
23150 +++ linux/fs/aufs/poll.c 2013-07-06 13:20:47.753531903 +0200
23153 + * Copyright (C) 2005-2013 Junjiro R. Okajima
23155 + * This program, aufs is free software; you can redistribute it and/or modify
23156 + * it under the terms of the GNU General Public License as published by
23157 + * the Free Software Foundation; either version 2 of the License, or
23158 + * (at your option) any later version.
23160 + * This program is distributed in the hope that it will be useful,
23161 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23162 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23163 + * GNU General Public License for more details.
23165 + * You should have received a copy of the GNU General Public License
23166 + * along with this program; if not, write to the Free Software
23167 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23172 + * There is only one filesystem which implements ->poll operation, currently.
23177 +unsigned int aufs_poll(struct file *file, poll_table *wait)
23179 + unsigned int mask;
23181 + struct file *h_file;
23182 + struct dentry *dentry;
23183 + struct super_block *sb;
23185 + /* We should pretend an error happened. */
23186 + mask = POLLERR /* | POLLIN | POLLOUT */;
23187 + dentry = file->f_dentry;
23188 + sb = dentry->d_sb;
23189 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
23190 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
23191 + if (unlikely(err))
23194 + /* it is not an error if h_file has no operation */
23195 + mask = DEFAULT_POLLMASK;
23196 + h_file = au_hf_top(file);
23197 + if (h_file->f_op && h_file->f_op->poll)
23198 + mask = h_file->f_op->poll(h_file, wait);
23200 + di_read_unlock(dentry, AuLock_IR);
23201 + fi_read_unlock(file);
23204 + si_read_unlock(sb);
23205 + AuTraceErr((int)mask);
23208 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
23209 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
23210 +++ linux/fs/aufs/procfs.c 2013-07-06 13:20:47.753531903 +0200
23213 + * Copyright (C) 2010-2013 Junjiro R. Okajima
23215 + * This program, aufs is free software; you can redistribute it and/or modify
23216 + * it under the terms of the GNU General Public License as published by
23217 + * the Free Software Foundation; either version 2 of the License, or
23218 + * (at your option) any later version.
23220 + * This program is distributed in the hope that it will be useful,
23221 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23222 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23223 + * GNU General Public License for more details.
23225 + * You should have received a copy of the GNU General Public License
23226 + * along with this program; if not, write to the Free Software
23227 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23231 + * procfs interfaces
23234 +#include <linux/proc_fs.h>
23237 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
23239 + struct au_sbinfo *sbinfo;
23241 + sbinfo = file->private_data;
23243 + au_plink_maint_leave(sbinfo);
23244 + kobject_put(&sbinfo->si_kobj);
23250 +static void au_procfs_plm_write_clean(struct file *file)
23252 + struct au_sbinfo *sbinfo;
23254 + sbinfo = file->private_data;
23256 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
23259 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
23262 + struct super_block *sb;
23263 + struct au_sbinfo *sbinfo;
23266 + if (unlikely(file->private_data))
23270 + /* don't use au_sbilist_lock() here */
23271 + spin_lock(&au_sbilist.spin);
23272 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
23273 + if (id == sysaufs_si_id(sbinfo)) {
23274 + kobject_get(&sbinfo->si_kobj);
23275 + sb = sbinfo->si_sb;
23278 + spin_unlock(&au_sbilist.spin);
23281 + if (unlikely(!sb))
23284 + err = au_plink_maint_enter(sb);
23286 + /* keep kobject_get() */
23287 + file->private_data = sbinfo;
23289 + kobject_put(&sbinfo->si_kobj);
23295 + * Accept a valid "si=xxxx" only.
23296 + * Once it is accepted successfully, accept "clean" too.
23298 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
23299 + size_t count, loff_t *ppos)
23302 + unsigned long id;
23303 + /* last newline is allowed */
23304 + char buf[3 + sizeof(unsigned long) * 2 + 1];
23307 + if (unlikely(!capable(CAP_SYS_ADMIN)))
23311 + if (unlikely(count > sizeof(buf)))
23314 + err = copy_from_user(buf, ubuf, count);
23315 + if (unlikely(err)) {
23322 + if (!strcmp("clean", buf)) {
23323 + au_procfs_plm_write_clean(file);
23324 + goto out_success;
23325 + } else if (unlikely(strncmp("si=", buf, 3)))
23328 + err = kstrtoul(buf + 3, 16, &id);
23329 + if (unlikely(err))
23332 + err = au_procfs_plm_write_si(file, id);
23333 + if (unlikely(err))
23337 + err = count; /* success */
23342 +static const struct file_operations au_procfs_plm_fop = {
23343 + .write = au_procfs_plm_write,
23344 + .release = au_procfs_plm_release,
23345 + .owner = THIS_MODULE
23348 +/* ---------------------------------------------------------------------- */
23350 +static struct proc_dir_entry *au_procfs_dir;
23352 +void au_procfs_fin(void)
23354 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
23355 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
23358 +int __init au_procfs_init(void)
23361 + struct proc_dir_entry *entry;
23364 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
23365 + if (unlikely(!au_procfs_dir))
23368 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR,
23369 + au_procfs_dir, &au_procfs_plm_fop);
23370 + if (unlikely(!entry))
23374 + goto out; /* success */
23378 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
23382 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
23383 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
23384 +++ linux/fs/aufs/rdu.c 2013-10-26 16:51:29.586298347 +0200
23387 + * Copyright (C) 2005-2013 Junjiro R. Okajima
23389 + * This program, aufs is free software; you can redistribute it and/or modify
23390 + * it under the terms of the GNU General Public License as published by
23391 + * the Free Software Foundation; either version 2 of the License, or
23392 + * (at your option) any later version.
23394 + * This program is distributed in the hope that it will be useful,
23395 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23396 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23397 + * GNU General Public License for more details.
23399 + * You should have received a copy of the GNU General Public License
23400 + * along with this program; if not, write to the Free Software
23401 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23405 + * readdir in userspace.
23408 +#include <linux/compat.h>
23409 +#include <linux/fs_stack.h>
23410 +#include <linux/security.h>
23413 +/* bits for struct aufs_rdu.flags */
23414 +#define AuRdu_CALLED 1
23415 +#define AuRdu_CONT (1 << 1)
23416 +#define AuRdu_FULL (1 << 2)
23417 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
23418 +#define au_fset_rdu(flags, name) \
23419 + do { (flags) |= AuRdu_##name; } while (0)
23420 +#define au_fclr_rdu(flags, name) \
23421 + do { (flags) &= ~AuRdu_##name; } while (0)
23423 +struct au_rdu_arg {
23424 + struct dir_context ctx;
23425 + struct aufs_rdu *rdu;
23426 + union au_rdu_ent_ul ent;
23427 + unsigned long end;
23429 + struct super_block *sb;
23433 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
23434 + loff_t offset, u64 h_ino, unsigned int d_type)
23437 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
23438 + struct aufs_rdu *rdu = arg->rdu;
23439 + struct au_rdu_ent ent;
23443 + au_fset_rdu(rdu->cookie.flags, CALLED);
23444 + len = au_rdu_len(nlen);
23445 + if (arg->ent.ul + len < arg->end) {
23447 + ent.bindex = rdu->cookie.bindex;
23448 + ent.type = d_type;
23450 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
23451 + ent.type = DT_UNKNOWN;
23453 + /* unnecessary to support mmap_sem since this is a dir */
23455 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
23457 + if (copy_to_user(arg->ent.e->name, name, nlen))
23459 + /* the terminating NULL */
23460 + if (__put_user(0, arg->ent.e->name + nlen))
23463 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
23464 + arg->ent.ul += len;
23468 + au_fset_rdu(rdu->cookie.flags, FULL);
23470 + rdu->tail = arg->ent;
23474 + /* AuTraceErr(err); */
23478 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
23482 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
23484 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
23485 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
23487 + if (unlikely(offset != cookie->h_pos))
23493 + au_fclr_rdu(cookie->flags, CALLED);
23495 + err = vfsub_iterate_dir(h_file, &arg->ctx);
23499 + && au_ftest_rdu(cookie->flags, CALLED)
23500 + && !au_ftest_rdu(cookie->flags, FULL));
23501 + cookie->h_pos = h_file->f_pos;
23508 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
23511 + aufs_bindex_t bend;
23512 + struct au_rdu_arg arg = {
23514 + .actor = au_diractor(au_rdu_fill)
23517 + struct dentry *dentry;
23518 + struct inode *inode;
23519 + struct file *h_file;
23520 + struct au_rdu_cookie *cookie = &rdu->cookie;
23522 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
23523 + if (unlikely(err)) {
23529 + rdu->tail = rdu->ent;
23532 + arg.ent = rdu->ent;
23533 + arg.end = arg.ent.ul;
23534 + arg.end += rdu->sz;
23537 + if (unlikely(!file->f_op || !file->f_op->iterate))
23540 + err = security_file_permission(file, MAY_READ);
23542 + if (unlikely(err))
23545 + dentry = file->f_dentry;
23546 + inode = dentry->d_inode;
23548 + mutex_lock(&inode->i_mutex);
23550 + err = mutex_lock_killable(&inode->i_mutex);
23552 + if (unlikely(err))
23556 + arg.sb = inode->i_sb;
23557 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
23558 + if (unlikely(err))
23560 + err = au_alive_dir(dentry);
23561 + if (unlikely(err))
23563 + /* todo: reval? */
23564 + fi_read_lock(file);
23567 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
23568 + && cookie->generation != au_figen(file)))
23573 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
23575 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
23577 + bend = au_fbstart(file);
23578 + if (cookie->bindex < bend)
23579 + cookie->bindex = bend;
23580 + bend = au_fbend_dir(file);
23581 + /* AuDbg("b%d, b%d\n", cookie->bindex, bend); */
23582 + for (; !err && cookie->bindex <= bend;
23583 + cookie->bindex++, cookie->h_pos = 0) {
23584 + h_file = au_hf_dir(file, cookie->bindex);
23588 + au_fclr_rdu(cookie->flags, FULL);
23589 + err = au_rdu_do(h_file, &arg);
23591 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
23594 + AuDbg("rent %llu\n", rdu->rent);
23596 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
23597 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
23598 + au_fset_rdu(cookie->flags, CONT);
23599 + cookie->generation = au_figen(file);
23602 + ii_read_lock_child(inode);
23603 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibstart(inode)));
23604 + ii_read_unlock(inode);
23607 + fi_read_unlock(file);
23609 + si_read_unlock(arg.sb);
23611 + mutex_unlock(&inode->i_mutex);
23617 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
23621 + unsigned long long nent;
23622 + union au_rdu_ent_ul *u;
23623 + struct au_rdu_ent ent;
23624 + struct super_block *sb;
23627 + nent = rdu->nent;
23629 + sb = file->f_dentry->d_sb;
23630 + si_read_lock(sb, AuLock_FLUSH);
23631 + while (nent-- > 0) {
23632 + /* unnecessary to support mmap_sem since this is a dir */
23633 + err = copy_from_user(&ent, u->e, sizeof(ent));
23635 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
23636 + if (unlikely(err)) {
23642 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
23644 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
23646 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
23648 + if (unlikely(err)) {
23653 + err = __put_user(ino, &u->e->ino);
23654 + if (unlikely(err)) {
23659 + u->ul += au_rdu_len(ent.nlen);
23661 + si_read_unlock(sb);
23666 +/* ---------------------------------------------------------------------- */
23668 +static int au_rdu_verify(struct aufs_rdu *rdu)
23670 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
23671 + "%llu, b%d, 0x%x, g%u}\n",
23672 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
23674 + rdu->rent, rdu->shwh, rdu->full,
23675 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
23676 + rdu->cookie.generation);
23678 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
23682 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
23686 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
23689 + struct aufs_rdu rdu;
23690 + void __user *p = (void __user *)arg;
23692 + err = copy_from_user(&rdu, p, sizeof(rdu));
23693 + if (unlikely(err)) {
23698 + err = au_rdu_verify(&rdu);
23699 + if (unlikely(err))
23703 + case AUFS_CTL_RDU:
23704 + err = au_rdu(file, &rdu);
23705 + if (unlikely(err))
23708 + e = copy_to_user(p, &rdu, sizeof(rdu));
23709 + if (unlikely(e)) {
23714 + case AUFS_CTL_RDU_INO:
23715 + err = au_rdu_ino(file, &rdu);
23719 + /* err = -ENOTTY; */
23728 +#ifdef CONFIG_COMPAT
23729 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
23732 + struct aufs_rdu rdu;
23733 + void __user *p = compat_ptr(arg);
23735 + /* todo: get_user()? */
23736 + err = copy_from_user(&rdu, p, sizeof(rdu));
23737 + if (unlikely(err)) {
23742 + rdu.ent.e = compat_ptr(rdu.ent.ul);
23743 + err = au_rdu_verify(&rdu);
23744 + if (unlikely(err))
23748 + case AUFS_CTL_RDU:
23749 + err = au_rdu(file, &rdu);
23750 + if (unlikely(err))
23753 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
23754 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
23755 + e = copy_to_user(p, &rdu, sizeof(rdu));
23756 + if (unlikely(e)) {
23761 + case AUFS_CTL_RDU_INO:
23762 + err = au_rdu_ino(file, &rdu);
23766 + /* err = -ENOTTY; */
23775 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
23776 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
23777 +++ linux/fs/aufs/rwsem.h 2013-07-06 13:20:47.753531903 +0200
23780 + * Copyright (C) 2005-2013 Junjiro R. Okajima
23782 + * This program, aufs is free software; you can redistribute it and/or modify
23783 + * it under the terms of the GNU General Public License as published by
23784 + * the Free Software Foundation; either version 2 of the License, or
23785 + * (at your option) any later version.
23787 + * This program is distributed in the hope that it will be useful,
23788 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23789 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23790 + * GNU General Public License for more details.
23792 + * You should have received a copy of the GNU General Public License
23793 + * along with this program; if not, write to the Free Software
23794 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23798 + * simple read-write semaphore wrappers
23801 +#ifndef __AUFS_RWSEM_H__
23802 +#define __AUFS_RWSEM_H__
23806 +#include "debug.h"
23809 + struct rw_semaphore rwsem;
23810 +#ifdef CONFIG_AUFS_DEBUG
23811 + /* just for debugging, not almighty counter */
23812 + atomic_t rcnt, wcnt;
23816 +#ifdef CONFIG_AUFS_DEBUG
23817 +#define AuDbgCntInit(rw) do { \
23818 + atomic_set(&(rw)->rcnt, 0); \
23819 + atomic_set(&(rw)->wcnt, 0); \
23820 + smp_mb(); /* atomic set */ \
23823 +#define AuDbgRcntInc(rw) atomic_inc(&(rw)->rcnt)
23824 +#define AuDbgRcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->rcnt) < 0)
23825 +#define AuDbgWcntInc(rw) atomic_inc(&(rw)->wcnt)
23826 +#define AuDbgWcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->wcnt) < 0)
23828 +#define AuDbgCntInit(rw) do {} while (0)
23829 +#define AuDbgRcntInc(rw) do {} while (0)
23830 +#define AuDbgRcntDec(rw) do {} while (0)
23831 +#define AuDbgWcntInc(rw) do {} while (0)
23832 +#define AuDbgWcntDec(rw) do {} while (0)
23833 +#endif /* CONFIG_AUFS_DEBUG */
23835 +/* to debug easier, do not make them inlined functions */
23836 +#define AuRwMustNoWaiters(rw) AuDebugOn(!list_empty(&(rw)->rwsem.wait_list))
23837 +/* rwsem_is_locked() is unusable */
23838 +#define AuRwMustReadLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0)
23839 +#define AuRwMustWriteLock(rw) AuDebugOn(atomic_read(&(rw)->wcnt) <= 0)
23840 +#define AuRwMustAnyLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0 \
23841 + && atomic_read(&(rw)->wcnt) <= 0)
23842 +#define AuRwDestroy(rw) AuDebugOn(atomic_read(&(rw)->rcnt) \
23843 + || atomic_read(&(rw)->wcnt))
23845 +#define au_rw_class(rw, key) lockdep_set_class(&(rw)->rwsem, key)
23847 +static inline void au_rw_init(struct au_rwsem *rw)
23849 + AuDbgCntInit(rw);
23850 + init_rwsem(&rw->rwsem);
23853 +static inline void au_rw_init_wlock(struct au_rwsem *rw)
23856 + down_write(&rw->rwsem);
23857 + AuDbgWcntInc(rw);
23860 +static inline void au_rw_init_wlock_nested(struct au_rwsem *rw,
23861 + unsigned int lsc)
23864 + down_write_nested(&rw->rwsem, lsc);
23865 + AuDbgWcntInc(rw);
23868 +static inline void au_rw_read_lock(struct au_rwsem *rw)
23870 + down_read(&rw->rwsem);
23871 + AuDbgRcntInc(rw);
23874 +static inline void au_rw_read_lock_nested(struct au_rwsem *rw, unsigned int lsc)
23876 + down_read_nested(&rw->rwsem, lsc);
23877 + AuDbgRcntInc(rw);
23880 +static inline void au_rw_read_unlock(struct au_rwsem *rw)
23882 + AuRwMustReadLock(rw);
23883 + AuDbgRcntDec(rw);
23884 + up_read(&rw->rwsem);
23887 +static inline void au_rw_dgrade_lock(struct au_rwsem *rw)
23889 + AuRwMustWriteLock(rw);
23890 + AuDbgRcntInc(rw);
23891 + AuDbgWcntDec(rw);
23892 + downgrade_write(&rw->rwsem);
23895 +static inline void au_rw_write_lock(struct au_rwsem *rw)
23897 + down_write(&rw->rwsem);
23898 + AuDbgWcntInc(rw);
23901 +static inline void au_rw_write_lock_nested(struct au_rwsem *rw,
23902 + unsigned int lsc)
23904 + down_write_nested(&rw->rwsem, lsc);
23905 + AuDbgWcntInc(rw);
23908 +static inline void au_rw_write_unlock(struct au_rwsem *rw)
23910 + AuRwMustWriteLock(rw);
23911 + AuDbgWcntDec(rw);
23912 + up_write(&rw->rwsem);
23915 +/* why is not _nested version defined */
23916 +static inline int au_rw_read_trylock(struct au_rwsem *rw)
23918 + int ret = down_read_trylock(&rw->rwsem);
23920 + AuDbgRcntInc(rw);
23924 +static inline int au_rw_write_trylock(struct au_rwsem *rw)
23926 + int ret = down_write_trylock(&rw->rwsem);
23928 + AuDbgWcntInc(rw);
23932 +#undef AuDbgCntInit
23933 +#undef AuDbgRcntInc
23934 +#undef AuDbgRcntDec
23935 +#undef AuDbgWcntInc
23936 +#undef AuDbgWcntDec
23938 +#define AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
23939 +static inline void prefix##_read_lock(param) \
23940 +{ au_rw_read_lock(rwsem); } \
23941 +static inline void prefix##_write_lock(param) \
23942 +{ au_rw_write_lock(rwsem); } \
23943 +static inline int prefix##_read_trylock(param) \
23944 +{ return au_rw_read_trylock(rwsem); } \
23945 +static inline int prefix##_write_trylock(param) \
23946 +{ return au_rw_write_trylock(rwsem); }
23947 +/* why is not _nested version defined */
23948 +/* static inline void prefix##_read_trylock_nested(param, lsc)
23949 +{ au_rw_read_trylock_nested(rwsem, lsc)); }
23950 +static inline void prefix##_write_trylock_nestd(param, lsc)
23951 +{ au_rw_write_trylock_nested(rwsem, lsc); } */
23953 +#define AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) \
23954 +static inline void prefix##_read_unlock(param) \
23955 +{ au_rw_read_unlock(rwsem); } \
23956 +static inline void prefix##_write_unlock(param) \
23957 +{ au_rw_write_unlock(rwsem); } \
23958 +static inline void prefix##_downgrade_lock(param) \
23959 +{ au_rw_dgrade_lock(rwsem); }
23961 +#define AuSimpleRwsemFuncs(prefix, param, rwsem) \
23962 + AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
23963 + AuSimpleUnlockRwsemFuncs(prefix, param, rwsem)
23965 +#endif /* __KERNEL__ */
23966 +#endif /* __AUFS_RWSEM_H__ */
23967 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
23968 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
23969 +++ linux/fs/aufs/sbinfo.c 2013-10-26 16:51:32.276373845 +0200
23972 + * Copyright (C) 2005-2013 Junjiro R. Okajima
23974 + * This program, aufs is free software; you can redistribute it and/or modify
23975 + * it under the terms of the GNU General Public License as published by
23976 + * the Free Software Foundation; either version 2 of the License, or
23977 + * (at your option) any later version.
23979 + * This program is distributed in the hope that it will be useful,
23980 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23981 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23982 + * GNU General Public License for more details.
23984 + * You should have received a copy of the GNU General Public License
23985 + * along with this program; if not, write to the Free Software
23986 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23990 + * superblock private data
23996 + * they are necessary regardless sysfs is disabled.
23998 +void au_si_free(struct kobject *kobj)
24001 + struct au_sbinfo *sbinfo;
24002 + char *locked __maybe_unused; /* debug only */
24004 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
24005 + for (i = 0; i < AuPlink_NHASH; i++)
24006 + AuDebugOn(!hlist_empty(&sbinfo->si_plink[i].head));
24007 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
24009 + au_rw_write_lock(&sbinfo->si_rwsem);
24010 + au_br_free(sbinfo);
24011 + au_rw_write_unlock(&sbinfo->si_rwsem);
24013 + AuDebugOn(radix_tree_gang_lookup
24014 + (&sbinfo->au_si_pid.tree, (void **)&locked,
24015 + /*first_index*/PID_MAX_DEFAULT - 1,
24016 + /*max_items*/sizeof(locked)/sizeof(*locked)));
24018 + kfree(sbinfo->si_branch);
24019 + kfree(sbinfo->au_si_pid.bitmap);
24020 + mutex_destroy(&sbinfo->si_xib_mtx);
24021 + AuRwDestroy(&sbinfo->si_rwsem);
24026 +int au_si_alloc(struct super_block *sb)
24029 + struct au_sbinfo *sbinfo;
24030 + static struct lock_class_key aufs_si;
24033 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
24034 + if (unlikely(!sbinfo))
24037 + BUILD_BUG_ON(sizeof(unsigned long) !=
24038 + sizeof(*sbinfo->au_si_pid.bitmap));
24039 + sbinfo->au_si_pid.bitmap = kcalloc(BITS_TO_LONGS(PID_MAX_DEFAULT),
24040 + sizeof(*sbinfo->au_si_pid.bitmap),
24042 + if (unlikely(!sbinfo->au_si_pid.bitmap))
24045 + /* will be reallocated separately */
24046 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
24047 + if (unlikely(!sbinfo->si_branch))
24050 + err = sysaufs_si_init(sbinfo);
24051 + if (unlikely(err))
24054 + au_nwt_init(&sbinfo->si_nowait);
24055 + au_rw_init_wlock(&sbinfo->si_rwsem);
24056 + au_rw_class(&sbinfo->si_rwsem, &aufs_si);
24057 + spin_lock_init(&sbinfo->au_si_pid.tree_lock);
24058 + INIT_RADIX_TREE(&sbinfo->au_si_pid.tree, GFP_ATOMIC | __GFP_NOFAIL);
24060 + atomic_long_set(&sbinfo->si_ninodes, 0);
24061 + atomic_long_set(&sbinfo->si_nfiles, 0);
24063 + sbinfo->si_bend = -1;
24064 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
24066 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
24067 + sbinfo->si_wbr_create = AuWbrCreate_Def;
24068 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
24069 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
24071 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
24073 + sbinfo->si_xino_jiffy = jiffies;
24074 + sbinfo->si_xino_expire
24075 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
24076 + mutex_init(&sbinfo->si_xib_mtx);
24077 + sbinfo->si_xino_brid = -1;
24078 + /* leave si_xib_last_pindex and si_xib_next_bit */
24080 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
24081 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
24082 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
24083 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
24085 + for (i = 0; i < AuPlink_NHASH; i++)
24086 + au_sphl_init(sbinfo->si_plink + i);
24087 + init_waitqueue_head(&sbinfo->si_plink_wq);
24088 + spin_lock_init(&sbinfo->si_plink_maint_lock);
24090 + /* leave other members for sysaufs and si_mnt. */
24091 + sbinfo->si_sb = sb;
24092 + sb->s_fs_info = sbinfo;
24094 + au_debug_sbinfo_init(sbinfo);
24095 + return 0; /* success */
24098 + kfree(sbinfo->si_branch);
24100 + kfree(sbinfo->au_si_pid.bitmap);
24107 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr)
24110 + struct au_branch **brp;
24112 + AuRwMustWriteLock(&sbinfo->si_rwsem);
24115 + sz = sizeof(*brp) * (sbinfo->si_bend + 1);
24116 + if (unlikely(!sz))
24117 + sz = sizeof(*brp);
24118 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS);
24120 + sbinfo->si_branch = brp;
24127 +/* ---------------------------------------------------------------------- */
24129 +unsigned int au_sigen_inc(struct super_block *sb)
24131 + unsigned int gen;
24133 + SiMustWriteLock(sb);
24135 + gen = ++au_sbi(sb)->si_generation;
24136 + au_update_digen(sb->s_root);
24137 + au_update_iigen(sb->s_root->d_inode, /*half*/0);
24138 + sb->s_root->d_inode->i_version++;
24142 +aufs_bindex_t au_new_br_id(struct super_block *sb)
24144 + aufs_bindex_t br_id;
24146 + struct au_sbinfo *sbinfo;
24148 + SiMustWriteLock(sb);
24150 + sbinfo = au_sbi(sb);
24151 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
24152 + br_id = ++sbinfo->si_last_br_id;
24153 + AuDebugOn(br_id < 0);
24154 + if (br_id && au_br_index(sb, br_id) < 0)
24161 +/* ---------------------------------------------------------------------- */
24163 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
24164 +int si_read_lock(struct super_block *sb, int flags)
24169 + if (au_ftest_lock(flags, FLUSH))
24170 + au_nwt_flush(&au_sbi(sb)->si_nowait);
24172 + si_noflush_read_lock(sb);
24173 + err = au_plink_maint(sb, flags);
24174 + if (unlikely(err))
24175 + si_read_unlock(sb);
24180 +int si_write_lock(struct super_block *sb, int flags)
24184 + if (au_ftest_lock(flags, FLUSH))
24185 + au_nwt_flush(&au_sbi(sb)->si_nowait);
24187 + si_noflush_write_lock(sb);
24188 + err = au_plink_maint(sb, flags);
24189 + if (unlikely(err))
24190 + si_write_unlock(sb);
24195 +/* dentry and super_block lock. call at entry point */
24196 +int aufs_read_lock(struct dentry *dentry, int flags)
24199 + struct super_block *sb;
24201 + sb = dentry->d_sb;
24202 + err = si_read_lock(sb, flags);
24203 + if (unlikely(err))
24206 + if (au_ftest_lock(flags, DW))
24207 + di_write_lock_child(dentry);
24209 + di_read_lock_child(dentry, flags);
24211 + if (au_ftest_lock(flags, GEN)) {
24212 + err = au_digen_test(dentry, au_sigen(sb));
24213 + AuDebugOn(!err && au_dbrange_test(dentry));
24214 + if (unlikely(err))
24215 + aufs_read_unlock(dentry, flags);
24222 +void aufs_read_unlock(struct dentry *dentry, int flags)
24224 + if (au_ftest_lock(flags, DW))
24225 + di_write_unlock(dentry);
24227 + di_read_unlock(dentry, flags);
24228 + si_read_unlock(dentry->d_sb);
24231 +void aufs_write_lock(struct dentry *dentry)
24233 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
24234 + di_write_lock_child(dentry);
24237 +void aufs_write_unlock(struct dentry *dentry)
24239 + di_write_unlock(dentry);
24240 + si_write_unlock(dentry->d_sb);
24243 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
24246 + unsigned int sigen;
24247 + struct super_block *sb;
24250 + err = si_read_lock(sb, flags);
24251 + if (unlikely(err))
24254 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIR));
24256 + if (au_ftest_lock(flags, GEN)) {
24257 + sigen = au_sigen(sb);
24258 + err = au_digen_test(d1, sigen);
24259 + AuDebugOn(!err && au_dbrange_test(d1));
24261 + err = au_digen_test(d2, sigen);
24262 + AuDebugOn(!err && au_dbrange_test(d2));
24264 + if (unlikely(err))
24265 + aufs_read_and_write_unlock2(d1, d2);
24272 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
24274 + di_write_unlock2(d1, d2);
24275 + si_read_unlock(d1->d_sb);
24278 +/* ---------------------------------------------------------------------- */
24280 +int si_pid_test_slow(struct super_block *sb)
24285 + p = radix_tree_lookup(&au_sbi(sb)->au_si_pid.tree, current->pid);
24286 + rcu_read_unlock();
24288 + return (long)!!p;
24291 +void si_pid_set_slow(struct super_block *sb)
24294 + struct au_sbinfo *sbinfo;
24296 + AuDebugOn(si_pid_test_slow(sb));
24298 + sbinfo = au_sbi(sb);
24299 + err = radix_tree_preload(GFP_NOFS | __GFP_NOFAIL);
24301 + spin_lock(&sbinfo->au_si_pid.tree_lock);
24302 + err = radix_tree_insert(&sbinfo->au_si_pid.tree, current->pid,
24303 + /*any valid ptr*/sb);
24304 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
24306 + radix_tree_preload_end();
24309 +void si_pid_clr_slow(struct super_block *sb)
24312 + struct au_sbinfo *sbinfo;
24314 + AuDebugOn(!si_pid_test_slow(sb));
24316 + sbinfo = au_sbi(sb);
24317 + spin_lock(&sbinfo->au_si_pid.tree_lock);
24318 + p = radix_tree_delete(&sbinfo->au_si_pid.tree, current->pid);
24319 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
24321 diff -urN /usr/share/empty/fs/aufs/spl.h linux/fs/aufs/spl.h
24322 --- /usr/share/empty/fs/aufs/spl.h 1970-01-01 01:00:00.000000000 +0100
24323 +++ linux/fs/aufs/spl.h 2013-07-06 13:20:47.753531903 +0200
24326 + * Copyright (C) 2005-2013 Junjiro R. Okajima
24328 + * This program, aufs is free software; you can redistribute it and/or modify
24329 + * it under the terms of the GNU General Public License as published by
24330 + * the Free Software Foundation; either version 2 of the License, or
24331 + * (at your option) any later version.
24333 + * This program is distributed in the hope that it will be useful,
24334 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24335 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24336 + * GNU General Public License for more details.
24338 + * You should have received a copy of the GNU General Public License
24339 + * along with this program; if not, write to the Free Software
24340 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24344 + * simple list protected by a spinlock
24347 +#ifndef __AUFS_SPL_H__
24348 +#define __AUFS_SPL_H__
24352 +struct au_splhead {
24354 + struct list_head head;
24357 +static inline void au_spl_init(struct au_splhead *spl)
24359 + spin_lock_init(&spl->spin);
24360 + INIT_LIST_HEAD(&spl->head);
24363 +static inline void au_spl_add(struct list_head *list, struct au_splhead *spl)
24365 + spin_lock(&spl->spin);
24366 + list_add(list, &spl->head);
24367 + spin_unlock(&spl->spin);
24370 +static inline void au_spl_del(struct list_head *list, struct au_splhead *spl)
24372 + spin_lock(&spl->spin);
24374 + spin_unlock(&spl->spin);
24377 +static inline void au_spl_del_rcu(struct list_head *list,
24378 + struct au_splhead *spl)
24380 + spin_lock(&spl->spin);
24381 + list_del_rcu(list);
24382 + spin_unlock(&spl->spin);
24385 +/* ---------------------------------------------------------------------- */
24387 +struct au_sphlhead {
24389 + struct hlist_head head;
24392 +static inline void au_sphl_init(struct au_sphlhead *sphl)
24394 + spin_lock_init(&sphl->spin);
24395 + INIT_HLIST_HEAD(&sphl->head);
24398 +static inline void au_sphl_add(struct hlist_node *hlist,
24399 + struct au_sphlhead *sphl)
24401 + spin_lock(&sphl->spin);
24402 + hlist_add_head(hlist, &sphl->head);
24403 + spin_unlock(&sphl->spin);
24406 +static inline void au_sphl_del(struct hlist_node *hlist,
24407 + struct au_sphlhead *sphl)
24409 + spin_lock(&sphl->spin);
24410 + hlist_del(hlist);
24411 + spin_unlock(&sphl->spin);
24414 +static inline void au_sphl_del_rcu(struct hlist_node *hlist,
24415 + struct au_sphlhead *sphl)
24417 + spin_lock(&sphl->spin);
24418 + hlist_del_rcu(hlist);
24419 + spin_unlock(&sphl->spin);
24422 +static inline unsigned long au_sphl_count(struct au_sphlhead *sphl)
24424 + unsigned long cnt;
24425 + struct hlist_node *pos;
24428 + spin_lock(&sphl->spin);
24429 + hlist_for_each(pos, &sphl->head)
24431 + spin_unlock(&sphl->spin);
24435 +#endif /* __KERNEL__ */
24436 +#endif /* __AUFS_SPL_H__ */
24437 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
24438 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
24439 +++ linux/fs/aufs/super.c 2013-10-26 16:51:32.276373845 +0200
24442 + * Copyright (C) 2005-2013 Junjiro R. Okajima
24444 + * This program, aufs is free software; you can redistribute it and/or modify
24445 + * it under the terms of the GNU General Public License as published by
24446 + * the Free Software Foundation; either version 2 of the License, or
24447 + * (at your option) any later version.
24449 + * This program is distributed in the hope that it will be useful,
24450 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24451 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24452 + * GNU General Public License for more details.
24454 + * You should have received a copy of the GNU General Public License
24455 + * along with this program; if not, write to the Free Software
24456 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24460 + * mount and super_block operations
24463 +#include <linux/mm.h>
24464 +#include <linux/module.h>
24465 +#include <linux/seq_file.h>
24466 +#include <linux/statfs.h>
24467 +#include <linux/vmalloc.h>
24468 +#include <linux/writeback.h>
24472 + * super_operations
24474 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
24476 + struct au_icntnr *c;
24478 + c = au_cache_alloc_icntnr();
24480 + au_icntnr_init(c);
24481 + c->vfs_inode.i_version = 1; /* sigen(sb); */
24482 + c->iinfo.ii_hinode = NULL;
24483 + return &c->vfs_inode;
24488 +static void aufs_destroy_inode_cb(struct rcu_head *head)
24490 + struct inode *inode = container_of(head, struct inode, i_rcu);
24492 + INIT_HLIST_HEAD(&inode->i_dentry);
24493 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
24496 +static void aufs_destroy_inode(struct inode *inode)
24498 + au_iinfo_fin(inode);
24499 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
24502 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
24504 + struct inode *inode;
24507 + inode = iget_locked(sb, ino);
24508 + if (unlikely(!inode)) {
24509 + inode = ERR_PTR(-ENOMEM);
24512 + if (!(inode->i_state & I_NEW))
24515 + err = au_xigen_new(inode);
24517 + err = au_iinfo_init(inode);
24519 + inode->i_version++;
24521 + iget_failed(inode);
24522 + inode = ERR_PTR(err);
24526 + /* never return NULL */
24527 + AuDebugOn(!inode);
24528 + AuTraceErrPtr(inode);
24532 +/* lock free root dinfo */
24533 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
24536 + aufs_bindex_t bindex, bend;
24537 + struct path path;
24538 + struct au_hdentry *hdp;
24539 + struct au_branch *br;
24543 + bend = au_sbend(sb);
24544 + hdp = au_di(sb->s_root)->di_hdentry;
24545 + for (bindex = 0; !err && bindex <= bend; bindex++) {
24546 + br = au_sbr(sb, bindex);
24547 + path.mnt = au_br_mnt(br);
24548 + path.dentry = hdp[bindex].hd_dentry;
24549 + err = au_seq_path(seq, &path);
24551 + perm = au_optstr_br_perm(br->br_perm);
24553 + err = seq_printf(seq, "=%s", perm);
24560 + if (!err && bindex != bend)
24561 + err = seq_putc(seq, ':');
24567 +static void au_show_wbr_create(struct seq_file *m, int v,
24568 + struct au_sbinfo *sbinfo)
24572 + AuRwMustAnyLock(&sbinfo->si_rwsem);
24574 + seq_puts(m, ",create=");
24575 + pat = au_optstr_wbr_create(v);
24577 + case AuWbrCreate_TDP:
24578 + case AuWbrCreate_RR:
24579 + case AuWbrCreate_MFS:
24580 + case AuWbrCreate_PMFS:
24581 + seq_puts(m, pat);
24583 + case AuWbrCreate_MFSV:
24584 + seq_printf(m, /*pat*/"mfs:%lu",
24585 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
24588 + case AuWbrCreate_PMFSV:
24589 + seq_printf(m, /*pat*/"pmfs:%lu",
24590 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
24593 + case AuWbrCreate_MFSRR:
24594 + seq_printf(m, /*pat*/"mfsrr:%llu",
24595 + sbinfo->si_wbr_mfs.mfsrr_watermark);
24597 + case AuWbrCreate_MFSRRV:
24598 + seq_printf(m, /*pat*/"mfsrr:%llu:%lu",
24599 + sbinfo->si_wbr_mfs.mfsrr_watermark,
24600 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
24603 + case AuWbrCreate_PMFSRR:
24604 + seq_printf(m, /*pat*/"pmfsrr:%llu",
24605 + sbinfo->si_wbr_mfs.mfsrr_watermark);
24607 + case AuWbrCreate_PMFSRRV:
24608 + seq_printf(m, /*pat*/"pmfsrr:%llu:%lu",
24609 + sbinfo->si_wbr_mfs.mfsrr_watermark,
24610 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
24616 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
24618 +#ifdef CONFIG_SYSFS
24622 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
24623 + aufs_bindex_t bindex, brid;
24624 + struct qstr *name;
24626 + struct dentry *d, *h_root;
24627 + struct au_hdentry *hdp;
24629 + AuRwMustAnyLock(&sbinfo->si_rwsem);
24632 + f = au_sbi(sb)->si_xib;
24636 + /* stop printing the default xino path on the first writable branch */
24638 + brid = au_xino_brid(sb);
24640 + bindex = au_br_index(sb, brid);
24641 + hdp = au_di(sb->s_root)->di_hdentry;
24642 + h_root = hdp[0 + bindex].hd_dentry;
24645 + name = &d->d_name;
24646 + /* safe ->d_parent because the file is unlinked */
24647 + if (d->d_parent == h_root
24648 + && name->len == len
24649 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
24652 + seq_puts(seq, ",xino=");
24653 + err = au_xino_path(seq, f);
24660 +/* seq_file will re-call me in case of too long string */
24661 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
24664 + unsigned int mnt_flags, v;
24665 + struct super_block *sb;
24666 + struct au_sbinfo *sbinfo;
24668 +#define AuBool(name, str) do { \
24669 + v = au_opt_test(mnt_flags, name); \
24670 + if (v != au_opt_test(AuOpt_Def, name)) \
24671 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
24674 +#define AuStr(name, str) do { \
24675 + v = mnt_flags & AuOptMask_##name; \
24676 + if (v != (AuOpt_Def & AuOptMask_##name)) \
24677 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
24680 +#define AuUInt(name, str, val) do { \
24681 + if (val != AUFS_##name##_DEF) \
24682 + seq_printf(m, "," #str "=%u", val); \
24685 + /* lock free root dinfo */
24686 + sb = dentry->d_sb;
24687 + si_noflush_read_lock(sb);
24688 + sbinfo = au_sbi(sb);
24689 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
24691 + mnt_flags = au_mntflags(sb);
24692 + if (au_opt_test(mnt_flags, XINO)) {
24693 + err = au_show_xino(m, sb);
24694 + if (unlikely(err))
24697 + seq_puts(m, ",noxino");
24699 + AuBool(TRUNC_XINO, trunc_xino);
24700 + AuStr(UDBA, udba);
24701 + AuBool(SHWH, shwh);
24702 + AuBool(PLINK, plink);
24703 + AuBool(DIO, dio);
24704 + /* AuBool(DIRPERM1, dirperm1); */
24705 + /* AuBool(REFROF, refrof); */
24707 + v = sbinfo->si_wbr_create;
24708 + if (v != AuWbrCreate_Def)
24709 + au_show_wbr_create(m, v, sbinfo);
24711 + v = sbinfo->si_wbr_copyup;
24712 + if (v != AuWbrCopyup_Def)
24713 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
24715 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
24716 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
24717 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
24719 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
24721 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
24722 + AuUInt(RDCACHE, rdcache, v);
24724 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
24725 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
24727 + AuBool(SUM, sum);
24728 + /* AuBool(SUM_W, wsum); */
24729 + AuBool(WARN_PERM, warn_perm);
24730 + AuBool(VERBOSE, verbose);
24733 + /* be sure to print "br:" last */
24734 + if (!sysaufs_brs) {
24735 + seq_puts(m, ",br:");
24736 + au_show_brs(m, sb);
24738 + si_read_unlock(sb);
24746 +/* ---------------------------------------------------------------------- */
24748 +/* sum mode which returns the summation for statfs(2) */
24750 +static u64 au_add_till_max(u64 a, u64 b)
24758 + return ULLONG_MAX;
24761 +static u64 au_mul_till_max(u64 a, long mul)
24769 + return ULLONG_MAX;
24772 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
24775 + long bsize, factor;
24776 + u64 blocks, bfree, bavail, files, ffree;
24777 + aufs_bindex_t bend, bindex, i;
24778 + unsigned char shared;
24779 + struct path h_path;
24780 + struct super_block *h_sb;
24783 + bsize = LONG_MAX;
24789 + bend = au_sbend(sb);
24790 + for (bindex = 0; bindex <= bend; bindex++) {
24791 + h_path.mnt = au_sbr_mnt(sb, bindex);
24792 + h_sb = h_path.mnt->mnt_sb;
24794 + for (i = 0; !shared && i < bindex; i++)
24795 + shared = (au_sbr_sb(sb, i) == h_sb);
24799 + /* sb->s_root for NFS is unreliable */
24800 + h_path.dentry = h_path.mnt->mnt_root;
24801 + err = vfs_statfs(&h_path, buf);
24802 + if (unlikely(err))
24805 + if (bsize > buf->f_bsize) {
24807 + * we will reduce bsize, so we have to expand blocks
24808 + * etc. to match them again
24810 + factor = (bsize / buf->f_bsize);
24811 + blocks = au_mul_till_max(blocks, factor);
24812 + bfree = au_mul_till_max(bfree, factor);
24813 + bavail = au_mul_till_max(bavail, factor);
24814 + bsize = buf->f_bsize;
24817 + factor = (buf->f_bsize / bsize);
24818 + blocks = au_add_till_max(blocks,
24819 + au_mul_till_max(buf->f_blocks, factor));
24820 + bfree = au_add_till_max(bfree,
24821 + au_mul_till_max(buf->f_bfree, factor));
24822 + bavail = au_add_till_max(bavail,
24823 + au_mul_till_max(buf->f_bavail, factor));
24824 + files = au_add_till_max(files, buf->f_files);
24825 + ffree = au_add_till_max(ffree, buf->f_ffree);
24828 + buf->f_bsize = bsize;
24829 + buf->f_blocks = blocks;
24830 + buf->f_bfree = bfree;
24831 + buf->f_bavail = bavail;
24832 + buf->f_files = files;
24833 + buf->f_ffree = ffree;
24834 + buf->f_frsize = 0;
24840 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
24843 + struct path h_path;
24844 + struct super_block *sb;
24846 + /* lock free root dinfo */
24847 + sb = dentry->d_sb;
24848 + si_noflush_read_lock(sb);
24849 + if (!au_opt_test(au_mntflags(sb), SUM)) {
24850 + /* sb->s_root for NFS is unreliable */
24851 + h_path.mnt = au_sbr_mnt(sb, 0);
24852 + h_path.dentry = h_path.mnt->mnt_root;
24853 + err = vfs_statfs(&h_path, buf);
24855 + err = au_statfs_sum(sb, buf);
24856 + si_read_unlock(sb);
24859 + buf->f_type = AUFS_SUPER_MAGIC;
24860 + buf->f_namelen = AUFS_MAX_NAMELEN;
24861 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
24863 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
24868 +/* ---------------------------------------------------------------------- */
24870 +static int aufs_sync_fs(struct super_block *sb, int wait)
24873 + aufs_bindex_t bend, bindex;
24874 + struct au_branch *br;
24875 + struct super_block *h_sb;
24878 + si_noflush_read_lock(sb);
24879 + bend = au_sbend(sb);
24880 + for (bindex = 0; bindex <= bend; bindex++) {
24881 + br = au_sbr(sb, bindex);
24882 + if (!au_br_writable(br->br_perm))
24885 + h_sb = au_sbr_sb(sb, bindex);
24886 + if (h_sb->s_op->sync_fs) {
24887 + e = h_sb->s_op->sync_fs(h_sb, wait);
24888 + if (unlikely(e && !err))
24890 + /* go on even if an error happens */
24893 + si_read_unlock(sb);
24898 +/* ---------------------------------------------------------------------- */
24900 +/* final actions when unmounting a file system */
24901 +static void aufs_put_super(struct super_block *sb)
24903 + struct au_sbinfo *sbinfo;
24905 + sbinfo = au_sbi(sb);
24909 + dbgaufs_si_fin(sbinfo);
24910 + kobject_put(&sbinfo->si_kobj);
24913 +/* ---------------------------------------------------------------------- */
24915 +void au_array_free(void *array)
24918 + if (!is_vmalloc_addr(array))
24925 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg)
24928 + unsigned long long n;
24935 + if (*hint > ULLONG_MAX / sizeof(array)) {
24936 + array = ERR_PTR(-EMFILE);
24937 + pr_err("hint %llu\n", *hint);
24941 + array = kmalloc(sizeof(array) * *hint, GFP_NOFS);
24942 + if (unlikely(!array))
24943 + array = vmalloc(sizeof(array) * *hint);
24944 + if (unlikely(!array)) {
24945 + array = ERR_PTR(-ENOMEM);
24949 + n = cb(array, *hint, arg);
24950 + AuDebugOn(n > *hint);
24957 +static unsigned long long au_iarray_cb(void *a,
24958 + unsigned long long max __maybe_unused,
24961 + unsigned long long n;
24962 + struct inode **p, *inode;
24963 + struct list_head *head;
24968 + spin_lock(&inode_sb_list_lock);
24969 + list_for_each_entry(inode, head, i_sb_list) {
24970 + if (!is_bad_inode(inode)
24971 + && au_ii(inode)->ii_bstart >= 0) {
24972 + spin_lock(&inode->i_lock);
24973 + if (atomic_read(&inode->i_count)) {
24977 + AuDebugOn(n > max);
24979 + spin_unlock(&inode->i_lock);
24982 + spin_unlock(&inode_sb_list_lock);
24987 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
24989 + *max = atomic_long_read(&au_sbi(sb)->si_ninodes);
24990 + return au_array_alloc(max, au_iarray_cb, &sb->s_inodes);
24993 +void au_iarray_free(struct inode **a, unsigned long long max)
24995 + unsigned long long ull;
24997 + for (ull = 0; ull < max; ull++)
24999 + au_array_free(a);
25002 +/* ---------------------------------------------------------------------- */
25005 + * refresh dentry and inode at remount time.
25007 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
25008 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
25009 + struct dentry *parent)
25013 + di_write_lock_child(dentry);
25014 + di_read_lock_parent(parent, AuLock_IR);
25015 + err = au_refresh_dentry(dentry, parent);
25016 + if (!err && dir_flags)
25017 + au_hn_reset(dentry->d_inode, dir_flags);
25018 + di_read_unlock(parent, AuLock_IR);
25019 + di_write_unlock(dentry);
25024 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
25025 + struct au_sbinfo *sbinfo,
25026 + const unsigned int dir_flags)
25029 + struct dentry *parent;
25030 + struct inode *inode;
25033 + parent = dget_parent(dentry);
25034 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
25035 + inode = dentry->d_inode;
25037 + if (!S_ISDIR(inode->i_mode))
25038 + err = au_do_refresh(dentry, /*dir_flags*/0,
25041 + err = au_do_refresh(dentry, dir_flags, parent);
25042 + if (unlikely(err))
25043 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
25046 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
25047 + AuDbgDentry(dentry);
25055 +static int au_refresh_d(struct super_block *sb)
25057 + int err, i, j, ndentry, e;
25058 + unsigned int sigen;
25059 + struct au_dcsub_pages dpages;
25060 + struct au_dpage *dpage;
25061 + struct dentry **dentries, *d;
25062 + struct au_sbinfo *sbinfo;
25063 + struct dentry *root = sb->s_root;
25064 + const unsigned int dir_flags = au_hi_flags(root->d_inode, /*isdir*/1);
25066 + err = au_dpages_init(&dpages, GFP_NOFS);
25067 + if (unlikely(err))
25069 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
25070 + if (unlikely(err))
25073 + sigen = au_sigen(sb);
25074 + sbinfo = au_sbi(sb);
25075 + for (i = 0; i < dpages.ndpage; i++) {
25076 + dpage = dpages.dpages + i;
25077 + dentries = dpage->dentries;
25078 + ndentry = dpage->ndentry;
25079 + for (j = 0; j < ndentry; j++) {
25081 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags);
25082 + if (unlikely(e && !err))
25084 + /* go on even err */
25089 + au_dpages_free(&dpages);
25094 +static int au_refresh_i(struct super_block *sb)
25097 + unsigned int sigen;
25098 + unsigned long long max, ull;
25099 + struct inode *inode, **array;
25101 + array = au_iarray_alloc(sb, &max);
25102 + err = PTR_ERR(array);
25103 + if (IS_ERR(array))
25107 + sigen = au_sigen(sb);
25108 + for (ull = 0; ull < max; ull++) {
25109 + inode = array[ull];
25110 + if (au_iigen(inode, NULL) != sigen) {
25111 + ii_write_lock_child(inode);
25112 + e = au_refresh_hinode_self(inode);
25113 + ii_write_unlock(inode);
25114 + if (unlikely(e)) {
25115 + pr_err("error %d, i%lu\n", e, inode->i_ino);
25118 + /* go on even if err */
25123 + au_iarray_free(array, max);
25129 +static void au_remount_refresh(struct super_block *sb)
25132 + unsigned int udba;
25133 + aufs_bindex_t bindex, bend;
25134 + struct dentry *root;
25135 + struct inode *inode;
25136 + struct au_branch *br;
25138 + au_sigen_inc(sb);
25139 + au_fclr_si(au_sbi(sb), FAILED_REFRESH_DIR);
25141 + root = sb->s_root;
25142 + DiMustNoWaiters(root);
25143 + inode = root->d_inode;
25144 + IiMustNoWaiters(inode);
25146 + udba = au_opt_udba(sb);
25147 + bend = au_sbend(sb);
25148 + for (bindex = 0; bindex <= bend; bindex++) {
25149 + br = au_sbr(sb, bindex);
25150 + err = au_hnotify_reset_br(udba, br, br->br_perm);
25151 + if (unlikely(err))
25152 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
25154 + /* go on even if err */
25156 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
25158 + di_write_unlock(root);
25159 + err = au_refresh_d(sb);
25160 + e = au_refresh_i(sb);
25161 + if (unlikely(e && !err))
25163 + /* aufs_write_lock() calls ..._child() */
25164 + di_write_lock_child(root);
25166 + au_cpup_attr_all(inode, /*force*/1);
25168 + if (unlikely(err))
25169 + AuIOErr("refresh failed, ignored, %d\n", err);
25172 +/* stop extra interpretation of errno in mount(8), and strange error messages */
25173 +static int cvt_err(int err)
25187 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
25190 + unsigned int mntflags;
25191 + struct au_opts opts;
25192 + struct dentry *root;
25193 + struct inode *inode;
25194 + struct au_sbinfo *sbinfo;
25197 + root = sb->s_root;
25198 + if (!data || !*data) {
25199 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
25201 + di_write_lock_child(root);
25202 + err = au_opts_verify(sb, *flags, /*pending*/0);
25203 + aufs_write_unlock(root);
25209 + memset(&opts, 0, sizeof(opts));
25210 + opts.opt = (void *)__get_free_page(GFP_NOFS);
25211 + if (unlikely(!opts.opt))
25213 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
25214 + opts.flags = AuOpts_REMOUNT;
25215 + opts.sb_flags = *flags;
25217 + /* parse it before aufs lock */
25218 + err = au_opts_parse(sb, data, &opts);
25219 + if (unlikely(err))
25222 + sbinfo = au_sbi(sb);
25223 + inode = root->d_inode;
25224 + mutex_lock(&inode->i_mutex);
25225 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
25226 + if (unlikely(err))
25228 + di_write_lock_child(root);
25230 + /* au_opts_remount() may return an error */
25231 + err = au_opts_remount(sb, &opts);
25232 + au_opts_free(&opts);
25234 + if (au_ftest_opts(opts.flags, REFRESH))
25235 + au_remount_refresh(sb);
25237 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
25238 + mntflags = au_mntflags(sb);
25239 + do_dx = !!au_opt_test(mntflags, DIO);
25240 + au_dy_arefresh(do_dx);
25243 + aufs_write_unlock(root);
25246 + mutex_unlock(&inode->i_mutex);
25248 + free_page((unsigned long)opts.opt);
25250 + err = cvt_err(err);
25255 +static const struct super_operations aufs_sop = {
25256 + .alloc_inode = aufs_alloc_inode,
25257 + .destroy_inode = aufs_destroy_inode,
25258 + /* always deleting, no clearing */
25259 + .drop_inode = generic_delete_inode,
25260 + .show_options = aufs_show_options,
25261 + .statfs = aufs_statfs,
25262 + .put_super = aufs_put_super,
25263 + .sync_fs = aufs_sync_fs,
25264 + .remount_fs = aufs_remount_fs
25267 +/* ---------------------------------------------------------------------- */
25269 +static int alloc_root(struct super_block *sb)
25272 + struct inode *inode;
25273 + struct dentry *root;
25276 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
25277 + err = PTR_ERR(inode);
25278 + if (IS_ERR(inode))
25281 + inode->i_op = &aufs_dir_iop;
25282 + inode->i_fop = &aufs_dir_fop;
25283 + inode->i_mode = S_IFDIR;
25284 + set_nlink(inode, 2);
25285 + unlock_new_inode(inode);
25287 + root = d_make_root(inode);
25288 + if (unlikely(!root))
25290 + err = PTR_ERR(root);
25291 + if (IS_ERR(root))
25294 + err = au_di_init(root);
25296 + sb->s_root = root;
25297 + return 0; /* success */
25305 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
25306 + int silent __maybe_unused)
25309 + struct au_opts opts;
25310 + struct dentry *root;
25311 + struct inode *inode;
25312 + char *arg = raw_data;
25314 + if (unlikely(!arg || !*arg)) {
25316 + pr_err("no arg\n");
25321 + memset(&opts, 0, sizeof(opts));
25322 + opts.opt = (void *)__get_free_page(GFP_NOFS);
25323 + if (unlikely(!opts.opt))
25325 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
25326 + opts.sb_flags = sb->s_flags;
25328 + err = au_si_alloc(sb);
25329 + if (unlikely(err))
25332 + /* all timestamps always follow the ones on the branch */
25333 + sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
25334 + sb->s_op = &aufs_sop;
25335 + sb->s_d_op = &aufs_dop;
25336 + sb->s_magic = AUFS_SUPER_MAGIC;
25337 + sb->s_maxbytes = 0;
25338 + au_export_init(sb);
25340 + err = alloc_root(sb);
25341 + if (unlikely(err)) {
25342 + si_write_unlock(sb);
25345 + root = sb->s_root;
25346 + inode = root->d_inode;
25349 + * actually we can parse options regardless aufs lock here.
25350 + * but at remount time, parsing must be done before aufs lock.
25351 + * so we follow the same rule.
25353 + ii_write_lock_parent(inode);
25354 + aufs_write_unlock(root);
25355 + err = au_opts_parse(sb, arg, &opts);
25356 + if (unlikely(err))
25359 + /* lock vfs_inode first, then aufs. */
25360 + mutex_lock(&inode->i_mutex);
25361 + aufs_write_lock(root);
25362 + err = au_opts_mount(sb, &opts);
25363 + au_opts_free(&opts);
25364 + aufs_write_unlock(root);
25365 + mutex_unlock(&inode->i_mutex);
25367 + goto out_opts; /* success */
25371 + sb->s_root = NULL;
25373 + dbgaufs_si_fin(au_sbi(sb));
25374 + kobject_put(&au_sbi(sb)->si_kobj);
25375 + sb->s_fs_info = NULL;
25377 + free_page((unsigned long)opts.opt);
25380 + err = cvt_err(err);
25385 +/* ---------------------------------------------------------------------- */
25387 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
25388 + const char *dev_name __maybe_unused,
25391 + struct dentry *root;
25392 + struct super_block *sb;
25394 + /* all timestamps always follow the ones on the branch */
25395 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
25396 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
25397 + if (IS_ERR(root))
25401 + si_write_lock(sb, !AuLock_FLUSH);
25402 + sysaufs_brs_add(sb, 0);
25403 + si_write_unlock(sb);
25404 + au_sbilist_add(sb);
25410 +static void aufs_kill_sb(struct super_block *sb)
25412 + struct au_sbinfo *sbinfo;
25414 + sbinfo = au_sbi(sb);
25416 + au_sbilist_del(sb);
25417 + aufs_write_lock(sb->s_root);
25418 + if (sbinfo->si_wbr_create_ops->fin)
25419 + sbinfo->si_wbr_create_ops->fin(sb);
25420 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
25421 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
25422 + au_remount_refresh(sb);
25424 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
25425 + au_plink_put(sb, /*verbose*/1);
25427 + sbinfo->si_sb = NULL;
25428 + aufs_write_unlock(sb->s_root);
25429 + au_nwt_flush(&sbinfo->si_nowait);
25431 + generic_shutdown_super(sb);
25434 +struct file_system_type aufs_fs_type = {
25435 + .name = AUFS_FSTYPE,
25436 + /* a race between rename and others */
25437 + .fs_flags = FS_RENAME_DOES_D_MOVE,
25438 + .mount = aufs_mount,
25439 + .kill_sb = aufs_kill_sb,
25440 + /* no need to __module_get() and module_put(). */
25441 + .owner = THIS_MODULE,
25443 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
25444 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
25445 +++ linux/fs/aufs/super.h 2013-10-26 16:51:32.276373845 +0200
25448 + * Copyright (C) 2005-2013 Junjiro R. Okajima
25450 + * This program, aufs is free software; you can redistribute it and/or modify
25451 + * it under the terms of the GNU General Public License as published by
25452 + * the Free Software Foundation; either version 2 of the License, or
25453 + * (at your option) any later version.
25455 + * This program is distributed in the hope that it will be useful,
25456 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25457 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25458 + * GNU General Public License for more details.
25460 + * You should have received a copy of the GNU General Public License
25461 + * along with this program; if not, write to the Free Software
25462 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25466 + * super_block operations
25469 +#ifndef __AUFS_SUPER_H__
25470 +#define __AUFS_SUPER_H__
25474 +#include <linux/fs.h>
25475 +#include "rwsem.h"
25479 +typedef ssize_t (*au_readf_t)(struct file *, char __user *, size_t, loff_t *);
25480 +typedef ssize_t (*au_writef_t)(struct file *, const char __user *, size_t,
25483 +/* policies to select one among multiple writable branches */
25484 +struct au_wbr_copyup_operations {
25485 + int (*copyup)(struct dentry *dentry);
25488 +#define AuWbr_DIR 1 /* target is a dir */
25489 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
25491 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
25492 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
25493 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
25495 +struct au_wbr_create_operations {
25496 + int (*create)(struct dentry *dentry, unsigned int flags);
25497 + int (*init)(struct super_block *sb);
25498 + int (*fin)(struct super_block *sb);
25501 +struct au_wbr_mfs {
25502 + struct mutex mfs_lock; /* protect this structure */
25503 + unsigned long mfs_jiffy;
25504 + unsigned long mfs_expire;
25505 + aufs_bindex_t mfs_bindex;
25507 + unsigned long long mfsrr_bytes;
25508 + unsigned long long mfsrr_watermark;
25511 +struct pseudo_link {
25513 + struct hlist_node hlist;
25514 + struct rcu_head rcu;
25516 + struct inode *inode;
25519 +#define AuPlink_NHASH 100
25520 +static inline int au_plink_hash(ino_t ino)
25522 + return ino % AuPlink_NHASH;
25526 +struct au_sbinfo {
25527 + /* nowait tasks in the system-wide workqueue */
25528 + struct au_nowait_tasks si_nowait;
25531 + * tried sb->s_umount, but failed due to the dependecy between i_mutex.
25532 + * rwsem for au_sbinfo is necessary.
25534 + struct au_rwsem si_rwsem;
25536 + /* prevent recursive locking in deleting inode */
25538 + unsigned long *bitmap;
25539 + spinlock_t tree_lock;
25540 + struct radix_tree_root tree;
25544 + * dirty approach to protect sb->sb_inodes and ->s_files from remount.
25546 + atomic_long_t si_ninodes, si_nfiles;
25548 + /* branch management */
25549 + unsigned int si_generation;
25551 + /* see above flags */
25552 + unsigned char au_si_status;
25554 + aufs_bindex_t si_bend;
25556 + /* dirty trick to keep br_id plus */
25557 + unsigned int si_last_br_id :
25558 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
25559 + struct au_branch **si_branch;
25561 + /* policy to select a writable branch */
25562 + unsigned char si_wbr_copyup;
25563 + unsigned char si_wbr_create;
25564 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
25565 + struct au_wbr_create_operations *si_wbr_create_ops;
25567 + /* round robin */
25568 + atomic_t si_wbr_rr_next;
25570 + /* most free space */
25571 + struct au_wbr_mfs si_wbr_mfs;
25573 + /* mount flags */
25574 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
25575 + unsigned int si_mntflags;
25577 + /* external inode number (bitmap and translation table) */
25578 + au_readf_t si_xread;
25579 + au_writef_t si_xwrite;
25580 + struct file *si_xib;
25581 + struct mutex si_xib_mtx; /* protect xib members */
25582 + unsigned long *si_xib_buf;
25583 + unsigned long si_xib_last_pindex;
25584 + int si_xib_next_bit;
25585 + aufs_bindex_t si_xino_brid;
25586 + unsigned long si_xino_jiffy;
25587 + unsigned long si_xino_expire;
25588 + /* reserved for future use */
25589 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
25591 +#ifdef CONFIG_AUFS_EXPORT
25592 + /* i_generation */
25593 + struct file *si_xigen;
25594 + atomic_t si_xigen_next;
25597 + /* vdir parameters */
25598 + unsigned long si_rdcache; /* max cache time in jiffies */
25599 + unsigned int si_rdblk; /* deblk size */
25600 + unsigned int si_rdhash; /* hash size */
25603 + * If the number of whiteouts are larger than si_dirwh, leave all of
25604 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
25605 + * future fsck.aufs or kernel thread will remove them later.
25606 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
25608 + unsigned int si_dirwh;
25611 + * rename(2) a directory with all children.
25613 + /* reserved for future use */
25614 + /* int si_rendir; */
25616 + /* pseudo_link list */
25617 + struct au_sphlhead si_plink[AuPlink_NHASH];
25618 + wait_queue_head_t si_plink_wq;
25619 + spinlock_t si_plink_maint_lock;
25620 + pid_t si_plink_maint_pid;
25623 + * sysfs and lifetime management.
25624 + * this is not a small structure and it may be a waste of memory in case
25625 + * of sysfs is disabled, particulary when many aufs-es are mounted.
25626 + * but using sysfs is majority.
25628 + struct kobject si_kobj;
25629 +#ifdef CONFIG_DEBUG_FS
25630 + struct dentry *si_dbgaufs;
25631 + struct dentry *si_dbgaufs_plink;
25632 + struct dentry *si_dbgaufs_xib;
25633 +#ifdef CONFIG_AUFS_EXPORT
25634 + struct dentry *si_dbgaufs_xigen;
25638 +#ifdef CONFIG_AUFS_SBILIST
25639 + struct list_head si_list;
25642 + /* dirty, necessary for unmounting, sysfs and sysrq */
25643 + struct super_block *si_sb;
25646 +/* sbinfo status flags */
25648 + * set true when refresh_dirs() failed at remount time.
25649 + * then try refreshing dirs at access time again.
25650 + * if it is false, refreshing dirs at access time is unnecesary
25652 +#define AuSi_FAILED_REFRESH_DIR 1
25653 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
25654 + unsigned int flag)
25656 + AuRwMustAnyLock(&sbi->si_rwsem);
25657 + return sbi->au_si_status & flag;
25659 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
25660 +#define au_fset_si(sbinfo, name) do { \
25661 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
25662 + (sbinfo)->au_si_status |= AuSi_##name; \
25664 +#define au_fclr_si(sbinfo, name) do { \
25665 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
25666 + (sbinfo)->au_si_status &= ~AuSi_##name; \
25669 +/* ---------------------------------------------------------------------- */
25671 +/* policy to select one among writable branches */
25672 +#define AuWbrCopyup(sbinfo, ...) \
25673 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
25674 +#define AuWbrCreate(sbinfo, ...) \
25675 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
25677 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
25678 +#define AuLock_DW 1 /* write-lock dentry */
25679 +#define AuLock_IR (1 << 1) /* read-lock inode */
25680 +#define AuLock_IW (1 << 2) /* write-lock inode */
25681 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
25682 +#define AuLock_DIR (1 << 4) /* target is a dir */
25683 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
25684 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
25685 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
25686 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
25687 +#define au_fset_lock(flags, name) \
25688 + do { (flags) |= AuLock_##name; } while (0)
25689 +#define au_fclr_lock(flags, name) \
25690 + do { (flags) &= ~AuLock_##name; } while (0)
25692 +/* ---------------------------------------------------------------------- */
25695 +extern struct file_system_type aufs_fs_type;
25696 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
25697 +typedef unsigned long long (*au_arraycb_t)(void *array, unsigned long long max,
25699 +void au_array_free(void *array);
25700 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg);
25701 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
25702 +void au_iarray_free(struct inode **a, unsigned long long max);
25705 +void au_si_free(struct kobject *kobj);
25706 +int au_si_alloc(struct super_block *sb);
25707 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr);
25709 +unsigned int au_sigen_inc(struct super_block *sb);
25710 +aufs_bindex_t au_new_br_id(struct super_block *sb);
25712 +int si_read_lock(struct super_block *sb, int flags);
25713 +int si_write_lock(struct super_block *sb, int flags);
25714 +int aufs_read_lock(struct dentry *dentry, int flags);
25715 +void aufs_read_unlock(struct dentry *dentry, int flags);
25716 +void aufs_write_lock(struct dentry *dentry);
25717 +void aufs_write_unlock(struct dentry *dentry);
25718 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
25719 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
25721 +int si_pid_test_slow(struct super_block *sb);
25722 +void si_pid_set_slow(struct super_block *sb);
25723 +void si_pid_clr_slow(struct super_block *sb);
25725 +/* wbr_policy.c */
25726 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
25727 +extern struct au_wbr_create_operations au_wbr_create_ops[];
25728 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
25729 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
25732 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
25734 +/* ---------------------------------------------------------------------- */
25736 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
25738 + return sb->s_fs_info;
25741 +/* ---------------------------------------------------------------------- */
25743 +#ifdef CONFIG_AUFS_EXPORT
25744 +int au_test_nfsd(void);
25745 +void au_export_init(struct super_block *sb);
25746 +void au_xigen_inc(struct inode *inode);
25747 +int au_xigen_new(struct inode *inode);
25748 +int au_xigen_set(struct super_block *sb, struct file *base);
25749 +void au_xigen_clr(struct super_block *sb);
25751 +static inline int au_busy_or_stale(void)
25753 + if (!au_test_nfsd())
25758 +AuStubInt0(au_test_nfsd, void)
25759 +AuStubVoid(au_export_init, struct super_block *sb)
25760 +AuStubVoid(au_xigen_inc, struct inode *inode)
25761 +AuStubInt0(au_xigen_new, struct inode *inode)
25762 +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base)
25763 +AuStubVoid(au_xigen_clr, struct super_block *sb)
25764 +static inline int au_busy_or_stale(void)
25768 +#endif /* CONFIG_AUFS_EXPORT */
25770 +/* ---------------------------------------------------------------------- */
25772 +#ifdef CONFIG_AUFS_SBILIST
25774 +extern struct au_splhead au_sbilist;
25776 +static inline void au_sbilist_init(void)
25778 + au_spl_init(&au_sbilist);
25781 +static inline void au_sbilist_add(struct super_block *sb)
25783 + au_spl_add(&au_sbi(sb)->si_list, &au_sbilist);
25786 +static inline void au_sbilist_del(struct super_block *sb)
25788 + au_spl_del(&au_sbi(sb)->si_list, &au_sbilist);
25791 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
25792 +static inline void au_sbilist_lock(void)
25794 + spin_lock(&au_sbilist.spin);
25797 +static inline void au_sbilist_unlock(void)
25799 + spin_unlock(&au_sbilist.spin);
25801 +#define AuGFP_SBILIST GFP_ATOMIC
25803 +AuStubVoid(au_sbilist_lock, void)
25804 +AuStubVoid(au_sbilist_unlock, void)
25805 +#define AuGFP_SBILIST GFP_NOFS
25806 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
25808 +AuStubVoid(au_sbilist_init, void)
25809 +AuStubVoid(au_sbilist_add, struct super_block*)
25810 +AuStubVoid(au_sbilist_del, struct super_block*)
25811 +AuStubVoid(au_sbilist_lock, void)
25812 +AuStubVoid(au_sbilist_unlock, void)
25813 +#define AuGFP_SBILIST GFP_NOFS
25816 +/* ---------------------------------------------------------------------- */
25818 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
25821 + * This function is a dynamic '__init' fucntion actually,
25822 + * so the tiny check for si_rwsem is unnecessary.
25824 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
25825 +#ifdef CONFIG_DEBUG_FS
25826 + sbinfo->si_dbgaufs = NULL;
25827 + sbinfo->si_dbgaufs_plink = NULL;
25828 + sbinfo->si_dbgaufs_xib = NULL;
25829 +#ifdef CONFIG_AUFS_EXPORT
25830 + sbinfo->si_dbgaufs_xigen = NULL;
25835 +/* ---------------------------------------------------------------------- */
25837 +static inline pid_t si_pid_bit(void)
25839 + /* the origin of pid is 1, but the bitmap's is 0 */
25840 + return current->pid - 1;
25843 +static inline int si_pid_test(struct super_block *sb)
25845 + pid_t bit = si_pid_bit();
25846 + if (bit < PID_MAX_DEFAULT)
25847 + return test_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
25849 + return si_pid_test_slow(sb);
25852 +static inline void si_pid_set(struct super_block *sb)
25854 + pid_t bit = si_pid_bit();
25855 + if (bit < PID_MAX_DEFAULT) {
25856 + AuDebugOn(test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
25857 + set_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
25860 + si_pid_set_slow(sb);
25863 +static inline void si_pid_clr(struct super_block *sb)
25865 + pid_t bit = si_pid_bit();
25866 + if (bit < PID_MAX_DEFAULT) {
25867 + AuDebugOn(!test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
25868 + clear_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
25871 + si_pid_clr_slow(sb);
25874 +/* ---------------------------------------------------------------------- */
25876 +/* lock superblock. mainly for entry point functions */
25878 + * __si_read_lock, __si_write_lock,
25879 + * __si_read_unlock, __si_write_unlock, __si_downgrade_lock
25881 +AuSimpleRwsemFuncs(__si, struct super_block *sb, &au_sbi(sb)->si_rwsem);
25883 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
25884 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
25885 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
25887 +static inline void si_noflush_read_lock(struct super_block *sb)
25889 + __si_read_lock(sb);
25893 +static inline int si_noflush_read_trylock(struct super_block *sb)
25895 + int locked = __si_read_trylock(sb);
25901 +static inline void si_noflush_write_lock(struct super_block *sb)
25903 + __si_write_lock(sb);
25907 +static inline int si_noflush_write_trylock(struct super_block *sb)
25909 + int locked = __si_write_trylock(sb);
25915 +#if 0 /* unused */
25916 +static inline int si_read_trylock(struct super_block *sb, int flags)
25918 + if (au_ftest_lock(flags, FLUSH))
25919 + au_nwt_flush(&au_sbi(sb)->si_nowait);
25920 + return si_noflush_read_trylock(sb);
25924 +static inline void si_read_unlock(struct super_block *sb)
25927 + __si_read_unlock(sb);
25930 +#if 0 /* unused */
25931 +static inline int si_write_trylock(struct super_block *sb, int flags)
25933 + if (au_ftest_lock(flags, FLUSH))
25934 + au_nwt_flush(&au_sbi(sb)->si_nowait);
25935 + return si_noflush_write_trylock(sb);
25939 +static inline void si_write_unlock(struct super_block *sb)
25942 + __si_write_unlock(sb);
25945 +#if 0 /* unused */
25946 +static inline void si_downgrade_lock(struct super_block *sb)
25948 + __si_downgrade_lock(sb);
25952 +/* ---------------------------------------------------------------------- */
25954 +static inline aufs_bindex_t au_sbend(struct super_block *sb)
25956 + SiMustAnyLock(sb);
25957 + return au_sbi(sb)->si_bend;
25960 +static inline unsigned int au_mntflags(struct super_block *sb)
25962 + SiMustAnyLock(sb);
25963 + return au_sbi(sb)->si_mntflags;
25966 +static inline unsigned int au_sigen(struct super_block *sb)
25968 + SiMustAnyLock(sb);
25969 + return au_sbi(sb)->si_generation;
25972 +static inline void au_ninodes_inc(struct super_block *sb)
25974 + atomic_long_inc(&au_sbi(sb)->si_ninodes);
25977 +static inline void au_ninodes_dec(struct super_block *sb)
25979 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_ninodes));
25980 + atomic_long_dec(&au_sbi(sb)->si_ninodes);
25983 +static inline void au_nfiles_inc(struct super_block *sb)
25985 + atomic_long_inc(&au_sbi(sb)->si_nfiles);
25988 +static inline void au_nfiles_dec(struct super_block *sb)
25990 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_nfiles));
25991 + atomic_long_dec(&au_sbi(sb)->si_nfiles);
25994 +static inline struct au_branch *au_sbr(struct super_block *sb,
25995 + aufs_bindex_t bindex)
25997 + SiMustAnyLock(sb);
25998 + return au_sbi(sb)->si_branch[0 + bindex];
26001 +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid)
26003 + SiMustWriteLock(sb);
26004 + au_sbi(sb)->si_xino_brid = brid;
26007 +static inline aufs_bindex_t au_xino_brid(struct super_block *sb)
26009 + SiMustAnyLock(sb);
26010 + return au_sbi(sb)->si_xino_brid;
26013 +#endif /* __KERNEL__ */
26014 +#endif /* __AUFS_SUPER_H__ */
26015 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
26016 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
26017 +++ linux/fs/aufs/sysaufs.c 2013-07-06 13:20:47.753531903 +0200
26020 + * Copyright (C) 2005-2013 Junjiro R. Okajima
26022 + * This program, aufs is free software; you can redistribute it and/or modify
26023 + * it under the terms of the GNU General Public License as published by
26024 + * the Free Software Foundation; either version 2 of the License, or
26025 + * (at your option) any later version.
26027 + * This program is distributed in the hope that it will be useful,
26028 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26029 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26030 + * GNU General Public License for more details.
26032 + * You should have received a copy of the GNU General Public License
26033 + * along with this program; if not, write to the Free Software
26034 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26038 + * sysfs interface and lifetime management
26039 + * they are necessary regardless sysfs is disabled.
26042 +#include <linux/random.h>
26045 +unsigned long sysaufs_si_mask;
26046 +struct kset *sysaufs_kset;
26048 +#define AuSiAttr(_name) { \
26049 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
26050 + .show = sysaufs_si_##_name, \
26053 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
26054 +struct attribute *sysaufs_si_attrs[] = {
26055 + &sysaufs_si_attr_xi_path.attr,
26059 +static const struct sysfs_ops au_sbi_ops = {
26060 + .show = sysaufs_si_show
26063 +static struct kobj_type au_sbi_ktype = {
26064 + .release = au_si_free,
26065 + .sysfs_ops = &au_sbi_ops,
26066 + .default_attrs = sysaufs_si_attrs
26069 +/* ---------------------------------------------------------------------- */
26071 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
26075 + sbinfo->si_kobj.kset = sysaufs_kset;
26076 + /* cf. sysaufs_name() */
26077 + err = kobject_init_and_add
26078 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
26079 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
26081 + dbgaufs_si_null(sbinfo);
26083 + err = dbgaufs_si_init(sbinfo);
26084 + if (unlikely(err))
26085 + kobject_put(&sbinfo->si_kobj);
26090 +void sysaufs_fin(void)
26093 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
26094 + kset_unregister(sysaufs_kset);
26097 +int __init sysaufs_init(void)
26102 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
26103 + } while (!sysaufs_si_mask);
26106 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
26107 + if (unlikely(!sysaufs_kset))
26109 + err = PTR_ERR(sysaufs_kset);
26110 + if (IS_ERR(sysaufs_kset))
26112 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
26113 + if (unlikely(err)) {
26114 + kset_unregister(sysaufs_kset);
26118 + err = dbgaufs_init();
26119 + if (unlikely(err))
26124 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
26125 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
26126 +++ linux/fs/aufs/sysaufs.h 2013-07-06 13:20:47.753531903 +0200
26129 + * Copyright (C) 2005-2013 Junjiro R. Okajima
26131 + * This program, aufs is free software; you can redistribute it and/or modify
26132 + * it under the terms of the GNU General Public License as published by
26133 + * the Free Software Foundation; either version 2 of the License, or
26134 + * (at your option) any later version.
26136 + * This program is distributed in the hope that it will be useful,
26137 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26138 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26139 + * GNU General Public License for more details.
26141 + * You should have received a copy of the GNU General Public License
26142 + * along with this program; if not, write to the Free Software
26143 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26147 + * sysfs interface and mount lifetime management
26150 +#ifndef __SYSAUFS_H__
26151 +#define __SYSAUFS_H__
26155 +#include <linux/sysfs.h>
26156 +#include "module.h"
26158 +struct super_block;
26161 +struct sysaufs_si_attr {
26162 + struct attribute attr;
26163 + int (*show)(struct seq_file *seq, struct super_block *sb);
26166 +/* ---------------------------------------------------------------------- */
26169 +extern unsigned long sysaufs_si_mask;
26170 +extern struct kset *sysaufs_kset;
26171 +extern struct attribute *sysaufs_si_attrs[];
26172 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
26173 +int __init sysaufs_init(void);
26174 +void sysaufs_fin(void);
26176 +/* ---------------------------------------------------------------------- */
26178 +/* some people doesn't like to show a pointer in kernel */
26179 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
26181 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
26184 +#define SysaufsSiNamePrefix "si_"
26185 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
26186 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
26188 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
26189 + sysaufs_si_id(sbinfo));
26193 +#ifdef CONFIG_SYSFS
26195 +extern struct attribute_group *sysaufs_attr_group;
26197 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
26198 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
26201 +void sysaufs_br_init(struct au_branch *br);
26202 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
26203 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
26205 +#define sysaufs_brs_init() do {} while (0)
26208 +#define sysaufs_attr_group NULL
26210 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
26213 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
26219 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
26220 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
26221 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
26223 +static inline void sysaufs_brs_init(void)
26228 +#endif /* CONFIG_SYSFS */
26230 +#endif /* __KERNEL__ */
26231 +#endif /* __SYSAUFS_H__ */
26232 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
26233 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
26234 +++ linux/fs/aufs/sysfs.c 2013-10-26 16:51:32.276373845 +0200
26237 + * Copyright (C) 2005-2013 Junjiro R. Okajima
26239 + * This program, aufs is free software; you can redistribute it and/or modify
26240 + * it under the terms of the GNU General Public License as published by
26241 + * the Free Software Foundation; either version 2 of the License, or
26242 + * (at your option) any later version.
26244 + * This program is distributed in the hope that it will be useful,
26245 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26246 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26247 + * GNU General Public License for more details.
26249 + * You should have received a copy of the GNU General Public License
26250 + * along with this program; if not, write to the Free Software
26251 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26255 + * sysfs interface
26258 +#include <linux/seq_file.h>
26261 +#ifdef CONFIG_AUFS_FS_MODULE
26262 +/* this entry violates the "one line per file" policy of sysfs */
26263 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
26267 + static char *conf =
26268 +/* this file is generated at compiling */
26269 +#include "conf.str"
26272 + err = snprintf(buf, PAGE_SIZE, conf);
26273 + if (unlikely(err >= PAGE_SIZE))
26278 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
26281 +static struct attribute *au_attr[] = {
26282 +#ifdef CONFIG_AUFS_FS_MODULE
26283 + &au_config_attr.attr,
26285 + NULL, /* need to NULL terminate the list of attributes */
26288 +static struct attribute_group sysaufs_attr_group_body = {
26292 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
26294 +/* ---------------------------------------------------------------------- */
26296 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
26300 + SiMustAnyLock(sb);
26303 + if (au_opt_test(au_mntflags(sb), XINO)) {
26304 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
26305 + seq_putc(seq, '\n');
26311 + * the lifetime of branch is independent from the entry under sysfs.
26312 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
26315 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
26316 + aufs_bindex_t bindex, int idx)
26319 + struct path path;
26320 + struct dentry *root;
26321 + struct au_branch *br;
26324 + AuDbg("b%d\n", bindex);
26327 + root = sb->s_root;
26328 + di_read_lock_parent(root, !AuLock_IR);
26329 + br = au_sbr(sb, bindex);
26332 + case AuBrSysfs_BR:
26333 + path.mnt = au_br_mnt(br);
26334 + path.dentry = au_h_dptr(root, bindex);
26335 + au_seq_path(seq, &path);
26336 + di_read_unlock(root, !AuLock_IR);
26337 + perm = au_optstr_br_perm(br->br_perm);
26339 + err = seq_printf(seq, "=%s\n", perm);
26346 + case AuBrSysfs_BRID:
26347 + err = seq_printf(seq, "%d\n", br->br_id);
26348 + di_read_unlock(root, !AuLock_IR);
26357 +/* ---------------------------------------------------------------------- */
26359 +static struct seq_file *au_seq(char *p, ssize_t len)
26361 + struct seq_file *seq;
26363 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
26365 + /* mutex_init(&seq.lock); */
26368 + return seq; /* success */
26371 + seq = ERR_PTR(-ENOMEM);
26375 +#define SysaufsBr_PREFIX "br"
26376 +#define SysaufsBrid_PREFIX "brid"
26378 +/* todo: file size may exceed PAGE_SIZE */
26379 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
26385 + aufs_bindex_t bend;
26386 + struct au_sbinfo *sbinfo;
26387 + struct super_block *sb;
26388 + struct seq_file *seq;
26390 + struct attribute **cattr;
26392 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
26393 + sb = sbinfo->si_sb;
26396 + * prevent a race condition between sysfs and aufs.
26397 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
26398 + * prohibits maintaining the sysfs entries.
26399 + * hew we acquire read lock after sysfs_get_active_two().
26400 + * on the other hand, the remount process may maintain the sysfs/aufs
26401 + * entries after acquiring write lock.
26402 + * it can cause a deadlock.
26403 + * simply we gave up processing read here.
26406 + if (unlikely(!si_noflush_read_trylock(sb)))
26409 + seq = au_seq(buf, PAGE_SIZE);
26410 + err = PTR_ERR(seq);
26414 + name = (void *)attr->name;
26415 + cattr = sysaufs_si_attrs;
26417 + if (!strcmp(name, (*cattr)->name)) {
26418 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
26425 + if (!strncmp(name, SysaufsBrid_PREFIX,
26426 + sizeof(SysaufsBrid_PREFIX) - 1)) {
26427 + idx = AuBrSysfs_BRID;
26428 + name += sizeof(SysaufsBrid_PREFIX) - 1;
26429 + } else if (!strncmp(name, SysaufsBr_PREFIX,
26430 + sizeof(SysaufsBr_PREFIX) - 1)) {
26431 + idx = AuBrSysfs_BR;
26432 + name += sizeof(SysaufsBr_PREFIX) - 1;
26436 + err = kstrtol(name, 10, &l);
26438 + bend = au_sbend(sb);
26440 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
26447 + err = seq->count;
26448 + /* sysfs limit */
26449 + if (unlikely(err == PAGE_SIZE))
26454 + si_read_unlock(sb);
26459 +/* ---------------------------------------------------------------------- */
26461 +void sysaufs_br_init(struct au_branch *br)
26464 + struct au_brsysfs *br_sysfs;
26465 + struct attribute *attr;
26467 + br_sysfs = br->br_sysfs;
26468 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
26469 + attr = &br_sysfs->attr;
26470 + sysfs_attr_init(attr);
26471 + attr->name = br_sysfs->name;
26472 + attr->mode = S_IRUGO;
26477 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
26479 + struct au_branch *br;
26480 + struct kobject *kobj;
26481 + struct au_brsysfs *br_sysfs;
26483 + aufs_bindex_t bend;
26485 + dbgaufs_brs_del(sb, bindex);
26487 + if (!sysaufs_brs)
26490 + kobj = &au_sbi(sb)->si_kobj;
26491 + bend = au_sbend(sb);
26492 + for (; bindex <= bend; bindex++) {
26493 + br = au_sbr(sb, bindex);
26494 + br_sysfs = br->br_sysfs;
26495 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
26496 + sysfs_remove_file(kobj, &br_sysfs->attr);
26502 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
26505 + aufs_bindex_t bend;
26506 + struct kobject *kobj;
26507 + struct au_branch *br;
26508 + struct au_brsysfs *br_sysfs;
26510 + dbgaufs_brs_add(sb, bindex);
26512 + if (!sysaufs_brs)
26515 + kobj = &au_sbi(sb)->si_kobj;
26516 + bend = au_sbend(sb);
26517 + for (; bindex <= bend; bindex++) {
26518 + br = au_sbr(sb, bindex);
26519 + br_sysfs = br->br_sysfs;
26520 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
26521 + SysaufsBr_PREFIX "%d", bindex);
26522 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
26523 + SysaufsBrid_PREFIX "%d", bindex);
26524 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
26525 + err = sysfs_create_file(kobj, &br_sysfs->attr);
26526 + if (unlikely(err))
26527 + pr_warn("failed %s under sysfs(%d)\n",
26528 + br_sysfs->name, err);
26533 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
26534 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
26535 +++ linux/fs/aufs/sysrq.c 2013-07-06 13:20:47.753531903 +0200
26538 + * Copyright (C) 2005-2013 Junjiro R. Okajima
26540 + * This program, aufs is free software; you can redistribute it and/or modify
26541 + * it under the terms of the GNU General Public License as published by
26542 + * the Free Software Foundation; either version 2 of the License, or
26543 + * (at your option) any later version.
26545 + * This program is distributed in the hope that it will be useful,
26546 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26547 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26548 + * GNU General Public License for more details.
26550 + * You should have received a copy of the GNU General Public License
26551 + * along with this program; if not, write to the Free Software
26552 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26556 + * magic sysrq hanlder
26559 +/* #include <linux/sysrq.h> */
26560 +#include <linux/writeback.h>
26563 +/* ---------------------------------------------------------------------- */
26565 +static void sysrq_sb(struct super_block *sb)
26568 + struct au_sbinfo *sbinfo;
26569 + struct file *file;
26571 + plevel = au_plevel;
26572 + au_plevel = KERN_WARNING;
26574 + /* since we define pr_fmt, call printk directly */
26575 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
26577 + sbinfo = au_sbi(sb);
26578 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
26579 + pr("superblock\n");
26583 + pr("root dentry\n");
26584 + au_dpri_dentry(sb->s_root);
26585 + pr("root inode\n");
26586 + au_dpri_inode(sb->s_root->d_inode);
26591 + int err, i, j, ndentry;
26592 + struct au_dcsub_pages dpages;
26593 + struct au_dpage *dpage;
26595 + err = au_dpages_init(&dpages, GFP_ATOMIC);
26596 + if (unlikely(err))
26598 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
26600 + for (i = 0; i < dpages.ndpage; i++) {
26601 + dpage = dpages.dpages + i;
26602 + ndentry = dpage->ndentry;
26603 + for (j = 0; j < ndentry; j++)
26604 + au_dpri_dentry(dpage->dentries[j]);
26606 + au_dpages_free(&dpages);
26613 + pr("isolated inode\n");
26614 + spin_lock(&inode_sb_list_lock);
26615 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
26616 + spin_lock(&i->i_lock);
26617 + if (1 || hlist_empty(&i->i_dentry))
26618 + au_dpri_inode(i);
26619 + spin_unlock(&i->i_lock);
26621 + spin_unlock(&inode_sb_list_lock);
26625 + lg_global_lock(&files_lglock);
26626 + do_file_list_for_each_entry(sb, file) {
26628 + mode = file_inode(file)->i_mode;
26629 + if (!special_file(mode) || au_special_file(mode))
26630 + au_dpri_file(file);
26631 + } while_file_list_for_each_entry;
26632 + lg_global_unlock(&files_lglock);
26636 + au_plevel = plevel;
26639 +/* ---------------------------------------------------------------------- */
26641 +/* module parameter */
26642 +static char *aufs_sysrq_key = "a";
26643 +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO);
26644 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
26646 +static void au_sysrq(int key __maybe_unused)
26648 + struct au_sbinfo *sbinfo;
26651 + au_sbilist_lock();
26652 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
26653 + sysrq_sb(sbinfo->si_sb);
26654 + au_sbilist_unlock();
26658 +static struct sysrq_key_op au_sysrq_op = {
26659 + .handler = au_sysrq,
26660 + .help_msg = "Aufs",
26661 + .action_msg = "Aufs",
26662 + .enable_mask = SYSRQ_ENABLE_DUMP
26665 +/* ---------------------------------------------------------------------- */
26667 +int __init au_sysrq_init(void)
26673 + key = *aufs_sysrq_key;
26674 + if ('a' <= key && key <= 'z')
26675 + err = register_sysrq_key(key, &au_sysrq_op);
26676 + if (unlikely(err))
26677 + pr_err("err %d, sysrq=%c\n", err, key);
26681 +void au_sysrq_fin(void)
26684 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
26685 + if (unlikely(err))
26686 + pr_err("err %d (ignored)\n", err);
26688 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
26689 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
26690 +++ linux/fs/aufs/vdir.c 2013-10-26 16:51:29.586298347 +0200
26693 + * Copyright (C) 2005-2013 Junjiro R. Okajima
26695 + * This program, aufs is free software; you can redistribute it and/or modify
26696 + * it under the terms of the GNU General Public License as published by
26697 + * the Free Software Foundation; either version 2 of the License, or
26698 + * (at your option) any later version.
26700 + * This program is distributed in the hope that it will be useful,
26701 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26702 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26703 + * GNU General Public License for more details.
26705 + * You should have received a copy of the GNU General Public License
26706 + * along with this program; if not, write to the Free Software
26707 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26711 + * virtual or vertical directory
26716 +static unsigned int calc_size(int nlen)
26718 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
26721 +static int set_deblk_end(union au_vdir_deblk_p *p,
26722 + union au_vdir_deblk_p *deblk_end)
26724 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
26725 + p->de->de_str.len = 0;
26729 + return -1; /* error */
26732 +/* returns true or false */
26733 +static int is_deblk_end(union au_vdir_deblk_p *p,
26734 + union au_vdir_deblk_p *deblk_end)
26736 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
26737 + return !p->de->de_str.len;
26741 +static unsigned char *last_deblk(struct au_vdir *vdir)
26743 + return vdir->vd_deblk[vdir->vd_nblk - 1];
26746 +/* ---------------------------------------------------------------------- */
26748 +/* estimate the apropriate size for name hash table */
26749 +unsigned int au_rdhash_est(loff_t sz)
26757 + if (sz < AUFS_RDHASH_DEF)
26758 + n = AUFS_RDHASH_DEF;
26759 + /* pr_info("n %u\n", n); */
26764 + * the allocated memory has to be freed by
26765 + * au_nhash_wh_free() or au_nhash_de_free().
26767 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
26769 + struct hlist_head *head;
26772 + head = kmalloc(sizeof(*nhash->nh_head) * num_hash, gfp);
26774 + nhash->nh_num = num_hash;
26775 + nhash->nh_head = head;
26776 + for (u = 0; u < num_hash; u++)
26777 + INIT_HLIST_HEAD(head++);
26778 + return 0; /* success */
26784 +static void nhash_count(struct hlist_head *head)
26788 + struct hlist_node *pos;
26791 + hlist_for_each(pos, head)
26793 + pr_info("%lu\n", n);
26797 +static void au_nhash_wh_do_free(struct hlist_head *head)
26799 + struct au_vdir_wh *pos;
26800 + struct hlist_node *node;
26802 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
26806 +static void au_nhash_de_do_free(struct hlist_head *head)
26808 + struct au_vdir_dehstr *pos;
26809 + struct hlist_node *node;
26811 + hlist_for_each_entry_safe(pos, node, head, hash)
26812 + au_cache_free_vdir_dehstr(pos);
26815 +static void au_nhash_do_free(struct au_nhash *nhash,
26816 + void (*free)(struct hlist_head *head))
26819 + struct hlist_head *head;
26821 + n = nhash->nh_num;
26825 + head = nhash->nh_head;
26826 + while (n-- > 0) {
26827 + nhash_count(head);
26830 + kfree(nhash->nh_head);
26833 +void au_nhash_wh_free(struct au_nhash *whlist)
26835 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
26838 +static void au_nhash_de_free(struct au_nhash *delist)
26840 + au_nhash_do_free(delist, au_nhash_de_do_free);
26843 +/* ---------------------------------------------------------------------- */
26845 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
26849 + unsigned int u, n;
26850 + struct hlist_head *head;
26851 + struct au_vdir_wh *pos;
26854 + n = whlist->nh_num;
26855 + head = whlist->nh_head;
26856 + for (u = 0; u < n; u++, head++)
26857 + hlist_for_each_entry(pos, head, wh_hash)
26858 + if (pos->wh_bindex == btgt && ++num > limit)
26863 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
26864 + unsigned char *name,
26865 + unsigned int len)
26868 + /* const unsigned int magic_bit = 12; */
26870 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
26875 + /* v = hash_long(v, magic_bit); */
26876 + v %= nhash->nh_num;
26877 + return nhash->nh_head + v;
26880 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
26883 + return str->len == nlen && !memcmp(str->name, name, nlen);
26886 +/* returns found or not */
26887 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
26889 + struct hlist_head *head;
26890 + struct au_vdir_wh *pos;
26891 + struct au_vdir_destr *str;
26893 + head = au_name_hash(whlist, name, nlen);
26894 + hlist_for_each_entry(pos, head, wh_hash) {
26895 + str = &pos->wh_str;
26896 + AuDbg("%.*s\n", str->len, str->name);
26897 + if (au_nhash_test_name(str, name, nlen))
26903 +/* returns found(true) or not */
26904 +static int test_known(struct au_nhash *delist, char *name, int nlen)
26906 + struct hlist_head *head;
26907 + struct au_vdir_dehstr *pos;
26908 + struct au_vdir_destr *str;
26910 + head = au_name_hash(delist, name, nlen);
26911 + hlist_for_each_entry(pos, head, hash) {
26913 + AuDbg("%.*s\n", str->len, str->name);
26914 + if (au_nhash_test_name(str, name, nlen))
26920 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
26921 + unsigned char d_type)
26923 +#ifdef CONFIG_AUFS_SHWH
26924 + wh->wh_ino = ino;
26925 + wh->wh_type = d_type;
26929 +/* ---------------------------------------------------------------------- */
26931 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
26932 + unsigned int d_type, aufs_bindex_t bindex,
26933 + unsigned char shwh)
26936 + struct au_vdir_destr *str;
26937 + struct au_vdir_wh *wh;
26939 + AuDbg("%.*s\n", nlen, name);
26940 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
26943 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
26944 + if (unlikely(!wh))
26948 + wh->wh_bindex = bindex;
26950 + au_shwh_init_wh(wh, ino, d_type);
26951 + str = &wh->wh_str;
26953 + memcpy(str->name, name, nlen);
26954 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
26961 +static int append_deblk(struct au_vdir *vdir)
26964 + unsigned long ul;
26965 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
26966 + union au_vdir_deblk_p p, deblk_end;
26967 + unsigned char **o;
26970 + o = krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
26972 + if (unlikely(!o))
26975 + vdir->vd_deblk = o;
26976 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
26978 + ul = vdir->vd_nblk++;
26979 + vdir->vd_deblk[ul] = p.deblk;
26980 + vdir->vd_last.ul = ul;
26981 + vdir->vd_last.p.deblk = p.deblk;
26982 + deblk_end.deblk = p.deblk + deblk_sz;
26983 + err = set_deblk_end(&p, &deblk_end);
26990 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
26991 + unsigned int d_type, struct au_nhash *delist)
26995 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
26996 + union au_vdir_deblk_p p, *room, deblk_end;
26997 + struct au_vdir_dehstr *dehstr;
26999 + p.deblk = last_deblk(vdir);
27000 + deblk_end.deblk = p.deblk + deblk_sz;
27001 + room = &vdir->vd_last.p;
27002 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
27003 + || !is_deblk_end(room, &deblk_end));
27005 + sz = calc_size(nlen);
27006 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
27007 + err = append_deblk(vdir);
27008 + if (unlikely(err))
27011 + p.deblk = last_deblk(vdir);
27012 + deblk_end.deblk = p.deblk + deblk_sz;
27014 + AuDebugOn(room->deblk != p.deblk);
27018 + dehstr = au_cache_alloc_vdir_dehstr();
27019 + if (unlikely(!dehstr))
27022 + dehstr->str = &room->de->de_str;
27023 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
27024 + room->de->de_ino = ino;
27025 + room->de->de_type = d_type;
27026 + room->de->de_str.len = nlen;
27027 + memcpy(room->de->de_str.name, name, nlen);
27030 + room->deblk += sz;
27031 + if (unlikely(set_deblk_end(room, &deblk_end)))
27032 + err = append_deblk(vdir);
27039 +/* ---------------------------------------------------------------------- */
27041 +void au_vdir_free(struct au_vdir *vdir)
27043 + unsigned char **deblk;
27045 + deblk = vdir->vd_deblk;
27046 + while (vdir->vd_nblk--)
27048 + kfree(vdir->vd_deblk);
27049 + au_cache_free_vdir(vdir);
27052 +static struct au_vdir *alloc_vdir(struct file *file)
27054 + struct au_vdir *vdir;
27055 + struct super_block *sb;
27058 + sb = file->f_dentry->d_sb;
27059 + SiMustAnyLock(sb);
27062 + vdir = au_cache_alloc_vdir();
27063 + if (unlikely(!vdir))
27066 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
27067 + if (unlikely(!vdir->vd_deblk))
27070 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
27071 + if (!vdir->vd_deblk_sz) {
27072 + /* estimate the apropriate size for deblk */
27073 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
27074 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
27076 + vdir->vd_nblk = 0;
27077 + vdir->vd_version = 0;
27078 + vdir->vd_jiffy = 0;
27079 + err = append_deblk(vdir);
27081 + return vdir; /* success */
27083 + kfree(vdir->vd_deblk);
27086 + au_cache_free_vdir(vdir);
27088 + vdir = ERR_PTR(err);
27092 +static int reinit_vdir(struct au_vdir *vdir)
27095 + union au_vdir_deblk_p p, deblk_end;
27097 + while (vdir->vd_nblk > 1) {
27098 + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
27099 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
27102 + p.deblk = vdir->vd_deblk[0];
27103 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
27104 + err = set_deblk_end(&p, &deblk_end);
27105 + /* keep vd_dblk_sz */
27106 + vdir->vd_last.ul = 0;
27107 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
27108 + vdir->vd_version = 0;
27109 + vdir->vd_jiffy = 0;
27114 +/* ---------------------------------------------------------------------- */
27116 +#define AuFillVdir_CALLED 1
27117 +#define AuFillVdir_WHABLE (1 << 1)
27118 +#define AuFillVdir_SHWH (1 << 2)
27119 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
27120 +#define au_fset_fillvdir(flags, name) \
27121 + do { (flags) |= AuFillVdir_##name; } while (0)
27122 +#define au_fclr_fillvdir(flags, name) \
27123 + do { (flags) &= ~AuFillVdir_##name; } while (0)
27125 +#ifndef CONFIG_AUFS_SHWH
27126 +#undef AuFillVdir_SHWH
27127 +#define AuFillVdir_SHWH 0
27130 +struct fillvdir_arg {
27131 + struct dir_context ctx;
27132 + struct file *file;
27133 + struct au_vdir *vdir;
27134 + struct au_nhash delist;
27135 + struct au_nhash whlist;
27136 + aufs_bindex_t bindex;
27137 + unsigned int flags;
27141 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
27142 + loff_t offset __maybe_unused, u64 h_ino,
27143 + unsigned int d_type)
27145 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
27146 + char *name = (void *)__name;
27147 + struct super_block *sb;
27149 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
27152 + sb = arg->file->f_dentry->d_sb;
27153 + au_fset_fillvdir(arg->flags, CALLED);
27155 + if (nlen <= AUFS_WH_PFX_LEN
27156 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
27157 + if (test_known(&arg->delist, name, nlen)
27158 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
27159 + goto out; /* already exists or whiteouted */
27161 + sb = arg->file->f_dentry->d_sb;
27162 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
27164 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
27165 + d_type = DT_UNKNOWN;
27166 + arg->err = append_de(arg->vdir, name, nlen, ino,
27167 + d_type, &arg->delist);
27169 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
27170 + name += AUFS_WH_PFX_LEN;
27171 + nlen -= AUFS_WH_PFX_LEN;
27172 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
27173 + goto out; /* already whiteouted */
27176 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
27179 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
27180 + d_type = DT_UNKNOWN;
27181 + arg->err = au_nhash_append_wh
27182 + (&arg->whlist, name, nlen, ino, d_type,
27183 + arg->bindex, shwh);
27189 + arg->vdir->vd_jiffy = jiffies;
27191 + AuTraceErr(arg->err);
27195 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
27196 + struct au_nhash *whlist, struct au_nhash *delist)
27198 +#ifdef CONFIG_AUFS_SHWH
27200 + unsigned int nh, u;
27201 + struct hlist_head *head;
27202 + struct au_vdir_wh *pos;
27203 + struct hlist_node *n;
27205 + struct au_vdir_destr *destr;
27207 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
27210 + o = p = (void *)__get_free_page(GFP_NOFS);
27211 + if (unlikely(!p))
27215 + nh = whlist->nh_num;
27216 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
27217 + p += AUFS_WH_PFX_LEN;
27218 + for (u = 0; u < nh; u++) {
27219 + head = whlist->nh_head + u;
27220 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
27221 + destr = &pos->wh_str;
27222 + memcpy(p, destr->name, destr->len);
27223 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
27224 + pos->wh_ino, pos->wh_type, delist);
27225 + if (unlikely(err))
27230 + free_page((unsigned long)o);
27240 +static int au_do_read_vdir(struct fillvdir_arg *arg)
27243 + unsigned int rdhash;
27245 + aufs_bindex_t bend, bindex, bstart;
27246 + unsigned char shwh;
27247 + struct file *hf, *file;
27248 + struct super_block *sb;
27250 + file = arg->file;
27251 + sb = file->f_dentry->d_sb;
27252 + SiMustAnyLock(sb);
27254 + rdhash = au_sbi(sb)->si_rdhash;
27256 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
27257 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
27258 + if (unlikely(err))
27260 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
27261 + if (unlikely(err))
27267 + if (au_opt_test(au_mntflags(sb), SHWH)) {
27269 + au_fset_fillvdir(arg->flags, SHWH);
27271 + bstart = au_fbstart(file);
27272 + bend = au_fbend_dir(file);
27273 + for (bindex = bstart; !err && bindex <= bend; bindex++) {
27274 + hf = au_hf_dir(file, bindex);
27278 + offset = vfsub_llseek(hf, 0, SEEK_SET);
27280 + if (unlikely(offset))
27283 + arg->bindex = bindex;
27284 + au_fclr_fillvdir(arg->flags, WHABLE);
27286 + || (bindex != bend
27287 + && au_br_whable(au_sbr_perm(sb, bindex))))
27288 + au_fset_fillvdir(arg->flags, WHABLE);
27291 + au_fclr_fillvdir(arg->flags, CALLED);
27293 + err = vfsub_iterate_dir(hf, &arg->ctx);
27296 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
27299 + * dir_relax() may be good for concurrency, but aufs should not
27300 + * use it since it will cause a lockdep problem.
27304 + if (!err && shwh)
27305 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
27307 + au_nhash_wh_free(&arg->whlist);
27310 + au_nhash_de_free(&arg->delist);
27315 +static int read_vdir(struct file *file, int may_read)
27318 + unsigned long expire;
27319 + unsigned char do_read;
27320 + struct fillvdir_arg arg = {
27322 + .actor = au_diractor(fillvdir)
27325 + struct inode *inode;
27326 + struct au_vdir *vdir, *allocated;
27329 + inode = file_inode(file);
27330 + IMustLock(inode);
27331 + SiMustAnyLock(inode->i_sb);
27333 + allocated = NULL;
27335 + expire = au_sbi(inode->i_sb)->si_rdcache;
27336 + vdir = au_ivdir(inode);
27339 + vdir = alloc_vdir(file);
27340 + err = PTR_ERR(vdir);
27341 + if (IS_ERR(vdir))
27344 + allocated = vdir;
27345 + } else if (may_read
27346 + && (inode->i_version != vdir->vd_version
27347 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
27349 + err = reinit_vdir(vdir);
27350 + if (unlikely(err))
27355 + return 0; /* success */
27359 + err = au_do_read_vdir(&arg);
27361 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
27362 + vdir->vd_version = inode->i_version;
27363 + vdir->vd_last.ul = 0;
27364 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
27366 + au_set_ivdir(inode, allocated);
27367 + } else if (allocated)
27368 + au_vdir_free(allocated);
27374 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
27377 + unsigned long ul, n;
27378 + const unsigned int deblk_sz = src->vd_deblk_sz;
27380 + AuDebugOn(tgt->vd_nblk != 1);
27383 + if (tgt->vd_nblk < src->vd_nblk) {
27384 + unsigned char **p;
27386 + p = krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
27388 + if (unlikely(!p))
27390 + tgt->vd_deblk = p;
27393 + if (tgt->vd_deblk_sz != deblk_sz) {
27394 + unsigned char *p;
27396 + tgt->vd_deblk_sz = deblk_sz;
27397 + p = krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS);
27398 + if (unlikely(!p))
27400 + tgt->vd_deblk[0] = p;
27402 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
27403 + tgt->vd_version = src->vd_version;
27404 + tgt->vd_jiffy = src->vd_jiffy;
27406 + n = src->vd_nblk;
27407 + for (ul = 1; ul < n; ul++) {
27408 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
27410 + if (unlikely(!tgt->vd_deblk[ul]))
27414 + tgt->vd_nblk = n;
27415 + tgt->vd_last.ul = tgt->vd_last.ul;
27416 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
27417 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
27418 + - src->vd_deblk[src->vd_last.ul];
27420 + return 0; /* success */
27423 + rerr = reinit_vdir(tgt);
27428 +int au_vdir_init(struct file *file)
27431 + struct inode *inode;
27432 + struct au_vdir *vdir_cache, *allocated;
27434 + /* test file->f_pos here instead of ctx->pos */
27435 + err = read_vdir(file, !file->f_pos);
27436 + if (unlikely(err))
27439 + allocated = NULL;
27440 + vdir_cache = au_fvdir_cache(file);
27441 + if (!vdir_cache) {
27442 + vdir_cache = alloc_vdir(file);
27443 + err = PTR_ERR(vdir_cache);
27444 + if (IS_ERR(vdir_cache))
27446 + allocated = vdir_cache;
27447 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
27448 + /* test file->f_pos here instead of ctx->pos */
27449 + err = reinit_vdir(vdir_cache);
27450 + if (unlikely(err))
27453 + return 0; /* success */
27455 + inode = file_inode(file);
27456 + err = copy_vdir(vdir_cache, au_ivdir(inode));
27458 + file->f_version = inode->i_version;
27460 + au_set_fvdir_cache(file, allocated);
27461 + } else if (allocated)
27462 + au_vdir_free(allocated);
27468 +static loff_t calc_offset(struct au_vdir *vdir)
27471 + union au_vdir_deblk_p p;
27473 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
27474 + offset = vdir->vd_last.p.deblk - p.deblk;
27475 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
27479 +/* returns true or false */
27480 +static int seek_vdir(struct file *file, struct dir_context *ctx)
27483 + unsigned int deblk_sz;
27484 + unsigned long ul, n;
27486 + union au_vdir_deblk_p p, deblk_end;
27487 + struct au_vdir *vdir_cache;
27490 + vdir_cache = au_fvdir_cache(file);
27491 + offset = calc_offset(vdir_cache);
27492 + AuDbg("offset %lld\n", offset);
27493 + if (ctx->pos == offset)
27496 + vdir_cache->vd_last.ul = 0;
27497 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
27502 + deblk_sz = vdir_cache->vd_deblk_sz;
27503 + ul = div64_u64(ctx->pos, deblk_sz);
27504 + AuDbg("ul %lu\n", ul);
27505 + if (ul >= vdir_cache->vd_nblk)
27508 + n = vdir_cache->vd_nblk;
27509 + for (; ul < n; ul++) {
27510 + p.deblk = vdir_cache->vd_deblk[ul];
27511 + deblk_end.deblk = p.deblk + deblk_sz;
27513 + offset *= deblk_sz;
27514 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
27517 + l = calc_size(p.de->de_str.len);
27521 + if (!is_deblk_end(&p, &deblk_end)) {
27523 + vdir_cache->vd_last.ul = ul;
27524 + vdir_cache->vd_last.p = p;
27531 + AuTraceErr(!valid);
27535 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
27537 + unsigned int l, deblk_sz;
27538 + union au_vdir_deblk_p deblk_end;
27539 + struct au_vdir *vdir_cache;
27540 + struct au_vdir_de *de;
27542 + vdir_cache = au_fvdir_cache(file);
27543 + if (!seek_vdir(file, ctx))
27546 + deblk_sz = vdir_cache->vd_deblk_sz;
27548 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
27549 + deblk_end.deblk += deblk_sz;
27550 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
27551 + de = vdir_cache->vd_last.p.de;
27552 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
27553 + de->de_str.len, de->de_str.name, ctx->pos,
27554 + (unsigned long)de->de_ino, de->de_type);
27555 + if (unlikely(!dir_emit(ctx, de->de_str.name,
27556 + de->de_str.len, de->de_ino,
27558 + /* todo: ignore the error caused by udba? */
27559 + /* return err; */
27563 + l = calc_size(de->de_str.len);
27564 + vdir_cache->vd_last.p.deblk += l;
27567 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
27568 + vdir_cache->vd_last.ul++;
27569 + vdir_cache->vd_last.p.deblk
27570 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
27571 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
27580 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
27581 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
27582 +++ linux/fs/aufs/vfsub.c 2013-10-26 16:51:29.586298347 +0200
27585 + * Copyright (C) 2005-2013 Junjiro R. Okajima
27587 + * This program, aufs is free software; you can redistribute it and/or modify
27588 + * it under the terms of the GNU General Public License as published by
27589 + * the Free Software Foundation; either version 2 of the License, or
27590 + * (at your option) any later version.
27592 + * This program is distributed in the hope that it will be useful,
27593 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27594 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27595 + * GNU General Public License for more details.
27597 + * You should have received a copy of the GNU General Public License
27598 + * along with this program; if not, write to the Free Software
27599 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27603 + * sub-routines for VFS
27606 +#include <linux/ima.h>
27607 +#include <linux/namei.h>
27608 +#include <linux/security.h>
27609 +#include <linux/splice.h>
27612 +int vfsub_update_h_iattr(struct path *h_path, int *did)
27616 + struct super_block *h_sb;
27618 + /* for remote fs, leave work for its getattr or d_revalidate */
27619 + /* for bad i_attr fs, handle them in aufs_getattr() */
27620 + /* still some fs may acquire i_mutex. we need to skip them */
27624 + h_sb = h_path->dentry->d_sb;
27625 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
27627 + err = vfs_getattr(h_path, &st);
27632 +/* ---------------------------------------------------------------------- */
27634 +struct file *vfsub_dentry_open(struct path *path, int flags)
27636 + struct file *file;
27638 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
27640 + if (!IS_ERR_OR_NULL(file)
27641 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
27642 + i_readcount_inc(path->dentry->d_inode);
27647 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
27649 + struct file *file;
27652 + file = filp_open(path,
27653 + oflags /* | __FMODE_NONOTIFY */,
27656 + if (IS_ERR(file))
27658 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
27664 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
27668 + err = kern_path(name, flags, path);
27669 + if (!err && path->dentry->d_inode)
27670 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
27674 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
27677 + struct path path = {
27681 + /* VFS checks it too, but by WARN_ON_ONCE() */
27682 + IMustLock(parent->d_inode);
27684 + path.dentry = lookup_one_len(name, parent, len);
27685 + if (IS_ERR(path.dentry))
27687 + if (path.dentry->d_inode)
27688 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
27691 + AuTraceErrPtr(path.dentry);
27692 + return path.dentry;
27695 +void vfsub_call_lkup_one(void *args)
27697 + struct vfsub_lkup_one_args *a = args;
27698 + *a->errp = vfsub_lkup_one(a->name, a->parent);
27701 +/* ---------------------------------------------------------------------- */
27703 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
27704 + struct dentry *d2, struct au_hinode *hdir2)
27706 + struct dentry *d;
27709 + d = lock_rename(d1, d2);
27711 + au_hn_suspend(hdir1);
27712 + if (hdir1 != hdir2)
27713 + au_hn_suspend(hdir2);
27718 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
27719 + struct dentry *d2, struct au_hinode *hdir2)
27721 + au_hn_resume(hdir1);
27722 + if (hdir1 != hdir2)
27723 + au_hn_resume(hdir2);
27725 + unlock_rename(d1, d2);
27729 +/* ---------------------------------------------------------------------- */
27731 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
27734 + struct dentry *d;
27738 + d = path->dentry;
27739 + path->dentry = d->d_parent;
27740 + err = security_path_mknod(path, d, mode, 0);
27741 + path->dentry = d;
27742 + if (unlikely(err))
27745 + err = vfs_create(dir, path->dentry, mode, want_excl);
27747 + struct path tmp = *path;
27750 + vfsub_update_h_iattr(&tmp, &did);
27752 + tmp.dentry = path->dentry->d_parent;
27753 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27762 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
27765 + struct dentry *d;
27769 + d = path->dentry;
27770 + path->dentry = d->d_parent;
27771 + err = security_path_symlink(path, d, symname);
27772 + path->dentry = d;
27773 + if (unlikely(err))
27776 + err = vfs_symlink(dir, path->dentry, symname);
27778 + struct path tmp = *path;
27781 + vfsub_update_h_iattr(&tmp, &did);
27783 + tmp.dentry = path->dentry->d_parent;
27784 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27793 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
27796 + struct dentry *d;
27800 + d = path->dentry;
27801 + path->dentry = d->d_parent;
27802 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
27803 + path->dentry = d;
27804 + if (unlikely(err))
27807 + err = vfs_mknod(dir, path->dentry, mode, dev);
27809 + struct path tmp = *path;
27812 + vfsub_update_h_iattr(&tmp, &did);
27814 + tmp.dentry = path->dentry->d_parent;
27815 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27824 +static int au_test_nlink(struct inode *inode)
27826 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
27828 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
27829 + || inode->i_nlink < link_max)
27834 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path)
27837 + struct dentry *d;
27841 + err = au_test_nlink(src_dentry->d_inode);
27842 + if (unlikely(err))
27845 + /* we don't call may_linkat() */
27846 + d = path->dentry;
27847 + path->dentry = d->d_parent;
27848 + err = security_path_link(src_dentry, path, d);
27849 + path->dentry = d;
27850 + if (unlikely(err))
27854 + err = vfs_link(src_dentry, dir, path->dentry);
27857 + struct path tmp = *path;
27860 + /* fuse has different memory inode for the same inumber */
27861 + vfsub_update_h_iattr(&tmp, &did);
27863 + tmp.dentry = path->dentry->d_parent;
27864 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27865 + tmp.dentry = src_dentry;
27866 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27875 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
27876 + struct inode *dir, struct path *path)
27879 + struct path tmp = {
27882 + struct dentry *d;
27885 + IMustLock(src_dir);
27887 + d = path->dentry;
27888 + path->dentry = d->d_parent;
27889 + tmp.dentry = src_dentry->d_parent;
27890 + err = security_path_rename(&tmp, src_dentry, path, d);
27891 + path->dentry = d;
27892 + if (unlikely(err))
27896 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry);
27901 + tmp.dentry = d->d_parent;
27902 + vfsub_update_h_iattr(&tmp, &did);
27904 + tmp.dentry = src_dentry;
27905 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27906 + tmp.dentry = src_dentry->d_parent;
27907 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27916 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
27919 + struct dentry *d;
27923 + d = path->dentry;
27924 + path->dentry = d->d_parent;
27925 + err = security_path_mkdir(path, d, mode);
27926 + path->dentry = d;
27927 + if (unlikely(err))
27930 + err = vfs_mkdir(dir, path->dentry, mode);
27932 + struct path tmp = *path;
27935 + vfsub_update_h_iattr(&tmp, &did);
27937 + tmp.dentry = path->dentry->d_parent;
27938 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27947 +int vfsub_rmdir(struct inode *dir, struct path *path)
27950 + struct dentry *d;
27954 + d = path->dentry;
27955 + path->dentry = d->d_parent;
27956 + err = security_path_rmdir(path, d);
27957 + path->dentry = d;
27958 + if (unlikely(err))
27962 + err = vfs_rmdir(dir, path->dentry);
27965 + struct path tmp = {
27966 + .dentry = path->dentry->d_parent,
27970 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
27977 +/* ---------------------------------------------------------------------- */
27979 +/* todo: support mmap_sem? */
27980 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
27986 + err = vfs_read(file, ubuf, count, ppos);
27989 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
27993 +/* todo: kernel_read()? */
27994 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
27998 + mm_segment_t oldfs;
28005 + oldfs = get_fs();
28006 + set_fs(KERNEL_DS);
28007 + err = vfsub_read_u(file, buf.u, count, ppos);
28012 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
28018 + err = vfs_write(file, ubuf, count, ppos);
28021 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
28025 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
28028 + mm_segment_t oldfs;
28031 + const char __user *u;
28035 + oldfs = get_fs();
28036 + set_fs(KERNEL_DS);
28037 + err = vfsub_write_u(file, buf.u, count, ppos);
28042 +int vfsub_flush(struct file *file, fl_owner_t id)
28047 + if (file->f_op && file->f_op->flush) {
28048 + if (!au_test_nfs(file->f_dentry->d_sb))
28049 + err = file->f_op->flush(file, id);
28052 + err = file->f_op->flush(file, id);
28056 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
28062 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
28066 + AuDbg("%.*s, ctx{%pf, %llu}\n",
28067 + AuDLNPair(file->f_dentry), ctx->actor, ctx->pos);
28070 + err = iterate_dir(file, ctx);
28073 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
28077 +long vfsub_splice_to(struct file *in, loff_t *ppos,
28078 + struct pipe_inode_info *pipe, size_t len,
28079 + unsigned int flags)
28084 + err = do_splice_to(in, ppos, pipe, len, flags);
28086 + file_accessed(in);
28088 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
28092 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
28093 + loff_t *ppos, size_t len, unsigned int flags)
28098 + err = do_splice_from(pipe, out, ppos, len, flags);
28101 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
28105 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
28109 + /* file can be NULL */
28111 + err = vfs_fsync(file, datasync);
28115 + AuDebugOn(!file);
28116 + path = &file->f_path;
28118 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
28123 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
28124 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
28125 + struct file *h_file)
28128 + struct inode *h_inode;
28129 + struct super_block *h_sb;
28132 + err = vfsub_truncate(h_path, length);
28136 + h_inode = h_path->dentry->d_inode;
28137 + h_sb = h_inode->i_sb;
28139 + sb_start_write(h_sb);
28141 + err = locks_verify_truncate(h_inode, h_file, length);
28143 + err = security_path_truncate(h_path);
28146 + err = do_truncate(h_path->dentry, length, attr, h_file);
28150 + sb_end_write(h_sb);
28157 +/* ---------------------------------------------------------------------- */
28159 +struct au_vfsub_mkdir_args {
28161 + struct inode *dir;
28162 + struct path *path;
28166 +static void au_call_vfsub_mkdir(void *args)
28168 + struct au_vfsub_mkdir_args *a = args;
28169 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
28172 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
28174 + int err, do_sio, wkq_err;
28176 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
28178 + err = vfsub_mkdir(dir, path, mode);
28180 + struct au_vfsub_mkdir_args args = {
28186 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
28187 + if (unlikely(wkq_err))
28194 +struct au_vfsub_rmdir_args {
28196 + struct inode *dir;
28197 + struct path *path;
28200 +static void au_call_vfsub_rmdir(void *args)
28202 + struct au_vfsub_rmdir_args *a = args;
28203 + *a->errp = vfsub_rmdir(a->dir, a->path);
28206 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
28208 + int err, do_sio, wkq_err;
28210 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
28212 + err = vfsub_rmdir(dir, path);
28214 + struct au_vfsub_rmdir_args args = {
28219 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
28220 + if (unlikely(wkq_err))
28227 +/* ---------------------------------------------------------------------- */
28229 +struct notify_change_args {
28231 + struct path *path;
28232 + struct iattr *ia;
28235 +static void call_notify_change(void *args)
28237 + struct notify_change_args *a = args;
28238 + struct inode *h_inode;
28240 + h_inode = a->path->dentry->d_inode;
28241 + IMustLock(h_inode);
28243 + *a->errp = -EPERM;
28244 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
28245 + *a->errp = notify_change(a->path->dentry, a->ia);
28247 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
28249 + AuTraceErr(*a->errp);
28252 +int vfsub_notify_change(struct path *path, struct iattr *ia)
28255 + struct notify_change_args args = {
28261 + call_notify_change(&args);
28266 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia)
28268 + int err, wkq_err;
28269 + struct notify_change_args args = {
28275 + wkq_err = au_wkq_wait(call_notify_change, &args);
28276 + if (unlikely(wkq_err))
28282 +/* ---------------------------------------------------------------------- */
28284 +struct unlink_args {
28286 + struct inode *dir;
28287 + struct path *path;
28290 +static void call_unlink(void *args)
28292 + struct unlink_args *a = args;
28293 + struct dentry *d = a->path->dentry;
28294 + struct inode *h_inode;
28295 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
28296 + && d_count(d) == 1);
28298 + IMustLock(a->dir);
28300 + a->path->dentry = d->d_parent;
28301 + *a->errp = security_path_unlink(a->path, d);
28302 + a->path->dentry = d;
28303 + if (unlikely(*a->errp))
28306 + if (!stop_sillyrename)
28308 + h_inode = d->d_inode;
28313 + *a->errp = vfs_unlink(a->dir, d);
28316 + struct path tmp = {
28317 + .dentry = d->d_parent,
28318 + .mnt = a->path->mnt
28320 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
28323 + if (!stop_sillyrename)
28328 + AuTraceErr(*a->errp);
28332 + * @dir: must be locked.
28333 + * @dentry: target dentry.
28335 +int vfsub_unlink(struct inode *dir, struct path *path, int force)
28338 + struct unlink_args args = {
28345 + call_unlink(&args);
28349 + wkq_err = au_wkq_wait(call_unlink, &args);
28350 + if (unlikely(wkq_err))
28356 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
28357 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
28358 +++ linux/fs/aufs/vfsub.h 2013-10-26 16:51:32.276373845 +0200
28361 + * Copyright (C) 2005-2013 Junjiro R. Okajima
28363 + * This program, aufs is free software; you can redistribute it and/or modify
28364 + * it under the terms of the GNU General Public License as published by
28365 + * the Free Software Foundation; either version 2 of the License, or
28366 + * (at your option) any later version.
28368 + * This program is distributed in the hope that it will be useful,
28369 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28370 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28371 + * GNU General Public License for more details.
28373 + * You should have received a copy of the GNU General Public License
28374 + * along with this program; if not, write to the Free Software
28375 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28379 + * sub-routines for VFS
28382 +#ifndef __AUFS_VFSUB_H__
28383 +#define __AUFS_VFSUB_H__
28387 +#include <linux/fs.h>
28388 +#include <linux/lglock.h>
28389 +#include <linux/mount.h>
28390 +#include "debug.h"
28392 +/* copied from linux/fs/internal.h */
28393 +/* todo: BAD approach!! */
28394 +extern struct lglock vfsmount_lock;
28395 +extern void __mnt_drop_write(struct vfsmount *);
28396 +extern spinlock_t inode_sb_list_lock;
28397 +void __file_sb_list_add(struct file *file, struct super_block *sb);
28399 +/* copied from linux/fs/file_table.c */
28400 +extern struct lglock files_lglock;
28403 + * These macros iterate all files on all CPUs for a given superblock.
28404 + * files_lglock must be held globally.
28406 +#define do_file_list_for_each_entry(__sb, __file) \
28409 + for_each_possible_cpu(i) { \
28410 + struct list_head *list; \
28411 + list = per_cpu_ptr((__sb)->s_files, i); \
28412 + list_for_each_entry((__file), list, f_u.fu_list)
28414 +#define while_file_list_for_each_entry \
28420 +#define do_file_list_for_each_entry(__sb, __file) \
28422 + struct list_head *list; \
28423 + list = &(sb)->s_files; \
28424 + list_for_each_entry((__file), list, f_u.fu_list)
28426 +#define while_file_list_for_each_entry \
28430 +/* ---------------------------------------------------------------------- */
28432 +/* lock subclass for lower inode */
28433 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
28434 +/* reduce? gave up. */
28436 + AuLsc_I_Begin = I_MUTEX_QUOTA, /* 4 */
28437 + AuLsc_I_PARENT, /* lower inode, parent first */
28438 + AuLsc_I_PARENT2, /* copyup dirs */
28439 + AuLsc_I_PARENT3, /* copyup wh */
28445 +/* to debug easier, do not make them inlined functions */
28446 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
28447 +#define IMustLock(i) MtxMustLock(&(i)->i_mutex)
28449 +/* ---------------------------------------------------------------------- */
28451 +static inline void vfsub_drop_nlink(struct inode *inode)
28453 + AuDebugOn(!inode->i_nlink);
28454 + drop_nlink(inode);
28457 +static inline void vfsub_dead_dir(struct inode *inode)
28459 + AuDebugOn(!S_ISDIR(inode->i_mode));
28460 + inode->i_flags |= S_DEAD;
28461 + clear_nlink(inode);
28464 +static inline int vfsub_native_ro(struct inode *inode)
28466 + return (inode->i_sb->s_flags & MS_RDONLY)
28467 + || IS_RDONLY(inode)
28468 + /* || IS_APPEND(inode) */
28469 + || IS_IMMUTABLE(inode);
28472 +/* ---------------------------------------------------------------------- */
28474 +int vfsub_update_h_iattr(struct path *h_path, int *did);
28475 +struct file *vfsub_dentry_open(struct path *path, int flags);
28476 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
28477 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
28479 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
28482 +struct vfsub_lkup_one_args {
28483 + struct dentry **errp;
28484 + struct qstr *name;
28485 + struct dentry *parent;
28488 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
28489 + struct dentry *parent)
28491 + return vfsub_lookup_one_len(name->name, parent, name->len);
28494 +void vfsub_call_lkup_one(void *args);
28496 +/* ---------------------------------------------------------------------- */
28498 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
28502 + err = mnt_want_write(mnt);
28507 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
28510 + mnt_drop_write(mnt);
28514 +static inline void vfsub_mnt_drop_write_file(struct file *file)
28517 + mnt_drop_write_file(file);
28521 +/* ---------------------------------------------------------------------- */
28524 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
28525 + struct dentry *d2, struct au_hinode *hdir2);
28526 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
28527 + struct dentry *d2, struct au_hinode *hdir2);
28529 +int vfsub_create(struct inode *dir, struct path *path, int mode,
28531 +int vfsub_symlink(struct inode *dir, struct path *path,
28532 + const char *symname);
28533 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
28534 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
28535 + struct path *path);
28536 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
28537 + struct inode *hdir, struct path *path);
28538 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
28539 +int vfsub_rmdir(struct inode *dir, struct path *path);
28541 +/* ---------------------------------------------------------------------- */
28543 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
28545 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
28547 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
28549 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
28551 +int vfsub_flush(struct file *file, fl_owner_t id);
28552 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
28554 +/* just for type-check */
28555 +static inline filldir_t au_diractor(int (*func)(struct dir_context *,
28556 + const char *, int, loff_t, u64,
28559 + return (filldir_t)func;
28563 +static inline loff_t vfsub_f_size_read(struct file *file)
28565 + return i_size_read(file_inode(file));
28568 +static inline unsigned int vfsub_file_flags(struct file *file)
28570 + unsigned int flags;
28572 + spin_lock(&file->f_lock);
28573 + flags = file->f_flags;
28574 + spin_unlock(&file->f_lock);
28579 +static inline void vfsub_file_accessed(struct file *h_file)
28581 + file_accessed(h_file);
28582 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
28585 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
28586 + struct dentry *h_dentry)
28588 + struct path h_path = {
28589 + .dentry = h_dentry,
28592 + touch_atime(&h_path);
28593 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
28596 +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts,
28599 + return update_time(h_inode, ts, flags);
28600 + /* no vfsub_update_h_iattr() since we don't have struct path */
28603 +long vfsub_splice_to(struct file *in, loff_t *ppos,
28604 + struct pipe_inode_info *pipe, size_t len,
28605 + unsigned int flags);
28606 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
28607 + loff_t *ppos, size_t len, unsigned int flags);
28609 +static inline long vfsub_truncate(struct path *path, loff_t length)
28613 + err = vfs_truncate(path, length);
28618 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
28619 + struct file *h_file);
28620 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
28622 +/* ---------------------------------------------------------------------- */
28624 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
28629 + err = vfs_llseek(file, offset, origin);
28634 +/* ---------------------------------------------------------------------- */
28636 +/* dirty workaround for strict type of fmode_t */
28642 +static inline unsigned int vfsub_fmode_to_uint(fmode_t fm)
28644 + union vfsub_fmu u = {
28648 + BUILD_BUG_ON(sizeof(u.fm) != sizeof(u.ui));
28653 +static inline fmode_t vfsub_uint_to_fmode(unsigned int ui)
28655 + union vfsub_fmu u = {
28662 +/* ---------------------------------------------------------------------- */
28664 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
28665 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
28666 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia);
28667 +int vfsub_notify_change(struct path *path, struct iattr *ia);
28668 +int vfsub_unlink(struct inode *dir, struct path *path, int force);
28670 +#endif /* __KERNEL__ */
28671 +#endif /* __AUFS_VFSUB_H__ */
28672 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
28673 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
28674 +++ linux/fs/aufs/wbr_policy.c 2013-10-26 16:51:32.276373845 +0200
28677 + * Copyright (C) 2005-2013 Junjiro R. Okajima
28679 + * This program, aufs is free software; you can redistribute it and/or modify
28680 + * it under the terms of the GNU General Public License as published by
28681 + * the Free Software Foundation; either version 2 of the License, or
28682 + * (at your option) any later version.
28684 + * This program is distributed in the hope that it will be useful,
28685 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28686 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28687 + * GNU General Public License for more details.
28689 + * You should have received a copy of the GNU General Public License
28690 + * along with this program; if not, write to the Free Software
28691 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28695 + * policies for selecting one among multiple writable branches
28698 +#include <linux/statfs.h>
28701 +/* subset of cpup_attr() */
28702 +static noinline_for_stack
28703 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
28707 + struct inode *h_isrc;
28709 + h_isrc = h_src->d_inode;
28710 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
28711 + ia.ia_mode = h_isrc->i_mode;
28712 + ia.ia_uid = h_isrc->i_uid;
28713 + ia.ia_gid = h_isrc->i_gid;
28714 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
28715 + au_cpup_attr_flags(h_path->dentry->d_inode, h_isrc->i_flags);
28716 + err = vfsub_sio_notify_change(h_path, &ia);
28718 + /* is this nfs only? */
28719 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
28720 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
28721 + ia.ia_mode = h_isrc->i_mode;
28722 + err = vfsub_sio_notify_change(h_path, &ia);
28728 +#define AuCpdown_PARENT_OPQ 1
28729 +#define AuCpdown_WHED (1 << 1)
28730 +#define AuCpdown_MADE_DIR (1 << 2)
28731 +#define AuCpdown_DIROPQ (1 << 3)
28732 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
28733 +#define au_fset_cpdown(flags, name) \
28734 + do { (flags) |= AuCpdown_##name; } while (0)
28735 +#define au_fclr_cpdown(flags, name) \
28736 + do { (flags) &= ~AuCpdown_##name; } while (0)
28738 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
28739 + unsigned int *flags)
28742 + struct dentry *opq_dentry;
28744 + opq_dentry = au_diropq_create(dentry, bdst);
28745 + err = PTR_ERR(opq_dentry);
28746 + if (IS_ERR(opq_dentry))
28748 + dput(opq_dentry);
28749 + au_fset_cpdown(*flags, DIROPQ);
28755 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
28756 + struct inode *dir, aufs_bindex_t bdst)
28759 + struct path h_path;
28760 + struct au_branch *br;
28762 + br = au_sbr(dentry->d_sb, bdst);
28763 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
28764 + err = PTR_ERR(h_path.dentry);
28765 + if (IS_ERR(h_path.dentry))
28769 + if (h_path.dentry->d_inode) {
28770 + h_path.mnt = au_br_mnt(br);
28771 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
28774 + dput(h_path.dentry);
28780 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
28781 + struct au_pin *pin,
28782 + struct dentry *h_parent, void *arg)
28785 + aufs_bindex_t bopq, bstart;
28786 + struct path h_path;
28787 + struct dentry *parent;
28788 + struct inode *h_dir, *h_inode, *inode, *dir;
28789 + unsigned int *flags = arg;
28791 + bstart = au_dbstart(dentry);
28792 + /* dentry is di-locked */
28793 + parent = dget_parent(dentry);
28794 + dir = parent->d_inode;
28795 + h_dir = h_parent->d_inode;
28796 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
28797 + IMustLock(h_dir);
28799 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
28800 + if (unlikely(err < 0))
28802 + h_path.dentry = au_h_dptr(dentry, bdst);
28803 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
28804 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path,
28805 + S_IRWXU | S_IRUGO | S_IXUGO);
28806 + if (unlikely(err))
28808 + au_fset_cpdown(*flags, MADE_DIR);
28810 + bopq = au_dbdiropq(dentry);
28811 + au_fclr_cpdown(*flags, WHED);
28812 + au_fclr_cpdown(*flags, DIROPQ);
28813 + if (au_dbwh(dentry) == bdst)
28814 + au_fset_cpdown(*flags, WHED);
28815 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
28816 + au_fset_cpdown(*flags, PARENT_OPQ);
28817 + h_inode = h_path.dentry->d_inode;
28818 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
28819 + if (au_ftest_cpdown(*flags, WHED)) {
28820 + err = au_cpdown_dir_opq(dentry, bdst, flags);
28821 + if (unlikely(err)) {
28822 + mutex_unlock(&h_inode->i_mutex);
28827 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, bstart));
28828 + mutex_unlock(&h_inode->i_mutex);
28829 + if (unlikely(err))
28832 + if (au_ftest_cpdown(*flags, WHED)) {
28833 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
28834 + if (unlikely(err))
28838 + inode = dentry->d_inode;
28839 + if (au_ibend(inode) < bdst)
28840 + au_set_ibend(inode, bdst);
28841 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
28842 + au_hi_flags(inode, /*isdir*/1));
28843 + goto out; /* success */
28847 + if (au_ftest_cpdown(*flags, DIROPQ)) {
28848 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
28849 + rerr = au_diropq_remove(dentry, bdst);
28850 + mutex_unlock(&h_inode->i_mutex);
28851 + if (unlikely(rerr)) {
28852 + AuIOErr("failed removing diropq for %.*s b%d (%d)\n",
28853 + AuDLNPair(dentry), bdst, rerr);
28859 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
28860 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
28861 + if (unlikely(rerr)) {
28862 + AuIOErr("failed removing %.*s b%d (%d)\n",
28863 + AuDLNPair(dentry), bdst, rerr);
28868 + au_set_h_dptr(dentry, bdst, NULL);
28869 + if (au_dbend(dentry) == bdst)
28870 + au_update_dbend(dentry);
28876 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
28879 + unsigned int flags;
28882 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
28887 +/* ---------------------------------------------------------------------- */
28889 +/* policies for create */
28891 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
28893 + int err, i, j, ndentry;
28894 + aufs_bindex_t bopq;
28895 + struct au_dcsub_pages dpages;
28896 + struct au_dpage *dpage;
28897 + struct dentry **dentries, *parent, *d;
28899 + err = au_dpages_init(&dpages, GFP_NOFS);
28900 + if (unlikely(err))
28902 + parent = dget_parent(dentry);
28903 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
28904 + if (unlikely(err))
28908 + for (i = 0; i < dpages.ndpage; i++) {
28909 + dpage = dpages.dpages + i;
28910 + dentries = dpage->dentries;
28911 + ndentry = dpage->ndentry;
28912 + for (j = 0; j < ndentry; j++) {
28914 + di_read_lock_parent2(d, !AuLock_IR);
28915 + bopq = au_dbdiropq(d);
28916 + di_read_unlock(d, !AuLock_IR);
28917 + if (bopq >= 0 && bopq < err)
28924 + au_dpages_free(&dpages);
28929 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
28931 + for (; bindex >= 0; bindex--)
28932 + if (!au_br_rdonly(au_sbr(sb, bindex)))
28937 +/* top down parent */
28938 +static int au_wbr_create_tdp(struct dentry *dentry,
28939 + unsigned int flags __maybe_unused)
28942 + aufs_bindex_t bstart, bindex;
28943 + struct super_block *sb;
28944 + struct dentry *parent, *h_parent;
28946 + sb = dentry->d_sb;
28947 + bstart = au_dbstart(dentry);
28949 + if (!au_br_rdonly(au_sbr(sb, bstart)))
28953 + parent = dget_parent(dentry);
28954 + for (bindex = au_dbstart(parent); bindex < bstart; bindex++) {
28955 + h_parent = au_h_dptr(parent, bindex);
28956 + if (!h_parent || !h_parent->d_inode)
28959 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
28966 + /* bottom up here */
28967 + if (unlikely(err < 0)) {
28968 + err = au_wbr_bu(sb, bstart - 1);
28970 + err = au_wbr_nonopq(dentry, err);
28974 + AuDbg("b%d\n", err);
28978 +/* ---------------------------------------------------------------------- */
28980 +/* an exception for the policy other than tdp */
28981 +static int au_wbr_create_exp(struct dentry *dentry)
28984 + aufs_bindex_t bwh, bdiropq;
28985 + struct dentry *parent;
28988 + bwh = au_dbwh(dentry);
28989 + parent = dget_parent(dentry);
28990 + bdiropq = au_dbdiropq(parent);
28992 + if (bdiropq >= 0)
28993 + err = min(bdiropq, bwh);
28996 + AuDbg("%d\n", err);
28997 + } else if (bdiropq >= 0) {
28999 + AuDbg("%d\n", err);
29004 + err = au_wbr_nonopq(dentry, err);
29006 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
29009 + AuDbg("%d\n", err);
29013 +/* ---------------------------------------------------------------------- */
29016 +static int au_wbr_create_init_rr(struct super_block *sb)
29020 + err = au_wbr_bu(sb, au_sbend(sb));
29021 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
29024 + AuDbg("b%d\n", err);
29028 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
29032 + aufs_bindex_t bindex, bend;
29033 + struct super_block *sb;
29036 + err = au_wbr_create_exp(dentry);
29040 + sb = dentry->d_sb;
29041 + next = &au_sbi(sb)->si_wbr_rr_next;
29042 + bend = au_sbend(sb);
29044 + for (bindex = 0; bindex <= bend; bindex++) {
29045 + if (!au_ftest_wbr(flags, DIR)) {
29046 + err = atomic_dec_return(next) + 1;
29047 + /* modulo for 0 is meaningless */
29048 + if (unlikely(!err))
29049 + err = atomic_dec_return(next) + 1;
29051 + err = atomic_read(next);
29052 + AuDbg("%d\n", err);
29055 + AuDbg("%d\n", err);
29056 + if (!au_br_rdonly(au_sbr(sb, err)))
29062 + err = au_wbr_nonopq(dentry, err);
29065 + AuDbg("%d\n", err);
29069 +/* ---------------------------------------------------------------------- */
29071 +/* most free space */
29072 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
29074 + struct super_block *sb;
29075 + struct au_branch *br;
29076 + struct au_wbr_mfs *mfs;
29077 + struct dentry *h_parent;
29078 + aufs_bindex_t bindex, bend;
29080 + unsigned long long b, bavail;
29081 + struct path h_path;
29082 + /* reduce the stack usage */
29083 + struct kstatfs *st;
29085 + st = kmalloc(sizeof(*st), GFP_NOFS);
29086 + if (unlikely(!st)) {
29087 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
29092 + sb = dentry->d_sb;
29093 + mfs = &au_sbi(sb)->si_wbr_mfs;
29094 + MtxMustLock(&mfs->mfs_lock);
29095 + mfs->mfs_bindex = -EROFS;
29096 + mfs->mfsrr_bytes = 0;
29099 + bend = au_sbend(sb);
29101 + bindex = au_dbstart(parent);
29102 + bend = au_dbtaildir(parent);
29105 + for (; bindex <= bend; bindex++) {
29107 + h_parent = au_h_dptr(parent, bindex);
29108 + if (!h_parent || !h_parent->d_inode)
29111 + br = au_sbr(sb, bindex);
29112 + if (au_br_rdonly(br))
29115 + /* sb->s_root for NFS is unreliable */
29116 + h_path.mnt = au_br_mnt(br);
29117 + h_path.dentry = h_path.mnt->mnt_root;
29118 + err = vfs_statfs(&h_path, st);
29119 + if (unlikely(err)) {
29120 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
29124 + /* when the available size is equal, select the lower one */
29125 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
29126 + || sizeof(b) < sizeof(st->f_bsize));
29127 + b = st->f_bavail * st->f_bsize;
29128 + br->br_wbr->wbr_bytes = b;
29129 + if (b >= bavail) {
29131 + mfs->mfs_bindex = bindex;
29132 + mfs->mfs_jiffy = jiffies;
29136 + mfs->mfsrr_bytes = bavail;
29137 + AuDbg("b%d\n", mfs->mfs_bindex);
29141 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
29144 + struct dentry *parent;
29145 + struct super_block *sb;
29146 + struct au_wbr_mfs *mfs;
29148 + err = au_wbr_create_exp(dentry);
29152 + sb = dentry->d_sb;
29154 + if (au_ftest_wbr(flags, PARENT))
29155 + parent = dget_parent(dentry);
29156 + mfs = &au_sbi(sb)->si_wbr_mfs;
29157 + mutex_lock(&mfs->mfs_lock);
29158 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
29159 + || mfs->mfs_bindex < 0
29160 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
29161 + au_mfs(dentry, parent);
29162 + mutex_unlock(&mfs->mfs_lock);
29163 + err = mfs->mfs_bindex;
29167 + err = au_wbr_nonopq(dentry, err);
29170 + AuDbg("b%d\n", err);
29174 +static int au_wbr_create_init_mfs(struct super_block *sb)
29176 + struct au_wbr_mfs *mfs;
29178 + mfs = &au_sbi(sb)->si_wbr_mfs;
29179 + mutex_init(&mfs->mfs_lock);
29180 + mfs->mfs_jiffy = 0;
29181 + mfs->mfs_bindex = -EROFS;
29186 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
29188 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
29192 +/* ---------------------------------------------------------------------- */
29194 +/* most free space and then round robin */
29195 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
29198 + struct au_wbr_mfs *mfs;
29200 + err = au_wbr_create_mfs(dentry, flags);
29202 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
29203 + mutex_lock(&mfs->mfs_lock);
29204 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
29205 + err = au_wbr_create_rr(dentry, flags);
29206 + mutex_unlock(&mfs->mfs_lock);
29209 + AuDbg("b%d\n", err);
29213 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
29217 + au_wbr_create_init_mfs(sb); /* ignore */
29218 + err = au_wbr_create_init_rr(sb);
29223 +/* ---------------------------------------------------------------------- */
29225 +/* top down parent and most free space */
29226 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
29229 + unsigned long long b;
29230 + aufs_bindex_t bindex, bstart, bend;
29231 + struct super_block *sb;
29232 + struct dentry *parent, *h_parent;
29233 + struct au_branch *br;
29235 + err = au_wbr_create_tdp(dentry, flags);
29236 + if (unlikely(err < 0))
29238 + parent = dget_parent(dentry);
29239 + bstart = au_dbstart(parent);
29240 + bend = au_dbtaildir(parent);
29241 + if (bstart == bend)
29242 + goto out_parent; /* success */
29244 + e2 = au_wbr_create_mfs(dentry, flags);
29246 + goto out_parent; /* success */
29248 + /* when the available size is equal, select upper one */
29249 + sb = dentry->d_sb;
29250 + br = au_sbr(sb, err);
29251 + b = br->br_wbr->wbr_bytes;
29252 + AuDbg("b%d, %llu\n", err, b);
29254 + for (bindex = bstart; bindex <= bend; bindex++) {
29255 + h_parent = au_h_dptr(parent, bindex);
29256 + if (!h_parent || !h_parent->d_inode)
29259 + br = au_sbr(sb, bindex);
29260 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
29261 + b = br->br_wbr->wbr_bytes;
29263 + AuDbg("b%d, %llu\n", err, b);
29268 + err = au_wbr_nonopq(dentry, err);
29273 + AuDbg("b%d\n", err);
29277 +/* ---------------------------------------------------------------------- */
29280 + * - top down parent
29281 + * - most free space with parent
29282 + * - most free space round-robin regardless parent
29284 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
29287 + unsigned long long watermark;
29288 + struct super_block *sb;
29289 + struct au_branch *br;
29290 + struct au_wbr_mfs *mfs;
29292 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
29293 + if (unlikely(err < 0))
29296 + sb = dentry->d_sb;
29297 + br = au_sbr(sb, err);
29298 + mfs = &au_sbi(sb)->si_wbr_mfs;
29299 + mutex_lock(&mfs->mfs_lock);
29300 + watermark = mfs->mfsrr_watermark;
29301 + mutex_unlock(&mfs->mfs_lock);
29302 + if (br->br_wbr->wbr_bytes < watermark)
29303 + /* regardless the parent dir */
29304 + err = au_wbr_create_mfsrr(dentry, flags);
29307 + AuDbg("b%d\n", err);
29311 +/* ---------------------------------------------------------------------- */
29313 +/* policies for copyup */
29315 +/* top down parent */
29316 +static int au_wbr_copyup_tdp(struct dentry *dentry)
29318 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
29321 +/* bottom up parent */
29322 +static int au_wbr_copyup_bup(struct dentry *dentry)
29325 + aufs_bindex_t bindex, bstart;
29326 + struct dentry *parent, *h_parent;
29327 + struct super_block *sb;
29330 + sb = dentry->d_sb;
29331 + parent = dget_parent(dentry);
29332 + bstart = au_dbstart(parent);
29333 + for (bindex = au_dbstart(dentry); bindex >= bstart; bindex--) {
29334 + h_parent = au_h_dptr(parent, bindex);
29335 + if (!h_parent || !h_parent->d_inode)
29338 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
29345 + /* bottom up here */
29346 + if (unlikely(err < 0))
29347 + err = au_wbr_bu(sb, bstart - 1);
29349 + AuDbg("b%d\n", err);
29354 +static int au_wbr_copyup_bu(struct dentry *dentry)
29357 + aufs_bindex_t bstart;
29359 + bstart = au_dbstart(dentry);
29360 + err = au_wbr_bu(dentry->d_sb, bstart);
29361 + AuDbg("b%d\n", err);
29362 + if (err > bstart)
29363 + err = au_wbr_nonopq(dentry, err);
29365 + AuDbg("b%d\n", err);
29369 +/* ---------------------------------------------------------------------- */
29371 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
29372 + [AuWbrCopyup_TDP] = {
29373 + .copyup = au_wbr_copyup_tdp
29375 + [AuWbrCopyup_BUP] = {
29376 + .copyup = au_wbr_copyup_bup
29378 + [AuWbrCopyup_BU] = {
29379 + .copyup = au_wbr_copyup_bu
29383 +struct au_wbr_create_operations au_wbr_create_ops[] = {
29384 + [AuWbrCreate_TDP] = {
29385 + .create = au_wbr_create_tdp
29387 + [AuWbrCreate_RR] = {
29388 + .create = au_wbr_create_rr,
29389 + .init = au_wbr_create_init_rr
29391 + [AuWbrCreate_MFS] = {
29392 + .create = au_wbr_create_mfs,
29393 + .init = au_wbr_create_init_mfs,
29394 + .fin = au_wbr_create_fin_mfs
29396 + [AuWbrCreate_MFSV] = {
29397 + .create = au_wbr_create_mfs,
29398 + .init = au_wbr_create_init_mfs,
29399 + .fin = au_wbr_create_fin_mfs
29401 + [AuWbrCreate_MFSRR] = {
29402 + .create = au_wbr_create_mfsrr,
29403 + .init = au_wbr_create_init_mfsrr,
29404 + .fin = au_wbr_create_fin_mfs
29406 + [AuWbrCreate_MFSRRV] = {
29407 + .create = au_wbr_create_mfsrr,
29408 + .init = au_wbr_create_init_mfsrr,
29409 + .fin = au_wbr_create_fin_mfs
29411 + [AuWbrCreate_PMFS] = {
29412 + .create = au_wbr_create_pmfs,
29413 + .init = au_wbr_create_init_mfs,
29414 + .fin = au_wbr_create_fin_mfs
29416 + [AuWbrCreate_PMFSV] = {
29417 + .create = au_wbr_create_pmfs,
29418 + .init = au_wbr_create_init_mfs,
29419 + .fin = au_wbr_create_fin_mfs
29421 + [AuWbrCreate_PMFSRR] = {
29422 + .create = au_wbr_create_pmfsrr,
29423 + .init = au_wbr_create_init_mfsrr,
29424 + .fin = au_wbr_create_fin_mfs
29426 + [AuWbrCreate_PMFSRRV] = {
29427 + .create = au_wbr_create_pmfsrr,
29428 + .init = au_wbr_create_init_mfsrr,
29429 + .fin = au_wbr_create_fin_mfs
29432 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
29433 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
29434 +++ linux/fs/aufs/whout.c 2013-07-06 13:20:47.760198800 +0200
29437 + * Copyright (C) 2005-2013 Junjiro R. Okajima
29439 + * This program, aufs is free software; you can redistribute it and/or modify
29440 + * it under the terms of the GNU General Public License as published by
29441 + * the Free Software Foundation; either version 2 of the License, or
29442 + * (at your option) any later version.
29444 + * This program is distributed in the hope that it will be useful,
29445 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29446 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29447 + * GNU General Public License for more details.
29449 + * You should have received a copy of the GNU General Public License
29450 + * along with this program; if not, write to the Free Software
29451 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29455 + * whiteout for logical deletion and opaque directory
29460 +#define WH_MASK S_IRUGO
29463 + * If a directory contains this file, then it is opaque. We start with the
29464 + * .wh. flag so that it is blocked by lookup.
29466 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
29467 + sizeof(AUFS_WH_DIROPQ) - 1);
29470 + * generate whiteout name, which is NOT terminated by NULL.
29471 + * @name: original d_name.name
29472 + * @len: original d_name.len
29473 + * @wh: whiteout qstr
29474 + * returns zero when succeeds, otherwise error.
29475 + * succeeded value as wh->name should be freed by kfree().
29477 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
29481 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
29482 + return -ENAMETOOLONG;
29484 + wh->len = name->len + AUFS_WH_PFX_LEN;
29485 + p = kmalloc(wh->len, GFP_NOFS);
29488 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
29489 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
29496 +/* ---------------------------------------------------------------------- */
29499 + * test if the @wh_name exists under @h_parent.
29500 + * @try_sio specifies the necessary of super-io.
29502 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name,
29503 + struct au_branch *br, int try_sio)
29506 + struct dentry *wh_dentry;
29509 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
29511 + wh_dentry = au_sio_lkup_one(wh_name, h_parent, br);
29512 + err = PTR_ERR(wh_dentry);
29513 + if (IS_ERR(wh_dentry))
29517 + if (!wh_dentry->d_inode)
29518 + goto out_wh; /* success */
29521 + if (S_ISREG(wh_dentry->d_inode->i_mode))
29522 + goto out_wh; /* success */
29525 + AuIOErr("%.*s Invalid whiteout entry type 0%o.\n",
29526 + AuDLNPair(wh_dentry), wh_dentry->d_inode->i_mode);
29535 + * test if the @h_dentry sets opaque or not.
29537 +int au_diropq_test(struct dentry *h_dentry, struct au_branch *br)
29540 + struct inode *h_dir;
29542 + h_dir = h_dentry->d_inode;
29543 + err = au_wh_test(h_dentry, &diropq_name, br,
29544 + au_test_h_perm_sio(h_dir, MAY_EXEC));
29549 + * returns a negative dentry whose name is unique and temporary.
29551 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
29552 + struct qstr *prefix)
29554 + struct dentry *dentry;
29556 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
29558 + /* strict atomic_t is unnecessary here */
29559 + static unsigned short cnt;
29562 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
29565 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
29566 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
29567 + dentry = ERR_PTR(-ENAMETOOLONG);
29568 + if (unlikely(qs.len > NAME_MAX))
29570 + dentry = ERR_PTR(-ENOMEM);
29571 + name = kmalloc(qs.len + 1, GFP_NOFS);
29572 + if (unlikely(!name))
29576 + /* doubly whiteout-ed */
29577 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
29578 + p = name + AUFS_WH_PFX_LEN * 2;
29579 + memcpy(p, prefix->name, prefix->len);
29580 + p += prefix->len;
29582 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
29585 + for (i = 0; i < 3; i++) {
29586 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
29587 + dentry = au_sio_lkup_one(&qs, h_parent, br);
29588 + if (IS_ERR(dentry) || !dentry->d_inode)
29592 + /* pr_warn("could not get random name\n"); */
29593 + dentry = ERR_PTR(-EEXIST);
29594 + AuDbg("%.*s\n", AuLNPair(&qs));
29598 + if (name != defname)
29601 + AuTraceErrPtr(dentry);
29606 + * rename the @h_dentry on @br to the whiteouted temporary name.
29608 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
29611 + struct path h_path = {
29612 + .mnt = au_br_mnt(br)
29614 + struct inode *h_dir;
29615 + struct dentry *h_parent;
29617 + h_parent = h_dentry->d_parent; /* dir inode is locked */
29618 + h_dir = h_parent->d_inode;
29619 + IMustLock(h_dir);
29621 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
29622 + err = PTR_ERR(h_path.dentry);
29623 + if (IS_ERR(h_path.dentry))
29626 + /* under the same dir, no need to lock_rename() */
29627 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path);
29629 + dput(h_path.dentry);
29636 +/* ---------------------------------------------------------------------- */
29638 + * functions for removing a whiteout
29641 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
29646 + * forces superio when the dir has a sticky bit.
29647 + * this may be a violation of unix fs semantics.
29649 + force = (h_dir->i_mode & S_ISVTX)
29650 + && !uid_eq(current_fsuid(), h_path->dentry->d_inode->i_uid);
29651 + return vfsub_unlink(h_dir, h_path, force);
29654 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
29655 + struct dentry *dentry)
29659 + err = do_unlink_wh(h_dir, h_path);
29660 + if (!err && dentry)
29661 + au_set_dbwh(dentry, -1);
29666 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
29667 + struct au_branch *br)
29670 + struct path h_path = {
29671 + .mnt = au_br_mnt(br)
29675 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
29676 + if (IS_ERR(h_path.dentry))
29677 + err = PTR_ERR(h_path.dentry);
29679 + if (h_path.dentry->d_inode
29680 + && S_ISREG(h_path.dentry->d_inode->i_mode))
29681 + err = do_unlink_wh(h_parent->d_inode, &h_path);
29682 + dput(h_path.dentry);
29688 +/* ---------------------------------------------------------------------- */
29690 + * initialize/clean whiteout for a branch
29693 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
29698 + if (!whpath->dentry->d_inode)
29702 + err = vfsub_rmdir(h_dir, whpath);
29704 + err = vfsub_unlink(h_dir, whpath, /*force*/0);
29705 + if (unlikely(err))
29706 + pr_warn("failed removing %.*s (%d), ignored.\n",
29707 + AuDLNPair(whpath->dentry), err);
29710 +static int test_linkable(struct dentry *h_root)
29712 + struct inode *h_dir = h_root->d_inode;
29714 + if (h_dir->i_op->link)
29717 + pr_err("%.*s (%s) doesn't support link(2), use noplink and rw+nolwh\n",
29718 + AuDLNPair(h_root), au_sbtype(h_root->d_sb));
29722 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
29723 +static int au_whdir(struct inode *h_dir, struct path *path)
29728 + if (!path->dentry->d_inode) {
29729 + int mode = S_IRWXU;
29731 + if (au_test_nfs(path->dentry->d_sb))
29733 + err = vfsub_mkdir(h_dir, path, mode);
29734 + } else if (S_ISDIR(path->dentry->d_inode->i_mode))
29737 + pr_err("unknown %.*s exists\n", AuDLNPair(path->dentry));
29742 +struct au_wh_base {
29743 + const struct qstr *name;
29744 + struct dentry *dentry;
29747 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
29748 + struct path *h_path)
29750 + h_path->dentry = base[AuBrWh_BASE].dentry;
29751 + au_wh_clean(h_dir, h_path, /*isdir*/0);
29752 + h_path->dentry = base[AuBrWh_PLINK].dentry;
29753 + au_wh_clean(h_dir, h_path, /*isdir*/1);
29754 + h_path->dentry = base[AuBrWh_ORPH].dentry;
29755 + au_wh_clean(h_dir, h_path, /*isdir*/1);
29759 + * returns tri-state,
29760 + * minus: error, caller should print the mesage
29762 + * plus: error, caller should NOT print the mesage
29764 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
29765 + int do_plink, struct au_wh_base base[],
29766 + struct path *h_path)
29769 + struct inode *h_dir;
29771 + h_dir = h_root->d_inode;
29772 + h_path->dentry = base[AuBrWh_BASE].dentry;
29773 + au_wh_clean(h_dir, h_path, /*isdir*/0);
29774 + h_path->dentry = base[AuBrWh_PLINK].dentry;
29776 + err = test_linkable(h_root);
29777 + if (unlikely(err)) {
29782 + err = au_whdir(h_dir, h_path);
29783 + if (unlikely(err))
29785 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
29787 + au_wh_clean(h_dir, h_path, /*isdir*/1);
29788 + h_path->dentry = base[AuBrWh_ORPH].dentry;
29789 + err = au_whdir(h_dir, h_path);
29790 + if (unlikely(err))
29792 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
29799 + * for the moment, aufs supports the branch filesystem which does not support
29800 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
29801 + * copyup failed. finally, such filesystem will not be used as the writable
29804 + * returns tri-state, see above.
29806 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
29807 + int do_plink, struct au_wh_base base[],
29808 + struct path *h_path)
29811 + struct inode *h_dir;
29813 + WbrWhMustWriteLock(wbr);
29815 + err = test_linkable(h_root);
29816 + if (unlikely(err)) {
29822 + * todo: should this create be done in /sbin/mount.aufs helper?
29825 + h_dir = h_root->d_inode;
29826 + if (!base[AuBrWh_BASE].dentry->d_inode) {
29827 + h_path->dentry = base[AuBrWh_BASE].dentry;
29828 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
29829 + } else if (S_ISREG(base[AuBrWh_BASE].dentry->d_inode->i_mode))
29832 + pr_err("unknown %.*s/%.*s exists\n",
29833 + AuDLNPair(h_root), AuDLNPair(base[AuBrWh_BASE].dentry));
29834 + if (unlikely(err))
29837 + h_path->dentry = base[AuBrWh_PLINK].dentry;
29839 + err = au_whdir(h_dir, h_path);
29840 + if (unlikely(err))
29842 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
29844 + au_wh_clean(h_dir, h_path, /*isdir*/1);
29845 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
29847 + h_path->dentry = base[AuBrWh_ORPH].dentry;
29848 + err = au_whdir(h_dir, h_path);
29849 + if (unlikely(err))
29851 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
29858 + * initialize the whiteout base file/dir for @br.
29860 +int au_wh_init(struct au_branch *br, struct super_block *sb)
29863 + const unsigned char do_plink
29864 + = !!au_opt_test(au_mntflags(sb), PLINK);
29865 + struct inode *h_dir;
29866 + struct path path = br->br_path;
29867 + struct dentry *h_root = path.dentry;
29868 + struct au_wbr *wbr = br->br_wbr;
29869 + static const struct qstr base_name[] = {
29870 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
29871 + sizeof(AUFS_BASE_NAME) - 1),
29872 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
29873 + sizeof(AUFS_PLINKDIR_NAME) - 1),
29874 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
29875 + sizeof(AUFS_ORPHDIR_NAME) - 1)
29877 + struct au_wh_base base[] = {
29878 + [AuBrWh_BASE] = {
29879 + .name = base_name + AuBrWh_BASE,
29882 + [AuBrWh_PLINK] = {
29883 + .name = base_name + AuBrWh_PLINK,
29886 + [AuBrWh_ORPH] = {
29887 + .name = base_name + AuBrWh_ORPH,
29893 + WbrWhMustWriteLock(wbr);
29895 + for (i = 0; i < AuBrWh_Last; i++) {
29896 + /* doubly whiteouted */
29897 + struct dentry *d;
29899 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
29900 + err = PTR_ERR(d);
29904 + base[i].dentry = d;
29906 + && wbr->wbr_wh[i]
29907 + && wbr->wbr_wh[i] != base[i].dentry);
29911 + for (i = 0; i < AuBrWh_Last; i++) {
29912 + dput(wbr->wbr_wh[i]);
29913 + wbr->wbr_wh[i] = NULL;
29917 + if (!au_br_writable(br->br_perm)) {
29918 + h_dir = h_root->d_inode;
29919 + au_wh_init_ro(h_dir, base, &path);
29920 + } else if (!au_br_wh_linkable(br->br_perm)) {
29921 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
29927 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
29933 + goto out; /* success */
29936 + pr_err("an error(%d) on the writable branch %.*s(%s)\n",
29937 + err, AuDLNPair(h_root), au_sbtype(h_root->d_sb));
29939 + for (i = 0; i < AuBrWh_Last; i++)
29940 + dput(base[i].dentry);
29944 +/* ---------------------------------------------------------------------- */
29946 + * whiteouts are all hard-linked usually.
29947 + * when its link count reaches a ceiling, we create a new whiteout base
29948 + * asynchronously.
29951 +struct reinit_br_wh {
29952 + struct super_block *sb;
29953 + struct au_branch *br;
29956 +static void reinit_br_wh(void *arg)
29959 + aufs_bindex_t bindex;
29960 + struct path h_path;
29961 + struct reinit_br_wh *a = arg;
29962 + struct au_wbr *wbr;
29963 + struct inode *dir;
29964 + struct dentry *h_root;
29965 + struct au_hinode *hdir;
29968 + wbr = a->br->br_wbr;
29969 + /* big aufs lock */
29970 + si_noflush_write_lock(a->sb);
29971 + if (!au_br_writable(a->br->br_perm))
29973 + bindex = au_br_index(a->sb, a->br->br_id);
29974 + if (unlikely(bindex < 0))
29977 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
29978 + dir = a->sb->s_root->d_inode;
29979 + hdir = au_hi(dir, bindex);
29980 + h_root = au_h_dptr(a->sb->s_root, bindex);
29981 + AuDebugOn(h_root != au_br_dentry(a->br));
29983 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
29984 + wbr_wh_write_lock(wbr);
29985 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
29988 + h_path.dentry = wbr->wbr_whbase;
29989 + h_path.mnt = au_br_mnt(a->br);
29990 + err = vfsub_unlink(hdir->hi_inode, &h_path, /*force*/0);
29992 + pr_warn("%.*s is moved, ignored\n",
29993 + AuDLNPair(wbr->wbr_whbase));
29996 + dput(wbr->wbr_whbase);
29997 + wbr->wbr_whbase = NULL;
29999 + err = au_wh_init(a->br, a->sb);
30000 + wbr_wh_write_unlock(wbr);
30001 + au_hn_imtx_unlock(hdir);
30002 + di_read_unlock(a->sb->s_root, AuLock_IR);
30006 + atomic_dec(&wbr->wbr_wh_running);
30007 + atomic_dec(&a->br->br_count);
30008 + si_write_unlock(a->sb);
30009 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
30011 + if (unlikely(err))
30012 + AuIOErr("err %d\n", err);
30015 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
30017 + int do_dec, wkq_err;
30018 + struct reinit_br_wh *arg;
30021 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
30024 + /* ignore ENOMEM */
30025 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
30028 + * dec(wh_running), kfree(arg) and dec(br_count)
30029 + * in reinit function
30033 + atomic_inc(&br->br_count);
30034 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
30035 + if (unlikely(wkq_err)) {
30036 + atomic_dec(&br->br_wbr->wbr_wh_running);
30037 + atomic_dec(&br->br_count);
30045 + atomic_dec(&br->br_wbr->wbr_wh_running);
30048 +/* ---------------------------------------------------------------------- */
30051 + * create the whiteout @wh.
30053 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
30054 + struct dentry *wh)
30057 + struct path h_path = {
30060 + struct au_branch *br;
30061 + struct au_wbr *wbr;
30062 + struct dentry *h_parent;
30063 + struct inode *h_dir;
30065 + h_parent = wh->d_parent; /* dir inode is locked */
30066 + h_dir = h_parent->d_inode;
30067 + IMustLock(h_dir);
30069 + br = au_sbr(sb, bindex);
30070 + h_path.mnt = au_br_mnt(br);
30071 + wbr = br->br_wbr;
30072 + wbr_wh_read_lock(wbr);
30073 + if (wbr->wbr_whbase) {
30074 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path);
30075 + if (!err || err != -EMLINK)
30078 + /* link count full. re-initialize br_whbase. */
30079 + kick_reinit_br_wh(sb, br);
30082 + /* return this error in this context */
30083 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
30086 + wbr_wh_read_unlock(wbr);
30090 +/* ---------------------------------------------------------------------- */
30093 + * create or remove the diropq.
30095 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
30096 + unsigned int flags)
30098 + struct dentry *opq_dentry, *h_dentry;
30099 + struct super_block *sb;
30100 + struct au_branch *br;
30103 + sb = dentry->d_sb;
30104 + br = au_sbr(sb, bindex);
30105 + h_dentry = au_h_dptr(dentry, bindex);
30106 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
30107 + if (IS_ERR(opq_dentry))
30110 + if (au_ftest_diropq(flags, CREATE)) {
30111 + err = link_or_create_wh(sb, bindex, opq_dentry);
30113 + au_set_dbdiropq(dentry, bindex);
30114 + goto out; /* success */
30117 + struct path tmp = {
30118 + .dentry = opq_dentry,
30119 + .mnt = au_br_mnt(br)
30121 + err = do_unlink_wh(au_h_iptr(dentry->d_inode, bindex), &tmp);
30123 + au_set_dbdiropq(dentry, -1);
30125 + dput(opq_dentry);
30126 + opq_dentry = ERR_PTR(err);
30129 + return opq_dentry;
30132 +struct do_diropq_args {
30133 + struct dentry **errp;
30134 + struct dentry *dentry;
30135 + aufs_bindex_t bindex;
30136 + unsigned int flags;
30139 +static void call_do_diropq(void *args)
30141 + struct do_diropq_args *a = args;
30142 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
30145 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
30146 + unsigned int flags)
30148 + struct dentry *diropq, *h_dentry;
30150 + h_dentry = au_h_dptr(dentry, bindex);
30151 + if (!au_test_h_perm_sio(h_dentry->d_inode, MAY_EXEC | MAY_WRITE))
30152 + diropq = do_diropq(dentry, bindex, flags);
30155 + struct do_diropq_args args = {
30157 + .dentry = dentry,
30158 + .bindex = bindex,
30162 + wkq_err = au_wkq_wait(call_do_diropq, &args);
30163 + if (unlikely(wkq_err))
30164 + diropq = ERR_PTR(wkq_err);
30170 +/* ---------------------------------------------------------------------- */
30173 + * lookup whiteout dentry.
30174 + * @h_parent: lower parent dentry which must exist and be locked
30175 + * @base_name: name of dentry which will be whiteouted
30176 + * returns dentry for whiteout.
30178 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
30179 + struct au_branch *br)
30182 + struct qstr wh_name;
30183 + struct dentry *wh_dentry;
30185 + err = au_wh_name_alloc(&wh_name, base_name);
30186 + wh_dentry = ERR_PTR(err);
30188 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
30189 + kfree(wh_name.name);
30191 + return wh_dentry;
30195 + * link/create a whiteout for @dentry on @bindex.
30197 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
30198 + struct dentry *h_parent)
30200 + struct dentry *wh_dentry;
30201 + struct super_block *sb;
30204 + sb = dentry->d_sb;
30205 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
30206 + if (!IS_ERR(wh_dentry) && !wh_dentry->d_inode) {
30207 + err = link_or_create_wh(sb, bindex, wh_dentry);
30209 + au_set_dbwh(dentry, bindex);
30212 + wh_dentry = ERR_PTR(err);
30216 + return wh_dentry;
30219 +/* ---------------------------------------------------------------------- */
30221 +/* Delete all whiteouts in this directory on branch bindex. */
30222 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
30223 + aufs_bindex_t bindex, struct au_branch *br)
30226 + unsigned long ul, n;
30227 + struct qstr wh_name;
30229 + struct hlist_head *head;
30230 + struct au_vdir_wh *pos;
30231 + struct au_vdir_destr *str;
30234 + p = (void *)__get_free_page(GFP_NOFS);
30235 + wh_name.name = p;
30236 + if (unlikely(!wh_name.name))
30240 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
30241 + p += AUFS_WH_PFX_LEN;
30242 + n = whlist->nh_num;
30243 + head = whlist->nh_head;
30244 + for (ul = 0; !err && ul < n; ul++, head++) {
30245 + hlist_for_each_entry(pos, head, wh_hash) {
30246 + if (pos->wh_bindex != bindex)
30249 + str = &pos->wh_str;
30250 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
30251 + memcpy(p, str->name, str->len);
30252 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
30253 + err = unlink_wh_name(h_dentry, &wh_name, br);
30258 + AuIOErr("whiteout name too long %.*s\n",
30259 + str->len, str->name);
30264 + free_page((unsigned long)wh_name.name);
30270 +struct del_wh_children_args {
30272 + struct dentry *h_dentry;
30273 + struct au_nhash *whlist;
30274 + aufs_bindex_t bindex;
30275 + struct au_branch *br;
30278 +static void call_del_wh_children(void *args)
30280 + struct del_wh_children_args *a = args;
30281 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
30284 +/* ---------------------------------------------------------------------- */
30286 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
30288 + struct au_whtmp_rmdir *whtmp;
30290 + unsigned int rdhash;
30292 + SiMustAnyLock(sb);
30294 + whtmp = kmalloc(sizeof(*whtmp), gfp);
30295 + if (unlikely(!whtmp)) {
30296 + whtmp = ERR_PTR(-ENOMEM);
30300 + whtmp->dir = NULL;
30301 + whtmp->br = NULL;
30302 + whtmp->wh_dentry = NULL;
30303 + /* no estimation for dir size */
30304 + rdhash = au_sbi(sb)->si_rdhash;
30306 + rdhash = AUFS_RDHASH_DEF;
30307 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
30308 + if (unlikely(err)) {
30310 + whtmp = ERR_PTR(err);
30317 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
30320 + atomic_dec(&whtmp->br->br_count);
30321 + dput(whtmp->wh_dentry);
30322 + iput(whtmp->dir);
30323 + au_nhash_wh_free(&whtmp->whlist);
30328 + * rmdir the whiteouted temporary named dir @h_dentry.
30329 + * @whlist: whiteouted children.
30331 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
30332 + struct dentry *wh_dentry, struct au_nhash *whlist)
30335 + struct path h_tmp;
30336 + struct inode *wh_inode, *h_dir;
30337 + struct au_branch *br;
30339 + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
30340 + IMustLock(h_dir);
30342 + br = au_sbr(dir->i_sb, bindex);
30343 + wh_inode = wh_dentry->d_inode;
30344 + mutex_lock_nested(&wh_inode->i_mutex, AuLsc_I_CHILD);
30347 + * someone else might change some whiteouts while we were sleeping.
30348 + * it means this whlist may have an obsoleted entry.
30350 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
30351 + err = del_wh_children(wh_dentry, whlist, bindex, br);
30354 + struct del_wh_children_args args = {
30356 + .h_dentry = wh_dentry,
30357 + .whlist = whlist,
30358 + .bindex = bindex,
30362 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
30363 + if (unlikely(wkq_err))
30366 + mutex_unlock(&wh_inode->i_mutex);
30369 + h_tmp.dentry = wh_dentry;
30370 + h_tmp.mnt = au_br_mnt(br);
30371 + err = vfsub_rmdir(h_dir, &h_tmp);
30375 + if (au_ibstart(dir) == bindex) {
30376 + /* todo: dir->i_mutex is necessary */
30377 + au_cpup_attr_timesizes(dir);
30378 + vfsub_drop_nlink(dir);
30380 + return 0; /* success */
30383 + pr_warn("failed removing %.*s(%d), ignored\n",
30384 + AuDLNPair(wh_dentry), err);
30388 +static void call_rmdir_whtmp(void *args)
30391 + aufs_bindex_t bindex;
30392 + struct au_whtmp_rmdir *a = args;
30393 + struct super_block *sb;
30394 + struct dentry *h_parent;
30395 + struct inode *h_dir;
30396 + struct au_hinode *hdir;
30398 + /* rmdir by nfsd may cause deadlock with this i_mutex */
30399 + /* mutex_lock(&a->dir->i_mutex); */
30401 + sb = a->dir->i_sb;
30402 + si_read_lock(sb, !AuLock_FLUSH);
30403 + if (!au_br_writable(a->br->br_perm))
30405 + bindex = au_br_index(sb, a->br->br_id);
30406 + if (unlikely(bindex < 0))
30410 + ii_write_lock_parent(a->dir);
30411 + h_parent = dget_parent(a->wh_dentry);
30412 + h_dir = h_parent->d_inode;
30413 + hdir = au_hi(a->dir, bindex);
30414 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
30415 + if (unlikely(err))
30417 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
30418 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
30421 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
30422 + au_hn_imtx_unlock(hdir);
30423 + vfsub_mnt_drop_write(au_br_mnt(a->br));
30427 + ii_write_unlock(a->dir);
30429 + /* mutex_unlock(&a->dir->i_mutex); */
30430 + au_whtmp_rmdir_free(a);
30431 + si_read_unlock(sb);
30432 + au_nwt_done(&au_sbi(sb)->si_nowait);
30433 + if (unlikely(err))
30434 + AuIOErr("err %d\n", err);
30437 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
30438 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
30441 + struct super_block *sb;
30445 + /* all post-process will be done in do_rmdir_whtmp(). */
30447 + args->dir = au_igrab(dir);
30448 + args->br = au_sbr(sb, bindex);
30449 + atomic_inc(&args->br->br_count);
30450 + args->wh_dentry = dget(wh_dentry);
30451 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
30452 + if (unlikely(wkq_err)) {
30453 + pr_warn("rmdir error %.*s (%d), ignored\n",
30454 + AuDLNPair(wh_dentry), wkq_err);
30455 + au_whtmp_rmdir_free(args);
30458 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
30459 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
30460 +++ linux/fs/aufs/whout.h 2013-07-06 13:20:47.760198800 +0200
30463 + * Copyright (C) 2005-2013 Junjiro R. Okajima
30465 + * This program, aufs is free software; you can redistribute it and/or modify
30466 + * it under the terms of the GNU General Public License as published by
30467 + * the Free Software Foundation; either version 2 of the License, or
30468 + * (at your option) any later version.
30470 + * This program is distributed in the hope that it will be useful,
30471 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30472 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30473 + * GNU General Public License for more details.
30475 + * You should have received a copy of the GNU General Public License
30476 + * along with this program; if not, write to the Free Software
30477 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30481 + * whiteout for logical deletion and opaque directory
30484 +#ifndef __AUFS_WHOUT_H__
30485 +#define __AUFS_WHOUT_H__
30492 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
30494 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name,
30495 + struct au_branch *br, int try_sio);
30496 +int au_diropq_test(struct dentry *h_dentry, struct au_branch *br);
30497 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
30498 + struct qstr *prefix);
30499 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
30500 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
30501 + struct dentry *dentry);
30502 +int au_wh_init(struct au_branch *br, struct super_block *sb);
30504 +/* diropq flags */
30505 +#define AuDiropq_CREATE 1
30506 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
30507 +#define au_fset_diropq(flags, name) \
30508 + do { (flags) |= AuDiropq_##name; } while (0)
30509 +#define au_fclr_diropq(flags, name) \
30510 + do { (flags) &= ~AuDiropq_##name; } while (0)
30512 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
30513 + unsigned int flags);
30514 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
30515 + struct au_branch *br);
30516 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
30517 + struct dentry *h_parent);
30519 +/* real rmdir for the whiteout-ed dir */
30520 +struct au_whtmp_rmdir {
30521 + struct inode *dir;
30522 + struct au_branch *br;
30523 + struct dentry *wh_dentry;
30524 + struct au_nhash whlist;
30527 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
30528 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
30529 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
30530 + struct dentry *wh_dentry, struct au_nhash *whlist);
30531 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
30532 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
30534 +/* ---------------------------------------------------------------------- */
30536 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
30537 + aufs_bindex_t bindex)
30539 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
30542 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
30544 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
30547 +#endif /* __KERNEL__ */
30548 +#endif /* __AUFS_WHOUT_H__ */
30549 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
30550 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
30551 +++ linux/fs/aufs/wkq.c 2013-10-26 16:51:32.276373845 +0200
30554 + * Copyright (C) 2005-2013 Junjiro R. Okajima
30556 + * This program, aufs is free software; you can redistribute it and/or modify
30557 + * it under the terms of the GNU General Public License as published by
30558 + * the Free Software Foundation; either version 2 of the License, or
30559 + * (at your option) any later version.
30561 + * This program is distributed in the hope that it will be useful,
30562 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30563 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30564 + * GNU General Public License for more details.
30566 + * You should have received a copy of the GNU General Public License
30567 + * along with this program; if not, write to the Free Software
30568 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30572 + * workqueue for asynchronous/super-io operations
30573 + * todo: try new dredential scheme
30576 +#include <linux/module.h>
30579 +/* internal workqueue named AUFS_WKQ_NAME */
30581 +static struct workqueue_struct *au_wkq;
30583 +struct au_wkinfo {
30584 + struct work_struct wk;
30585 + struct kobject *kobj;
30587 + unsigned int flags; /* see wkq.h */
30589 + au_wkq_func_t func;
30592 + struct completion *comp;
30595 +/* ---------------------------------------------------------------------- */
30597 +static void wkq_func(struct work_struct *wk)
30599 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
30601 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
30602 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
30604 + wkinfo->func(wkinfo->args);
30605 + if (au_ftest_wkq(wkinfo->flags, WAIT))
30606 + complete(wkinfo->comp);
30608 + kobject_put(wkinfo->kobj);
30609 + module_put(THIS_MODULE); /* todo: ?? */
30615 + * Since struct completion is large, try allocating it dynamically.
30617 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
30618 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
30620 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
30622 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
30624 + init_completion(*comp);
30625 + wkinfo->comp = *comp;
30631 +static void au_wkq_comp_free(struct completion *comp)
30639 +#define AuWkqCompDeclare(name) \
30640 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
30641 + struct completion *comp = &_ ## name
30643 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
30645 + wkinfo->comp = *comp;
30649 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
30653 +#endif /* 4KSTACKS */
30655 +static void au_wkq_run(struct au_wkinfo *wkinfo)
30657 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
30658 + if (au_wkq_test()) {
30659 + AuWarn1("wkq from wkq, due to a dead dir by UDBA?\n");
30660 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
30663 + au_dbg_verify_kthread();
30665 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
30666 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
30667 + queue_work(au_wkq, &wkinfo->wk);
30669 + INIT_WORK(&wkinfo->wk, wkq_func);
30670 + schedule_work(&wkinfo->wk);
30675 + * Be careful. It is easy to make deadlock happen.
30676 + * processA: lock, wkq and wait
30677 + * processB: wkq and wait, lock in wkq
30680 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
30683 + AuWkqCompDeclare(comp);
30684 + struct au_wkinfo wkinfo = {
30690 + err = au_wkq_comp_alloc(&wkinfo, &comp);
30692 + au_wkq_run(&wkinfo);
30693 + /* no timeout, no interrupt */
30694 + wait_for_completion(wkinfo.comp);
30695 + au_wkq_comp_free(comp);
30696 + destroy_work_on_stack(&wkinfo.wk);
30704 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
30705 + * problem in a concurrent umounting.
30707 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
30708 + unsigned int flags)
30711 + struct au_wkinfo *wkinfo;
30713 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
30716 + * wkq_func() must free this wkinfo.
30717 + * it highly depends upon the implementation of workqueue.
30720 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
30722 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
30723 + wkinfo->flags = flags & ~AuWkq_WAIT;
30724 + wkinfo->func = func;
30725 + wkinfo->args = args;
30726 + wkinfo->comp = NULL;
30727 + kobject_get(wkinfo->kobj);
30728 + __module_get(THIS_MODULE); /* todo: ?? */
30730 + au_wkq_run(wkinfo);
30733 + au_nwt_done(&au_sbi(sb)->si_nowait);
30739 +/* ---------------------------------------------------------------------- */
30741 +void au_nwt_init(struct au_nowait_tasks *nwt)
30743 + atomic_set(&nwt->nw_len, 0);
30744 + /* smp_mb(); */ /* atomic_set */
30745 + init_waitqueue_head(&nwt->nw_wq);
30748 +void au_wkq_fin(void)
30750 + destroy_workqueue(au_wkq);
30753 +int __init au_wkq_init(void)
30758 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
30759 + if (IS_ERR(au_wkq))
30760 + err = PTR_ERR(au_wkq);
30761 + else if (!au_wkq)
30766 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
30767 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
30768 +++ linux/fs/aufs/wkq.h 2013-07-06 13:20:47.760198800 +0200
30771 + * Copyright (C) 2005-2013 Junjiro R. Okajima
30773 + * This program, aufs is free software; you can redistribute it and/or modify
30774 + * it under the terms of the GNU General Public License as published by
30775 + * the Free Software Foundation; either version 2 of the License, or
30776 + * (at your option) any later version.
30778 + * This program is distributed in the hope that it will be useful,
30779 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30780 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30781 + * GNU General Public License for more details.
30783 + * You should have received a copy of the GNU General Public License
30784 + * along with this program; if not, write to the Free Software
30785 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30789 + * workqueue for asynchronous/super-io operations
30790 + * todo: try new credentials management scheme
30793 +#ifndef __AUFS_WKQ_H__
30794 +#define __AUFS_WKQ_H__
30798 +struct super_block;
30800 +/* ---------------------------------------------------------------------- */
30803 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
30805 +struct au_nowait_tasks {
30807 + wait_queue_head_t nw_wq;
30810 +/* ---------------------------------------------------------------------- */
30812 +typedef void (*au_wkq_func_t)(void *args);
30815 +#define AuWkq_WAIT 1
30816 +#define AuWkq_NEST (1 << 1)
30817 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
30818 +#define au_fset_wkq(flags, name) \
30819 + do { (flags) |= AuWkq_##name; } while (0)
30820 +#define au_fclr_wkq(flags, name) \
30821 + do { (flags) &= ~AuWkq_##name; } while (0)
30823 +#ifndef CONFIG_AUFS_HNOTIFY
30825 +#define AuWkq_NEST 0
30829 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
30830 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
30831 + unsigned int flags);
30832 +void au_nwt_init(struct au_nowait_tasks *nwt);
30833 +int __init au_wkq_init(void);
30834 +void au_wkq_fin(void);
30836 +/* ---------------------------------------------------------------------- */
30838 +static inline int au_wkq_test(void)
30840 + return current->flags & PF_WQ_WORKER;
30843 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
30845 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
30848 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
30850 + if (atomic_dec_and_test(&nwt->nw_len))
30851 + wake_up_all(&nwt->nw_wq);
30854 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
30856 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
30860 +#endif /* __KERNEL__ */
30861 +#endif /* __AUFS_WKQ_H__ */
30862 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
30863 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
30864 +++ linux/fs/aufs/xino.c 2013-10-26 16:51:32.276373845 +0200
30867 + * Copyright (C) 2005-2013 Junjiro R. Okajima
30869 + * This program, aufs is free software; you can redistribute it and/or modify
30870 + * it under the terms of the GNU General Public License as published by
30871 + * the Free Software Foundation; either version 2 of the License, or
30872 + * (at your option) any later version.
30874 + * This program is distributed in the hope that it will be useful,
30875 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30876 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30877 + * GNU General Public License for more details.
30879 + * You should have received a copy of the GNU General Public License
30880 + * along with this program; if not, write to the Free Software
30881 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30885 + * external inode number translation table and bitmap
30888 +#include <linux/seq_file.h>
30889 +#include <linux/statfs.h>
30892 +/* todo: unnecessary to support mmap_sem since kernel-space? */
30893 +ssize_t xino_fread(au_readf_t func, struct file *file, void *kbuf, size_t size,
30897 + mm_segment_t oldfs;
30904 + oldfs = get_fs();
30905 + set_fs(KERNEL_DS);
30907 + /* todo: signal_pending? */
30908 + err = func(file, buf.u, size, pos);
30909 + } while (err == -EAGAIN || err == -EINTR);
30912 +#if 0 /* reserved for future use */
30914 + fsnotify_access(file->f_dentry);
30920 +/* ---------------------------------------------------------------------- */
30922 +static ssize_t do_xino_fwrite(au_writef_t func, struct file *file, void *kbuf,
30923 + size_t size, loff_t *pos)
30926 + mm_segment_t oldfs;
30929 + const char __user *u;
30933 + oldfs = get_fs();
30934 + set_fs(KERNEL_DS);
30936 + /* todo: signal_pending? */
30937 + err = func(file, buf.u, size, pos);
30938 + } while (err == -EAGAIN || err == -EINTR);
30941 +#if 0 /* reserved for future use */
30943 + fsnotify_modify(file->f_dentry);
30949 +struct do_xino_fwrite_args {
30951 + au_writef_t func;
30952 + struct file *file;
30958 +static void call_do_xino_fwrite(void *args)
30960 + struct do_xino_fwrite_args *a = args;
30961 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
30964 +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size,
30969 + /* todo: signal block and no wkq? */
30970 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
30972 + err = do_xino_fwrite(func, file, buf, size, pos);
30976 + * it breaks RLIMIT_FSIZE and normal user's limit,
30977 + * users should care about quota and real 'filesystem full.'
30980 + struct do_xino_fwrite_args args = {
30989 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
30990 + if (unlikely(wkq_err))
30997 +/* ---------------------------------------------------------------------- */
31000 + * create a new xinofile at the same place/path as @base_file.
31002 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src)
31004 + struct file *file;
31005 + struct dentry *base, *parent;
31006 + struct inode *dir;
31007 + struct qstr *name;
31008 + struct path path;
31011 + base = base_file->f_dentry;
31012 + parent = base->d_parent; /* dir inode is locked */
31013 + dir = parent->d_inode;
31016 + file = ERR_PTR(-EINVAL);
31017 + name = &base->d_name;
31018 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
31019 + if (IS_ERR(path.dentry)) {
31020 + file = (void *)path.dentry;
31021 + pr_err("%.*s lookup err %ld\n",
31022 + AuLNPair(name), PTR_ERR(path.dentry));
31026 + /* no need to mnt_want_write() since we call dentry_open() later */
31027 + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL);
31028 + if (unlikely(err)) {
31029 + file = ERR_PTR(err);
31030 + pr_err("%.*s create err %d\n", AuLNPair(name), err);
31034 + path.mnt = base_file->f_path.mnt;
31035 + file = vfsub_dentry_open(&path,
31036 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
31037 + /* | __FMODE_NONOTIFY */);
31038 + if (IS_ERR(file)) {
31039 + pr_err("%.*s open err %ld\n", AuLNPair(name), PTR_ERR(file));
31043 + err = vfsub_unlink(dir, &file->f_path, /*force*/0);
31044 + if (unlikely(err)) {
31045 + pr_err("%.*s unlink err %d\n", AuLNPair(name), err);
31050 + /* no one can touch copy_src xino */
31051 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
31052 + if (unlikely(err)) {
31053 + pr_err("%.*s copy err %d\n", AuLNPair(name), err);
31057 + goto out_dput; /* success */
31061 + file = ERR_PTR(err);
31063 + dput(path.dentry);
31068 +struct au_xino_lock_dir {
31069 + struct au_hinode *hdir;
31070 + struct dentry *parent;
31071 + struct mutex *mtx;
31074 +static void au_xino_lock_dir(struct super_block *sb, struct file *xino,
31075 + struct au_xino_lock_dir *ldir)
31077 + aufs_bindex_t brid, bindex;
31079 + ldir->hdir = NULL;
31081 + brid = au_xino_brid(sb);
31083 + bindex = au_br_index(sb, brid);
31084 + if (bindex >= 0) {
31085 + ldir->hdir = au_hi(sb->s_root->d_inode, bindex);
31086 + au_hn_imtx_lock_nested(ldir->hdir, AuLsc_I_PARENT);
31088 + ldir->parent = dget_parent(xino->f_dentry);
31089 + ldir->mtx = &ldir->parent->d_inode->i_mutex;
31090 + mutex_lock_nested(ldir->mtx, AuLsc_I_PARENT);
31094 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
31097 + au_hn_imtx_unlock(ldir->hdir);
31099 + mutex_unlock(ldir->mtx);
31100 + dput(ldir->parent);
31104 +/* ---------------------------------------------------------------------- */
31106 +/* trucate xino files asynchronously */
31108 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
31111 + unsigned long jiffy;
31113 + aufs_bindex_t bi, bend;
31114 + struct kstatfs *st;
31115 + struct au_branch *br;
31116 + struct file *new_xino, *file;
31117 + struct super_block *h_sb;
31118 + struct au_xino_lock_dir ldir;
31121 + st = kzalloc(sizeof(*st), GFP_NOFS);
31122 + if (unlikely(!st))
31126 + bend = au_sbend(sb);
31127 + if (unlikely(bindex < 0 || bend < bindex))
31129 + br = au_sbr(sb, bindex);
31130 + file = br->br_xino.xi_file;
31134 + err = vfs_statfs(&file->f_path, st);
31135 + if (unlikely(err))
31136 + AuErr1("statfs err %d, ignored\n", err);
31138 + blocks = file_inode(file)->i_blocks;
31139 + pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
31140 + bindex, (u64)blocks, st->f_bfree, st->f_blocks);
31142 + au_xino_lock_dir(sb, file, &ldir);
31143 + /* mnt_want_write() is unnecessary here */
31144 + new_xino = au_xino_create2(file, file);
31145 + au_xino_unlock_dir(&ldir);
31146 + err = PTR_ERR(new_xino);
31147 + if (IS_ERR(new_xino)) {
31148 + pr_err("err %d, ignored\n", err);
31153 + br->br_xino.xi_file = new_xino;
31155 + h_sb = au_br_sb(br);
31156 + for (bi = 0; bi <= bend; bi++) {
31157 + if (unlikely(bi == bindex))
31159 + br = au_sbr(sb, bi);
31160 + if (au_br_sb(br) != h_sb)
31163 + fput(br->br_xino.xi_file);
31164 + br->br_xino.xi_file = new_xino;
31165 + get_file(new_xino);
31168 + err = vfs_statfs(&new_xino->f_path, st);
31170 + pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
31171 + bindex, (u64)file_inode(new_xino)->i_blocks,
31172 + st->f_bfree, st->f_blocks);
31173 + if (file_inode(new_xino)->i_blocks < blocks)
31174 + au_sbi(sb)->si_xino_jiffy = jiffy;
31176 + AuErr1("statfs err %d, ignored\n", err);
31184 +struct xino_do_trunc_args {
31185 + struct super_block *sb;
31186 + struct au_branch *br;
31189 +static void xino_do_trunc(void *_args)
31191 + struct xino_do_trunc_args *args = _args;
31192 + struct super_block *sb;
31193 + struct au_branch *br;
31194 + struct inode *dir;
31196 + aufs_bindex_t bindex;
31200 + dir = sb->s_root->d_inode;
31203 + si_noflush_write_lock(sb);
31204 + ii_read_lock_parent(dir);
31205 + bindex = au_br_index(sb, br->br_id);
31206 + err = au_xino_trunc(sb, bindex);
31207 + ii_read_unlock(dir);
31208 + if (unlikely(err))
31209 + pr_warn("err b%d, (%d)\n", bindex, err);
31210 + atomic_dec(&br->br_xino_running);
31211 + atomic_dec(&br->br_count);
31212 + si_write_unlock(sb);
31213 + au_nwt_done(&au_sbi(sb)->si_nowait);
31217 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
31220 + struct kstatfs st;
31221 + struct au_sbinfo *sbinfo;
31223 + /* todo: si_xino_expire and the ratio should be customizable */
31224 + sbinfo = au_sbi(sb);
31225 + if (time_before(jiffies,
31226 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
31229 + /* truncation border */
31230 + err = vfs_statfs(&br->br_xino.xi_file->f_path, &st);
31231 + if (unlikely(err)) {
31232 + AuErr1("statfs err %d, ignored\n", err);
31235 + if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC)
31241 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
31243 + struct xino_do_trunc_args *args;
31246 + if (!xino_trunc_test(sb, br))
31249 + if (atomic_inc_return(&br->br_xino_running) > 1)
31252 + /* lock and kfree() will be called in trunc_xino() */
31253 + args = kmalloc(sizeof(*args), GFP_NOFS);
31254 + if (unlikely(!args)) {
31255 + AuErr1("no memory\n");
31259 + atomic_inc(&br->br_count);
31262 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
31264 + return; /* success */
31266 + pr_err("wkq %d\n", wkq_err);
31267 + atomic_dec(&br->br_count);
31272 + atomic_dec(&br->br_xino_running);
31275 +/* ---------------------------------------------------------------------- */
31277 +static int au_xino_do_write(au_writef_t write, struct file *file,
31278 + ino_t h_ino, ino_t ino)
31284 + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) {
31285 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
31288 + pos *= sizeof(ino);
31289 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos);
31290 + if (sz == sizeof(ino))
31291 + return 0; /* success */
31293 + AuIOErr("write failed (%zd)\n", sz);
31298 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
31299 + * at the position of @h_ino.
31300 + * even if @ino is zero, it is written to the xinofile and means no entry.
31301 + * if the size of the xino file on a specific filesystem exceeds the watermark,
31302 + * try truncating it.
31304 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
31308 + unsigned int mnt_flags;
31309 + struct au_branch *br;
31311 + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max)
31312 + || ((loff_t)-1) > 0);
31313 + SiMustAnyLock(sb);
31315 + mnt_flags = au_mntflags(sb);
31316 + if (!au_opt_test(mnt_flags, XINO))
31319 + br = au_sbr(sb, bindex);
31320 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
31323 + if (au_opt_test(mnt_flags, TRUNC_XINO)
31324 + && au_test_fs_trunc_xino(au_br_sb(br)))
31325 + xino_try_trunc(sb, br);
31326 + return 0; /* success */
31329 + AuIOErr("write failed (%d)\n", err);
31333 +/* ---------------------------------------------------------------------- */
31335 +/* aufs inode number bitmap */
31337 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
31338 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
31342 + AuDebugOn(bit < 0 || page_bits <= bit);
31343 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
31347 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
31349 + AuDebugOn(ino < AUFS_FIRST_INO);
31350 + ino -= AUFS_FIRST_INO;
31351 + *pindex = ino / page_bits;
31352 + *bit = ino % page_bits;
31355 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
31360 + struct au_sbinfo *sbinfo;
31361 + struct file *xib;
31362 + unsigned long *p;
31364 + sbinfo = au_sbi(sb);
31365 + MtxMustLock(&sbinfo->si_xib_mtx);
31366 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
31367 + || !au_opt_test(sbinfo->si_mntflags, XINO));
31369 + if (pindex == sbinfo->si_xib_last_pindex)
31372 + xib = sbinfo->si_xib;
31373 + p = sbinfo->si_xib_buf;
31374 + pos = sbinfo->si_xib_last_pindex;
31375 + pos *= PAGE_SIZE;
31376 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
31377 + if (unlikely(sz != PAGE_SIZE))
31381 + pos *= PAGE_SIZE;
31382 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
31383 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
31385 + memset(p, 0, PAGE_SIZE);
31386 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
31388 + if (sz == PAGE_SIZE) {
31389 + sbinfo->si_xib_last_pindex = pindex;
31390 + return 0; /* success */
31394 + AuIOErr1("write failed (%zd)\n", sz);
31401 +/* ---------------------------------------------------------------------- */
31403 +static void au_xib_clear_bit(struct inode *inode)
31406 + unsigned long pindex;
31407 + struct super_block *sb;
31408 + struct au_sbinfo *sbinfo;
31410 + AuDebugOn(inode->i_nlink);
31412 + sb = inode->i_sb;
31413 + xib_calc_bit(inode->i_ino, &pindex, &bit);
31414 + AuDebugOn(page_bits <= bit);
31415 + sbinfo = au_sbi(sb);
31416 + mutex_lock(&sbinfo->si_xib_mtx);
31417 + err = xib_pindex(sb, pindex);
31419 + clear_bit(bit, sbinfo->si_xib_buf);
31420 + sbinfo->si_xib_next_bit = bit;
31422 + mutex_unlock(&sbinfo->si_xib_mtx);
31425 +/* for s_op->delete_inode() */
31426 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
31429 + unsigned int mnt_flags;
31430 + aufs_bindex_t bindex, bend, bi;
31431 + unsigned char try_trunc;
31432 + struct au_iinfo *iinfo;
31433 + struct super_block *sb;
31434 + struct au_hinode *hi;
31435 + struct inode *h_inode;
31436 + struct au_branch *br;
31437 + au_writef_t xwrite;
31439 + sb = inode->i_sb;
31440 + mnt_flags = au_mntflags(sb);
31441 + if (!au_opt_test(mnt_flags, XINO)
31442 + || inode->i_ino == AUFS_ROOT_INO)
31446 + au_xigen_inc(inode);
31447 + au_xib_clear_bit(inode);
31450 + iinfo = au_ii(inode);
31454 + bindex = iinfo->ii_bstart;
31458 + xwrite = au_sbi(sb)->si_xwrite;
31459 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
31460 + hi = iinfo->ii_hinode + bindex;
31461 + bend = iinfo->ii_bend;
31462 + for (; bindex <= bend; bindex++, hi++) {
31463 + h_inode = hi->hi_inode;
31465 + || (!unlinked && h_inode->i_nlink))
31468 + /* inode may not be revalidated */
31469 + bi = au_br_index(sb, hi->hi_id);
31473 + br = au_sbr(sb, bi);
31474 + err = au_xino_do_write(xwrite, br->br_xino.xi_file,
31475 + h_inode->i_ino, /*ino*/0);
31476 + if (!err && try_trunc
31477 + && au_test_fs_trunc_xino(au_br_sb(br)))
31478 + xino_try_trunc(sb, br);
31482 +/* get an unused inode number from bitmap */
31483 +ino_t au_xino_new_ino(struct super_block *sb)
31486 + unsigned long *p, pindex, ul, pend;
31487 + struct au_sbinfo *sbinfo;
31488 + struct file *file;
31489 + int free_bit, err;
31491 + if (!au_opt_test(au_mntflags(sb), XINO))
31492 + return iunique(sb, AUFS_FIRST_INO);
31494 + sbinfo = au_sbi(sb);
31495 + mutex_lock(&sbinfo->si_xib_mtx);
31496 + p = sbinfo->si_xib_buf;
31497 + free_bit = sbinfo->si_xib_next_bit;
31498 + if (free_bit < page_bits && !test_bit(free_bit, p))
31499 + goto out; /* success */
31500 + free_bit = find_first_zero_bit(p, page_bits);
31501 + if (free_bit < page_bits)
31502 + goto out; /* success */
31504 + pindex = sbinfo->si_xib_last_pindex;
31505 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
31506 + err = xib_pindex(sb, ul);
31507 + if (unlikely(err))
31509 + free_bit = find_first_zero_bit(p, page_bits);
31510 + if (free_bit < page_bits)
31511 + goto out; /* success */
31514 + file = sbinfo->si_xib;
31515 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
31516 + for (ul = pindex + 1; ul <= pend; ul++) {
31517 + err = xib_pindex(sb, ul);
31518 + if (unlikely(err))
31520 + free_bit = find_first_zero_bit(p, page_bits);
31521 + if (free_bit < page_bits)
31522 + goto out; /* success */
31527 + set_bit(free_bit, p);
31528 + sbinfo->si_xib_next_bit = free_bit + 1;
31529 + pindex = sbinfo->si_xib_last_pindex;
31530 + mutex_unlock(&sbinfo->si_xib_mtx);
31531 + ino = xib_calc_ino(pindex, free_bit);
31532 + AuDbg("i%lu\n", (unsigned long)ino);
31535 + mutex_unlock(&sbinfo->si_xib_mtx);
31541 + * read @ino from xinofile for the specified branch{@sb, @bindex}
31542 + * at the position of @h_ino.
31543 + * if @ino does not exist and @do_new is true, get new one.
31545 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
31551 + struct file *file;
31552 + struct au_sbinfo *sbinfo;
31555 + if (!au_opt_test(au_mntflags(sb), XINO))
31556 + return 0; /* no xino */
31559 + sbinfo = au_sbi(sb);
31561 + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) {
31562 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
31565 + pos *= sizeof(*ino);
31567 + file = au_sbr(sb, bindex)->br_xino.xi_file;
31568 + if (vfsub_f_size_read(file) < pos + sizeof(*ino))
31569 + return 0; /* no ino */
31571 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
31572 + if (sz == sizeof(*ino))
31573 + return 0; /* success */
31576 + if (unlikely(sz >= 0)) {
31578 + AuIOErr("xino read error (%zd)\n", sz);
31584 +/* ---------------------------------------------------------------------- */
31586 +/* create and set a new xino file */
31588 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent)
31590 + struct file *file;
31591 + struct dentry *h_parent, *d;
31592 + struct inode *h_dir;
31596 + * at mount-time, and the xino file is the default path,
31597 + * hnotify is disabled so we have no notify events to ignore.
31598 + * when a user specified the xino, we cannot get au_hdir to be ignored.
31600 + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
31601 + /* | __FMODE_NONOTIFY */,
31602 + S_IRUGO | S_IWUGO);
31603 + if (IS_ERR(file)) {
31605 + pr_err("open %s(%ld)\n", fname, PTR_ERR(file));
31609 + /* keep file count */
31610 + h_parent = dget_parent(file->f_dentry);
31611 + h_dir = h_parent->d_inode;
31612 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
31613 + /* mnt_want_write() is unnecessary here */
31614 + err = vfsub_unlink(h_dir, &file->f_path, /*force*/0);
31615 + mutex_unlock(&h_dir->i_mutex);
31617 + if (unlikely(err)) {
31619 + pr_err("unlink %s(%d)\n", fname, err);
31624 + d = file->f_dentry;
31625 + if (unlikely(sb == d->d_sb)) {
31627 + pr_err("%s must be outside\n", fname);
31630 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
31632 + pr_err("xino doesn't support %s(%s)\n",
31633 + fname, au_sbtype(d->d_sb));
31636 + return file; /* success */
31640 + file = ERR_PTR(err);
31645 + * find another branch who is on the same filesystem of the specified
31646 + * branch{@btgt}. search until @bend.
31648 +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
31649 + aufs_bindex_t bend)
31651 + aufs_bindex_t bindex;
31652 + struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
31654 + for (bindex = 0; bindex < btgt; bindex++)
31655 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
31657 + for (bindex++; bindex <= bend; bindex++)
31658 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
31663 +/* ---------------------------------------------------------------------- */
31666 + * initialize the xinofile for the specified branch @br
31667 + * at the place/path where @base_file indicates.
31668 + * test whether another branch is on the same filesystem or not,
31669 + * if @do_test is true.
31671 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
31672 + struct file *base_file, int do_test)
31676 + aufs_bindex_t bend, bindex;
31677 + struct au_branch *shared_br, *b;
31678 + struct file *file;
31679 + struct super_block *tgt_sb;
31681 + shared_br = NULL;
31682 + bend = au_sbend(sb);
31684 + tgt_sb = au_br_sb(br);
31685 + for (bindex = 0; bindex <= bend; bindex++) {
31686 + b = au_sbr(sb, bindex);
31687 + if (tgt_sb == au_br_sb(b)) {
31694 + if (!shared_br || !shared_br->br_xino.xi_file) {
31695 + struct au_xino_lock_dir ldir;
31697 + au_xino_lock_dir(sb, base_file, &ldir);
31698 + /* mnt_want_write() is unnecessary here */
31699 + file = au_xino_create2(base_file, NULL);
31700 + au_xino_unlock_dir(&ldir);
31701 + err = PTR_ERR(file);
31702 + if (IS_ERR(file))
31704 + br->br_xino.xi_file = file;
31706 + br->br_xino.xi_file = shared_br->br_xino.xi_file;
31707 + get_file(br->br_xino.xi_file);
31710 + ino = AUFS_ROOT_INO;
31711 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
31713 + if (unlikely(err)) {
31714 + fput(br->br_xino.xi_file);
31715 + br->br_xino.xi_file = NULL;
31722 +/* ---------------------------------------------------------------------- */
31724 +/* trucate a xino bitmap file */
31727 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
31731 + unsigned long pindex;
31732 + loff_t pos, pend;
31733 + struct au_sbinfo *sbinfo;
31736 + unsigned long *p;
31739 + sbinfo = au_sbi(sb);
31740 + MtxMustLock(&sbinfo->si_xib_mtx);
31741 + p = sbinfo->si_xib_buf;
31742 + func = sbinfo->si_xread;
31743 + pend = vfsub_f_size_read(file);
31745 + while (pos < pend) {
31746 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
31748 + if (unlikely(sz <= 0))
31752 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
31753 + if (unlikely(*ino < AUFS_FIRST_INO))
31756 + xib_calc_bit(*ino, &pindex, &bit);
31757 + AuDebugOn(page_bits <= bit);
31758 + err = xib_pindex(sb, pindex);
31770 +static int xib_restore(struct super_block *sb)
31773 + aufs_bindex_t bindex, bend;
31777 + page = (void *)__get_free_page(GFP_NOFS);
31778 + if (unlikely(!page))
31782 + bend = au_sbend(sb);
31783 + for (bindex = 0; !err && bindex <= bend; bindex++)
31784 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
31785 + err = do_xib_restore
31786 + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page);
31788 + AuDbg("b%d\n", bindex);
31789 + free_page((unsigned long)page);
31795 +int au_xib_trunc(struct super_block *sb)
31800 + struct au_xino_lock_dir ldir;
31801 + struct au_sbinfo *sbinfo;
31802 + unsigned long *p;
31803 + struct file *file;
31805 + SiMustWriteLock(sb);
31808 + sbinfo = au_sbi(sb);
31809 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
31812 + file = sbinfo->si_xib;
31813 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
31816 + au_xino_lock_dir(sb, file, &ldir);
31817 + /* mnt_want_write() is unnecessary here */
31818 + file = au_xino_create2(sbinfo->si_xib, NULL);
31819 + au_xino_unlock_dir(&ldir);
31820 + err = PTR_ERR(file);
31821 + if (IS_ERR(file))
31823 + fput(sbinfo->si_xib);
31824 + sbinfo->si_xib = file;
31826 + p = sbinfo->si_xib_buf;
31827 + memset(p, 0, PAGE_SIZE);
31829 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
31830 + if (unlikely(sz != PAGE_SIZE)) {
31832 + AuIOErr("err %d\n", err);
31838 + mutex_lock(&sbinfo->si_xib_mtx);
31839 + /* mnt_want_write() is unnecessary here */
31840 + err = xib_restore(sb);
31841 + mutex_unlock(&sbinfo->si_xib_mtx);
31847 +/* ---------------------------------------------------------------------- */
31850 + * xino mount option handlers
31852 +static au_readf_t find_readf(struct file *h_file)
31854 + const struct file_operations *fop = h_file->f_op;
31858 + return fop->read;
31859 + if (fop->aio_read)
31860 + return do_sync_read;
31862 + return ERR_PTR(-ENOSYS);
31865 +static au_writef_t find_writef(struct file *h_file)
31867 + const struct file_operations *fop = h_file->f_op;
31871 + return fop->write;
31872 + if (fop->aio_write)
31873 + return do_sync_write;
31875 + return ERR_PTR(-ENOSYS);
31879 +static void xino_clear_xib(struct super_block *sb)
31881 + struct au_sbinfo *sbinfo;
31883 + SiMustWriteLock(sb);
31885 + sbinfo = au_sbi(sb);
31886 + sbinfo->si_xread = NULL;
31887 + sbinfo->si_xwrite = NULL;
31888 + if (sbinfo->si_xib)
31889 + fput(sbinfo->si_xib);
31890 + sbinfo->si_xib = NULL;
31891 + free_page((unsigned long)sbinfo->si_xib_buf);
31892 + sbinfo->si_xib_buf = NULL;
31895 +static int au_xino_set_xib(struct super_block *sb, struct file *base)
31899 + struct au_sbinfo *sbinfo;
31900 + struct file *file;
31902 + SiMustWriteLock(sb);
31904 + sbinfo = au_sbi(sb);
31905 + file = au_xino_create2(base, sbinfo->si_xib);
31906 + err = PTR_ERR(file);
31907 + if (IS_ERR(file))
31909 + if (sbinfo->si_xib)
31910 + fput(sbinfo->si_xib);
31911 + sbinfo->si_xib = file;
31912 + sbinfo->si_xread = find_readf(file);
31913 + sbinfo->si_xwrite = find_writef(file);
31916 + if (!sbinfo->si_xib_buf)
31917 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
31918 + if (unlikely(!sbinfo->si_xib_buf))
31921 + sbinfo->si_xib_last_pindex = 0;
31922 + sbinfo->si_xib_next_bit = 0;
31923 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
31925 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
31926 + PAGE_SIZE, &pos);
31927 + if (unlikely(err != PAGE_SIZE))
31931 + goto out; /* success */
31934 + free_page((unsigned long)sbinfo->si_xib_buf);
31935 + sbinfo->si_xib_buf = NULL;
31939 + fput(sbinfo->si_xib);
31940 + sbinfo->si_xib = NULL;
31941 + sbinfo->si_xread = NULL;
31942 + sbinfo->si_xwrite = NULL;
31947 +/* xino for each branch */
31948 +static void xino_clear_br(struct super_block *sb)
31950 + aufs_bindex_t bindex, bend;
31951 + struct au_branch *br;
31953 + bend = au_sbend(sb);
31954 + for (bindex = 0; bindex <= bend; bindex++) {
31955 + br = au_sbr(sb, bindex);
31956 + if (!br || !br->br_xino.xi_file)
31959 + fput(br->br_xino.xi_file);
31960 + br->br_xino.xi_file = NULL;
31964 +static int au_xino_set_br(struct super_block *sb, struct file *base)
31968 + aufs_bindex_t bindex, bend, bshared;
31970 + struct file *old, *new;
31972 + struct au_branch *br;
31973 + struct inode *inode;
31974 + au_writef_t writef;
31976 + SiMustWriteLock(sb);
31979 + bend = au_sbend(sb);
31980 + fpair = kcalloc(bend + 1, sizeof(*fpair), GFP_NOFS);
31981 + if (unlikely(!fpair))
31984 + inode = sb->s_root->d_inode;
31985 + ino = AUFS_ROOT_INO;
31986 + writef = au_sbi(sb)->si_xwrite;
31987 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
31988 + br = au_sbr(sb, bindex);
31989 + bshared = is_sb_shared(sb, bindex, bindex - 1);
31990 + if (bshared >= 0) {
31991 + /* shared xino */
31992 + *p = fpair[bshared];
31993 + get_file(p->new);
31998 + p->old = br->br_xino.xi_file;
31999 + p->new = au_xino_create2(base, br->br_xino.xi_file);
32000 + err = PTR_ERR(p->new);
32001 + if (IS_ERR(p->new)) {
32007 + err = au_xino_do_write(writef, p->new,
32008 + au_h_iptr(inode, bindex)->i_ino, ino);
32009 + if (unlikely(err))
32013 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
32014 + br = au_sbr(sb, bindex);
32015 + if (br->br_xino.xi_file)
32016 + fput(br->br_xino.xi_file);
32017 + get_file(p->new);
32018 + br->br_xino.xi_file = p->new;
32022 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++)
32032 +void au_xino_clr(struct super_block *sb)
32034 + struct au_sbinfo *sbinfo;
32036 + au_xigen_clr(sb);
32037 + xino_clear_xib(sb);
32038 + xino_clear_br(sb);
32039 + sbinfo = au_sbi(sb);
32040 + /* lvalue, do not call au_mntflags() */
32041 + au_opt_clr(sbinfo->si_mntflags, XINO);
32044 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
32047 + struct dentry *parent, *cur_parent;
32048 + struct qstr *dname, *cur_name;
32049 + struct file *cur_xino;
32050 + struct inode *dir;
32051 + struct au_sbinfo *sbinfo;
32053 + SiMustWriteLock(sb);
32056 + sbinfo = au_sbi(sb);
32057 + parent = dget_parent(xino->file->f_dentry);
32060 + dname = &xino->file->f_dentry->d_name;
32061 + cur_xino = sbinfo->si_xib;
32063 + cur_parent = dget_parent(cur_xino->f_dentry);
32064 + cur_name = &cur_xino->f_dentry->d_name;
32065 + skip = (cur_parent == parent
32066 + && dname->len == cur_name->len
32067 + && !memcmp(dname->name, cur_name->name,
32069 + dput(cur_parent);
32075 + au_opt_set(sbinfo->si_mntflags, XINO);
32076 + dir = parent->d_inode;
32077 + mutex_lock_nested(&dir->i_mutex, AuLsc_I_PARENT);
32078 + /* mnt_want_write() is unnecessary here */
32079 + err = au_xino_set_xib(sb, xino->file);
32081 + err = au_xigen_set(sb, xino->file);
32083 + err = au_xino_set_br(sb, xino->file);
32084 + mutex_unlock(&dir->i_mutex);
32086 + goto out; /* success */
32089 + AuIOErr("failed creating xino(%d).\n", err);
32096 +/* ---------------------------------------------------------------------- */
32099 + * create a xinofile at the default place/path.
32101 +struct file *au_xino_def(struct super_block *sb)
32103 + struct file *file;
32105 + struct au_branch *br;
32106 + struct super_block *h_sb;
32107 + struct path path;
32108 + aufs_bindex_t bend, bindex, bwr;
32111 + bend = au_sbend(sb);
32113 + for (bindex = 0; bindex <= bend; bindex++) {
32114 + br = au_sbr(sb, bindex);
32115 + if (au_br_writable(br->br_perm)
32116 + && !au_test_fs_bad_xino(au_br_sb(br))) {
32123 + file = ERR_PTR(-ENOMEM);
32124 + page = (void *)__get_free_page(GFP_NOFS);
32125 + if (unlikely(!page))
32127 + path.mnt = au_br_mnt(br);
32128 + path.dentry = au_h_dptr(sb->s_root, bwr);
32129 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
32130 + file = (void *)p;
32131 + if (!IS_ERR(p)) {
32132 + strcat(p, "/" AUFS_XINO_FNAME);
32133 + AuDbg("%s\n", p);
32134 + file = au_xino_create(sb, p, /*silent*/0);
32135 + if (!IS_ERR(file))
32136 + au_xino_brid_set(sb, br->br_id);
32138 + free_page((unsigned long)page);
32140 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
32141 + if (IS_ERR(file))
32143 + h_sb = file->f_dentry->d_sb;
32144 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
32145 + pr_err("xino doesn't support %s(%s)\n",
32146 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
32148 + file = ERR_PTR(-EINVAL);
32150 + if (!IS_ERR(file))
32151 + au_xino_brid_set(sb, -1);
32158 +/* ---------------------------------------------------------------------- */
32160 +int au_xino_path(struct seq_file *seq, struct file *file)
32164 + err = au_seq_path(seq, &file->f_path);
32165 + if (unlikely(err < 0))
32169 +#define Deleted "\\040(deleted)"
32170 + seq->count -= sizeof(Deleted) - 1;
32171 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
32172 + sizeof(Deleted) - 1));
32178 diff -urN /usr/share/empty/include/linux/aufs_type.h linux/include/linux/aufs_type.h
32179 --- /usr/share/empty/include/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
32180 +++ linux/include/linux/aufs_type.h 2013-07-06 13:20:47.760198800 +0200
32183 + * Copyright (C) 2012-2013 Junjiro R. Okajima
32185 + * This program, aufs is free software; you can redistribute it and/or modify
32186 + * it under the terms of the GNU General Public License as published by
32187 + * the Free Software Foundation; either version 2 of the License, or
32188 + * (at your option) any later version.
32190 + * This program is distributed in the hope that it will be useful,
32191 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32192 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32193 + * GNU General Public License for more details.
32195 + * You should have received a copy of the GNU General Public License
32196 + * along with this program; if not, write to the Free Software
32197 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32200 +#include <uapi/linux/aufs_type.h>
32201 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
32202 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
32203 +++ linux/include/uapi/linux/aufs_type.h 2013-10-26 16:51:32.276373845 +0200
32206 + * Copyright (C) 2005-2013 Junjiro R. Okajima
32208 + * This program, aufs is free software; you can redistribute it and/or modify
32209 + * it under the terms of the GNU General Public License as published by
32210 + * the Free Software Foundation; either version 2 of the License, or
32211 + * (at your option) any later version.
32213 + * This program is distributed in the hope that it will be useful,
32214 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32215 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32216 + * GNU General Public License for more details.
32218 + * You should have received a copy of the GNU General Public License
32219 + * along with this program; if not, write to the Free Software
32220 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32223 +#ifndef __AUFS_TYPE_H__
32224 +#define __AUFS_TYPE_H__
32226 +#define AUFS_NAME "aufs"
32230 + * define it before including all other headers.
32231 + * sched.h may use pr_* macros before defining "current", so define the
32232 + * no-current version first, and re-define later.
32234 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
32235 +#include <linux/sched.h>
32237 +#define pr_fmt(fmt) \
32238 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
32239 + (int)sizeof(current->comm), current->comm, current->pid
32241 +#include <stdint.h>
32242 +#include <sys/types.h>
32243 +#endif /* __KERNEL__ */
32245 +#include <linux/limits.h>
32247 +#define AUFS_VERSION "3.x-rcN-20131014"
32249 +/* todo? move this to linux-2.6.19/include/magic.h */
32250 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
32252 +/* ---------------------------------------------------------------------- */
32254 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
32255 +typedef int8_t aufs_bindex_t;
32256 +#define AUFS_BRANCH_MAX 127
32258 +typedef int16_t aufs_bindex_t;
32259 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
32260 +#define AUFS_BRANCH_MAX 511
32261 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
32262 +#define AUFS_BRANCH_MAX 1023
32263 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
32264 +#define AUFS_BRANCH_MAX 32767
32269 +#ifndef AUFS_BRANCH_MAX
32270 +#error unknown CONFIG_AUFS_BRANCH_MAX value
32272 +#endif /* __KERNEL__ */
32274 +/* ---------------------------------------------------------------------- */
32276 +#define AUFS_FSTYPE AUFS_NAME
32278 +#define AUFS_ROOT_INO 2
32279 +#define AUFS_FIRST_INO 11
32281 +#define AUFS_WH_PFX ".wh."
32282 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
32283 +#define AUFS_WH_TMP_LEN 4
32284 +/* a limit for rmdir/rename a dir and copyup */
32285 +#define AUFS_MAX_NAMELEN (NAME_MAX \
32286 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
32288 + - AUFS_WH_TMP_LEN) /* hex */
32289 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
32290 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
32291 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
32292 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
32293 +#define AUFS_DIRWH_DEF 3
32294 +#define AUFS_RDCACHE_DEF 10 /* seconds */
32295 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
32296 +#define AUFS_RDBLK_DEF 512 /* bytes */
32297 +#define AUFS_RDHASH_DEF 32
32298 +#define AUFS_WKQ_NAME AUFS_NAME "d"
32299 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
32300 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
32301 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
32303 +/* pseudo-link maintenace under /proc */
32304 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
32305 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
32306 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
32308 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
32309 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
32311 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
32312 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
32313 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
32315 +/* doubly whiteouted */
32316 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
32317 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
32318 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
32320 +/* branch permissions and attributes */
32321 +#define AUFS_BRPERM_RW "rw"
32322 +#define AUFS_BRPERM_RO "ro"
32323 +#define AUFS_BRPERM_RR "rr"
32324 +#define AUFS_BRRATTR_WH "wh"
32325 +#define AUFS_BRWATTR_NLWH "nolwh"
32326 +#define AUFS_BRATTR_UNPIN "unpin"
32328 +/* ---------------------------------------------------------------------- */
32332 + /* readdir in userspace */
32336 + /* pathconf wrapper */
32346 +/* borrowed from linux/include/linux/kernel.h */
32348 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
32349 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
32352 +/* borrowed from linux/include/linux/compiler-gcc3.h */
32354 +#define __aligned(x) __attribute__((aligned(x)))
32359 +#define __packed __attribute__((packed))
32363 +struct au_rdu_cookie {
32368 + uint32_t generation;
32371 +struct au_rdu_ent {
32380 +static inline int au_rdu_len(int nlen)
32382 + /* include the terminating NULL */
32383 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
32384 + sizeof(uint64_t));
32387 +union au_rdu_ent_ul {
32388 + struct au_rdu_ent __user *e;
32400 + uint64_t sz; /* AuCtl_RDU */
32401 + uint64_t nent; /* AuCtl_RDU_INO */
32403 + union au_rdu_ent_ul ent;
32404 + uint16_t verify[AufsCtlRduV_End];
32406 + /* input/output */
32410 + union au_rdu_ent_ul tail;
32411 + /* number of entries which were added in a single call */
32416 + struct au_rdu_cookie cookie;
32419 +/* ---------------------------------------------------------------------- */
32421 +struct aufs_wbr_fd {
32426 +/* ---------------------------------------------------------------------- */
32428 +struct aufs_ibusy {
32429 + uint64_t ino, h_ino;
32433 +/* ---------------------------------------------------------------------- */
32435 +/* error code for move-down */
32436 +/* the actual message strings are implemented in aufs-util.git */
32438 + EAU_MVDOWN_OPAQUE = 1,
32439 + EAU_MVDOWN_WHITEOUT,
32440 + EAU_MVDOWN_UPPER,
32441 + EAU_MVDOWN_BOTTOM,
32442 + EAU_MVDOWN_NOUPPER,
32443 + EAU_MVDOWN_NOLOWERBR,
32447 +/* flags for move-down */
32448 +#define AUFS_MVDOWN_DMSG 1
32449 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
32450 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
32451 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
32452 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
32453 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
32454 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
32455 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
32456 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
32457 +/* will be added more */
32460 + AUFS_MVDOWN_UPPER,
32461 + AUFS_MVDOWN_LOWER,
32462 + AUFS_MVDOWN_NARRAY
32465 +struct aufs_mvdown {
32470 + } a[AUFS_MVDOWN_NARRAY];
32472 + /* will be added more */
32475 +/* ---------------------------------------------------------------------- */
32477 +#define AuCtlType 'A'
32478 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
32479 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
32480 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
32481 + struct aufs_wbr_fd)
32482 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
32483 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
32484 + struct aufs_mvdown)
32486 +#endif /* __AUFS_TYPE_H__ */