3 diff --git a/fs/Kconfig b/fs/Kconfig
4 index 7385e54..d5c769c 100644
7 @@ -208,6 +208,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 47ac07b..0c6a294 100644
19 @@ -125,3 +125,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 3ce25b5..9faebdc 100644
26 --- a/include/uapi/linux/Kbuild
27 +++ b/include/uapi/linux/Kbuild
28 @@ -56,6 +56,7 @@ header-y += atmppp.h
32 +header-y += aufs_type.h
34 header-y += auto_fs4.h
38 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39 index 66e8c3b..ec278ac 100644
40 --- a/drivers/block/loop.c
41 +++ b/drivers/block/loop.c
42 @@ -692,6 +692,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/inode.c b/fs/inode.c
68 index 4bcdad3..bc83168 100644
71 @@ -1497,7 +1497,7 @@ static int relatime_need_update(struct vfsmount *mnt, struct inode *inode,
72 * This does the actual work of updating an inodes time or version. Must have
73 * had called mnt_want_write() before calling this.
75 -static int update_time(struct inode *inode, struct timespec *time, int flags)
76 +int update_time(struct inode *inode, struct timespec *time, int flags)
78 if (inode->i_op->update_time)
79 return inode->i_op->update_time(inode, time, flags);
80 diff --git a/fs/splice.c b/fs/splice.c
81 index 12028fa..f26cbaf 100644
84 @@ -1111,8 +1111,8 @@ EXPORT_SYMBOL(generic_splice_sendpage);
86 * Attempt to initiate a splice from pipe to file.
88 -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
89 - loff_t *ppos, size_t len, unsigned int flags)
90 +long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
91 + loff_t *ppos, size_t len, unsigned int flags)
93 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
94 loff_t *, size_t, unsigned int);
95 @@ -1128,9 +1128,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
97 * Attempt to initiate a splice from a file to a pipe.
99 -static long do_splice_to(struct file *in, loff_t *ppos,
100 - struct pipe_inode_info *pipe, size_t len,
101 - unsigned int flags)
102 +long do_splice_to(struct file *in, loff_t *ppos,
103 + struct pipe_inode_info *pipe, size_t len,
104 + unsigned int flags)
106 ssize_t (*splice_read)(struct file *, loff_t *,
107 struct pipe_inode_info *, size_t, unsigned int);
108 diff --git a/include/linux/fs.h b/include/linux/fs.h
109 index 23b2a35..f3f635c 100644
110 --- a/include/linux/fs.h
111 +++ b/include/linux/fs.h
112 @@ -2669,6 +2669,7 @@ extern int inode_change_ok(const struct inode *, struct iattr *);
113 extern int inode_newsize_ok(const struct inode *, loff_t offset);
114 extern void setattr_copy(struct inode *inode, const struct iattr *attr);
116 +extern int update_time(struct inode *, struct timespec *, int);
117 extern int file_update_time(struct file *file);
119 extern int generic_show_options(struct seq_file *m, struct dentry *root);
120 diff --git a/include/linux/splice.h b/include/linux/splice.h
121 index 0e43906..304169e 100644
122 --- a/include/linux/splice.h
123 +++ b/include/linux/splice.h
124 @@ -93,4 +93,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
125 extern void spd_release_page(struct splice_pipe_desc *, unsigned int);
127 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
129 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
130 + loff_t *ppos, size_t len, unsigned int flags);
131 +extern long do_splice_to(struct file *in, loff_t *ppos,
132 + struct pipe_inode_info *pipe, size_t len,
133 + unsigned int flags);
137 diff --git a/fs/buffer.c b/fs/buffer.c
138 index 27265a8..75427a6 100644
141 @@ -2448,7 +2448,7 @@ int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
142 * Update file times before taking page lock. We may end up failing the
143 * fault so this update may be superfluous but who really cares...
145 - file_update_time(vma->vm_file);
146 + vma_file_update_time(vma);
148 ret = __block_page_mkwrite(vma, vmf, get_block);
149 sb_end_pagefault(sb);
150 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
151 index d4a3574..e44a744 100644
152 --- a/fs/proc/nommu.c
153 +++ b/fs/proc/nommu.c
154 @@ -45,7 +45,9 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
155 file = region->vm_file;
158 - struct inode *inode = file_inode(region->vm_file);
159 + struct inode *inode;
160 + file = vmr_pr_or_file(region);
161 + inode = file_inode(file);
162 dev = inode->i_sb->s_dev;
165 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
166 index fb52b54..1aca72e 100644
167 --- a/fs/proc/task_mmu.c
168 +++ b/fs/proc/task_mmu.c
169 @@ -264,7 +264,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
170 const char *name = NULL;
173 - struct inode *inode = file_inode(vma->vm_file);
174 + struct inode *inode;
175 + file = vma_pr_or_file(vma);
176 + inode = file_inode(file);
177 dev = inode->i_sb->s_dev;
179 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
180 @@ -1407,6 +1409,7 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
181 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
184 + file = vma_pr_or_file(vma);
185 seq_printf(m, " file=");
186 seq_path(m, &file->f_path, "\n\t= ");
187 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
188 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
189 index 678455d..ad0ce45 100644
190 --- a/fs/proc/task_nommu.c
191 +++ b/fs/proc/task_nommu.c
192 @@ -141,7 +141,9 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
196 - struct inode *inode = file_inode(vma->vm_file);
197 + struct inode *inode;
198 + file = vma_pr_or_file(file);
199 + inode = file_inode(file);
200 dev = inode->i_sb->s_dev;
202 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
203 diff --git a/include/linux/mm.h b/include/linux/mm.h
204 index c1b7414..02036e0 100644
205 --- a/include/linux/mm.h
206 +++ b/include/linux/mm.h
208 #include <linux/pfn.h>
209 #include <linux/bit_spinlock.h>
210 #include <linux/shrinker.h>
211 +#include <linux/dcache.h>
212 +#include <linux/file.h>
213 +#include <linux/fs.h>
217 @@ -1152,6 +1155,87 @@ static inline int fixup_user_fault(struct task_struct *tsk,
222 + * Mainly for aufs which mmap(2) diffrent file and wants to print different path
223 + * in /proc/PID/maps.
225 +/* #define AUFS_DEBUG_MMAP */
226 +static inline void aufs_trace(struct file *f, struct file *pr,
227 + const char func[], int line, const char func2[])
229 +#ifdef AUFS_DEBUG_MMAP
231 + pr_info("%s:%d: %s, %p\n", func, line, func2,
232 + f ? (char *)f->f_dentry->d_name.name : "(null)");
236 +static inline struct file *vmr_do_pr_or_file(struct vm_region *region,
237 + const char func[], int line)
239 + struct file *f = region->vm_file, *pr = region->vm_prfile;
240 + aufs_trace(f, pr, func, line, __func__);
241 + return (f && pr) ? pr : f;
244 +static inline void vmr_do_fput(struct vm_region *region,
245 + const char func[], int line)
247 + struct file *f = region->vm_file, *pr = region->vm_prfile;
248 + aufs_trace(f, pr, func, line, __func__);
254 +static inline void vma_do_file_update_time(struct vm_area_struct *vma,
255 + const char func[], int line)
257 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
258 + aufs_trace(f, pr, func, line, __func__);
259 + file_update_time(f);
261 + file_update_time(pr);
264 +static inline struct file *vma_do_pr_or_file(struct vm_area_struct *vma,
265 + const char func[], int line)
267 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
268 + aufs_trace(f, pr, func, line, __func__);
269 + return (f && pr) ? pr : f;
272 +static inline void vma_do_get_file(struct vm_area_struct *vma,
273 + const char func[], int line)
275 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
276 + aufs_trace(f, pr, func, line, __func__);
282 +static inline void vma_do_fput(struct vm_area_struct *vma,
283 + const char func[], int line)
285 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
286 + aufs_trace(f, pr, func, line, __func__);
292 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
294 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
295 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
297 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
299 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
300 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
302 extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
303 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
304 void *buf, int len, int write);
305 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
306 index 290901a..c21588b 100644
307 --- a/include/linux/mm_types.h
308 +++ b/include/linux/mm_types.h
309 @@ -231,6 +231,7 @@ struct vm_region {
310 unsigned long vm_top; /* region allocated to here */
311 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
312 struct file *vm_file; /* the backing file or NULL */
313 + struct file *vm_prfile; /* the virtual backing file or NULL */
315 int vm_usage; /* region usage count (access under nommu_region_sem) */
316 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
317 @@ -299,6 +300,7 @@ struct vm_area_struct {
318 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
319 units, *not* PAGE_CACHE_SIZE */
320 struct file * vm_file; /* File we map to (can be NULL). */
321 + struct file *vm_prfile; /* shadow of vm_file */
322 void * vm_private_data; /* was vm_pte (shared mem) */
325 diff --git a/kernel/fork.c b/kernel/fork.c
326 index a17621c..40d9f6a 100644
329 @@ -412,7 +412,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
330 struct inode *inode = file_inode(file);
331 struct address_space *mapping = file->f_mapping;
335 if (tmp->vm_flags & VM_DENYWRITE)
336 atomic_dec(&inode->i_writecount);
337 mutex_lock(&mapping->i_mmap_mutex);
338 diff --git a/mm/filemap.c b/mm/filemap.c
339 index 7a13f6a..f1805df 100644
342 @@ -1733,7 +1733,7 @@ int filemap_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
343 int ret = VM_FAULT_LOCKED;
345 sb_start_pagefault(inode->i_sb);
346 - file_update_time(vma->vm_file);
347 + vma_file_update_time(vma);
349 if (page->mapping != inode->i_mapping) {
351 diff --git a/mm/fremap.c b/mm/fremap.c
352 index 34feba6..d857364 100644
355 @@ -227,7 +227,9 @@ get_write_lock:
356 /* mmap_region may free vma; grab the info now */
357 vm_flags = vma->vm_flags;
360 addr = mmap_region(file, start, size, vm_flags, pgoff);
363 if (IS_ERR_VALUE(addr)) {
365 diff --git a/mm/madvise.c b/mm/madvise.c
366 index 539eeb9..5e700b1 100644
369 @@ -327,12 +327,12 @@ static long madvise_remove(struct vm_area_struct *vma,
370 * vma's reference to the file) can go away as soon as we drop
375 up_read(¤t->mm->mmap_sem);
376 error = do_fallocate(f,
377 FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
378 offset, end - start);
381 down_read(¤t->mm->mmap_sem);
384 diff --git a/mm/memory.c b/mm/memory.c
385 index 22dfa61..81813d9 100644
388 @@ -2755,7 +2755,7 @@ reuse:
389 set_page_dirty_balance(dirty_page, page_mkwrite);
390 /* file_update_time outside page_lock */
392 - file_update_time(vma->vm_file);
393 + vma_file_update_time(vma);
395 put_page(dirty_page);
397 @@ -3467,7 +3467,7 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
399 /* file_update_time outside page_lock */
400 if (vma->vm_file && !page_mkwrite)
401 - file_update_time(vma->vm_file);
402 + vma_file_update_time(vma);
404 unlock_page(vmf.page);
406 diff --git a/mm/mmap.c b/mm/mmap.c
407 index 20ff0c3..f743033 100644
410 @@ -249,7 +249,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
411 if (vma->vm_ops && vma->vm_ops->close)
412 vma->vm_ops->close(vma);
414 - fput(vma->vm_file);
416 mpol_put(vma_policy(vma));
417 kmem_cache_free(vm_area_cachep, vma);
419 @@ -859,7 +859,7 @@ again: remove_next = 1 + (end > next->vm_end);
422 uprobe_munmap(next, next->vm_start, next->vm_end);
427 anon_vma_merge(vma, next);
428 @@ -1639,8 +1639,8 @@ out:
430 if (vm_flags & VM_DENYWRITE)
431 allow_write_access(file);
436 /* Undo any partial mapping done by a device driver. */
437 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
438 @@ -2429,7 +2429,7 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
442 - get_file(new->vm_file);
445 if (new->vm_ops && new->vm_ops->open)
446 new->vm_ops->open(new);
447 @@ -2448,7 +2448,7 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
448 if (new->vm_ops && new->vm_ops->close)
449 new->vm_ops->close(new);
451 - fput(new->vm_file);
453 unlink_anon_vmas(new);
455 mpol_put(vma_policy(new));
456 @@ -2837,7 +2837,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
457 if (anon_vma_clone(new_vma, vma))
458 goto out_free_mempol;
459 if (new_vma->vm_file)
460 - get_file(new_vma->vm_file);
461 + vma_get_file(new_vma);
462 if (new_vma->vm_ops && new_vma->vm_ops->open)
463 new_vma->vm_ops->open(new_vma);
464 vma_link(mm, new_vma, prev, rb_link, rb_parent);
465 diff --git a/mm/msync.c b/mm/msync.c
466 index 632df45..02d770e 100644
469 @@ -80,10 +80,10 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags)
471 if ((flags & MS_SYNC) && file &&
472 (vma->vm_flags & VM_SHARED)) {
475 up_read(&mm->mmap_sem);
476 error = vfs_fsync(file, 0);
479 if (error || start >= end)
481 down_read(&mm->mmap_sem);
482 diff --git a/mm/nommu.c b/mm/nommu.c
483 index 8740213..ea7e336 100644
486 @@ -653,7 +653,7 @@ static void __put_nommu_region(struct vm_region *region)
487 up_write(&nommu_region_sem);
490 - fput(region->vm_file);
493 /* IO memory and memory shared directly out of the pagecache
494 * from ramfs/tmpfs mustn't be released here */
495 @@ -811,7 +811,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
496 if (vma->vm_ops && vma->vm_ops->close)
497 vma->vm_ops->close(vma);
499 - fput(vma->vm_file);
501 put_nommu_region(vma->vm_region);
502 kmem_cache_free(vm_area_cachep, vma);
504 @@ -1377,7 +1377,7 @@ unsigned long do_mmap_pgoff(struct file *file,
505 goto error_just_free;
508 - fput(region->vm_file);
510 kmem_cache_free(vm_region_jar, region);
513 @@ -1453,10 +1453,10 @@ error_just_free:
514 up_write(&nommu_region_sem);
517 - fput(region->vm_file);
519 kmem_cache_free(vm_region_jar, region);
521 - fput(vma->vm_file);
523 kmem_cache_free(vm_area_cachep, vma);
524 kleave(" = %d", ret);
526 aufs3.14 standalone patch
528 diff --git a/fs/inode.c b/fs/inode.c
529 index bc83168..6dd1207 100644
532 @@ -57,6 +57,7 @@ static struct hlist_head *inode_hashtable __read_mostly;
533 static __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_hash_lock);
535 __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_sb_list_lock);
536 +EXPORT_SYMBOL(inode_sb_list_lock);
539 * Empty aops. Can be used for the cases where the user does not
540 @@ -1513,6 +1514,7 @@ int update_time(struct inode *inode, struct timespec *time, int flags)
541 mark_inode_dirty_sync(inode);
544 +EXPORT_SYMBOL(update_time);
547 * touch_atime - update the access time
548 diff --git a/fs/namespace.c b/fs/namespace.c
549 index 2ffc5a2..785a51f 100644
552 @@ -455,6 +455,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
553 mnt_dec_writers(real_mount(mnt));
556 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
559 * mnt_drop_write - give up write access to a mount
560 @@ -1555,6 +1556,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
564 +EXPORT_SYMBOL(iterate_mounts);
566 static void cleanup_group_ids(struct mount *mnt, struct mount *end)
568 diff --git a/fs/notify/group.c b/fs/notify/group.c
569 index ad19959..adf290d 100644
570 --- a/fs/notify/group.c
571 +++ b/fs/notify/group.c
573 #include <linux/srcu.h>
574 #include <linux/rculist.h>
575 #include <linux/wait.h>
576 +#include <linux/module.h>
578 #include <linux/fsnotify_backend.h>
579 #include "fsnotify.h"
580 @@ -72,6 +73,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
582 atomic_inc(&group->refcnt);
584 +EXPORT_SYMBOL(fsnotify_get_group);
587 * Drop a reference to a group. Free it if it's through.
588 @@ -81,6 +83,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
589 if (atomic_dec_and_test(&group->refcnt))
590 fsnotify_final_destroy_group(group);
592 +EXPORT_SYMBOL(fsnotify_put_group);
595 * Create a new fsnotify_group and hold a reference for the group returned.
596 @@ -109,6 +112,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
600 +EXPORT_SYMBOL(fsnotify_alloc_group);
602 int fsnotify_fasync(int fd, struct file *file, int on)
604 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
605 index 923fe4a..176b435 100644
606 --- a/fs/notify/mark.c
607 +++ b/fs/notify/mark.c
608 @@ -109,6 +109,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
609 mark->free_mark(mark);
612 +EXPORT_SYMBOL(fsnotify_put_mark);
615 * Any time a mark is getting freed we end up here.
616 @@ -191,6 +192,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
617 fsnotify_destroy_mark_locked(mark, group);
618 mutex_unlock(&group->mark_mutex);
620 +EXPORT_SYMBOL(fsnotify_destroy_mark);
622 void fsnotify_set_mark_mask_locked(struct fsnotify_mark *mark, __u32 mask)
624 @@ -275,6 +277,7 @@ err:
628 +EXPORT_SYMBOL(fsnotify_add_mark);
630 int fsnotify_add_mark(struct fsnotify_mark *mark, struct fsnotify_group *group,
631 struct inode *inode, struct vfsmount *mnt, int allow_dups)
632 @@ -336,6 +339,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
633 atomic_set(&mark->refcnt, 1);
634 mark->free_mark = free_mark;
636 +EXPORT_SYMBOL(fsnotify_init_mark);
638 static int fsnotify_mark_destroy(void *ignored)
640 diff --git a/fs/open.c b/fs/open.c
641 index b9ed8b2..3ea66972 100644
644 @@ -62,6 +62,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
645 mutex_unlock(&dentry->d_inode->i_mutex);
648 +EXPORT_SYMBOL(do_truncate);
650 long vfs_truncate(struct path *path, loff_t length)
652 diff --git a/fs/splice.c b/fs/splice.c
653 index f26cbaf..ac02366 100644
656 @@ -1124,6 +1124,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
658 return splice_write(pipe, out, ppos, len, flags);
660 +EXPORT_SYMBOL(do_splice_from);
663 * Attempt to initiate a splice from a file to a pipe.
664 @@ -1150,6 +1151,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
666 return splice_read(in, ppos, pipe, len, flags);
668 +EXPORT_SYMBOL(do_splice_to);
671 * splice_direct_to_actor - splices data directly between two non-pipes
672 diff --git a/security/commoncap.c b/security/commoncap.c
673 index b9d613e..ba3b618 100644
674 --- a/security/commoncap.c
675 +++ b/security/commoncap.c
676 @@ -988,9 +988,11 @@ int cap_mmap_addr(unsigned long addr)
680 +EXPORT_SYMBOL(cap_mmap_addr);
682 int cap_mmap_file(struct file *file, unsigned long reqprot,
683 unsigned long prot, unsigned long flags)
687 +EXPORT_SYMBOL(cap_mmap_file);
688 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
689 index d3b6d2c..5076912 100644
690 --- a/security/device_cgroup.c
691 +++ b/security/device_cgroup.c
693 #include <linux/device_cgroup.h>
694 #include <linux/cgroup.h>
695 #include <linux/ctype.h>
696 +#include <linux/export.h>
697 #include <linux/list.h>
698 #include <linux/uaccess.h>
699 #include <linux/seq_file.h>
700 @@ -744,6 +745,7 @@ int __devcgroup_inode_permission(struct inode *inode, int mask)
701 return __devcgroup_check_permission(type, imajor(inode), iminor(inode),
704 +EXPORT_SYMBOL(__devcgroup_inode_permission);
706 int devcgroup_inode_mknod(int mode, dev_t dev)
708 diff --git a/security/security.c b/security/security.c
709 index 919cad9..f9e9e17 100644
710 --- a/security/security.c
711 +++ b/security/security.c
712 @@ -407,6 +407,7 @@ int security_path_rmdir(struct path *dir, struct dentry *dentry)
714 return security_ops->path_rmdir(dir, dentry);
716 +EXPORT_SYMBOL(security_path_rmdir);
718 int security_path_unlink(struct path *dir, struct dentry *dentry)
720 @@ -423,6 +424,7 @@ int security_path_symlink(struct path *dir, struct dentry *dentry,
722 return security_ops->path_symlink(dir, dentry, old_name);
724 +EXPORT_SYMBOL(security_path_symlink);
726 int security_path_link(struct dentry *old_dentry, struct path *new_dir,
727 struct dentry *new_dentry)
728 @@ -431,6 +433,7 @@ int security_path_link(struct dentry *old_dentry, struct path *new_dir,
730 return security_ops->path_link(old_dentry, new_dir, new_dentry);
732 +EXPORT_SYMBOL(security_path_link);
734 int security_path_rename(struct path *old_dir, struct dentry *old_dentry,
735 struct path *new_dir, struct dentry *new_dentry)
736 @@ -449,6 +452,7 @@ int security_path_truncate(struct path *path)
738 return security_ops->path_truncate(path);
740 +EXPORT_SYMBOL(security_path_truncate);
742 int security_path_chmod(struct path *path, umode_t mode)
744 @@ -456,6 +460,7 @@ int security_path_chmod(struct path *path, umode_t mode)
746 return security_ops->path_chmod(path, mode);
748 +EXPORT_SYMBOL(security_path_chmod);
750 int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
752 @@ -463,6 +468,7 @@ int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
754 return security_ops->path_chown(path, uid, gid);
756 +EXPORT_SYMBOL(security_path_chown);
758 int security_path_chroot(struct path *path)
760 @@ -539,6 +545,7 @@ int security_inode_readlink(struct dentry *dentry)
762 return security_ops->inode_readlink(dentry);
764 +EXPORT_SYMBOL(security_inode_readlink);
766 int security_inode_follow_link(struct dentry *dentry, struct nameidata *nd)
768 @@ -553,6 +560,7 @@ int security_inode_permission(struct inode *inode, int mask)
770 return security_ops->inode_permission(inode, mask);
772 +EXPORT_SYMBOL(security_inode_permission);
774 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
776 @@ -675,6 +683,7 @@ int security_file_permission(struct file *file, int mask)
778 return fsnotify_perm(file, mask);
780 +EXPORT_SYMBOL(security_file_permission);
782 int security_file_alloc(struct file *file)
784 @@ -735,6 +744,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
786 return ima_file_mmap(file, prot);
788 +EXPORT_SYMBOL(security_mmap_file);
790 int security_mmap_addr(unsigned long addr)
792 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
793 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
794 +++ linux/Documentation/ABI/testing/debugfs-aufs 2014-04-24 22:11:10.471931783 +0200
796 +What: /debug/aufs/si_<id>/
798 +Contact: J. R. Okajima <hooanon05g@gmail.com>
800 + Under /debug/aufs, a directory named si_<id> is created
801 + per aufs mount, where <id> is a unique id generated
804 +What: /debug/aufs/si_<id>/plink
806 +Contact: J. R. Okajima <hooanon05g@gmail.com>
808 + It has three lines and shows the information about the
809 + pseudo-link. The first line is a single number
810 + representing a number of buckets. The second line is a
811 + number of pseudo-links per buckets (separated by a
812 + blank). The last line is a single number representing a
813 + total number of psedo-links.
814 + When the aufs mount option 'noplink' is specified, it
815 + will show "1\n0\n0\n".
817 +What: /debug/aufs/si_<id>/xib
819 +Contact: J. R. Okajima <hooanon05g@gmail.com>
821 + It shows the consumed blocks by xib (External Inode Number
822 + Bitmap), its block size and file size.
823 + When the aufs mount option 'noxino' is specified, it
824 + will be empty. About XINO files, see the aufs manual.
826 +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN
828 +Contact: J. R. Okajima <hooanon05g@gmail.com>
830 + It shows the consumed blocks by xino (External Inode Number
831 + Translation Table), its link count, block size and file
833 + When the aufs mount option 'noxino' is specified, it
834 + will be empty. About XINO files, see the aufs manual.
836 +What: /debug/aufs/si_<id>/xigen
838 +Contact: J. R. Okajima <hooanon05g@gmail.com>
840 + It shows the consumed blocks by xigen (External Inode
841 + Generation Table), its block size and file size.
842 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
844 + When the aufs mount option 'noxino' is specified, it
845 + will be empty. About XINO files, see the aufs manual.
846 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
847 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
848 +++ linux/Documentation/ABI/testing/sysfs-aufs 2014-04-24 22:11:10.471931783 +0200
850 +What: /sys/fs/aufs/si_<id>/
852 +Contact: J. R. Okajima <hooanon05g@gmail.com>
854 + Under /sys/fs/aufs, a directory named si_<id> is created
855 + per aufs mount, where <id> is a unique id generated
858 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
860 +Contact: J. R. Okajima <hooanon05g@gmail.com>
862 + It shows the abolute path of a member directory (which
863 + is called branch) in aufs, and its permission.
865 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
867 +Contact: J. R. Okajima <hooanon05g@gmail.com>
869 + It shows the id of a member directory (which is called
872 +What: /sys/fs/aufs/si_<id>/xi_path
874 +Contact: J. R. Okajima <hooanon05g@gmail.com>
876 + It shows the abolute path of XINO (External Inode Number
877 + Bitmap, Translation Table and Generation Table) file
878 + even if it is the default path.
879 + When the aufs mount option 'noxino' is specified, it
880 + will be empty. About XINO files, see the aufs manual.
881 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
882 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
883 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2014-04-24 22:11:10.471931783 +0200
886 +# Copyright (C) 2005-2014 Junjiro R. Okajima
888 +# This program is free software; you can redistribute it and/or modify
889 +# it under the terms of the GNU General Public License as published by
890 +# the Free Software Foundation; either version 2 of the License, or
891 +# (at your option) any later version.
893 +# This program is distributed in the hope that it will be useful,
894 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
895 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
896 +# GNU General Public License for more details.
898 +# You should have received a copy of the GNU General Public License
899 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
902 +----------------------------------------
904 +aufs [ei ju: ef es] | [a u f s]
905 +1. abbrev. for "advanced multi-layered unification filesystem".
906 +2. abbrev. for "another unionfs".
907 +3. abbrev. for "auf das" in German which means "on the" in English.
908 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
909 + But "Filesystem aufs Filesystem" is hard to understand.
911 +AUFS is a filesystem with features:
912 +- multi layered stackable unification filesystem, the member directory
913 + is called as a branch.
914 +- branch permission and attribute, 'readonly', 'real-readonly',
915 + 'readwrite', 'whiteout-able', 'link-able whiteout' and their
917 +- internal "file copy-on-write".
918 +- logical deletion, whiteout.
919 +- dynamic branch manipulation, adding, deleting and changing permission.
920 +- allow bypassing aufs, user's direct branch access.
921 +- external inode number translation table and bitmap which maintains the
922 + persistent aufs inode number.
923 +- seekable directory, including NFS readdir.
924 +- file mapping, mmap and sharing pages.
925 +- pseudo-link, hardlink over branches.
926 +- loopback mounted filesystem as a branch.
927 +- several policies to select one among multiple writable branches.
928 +- revert a single systemcall when an error occurs in aufs.
932 +Multi Layered Stackable Unification Filesystem
933 +----------------------------------------------------------------------
934 +Most people already knows what it is.
935 +It is a filesystem which unifies several directories and provides a
936 +merged single directory. When users access a file, the access will be
937 +passed/re-directed/converted (sorry, I am not sure which English word is
938 +correct) to the real file on the member filesystem. The member
939 +filesystem is called 'lower filesystem' or 'branch' and has a mode
940 +'readonly' and 'readwrite.' And the deletion for a file on the lower
941 +readonly branch is handled by creating 'whiteout' on the upper writable
944 +On LKML, there have been discussions about UnionMount (Jan Blunck,
945 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
946 +different approaches to implement the merged-view.
947 +The former tries putting it into VFS, and the latter implements as a
948 +separate filesystem.
949 +(If I misunderstand about these implementations, please let me know and
950 +I shall correct it. Because it is a long time ago when I read their
951 +source files last time).
953 +UnionMount's approach will be able to small, but may be hard to share
954 +branches between several UnionMount since the whiteout in it is
955 +implemented in the inode on branch filesystem and always
956 +shared. According to Bharata's post, readdir does not seems to be
958 +There are several missing features known in this implementations such as
959 +- for users, the inode number may change silently. eg. copy-up.
960 +- link(2) may break by copy-up.
961 +- read(2) may get an obsoleted filedata (fstat(2) too).
962 +- fcntl(F_SETLK) may be broken by copy-up.
963 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
966 +Unionfs has a longer history. When I started implementing a stacking filesystem
967 +(Aug 2005), it already existed. It has virtual super_block, inode,
968 +dentry and file objects and they have an array pointing lower same kind
969 +objects. After contributing many patches for Unionfs, I re-started my
970 +project AUFS (Jun 2006).
972 +In AUFS, the structure of filesystem resembles to Unionfs, but I
973 +implemented my own ideas, approaches and enhancements and it became
974 +totally different one.
976 +Comparing DM snapshot and fs based implementation
977 +- the number of bytes to be copied between devices is much smaller.
978 +- the type of filesystem must be one and only.
979 +- the fs must be writable, no readonly fs, even for the lower original
980 + device. so the compression fs will not be usable. but if we use
981 + loopback mount, we may address this issue.
983 + mount /cdrom/squashfs.img /sq
984 + losetup /sq/ext2.img
985 + losetup /somewhere/cow
986 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
987 +- it will be difficult (or needs more operations) to extract the
988 + difference between the original device and COW.
989 +- DM snapshot-merge may help a lot when users try merging. in the
990 + fs-layer union, users will use rsync(1).
993 +Several characters/aspects of aufs
994 +----------------------------------------------------------------------
996 +Aufs has several characters or aspects.
997 +1. a filesystem, callee of VFS helper
998 +2. sub-VFS, caller of VFS helper for branches
999 +3. a virtual filesystem which maintains persistent inode number
1000 +4. reader/writer of files on branches such like an application
1002 +1. Callee of VFS Helper
1003 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1004 +unlink(2) from an application reaches sys_unlink() kernel function and
1005 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1006 +calls filesystem specific unlink operation. Actually aufs implements the
1007 +unlink operation but it behaves like a redirector.
1009 +2. Caller of VFS Helper for Branches
1010 +aufs_unlink() passes the unlink request to the branch filesystem as if
1011 +it were called from VFS. So the called unlink operation of the branch
1012 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1013 +every necessary pre/post operation for the branch filesystem.
1014 +- acquire the lock for the parent dir on a branch
1015 +- lookup in a branch
1016 +- revalidate dentry on a branch
1017 +- mnt_want_write() for a branch
1018 +- vfs_unlink() for a branch
1019 +- mnt_drop_write() for a branch
1020 +- release the lock on a branch
1022 +3. Persistent Inode Number
1023 +One of the most important issue for a filesystem is to maintain inode
1024 +numbers. This is particularly important to support exporting a
1025 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1026 +backend block device for its own. But some storage is necessary to
1027 +maintain inode number. It may be a large space and may not suit to keep
1028 +in memory. Aufs rents some space from its first writable branch
1029 +filesystem (by default) and creates file(s) on it. These files are
1030 +created by aufs internally and removed soon (currently) keeping opened.
1031 +Note: Because these files are removed, they are totally gone after
1032 + unmounting aufs. It means the inode numbers are not persistent
1033 + across unmount or reboot. I have a plan to make them really
1034 + persistent which will be important for aufs on NFS server.
1036 +4. Read/Write Files Internally (copy-on-write)
1037 +Because a branch can be readonly, when you write a file on it, aufs will
1038 +"copy-up" it to the upper writable branch internally. And then write the
1039 +originally requested thing to the file. Generally kernel doesn't
1040 +open/read/write file actively. In aufs, even a single write may cause a
1041 +internal "file copy". This behaviour is very similar to cp(1) command.
1043 +Some people may think it is better to pass such work to user space
1044 +helper, instead of doing in kernel space. Actually I am still thinking
1045 +about it. But currently I have implemented it in kernel space.
1046 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1047 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1048 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2014-04-24 22:11:10.471931783 +0200
1051 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1053 +# This program is free software; you can redistribute it and/or modify
1054 +# it under the terms of the GNU General Public License as published by
1055 +# the Free Software Foundation; either version 2 of the License, or
1056 +# (at your option) any later version.
1058 +# This program is distributed in the hope that it will be useful,
1059 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1060 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1061 +# GNU General Public License for more details.
1063 +# You should have received a copy of the GNU General Public License
1064 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1066 +Basic Aufs Internal Structure
1068 +Superblock/Inode/Dentry/File Objects
1069 +----------------------------------------------------------------------
1070 +As like an ordinary filesystem, aufs has its own
1071 +superblock/inode/dentry/file objects. All these objects have a
1072 +dynamically allocated array and store the same kind of pointers to the
1073 +lower filesystem, branch.
1074 +For example, when you build a union with one readwrite branch and one
1075 +readonly, mounted /au, /rw and /ro respectively.
1077 +- /ro/fileA exists but /rw/fileA
1079 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1080 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1084 +This style of an array is essentially same to the aufs
1085 +superblock/inode/dentry/file objects.
1087 +Because aufs supports manipulating branches, ie. add/delete/change
1088 +dynamically, these objects has its own generation. When branches are
1089 +changed, the generation in aufs superblock is incremented. And a
1090 +generation in other object are compared when it is accessed.
1091 +When a generation in other objects are obsoleted, aufs refreshes the
1096 +----------------------------------------------------------------------
1097 +Additionally aufs superblock has some data for policies to select one
1098 +among multiple writable branches, XIB files, pseudo-links and kobject.
1099 +See below in detail.
1100 +About the policies which supports copy-down a directory, see policy.txt
1104 +Branch and XINO(External Inode Number Translation Table)
1105 +----------------------------------------------------------------------
1106 +Every branch has its own xino (external inode number translation table)
1107 +file. The xino file is created and unlinked by aufs internally. When two
1108 +members of a union exist on the same filesystem, they share the single
1110 +The struct of a xino file is simple, just a sequence of aufs inode
1111 +numbers which is indexed by the lower inode number.
1112 +In the above sample, assume the inode number of /ro/fileA is i111 and
1113 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1114 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1116 +When the inode numbers are not contiguous, the xino file will be sparse
1117 +which has a hole in it and doesn't consume as much disk space as it
1118 +might appear. If your branch filesystem consumes disk space for such
1119 +holes, then you should specify 'xino=' option at mounting aufs.
1121 +Also a writable branch has three kinds of "whiteout bases". All these
1122 +are existed when the branch is joined to aufs and the names are
1123 +whiteout-ed doubly, so that users will never see their names in aufs
1125 +1. a regular file which will be linked to all whiteouts.
1126 +2. a directory to store a pseudo-link.
1127 +3. a directory to store an "orphan-ed" file temporary.
1130 + When you remove a file on a readonly branch, aufs handles it as a
1131 + logical deletion and creates a whiteout on the upper writable branch
1132 + as a hardlink of this file in order not to consume inode on the
1135 + See below, Pseudo-link.
1137 + When "fileC" exists on the lower readonly branch only and it is
1138 + opened and removed with its parent dir, and then user writes
1139 + something into it, then aufs copies-up fileC to this
1140 + directory. Because there is no other dir to store fileC. After
1141 + creating a file under this dir, the file is unlinked.
1143 +Because aufs supports manipulating branches, ie. add/delete/change
1144 +dynamically, a branch has its own id. When the branch order changes, aufs
1145 +finds the new index by searching the branch id.
1149 +----------------------------------------------------------------------
1150 +Assume "fileA" exists on the lower readonly branch only and it is
1151 +hardlinked to "fileB" on the branch. When you write something to fileA,
1152 +aufs copies-up it to the upper writable branch. Additionally aufs
1153 +creates a hardlink under the Pseudo-link Directory of the writable
1154 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1155 +simple list. If fileB is read after unlinking fileA, aufs returns
1156 +filedata from the pseudo-link instead of the lower readonly
1157 +branch. Because the pseudo-link is based upon the inode, to keep the
1158 +inode number by xino (see above) is important.
1160 +All the hardlinks under the Pseudo-link Directory of the writable branch
1161 +should be restored in a proper location later. Aufs provides a utility
1162 +to do this. The userspace helpers executed at remounting and unmounting
1164 +During this utility is running, it puts aufs into the pseudo-link
1165 +maintenance mode. In this mode, only the process which began the
1166 +maintenance mode (and its child processes) is allowed to operate in
1167 +aufs. Some other processes which are not related to the pseudo-link will
1168 +be allowed to run too, but the rest have to return an error or wait
1169 +until the maintenance mode ends. If a process already acquires an inode
1170 +mutex (in VFS), it has to return an error.
1173 +XIB(external inode number bitmap)
1174 +----------------------------------------------------------------------
1175 +Addition to the xino file per a branch, aufs has an external inode number
1176 +bitmap in a superblock object. It is also a file such like a xino file.
1177 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1179 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1181 +Aufs implements a feature to truncate/refresh both of xino and xib to
1182 +reduce the number of consumed disk blocks for these files.
1185 +Virtual or Vertical Dir, and Readdir in Userspace
1186 +----------------------------------------------------------------------
1187 +In order to support multiple layers (branches), aufs readdir operation
1188 +constructs a virtual dir block on memory. For readdir, aufs calls
1189 +vfs_readdir() internally for each dir on branches, merges their entries
1190 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1191 +object. So the file object has its entry list until it is closed. The
1192 +entry list will be updated when the file position is zero and becomes
1193 +old. This decision is made in aufs automatically.
1195 +The dynamically allocated memory block for the name of entries has a
1196 +unit of 512 bytes (by default) and stores the names contiguously (no
1197 +padding). Another block for each entry is handled by kmem_cache too.
1198 +During building dir blocks, aufs creates hash list and judging whether
1199 +the entry is whiteouted by its upper branch or already listed.
1200 +The merged result is cached in the corresponding inode object and
1201 +maintained by a customizable life-time option.
1203 +Some people may call it can be a security hole or invite DoS attack
1204 +since the opened and once readdir-ed dir (file object) holds its entry
1205 +list and becomes a pressure for system memory. But I'd say it is similar
1206 +to files under /proc or /sys. The virtual files in them also holds a
1207 +memory page (generally) while they are opened. When an idea to reduce
1208 +memory for them is introduced, it will be applied to aufs too.
1209 +For those who really hate this situation, I've developed readdir(3)
1210 +library which operates this merging in userspace. You just need to set
1211 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1212 +kernel space for readdir(3).
1216 +----------------------------------------------------------------------
1217 +Aufs sometimes requires privilege access to a branch. For instance,
1218 +in copy-up/down operation. When a user process is going to make changes
1219 +to a file which exists in the lower readonly branch only, and the mode
1220 +of one of ancestor directories may not be writable by a user
1221 +process. Here aufs copy-up the file with its ancestors and they may
1222 +require privilege to set its owner/group/mode/etc.
1223 +This is a typical case of a application character of aufs (see
1226 +Aufs uses workqueue synchronously for this case. It creates its own
1227 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1228 +passes the request to call mkdir or write (for example), and wait for
1229 +its completion. This approach solves a problem of a signal handler
1231 +If aufs didn't adopt the workqueue and changed the privilege of the
1232 +process, and if the mkdir/write call arises SIGXFSZ or other signal,
1233 +then the user process might gain a privilege or the generated core file
1234 +was owned by a superuser.
1236 +Also aufs uses the system global workqueue ("events" kernel thread) too
1237 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1238 +whiteout base and etc. This is unrelated to a privilege.
1239 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1240 +superblock at the beginning, at the same time waits for the completion
1241 +of all queued asynchronous tasks.
1245 +----------------------------------------------------------------------
1246 +The whiteout in aufs is very similar to Unionfs's. That is represented
1247 +by its filename. UnionMount takes an approach of a file mode, but I am
1248 +afraid several utilities (find(1) or something) will have to support it.
1250 +Basically the whiteout represents "logical deletion" which stops aufs to
1251 +lookup further, but also it represents "dir is opaque" which also stop
1254 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1255 +In order to make several functions in a single systemcall to be
1256 +revertible, aufs adopts an approach to rename a directory to a temporary
1257 +unique whiteouted name.
1258 +For example, in rename(2) dir where the target dir already existed, aufs
1259 +renames the target dir to a temporary unique whiteouted name before the
1260 +actual rename on a branch and then handles other actions (make it opaque,
1261 +update the attributes, etc). If an error happens in these actions, aufs
1262 +simply renames the whiteouted name back and returns an error. If all are
1263 +succeeded, aufs registers a function to remove the whiteouted unique
1264 +temporary name completely and asynchronously to the system global
1269 +----------------------------------------------------------------------
1270 +It is a well-known feature or concept.
1271 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1272 +internally and makes change to the new file on the upper writable branch.
1273 +When the trigger systemcall does not update the timestamps of the parent
1274 +dir, aufs reverts it after copy-up.
1277 +Move-down (aufs3.9 and later)
1278 +----------------------------------------------------------------------
1279 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1280 +the lower readonly branch to the upper writable branch when a user
1281 +changes something about the file.
1282 +"Move-down" is an opposite action of copy-up. Basically this action is
1283 +ran manually instead of automatically and internally.
1285 +Sometimes users want to move-down a file from the upper writable branch
1286 +to the lower readonly or writable branch. For instance,
1287 +- the free space of the upper writable branch is going to run out.
1288 +- create a new intermediate branch between the upper and lower branch.
1291 +For this purpose, use "aumvdown" command in aufs-util.git.
1292 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1293 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1294 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2014-04-24 22:11:10.471931783 +0200
1297 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1299 +# This program is free software; you can redistribute it and/or modify
1300 +# it under the terms of the GNU General Public License as published by
1301 +# the Free Software Foundation; either version 2 of the License, or
1302 +# (at your option) any later version.
1304 +# This program is distributed in the hope that it will be useful,
1305 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1306 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1307 +# GNU General Public License for more details.
1309 +# You should have received a copy of the GNU General Public License
1310 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1313 +----------------------------------------------------------------------
1314 +Since aufs has a character of sub-VFS (see Introduction), it operates
1315 +lookup for branches as VFS does. It may be a heavy work. Generally
1316 +speaking struct nameidata is a bigger structure and includes many
1317 +information. But almost all lookup operation in aufs is the simplest
1318 +case, ie. lookup only an entry directly connected to its parent. Digging
1319 +down the directory hierarchy is unnecessary.
1321 +VFS has a function lookup_one_len() for that use, but it is not usable
1322 +for a branch filesystem which requires struct nameidata. So aufs
1323 +implements a simple lookup wrapper function. When a branch filesystem
1324 +allows NULL as nameidata, it calls lookup_one_len(). Otherwise it builds
1325 +a simplest nameidata and calls lookup_hash().
1326 +Here aufs applies "a principle in NFSD", ie. if the filesystem supports
1327 +NFS-export, then it has to support NULL as a nameidata parameter for
1328 +->create(), ->lookup() and ->d_revalidate(). So the lookup wrapper in
1329 +aufs tests if ->s_export_op in the branch is NULL or not.
1331 +When a branch is a remote filesystem, aufs basically trusts its
1332 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1334 +For d_revalidate, aufs implements three levels of revalidate tests. See
1335 +"Revalidate Dentry and UDBA" in detail.
1339 +----------------------------------------------------------------------
1340 +Basically aufs supports any type of filesystem and block device for a
1341 +branch (actually there are some exceptions). But it is prohibited to add
1342 +a loopback mounted one whose backend file exists in a filesystem which is
1343 +already added to aufs. The reason is to protect aufs from a recursive
1344 +lookup. If it was allowed, the aufs lookup operation might re-enter a
1345 +lookup for the loopback mounted branch in the same context, and will
1349 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1350 +----------------------------------------------------------------------
1351 +Generally VFS helpers re-validate a dentry as a part of lookup.
1352 +0. digging down the directory hierarchy.
1353 +1. lock the parent dir by its i_mutex.
1354 +2. lookup the final (child) entry.
1356 +4. call the actual operation (create, unlink, etc.)
1357 +5. unlock the parent dir
1359 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1360 +called. Actually aufs implements it and checks the dentry on a branch is
1362 +But it is not enough. Because aufs has to release the lock for the
1363 +parent dir on a branch at the end of ->lookup() (step 2) and
1364 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1366 +If the file on a branch is changed directly, eg. bypassing aufs, after
1367 +aufs released the lock, then the subsequent operation may cause
1368 +something unpleasant result.
1370 +This situation is a result of VFS architecture, ->lookup() and
1371 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1372 +design from VFS's point of view. It is just not suitable for sub-VFS
1375 +Aufs supports such case by three level of revalidation which is
1376 +selectable by user.
1377 +1. Simple Revalidate
1378 + Addition to the native flow in VFS's, confirm the child-parent
1379 + relationship on the branch just after locking the parent dir on the
1380 + branch in the "actual operation" (step 4). When this validation
1381 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1382 + checks the validation of the dentry on branches.
1383 +2. Monitor Changes Internally by Inotify/Fsnotify
1384 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1385 + the dentry on the branch, and returns EBUSY if it finds different
1387 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1388 + during it is in cache. When the event is notified, aufs registers a
1389 + function to kernel 'events' thread by schedule_work(). And the
1390 + function sets some special status to the cached aufs dentry and inode
1391 + private data. If they are not cached, then aufs has nothing to
1392 + do. When the same file is accessed through aufs (step 0-3) later,
1393 + aufs will detect the status and refresh all necessary data.
1394 + In this mode, aufs has to ignore the event which is fired by aufs
1396 +3. No Extra Validation
1397 + This is the simplest test and doesn't add any additional revalidation
1398 + test, and skip therevalidatin in step 4. It is useful and improves
1399 + aufs performance when system surely hide the aufs branches from user,
1400 + by over-mounting something (or another method).
1401 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1402 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1403 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2014-04-24 22:11:10.471931783 +0200
1406 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1408 +# This program is free software; you can redistribute it and/or modify
1409 +# it under the terms of the GNU General Public License as published by
1410 +# the Free Software Foundation; either version 2 of the License, or
1411 +# (at your option) any later version.
1413 +# This program is distributed in the hope that it will be useful,
1414 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1415 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1416 +# GNU General Public License for more details.
1418 +# You should have received a copy of the GNU General Public License
1419 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1421 +Branch Manipulation
1423 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1424 +and changing its permission/attribute, there are a lot of works to do.
1428 +----------------------------------------------------------------------
1429 +o Confirm the adding dir exists outside of aufs, including loopback
1431 +- and other various attributes...
1432 +o Initialize the xino file and whiteout bases if necessary.
1435 +o Check the owner/group/mode of the directory
1436 + When the owner/group/mode of the adding directory differs from the
1437 + existing branch, aufs issues a warning because it may impose a
1439 + For example, when a upper writable branch has a world writable empty
1440 + top directory, a malicious user can create any files on the writable
1441 + branch directly, like copy-up and modify manually. If something like
1442 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1443 + writable branch, and the writable branch is world-writable, then a
1444 + malicious guy may create /etc/passwd on the writable branch directly
1445 + and the infected file will be valid in aufs.
1446 + I am afraid it can be a security issue, but nothing to do except
1447 + producing a warning.
1451 +----------------------------------------------------------------------
1452 +o Confirm the deleting branch is not busy
1453 + To be general, there is one merit to adopt "remount" interface to
1454 + manipulate branches. It is to discard caches. At deleting a branch,
1455 + aufs checks the still cached (and connected) dentries and inodes. If
1456 + there are any, then they are all in-use. An inode without its
1457 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1459 + For the cached one, aufs checks whether the same named entry exists on
1461 + If the cached one is a directory, because aufs provides a merged view
1462 + to users, as long as one dir is left on any branch aufs can show the
1463 + dir to users. In this case, the branch can be removed from aufs.
1464 + Otherwise aufs rejects deleting the branch.
1466 + If any file on the deleting branch is opened by aufs, then aufs
1470 +Modify the Permission of a Branch
1471 +----------------------------------------------------------------------
1472 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1475 +o rw --> ro: Confirm the modifying branch is not busy
1476 + Aufs rejects the request if any of these conditions are true.
1477 + - a file on the branch is mmap-ed.
1478 + - a regular file on the branch is opened for write and there is no
1479 + same named entry on the upper branch.
1480 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1481 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1482 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2014-04-24 22:11:10.471931783 +0200
1485 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1487 +# This program is free software; you can redistribute it and/or modify
1488 +# it under the terms of the GNU General Public License as published by
1489 +# the Free Software Foundation; either version 2 of the License, or
1490 +# (at your option) any later version.
1492 +# This program is distributed in the hope that it will be useful,
1493 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1494 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1495 +# GNU General Public License for more details.
1497 +# You should have received a copy of the GNU General Public License
1498 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1500 +Policies to Select One among Multiple Writable Branches
1501 +----------------------------------------------------------------------
1502 +When the number of writable branch is more than one, aufs has to decide
1503 +the target branch for file creation or copy-up. By default, the highest
1504 +writable branch which has the parent (or ancestor) dir of the target
1505 +file is chosen (top-down-parent policy).
1506 +By user's request, aufs implements some other policies to select the
1507 +writable branch, for file creation two policies, round-robin and
1508 +most-free-space policies. For copy-up three policies, top-down-parent,
1509 +bottom-up-parent and bottom-up policies.
1511 +As expected, the round-robin policy selects the branch in circular. When
1512 +you have two writable branches and creates 10 new files, 5 files will be
1513 +created for each branch. mkdir(2) systemcall is an exception. When you
1514 +create 10 new directories, all will be created on the same branch.
1515 +And the most-free-space policy selects the one which has most free
1516 +space among the writable branches. The amount of free space will be
1517 +checked by aufs internally, and users can specify its time interval.
1519 +The policies for copy-up is more simple,
1520 +top-down-parent is equivalent to the same named on in create policy,
1521 +bottom-up-parent selects the writable branch where the parent dir
1522 +exists and the nearest upper one from the copyup-source,
1523 +bottom-up selects the nearest upper writable branch from the
1524 +copyup-source, regardless the existence of the parent dir.
1526 +There are some rules or exceptions to apply these policies.
1527 +- If there is a readonly branch above the policy-selected branch and
1528 + the parent dir is marked as opaque (a variation of whiteout), or the
1529 + target (creating) file is whiteout-ed on the upper readonly branch,
1530 + then the result of the policy is ignored and the target file will be
1531 + created on the nearest upper writable branch than the readonly branch.
1532 +- If there is a writable branch above the policy-selected branch and
1533 + the parent dir is marked as opaque or the target file is whiteouted
1534 + on the branch, then the result of the policy is ignored and the target
1535 + file will be created on the highest one among the upper writable
1536 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1538 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1539 + They try selecting the branch where the source exists as possible
1540 + since copyup a large file will take long time. If it can't be,
1541 + ie. the branch where the source exists is readonly, then they will
1542 + follow the copyup policy.
1543 +- There is an exception for rename(2) when the target exists.
1544 + If the rename target exists, aufs compares the index of the branches
1545 + where the source and the target exists and selects the higher
1546 + one. If the selected branch is readonly, then aufs follows the
1548 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
1549 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
1550 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2014-04-24 22:11:10.471931783 +0200
1553 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1555 +# This program is free software; you can redistribute it and/or modify
1556 +# it under the terms of the GNU General Public License as published by
1557 +# the Free Software Foundation; either version 2 of the License, or
1558 +# (at your option) any later version.
1560 +# This program is distributed in the hope that it will be useful,
1561 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1562 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1563 +# GNU General Public License for more details.
1565 +# You should have received a copy of the GNU General Public License
1566 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1568 +mmap(2) -- File Memory Mapping
1569 +----------------------------------------------------------------------
1570 +In aufs, the file-mapped pages are handled by a branch fs directly, no
1571 +interaction with aufs. It means aufs_mmap() calls the branch fs's
1573 +This approach is simple and good, but there is one problem.
1574 +Under /proc, several entries show the mmap-ped files by its path (with
1575 +device and inode number), and the printed path will be the path on the
1576 +branch fs's instead of virtual aufs's.
1577 +This is not a problem in most cases, but some utilities lsof(1) (and its
1578 +user) may expect the path on aufs.
1580 +To address this issue, aufs adds a new member called vm_prfile in struct
1581 +vm_area_struct (and struct vm_region). The original vm_file points to
1582 +the file on the branch fs in order to handle everything correctly as
1583 +usual. The new vm_prfile points to a virtual file in aufs, and the
1584 +show-functions in procfs refers to vm_prfile if it is set.
1585 +Also we need to maintain several other places where touching vm_file
1587 +- fork()/clone() copies vma and the reference count of vm_file is
1589 +- merging vma maintains the ref count too.
1591 +This is not a good approach. It just faking the printed path. But it
1592 +leaves all behaviour around f_mapping unchanged. This is surely an
1594 +Actually aufs had adopted another complicated approach which calls
1595 +generic_file_mmap() and handles struct vm_operations_struct. In this
1596 +approach, aufs met a hard problem and I could not solve it without
1597 +switching the approach.
1598 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
1599 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
1600 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2014-04-24 22:11:10.471931783 +0200
1603 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1605 +# This program is free software; you can redistribute it and/or modify
1606 +# it under the terms of the GNU General Public License as published by
1607 +# the Free Software Foundation; either version 2 of the License, or
1608 +# (at your option) any later version.
1610 +# This program is distributed in the hope that it will be useful,
1611 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1612 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1613 +# GNU General Public License for more details.
1615 +# You should have received a copy of the GNU General Public License
1616 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1618 +Export Aufs via NFS
1619 +----------------------------------------------------------------------
1620 +Here is an approach.
1621 +- like xino/xib, add a new file 'xigen' which stores aufs inode
1623 +- iget_locked(): initialize aufs inode generation for a new inode, and
1624 + store it in xigen file.
1625 +- destroy_inode(): increment aufs inode generation and store it in xigen
1626 + file. it is necessary even if it is not unlinked, because any data of
1627 + inode may be changed by UDBA.
1628 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
1629 + build file handle by
1630 + + branch id (4 bytes)
1631 + + superblock generation (4 bytes)
1632 + + inode number (4 or 8 bytes)
1633 + + parent dir inode number (4 or 8 bytes)
1634 + + inode generation (4 bytes))
1635 + + return value of exportfs_encode_fh() for the parent on a branch (4
1637 + + file handle for a branch (by exportfs_encode_fh())
1639 + + find the index of a branch from its id in handle, and check it is
1640 + still exist in aufs.
1641 + + 1st level: get the inode number from handle and search it in cache.
1642 + + 2nd level: if not found, get the parent inode number from handle and
1643 + search it in cache. and then open the parent dir, find the matching
1644 + inode number by vfs_readdir() and get its name, and call
1645 + lookup_one_len() for the target dentry.
1646 + + 3rd level: if the parent dir is not cached, call
1647 + exportfs_decode_fh() for a branch and get the parent on a branch,
1648 + build a pathname of it, convert it a pathname in aufs, call
1649 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
1651 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
1652 + for every branch, but not itself. to get this, (currently) aufs
1653 + searches in current->nsproxy->mnt_ns list. it may not be a good
1654 + idea, but I didn't get other approach.
1655 + + test the generation of the gotten inode.
1656 +- every inode operation: they may get EBUSY due to UDBA. in this case,
1657 + convert it into ESTALE for NFSD.
1658 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
1659 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
1660 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
1661 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
1662 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2014-04-24 22:11:10.471931783 +0200
1665 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1667 +# This program is free software; you can redistribute it and/or modify
1668 +# it under the terms of the GNU General Public License as published by
1669 +# the Free Software Foundation; either version 2 of the License, or
1670 +# (at your option) any later version.
1672 +# This program is distributed in the hope that it will be useful,
1673 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1674 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1675 +# GNU General Public License for more details.
1677 +# You should have received a copy of the GNU General Public License
1678 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1680 +Show Whiteout Mode (shwh)
1681 +----------------------------------------------------------------------
1682 +Generally aufs hides the name of whiteouts. But in some cases, to show
1683 +them is very useful for users. For instance, creating a new middle layer
1684 +(branch) by merging existing layers.
1686 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
1687 +When you have three branches,
1688 +- Bottom: 'system', squashfs (underlying base system), read-only
1689 +- Middle: 'mods', squashfs, read-only
1690 +- Top: 'overlay', ram (tmpfs), read-write
1692 +The top layer is loaded at boot time and saved at shutdown, to preserve
1693 +the changes made to the system during the session.
1694 +When larger changes have been made, or smaller changes have accumulated,
1695 +the size of the saved top layer data grows. At this point, it would be
1696 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
1697 +and rewrite the 'mods' squashfs, clearing the top layer and thus
1698 +restoring save and load speed.
1700 +This merging is simplified by the use of another aufs mount, of just the
1701 +two overlay branches using the 'shwh' option.
1702 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
1703 + aufs /livesys/merge_union
1705 +A merged view of these two branches is then available at
1706 +/livesys/merge_union, and the new feature is that the whiteouts are
1708 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
1709 +writing to all branches. Also the default mode for all branches is 'ro'.
1710 +It is now possible to save the combined contents of the two overlay
1711 +branches to a new squashfs, e.g.:
1712 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
1714 +This new squashfs archive can be stored on the boot device and the
1715 +initramfs will use it to replace the old one at the next boot.
1716 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
1717 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
1718 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2014-04-24 22:11:10.471931783 +0200
1721 +# Copyright (C) 2010-2014 Junjiro R. Okajima
1723 +# This program is free software; you can redistribute it and/or modify
1724 +# it under the terms of the GNU General Public License as published by
1725 +# the Free Software Foundation; either version 2 of the License, or
1726 +# (at your option) any later version.
1728 +# This program is distributed in the hope that it will be useful,
1729 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1730 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1731 +# GNU General Public License for more details.
1733 +# You should have received a copy of the GNU General Public License
1734 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1736 +Dynamically customizable FS operations
1737 +----------------------------------------------------------------------
1738 +Generally FS operations (struct inode_operations, struct
1739 +address_space_operations, struct file_operations, etc.) are defined as
1740 +"static const", but it never means that FS have only one set of
1741 +operation. Some FS have multiple sets of them. For instance, ext2 has
1742 +three sets, one for XIP, for NOBH, and for normal.
1743 +Since aufs overrides and redirects these operations, sometimes aufs has
1744 +to change its behaviour according to the branch FS type. More imporantly
1745 +VFS acts differently if a function (member in the struct) is set or
1746 +not. It means aufs should have several sets of operations and select one
1747 +among them according to the branch FS definition.
1749 +In order to solve this problem and not to affect the behavour of VFS,
1750 +aufs defines these operations dynamically. For instance, aufs defines
1751 +aio_read function for struct file_operations, but it may not be set to
1752 +the file_operations. When the branch FS doesn't have it, aufs doesn't
1753 +set it to its file_operations while the function definition itself is
1754 +still alive. So the behaviour of io_submit(2) will not change, and it
1755 +will return an error when aio_read is not defined.
1757 +The lifetime of these dynamically generated operation object is
1758 +maintained by aufs branch object. When the branch is removed from aufs,
1759 +the reference counter of the object is decremented. When it reaches
1760 +zero, the dynamically generated operation object will be freed.
1762 +This approach is designed to support AIO (io_submit), Direcit I/O and
1764 +Currently this approach is applied to file_operations and
1765 +vm_operations_struct for regular files only.
1766 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt linux/Documentation/filesystems/aufs/design/99plan.txt
1767 --- /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt 1970-01-01 01:00:00.000000000 +0100
1768 +++ linux/Documentation/filesystems/aufs/design/99plan.txt 2014-04-24 22:11:10.471931783 +0200
1771 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1773 +# This program is free software; you can redistribute it and/or modify
1774 +# it under the terms of the GNU General Public License as published by
1775 +# the Free Software Foundation; either version 2 of the License, or
1776 +# (at your option) any later version.
1778 +# This program is distributed in the hope that it will be useful,
1779 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1780 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1781 +# GNU General Public License for more details.
1783 +# You should have received a copy of the GNU General Public License
1784 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1788 +Restoring some features which was implemented in aufs1.
1789 +They were dropped in aufs2 in order to make source files simpler and
1790 +easier to be reviewed.
1793 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1794 +----------------------------------------------------------------------
1795 +Let's try case study.
1796 +- aufs has two branches, upper readwrite and lower readonly.
1798 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1799 +- user invoked "chmod a+rx /au/dirA"
1800 +- then "dirA" becomes world readable?
1802 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1803 +or it may be a natively readonly filesystem. If aufs respects the lower
1804 +branch, it should not respond readdir request from other users. But user
1805 +allowed it by chmod. Should really aufs rejects showing the entries
1808 +To be honest, I don't have a best solution for this case. So I
1809 +implemented 'dirperm1' and 'nodirperm1' option in aufs1, and leave it to
1811 +When dirperm1 is specified, aufs checks only the highest one for the
1812 +directory permission, and shows the entries. Otherwise, as usual, checks
1813 +every dir existing on all branches and rejects the request.
1815 +As a side effect, dirperm1 option improves the performance of aufs
1816 +because the number of permission check is reduced.
1819 +Being Another Aufs's Readonly Branch (robr)
1820 +----------------------------------------------------------------------
1821 +Aufs1 allows aufs to be another aufs's readonly branch.
1822 +This feature was developed by a user's request. But it may not be used
1826 +Copy-up on Open (coo=)
1827 +----------------------------------------------------------------------
1828 +By default the internal copy-up is executed when it is really necessary.
1829 +It is not done when a file is opened for writing, but when write(2) is
1830 +done. Users who have many (over 100) branches want to know and analyse
1831 +when and what file is copied-up. To insert a new upper branch which
1832 +contains such files only may improve the performance of aufs.
1834 +Aufs1 implemented "coo=none | leaf | all" option.
1837 +Refresh the Opened File (refrof)
1838 +----------------------------------------------------------------------
1839 +This option is implemented in aufs1 but incomplete.
1841 +When user reads from a file, he expects to get its latest filedata
1842 +generally. If the file is removed and a new same named file is created,
1843 +the content he gets is unchanged, ie. the unlinked filedata.
1845 +Let's try case study again.
1846 +- aufs has two branches.
1848 +- "fileA" exists under /ro, but /rw.
1849 +- user opened "/au/fileA".
1850 +- he or someone else inserts a branch (/new) between /rw and /ro.
1851 + /au = /rw + /new + /ro
1852 +- the new branch has "fileA".
1853 +- user reads from the opened "fileA"
1854 +- which filedata should aufs return, from /ro or /new?
1856 +Some people says it has to be "from /ro" and it is a semantics of Unix.
1857 +The others say it should be "from /new" because the file is not removed
1858 +and it is equivalent to the case of someone else modifies the file.
1860 +Here again I don't have a best and final answer. I got an idea to
1861 +implement 'refrof' and 'norefrof' option. When 'refrof' (REFResh the
1862 +Opened File) is specified (by default), aufs returns the filedata from
1864 +Otherwise from /new.
1865 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
1866 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
1867 +++ linux/Documentation/filesystems/aufs/README 2014-04-24 22:11:10.471931783 +0200
1870 +Aufs3 -- advanced multi layered unification filesystem version 3.x
1876 +----------------------------------------
1877 +In the early days, aufs was entirely re-designed and re-implemented
1878 +Unionfs Version 1.x series. After many original ideas, approaches,
1879 +improvements and implementations, it becomes totally different from
1880 +Unionfs while keeping the basic features.
1881 +Recently, Unionfs Version 2.x series begin taking some of the same
1882 +approaches to aufs1's.
1883 +Unionfs is being developed by Professor Erez Zadok at Stony Brook
1884 +University and his team.
1886 +Aufs3 supports linux-3.0 and later.
1887 +If you want older kernel version support, try aufs2-2.6.git or
1888 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
1890 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
1891 +According to Christoph Hellwig, linux rejects all union-type filesystems
1893 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
1897 +----------------------------------------
1898 +- unite several directories into a single virtual filesystem. The member
1899 + directory is called as a branch.
1900 +- you can specify the permission flags to the branch, which are 'readonly',
1901 + 'readwrite' and 'whiteout-able.'
1902 +- by upper writable branch, internal copyup and whiteout, files/dirs on
1903 + readonly branch are modifiable logically.
1904 +- dynamic branch manipulation, add, del.
1907 +Also there are many enhancements in aufs1, such as:
1908 +- readdir(3) in userspace.
1909 +- keep inode number by external inode number table
1910 +- keep the timestamps of file/dir in internal copyup operation
1911 +- seekable directory, supporting NFS readdir.
1912 +- whiteout is hardlinked in order to reduce the consumption of inodes
1914 +- do not copyup, nor create a whiteout when it is unnecessary
1915 +- revert a single systemcall when an error occurs in aufs
1916 +- remount interface instead of ioctl
1917 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
1918 +- loopback mounted filesystem as a branch
1919 +- kernel thread for removing the dir who has a plenty of whiteouts
1920 +- support copyup sparse file (a file which has a 'hole' in it)
1921 +- default permission flags for branches
1922 +- selectable permission flags for ro branch, whether whiteout can
1925 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
1926 +- support multiple writable branches, some policies to select one
1927 + among multiple writable branches.
1928 +- a new semantics for link(2) and rename(2) to support multiple
1929 + writable branches.
1930 +- no glibc changes are required.
1931 +- pseudo hardlink (hardlink over branches)
1932 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
1933 + including NFS or remote filesystem branch.
1934 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
1937 +Currently these features are dropped temporary from aufs3.
1938 +See design/08plan.txt in detail.
1939 +- test only the highest one for the directory permission (dirperm1)
1940 +- copyup on open (coo=)
1941 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
1943 +- statistics of aufs thread (/sys/fs/aufs/stat)
1944 +- delegation mode (dlgt)
1945 + a delegation of the internal branch access to support task I/O
1946 + accounting, which also supports Linux Security Modules (LSM) mainly
1947 + for Suse AppArmor.
1948 +- intent.open/create (file open in a single lookup)
1950 +Features or just an idea in the future (see also design/*.txt),
1951 +- reorder the branch index without del/re-add.
1952 +- permanent xino files for NFSD
1953 +- an option for refreshing the opened files after add/del branches
1954 +- 'move' policy for copy-up between two writable branches, after
1955 + checking free space.
1956 +- light version, without branch manipulation. (unnecessary?)
1957 +- copyup in userspace
1958 +- inotify in userspace
1964 +----------------------------------------
1965 +There were three GIT trees for aufs3, aufs3-linux.git,
1966 +aufs3-standalone.git, and aufs-util.git. Note that there is no "3" in
1968 +While the aufs-util is always necessary, you need either of aufs3-linux
1969 +or aufs3-standalone.
1971 +The aufs3-linux tree includes the whole linux mainline GIT tree,
1972 +git://git.kernel.org/.../torvalds/linux.git.
1973 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
1974 +build aufs3 as an external kernel module.
1976 +On the other hand, the aufs3-standalone tree has only aufs source files
1977 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
1979 +You will find GIT branches whose name is in form of "aufs3.x" where "x"
1980 +represents the linux kernel version, "linux-3.x". For instance,
1981 +"aufs3.0" is for linux-3.0. For latest "linux-3.x-rcN", use
1982 +"aufs3.x-rcN" branch.
1985 +$ git clone --reference /your/linux/git/tree \
1986 + git://git.code.sf.net/p/aufs/aufs3-linux aufs-aufs3-linux \
1988 +- if you don't have linux GIT tree, then remove "--reference ..."
1989 +$ cd aufs3-linux.git
1990 +$ git checkout origin/aufs3.0
1992 +o aufs3-standalone tree
1993 +$ git clone git://git.code.sf.net/p/aufs/aufs3-standalone \
1994 + aufs3-standalone.git
1995 +$ cd aufs3-standalone.git
1996 +$ git checkout origin/aufs3.0
1999 +$ git clone git://git.code.sf.net/p/aufs/aufs-util \
2002 +$ git checkout origin/aufs3.0
2004 +Note: The 3.x-rcN branch is to be used with `rc' kernel versions ONLY.
2005 +The minor version number, 'x' in '3.x', of aufs may not always
2006 +follow the minor version number of the kernel.
2007 +Because changes in the kernel that cause the use of a new
2008 +minor version number do not always require changes to aufs-util.
2010 +Since aufs-util has its own minor version number, you may not be
2011 +able to find a GIT branch in aufs-util for your kernel's
2012 +exact minor version number.
2013 +In this case, you should git-checkout the branch for the
2014 +nearest lower number.
2016 +For (an unreleased) example:
2017 +If you are using "linux-3.10" and the "aufs3.10" branch
2018 +does not exist in aufs-util repository, then "aufs3.9", "aufs3.8"
2019 +or something numerically smaller is the branch for your kernel.
2021 +Also you can view all branches by
2025 +3. Configuration and Compilation
2026 +----------------------------------------
2027 +Make sure you have git-checkout'ed the correct branch.
2029 +For aufs3-linux tree,
2030 +- enable CONFIG_AUFS_FS.
2031 +- set other aufs configurations if necessary.
2033 +For aufs3-standalone tree,
2034 +There are several ways to build.
2037 +- apply ./aufs3-kbuild.patch to your kernel source files.
2038 +- apply ./aufs3-base.patch too.
2039 +- apply ./aufs3-mmap.patch too.
2040 +- apply ./aufs3-standalone.patch too, if you have a plan to set
2041 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs3-standalone.patch.
2042 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2043 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2044 +- enable CONFIG_AUFS_FS, you can select either
2046 +- and build your kernel as usual.
2047 +- install the built kernel.
2048 + Note: Since linux-3.9, every filesystem module requires an alias
2049 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2050 + modules.aliases file if you set CONFIG_AUFS_FS=m.
2051 +- install the header files too by "make headers_install" to the
2052 + directory where you specify. By default, it is $PWD/usr.
2053 + "make help" shows a brief note for headers_install.
2054 +- and reboot your system.
2057 +- module only (CONFIG_AUFS_FS=m).
2058 +- apply ./aufs3-base.patch to your kernel source files.
2059 +- apply ./aufs3-mmap.patch too.
2060 +- apply ./aufs3-standalone.patch too.
2061 +- build your kernel, don't forget "make headers_install", and reboot.
2062 +- edit ./config.mk and set other aufs configurations if necessary.
2063 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2064 + every aufs configurations.
2065 +- build the module by simple "make".
2066 + Note: Since linux-3.9, every filesystem module requires an alias
2067 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2068 + modules.aliases file.
2069 +- you can specify ${KDIR} make variable which points to your kernel
2071 +- install the files
2072 + + run "make install" to install the aufs module, or copy the built
2073 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2074 + + run "make install_headers" (instead of headers_install) to install
2075 + the modified aufs header file (you can specify DESTDIR which is
2076 + available in aufs standalone version's Makefile only), or copy
2077 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2078 + you like manually. By default, the target directory is $PWD/usr.
2079 +- no need to apply aufs3-kbuild.patch, nor copying source files to your
2080 + kernel source tree.
2082 +Note: The header file aufs_type.h is necessary to build aufs-util
2083 + as well as "make headers_install" in the kernel source tree.
2084 + headers_install is subject to be forgotten, but it is essentially
2085 + necessary, not only for building aufs-util.
2086 + You may not meet problems without headers_install in some older
2090 +- read README in aufs-util, build and install it
2091 +- note that your distribution may contain an obsoleted version of
2092 + aufs_type.h in /usr/include/linux or something. When you build aufs
2093 + utilities, make sure that your compiler refers the correct aufs header
2094 + file which is built by "make headers_install."
2095 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2096 + then run "make install_ulib" too. And refer to the aufs manual in
2101 +----------------------------------------
2102 +At first, make sure aufs-util are installed, and please read the aufs
2103 +manual, aufs.5 in aufs-util.git tree.
2107 +$ mkdir /tmp/rw /tmp/aufs
2108 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2110 +Here is another example. The result is equivalent.
2111 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2113 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2114 +# mount -o remount,append:${HOME} /tmp/aufs
2116 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2117 +you modify a file under /tmp/aufs, the one on your home directory is
2118 +not affected, instead the same named file will be newly created under
2119 +/tmp/rw. And all of your modification to a file will be applied to
2120 +the one under /tmp/rw. This is called the file based Copy on Write
2122 +Aufs mount options are described in aufs.5.
2123 +If you run chroot or something and make your aufs as a root directory,
2124 +then you need to customize the shutdown script. See the aufs manual in
2127 +Additionally, there are some sample usages of aufs which are a
2128 +diskless system with network booting, and LiveCD over NFS.
2129 +See sample dir in CVS tree on SourceForge.
2133 +----------------------------------------
2134 +When you have any problems or strange behaviour in aufs, please let me
2136 +- /proc/mounts (instead of the output of mount(8))
2137 +- /sys/module/aufs/*
2138 +- /sys/fs/aufs/* (if you have them)
2139 +- /debug/aufs/* (if you have them)
2140 +- linux kernel version
2141 + if your kernel is not plain, for example modified by distributor,
2142 + the url where i can download its source is necessary too.
2143 +- aufs version which was printed at loading the module or booting the
2144 + system, instead of the date you downloaded.
2145 +- configuration (define/undefine CONFIG_AUFS_xxx)
2146 +- kernel configuration or /proc/config.gz (if you have it)
2147 +- behaviour which you think to be incorrect
2148 +- actual operation, reproducible one is better
2149 +- mailto: aufs-users at lists.sourceforge.net
2151 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2152 +and Feature Requests) on SourceForge. Please join and write to
2156 +6. Acknowledgements
2157 +----------------------------------------
2158 +Thanks to everyone who have tried and are using aufs, whoever
2159 +have reported a bug or any feedback.
2161 +Especially donators:
2162 +Tomas Matejicek(slax.org) made a donation (much more than once).
2163 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2164 + scripts) is making "doubling" donations.
2165 + Unfortunately I cannot list all of the donators, but I really
2167 + It ends Aug 2010, but the ordinary donation URL is still available.
2168 + <http://sourceforge.net/donate/index.php?group_id=167503>
2169 +Dai Itasaka made a donation (2007/8).
2170 +Chuck Smith made a donation (2008/4, 10 and 12).
2171 +Henk Schoneveld made a donation (2008/9).
2172 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2173 +Francois Dupoux made a donation (2008/11).
2174 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2175 + aufs2 GIT tree (2009/2).
2176 +William Grant made a donation (2009/3).
2177 +Patrick Lane made a donation (2009/4).
2178 +The Mail Archive (mail-archive.com) made donations (2009/5).
2179 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2180 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2181 +Pavel Pronskiy made a donation (2011/2).
2182 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2183 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2184 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2186 +Sam Liddicott made a donation (2011/9).
2187 +Era Scarecrow made a donation (2013/4).
2188 +Bor Ratajc made a donation (2013/4).
2189 +Alessandro Gorreta made a donation (2013/4).
2190 +POIRETTE Marc made a donation (2013/4).
2191 +Alessandro Gorreta made a donation (2013/4).
2192 +lauri kasvandik made a donation (2013/5).
2193 +"pemasu from Finland" made a donation (2013/7).
2194 +The Parted Magic Project made a donation (2013/9 and 11).
2195 +Pavel Barta made a donation (2013/10).
2197 +Thank you very much.
2198 +Donations are always, including future donations, very important and
2199 +helpful for me to keep on developing aufs.
2203 +----------------------------------------
2204 +If you are an experienced user, no explanation is needed. Aufs is
2205 +just a linux filesystem.
2210 +# Local variables: ;
2213 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2214 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2215 +++ linux/fs/aufs/aufs.h 2014-04-24 22:11:10.848602379 +0200
2218 + * Copyright (C) 2005-2014 Junjiro R. Okajima
2220 + * This program, aufs is free software; you can redistribute it and/or modify
2221 + * it under the terms of the GNU General Public License as published by
2222 + * the Free Software Foundation; either version 2 of the License, or
2223 + * (at your option) any later version.
2225 + * This program is distributed in the hope that it will be useful,
2226 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2227 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2228 + * GNU General Public License for more details.
2230 + * You should have received a copy of the GNU General Public License
2231 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2235 + * all header files
2243 +#define AuStub(type, name, body, ...) \
2244 + static inline type name(__VA_ARGS__) { body; }
2246 +#define AuStubVoid(name, ...) \
2247 + AuStub(void, name, , __VA_ARGS__)
2248 +#define AuStubInt0(name, ...) \
2249 + AuStub(int, name, return 0, __VA_ARGS__)
2253 +#include "branch.h"
2256 +#include "dbgaufs.h"
2257 +#include "dentry.h"
2261 +#include "fstype.h"
2264 +#include "module.h"
2269 +#include "sysaufs.h"
2274 +#endif /* __KERNEL__ */
2275 +#endif /* __AUFS_H__ */
2276 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2277 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2278 +++ linux/fs/aufs/branch.c 2014-04-24 22:11:10.848602379 +0200
2281 + * Copyright (C) 2005-2014 Junjiro R. Okajima
2283 + * This program, aufs is free software; you can redistribute it and/or modify
2284 + * it under the terms of the GNU General Public License as published by
2285 + * the Free Software Foundation; either version 2 of the License, or
2286 + * (at your option) any later version.
2288 + * This program is distributed in the hope that it will be useful,
2289 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2290 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2291 + * GNU General Public License for more details.
2293 + * You should have received a copy of the GNU General Public License
2294 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2298 + * branch management
2301 +#include <linux/compat.h>
2302 +#include <linux/statfs.h>
2306 + * free a single branch
2309 +/* prohibit rmdir to the root of the branch */
2310 +/* todo: another new flag? */
2311 +static void au_br_dflags_force(struct au_branch *br)
2313 + struct dentry *h_dentry;
2315 + h_dentry = au_br_dentry(br);
2316 + spin_lock(&h_dentry->d_lock);
2317 + br->br_dflags = h_dentry->d_flags & DCACHE_MOUNTED;
2318 + h_dentry->d_flags |= DCACHE_MOUNTED;
2319 + spin_unlock(&h_dentry->d_lock);
2322 +/* restore its d_flags */
2323 +static void au_br_dflags_restore(struct au_branch *br)
2325 + struct dentry *h_dentry;
2327 + if (br->br_dflags)
2330 + h_dentry = au_br_dentry(br);
2331 + spin_lock(&h_dentry->d_lock);
2332 + h_dentry->d_flags &= ~DCACHE_MOUNTED;
2333 + spin_unlock(&h_dentry->d_lock);
2336 +static void au_br_do_free(struct au_branch *br)
2339 + struct au_wbr *wbr;
2340 + struct au_dykey **key;
2342 + au_hnotify_fin_br(br);
2344 + if (br->br_xino.xi_file)
2345 + fput(br->br_xino.xi_file);
2346 + mutex_destroy(&br->br_xino.xi_nondir_mtx);
2348 + AuDebugOn(atomic_read(&br->br_count));
2352 + for (i = 0; i < AuBrWh_Last; i++)
2353 + dput(wbr->wbr_wh[i]);
2354 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2355 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2358 + key = br->br_dykey;
2359 + for (i = 0; i < AuBrDynOp; i++, key++)
2365 + au_br_dflags_restore(br);
2367 + /* recursive lock, s_umount of branch's */
2369 + path_put(&br->br_path);
2376 + * frees all branches
2378 +void au_br_free(struct au_sbinfo *sbinfo)
2380 + aufs_bindex_t bmax;
2381 + struct au_branch **br;
2383 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2385 + bmax = sbinfo->si_bend + 1;
2386 + br = sbinfo->si_branch;
2388 + au_br_do_free(*br++);
2392 + * find the index of a branch which is specified by @br_id.
2394 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
2396 + aufs_bindex_t bindex, bend;
2398 + bend = au_sbend(sb);
2399 + for (bindex = 0; bindex <= bend; bindex++)
2400 + if (au_sbr_id(sb, bindex) == br_id)
2405 +/* ---------------------------------------------------------------------- */
2411 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
2412 + struct dentry *h_root)
2414 + if (unlikely(h_adding == h_root
2415 + || au_test_loopback_overlap(sb, h_adding)))
2417 + if (h_adding->d_sb != h_root->d_sb)
2419 + return au_test_subdir(h_adding, h_root)
2420 + || au_test_subdir(h_root, h_adding);
2424 + * returns a newly allocated branch. @new_nbranch is a number of branches
2425 + * after adding a branch.
2427 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
2430 + struct au_branch *add_branch;
2431 + struct dentry *root;
2435 + root = sb->s_root;
2436 + add_branch = kmalloc(sizeof(*add_branch), GFP_NOFS);
2437 + if (unlikely(!add_branch))
2440 + err = au_hnotify_init_br(add_branch, perm);
2441 + if (unlikely(err))
2444 + add_branch->br_wbr = NULL;
2445 + if (au_br_writable(perm)) {
2446 + /* may be freed separately at changing the branch permission */
2447 + add_branch->br_wbr = kmalloc(sizeof(*add_branch->br_wbr),
2449 + if (unlikely(!add_branch->br_wbr))
2453 + err = au_sbr_realloc(au_sbi(sb), new_nbranch);
2455 + err = au_di_realloc(au_di(root), new_nbranch);
2457 + err = au_ii_realloc(au_ii(root->d_inode), new_nbranch);
2459 + return add_branch; /* success */
2461 + kfree(add_branch->br_wbr);
2464 + au_hnotify_fin_br(add_branch);
2466 + kfree(add_branch);
2468 + return ERR_PTR(err);
2472 + * test if the branch permission is legal or not.
2474 +static int test_br(struct inode *inode, int brperm, char *path)
2478 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
2483 + pr_err("write permission for readonly mount or inode, %s\n", path);
2491 + * 0: success, the caller will add it
2492 + * plus: success, it is already unified, the caller should ignore it
2495 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
2498 + aufs_bindex_t bend, bindex;
2499 + struct dentry *root;
2500 + struct inode *inode, *h_inode;
2502 + root = sb->s_root;
2503 + bend = au_sbend(sb);
2504 + if (unlikely(bend >= 0
2505 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
2509 + pr_err("%s duplicated\n", add->pathname);
2514 + err = -ENOSPC; /* -E2BIG; */
2515 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
2516 + || AUFS_BRANCH_MAX - 1 <= bend)) {
2517 + pr_err("number of branches exceeded %s\n", add->pathname);
2522 + if (unlikely(add->bindex < 0 || bend + 1 < add->bindex)) {
2523 + pr_err("bad index %d\n", add->bindex);
2527 + inode = add->path.dentry->d_inode;
2529 + if (unlikely(!inode->i_nlink)) {
2530 + pr_err("no existence %s\n", add->pathname);
2535 + if (unlikely(inode->i_sb == sb)) {
2536 + pr_err("%s must be outside\n", add->pathname);
2540 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
2541 + pr_err("unsupported filesystem, %s (%s)\n",
2542 + add->pathname, au_sbtype(inode->i_sb));
2546 + err = test_br(add->path.dentry->d_inode, add->perm, add->pathname);
2547 + if (unlikely(err))
2551 + return 0; /* success */
2554 + for (bindex = 0; bindex <= bend; bindex++)
2555 + if (unlikely(test_overlap(sb, add->path.dentry,
2556 + au_h_dptr(root, bindex)))) {
2557 + pr_err("%s is overlapped\n", add->pathname);
2562 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
2563 + h_inode = au_h_dptr(root, 0)->d_inode;
2564 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
2565 + || !uid_eq(h_inode->i_uid, inode->i_uid)
2566 + || !gid_eq(h_inode->i_gid, inode->i_gid))
2567 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
2569 + i_uid_read(inode), i_gid_read(inode),
2570 + (inode->i_mode & S_IALLUGO),
2571 + i_uid_read(h_inode), i_gid_read(h_inode),
2572 + (h_inode->i_mode & S_IALLUGO));
2580 + * initialize or clean the whiteouts for an adding branch
2582 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
2585 + int err, old_perm;
2586 + aufs_bindex_t bindex;
2587 + struct mutex *h_mtx;
2588 + struct au_wbr *wbr;
2589 + struct au_hinode *hdir;
2591 + err = vfsub_mnt_want_write(au_br_mnt(br));
2592 + if (unlikely(err))
2596 + old_perm = br->br_perm;
2597 + br->br_perm = new_perm;
2600 + bindex = au_br_index(sb, br->br_id);
2601 + if (0 <= bindex) {
2602 + hdir = au_hi(sb->s_root->d_inode, bindex);
2603 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
2605 + h_mtx = &au_br_dentry(br)->d_inode->i_mutex;
2606 + mutex_lock_nested(h_mtx, AuLsc_I_PARENT);
2609 + err = au_wh_init(br, sb);
2611 + wbr_wh_write_lock(wbr);
2612 + err = au_wh_init(br, sb);
2613 + wbr_wh_write_unlock(wbr);
2616 + au_hn_imtx_unlock(hdir);
2618 + mutex_unlock(h_mtx);
2619 + vfsub_mnt_drop_write(au_br_mnt(br));
2620 + br->br_perm = old_perm;
2622 + if (!err && wbr && !au_br_writable(new_perm)) {
2624 + br->br_wbr = NULL;
2631 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
2635 + struct kstatfs kst;
2636 + struct au_wbr *wbr;
2639 + au_rw_init(&wbr->wbr_wh_rwsem);
2640 + memset(wbr->wbr_wh, 0, sizeof(wbr->wbr_wh));
2641 + atomic_set(&wbr->wbr_wh_running, 0);
2642 + wbr->wbr_bytes = 0;
2645 + * a limit for rmdir/rename a dir
2646 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
2648 + err = vfs_statfs(&br->br_path, &kst);
2649 + if (unlikely(err))
2652 + if (kst.f_namelen >= NAME_MAX)
2653 + err = au_br_init_wh(sb, br, perm);
2655 + pr_err("%pd(%s), unsupported namelen %ld\n",
2657 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
2663 +/* intialize a new branch */
2664 +static int au_br_init(struct au_branch *br, struct super_block *sb,
2665 + struct au_opt_add *add)
2670 + memset(&br->br_xino, 0, sizeof(br->br_xino));
2671 + mutex_init(&br->br_xino.xi_nondir_mtx);
2672 + br->br_perm = add->perm;
2673 + BUILD_BUG_ON(sizeof(br->br_dflags)
2674 + != sizeof(br->br_path.dentry->d_flags));
2675 + br->br_dflags = DCACHE_MOUNTED;
2676 + br->br_path = add->path; /* set first, path_get() later */
2677 + spin_lock_init(&br->br_dykey_lock);
2678 + memset(br->br_dykey, 0, sizeof(br->br_dykey));
2679 + atomic_set(&br->br_count, 0);
2680 + atomic_set(&br->br_xino_running, 0);
2681 + br->br_id = au_new_br_id(sb);
2682 + AuDebugOn(br->br_id < 0);
2684 + if (au_br_writable(add->perm)) {
2685 + err = au_wbr_init(br, sb, add->perm);
2686 + if (unlikely(err))
2690 + if (au_opt_test(au_mntflags(sb), XINO)) {
2691 + err = au_xino_br(sb, br, add->path.dentry->d_inode->i_ino,
2692 + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1);
2693 + if (unlikely(err)) {
2694 + AuDebugOn(br->br_xino.xi_file);
2699 + sysaufs_br_init(br);
2700 + path_get(&br->br_path);
2701 + goto out; /* success */
2704 + memset(&br->br_path, 0, sizeof(br->br_path));
2709 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
2710 + struct au_branch *br, aufs_bindex_t bend,
2711 + aufs_bindex_t amount)
2713 + struct au_branch **brp;
2715 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2717 + brp = sbinfo->si_branch + bindex;
2718 + memmove(brp + 1, brp, sizeof(*brp) * amount);
2720 + sbinfo->si_bend++;
2721 + if (unlikely(bend < 0))
2722 + sbinfo->si_bend = 0;
2725 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
2726 + aufs_bindex_t bend, aufs_bindex_t amount)
2728 + struct au_hdentry *hdp;
2730 + AuRwMustWriteLock(&dinfo->di_rwsem);
2732 + hdp = dinfo->di_hdentry + bindex;
2733 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
2734 + au_h_dentry_init(hdp);
2736 + if (unlikely(bend < 0))
2737 + dinfo->di_bstart = 0;
2740 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
2741 + aufs_bindex_t bend, aufs_bindex_t amount)
2743 + struct au_hinode *hip;
2745 + AuRwMustWriteLock(&iinfo->ii_rwsem);
2747 + hip = iinfo->ii_hinode + bindex;
2748 + memmove(hip + 1, hip, sizeof(*hip) * amount);
2749 + hip->hi_inode = NULL;
2752 + if (unlikely(bend < 0))
2753 + iinfo->ii_bstart = 0;
2756 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
2757 + aufs_bindex_t bindex)
2759 + struct dentry *root, *h_dentry;
2760 + struct inode *root_inode;
2761 + aufs_bindex_t bend, amount;
2763 + au_br_dflags_force(br);
2765 + root = sb->s_root;
2766 + root_inode = root->d_inode;
2767 + bend = au_sbend(sb);
2768 + amount = bend + 1 - bindex;
2769 + h_dentry = au_br_dentry(br);
2770 + au_sbilist_lock();
2771 + au_br_do_add_brp(au_sbi(sb), bindex, br, bend, amount);
2772 + au_br_do_add_hdp(au_di(root), bindex, bend, amount);
2773 + au_br_do_add_hip(au_ii(root_inode), bindex, bend, amount);
2774 + au_set_h_dptr(root, bindex, dget(h_dentry));
2775 + au_set_h_iptr(root_inode, bindex, au_igrab(h_dentry->d_inode),
2777 + au_sbilist_unlock();
2780 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
2783 + aufs_bindex_t bend, add_bindex;
2784 + struct dentry *root, *h_dentry;
2785 + struct inode *root_inode;
2786 + struct au_branch *add_branch;
2788 + root = sb->s_root;
2789 + root_inode = root->d_inode;
2790 + IMustLock(root_inode);
2791 + err = test_add(sb, add, remount);
2792 + if (unlikely(err < 0))
2796 + goto out; /* success */
2799 + bend = au_sbend(sb);
2800 + add_branch = au_br_alloc(sb, bend + 2, add->perm);
2801 + err = PTR_ERR(add_branch);
2802 + if (IS_ERR(add_branch))
2805 + err = au_br_init(add_branch, sb, add);
2806 + if (unlikely(err)) {
2807 + au_br_do_free(add_branch);
2811 + add_bindex = add->bindex;
2813 + au_br_do_add(sb, add_branch, add_bindex);
2815 + sysaufs_brs_del(sb, add_bindex);
2816 + au_br_do_add(sb, add_branch, add_bindex);
2817 + sysaufs_brs_add(sb, add_bindex);
2820 + h_dentry = add->path.dentry;
2821 + if (!add_bindex) {
2822 + au_cpup_attr_all(root_inode, /*force*/1);
2823 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
2825 + au_add_nlink(root_inode, h_dentry->d_inode);
2828 + * this test/set prevents aufs from handling unnecesary notify events
2829 + * of xino files, in case of re-adding a writable branch which was
2830 + * once detached from aufs.
2832 + if (au_xino_brid(sb) < 0
2833 + && au_br_writable(add_branch->br_perm)
2834 + && !au_test_fs_bad_xino(h_dentry->d_sb)
2835 + && add_branch->br_xino.xi_file
2836 + && add_branch->br_xino.xi_file->f_dentry->d_parent == h_dentry)
2837 + au_xino_brid_set(sb, add_branch->br_id);
2843 +/* ---------------------------------------------------------------------- */
2849 +/* to show the line number, do not make it inlined function */
2850 +#define AuVerbose(do_info, fmt, ...) do { \
2852 + pr_info(fmt, ##__VA_ARGS__); \
2855 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t bstart,
2856 + aufs_bindex_t bend)
2858 + return (inode && !S_ISDIR(inode->i_mode)) || bstart == bend;
2861 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t bstart,
2862 + aufs_bindex_t bend)
2864 + return au_test_ibusy(dentry->d_inode, bstart, bend);
2868 + * test if the branch is deletable or not.
2870 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
2871 + unsigned int sigen, const unsigned int verbose)
2873 + int err, i, j, ndentry;
2874 + aufs_bindex_t bstart, bend;
2875 + struct au_dcsub_pages dpages;
2876 + struct au_dpage *dpage;
2879 + err = au_dpages_init(&dpages, GFP_NOFS);
2880 + if (unlikely(err))
2882 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
2883 + if (unlikely(err))
2886 + for (i = 0; !err && i < dpages.ndpage; i++) {
2887 + dpage = dpages.dpages + i;
2888 + ndentry = dpage->ndentry;
2889 + for (j = 0; !err && j < ndentry; j++) {
2890 + d = dpage->dentries[j];
2891 + AuDebugOn(!d_count(d));
2892 + if (!au_digen_test(d, sigen)) {
2893 + di_read_lock_child(d, AuLock_IR);
2894 + if (unlikely(au_dbrange_test(d))) {
2895 + di_read_unlock(d, AuLock_IR);
2899 + di_write_lock_child(d);
2900 + if (unlikely(au_dbrange_test(d))) {
2901 + di_write_unlock(d);
2904 + err = au_reval_dpath(d, sigen);
2906 + di_downgrade_lock(d, AuLock_IR);
2908 + di_write_unlock(d);
2913 + /* AuDbgDentry(d); */
2914 + bstart = au_dbstart(d);
2915 + bend = au_dbend(d);
2916 + if (bstart <= bindex
2918 + && au_h_dptr(d, bindex)
2919 + && au_test_dbusy(d, bstart, bend)) {
2921 + AuVerbose(verbose, "busy %pd\n", d);
2924 + di_read_unlock(d, AuLock_IR);
2929 + au_dpages_free(&dpages);
2934 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
2935 + unsigned int sigen, const unsigned int verbose)
2938 + unsigned long long max, ull;
2939 + struct inode *i, **array;
2940 + aufs_bindex_t bstart, bend;
2942 + array = au_iarray_alloc(sb, &max);
2943 + err = PTR_ERR(array);
2944 + if (IS_ERR(array))
2948 + AuDbg("b%d\n", bindex);
2949 + for (ull = 0; !err && ull < max; ull++) {
2951 + if (i->i_ino == AUFS_ROOT_INO)
2954 + /* AuDbgInode(i); */
2955 + if (au_iigen(i, NULL) == sigen)
2956 + ii_read_lock_child(i);
2958 + ii_write_lock_child(i);
2959 + err = au_refresh_hinode_self(i);
2962 + ii_downgrade_lock(i);
2964 + ii_write_unlock(i);
2969 + bstart = au_ibstart(i);
2970 + bend = au_ibend(i);
2971 + if (bstart <= bindex
2973 + && au_h_iptr(i, bindex)
2974 + && au_test_ibusy(i, bstart, bend)) {
2976 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
2979 + ii_read_unlock(i);
2981 + au_iarray_free(array, max);
2987 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
2988 + const unsigned int verbose)
2991 + unsigned int sigen;
2993 + sigen = au_sigen(root->d_sb);
2994 + DiMustNoWaiters(root);
2995 + IiMustNoWaiters(root->d_inode);
2996 + di_write_unlock(root);
2997 + err = test_dentry_busy(root, bindex, sigen, verbose);
2999 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3000 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3005 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3006 + const aufs_bindex_t bindex,
3007 + const aufs_bindex_t bend)
3009 + struct au_branch **brp, **p;
3011 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3013 + brp = sbinfo->si_branch + bindex;
3014 + if (bindex < bend)
3015 + memmove(brp, brp + 1, sizeof(*brp) * (bend - bindex));
3016 + sbinfo->si_branch[0 + bend] = NULL;
3017 + sbinfo->si_bend--;
3019 + p = krealloc(sbinfo->si_branch, sizeof(*p) * bend, AuGFP_SBILIST);
3021 + sbinfo->si_branch = p;
3022 + /* harmless error */
3025 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3026 + const aufs_bindex_t bend)
3028 + struct au_hdentry *hdp, *p;
3030 + AuRwMustWriteLock(&dinfo->di_rwsem);
3032 + hdp = dinfo->di_hdentry;
3033 + if (bindex < bend)
3034 + memmove(hdp + bindex, hdp + bindex + 1,
3035 + sizeof(*hdp) * (bend - bindex));
3036 + hdp[0 + bend].hd_dentry = NULL;
3039 + p = krealloc(hdp, sizeof(*p) * bend, AuGFP_SBILIST);
3041 + dinfo->di_hdentry = p;
3042 + /* harmless error */
3045 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3046 + const aufs_bindex_t bend)
3048 + struct au_hinode *hip, *p;
3050 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3052 + hip = iinfo->ii_hinode + bindex;
3053 + if (bindex < bend)
3054 + memmove(hip, hip + 1, sizeof(*hip) * (bend - bindex));
3055 + iinfo->ii_hinode[0 + bend].hi_inode = NULL;
3056 + au_hn_init(iinfo->ii_hinode + bend);
3059 + p = krealloc(iinfo->ii_hinode, sizeof(*p) * bend, AuGFP_SBILIST);
3061 + iinfo->ii_hinode = p;
3062 + /* harmless error */
3065 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3066 + struct au_branch *br)
3068 + aufs_bindex_t bend;
3069 + struct au_sbinfo *sbinfo;
3070 + struct dentry *root, *h_root;
3071 + struct inode *inode, *h_inode;
3072 + struct au_hinode *hinode;
3074 + SiMustWriteLock(sb);
3076 + root = sb->s_root;
3077 + inode = root->d_inode;
3078 + sbinfo = au_sbi(sb);
3079 + bend = sbinfo->si_bend;
3081 + h_root = au_h_dptr(root, bindex);
3082 + hinode = au_hi(inode, bindex);
3083 + h_inode = au_igrab(hinode->hi_inode);
3086 + au_sbilist_lock();
3087 + au_br_do_del_brp(sbinfo, bindex, bend);
3088 + au_br_do_del_hdp(au_di(root), bindex, bend);
3089 + au_br_do_del_hip(au_ii(inode), bindex, bend);
3090 + au_sbilist_unlock();
3094 + au_br_do_free(br);
3097 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3100 + unsigned int mnt_flags;
3101 + aufs_bindex_t bindex, bend, br_id;
3102 + unsigned char do_wh, verbose;
3103 + struct au_branch *br;
3104 + struct au_wbr *wbr;
3107 + bindex = au_find_dbindex(sb->s_root, del->h_path.dentry);
3110 + goto out; /* success */
3112 + pr_err("%s no such branch\n", del->pathname);
3115 + AuDbg("bindex b%d\n", bindex);
3118 + mnt_flags = au_mntflags(sb);
3119 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3120 + bend = au_sbend(sb);
3121 + if (unlikely(!bend)) {
3122 + AuVerbose(verbose, "no more branches left\n");
3125 + br = au_sbr(sb, bindex);
3126 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3127 + i = atomic_read(&br->br_count);
3128 + if (unlikely(i)) {
3129 + AuVerbose(verbose, "%d file(s) opened\n", i);
3134 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3136 + /* instead of WbrWhMustWriteLock(wbr) */
3137 + SiMustWriteLock(sb);
3138 + for (i = 0; i < AuBrWh_Last; i++) {
3139 + dput(wbr->wbr_wh[i]);
3140 + wbr->wbr_wh[i] = NULL;
3144 + err = test_children_busy(sb->s_root, bindex, verbose);
3145 + if (unlikely(err)) {
3152 + br_id = br->br_id;
3154 + au_br_do_del(sb, bindex, br);
3156 + sysaufs_brs_del(sb, bindex);
3157 + au_br_do_del(sb, bindex, br);
3158 + sysaufs_brs_add(sb, bindex);
3162 + au_cpup_attr_all(sb->s_root->d_inode, /*force*/1);
3163 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
3165 + au_sub_nlink(sb->s_root->d_inode, del->h_path.dentry->d_inode);
3166 + if (au_opt_test(mnt_flags, PLINK))
3167 + au_plink_half_refresh(sb, br_id);
3169 + if (au_xino_brid(sb) == br_id)
3170 + au_xino_brid_set(sb, -1);
3171 + goto out; /* success */
3175 + rerr = au_br_init_wh(sb, br, br->br_perm);
3177 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
3178 + del->pathname, rerr);
3183 +/* ---------------------------------------------------------------------- */
3185 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
3188 + aufs_bindex_t bstart, bend;
3189 + struct aufs_ibusy ibusy;
3190 + struct inode *inode, *h_inode;
3193 + if (unlikely(!capable(CAP_SYS_ADMIN)))
3196 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
3198 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
3199 + if (unlikely(err)) {
3206 + si_read_lock(sb, AuLock_FLUSH);
3207 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbend(sb)))
3211 + ibusy.h_ino = 0; /* invalid */
3212 + inode = ilookup(sb, ibusy.ino);
3214 + || inode->i_ino == AUFS_ROOT_INO
3215 + || is_bad_inode(inode))
3218 + ii_read_lock_child(inode);
3219 + bstart = au_ibstart(inode);
3220 + bend = au_ibend(inode);
3221 + if (bstart <= ibusy.bindex && ibusy.bindex <= bend) {
3222 + h_inode = au_h_iptr(inode, ibusy.bindex);
3223 + if (h_inode && au_test_ibusy(inode, bstart, bend))
3224 + ibusy.h_ino = h_inode->i_ino;
3226 + ii_read_unlock(inode);
3230 + si_read_unlock(sb);
3232 + err = __put_user(ibusy.h_ino, &arg->h_ino);
3233 + if (unlikely(err)) {
3242 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
3244 + return au_ibusy(file->f_dentry->d_sb, (void __user *)arg);
3247 +#ifdef CONFIG_COMPAT
3248 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
3250 + return au_ibusy(file->f_dentry->d_sb, compat_ptr(arg));
3254 +/* ---------------------------------------------------------------------- */
3257 + * change a branch permission
3260 +static void au_warn_ima(void)
3263 + /* since it doesn't support mark_files_ro() */
3264 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
3268 +static int do_need_sigen_inc(int a, int b)
3270 + return au_br_whable(a) && !au_br_whable(b);
3273 +static int need_sigen_inc(int old, int new)
3275 + return do_need_sigen_inc(old, new)
3276 + || do_need_sigen_inc(new, old);
3279 +static unsigned long long au_farray_cb(void *a,
3280 + unsigned long long max __maybe_unused,
3283 + unsigned long long n;
3284 + struct file **p, *f;
3285 + struct au_sphlhead *files;
3286 + struct au_finfo *finfo;
3287 + struct super_block *sb = arg;
3291 + files = &au_sbi(sb)->si_files;
3292 + spin_lock(&files->spin);
3293 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
3294 + f = finfo->fi_file;
3296 + && !special_file(file_inode(f)->i_mode)) {
3300 + AuDebugOn(n > max);
3303 + spin_unlock(&files->spin);
3308 +static struct file **au_farray_alloc(struct super_block *sb,
3309 + unsigned long long *max)
3311 + *max = atomic_long_read(&au_sbi(sb)->si_nfiles);
3312 + return au_array_alloc(max, au_farray_cb, sb);
3315 +static void au_farray_free(struct file **a, unsigned long long max)
3317 + unsigned long long ull;
3319 + for (ull = 0; ull < max; ull++)
3325 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
3328 + unsigned int mnt_flags;
3329 + unsigned long long ull, max;
3330 + aufs_bindex_t br_id;
3331 + unsigned char verbose;
3332 + struct file *file, *hf, **array;
3333 + struct inode *inode;
3334 + struct au_hfile *hfile;
3336 + mnt_flags = au_mntflags(sb);
3337 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3339 + array = au_farray_alloc(sb, &max);
3340 + err = PTR_ERR(array);
3341 + if (IS_ERR(array))
3345 + br_id = au_sbr_id(sb, bindex);
3346 + for (ull = 0; ull < max; ull++) {
3347 + file = array[ull];
3349 + /* AuDbg("%pD\n", file); */
3350 + fi_read_lock(file);
3351 + if (unlikely(au_test_mmapped(file))) {
3353 + AuVerbose(verbose, "mmapped %pD\n", file);
3355 + FiMustNoWaiters(file);
3356 + fi_read_unlock(file);
3360 + inode = file_inode(file);
3361 + hfile = &au_fi(file)->fi_htop;
3362 + hf = hfile->hf_file;
3363 + if (!S_ISREG(inode->i_mode)
3364 + || !(file->f_mode & FMODE_WRITE)
3365 + || hfile->hf_br->br_id != br_id
3366 + || !(hf->f_mode & FMODE_WRITE))
3367 + array[ull] = NULL;
3373 + FiMustNoWaiters(file);
3374 + fi_read_unlock(file);
3382 + for (ull = 0; ull < max; ull++) {
3383 + file = array[ull];
3387 + /* todo: already flushed? */
3389 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
3390 + * approach which resets f_mode and calls mnt_drop_write() and
3391 + * file_release_write() for each file, because the branch
3392 + * attribute in aufs world is totally different from the native
3395 + /* fi_read_lock(file); */
3396 + hfile = &au_fi(file)->fi_htop;
3397 + hf = hfile->hf_file;
3398 + /* fi_read_unlock(file); */
3399 + spin_lock(&hf->f_lock);
3400 + hf->f_mode &= ~FMODE_WRITE;
3401 + spin_unlock(&hf->f_lock);
3402 + if (!file_check_writeable(hf)) {
3403 + __mnt_drop_write(hf->f_path.mnt);
3404 + file_release_write(hf);
3409 + au_farray_free(array, max);
3415 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
3419 + aufs_bindex_t bindex;
3420 + struct dentry *root;
3421 + struct au_branch *br;
3423 + root = sb->s_root;
3424 + bindex = au_find_dbindex(root, mod->h_root);
3427 + return 0; /* success */
3429 + pr_err("%s no such branch\n", mod->path);
3432 + AuDbg("bindex b%d\n", bindex);
3434 + err = test_br(mod->h_root->d_inode, mod->perm, mod->path);
3435 + if (unlikely(err))
3438 + br = au_sbr(sb, bindex);
3439 + AuDebugOn(mod->h_root != au_br_dentry(br));
3440 + if (br->br_perm == mod->perm)
3441 + return 0; /* success */
3443 + if (au_br_writable(br->br_perm)) {
3444 + /* remove whiteout base */
3445 + err = au_br_init_wh(sb, br, mod->perm);
3446 + if (unlikely(err))
3449 + if (!au_br_writable(mod->perm)) {
3450 + /* rw --> ro, file might be mmapped */
3451 + DiMustNoWaiters(root);
3452 + IiMustNoWaiters(root->d_inode);
3453 + di_write_unlock(root);
3454 + err = au_br_mod_files_ro(sb, bindex);
3455 + /* aufs_write_lock() calls ..._child() */
3456 + di_write_lock_child(root);
3458 + if (unlikely(err)) {
3460 + br->br_wbr = kmalloc(sizeof(*br->br_wbr),
3463 + rerr = au_wbr_init(br, sb, br->br_perm);
3464 + if (unlikely(rerr)) {
3465 + AuIOErr("nested error %d (%d)\n",
3467 + br->br_perm = mod->perm;
3471 + } else if (au_br_writable(mod->perm)) {
3474 + br->br_wbr = kmalloc(sizeof(*br->br_wbr), GFP_NOFS);
3476 + err = au_wbr_init(br, sb, mod->perm);
3477 + if (unlikely(err)) {
3478 + kfree(br->br_wbr);
3479 + br->br_wbr = NULL;
3485 + if ((br->br_perm & AuBrAttr_UNPIN)
3486 + && !(mod->perm & AuBrAttr_UNPIN))
3487 + au_br_dflags_force(br);
3488 + else if (!(br->br_perm & AuBrAttr_UNPIN)
3489 + && (mod->perm & AuBrAttr_UNPIN))
3490 + au_br_dflags_restore(br);
3491 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
3492 + br->br_perm = mod->perm;
3499 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
3500 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
3501 +++ linux/fs/aufs/branch.h 2014-04-24 22:11:10.848602379 +0200
3504 + * Copyright (C) 2005-2014 Junjiro R. Okajima
3506 + * This program, aufs is free software; you can redistribute it and/or modify
3507 + * it under the terms of the GNU General Public License as published by
3508 + * the Free Software Foundation; either version 2 of the License, or
3509 + * (at your option) any later version.
3511 + * This program is distributed in the hope that it will be useful,
3512 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3513 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3514 + * GNU General Public License for more details.
3516 + * You should have received a copy of the GNU General Public License
3517 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3521 + * branch filesystems and xino for them
3524 +#ifndef __AUFS_BRANCH_H__
3525 +#define __AUFS_BRANCH_H__
3529 +#include <linux/mount.h>
3534 +/* ---------------------------------------------------------------------- */
3537 +struct au_xino_file {
3538 + struct file *xi_file;
3539 + struct mutex xi_nondir_mtx;
3541 + /* todo: make xino files an array to support huge inode number */
3543 +#ifdef CONFIG_DEBUG_FS
3544 + struct dentry *xi_dbgaufs;
3548 +/* members for writable branch only */
3549 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
3551 + struct au_rwsem wbr_wh_rwsem;
3552 + struct dentry *wbr_wh[AuBrWh_Last];
3553 + atomic_t wbr_wh_running;
3554 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
3555 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
3556 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
3559 + unsigned long long wbr_bytes;
3562 +/* ext2 has 3 types of operations at least, ext3 has 4 */
3563 +#define AuBrDynOp (AuDyLast * 4)
3565 +#ifdef CONFIG_AUFS_HFSNOTIFY
3566 +/* support for asynchronous destruction */
3567 +struct au_br_hfsnotify {
3568 + struct fsnotify_group *hfsn_group;
3572 +/* sysfs entries */
3573 +struct au_brsysfs {
3575 + struct attribute attr;
3584 +/* protected by superblock rwsem */
3586 + struct au_xino_file br_xino;
3588 + aufs_bindex_t br_id;
3591 + unsigned int br_dflags;
3592 + struct path br_path;
3593 + spinlock_t br_dykey_lock;
3594 + struct au_dykey *br_dykey[AuBrDynOp];
3595 + atomic_t br_count;
3597 + struct au_wbr *br_wbr;
3599 + /* xino truncation */
3600 + atomic_t br_xino_running;
3602 +#ifdef CONFIG_AUFS_HFSNOTIFY
3603 + struct au_br_hfsnotify *br_hfsn;
3606 +#ifdef CONFIG_SYSFS
3607 + /* entries under sysfs per mount-point */
3608 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
3612 +/* ---------------------------------------------------------------------- */
3614 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
3616 + return br->br_path.mnt;
3619 +static inline struct dentry *au_br_dentry(struct au_branch *br)
3621 + return br->br_path.dentry;
3624 +static inline struct super_block *au_br_sb(struct au_branch *br)
3626 + return au_br_mnt(br)->mnt_sb;
3629 +/* branch permissions and attributes */
3630 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
3631 +#define AuBrPerm_RO (1 << 1) /* readonly */
3632 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
3633 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
3635 +#define AuBrRAttr_WH (1 << 3) /* whiteout-able */
3637 +#define AuBrWAttr_NoLinkWH (1 << 4) /* un-hardlinkable whiteouts */
3639 +#define AuBrAttr_UNPIN (1 << 5) /* rename-able top dir of
3642 +static inline int au_br_writable(int brperm)
3644 + return brperm & AuBrPerm_RW;
3647 +static inline int au_br_whable(int brperm)
3649 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
3652 +static inline int au_br_wh_linkable(int brperm)
3654 + return !(brperm & AuBrWAttr_NoLinkWH);
3657 +static inline int au_br_rdonly(struct au_branch *br)
3659 + return ((au_br_sb(br)->s_flags & MS_RDONLY)
3660 + || !au_br_writable(br->br_perm))
3664 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
3666 +#ifdef CONFIG_AUFS_HNOTIFY
3667 + return !(brperm & AuBrPerm_RR);
3673 +/* ---------------------------------------------------------------------- */
3677 +void au_br_free(struct au_sbinfo *sinfo);
3678 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
3680 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
3682 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
3683 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
3684 +#ifdef CONFIG_COMPAT
3685 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
3688 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
3692 +static const loff_t au_loff_max = LLONG_MAX;
3694 +int au_xib_trunc(struct super_block *sb);
3695 +ssize_t xino_fread(au_readf_t func, struct file *file, void *buf, size_t size,
3697 +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size,
3699 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src);
3700 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent);
3701 +ino_t au_xino_new_ino(struct super_block *sb);
3702 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
3703 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
3705 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
3707 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino,
3708 + struct file *base_file, int do_test);
3709 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex);
3711 +struct au_opt_xino;
3712 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount);
3713 +void au_xino_clr(struct super_block *sb);
3714 +struct file *au_xino_def(struct super_block *sb);
3715 +int au_xino_path(struct seq_file *seq, struct file *file);
3717 +/* ---------------------------------------------------------------------- */
3719 +/* Superblock to branch */
3721 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
3723 + return au_sbr(sb, bindex)->br_id;
3727 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
3729 + return au_br_mnt(au_sbr(sb, bindex));
3733 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
3735 + return au_br_sb(au_sbr(sb, bindex));
3738 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
3740 + atomic_dec(&au_sbr(sb, bindex)->br_count);
3743 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
3745 + return au_sbr(sb, bindex)->br_perm;
3748 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
3750 + return au_br_whable(au_sbr_perm(sb, bindex));
3753 +/* ---------------------------------------------------------------------- */
3756 + * wbr_wh_read_lock, wbr_wh_write_lock
3757 + * wbr_wh_read_unlock, wbr_wh_write_unlock, wbr_wh_downgrade_lock
3759 +AuSimpleRwsemFuncs(wbr_wh, struct au_wbr *wbr, &wbr->wbr_wh_rwsem);
3761 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&wbr->wbr_wh_rwsem)
3762 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&wbr->wbr_wh_rwsem)
3763 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&wbr->wbr_wh_rwsem)
3765 +#endif /* __KERNEL__ */
3766 +#endif /* __AUFS_BRANCH_H__ */
3767 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
3768 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
3769 +++ linux/fs/aufs/conf.mk 2014-04-24 22:11:10.848602379 +0200
3772 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
3776 +AuConfStr += ${1}=${${1}}
3780 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
3782 + HNOTIFY HFSNOTIFY \
3792 +$(foreach i, ${AuConfAll}, \
3793 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
3795 +AuConfName = ${obj}/conf.str
3796 +${AuConfName}.tmp: FORCE
3797 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
3798 +${AuConfName}: ${AuConfName}.tmp
3799 + @diff -q $< $@ > /dev/null 2>&1 || { \
3800 + echo ' GEN ' $@; \
3804 +clean-files += ${AuConfName} ${AuConfName}.tmp
3805 +${obj}/sysfs.o: ${AuConfName}
3807 +-include ${srctree}/${src}/conf_priv.mk
3808 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
3809 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
3810 +++ linux/fs/aufs/cpup.c 2014-04-24 22:11:10.848602379 +0200
3813 + * Copyright (C) 2005-2014 Junjiro R. Okajima
3815 + * This program, aufs is free software; you can redistribute it and/or modify
3816 + * it under the terms of the GNU General Public License as published by
3817 + * the Free Software Foundation; either version 2 of the License, or
3818 + * (at your option) any later version.
3820 + * This program is distributed in the hope that it will be useful,
3821 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3822 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3823 + * GNU General Public License for more details.
3825 + * You should have received a copy of the GNU General Public License
3826 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3830 + * copy-up functions, see wbr_policy.c for copy-down
3833 +#include <linux/fs_stack.h>
3834 +#include <linux/mm.h>
3837 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
3839 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
3840 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
3842 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
3844 + dst->i_flags |= iflags & ~mask;
3845 + if (au_test_fs_notime(dst->i_sb))
3846 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
3849 +void au_cpup_attr_timesizes(struct inode *inode)
3851 + struct inode *h_inode;
3853 + h_inode = au_h_iptr(inode, au_ibstart(inode));
3854 + fsstack_copy_attr_times(inode, h_inode);
3855 + fsstack_copy_inode_size(inode, h_inode);
3858 +void au_cpup_attr_nlink(struct inode *inode, int force)
3860 + struct inode *h_inode;
3861 + struct super_block *sb;
3862 + aufs_bindex_t bindex, bend;
3865 + bindex = au_ibstart(inode);
3866 + h_inode = au_h_iptr(inode, bindex);
3868 + && !S_ISDIR(h_inode->i_mode)
3869 + && au_opt_test(au_mntflags(sb), PLINK)
3870 + && au_plink_test(inode))
3874 + * 0 can happen in revalidating.
3875 + * h_inode->i_mutex is not held, but it is harmless since once i_nlink
3876 + * reaches 0, it will never become positive.
3878 + set_nlink(inode, h_inode->i_nlink);
3881 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
3882 + * it may includes whplink directory.
3884 + if (S_ISDIR(h_inode->i_mode)) {
3885 + bend = au_ibend(inode);
3886 + for (bindex++; bindex <= bend; bindex++) {
3887 + h_inode = au_h_iptr(inode, bindex);
3889 + au_add_nlink(inode, h_inode);
3894 +void au_cpup_attr_changeable(struct inode *inode)
3896 + struct inode *h_inode;
3898 + h_inode = au_h_iptr(inode, au_ibstart(inode));
3899 + inode->i_mode = h_inode->i_mode;
3900 + inode->i_uid = h_inode->i_uid;
3901 + inode->i_gid = h_inode->i_gid;
3902 + au_cpup_attr_timesizes(inode);
3903 + au_cpup_attr_flags(inode, h_inode->i_flags);
3906 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
3908 + struct au_iinfo *iinfo = au_ii(inode);
3910 + IiMustWriteLock(inode);
3912 + iinfo->ii_higen = h_inode->i_generation;
3913 + iinfo->ii_hsb1 = h_inode->i_sb;
3916 +void au_cpup_attr_all(struct inode *inode, int force)
3918 + struct inode *h_inode;
3920 + h_inode = au_h_iptr(inode, au_ibstart(inode));
3921 + au_cpup_attr_changeable(inode);
3922 + if (inode->i_nlink > 0)
3923 + au_cpup_attr_nlink(inode, force);
3924 + inode->i_rdev = h_inode->i_rdev;
3925 + inode->i_blkbits = h_inode->i_blkbits;
3926 + au_cpup_igen(inode, h_inode);
3929 +/* ---------------------------------------------------------------------- */
3931 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
3933 +/* keep the timestamps of the parent dir when cpup */
3934 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
3935 + struct path *h_path)
3937 + struct inode *h_inode;
3939 + dt->dt_dentry = dentry;
3940 + dt->dt_h_path = *h_path;
3941 + h_inode = h_path->dentry->d_inode;
3942 + dt->dt_atime = h_inode->i_atime;
3943 + dt->dt_mtime = h_inode->i_mtime;
3947 +void au_dtime_revert(struct au_dtime *dt)
3949 + struct iattr attr;
3952 + attr.ia_atime = dt->dt_atime;
3953 + attr.ia_mtime = dt->dt_mtime;
3954 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
3955 + | ATTR_ATIME | ATTR_ATIME_SET;
3957 + /* no delegation since this is a directory */
3958 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
3959 + if (unlikely(err))
3960 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
3963 +/* ---------------------------------------------------------------------- */
3965 +/* internal use only */
3966 +struct au_cpup_reg_attr {
3969 + unsigned int iflags; /* inode->i_flags */
3972 +static noinline_for_stack
3973 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
3974 + struct au_cpup_reg_attr *h_src_attr)
3978 + struct path h_path;
3979 + struct inode *h_isrc, *h_idst;
3980 + struct kstat *h_st;
3982 + h_path.dentry = au_h_dptr(dst, bindex);
3983 + h_idst = h_path.dentry->d_inode;
3984 + h_path.mnt = au_sbr_mnt(dst->d_sb, bindex);
3985 + h_isrc = h_src->d_inode;
3986 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
3987 + | ATTR_ATIME | ATTR_MTIME
3988 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
3989 + if (h_src_attr && h_src_attr->valid) {
3990 + h_st = &h_src_attr->st;
3991 + ia.ia_uid = h_st->uid;
3992 + ia.ia_gid = h_st->gid;
3993 + ia.ia_atime = h_st->atime;
3994 + ia.ia_mtime = h_st->mtime;
3995 + if (h_idst->i_mode != h_st->mode
3996 + && !S_ISLNK(h_idst->i_mode)) {
3997 + ia.ia_valid |= ATTR_MODE;
3998 + ia.ia_mode = h_st->mode;
4000 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4001 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4003 + ia.ia_uid = h_isrc->i_uid;
4004 + ia.ia_gid = h_isrc->i_gid;
4005 + ia.ia_atime = h_isrc->i_atime;
4006 + ia.ia_mtime = h_isrc->i_mtime;
4007 + if (h_idst->i_mode != h_isrc->i_mode
4008 + && !S_ISLNK(h_idst->i_mode)) {
4009 + ia.ia_valid |= ATTR_MODE;
4010 + ia.ia_mode = h_isrc->i_mode;
4012 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4013 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4015 + /* no delegation since it is just created */
4016 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4018 + /* is this nfs only? */
4019 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
4020 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
4021 + ia.ia_mode = h_isrc->i_mode;
4022 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4028 +/* ---------------------------------------------------------------------- */
4030 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
4031 + char *buf, unsigned long blksize)
4034 + size_t sz, rbytes, wbytes;
4035 + unsigned char all_zero;
4037 + struct mutex *h_mtx;
4038 + /* reduce stack usage */
4041 + zp = page_address(ZERO_PAGE(0));
4042 + if (unlikely(!zp))
4043 + return -ENOMEM; /* possible? */
4048 + AuDbg("len %lld\n", len);
4050 + if (len < blksize)
4054 + /* todo: signal_pending? */
4055 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
4056 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
4059 + if (unlikely(err < 0))
4063 + if (len >= rbytes && rbytes == blksize)
4064 + all_zero = !memcmp(buf, zp, rbytes);
4071 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
4073 + /* todo: signal_pending? */
4074 + if (unlikely(err == -EAGAIN || err == -EINTR))
4076 + if (unlikely(err < 0))
4081 + if (unlikely(err < 0))
4087 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
4089 + if (unlikely(res < 0))
4096 + /* the last block may be a hole */
4097 + if (!err && all_zero) {
4098 + AuLabel(last hole);
4101 + if (au_test_nfs(dst->f_dentry->d_sb)) {
4102 + /* nfs requires this step to make last hole */
4103 + /* is this only nfs? */
4105 + /* todo: signal_pending? */
4106 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
4107 + } while (err == -EAGAIN || err == -EINTR);
4114 + ia->ia_size = dst->f_pos;
4115 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
4116 + ia->ia_file = dst;
4117 + h_mtx = &file_inode(dst)->i_mutex;
4118 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
4119 + /* no delegation since it is just created */
4120 + err = vfsub_notify_change(&dst->f_path, ia,
4121 + /*delegated*/NULL);
4122 + mutex_unlock(h_mtx);
4129 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
4132 + unsigned long blksize;
4133 + unsigned char do_kfree;
4137 + blksize = dst->f_dentry->d_sb->s_blocksize;
4138 + if (!blksize || PAGE_SIZE < blksize)
4139 + blksize = PAGE_SIZE;
4140 + AuDbg("blksize %lu\n", blksize);
4141 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
4143 + buf = kmalloc(blksize, GFP_NOFS);
4145 + buf = (void *)__get_free_page(GFP_NOFS);
4146 + if (unlikely(!buf))
4149 + if (len > (1 << 22))
4150 + AuDbg("copying a large file %lld\n", (long long)len);
4154 + err = au_do_copy_file(dst, src, len, buf, blksize);
4158 + free_page((unsigned long)buf);
4165 + * to support a sparse file which is opened with O_APPEND,
4166 + * we need to close the file.
4168 +static int au_cp_regular(struct au_cp_generic *cpg)
4171 + enum { SRC, DST };
4173 + aufs_bindex_t bindex;
4174 + unsigned int flags;
4175 + struct dentry *dentry;
4177 + struct file *file;
4181 + .bindex = cpg->bsrc,
4182 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
4186 + .bindex = cpg->bdst,
4187 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
4188 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
4189 + .label = &&out_src
4192 + struct super_block *sb;
4194 + /* bsrc branch can be ro/rw. */
4195 + sb = cpg->dentry->d_sb;
4197 + for (i = 0; i < 2; i++, f++) {
4198 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
4199 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
4200 + /*file*/NULL, f->force_wr);
4201 + err = PTR_ERR(f->file);
4202 + if (IS_ERR(f->file))
4206 + /* try stopping to update while we copyup */
4207 + IMustLock(file[SRC].dentry->d_inode);
4208 + err = au_copy_file(file[DST].file, file[SRC].file, cpg->len);
4210 + fput(file[DST].file);
4211 + au_sbr_put(sb, file[DST].bindex);
4214 + fput(file[SRC].file);
4215 + au_sbr_put(sb, file[SRC].bindex);
4220 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
4221 + struct au_cpup_reg_attr *h_src_attr)
4225 + struct path h_path;
4226 + struct inode *h_src_inode;
4229 + h_src_inode = au_h_iptr(cpg->dentry->d_inode, cpg->bsrc);
4230 + l = i_size_read(h_src_inode);
4231 + if (cpg->len == -1 || l < cpg->len)
4234 + /* try stopping to update while we are referencing */
4235 + mutex_lock_nested(&h_src_inode->i_mutex, AuLsc_I_CHILD);
4236 + au_pin_hdir_unlock(cpg->pin);
4238 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
4239 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
4240 + h_src_attr->iflags = h_src_inode->i_flags;
4241 + err = vfs_getattr(&h_path, &h_src_attr->st);
4242 + if (unlikely(err)) {
4243 + mutex_unlock(&h_src_inode->i_mutex);
4246 + h_src_attr->valid = 1;
4247 + err = au_cp_regular(cpg);
4248 + mutex_unlock(&h_src_inode->i_mutex);
4249 + rerr = au_pin_hdir_relock(cpg->pin);
4258 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
4259 + struct inode *h_dir)
4262 + mm_segment_t old_fs;
4269 + if (unlikely(!h_src->d_inode->i_op->readlink))
4273 + sym.k = (void *)__get_free_page(GFP_NOFS);
4274 + if (unlikely(!sym.k))
4277 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
4278 + old_fs = get_fs();
4279 + set_fs(KERNEL_DS);
4280 + symlen = h_src->d_inode->i_op->readlink(h_src, sym.u, PATH_MAX);
4285 + sym.k[symlen] = 0;
4286 + err = vfsub_symlink(h_dir, h_path, sym.k);
4288 + free_page((unsigned long)sym.k);
4294 +static noinline_for_stack
4295 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
4296 + struct au_cpup_reg_attr *h_src_attr)
4300 + unsigned int mnt_flags;
4301 + unsigned char isdir;
4302 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
4303 + struct au_dtime dt;
4304 + struct path h_path;
4305 + struct dentry *h_src, *h_dst, *h_parent;
4306 + struct inode *h_inode, *h_dir;
4307 + struct super_block *sb;
4309 + /* bsrc branch can be ro/rw. */
4310 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
4311 + h_inode = h_src->d_inode;
4312 + AuDebugOn(h_inode != au_h_iptr(cpg->dentry->d_inode, cpg->bsrc));
4314 + /* try stopping to be referenced while we are creating */
4315 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
4316 + if (au_ftest_cpup(cpg->flags, RENAME))
4317 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
4318 + AUFS_WH_PFX_LEN));
4319 + h_parent = h_dst->d_parent; /* dir inode is locked */
4320 + h_dir = h_parent->d_inode;
4322 + AuDebugOn(h_parent != h_dst->d_parent);
4324 + sb = cpg->dentry->d_sb;
4325 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
4327 + h_path.dentry = h_parent;
4328 + au_dtime_store(&dt, dst_parent, &h_path);
4330 + h_path.dentry = h_dst;
4333 + mode = h_inode->i_mode;
4334 + switch (mode & S_IFMT) {
4336 + err = vfsub_create(h_dir, &h_path, mode | S_IWUSR,
4337 + /*want_excl*/true);
4339 + err = au_do_cpup_regular(cpg, h_src_attr);
4343 + err = vfsub_mkdir(h_dir, &h_path, mode);
4346 + * strange behaviour from the users view,
4347 + * particularry setattr case
4349 + if (au_ibstart(dst_parent->d_inode) == cpg->bdst)
4350 + au_cpup_attr_nlink(dst_parent->d_inode,
4352 + au_cpup_attr_nlink(cpg->dentry->d_inode, /*force*/1);
4356 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
4360 + AuDebugOn(!capable(CAP_MKNOD));
4364 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
4367 + AuIOErr("Unknown inode type 0%o\n", mode);
4371 + mnt_flags = au_mntflags(sb);
4372 + if (!au_opt_test(mnt_flags, UDBA_NONE)
4374 + && au_opt_test(mnt_flags, XINO)
4375 + && h_inode->i_nlink == 1
4376 + /* todo: unnecessary? */
4377 + /* && cpg->dentry->d_inode->i_nlink == 1 */
4378 + && cpg->bdst < cpg->bsrc
4379 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
4380 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
4381 + /* ignore this error */
4384 + au_dtime_revert(&dt);
4388 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
4391 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
4392 + struct inode *h_dir;
4393 + aufs_bindex_t bdst;
4395 + dentry = cpg->dentry;
4397 + h_dentry = au_h_dptr(dentry, bdst);
4398 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
4400 + au_set_h_dptr(dentry, bdst, NULL);
4401 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
4403 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
4404 + au_set_h_dptr(dentry, bdst, h_dentry);
4407 + parent = dget_parent(dentry);
4408 + h_parent = au_h_dptr(parent, bdst);
4410 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
4411 + if (IS_ERR(h_path->dentry))
4412 + err = PTR_ERR(h_path->dentry);
4414 + if (unlikely(err))
4417 + h_parent = h_dentry->d_parent; /* dir inode is locked */
4418 + h_dir = h_parent->d_inode;
4420 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
4421 + /* no delegation since it is just created */
4422 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL);
4423 + dput(h_path->dentry);
4430 + * copyup the @dentry from @bsrc to @bdst.
4431 + * the caller must set the both of lower dentries.
4432 + * @len is for truncating when it is -1 copyup the entire file.
4433 + * in link/rename cases, @dst_parent may be different from the real one.
4434 + * basic->bsrc can be larger than basic->bdst.
4436 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
4439 + aufs_bindex_t old_ibstart;
4440 + unsigned char isdir, plink;
4441 + struct dentry *h_src, *h_dst, *h_parent;
4442 + struct inode *dst_inode, *h_dir, *inode, *delegated;
4443 + struct super_block *sb;
4444 + struct au_branch *br;
4445 + /* to reuduce stack size */
4447 + struct au_dtime dt;
4448 + struct path h_path;
4449 + struct au_cpup_reg_attr h_src_attr;
4453 + a = kmalloc(sizeof(*a), GFP_NOFS);
4456 + a->h_src_attr.valid = 0;
4458 + sb = cpg->dentry->d_sb;
4459 + br = au_sbr(sb, cpg->bdst);
4460 + a->h_path.mnt = au_br_mnt(br);
4461 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
4462 + h_parent = h_dst->d_parent; /* dir inode is locked */
4463 + h_dir = h_parent->d_inode;
4466 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
4467 + inode = cpg->dentry->d_inode;
4470 + dst_parent = dget_parent(cpg->dentry);
4474 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
4475 + dst_inode = au_h_iptr(inode, cpg->bdst);
4477 + if (unlikely(!plink)) {
4479 + AuIOErr("hi%lu(i%lu) exists on b%d "
4480 + "but plink is disabled\n",
4481 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
4485 + if (dst_inode->i_nlink) {
4486 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
4488 + h_src = au_plink_lkup(inode, cpg->bdst);
4489 + err = PTR_ERR(h_src);
4490 + if (IS_ERR(h_src))
4492 + if (unlikely(!h_src->d_inode)) {
4494 + AuIOErr("i%lu exists on a upper branch "
4495 + "but not pseudo-linked\n",
4502 + a->h_path.dentry = h_parent;
4503 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
4506 + a->h_path.dentry = h_dst;
4508 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
4509 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
4510 + err = au_do_ren_after_cpup(cpg, &a->h_path);
4512 + au_dtime_revert(&a->dt);
4513 + if (unlikely(err == -EWOULDBLOCK)) {
4514 + pr_warn("cannot retry for NFSv4 delegation"
4515 + " for an internal link\n");
4521 + /* todo: cpup_wh_file? */
4523 + au_update_ibrange(inode, /*do_put_zero*/1);
4526 + isdir = S_ISDIR(inode->i_mode);
4527 + old_ibstart = au_ibstart(inode);
4528 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
4529 + if (unlikely(err))
4531 + dst_inode = h_dst->d_inode;
4532 + mutex_lock_nested(&dst_inode->i_mutex, AuLsc_I_CHILD2);
4533 + /* todo: necessary? */
4534 + /* au_pin_hdir_unlock(cpg->pin); */
4536 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
4537 + if (unlikely(err)) {
4538 + /* todo: necessary? */
4539 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
4540 + mutex_unlock(&dst_inode->i_mutex);
4544 + if (cpg->bdst < old_ibstart) {
4545 + if (S_ISREG(inode->i_mode)) {
4546 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
4547 + if (unlikely(err)) {
4548 + /* ignore an error */
4549 + /* au_pin_hdir_relock(cpg->pin); */
4550 + mutex_unlock(&dst_inode->i_mutex);
4554 + au_set_ibstart(inode, cpg->bdst);
4556 + au_set_ibend(inode, cpg->bdst);
4557 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
4558 + au_hi_flags(inode, isdir));
4560 + /* todo: necessary? */
4561 + /* err = au_pin_hdir_relock(cpg->pin); */
4562 + mutex_unlock(&dst_inode->i_mutex);
4563 + if (unlikely(err))
4567 + && h_src->d_inode->i_nlink > 1
4569 + au_plink_append(inode, cpg->bdst, h_dst);
4571 + if (au_ftest_cpup(cpg->flags, RENAME)) {
4572 + a->h_path.dentry = h_dst;
4573 + err = au_do_ren_after_cpup(cpg, &a->h_path);
4576 + goto out_parent; /* success */
4580 + a->h_path.dentry = h_parent;
4581 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
4582 + a->h_path.dentry = h_dst;
4584 + if (h_dst->d_inode) {
4586 + /* no delegation since it is just created */
4587 + rerr = vfsub_unlink(h_dir, &a->h_path,
4588 + /*delegated*/NULL, /*force*/0);
4590 + rerr = vfsub_rmdir(h_dir, &a->h_path);
4592 + au_dtime_revert(&a->dt);
4594 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
4605 +struct au_cpup_single_args {
4607 + struct au_cp_generic *cpg;
4608 + struct dentry *dst_parent;
4611 +static void au_call_cpup_single(void *args)
4613 + struct au_cpup_single_args *a = args;
4615 + au_pin_hdir_acquire_nest(a->cpg->pin);
4616 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
4617 + au_pin_hdir_release(a->cpg->pin);
4622 + * prevent SIGXFSZ in copy-up.
4623 + * testing CAP_MKNOD is for generic fs,
4624 + * but CAP_FSETID is for xfs only, currently.
4626 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
4629 + struct super_block *sb;
4630 + struct inode *h_dir;
4633 + sb = au_pinned_parent(pin)->d_sb;
4634 + if (!au_wkq_test()
4635 + && (!au_sbi(sb)->si_plink_maint_pid
4636 + || au_plink_maint(sb, AuLock_NOPLM))) {
4637 + switch (mode & S_IFMT) {
4639 + /* no condition about RLIMIT_FSIZE and the file size */
4644 + do_sio = !capable(CAP_MKNOD);
4648 + do_sio = ((mode & (S_ISUID | S_ISGID))
4649 + && !capable(CAP_FSETID));
4650 + /* this workaround may be removed in the future */
4652 + h_dir = au_pinned_h_dir(pin);
4653 + do_sio = h_dir->i_mode & S_ISVTX;
4661 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
4664 + struct dentry *h_dentry;
4666 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
4667 + if (!au_cpup_sio_test(pin, h_dentry->d_inode->i_mode))
4668 + err = au_cpup_single(cpg, dst_parent);
4670 + struct au_cpup_single_args args = {
4673 + .dst_parent = dst_parent
4675 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
4676 + if (unlikely(wkq_err))
4685 + * copyup the @dentry from the first active lower branch to @bdst,
4686 + * using au_cpup_single().
4688 +static int au_cpup_simple(struct au_cp_generic *cpg)
4691 + unsigned int flags_orig;
4692 + struct dentry *dentry;
4694 + AuDebugOn(cpg->bsrc < 0);
4696 + dentry = cpg->dentry;
4697 + DiMustWriteLock(dentry);
4699 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
4701 + flags_orig = cpg->flags;
4702 + au_fset_cpup(cpg->flags, RENAME);
4703 + err = au_cpup_single(cpg, NULL);
4704 + cpg->flags = flags_orig;
4706 + return 0; /* success */
4709 + au_set_h_dptr(dentry, cpg->bdst, NULL);
4710 + au_set_dbstart(dentry, cpg->bsrc);
4716 +struct au_cpup_simple_args {
4718 + struct au_cp_generic *cpg;
4721 +static void au_call_cpup_simple(void *args)
4723 + struct au_cpup_simple_args *a = args;
4725 + au_pin_hdir_acquire_nest(a->cpg->pin);
4726 + *a->errp = au_cpup_simple(a->cpg);
4727 + au_pin_hdir_release(a->cpg->pin);
4730 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
4733 + struct dentry *dentry, *parent;
4734 + struct file *h_file;
4735 + struct inode *h_dir;
4737 + dentry = cpg->dentry;
4739 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
4740 + AuDebugOn(cpg->bsrc < 0);
4741 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
4742 + err = PTR_ERR(h_file);
4743 + if (IS_ERR(h_file))
4747 + parent = dget_parent(dentry);
4748 + h_dir = au_h_iptr(parent->d_inode, cpg->bdst);
4749 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
4750 + && !au_cpup_sio_test(cpg->pin, dentry->d_inode->i_mode))
4751 + err = au_cpup_simple(cpg);
4753 + struct au_cpup_simple_args args = {
4757 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
4758 + if (unlikely(wkq_err))
4764 + au_h_open_post(dentry, cpg->bsrc, h_file);
4770 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
4772 + aufs_bindex_t bsrc, bend;
4773 + struct dentry *dentry, *h_dentry;
4775 + if (cpg->bsrc < 0) {
4776 + dentry = cpg->dentry;
4777 + bend = au_dbend(dentry);
4778 + for (bsrc = cpg->bdst + 1; bsrc <= bend; bsrc++) {
4779 + h_dentry = au_h_dptr(dentry, bsrc);
4781 + AuDebugOn(!h_dentry->d_inode);
4785 + AuDebugOn(bsrc > bend);
4788 + AuDebugOn(cpg->bsrc <= cpg->bdst);
4789 + return au_do_sio_cpup_simple(cpg);
4792 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
4794 + AuDebugOn(cpg->bdst <= cpg->bsrc);
4795 + return au_do_sio_cpup_simple(cpg);
4798 +/* ---------------------------------------------------------------------- */
4801 + * copyup the deleted file for writing.
4803 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
4804 + struct file *file)
4807 + unsigned int flags_orig;
4808 + aufs_bindex_t bsrc_orig;
4809 + struct dentry *h_d_dst, *h_d_start;
4810 + struct au_dinfo *dinfo;
4811 + struct au_hdentry *hdp;
4813 + dinfo = au_di(cpg->dentry);
4814 + AuRwMustWriteLock(&dinfo->di_rwsem);
4816 + bsrc_orig = cpg->bsrc;
4817 + cpg->bsrc = dinfo->di_bstart;
4818 + hdp = dinfo->di_hdentry;
4819 + h_d_dst = hdp[0 + cpg->bdst].hd_dentry;
4820 + dinfo->di_bstart = cpg->bdst;
4821 + hdp[0 + cpg->bdst].hd_dentry = wh_dentry;
4824 + h_d_start = hdp[0 + cpg->bsrc].hd_dentry;
4825 + hdp[0 + cpg->bsrc].hd_dentry = au_hf_top(file)->f_dentry;
4827 + flags_orig = cpg->flags;
4828 + cpg->flags = !AuCpup_DTIME;
4829 + err = au_cpup_single(cpg, /*h_parent*/NULL);
4830 + cpg->flags = flags_orig;
4833 + err = au_reopen_nondir(file);
4834 + hdp[0 + cpg->bsrc].hd_dentry = h_d_start;
4836 + hdp[0 + cpg->bdst].hd_dentry = h_d_dst;
4837 + dinfo->di_bstart = cpg->bsrc;
4838 + cpg->bsrc = bsrc_orig;
4843 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
4846 + aufs_bindex_t bdst;
4847 + struct au_dtime dt;
4848 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
4849 + struct au_branch *br;
4850 + struct path h_path;
4852 + dentry = cpg->dentry;
4854 + br = au_sbr(dentry->d_sb, bdst);
4855 + parent = dget_parent(dentry);
4856 + h_parent = au_h_dptr(parent, bdst);
4857 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
4858 + err = PTR_ERR(wh_dentry);
4859 + if (IS_ERR(wh_dentry))
4862 + h_path.dentry = h_parent;
4863 + h_path.mnt = au_br_mnt(br);
4864 + au_dtime_store(&dt, parent, &h_path);
4865 + err = au_do_cpup_wh(cpg, wh_dentry, file);
4866 + if (unlikely(err))
4870 + h_path.dentry = wh_dentry;
4871 + if (!S_ISDIR(wh_dentry->d_inode->i_mode)) {
4872 + /* no delegation since it is just created */
4873 + err = vfsub_unlink(h_parent->d_inode, &h_path,
4874 + /*delegated*/NULL, /*force*/0);
4876 + err = vfsub_rmdir(h_parent->d_inode, &h_path);
4877 + if (unlikely(err)) {
4878 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
4882 + au_dtime_revert(&dt);
4883 + au_set_hi_wh(dentry->d_inode, bdst, wh_dentry);
4892 +struct au_cpup_wh_args {
4894 + struct au_cp_generic *cpg;
4895 + struct file *file;
4898 +static void au_call_cpup_wh(void *args)
4900 + struct au_cpup_wh_args *a = args;
4902 + au_pin_hdir_acquire_nest(a->cpg->pin);
4903 + *a->errp = au_cpup_wh(a->cpg, a->file);
4904 + au_pin_hdir_release(a->cpg->pin);
4907 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
4910 + aufs_bindex_t bdst;
4911 + struct dentry *dentry, *parent, *h_orph, *h_parent, *h_dentry;
4912 + struct inode *dir, *h_dir, *h_tmpdir;
4913 + struct au_wbr *wbr;
4914 + struct au_pin wh_pin, *pin_orig;
4916 + dentry = cpg->dentry;
4918 + parent = dget_parent(dentry);
4919 + dir = parent->d_inode;
4922 + h_dir = au_igrab(au_h_iptr(dir, bdst));
4925 + if (!h_dir->i_nlink) {
4926 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
4927 + h_orph = wbr->wbr_orph;
4929 + h_parent = dget(au_h_dptr(parent, bdst));
4930 + au_set_h_dptr(parent, bdst, dget(h_orph));
4931 + h_tmpdir = h_orph->d_inode;
4932 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
4935 + h_dentry = au_hf_top(file)->f_dentry;
4937 + h_dentry = au_h_dptr(dentry, au_dbstart(dentry));
4938 + mutex_lock_nested(&h_tmpdir->i_mutex, AuLsc_I_PARENT3);
4939 + /* todo: au_h_open_pre()? */
4941 + pin_orig = cpg->pin;
4942 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
4943 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
4944 + cpg->pin = &wh_pin;
4947 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
4948 + && !au_cpup_sio_test(cpg->pin, dentry->d_inode->i_mode))
4949 + err = au_cpup_wh(cpg, file);
4951 + struct au_cpup_wh_args args = {
4956 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
4957 + if (unlikely(wkq_err))
4962 + mutex_unlock(&h_tmpdir->i_mutex);
4963 + /* todo: au_h_open_post()? */
4964 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
4965 + au_set_h_dptr(parent, bdst, h_parent);
4966 + AuDebugOn(!pin_orig);
4967 + cpg->pin = pin_orig;
4975 +/* ---------------------------------------------------------------------- */
4978 + * generic routine for both of copy-up and copy-down.
4980 +/* cf. revalidate function in file.c */
4981 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
4982 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
4983 + struct au_pin *pin,
4984 + struct dentry *h_parent, void *arg),
4988 + struct au_pin pin;
4989 + struct dentry *d, *parent, *h_parent, *real_parent;
4992 + parent = dget_parent(dentry);
4993 + if (IS_ROOT(parent))
4996 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
4997 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
4999 + /* do not use au_dpage */
5000 + real_parent = parent;
5003 + parent = dget_parent(dentry);
5004 + h_parent = au_h_dptr(parent, bdst);
5006 + goto out; /* success */
5008 + /* find top dir which is necessary to cpup */
5012 + parent = dget_parent(d);
5013 + di_read_lock_parent3(parent, !AuLock_IR);
5014 + h_parent = au_h_dptr(parent, bdst);
5015 + di_read_unlock(parent, !AuLock_IR);
5016 + } while (!h_parent);
5018 + if (d != real_parent)
5019 + di_write_lock_child3(d);
5021 + /* somebody else might create while we were sleeping */
5022 + if (!au_h_dptr(d, bdst) || !au_h_dptr(d, bdst)->d_inode) {
5023 + if (au_h_dptr(d, bdst))
5024 + au_update_dbstart(d);
5026 + au_pin_set_dentry(&pin, d);
5027 + err = au_do_pin(&pin);
5029 + err = cp(d, bdst, &pin, h_parent, arg);
5034 + if (d != real_parent)
5035 + di_write_unlock(d);
5036 + if (unlikely(err))
5045 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
5046 + struct au_pin *pin,
5047 + struct dentry *h_parent __maybe_unused ,
5048 + void *arg __maybe_unused)
5050 + struct au_cp_generic cpg = {
5056 + .flags = AuCpup_DTIME
5058 + return au_sio_cpup_simple(&cpg);
5061 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
5063 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
5066 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
5069 + struct dentry *parent;
5070 + struct inode *dir;
5072 + parent = dget_parent(dentry);
5073 + dir = parent->d_inode;
5075 + if (au_h_iptr(dir, bdst))
5078 + di_read_unlock(parent, AuLock_IR);
5079 + di_write_lock_parent(parent);
5080 + /* someone else might change our inode while we were sleeping */
5081 + if (!au_h_iptr(dir, bdst))
5082 + err = au_cpup_dirs(dentry, bdst);
5083 + di_downgrade_lock(parent, AuLock_IR);
5089 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
5090 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
5091 +++ linux/fs/aufs/cpup.h 2014-04-24 22:11:10.848602379 +0200
5094 + * Copyright (C) 2005-2014 Junjiro R. Okajima
5096 + * This program, aufs is free software; you can redistribute it and/or modify
5097 + * it under the terms of the GNU General Public License as published by
5098 + * the Free Software Foundation; either version 2 of the License, or
5099 + * (at your option) any later version.
5101 + * This program is distributed in the hope that it will be useful,
5102 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5103 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5104 + * GNU General Public License for more details.
5106 + * You should have received a copy of the GNU General Public License
5107 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5111 + * copy-up/down functions
5114 +#ifndef __AUFS_CPUP_H__
5115 +#define __AUFS_CPUP_H__
5119 +#include <linux/path.h>
5125 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
5126 +void au_cpup_attr_timesizes(struct inode *inode);
5127 +void au_cpup_attr_nlink(struct inode *inode, int force);
5128 +void au_cpup_attr_changeable(struct inode *inode);
5129 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
5130 +void au_cpup_attr_all(struct inode *inode, int force);
5132 +/* ---------------------------------------------------------------------- */
5134 +struct au_cp_generic {
5135 + struct dentry *dentry;
5136 + aufs_bindex_t bdst, bsrc;
5138 + struct au_pin *pin;
5139 + unsigned int flags;
5143 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
5144 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
5146 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
5147 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
5149 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
5151 +#define AuCpup_RWDST (1 << 5) /* force write target even if
5152 + the branch is marked as RO */
5154 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
5155 +#define au_fset_cpup(flags, name) \
5156 + do { (flags) |= AuCpup_##name; } while (0)
5157 +#define au_fclr_cpup(flags, name) \
5158 + do { (flags) &= ~AuCpup_##name; } while (0)
5160 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
5161 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
5162 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
5163 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
5165 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
5166 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
5167 + struct au_pin *pin,
5168 + struct dentry *h_parent, void *arg),
5170 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
5171 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
5173 +/* ---------------------------------------------------------------------- */
5175 +/* keep timestamps when copyup */
5177 + struct dentry *dt_dentry;
5178 + struct path dt_h_path;
5179 + struct timespec dt_atime, dt_mtime;
5181 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
5182 + struct path *h_path);
5183 +void au_dtime_revert(struct au_dtime *dt);
5185 +#endif /* __KERNEL__ */
5186 +#endif /* __AUFS_CPUP_H__ */
5187 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
5188 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
5189 +++ linux/fs/aufs/dbgaufs.c 2014-04-24 22:11:10.848602379 +0200
5192 + * Copyright (C) 2005-2014 Junjiro R. Okajima
5194 + * This program, aufs is free software; you can redistribute it and/or modify
5195 + * it under the terms of the GNU General Public License as published by
5196 + * the Free Software Foundation; either version 2 of the License, or
5197 + * (at your option) any later version.
5199 + * This program is distributed in the hope that it will be useful,
5200 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5201 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5202 + * GNU General Public License for more details.
5204 + * You should have received a copy of the GNU General Public License
5205 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5209 + * debugfs interface
5212 +#include <linux/debugfs.h>
5215 +#ifndef CONFIG_SYSFS
5216 +#error DEBUG_FS depends upon SYSFS
5219 +static struct dentry *dbgaufs;
5220 +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH;
5222 +/* 20 is max digits length of ulong 64 */
5223 +struct dbgaufs_arg {
5229 + * common function for all XINO files
5231 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
5232 + struct file *file)
5234 + kfree(file->private_data);
5238 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt)
5242 + struct dbgaufs_arg *p;
5245 + p = kmalloc(sizeof(*p), GFP_NOFS);
5251 + file->private_data = p;
5255 + err = vfs_getattr(&xf->f_path, &st);
5259 + (p->a, sizeof(p->a), "%ld, %llux%lu %lld\n",
5260 + (long)file_count(xf), st.blocks, st.blksize,
5261 + (long long)st.size);
5263 + p->n = snprintf(p->a, sizeof(p->a), "%llux%lu %lld\n",
5264 + st.blocks, st.blksize,
5265 + (long long)st.size);
5266 + AuDebugOn(p->n >= sizeof(p->a));
5268 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
5277 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
5278 + size_t count, loff_t *ppos)
5280 + struct dbgaufs_arg *p;
5282 + p = file->private_data;
5283 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
5286 +/* ---------------------------------------------------------------------- */
5288 +struct dbgaufs_plink_arg {
5293 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
5294 + struct file *file)
5296 + free_page((unsigned long)file->private_data);
5300 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
5302 + int err, i, limit;
5303 + unsigned long n, sum;
5304 + struct dbgaufs_plink_arg *p;
5305 + struct au_sbinfo *sbinfo;
5306 + struct super_block *sb;
5307 + struct au_sphlhead *sphl;
5310 + p = (void *)get_zeroed_page(GFP_NOFS);
5315 + sbinfo = inode->i_private;
5316 + sb = sbinfo->si_sb;
5317 + si_noflush_read_lock(sb);
5318 + if (au_opt_test(au_mntflags(sb), PLINK)) {
5319 + limit = PAGE_SIZE - sizeof(p->n);
5321 + /* the number of buckets */
5322 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
5327 + for (i = 0, sphl = sbinfo->si_plink;
5328 + i < AuPlink_NHASH;
5330 + n = au_sphl_count(sphl);
5333 + n = snprintf(p->a + p->n, limit, "%lu ", n);
5336 + if (unlikely(limit <= 0))
5339 + p->a[p->n - 1] = '\n';
5341 + /* the sum of plinks */
5342 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
5345 + if (unlikely(limit <= 0))
5348 +#define str "1\n0\n0\n"
5349 + p->n = sizeof(str) - 1;
5350 + strcpy(p->a, str);
5353 + si_read_unlock(sb);
5356 + file->private_data = p;
5357 + goto out; /* success */
5360 + free_page((unsigned long)p);
5365 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
5366 + size_t count, loff_t *ppos)
5368 + struct dbgaufs_plink_arg *p;
5370 + p = file->private_data;
5371 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
5374 +static const struct file_operations dbgaufs_plink_fop = {
5375 + .owner = THIS_MODULE,
5376 + .open = dbgaufs_plink_open,
5377 + .release = dbgaufs_plink_release,
5378 + .read = dbgaufs_plink_read
5381 +/* ---------------------------------------------------------------------- */
5383 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
5386 + struct au_sbinfo *sbinfo;
5387 + struct super_block *sb;
5389 + sbinfo = inode->i_private;
5390 + sb = sbinfo->si_sb;
5391 + si_noflush_read_lock(sb);
5392 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
5393 + si_read_unlock(sb);
5397 +static const struct file_operations dbgaufs_xib_fop = {
5398 + .owner = THIS_MODULE,
5399 + .open = dbgaufs_xib_open,
5400 + .release = dbgaufs_xi_release,
5401 + .read = dbgaufs_xi_read
5404 +/* ---------------------------------------------------------------------- */
5406 +#define DbgaufsXi_PREFIX "xi"
5408 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
5412 + struct au_sbinfo *sbinfo;
5413 + struct super_block *sb;
5415 + struct qstr *name;
5419 + name = &file->f_dentry->d_name;
5420 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
5421 + || memcmp(name->name, DbgaufsXi_PREFIX,
5422 + sizeof(DbgaufsXi_PREFIX) - 1)))
5424 + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
5425 + if (unlikely(err))
5428 + sbinfo = inode->i_private;
5429 + sb = sbinfo->si_sb;
5430 + si_noflush_read_lock(sb);
5431 + if (l <= au_sbend(sb)) {
5432 + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file;
5433 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1);
5436 + si_read_unlock(sb);
5442 +static const struct file_operations dbgaufs_xino_fop = {
5443 + .owner = THIS_MODULE,
5444 + .open = dbgaufs_xino_open,
5445 + .release = dbgaufs_xi_release,
5446 + .read = dbgaufs_xi_read
5449 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
5451 + aufs_bindex_t bend;
5452 + struct au_branch *br;
5453 + struct au_xino_file *xi;
5455 + if (!au_sbi(sb)->si_dbgaufs)
5458 + bend = au_sbend(sb);
5459 + for (; bindex <= bend; bindex++) {
5460 + br = au_sbr(sb, bindex);
5461 + xi = &br->br_xino;
5462 + debugfs_remove(xi->xi_dbgaufs);
5463 + xi->xi_dbgaufs = NULL;
5467 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
5469 + struct au_sbinfo *sbinfo;
5470 + struct dentry *parent;
5471 + struct au_branch *br;
5472 + struct au_xino_file *xi;
5473 + aufs_bindex_t bend;
5474 + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
5476 + sbinfo = au_sbi(sb);
5477 + parent = sbinfo->si_dbgaufs;
5481 + bend = au_sbend(sb);
5482 + for (; bindex <= bend; bindex++) {
5483 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
5484 + br = au_sbr(sb, bindex);
5485 + xi = &br->br_xino;
5486 + AuDebugOn(xi->xi_dbgaufs);
5487 + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
5488 + sbinfo, &dbgaufs_xino_fop);
5489 + /* ignore an error */
5490 + if (unlikely(!xi->xi_dbgaufs))
5491 + AuWarn1("failed %s under debugfs\n", name);
5495 +/* ---------------------------------------------------------------------- */
5497 +#ifdef CONFIG_AUFS_EXPORT
5498 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
5501 + struct au_sbinfo *sbinfo;
5502 + struct super_block *sb;
5504 + sbinfo = inode->i_private;
5505 + sb = sbinfo->si_sb;
5506 + si_noflush_read_lock(sb);
5507 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0);
5508 + si_read_unlock(sb);
5512 +static const struct file_operations dbgaufs_xigen_fop = {
5513 + .owner = THIS_MODULE,
5514 + .open = dbgaufs_xigen_open,
5515 + .release = dbgaufs_xi_release,
5516 + .read = dbgaufs_xi_read
5519 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
5524 + * This function is a dynamic '__init' fucntion actually,
5525 + * so the tiny check for si_rwsem is unnecessary.
5527 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
5530 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
5531 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
5532 + &dbgaufs_xigen_fop);
5533 + if (sbinfo->si_dbgaufs_xigen)
5539 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
5543 +#endif /* CONFIG_AUFS_EXPORT */
5545 +/* ---------------------------------------------------------------------- */
5547 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
5550 + * This function is a dynamic '__init' fucntion actually,
5551 + * so the tiny check for si_rwsem is unnecessary.
5553 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
5555 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
5556 + sbinfo->si_dbgaufs = NULL;
5557 + kobject_put(&sbinfo->si_kobj);
5560 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
5563 + char name[SysaufsSiNameLen];
5566 + * This function is a dynamic '__init' fucntion actually,
5567 + * so the tiny check for si_rwsem is unnecessary.
5569 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
5573 + AuErr1("/debug/aufs is uninitialized\n");
5578 + sysaufs_name(sbinfo, name);
5579 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
5580 + if (unlikely(!sbinfo->si_dbgaufs))
5582 + kobject_get(&sbinfo->si_kobj);
5584 + sbinfo->si_dbgaufs_xib = debugfs_create_file
5585 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
5586 + &dbgaufs_xib_fop);
5587 + if (unlikely(!sbinfo->si_dbgaufs_xib))
5590 + sbinfo->si_dbgaufs_plink = debugfs_create_file
5591 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
5592 + &dbgaufs_plink_fop);
5593 + if (unlikely(!sbinfo->si_dbgaufs_plink))
5596 + err = dbgaufs_xigen_init(sbinfo);
5598 + goto out; /* success */
5601 + dbgaufs_si_fin(sbinfo);
5606 +/* ---------------------------------------------------------------------- */
5608 +void dbgaufs_fin(void)
5610 + debugfs_remove(dbgaufs);
5613 +int __init dbgaufs_init(void)
5618 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
5623 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
5624 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
5625 +++ linux/fs/aufs/dbgaufs.h 2014-04-24 22:11:10.848602379 +0200
5628 + * Copyright (C) 2005-2014 Junjiro R. Okajima
5630 + * This program, aufs is free software; you can redistribute it and/or modify
5631 + * it under the terms of the GNU General Public License as published by
5632 + * the Free Software Foundation; either version 2 of the License, or
5633 + * (at your option) any later version.
5635 + * This program is distributed in the hope that it will be useful,
5636 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5637 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5638 + * GNU General Public License for more details.
5640 + * You should have received a copy of the GNU General Public License
5641 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5645 + * debugfs interface
5648 +#ifndef __DBGAUFS_H__
5649 +#define __DBGAUFS_H__
5653 +struct super_block;
5656 +#ifdef CONFIG_DEBUG_FS
5658 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
5659 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
5660 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
5661 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
5662 +void dbgaufs_fin(void);
5663 +int __init dbgaufs_init(void);
5665 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
5666 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
5667 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
5668 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
5669 +AuStubVoid(dbgaufs_fin, void)
5670 +AuStubInt0(__init dbgaufs_init, void)
5671 +#endif /* CONFIG_DEBUG_FS */
5673 +#endif /* __KERNEL__ */
5674 +#endif /* __DBGAUFS_H__ */
5675 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
5676 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
5677 +++ linux/fs/aufs/dcsub.c 2014-04-24 22:11:10.848602379 +0200
5680 + * Copyright (C) 2005-2014 Junjiro R. Okajima
5682 + * This program, aufs is free software; you can redistribute it and/or modify
5683 + * it under the terms of the GNU General Public License as published by
5684 + * the Free Software Foundation; either version 2 of the License, or
5685 + * (at your option) any later version.
5687 + * This program is distributed in the hope that it will be useful,
5688 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5689 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5690 + * GNU General Public License for more details.
5692 + * You should have received a copy of the GNU General Public License
5693 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5697 + * sub-routines for dentry cache
5702 +static void au_dpage_free(struct au_dpage *dpage)
5705 + struct dentry **p;
5707 + p = dpage->dentries;
5708 + for (i = 0; i < dpage->ndentry; i++)
5710 + free_page((unsigned long)dpage->dentries);
5713 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
5719 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
5720 + if (unlikely(!dpages->dpages))
5723 + p = (void *)__get_free_page(gfp);
5727 + dpages->dpages[0].ndentry = 0;
5728 + dpages->dpages[0].dentries = p;
5729 + dpages->ndpage = 1;
5730 + return 0; /* success */
5733 + kfree(dpages->dpages);
5738 +void au_dpages_free(struct au_dcsub_pages *dpages)
5741 + struct au_dpage *p;
5743 + p = dpages->dpages;
5744 + for (i = 0; i < dpages->ndpage; i++)
5745 + au_dpage_free(p++);
5746 + kfree(dpages->dpages);
5749 +static int au_dpages_append(struct au_dcsub_pages *dpages,
5750 + struct dentry *dentry, gfp_t gfp)
5753 + struct au_dpage *dpage;
5756 + dpage = dpages->dpages + dpages->ndpage - 1;
5757 + sz = PAGE_SIZE / sizeof(dentry);
5758 + if (unlikely(dpage->ndentry >= sz)) {
5759 + AuLabel(new dpage);
5761 + sz = dpages->ndpage * sizeof(*dpages->dpages);
5762 + p = au_kzrealloc(dpages->dpages, sz,
5763 + sz + sizeof(*dpages->dpages), gfp);
5767 + dpages->dpages = p;
5768 + dpage = dpages->dpages + dpages->ndpage;
5769 + p = (void *)__get_free_page(gfp);
5773 + dpage->ndentry = 0;
5774 + dpage->dentries = p;
5778 + AuDebugOn(!d_count(dentry));
5779 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
5780 + return 0; /* success */
5786 +/* try d_walk() in linux/fs/dcache.c */
5787 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
5788 + au_dpages_test test, void *arg)
5791 + struct dentry *this_parent;
5792 + struct list_head *next;
5793 + struct super_block *sb = root->d_sb;
5796 + write_seqlock(&rename_lock);
5797 + this_parent = root;
5798 + spin_lock(&this_parent->d_lock);
5800 + next = this_parent->d_subdirs.next;
5802 + if (this_parent->d_sb == sb
5803 + && !IS_ROOT(this_parent)
5804 + && au_di(this_parent)
5805 + && d_count(this_parent)
5806 + && (!test || test(this_parent, arg))) {
5807 + err = au_dpages_append(dpages, this_parent, GFP_ATOMIC);
5808 + if (unlikely(err))
5812 + while (next != &this_parent->d_subdirs) {
5813 + struct list_head *tmp = next;
5814 + struct dentry *dentry = list_entry(tmp, struct dentry,
5818 + spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED);
5819 + if (d_count(dentry)) {
5820 + if (!list_empty(&dentry->d_subdirs)) {
5821 + spin_unlock(&this_parent->d_lock);
5822 + spin_release(&dentry->d_lock.dep_map, 1,
5824 + this_parent = dentry;
5825 + spin_acquire(&this_parent->d_lock.dep_map, 0, 1,
5829 + if (dentry->d_sb == sb
5831 + && (!test || test(dentry, arg)))
5832 + err = au_dpages_append(dpages, dentry,
5835 + spin_unlock(&dentry->d_lock);
5836 + if (unlikely(err))
5840 + if (this_parent != root) {
5841 + struct dentry *tmp;
5842 + struct dentry *child;
5844 + tmp = this_parent->d_parent;
5846 + spin_unlock(&this_parent->d_lock);
5847 + child = this_parent;
5848 + this_parent = tmp;
5849 + spin_lock(&this_parent->d_lock);
5850 + rcu_read_unlock();
5851 + next = child->d_child.next;
5856 + spin_unlock(&this_parent->d_lock);
5857 + write_sequnlock(&rename_lock);
5861 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
5862 + int do_include, au_dpages_test test, void *arg)
5867 + write_seqlock(&rename_lock);
5868 + spin_lock(&dentry->d_lock);
5870 + && d_count(dentry)
5871 + && (!test || test(dentry, arg)))
5872 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
5873 + spin_unlock(&dentry->d_lock);
5874 + if (unlikely(err))
5878 + * RCU for vfsmount is unnecessary since this is a traverse in a single
5881 + while (!IS_ROOT(dentry)) {
5882 + dentry = dentry->d_parent; /* rename_lock is locked */
5883 + spin_lock(&dentry->d_lock);
5884 + if (d_count(dentry)
5885 + && (!test || test(dentry, arg)))
5886 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
5887 + spin_unlock(&dentry->d_lock);
5888 + if (unlikely(err))
5893 + write_sequnlock(&rename_lock);
5897 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
5899 + return au_di(dentry) && dentry->d_sb == arg;
5902 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
5903 + struct dentry *dentry, int do_include)
5905 + return au_dcsub_pages_rev(dpages, dentry, do_include,
5906 + au_dcsub_dpages_aufs, dentry->d_sb);
5909 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
5911 + struct path path[2] = {
5920 + return path_is_under(path + 0, path + 1);
5922 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
5923 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
5924 +++ linux/fs/aufs/dcsub.h 2014-04-24 22:11:10.848602379 +0200
5927 + * Copyright (C) 2005-2014 Junjiro R. Okajima
5929 + * This program, aufs is free software; you can redistribute it and/or modify
5930 + * it under the terms of the GNU General Public License as published by
5931 + * the Free Software Foundation; either version 2 of the License, or
5932 + * (at your option) any later version.
5934 + * This program is distributed in the hope that it will be useful,
5935 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5936 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5937 + * GNU General Public License for more details.
5939 + * You should have received a copy of the GNU General Public License
5940 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5944 + * sub-routines for dentry cache
5947 +#ifndef __AUFS_DCSUB_H__
5948 +#define __AUFS_DCSUB_H__
5952 +#include <linux/dcache.h>
5953 +#include <linux/fs.h>
5959 + struct dentry **dentries;
5962 +struct au_dcsub_pages {
5964 + struct au_dpage *dpages;
5967 +/* ---------------------------------------------------------------------- */
5970 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
5971 +void au_dpages_free(struct au_dcsub_pages *dpages);
5972 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
5973 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
5974 + au_dpages_test test, void *arg);
5975 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
5976 + int do_include, au_dpages_test test, void *arg);
5977 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
5978 + struct dentry *dentry, int do_include);
5979 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
5981 +/* ---------------------------------------------------------------------- */
5984 + * todo: in linux-3.13, several similar (but faster) helpers are added to
5985 + * include/linux/dcache.h. Try them (in the future).
5988 +static inline int au_d_hashed_positive(struct dentry *d)
5991 + struct inode *inode = d->d_inode;
5993 + if (unlikely(d_unhashed(d) || !inode || !inode->i_nlink))
5998 +static inline int au_d_alive(struct dentry *d)
6001 + struct inode *inode;
6004 + err = au_d_hashed_positive(d);
6006 + inode = d->d_inode;
6007 + if (unlikely(d_unlinked(d) || !inode || !inode->i_nlink))
6013 +static inline int au_alive_dir(struct dentry *d)
6016 + err = au_d_alive(d);
6017 + if (unlikely(err || IS_DEADDIR(d->d_inode)))
6022 +#endif /* __KERNEL__ */
6023 +#endif /* __AUFS_DCSUB_H__ */
6024 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
6025 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
6026 +++ linux/fs/aufs/debug.c 2014-04-24 22:11:10.848602379 +0200
6029 + * Copyright (C) 2005-2014 Junjiro R. Okajima
6031 + * This program, aufs is free software; you can redistribute it and/or modify
6032 + * it under the terms of the GNU General Public License as published by
6033 + * the Free Software Foundation; either version 2 of the License, or
6034 + * (at your option) any later version.
6036 + * This program is distributed in the hope that it will be useful,
6037 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6038 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6039 + * GNU General Public License for more details.
6041 + * You should have received a copy of the GNU General Public License
6042 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6046 + * debug print functions
6049 +#include <linux/vt_kern.h>
6052 +/* Returns 0, or -errno. arg is in kp->arg. */
6053 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
6057 + err = kstrtoint(val, 0, &n);
6067 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
6068 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
6073 + return sprintf(buffer, "%d", atomic_read(a));
6076 +static struct kernel_param_ops param_ops_atomic_t = {
6077 + .set = param_atomic_t_set,
6078 + .get = param_atomic_t_get
6079 + /* void (*free)(void *arg) */
6082 +atomic_t aufs_debug = ATOMIC_INIT(0);
6083 +MODULE_PARM_DESC(debug, "debug print");
6084 +module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP);
6086 +char *au_plevel = KERN_DEBUG;
6087 +#define dpri(fmt, ...) do { \
6089 + && strcmp(au_plevel, KERN_DEBUG)) \
6090 + || au_debug_test()) \
6091 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
6094 +/* ---------------------------------------------------------------------- */
6096 +void au_dpri_whlist(struct au_nhash *whlist)
6098 + unsigned long ul, n;
6099 + struct hlist_head *head;
6100 + struct au_vdir_wh *pos;
6102 + n = whlist->nh_num;
6103 + head = whlist->nh_head;
6104 + for (ul = 0; ul < n; ul++) {
6105 + hlist_for_each_entry(pos, head, wh_hash)
6106 + dpri("b%d, %.*s, %d\n",
6108 + pos->wh_str.len, pos->wh_str.name,
6114 +void au_dpri_vdir(struct au_vdir *vdir)
6117 + union au_vdir_deblk_p p;
6120 + if (!vdir || IS_ERR(vdir)) {
6121 + dpri("err %ld\n", PTR_ERR(vdir));
6125 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n",
6126 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
6127 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
6128 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
6129 + p.deblk = vdir->vd_deblk[ul];
6131 + dpri("[%lu]: %p\n", ul, o);
6135 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
6136 + struct dentry *wh)
6141 + if (!inode || IS_ERR(inode)) {
6142 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
6146 + /* the type of i_blocks depends upon CONFIG_LBDAF */
6147 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
6148 + && sizeof(inode->i_blocks) != sizeof(u64));
6150 + n = (void *)wh->d_name.name;
6151 + l = wh->d_name.len;
6154 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
6155 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
6157 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
6158 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
6159 + i_size_read(inode), (unsigned long long)inode->i_blocks,
6160 + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
6161 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
6162 + inode->i_state, inode->i_flags, inode->i_version,
6163 + inode->i_generation,
6164 + l ? ", wh " : "", l, n);
6168 +void au_dpri_inode(struct inode *inode)
6170 + struct au_iinfo *iinfo;
6171 + aufs_bindex_t bindex;
6174 + err = do_pri_inode(-1, inode, -1, NULL);
6175 + if (err || !au_test_aufs(inode->i_sb))
6178 + iinfo = au_ii(inode);
6181 + dpri("i-1: bstart %d, bend %d, gen %d\n",
6182 + iinfo->ii_bstart, iinfo->ii_bend, au_iigen(inode, NULL));
6183 + if (iinfo->ii_bstart < 0)
6186 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend; bindex++) {
6187 + hn = !!au_hn(iinfo->ii_hinode + bindex);
6188 + do_pri_inode(bindex, iinfo->ii_hinode[0 + bindex].hi_inode, hn,
6189 + iinfo->ii_hinode[0 + bindex].hi_whdentry);
6193 +void au_dpri_dalias(struct inode *inode)
6197 + spin_lock(&inode->i_lock);
6198 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
6199 + au_dpri_dentry(d);
6200 + spin_unlock(&inode->i_lock);
6203 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
6205 + struct dentry *wh = NULL;
6208 + if (!dentry || IS_ERR(dentry)) {
6209 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
6212 + /* do not call dget_parent() here */
6213 + /* note: access d_xxx without d_lock */
6214 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
6215 + bindex, dentry, dentry,
6216 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
6217 + d_count(dentry), dentry->d_flags,
6218 + d_unhashed(dentry) ? "un" : "");
6220 + if (bindex >= 0 && dentry->d_inode && au_test_aufs(dentry->d_sb)) {
6221 + struct au_iinfo *iinfo = au_ii(dentry->d_inode);
6223 + hn = !!au_hn(iinfo->ii_hinode + bindex);
6224 + wh = iinfo->ii_hinode[0 + bindex].hi_whdentry;
6227 + do_pri_inode(bindex, dentry->d_inode, hn, wh);
6231 +void au_dpri_dentry(struct dentry *dentry)
6233 + struct au_dinfo *dinfo;
6234 + aufs_bindex_t bindex;
6236 + struct au_hdentry *hdp;
6238 + err = do_pri_dentry(-1, dentry);
6239 + if (err || !au_test_aufs(dentry->d_sb))
6242 + dinfo = au_di(dentry);
6245 + dpri("d-1: bstart %d, bend %d, bwh %d, bdiropq %d, gen %d\n",
6246 + dinfo->di_bstart, dinfo->di_bend,
6247 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry));
6248 + if (dinfo->di_bstart < 0)
6250 + hdp = dinfo->di_hdentry;
6251 + for (bindex = dinfo->di_bstart; bindex <= dinfo->di_bend; bindex++)
6252 + do_pri_dentry(bindex, hdp[0 + bindex].hd_dentry);
6255 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
6259 + if (!file || IS_ERR(file)) {
6260 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
6266 + && au_test_aufs(file->f_dentry->d_sb)
6268 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
6269 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
6270 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
6271 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
6272 + file->f_version, file->f_pos, a);
6273 + if (file->f_dentry)
6274 + do_pri_dentry(bindex, file->f_dentry);
6278 +void au_dpri_file(struct file *file)
6280 + struct au_finfo *finfo;
6281 + struct au_fidir *fidir;
6282 + struct au_hfile *hfile;
6283 + aufs_bindex_t bindex;
6286 + err = do_pri_file(-1, file);
6287 + if (err || !file->f_dentry || !au_test_aufs(file->f_dentry->d_sb))
6290 + finfo = au_fi(file);
6293 + if (finfo->fi_btop < 0)
6295 + fidir = finfo->fi_hdir;
6297 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
6299 + for (bindex = finfo->fi_btop;
6300 + bindex >= 0 && bindex <= fidir->fd_bbot;
6302 + hfile = fidir->fd_hfile + bindex;
6303 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
6307 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
6309 + struct vfsmount *mnt;
6310 + struct super_block *sb;
6312 + if (!br || IS_ERR(br))
6314 + mnt = au_br_mnt(br);
6315 + if (!mnt || IS_ERR(mnt))
6318 + if (!sb || IS_ERR(sb))
6321 + dpri("s%d: {perm 0x%x, id %d, cnt %d, wbr %p}, "
6322 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
6324 + bindex, br->br_perm, br->br_id, atomic_read(&br->br_count),
6325 + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
6326 + sb->s_flags, sb->s_count,
6327 + atomic_read(&sb->s_active), !!br->br_xino.xi_file);
6331 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
6335 +void au_dpri_sb(struct super_block *sb)
6337 + struct au_sbinfo *sbinfo;
6338 + aufs_bindex_t bindex;
6340 + /* to reuduce stack size */
6342 + struct vfsmount mnt;
6343 + struct au_branch fake;
6346 + /* this function can be called from magic sysrq */
6347 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
6348 + if (unlikely(!a)) {
6349 + dpri("no memory\n");
6353 + a->mnt.mnt_sb = sb;
6354 + a->fake.br_perm = 0;
6355 + a->fake.br_path.mnt = &a->mnt;
6356 + a->fake.br_xino.xi_file = NULL;
6357 + atomic_set(&a->fake.br_count, 0);
6358 + smp_mb(); /* atomic_set */
6359 + err = do_pri_br(-1, &a->fake);
6361 + dpri("dev 0x%x\n", sb->s_dev);
6362 + if (err || !au_test_aufs(sb))
6365 + sbinfo = au_sbi(sb);
6368 + dpri("nw %d, gen %u, kobj %d\n",
6369 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
6370 + atomic_read(&sbinfo->si_kobj.kref.refcount));
6371 + for (bindex = 0; bindex <= sbinfo->si_bend; bindex++)
6372 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
6375 +/* ---------------------------------------------------------------------- */
6377 +void au_dbg_sleep_jiffy(int jiffy)
6380 + jiffy = schedule_timeout_uninterruptible(jiffy);
6383 +void au_dbg_iattr(struct iattr *ia)
6385 +#define AuBit(name) \
6387 + if (ia->ia_valid & ATTR_ ## name) \
6388 + dpri(#name "\n"); \
6408 + dpri("ia_file %p\n", ia->ia_file);
6411 +/* ---------------------------------------------------------------------- */
6413 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
6415 + struct inode *h_inode, *inode = dentry->d_inode;
6416 + struct dentry *h_dentry;
6417 + aufs_bindex_t bindex, bend, bi;
6419 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
6422 + bend = au_dbend(dentry);
6423 + bi = au_ibend(inode);
6426 + bindex = au_dbstart(dentry);
6427 + bi = au_ibstart(inode);
6431 + for (; bindex <= bend; bindex++) {
6432 + h_dentry = au_h_dptr(dentry, bindex);
6435 + h_inode = au_h_iptr(inode, bindex);
6436 + if (unlikely(h_inode != h_dentry->d_inode)) {
6438 + AuDbg("b%d, %s:%d\n", bindex, func, line);
6439 + AuDbgDentry(dentry);
6440 + AuDbgInode(inode);
6447 +void au_dbg_verify_dir_parent(struct dentry *dentry, unsigned int sigen)
6449 + struct dentry *parent;
6451 + parent = dget_parent(dentry);
6452 + AuDebugOn(!S_ISDIR(dentry->d_inode->i_mode));
6453 + AuDebugOn(IS_ROOT(dentry));
6454 + AuDebugOn(au_digen_test(parent, sigen));
6458 +void au_dbg_verify_nondir_parent(struct dentry *dentry, unsigned int sigen)
6460 + struct dentry *parent;
6461 + struct inode *inode;
6463 + parent = dget_parent(dentry);
6464 + inode = dentry->d_inode;
6465 + AuDebugOn(inode && S_ISDIR(dentry->d_inode->i_mode));
6466 + AuDebugOn(au_digen_test(parent, sigen));
6470 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
6473 + struct au_dcsub_pages dpages;
6474 + struct au_dpage *dpage;
6475 + struct dentry **dentries;
6477 + err = au_dpages_init(&dpages, GFP_NOFS);
6479 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
6481 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
6482 + dpage = dpages.dpages + i;
6483 + dentries = dpage->dentries;
6484 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
6485 + AuDebugOn(au_digen_test(dentries[j], sigen));
6487 + au_dpages_free(&dpages);
6490 +void au_dbg_verify_kthread(void)
6492 + if (au_wkq_test()) {
6495 + * It may be recursive, but udba=notify between two aufs mounts,
6496 + * where a single ro branch is shared, is not a problem.
6502 +/* ---------------------------------------------------------------------- */
6504 +void au_debug_sbinfo_init(struct au_sbinfo *sbinfo __maybe_unused)
6506 +#ifdef AuForceNoPlink
6507 + au_opt_clr(sbinfo->si_mntflags, PLINK);
6509 +#ifdef AuForceNoXino
6510 + au_opt_clr(sbinfo->si_mntflags, XINO);
6512 +#ifdef AuForceNoRefrof
6513 + au_opt_clr(sbinfo->si_mntflags, REFROF);
6515 +#ifdef AuForceHnotify
6516 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_HNOTIFY);
6519 + sbinfo->si_rdblk = 0;
6520 + sbinfo->si_rdhash = 0;
6524 +int __init au_debug_init(void)
6526 + aufs_bindex_t bindex;
6527 + struct au_vdir_destr destr;
6530 + AuDebugOn(bindex >= 0);
6533 + AuDebugOn(destr.len < NAME_MAX);
6535 +#ifdef CONFIG_4KSTACKS
6536 + pr_warn("CONFIG_4KSTACKS is defined.\n");
6539 +#ifdef AuForceNoBrs
6545 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
6546 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
6547 +++ linux/fs/aufs/debug.h 2014-04-24 22:11:10.848602379 +0200
6550 + * Copyright (C) 2005-2014 Junjiro R. Okajima
6552 + * This program, aufs is free software; you can redistribute it and/or modify
6553 + * it under the terms of the GNU General Public License as published by
6554 + * the Free Software Foundation; either version 2 of the License, or
6555 + * (at your option) any later version.
6557 + * This program is distributed in the hope that it will be useful,
6558 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6559 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6560 + * GNU General Public License for more details.
6562 + * You should have received a copy of the GNU General Public License
6563 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6567 + * debug print functions
6570 +#ifndef __AUFS_DEBUG_H__
6571 +#define __AUFS_DEBUG_H__
6575 +#include <linux/atomic.h>
6576 +#include <linux/module.h>
6577 +#include <linux/kallsyms.h>
6578 +#include <linux/sysrq.h>
6580 +#ifdef CONFIG_AUFS_DEBUG
6581 +#define AuDebugOn(a) BUG_ON(a)
6583 +/* module parameter */
6584 +extern atomic_t aufs_debug;
6585 +static inline void au_debug_on(void)
6587 + atomic_inc(&aufs_debug);
6589 +static inline void au_debug_off(void)
6591 + atomic_dec_if_positive(&aufs_debug);
6594 +static inline int au_debug_test(void)
6596 + return atomic_read(&aufs_debug) > 0;
6599 +#define AuDebugOn(a) do {} while (0)
6600 +AuStubVoid(au_debug_on, void)
6601 +AuStubVoid(au_debug_off, void)
6602 +AuStubInt0(au_debug_test, void)
6603 +#endif /* CONFIG_AUFS_DEBUG */
6605 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
6607 +/* ---------------------------------------------------------------------- */
6611 +#define AuDbg(fmt, ...) do { \
6612 + if (au_debug_test()) \
6613 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
6615 +#define AuLabel(l) AuDbg(#l "\n")
6616 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
6617 +#define AuWarn1(fmt, ...) do { \
6618 + static unsigned char _c; \
6620 + pr_warn(fmt, ##__VA_ARGS__); \
6623 +#define AuErr1(fmt, ...) do { \
6624 + static unsigned char _c; \
6626 + pr_err(fmt, ##__VA_ARGS__); \
6629 +#define AuIOErr1(fmt, ...) do { \
6630 + static unsigned char _c; \
6632 + AuIOErr(fmt, ##__VA_ARGS__); \
6635 +#define AuUnsupportMsg "This operation is not supported." \
6636 + " Please report this application to aufs-users ML."
6637 +#define AuUnsupport(fmt, ...) do { \
6638 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
6642 +#define AuTraceErr(e) do { \
6643 + if (unlikely((e) < 0)) \
6644 + AuDbg("err %d\n", (int)(e)); \
6647 +#define AuTraceErrPtr(p) do { \
6649 + AuDbg("err %ld\n", PTR_ERR(p)); \
6652 +/* dirty macros for debug print, use with "%.*s" and caution */
6653 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
6655 +/* ---------------------------------------------------------------------- */
6660 +#ifdef CONFIG_AUFS_DEBUG
6661 +extern char *au_plevel;
6663 +void au_dpri_whlist(struct au_nhash *whlist);
6665 +void au_dpri_vdir(struct au_vdir *vdir);
6667 +void au_dpri_inode(struct inode *inode);
6668 +void au_dpri_dalias(struct inode *inode);
6669 +void au_dpri_dentry(struct dentry *dentry);
6671 +void au_dpri_file(struct file *filp);
6672 +struct super_block;
6673 +void au_dpri_sb(struct super_block *sb);
6675 +void au_dbg_sleep_jiffy(int jiffy);
6677 +void au_dbg_iattr(struct iattr *ia);
6679 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
6680 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
6681 +void au_dbg_verify_dir_parent(struct dentry *dentry, unsigned int sigen);
6682 +void au_dbg_verify_nondir_parent(struct dentry *dentry, unsigned int sigen);
6683 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
6684 +void au_dbg_verify_kthread(void);
6686 +int __init au_debug_init(void);
6687 +void au_debug_sbinfo_init(struct au_sbinfo *sbinfo);
6688 +#define AuDbgWhlist(w) do { \
6690 + au_dpri_whlist(w); \
6693 +#define AuDbgVdir(v) do { \
6695 + au_dpri_vdir(v); \
6698 +#define AuDbgInode(i) do { \
6700 + au_dpri_inode(i); \
6703 +#define AuDbgDAlias(i) do { \
6705 + au_dpri_dalias(i); \
6708 +#define AuDbgDentry(d) do { \
6710 + au_dpri_dentry(d); \
6713 +#define AuDbgFile(f) do { \
6715 + au_dpri_file(f); \
6718 +#define AuDbgSb(sb) do { \
6719 + AuDbg(#sb "\n"); \
6723 +#define AuDbgSleep(sec) do { \
6724 + AuDbg("sleep %d sec\n", sec); \
6728 +#define AuDbgSleepJiffy(jiffy) do { \
6729 + AuDbg("sleep %d jiffies\n", jiffy); \
6730 + au_dbg_sleep_jiffy(jiffy); \
6733 +#define AuDbgIAttr(ia) do { \
6734 + AuDbg("ia_valid 0x%x\n", (ia)->ia_valid); \
6735 + au_dbg_iattr(ia); \
6738 +#define AuDbgSym(addr) do { \
6739 + char sym[KSYM_SYMBOL_LEN]; \
6740 + sprint_symbol(sym, (unsigned long)addr); \
6741 + AuDbg("%s\n", sym); \
6744 +#define AuInfoSym(addr) do { \
6745 + char sym[KSYM_SYMBOL_LEN]; \
6746 + sprint_symbol(sym, (unsigned long)addr); \
6747 + AuInfo("%s\n", sym); \
6750 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
6751 +AuStubVoid(au_dbg_verify_dir_parent, struct dentry *dentry, unsigned int sigen)
6752 +AuStubVoid(au_dbg_verify_nondir_parent, struct dentry *dentry,
6753 + unsigned int sigen)
6754 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
6755 +AuStubVoid(au_dbg_verify_kthread, void)
6756 +AuStubInt0(__init au_debug_init, void)
6757 +AuStubVoid(au_debug_sbinfo_init, struct au_sbinfo *sbinfo)
6759 +#define AuDbgWhlist(w) do {} while (0)
6760 +#define AuDbgVdir(v) do {} while (0)
6761 +#define AuDbgInode(i) do {} while (0)
6762 +#define AuDbgDAlias(i) do {} while (0)
6763 +#define AuDbgDentry(d) do {} while (0)
6764 +#define AuDbgFile(f) do {} while (0)
6765 +#define AuDbgSb(sb) do {} while (0)
6766 +#define AuDbgSleep(sec) do {} while (0)
6767 +#define AuDbgSleepJiffy(jiffy) do {} while (0)
6768 +#define AuDbgIAttr(ia) do {} while (0)
6769 +#define AuDbgSym(addr) do {} while (0)
6770 +#define AuInfoSym(addr) do {} while (0)
6771 +#endif /* CONFIG_AUFS_DEBUG */
6773 +/* ---------------------------------------------------------------------- */
6775 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
6776 +int __init au_sysrq_init(void);
6777 +void au_sysrq_fin(void);
6779 +#ifdef CONFIG_HW_CONSOLE
6780 +#define au_dbg_blocked() do { \
6782 + handle_sysrq('w'); \
6785 +AuStubVoid(au_dbg_blocked, void)
6789 +AuStubInt0(__init au_sysrq_init, void)
6790 +AuStubVoid(au_sysrq_fin, void)
6791 +AuStubVoid(au_dbg_blocked, void)
6792 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
6794 +#endif /* __KERNEL__ */
6795 +#endif /* __AUFS_DEBUG_H__ */
6796 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
6797 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
6798 +++ linux/fs/aufs/dentry.c 2014-04-24 22:11:10.848602379 +0200
6801 + * Copyright (C) 2005-2014 Junjiro R. Okajima
6803 + * This program, aufs is free software; you can redistribute it and/or modify
6804 + * it under the terms of the GNU General Public License as published by
6805 + * the Free Software Foundation; either version 2 of the License, or
6806 + * (at your option) any later version.
6808 + * This program is distributed in the hope that it will be useful,
6809 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6810 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6811 + * GNU General Public License for more details.
6813 + * You should have received a copy of the GNU General Public License
6814 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6818 + * lookup and dentry operations
6821 +#include <linux/namei.h>
6824 +#define AuLkup_ALLOW_NEG 1
6825 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
6826 +#define au_fset_lkup(flags, name) \
6827 + do { (flags) |= AuLkup_##name; } while (0)
6828 +#define au_fclr_lkup(flags, name) \
6829 + do { (flags) &= ~AuLkup_##name; } while (0)
6831 +struct au_do_lookup_args {
6832 + unsigned int flags;
6837 + * returns positive/negative dentry, NULL or an error.
6838 + * NULL means whiteout-ed or not-found.
6840 +static struct dentry*
6841 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
6842 + aufs_bindex_t bindex, struct qstr *wh_name,
6843 + struct au_do_lookup_args *args)
6845 + struct dentry *h_dentry;
6846 + struct inode *h_inode, *inode;
6847 + struct au_branch *br;
6848 + int wh_found, opq;
6849 + unsigned char wh_able;
6850 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
6853 + br = au_sbr(dentry->d_sb, bindex);
6854 + wh_able = !!au_br_whable(br->br_perm);
6856 + wh_found = au_wh_test(h_parent, wh_name, br, /*try_sio*/0);
6857 + h_dentry = ERR_PTR(wh_found);
6860 + if (unlikely(wh_found < 0))
6863 + /* We found a whiteout */
6864 + /* au_set_dbend(dentry, bindex); */
6865 + au_set_dbwh(dentry, bindex);
6867 + return NULL; /* success */
6870 + h_dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
6871 + if (IS_ERR(h_dentry))
6874 + h_inode = h_dentry->d_inode;
6878 + } else if (wh_found
6879 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
6882 + if (au_dbend(dentry) <= bindex)
6883 + au_set_dbend(dentry, bindex);
6884 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
6885 + au_set_dbstart(dentry, bindex);
6886 + au_set_h_dptr(dentry, bindex, h_dentry);
6888 + inode = dentry->d_inode;
6889 + if (!h_inode || !S_ISDIR(h_inode->i_mode) || !wh_able
6890 + || (inode && !S_ISDIR(inode->i_mode)))
6891 + goto out; /* success */
6893 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
6894 + opq = au_diropq_test(h_dentry, br);
6895 + mutex_unlock(&h_inode->i_mutex);
6897 + au_set_dbdiropq(dentry, bindex);
6898 + else if (unlikely(opq < 0)) {
6899 + au_set_h_dptr(dentry, bindex, NULL);
6900 + h_dentry = ERR_PTR(opq);
6911 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
6913 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
6914 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
6920 + * returns the number of lower positive dentries,
6921 + * otherwise an error.
6922 + * can be called at unlinking with @type is zero.
6924 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type)
6926 + int npositive, err;
6927 + aufs_bindex_t bindex, btail, bdiropq;
6928 + unsigned char isdir;
6929 + struct qstr whname;
6930 + struct au_do_lookup_args args = {
6934 + const struct qstr *name = &dentry->d_name;
6935 + struct dentry *parent;
6936 + struct inode *inode;
6938 + err = au_test_shwh(dentry->d_sb, name);
6939 + if (unlikely(err))
6942 + err = au_wh_name_alloc(&whname, name);
6943 + if (unlikely(err))
6946 + inode = dentry->d_inode;
6947 + isdir = !!(inode && S_ISDIR(inode->i_mode));
6949 + au_fset_lkup(args.flags, ALLOW_NEG);
6952 + parent = dget_parent(dentry);
6953 + btail = au_dbtaildir(parent);
6954 + for (bindex = bstart; bindex <= btail; bindex++) {
6955 + struct dentry *h_parent, *h_dentry;
6956 + struct inode *h_inode, *h_dir;
6958 + h_dentry = au_h_dptr(dentry, bindex);
6960 + if (h_dentry->d_inode)
6962 + if (type != S_IFDIR)
6966 + h_parent = au_h_dptr(parent, bindex);
6969 + h_dir = h_parent->d_inode;
6970 + if (!h_dir || !S_ISDIR(h_dir->i_mode))
6973 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
6974 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname,
6976 + mutex_unlock(&h_dir->i_mutex);
6977 + err = PTR_ERR(h_dentry);
6978 + if (IS_ERR(h_dentry))
6980 + au_fclr_lkup(args.flags, ALLOW_NEG);
6982 + if (au_dbwh(dentry) >= 0)
6986 + h_inode = h_dentry->d_inode;
6991 + args.type = h_inode->i_mode & S_IFMT;
6992 + if (args.type != S_IFDIR)
6995 + /* the type of lower may be different */
6996 + bdiropq = au_dbdiropq(dentry);
6997 + if (bdiropq >= 0 && bdiropq <= bindex)
7003 + AuLabel(positive);
7004 + au_update_dbstart(dentry);
7007 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
7008 + && au_dbstart(dentry) < 0)) {
7010 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
7016 + kfree(whname.name);
7021 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent,
7022 + struct au_branch *br)
7024 + struct dentry *dentry;
7027 + if (!au_test_h_perm_sio(parent->d_inode, MAY_EXEC))
7028 + dentry = vfsub_lkup_one(name, parent);
7030 + struct vfsub_lkup_one_args args = {
7036 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
7037 + if (unlikely(wkq_err))
7038 + dentry = ERR_PTR(wkq_err);
7045 + * lookup @dentry on @bindex which should be negative.
7047 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
7050 + struct dentry *parent, *h_parent, *h_dentry;
7051 + struct au_branch *br;
7053 + parent = dget_parent(dentry);
7054 + h_parent = au_h_dptr(parent, bindex);
7055 + br = au_sbr(dentry->d_sb, bindex);
7057 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
7059 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent, br);
7060 + err = PTR_ERR(h_dentry);
7061 + if (IS_ERR(h_dentry))
7063 + if (unlikely(h_dentry->d_inode)) {
7065 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
7071 + if (bindex < au_dbstart(dentry))
7072 + au_set_dbstart(dentry, bindex);
7073 + if (au_dbend(dentry) < bindex)
7074 + au_set_dbend(dentry, bindex);
7075 + au_set_h_dptr(dentry, bindex, h_dentry);
7082 +/* ---------------------------------------------------------------------- */
7084 +/* subset of struct inode */
7086 + unsigned long i_ino;
7087 + /* unsigned int i_nlink; */
7093 + blkcnt_t i_blocks;
7098 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
7100 + ia->i_ino = h_inode->i_ino;
7101 + /* ia->i_nlink = h_inode->i_nlink; */
7102 + ia->i_uid = h_inode->i_uid;
7103 + ia->i_gid = h_inode->i_gid;
7104 + ia->i_version = h_inode->i_version;
7106 + ia->i_size = h_inode->i_size;
7107 + ia->i_blocks = h_inode->i_blocks;
7109 + ia->i_mode = (h_inode->i_mode & S_IFMT);
7112 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
7114 + return ia->i_ino != h_inode->i_ino
7115 + /* || ia->i_nlink != h_inode->i_nlink */
7116 + || !uid_eq(ia->i_uid, h_inode->i_uid)
7117 + || !gid_eq(ia->i_gid, h_inode->i_gid)
7118 + || ia->i_version != h_inode->i_version
7120 + || ia->i_size != h_inode->i_size
7121 + || ia->i_blocks != h_inode->i_blocks
7123 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
7126 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
7127 + struct au_branch *br)
7130 + struct au_iattr ia;
7131 + struct inode *h_inode;
7132 + struct dentry *h_d;
7133 + struct super_block *h_sb;
7136 + memset(&ia, -1, sizeof(ia));
7137 + h_sb = h_dentry->d_sb;
7138 + h_inode = h_dentry->d_inode;
7140 + au_iattr_save(&ia, h_inode);
7141 + else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
7142 + /* nfs d_revalidate may return 0 for negative dentry */
7143 + /* fuse d_revalidate always return 0 for negative dentry */
7146 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
7147 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
7148 + err = PTR_ERR(h_d);
7153 + if (unlikely(h_d != h_dentry
7154 + || h_d->d_inode != h_inode
7155 + || (h_inode && au_iattr_test(&ia, h_inode))))
7156 + err = au_busy_or_stale();
7164 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
7165 + struct dentry *h_parent, struct au_branch *br)
7170 + if (udba == AuOpt_UDBA_REVAL
7171 + && !au_test_fs_remote(h_dentry->d_sb)) {
7173 + err = (h_dentry->d_parent->d_inode != h_dir);
7174 + } else if (udba != AuOpt_UDBA_NONE)
7175 + err = au_h_verify_dentry(h_dentry, h_parent, br);
7180 +/* ---------------------------------------------------------------------- */
7182 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
7185 + aufs_bindex_t new_bindex, bindex, bend, bwh, bdiropq;
7186 + struct au_hdentry tmp, *p, *q;
7187 + struct au_dinfo *dinfo;
7188 + struct super_block *sb;
7190 + DiMustWriteLock(dentry);
7192 + sb = dentry->d_sb;
7193 + dinfo = au_di(dentry);
7194 + bend = dinfo->di_bend;
7195 + bwh = dinfo->di_bwh;
7196 + bdiropq = dinfo->di_bdiropq;
7197 + p = dinfo->di_hdentry + dinfo->di_bstart;
7198 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++, p++) {
7199 + if (!p->hd_dentry)
7202 + new_bindex = au_br_index(sb, p->hd_id);
7203 + if (new_bindex == bindex)
7206 + if (dinfo->di_bwh == bindex)
7208 + if (dinfo->di_bdiropq == bindex)
7209 + bdiropq = new_bindex;
7210 + if (new_bindex < 0) {
7212 + p->hd_dentry = NULL;
7216 + /* swap two lower dentries, and loop again */
7217 + q = dinfo->di_hdentry + new_bindex;
7221 + if (tmp.hd_dentry) {
7227 + dinfo->di_bwh = -1;
7228 + if (bwh >= 0 && bwh <= au_sbend(sb) && au_sbr_whable(sb, bwh))
7229 + dinfo->di_bwh = bwh;
7231 + dinfo->di_bdiropq = -1;
7233 + && bdiropq <= au_sbend(sb)
7234 + && au_sbr_whable(sb, bdiropq))
7235 + dinfo->di_bdiropq = bdiropq;
7238 + dinfo->di_bstart = -1;
7239 + dinfo->di_bend = -1;
7240 + bend = au_dbend(parent);
7241 + p = dinfo->di_hdentry;
7242 + for (bindex = 0; bindex <= bend; bindex++, p++)
7243 + if (p->hd_dentry) {
7244 + dinfo->di_bstart = bindex;
7248 + if (dinfo->di_bstart >= 0) {
7249 + p = dinfo->di_hdentry + bend;
7250 + for (bindex = bend; bindex >= 0; bindex--, p--)
7251 + if (p->hd_dentry) {
7252 + dinfo->di_bend = bindex;
7261 +static void au_do_hide(struct dentry *dentry)
7263 + struct inode *inode;
7265 + inode = dentry->d_inode;
7267 + if (!S_ISDIR(inode->i_mode)) {
7268 + if (inode->i_nlink && !d_unhashed(dentry))
7269 + drop_nlink(inode);
7271 + clear_nlink(inode);
7272 + /* stop next lookup */
7273 + inode->i_flags |= S_DEAD;
7275 + smp_mb(); /* necessary? */
7280 +static int au_hide_children(struct dentry *parent)
7282 + int err, i, j, ndentry;
7283 + struct au_dcsub_pages dpages;
7284 + struct au_dpage *dpage;
7285 + struct dentry *dentry;
7287 + err = au_dpages_init(&dpages, GFP_NOFS);
7288 + if (unlikely(err))
7290 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
7291 + if (unlikely(err))
7294 + /* in reverse order */
7295 + for (i = dpages.ndpage - 1; i >= 0; i--) {
7296 + dpage = dpages.dpages + i;
7297 + ndentry = dpage->ndentry;
7298 + for (j = ndentry - 1; j >= 0; j--) {
7299 + dentry = dpage->dentries[j];
7300 + if (dentry != parent)
7301 + au_do_hide(dentry);
7306 + au_dpages_free(&dpages);
7311 +static void au_hide(struct dentry *dentry)
7314 + struct inode *inode;
7316 + AuDbgDentry(dentry);
7317 + inode = dentry->d_inode;
7318 + if (inode && S_ISDIR(inode->i_mode)) {
7319 + /* shrink_dcache_parent(dentry); */
7320 + err = au_hide_children(dentry);
7321 + if (unlikely(err))
7322 + AuIOErr("%pd, failed hiding children, ignored %d\n",
7325 + au_do_hide(dentry);
7329 + * By adding a dirty branch, a cached dentry may be affected in various ways.
7331 + * a dirty branch is added
7332 + * - on the top of layers
7333 + * - in the middle of layers
7334 + * - to the bottom of layers
7336 + * on the added branch there exists
7339 + * - a same named entry
7341 + * * negative --> positive
7342 + * * positive --> positive
7343 + * - type is unchanged
7344 + * - type is changed
7346 + * * negative --> negative
7347 + * * positive --> negative (rejected by au_br_del() for non-dir case)
7350 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
7351 + struct au_dinfo *tmp)
7354 + aufs_bindex_t bindex, bend;
7356 + struct dentry *dentry;
7357 + struct inode *inode;
7360 + struct au_hdentry *hd;
7361 + struct inode *inode, *h_inode;
7362 + struct dentry *h_dentry;
7365 + AuDebugOn(dinfo->di_bstart < 0);
7366 + orig_h.dentry = dinfo->di_hdentry[dinfo->di_bstart].hd_dentry;
7367 + orig_h.inode = orig_h.dentry->d_inode;
7370 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
7371 + memset(&tmp_h, 0, sizeof(tmp_h));
7372 + if (tmp->di_bstart >= 0) {
7373 + tmp_h.dentry = tmp->di_hdentry[tmp->di_bstart].hd_dentry;
7374 + tmp_h.inode = tmp_h.dentry->d_inode;
7376 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
7379 + inode = dentry->d_inode;
7380 + if (!orig_h.inode) {
7381 + AuDbg("nagative originally\n");
7387 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
7388 + AuDebugOn(dinfo->di_bdiropq != -1);
7390 + if (!tmp_h.inode) {
7391 + AuDbg("negative --> negative\n");
7392 + /* should have only one negative lower */
7393 + if (tmp->di_bstart >= 0
7394 + && tmp->di_bstart < dinfo->di_bstart) {
7395 + AuDebugOn(tmp->di_bstart != tmp->di_bend);
7396 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
7397 + au_set_h_dptr(dentry, dinfo->di_bstart, NULL);
7398 + au_di_cp(dinfo, tmp);
7399 + hd = tmp->di_hdentry + tmp->di_bstart;
7400 + au_set_h_dptr(dentry, tmp->di_bstart,
7401 + dget(hd->hd_dentry));
7403 + au_dbg_verify_dinode(dentry);
7405 + AuDbg("negative --> positive\n");
7407 + * similar to the behaviour of creating with bypassing
7409 + * unhash it in order to force an error in the
7410 + * succeeding create operation.
7411 + * we should not set S_DEAD here.
7414 + /* au_di_swap(tmp, dinfo); */
7415 + au_dbg_verify_dinode(dentry);
7418 + AuDbg("positive originally\n");
7419 + /* inode may be NULL */
7420 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
7421 + if (!tmp_h.inode) {
7422 + AuDbg("positive --> negative\n");
7423 + /* or bypassing aufs */
7425 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_bstart)
7426 + dinfo->di_bwh = tmp->di_bwh;
7428 + err = au_refresh_hinode_self(inode);
7429 + au_dbg_verify_dinode(dentry);
7430 + } else if (orig_h.mode == tmp_h.mode) {
7431 + AuDbg("positive --> positive, same type\n");
7432 + if (!S_ISDIR(orig_h.mode)
7433 + && dinfo->di_bstart > tmp->di_bstart) {
7435 + * similar to the behaviour of removing and
7440 + err = au_refresh_hinode_self(inode);
7441 + au_dbg_verify_dinode(dentry);
7443 + /* fill empty slots */
7444 + if (dinfo->di_bstart > tmp->di_bstart)
7445 + dinfo->di_bstart = tmp->di_bstart;
7446 + if (dinfo->di_bend < tmp->di_bend)
7447 + dinfo->di_bend = tmp->di_bend;
7448 + dinfo->di_bwh = tmp->di_bwh;
7449 + dinfo->di_bdiropq = tmp->di_bdiropq;
7450 + hd = tmp->di_hdentry;
7451 + bend = dinfo->di_bend;
7452 + for (bindex = tmp->di_bstart; bindex <= bend;
7454 + if (au_h_dptr(dentry, bindex))
7456 + h_dentry = hd[bindex].hd_dentry;
7459 + h_inode = h_dentry->d_inode;
7460 + AuDebugOn(!h_inode);
7461 + AuDebugOn(orig_h.mode
7462 + != (h_inode->i_mode
7464 + au_set_h_dptr(dentry, bindex,
7467 + err = au_refresh_hinode(inode, dentry);
7468 + au_dbg_verify_dinode(dentry);
7471 + AuDbg("positive --> positive, different type\n");
7472 + /* similar to the behaviour of removing and creating */
7475 + err = au_refresh_hinode_self(inode);
7476 + au_dbg_verify_dinode(dentry);
7484 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
7487 + unsigned int sigen;
7488 + struct au_dinfo *dinfo, *tmp;
7489 + struct super_block *sb;
7490 + struct inode *inode;
7492 + DiMustWriteLock(dentry);
7493 + AuDebugOn(IS_ROOT(dentry));
7494 + AuDebugOn(!parent->d_inode);
7496 + sb = dentry->d_sb;
7497 + inode = dentry->d_inode;
7498 + sigen = au_sigen(sb);
7499 + err = au_digen_test(parent, sigen);
7500 + if (unlikely(err))
7503 + dinfo = au_di(dentry);
7504 + err = au_di_realloc(dinfo, au_sbend(sb) + 1);
7505 + if (unlikely(err))
7507 + ebrange = au_dbrange_test(dentry);
7509 + ebrange = au_do_refresh_hdentry(dentry, parent);
7511 + if (d_unhashed(dentry) || ebrange) {
7512 + AuDebugOn(au_dbstart(dentry) < 0 && au_dbend(dentry) >= 0);
7514 + err = au_refresh_hinode_self(inode);
7515 + au_dbg_verify_dinode(dentry);
7517 + goto out_dgen; /* success */
7521 + /* temporary dinfo */
7522 + AuDbgDentry(dentry);
7524 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
7525 + if (unlikely(!tmp))
7527 + au_di_swap(tmp, dinfo);
7528 + /* returns the number of positive dentries */
7530 + * if current working dir is removed, it returns an error.
7531 + * but the dentry is legal.
7533 + err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0);
7534 + AuDbgDentry(dentry);
7535 + au_di_swap(tmp, dinfo);
7536 + if (err == -ENOENT)
7539 + /* compare/refresh by dinfo */
7540 + AuDbgDentry(dentry);
7541 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
7542 + au_dbg_verify_dinode(dentry);
7545 + au_rw_write_unlock(&tmp->di_rwsem);
7547 + if (unlikely(err))
7551 + au_update_digen(dentry);
7553 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
7554 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
7555 + AuDbgDentry(dentry);
7561 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
7562 + struct dentry *dentry, aufs_bindex_t bindex)
7567 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
7570 + AuDbg("b%d\n", bindex);
7572 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
7573 + * due to whiteout and branch permission.
7575 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
7576 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
7577 + /* it may return tri-state */
7578 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
7580 + if (unlikely(valid < 0))
7590 +/* todo: remove this */
7591 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
7592 + unsigned int flags, int do_udba)
7595 + umode_t mode, h_mode;
7596 + aufs_bindex_t bindex, btail, bstart, ibs, ibe;
7597 + unsigned char plus, unhashed, is_root, h_plus, h_nfs;
7598 + struct inode *h_inode, *h_cached_inode;
7599 + struct dentry *h_dentry;
7600 + struct qstr *name, *h_name;
7607 + unhashed = !!d_unhashed(dentry);
7608 + is_root = !!IS_ROOT(dentry);
7609 + name = &dentry->d_name;
7612 + * Theoretically, REVAL test should be unnecessary in case of
7614 + * But {fs,i}notify doesn't fire some necessary events,
7615 + * IN_ATTRIB for atime/nlink/pageio
7616 + * IN_DELETE for NFS dentry
7617 + * Let's do REVAL test too.
7619 + if (do_udba && inode) {
7620 + mode = (inode->i_mode & S_IFMT);
7621 + plus = (inode->i_nlink > 0);
7622 + ibs = au_ibstart(inode);
7623 + ibe = au_ibend(inode);
7626 + bstart = au_dbstart(dentry);
7628 + if (inode && S_ISDIR(inode->i_mode))
7629 + btail = au_dbtaildir(dentry);
7630 + for (bindex = bstart; bindex <= btail; bindex++) {
7631 + h_dentry = au_h_dptr(dentry, bindex);
7635 + AuDbg("b%d, %pd\n", bindex, h_dentry);
7636 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
7637 + spin_lock(&h_dentry->d_lock);
7638 + h_name = &h_dentry->d_name;
7639 + if (unlikely(do_udba
7642 + && (unhashed != !!d_unhashed(h_dentry)
7643 + || name->len != h_name->len
7644 + || memcmp(name->name, h_name->name,
7647 + && !(flags & LOOKUP_OPEN)
7648 + && (h_dentry->d_flags
7649 + & DCACHE_NFSFS_RENAMED)))
7651 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
7652 + unhashed, d_unhashed(h_dentry),
7653 + dentry, h_dentry);
7654 + spin_unlock(&h_dentry->d_lock);
7657 + spin_unlock(&h_dentry->d_lock);
7659 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
7660 + if (unlikely(err))
7661 + /* do not goto err, to keep the errno */
7664 + /* todo: plink too? */
7669 + h_inode = h_dentry->d_inode;
7670 + if (unlikely(!!inode != !!h_inode))
7675 + h_cached_inode = h_inode;
7677 + h_mode = (h_inode->i_mode & S_IFMT);
7678 + h_plus = (h_inode->i_nlink > 0);
7680 + if (inode && ibs <= bindex && bindex <= ibe)
7681 + h_cached_inode = au_h_iptr(inode, bindex);
7684 + if (unlikely(plus != h_plus))
7687 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
7689 + && !IS_ROOT(h_dentry)
7690 + && unhashed != d_unhashed(h_dentry)))
7693 + if (unlikely(mode != h_mode
7694 + || h_cached_inode != h_inode))
7707 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
7708 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
7711 + struct dentry *parent;
7713 + if (!au_digen_test(dentry, sigen))
7716 + parent = dget_parent(dentry);
7717 + di_read_lock_parent(parent, AuLock_IR);
7718 + AuDebugOn(au_digen_test(parent, sigen));
7719 + au_dbg_verify_gen(parent, sigen);
7720 + err = au_refresh_dentry(dentry, parent);
7721 + di_read_unlock(parent, AuLock_IR);
7727 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
7730 + struct dentry *d, *parent;
7731 + struct inode *inode;
7733 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
7734 + return simple_reval_dpath(dentry, sigen);
7736 + /* slow loop, keep it simple and stupid */
7737 + /* cf: au_cpup_dirs() */
7740 + while (au_digen_test(dentry, sigen)) {
7744 + parent = dget_parent(d);
7745 + if (!au_digen_test(parent, sigen))
7750 + inode = d->d_inode;
7752 + di_write_lock_child2(d);
7754 + /* someone might update our dentry while we were sleeping */
7755 + if (au_digen_test(d, sigen)) {
7757 + * todo: consolidate with simple_reval_dpath(),
7758 + * do_refresh() and au_reval_for_attr().
7760 + di_read_lock_parent(parent, AuLock_IR);
7761 + err = au_refresh_dentry(d, parent);
7762 + di_read_unlock(parent, AuLock_IR);
7766 + di_write_unlock(d);
7768 + if (unlikely(err))
7776 + * if valid returns 1, otherwise 0.
7778 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
7781 + unsigned int sigen;
7782 + unsigned char do_udba;
7783 + struct super_block *sb;
7784 + struct inode *inode;
7786 + /* todo: support rcu-walk? */
7787 + if (flags & LOOKUP_RCU)
7791 + if (unlikely(!au_di(dentry)))
7794 + inode = dentry->d_inode;
7795 + if (inode && is_bad_inode(inode))
7799 + sb = dentry->d_sb;
7802 + * i_mutex of parent dir may be held,
7803 + * but we should not return 'invalid' due to busy.
7805 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
7806 + if (unlikely(err)) {
7811 + if (unlikely(au_dbrange_test(dentry))) {
7817 + sigen = au_sigen(sb);
7818 + if (au_digen_test(dentry, sigen)) {
7819 + AuDebugOn(IS_ROOT(dentry));
7820 + err = au_reval_dpath(dentry, sigen);
7821 + if (unlikely(err)) {
7826 + di_downgrade_lock(dentry, AuLock_IR);
7829 + if (!(flags & LOOKUP_OPEN)
7831 + && (IS_DEADDIR(inode) || !inode->i_nlink))
7834 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
7835 + if (do_udba && inode) {
7836 + aufs_bindex_t bstart = au_ibstart(inode);
7837 + struct inode *h_inode;
7839 + if (bstart >= 0) {
7840 + h_inode = au_h_iptr(inode, bstart);
7841 + if (h_inode && au_test_higen(inode, h_inode))
7846 + err = h_d_revalidate(dentry, inode, flags, do_udba);
7847 + if (unlikely(!err && do_udba && au_dbstart(dentry) < 0)) {
7849 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
7855 + di_downgrade_lock(dentry, AuLock_IR);
7857 + aufs_read_unlock(dentry, AuLock_IR);
7862 + AuDbg("%pd invalid, %d\n", dentry, valid);
7868 +static void aufs_d_release(struct dentry *dentry)
7870 + if (au_di(dentry)) {
7871 + au_di_fin(dentry);
7872 + au_hn_di_reinit(dentry);
7876 +const struct dentry_operations aufs_dop = {
7877 + .d_revalidate = aufs_d_revalidate,
7878 + .d_weak_revalidate = aufs_d_revalidate,
7879 + .d_release = aufs_d_release
7881 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
7882 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
7883 +++ linux/fs/aufs/dentry.h 2014-04-24 22:11:10.848602379 +0200
7886 + * Copyright (C) 2005-2014 Junjiro R. Okajima
7888 + * This program, aufs is free software; you can redistribute it and/or modify
7889 + * it under the terms of the GNU General Public License as published by
7890 + * the Free Software Foundation; either version 2 of the License, or
7891 + * (at your option) any later version.
7893 + * This program is distributed in the hope that it will be useful,
7894 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7895 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7896 + * GNU General Public License for more details.
7898 + * You should have received a copy of the GNU General Public License
7899 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7903 + * lookup and dentry operations
7906 +#ifndef __AUFS_DENTRY_H__
7907 +#define __AUFS_DENTRY_H__
7911 +#include <linux/dcache.h>
7914 +struct au_hdentry {
7915 + struct dentry *hd_dentry;
7916 + aufs_bindex_t hd_id;
7920 + atomic_t di_generation;
7922 + struct au_rwsem di_rwsem;
7923 + aufs_bindex_t di_bstart, di_bend, di_bwh, di_bdiropq;
7924 + struct au_hdentry *di_hdentry;
7925 +} ____cacheline_aligned_in_smp;
7927 +/* ---------------------------------------------------------------------- */
7930 +extern const struct dentry_operations aufs_dop;
7932 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent,
7933 + struct au_branch *br);
7934 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
7935 + struct dentry *h_parent, struct au_branch *br);
7937 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type);
7938 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
7939 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
7940 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
7943 +void au_di_init_once(void *_di);
7944 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
7945 +void au_di_free(struct au_dinfo *dinfo);
7946 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
7947 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
7948 +int au_di_init(struct dentry *dentry);
7949 +void au_di_fin(struct dentry *dentry);
7950 +int au_di_realloc(struct au_dinfo *dinfo, int nbr);
7952 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
7953 +void di_read_unlock(struct dentry *d, int flags);
7954 +void di_downgrade_lock(struct dentry *d, int flags);
7955 +void di_write_lock(struct dentry *d, unsigned int lsc);
7956 +void di_write_unlock(struct dentry *d);
7957 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
7958 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
7959 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
7961 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
7962 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
7963 +aufs_bindex_t au_dbtail(struct dentry *dentry);
7964 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
7966 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
7967 + struct dentry *h_dentry);
7968 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
7969 +int au_dbrange_test(struct dentry *dentry);
7970 +void au_update_digen(struct dentry *dentry);
7971 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
7972 +void au_update_dbstart(struct dentry *dentry);
7973 +void au_update_dbend(struct dentry *dentry);
7974 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
7976 +/* ---------------------------------------------------------------------- */
7978 +static inline struct au_dinfo *au_di(struct dentry *dentry)
7980 + return dentry->d_fsdata;
7983 +/* ---------------------------------------------------------------------- */
7985 +/* lock subclass for dinfo */
7987 + AuLsc_DI_CHILD, /* child first */
7988 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
7989 + AuLsc_DI_CHILD3, /* copyup dirs */
7993 + AuLsc_DI_TMP /* temp for replacing dinfo */
7997 + * di_read_lock_child, di_write_lock_child,
7998 + * di_read_lock_child2, di_write_lock_child2,
7999 + * di_read_lock_child3, di_write_lock_child3,
8000 + * di_read_lock_parent, di_write_lock_parent,
8001 + * di_read_lock_parent2, di_write_lock_parent2,
8002 + * di_read_lock_parent3, di_write_lock_parent3,
8004 +#define AuReadLockFunc(name, lsc) \
8005 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
8006 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
8008 +#define AuWriteLockFunc(name, lsc) \
8009 +static inline void di_write_lock_##name(struct dentry *d) \
8010 +{ di_write_lock(d, AuLsc_DI_##lsc); }
8012 +#define AuRWLockFuncs(name, lsc) \
8013 + AuReadLockFunc(name, lsc) \
8014 + AuWriteLockFunc(name, lsc)
8016 +AuRWLockFuncs(child, CHILD);
8017 +AuRWLockFuncs(child2, CHILD2);
8018 +AuRWLockFuncs(child3, CHILD3);
8019 +AuRWLockFuncs(parent, PARENT);
8020 +AuRWLockFuncs(parent2, PARENT2);
8021 +AuRWLockFuncs(parent3, PARENT3);
8023 +#undef AuReadLockFunc
8024 +#undef AuWriteLockFunc
8025 +#undef AuRWLockFuncs
8027 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
8028 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
8029 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
8031 +/* ---------------------------------------------------------------------- */
8033 +/* todo: memory barrier? */
8034 +static inline unsigned int au_digen(struct dentry *d)
8036 + return atomic_read(&au_di(d)->di_generation);
8039 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
8041 + hdentry->hd_dentry = NULL;
8044 +static inline void au_hdput(struct au_hdentry *hd)
8047 + dput(hd->hd_dentry);
8050 +static inline aufs_bindex_t au_dbstart(struct dentry *dentry)
8052 + DiMustAnyLock(dentry);
8053 + return au_di(dentry)->di_bstart;
8056 +static inline aufs_bindex_t au_dbend(struct dentry *dentry)
8058 + DiMustAnyLock(dentry);
8059 + return au_di(dentry)->di_bend;
8062 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
8064 + DiMustAnyLock(dentry);
8065 + return au_di(dentry)->di_bwh;
8068 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
8070 + DiMustAnyLock(dentry);
8071 + return au_di(dentry)->di_bdiropq;
8074 +/* todo: hard/soft set? */
8075 +static inline void au_set_dbstart(struct dentry *dentry, aufs_bindex_t bindex)
8077 + DiMustWriteLock(dentry);
8078 + au_di(dentry)->di_bstart = bindex;
8081 +static inline void au_set_dbend(struct dentry *dentry, aufs_bindex_t bindex)
8083 + DiMustWriteLock(dentry);
8084 + au_di(dentry)->di_bend = bindex;
8087 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
8089 + DiMustWriteLock(dentry);
8090 + /* dbwh can be outside of bstart - bend range */
8091 + au_di(dentry)->di_bwh = bindex;
8094 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
8096 + DiMustWriteLock(dentry);
8097 + au_di(dentry)->di_bdiropq = bindex;
8100 +/* ---------------------------------------------------------------------- */
8102 +#ifdef CONFIG_AUFS_HNOTIFY
8103 +static inline void au_digen_dec(struct dentry *d)
8105 + atomic_dec(&au_di(d)->di_generation);
8108 +static inline void au_hn_di_reinit(struct dentry *dentry)
8110 + dentry->d_fsdata = NULL;
8113 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
8114 +#endif /* CONFIG_AUFS_HNOTIFY */
8116 +#endif /* __KERNEL__ */
8117 +#endif /* __AUFS_DENTRY_H__ */
8118 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
8119 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
8120 +++ linux/fs/aufs/dinfo.c 2014-04-24 22:11:10.848602379 +0200
8123 + * Copyright (C) 2005-2014 Junjiro R. Okajima
8125 + * This program, aufs is free software; you can redistribute it and/or modify
8126 + * it under the terms of the GNU General Public License as published by
8127 + * the Free Software Foundation; either version 2 of the License, or
8128 + * (at your option) any later version.
8130 + * This program is distributed in the hope that it will be useful,
8131 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8132 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8133 + * GNU General Public License for more details.
8135 + * You should have received a copy of the GNU General Public License
8136 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8140 + * dentry private data
8145 +void au_di_init_once(void *_dinfo)
8147 + struct au_dinfo *dinfo = _dinfo;
8148 + static struct lock_class_key aufs_di;
8150 + au_rw_init(&dinfo->di_rwsem);
8151 + au_rw_class(&dinfo->di_rwsem, &aufs_di);
8154 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
8156 + struct au_dinfo *dinfo;
8159 + dinfo = au_cache_alloc_dinfo();
8160 + if (unlikely(!dinfo))
8163 + nbr = au_sbend(sb) + 1;
8166 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
8167 + if (dinfo->di_hdentry) {
8168 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
8169 + dinfo->di_bstart = -1;
8170 + dinfo->di_bend = -1;
8171 + dinfo->di_bwh = -1;
8172 + dinfo->di_bdiropq = -1;
8173 + for (i = 0; i < nbr; i++)
8174 + dinfo->di_hdentry[i].hd_id = -1;
8178 + au_cache_free_dinfo(dinfo);
8185 +void au_di_free(struct au_dinfo *dinfo)
8187 + struct au_hdentry *p;
8188 + aufs_bindex_t bend, bindex;
8190 + /* dentry may not be revalidated */
8191 + bindex = dinfo->di_bstart;
8192 + if (bindex >= 0) {
8193 + bend = dinfo->di_bend;
8194 + p = dinfo->di_hdentry + bindex;
8195 + while (bindex++ <= bend)
8198 + kfree(dinfo->di_hdentry);
8199 + au_cache_free_dinfo(dinfo);
8202 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
8204 + struct au_hdentry *p;
8207 + AuRwMustWriteLock(&a->di_rwsem);
8208 + AuRwMustWriteLock(&b->di_rwsem);
8210 +#define DiSwap(v, name) \
8212 + v = a->di_##name; \
8213 + a->di_##name = b->di_##name; \
8214 + b->di_##name = v; \
8217 + DiSwap(p, hdentry);
8218 + DiSwap(bi, bstart);
8221 + DiSwap(bi, bdiropq);
8227 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
8229 + AuRwMustWriteLock(&dst->di_rwsem);
8230 + AuRwMustWriteLock(&src->di_rwsem);
8232 + dst->di_bstart = src->di_bstart;
8233 + dst->di_bend = src->di_bend;
8234 + dst->di_bwh = src->di_bwh;
8235 + dst->di_bdiropq = src->di_bdiropq;
8239 +int au_di_init(struct dentry *dentry)
8242 + struct super_block *sb;
8243 + struct au_dinfo *dinfo;
8246 + sb = dentry->d_sb;
8247 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
8249 + atomic_set(&dinfo->di_generation, au_sigen(sb));
8250 + /* smp_mb(); */ /* atomic_set */
8251 + dentry->d_fsdata = dinfo;
8258 +void au_di_fin(struct dentry *dentry)
8260 + struct au_dinfo *dinfo;
8262 + dinfo = au_di(dentry);
8263 + AuRwDestroy(&dinfo->di_rwsem);
8264 + au_di_free(dinfo);
8267 +int au_di_realloc(struct au_dinfo *dinfo, int nbr)
8270 + struct au_hdentry *hdp;
8272 + AuRwMustWriteLock(&dinfo->di_rwsem);
8275 + sz = sizeof(*hdp) * (dinfo->di_bend + 1);
8277 + sz = sizeof(*hdp);
8278 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS);
8280 + dinfo->di_hdentry = hdp;
8287 +/* ---------------------------------------------------------------------- */
8289 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
8292 + case AuLsc_DI_CHILD:
8293 + ii_write_lock_child(inode);
8295 + case AuLsc_DI_CHILD2:
8296 + ii_write_lock_child2(inode);
8298 + case AuLsc_DI_CHILD3:
8299 + ii_write_lock_child3(inode);
8301 + case AuLsc_DI_PARENT:
8302 + ii_write_lock_parent(inode);
8304 + case AuLsc_DI_PARENT2:
8305 + ii_write_lock_parent2(inode);
8307 + case AuLsc_DI_PARENT3:
8308 + ii_write_lock_parent3(inode);
8315 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
8318 + case AuLsc_DI_CHILD:
8319 + ii_read_lock_child(inode);
8321 + case AuLsc_DI_CHILD2:
8322 + ii_read_lock_child2(inode);
8324 + case AuLsc_DI_CHILD3:
8325 + ii_read_lock_child3(inode);
8327 + case AuLsc_DI_PARENT:
8328 + ii_read_lock_parent(inode);
8330 + case AuLsc_DI_PARENT2:
8331 + ii_read_lock_parent2(inode);
8333 + case AuLsc_DI_PARENT3:
8334 + ii_read_lock_parent3(inode);
8341 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
8343 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
8345 + if (au_ftest_lock(flags, IW))
8346 + do_ii_write_lock(d->d_inode, lsc);
8347 + else if (au_ftest_lock(flags, IR))
8348 + do_ii_read_lock(d->d_inode, lsc);
8352 +void di_read_unlock(struct dentry *d, int flags)
8355 + if (au_ftest_lock(flags, IW)) {
8356 + au_dbg_verify_dinode(d);
8357 + ii_write_unlock(d->d_inode);
8358 + } else if (au_ftest_lock(flags, IR)) {
8359 + au_dbg_verify_dinode(d);
8360 + ii_read_unlock(d->d_inode);
8363 + au_rw_read_unlock(&au_di(d)->di_rwsem);
8366 +void di_downgrade_lock(struct dentry *d, int flags)
8368 + if (d->d_inode && au_ftest_lock(flags, IR))
8369 + ii_downgrade_lock(d->d_inode);
8370 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
8373 +void di_write_lock(struct dentry *d, unsigned int lsc)
8375 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
8377 + do_ii_write_lock(d->d_inode, lsc);
8380 +void di_write_unlock(struct dentry *d)
8382 + au_dbg_verify_dinode(d);
8384 + ii_write_unlock(d->d_inode);
8385 + au_rw_write_unlock(&au_di(d)->di_rwsem);
8388 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
8390 + AuDebugOn(d1 == d2
8391 + || d1->d_inode == d2->d_inode
8392 + || d1->d_sb != d2->d_sb);
8394 + if (isdir && au_test_subdir(d1, d2)) {
8395 + di_write_lock_child(d1);
8396 + di_write_lock_child2(d2);
8398 + /* there should be no races */
8399 + di_write_lock_child(d2);
8400 + di_write_lock_child2(d1);
8404 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
8406 + AuDebugOn(d1 == d2
8407 + || d1->d_inode == d2->d_inode
8408 + || d1->d_sb != d2->d_sb);
8410 + if (isdir && au_test_subdir(d1, d2)) {
8411 + di_write_lock_parent(d1);
8412 + di_write_lock_parent2(d2);
8414 + /* there should be no races */
8415 + di_write_lock_parent(d2);
8416 + di_write_lock_parent2(d1);
8420 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
8422 + di_write_unlock(d1);
8423 + if (d1->d_inode == d2->d_inode)
8424 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
8426 + di_write_unlock(d2);
8429 +/* ---------------------------------------------------------------------- */
8431 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
8435 + DiMustAnyLock(dentry);
8437 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
8439 + AuDebugOn(bindex < 0);
8440 + d = au_di(dentry)->di_hdentry[0 + bindex].hd_dentry;
8441 + AuDebugOn(d && d_count(d) <= 0);
8446 + * extended version of au_h_dptr().
8447 + * returns a hashed and positive h_dentry in bindex, NULL, or error.
8449 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
8451 + struct dentry *h_dentry;
8452 + struct inode *inode, *h_inode;
8454 + inode = dentry->d_inode;
8455 + AuDebugOn(!inode);
8458 + if (au_dbstart(dentry) <= bindex
8459 + && bindex <= au_dbend(dentry))
8460 + h_dentry = au_h_dptr(dentry, bindex);
8461 + if (h_dentry && !au_d_hashed_positive(h_dentry)) {
8463 + goto out; /* success */
8466 + AuDebugOn(bindex < au_ibstart(inode));
8467 + AuDebugOn(au_ibend(inode) < bindex);
8468 + h_inode = au_h_iptr(inode, bindex);
8469 + h_dentry = d_find_alias(h_inode);
8471 + if (!IS_ERR(h_dentry)) {
8472 + if (!au_d_hashed_positive(h_dentry))
8473 + goto out; /* success */
8479 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
8480 + h_dentry = au_plink_lkup(inode, bindex);
8481 + AuDebugOn(!h_dentry);
8482 + if (!IS_ERR(h_dentry)) {
8483 + if (!au_d_hashed_positive(h_dentry))
8484 + goto out; /* success */
8491 + AuDbgDentry(h_dentry);
8495 +aufs_bindex_t au_dbtail(struct dentry *dentry)
8497 + aufs_bindex_t bend, bwh;
8499 + bend = au_dbend(dentry);
8501 + bwh = au_dbwh(dentry);
8504 + if (0 < bwh && bwh < bend)
8510 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
8512 + aufs_bindex_t bend, bopq;
8514 + bend = au_dbtail(dentry);
8516 + bopq = au_dbdiropq(dentry);
8517 + if (0 <= bopq && bopq < bend)
8523 +/* ---------------------------------------------------------------------- */
8525 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
8526 + struct dentry *h_dentry)
8528 + struct au_hdentry *hd = au_di(dentry)->di_hdentry + bindex;
8529 + struct au_branch *br;
8531 + DiMustWriteLock(dentry);
8534 + hd->hd_dentry = h_dentry;
8536 + br = au_sbr(dentry->d_sb, bindex);
8537 + hd->hd_id = br->br_id;
8541 +int au_dbrange_test(struct dentry *dentry)
8544 + aufs_bindex_t bstart, bend;
8547 + bstart = au_dbstart(dentry);
8548 + bend = au_dbend(dentry);
8550 + AuDebugOn(bend < 0 && bstart > bend);
8553 + AuDebugOn(bend >= 0);
8559 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
8564 + if (unlikely(au_digen(dentry) != sigen
8565 + || au_iigen_test(dentry->d_inode, sigen)))
8571 +void au_update_digen(struct dentry *dentry)
8573 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
8574 + /* smp_mb(); */ /* atomic_set */
8577 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
8579 + struct au_dinfo *dinfo;
8580 + struct dentry *h_d;
8581 + struct au_hdentry *hdp;
8583 + DiMustWriteLock(dentry);
8585 + dinfo = au_di(dentry);
8586 + if (!dinfo || dinfo->di_bstart < 0)
8589 + hdp = dinfo->di_hdentry;
8590 + if (do_put_zero) {
8591 + aufs_bindex_t bindex, bend;
8593 + bend = dinfo->di_bend;
8594 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++) {
8595 + h_d = hdp[0 + bindex].hd_dentry;
8596 + if (h_d && !h_d->d_inode)
8597 + au_set_h_dptr(dentry, bindex, NULL);
8601 + dinfo->di_bstart = -1;
8602 + while (++dinfo->di_bstart <= dinfo->di_bend)
8603 + if (hdp[0 + dinfo->di_bstart].hd_dentry)
8605 + if (dinfo->di_bstart > dinfo->di_bend) {
8606 + dinfo->di_bstart = -1;
8607 + dinfo->di_bend = -1;
8612 + while (0 <= --dinfo->di_bend)
8613 + if (hdp[0 + dinfo->di_bend].hd_dentry)
8615 + AuDebugOn(dinfo->di_bstart > dinfo->di_bend || dinfo->di_bend < 0);
8618 +void au_update_dbstart(struct dentry *dentry)
8620 + aufs_bindex_t bindex, bend;
8621 + struct dentry *h_dentry;
8623 + bend = au_dbend(dentry);
8624 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
8625 + h_dentry = au_h_dptr(dentry, bindex);
8628 + if (h_dentry->d_inode) {
8629 + au_set_dbstart(dentry, bindex);
8632 + au_set_h_dptr(dentry, bindex, NULL);
8636 +void au_update_dbend(struct dentry *dentry)
8638 + aufs_bindex_t bindex, bstart;
8639 + struct dentry *h_dentry;
8641 + bstart = au_dbstart(dentry);
8642 + for (bindex = au_dbend(dentry); bindex >= bstart; bindex--) {
8643 + h_dentry = au_h_dptr(dentry, bindex);
8646 + if (h_dentry->d_inode) {
8647 + au_set_dbend(dentry, bindex);
8650 + au_set_h_dptr(dentry, bindex, NULL);
8654 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
8656 + aufs_bindex_t bindex, bend;
8658 + bend = au_dbend(dentry);
8659 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++)
8660 + if (au_h_dptr(dentry, bindex) == h_dentry)
8664 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
8665 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
8666 +++ linux/fs/aufs/dir.c 2014-04-24 22:11:10.848602379 +0200
8669 + * Copyright (C) 2005-2014 Junjiro R. Okajima
8671 + * This program, aufs is free software; you can redistribute it and/or modify
8672 + * it under the terms of the GNU General Public License as published by
8673 + * the Free Software Foundation; either version 2 of the License, or
8674 + * (at your option) any later version.
8676 + * This program is distributed in the hope that it will be useful,
8677 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8678 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8679 + * GNU General Public License for more details.
8681 + * You should have received a copy of the GNU General Public License
8682 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8686 + * directory operations
8689 +#include <linux/fs_stack.h>
8692 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
8694 + unsigned int nlink;
8696 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
8698 + nlink = dir->i_nlink;
8699 + nlink += h_dir->i_nlink - 2;
8700 + if (h_dir->i_nlink < 2)
8702 + smp_mb(); /* for i_nlink */
8703 + /* 0 can happen in revaliding */
8704 + set_nlink(dir, nlink);
8707 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
8709 + unsigned int nlink;
8711 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
8713 + nlink = dir->i_nlink;
8714 + nlink -= h_dir->i_nlink - 2;
8715 + if (h_dir->i_nlink < 2)
8717 + smp_mb(); /* for i_nlink */
8718 + /* nlink == 0 means the branch-fs is broken */
8719 + set_nlink(dir, nlink);
8722 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
8725 + aufs_bindex_t bindex, bend;
8726 + struct file *h_file;
8727 + struct dentry *h_dentry;
8731 + AuDebugOn(!file_inode(file));
8732 + AuDebugOn(!S_ISDIR(file_inode(file)->i_mode));
8734 + bend = au_fbend_dir(file);
8735 + for (bindex = au_fbstart(file);
8736 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
8738 + h_file = au_hf_dir(file, bindex);
8739 + if (h_file && file_inode(h_file))
8740 + sz += vfsub_f_size_read(h_file);
8743 + AuDebugOn(!dentry);
8744 + AuDebugOn(!dentry->d_inode);
8745 + AuDebugOn(!S_ISDIR(dentry->d_inode->i_mode));
8747 + bend = au_dbtaildir(dentry);
8748 + for (bindex = au_dbstart(dentry);
8749 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
8751 + h_dentry = au_h_dptr(dentry, bindex);
8752 + if (h_dentry && h_dentry->d_inode)
8753 + sz += i_size_read(h_dentry->d_inode);
8756 + if (sz < KMALLOC_MAX_SIZE)
8757 + sz = roundup_pow_of_two(sz);
8758 + if (sz > KMALLOC_MAX_SIZE)
8759 + sz = KMALLOC_MAX_SIZE;
8760 + else if (sz < NAME_MAX) {
8761 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
8762 + sz = AUFS_RDBLK_DEF;
8767 +/* ---------------------------------------------------------------------- */
8769 +static int reopen_dir(struct file *file)
8772 + unsigned int flags;
8773 + aufs_bindex_t bindex, btail, bstart;
8774 + struct dentry *dentry, *h_dentry;
8775 + struct file *h_file;
8777 + /* open all lower dirs */
8778 + dentry = file->f_dentry;
8779 + bstart = au_dbstart(dentry);
8780 + for (bindex = au_fbstart(file); bindex < bstart; bindex++)
8781 + au_set_h_fptr(file, bindex, NULL);
8782 + au_set_fbstart(file, bstart);
8784 + btail = au_dbtaildir(dentry);
8785 + for (bindex = au_fbend_dir(file); btail < bindex; bindex--)
8786 + au_set_h_fptr(file, bindex, NULL);
8787 + au_set_fbend_dir(file, btail);
8789 + flags = vfsub_file_flags(file);
8790 + for (bindex = bstart; bindex <= btail; bindex++) {
8791 + h_dentry = au_h_dptr(dentry, bindex);
8794 + h_file = au_hf_dir(file, bindex);
8798 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
8799 + err = PTR_ERR(h_file);
8800 + if (IS_ERR(h_file))
8801 + goto out; /* close all? */
8802 + au_set_h_fptr(file, bindex, h_file);
8804 + au_update_figen(file);
8805 + /* todo: necessary? */
8806 + /* file->f_ra = h_file->f_ra; */
8813 +static int do_open_dir(struct file *file, int flags)
8816 + aufs_bindex_t bindex, btail;
8817 + struct dentry *dentry, *h_dentry;
8818 + struct file *h_file;
8820 + FiMustWriteLock(file);
8823 + dentry = file->f_dentry;
8824 + file->f_version = dentry->d_inode->i_version;
8825 + bindex = au_dbstart(dentry);
8826 + au_set_fbstart(file, bindex);
8827 + btail = au_dbtaildir(dentry);
8828 + au_set_fbend_dir(file, btail);
8829 + for (; !err && bindex <= btail; bindex++) {
8830 + h_dentry = au_h_dptr(dentry, bindex);
8834 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
8835 + if (IS_ERR(h_file)) {
8836 + err = PTR_ERR(h_file);
8839 + au_set_h_fptr(file, bindex, h_file);
8841 + au_update_figen(file);
8842 + /* todo: necessary? */
8843 + /* file->f_ra = h_file->f_ra; */
8845 + return 0; /* success */
8848 + for (bindex = au_fbstart(file); bindex <= btail; bindex++)
8849 + au_set_h_fptr(file, bindex, NULL);
8850 + au_set_fbstart(file, -1);
8851 + au_set_fbend_dir(file, -1);
8856 +static int aufs_open_dir(struct inode *inode __maybe_unused,
8857 + struct file *file)
8860 + struct super_block *sb;
8861 + struct au_fidir *fidir;
8864 + sb = file->f_dentry->d_sb;
8865 + si_read_lock(sb, AuLock_FLUSH);
8866 + fidir = au_fidir_alloc(sb);
8868 + err = au_do_open(file, do_open_dir, fidir);
8869 + if (unlikely(err))
8872 + si_read_unlock(sb);
8876 +static int aufs_release_dir(struct inode *inode __maybe_unused,
8877 + struct file *file)
8879 + struct au_vdir *vdir_cache;
8880 + struct au_finfo *finfo;
8881 + struct au_fidir *fidir;
8882 + aufs_bindex_t bindex, bend;
8884 + finfo = au_fi(file);
8885 + fidir = finfo->fi_hdir;
8887 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
8889 + au_vdir_free(vdir_cache);
8891 + bindex = finfo->fi_btop;
8892 + if (bindex >= 0) {
8894 + * calls fput() instead of filp_close(),
8895 + * since no dnotify or lock for the lower file.
8897 + bend = fidir->fd_bbot;
8898 + for (; bindex <= bend; bindex++)
8899 + au_set_h_fptr(file, bindex, NULL);
8902 + finfo->fi_hdir = NULL;
8904 + au_finfo_fin(file);
8908 +/* ---------------------------------------------------------------------- */
8910 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
8913 + aufs_bindex_t bindex, bend;
8914 + struct file *h_file;
8917 + bend = au_fbend_dir(file);
8918 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
8919 + h_file = au_hf_dir(file, bindex);
8921 + err = vfsub_flush(h_file, id);
8926 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
8928 + return au_do_flush(file, id, au_do_flush_dir);
8931 +/* ---------------------------------------------------------------------- */
8933 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
8936 + aufs_bindex_t bend, bindex;
8937 + struct inode *inode;
8938 + struct super_block *sb;
8941 + sb = dentry->d_sb;
8942 + inode = dentry->d_inode;
8944 + bend = au_dbend(dentry);
8945 + for (bindex = au_dbstart(dentry); !err && bindex <= bend; bindex++) {
8946 + struct path h_path;
8948 + if (au_test_ro(sb, bindex, inode))
8950 + h_path.dentry = au_h_dptr(dentry, bindex);
8951 + if (!h_path.dentry)
8954 + h_path.mnt = au_sbr_mnt(sb, bindex);
8955 + err = vfsub_fsync(NULL, &h_path, datasync);
8961 +static int au_do_fsync_dir(struct file *file, int datasync)
8964 + aufs_bindex_t bend, bindex;
8965 + struct file *h_file;
8966 + struct super_block *sb;
8967 + struct inode *inode;
8969 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
8970 + if (unlikely(err))
8973 + sb = file->f_dentry->d_sb;
8974 + inode = file_inode(file);
8975 + bend = au_fbend_dir(file);
8976 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
8977 + h_file = au_hf_dir(file, bindex);
8978 + if (!h_file || au_test_ro(sb, bindex, inode))
8981 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
8989 + * @file may be NULL
8991 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
8995 + struct dentry *dentry;
8996 + struct super_block *sb;
8997 + struct mutex *mtx;
9000 + dentry = file->f_dentry;
9001 + mtx = &dentry->d_inode->i_mutex;
9003 + sb = dentry->d_sb;
9004 + si_noflush_read_lock(sb);
9006 + err = au_do_fsync_dir(file, datasync);
9008 + di_write_lock_child(dentry);
9009 + err = au_do_fsync_dir_no_file(dentry, datasync);
9011 + au_cpup_attr_timesizes(dentry->d_inode);
9012 + di_write_unlock(dentry);
9014 + fi_write_unlock(file);
9016 + si_read_unlock(sb);
9017 + mutex_unlock(mtx);
9021 +/* ---------------------------------------------------------------------- */
9023 +static int aufs_iterate(struct file *file, struct dir_context *ctx)
9026 + struct dentry *dentry;
9027 + struct inode *inode, *h_inode;
9028 + struct super_block *sb;
9030 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
9032 + dentry = file->f_dentry;
9033 + inode = dentry->d_inode;
9036 + sb = dentry->d_sb;
9037 + si_read_lock(sb, AuLock_FLUSH);
9038 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
9039 + if (unlikely(err))
9041 + err = au_alive_dir(dentry);
9043 + err = au_vdir_init(file);
9044 + di_downgrade_lock(dentry, AuLock_IR);
9045 + if (unlikely(err))
9048 + h_inode = au_h_iptr(inode, au_ibstart(inode));
9049 + if (!au_test_nfsd()) {
9050 + err = au_vdir_fill_de(file, ctx);
9051 + fsstack_copy_attr_atime(inode, h_inode);
9054 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
9055 + * encode_fh() and others.
9057 + atomic_inc(&h_inode->i_count);
9058 + di_read_unlock(dentry, AuLock_IR);
9059 + si_read_unlock(sb);
9060 + err = au_vdir_fill_de(file, ctx);
9061 + fsstack_copy_attr_atime(inode, h_inode);
9062 + fi_write_unlock(file);
9070 + di_read_unlock(dentry, AuLock_IR);
9071 + fi_write_unlock(file);
9073 + si_read_unlock(sb);
9077 +/* ---------------------------------------------------------------------- */
9079 +#define AuTestEmpty_WHONLY 1
9080 +#define AuTestEmpty_CALLED (1 << 1)
9081 +#define AuTestEmpty_SHWH (1 << 2)
9082 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
9083 +#define au_fset_testempty(flags, name) \
9084 + do { (flags) |= AuTestEmpty_##name; } while (0)
9085 +#define au_fclr_testempty(flags, name) \
9086 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
9088 +#ifndef CONFIG_AUFS_SHWH
9089 +#undef AuTestEmpty_SHWH
9090 +#define AuTestEmpty_SHWH 0
9093 +struct test_empty_arg {
9094 + struct dir_context ctx;
9095 + struct au_nhash *whlist;
9096 + unsigned int flags;
9098 + aufs_bindex_t bindex;
9101 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
9102 + int namelen, loff_t offset __maybe_unused, u64 ino,
9103 + unsigned int d_type)
9105 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
9107 + char *name = (void *)__name;
9110 + au_fset_testempty(arg->flags, CALLED);
9112 + if (name[0] == '.'
9113 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
9114 + goto out; /* success */
9116 + if (namelen <= AUFS_WH_PFX_LEN
9117 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
9118 + if (au_ftest_testempty(arg->flags, WHONLY)
9119 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
9120 + arg->err = -ENOTEMPTY;
9124 + name += AUFS_WH_PFX_LEN;
9125 + namelen -= AUFS_WH_PFX_LEN;
9126 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
9127 + arg->err = au_nhash_append_wh
9128 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
9129 + au_ftest_testempty(arg->flags, SHWH));
9133 + AuTraceErr(arg->err);
9137 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
9140 + struct file *h_file;
9142 + h_file = au_h_open(dentry, arg->bindex,
9143 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
9144 + /*file*/NULL, /*force_wr*/0);
9145 + err = PTR_ERR(h_file);
9146 + if (IS_ERR(h_file))
9150 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
9151 + && !file_inode(h_file)->i_nlink)
9156 + au_fclr_testempty(arg->flags, CALLED);
9158 + err = vfsub_iterate_dir(h_file, &arg->ctx);
9161 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
9165 + au_sbr_put(dentry->d_sb, arg->bindex);
9170 +struct do_test_empty_args {
9172 + struct dentry *dentry;
9173 + struct test_empty_arg *arg;
9176 +static void call_do_test_empty(void *args)
9178 + struct do_test_empty_args *a = args;
9179 + *a->errp = do_test_empty(a->dentry, a->arg);
9182 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
9185 + struct dentry *h_dentry;
9186 + struct inode *h_inode;
9188 + h_dentry = au_h_dptr(dentry, arg->bindex);
9189 + h_inode = h_dentry->d_inode;
9190 + /* todo: i_mode changes anytime? */
9191 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
9192 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
9193 + mutex_unlock(&h_inode->i_mutex);
9195 + err = do_test_empty(dentry, arg);
9197 + struct do_test_empty_args args = {
9202 + unsigned int flags = arg->flags;
9204 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
9205 + if (unlikely(wkq_err))
9207 + arg->flags = flags;
9213 +int au_test_empty_lower(struct dentry *dentry)
9216 + unsigned int rdhash;
9217 + aufs_bindex_t bindex, bstart, btail;
9218 + struct au_nhash whlist;
9219 + struct test_empty_arg arg = {
9221 + .actor = au_diractor(test_empty_cb)
9225 + SiMustAnyLock(dentry->d_sb);
9227 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
9229 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
9230 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
9231 + if (unlikely(err))
9235 + arg.whlist = &whlist;
9236 + bstart = au_dbstart(dentry);
9237 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
9238 + au_fset_testempty(arg.flags, SHWH);
9239 + arg.bindex = bstart;
9240 + err = do_test_empty(dentry, &arg);
9241 + if (unlikely(err))
9244 + au_fset_testempty(arg.flags, WHONLY);
9245 + btail = au_dbtaildir(dentry);
9246 + for (bindex = bstart + 1; !err && bindex <= btail; bindex++) {
9247 + struct dentry *h_dentry;
9249 + h_dentry = au_h_dptr(dentry, bindex);
9250 + if (h_dentry && h_dentry->d_inode) {
9251 + arg.bindex = bindex;
9252 + err = do_test_empty(dentry, &arg);
9257 + au_nhash_wh_free(&whlist);
9262 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
9265 + struct test_empty_arg arg = {
9267 + .actor = au_diractor(test_empty_cb)
9270 + aufs_bindex_t bindex, btail;
9273 + arg.whlist = whlist;
9274 + arg.flags = AuTestEmpty_WHONLY;
9275 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
9276 + au_fset_testempty(arg.flags, SHWH);
9277 + btail = au_dbtaildir(dentry);
9278 + for (bindex = au_dbstart(dentry); !err && bindex <= btail; bindex++) {
9279 + struct dentry *h_dentry;
9281 + h_dentry = au_h_dptr(dentry, bindex);
9282 + if (h_dentry && h_dentry->d_inode) {
9283 + arg.bindex = bindex;
9284 + err = sio_test_empty(dentry, &arg);
9291 +/* ---------------------------------------------------------------------- */
9293 +const struct file_operations aufs_dir_fop = {
9294 + .owner = THIS_MODULE,
9295 + .llseek = default_llseek,
9296 + .read = generic_read_dir,
9297 + .iterate = aufs_iterate,
9298 + .unlocked_ioctl = aufs_ioctl_dir,
9299 +#ifdef CONFIG_COMPAT
9300 + .compat_ioctl = aufs_compat_ioctl_dir,
9302 + .open = aufs_open_dir,
9303 + .release = aufs_release_dir,
9304 + .flush = aufs_flush_dir,
9305 + .fsync = aufs_fsync_dir
9307 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
9308 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
9309 +++ linux/fs/aufs/dir.h 2014-04-24 22:11:10.851935747 +0200
9312 + * Copyright (C) 2005-2014 Junjiro R. Okajima
9314 + * This program, aufs is free software; you can redistribute it and/or modify
9315 + * it under the terms of the GNU General Public License as published by
9316 + * the Free Software Foundation; either version 2 of the License, or
9317 + * (at your option) any later version.
9319 + * This program is distributed in the hope that it will be useful,
9320 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9321 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9322 + * GNU General Public License for more details.
9324 + * You should have received a copy of the GNU General Public License
9325 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9329 + * directory operations
9332 +#ifndef __AUFS_DIR_H__
9333 +#define __AUFS_DIR_H__
9337 +#include <linux/fs.h>
9339 +/* ---------------------------------------------------------------------- */
9341 +/* need to be faster and smaller */
9344 + unsigned int nh_num;
9345 + struct hlist_head *nh_head;
9348 +struct au_vdir_destr {
9349 + unsigned char len;
9350 + unsigned char name[0];
9353 +struct au_vdir_dehstr {
9354 + struct hlist_node hash;
9355 + struct au_vdir_destr *str;
9356 +} ____cacheline_aligned_in_smp;
9358 +struct au_vdir_de {
9360 + unsigned char de_type;
9361 + /* caution: packed */
9362 + struct au_vdir_destr de_str;
9365 +struct au_vdir_wh {
9366 + struct hlist_node wh_hash;
9367 +#ifdef CONFIG_AUFS_SHWH
9369 + aufs_bindex_t wh_bindex;
9370 + unsigned char wh_type;
9372 + aufs_bindex_t wh_bindex;
9374 + /* caution: packed */
9375 + struct au_vdir_destr wh_str;
9378 +union au_vdir_deblk_p {
9379 + unsigned char *deblk;
9380 + struct au_vdir_de *de;
9384 + unsigned char **vd_deblk;
9385 + unsigned long vd_nblk;
9388 + union au_vdir_deblk_p p;
9391 + unsigned long vd_version;
9392 + unsigned int vd_deblk_sz;
9393 + unsigned long vd_jiffy;
9394 +} ____cacheline_aligned_in_smp;
9396 +/* ---------------------------------------------------------------------- */
9399 +extern const struct file_operations aufs_dir_fop;
9400 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
9401 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
9402 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
9403 +int au_test_empty_lower(struct dentry *dentry);
9404 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
9407 +unsigned int au_rdhash_est(loff_t sz);
9408 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
9409 +void au_nhash_wh_free(struct au_nhash *whlist);
9410 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
9412 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
9413 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
9414 + unsigned int d_type, aufs_bindex_t bindex,
9415 + unsigned char shwh);
9416 +void au_vdir_free(struct au_vdir *vdir);
9417 +int au_vdir_init(struct file *file);
9418 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
9421 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
9423 +#ifdef CONFIG_AUFS_RDU
9425 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
9426 +#ifdef CONFIG_COMPAT
9427 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
9428 + unsigned long arg);
9431 +static inline long au_rdu_ioctl(struct file *file, unsigned int cmd,
9432 + unsigned long arg)
9436 +#ifdef CONFIG_COMPAT
9437 +static inline long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
9438 + unsigned long arg)
9445 +#endif /* __KERNEL__ */
9446 +#endif /* __AUFS_DIR_H__ */
9447 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
9448 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
9449 +++ linux/fs/aufs/dynop.c 2014-04-24 22:11:10.851935747 +0200
9452 + * Copyright (C) 2010-2014 Junjiro R. Okajima
9454 + * This program, aufs is free software; you can redistribute it and/or modify
9455 + * it under the terms of the GNU General Public License as published by
9456 + * the Free Software Foundation; either version 2 of the License, or
9457 + * (at your option) any later version.
9459 + * This program is distributed in the hope that it will be useful,
9460 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9461 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9462 + * GNU General Public License for more details.
9464 + * You should have received a copy of the GNU General Public License
9465 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9469 + * dynamically customizable operations for regular files
9474 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
9477 + * How large will these lists be?
9478 + * Usually just a few elements, 20-30 at most for each, I guess.
9480 +static struct au_splhead dynop[AuDyLast];
9482 +static struct au_dykey *dy_gfind_get(struct au_splhead *spl, const void *h_op)
9484 + struct au_dykey *key, *tmp;
9485 + struct list_head *head;
9488 + head = &spl->head;
9490 + list_for_each_entry_rcu(tmp, head, dk_list)
9491 + if (tmp->dk_op.dy_hop == h_op) {
9493 + kref_get(&key->dk_kref);
9496 + rcu_read_unlock();
9501 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
9503 + struct au_dykey **k, *found;
9504 + const void *h_op = key->dk_op.dy_hop;
9509 + for (i = 0; i < AuBrDynOp; i++)
9511 + if (k[i]->dk_op.dy_hop == h_op) {
9518 + spin_lock(&br->br_dykey_lock);
9519 + for (; i < AuBrDynOp; i++)
9521 + if (k[i]->dk_op.dy_hop == h_op) {
9529 + spin_unlock(&br->br_dykey_lock);
9530 + BUG_ON(i == AuBrDynOp); /* expand the array */
9536 +/* kref_get() if @key is already added */
9537 +static struct au_dykey *dy_gadd(struct au_splhead *spl, struct au_dykey *key)
9539 + struct au_dykey *tmp, *found;
9540 + struct list_head *head;
9541 + const void *h_op = key->dk_op.dy_hop;
9544 + head = &spl->head;
9545 + spin_lock(&spl->spin);
9546 + list_for_each_entry(tmp, head, dk_list)
9547 + if (tmp->dk_op.dy_hop == h_op) {
9548 + kref_get(&tmp->dk_kref);
9553 + list_add_rcu(&key->dk_list, head);
9554 + spin_unlock(&spl->spin);
9561 +static void dy_free_rcu(struct rcu_head *rcu)
9563 + struct au_dykey *key;
9565 + key = container_of(rcu, struct au_dykey, dk_rcu);
9570 +static void dy_free(struct kref *kref)
9572 + struct au_dykey *key;
9573 + struct au_splhead *spl;
9575 + key = container_of(kref, struct au_dykey, dk_kref);
9576 + spl = dynop + key->dk_op.dy_type;
9577 + au_spl_del_rcu(&key->dk_list, spl);
9578 + call_rcu(&key->dk_rcu, dy_free_rcu);
9581 +void au_dy_put(struct au_dykey *key)
9583 + kref_put(&key->dk_kref, dy_free);
9586 +/* ---------------------------------------------------------------------- */
9588 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
9590 +#ifdef CONFIG_AUFS_DEBUG
9591 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
9592 +#define DyDbgInc(cnt) do { cnt++; } while (0)
9594 +#define DyDbgDeclare(cnt) do {} while (0)
9595 +#define DyDbgInc(cnt) do {} while (0)
9598 +#define DySet(func, dst, src, h_op, h_sb) do { \
9600 + if (h_op->func) { \
9602 + dst.func = src.func; \
9604 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
9608 +#define DySetForce(func, dst, src) do { \
9609 + AuDebugOn(!src.func); \
9611 + dst.func = src.func; \
9614 +#define DySetAop(func) \
9615 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
9616 +#define DySetAopForce(func) \
9617 + DySetForce(func, dyaop->da_op, aufs_aop)
9619 +static void dy_aop(struct au_dykey *key, const void *h_op,
9620 + struct super_block *h_sb __maybe_unused)
9622 + struct au_dyaop *dyaop = (void *)key;
9623 + const struct address_space_operations *h_aop = h_op;
9624 + DyDbgDeclare(cnt);
9626 + AuDbg("%s\n", au_sbtype(h_sb));
9628 + DySetAop(writepage);
9629 + DySetAopForce(readpage); /* force */
9630 + DySetAop(writepages);
9631 + DySetAop(set_page_dirty);
9632 + DySetAop(readpages);
9633 + DySetAop(write_begin);
9634 + DySetAop(write_end);
9636 + DySetAop(invalidatepage);
9637 + DySetAop(releasepage);
9638 + DySetAop(freepage);
9639 + /* these two will be changed according to an aufs mount option */
9640 + DySetAop(direct_IO);
9641 + DySetAop(get_xip_mem);
9642 + DySetAop(migratepage);
9643 + DySetAop(launder_page);
9644 + DySetAop(is_partially_uptodate);
9645 + DySetAop(is_dirty_writeback);
9646 + DySetAop(error_remove_page);
9647 + DySetAop(swap_activate);
9648 + DySetAop(swap_deactivate);
9650 + DyDbgSize(cnt, *h_aop);
9651 + dyaop->da_get_xip_mem = h_aop->get_xip_mem;
9654 +/* ---------------------------------------------------------------------- */
9656 +static void dy_bug(struct kref *kref)
9661 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
9663 + struct au_dykey *key, *old;
9664 + struct au_splhead *spl;
9667 + void (*set)(struct au_dykey *key, const void *h_op,
9668 + struct super_block *h_sb __maybe_unused);
9670 + static const struct op a[] = {
9672 + .sz = sizeof(struct au_dyaop),
9676 + const struct op *p;
9678 + spl = dynop + op->dy_type;
9679 + key = dy_gfind_get(spl, op->dy_hop);
9681 + goto out_add; /* success */
9683 + p = a + op->dy_type;
9684 + key = kzalloc(p->sz, GFP_NOFS);
9685 + if (unlikely(!key)) {
9686 + key = ERR_PTR(-ENOMEM);
9690 + key->dk_op.dy_hop = op->dy_hop;
9691 + kref_init(&key->dk_kref);
9692 + p->set(key, op->dy_hop, au_br_sb(br));
9693 + old = dy_gadd(spl, key);
9700 + old = dy_bradd(br, key);
9702 + /* its ref-count should never be zero here */
9703 + kref_put(&key->dk_kref, dy_bug);
9708 +/* ---------------------------------------------------------------------- */
9710 + * Aufs prohibits O_DIRECT by defaut even if the branch supports it.
9711 + * This behaviour is neccessary to return an error from open(O_DIRECT) instead
9712 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
9713 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
9714 + * See the aufs manual in detail.
9716 + * To keep this behaviour, aufs has to set NULL to ->get_xip_mem too, and the
9717 + * performance of fadvise() and madvise() may be affected.
9719 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
9722 + dyaop->da_op.direct_IO = NULL;
9723 + dyaop->da_op.get_xip_mem = NULL;
9725 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
9726 + dyaop->da_op.get_xip_mem = aufs_aop.get_xip_mem;
9727 + if (!dyaop->da_get_xip_mem)
9728 + dyaop->da_op.get_xip_mem = NULL;
9732 +static struct au_dyaop *dy_aget(struct au_branch *br,
9733 + const struct address_space_operations *h_aop,
9736 + struct au_dyaop *dyaop;
9737 + struct au_dynop op;
9739 + op.dy_type = AuDy_AOP;
9740 + op.dy_haop = h_aop;
9741 + dyaop = (void *)dy_get(&op, br);
9742 + if (IS_ERR(dyaop))
9744 + dy_adx(dyaop, do_dx);
9750 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
9751 + struct inode *h_inode)
9754 + struct super_block *sb;
9755 + struct au_branch *br;
9756 + struct au_dyaop *dyaop;
9758 + AuDebugOn(!S_ISREG(h_inode->i_mode));
9759 + IiMustWriteLock(inode);
9762 + br = au_sbr(sb, bindex);
9763 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
9764 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
9765 + err = PTR_ERR(dyaop);
9766 + if (IS_ERR(dyaop))
9767 + /* unnecessary to call dy_fput() */
9771 + inode->i_mapping->a_ops = &dyaop->da_op;
9778 + * Is it safe to replace a_ops during the inode/file is in operation?
9781 +int au_dy_irefresh(struct inode *inode)
9784 + aufs_bindex_t bstart;
9785 + struct inode *h_inode;
9788 + if (S_ISREG(inode->i_mode)) {
9789 + bstart = au_ibstart(inode);
9790 + h_inode = au_h_iptr(inode, bstart);
9791 + err = au_dy_iaop(inode, bstart, h_inode);
9796 +void au_dy_arefresh(int do_dx)
9798 + struct au_splhead *spl;
9799 + struct list_head *head;
9800 + struct au_dykey *key;
9802 + spl = dynop + AuDy_AOP;
9803 + head = &spl->head;
9804 + spin_lock(&spl->spin);
9805 + list_for_each_entry(key, head, dk_list)
9806 + dy_adx((void *)key, do_dx);
9807 + spin_unlock(&spl->spin);
9810 +/* ---------------------------------------------------------------------- */
9812 +void __init au_dy_init(void)
9816 + /* make sure that 'struct au_dykey *' can be any type */
9817 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
9819 + for (i = 0; i < AuDyLast; i++)
9820 + au_spl_init(dynop + i);
9823 +void au_dy_fin(void)
9827 + for (i = 0; i < AuDyLast; i++)
9828 + WARN_ON(!list_empty(&dynop[i].head));
9830 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
9831 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
9832 +++ linux/fs/aufs/dynop.h 2014-04-24 22:11:10.851935747 +0200
9835 + * Copyright (C) 2010-2014 Junjiro R. Okajima
9837 + * This program, aufs is free software; you can redistribute it and/or modify
9838 + * it under the terms of the GNU General Public License as published by
9839 + * the Free Software Foundation; either version 2 of the License, or
9840 + * (at your option) any later version.
9842 + * This program is distributed in the hope that it will be useful,
9843 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9844 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9845 + * GNU General Public License for more details.
9847 + * You should have received a copy of the GNU General Public License
9848 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9852 + * dynamically customizable operations (for regular files only)
9855 +#ifndef __AUFS_DYNOP_H__
9856 +#define __AUFS_DYNOP_H__
9862 +enum {AuDy_AOP, AuDyLast};
9867 + const void *dy_hop;
9868 + const struct address_space_operations *dy_haop;
9874 + struct list_head dk_list;
9875 + struct rcu_head dk_rcu;
9877 + struct au_dynop dk_op;
9880 + * during I am in the branch local array, kref is gotten. when the
9881 + * branch is removed, kref is put.
9883 + struct kref dk_kref;
9886 +/* stop unioning since their sizes are very different from each other */
9888 + struct au_dykey da_key;
9889 + struct address_space_operations da_op; /* not const */
9890 + int (*da_get_xip_mem)(struct address_space *, pgoff_t, int,
9891 + void **, unsigned long *);
9894 +/* ---------------------------------------------------------------------- */
9898 +void au_dy_put(struct au_dykey *key);
9899 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
9900 + struct inode *h_inode);
9901 +int au_dy_irefresh(struct inode *inode);
9902 +void au_dy_arefresh(int do_dio);
9904 +void __init au_dy_init(void);
9905 +void au_dy_fin(void);
9907 +#endif /* __KERNEL__ */
9908 +#endif /* __AUFS_DYNOP_H__ */
9909 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
9910 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
9911 +++ linux/fs/aufs/export.c 2014-04-24 22:11:10.851935747 +0200
9914 + * Copyright (C) 2005-2014 Junjiro R. Okajima
9916 + * This program, aufs is free software; you can redistribute it and/or modify
9917 + * it under the terms of the GNU General Public License as published by
9918 + * the Free Software Foundation; either version 2 of the License, or
9919 + * (at your option) any later version.
9921 + * This program is distributed in the hope that it will be useful,
9922 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9923 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9924 + * GNU General Public License for more details.
9926 + * You should have received a copy of the GNU General Public License
9927 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9934 +#include <linux/exportfs.h>
9935 +#include <linux/fs_struct.h>
9936 +#include <linux/namei.h>
9937 +#include <linux/nsproxy.h>
9938 +#include <linux/random.h>
9939 +#include <linux/writeback.h>
9940 +#include "../fs/mount.h"
9944 +#ifdef CONFIG_AUFS_INO_T_64
9952 +static ino_t decode_ino(__u32 *a)
9956 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
9958 +#ifdef CONFIG_AUFS_INO_T_64
9964 +static void encode_ino(__u32 *a, ino_t ino)
9970 +#ifdef CONFIG_AUFS_INO_T_64
9975 +/* NFS file handle */
9979 +#ifdef CONFIG_AUFS_INO_T_64
9980 + /* support 64bit inode number */
9994 + Fh_dir_ino = Fh_dir_ino1
9997 +static int au_test_anon(struct dentry *dentry)
9999 + /* note: read d_flags without d_lock */
10000 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
10003 +int au_test_nfsd(void)
10006 + struct task_struct *tsk = current;
10007 + char comm[sizeof(tsk->comm)];
10010 + if (tsk->flags & PF_KTHREAD) {
10011 + get_task_comm(comm, tsk);
10012 + ret = !strcmp(comm, "nfsd");
10018 +/* ---------------------------------------------------------------------- */
10019 +/* inode generation external table */
10021 +void au_xigen_inc(struct inode *inode)
10026 + struct super_block *sb;
10027 + struct au_sbinfo *sbinfo;
10029 + sb = inode->i_sb;
10030 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
10032 + sbinfo = au_sbi(sb);
10033 + pos = inode->i_ino;
10034 + pos *= sizeof(igen);
10035 + igen = inode->i_generation + 1;
10036 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
10037 + sizeof(igen), &pos);
10038 + if (sz == sizeof(igen))
10039 + return; /* success */
10041 + if (unlikely(sz >= 0))
10042 + AuIOErr("xigen error (%zd)\n", sz);
10045 +int au_xigen_new(struct inode *inode)
10050 + struct super_block *sb;
10051 + struct au_sbinfo *sbinfo;
10052 + struct file *file;
10055 + /* todo: dirty, at mount time */
10056 + if (inode->i_ino == AUFS_ROOT_INO)
10058 + sb = inode->i_sb;
10059 + SiMustAnyLock(sb);
10060 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
10064 + pos = inode->i_ino;
10065 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
10066 + AuIOErr1("too large i%lld\n", pos);
10069 + pos *= sizeof(inode->i_generation);
10072 + sbinfo = au_sbi(sb);
10073 + file = sbinfo->si_xigen;
10076 + if (vfsub_f_size_read(file)
10077 + < pos + sizeof(inode->i_generation)) {
10078 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
10079 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
10080 + sizeof(inode->i_generation), &pos);
10082 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
10083 + sizeof(inode->i_generation), &pos);
10084 + if (sz == sizeof(inode->i_generation))
10085 + goto out; /* success */
10088 + if (unlikely(sz >= 0)) {
10090 + AuIOErr("xigen error (%zd)\n", sz);
10097 +int au_xigen_set(struct super_block *sb, struct file *base)
10100 + struct au_sbinfo *sbinfo;
10101 + struct file *file;
10103 + SiMustWriteLock(sb);
10105 + sbinfo = au_sbi(sb);
10106 + file = au_xino_create2(base, sbinfo->si_xigen);
10107 + err = PTR_ERR(file);
10108 + if (IS_ERR(file))
10111 + if (sbinfo->si_xigen)
10112 + fput(sbinfo->si_xigen);
10113 + sbinfo->si_xigen = file;
10119 +void au_xigen_clr(struct super_block *sb)
10121 + struct au_sbinfo *sbinfo;
10123 + SiMustWriteLock(sb);
10125 + sbinfo = au_sbi(sb);
10126 + if (sbinfo->si_xigen) {
10127 + fput(sbinfo->si_xigen);
10128 + sbinfo->si_xigen = NULL;
10132 +/* ---------------------------------------------------------------------- */
10134 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
10137 + struct dentry *dentry, *d;
10138 + struct inode *inode;
10139 + unsigned int sigen;
10142 + inode = ilookup(sb, ino);
10146 + dentry = ERR_PTR(-ESTALE);
10147 + sigen = au_sigen(sb);
10148 + if (unlikely(is_bad_inode(inode)
10149 + || IS_DEADDIR(inode)
10150 + || sigen != au_iigen(inode, NULL)))
10154 + if (!dir_ino || S_ISDIR(inode->i_mode))
10155 + dentry = d_find_alias(inode);
10157 + spin_lock(&inode->i_lock);
10158 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
10159 + spin_lock(&d->d_lock);
10160 + if (!au_test_anon(d)
10161 + && d->d_parent->d_inode->i_ino == dir_ino) {
10162 + dentry = dget_dlock(d);
10163 + spin_unlock(&d->d_lock);
10166 + spin_unlock(&d->d_lock);
10168 + spin_unlock(&inode->i_lock);
10170 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
10171 + /* need to refresh */
10179 + AuTraceErrPtr(dentry);
10183 +/* ---------------------------------------------------------------------- */
10185 +/* todo: dirty? */
10186 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
10188 +struct au_compare_mnt_args {
10190 + struct super_block *sb;
10193 + struct vfsmount *mnt;
10196 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
10198 + struct au_compare_mnt_args *a = arg;
10200 + if (mnt->mnt_sb != a->sb)
10202 + a->mnt = mntget(mnt);
10206 +static struct vfsmount *au_mnt_get(struct super_block *sb)
10209 + struct path root;
10210 + struct au_compare_mnt_args args = {
10214 + get_fs_root(current->fs, &root);
10216 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
10217 + rcu_read_unlock();
10220 + AuDebugOn(!args.mnt);
10224 +struct au_nfsd_si_lock {
10225 + unsigned int sigen;
10226 + aufs_bindex_t bindex, br_id;
10227 + unsigned char force_lock;
10230 +static int si_nfsd_read_lock(struct super_block *sb,
10231 + struct au_nfsd_si_lock *nsi_lock)
10234 + aufs_bindex_t bindex;
10236 + si_read_lock(sb, AuLock_FLUSH);
10238 + /* branch id may be wrapped around */
10240 + bindex = au_br_index(sb, nsi_lock->br_id);
10241 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
10242 + goto out; /* success */
10246 + if (!nsi_lock->force_lock)
10247 + si_read_unlock(sb);
10250 + nsi_lock->bindex = bindex;
10254 +struct find_name_by_ino {
10255 + struct dir_context ctx;
10256 + int called, found;
10263 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
10264 + loff_t offset, u64 ino, unsigned int d_type)
10266 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
10270 + if (a->ino != ino)
10273 + memcpy(a->name, name, namelen);
10274 + a->namelen = namelen;
10279 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
10280 + struct au_nfsd_si_lock *nsi_lock)
10282 + struct dentry *dentry, *parent;
10283 + struct file *file;
10284 + struct inode *dir;
10285 + struct find_name_by_ino arg = {
10287 + .actor = au_diractor(find_name_by_ino)
10292 + parent = path->dentry;
10294 + si_read_unlock(parent->d_sb);
10295 + file = vfsub_dentry_open(path, au_dir_roflags);
10296 + dentry = (void *)file;
10297 + if (IS_ERR(file))
10300 + dentry = ERR_PTR(-ENOMEM);
10301 + arg.name = (void *)__get_free_page(GFP_NOFS);
10302 + if (unlikely(!arg.name))
10309 + err = vfsub_iterate_dir(file, &arg.ctx);
10310 + } while (!err && !arg.found && arg.called);
10311 + dentry = ERR_PTR(err);
10312 + if (unlikely(err))
10314 + /* instead of ENOENT */
10315 + dentry = ERR_PTR(-ESTALE);
10319 + /* do not call vfsub_lkup_one() */
10320 + dir = parent->d_inode;
10321 + mutex_lock(&dir->i_mutex);
10322 + dentry = vfsub_lookup_one_len(arg.name, parent, arg.namelen);
10323 + mutex_unlock(&dir->i_mutex);
10324 + AuTraceErrPtr(dentry);
10325 + if (IS_ERR(dentry))
10327 + AuDebugOn(au_test_anon(dentry));
10328 + if (unlikely(!dentry->d_inode)) {
10330 + dentry = ERR_PTR(-ENOENT);
10334 + free_page((unsigned long)arg.name);
10338 + if (unlikely(nsi_lock
10339 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
10340 + if (!IS_ERR(dentry)) {
10342 + dentry = ERR_PTR(-ESTALE);
10344 + AuTraceErrPtr(dentry);
10348 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
10350 + struct au_nfsd_si_lock *nsi_lock)
10352 + struct dentry *dentry;
10353 + struct path path;
10355 + if (dir_ino != AUFS_ROOT_INO) {
10356 + path.dentry = decode_by_ino(sb, dir_ino, 0);
10357 + dentry = path.dentry;
10358 + if (!path.dentry || IS_ERR(path.dentry))
10360 + AuDebugOn(au_test_anon(path.dentry));
10362 + path.dentry = dget(sb->s_root);
10364 + path.mnt = au_mnt_get(sb);
10365 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
10369 + AuTraceErrPtr(dentry);
10373 +/* ---------------------------------------------------------------------- */
10375 +static int h_acceptable(void *expv, struct dentry *dentry)
10380 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
10381 + char *buf, int len, struct super_block *sb)
10385 + struct path path;
10387 + p = d_path(h_rootpath, buf, len);
10392 + path.mnt = h_rootpath->mnt;
10393 + path.dentry = h_parent;
10394 + p = d_path(&path, buf, len);
10400 + path.mnt = au_mnt_get(sb);
10401 + path.dentry = sb->s_root;
10402 + p = d_path(&path, buf, len - strlen(p));
10403 + mntput(path.mnt);
10407 + p[strlen(p)] = '/';
10410 + AuTraceErrPtr(p);
10415 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
10416 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
10418 + struct dentry *dentry, *h_parent, *root;
10419 + struct super_block *h_sb;
10420 + char *pathname, *p;
10421 + struct vfsmount *h_mnt;
10422 + struct au_branch *br;
10424 + struct path path;
10426 + br = au_sbr(sb, nsi_lock->bindex);
10427 + h_mnt = au_br_mnt(br);
10428 + h_sb = h_mnt->mnt_sb;
10429 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
10430 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
10431 + fh_len - Fh_tail, fh[Fh_h_type],
10432 + h_acceptable, /*context*/NULL);
10433 + dentry = h_parent;
10434 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
10435 + AuWarn1("%s decode_fh failed, %ld\n",
10436 + au_sbtype(h_sb), PTR_ERR(h_parent));
10440 + if (unlikely(au_test_anon(h_parent))) {
10441 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
10442 + au_sbtype(h_sb));
10443 + goto out_h_parent;
10446 + dentry = ERR_PTR(-ENOMEM);
10447 + pathname = (void *)__get_free_page(GFP_NOFS);
10448 + if (unlikely(!pathname))
10449 + goto out_h_parent;
10451 + root = sb->s_root;
10452 + path.mnt = h_mnt;
10453 + di_read_lock_parent(root, !AuLock_IR);
10454 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
10455 + di_read_unlock(root, !AuLock_IR);
10456 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
10457 + dentry = (void *)p;
10459 + goto out_pathname;
10461 + si_read_unlock(sb);
10462 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
10463 + dentry = ERR_PTR(err);
10464 + if (unlikely(err))
10467 + dentry = ERR_PTR(-ENOENT);
10468 + AuDebugOn(au_test_anon(path.dentry));
10469 + if (unlikely(!path.dentry->d_inode))
10472 + if (ino != path.dentry->d_inode->i_ino)
10473 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
10475 + dentry = dget(path.dentry);
10480 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
10481 + if (!IS_ERR(dentry)) {
10483 + dentry = ERR_PTR(-ESTALE);
10486 + free_page((unsigned long)pathname);
10490 + AuTraceErrPtr(dentry);
10494 +/* ---------------------------------------------------------------------- */
10496 +static struct dentry *
10497 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
10500 + struct dentry *dentry;
10501 + __u32 *fh = fid->raw;
10502 + struct au_branch *br;
10503 + ino_t ino, dir_ino;
10504 + struct au_nfsd_si_lock nsi_lock = {
10508 + dentry = ERR_PTR(-ESTALE);
10509 + /* it should never happen, but the file handle is unreliable */
10510 + if (unlikely(fh_len < Fh_tail))
10512 + nsi_lock.sigen = fh[Fh_sigen];
10513 + nsi_lock.br_id = fh[Fh_br_id];
10515 + /* branch id may be wrapped around */
10517 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
10519 + nsi_lock.force_lock = 1;
10521 + /* is this inode still cached? */
10522 + ino = decode_ino(fh + Fh_ino);
10523 + /* it should never happen */
10524 + if (unlikely(ino == AUFS_ROOT_INO))
10527 + dir_ino = decode_ino(fh + Fh_dir_ino);
10528 + dentry = decode_by_ino(sb, ino, dir_ino);
10529 + if (IS_ERR(dentry))
10534 + /* is the parent dir cached? */
10535 + br = au_sbr(sb, nsi_lock.bindex);
10536 + atomic_inc(&br->br_count);
10537 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
10538 + if (IS_ERR(dentry))
10543 + /* lookup path */
10544 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
10545 + if (IS_ERR(dentry))
10547 + if (unlikely(!dentry))
10548 + /* todo?: make it ESTALE */
10552 + if (!au_digen_test(dentry, au_sigen(sb))
10553 + && dentry->d_inode->i_generation == fh[Fh_igen])
10554 + goto out_unlock; /* success */
10557 + dentry = ERR_PTR(-ESTALE);
10560 + atomic_dec(&br->br_count);
10561 + si_read_unlock(sb);
10563 + AuTraceErrPtr(dentry);
10567 +#if 0 /* reserved for future use */
10568 +/* support subtreecheck option */
10569 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
10570 + int fh_len, int fh_type)
10572 + struct dentry *parent;
10573 + __u32 *fh = fid->raw;
10576 + dir_ino = decode_ino(fh + Fh_dir_ino);
10577 + parent = decode_by_ino(sb, dir_ino, 0);
10578 + if (IS_ERR(parent))
10581 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
10582 + dir_ino, fh, fh_len);
10585 + AuTraceErrPtr(parent);
10590 +/* ---------------------------------------------------------------------- */
10592 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
10593 + struct inode *dir)
10596 + aufs_bindex_t bindex;
10597 + struct super_block *sb, *h_sb;
10598 + struct dentry *dentry, *parent, *h_parent;
10599 + struct inode *h_dir;
10600 + struct au_branch *br;
10603 + if (unlikely(*max_len <= Fh_tail)) {
10604 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
10608 + err = FILEID_ROOT;
10609 + if (inode->i_ino == AUFS_ROOT_INO) {
10610 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
10615 + sb = inode->i_sb;
10616 + err = si_read_lock(sb, AuLock_FLUSH);
10617 + if (unlikely(err))
10620 +#ifdef CONFIG_AUFS_DEBUG
10621 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
10622 + AuWarn1("NFS-exporting requires xino\n");
10626 + ii_read_lock_child(inode);
10627 + bindex = au_ibstart(inode);
10629 + dentry = d_find_alias(inode);
10630 + if (unlikely(!dentry))
10632 + AuDebugOn(au_test_anon(dentry));
10633 + parent = dget_parent(dentry);
10635 + if (unlikely(!parent))
10637 + dir = parent->d_inode;
10640 + ii_read_lock_parent(dir);
10641 + h_dir = au_h_iptr(dir, bindex);
10642 + ii_read_unlock(dir);
10643 + if (unlikely(!h_dir))
10645 + h_parent = d_find_alias(h_dir);
10646 + if (unlikely(!h_parent))
10647 + goto out_hparent;
10650 + br = au_sbr(sb, bindex);
10651 + h_sb = au_br_sb(br);
10652 + if (unlikely(!h_sb->s_export_op)) {
10653 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
10654 + goto out_hparent;
10657 + fh[Fh_br_id] = br->br_id;
10658 + fh[Fh_sigen] = au_sigen(sb);
10659 + encode_ino(fh + Fh_ino, inode->i_ino);
10660 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
10661 + fh[Fh_igen] = inode->i_generation;
10663 + *max_len -= Fh_tail;
10664 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
10666 + /*connectable or subtreecheck*/0);
10667 + err = fh[Fh_h_type];
10668 + *max_len += Fh_tail;
10669 + /* todo: macros? */
10670 + if (err != FILEID_INVALID)
10673 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
10680 + ii_read_unlock(inode);
10681 + si_read_unlock(sb);
10683 + if (unlikely(err < 0))
10684 + err = FILEID_INVALID;
10688 +/* ---------------------------------------------------------------------- */
10690 +static int aufs_commit_metadata(struct inode *inode)
10693 + aufs_bindex_t bindex;
10694 + struct super_block *sb;
10695 + struct inode *h_inode;
10696 + int (*f)(struct inode *inode);
10698 + sb = inode->i_sb;
10699 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
10700 + ii_write_lock_child(inode);
10701 + bindex = au_ibstart(inode);
10702 + AuDebugOn(bindex < 0);
10703 + h_inode = au_h_iptr(inode, bindex);
10705 + f = h_inode->i_sb->s_export_op->commit_metadata;
10707 + err = f(h_inode);
10709 + struct writeback_control wbc = {
10710 + .sync_mode = WB_SYNC_ALL,
10711 + .nr_to_write = 0 /* metadata only */
10714 + err = sync_inode(h_inode, &wbc);
10717 + au_cpup_attr_timesizes(inode);
10718 + ii_write_unlock(inode);
10719 + si_read_unlock(sb);
10723 +/* ---------------------------------------------------------------------- */
10725 +static struct export_operations aufs_export_op = {
10726 + .fh_to_dentry = aufs_fh_to_dentry,
10727 + /* .fh_to_parent = aufs_fh_to_parent, */
10728 + .encode_fh = aufs_encode_fh,
10729 + .commit_metadata = aufs_commit_metadata
10732 +void au_export_init(struct super_block *sb)
10734 + struct au_sbinfo *sbinfo;
10737 + sb->s_export_op = &aufs_export_op;
10738 + sbinfo = au_sbi(sb);
10739 + sbinfo->si_xigen = NULL;
10740 + get_random_bytes(&u, sizeof(u));
10741 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
10742 + atomic_set(&sbinfo->si_xigen_next, u);
10744 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
10745 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
10746 +++ linux/fs/aufs/file.c 2014-04-24 22:11:10.851935747 +0200
10749 + * Copyright (C) 2005-2014 Junjiro R. Okajima
10751 + * This program, aufs is free software; you can redistribute it and/or modify
10752 + * it under the terms of the GNU General Public License as published by
10753 + * the Free Software Foundation; either version 2 of the License, or
10754 + * (at your option) any later version.
10756 + * This program is distributed in the hope that it will be useful,
10757 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10758 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10759 + * GNU General Public License for more details.
10761 + * You should have received a copy of the GNU General Public License
10762 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10766 + * handling file/dir, and address_space operation
10769 +#ifdef CONFIG_AUFS_DEBUG
10770 +#include <linux/migrate.h>
10772 +#include <linux/pagemap.h>
10775 +/* drop flags for writing */
10776 +unsigned int au_file_roflags(unsigned int flags)
10778 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
10779 + flags |= O_RDONLY | O_NOATIME;
10783 +/* common functions to regular file and dir */
10784 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
10785 + struct file *file, int force_wr)
10787 + struct file *h_file;
10788 + struct dentry *h_dentry;
10789 + struct inode *h_inode;
10790 + struct super_block *sb;
10791 + struct au_branch *br;
10792 + struct path h_path;
10793 + int err, exec_flag;
10795 + /* a race condition can happen between open and unlink/rmdir */
10796 + h_file = ERR_PTR(-ENOENT);
10797 + h_dentry = au_h_dptr(dentry, bindex);
10798 + if (au_test_nfsd() && !h_dentry)
10800 + h_inode = h_dentry->d_inode;
10801 + if (au_test_nfsd() && !h_inode)
10803 + spin_lock(&h_dentry->d_lock);
10804 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
10806 + /* || !dentry->d_inode->i_nlink */
10808 + spin_unlock(&h_dentry->d_lock);
10809 + if (unlikely(err))
10812 + sb = dentry->d_sb;
10813 + br = au_sbr(sb, bindex);
10814 + h_file = ERR_PTR(-EACCES);
10815 + exec_flag = flags & __FMODE_EXEC;
10816 + if (exec_flag && (au_br_mnt(br)->mnt_flags & MNT_NOEXEC))
10819 + /* drop flags for writing */
10820 + if (au_test_ro(sb, bindex, dentry->d_inode)) {
10821 + if (force_wr && !(flags & O_WRONLY))
10823 + flags = au_file_roflags(flags);
10825 + h_file = ERR_PTR(-EROFS);
10826 + flags = au_file_roflags(flags);
10827 + if (unlikely(vfsub_native_ro(h_inode)
10828 + || IS_APPEND(h_inode)))
10830 + flags &= ~O_ACCMODE;
10831 + flags |= O_WRONLY;
10834 + flags &= ~O_CREAT;
10835 + atomic_inc(&br->br_count);
10836 + h_path.dentry = h_dentry;
10837 + h_path.mnt = au_br_mnt(br);
10838 + if (!au_special_file(h_inode->i_mode))
10839 + h_file = vfsub_dentry_open(&h_path, flags);
10841 + /* this block depends upon the configuration */
10842 + di_read_unlock(dentry, AuLock_IR);
10843 + fi_write_unlock(file);
10844 + si_read_unlock(sb);
10845 + h_file = vfsub_dentry_open(&h_path, flags);
10846 + si_noflush_read_lock(sb);
10847 + fi_write_lock(file);
10848 + di_read_lock_child(dentry, AuLock_IR);
10850 + if (IS_ERR(h_file))
10854 + err = deny_write_access(h_file);
10855 + if (unlikely(err)) {
10857 + h_file = ERR_PTR(err);
10861 + fsnotify_open(h_file);
10862 + goto out; /* success */
10865 + atomic_dec(&br->br_count);
10870 +int au_do_open(struct file *file, int (*open)(struct file *file, int flags),
10871 + struct au_fidir *fidir)
10874 + struct dentry *dentry;
10876 + err = au_finfo_init(file, fidir);
10877 + if (unlikely(err))
10880 + dentry = file->f_dentry;
10881 + di_read_lock_child(dentry, AuLock_IR);
10882 + err = open(file, vfsub_file_flags(file));
10883 + di_read_unlock(dentry, AuLock_IR);
10885 + fi_write_unlock(file);
10886 + if (unlikely(err)) {
10887 + au_fi(file)->fi_hdir = NULL;
10888 + au_finfo_fin(file);
10895 +int au_reopen_nondir(struct file *file)
10898 + aufs_bindex_t bstart;
10899 + struct dentry *dentry;
10900 + struct file *h_file, *h_file_tmp;
10902 + dentry = file->f_dentry;
10903 + AuDebugOn(au_special_file(dentry->d_inode->i_mode));
10904 + bstart = au_dbstart(dentry);
10905 + h_file_tmp = NULL;
10906 + if (au_fbstart(file) == bstart) {
10907 + h_file = au_hf_top(file);
10908 + if (file->f_mode == h_file->f_mode)
10909 + return 0; /* success */
10910 + h_file_tmp = h_file;
10911 + get_file(h_file_tmp);
10912 + au_set_h_fptr(file, bstart, NULL);
10914 + AuDebugOn(au_fi(file)->fi_hdir);
10917 + * file exists on both of rw and ro
10918 + * open --> dbstart and fbstart are both 0
10919 + * prepend a branch as rw, "rw" become ro
10921 + * delete the top branch, "rw" becomes rw again
10922 + * --> dbstart is 1, fbstart is still 0
10923 + * write --> fbstart is 0 but dbstart is 1
10925 + /* AuDebugOn(au_fbstart(file) < bstart); */
10927 + h_file = au_h_open(dentry, bstart, vfsub_file_flags(file) & ~O_TRUNC,
10928 + file, /*force_wr*/0);
10929 + err = PTR_ERR(h_file);
10930 + if (IS_ERR(h_file)) {
10931 + if (h_file_tmp) {
10932 + atomic_inc(&au_sbr(dentry->d_sb, bstart)->br_count);
10933 + au_set_h_fptr(file, bstart, h_file_tmp);
10934 + h_file_tmp = NULL;
10936 + goto out; /* todo: close all? */
10940 + au_set_fbstart(file, bstart);
10941 + au_set_h_fptr(file, bstart, h_file);
10942 + au_update_figen(file);
10943 + /* todo: necessary? */
10944 + /* file->f_ra = h_file->f_ra; */
10948 + fput(h_file_tmp);
10952 +/* ---------------------------------------------------------------------- */
10954 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
10955 + struct dentry *hi_wh)
10958 + aufs_bindex_t bstart;
10959 + struct au_dinfo *dinfo;
10960 + struct dentry *h_dentry;
10961 + struct au_hdentry *hdp;
10963 + dinfo = au_di(file->f_dentry);
10964 + AuRwMustWriteLock(&dinfo->di_rwsem);
10966 + bstart = dinfo->di_bstart;
10967 + dinfo->di_bstart = btgt;
10968 + hdp = dinfo->di_hdentry;
10969 + h_dentry = hdp[0 + btgt].hd_dentry;
10970 + hdp[0 + btgt].hd_dentry = hi_wh;
10971 + err = au_reopen_nondir(file);
10972 + hdp[0 + btgt].hd_dentry = h_dentry;
10973 + dinfo->di_bstart = bstart;
10978 +static int au_ready_to_write_wh(struct file *file, loff_t len,
10979 + aufs_bindex_t bcpup, struct au_pin *pin)
10982 + struct inode *inode, *h_inode;
10983 + struct dentry *h_dentry, *hi_wh;
10984 + struct au_cp_generic cpg = {
10985 + .dentry = file->f_dentry,
10992 + au_update_dbstart(cpg.dentry);
10993 + inode = cpg.dentry->d_inode;
10995 + if (au_dbstart(cpg.dentry) <= bcpup
10996 + && au_dbend(cpg.dentry) >= bcpup) {
10997 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
10999 + h_inode = h_dentry->d_inode;
11001 + hi_wh = au_hi_wh(inode, bcpup);
11002 + if (!hi_wh && !h_inode)
11003 + err = au_sio_cpup_wh(&cpg, file);
11005 + /* already copied-up after unlink */
11006 + err = au_reopen_wh(file, bcpup, hi_wh);
11009 + && inode->i_nlink > 1
11010 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
11011 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
11017 + * prepare the @file for writing.
11019 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
11022 + aufs_bindex_t dbstart;
11023 + struct dentry *parent, *h_dentry;
11024 + struct inode *inode;
11025 + struct super_block *sb;
11026 + struct file *h_file;
11027 + struct au_cp_generic cpg = {
11028 + .dentry = file->f_dentry,
11033 + .flags = AuCpup_DTIME
11036 + sb = cpg.dentry->d_sb;
11037 + inode = cpg.dentry->d_inode;
11038 + AuDebugOn(au_special_file(inode->i_mode));
11039 + cpg.bsrc = au_fbstart(file);
11040 + err = au_test_ro(sb, cpg.bsrc, inode);
11041 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
11042 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
11047 + /* need to cpup or reopen */
11048 + parent = dget_parent(cpg.dentry);
11049 + di_write_lock_parent(parent);
11050 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
11052 + if (unlikely(err < 0))
11056 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
11057 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
11058 + if (unlikely(err))
11062 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
11063 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
11064 + if (unlikely(err))
11067 + h_dentry = au_hf_top(file)->f_dentry;
11068 + dbstart = au_dbstart(cpg.dentry);
11069 + if (dbstart <= cpg.bdst) {
11070 + h_dentry = au_h_dptr(cpg.dentry, cpg.bdst);
11071 + AuDebugOn(!h_dentry);
11072 + cpg.bsrc = cpg.bdst;
11075 + if (dbstart <= cpg.bdst /* just reopen */
11076 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
11078 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
11079 + if (IS_ERR(h_file))
11080 + err = PTR_ERR(h_file);
11082 + di_downgrade_lock(parent, AuLock_IR);
11083 + if (dbstart > cpg.bdst)
11084 + err = au_sio_cpup_simple(&cpg);
11086 + err = au_reopen_nondir(file);
11087 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
11089 + } else { /* copyup as wh and reopen */
11091 + * since writable hfsplus branch is not supported,
11092 + * h_open_pre/post() are unnecessary.
11094 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
11095 + di_downgrade_lock(parent, AuLock_IR);
11099 + au_pin_set_parent_lflag(pin, /*lflag*/0);
11100 + goto out_dput; /* success */
11106 + di_downgrade_lock(parent, AuLock_IR);
11108 + di_read_unlock(parent, AuLock_IR);
11115 +/* ---------------------------------------------------------------------- */
11117 +int au_do_flush(struct file *file, fl_owner_t id,
11118 + int (*flush)(struct file *file, fl_owner_t id))
11121 + struct super_block *sb;
11122 + struct inode *inode;
11124 + inode = file_inode(file);
11125 + sb = inode->i_sb;
11126 + si_noflush_read_lock(sb);
11127 + fi_read_lock(file);
11128 + ii_read_lock_child(inode);
11130 + err = flush(file, id);
11131 + au_cpup_attr_timesizes(inode);
11133 + ii_read_unlock(inode);
11134 + fi_read_unlock(file);
11135 + si_read_unlock(sb);
11139 +/* ---------------------------------------------------------------------- */
11141 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
11144 + struct au_pin pin;
11145 + struct au_finfo *finfo;
11146 + struct dentry *parent, *hi_wh;
11147 + struct inode *inode;
11148 + struct super_block *sb;
11149 + struct au_cp_generic cpg = {
11150 + .dentry = file->f_dentry,
11155 + .flags = AuCpup_DTIME
11158 + FiMustWriteLock(file);
11161 + finfo = au_fi(file);
11162 + sb = cpg.dentry->d_sb;
11163 + inode = cpg.dentry->d_inode;
11164 + cpg.bdst = au_ibstart(inode);
11165 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
11168 + parent = dget_parent(cpg.dentry);
11169 + if (au_test_ro(sb, cpg.bdst, inode)) {
11170 + di_read_lock_parent(parent, !AuLock_IR);
11171 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
11173 + di_read_unlock(parent, !AuLock_IR);
11174 + if (unlikely(err < 0))
11179 + di_read_lock_parent(parent, AuLock_IR);
11180 + hi_wh = au_hi_wh(inode, cpg.bdst);
11181 + if (!S_ISDIR(inode->i_mode)
11182 + && au_opt_test(au_mntflags(sb), PLINK)
11183 + && au_plink_test(inode)
11184 + && !d_unhashed(cpg.dentry)
11185 + && cpg.bdst < au_dbstart(cpg.dentry)) {
11186 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
11187 + if (unlikely(err))
11190 + /* always superio. */
11191 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
11192 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
11194 + err = au_sio_cpup_simple(&cpg);
11197 + } else if (hi_wh) {
11198 + /* already copied-up after unlink */
11199 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
11200 + *need_reopen = 0;
11204 + di_read_unlock(parent, AuLock_IR);
11211 +static void au_do_refresh_dir(struct file *file)
11213 + aufs_bindex_t bindex, bend, new_bindex, brid;
11214 + struct au_hfile *p, tmp, *q;
11215 + struct au_finfo *finfo;
11216 + struct super_block *sb;
11217 + struct au_fidir *fidir;
11219 + FiMustWriteLock(file);
11221 + sb = file->f_dentry->d_sb;
11222 + finfo = au_fi(file);
11223 + fidir = finfo->fi_hdir;
11224 + AuDebugOn(!fidir);
11225 + p = fidir->fd_hfile + finfo->fi_btop;
11226 + brid = p->hf_br->br_id;
11227 + bend = fidir->fd_bbot;
11228 + for (bindex = finfo->fi_btop; bindex <= bend; bindex++, p++) {
11232 + new_bindex = au_br_index(sb, p->hf_br->br_id);
11233 + if (new_bindex == bindex)
11235 + if (new_bindex < 0) {
11236 + au_set_h_fptr(file, bindex, NULL);
11240 + /* swap two lower inode, and loop again */
11241 + q = fidir->fd_hfile + new_bindex;
11245 + if (tmp.hf_file) {
11251 + p = fidir->fd_hfile;
11252 + if (!au_test_mmapped(file) && !d_unlinked(file->f_dentry)) {
11253 + bend = au_sbend(sb);
11254 + for (finfo->fi_btop = 0; finfo->fi_btop <= bend;
11255 + finfo->fi_btop++, p++)
11256 + if (p->hf_file) {
11257 + if (file_inode(p->hf_file))
11260 + au_hfput(p, file);
11263 + bend = au_br_index(sb, brid);
11264 + for (finfo->fi_btop = 0; finfo->fi_btop < bend;
11265 + finfo->fi_btop++, p++)
11267 + au_hfput(p, file);
11268 + bend = au_sbend(sb);
11271 + p = fidir->fd_hfile + bend;
11272 + for (fidir->fd_bbot = bend; fidir->fd_bbot >= finfo->fi_btop;
11273 + fidir->fd_bbot--, p--)
11274 + if (p->hf_file) {
11275 + if (file_inode(p->hf_file))
11278 + au_hfput(p, file);
11280 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
11284 + * after branch manipulating, refresh the file.
11286 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
11288 + int err, need_reopen;
11289 + aufs_bindex_t bend, bindex;
11290 + struct dentry *dentry;
11291 + struct au_finfo *finfo;
11292 + struct au_hfile *hfile;
11294 + dentry = file->f_dentry;
11295 + finfo = au_fi(file);
11296 + if (!finfo->fi_hdir) {
11297 + hfile = &finfo->fi_htop;
11298 + AuDebugOn(!hfile->hf_file);
11299 + bindex = au_br_index(dentry->d_sb, hfile->hf_br->br_id);
11300 + AuDebugOn(bindex < 0);
11301 + if (bindex != finfo->fi_btop)
11302 + au_set_fbstart(file, bindex);
11304 + err = au_fidir_realloc(finfo, au_sbend(dentry->d_sb) + 1);
11305 + if (unlikely(err))
11307 + au_do_refresh_dir(file);
11312 + if (!au_test_mmapped(file))
11313 + err = au_file_refresh_by_inode(file, &need_reopen);
11314 + if (!err && need_reopen && !d_unlinked(dentry))
11315 + err = reopen(file);
11317 + au_update_figen(file);
11318 + goto out; /* success */
11321 + /* error, close all lower files */
11322 + if (finfo->fi_hdir) {
11323 + bend = au_fbend_dir(file);
11324 + for (bindex = au_fbstart(file); bindex <= bend; bindex++)
11325 + au_set_h_fptr(file, bindex, NULL);
11332 +/* common function to regular file and dir */
11333 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
11337 + unsigned int sigen, figen;
11338 + aufs_bindex_t bstart;
11339 + unsigned char pseudo_link;
11340 + struct dentry *dentry;
11341 + struct inode *inode;
11344 + dentry = file->f_dentry;
11345 + inode = dentry->d_inode;
11346 + AuDebugOn(au_special_file(inode->i_mode));
11347 + sigen = au_sigen(dentry->d_sb);
11348 + fi_write_lock(file);
11349 + figen = au_figen(file);
11350 + di_write_lock_child(dentry);
11351 + bstart = au_dbstart(dentry);
11352 + pseudo_link = (bstart != au_ibstart(inode));
11353 + if (sigen == figen && !pseudo_link && au_fbstart(file) == bstart) {
11355 + di_downgrade_lock(dentry, AuLock_IR);
11356 + fi_downgrade_lock(file);
11358 + goto out; /* success */
11361 + AuDbg("sigen %d, figen %d\n", sigen, figen);
11362 + if (au_digen_test(dentry, sigen)) {
11363 + err = au_reval_dpath(dentry, sigen);
11364 + AuDebugOn(!err && au_digen_test(dentry, sigen));
11368 + err = refresh_file(file, reopen);
11371 + di_downgrade_lock(dentry, AuLock_IR);
11372 + fi_downgrade_lock(file);
11375 + di_write_unlock(dentry);
11376 + fi_write_unlock(file);
11383 +/* ---------------------------------------------------------------------- */
11385 +/* cf. aufs_nopage() */
11386 +/* for madvise(2) */
11387 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
11389 + unlock_page(page);
11393 +/* it will never be called, but necessary to support O_DIRECT */
11394 +static ssize_t aufs_direct_IO(int rw, struct kiocb *iocb,
11395 + const struct iovec *iov, loff_t offset,
11396 + unsigned long nr_segs)
11397 +{ BUG(); return 0; }
11400 + * it will never be called, but madvise and fadvise behaves differently
11401 + * when get_xip_mem is defined
11403 +static int aufs_get_xip_mem(struct address_space *mapping, pgoff_t pgoff,
11404 + int create, void **kmem, unsigned long *pfn)
11405 +{ BUG(); return 0; }
11407 +/* they will never be called. */
11408 +#ifdef CONFIG_AUFS_DEBUG
11409 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
11410 + loff_t pos, unsigned len, unsigned flags,
11411 + struct page **pagep, void **fsdata)
11412 +{ AuUnsupport(); return 0; }
11413 +static int aufs_write_end(struct file *file, struct address_space *mapping,
11414 + loff_t pos, unsigned len, unsigned copied,
11415 + struct page *page, void *fsdata)
11416 +{ AuUnsupport(); return 0; }
11417 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
11418 +{ AuUnsupport(); return 0; }
11420 +static int aufs_set_page_dirty(struct page *page)
11421 +{ AuUnsupport(); return 0; }
11422 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
11423 + unsigned int length)
11424 +{ AuUnsupport(); }
11425 +static int aufs_releasepage(struct page *page, gfp_t gfp)
11426 +{ AuUnsupport(); return 0; }
11427 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
11428 + struct page *page, enum migrate_mode mode)
11429 +{ AuUnsupport(); return 0; }
11430 +static int aufs_launder_page(struct page *page)
11431 +{ AuUnsupport(); return 0; }
11432 +static int aufs_is_partially_uptodate(struct page *page,
11433 + read_descriptor_t *desc,
11434 + unsigned long from)
11435 +{ AuUnsupport(); return 0; }
11436 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
11438 +{ AuUnsupport(); }
11439 +static int aufs_error_remove_page(struct address_space *mapping,
11440 + struct page *page)
11441 +{ AuUnsupport(); return 0; }
11442 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
11444 +{ AuUnsupport(); return 0; }
11445 +static void aufs_swap_deactivate(struct file *file)
11446 +{ AuUnsupport(); }
11447 +#endif /* CONFIG_AUFS_DEBUG */
11449 +const struct address_space_operations aufs_aop = {
11450 + .readpage = aufs_readpage,
11451 + .direct_IO = aufs_direct_IO,
11452 + .get_xip_mem = aufs_get_xip_mem,
11453 +#ifdef CONFIG_AUFS_DEBUG
11454 + .writepage = aufs_writepage,
11455 + /* no writepages, because of writepage */
11456 + .set_page_dirty = aufs_set_page_dirty,
11457 + /* no readpages, because of readpage */
11458 + .write_begin = aufs_write_begin,
11459 + .write_end = aufs_write_end,
11460 + /* no bmap, no block device */
11461 + .invalidatepage = aufs_invalidatepage,
11462 + .releasepage = aufs_releasepage,
11463 + .migratepage = aufs_migratepage,
11464 + .launder_page = aufs_launder_page,
11465 + .is_partially_uptodate = aufs_is_partially_uptodate,
11466 + .is_dirty_writeback = aufs_is_dirty_writeback,
11467 + .error_remove_page = aufs_error_remove_page,
11468 + .swap_activate = aufs_swap_activate,
11469 + .swap_deactivate = aufs_swap_deactivate
11470 +#endif /* CONFIG_AUFS_DEBUG */
11472 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
11473 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
11474 +++ linux/fs/aufs/file.h 2014-04-24 22:11:10.851935747 +0200
11477 + * Copyright (C) 2005-2014 Junjiro R. Okajima
11479 + * This program, aufs is free software; you can redistribute it and/or modify
11480 + * it under the terms of the GNU General Public License as published by
11481 + * the Free Software Foundation; either version 2 of the License, or
11482 + * (at your option) any later version.
11484 + * This program is distributed in the hope that it will be useful,
11485 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11486 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11487 + * GNU General Public License for more details.
11489 + * You should have received a copy of the GNU General Public License
11490 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11494 + * file operations
11497 +#ifndef __AUFS_FILE_H__
11498 +#define __AUFS_FILE_H__
11502 +#include <linux/file.h>
11503 +#include <linux/fs.h>
11504 +#include <linux/poll.h>
11505 +#include "rwsem.h"
11509 + struct file *hf_file;
11510 + struct au_branch *hf_br;
11515 + aufs_bindex_t fd_bbot;
11516 + aufs_bindex_t fd_nent;
11517 + struct au_vdir *fd_vdir_cache;
11518 + struct au_hfile fd_hfile[];
11521 +static inline int au_fidir_sz(int nent)
11523 + AuDebugOn(nent < 0);
11524 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
11528 + atomic_t fi_generation;
11530 + struct au_rwsem fi_rwsem;
11531 + aufs_bindex_t fi_btop;
11533 + /* do not union them */
11534 + struct { /* for non-dir */
11535 + struct au_hfile fi_htop;
11536 + atomic_t fi_mmapped;
11538 + struct au_fidir *fi_hdir; /* for dir only */
11540 + struct hlist_node fi_hlist;
11541 + struct file *fi_file; /* very ugly */
11542 +} ____cacheline_aligned_in_smp;
11544 +/* ---------------------------------------------------------------------- */
11547 +extern const struct address_space_operations aufs_aop;
11548 +unsigned int au_file_roflags(unsigned int flags);
11549 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
11550 + struct file *file, int force_wr);
11551 +int au_do_open(struct file *file, int (*open)(struct file *file, int flags),
11552 + struct au_fidir *fidir);
11553 +int au_reopen_nondir(struct file *file);
11555 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
11556 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
11558 +int au_do_flush(struct file *file, fl_owner_t id,
11559 + int (*flush)(struct file *file, fl_owner_t id));
11562 +#ifdef CONFIG_AUFS_POLL
11563 +unsigned int aufs_poll(struct file *file, poll_table *wait);
11566 +#ifdef CONFIG_AUFS_BR_HFSPLUS
11568 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
11570 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
11571 + struct file *h_file);
11574 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
11580 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
11581 + struct file *h_file);
11585 +extern const struct file_operations aufs_file_fop;
11586 +int au_do_open_nondir(struct file *file, int flags);
11587 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
11589 +#ifdef CONFIG_AUFS_SP_IATTR
11591 +struct au_finfo *au_fi_sp(struct file *file);
11592 +int au_special_file(umode_t mode);
11593 +void au_init_special_fop(struct inode *inode, umode_t mode, dev_t rdev);
11595 +static inline struct au_finfo *au_fi_sp(struct file *file)
11599 +AuStubInt0(au_special_file, umode_t mode)
11600 +static inline void au_init_special_fop(struct inode *inode, umode_t mode,
11603 + init_special_inode(inode, mode, rdev);
11608 +void au_hfput(struct au_hfile *hf, struct file *file);
11609 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
11610 + struct file *h_file);
11612 +void au_update_figen(struct file *file);
11613 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
11614 +int au_fidir_realloc(struct au_finfo *finfo, int nbr);
11616 +void au_fi_init_once(void *_fi);
11617 +void au_finfo_fin(struct file *file);
11618 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
11621 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
11622 +#ifdef CONFIG_COMPAT
11623 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
11624 + unsigned long arg);
11625 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
11626 + unsigned long arg);
11629 +/* ---------------------------------------------------------------------- */
11631 +static inline struct au_finfo *au_fi(struct file *file)
11633 + struct au_finfo *finfo;
11635 + finfo = au_fi_sp(file);
11637 + finfo = file->private_data;
11641 +/* ---------------------------------------------------------------------- */
11644 + * fi_read_lock, fi_write_lock,
11645 + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock
11647 +AuSimpleRwsemFuncs(fi, struct file *f, &au_fi(f)->fi_rwsem);
11649 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
11650 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
11651 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
11653 +/* ---------------------------------------------------------------------- */
11655 +/* todo: hard/soft set? */
11656 +static inline aufs_bindex_t au_fbstart(struct file *file)
11658 + FiMustAnyLock(file);
11659 + return au_fi(file)->fi_btop;
11662 +static inline aufs_bindex_t au_fbend_dir(struct file *file)
11664 + FiMustAnyLock(file);
11665 + AuDebugOn(!au_fi(file)->fi_hdir);
11666 + return au_fi(file)->fi_hdir->fd_bbot;
11669 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
11671 + FiMustAnyLock(file);
11672 + AuDebugOn(!au_fi(file)->fi_hdir);
11673 + return au_fi(file)->fi_hdir->fd_vdir_cache;
11676 +static inline void au_set_fbstart(struct file *file, aufs_bindex_t bindex)
11678 + FiMustWriteLock(file);
11679 + au_fi(file)->fi_btop = bindex;
11682 +static inline void au_set_fbend_dir(struct file *file, aufs_bindex_t bindex)
11684 + FiMustWriteLock(file);
11685 + AuDebugOn(!au_fi(file)->fi_hdir);
11686 + au_fi(file)->fi_hdir->fd_bbot = bindex;
11689 +static inline void au_set_fvdir_cache(struct file *file,
11690 + struct au_vdir *vdir_cache)
11692 + FiMustWriteLock(file);
11693 + AuDebugOn(!au_fi(file)->fi_hdir);
11694 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
11697 +static inline struct file *au_hf_top(struct file *file)
11699 + FiMustAnyLock(file);
11700 + AuDebugOn(au_fi(file)->fi_hdir);
11701 + return au_fi(file)->fi_htop.hf_file;
11704 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
11706 + FiMustAnyLock(file);
11707 + AuDebugOn(!au_fi(file)->fi_hdir);
11708 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
11711 +/* todo: memory barrier? */
11712 +static inline unsigned int au_figen(struct file *f)
11714 + return atomic_read(&au_fi(f)->fi_generation);
11717 +static inline void au_set_mmapped(struct file *f)
11719 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
11721 + pr_warn("fi_mmapped wrapped around\n");
11722 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
11726 +static inline void au_unset_mmapped(struct file *f)
11728 + atomic_dec(&au_fi(f)->fi_mmapped);
11731 +static inline int au_test_mmapped(struct file *f)
11733 + return atomic_read(&au_fi(f)->fi_mmapped);
11736 +/* customize vma->vm_file */
11738 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
11739 + struct file *file)
11743 + f = vma->vm_file;
11745 + vma->vm_file = file;
11750 +#define AuDbgVmRegion(file, vma) do {} while (0)
11752 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
11753 + struct file *file)
11755 + au_do_vm_file_reset(vma, file);
11758 +#define AuDbgVmRegion(file, vma) \
11759 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
11761 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
11762 + struct file *file)
11766 + au_do_vm_file_reset(vma, file);
11767 + f = vma->vm_region->vm_file;
11769 + vma->vm_region->vm_file = file;
11772 +#endif /* CONFIG_MMU */
11774 +/* handle vma->vm_prfile */
11775 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
11776 + struct file *file)
11779 + vma->vm_prfile = file;
11780 +#ifndef CONFIG_MMU
11782 + vma->vm_region->vm_prfile = file;
11786 +#endif /* __KERNEL__ */
11787 +#endif /* __AUFS_FILE_H__ */
11788 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
11789 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
11790 +++ linux/fs/aufs/finfo.c 2014-04-24 22:11:10.851935747 +0200
11793 + * Copyright (C) 2005-2014 Junjiro R. Okajima
11795 + * This program, aufs is free software; you can redistribute it and/or modify
11796 + * it under the terms of the GNU General Public License as published by
11797 + * the Free Software Foundation; either version 2 of the License, or
11798 + * (at your option) any later version.
11800 + * This program is distributed in the hope that it will be useful,
11801 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11802 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11803 + * GNU General Public License for more details.
11805 + * You should have received a copy of the GNU General Public License
11806 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11810 + * file private data
11815 +void au_hfput(struct au_hfile *hf, struct file *file)
11817 + /* todo: direct access f_flags */
11818 + if (vfsub_file_flags(file) & __FMODE_EXEC)
11819 + allow_write_access(hf->hf_file);
11820 + fput(hf->hf_file);
11821 + hf->hf_file = NULL;
11822 + atomic_dec(&hf->hf_br->br_count);
11823 + hf->hf_br = NULL;
11826 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
11828 + struct au_finfo *finfo = au_fi(file);
11829 + struct au_hfile *hf;
11830 + struct au_fidir *fidir;
11832 + fidir = finfo->fi_hdir;
11834 + AuDebugOn(finfo->fi_btop != bindex);
11835 + hf = &finfo->fi_htop;
11837 + hf = fidir->fd_hfile + bindex;
11839 + if (hf && hf->hf_file)
11840 + au_hfput(hf, file);
11842 + FiMustWriteLock(file);
11843 + hf->hf_file = val;
11844 + hf->hf_br = au_sbr(file->f_dentry->d_sb, bindex);
11848 +void au_update_figen(struct file *file)
11850 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_dentry));
11851 + /* smp_mb(); */ /* atomic_set */
11854 +/* ---------------------------------------------------------------------- */
11856 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
11858 + struct au_fidir *fidir;
11861 + nbr = au_sbend(sb) + 1;
11863 + nbr = 2; /* initial allocate for 2 branches */
11864 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
11866 + fidir->fd_bbot = -1;
11867 + fidir->fd_nent = nbr;
11868 + fidir->fd_vdir_cache = NULL;
11874 +int au_fidir_realloc(struct au_finfo *finfo, int nbr)
11877 + struct au_fidir *fidir, *p;
11879 + AuRwMustWriteLock(&finfo->fi_rwsem);
11880 + fidir = finfo->fi_hdir;
11881 + AuDebugOn(!fidir);
11884 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
11887 + p->fd_nent = nbr;
11888 + finfo->fi_hdir = p;
11895 +/* ---------------------------------------------------------------------- */
11897 +void au_finfo_fin(struct file *file)
11899 + struct au_finfo *finfo;
11901 + au_nfiles_dec(file->f_dentry->d_sb);
11903 + finfo = au_fi(file);
11904 + AuDebugOn(finfo->fi_hdir);
11905 + AuRwDestroy(&finfo->fi_rwsem);
11906 + au_cache_free_finfo(finfo);
11909 +void au_fi_init_once(void *_finfo)
11911 + struct au_finfo *finfo = _finfo;
11912 + static struct lock_class_key aufs_fi;
11914 + au_rw_init(&finfo->fi_rwsem);
11915 + au_rw_class(&finfo->fi_rwsem, &aufs_fi);
11918 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
11921 + struct au_finfo *finfo;
11922 + struct dentry *dentry;
11925 + dentry = file->f_dentry;
11926 + finfo = au_cache_alloc_finfo();
11927 + if (unlikely(!finfo))
11931 + au_nfiles_inc(dentry->d_sb);
11932 + /* verbose coding for lock class name */
11934 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcNonDir_FIINFO);
11936 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcDir_FIINFO);
11937 + au_rw_write_lock(&finfo->fi_rwsem);
11938 + finfo->fi_btop = -1;
11939 + finfo->fi_hdir = fidir;
11940 + atomic_set(&finfo->fi_generation, au_digen(dentry));
11941 + /* smp_mb(); */ /* atomic_set */
11943 + file->private_data = finfo;
11948 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
11949 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
11950 +++ linux/fs/aufs/f_op.c 2014-04-24 22:11:10.851935747 +0200
11953 + * Copyright (C) 2005-2014 Junjiro R. Okajima
11955 + * This program, aufs is free software; you can redistribute it and/or modify
11956 + * it under the terms of the GNU General Public License as published by
11957 + * the Free Software Foundation; either version 2 of the License, or
11958 + * (at your option) any later version.
11960 + * This program is distributed in the hope that it will be useful,
11961 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11962 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11963 + * GNU General Public License for more details.
11965 + * You should have received a copy of the GNU General Public License
11966 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11970 + * file and vm operations
11973 +#include <linux/aio.h>
11974 +#include <linux/fs_stack.h>
11975 +#include <linux/mman.h>
11976 +#include <linux/security.h>
11979 +int au_do_open_nondir(struct file *file, int flags)
11982 + aufs_bindex_t bindex;
11983 + struct file *h_file;
11984 + struct dentry *dentry;
11985 + struct au_finfo *finfo;
11987 + FiMustWriteLock(file);
11990 + dentry = file->f_dentry;
11991 + finfo = au_fi(file);
11992 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
11993 + atomic_set(&finfo->fi_mmapped, 0);
11994 + bindex = au_dbstart(dentry);
11995 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
11996 + if (IS_ERR(h_file))
11997 + err = PTR_ERR(h_file);
11999 + au_set_fbstart(file, bindex);
12000 + au_set_h_fptr(file, bindex, h_file);
12001 + au_update_figen(file);
12002 + finfo->fi_file = file;
12003 + au_sphl_add(&finfo->fi_hlist, &au_sbi(dentry->d_sb)->si_files);
12004 + /* todo: necessary? */
12005 + /* file->f_ra = h_file->f_ra; */
12011 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
12012 + struct file *file)
12015 + struct super_block *sb;
12017 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
12018 + file, vfsub_file_flags(file), file->f_mode);
12020 + sb = file->f_dentry->d_sb;
12021 + si_read_lock(sb, AuLock_FLUSH);
12022 + err = au_do_open(file, au_do_open_nondir, /*fidir*/NULL);
12023 + si_read_unlock(sb);
12027 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
12029 + struct au_finfo *finfo;
12030 + aufs_bindex_t bindex;
12032 + finfo = au_fi(file);
12033 + au_sphl_del(&finfo->fi_hlist, &au_sbi(file->f_dentry->d_sb)->si_files);
12034 + bindex = finfo->fi_btop;
12036 + au_set_h_fptr(file, bindex, NULL);
12038 + au_finfo_fin(file);
12042 +/* ---------------------------------------------------------------------- */
12044 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
12047 + struct file *h_file;
12050 + h_file = au_hf_top(file);
12052 + err = vfsub_flush(h_file, id);
12056 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
12058 + return au_do_flush(file, id, au_do_flush_nondir);
12061 +/* ---------------------------------------------------------------------- */
12063 + * read and write functions acquire [fdi]_rwsem once, but release before
12064 + * mmap_sem. This is because to stop a race condition between mmap(2).
12065 + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping
12066 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
12067 + * read functions after [fdi]_rwsem are released, but it should be harmless.
12070 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
12074 + struct dentry *dentry;
12075 + struct file *h_file;
12076 + struct super_block *sb;
12078 + dentry = file->f_dentry;
12079 + sb = dentry->d_sb;
12080 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
12081 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
12082 + if (unlikely(err))
12085 + h_file = au_hf_top(file);
12086 + get_file(h_file);
12087 + di_read_unlock(dentry, AuLock_IR);
12088 + fi_read_unlock(file);
12090 + /* filedata may be obsoleted by concurrent copyup, but no problem */
12091 + err = vfsub_read_u(h_file, buf, count, ppos);
12092 + /* todo: necessary? */
12093 + /* file->f_ra = h_file->f_ra; */
12094 + /* update without lock, I don't think it a problem */
12095 + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
12099 + si_read_unlock(sb);
12104 + * todo: very ugly
12105 + * it locks both of i_mutex and si_rwsem for read in safe.
12106 + * if the plink maintenance mode continues forever (that is the problem),
12107 + * may loop forever.
12109 +static void au_mtx_and_read_lock(struct inode *inode)
12112 + struct super_block *sb = inode->i_sb;
12115 + mutex_lock(&inode->i_mutex);
12116 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
12119 + mutex_unlock(&inode->i_mutex);
12120 + si_read_lock(sb, AuLock_NOPLMW);
12121 + si_read_unlock(sb);
12125 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
12126 + size_t count, loff_t *ppos)
12129 + struct au_pin pin;
12130 + struct dentry *dentry;
12131 + struct super_block *sb;
12132 + struct inode *inode;
12133 + struct file *h_file;
12134 + char __user *buf = (char __user *)ubuf;
12136 + dentry = file->f_dentry;
12137 + sb = dentry->d_sb;
12138 + inode = dentry->d_inode;
12139 + au_mtx_and_read_lock(inode);
12141 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
12142 + if (unlikely(err))
12145 + err = au_ready_to_write(file, -1, &pin);
12146 + di_downgrade_lock(dentry, AuLock_IR);
12147 + if (unlikely(err)) {
12148 + di_read_unlock(dentry, AuLock_IR);
12149 + fi_write_unlock(file);
12153 + h_file = au_hf_top(file);
12154 + get_file(h_file);
12156 + di_read_unlock(dentry, AuLock_IR);
12157 + fi_write_unlock(file);
12159 + err = vfsub_write_u(h_file, buf, count, ppos);
12160 + ii_write_lock_child(inode);
12161 + au_cpup_attr_timesizes(inode);
12162 + inode->i_mode = file_inode(h_file)->i_mode;
12163 + ii_write_unlock(inode);
12167 + si_read_unlock(sb);
12168 + mutex_unlock(&inode->i_mutex);
12172 +static ssize_t au_do_aio(struct file *h_file, int rw, struct kiocb *kio,
12173 + const struct iovec *iov, unsigned long nv, loff_t pos)
12176 + struct file *file;
12177 + ssize_t (*func)(struct kiocb *, const struct iovec *, unsigned long,
12180 + err = security_file_permission(h_file, rw);
12181 + if (unlikely(err))
12186 + if (rw == MAY_READ)
12187 + func = h_file->f_op->aio_read;
12188 + else if (rw == MAY_WRITE)
12189 + func = h_file->f_op->aio_write;
12191 + file = kio->ki_filp;
12192 + kio->ki_filp = h_file;
12194 + err = func(kio, iov, nv, pos);
12196 + kio->ki_filp = file;
12198 + /* currently there is no such fs */
12205 +static ssize_t aufs_aio_read(struct kiocb *kio, const struct iovec *iov,
12206 + unsigned long nv, loff_t pos)
12209 + struct file *file, *h_file;
12210 + struct dentry *dentry;
12211 + struct super_block *sb;
12213 + file = kio->ki_filp;
12214 + dentry = file->f_dentry;
12215 + sb = dentry->d_sb;
12216 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
12217 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
12218 + if (unlikely(err))
12221 + h_file = au_hf_top(file);
12222 + get_file(h_file);
12223 + di_read_unlock(dentry, AuLock_IR);
12224 + fi_read_unlock(file);
12226 + err = au_do_aio(h_file, MAY_READ, kio, iov, nv, pos);
12227 + /* todo: necessary? */
12228 + /* file->f_ra = h_file->f_ra; */
12229 + /* update without lock, I don't think it a problem */
12230 + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
12234 + si_read_unlock(sb);
12238 +static ssize_t aufs_aio_write(struct kiocb *kio, const struct iovec *iov,
12239 + unsigned long nv, loff_t pos)
12242 + struct au_pin pin;
12243 + struct dentry *dentry;
12244 + struct inode *inode;
12245 + struct file *file, *h_file;
12246 + struct super_block *sb;
12248 + file = kio->ki_filp;
12249 + dentry = file->f_dentry;
12250 + sb = dentry->d_sb;
12251 + inode = dentry->d_inode;
12252 + au_mtx_and_read_lock(inode);
12254 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
12255 + if (unlikely(err))
12258 + err = au_ready_to_write(file, -1, &pin);
12259 + di_downgrade_lock(dentry, AuLock_IR);
12260 + if (unlikely(err)) {
12261 + di_read_unlock(dentry, AuLock_IR);
12262 + fi_write_unlock(file);
12266 + h_file = au_hf_top(file);
12267 + get_file(h_file);
12269 + di_read_unlock(dentry, AuLock_IR);
12270 + fi_write_unlock(file);
12272 + err = au_do_aio(h_file, MAY_WRITE, kio, iov, nv, pos);
12273 + ii_write_lock_child(inode);
12274 + au_cpup_attr_timesizes(inode);
12275 + inode->i_mode = file_inode(h_file)->i_mode;
12276 + ii_write_unlock(inode);
12280 + si_read_unlock(sb);
12281 + mutex_unlock(&inode->i_mutex);
12285 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
12286 + struct pipe_inode_info *pipe, size_t len,
12287 + unsigned int flags)
12290 + struct file *h_file;
12291 + struct dentry *dentry;
12292 + struct super_block *sb;
12294 + dentry = file->f_dentry;
12295 + sb = dentry->d_sb;
12296 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
12297 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
12298 + if (unlikely(err))
12302 + h_file = au_hf_top(file);
12303 + get_file(h_file);
12304 + if (au_test_loopback_kthread()) {
12305 + au_warn_loopback(h_file->f_dentry->d_sb);
12306 + if (file->f_mapping != h_file->f_mapping) {
12307 + file->f_mapping = h_file->f_mapping;
12308 + smp_mb(); /* unnecessary? */
12311 + di_read_unlock(dentry, AuLock_IR);
12312 + fi_read_unlock(file);
12314 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
12315 + /* todo: necessasry? */
12316 + /* file->f_ra = h_file->f_ra; */
12317 + /* update without lock, I don't think it a problem */
12318 + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
12322 + si_read_unlock(sb);
12327 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
12328 + size_t len, unsigned int flags)
12331 + struct au_pin pin;
12332 + struct dentry *dentry;
12333 + struct inode *inode;
12334 + struct file *h_file;
12335 + struct super_block *sb;
12337 + dentry = file->f_dentry;
12338 + sb = dentry->d_sb;
12339 + inode = dentry->d_inode;
12340 + au_mtx_and_read_lock(inode);
12342 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
12343 + if (unlikely(err))
12346 + err = au_ready_to_write(file, -1, &pin);
12347 + di_downgrade_lock(dentry, AuLock_IR);
12348 + if (unlikely(err)) {
12349 + di_read_unlock(dentry, AuLock_IR);
12350 + fi_write_unlock(file);
12354 + h_file = au_hf_top(file);
12355 + get_file(h_file);
12357 + di_read_unlock(dentry, AuLock_IR);
12358 + fi_write_unlock(file);
12360 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
12361 + ii_write_lock_child(inode);
12362 + au_cpup_attr_timesizes(inode);
12363 + inode->i_mode = file_inode(h_file)->i_mode;
12364 + ii_write_unlock(inode);
12368 + si_read_unlock(sb);
12369 + mutex_unlock(&inode->i_mutex);
12373 +/* ---------------------------------------------------------------------- */
12376 + * The locking order around current->mmap_sem.
12377 + * - in most and regular cases
12378 + * file I/O syscall -- aufs_read() or something
12379 + * -- si_rwsem for read -- mmap_sem
12380 + * (Note that [fdi]i_rwsem are released before mmap_sem).
12382 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
12383 + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
12384 + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
12385 + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
12386 + * It means that when aufs acquires si_rwsem for write, the process should never
12387 + * acquire mmap_sem.
12389 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
12390 + * problem either since any directory is not able to be mmap-ed.
12391 + * The similar scenario is applied to aufs_readlink() too.
12394 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
12395 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
12397 +static unsigned long au_arch_prot_conv(unsigned long flags)
12399 + /* currently ppc64 only */
12400 +#ifdef CONFIG_PPC64
12401 + /* cf. linux/arch/powerpc/include/asm/mman.h */
12402 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
12403 + return AuConv_VM_PROT(flags, SAO);
12405 + AuDebugOn(arch_calc_vm_prot_bits(-1));
12410 +static unsigned long au_prot_conv(unsigned long flags)
12412 + return AuConv_VM_PROT(flags, READ)
12413 + | AuConv_VM_PROT(flags, WRITE)
12414 + | AuConv_VM_PROT(flags, EXEC)
12415 + | au_arch_prot_conv(flags);
12418 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
12419 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
12421 +static unsigned long au_flag_conv(unsigned long flags)
12423 + return AuConv_VM_MAP(flags, GROWSDOWN)
12424 + | AuConv_VM_MAP(flags, DENYWRITE)
12425 + | AuConv_VM_MAP(flags, LOCKED);
12428 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
12431 + aufs_bindex_t bstart;
12432 + const unsigned char wlock
12433 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
12434 + struct dentry *dentry;
12435 + struct super_block *sb;
12436 + struct file *h_file;
12437 + struct au_branch *br;
12438 + struct au_pin pin;
12440 + AuDbgVmRegion(file, vma);
12442 + dentry = file->f_dentry;
12443 + sb = dentry->d_sb;
12445 + si_read_lock(sb, AuLock_NOPLMW);
12446 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
12447 + if (unlikely(err))
12451 + err = au_ready_to_write(file, -1, &pin);
12452 + di_write_unlock(dentry);
12453 + if (unlikely(err)) {
12454 + fi_write_unlock(file);
12459 + di_write_unlock(dentry);
12461 + bstart = au_fbstart(file);
12462 + br = au_sbr(sb, bstart);
12463 + h_file = au_hf_top(file);
12464 + get_file(h_file);
12465 + au_set_mmapped(file);
12466 + fi_write_unlock(file);
12469 + au_vm_file_reset(vma, h_file);
12470 + err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
12471 + au_flag_conv(vma->vm_flags));
12473 + err = h_file->f_op->mmap(h_file, vma);
12474 + if (unlikely(err))
12477 + au_vm_prfile_set(vma, file);
12478 + /* update without lock, I don't think it a problem */
12479 + fsstack_copy_attr_atime(file_inode(file), file_inode(h_file));
12480 + goto out_fput; /* success */
12483 + au_unset_mmapped(file);
12484 + au_vm_file_reset(vma, file);
12489 + si_read_unlock(sb);
12495 +/* ---------------------------------------------------------------------- */
12497 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
12501 + struct au_pin pin;
12502 + struct dentry *dentry;
12503 + struct inode *inode;
12504 + struct file *h_file;
12505 + struct super_block *sb;
12507 + dentry = file->f_dentry;
12508 + inode = dentry->d_inode;
12509 + sb = dentry->d_sb;
12510 + mutex_lock(&inode->i_mutex);
12511 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
12512 + if (unlikely(err))
12515 + err = 0; /* -EBADF; */ /* posix? */
12516 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
12518 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
12519 + if (unlikely(err))
12522 + err = au_ready_to_write(file, -1, &pin);
12523 + di_downgrade_lock(dentry, AuLock_IR);
12524 + if (unlikely(err))
12529 + h_file = au_hf_top(file);
12530 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
12531 + au_cpup_attr_timesizes(inode);
12534 + di_read_unlock(dentry, AuLock_IR);
12535 + fi_write_unlock(file);
12537 + si_read_unlock(sb);
12539 + mutex_unlock(&inode->i_mutex);
12543 +/* no one supports this operation, currently */
12545 +static int aufs_aio_fsync_nondir(struct kiocb *kio, int datasync)
12548 + struct au_pin pin;
12549 + struct dentry *dentry;
12550 + struct inode *inode;
12551 + struct file *file, *h_file;
12553 + file = kio->ki_filp;
12554 + dentry = file->f_dentry;
12555 + inode = dentry->d_inode;
12556 + au_mtx_and_read_lock(inode);
12558 + err = 0; /* -EBADF; */ /* posix? */
12559 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
12561 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
12562 + if (unlikely(err))
12565 + err = au_ready_to_write(file, -1, &pin);
12566 + di_downgrade_lock(dentry, AuLock_IR);
12567 + if (unlikely(err))
12572 + h_file = au_hf_top(file);
12573 + if (h_file->f_op->aio_fsync) {
12574 + struct mutex *h_mtx;
12576 + h_mtx = &file_inode(h_file)->i_mutex;
12577 + if (!is_sync_kiocb(kio)) {
12578 + get_file(h_file);
12581 + kio->ki_filp = h_file;
12582 + err = h_file->f_op->aio_fsync(kio, datasync);
12583 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
12585 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL);
12587 + au_cpup_attr_timesizes(inode);
12588 + mutex_unlock(h_mtx);
12592 + di_read_unlock(dentry, AuLock_IR);
12593 + fi_write_unlock(file);
12595 + si_read_unlock(inode->sb);
12596 + mutex_unlock(&inode->i_mutex);
12601 +static int aufs_fasync(int fd, struct file *file, int flag)
12604 + struct file *h_file;
12605 + struct dentry *dentry;
12606 + struct super_block *sb;
12608 + dentry = file->f_dentry;
12609 + sb = dentry->d_sb;
12610 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
12611 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
12612 + if (unlikely(err))
12615 + h_file = au_hf_top(file);
12616 + if (h_file->f_op->fasync)
12617 + err = h_file->f_op->fasync(fd, h_file, flag);
12619 + di_read_unlock(dentry, AuLock_IR);
12620 + fi_read_unlock(file);
12623 + si_read_unlock(sb);
12627 +/* ---------------------------------------------------------------------- */
12629 +/* no one supports this operation, currently */
12631 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
12632 + size_t len, loff_t *pos , int more)
12637 +/* ---------------------------------------------------------------------- */
12639 +const struct file_operations aufs_file_fop = {
12640 + .owner = THIS_MODULE,
12642 + .llseek = default_llseek,
12644 + .read = aufs_read,
12645 + .write = aufs_write,
12646 + .aio_read = aufs_aio_read,
12647 + .aio_write = aufs_aio_write,
12648 +#ifdef CONFIG_AUFS_POLL
12649 + .poll = aufs_poll,
12651 + .unlocked_ioctl = aufs_ioctl_nondir,
12652 +#ifdef CONFIG_COMPAT
12653 + .compat_ioctl = aufs_compat_ioctl_nondir,
12655 + .mmap = aufs_mmap,
12656 + .open = aufs_open_nondir,
12657 + .flush = aufs_flush_nondir,
12658 + .release = aufs_release_nondir,
12659 + .fsync = aufs_fsync_nondir,
12660 + /* .aio_fsync = aufs_aio_fsync_nondir, */
12661 + .fasync = aufs_fasync,
12662 + /* .sendpage = aufs_sendpage, */
12663 + .splice_write = aufs_splice_write,
12664 + .splice_read = aufs_splice_read,
12666 + .aio_splice_write = aufs_aio_splice_write,
12667 + .aio_splice_read = aufs_aio_splice_read
12670 diff -urN /usr/share/empty/fs/aufs/f_op_sp.c linux/fs/aufs/f_op_sp.c
12671 --- /usr/share/empty/fs/aufs/f_op_sp.c 1970-01-01 01:00:00.000000000 +0100
12672 +++ linux/fs/aufs/f_op_sp.c 2014-04-24 22:11:10.851935747 +0200
12675 + * Copyright (C) 2005-2014 Junjiro R. Okajima
12677 + * This program, aufs is free software; you can redistribute it and/or modify
12678 + * it under the terms of the GNU General Public License as published by
12679 + * the Free Software Foundation; either version 2 of the License, or
12680 + * (at your option) any later version.
12682 + * This program is distributed in the hope that it will be useful,
12683 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12684 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12685 + * GNU General Public License for more details.
12687 + * You should have received a copy of the GNU General Public License
12688 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12692 + * file operations for special files.
12693 + * while they exist in aufs virtually,
12694 + * their file I/O is handled out of aufs.
12697 +#include <linux/aio.h>
12701 + * I don't think the size of this list grows much.
12702 + * so here is a very simple list implemented in order to find finfo matching a
12705 +static struct au_sphlhead au_finfo_sp = {
12706 + .spin = __SPIN_LOCK_INITIALIZER(au_finfo_sp.spin),
12707 + .head = HLIST_HEAD_INIT
12710 +struct au_finfo_sp {
12711 + struct hlist_node hlist;
12712 + struct file *file;
12713 + struct au_finfo *finfo;
12716 +struct au_finfo *au_fi_sp(struct file *file)
12718 + struct au_finfo *finfo;
12719 + struct au_finfo_sp *sp;
12722 + spin_lock(&au_finfo_sp.spin);
12723 + hlist_for_each_entry(sp, &au_finfo_sp.head, hlist) {
12724 + if (sp->file != file)
12726 + finfo = sp->finfo;
12729 + spin_unlock(&au_finfo_sp.spin);
12734 +static int au_fi_sp_add(struct file *file)
12737 + struct au_finfo_sp *sp;
12740 + sp = kmalloc(sizeof(*sp), GFP_NOFS);
12744 + sp->finfo = file->private_data;
12745 + spin_lock(&au_finfo_sp.spin);
12746 + hlist_add_head(&sp->hlist, &au_finfo_sp.head);
12747 + spin_unlock(&au_finfo_sp.spin);
12752 +static void au_fi_sp_del(struct file *file)
12754 + struct au_finfo_sp *sp, *do_free;
12757 + spin_lock(&au_finfo_sp.spin);
12758 + hlist_for_each_entry(sp, &au_finfo_sp.head, hlist) {
12759 + if (sp->file != file)
12761 + hlist_del(&sp->hlist);
12765 + spin_unlock(&au_finfo_sp.spin);
12769 +/* ---------------------------------------------------------------------- */
12771 +static ssize_t aufs_aio_read_sp(struct kiocb *kio, const struct iovec *iov,
12772 + unsigned long nv, loff_t pos)
12775 + aufs_bindex_t bstart;
12776 + unsigned char wbr;
12777 + struct file *file, *h_file;
12778 + struct super_block *sb;
12780 + file = kio->ki_filp;
12781 + sb = file->f_dentry->d_sb;
12782 + si_read_lock(sb, AuLock_FLUSH);
12783 + fi_read_lock(file);
12784 + bstart = au_fbstart(file);
12785 + h_file = au_hf_top(file);
12786 + fi_read_unlock(file);
12787 + wbr = !!au_br_writable(au_sbr(sb, bstart)->br_perm);
12788 + si_read_unlock(sb);
12790 + /* do not change the file in kio */
12791 + AuDebugOn(!h_file->f_op || !h_file->f_op->aio_read);
12792 + err = h_file->f_op->aio_read(kio, iov, nv, pos);
12793 + if (err > 0 && wbr)
12794 + file_accessed(h_file);
12799 +static ssize_t aufs_aio_write_sp(struct kiocb *kio, const struct iovec *iov,
12800 + unsigned long nv, loff_t pos)
12803 + aufs_bindex_t bstart;
12804 + unsigned char wbr;
12805 + struct super_block *sb;
12806 + struct file *file, *h_file;
12808 + file = kio->ki_filp;
12809 + sb = file->f_dentry->d_sb;
12810 + si_read_lock(sb, AuLock_FLUSH);
12811 + fi_read_lock(file);
12812 + bstart = au_fbstart(file);
12813 + h_file = au_hf_top(file);
12814 + fi_read_unlock(file);
12815 + wbr = !!au_br_writable(au_sbr(sb, bstart)->br_perm);
12816 + si_read_unlock(sb);
12818 + /* do not change the file in kio */
12819 + AuDebugOn(!h_file->f_op || !h_file->f_op->aio_write);
12820 + err = h_file->f_op->aio_write(kio, iov, nv, pos);
12824 +/* ---------------------------------------------------------------------- */
12826 +static int aufs_release_sp(struct inode *inode, struct file *file)
12829 + struct file *h_file;
12831 + fi_read_lock(file);
12832 + h_file = au_hf_top(file);
12833 + fi_read_unlock(file);
12834 + /* close this fifo in aufs */
12835 + err = h_file->f_op->release(inode, file); /* ignore */
12836 + aufs_release_nondir(inode, file); /* ignore */
12837 + au_fi_sp_del(file);
12841 +/* ---------------------------------------------------------------------- */
12843 +/* currently, support only FIFO */
12845 + AuSp_FIFO, AuSp_FIFO_R, AuSp_FIFO_W, AuSp_FIFO_RW,
12846 + /* AuSp_SOCK, AuSp_CHR, AuSp_BLK, */
12849 +static int aufs_open_sp(struct inode *inode, struct file *file);
12850 +static struct au_sp_fop {
12852 + struct file_operations fop; /* not 'const' */
12854 +} au_sp_fop[AuSp_Last] = {
12857 + .owner = THIS_MODULE,
12858 + .open = aufs_open_sp
12863 +static void au_init_fop_sp(struct file *file)
12865 + struct au_sp_fop *p;
12867 + struct file *h_file;
12870 + if (unlikely(!p->done)) {
12871 + /* initialize first time only */
12872 + static DEFINE_SPINLOCK(spin);
12874 + spin_lock(&spin);
12876 + BUILD_BUG_ON(sizeof(au_sp_fop)/sizeof(*au_sp_fop)
12878 + for (i = 0; i < AuSp_Last; i++)
12879 + spin_lock_init(&p[i].spin);
12882 + spin_unlock(&spin);
12885 + switch (file->f_mode & (FMODE_READ | FMODE_WRITE)) {
12889 + case FMODE_WRITE:
12892 + case FMODE_READ | FMODE_WRITE:
12893 + i = AuSp_FIFO_RW;
12900 + if (unlikely(!p->done)) {
12901 + /* initialize first time only */
12902 + h_file = au_hf_top(file);
12903 + spin_lock(&p->spin);
12905 + p->fop = *h_file->f_op;
12906 + p->fop.owner = THIS_MODULE;
12907 + if (p->fop.aio_read)
12908 + p->fop.aio_read = aufs_aio_read_sp;
12909 + if (p->fop.aio_write)
12910 + p->fop.aio_write = aufs_aio_write_sp;
12911 + p->fop.release = aufs_release_sp;
12914 + spin_unlock(&p->spin);
12916 + file->f_op = &p->fop;
12919 +static int au_cpup_sp(struct dentry *dentry)
12922 + struct au_pin pin;
12923 + struct au_wr_dir_args wr_dir_args = {
12924 + .force_btgt = -1,
12927 + struct au_cp_generic cpg = {
12928 + .dentry = dentry,
12933 + .flags = AuCpup_DTIME
12936 + AuDbg("%pd\n", dentry);
12938 + di_read_unlock(dentry, AuLock_IR);
12939 + di_write_lock_child(dentry);
12940 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
12941 + if (unlikely(err < 0))
12945 + if (cpg.bdst == au_dbstart(dentry))
12946 + goto out; /* success */
12948 + err = au_pin(&pin, dentry, cpg.bdst, au_opt_udba(dentry->d_sb),
12949 + AuPin_MNT_WRITE);
12951 + err = au_sio_cpup_simple(&cpg);
12956 + di_downgrade_lock(dentry, AuLock_IR);
12960 +static int au_do_open_sp(struct file *file, int flags)
12963 + struct dentry *dentry;
12964 + struct super_block *sb;
12965 + struct file *h_file;
12966 + struct inode *h_inode;
12968 + err = au_fi_sp_add(file);
12969 + if (unlikely(err))
12972 + dentry = file->f_dentry;
12973 + AuDbg("%pd\n", dentry);
12976 + * try copying-up.
12977 + * operate on the ro branch is not an error.
12979 + au_cpup_sp(dentry); /* ignore */
12981 + /* prepare h_file */
12982 + err = au_do_open_nondir(file, vfsub_file_flags(file));
12983 + if (unlikely(err))
12986 + sb = dentry->d_sb;
12987 + h_file = au_hf_top(file);
12988 + h_inode = file_inode(h_file);
12989 + di_read_unlock(dentry, AuLock_IR);
12990 + fi_write_unlock(file);
12991 + si_read_unlock(sb);
12992 + /* open this fifo in aufs */
12993 + err = h_inode->i_fop->open(file_inode(file), file);
12994 + si_noflush_read_lock(sb);
12995 + fi_write_lock(file);
12996 + di_read_lock_child(dentry, AuLock_IR);
12998 + au_init_fop_sp(file);
12999 + goto out; /* success */
13003 + au_fi_sp_del(file);
13008 +static int aufs_open_sp(struct inode *inode, struct file *file)
13011 + struct super_block *sb;
13013 + sb = file->f_dentry->d_sb;
13014 + si_read_lock(sb, AuLock_FLUSH);
13015 + err = au_do_open(file, au_do_open_sp, /*fidir*/NULL);
13016 + si_read_unlock(sb);
13020 +/* ---------------------------------------------------------------------- */
13022 +void au_init_special_fop(struct inode *inode, umode_t mode, dev_t rdev)
13024 + init_special_inode(inode, mode, rdev);
13026 + switch (mode & S_IFMT) {
13028 + inode->i_fop = &au_sp_fop[AuSp_FIFO].fop;
13039 +int au_special_file(umode_t mode)
13044 + switch (mode & S_IFMT) {
13056 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
13057 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
13058 +++ linux/fs/aufs/fstype.h 2014-04-24 22:11:10.851935747 +0200
13061 + * Copyright (C) 2005-2014 Junjiro R. Okajima
13063 + * This program, aufs is free software; you can redistribute it and/or modify
13064 + * it under the terms of the GNU General Public License as published by
13065 + * the Free Software Foundation; either version 2 of the License, or
13066 + * (at your option) any later version.
13068 + * This program is distributed in the hope that it will be useful,
13069 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13070 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13071 + * GNU General Public License for more details.
13073 + * You should have received a copy of the GNU General Public License
13074 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13078 + * judging filesystem type
13081 +#ifndef __AUFS_FSTYPE_H__
13082 +#define __AUFS_FSTYPE_H__
13086 +#include <linux/fs.h>
13087 +#include <linux/magic.h>
13088 +#include <linux/romfs_fs.h>
13090 +static inline int au_test_aufs(struct super_block *sb)
13092 + return sb->s_magic == AUFS_SUPER_MAGIC;
13095 +static inline const char *au_sbtype(struct super_block *sb)
13097 + return sb->s_type->name;
13100 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
13102 +#if defined(CONFIG_ROMFS_FS) || defined(CONFIG_ROMFS_FS_MODULE)
13103 + return sb->s_magic == ROMFS_MAGIC;
13109 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
13111 +#if defined(CONFIG_ISO9660_FS) || defined(CONFIG_ISO9660_FS_MODULE)
13112 + return sb->s_magic == ISOFS_SUPER_MAGIC;
13118 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
13120 +#if defined(CONFIG_CRAMFS) || defined(CONFIG_CRAMFS_MODULE)
13121 + return sb->s_magic == CRAMFS_MAGIC;
13126 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
13128 +#if defined(CONFIG_NFS_FS) || defined(CONFIG_NFS_FS_MODULE)
13129 + return sb->s_magic == NFS_SUPER_MAGIC;
13135 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
13137 +#if defined(CONFIG_FUSE_FS) || defined(CONFIG_FUSE_FS_MODULE)
13138 + return sb->s_magic == FUSE_SUPER_MAGIC;
13144 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
13146 +#if defined(CONFIG_XFS_FS) || defined(CONFIG_XFS_FS_MODULE)
13147 + return sb->s_magic == XFS_SB_MAGIC;
13153 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
13155 +#ifdef CONFIG_TMPFS
13156 + return sb->s_magic == TMPFS_MAGIC;
13162 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
13164 +#if defined(CONFIG_ECRYPT_FS) || defined(CONFIG_ECRYPT_FS_MODULE)
13165 + return !strcmp(au_sbtype(sb), "ecryptfs");
13171 +static inline int au_test_ocfs2(struct super_block *sb __maybe_unused)
13173 +#if defined(CONFIG_OCFS2_FS) || defined(CONFIG_OCFS2_FS_MODULE)
13174 + return sb->s_magic == OCFS2_SUPER_MAGIC;
13180 +static inline int au_test_ocfs2_dlmfs(struct super_block *sb __maybe_unused)
13182 +#if defined(CONFIG_OCFS2_FS_O2CB) || defined(CONFIG_OCFS2_FS_O2CB_MODULE)
13183 + return sb->s_magic == DLMFS_MAGIC;
13189 +static inline int au_test_coda(struct super_block *sb __maybe_unused)
13191 +#if defined(CONFIG_CODA_FS) || defined(CONFIG_CODA_FS_MODULE)
13192 + return sb->s_magic == CODA_SUPER_MAGIC;
13198 +static inline int au_test_v9fs(struct super_block *sb __maybe_unused)
13200 +#if defined(CONFIG_9P_FS) || defined(CONFIG_9P_FS_MODULE)
13201 + return sb->s_magic == V9FS_MAGIC;
13207 +static inline int au_test_ext4(struct super_block *sb __maybe_unused)
13209 +#if defined(CONFIG_EXT4_FS) || defined(CONFIG_EXT4_FS_MODULE)
13210 + return sb->s_magic == EXT4_SUPER_MAGIC;
13216 +static inline int au_test_sysv(struct super_block *sb __maybe_unused)
13218 +#if defined(CONFIG_SYSV_FS) || defined(CONFIG_SYSV_FS_MODULE)
13219 + return !strcmp(au_sbtype(sb), "sysv");
13225 +static inline int au_test_ramfs(struct super_block *sb)
13227 + return sb->s_magic == RAMFS_MAGIC;
13230 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
13232 +#if defined(CONFIG_UBIFS_FS) || defined(CONFIG_UBIFS_FS_MODULE)
13233 + return sb->s_magic == UBIFS_SUPER_MAGIC;
13239 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
13241 +#ifdef CONFIG_PROC_FS
13242 + return sb->s_magic == PROC_SUPER_MAGIC;
13248 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
13250 +#ifdef CONFIG_SYSFS
13251 + return sb->s_magic == SYSFS_MAGIC;
13257 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
13259 +#if defined(CONFIG_CONFIGFS_FS) || defined(CONFIG_CONFIGFS_FS_MODULE)
13260 + return sb->s_magic == CONFIGFS_MAGIC;
13266 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
13268 +#if defined(CONFIG_MINIX_FS) || defined(CONFIG_MINIX_FS_MODULE)
13269 + return sb->s_magic == MINIX3_SUPER_MAGIC
13270 + || sb->s_magic == MINIX2_SUPER_MAGIC
13271 + || sb->s_magic == MINIX2_SUPER_MAGIC2
13272 + || sb->s_magic == MINIX_SUPER_MAGIC
13273 + || sb->s_magic == MINIX_SUPER_MAGIC2;
13279 +static inline int au_test_cifs(struct super_block *sb __maybe_unused)
13281 +#if defined(CONFIG_CIFS_FS) || defined(CONFIGCIFS_FS_MODULE)
13282 + return sb->s_magic == CIFS_MAGIC_NUMBER;
13288 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
13290 +#if defined(CONFIG_FAT_FS) || defined(CONFIG_FAT_FS_MODULE)
13291 + return sb->s_magic == MSDOS_SUPER_MAGIC;
13297 +static inline int au_test_msdos(struct super_block *sb)
13299 + return au_test_fat(sb);
13302 +static inline int au_test_vfat(struct super_block *sb)
13304 + return au_test_fat(sb);
13307 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
13309 +#ifdef CONFIG_SECURITYFS
13310 + return sb->s_magic == SECURITYFS_MAGIC;
13316 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
13318 +#if defined(CONFIG_SQUASHFS) || defined(CONFIG_SQUASHFS_MODULE)
13319 + return sb->s_magic == SQUASHFS_MAGIC;
13325 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
13327 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
13328 + return sb->s_magic == BTRFS_SUPER_MAGIC;
13334 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
13336 +#if defined(CONFIG_XENFS) || defined(CONFIG_XENFS_MODULE)
13337 + return sb->s_magic == XENFS_SUPER_MAGIC;
13343 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
13345 +#ifdef CONFIG_DEBUG_FS
13346 + return sb->s_magic == DEBUGFS_MAGIC;
13352 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
13354 +#if defined(CONFIG_NILFS) || defined(CONFIG_NILFS_MODULE)
13355 + return sb->s_magic == NILFS_SUPER_MAGIC;
13361 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
13363 +#if defined(CONFIG_HFSPLUS_FS) || defined(CONFIG_HFSPLUS_FS_MODULE)
13364 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
13370 +/* ---------------------------------------------------------------------- */
13372 + * they can't be an aufs branch.
13374 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
13377 +#ifndef CONFIG_AUFS_BR_RAMFS
13378 + au_test_ramfs(sb) ||
13380 + au_test_procfs(sb)
13381 + || au_test_sysfs(sb)
13382 + || au_test_configfs(sb)
13383 + || au_test_debugfs(sb)
13384 + || au_test_securityfs(sb)
13385 + || au_test_xenfs(sb)
13386 + || au_test_ecryptfs(sb)
13387 + /* || !strcmp(au_sbtype(sb), "unionfs") */
13388 + || au_test_aufs(sb); /* will be supported in next version */
13391 +static inline int au_test_fs_remote(struct super_block *sb)
13393 + return !au_test_tmpfs(sb)
13394 +#ifdef CONFIG_AUFS_BR_RAMFS
13395 + && !au_test_ramfs(sb)
13397 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
13400 +/* ---------------------------------------------------------------------- */
13403 + * Note: these functions (below) are created after reading ->getattr() in all
13404 + * filesystems under linux/fs. it means we have to do so in every update...
13408 + * some filesystems require getattr to refresh the inode attributes before
13410 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
13411 + * and leave the work for d_revalidate()
13413 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
13415 + return au_test_nfs(sb)
13416 + || au_test_fuse(sb)
13417 + /* || au_test_ocfs2(sb) */ /* untested */
13418 + /* || au_test_btrfs(sb) */ /* untested */
13419 + /* || au_test_coda(sb) */ /* untested */
13420 + /* || au_test_v9fs(sb) */ /* untested */
13425 + * filesystems which don't maintain i_size or i_blocks.
13427 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
13429 + return au_test_xfs(sb)
13430 + || au_test_btrfs(sb)
13431 + || au_test_ubifs(sb)
13432 + || au_test_hfsplus(sb) /* maintained, but incorrect */
13433 + /* || au_test_ext4(sb) */ /* untested */
13434 + /* || au_test_ocfs2(sb) */ /* untested */
13435 + /* || au_test_ocfs2_dlmfs(sb) */ /* untested */
13436 + /* || au_test_sysv(sb) */ /* untested */
13437 + /* || au_test_minix(sb) */ /* untested */
13442 + * filesystems which don't store the correct value in some of their inode
13445 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
13447 + return au_test_fs_bad_iattr_size(sb)
13448 + /* || au_test_cifs(sb) */ /* untested */
13449 + || au_test_fat(sb)
13450 + || au_test_msdos(sb)
13451 + || au_test_vfat(sb);
13454 +/* they don't check i_nlink in link(2) */
13455 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
13457 + return au_test_tmpfs(sb)
13458 +#ifdef CONFIG_AUFS_BR_RAMFS
13459 + || au_test_ramfs(sb)
13461 + || au_test_ubifs(sb)
13462 + || au_test_hfsplus(sb);
13466 + * filesystems which sets S_NOATIME and S_NOCMTIME.
13468 +static inline int au_test_fs_notime(struct super_block *sb)
13470 + return au_test_nfs(sb)
13471 + || au_test_fuse(sb)
13472 + || au_test_ubifs(sb)
13473 + /* || au_test_cifs(sb) */ /* untested */
13478 + * filesystems which requires replacing i_mapping.
13480 +static inline int au_test_fs_bad_mapping(struct super_block *sb)
13482 + return au_test_fuse(sb)
13483 + || au_test_ubifs(sb);
13486 +/* temporary support for i#1 in cramfs */
13487 +static inline int au_test_fs_unique_ino(struct inode *inode)
13489 + if (au_test_cramfs(inode->i_sb))
13490 + return inode->i_ino != 1;
13494 +/* ---------------------------------------------------------------------- */
13497 + * the filesystem where the xino files placed must support i/o after unlink and
13498 + * maintain i_size and i_blocks.
13500 +static inline int au_test_fs_bad_xino(struct super_block *sb)
13502 + return au_test_fs_remote(sb)
13503 + || au_test_fs_bad_iattr_size(sb)
13504 + /* don't want unnecessary work for xino */
13505 + || au_test_aufs(sb)
13506 + || au_test_ecryptfs(sb)
13507 + || au_test_nilfs(sb);
13510 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
13512 + return au_test_tmpfs(sb)
13513 + || au_test_ramfs(sb);
13517 + * test if the @sb is real-readonly.
13519 +static inline int au_test_fs_rr(struct super_block *sb)
13521 + return au_test_squashfs(sb)
13522 + || au_test_iso9660(sb)
13523 + || au_test_cramfs(sb)
13524 + || au_test_romfs(sb);
13527 +#endif /* __KERNEL__ */
13528 +#endif /* __AUFS_FSTYPE_H__ */
13529 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
13530 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
13531 +++ linux/fs/aufs/hfsnotify.c 2014-04-24 22:11:10.851935747 +0200
13534 + * Copyright (C) 2005-2014 Junjiro R. Okajima
13536 + * This program, aufs is free software; you can redistribute it and/or modify
13537 + * it under the terms of the GNU General Public License as published by
13538 + * the Free Software Foundation; either version 2 of the License, or
13539 + * (at your option) any later version.
13541 + * This program is distributed in the hope that it will be useful,
13542 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13543 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13544 + * GNU General Public License for more details.
13546 + * You should have received a copy of the GNU General Public License
13547 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13551 + * fsnotify for the lower directories
13556 +/* FS_IN_IGNORED is unnecessary */
13557 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
13558 + | FS_CREATE | FS_EVENT_ON_CHILD);
13559 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
13560 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
13562 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
13564 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
13567 + au_cache_free_hnotify(hn);
13568 + smp_mb__before_atomic_dec();
13569 + if (atomic64_dec_and_test(&au_hfsn_ifree))
13570 + wake_up(&au_hfsn_wq);
13573 +static int au_hfsn_alloc(struct au_hinode *hinode)
13576 + struct au_hnotify *hn;
13577 + struct super_block *sb;
13578 + struct au_branch *br;
13579 + struct fsnotify_mark *mark;
13580 + aufs_bindex_t bindex;
13582 + hn = hinode->hi_notify;
13583 + sb = hn->hn_aufs_inode->i_sb;
13584 + bindex = au_br_index(sb, hinode->hi_id);
13585 + br = au_sbr(sb, bindex);
13586 + AuDebugOn(!br->br_hfsn);
13588 + mark = &hn->hn_mark;
13589 + fsnotify_init_mark(mark, au_hfsn_free_mark);
13590 + mark->mask = AuHfsnMask;
13592 + * by udba rename or rmdir, aufs assign a new inode to the known
13593 + * h_inode, so specify 1 to allow dups.
13595 + err = fsnotify_add_mark(mark, br->br_hfsn->hfsn_group, hinode->hi_inode,
13596 + /*mnt*/NULL, /*allow_dups*/1);
13597 + /* even if err */
13598 + fsnotify_put_mark(mark);
13603 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
13605 + struct fsnotify_mark *mark;
13606 + unsigned long long ull;
13607 + struct fsnotify_group *group;
13609 + ull = atomic64_inc_return(&au_hfsn_ifree);
13612 + mark = &hn->hn_mark;
13613 + spin_lock(&mark->lock);
13614 + group = mark->group;
13615 + fsnotify_get_group(group);
13616 + spin_unlock(&mark->lock);
13617 + fsnotify_destroy_mark(mark, group);
13618 + fsnotify_put_group(group);
13620 + /* free hn by myself */
13624 +/* ---------------------------------------------------------------------- */
13626 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
13628 + struct fsnotify_mark *mark;
13630 + mark = &hinode->hi_notify->hn_mark;
13631 + spin_lock(&mark->lock);
13633 + AuDebugOn(mark->mask & AuHfsnMask);
13634 + mark->mask |= AuHfsnMask;
13636 + AuDebugOn(!(mark->mask & AuHfsnMask));
13637 + mark->mask &= ~AuHfsnMask;
13639 + spin_unlock(&mark->lock);
13640 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
13643 +/* ---------------------------------------------------------------------- */
13645 +/* #define AuDbgHnotify */
13646 +#ifdef AuDbgHnotify
13647 +static char *au_hfsn_name(u32 mask)
13649 +#ifdef CONFIG_AUFS_DEBUG
13650 +#define test_ret(flag) \
13652 + if (mask & flag) \
13655 + test_ret(FS_ACCESS);
13656 + test_ret(FS_MODIFY);
13657 + test_ret(FS_ATTRIB);
13658 + test_ret(FS_CLOSE_WRITE);
13659 + test_ret(FS_CLOSE_NOWRITE);
13660 + test_ret(FS_OPEN);
13661 + test_ret(FS_MOVED_FROM);
13662 + test_ret(FS_MOVED_TO);
13663 + test_ret(FS_CREATE);
13664 + test_ret(FS_DELETE);
13665 + test_ret(FS_DELETE_SELF);
13666 + test_ret(FS_MOVE_SELF);
13667 + test_ret(FS_UNMOUNT);
13668 + test_ret(FS_Q_OVERFLOW);
13669 + test_ret(FS_IN_IGNORED);
13670 + test_ret(FS_IN_ISDIR);
13671 + test_ret(FS_IN_ONESHOT);
13672 + test_ret(FS_EVENT_ON_CHILD);
13681 +/* ---------------------------------------------------------------------- */
13683 +static void au_hfsn_free_group(struct fsnotify_group *group)
13685 + struct au_br_hfsnotify *hfsn = group->private;
13691 +static int au_hfsn_handle_event(struct fsnotify_group *group,
13692 + struct inode *inode,
13693 + struct fsnotify_mark *inode_mark,
13694 + struct fsnotify_mark *vfsmount_mark,
13695 + u32 mask, void *data, int data_type,
13696 + const unsigned char *file_name, u32 cookie)
13699 + struct au_hnotify *hnotify;
13700 + struct inode *h_dir, *h_inode;
13701 + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
13703 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
13706 + /* if FS_UNMOUNT happens, there must be another bug */
13707 + AuDebugOn(mask & FS_UNMOUNT);
13708 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
13713 +#ifdef AuDbgHnotify
13715 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
13716 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
13717 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
13718 + h_dir->i_ino, mask, au_hfsn_name(mask),
13719 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
13720 + /* WARN_ON(1); */
13725 + AuDebugOn(!inode_mark);
13726 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
13727 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
13733 +static struct fsnotify_ops au_hfsn_ops = {
13734 + .handle_event = au_hfsn_handle_event,
13735 + .free_group_priv = au_hfsn_free_group
13738 +/* ---------------------------------------------------------------------- */
13740 +static void au_hfsn_fin_br(struct au_branch *br)
13742 + struct au_br_hfsnotify *hfsn;
13744 + hfsn = br->br_hfsn;
13746 + fsnotify_put_group(hfsn->hfsn_group);
13749 +static int au_hfsn_init_br(struct au_branch *br, int perm)
13752 + struct fsnotify_group *group;
13753 + struct au_br_hfsnotify *hfsn;
13756 + br->br_hfsn = NULL;
13757 + if (!au_br_hnotifyable(perm))
13761 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
13762 + if (unlikely(!hfsn))
13766 + group = fsnotify_alloc_group(&au_hfsn_ops);
13767 + if (IS_ERR(group)) {
13768 + err = PTR_ERR(group);
13769 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
13773 + group->private = hfsn;
13774 + hfsn->hfsn_group = group;
13775 + br->br_hfsn = hfsn;
13776 + goto out; /* success */
13784 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
13789 + if (!br->br_hfsn)
13790 + err = au_hfsn_init_br(br, perm);
13795 +/* ---------------------------------------------------------------------- */
13797 +static void au_hfsn_fin(void)
13799 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
13800 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
13803 +const struct au_hnotify_op au_hnotify_op = {
13804 + .ctl = au_hfsn_ctl,
13805 + .alloc = au_hfsn_alloc,
13806 + .free = au_hfsn_free,
13808 + .fin = au_hfsn_fin,
13810 + .reset_br = au_hfsn_reset_br,
13811 + .fin_br = au_hfsn_fin_br,
13812 + .init_br = au_hfsn_init_br
13814 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
13815 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
13816 +++ linux/fs/aufs/hfsplus.c 2014-04-24 22:11:10.851935747 +0200
13819 + * Copyright (C) 2010-2014 Junjiro R. Okajima
13821 + * This program, aufs is free software; you can redistribute it and/or modify
13822 + * it under the terms of the GNU General Public License as published by
13823 + * the Free Software Foundation; either version 2 of the License, or
13824 + * (at your option) any later version.
13826 + * This program is distributed in the hope that it will be useful,
13827 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13828 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13829 + * GNU General Public License for more details.
13831 + * You should have received a copy of the GNU General Public License
13832 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13836 + * special support for filesystems which aqucires an inode mutex
13837 + * at final closing a file, eg, hfsplus.
13839 + * This trick is very simple and stupid, just to open the file before really
13840 + * neceeary open to tell hfsplus that this is not the final closing.
13841 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
13842 + * and au_h_open_post() after releasing it.
13847 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
13850 + struct file *h_file;
13851 + struct dentry *h_dentry;
13853 + h_dentry = au_h_dptr(dentry, bindex);
13854 + AuDebugOn(!h_dentry);
13855 + AuDebugOn(!h_dentry->d_inode);
13858 + if (au_test_hfsplus(h_dentry->d_sb)
13859 + && S_ISREG(h_dentry->d_inode->i_mode))
13860 + h_file = au_h_open(dentry, bindex,
13861 + O_RDONLY | O_NOATIME | O_LARGEFILE,
13862 + /*file*/NULL, force_wr);
13866 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
13867 + struct file *h_file)
13871 + au_sbr_put(dentry->d_sb, bindex);
13874 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
13875 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
13876 +++ linux/fs/aufs/hnotify.c 2014-04-24 22:11:10.851935747 +0200
13879 + * Copyright (C) 2005-2014 Junjiro R. Okajima
13881 + * This program, aufs is free software; you can redistribute it and/or modify
13882 + * it under the terms of the GNU General Public License as published by
13883 + * the Free Software Foundation; either version 2 of the License, or
13884 + * (at your option) any later version.
13886 + * This program is distributed in the hope that it will be useful,
13887 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13888 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13889 + * GNU General Public License for more details.
13891 + * You should have received a copy of the GNU General Public License
13892 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13896 + * abstraction to notify the direct changes on lower directories
13901 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
13904 + struct au_hnotify *hn;
13907 + hn = au_cache_alloc_hnotify();
13909 + hn->hn_aufs_inode = inode;
13910 + hinode->hi_notify = hn;
13911 + err = au_hnotify_op.alloc(hinode);
13913 + if (unlikely(err)) {
13914 + hinode->hi_notify = NULL;
13915 + au_cache_free_hnotify(hn);
13917 + * The upper dir was removed by udba, but the same named
13918 + * dir left. In this case, aufs assignes a new inode
13919 + * number and set the monitor again.
13920 + * For the lower dir, the old monitnor is still left.
13922 + if (err == -EEXIST)
13931 +void au_hn_free(struct au_hinode *hinode)
13933 + struct au_hnotify *hn;
13935 + hn = hinode->hi_notify;
13937 + hinode->hi_notify = NULL;
13938 + if (au_hnotify_op.free(hinode, hn))
13939 + au_cache_free_hnotify(hn);
13943 +/* ---------------------------------------------------------------------- */
13945 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
13947 + if (hinode->hi_notify)
13948 + au_hnotify_op.ctl(hinode, do_set);
13951 +void au_hn_reset(struct inode *inode, unsigned int flags)
13953 + aufs_bindex_t bindex, bend;
13954 + struct inode *hi;
13955 + struct dentry *iwhdentry;
13957 + bend = au_ibend(inode);
13958 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
13959 + hi = au_h_iptr(inode, bindex);
13963 + /* mutex_lock_nested(&hi->i_mutex, AuLsc_I_CHILD); */
13964 + iwhdentry = au_hi_wh(inode, bindex);
13968 + au_set_h_iptr(inode, bindex, NULL, 0);
13969 + au_set_h_iptr(inode, bindex, au_igrab(hi),
13970 + flags & ~AuHi_XINO);
13973 + /* mutex_unlock(&hi->i_mutex); */
13977 +/* ---------------------------------------------------------------------- */
13979 +static int hn_xino(struct inode *inode, struct inode *h_inode)
13982 + aufs_bindex_t bindex, bend, bfound, bstart;
13983 + struct inode *h_i;
13986 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
13987 + pr_warn("branch root dir was changed\n");
13992 + bend = au_ibend(inode);
13993 + bstart = au_ibstart(inode);
13994 +#if 0 /* reserved for future use */
13995 + if (bindex == bend) {
13996 + /* keep this ino in rename case */
14000 + for (bindex = bstart; bindex <= bend; bindex++)
14001 + if (au_h_iptr(inode, bindex) == h_inode) {
14008 + for (bindex = bstart; bindex <= bend; bindex++) {
14009 + h_i = au_h_iptr(inode, bindex);
14013 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
14014 + /* ignore this error */
14015 + /* bad action? */
14018 + /* children inode number will be broken */
14025 +static int hn_gen_tree(struct dentry *dentry)
14027 + int err, i, j, ndentry;
14028 + struct au_dcsub_pages dpages;
14029 + struct au_dpage *dpage;
14030 + struct dentry **dentries;
14032 + err = au_dpages_init(&dpages, GFP_NOFS);
14033 + if (unlikely(err))
14035 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
14036 + if (unlikely(err))
14039 + for (i = 0; i < dpages.ndpage; i++) {
14040 + dpage = dpages.dpages + i;
14041 + dentries = dpage->dentries;
14042 + ndentry = dpage->ndentry;
14043 + for (j = 0; j < ndentry; j++) {
14044 + struct dentry *d;
14052 + /* todo: reset children xino?
14053 + cached children only? */
14054 + au_iigen_dec(d->d_inode);
14059 + au_dpages_free(&dpages);
14062 + /* discard children */
14063 + dentry_unhash(dentry);
14071 + * return 0 if processed.
14073 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
14074 + const unsigned int isdir)
14077 + struct dentry *d;
14078 + struct qstr *dname;
14081 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
14082 + pr_warn("branch root dir was changed\n");
14088 + AuDebugOn(!name);
14089 + au_iigen_dec(inode);
14090 + spin_lock(&inode->i_lock);
14091 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
14092 + spin_lock(&d->d_lock);
14093 + dname = &d->d_name;
14094 + if (dname->len != nlen
14095 + && memcmp(dname->name, name, nlen)) {
14096 + spin_unlock(&d->d_lock);
14101 + spin_unlock(&d->d_lock);
14104 + spin_unlock(&inode->i_lock);
14106 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
14107 + d = d_find_alias(inode);
14109 + au_iigen_dec(inode);
14113 + spin_lock(&d->d_lock);
14114 + dname = &d->d_name;
14115 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
14116 + spin_unlock(&d->d_lock);
14117 + err = hn_gen_tree(d);
14118 + spin_lock(&d->d_lock);
14120 + spin_unlock(&d->d_lock);
14129 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
14132 + struct inode *inode;
14134 + inode = dentry->d_inode;
14135 + if (IS_ROOT(dentry)
14136 + /* || (inode && inode->i_ino == AUFS_ROOT_INO) */
14138 + pr_warn("branch root dir was changed\n");
14144 + au_digen_dec(dentry);
14146 + au_iigen_dec(inode);
14148 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
14150 + err = hn_gen_tree(dentry);
14157 +/* ---------------------------------------------------------------------- */
14159 +/* hnotify job flags */
14160 +#define AuHnJob_XINO0 1
14161 +#define AuHnJob_GEN (1 << 1)
14162 +#define AuHnJob_DIRENT (1 << 2)
14163 +#define AuHnJob_ISDIR (1 << 3)
14164 +#define AuHnJob_TRYXINO0 (1 << 4)
14165 +#define AuHnJob_MNTPNT (1 << 5)
14166 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
14167 +#define au_fset_hnjob(flags, name) \
14168 + do { (flags) |= AuHnJob_##name; } while (0)
14169 +#define au_fclr_hnjob(flags, name) \
14170 + do { (flags) &= ~AuHnJob_##name; } while (0)
14178 +struct au_hnotify_args {
14179 + struct inode *h_dir, *dir, *h_child_inode;
14181 + unsigned int flags[AuHnLast];
14182 + unsigned int h_child_nlen;
14183 + char h_child_name[];
14186 +struct hn_job_args {
14187 + unsigned int flags;
14188 + struct inode *inode, *h_inode, *dir, *h_dir;
14189 + struct dentry *dentry;
14194 +static int hn_job(struct hn_job_args *a)
14196 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
14199 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
14200 + hn_xino(a->inode, a->h_inode); /* ignore this error */
14202 + if (au_ftest_hnjob(a->flags, TRYXINO0)
14205 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
14206 + if (!a->h_inode->i_nlink)
14207 + hn_xino(a->inode, a->h_inode); /* ignore this error */
14208 + mutex_unlock(&a->h_inode->i_mutex);
14211 + /* make the generation obsolete */
14212 + if (au_ftest_hnjob(a->flags, GEN)) {
14215 + err = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
14217 + if (err && a->dentry)
14218 + hn_gen_by_name(a->dentry, isdir);
14219 + /* ignore this error */
14222 + /* make dir entries obsolete */
14223 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
14224 + struct au_vdir *vdir;
14226 + vdir = au_ivdir(a->inode);
14228 + vdir->vd_jiffy = 0;
14229 + /* IMustLock(a->inode); */
14230 + /* a->inode->i_version++; */
14233 + /* can do nothing but warn */
14234 + if (au_ftest_hnjob(a->flags, MNTPNT)
14236 + && d_mountpoint(a->dentry))
14237 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
14242 +/* ---------------------------------------------------------------------- */
14244 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
14245 + struct inode *dir)
14247 + struct dentry *dentry, *d, *parent;
14248 + struct qstr *dname;
14250 + parent = d_find_alias(dir);
14255 + spin_lock(&parent->d_lock);
14256 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
14257 + /* AuDbg("%pd\n", d); */
14258 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
14259 + dname = &d->d_name;
14260 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
14261 + goto cont_unlock;
14265 + goto cont_unlock;
14266 + if (d_count(d)) {
14267 + dentry = dget_dlock(d);
14268 + spin_unlock(&d->d_lock);
14273 + spin_unlock(&d->d_lock);
14275 + spin_unlock(&parent->d_lock);
14279 + di_write_lock_child(dentry);
14284 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
14285 + aufs_bindex_t bindex, ino_t h_ino)
14287 + struct inode *inode;
14292 + err = au_xino_read(sb, bindex, h_ino, &ino);
14294 + inode = ilookup(sb, ino);
14298 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
14299 + pr_warn("wrong root branch\n");
14305 + ii_write_lock_child(inode);
14311 +static void au_hn_bh(void *_args)
14313 + struct au_hnotify_args *a = _args;
14314 + struct super_block *sb;
14315 + aufs_bindex_t bindex, bend, bfound;
14316 + unsigned char xino, try_iput;
14318 + struct inode *inode;
14320 + struct hn_job_args args;
14321 + struct dentry *dentry;
14322 + struct au_sbinfo *sbinfo;
14324 + AuDebugOn(!_args);
14325 + AuDebugOn(!a->h_dir);
14326 + AuDebugOn(!a->dir);
14327 + AuDebugOn(!a->mask);
14328 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
14329 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
14330 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
14335 + * do not lock a->dir->i_mutex here
14336 + * because of d_revalidate() may cause a deadlock.
14338 + sb = a->dir->i_sb;
14340 + sbinfo = au_sbi(sb);
14341 + AuDebugOn(!sbinfo);
14342 + si_write_lock(sb, AuLock_NOPLMW);
14344 + ii_read_lock_parent(a->dir);
14346 + bend = au_ibend(a->dir);
14347 + for (bindex = au_ibstart(a->dir); bindex <= bend; bindex++)
14348 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
14352 + ii_read_unlock(a->dir);
14353 + if (unlikely(bfound < 0))
14356 + xino = !!au_opt_test(au_mntflags(sb), XINO);
14358 + if (a->h_child_inode)
14359 + h_ino = a->h_child_inode->i_ino;
14361 + if (a->h_child_nlen
14362 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
14363 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
14364 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
14368 + inode = dentry->d_inode;
14369 + if (xino && !inode && h_ino
14370 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
14371 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
14372 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
14373 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
14377 + args.flags = a->flags[AuHn_CHILD];
14378 + args.dentry = dentry;
14379 + args.inode = inode;
14380 + args.h_inode = a->h_child_inode;
14381 + args.dir = a->dir;
14382 + args.h_dir = a->h_dir;
14383 + args.h_name = a->h_child_name;
14384 + args.h_nlen = a->h_child_nlen;
14385 + err = hn_job(&args);
14387 + if (au_di(dentry))
14388 + di_write_unlock(dentry);
14391 + if (inode && try_iput) {
14392 + ii_write_unlock(inode);
14396 + ii_write_lock_parent(a->dir);
14397 + args.flags = a->flags[AuHn_PARENT];
14398 + args.dentry = NULL;
14399 + args.inode = a->dir;
14400 + args.h_inode = a->h_dir;
14402 + args.h_dir = NULL;
14403 + args.h_name = NULL;
14405 + err = hn_job(&args);
14406 + ii_write_unlock(a->dir);
14409 + iput(a->h_child_inode);
14412 + si_write_unlock(sb);
14413 + au_nwt_done(&sbinfo->si_nowait);
14417 +/* ---------------------------------------------------------------------- */
14419 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
14420 + struct qstr *h_child_qstr, struct inode *h_child_inode)
14423 + unsigned int flags[AuHnLast], f;
14424 + unsigned char isdir, isroot, wh;
14425 + struct inode *dir;
14426 + struct au_hnotify_args *args;
14427 + char *p, *h_child_name;
14430 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
14431 + dir = igrab(hnotify->hn_aufs_inode);
14435 + isroot = (dir->i_ino == AUFS_ROOT_INO);
14437 + h_child_name = (void *)h_child_qstr->name;
14438 + len = h_child_qstr->len;
14439 + if (h_child_name) {
14440 + if (len > AUFS_WH_PFX_LEN
14441 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
14442 + h_child_name += AUFS_WH_PFX_LEN;
14443 + len -= AUFS_WH_PFX_LEN;
14449 + if (h_child_inode)
14450 + isdir = !!S_ISDIR(h_child_inode->i_mode);
14451 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
14452 + flags[AuHn_CHILD] = 0;
14454 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
14455 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
14456 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
14457 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
14458 + case FS_MOVED_FROM:
14459 + case FS_MOVED_TO:
14460 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
14461 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
14464 + AuDebugOn(!h_child_name);
14469 + * aufs never be able to get this child inode.
14470 + * revalidation should be in d_revalidate()
14471 + * by checking i_nlink, i_generation or d_unhashed().
14473 + AuDebugOn(!h_child_name);
14474 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
14475 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
14483 + h_child_inode = NULL;
14486 + /* iput() and kfree() will be called in au_hnotify() */
14487 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
14488 + if (unlikely(!args)) {
14489 + AuErr1("no memory\n");
14493 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
14494 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
14495 + args->mask = mask;
14497 + args->h_dir = igrab(h_dir);
14498 + if (h_child_inode)
14499 + h_child_inode = igrab(h_child_inode); /* can be NULL */
14500 + args->h_child_inode = h_child_inode;
14501 + args->h_child_nlen = len;
14503 + p = (void *)args;
14504 + p += sizeof(*args);
14505 + memcpy(p, h_child_name, len);
14510 + if (!dir->i_nlink)
14512 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
14513 + if (unlikely(err)) {
14514 + pr_err("wkq %d\n", err);
14515 + iput(args->h_child_inode);
14516 + iput(args->h_dir);
14525 +/* ---------------------------------------------------------------------- */
14527 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
14531 + AuDebugOn(!(udba & AuOptMask_UDBA));
14534 + if (au_hnotify_op.reset_br)
14535 + err = au_hnotify_op.reset_br(udba, br, perm);
14540 +int au_hnotify_init_br(struct au_branch *br, int perm)
14545 + if (au_hnotify_op.init_br)
14546 + err = au_hnotify_op.init_br(br, perm);
14551 +void au_hnotify_fin_br(struct au_branch *br)
14553 + if (au_hnotify_op.fin_br)
14554 + au_hnotify_op.fin_br(br);
14557 +static void au_hn_destroy_cache(void)
14559 + kmem_cache_destroy(au_cachep[AuCache_HNOTIFY]);
14560 + au_cachep[AuCache_HNOTIFY] = NULL;
14563 +int __init au_hnotify_init(void)
14568 + au_cachep[AuCache_HNOTIFY] = AuCache(au_hnotify);
14569 + if (au_cachep[AuCache_HNOTIFY]) {
14571 + if (au_hnotify_op.init)
14572 + err = au_hnotify_op.init();
14573 + if (unlikely(err))
14574 + au_hn_destroy_cache();
14580 +void au_hnotify_fin(void)
14582 + if (au_hnotify_op.fin)
14583 + au_hnotify_op.fin();
14584 + /* cf. au_cache_fin() */
14585 + if (au_cachep[AuCache_HNOTIFY])
14586 + au_hn_destroy_cache();
14588 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
14589 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
14590 +++ linux/fs/aufs/iinfo.c 2014-04-24 22:11:10.855269116 +0200
14593 + * Copyright (C) 2005-2014 Junjiro R. Okajima
14595 + * This program, aufs is free software; you can redistribute it and/or modify
14596 + * it under the terms of the GNU General Public License as published by
14597 + * the Free Software Foundation; either version 2 of the License, or
14598 + * (at your option) any later version.
14600 + * This program is distributed in the hope that it will be useful,
14601 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14602 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14603 + * GNU General Public License for more details.
14605 + * You should have received a copy of the GNU General Public License
14606 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14610 + * inode private data
14615 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
14617 + struct inode *h_inode;
14619 + IiMustAnyLock(inode);
14621 + h_inode = au_ii(inode)->ii_hinode[0 + bindex].hi_inode;
14622 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
14626 +/* todo: hard/soft set? */
14627 +void au_hiput(struct au_hinode *hinode)
14629 + au_hn_free(hinode);
14630 + dput(hinode->hi_whdentry);
14631 + iput(hinode->hi_inode);
14634 +unsigned int au_hi_flags(struct inode *inode, int isdir)
14636 + unsigned int flags;
14637 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
14640 + if (au_opt_test(mnt_flags, XINO))
14641 + au_fset_hi(flags, XINO);
14642 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
14643 + au_fset_hi(flags, HNOTIFY);
14647 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
14648 + struct inode *h_inode, unsigned int flags)
14650 + struct au_hinode *hinode;
14651 + struct inode *hi;
14652 + struct au_iinfo *iinfo = au_ii(inode);
14654 + IiMustWriteLock(inode);
14656 + hinode = iinfo->ii_hinode + bindex;
14657 + hi = hinode->hi_inode;
14658 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
14661 + au_hiput(hinode);
14662 + hinode->hi_inode = h_inode;
14665 + struct super_block *sb = inode->i_sb;
14666 + struct au_branch *br;
14668 + AuDebugOn(inode->i_mode
14669 + && (h_inode->i_mode & S_IFMT)
14670 + != (inode->i_mode & S_IFMT));
14671 + if (bindex == iinfo->ii_bstart)
14672 + au_cpup_igen(inode, h_inode);
14673 + br = au_sbr(sb, bindex);
14674 + hinode->hi_id = br->br_id;
14675 + if (au_ftest_hi(flags, XINO)) {
14676 + err = au_xino_write(sb, bindex, h_inode->i_ino,
14678 + if (unlikely(err))
14679 + AuIOErr1("failed au_xino_write() %d\n", err);
14682 + if (au_ftest_hi(flags, HNOTIFY)
14683 + && au_br_hnotifyable(br->br_perm)) {
14684 + err = au_hn_alloc(hinode, inode);
14685 + if (unlikely(err))
14686 + AuIOErr1("au_hn_alloc() %d\n", err);
14691 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
14692 + struct dentry *h_wh)
14694 + struct au_hinode *hinode;
14696 + IiMustWriteLock(inode);
14698 + hinode = au_ii(inode)->ii_hinode + bindex;
14699 + AuDebugOn(hinode->hi_whdentry);
14700 + hinode->hi_whdentry = h_wh;
14703 +void au_update_iigen(struct inode *inode, int half)
14705 + struct au_iinfo *iinfo;
14706 + struct au_iigen *iigen;
14707 + unsigned int sigen;
14709 + sigen = au_sigen(inode->i_sb);
14710 + iinfo = au_ii(inode);
14711 + iigen = &iinfo->ii_generation;
14712 + spin_lock(&iinfo->ii_genspin);
14713 + iigen->ig_generation = sigen;
14715 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
14717 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
14718 + spin_unlock(&iinfo->ii_genspin);
14721 +/* it may be called at remount time, too */
14722 +void au_update_ibrange(struct inode *inode, int do_put_zero)
14724 + struct au_iinfo *iinfo;
14725 + aufs_bindex_t bindex, bend;
14727 + iinfo = au_ii(inode);
14731 + IiMustWriteLock(inode);
14733 + if (do_put_zero && iinfo->ii_bstart >= 0) {
14734 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
14736 + struct inode *h_i;
14738 + h_i = iinfo->ii_hinode[0 + bindex].hi_inode;
14739 + if (h_i && !h_i->i_nlink)
14740 + au_set_h_iptr(inode, bindex, NULL, 0);
14744 + iinfo->ii_bstart = -1;
14745 + iinfo->ii_bend = -1;
14746 + bend = au_sbend(inode->i_sb);
14747 + for (bindex = 0; bindex <= bend; bindex++)
14748 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
14749 + iinfo->ii_bstart = bindex;
14752 + if (iinfo->ii_bstart >= 0)
14753 + for (bindex = bend; bindex >= iinfo->ii_bstart; bindex--)
14754 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
14755 + iinfo->ii_bend = bindex;
14758 + AuDebugOn(iinfo->ii_bstart > iinfo->ii_bend);
14761 +/* ---------------------------------------------------------------------- */
14763 +void au_icntnr_init_once(void *_c)
14765 + struct au_icntnr *c = _c;
14766 + struct au_iinfo *iinfo = &c->iinfo;
14767 + static struct lock_class_key aufs_ii;
14769 + spin_lock_init(&iinfo->ii_genspin);
14770 + au_rw_init(&iinfo->ii_rwsem);
14771 + au_rw_class(&iinfo->ii_rwsem, &aufs_ii);
14772 + inode_init_once(&c->vfs_inode);
14775 +int au_iinfo_init(struct inode *inode)
14777 + struct au_iinfo *iinfo;
14778 + struct super_block *sb;
14781 + sb = inode->i_sb;
14782 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
14783 + nbr = au_sbend(sb) + 1;
14784 + if (unlikely(nbr <= 0))
14786 + iinfo->ii_hinode = kcalloc(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
14787 + if (iinfo->ii_hinode) {
14788 + au_ninodes_inc(sb);
14789 + for (i = 0; i < nbr; i++)
14790 + iinfo->ii_hinode[i].hi_id = -1;
14792 + iinfo->ii_generation.ig_generation = au_sigen(sb);
14793 + iinfo->ii_bstart = -1;
14794 + iinfo->ii_bend = -1;
14795 + iinfo->ii_vdir = NULL;
14801 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr)
14804 + struct au_hinode *hip;
14806 + AuRwMustWriteLock(&iinfo->ii_rwsem);
14809 + sz = sizeof(*hip) * (iinfo->ii_bend + 1);
14811 + sz = sizeof(*hip);
14812 + hip = au_kzrealloc(iinfo->ii_hinode, sz, sizeof(*hip) * nbr, GFP_NOFS);
14814 + iinfo->ii_hinode = hip;
14821 +void au_iinfo_fin(struct inode *inode)
14823 + struct au_iinfo *iinfo;
14824 + struct au_hinode *hi;
14825 + struct super_block *sb;
14826 + aufs_bindex_t bindex, bend;
14827 + const unsigned char unlinked = !inode->i_nlink;
14829 + iinfo = au_ii(inode);
14830 + /* bad_inode case */
14834 + sb = inode->i_sb;
14835 + au_ninodes_dec(sb);
14836 + if (si_pid_test(sb))
14837 + au_xino_delete_inode(inode, unlinked);
14840 + * it is safe to hide the dependency between sbinfo and
14844 + si_noflush_read_lock(sb);
14845 + au_xino_delete_inode(inode, unlinked);
14846 + si_read_unlock(sb);
14850 + if (iinfo->ii_vdir)
14851 + au_vdir_free(iinfo->ii_vdir);
14853 + bindex = iinfo->ii_bstart;
14854 + if (bindex >= 0) {
14855 + hi = iinfo->ii_hinode + bindex;
14856 + bend = iinfo->ii_bend;
14857 + while (bindex++ <= bend) {
14858 + if (hi->hi_inode)
14863 + kfree(iinfo->ii_hinode);
14864 + iinfo->ii_hinode = NULL;
14865 + AuRwDestroy(&iinfo->ii_rwsem);
14867 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
14868 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
14869 +++ linux/fs/aufs/inode.c 2014-04-24 22:11:10.855269116 +0200
14872 + * Copyright (C) 2005-2014 Junjiro R. Okajima
14874 + * This program, aufs is free software; you can redistribute it and/or modify
14875 + * it under the terms of the GNU General Public License as published by
14876 + * the Free Software Foundation; either version 2 of the License, or
14877 + * (at your option) any later version.
14879 + * This program is distributed in the hope that it will be useful,
14880 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14881 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14882 + * GNU General Public License for more details.
14884 + * You should have received a copy of the GNU General Public License
14885 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14889 + * inode functions
14894 +struct inode *au_igrab(struct inode *inode)
14897 + AuDebugOn(!atomic_read(&inode->i_count));
14903 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
14905 + au_cpup_attr_all(inode, /*force*/0);
14906 + au_update_iigen(inode, /*half*/1);
14908 + inode->i_version++;
14911 +static int au_ii_refresh(struct inode *inode, int *update)
14915 + aufs_bindex_t bindex, new_bindex;
14916 + struct super_block *sb;
14917 + struct au_iinfo *iinfo;
14918 + struct au_hinode *p, *q, tmp;
14920 + IiMustWriteLock(inode);
14923 + sb = inode->i_sb;
14924 + type = inode->i_mode & S_IFMT;
14925 + iinfo = au_ii(inode);
14926 + err = au_ii_realloc(iinfo, au_sbend(sb) + 1);
14927 + if (unlikely(err))
14930 + AuDebugOn(iinfo->ii_bstart < 0);
14931 + p = iinfo->ii_hinode + iinfo->ii_bstart;
14932 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
14934 + if (!p->hi_inode)
14937 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
14938 + new_bindex = au_br_index(sb, p->hi_id);
14939 + if (new_bindex == bindex)
14942 + if (new_bindex < 0) {
14945 + p->hi_inode = NULL;
14949 + if (new_bindex < iinfo->ii_bstart)
14950 + iinfo->ii_bstart = new_bindex;
14951 + if (iinfo->ii_bend < new_bindex)
14952 + iinfo->ii_bend = new_bindex;
14953 + /* swap two lower inode, and loop again */
14954 + q = iinfo->ii_hinode + new_bindex;
14958 + if (tmp.hi_inode) {
14963 + au_update_ibrange(inode, /*do_put_zero*/0);
14964 + e = au_dy_irefresh(inode);
14965 + if (unlikely(e && !err))
14973 +int au_refresh_hinode_self(struct inode *inode)
14977 + err = au_ii_refresh(inode, &update);
14979 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
14985 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
14987 + int err, e, update;
14988 + unsigned int flags;
14990 + aufs_bindex_t bindex, bend;
14991 + unsigned char isdir;
14992 + struct au_hinode *p;
14993 + struct au_iinfo *iinfo;
14995 + err = au_ii_refresh(inode, &update);
14996 + if (unlikely(err))
15000 + iinfo = au_ii(inode);
15001 + p = iinfo->ii_hinode + iinfo->ii_bstart;
15002 + mode = (inode->i_mode & S_IFMT);
15003 + isdir = S_ISDIR(mode);
15004 + flags = au_hi_flags(inode, isdir);
15005 + bend = au_dbend(dentry);
15006 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
15007 + struct inode *h_i;
15008 + struct dentry *h_d;
15010 + h_d = au_h_dptr(dentry, bindex);
15011 + if (!h_d || !h_d->d_inode)
15014 + AuDebugOn(mode != (h_d->d_inode->i_mode & S_IFMT));
15015 + if (iinfo->ii_bstart <= bindex && bindex <= iinfo->ii_bend) {
15016 + h_i = au_h_iptr(inode, bindex);
15018 + if (h_i == h_d->d_inode)
15024 + if (bindex < iinfo->ii_bstart)
15025 + iinfo->ii_bstart = bindex;
15026 + if (iinfo->ii_bend < bindex)
15027 + iinfo->ii_bend = bindex;
15028 + au_set_h_iptr(inode, bindex, au_igrab(h_d->d_inode), flags);
15031 + au_update_ibrange(inode, /*do_put_zero*/0);
15032 + e = au_dy_irefresh(inode);
15033 + if (unlikely(e && !err))
15036 + au_refresh_hinode_attr(inode, update && isdir);
15043 +static int set_inode(struct inode *inode, struct dentry *dentry)
15046 + unsigned int flags;
15048 + aufs_bindex_t bindex, bstart, btail;
15049 + unsigned char isdir;
15050 + struct dentry *h_dentry;
15051 + struct inode *h_inode;
15052 + struct au_iinfo *iinfo;
15054 + IiMustWriteLock(inode);
15058 + bstart = au_dbstart(dentry);
15059 + h_inode = au_h_dptr(dentry, bstart)->d_inode;
15060 + mode = h_inode->i_mode;
15061 + switch (mode & S_IFMT) {
15063 + btail = au_dbtail(dentry);
15064 + inode->i_op = &aufs_iop;
15065 + inode->i_fop = &aufs_file_fop;
15066 + err = au_dy_iaop(inode, bstart, h_inode);
15067 + if (unlikely(err))
15072 + btail = au_dbtaildir(dentry);
15073 + inode->i_op = &aufs_dir_iop;
15074 + inode->i_fop = &aufs_dir_fop;
15077 + btail = au_dbtail(dentry);
15078 + inode->i_op = &aufs_symlink_iop;
15084 + btail = au_dbtail(dentry);
15085 + inode->i_op = &aufs_iop;
15086 + au_init_special_fop(inode, mode, h_inode->i_rdev);
15089 + AuIOErr("Unknown file type 0%o\n", mode);
15094 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
15095 + flags = au_hi_flags(inode, isdir);
15096 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
15097 + && au_ftest_hi(flags, HNOTIFY)
15098 + && dentry->d_name.len > AUFS_WH_PFX_LEN
15099 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
15100 + au_fclr_hi(flags, HNOTIFY);
15101 + iinfo = au_ii(inode);
15102 + iinfo->ii_bstart = bstart;
15103 + iinfo->ii_bend = btail;
15104 + for (bindex = bstart; bindex <= btail; bindex++) {
15105 + h_dentry = au_h_dptr(dentry, bindex);
15107 + au_set_h_iptr(inode, bindex,
15108 + au_igrab(h_dentry->d_inode), flags);
15110 + au_cpup_attr_all(inode, /*force*/1);
15117 + * successful returns with iinfo write_locked
15119 + * zero: success, matched
15120 + * plus: no error, but unmatched
15122 +static int reval_inode(struct inode *inode, struct dentry *dentry)
15125 + unsigned int gen;
15126 + struct au_iigen iigen;
15127 + aufs_bindex_t bindex, bend;
15128 + struct inode *h_inode, *h_dinode;
15131 + * before this function, if aufs got any iinfo lock, it must be only
15132 + * one, the parent dir.
15133 + * it can happen by UDBA and the obsoleted inode number.
15136 + if (unlikely(inode->i_ino == parent_ino(dentry)))
15140 + ii_write_lock_new_child(inode);
15141 + h_dinode = au_h_dptr(dentry, au_dbstart(dentry))->d_inode;
15142 + bend = au_ibend(inode);
15143 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
15144 + h_inode = au_h_iptr(inode, bindex);
15145 + if (!h_inode || h_inode != h_dinode)
15149 + gen = au_iigen(inode, &iigen);
15150 + if (gen == au_digen(dentry)
15151 + && !au_ig_ftest(iigen.ig_flags, HALF_REFRESHED))
15154 + /* fully refresh inode using dentry */
15155 + err = au_refresh_hinode(inode, dentry);
15157 + au_update_iigen(inode, /*half*/0);
15161 + if (unlikely(err))
15162 + ii_write_unlock(inode);
15167 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
15168 + unsigned int d_type, ino_t *ino)
15171 + struct mutex *mtx;
15173 + /* prevent hardlinked inode number from race condition */
15175 + if (d_type != DT_DIR) {
15176 + mtx = &au_sbr(sb, bindex)->br_xino.xi_nondir_mtx;
15179 + err = au_xino_read(sb, bindex, h_ino, ino);
15180 + if (unlikely(err))
15185 + *ino = au_xino_new_ino(sb);
15186 + if (unlikely(!*ino))
15188 + err = au_xino_write(sb, bindex, h_ino, *ino);
15189 + if (unlikely(err))
15195 + mutex_unlock(mtx);
15199 +/* successful returns with iinfo write_locked */
15200 +/* todo: return with unlocked? */
15201 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
15203 + struct inode *inode, *h_inode;
15204 + struct dentry *h_dentry;
15205 + struct super_block *sb;
15206 + struct mutex *mtx;
15207 + ino_t h_ino, ino;
15209 + aufs_bindex_t bstart;
15211 + sb = dentry->d_sb;
15212 + bstart = au_dbstart(dentry);
15213 + h_dentry = au_h_dptr(dentry, bstart);
15214 + h_inode = h_dentry->d_inode;
15215 + h_ino = h_inode->i_ino;
15218 + * stop 'race'-ing between hardlinks under different
15222 + if (!S_ISDIR(h_inode->i_mode))
15223 + mtx = &au_sbr(sb, bstart)->br_xino.xi_nondir_mtx;
15228 + err = au_xino_read(sb, bstart, h_ino, &ino);
15229 + inode = ERR_PTR(err);
15230 + if (unlikely(err))
15234 + ino = au_xino_new_ino(sb);
15235 + if (unlikely(!ino)) {
15236 + inode = ERR_PTR(-EIO);
15241 + AuDbg("i%lu\n", (unsigned long)ino);
15242 + inode = au_iget_locked(sb, ino);
15243 + err = PTR_ERR(inode);
15244 + if (IS_ERR(inode))
15247 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
15248 + if (inode->i_state & I_NEW) {
15249 + /* verbose coding for lock class name */
15250 + if (unlikely(S_ISLNK(h_inode->i_mode)))
15251 + au_rw_class(&au_ii(inode)->ii_rwsem,
15252 + au_lc_key + AuLcSymlink_IIINFO);
15253 + else if (unlikely(S_ISDIR(h_inode->i_mode)))
15254 + au_rw_class(&au_ii(inode)->ii_rwsem,
15255 + au_lc_key + AuLcDir_IIINFO);
15256 + else /* likely */
15257 + au_rw_class(&au_ii(inode)->ii_rwsem,
15258 + au_lc_key + AuLcNonDir_IIINFO);
15260 + ii_write_lock_new_child(inode);
15261 + err = set_inode(inode, dentry);
15263 + unlock_new_inode(inode);
15264 + goto out; /* success */
15268 + * iget_failed() calls iput(), but we need to call
15269 + * ii_write_unlock() after iget_failed(). so dirty hack for
15272 + atomic_inc(&inode->i_count);
15273 + iget_failed(inode);
15274 + ii_write_unlock(inode);
15275 + au_xino_write(sb, bstart, h_ino, /*ino*/0);
15276 + /* ignore this error */
15278 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
15280 + * horrible race condition between lookup, readdir and copyup
15281 + * (or something).
15284 + mutex_unlock(mtx);
15285 + err = reval_inode(inode, dentry);
15286 + if (unlikely(err < 0)) {
15293 + goto out; /* success */
15298 + if (unlikely(au_test_fs_unique_ino(h_dentry->d_inode)))
15299 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
15300 + " b%d, %s, %pd, hi%lu, i%lu.\n",
15301 + bstart, au_sbtype(h_dentry->d_sb), dentry,
15302 + (unsigned long)h_ino, (unsigned long)ino);
15304 + err = au_xino_write(sb, bstart, h_ino, /*ino*/0);
15308 + mutex_unlock(mtx);
15314 + inode = ERR_PTR(err);
15317 + mutex_unlock(mtx);
15321 +/* ---------------------------------------------------------------------- */
15323 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
15324 + struct inode *inode)
15328 + err = au_br_rdonly(au_sbr(sb, bindex));
15330 + /* pseudo-link after flushed may happen out of bounds */
15333 + && au_ibstart(inode) <= bindex
15334 + && bindex <= au_ibend(inode)) {
15336 + * permission check is unnecessary since vfsub routine
15337 + * will be called later
15339 + struct inode *hi = au_h_iptr(inode, bindex);
15341 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
15347 +int au_test_h_perm(struct inode *h_inode, int mask)
15349 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
15351 + return inode_permission(h_inode, mask);
15354 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
15356 + if (au_test_nfs(h_inode->i_sb)
15357 + && (mask & MAY_WRITE)
15358 + && S_ISDIR(h_inode->i_mode))
15359 + mask |= MAY_READ; /* force permission check */
15360 + return au_test_h_perm(h_inode, mask);
15362 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
15363 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
15364 +++ linux/fs/aufs/inode.h 2014-04-24 22:11:10.855269116 +0200
15367 + * Copyright (C) 2005-2014 Junjiro R. Okajima
15369 + * This program, aufs is free software; you can redistribute it and/or modify
15370 + * it under the terms of the GNU General Public License as published by
15371 + * the Free Software Foundation; either version 2 of the License, or
15372 + * (at your option) any later version.
15374 + * This program is distributed in the hope that it will be useful,
15375 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15376 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15377 + * GNU General Public License for more details.
15379 + * You should have received a copy of the GNU General Public License
15380 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15384 + * inode operations
15387 +#ifndef __AUFS_INODE_H__
15388 +#define __AUFS_INODE_H__
15392 +#include <linux/fsnotify.h>
15393 +#include "rwsem.h"
15397 +struct au_hnotify {
15398 +#ifdef CONFIG_AUFS_HNOTIFY
15399 +#ifdef CONFIG_AUFS_HFSNOTIFY
15400 + /* never use fsnotify_add_vfsmount_mark() */
15401 + struct fsnotify_mark hn_mark;
15403 + struct inode *hn_aufs_inode; /* no get/put */
15405 +} ____cacheline_aligned_in_smp;
15407 +struct au_hinode {
15408 + struct inode *hi_inode;
15409 + aufs_bindex_t hi_id;
15410 +#ifdef CONFIG_AUFS_HNOTIFY
15411 + struct au_hnotify *hi_notify;
15414 + /* reference to the copied-up whiteout with get/put */
15415 + struct dentry *hi_whdentry;
15419 +#define AuIG_HALF_REFRESHED 1
15420 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
15421 +#define au_ig_fset(flags, name) \
15422 + do { (flags) |= AuIG_##name; } while (0)
15423 +#define au_ig_fclr(flags, name) \
15424 + do { (flags) &= ~AuIG_##name; } while (0)
15427 + __u32 ig_generation, ig_flags;
15432 + spinlock_t ii_genspin;
15433 + struct au_iigen ii_generation;
15434 + struct super_block *ii_hsb1; /* no get/put */
15436 + struct au_rwsem ii_rwsem;
15437 + aufs_bindex_t ii_bstart, ii_bend;
15439 + struct au_hinode *ii_hinode;
15440 + struct au_vdir *ii_vdir;
15443 +struct au_icntnr {
15444 + struct au_iinfo iinfo;
15445 + struct inode vfs_inode;
15446 +} ____cacheline_aligned_in_smp;
15448 +/* au_pin flags */
15449 +#define AuPin_DI_LOCKED 1
15450 +#define AuPin_MNT_WRITE (1 << 1)
15451 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
15452 +#define au_fset_pin(flags, name) \
15453 + do { (flags) |= AuPin_##name; } while (0)
15454 +#define au_fclr_pin(flags, name) \
15455 + do { (flags) &= ~AuPin_##name; } while (0)
15459 + struct dentry *dentry;
15460 + unsigned int udba;
15461 + unsigned char lsc_di, lsc_hi, flags;
15462 + aufs_bindex_t bindex;
15465 + struct dentry *parent;
15466 + struct au_hinode *hdir;
15467 + struct vfsmount *h_mnt;
15469 + /* temporary unlock/relock for copyup */
15470 + struct dentry *h_dentry, *h_parent;
15471 + struct au_branch *br;
15472 + struct task_struct *task;
15475 +void au_pin_hdir_unlock(struct au_pin *p);
15476 +int au_pin_hdir_relock(struct au_pin *p);
15477 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task);
15478 +void au_pin_hdir_acquire_nest(struct au_pin *p);
15479 +void au_pin_hdir_release(struct au_pin *p);
15481 +/* ---------------------------------------------------------------------- */
15483 +static inline struct au_iinfo *au_ii(struct inode *inode)
15485 + struct au_iinfo *iinfo;
15487 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
15488 + if (iinfo->ii_hinode)
15490 + return NULL; /* debugging bad_inode case */
15493 +/* ---------------------------------------------------------------------- */
15496 +struct inode *au_igrab(struct inode *inode);
15497 +int au_refresh_hinode_self(struct inode *inode);
15498 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
15499 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
15500 + unsigned int d_type, ino_t *ino);
15501 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
15502 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
15503 + struct inode *inode);
15504 +int au_test_h_perm(struct inode *h_inode, int mask);
15505 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
15507 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
15508 + ino_t h_ino, unsigned int d_type, ino_t *ino)
15510 +#ifdef CONFIG_AUFS_SHWH
15511 + return au_ino(sb, bindex, h_ino, d_type, ino);
15518 +extern struct inode_operations aufs_iop, aufs_symlink_iop, aufs_dir_iop;
15520 +/* au_wr_dir flags */
15521 +#define AuWrDir_ADD_ENTRY 1
15522 +#define AuWrDir_TMP_WHENTRY (1 << 1)
15523 +#define AuWrDir_ISDIR (1 << 2)
15524 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
15525 +#define au_fset_wrdir(flags, name) \
15526 + do { (flags) |= AuWrDir_##name; } while (0)
15527 +#define au_fclr_wrdir(flags, name) \
15528 + do { (flags) &= ~AuWrDir_##name; } while (0)
15530 +struct au_wr_dir_args {
15531 + aufs_bindex_t force_btgt;
15532 + unsigned char flags;
15534 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
15535 + struct au_wr_dir_args *args);
15537 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
15538 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
15539 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
15540 + unsigned int udba, unsigned char flags);
15541 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
15542 + unsigned int udba, unsigned char flags) __must_check;
15543 +int au_do_pin(struct au_pin *pin) __must_check;
15544 +void au_unpin(struct au_pin *pin);
15547 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
15548 + struct dentry *h_parent, int isdir);
15549 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
15551 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
15552 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
15554 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
15555 + struct dentry *dentry);
15556 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
15559 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
15560 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
15561 + struct dentry *h_parent, int isdir);
15562 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
15563 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
15566 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
15567 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
15568 + struct inode *dir, struct dentry *dentry);
15571 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
15572 +void au_hiput(struct au_hinode *hinode);
15573 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
15574 + struct dentry *h_wh);
15575 +unsigned int au_hi_flags(struct inode *inode, int isdir);
15577 +/* hinode flags */
15578 +#define AuHi_XINO 1
15579 +#define AuHi_HNOTIFY (1 << 1)
15580 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
15581 +#define au_fset_hi(flags, name) \
15582 + do { (flags) |= AuHi_##name; } while (0)
15583 +#define au_fclr_hi(flags, name) \
15584 + do { (flags) &= ~AuHi_##name; } while (0)
15586 +#ifndef CONFIG_AUFS_HNOTIFY
15587 +#undef AuHi_HNOTIFY
15588 +#define AuHi_HNOTIFY 0
15591 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
15592 + struct inode *h_inode, unsigned int flags);
15594 +void au_update_iigen(struct inode *inode, int half);
15595 +void au_update_ibrange(struct inode *inode, int do_put_zero);
15597 +void au_icntnr_init_once(void *_c);
15598 +int au_iinfo_init(struct inode *inode);
15599 +void au_iinfo_fin(struct inode *inode);
15600 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr);
15602 +#ifdef CONFIG_PROC_FS
15604 +int au_plink_maint(struct super_block *sb, int flags);
15605 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
15606 +int au_plink_maint_enter(struct super_block *sb);
15607 +#ifdef CONFIG_AUFS_DEBUG
15608 +void au_plink_list(struct super_block *sb);
15610 +AuStubVoid(au_plink_list, struct super_block *sb)
15612 +int au_plink_test(struct inode *inode);
15613 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
15614 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
15615 + struct dentry *h_dentry);
15616 +void au_plink_put(struct super_block *sb, int verbose);
15617 +void au_plink_clean(struct super_block *sb, int verbose);
15618 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
15620 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
15621 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
15622 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
15623 +AuStubVoid(au_plink_list, struct super_block *sb);
15624 +AuStubInt0(au_plink_test, struct inode *inode);
15625 +AuStub(struct dentry *, au_plink_lkup, return NULL,
15626 + struct inode *inode, aufs_bindex_t bindex);
15627 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
15628 + struct dentry *h_dentry);
15629 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
15630 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
15631 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
15632 +#endif /* CONFIG_PROC_FS */
15634 +/* ---------------------------------------------------------------------- */
15636 +/* lock subclass for iinfo */
15638 + AuLsc_II_CHILD, /* child first */
15639 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
15640 + AuLsc_II_CHILD3, /* copyup dirs */
15641 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
15642 + AuLsc_II_PARENT2,
15643 + AuLsc_II_PARENT3, /* copyup dirs */
15644 + AuLsc_II_NEW_CHILD
15648 + * ii_read_lock_child, ii_write_lock_child,
15649 + * ii_read_lock_child2, ii_write_lock_child2,
15650 + * ii_read_lock_child3, ii_write_lock_child3,
15651 + * ii_read_lock_parent, ii_write_lock_parent,
15652 + * ii_read_lock_parent2, ii_write_lock_parent2,
15653 + * ii_read_lock_parent3, ii_write_lock_parent3,
15654 + * ii_read_lock_new_child, ii_write_lock_new_child,
15656 +#define AuReadLockFunc(name, lsc) \
15657 +static inline void ii_read_lock_##name(struct inode *i) \
15659 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
15662 +#define AuWriteLockFunc(name, lsc) \
15663 +static inline void ii_write_lock_##name(struct inode *i) \
15665 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
15668 +#define AuRWLockFuncs(name, lsc) \
15669 + AuReadLockFunc(name, lsc) \
15670 + AuWriteLockFunc(name, lsc)
15672 +AuRWLockFuncs(child, CHILD);
15673 +AuRWLockFuncs(child2, CHILD2);
15674 +AuRWLockFuncs(child3, CHILD3);
15675 +AuRWLockFuncs(parent, PARENT);
15676 +AuRWLockFuncs(parent2, PARENT2);
15677 +AuRWLockFuncs(parent3, PARENT3);
15678 +AuRWLockFuncs(new_child, NEW_CHILD);
15680 +#undef AuReadLockFunc
15681 +#undef AuWriteLockFunc
15682 +#undef AuRWLockFuncs
15685 + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock
15687 +AuSimpleUnlockRwsemFuncs(ii, struct inode *i, &au_ii(i)->ii_rwsem);
15689 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
15690 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
15691 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
15693 +/* ---------------------------------------------------------------------- */
15695 +static inline void au_icntnr_init(struct au_icntnr *c)
15697 +#ifdef CONFIG_AUFS_DEBUG
15698 + c->vfs_inode.i_mode = 0;
15702 +static inline unsigned int au_iigen(struct inode *inode, struct au_iigen *iigen)
15704 + unsigned int gen;
15705 + struct au_iinfo *iinfo;
15707 + iinfo = au_ii(inode);
15708 + spin_lock(&iinfo->ii_genspin);
15710 + *iigen = iinfo->ii_generation;
15711 + gen = iinfo->ii_generation.ig_generation;
15712 + spin_unlock(&iinfo->ii_genspin);
15717 +/* tiny test for inode number */
15718 +/* tmpfs generation is too rough */
15719 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
15721 + struct au_iinfo *iinfo;
15723 + iinfo = au_ii(inode);
15724 + AuRwMustAnyLock(&iinfo->ii_rwsem);
15725 + return !(iinfo->ii_hsb1 == h_inode->i_sb
15726 + && iinfo->ii_higen == h_inode->i_generation);
15729 +static inline void au_iigen_dec(struct inode *inode)
15731 + struct au_iinfo *iinfo;
15733 + iinfo = au_ii(inode);
15734 + spin_lock(&iinfo->ii_genspin);
15735 + iinfo->ii_generation.ig_generation--;
15736 + spin_unlock(&iinfo->ii_genspin);
15739 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
15744 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
15750 +/* ---------------------------------------------------------------------- */
15752 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
15753 + aufs_bindex_t bindex)
15755 + IiMustAnyLock(inode);
15756 + return au_ii(inode)->ii_hinode[0 + bindex].hi_id;
15759 +static inline aufs_bindex_t au_ibstart(struct inode *inode)
15761 + IiMustAnyLock(inode);
15762 + return au_ii(inode)->ii_bstart;
15765 +static inline aufs_bindex_t au_ibend(struct inode *inode)
15767 + IiMustAnyLock(inode);
15768 + return au_ii(inode)->ii_bend;
15771 +static inline struct au_vdir *au_ivdir(struct inode *inode)
15773 + IiMustAnyLock(inode);
15774 + return au_ii(inode)->ii_vdir;
15777 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
15779 + IiMustAnyLock(inode);
15780 + return au_ii(inode)->ii_hinode[0 + bindex].hi_whdentry;
15783 +static inline void au_set_ibstart(struct inode *inode, aufs_bindex_t bindex)
15785 + IiMustWriteLock(inode);
15786 + au_ii(inode)->ii_bstart = bindex;
15789 +static inline void au_set_ibend(struct inode *inode, aufs_bindex_t bindex)
15791 + IiMustWriteLock(inode);
15792 + au_ii(inode)->ii_bend = bindex;
15795 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
15797 + IiMustWriteLock(inode);
15798 + au_ii(inode)->ii_vdir = vdir;
15801 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
15803 + IiMustAnyLock(inode);
15804 + return au_ii(inode)->ii_hinode + bindex;
15807 +/* ---------------------------------------------------------------------- */
15809 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
15812 + return pin->parent;
15816 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
15818 + if (pin && pin->hdir)
15819 + return pin->hdir->hi_inode;
15823 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
15826 + return pin->hdir;
15830 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
15833 + pin->dentry = dentry;
15836 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
15837 + unsigned char lflag)
15841 + au_fset_pin(pin->flags, DI_LOCKED);
15843 + au_fclr_pin(pin->flags, DI_LOCKED);
15847 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
15850 + dput(pin->parent);
15851 + pin->parent = dget(parent);
15855 +/* ---------------------------------------------------------------------- */
15858 +#ifdef CONFIG_AUFS_HNOTIFY
15859 +struct au_hnotify_op {
15860 + void (*ctl)(struct au_hinode *hinode, int do_set);
15861 + int (*alloc)(struct au_hinode *hinode);
15864 + * if it returns true, the the caller should free hinode->hi_notify,
15865 + * otherwise ->free() frees it.
15867 + int (*free)(struct au_hinode *hinode,
15868 + struct au_hnotify *hn) __must_check;
15870 + void (*fin)(void);
15871 + int (*init)(void);
15873 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
15874 + void (*fin_br)(struct au_branch *br);
15875 + int (*init_br)(struct au_branch *br, int perm);
15879 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
15880 +void au_hn_free(struct au_hinode *hinode);
15881 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
15882 +void au_hn_reset(struct inode *inode, unsigned int flags);
15883 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
15884 + struct qstr *h_child_qstr, struct inode *h_child_inode);
15885 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
15886 +int au_hnotify_init_br(struct au_branch *br, int perm);
15887 +void au_hnotify_fin_br(struct au_branch *br);
15888 +int __init au_hnotify_init(void);
15889 +void au_hnotify_fin(void);
15892 +extern const struct au_hnotify_op au_hnotify_op;
15895 +void au_hn_init(struct au_hinode *hinode)
15897 + hinode->hi_notify = NULL;
15900 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
15902 + return hinode->hi_notify;
15907 +int au_hn_alloc(struct au_hinode *hinode __maybe_unused,
15908 + struct inode *inode __maybe_unused)
15910 + return -EOPNOTSUPP;
15913 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
15918 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
15919 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
15920 + int do_set __maybe_unused)
15921 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
15922 + unsigned int flags __maybe_unused)
15923 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
15924 + struct au_branch *br __maybe_unused,
15925 + int perm __maybe_unused)
15926 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
15927 + int perm __maybe_unused)
15928 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
15929 +AuStubInt0(__init au_hnotify_init, void)
15930 +AuStubVoid(au_hnotify_fin, void)
15931 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
15932 +#endif /* CONFIG_AUFS_HNOTIFY */
15934 +static inline void au_hn_suspend(struct au_hinode *hdir)
15936 + au_hn_ctl(hdir, /*do_set*/0);
15939 +static inline void au_hn_resume(struct au_hinode *hdir)
15941 + au_hn_ctl(hdir, /*do_set*/1);
15944 +static inline void au_hn_imtx_lock(struct au_hinode *hdir)
15946 + mutex_lock(&hdir->hi_inode->i_mutex);
15947 + au_hn_suspend(hdir);
15950 +static inline void au_hn_imtx_lock_nested(struct au_hinode *hdir,
15951 + unsigned int sc __maybe_unused)
15953 + mutex_lock_nested(&hdir->hi_inode->i_mutex, sc);
15954 + au_hn_suspend(hdir);
15957 +static inline void au_hn_imtx_unlock(struct au_hinode *hdir)
15959 + au_hn_resume(hdir);
15960 + mutex_unlock(&hdir->hi_inode->i_mutex);
15963 +#endif /* __KERNEL__ */
15964 +#endif /* __AUFS_INODE_H__ */
15965 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
15966 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
15967 +++ linux/fs/aufs/ioctl.c 2014-04-24 22:11:10.855269116 +0200
15970 + * Copyright (C) 2005-2014 Junjiro R. Okajima
15972 + * This program, aufs is free software; you can redistribute it and/or modify
15973 + * it under the terms of the GNU General Public License as published by
15974 + * the Free Software Foundation; either version 2 of the License, or
15975 + * (at your option) any later version.
15977 + * This program is distributed in the hope that it will be useful,
15978 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15979 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15980 + * GNU General Public License for more details.
15982 + * You should have received a copy of the GNU General Public License
15983 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15988 + * plink-management and readdir in userspace.
15989 + * assist the pathconf(3) wrapper library.
15993 +#include <linux/compat.h>
15994 +#include <linux/file.h>
15997 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
16000 + aufs_bindex_t wbi, bindex, bend;
16001 + struct file *h_file;
16002 + struct super_block *sb;
16003 + struct dentry *root;
16004 + struct au_branch *br;
16005 + struct aufs_wbr_fd wbrfd = {
16006 + .oflags = au_dir_roflags,
16009 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
16010 + | O_NOATIME | O_CLOEXEC;
16012 + AuDebugOn(wbrfd.oflags & ~valid);
16015 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
16016 + if (unlikely(err)) {
16022 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
16023 + wbrfd.oflags |= au_dir_roflags;
16024 + AuDbg("0%o\n", wbrfd.oflags);
16025 + if (unlikely(wbrfd.oflags & ~valid))
16029 + fd = get_unused_fd();
16031 + if (unlikely(fd < 0))
16034 + h_file = ERR_PTR(-EINVAL);
16037 + sb = path->dentry->d_sb;
16038 + root = sb->s_root;
16039 + aufs_read_lock(root, AuLock_IR);
16040 + bend = au_sbend(sb);
16041 + if (wbrfd.brid >= 0) {
16042 + wbi = au_br_index(sb, wbrfd.brid);
16043 + if (unlikely(wbi < 0 || wbi > bend))
16047 + h_file = ERR_PTR(-ENOENT);
16048 + br = au_sbr(sb, wbi);
16049 + if (!au_br_writable(br->br_perm)) {
16053 + bindex = wbi + 1;
16055 + for (; bindex <= bend; bindex++) {
16056 + br = au_sbr(sb, bindex);
16057 + if (au_br_writable(br->br_perm)) {
16059 + br = au_sbr(sb, wbi);
16064 + AuDbg("wbi %d\n", wbi);
16066 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
16070 + aufs_read_unlock(root, AuLock_IR);
16071 + err = PTR_ERR(h_file);
16072 + if (IS_ERR(h_file))
16075 + atomic_dec(&br->br_count); /* cf. au_h_open() */
16076 + fd_install(fd, h_file);
16078 + goto out; /* success */
16081 + put_unused_fd(fd);
16087 +/* ---------------------------------------------------------------------- */
16089 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
16094 + case AUFS_CTL_RDU:
16095 + case AUFS_CTL_RDU_INO:
16096 + err = au_rdu_ioctl(file, cmd, arg);
16099 + case AUFS_CTL_WBR_FD:
16100 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
16103 + case AUFS_CTL_IBUSY:
16104 + err = au_ibusy_ioctl(file, arg);
16108 + /* do not call the lower */
16109 + AuDbg("0x%x\n", cmd);
16117 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
16122 + case AUFS_CTL_MVDOWN:
16123 + err = au_mvdown(file->f_dentry, (void __user *)arg);
16126 + case AUFS_CTL_WBR_FD:
16127 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
16131 + /* do not call the lower */
16132 + AuDbg("0x%x\n", cmd);
16140 +#ifdef CONFIG_COMPAT
16141 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
16142 + unsigned long arg)
16147 + case AUFS_CTL_RDU:
16148 + case AUFS_CTL_RDU_INO:
16149 + err = au_rdu_compat_ioctl(file, cmd, arg);
16152 + case AUFS_CTL_IBUSY:
16153 + err = au_ibusy_compat_ioctl(file, arg);
16157 + err = aufs_ioctl_dir(file, cmd, arg);
16164 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
16165 + unsigned long arg)
16167 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
16170 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
16171 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
16172 +++ linux/fs/aufs/i_op_add.c 2014-04-24 22:11:10.851935747 +0200
16175 + * Copyright (C) 2005-2014 Junjiro R. Okajima
16177 + * This program, aufs is free software; you can redistribute it and/or modify
16178 + * it under the terms of the GNU General Public License as published by
16179 + * the Free Software Foundation; either version 2 of the License, or
16180 + * (at your option) any later version.
16182 + * This program is distributed in the hope that it will be useful,
16183 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16184 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16185 + * GNU General Public License for more details.
16187 + * You should have received a copy of the GNU General Public License
16188 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16192 + * inode operations (add entry)
16198 + * final procedure of adding a new entry, except link(2).
16199 + * remove whiteout, instantiate, copyup the parent dir's times and size
16200 + * and update version.
16201 + * if it failed, re-create the removed whiteout.
16203 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
16204 + struct dentry *wh_dentry, struct dentry *dentry)
16207 + aufs_bindex_t bwh;
16208 + struct path h_path;
16209 + struct inode *inode, *h_dir;
16210 + struct dentry *wh;
16214 + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
16215 + IMustLock(h_dir);
16216 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
16217 + bwh = au_dbwh(dentry);
16218 + h_path.dentry = wh_dentry;
16219 + h_path.mnt = au_sbr_mnt(dir->i_sb, bindex);
16220 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
16222 + if (unlikely(err))
16226 + inode = au_new_inode(dentry, /*must_new*/1);
16227 + if (!IS_ERR(inode)) {
16228 + d_instantiate(dentry, inode);
16229 + dir = dentry->d_parent->d_inode; /* dir inode is locked */
16231 + if (au_ibstart(dir) == au_dbstart(dentry))
16232 + au_cpup_attr_timesizes(dir);
16233 + dir->i_version++;
16234 + return 0; /* success */
16237 + err = PTR_ERR(inode);
16242 + /* dir inode is locked */
16243 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
16244 + rerr = PTR_ERR(wh);
16245 + if (IS_ERR(wh)) {
16246 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
16247 + dentry, err, rerr);
16256 +static int au_d_may_add(struct dentry *dentry)
16261 + if (unlikely(d_unhashed(dentry)))
16263 + if (unlikely(dentry->d_inode))
16269 + * simple tests for the adding inode operations.
16270 + * following the checks in vfs, plus the parent-child relationship.
16272 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
16273 + struct dentry *h_parent, int isdir)
16277 + struct dentry *h_dentry;
16278 + struct inode *h_inode;
16280 + err = -ENAMETOOLONG;
16281 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
16284 + h_dentry = au_h_dptr(dentry, bindex);
16285 + h_inode = h_dentry->d_inode;
16286 + if (!dentry->d_inode) {
16288 + if (unlikely(h_inode))
16291 + /* rename(2) case */
16293 + if (unlikely(!h_inode || !h_inode->i_nlink))
16296 + h_mode = h_inode->i_mode;
16299 + if (unlikely(S_ISDIR(h_mode)))
16301 + } else if (unlikely(!S_ISDIR(h_mode))) {
16308 + /* expected parent dir is locked */
16309 + if (unlikely(h_parent != h_dentry->d_parent))
16318 + * initial procedure of adding a new entry.
16319 + * prepare writable branch and the parent dir, lock it,
16320 + * and lookup whiteout for the new entry.
16322 +static struct dentry*
16323 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
16324 + struct dentry *src_dentry, struct au_pin *pin,
16325 + struct au_wr_dir_args *wr_dir_args)
16327 + struct dentry *wh_dentry, *h_parent;
16328 + struct super_block *sb;
16329 + struct au_branch *br;
16331 + unsigned int udba;
16332 + aufs_bindex_t bcpup;
16334 + AuDbg("%pd\n", dentry);
16336 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
16338 + wh_dentry = ERR_PTR(err);
16339 + if (unlikely(err < 0))
16342 + sb = dentry->d_sb;
16343 + udba = au_opt_udba(sb);
16344 + err = au_pin(pin, dentry, bcpup, udba,
16345 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
16346 + wh_dentry = ERR_PTR(err);
16347 + if (unlikely(err))
16350 + h_parent = au_pinned_h_parent(pin);
16351 + if (udba != AuOpt_UDBA_NONE
16352 + && au_dbstart(dentry) == bcpup)
16353 + err = au_may_add(dentry, bcpup, h_parent,
16354 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
16355 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
16356 + err = -ENAMETOOLONG;
16357 + wh_dentry = ERR_PTR(err);
16358 + if (unlikely(err))
16361 + br = au_sbr(sb, bcpup);
16363 + struct path tmp = {
16364 + .dentry = h_parent,
16365 + .mnt = au_br_mnt(br)
16367 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
16370 + wh_dentry = NULL;
16371 + if (bcpup != au_dbwh(dentry))
16372 + goto out; /* success */
16374 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
16377 + if (IS_ERR(wh_dentry))
16380 + return wh_dentry;
16383 +/* ---------------------------------------------------------------------- */
16385 +enum { Mknod, Symlink, Creat };
16386 +struct simple_arg {
16394 + const char *symname;
16403 +static int add_simple(struct inode *dir, struct dentry *dentry,
16404 + struct simple_arg *arg)
16407 + aufs_bindex_t bstart;
16408 + unsigned char created;
16409 + struct dentry *wh_dentry, *parent;
16410 + struct inode *h_dir;
16411 + /* to reuduce stack size */
16413 + struct au_dtime dt;
16414 + struct au_pin pin;
16415 + struct path h_path;
16416 + struct au_wr_dir_args wr_dir_args;
16419 + AuDbg("%pd\n", dentry);
16423 + a = kmalloc(sizeof(*a), GFP_NOFS);
16424 + if (unlikely(!a))
16426 + a->wr_dir_args.force_btgt = -1;
16427 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
16429 + parent = dentry->d_parent; /* dir inode is locked */
16430 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
16431 + if (unlikely(err))
16433 + err = au_d_may_add(dentry);
16434 + if (unlikely(err))
16436 + di_write_lock_parent(parent);
16437 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
16438 + &a->pin, &a->wr_dir_args);
16439 + err = PTR_ERR(wh_dentry);
16440 + if (IS_ERR(wh_dentry))
16443 + bstart = au_dbstart(dentry);
16444 + a->h_path.dentry = au_h_dptr(dentry, bstart);
16445 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
16446 + h_dir = au_pinned_h_dir(&a->pin);
16447 + switch (arg->type) {
16449 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
16450 + arg->u.c.want_excl);
16453 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
16456 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
16464 + err = epilog(dir, bstart, wh_dentry, dentry);
16467 + if (unlikely(created && err && a->h_path.dentry->d_inode)) {
16469 + /* no delegation since it is just created */
16470 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
16473 + AuIOErr("%pd revert failure(%d, %d)\n",
16474 + dentry, err, rerr);
16477 + au_dtime_revert(&a->dt);
16480 + au_unpin(&a->pin);
16484 + di_write_unlock(parent);
16486 + if (unlikely(err)) {
16487 + au_update_dbstart(dentry);
16490 + aufs_read_unlock(dentry, AuLock_DW);
16497 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
16500 + struct simple_arg arg = {
16507 + return add_simple(dir, dentry, &arg);
16510 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
16512 + struct simple_arg arg = {
16514 + .u.s.symname = symname
16516 + return add_simple(dir, dentry, &arg);
16519 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
16522 + struct simple_arg arg = {
16526 + .want_excl = want_excl
16529 + return add_simple(dir, dentry, &arg);
16532 +/* ---------------------------------------------------------------------- */
16534 +struct au_link_args {
16535 + aufs_bindex_t bdst, bsrc;
16536 + struct au_pin pin;
16537 + struct path h_path;
16538 + struct dentry *src_parent, *parent;
16541 +static int au_cpup_before_link(struct dentry *src_dentry,
16542 + struct au_link_args *a)
16545 + struct dentry *h_src_dentry;
16546 + struct au_cp_generic cpg = {
16547 + .dentry = src_dentry,
16552 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
16555 + di_read_lock_parent(a->src_parent, AuLock_IR);
16556 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
16557 + if (unlikely(err))
16560 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
16561 + err = au_pin(&a->pin, src_dentry, a->bdst,
16562 + au_opt_udba(src_dentry->d_sb),
16563 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
16564 + if (unlikely(err))
16567 + err = au_sio_cpup_simple(&cpg);
16568 + au_unpin(&a->pin);
16571 + di_read_unlock(a->src_parent, AuLock_IR);
16575 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
16576 + struct au_link_args *a)
16579 + unsigned char plink;
16580 + aufs_bindex_t bend;
16581 + struct dentry *h_src_dentry;
16582 + struct inode *h_inode, *inode, *delegated;
16583 + struct super_block *sb;
16584 + struct file *h_file;
16588 + sb = src_dentry->d_sb;
16589 + inode = src_dentry->d_inode;
16590 + if (au_ibstart(inode) <= a->bdst)
16591 + h_inode = au_h_iptr(inode, a->bdst);
16592 + if (!h_inode || !h_inode->i_nlink) {
16593 + /* copyup src_dentry as the name of dentry. */
16594 + bend = au_dbend(dentry);
16595 + if (bend < a->bsrc)
16596 + au_set_dbend(dentry, a->bsrc);
16597 + au_set_h_dptr(dentry, a->bsrc,
16598 + dget(au_h_dptr(src_dentry, a->bsrc)));
16599 + dget(a->h_path.dentry);
16600 + au_set_h_dptr(dentry, a->bdst, NULL);
16601 + dentry->d_inode = src_dentry->d_inode; /* tmp */
16602 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
16603 + if (IS_ERR(h_file))
16604 + err = PTR_ERR(h_file);
16606 + struct au_cp_generic cpg = {
16607 + .dentry = dentry,
16612 + .flags = AuCpup_KEEPLINO
16614 + err = au_sio_cpup_simple(&cpg);
16615 + au_h_open_post(dentry, a->bsrc, h_file);
16617 + dput(a->h_path.dentry);
16618 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
16620 + au_set_h_dptr(dentry, a->bdst,
16621 + a->h_path.dentry);
16623 + dentry->d_inode = NULL; /* restore */
16624 + au_set_h_dptr(dentry, a->bsrc, NULL);
16625 + au_set_dbend(dentry, bend);
16627 + /* the inode of src_dentry already exists on a.bdst branch */
16628 + h_src_dentry = d_find_alias(h_inode);
16629 + if (!h_src_dentry && au_plink_test(inode)) {
16631 + h_src_dentry = au_plink_lkup(inode, a->bdst);
16632 + err = PTR_ERR(h_src_dentry);
16633 + if (IS_ERR(h_src_dentry))
16636 + if (unlikely(!h_src_dentry->d_inode)) {
16637 + dput(h_src_dentry);
16638 + h_src_dentry = NULL;
16642 + if (h_src_dentry) {
16643 + delegated = NULL;
16644 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
16645 + &a->h_path, &delegated);
16646 + if (unlikely(err == -EWOULDBLOCK)) {
16647 + pr_warn("cannot retry for NFSv4 delegation"
16648 + " for an internal link\n");
16651 + dput(h_src_dentry);
16653 + AuIOErr("no dentry found for hi%lu on b%d\n",
16654 + h_inode->i_ino, a->bdst);
16659 + if (!err && !plink)
16660 + au_plink_append(inode, a->bdst, a->h_path.dentry);
16667 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
16668 + struct dentry *dentry)
16671 + struct au_dtime dt;
16672 + struct au_link_args *a;
16673 + struct dentry *wh_dentry, *h_src_dentry;
16674 + struct inode *inode, *delegated;
16675 + struct super_block *sb;
16676 + struct au_wr_dir_args wr_dir_args = {
16677 + /* .force_btgt = -1, */
16678 + .flags = AuWrDir_ADD_ENTRY
16682 + inode = src_dentry->d_inode;
16683 + IMustLock(inode);
16686 + a = kzalloc(sizeof(*a), GFP_NOFS);
16687 + if (unlikely(!a))
16690 + a->parent = dentry->d_parent; /* dir inode is locked */
16691 + err = aufs_read_and_write_lock2(dentry, src_dentry,
16692 + AuLock_NOPLM | AuLock_GEN);
16693 + if (unlikely(err))
16695 + err = au_d_hashed_positive(src_dentry);
16696 + if (unlikely(err))
16698 + err = au_d_may_add(dentry);
16699 + if (unlikely(err))
16702 + a->src_parent = dget_parent(src_dentry);
16703 + wr_dir_args.force_btgt = au_ibstart(inode);
16705 + di_write_lock_parent(a->parent);
16706 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
16707 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
16709 + err = PTR_ERR(wh_dentry);
16710 + if (IS_ERR(wh_dentry))
16714 + sb = dentry->d_sb;
16715 + a->bdst = au_dbstart(dentry);
16716 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
16717 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
16718 + a->bsrc = au_ibstart(inode);
16719 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
16720 + if (!h_src_dentry) {
16721 + a->bsrc = au_dbstart(src_dentry);
16722 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
16723 + AuDebugOn(!h_src_dentry);
16724 + } else if (IS_ERR(h_src_dentry))
16727 + if (au_opt_test(au_mntflags(sb), PLINK)) {
16728 + if (a->bdst < a->bsrc
16729 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
16730 + err = au_cpup_or_link(src_dentry, dentry, a);
16732 + delegated = NULL;
16733 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
16734 + &a->h_path, &delegated);
16735 + if (unlikely(err == -EWOULDBLOCK)) {
16736 + pr_warn("cannot retry for NFSv4 delegation"
16737 + " for an internal link\n");
16741 + dput(h_src_dentry);
16744 + * copyup src_dentry to the branch we process,
16745 + * and then link(2) to it.
16747 + dput(h_src_dentry);
16748 + if (a->bdst < a->bsrc
16749 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
16750 + au_unpin(&a->pin);
16751 + di_write_unlock(a->parent);
16752 + err = au_cpup_before_link(src_dentry, a);
16753 + di_write_lock_parent(a->parent);
16755 + err = au_pin(&a->pin, dentry, a->bdst,
16757 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
16758 + if (unlikely(err))
16762 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
16764 + if (h_src_dentry && h_src_dentry->d_inode) {
16765 + delegated = NULL;
16766 + err = vfsub_link(h_src_dentry,
16767 + au_pinned_h_dir(&a->pin),
16768 + &a->h_path, &delegated);
16769 + if (unlikely(err == -EWOULDBLOCK)) {
16770 + pr_warn("cannot retry"
16771 + " for NFSv4 delegation"
16772 + " for an internal link\n");
16778 + if (unlikely(err))
16782 + a->h_path.dentry = wh_dentry;
16783 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
16785 + if (unlikely(err))
16789 + dir->i_version++;
16790 + if (au_ibstart(dir) == au_dbstart(dentry))
16791 + au_cpup_attr_timesizes(dir);
16792 + inc_nlink(inode);
16793 + inode->i_ctime = dir->i_ctime;
16794 + d_instantiate(dentry, au_igrab(inode));
16795 + if (d_unhashed(a->h_path.dentry))
16796 + /* some filesystem calls d_drop() */
16798 + goto out_unpin; /* success */
16801 + /* no delegation since it is just created */
16802 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
16803 + /*delegated*/NULL, /*force*/0);
16804 + if (unlikely(rerr)) {
16805 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
16808 + au_dtime_revert(&dt);
16810 + au_unpin(&a->pin);
16814 + di_write_unlock(a->parent);
16815 + dput(a->src_parent);
16817 + if (unlikely(err)) {
16818 + au_update_dbstart(dentry);
16821 + aufs_read_and_write_unlock2(dentry, src_dentry);
16829 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
16832 + aufs_bindex_t bindex;
16833 + unsigned char diropq;
16834 + struct path h_path;
16835 + struct dentry *wh_dentry, *parent, *opq_dentry;
16836 + struct mutex *h_mtx;
16837 + struct super_block *sb;
16839 + struct au_pin pin;
16840 + struct au_dtime dt;
16841 + } *a; /* reduce the stack usage */
16842 + struct au_wr_dir_args wr_dir_args = {
16843 + .force_btgt = -1,
16844 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
16850 + a = kmalloc(sizeof(*a), GFP_NOFS);
16851 + if (unlikely(!a))
16854 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
16855 + if (unlikely(err))
16857 + err = au_d_may_add(dentry);
16858 + if (unlikely(err))
16861 + parent = dentry->d_parent; /* dir inode is locked */
16862 + di_write_lock_parent(parent);
16863 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
16864 + &a->pin, &wr_dir_args);
16865 + err = PTR_ERR(wh_dentry);
16866 + if (IS_ERR(wh_dentry))
16869 + sb = dentry->d_sb;
16870 + bindex = au_dbstart(dentry);
16871 + h_path.dentry = au_h_dptr(dentry, bindex);
16872 + h_path.mnt = au_sbr_mnt(sb, bindex);
16873 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
16874 + if (unlikely(err))
16877 + /* make the dir opaque */
16879 + h_mtx = &h_path.dentry->d_inode->i_mutex;
16881 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
16882 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
16883 + opq_dentry = au_diropq_create(dentry, bindex);
16884 + mutex_unlock(h_mtx);
16885 + err = PTR_ERR(opq_dentry);
16886 + if (IS_ERR(opq_dentry))
16888 + dput(opq_dentry);
16892 + err = epilog(dir, bindex, wh_dentry, dentry);
16895 + goto out_unpin; /* success */
16900 + AuLabel(revert opq);
16901 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
16902 + rerr = au_diropq_remove(dentry, bindex);
16903 + mutex_unlock(h_mtx);
16905 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
16906 + dentry, err, rerr);
16912 + AuLabel(revert dir);
16913 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
16915 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
16916 + dentry, err, rerr);
16919 + au_dtime_revert(&a->dt);
16921 + au_unpin(&a->pin);
16924 + di_write_unlock(parent);
16926 + if (unlikely(err)) {
16927 + au_update_dbstart(dentry);
16930 + aufs_read_unlock(dentry, AuLock_DW);
16936 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
16937 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
16938 +++ linux/fs/aufs/i_op.c 2014-04-24 22:11:10.851935747 +0200
16941 + * Copyright (C) 2005-2014 Junjiro R. Okajima
16943 + * This program, aufs is free software; you can redistribute it and/or modify
16944 + * it under the terms of the GNU General Public License as published by
16945 + * the Free Software Foundation; either version 2 of the License, or
16946 + * (at your option) any later version.
16948 + * This program is distributed in the hope that it will be useful,
16949 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16950 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16951 + * GNU General Public License for more details.
16953 + * You should have received a copy of the GNU General Public License
16954 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16958 + * inode operations (except add/del/rename)
16961 +#include <linux/device_cgroup.h>
16962 +#include <linux/fs_stack.h>
16963 +#include <linux/mm.h>
16964 +#include <linux/namei.h>
16965 +#include <linux/security.h>
16968 +static int h_permission(struct inode *h_inode, int mask,
16969 + struct vfsmount *h_mnt, int brperm)
16972 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
16975 + if ((write_mask && IS_IMMUTABLE(h_inode))
16976 + || ((mask & MAY_EXEC)
16977 + && S_ISREG(h_inode->i_mode)
16978 + && ((h_mnt->mnt_flags & MNT_NOEXEC)
16979 + || !(h_inode->i_mode & S_IXUGO))))
16983 + * - skip the lower fs test in the case of write to ro branch.
16984 + * - nfs dir permission write check is optimized, but a policy for
16985 + * link/rename requires a real check.
16987 + if ((write_mask && !au_br_writable(brperm))
16988 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
16989 + && write_mask && !(mask & MAY_READ))
16990 + || !h_inode->i_op->permission) {
16991 + /* AuLabel(generic_permission); */
16992 + err = generic_permission(h_inode, mask);
16994 + /* AuLabel(h_inode->permission); */
16995 + err = h_inode->i_op->permission(h_inode, mask);
17000 + err = devcgroup_inode_permission(h_inode, mask);
17002 + err = security_inode_permission(h_inode, mask);
17006 + /* todo: do we need to call ima_path_check()? */
17007 + struct path h_path = {
17011 + err = ima_path_check(&h_path,
17012 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
17013 + IMA_COUNT_LEAVE);
17021 +static int aufs_permission(struct inode *inode, int mask)
17024 + aufs_bindex_t bindex, bend;
17025 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
17026 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
17027 + struct inode *h_inode;
17028 + struct super_block *sb;
17029 + struct au_branch *br;
17031 + /* todo: support rcu-walk? */
17032 + if (mask & MAY_NOT_BLOCK)
17035 + sb = inode->i_sb;
17036 + si_read_lock(sb, AuLock_FLUSH);
17037 + ii_read_lock_child(inode);
17039 + err = au_iigen_test(inode, au_sigen(sb));
17040 + if (unlikely(err))
17044 + if (!isdir || write_mask) {
17045 + err = au_busy_or_stale();
17046 + h_inode = au_h_iptr(inode, au_ibstart(inode));
17047 + if (unlikely(!h_inode
17048 + || (h_inode->i_mode & S_IFMT)
17049 + != (inode->i_mode & S_IFMT)))
17053 + bindex = au_ibstart(inode);
17054 + br = au_sbr(sb, bindex);
17055 + err = h_permission(h_inode, mask, au_br_mnt(br), br->br_perm);
17058 + && !special_file(h_inode->i_mode)) {
17059 + /* test whether the upper writable branch exists */
17061 + for (; bindex >= 0; bindex--)
17062 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
17070 + /* non-write to dir */
17072 + bend = au_ibend(inode);
17073 + for (bindex = au_ibstart(inode); !err && bindex <= bend; bindex++) {
17074 + h_inode = au_h_iptr(inode, bindex);
17076 + err = au_busy_or_stale();
17077 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
17080 + br = au_sbr(sb, bindex);
17081 + err = h_permission(h_inode, mask, au_br_mnt(br),
17087 + ii_read_unlock(inode);
17088 + si_read_unlock(sb);
17092 +/* ---------------------------------------------------------------------- */
17094 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
17095 + unsigned int flags)
17097 + struct dentry *ret, *parent;
17098 + struct inode *inode;
17099 + struct super_block *sb;
17100 + int err, npositive;
17104 + /* todo: support rcu-walk? */
17105 + ret = ERR_PTR(-ECHILD);
17106 + if (flags & LOOKUP_RCU)
17109 + ret = ERR_PTR(-ENAMETOOLONG);
17110 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17114 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
17115 + ret = ERR_PTR(err);
17116 + if (unlikely(err))
17119 + err = au_di_init(dentry);
17120 + ret = ERR_PTR(err);
17121 + if (unlikely(err))
17125 + npositive = 0; /* suppress a warning */
17126 + parent = dentry->d_parent; /* dir inode is locked */
17127 + di_read_lock_parent(parent, AuLock_IR);
17128 + err = au_alive_dir(parent);
17130 + err = au_digen_test(parent, au_sigen(sb));
17132 + npositive = au_lkup_dentry(dentry, au_dbstart(parent),
17136 + di_read_unlock(parent, AuLock_IR);
17137 + ret = ERR_PTR(err);
17138 + if (unlikely(err < 0))
17142 + inode = au_new_inode(dentry, /*must_new*/0);
17143 + ret = (void *)inode;
17145 + if (IS_ERR(inode)) {
17150 + ret = d_splice_alias(inode, dentry);
17152 + if (unlikely(d_need_lookup(dentry))) {
17153 + spin_lock(&dentry->d_lock);
17154 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
17155 + spin_unlock(&dentry->d_lock);
17158 + if (unlikely(IS_ERR(ret) && inode)) {
17159 + ii_write_unlock(inode);
17165 + di_write_unlock(dentry);
17167 + /* verbose coding for lock class name */
17168 + if (unlikely(S_ISLNK(inode->i_mode)))
17169 + au_rw_class(&au_di(dentry)->di_rwsem,
17170 + au_lc_key + AuLcSymlink_DIINFO);
17171 + else if (unlikely(S_ISDIR(inode->i_mode)))
17172 + au_rw_class(&au_di(dentry)->di_rwsem,
17173 + au_lc_key + AuLcDir_DIINFO);
17174 + else /* likely */
17175 + au_rw_class(&au_di(dentry)->di_rwsem,
17176 + au_lc_key + AuLcNonDir_DIINFO);
17179 + si_read_unlock(sb);
17184 +/* ---------------------------------------------------------------------- */
17186 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
17187 + const unsigned char add_entry, aufs_bindex_t bcpup,
17188 + aufs_bindex_t bstart)
17191 + struct dentry *h_parent;
17192 + struct inode *h_dir;
17195 + IMustLock(parent->d_inode);
17197 + di_write_lock_parent(parent);
17200 + if (!au_h_dptr(parent, bcpup)) {
17201 + if (bstart > bcpup)
17202 + err = au_cpup_dirs(dentry, bcpup);
17203 + else if (bstart < bcpup)
17204 + err = au_cpdown_dirs(dentry, bcpup);
17208 + if (!err && add_entry) {
17209 + h_parent = au_h_dptr(parent, bcpup);
17210 + h_dir = h_parent->d_inode;
17211 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
17212 + err = au_lkup_neg(dentry, bcpup,
17213 + au_ftest_wrdir(add_entry, TMP_WHENTRY));
17214 + /* todo: no unlock here */
17215 + mutex_unlock(&h_dir->i_mutex);
17217 + AuDbg("bcpup %d\n", bcpup);
17219 + if (!dentry->d_inode)
17220 + au_set_h_dptr(dentry, bstart, NULL);
17221 + au_update_dbrange(dentry, /*do_put_zero*/0);
17226 + di_write_unlock(parent);
17228 + err = bcpup; /* success */
17235 + * decide the branch and the parent dir where we will create a new entry.
17236 + * returns new bindex or an error.
17237 + * copyup the parent dir if needed.
17239 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
17240 + struct au_wr_dir_args *args)
17243 + unsigned int flags;
17244 + aufs_bindex_t bcpup, bstart, src_bstart;
17245 + const unsigned char add_entry
17246 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
17247 + | au_ftest_wrdir(args->flags, TMP_WHENTRY);
17248 + struct super_block *sb;
17249 + struct dentry *parent;
17250 + struct au_sbinfo *sbinfo;
17252 + sb = dentry->d_sb;
17253 + sbinfo = au_sbi(sb);
17254 + parent = dget_parent(dentry);
17255 + bstart = au_dbstart(dentry);
17257 + if (args->force_btgt < 0) {
17258 + if (src_dentry) {
17259 + src_bstart = au_dbstart(src_dentry);
17260 + if (src_bstart < bstart)
17261 + bcpup = src_bstart;
17262 + } else if (add_entry) {
17264 + if (au_ftest_wrdir(args->flags, ISDIR))
17265 + au_fset_wbr(flags, DIR);
17266 + err = AuWbrCreate(sbinfo, dentry, flags);
17270 + if (bcpup < 0 || au_test_ro(sb, bcpup, dentry->d_inode)) {
17272 + err = AuWbrCopyup(sbinfo, dentry);
17274 + if (!IS_ROOT(dentry)) {
17275 + di_read_lock_parent(parent, !AuLock_IR);
17276 + err = AuWbrCopyup(sbinfo, dentry);
17277 + di_read_unlock(parent, !AuLock_IR);
17279 + err = AuWbrCopyup(sbinfo, dentry);
17282 + if (unlikely(err < 0))
17286 + bcpup = args->force_btgt;
17287 + AuDebugOn(au_test_ro(sb, bcpup, dentry->d_inode));
17290 + AuDbg("bstart %d, bcpup %d\n", bstart, bcpup);
17292 + if (bcpup == bstart)
17293 + goto out; /* success */
17295 + /* copyup the new parent into the branch we process */
17296 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, bstart);
17298 + if (!dentry->d_inode) {
17299 + au_set_h_dptr(dentry, bstart, NULL);
17300 + au_set_dbstart(dentry, bcpup);
17301 + au_set_dbend(dentry, bcpup);
17303 + AuDebugOn(add_entry && !au_h_dptr(dentry, bcpup));
17311 +/* ---------------------------------------------------------------------- */
17313 +void au_pin_hdir_unlock(struct au_pin *p)
17316 + au_hn_imtx_unlock(p->hdir);
17319 +static int au_pin_hdir_lock(struct au_pin *p)
17327 + /* even if an error happens later, keep this lock */
17328 + au_hn_imtx_lock_nested(p->hdir, p->lsc_hi);
17331 + if (unlikely(p->hdir->hi_inode != p->h_parent->d_inode))
17336 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
17337 + p->h_parent, p->br);
17343 +int au_pin_hdir_relock(struct au_pin *p)
17346 + struct inode *h_i;
17347 + struct dentry *h_d[] = {
17352 + err = au_pin_hdir_lock(p);
17353 + if (unlikely(err))
17356 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
17359 + h_i = h_d[i]->d_inode;
17361 + err = !h_i->i_nlink;
17368 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
17370 +#if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
17371 + p->hdir->hi_inode->i_mutex.owner = task;
17375 +void au_pin_hdir_acquire_nest(struct au_pin *p)
17378 + mutex_acquire_nest(&p->hdir->hi_inode->i_mutex.dep_map,
17379 + p->lsc_hi, 0, NULL, _RET_IP_);
17380 + au_pin_hdir_set_owner(p, current);
17384 +void au_pin_hdir_release(struct au_pin *p)
17387 + au_pin_hdir_set_owner(p, p->task);
17388 + mutex_release(&p->hdir->hi_inode->i_mutex.dep_map, 1, _RET_IP_);
17392 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
17394 + if (pin && pin->parent)
17395 + return au_h_dptr(pin->parent, pin->bindex);
17399 +void au_unpin(struct au_pin *p)
17402 + au_pin_hdir_unlock(p);
17403 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
17404 + vfsub_mnt_drop_write(p->h_mnt);
17408 + if (!au_ftest_pin(p->flags, DI_LOCKED))
17409 + di_read_unlock(p->parent, AuLock_IR);
17410 + iput(p->hdir->hi_inode);
17412 + p->parent = NULL;
17415 + /* do not clear p->task */
17418 +int au_do_pin(struct au_pin *p)
17421 + struct super_block *sb;
17422 + struct inode *h_dir;
17425 + sb = p->dentry->d_sb;
17426 + p->br = au_sbr(sb, p->bindex);
17427 + if (IS_ROOT(p->dentry)) {
17428 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
17429 + p->h_mnt = au_br_mnt(p->br);
17430 + err = vfsub_mnt_want_write(p->h_mnt);
17431 + if (unlikely(err)) {
17432 + au_fclr_pin(p->flags, MNT_WRITE);
17439 + p->h_dentry = NULL;
17440 + if (p->bindex <= au_dbend(p->dentry))
17441 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
17443 + p->parent = dget_parent(p->dentry);
17444 + if (!au_ftest_pin(p->flags, DI_LOCKED))
17445 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
17448 + p->h_parent = au_h_dptr(p->parent, p->bindex);
17449 + p->hdir = au_hi(p->parent->d_inode, p->bindex);
17451 + h_dir = p->hdir->hi_inode;
17455 + * if DI_LOCKED is not set, then p->parent may be different
17456 + * and h_parent can be NULL.
17458 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
17460 + if (!au_ftest_pin(p->flags, DI_LOCKED))
17461 + di_read_unlock(p->parent, AuLock_IR);
17463 + p->parent = NULL;
17467 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
17468 + p->h_mnt = au_br_mnt(p->br);
17469 + err = vfsub_mnt_want_write(p->h_mnt);
17470 + if (unlikely(err)) {
17471 + au_fclr_pin(p->flags, MNT_WRITE);
17472 + if (!au_ftest_pin(p->flags, DI_LOCKED))
17473 + di_read_unlock(p->parent, AuLock_IR);
17475 + p->parent = NULL;
17481 + err = au_pin_hdir_lock(p);
17483 + goto out; /* success */
17486 + pr_err("err %d\n", err);
17487 + err = au_busy_or_stale();
17492 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
17493 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
17494 + unsigned int udba, unsigned char flags)
17496 + p->dentry = dentry;
17498 + p->lsc_di = lsc_di;
17499 + p->lsc_hi = lsc_hi;
17500 + p->flags = flags;
17501 + p->bindex = bindex;
17503 + p->parent = NULL;
17507 + p->h_dentry = NULL;
17508 + p->h_parent = NULL;
17510 + p->task = current;
17513 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
17514 + unsigned int udba, unsigned char flags)
17516 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
17518 + return au_do_pin(pin);
17521 +/* ---------------------------------------------------------------------- */
17524 + * ->setattr() and ->getattr() are called in various cases.
17525 + * chmod, stat: dentry is revalidated.
17526 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
17528 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
17530 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
17531 +static int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
17534 + struct inode *inode;
17535 + struct dentry *parent;
17538 + inode = dentry->d_inode;
17539 + if (au_digen_test(dentry, sigen)) {
17540 + parent = dget_parent(dentry);
17541 + di_read_lock_parent(parent, AuLock_IR);
17542 + err = au_refresh_dentry(dentry, parent);
17543 + di_read_unlock(parent, AuLock_IR);
17551 +#define AuIcpup_DID_CPUP 1
17552 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
17553 +#define au_fset_icpup(flags, name) \
17554 + do { (flags) |= AuIcpup_##name; } while (0)
17555 +#define au_fclr_icpup(flags, name) \
17556 + do { (flags) &= ~AuIcpup_##name; } while (0)
17558 +struct au_icpup_args {
17559 + unsigned char flags;
17560 + unsigned char pin_flags;
17561 + aufs_bindex_t btgt;
17562 + unsigned int udba;
17563 + struct au_pin pin;
17564 + struct path h_path;
17565 + struct inode *h_inode;
17568 +static int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
17569 + struct au_icpup_args *a)
17573 + aufs_bindex_t bstart, ibstart;
17574 + struct dentry *hi_wh, *parent;
17575 + struct inode *inode;
17576 + struct au_wr_dir_args wr_dir_args = {
17577 + .force_btgt = -1,
17581 + bstart = au_dbstart(dentry);
17582 + inode = dentry->d_inode;
17583 + if (S_ISDIR(inode->i_mode))
17584 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
17585 + /* plink or hi_wh() case */
17586 + ibstart = au_ibstart(inode);
17587 + if (bstart != ibstart && !au_test_ro(inode->i_sb, ibstart, inode))
17588 + wr_dir_args.force_btgt = ibstart;
17589 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
17590 + if (unlikely(err < 0))
17593 + if (err != bstart)
17594 + au_fset_icpup(a->flags, DID_CPUP);
17597 + a->pin_flags = AuPin_MNT_WRITE;
17599 + if (!IS_ROOT(dentry)) {
17600 + au_fset_pin(a->pin_flags, DI_LOCKED);
17601 + parent = dget_parent(dentry);
17602 + di_write_lock_parent(parent);
17605 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
17606 + if (unlikely(err))
17609 + a->h_path.dentry = au_h_dptr(dentry, bstart);
17610 + a->h_inode = a->h_path.dentry->d_inode;
17611 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
17613 + if ((ia->ia_valid & ATTR_SIZE) && ia->ia_size < i_size_read(a->h_inode))
17614 + sz = ia->ia_size;
17615 + mutex_unlock(&a->h_inode->i_mutex);
17618 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
17619 + hi_wh = au_hi_wh(inode, a->btgt);
17621 + struct au_cp_generic cpg = {
17622 + .dentry = dentry,
17628 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
17629 + if (unlikely(err))
17631 + hi_wh = au_hi_wh(inode, a->btgt);
17632 + /* todo: revalidate hi_wh? */
17637 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
17638 + di_downgrade_lock(parent, AuLock_IR);
17642 + if (!au_ftest_icpup(a->flags, DID_CPUP))
17643 + goto out; /* success */
17645 + if (!d_unhashed(dentry)) {
17646 + struct au_cp_generic cpg = {
17647 + .dentry = dentry,
17652 + .flags = AuCpup_DTIME | AuCpup_HOPEN
17654 + err = au_sio_cpup_simple(&cpg);
17656 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
17657 + } else if (!hi_wh)
17658 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
17660 + a->h_path.dentry = hi_wh; /* do not dget here */
17663 + a->h_inode = a->h_path.dentry->d_inode;
17665 + goto out; /* success */
17666 + au_unpin(&a->pin);
17669 + di_write_unlock(parent);
17674 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
17678 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
17681 + struct inode *inode, *delegated;
17682 + struct super_block *sb;
17683 + struct file *file;
17684 + struct au_icpup_args *a;
17686 + inode = dentry->d_inode;
17687 + IMustLock(inode);
17690 + a = kzalloc(sizeof(*a), GFP_NOFS);
17691 + if (unlikely(!a))
17694 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
17695 + ia->ia_valid &= ~ATTR_MODE;
17698 + sb = dentry->d_sb;
17699 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
17700 + if (unlikely(err))
17703 + if (ia->ia_valid & ATTR_FILE) {
17704 + /* currently ftruncate(2) only */
17705 + AuDebugOn(!S_ISREG(inode->i_mode));
17706 + file = ia->ia_file;
17707 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
17708 + if (unlikely(err))
17710 + ia->ia_file = au_hf_top(file);
17711 + a->udba = AuOpt_UDBA_NONE;
17713 + /* fchmod() doesn't pass ia_file */
17714 + a->udba = au_opt_udba(sb);
17715 + di_write_lock_child(dentry);
17716 + /* no d_unlinked(), to set UDBA_NONE for root */
17717 + if (d_unhashed(dentry))
17718 + a->udba = AuOpt_UDBA_NONE;
17719 + if (a->udba != AuOpt_UDBA_NONE) {
17720 + AuDebugOn(IS_ROOT(dentry));
17721 + err = au_reval_for_attr(dentry, au_sigen(sb));
17722 + if (unlikely(err))
17727 + err = au_pin_and_icpup(dentry, ia, a);
17728 + if (unlikely(err < 0))
17730 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
17731 + ia->ia_file = NULL;
17732 + ia->ia_valid &= ~ATTR_FILE;
17735 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
17736 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
17737 + == (ATTR_MODE | ATTR_CTIME)) {
17738 + err = security_path_chmod(&a->h_path, ia->ia_mode);
17739 + if (unlikely(err))
17741 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
17742 + && (ia->ia_valid & ATTR_CTIME)) {
17743 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
17744 + if (unlikely(err))
17748 + if (ia->ia_valid & ATTR_SIZE) {
17751 + if (ia->ia_size < i_size_read(inode))
17753 + truncate_setsize(inode, ia->ia_size);
17756 + if (ia->ia_valid & ATTR_FILE)
17758 + mutex_unlock(&a->h_inode->i_mutex);
17759 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
17760 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
17762 + delegated = NULL;
17764 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
17766 + err = break_deleg_wait(&delegated);
17774 + au_cpup_attr_changeable(inode);
17777 + mutex_unlock(&a->h_inode->i_mutex);
17778 + au_unpin(&a->pin);
17779 + if (unlikely(err))
17780 + au_update_dbstart(dentry);
17782 + di_write_unlock(dentry);
17784 + fi_write_unlock(file);
17785 + ia->ia_file = file;
17786 + ia->ia_valid |= ATTR_FILE;
17789 + si_read_unlock(sb);
17797 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
17798 + unsigned int nlink)
17802 + inode->i_mode = st->mode;
17803 + /* don't i_[ug]id_write() here */
17804 + inode->i_uid = st->uid;
17805 + inode->i_gid = st->gid;
17806 + inode->i_atime = st->atime;
17807 + inode->i_mtime = st->mtime;
17808 + inode->i_ctime = st->ctime;
17810 + au_cpup_attr_nlink(inode, /*force*/0);
17811 + if (S_ISDIR(inode->i_mode)) {
17812 + n = inode->i_nlink;
17815 + smp_mb(); /* for i_nlink */
17816 + /* 0 can happen */
17817 + set_nlink(inode, n);
17820 + spin_lock(&inode->i_lock);
17821 + inode->i_blocks = st->blocks;
17822 + i_size_write(inode, st->size);
17823 + spin_unlock(&inode->i_lock);
17826 +static int aufs_getattr(struct vfsmount *mnt __maybe_unused,
17827 + struct dentry *dentry, struct kstat *st)
17830 + unsigned int mnt_flags;
17831 + aufs_bindex_t bindex;
17832 + unsigned char udba_none, positive;
17833 + struct super_block *sb, *h_sb;
17834 + struct inode *inode;
17835 + struct path h_path;
17837 + sb = dentry->d_sb;
17838 + inode = dentry->d_inode;
17839 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
17840 + if (unlikely(err))
17842 + mnt_flags = au_mntflags(sb);
17843 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
17845 + /* support fstat(2) */
17846 + if (!d_unlinked(dentry) && !udba_none) {
17847 + unsigned int sigen = au_sigen(sb);
17848 + err = au_digen_test(dentry, sigen);
17850 + di_read_lock_child(dentry, AuLock_IR);
17851 + err = au_dbrange_test(dentry);
17852 + if (unlikely(err))
17855 + AuDebugOn(IS_ROOT(dentry));
17856 + di_write_lock_child(dentry);
17857 + err = au_dbrange_test(dentry);
17859 + err = au_reval_for_attr(dentry, sigen);
17860 + di_downgrade_lock(dentry, AuLock_IR);
17861 + if (unlikely(err))
17865 + di_read_lock_child(dentry, AuLock_IR);
17867 + bindex = au_ibstart(inode);
17868 + h_path.mnt = au_sbr_mnt(sb, bindex);
17869 + h_sb = h_path.mnt->mnt_sb;
17870 + if (!au_test_fs_bad_iattr(h_sb) && udba_none)
17871 + goto out_fill; /* success */
17873 + h_path.dentry = NULL;
17874 + if (au_dbstart(dentry) == bindex)
17875 + h_path.dentry = dget(au_h_dptr(dentry, bindex));
17876 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
17877 + h_path.dentry = au_plink_lkup(inode, bindex);
17878 + if (IS_ERR(h_path.dentry))
17879 + goto out_fill; /* pretending success */
17881 + /* illegally overlapped or something */
17882 + if (unlikely(!h_path.dentry))
17883 + goto out_fill; /* pretending success */
17885 + positive = !!h_path.dentry->d_inode;
17887 + err = vfs_getattr(&h_path, st);
17888 + dput(h_path.dentry);
17891 + au_refresh_iattr(inode, st,
17892 + h_path.dentry->d_inode->i_nlink);
17893 + goto out_fill; /* success */
17899 + generic_fillattr(inode, st);
17901 + di_read_unlock(dentry, AuLock_IR);
17902 + si_read_unlock(sb);
17908 +/* ---------------------------------------------------------------------- */
17910 +static int h_readlink(struct dentry *dentry, int bindex, char __user *buf,
17914 + struct super_block *sb;
17915 + struct dentry *h_dentry;
17918 + h_dentry = au_h_dptr(dentry, bindex);
17919 + if (unlikely(!h_dentry->d_inode->i_op->readlink))
17922 + err = security_inode_readlink(h_dentry);
17923 + if (unlikely(err))
17926 + sb = dentry->d_sb;
17927 + if (!au_test_ro(sb, bindex, dentry->d_inode)) {
17928 + vfsub_touch_atime(au_sbr_mnt(sb, bindex), h_dentry);
17929 + fsstack_copy_attr_atime(dentry->d_inode, h_dentry->d_inode);
17931 + err = h_dentry->d_inode->i_op->readlink(h_dentry, buf, bufsiz);
17937 +static int aufs_readlink(struct dentry *dentry, char __user *buf, int bufsiz)
17941 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
17942 + if (unlikely(err))
17944 + err = au_d_hashed_positive(dentry);
17946 + err = h_readlink(dentry, au_dbstart(dentry), buf, bufsiz);
17947 + aufs_read_unlock(dentry, AuLock_IR);
17953 +static void *aufs_follow_link(struct dentry *dentry, struct nameidata *nd)
17956 + mm_segment_t old_fs;
17963 + buf.k = (void *)__get_free_page(GFP_NOFS);
17964 + if (unlikely(!buf.k))
17967 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
17968 + if (unlikely(err))
17971 + err = au_d_hashed_positive(dentry);
17973 + old_fs = get_fs();
17974 + set_fs(KERNEL_DS);
17975 + err = h_readlink(dentry, au_dbstart(dentry), buf.u, PATH_MAX);
17978 + aufs_read_unlock(dentry, AuLock_IR);
17982 + /* will be freed by put_link */
17983 + nd_set_link(nd, buf.k);
17984 + return NULL; /* success */
17988 + free_page((unsigned long)buf.k);
17991 + return ERR_PTR(err);
17994 +static void aufs_put_link(struct dentry *dentry __maybe_unused,
17995 + struct nameidata *nd, void *cookie __maybe_unused)
17999 + p = nd_get_link(nd);
18000 + if (!IS_ERR_OR_NULL(p))
18001 + free_page((unsigned long)p);
18004 +/* ---------------------------------------------------------------------- */
18006 +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags)
18009 + struct super_block *sb;
18010 + struct inode *h_inode;
18012 + sb = inode->i_sb;
18013 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
18015 + si_read_lock(sb, AuLock_FLUSH);
18016 + ii_write_lock_child(inode);
18018 + h_inode = au_h_iptr(inode, au_ibstart(inode));
18019 + err = vfsub_update_time(h_inode, ts, flags);
18021 + ii_write_unlock(inode);
18022 + si_read_unlock(sb);
18027 +/* ---------------------------------------------------------------------- */
18029 +struct inode_operations aufs_symlink_iop = {
18030 + .permission = aufs_permission,
18031 + .setattr = aufs_setattr,
18032 + .getattr = aufs_getattr,
18034 + .readlink = aufs_readlink,
18035 + .follow_link = aufs_follow_link,
18036 + .put_link = aufs_put_link,
18038 + /* .update_time = aufs_update_time */
18041 +struct inode_operations aufs_dir_iop = {
18042 + .create = aufs_create,
18043 + .lookup = aufs_lookup,
18044 + .link = aufs_link,
18045 + .unlink = aufs_unlink,
18046 + .symlink = aufs_symlink,
18047 + .mkdir = aufs_mkdir,
18048 + .rmdir = aufs_rmdir,
18049 + .mknod = aufs_mknod,
18050 + .rename = aufs_rename,
18052 + .permission = aufs_permission,
18053 + .setattr = aufs_setattr,
18054 + .getattr = aufs_getattr,
18056 + .update_time = aufs_update_time
18057 + /* no support for atomic_open() */
18060 +struct inode_operations aufs_iop = {
18061 + .permission = aufs_permission,
18062 + .setattr = aufs_setattr,
18063 + .getattr = aufs_getattr,
18065 + .update_time = aufs_update_time
18067 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
18068 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
18069 +++ linux/fs/aufs/i_op_del.c 2014-04-24 22:11:10.855269116 +0200
18072 + * Copyright (C) 2005-2014 Junjiro R. Okajima
18074 + * This program, aufs is free software; you can redistribute it and/or modify
18075 + * it under the terms of the GNU General Public License as published by
18076 + * the Free Software Foundation; either version 2 of the License, or
18077 + * (at your option) any later version.
18079 + * This program is distributed in the hope that it will be useful,
18080 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18081 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18082 + * GNU General Public License for more details.
18084 + * You should have received a copy of the GNU General Public License
18085 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18089 + * inode operations (del entry)
18095 + * decide if a new whiteout for @dentry is necessary or not.
18096 + * when it is necessary, prepare the parent dir for the upper branch whose
18097 + * branch index is @bcpup for creation. the actual creation of the whiteout will
18098 + * be done by caller.
18100 + * 0: wh is unnecessary
18101 + * plus: wh is necessary
18104 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
18106 + int need_wh, err;
18107 + aufs_bindex_t bstart;
18108 + struct super_block *sb;
18110 + sb = dentry->d_sb;
18111 + bstart = au_dbstart(dentry);
18112 + if (*bcpup < 0) {
18114 + if (au_test_ro(sb, bstart, dentry->d_inode)) {
18115 + err = AuWbrCopyup(au_sbi(sb), dentry);
18117 + if (unlikely(err < 0))
18121 + AuDebugOn(bstart < *bcpup
18122 + || au_test_ro(sb, *bcpup, dentry->d_inode));
18123 + AuDbg("bcpup %d, bstart %d\n", *bcpup, bstart);
18125 + if (*bcpup != bstart) {
18126 + err = au_cpup_dirs(dentry, *bcpup);
18127 + if (unlikely(err))
18131 + struct au_dinfo *dinfo, *tmp;
18133 + need_wh = -ENOMEM;
18134 + dinfo = au_di(dentry);
18135 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
18137 + au_di_cp(tmp, dinfo);
18138 + au_di_swap(tmp, dinfo);
18139 + /* returns the number of positive dentries */
18140 + need_wh = au_lkup_dentry(dentry, bstart + 1, /*type*/0);
18141 + au_di_swap(tmp, dinfo);
18142 + au_rw_write_unlock(&tmp->di_rwsem);
18146 + AuDbg("need_wh %d\n", need_wh);
18154 + * simple tests for the del-entry operations.
18155 + * following the checks in vfs, plus the parent-child relationship.
18157 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
18158 + struct dentry *h_parent, int isdir)
18162 + struct dentry *h_dentry, *h_latest;
18163 + struct inode *h_inode;
18165 + h_dentry = au_h_dptr(dentry, bindex);
18166 + h_inode = h_dentry->d_inode;
18167 + if (dentry->d_inode) {
18169 + if (unlikely(!h_inode || !h_inode->i_nlink))
18172 + h_mode = h_inode->i_mode;
18175 + if (unlikely(S_ISDIR(h_mode)))
18177 + } else if (unlikely(!S_ISDIR(h_mode))) {
18182 + /* rename(2) case */
18184 + if (unlikely(h_inode))
18189 + /* expected parent dir is locked */
18190 + if (unlikely(h_parent != h_dentry->d_parent))
18195 + * rmdir a dir may break the consistency on some filesystem.
18196 + * let's try heavy test.
18199 + if (unlikely(au_test_h_perm(h_parent->d_inode, MAY_EXEC | MAY_WRITE)))
18202 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent,
18203 + au_sbr(dentry->d_sb, bindex));
18205 + if (IS_ERR(h_latest))
18207 + if (h_latest == h_dentry)
18216 + * decide the branch where we operate for @dentry. the branch index will be set
18217 + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent
18218 + * dir for reverting.
18219 + * when a new whiteout is necessary, create it.
18221 +static struct dentry*
18222 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
18223 + struct au_dtime *dt, struct au_pin *pin)
18225 + struct dentry *wh_dentry;
18226 + struct super_block *sb;
18227 + struct path h_path;
18228 + int err, need_wh;
18229 + unsigned int udba;
18230 + aufs_bindex_t bcpup;
18232 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
18233 + wh_dentry = ERR_PTR(need_wh);
18234 + if (unlikely(need_wh < 0))
18237 + sb = dentry->d_sb;
18238 + udba = au_opt_udba(sb);
18240 + err = au_pin(pin, dentry, bcpup, udba,
18241 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
18242 + wh_dentry = ERR_PTR(err);
18243 + if (unlikely(err))
18246 + h_path.dentry = au_pinned_h_parent(pin);
18247 + if (udba != AuOpt_UDBA_NONE
18248 + && au_dbstart(dentry) == bcpup) {
18249 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
18250 + wh_dentry = ERR_PTR(err);
18251 + if (unlikely(err))
18255 + h_path.mnt = au_sbr_mnt(sb, bcpup);
18256 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
18257 + wh_dentry = NULL;
18259 + goto out; /* success, no need to create whiteout */
18261 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
18262 + if (IS_ERR(wh_dentry))
18265 + /* returns with the parent is locked and wh_dentry is dget-ed */
18266 + goto out; /* success */
18271 + return wh_dentry;
18275 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
18276 + * in order to be revertible and save time for removing many child whiteouts
18278 + * returns 1 when there are too many child whiteout and caller should remove
18279 + * them asynchronously. returns 0 when the number of children is enough small to
18280 + * remove now or the branch fs is a remote fs.
18281 + * otherwise return an error.
18283 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
18284 + struct au_nhash *whlist, struct inode *dir)
18286 + int rmdir_later, err, dirwh;
18287 + struct dentry *h_dentry;
18288 + struct super_block *sb;
18290 + sb = dentry->d_sb;
18291 + SiMustAnyLock(sb);
18292 + h_dentry = au_h_dptr(dentry, bindex);
18293 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
18294 + if (unlikely(err))
18297 + /* stop monitoring */
18298 + au_hn_free(au_hi(dentry->d_inode, bindex));
18300 + if (!au_test_fs_remote(h_dentry->d_sb)) {
18301 + dirwh = au_sbi(sb)->si_dirwh;
18302 + rmdir_later = (dirwh <= 1);
18303 + if (!rmdir_later)
18304 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
18307 + return rmdir_later;
18310 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
18311 + if (unlikely(err)) {
18312 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
18313 + h_dentry, bindex, err);
18323 + * final procedure for deleting a entry.
18324 + * maintain dentry and iattr.
18326 +static void epilog(struct inode *dir, struct dentry *dentry,
18327 + aufs_bindex_t bindex)
18329 + struct inode *inode;
18331 + inode = dentry->d_inode;
18333 + inode->i_ctime = dir->i_ctime;
18335 + if (au_ibstart(dir) == bindex)
18336 + au_cpup_attr_timesizes(dir);
18337 + dir->i_version++;
18341 + * when an error happened, remove the created whiteout and revert everything.
18343 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
18344 + aufs_bindex_t bwh, struct dentry *wh_dentry,
18345 + struct dentry *dentry, struct au_dtime *dt)
18348 + struct path h_path = {
18349 + .dentry = wh_dentry,
18350 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
18353 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
18355 + au_set_dbwh(dentry, bwh);
18356 + au_dtime_revert(dt);
18360 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
18364 +/* ---------------------------------------------------------------------- */
18366 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
18369 + aufs_bindex_t bwh, bindex, bstart;
18370 + struct inode *inode, *h_dir, *delegated;
18371 + struct dentry *parent, *wh_dentry;
18372 + /* to reuduce stack size */
18374 + struct au_dtime dt;
18375 + struct au_pin pin;
18376 + struct path h_path;
18382 + a = kmalloc(sizeof(*a), GFP_NOFS);
18383 + if (unlikely(!a))
18386 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
18387 + if (unlikely(err))
18389 + err = au_d_hashed_positive(dentry);
18390 + if (unlikely(err))
18392 + inode = dentry->d_inode;
18393 + IMustLock(inode);
18395 + if (unlikely(S_ISDIR(inode->i_mode)))
18396 + goto out_unlock; /* possible? */
18398 + bstart = au_dbstart(dentry);
18399 + bwh = au_dbwh(dentry);
18401 + parent = dentry->d_parent; /* dir inode is locked */
18402 + di_write_lock_parent(parent);
18403 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
18405 + err = PTR_ERR(wh_dentry);
18406 + if (IS_ERR(wh_dentry))
18409 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
18410 + a->h_path.dentry = au_h_dptr(dentry, bstart);
18411 + dget(a->h_path.dentry);
18412 + if (bindex == bstart) {
18413 + h_dir = au_pinned_h_dir(&a->pin);
18414 + delegated = NULL;
18415 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
18416 + if (unlikely(err == -EWOULDBLOCK)) {
18417 + pr_warn("cannot retry for NFSv4 delegation"
18418 + " for an internal unlink\n");
18422 + /* dir inode is locked */
18423 + h_dir = wh_dentry->d_parent->d_inode;
18424 + IMustLock(h_dir);
18429 + vfsub_drop_nlink(inode);
18430 + epilog(dir, dentry, bindex);
18432 + /* update target timestamps */
18433 + if (bindex == bstart) {
18434 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
18436 + inode->i_ctime = a->h_path.dentry->d_inode->i_ctime;
18438 + /* todo: this timestamp may be reverted later */
18439 + inode->i_ctime = h_dir->i_ctime;
18440 + goto out_unpin; /* success */
18447 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
18454 + au_unpin(&a->pin);
18456 + dput(a->h_path.dentry);
18458 + di_write_unlock(parent);
18460 + aufs_read_unlock(dentry, AuLock_DW);
18467 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
18469 + int err, rmdir_later;
18470 + aufs_bindex_t bwh, bindex, bstart;
18471 + struct inode *inode;
18472 + struct dentry *parent, *wh_dentry, *h_dentry;
18473 + struct au_whtmp_rmdir *args;
18474 + /* to reuduce stack size */
18476 + struct au_dtime dt;
18477 + struct au_pin pin;
18483 + a = kmalloc(sizeof(*a), GFP_NOFS);
18484 + if (unlikely(!a))
18487 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
18488 + if (unlikely(err))
18490 + err = au_alive_dir(dentry);
18491 + if (unlikely(err))
18493 + inode = dentry->d_inode;
18494 + IMustLock(inode);
18496 + if (unlikely(!S_ISDIR(inode->i_mode)))
18497 + goto out_unlock; /* possible? */
18500 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
18501 + if (unlikely(!args))
18504 + parent = dentry->d_parent; /* dir inode is locked */
18505 + di_write_lock_parent(parent);
18506 + err = au_test_empty(dentry, &args->whlist);
18507 + if (unlikely(err))
18510 + bstart = au_dbstart(dentry);
18511 + bwh = au_dbwh(dentry);
18513 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
18515 + err = PTR_ERR(wh_dentry);
18516 + if (IS_ERR(wh_dentry))
18519 + h_dentry = au_h_dptr(dentry, bstart);
18522 + if (bindex == bstart) {
18523 + err = renwh_and_rmdir(dentry, bstart, &args->whlist, dir);
18525 + rmdir_later = err;
18529 + /* stop monitoring */
18530 + au_hn_free(au_hi(inode, bstart));
18532 + /* dir inode is locked */
18533 + IMustLock(wh_dentry->d_parent->d_inode);
18538 + vfsub_dead_dir(inode);
18539 + au_set_dbdiropq(dentry, -1);
18540 + epilog(dir, dentry, bindex);
18542 + if (rmdir_later) {
18543 + au_whtmp_kick_rmdir(dir, bstart, h_dentry, args);
18547 + goto out_unpin; /* success */
18555 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
18562 + au_unpin(&a->pin);
18566 + di_write_unlock(parent);
18568 + au_whtmp_rmdir_free(args);
18570 + aufs_read_unlock(dentry, AuLock_DW);
18577 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
18578 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
18579 +++ linux/fs/aufs/i_op_ren.c 2014-04-24 22:11:10.855269116 +0200
18582 + * Copyright (C) 2005-2014 Junjiro R. Okajima
18584 + * This program, aufs is free software; you can redistribute it and/or modify
18585 + * it under the terms of the GNU General Public License as published by
18586 + * the Free Software Foundation; either version 2 of the License, or
18587 + * (at your option) any later version.
18589 + * This program is distributed in the hope that it will be useful,
18590 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18591 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18592 + * GNU General Public License for more details.
18594 + * You should have received a copy of the GNU General Public License
18595 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18599 + * inode operation (rename entry)
18600 + * todo: this is crazy monster
18605 +enum { AuSRC, AuDST, AuSrcDst };
18606 +enum { AuPARENT, AuCHILD, AuParentChild };
18608 +#define AuRen_ISDIR 1
18609 +#define AuRen_ISSAMEDIR (1 << 1)
18610 +#define AuRen_WHSRC (1 << 2)
18611 +#define AuRen_WHDST (1 << 3)
18612 +#define AuRen_MNT_WRITE (1 << 4)
18613 +#define AuRen_DT_DSTDIR (1 << 5)
18614 +#define AuRen_DIROPQ (1 << 6)
18615 +#define AuRen_CPUP (1 << 7)
18616 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
18617 +#define au_fset_ren(flags, name) \
18618 + do { (flags) |= AuRen_##name; } while (0)
18619 +#define au_fclr_ren(flags, name) \
18620 + do { (flags) &= ~AuRen_##name; } while (0)
18622 +struct au_ren_args {
18624 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
18626 + struct inode *dir, *inode;
18627 + struct au_hinode *hdir;
18628 + struct au_dtime dt[AuParentChild];
18629 + aufs_bindex_t bstart;
18632 +#define src_dentry sd[AuSRC].dentry
18633 +#define src_dir sd[AuSRC].dir
18634 +#define src_inode sd[AuSRC].inode
18635 +#define src_h_dentry sd[AuSRC].h_dentry
18636 +#define src_parent sd[AuSRC].parent
18637 +#define src_h_parent sd[AuSRC].h_parent
18638 +#define src_wh_dentry sd[AuSRC].wh_dentry
18639 +#define src_hdir sd[AuSRC].hdir
18640 +#define src_h_dir sd[AuSRC].hdir->hi_inode
18641 +#define src_dt sd[AuSRC].dt
18642 +#define src_bstart sd[AuSRC].bstart
18644 +#define dst_dentry sd[AuDST].dentry
18645 +#define dst_dir sd[AuDST].dir
18646 +#define dst_inode sd[AuDST].inode
18647 +#define dst_h_dentry sd[AuDST].h_dentry
18648 +#define dst_parent sd[AuDST].parent
18649 +#define dst_h_parent sd[AuDST].h_parent
18650 +#define dst_wh_dentry sd[AuDST].wh_dentry
18651 +#define dst_hdir sd[AuDST].hdir
18652 +#define dst_h_dir sd[AuDST].hdir->hi_inode
18653 +#define dst_dt sd[AuDST].dt
18654 +#define dst_bstart sd[AuDST].bstart
18656 + struct dentry *h_trap;
18657 + struct au_branch *br;
18658 + struct au_hinode *src_hinode;
18659 + struct path h_path;
18660 + struct au_nhash whlist;
18661 + aufs_bindex_t btgt, src_bwh, src_bdiropq;
18663 + unsigned int flags;
18665 + struct au_whtmp_rmdir *thargs;
18666 + struct dentry *h_dst;
18669 +/* ---------------------------------------------------------------------- */
18672 + * functions for reverting.
18673 + * when an error happened in a single rename systemcall, we should revert
18674 + * everything as if nothing happend.
18675 + * we don't need to revert the copied-up/down the parent dir since they are
18679 +#define RevertFailure(fmt, ...) do { \
18680 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
18681 + ##__VA_ARGS__, err, rerr); \
18685 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
18689 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
18690 + rerr = au_diropq_remove(a->src_dentry, a->btgt);
18691 + au_hn_imtx_unlock(a->src_hinode);
18692 + au_set_dbdiropq(a->src_dentry, a->src_bdiropq);
18694 + RevertFailure("remove diropq %pd", a->src_dentry);
18697 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
18700 + struct inode *delegated;
18702 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
18703 + a->src_h_parent);
18704 + rerr = PTR_ERR(a->h_path.dentry);
18705 + if (IS_ERR(a->h_path.dentry)) {
18706 + RevertFailure("lkup one %pd", a->src_dentry);
18710 + delegated = NULL;
18711 + rerr = vfsub_rename(a->dst_h_dir,
18712 + au_h_dptr(a->src_dentry, a->btgt),
18713 + a->src_h_dir, &a->h_path, &delegated);
18714 + if (unlikely(rerr == -EWOULDBLOCK)) {
18715 + pr_warn("cannot retry for NFSv4 delegation"
18716 + " for an internal rename\n");
18719 + d_drop(a->h_path.dentry);
18720 + dput(a->h_path.dentry);
18721 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
18723 + RevertFailure("rename %pd", a->src_dentry);
18726 +static void au_ren_rev_cpup(int err, struct au_ren_args *a)
18730 + a->h_path.dentry = a->dst_h_dentry;
18731 + /* no delegation since it is just created */
18732 + rerr = vfsub_unlink(a->dst_h_dir, &a->h_path, /*delegated*/NULL,
18734 + au_set_h_dptr(a->src_dentry, a->btgt, NULL);
18735 + au_set_dbstart(a->src_dentry, a->src_bstart);
18737 + RevertFailure("unlink %pd", a->dst_h_dentry);
18740 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
18743 + struct inode *delegated;
18745 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
18746 + a->dst_h_parent);
18747 + rerr = PTR_ERR(a->h_path.dentry);
18748 + if (IS_ERR(a->h_path.dentry)) {
18749 + RevertFailure("lkup one %pd", a->dst_dentry);
18752 + if (a->h_path.dentry->d_inode) {
18753 + d_drop(a->h_path.dentry);
18754 + dput(a->h_path.dentry);
18758 + delegated = NULL;
18759 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
18761 + if (unlikely(rerr == -EWOULDBLOCK)) {
18762 + pr_warn("cannot retry for NFSv4 delegation"
18763 + " for an internal rename\n");
18766 + d_drop(a->h_path.dentry);
18767 + dput(a->h_path.dentry);
18769 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
18771 + RevertFailure("rename %pd", a->h_dst);
18774 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
18778 + a->h_path.dentry = a->src_wh_dentry;
18779 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
18780 + au_set_dbwh(a->src_dentry, a->src_bwh);
18782 + RevertFailure("unlink %pd", a->src_wh_dentry);
18784 +#undef RevertFailure
18786 +/* ---------------------------------------------------------------------- */
18789 + * when we have to copyup the renaming entry, do it with the rename-target name
18790 + * in order to minimize the cost (the later actual rename is unnecessary).
18791 + * otherwise rename it on the target branch.
18793 +static int au_ren_or_cpup(struct au_ren_args *a)
18796 + struct dentry *d;
18797 + struct inode *delegated;
18799 + d = a->src_dentry;
18800 + if (au_dbstart(d) == a->btgt) {
18801 + a->h_path.dentry = a->dst_h_dentry;
18802 + if (au_ftest_ren(a->flags, DIROPQ)
18803 + && au_dbdiropq(d) == a->btgt)
18804 + au_fclr_ren(a->flags, DIROPQ);
18805 + AuDebugOn(au_dbstart(d) != a->btgt);
18806 + delegated = NULL;
18807 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
18808 + a->dst_h_dir, &a->h_path, &delegated);
18809 + if (unlikely(err == -EWOULDBLOCK)) {
18810 + pr_warn("cannot retry for NFSv4 delegation"
18811 + " for an internal rename\n");
18817 + if (!err && a->h_dst)
18818 + /* it will be set to dinfo later */
18824 +/* cf. aufs_rmdir() */
18825 +static int au_ren_del_whtmp(struct au_ren_args *a)
18828 + struct inode *dir;
18830 + dir = a->dst_dir;
18831 + SiMustAnyLock(dir->i_sb);
18832 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
18833 + au_sbi(dir->i_sb)->si_dirwh)
18834 + || au_test_fs_remote(a->h_dst->d_sb)) {
18835 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
18836 + if (unlikely(err))
18837 + pr_warn("failed removing whtmp dir %pd (%d), "
18838 + "ignored.\n", a->h_dst, err);
18840 + au_nhash_wh_free(&a->thargs->whlist);
18841 + a->thargs->whlist = a->whlist;
18842 + a->whlist.nh_num = 0;
18843 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
18845 + a->thargs = NULL;
18851 +/* make it 'opaque' dir. */
18852 +static int au_ren_diropq(struct au_ren_args *a)
18855 + struct dentry *diropq;
18858 + a->src_bdiropq = au_dbdiropq(a->src_dentry);
18859 + a->src_hinode = au_hi(a->src_inode, a->btgt);
18860 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
18861 + diropq = au_diropq_create(a->src_dentry, a->btgt);
18862 + au_hn_imtx_unlock(a->src_hinode);
18863 + if (IS_ERR(diropq))
18864 + err = PTR_ERR(diropq);
18870 +static int do_rename(struct au_ren_args *a)
18873 + struct dentry *d, *h_d;
18875 + /* prepare workqueue args for asynchronous rmdir */
18876 + h_d = a->dst_h_dentry;
18877 + if (au_ftest_ren(a->flags, ISDIR) && h_d->d_inode) {
18879 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb, GFP_NOFS);
18880 + if (unlikely(!a->thargs))
18882 + a->h_dst = dget(h_d);
18885 + /* create whiteout for src_dentry */
18886 + if (au_ftest_ren(a->flags, WHSRC)) {
18887 + a->src_bwh = au_dbwh(a->src_dentry);
18888 + AuDebugOn(a->src_bwh >= 0);
18890 + = au_wh_create(a->src_dentry, a->btgt, a->src_h_parent);
18891 + err = PTR_ERR(a->src_wh_dentry);
18892 + if (IS_ERR(a->src_wh_dentry))
18896 + /* lookup whiteout for dentry */
18897 + if (au_ftest_ren(a->flags, WHDST)) {
18898 + h_d = au_wh_lkup(a->dst_h_parent, &a->dst_dentry->d_name,
18900 + err = PTR_ERR(h_d);
18903 + if (!h_d->d_inode)
18906 + a->dst_wh_dentry = h_d;
18909 + /* rename dentry to tmpwh */
18911 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
18912 + if (unlikely(err))
18915 + d = a->dst_dentry;
18916 + au_set_h_dptr(d, a->btgt, NULL);
18917 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
18918 + if (unlikely(err))
18920 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
18923 + BUG_ON(a->dst_h_dentry->d_inode && a->src_bstart != a->btgt);
18925 + /* rename by vfs_rename or cpup */
18926 + d = a->dst_dentry;
18927 + if (au_ftest_ren(a->flags, ISDIR)
18928 + && (a->dst_wh_dentry
18929 + || au_dbdiropq(d) == a->btgt
18930 + /* hide the lower to keep xino */
18931 + || a->btgt < au_dbend(d)
18932 + || au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ)))
18933 + au_fset_ren(a->flags, DIROPQ);
18934 + err = au_ren_or_cpup(a);
18935 + if (unlikely(err))
18936 + /* leave the copied-up one */
18939 + /* make dir opaque */
18940 + if (au_ftest_ren(a->flags, DIROPQ)) {
18941 + err = au_ren_diropq(a);
18942 + if (unlikely(err))
18946 + /* update target timestamps */
18947 + AuDebugOn(au_dbstart(a->src_dentry) != a->btgt);
18948 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
18949 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
18950 + a->src_inode->i_ctime = a->h_path.dentry->d_inode->i_ctime;
18952 + /* remove whiteout for dentry */
18953 + if (a->dst_wh_dentry) {
18954 + a->h_path.dentry = a->dst_wh_dentry;
18955 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
18957 + if (unlikely(err))
18961 + /* remove whtmp */
18963 + au_ren_del_whtmp(a); /* ignore this error */
18966 + goto out_success;
18969 + if (au_ftest_ren(a->flags, DIROPQ))
18970 + au_ren_rev_diropq(err, a);
18972 + if (!au_ftest_ren(a->flags, CPUP))
18973 + au_ren_rev_rename(err, a);
18975 + au_ren_rev_cpup(err, a);
18979 + au_ren_rev_whtmp(err, a);
18981 + dput(a->dst_wh_dentry);
18982 + a->dst_wh_dentry = NULL;
18984 + if (a->src_wh_dentry)
18985 + au_ren_rev_whsrc(err, a);
18987 + dput(a->src_wh_dentry);
18988 + dput(a->dst_wh_dentry);
18992 + au_whtmp_rmdir_free(a->thargs);
18993 + a->thargs = NULL;
18999 +/* ---------------------------------------------------------------------- */
19002 + * test if @dentry dir can be rename destination or not.
19003 + * success means, it is a logically empty dir.
19005 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
19007 + return au_test_empty(dentry, whlist);
19011 + * test if @dentry dir can be rename source or not.
19012 + * if it can, return 0 and @children is filled.
19014 + * - it is a logically empty dir.
19015 + * - or, it exists on writable branch and has no children including whiteouts
19016 + * on the lower branch.
19018 +static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt)
19021 + unsigned int rdhash;
19022 + aufs_bindex_t bstart;
19024 + bstart = au_dbstart(dentry);
19025 + if (bstart != btgt) {
19026 + struct au_nhash whlist;
19028 + SiMustAnyLock(dentry->d_sb);
19029 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
19031 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
19033 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
19034 + if (unlikely(err))
19036 + err = au_test_empty(dentry, &whlist);
19037 + au_nhash_wh_free(&whlist);
19041 + if (bstart == au_dbtaildir(dentry))
19042 + return 0; /* success */
19044 + err = au_test_empty_lower(dentry);
19047 + if (err == -ENOTEMPTY) {
19048 + AuWarn1("renaming dir who has child(ren) on multiple branches,"
19049 + " is not supported\n");
19055 +/* side effect: sets whlist and h_dentry */
19056 +static int au_ren_may_dir(struct au_ren_args *a)
19059 + unsigned int rdhash;
19060 + struct dentry *d;
19062 + d = a->dst_dentry;
19063 + SiMustAnyLock(d->d_sb);
19066 + if (au_ftest_ren(a->flags, ISDIR) && a->dst_inode) {
19067 + rdhash = au_sbi(d->d_sb)->si_rdhash;
19069 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
19070 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
19071 + if (unlikely(err))
19074 + au_set_dbstart(d, a->dst_bstart);
19075 + err = may_rename_dstdir(d, &a->whlist);
19076 + au_set_dbstart(d, a->btgt);
19078 + a->dst_h_dentry = au_h_dptr(d, au_dbstart(d));
19079 + if (unlikely(err))
19082 + d = a->src_dentry;
19083 + a->src_h_dentry = au_h_dptr(d, au_dbstart(d));
19084 + if (au_ftest_ren(a->flags, ISDIR)) {
19085 + err = may_rename_srcdir(d, a->btgt);
19086 + if (unlikely(err)) {
19087 + au_nhash_wh_free(&a->whlist);
19088 + a->whlist.nh_num = 0;
19095 +/* ---------------------------------------------------------------------- */
19098 + * simple tests for rename.
19099 + * following the checks in vfs, plus the parent-child relationship.
19101 +static int au_may_ren(struct au_ren_args *a)
19104 + struct inode *h_inode;
19106 + if (a->src_bstart == a->btgt) {
19107 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
19108 + au_ftest_ren(a->flags, ISDIR));
19109 + if (unlikely(err))
19112 + if (unlikely(a->src_h_dentry == a->h_trap))
19117 + if (a->dst_bstart != a->btgt)
19120 + err = -ENOTEMPTY;
19121 + if (unlikely(a->dst_h_dentry == a->h_trap))
19125 + h_inode = a->dst_h_dentry->d_inode;
19126 + isdir = !!au_ftest_ren(a->flags, ISDIR);
19127 + if (!a->dst_dentry->d_inode) {
19128 + if (unlikely(h_inode))
19130 + err = au_may_add(a->dst_dentry, a->btgt, a->dst_h_parent,
19133 + if (unlikely(!h_inode || !h_inode->i_nlink))
19135 + err = au_may_del(a->dst_dentry, a->btgt, a->dst_h_parent,
19137 + if (unlikely(err))
19142 + if (unlikely(err == -ENOENT || err == -EEXIST))
19148 +/* ---------------------------------------------------------------------- */
19153 + * - src_dir and dir by lock_rename()
19154 + * - inode if exitsts
19157 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
19159 + * + di_write_lock2_child()
19160 + * + di_write_lock_child()
19161 + * + ii_write_lock_child()
19162 + * + di_write_lock_child2()
19163 + * + ii_write_lock_child2()
19164 + * + src_parent and parent
19165 + * + di_write_lock_parent()
19166 + * + ii_write_lock_parent()
19167 + * + di_write_lock_parent2()
19168 + * + ii_write_lock_parent2()
19169 + * + lower src_dir and dir by vfsub_lock_rename()
19170 + * + verify the every relationships between child and parent. if any
19171 + * of them failed, unlock all and return -EBUSY.
19173 +static void au_ren_unlock(struct au_ren_args *a)
19175 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
19176 + a->dst_h_parent, a->dst_hdir);
19177 + if (au_ftest_ren(a->flags, MNT_WRITE))
19178 + vfsub_mnt_drop_write(au_br_mnt(a->br));
19181 +static int au_ren_lock(struct au_ren_args *a)
19184 + unsigned int udba;
19187 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
19188 + a->src_hdir = au_hi(a->src_dir, a->btgt);
19189 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
19190 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
19192 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
19193 + if (unlikely(err))
19195 + au_fset_ren(a->flags, MNT_WRITE);
19196 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
19197 + a->dst_h_parent, a->dst_hdir);
19198 + udba = au_opt_udba(a->src_dentry->d_sb);
19199 + if (unlikely(a->src_hdir->hi_inode != a->src_h_parent->d_inode
19200 + || a->dst_hdir->hi_inode != a->dst_h_parent->d_inode))
19201 + err = au_busy_or_stale();
19202 + if (!err && au_dbstart(a->src_dentry) == a->btgt)
19203 + err = au_h_verify(a->src_h_dentry, udba,
19204 + a->src_h_parent->d_inode, a->src_h_parent,
19206 + if (!err && au_dbstart(a->dst_dentry) == a->btgt)
19207 + err = au_h_verify(a->dst_h_dentry, udba,
19208 + a->dst_h_parent->d_inode, a->dst_h_parent,
19211 + goto out; /* success */
19213 + err = au_busy_or_stale();
19214 + au_ren_unlock(a);
19220 +/* ---------------------------------------------------------------------- */
19222 +static void au_ren_refresh_dir(struct au_ren_args *a)
19224 + struct inode *dir;
19226 + dir = a->dst_dir;
19227 + dir->i_version++;
19228 + if (au_ftest_ren(a->flags, ISDIR)) {
19229 + /* is this updating defined in POSIX? */
19230 + au_cpup_attr_timesizes(a->src_inode);
19231 + au_cpup_attr_nlink(dir, /*force*/1);
19234 + if (au_ibstart(dir) == a->btgt)
19235 + au_cpup_attr_timesizes(dir);
19237 + if (au_ftest_ren(a->flags, ISSAMEDIR))
19240 + dir = a->src_dir;
19241 + dir->i_version++;
19242 + if (au_ftest_ren(a->flags, ISDIR))
19243 + au_cpup_attr_nlink(dir, /*force*/1);
19244 + if (au_ibstart(dir) == a->btgt)
19245 + au_cpup_attr_timesizes(dir);
19248 +static void au_ren_refresh(struct au_ren_args *a)
19250 + aufs_bindex_t bend, bindex;
19251 + struct dentry *d, *h_d;
19252 + struct inode *i, *h_i;
19253 + struct super_block *sb;
19255 + d = a->dst_dentry;
19258 + /* already dget-ed by au_ren_or_cpup() */
19259 + au_set_h_dptr(d, a->btgt, a->h_dst);
19261 + i = a->dst_inode;
19263 + if (!au_ftest_ren(a->flags, ISDIR))
19264 + vfsub_drop_nlink(i);
19266 + vfsub_dead_dir(i);
19267 + au_cpup_attr_timesizes(i);
19269 + au_update_dbrange(d, /*do_put_zero*/1);
19272 + for (bindex = au_dbstart(d); bindex < bend; bindex++)
19273 + au_set_h_dptr(d, bindex, NULL);
19274 + bend = au_dbend(d);
19275 + for (bindex = a->btgt + 1; bindex <= bend; bindex++)
19276 + au_set_h_dptr(d, bindex, NULL);
19277 + au_update_dbrange(d, /*do_put_zero*/0);
19280 + d = a->src_dentry;
19281 + au_set_dbwh(d, -1);
19282 + bend = au_dbend(d);
19283 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
19284 + h_d = au_h_dptr(d, bindex);
19286 + au_set_h_dptr(d, bindex, NULL);
19288 + au_set_dbend(d, a->btgt);
19291 + i = a->src_inode;
19292 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
19293 + return; /* success */
19295 + bend = au_ibend(i);
19296 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
19297 + h_i = au_h_iptr(i, bindex);
19299 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
19300 + /* ignore this error */
19301 + au_set_h_iptr(i, bindex, NULL, 0);
19304 + au_set_ibend(i, a->btgt);
19307 +/* ---------------------------------------------------------------------- */
19309 +/* mainly for link(2) and rename(2) */
19310 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
19312 + aufs_bindex_t bdiropq, bwh;
19313 + struct dentry *parent;
19314 + struct au_branch *br;
19316 + parent = dentry->d_parent;
19317 + IMustLock(parent->d_inode); /* dir is locked */
19319 + bdiropq = au_dbdiropq(parent);
19320 + bwh = au_dbwh(dentry);
19321 + br = au_sbr(dentry->d_sb, btgt);
19322 + if (au_br_rdonly(br)
19323 + || (0 <= bdiropq && bdiropq < btgt)
19324 + || (0 <= bwh && bwh < btgt))
19327 + AuDbg("btgt %d\n", btgt);
19331 +/* sets src_bstart, dst_bstart and btgt */
19332 +static int au_ren_wbr(struct au_ren_args *a)
19335 + struct au_wr_dir_args wr_dir_args = {
19336 + /* .force_btgt = -1, */
19337 + .flags = AuWrDir_ADD_ENTRY
19340 + a->src_bstart = au_dbstart(a->src_dentry);
19341 + a->dst_bstart = au_dbstart(a->dst_dentry);
19342 + if (au_ftest_ren(a->flags, ISDIR))
19343 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
19344 + wr_dir_args.force_btgt = a->src_bstart;
19345 + if (a->dst_inode && a->dst_bstart < a->src_bstart)
19346 + wr_dir_args.force_btgt = a->dst_bstart;
19347 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
19348 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
19354 +static void au_ren_dt(struct au_ren_args *a)
19356 + a->h_path.dentry = a->src_h_parent;
19357 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
19358 + if (!au_ftest_ren(a->flags, ISSAMEDIR)) {
19359 + a->h_path.dentry = a->dst_h_parent;
19360 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
19363 + au_fclr_ren(a->flags, DT_DSTDIR);
19364 + if (!au_ftest_ren(a->flags, ISDIR))
19367 + a->h_path.dentry = a->src_h_dentry;
19368 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
19369 + if (a->dst_h_dentry->d_inode) {
19370 + au_fset_ren(a->flags, DT_DSTDIR);
19371 + a->h_path.dentry = a->dst_h_dentry;
19372 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
19376 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
19378 + struct dentry *h_d;
19379 + struct mutex *h_mtx;
19381 + au_dtime_revert(a->src_dt + AuPARENT);
19382 + if (!au_ftest_ren(a->flags, ISSAMEDIR))
19383 + au_dtime_revert(a->dst_dt + AuPARENT);
19385 + if (au_ftest_ren(a->flags, ISDIR) && err != -EIO) {
19386 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
19387 + h_mtx = &h_d->d_inode->i_mutex;
19388 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
19389 + au_dtime_revert(a->src_dt + AuCHILD);
19390 + mutex_unlock(h_mtx);
19392 + if (au_ftest_ren(a->flags, DT_DSTDIR)) {
19393 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
19394 + h_mtx = &h_d->d_inode->i_mutex;
19395 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
19396 + au_dtime_revert(a->dst_dt + AuCHILD);
19397 + mutex_unlock(h_mtx);
19402 +/* ---------------------------------------------------------------------- */
19404 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
19405 + struct inode *_dst_dir, struct dentry *_dst_dentry)
19408 + /* reduce stack space */
19409 + struct au_ren_args *a;
19411 + AuDbg("%pd, %pd\n", _src_dentry, _dst_dentry);
19412 + IMustLock(_src_dir);
19413 + IMustLock(_dst_dir);
19416 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
19417 + a = kzalloc(sizeof(*a), GFP_NOFS);
19418 + if (unlikely(!a))
19421 + a->src_dir = _src_dir;
19422 + a->src_dentry = _src_dentry;
19423 + a->src_inode = a->src_dentry->d_inode;
19424 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
19425 + a->dst_dir = _dst_dir;
19426 + a->dst_dentry = _dst_dentry;
19427 + a->dst_inode = a->dst_dentry->d_inode;
19428 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
19429 + if (a->dst_inode) {
19430 + IMustLock(a->dst_inode);
19431 + au_igrab(a->dst_inode);
19435 + flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
19436 + if (S_ISDIR(a->src_inode->i_mode)) {
19437 + au_fset_ren(a->flags, ISDIR);
19438 + if (unlikely(a->dst_inode && !S_ISDIR(a->dst_inode->i_mode)))
19440 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
19441 + AuLock_DIR | flags);
19443 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
19445 + if (unlikely(err))
19448 + err = au_d_hashed_positive(a->src_dentry);
19449 + if (unlikely(err))
19452 + if (a->dst_inode) {
19454 + * If it is a dir, VFS unhash dst_dentry before this
19455 + * function. It means we cannot rely upon d_unhashed().
19457 + if (unlikely(!a->dst_inode->i_nlink))
19459 + if (!S_ISDIR(a->dst_inode->i_mode)) {
19460 + err = au_d_hashed_positive(a->dst_dentry);
19461 + if (unlikely(err))
19463 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
19465 + } else if (unlikely(d_unhashed(a->dst_dentry)))
19469 + * is it possible?
19470 + * yes, it happend (in linux-3.3-rcN) but I don't know why.
19471 + * there may exist a problem somewhere else.
19474 + if (unlikely(a->dst_parent->d_inode == a->src_dentry->d_inode))
19477 + au_fset_ren(a->flags, ISSAMEDIR); /* temporary */
19478 + di_write_lock_parent(a->dst_parent);
19480 + /* which branch we process */
19481 + err = au_ren_wbr(a);
19482 + if (unlikely(err < 0))
19484 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
19485 + a->h_path.mnt = au_br_mnt(a->br);
19487 + /* are they available to be renamed */
19488 + err = au_ren_may_dir(a);
19489 + if (unlikely(err))
19490 + goto out_children;
19492 + /* prepare the writable parent dir on the same branch */
19493 + if (a->dst_bstart == a->btgt) {
19494 + au_fset_ren(a->flags, WHDST);
19496 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
19497 + if (unlikely(err))
19498 + goto out_children;
19501 + if (a->src_dir != a->dst_dir) {
19503 + * this temporary unlock is safe,
19504 + * because both dir->i_mutex are locked.
19506 + di_write_unlock(a->dst_parent);
19507 + di_write_lock_parent(a->src_parent);
19508 + err = au_wr_dir_need_wh(a->src_dentry,
19509 + au_ftest_ren(a->flags, ISDIR),
19511 + di_write_unlock(a->src_parent);
19512 + di_write_lock2_parent(a->src_parent, a->dst_parent, /*isdir*/1);
19513 + au_fclr_ren(a->flags, ISSAMEDIR);
19515 + err = au_wr_dir_need_wh(a->src_dentry,
19516 + au_ftest_ren(a->flags, ISDIR),
19518 + if (unlikely(err < 0))
19519 + goto out_children;
19521 + au_fset_ren(a->flags, WHSRC);
19524 + if (a->src_bstart != a->btgt) {
19525 + struct au_pin pin;
19527 + err = au_pin(&pin, a->src_dentry, a->btgt,
19528 + au_opt_udba(a->src_dentry->d_sb),
19529 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19531 + struct au_cp_generic cpg = {
19532 + .dentry = a->src_dentry,
19534 + .bsrc = a->src_bstart,
19537 + .flags = AuCpup_DTIME | AuCpup_HOPEN
19539 + AuDebugOn(au_dbstart(a->src_dentry) != a->src_bstart);
19540 + err = au_sio_cpup_simple(&cpg);
19543 + if (unlikely(err))
19544 + goto out_children;
19545 + a->src_bstart = a->btgt;
19546 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
19547 + au_fset_ren(a->flags, WHSRC);
19550 + /* lock them all */
19551 + err = au_ren_lock(a);
19552 + if (unlikely(err))
19553 + /* leave the copied-up one */
19554 + goto out_children;
19556 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
19557 + err = au_may_ren(a);
19558 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
19559 + err = -ENAMETOOLONG;
19560 + if (unlikely(err))
19563 + /* store timestamps to be revertible */
19567 + err = do_rename(a);
19568 + if (unlikely(err))
19571 + /* update dir attributes */
19572 + au_ren_refresh_dir(a);
19574 + /* dput/iput all lower dentries */
19575 + au_ren_refresh(a);
19577 + goto out_hdir; /* success */
19580 + au_ren_rev_dt(err, a);
19582 + au_ren_unlock(a);
19584 + au_nhash_wh_free(&a->whlist);
19585 + if (err && a->dst_inode && a->dst_bstart != a->btgt) {
19586 + AuDbg("bstart %d, btgt %d\n", a->dst_bstart, a->btgt);
19587 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
19588 + au_set_dbstart(a->dst_dentry, a->dst_bstart);
19592 + d_move(a->src_dentry, a->dst_dentry);
19594 + au_update_dbstart(a->dst_dentry);
19595 + if (!a->dst_inode)
19596 + d_drop(a->dst_dentry);
19598 + if (au_ftest_ren(a->flags, ISSAMEDIR))
19599 + di_write_unlock(a->dst_parent);
19601 + di_write_unlock2(a->src_parent, a->dst_parent);
19603 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
19605 + iput(a->dst_inode);
19607 + au_whtmp_rmdir_free(a->thargs);
19613 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
19614 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
19615 +++ linux/fs/aufs/Kconfig 2014-04-24 22:11:10.835268907 +0200
19618 + tristate "Aufs (Advanced multi layered unification filesystem) support"
19620 + Aufs is a stackable unification filesystem such as Unionfs,
19621 + which unifies several directories and provides a merged single
19623 + In the early days, aufs was entirely re-designed and
19624 + re-implemented Unionfs Version 1.x series. Introducing many
19625 + original ideas, approaches and improvements, it becomes totally
19626 + different from Unionfs while keeping the basic features.
19630 + prompt "Maximum number of branches"
19631 + default AUFS_BRANCH_MAX_127
19633 + Specifies the maximum number of branches (or member directories)
19634 + in a single aufs. The larger value consumes more system
19635 + resources and has a minor impact to performance.
19636 +config AUFS_BRANCH_MAX_127
19639 + Specifies the maximum number of branches (or member directories)
19640 + in a single aufs. The larger value consumes more system
19641 + resources and has a minor impact to performance.
19642 +config AUFS_BRANCH_MAX_511
19645 + Specifies the maximum number of branches (or member directories)
19646 + in a single aufs. The larger value consumes more system
19647 + resources and has a minor impact to performance.
19648 +config AUFS_BRANCH_MAX_1023
19651 + Specifies the maximum number of branches (or member directories)
19652 + in a single aufs. The larger value consumes more system
19653 + resources and has a minor impact to performance.
19654 +config AUFS_BRANCH_MAX_32767
19657 + Specifies the maximum number of branches (or member directories)
19658 + in a single aufs. The larger value consumes more system
19659 + resources and has a minor impact to performance.
19662 +config AUFS_SBILIST
19664 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
19667 + Automatic configuration for internal use.
19668 + When aufs supports Magic SysRq or /proc, enabled automatically.
19670 +config AUFS_HNOTIFY
19671 + bool "Detect direct branch access (bypassing aufs)"
19673 + If you want to modify files on branches directly, eg. bypassing aufs,
19674 + and want aufs to detect the changes of them fully, then enable this
19675 + option and use 'udba=notify' mount option.
19676 + Currently there is only one available configuration, "fsnotify".
19677 + It will have a negative impact to the performance.
19678 + See detail in aufs.5.
19681 + prompt "method" if AUFS_HNOTIFY
19682 + default AUFS_HFSNOTIFY
19683 +config AUFS_HFSNOTIFY
19688 +config AUFS_EXPORT
19689 + bool "NFS-exportable aufs"
19690 + depends on EXPORTFS
19692 + If you want to export your mounted aufs via NFS, then enable this
19693 + option. There are several requirements for this configuration.
19694 + See detail in aufs.5.
19696 +config AUFS_INO_T_64
19698 + depends on AUFS_EXPORT
19699 + depends on 64BIT && !(ALPHA || S390)
19702 + Automatic configuration for internal use.
19703 + /* typedef unsigned long/int __kernel_ino_t */
19704 + /* alpha and s390x are int */
19707 + bool "Readdir in userspace"
19709 + Aufs has two methods to provide a merged view for a directory,
19710 + by a user-space library and by kernel-space natively. The latter
19711 + is always enabled but sometimes large and slow.
19712 + If you enable this option, install the library in aufs2-util
19713 + package, and set some environment variables for your readdir(3),
19714 + then the work will be handled in user-space which generally
19715 + shows better performance in most cases.
19716 + See detail in aufs.5.
19718 +config AUFS_SP_IATTR
19719 + bool "Respect the attributes (mtime/ctime mainly) of special files"
19721 + When you write something to a special file, some attributes of it
19722 + (mtime/ctime mainly) may be updated. Generally such updates are
19723 + less important (actually some device drivers and NFS ignore
19724 + it). But some applications (such like test program) requires
19725 + such updates. If you need these updates, then enable this
19726 + configuration which introduces some overhead.
19727 + Currently this configuration handles FIFO only.
19730 + bool "Show whiteouts"
19732 + If you want to make the whiteouts in aufs visible, then enable
19733 + this option and specify 'shwh' mount option. Although it may
19734 + sounds like philosophy or something, but in technically it
19735 + simply shows the name of whiteout with keeping its behaviour.
19737 +config AUFS_BR_RAMFS
19738 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
19740 + If you want to use ramfs as an aufs branch fs, then enable this
19741 + option. Generally tmpfs is recommended.
19742 + Aufs prohibited them to be a branch fs by default, because
19743 + initramfs becomes unusable after switch_root or something
19744 + generally. If you sets initramfs as an aufs branch and boot your
19745 + system by switch_root, you will meet a problem easily since the
19746 + files in initramfs may be inaccessible.
19747 + Unless you are going to use ramfs as an aufs branch fs without
19748 + switch_root or something, leave it N.
19750 +config AUFS_BR_FUSE
19751 + bool "Fuse fs as an aufs branch"
19752 + depends on FUSE_FS
19755 + If you want to use fuse-based userspace filesystem as an aufs
19756 + branch fs, then enable this option.
19757 + It implements the internal poll(2) operation which is
19758 + implemented by fuse only (curretnly).
19763 + Automatic configuration for internal use.
19765 +config AUFS_BR_HFSPLUS
19766 + bool "Hfsplus as an aufs branch"
19767 + depends on HFSPLUS_FS
19770 + If you want to use hfsplus fs as an aufs branch fs, then enable
19771 + this option. This option introduces a small overhead at
19772 + copying-up a file on hfsplus.
19774 +config AUFS_BDEV_LOOP
19776 + depends on BLK_DEV_LOOP
19779 + Automatic configuration for internal use.
19780 + Convert =[ym] into =y.
19783 + bool "Debug aufs"
19785 + Enable this to compile aufs internal debug code.
19786 + It will have a negative impact to the performance.
19788 +config AUFS_MAGIC_SYSRQ
19790 + depends on AUFS_DEBUG && MAGIC_SYSRQ
19793 + Automatic configuration for internal use.
19794 + When aufs supports Magic SysRq, enabled automatically.
19796 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
19797 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
19798 +++ linux/fs/aufs/loop.c 2014-04-24 22:11:10.855269116 +0200
19801 + * Copyright (C) 2005-2014 Junjiro R. Okajima
19803 + * This program, aufs is free software; you can redistribute it and/or modify
19804 + * it under the terms of the GNU General Public License as published by
19805 + * the Free Software Foundation; either version 2 of the License, or
19806 + * (at your option) any later version.
19808 + * This program is distributed in the hope that it will be useful,
19809 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19810 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19811 + * GNU General Public License for more details.
19813 + * You should have received a copy of the GNU General Public License
19814 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19818 + * support for loopback block device as a branch
19823 +/* added into drivers/block/loop.c */
19824 +static struct file *(*backing_file_func)(struct super_block *sb);
19827 + * test if two lower dentries have overlapping branches.
19829 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
19831 + struct super_block *h_sb;
19832 + struct file *backing_file;
19834 + if (unlikely(!backing_file_func)) {
19835 + /* don't load "loop" module here */
19836 + backing_file_func = symbol_get(loop_backing_file);
19837 + if (unlikely(!backing_file_func))
19838 + /* "loop" module is not loaded */
19842 + h_sb = h_adding->d_sb;
19843 + backing_file = backing_file_func(h_sb);
19844 + if (!backing_file)
19847 + h_adding = backing_file->f_dentry;
19849 + * h_adding can be local NFS.
19850 + * in this case aufs cannot detect the loop.
19852 + if (unlikely(h_adding->d_sb == sb))
19854 + return !!au_test_subdir(h_adding, sb->s_root);
19857 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
19858 +int au_test_loopback_kthread(void)
19861 + struct task_struct *tsk = current;
19862 + char c, comm[sizeof(tsk->comm)];
19865 + if (tsk->flags & PF_KTHREAD) {
19866 + get_task_comm(comm, tsk);
19868 + ret = ('0' <= c && c <= '9'
19869 + && !strncmp(comm, "loop", 4));
19875 +/* ---------------------------------------------------------------------- */
19877 +#define au_warn_loopback_step 16
19878 +static int au_warn_loopback_nelem = au_warn_loopback_step;
19879 +static unsigned long *au_warn_loopback_array;
19881 +void au_warn_loopback(struct super_block *h_sb)
19883 + int i, new_nelem;
19884 + unsigned long *a, magic;
19885 + static DEFINE_SPINLOCK(spin);
19887 + magic = h_sb->s_magic;
19888 + spin_lock(&spin);
19889 + a = au_warn_loopback_array;
19890 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
19891 + if (a[i] == magic) {
19892 + spin_unlock(&spin);
19896 + /* h_sb is new to us, print it */
19897 + if (i < au_warn_loopback_nelem) {
19902 + /* expand the array */
19903 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
19904 + a = au_kzrealloc(au_warn_loopback_array,
19905 + au_warn_loopback_nelem * sizeof(unsigned long),
19906 + new_nelem * sizeof(unsigned long), GFP_ATOMIC);
19908 + au_warn_loopback_nelem = new_nelem;
19909 + au_warn_loopback_array = a;
19914 + spin_unlock(&spin);
19915 + AuWarn1("realloc failed, ignored\n");
19919 + spin_unlock(&spin);
19920 + pr_warn("you may want to try another patch for loopback file "
19921 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
19924 +int au_loopback_init(void)
19927 + struct super_block *sb __maybe_unused;
19929 + AuDebugOn(sizeof(sb->s_magic) != sizeof(unsigned long));
19932 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
19933 + sizeof(unsigned long), GFP_NOFS);
19934 + if (unlikely(!au_warn_loopback_array))
19940 +void au_loopback_fin(void)
19942 + symbol_put(loop_backing_file);
19943 + kfree(au_warn_loopback_array);
19945 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
19946 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
19947 +++ linux/fs/aufs/loop.h 2014-04-24 22:11:10.855269116 +0200
19950 + * Copyright (C) 2005-2014 Junjiro R. Okajima
19952 + * This program, aufs is free software; you can redistribute it and/or modify
19953 + * it under the terms of the GNU General Public License as published by
19954 + * the Free Software Foundation; either version 2 of the License, or
19955 + * (at your option) any later version.
19957 + * This program is distributed in the hope that it will be useful,
19958 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19959 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19960 + * GNU General Public License for more details.
19962 + * You should have received a copy of the GNU General Public License
19963 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19967 + * support for loopback mount as a branch
19970 +#ifndef __AUFS_LOOP_H__
19971 +#define __AUFS_LOOP_H__
19976 +struct super_block;
19978 +#ifdef CONFIG_AUFS_BDEV_LOOP
19979 +/* drivers/block/loop.c */
19980 +struct file *loop_backing_file(struct super_block *sb);
19983 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
19984 +int au_test_loopback_kthread(void);
19985 +void au_warn_loopback(struct super_block *h_sb);
19987 +int au_loopback_init(void);
19988 +void au_loopback_fin(void);
19990 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
19991 + struct dentry *h_adding)
19992 +AuStubInt0(au_test_loopback_kthread, void)
19993 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
19995 +AuStubInt0(au_loopback_init, void)
19996 +AuStubVoid(au_loopback_fin, void)
19997 +#endif /* BLK_DEV_LOOP */
19999 +#endif /* __KERNEL__ */
20000 +#endif /* __AUFS_LOOP_H__ */
20001 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
20002 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
20003 +++ linux/fs/aufs/magic.mk 2012-10-05 20:40:23.980965955 +0200
20006 +# defined in ${srctree}/fs/fuse/inode.c
20008 +ifdef CONFIG_FUSE_FS
20009 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
20012 +# defined in ${srctree}/fs/ocfs2/ocfs2_fs.h
20014 +ifdef CONFIG_OCFS2_FS
20015 +ccflags-y += -DOCFS2_SUPER_MAGIC=0x7461636f
20018 +# defined in ${srctree}/fs/ocfs2/dlm/userdlm.h
20020 +ifdef CONFIG_OCFS2_FS_O2CB
20021 +ccflags-y += -DDLMFS_MAGIC=0x76a9f425
20024 +# defined in ${srctree}/fs/cifs/cifsfs.c
20026 +ifdef CONFIG_CIFS_FS
20027 +ccflags-y += -DCIFS_MAGIC_NUMBER=0xFF534D42
20030 +# defined in ${srctree}/fs/xfs/xfs_sb.h
20032 +ifdef CONFIG_XFS_FS
20033 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
20036 +# defined in ${srctree}/fs/configfs/mount.c
20038 +ifdef CONFIG_CONFIGFS_FS
20039 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
20042 +# defined in ${srctree}/fs/9p/v9fs.h
20044 +ifdef CONFIG_9P_FS
20045 +ccflags-y += -DV9FS_MAGIC=0x01021997
20048 +# defined in ${srctree}/fs/ubifs/ubifs.h
20050 +ifdef CONFIG_UBIFS_FS
20051 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
20054 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
20056 +ifdef CONFIG_HFSPLUS_FS
20057 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
20059 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
20060 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
20061 +++ linux/fs/aufs/Makefile 2014-04-24 22:11:10.845269011 +0200
20064 +include ${src}/magic.mk
20065 +ifeq (${CONFIG_AUFS_FS},m)
20066 +include ${src}/conf.mk
20068 +-include ${src}/priv_def.mk
20070 +# cf. include/linux/kernel.h
20072 +ccflags-y += -DDEBUG
20073 +# sparse requires the full pathname
20075 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
20077 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
20080 +obj-$(CONFIG_AUFS_FS) += aufs.o
20081 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
20082 + wkq.o vfsub.o dcsub.o \
20083 + cpup.o whout.o wbr_policy.o \
20084 + dinfo.o dentry.o \
20086 + finfo.o file.o f_op.o \
20088 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
20092 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
20093 +aufs-$(CONFIG_SYSFS) += sysfs.o
20094 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
20095 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
20096 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
20097 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
20098 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
20099 +aufs-$(CONFIG_AUFS_POLL) += poll.o
20100 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
20101 +aufs-$(CONFIG_AUFS_SP_IATTR) += f_op_sp.o
20102 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
20103 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
20104 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
20105 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
20106 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
20107 +++ linux/fs/aufs/module.c 2014-04-24 22:11:10.855269116 +0200
20110 + * Copyright (C) 2005-2014 Junjiro R. Okajima
20112 + * This program, aufs is free software; you can redistribute it and/or modify
20113 + * it under the terms of the GNU General Public License as published by
20114 + * the Free Software Foundation; either version 2 of the License, or
20115 + * (at your option) any later version.
20117 + * This program is distributed in the hope that it will be useful,
20118 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20119 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20120 + * GNU General Public License for more details.
20122 + * You should have received a copy of the GNU General Public License
20123 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20127 + * module global variables and operations
20130 +#include <linux/module.h>
20131 +#include <linux/seq_file.h>
20134 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp)
20136 + if (new_sz <= nused)
20139 + p = krealloc(p, new_sz, gfp);
20141 + memset(p + nused, 0, new_sz - nused);
20145 +/* ---------------------------------------------------------------------- */
20150 +struct kmem_cache *au_cachep[AuCache_Last];
20151 +static int __init au_cache_init(void)
20153 + au_cachep[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
20154 + if (au_cachep[AuCache_DINFO])
20155 + /* SLAB_DESTROY_BY_RCU */
20156 + au_cachep[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
20157 + au_icntnr_init_once);
20158 + if (au_cachep[AuCache_ICNTNR])
20159 + au_cachep[AuCache_FINFO] = AuCacheCtor(au_finfo,
20160 + au_fi_init_once);
20161 + if (au_cachep[AuCache_FINFO])
20162 + au_cachep[AuCache_VDIR] = AuCache(au_vdir);
20163 + if (au_cachep[AuCache_VDIR])
20164 + au_cachep[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
20165 + if (au_cachep[AuCache_DEHSTR])
20171 +static void au_cache_fin(void)
20176 + * Make sure all delayed rcu free inodes are flushed before we
20181 + /* excluding AuCache_HNOTIFY */
20182 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
20183 + for (i = 0; i < AuCache_HNOTIFY; i++)
20184 + if (au_cachep[i]) {
20185 + kmem_cache_destroy(au_cachep[i]);
20186 + au_cachep[i] = NULL;
20190 +/* ---------------------------------------------------------------------- */
20192 +int au_dir_roflags;
20194 +#ifdef CONFIG_AUFS_SBILIST
20196 + * iterate_supers_type() doesn't protect us from
20197 + * remounting (branch management)
20199 +struct au_splhead au_sbilist;
20202 +struct lock_class_key au_lc_key[AuLcKey_Last];
20205 + * functions for module interface.
20207 +MODULE_LICENSE("GPL");
20208 +/* MODULE_LICENSE("GPL v2"); */
20209 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
20210 +MODULE_DESCRIPTION(AUFS_NAME
20211 + " -- Advanced multi layered unification filesystem");
20212 +MODULE_VERSION(AUFS_VERSION);
20213 +MODULE_ALIAS_FS(AUFS_NAME);
20215 +/* this module parameter has no meaning when SYSFS is disabled */
20216 +int sysaufs_brs = 1;
20217 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
20218 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
20220 +/* ---------------------------------------------------------------------- */
20222 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
20224 +int au_seq_path(struct seq_file *seq, struct path *path)
20226 + return seq_path(seq, path, au_esc_chars);
20229 +/* ---------------------------------------------------------------------- */
20231 +static int __init aufs_init(void)
20236 + p = au_esc_chars;
20237 + for (i = 1; i <= ' '; i++)
20243 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
20245 + au_sbilist_init();
20246 + sysaufs_brs_init();
20249 + err = sysaufs_init();
20250 + if (unlikely(err))
20252 + err = au_procfs_init();
20253 + if (unlikely(err))
20254 + goto out_sysaufs;
20255 + err = au_wkq_init();
20256 + if (unlikely(err))
20258 + err = au_loopback_init();
20259 + if (unlikely(err))
20261 + err = au_hnotify_init();
20262 + if (unlikely(err))
20263 + goto out_loopback;
20264 + err = au_sysrq_init();
20265 + if (unlikely(err))
20267 + err = au_cache_init();
20268 + if (unlikely(err))
20270 + err = register_filesystem(&aufs_fs_type);
20271 + if (unlikely(err))
20273 + /* since we define pr_fmt, call printk directly */
20274 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
20275 + goto out; /* success */
20282 + au_hnotify_fin();
20284 + au_loopback_fin();
20296 +static void __exit aufs_exit(void)
20298 + unregister_filesystem(&aufs_fs_type);
20301 + au_hnotify_fin();
20302 + au_loopback_fin();
20309 +module_init(aufs_init);
20310 +module_exit(aufs_exit);
20311 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
20312 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
20313 +++ linux/fs/aufs/module.h 2014-04-24 22:11:10.855269116 +0200
20316 + * Copyright (C) 2005-2014 Junjiro R. Okajima
20318 + * This program, aufs is free software; you can redistribute it and/or modify
20319 + * it under the terms of the GNU General Public License as published by
20320 + * the Free Software Foundation; either version 2 of the License, or
20321 + * (at your option) any later version.
20323 + * This program is distributed in the hope that it will be useful,
20324 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20325 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20326 + * GNU General Public License for more details.
20328 + * You should have received a copy of the GNU General Public License
20329 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20333 + * module initialization and module-global
20336 +#ifndef __AUFS_MODULE_H__
20337 +#define __AUFS_MODULE_H__
20341 +#include <linux/slab.h>
20346 +/* module parameters */
20347 +extern int sysaufs_brs;
20349 +/* ---------------------------------------------------------------------- */
20351 +extern int au_dir_roflags;
20354 + AuLcNonDir_FIINFO,
20355 + AuLcNonDir_DIINFO,
20356 + AuLcNonDir_IIINFO,
20362 + AuLcSymlink_DIINFO,
20363 + AuLcSymlink_IIINFO,
20367 +extern struct lock_class_key au_lc_key[AuLcKey_Last];
20369 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp);
20370 +int au_seq_path(struct seq_file *seq, struct path *path);
20372 +#ifdef CONFIG_PROC_FS
20374 +int __init au_procfs_init(void);
20375 +void au_procfs_fin(void);
20377 +AuStubInt0(au_procfs_init, void);
20378 +AuStubVoid(au_procfs_fin, void);
20381 +/* ---------------------------------------------------------------------- */
20390 + AuCache_HNOTIFY, /* must be last */
20394 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
20395 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
20396 +#define AuCacheCtor(type, ctor) \
20397 + kmem_cache_create(#type, sizeof(struct type), \
20398 + __alignof__(struct type), AuCacheFlags, ctor)
20400 +extern struct kmem_cache *au_cachep[];
20402 +#define AuCacheFuncs(name, index) \
20403 +static inline struct au_##name *au_cache_alloc_##name(void) \
20404 +{ return kmem_cache_alloc(au_cachep[AuCache_##index], GFP_NOFS); } \
20405 +static inline void au_cache_free_##name(struct au_##name *p) \
20406 +{ kmem_cache_free(au_cachep[AuCache_##index], p); }
20408 +AuCacheFuncs(dinfo, DINFO);
20409 +AuCacheFuncs(icntnr, ICNTNR);
20410 +AuCacheFuncs(finfo, FINFO);
20411 +AuCacheFuncs(vdir, VDIR);
20412 +AuCacheFuncs(vdir_dehstr, DEHSTR);
20413 +#ifdef CONFIG_AUFS_HNOTIFY
20414 +AuCacheFuncs(hnotify, HNOTIFY);
20417 +#endif /* __KERNEL__ */
20418 +#endif /* __AUFS_MODULE_H__ */
20419 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
20420 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
20421 +++ linux/fs/aufs/mvdown.c 2014-04-24 22:11:10.855269116 +0200
20424 + * Copyright (C) 2011-2014 Junjiro R. Okajima
20426 + * This program, aufs is free software; you can redistribute it and/or modify
20427 + * it under the terms of the GNU General Public License as published by
20428 + * the Free Software Foundation; either version 2 of the License, or
20429 + * (at your option) any later version.
20431 + * This program is distributed in the hope that it will be useful,
20432 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20433 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20434 + * GNU General Public License for more details.
20436 + * You should have received a copy of the GNU General Public License
20437 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20441 + * move-down, opposite of copy-up
20446 +struct au_mvd_args {
20448 + struct super_block *h_sb;
20449 + struct dentry *h_parent;
20450 + struct au_hinode *hdir;
20451 + struct inode *h_dir, *h_inode;
20452 + } info[AUFS_MVDOWN_NARRAY];
20454 + struct aufs_mvdown mvdown;
20455 + struct dentry *dentry, *parent;
20456 + struct inode *inode, *dir;
20457 + struct super_block *sb;
20458 + aufs_bindex_t bopq, bwh, bfound;
20459 + unsigned char rename_lock;
20460 + struct au_pin pin;
20463 +#define mvd_errno mvdown.au_errno
20464 +#define mvd_bsrc mvdown.a[AUFS_MVDOWN_UPPER].bindex
20465 +#define mvd_src_brid mvdown.a[AUFS_MVDOWN_UPPER].brid
20466 +#define mvd_bdst mvdown.a[AUFS_MVDOWN_LOWER].bindex
20467 +#define mvd_dst_brid mvdown.a[AUFS_MVDOWN_LOWER].brid
20469 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
20470 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
20471 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
20472 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
20473 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
20475 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
20476 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
20477 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
20478 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
20479 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
20481 +#define AU_MVD_PR(flag, ...) do { \
20483 + pr_err(__VA_ARGS__); \
20486 +/* make the parent dir on bdst */
20487 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
20492 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
20493 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
20494 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
20495 + a->mvd_h_dst_parent = NULL;
20496 + if (au_dbend(a->parent) >= a->mvd_bdst)
20497 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
20498 + if (!a->mvd_h_dst_parent) {
20499 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
20500 + if (unlikely(err)) {
20501 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
20504 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
20512 +/* lock them all */
20513 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
20516 + struct dentry *h_trap;
20518 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
20519 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
20520 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
20521 + a->rename_lock = 0;
20522 + err = au_pin(&a->pin, a->dentry, a->mvd_bdst,
20523 + au_opt_udba(a->sb),
20524 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
20526 + a->mvd_h_src_dir = a->mvd_h_src_parent->d_inode;
20527 + mutex_lock_nested(&a->mvd_h_src_dir->i_mutex,
20528 + AuLsc_I_PARENT3);
20530 + AU_MVD_PR(dmsg, "pin failed\n");
20535 + a->rename_lock = 1;
20536 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
20537 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
20539 + err = (h_trap != a->mvd_h_src_parent);
20541 + err = (h_trap != a->mvd_h_dst_parent);
20543 + BUG_ON(err); /* it should never happen */
20550 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
20552 + if (!a->rename_lock) {
20553 + mutex_unlock(&a->mvd_h_src_dir->i_mutex);
20554 + au_unpin(&a->pin);
20556 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
20557 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
20560 +/* copy-down the file */
20561 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
20564 + struct au_cp_generic cpg = {
20565 + .dentry = a->dentry,
20566 + .bdst = a->mvd_bdst,
20567 + .bsrc = a->mvd_bsrc,
20570 + .flags = AuCpup_DTIME | AuCpup_HOPEN
20573 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
20574 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
20575 + au_fset_cpup(cpg.flags, OVERWRITE);
20576 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
20577 + au_fset_cpup(cpg.flags, RWDST);
20578 + err = au_sio_cpdown_simple(&cpg);
20579 + if (unlikely(err))
20580 + AU_MVD_PR(dmsg, "cpdown failed\n");
20587 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
20590 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
20593 + struct path h_path;
20594 + struct au_branch *br;
20595 + struct inode *delegated;
20597 + br = au_sbr(a->sb, a->mvd_bdst);
20598 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
20599 + err = PTR_ERR(h_path.dentry);
20600 + if (IS_ERR(h_path.dentry)) {
20601 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
20606 + if (h_path.dentry->d_inode) {
20607 + h_path.mnt = au_br_mnt(br);
20608 + delegated = NULL;
20609 + err = vfsub_unlink(a->mvd_h_dst_parent->d_inode, &h_path,
20610 + &delegated, /*force*/0);
20611 + if (unlikely(err == -EWOULDBLOCK)) {
20612 + pr_warn("cannot retry for NFSv4 delegation"
20613 + " for an internal unlink\n");
20616 + if (unlikely(err))
20617 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
20619 + dput(h_path.dentry);
20627 + * unlink the topmost h_dentry
20628 + * Note: the target file MAY be modified by UDBA between this mutex_unlock() and
20629 + * mutex_lock() in vfs_unlink(). in this case, such changes may be lost.
20631 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
20634 + struct path h_path;
20635 + struct inode *delegated;
20637 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
20638 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
20639 + delegated = NULL;
20640 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
20641 + if (unlikely(err == -EWOULDBLOCK)) {
20642 + pr_warn("cannot retry for NFSv4 delegation"
20643 + " for an internal unlink\n");
20646 + if (unlikely(err))
20647 + AU_MVD_PR(dmsg, "unlink failed\n");
20654 + * copy-down the file and unlink the bsrc file.
20655 + * - unlink the bdst whout if exist
20656 + * - copy-down the file (with whtmp name and rename)
20657 + * - unlink the bsrc file
20659 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
20663 + err = au_do_mkdir(dmsg, a);
20665 + err = au_do_lock(dmsg, a);
20666 + if (unlikely(err))
20670 + * do not revert the activities we made on bdst since they should be
20671 + * harmless in aufs.
20674 + err = au_do_cpdown(dmsg, a);
20676 + err = au_do_unlink_wh(dmsg, a);
20677 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
20678 + err = au_do_unlink(dmsg, a);
20679 + if (unlikely(err))
20682 + /* maintain internal array */
20683 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
20684 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
20685 + au_set_dbstart(a->dentry, a->mvd_bdst);
20686 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
20687 + au_set_ibstart(a->inode, a->mvd_bdst);
20689 + if (au_dbend(a->dentry) < a->mvd_bdst)
20690 + au_set_dbend(a->dentry, a->mvd_bdst);
20691 + if (au_ibend(a->inode) < a->mvd_bdst)
20692 + au_set_ibend(a->inode, a->mvd_bdst);
20695 + au_do_unlock(dmsg, a);
20701 +/* ---------------------------------------------------------------------- */
20703 +static int find_lower_writable(struct au_mvd_args *a)
20705 + struct super_block *sb;
20706 + aufs_bindex_t bindex, bend;
20707 + struct au_branch *br;
20710 + bindex = a->mvd_bsrc;
20711 + bend = au_sbend(sb);
20712 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER)) {
20713 + for (bindex++; bindex <= bend; bindex++) {
20714 + br = au_sbr(sb, bindex);
20715 + if (!au_br_rdonly(br))
20719 + for (bindex++; bindex <= bend; bindex++) {
20720 + br = au_sbr(sb, bindex);
20721 + if (!(au_br_sb(br)->s_flags & MS_RDONLY)) {
20722 + if (au_br_rdonly(br))
20724 + |= AUFS_MVDOWN_ROLOWER_R;
20733 +/* make sure the file is idle */
20734 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
20736 + int err, plinked;
20739 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
20740 + if (au_dbstart(a->dentry) == a->mvd_bsrc
20741 + && d_count(a->dentry) == 1
20742 + && atomic_read(&a->inode->i_count) == 1
20743 + /* && a->mvd_h_src_inode->i_nlink == 1 */
20744 + && (!plinked || !au_plink_test(a->inode))
20745 + && a->inode->i_nlink == 1)
20750 + "b%d, d{b%d, c%u?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
20751 + a->mvd_bsrc, au_dbstart(a->dentry), d_count(a->dentry),
20752 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
20753 + a->mvd_h_src_inode->i_nlink,
20754 + plinked, plinked ? au_plink_test(a->inode) : 0);
20761 +/* make sure the parent dir is fine */
20762 +static int au_mvd_args_parent(const unsigned char dmsg,
20763 + struct au_mvd_args *a)
20766 + aufs_bindex_t bindex;
20769 + if (unlikely(au_alive_dir(a->parent))) {
20771 + AU_MVD_PR(dmsg, "parent dir is dead\n");
20775 + a->bopq = au_dbdiropq(a->parent);
20776 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
20777 + AuDbg("b%d\n", bindex);
20778 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
20779 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
20781 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
20782 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
20783 + a->bopq, a->mvd_bdst);
20791 +static int au_mvd_args_intermediate(const unsigned char dmsg,
20792 + struct au_mvd_args *a)
20795 + struct au_dinfo *dinfo, *tmp;
20797 + /* lookup the next lower positive entry */
20799 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
20800 + if (unlikely(!tmp))
20805 + dinfo = au_di(a->dentry);
20806 + au_di_cp(tmp, dinfo);
20807 + au_di_swap(tmp, dinfo);
20809 + /* returns the number of positive dentries */
20810 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1, /*type*/0);
20812 + a->bwh = au_dbwh(a->dentry);
20813 + else if (err > 0)
20814 + a->bfound = au_dbstart(a->dentry);
20816 + au_di_swap(tmp, dinfo);
20817 + au_rw_write_unlock(&tmp->di_rwsem);
20819 + if (unlikely(err < 0))
20820 + AU_MVD_PR(dmsg, "failed look-up lower\n");
20823 + * here, we have these cases.
20825 + * no positive dentry under bsrc. there are more sub-cases.
20827 + * there no whiteout, we can safely move-down.
20830 + * bsrc < bwh && bwh < bdst
20831 + * there is a whiteout on RO branch. cannot proceed.
20833 + * there is a whiteout on the RW target branch. it should
20836 + * there is a whiteout somewhere unrelated branch.
20837 + * -1 < bfound && bfound <= bsrc
20840 + * found, but it is on RO branch between bsrc and bdst. cannot
20843 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
20846 + * found, after we create the file on bdst, it will be hidden.
20849 + AuDebugOn(a->bfound == -1
20851 + && a->bwh <= a->mvd_bsrc);
20852 + AuDebugOn(-1 < a->bfound
20853 + && a->bfound <= a->mvd_bsrc);
20856 + if (a->bfound == -1
20857 + && a->mvd_bsrc < a->bwh
20859 + && a->bwh < a->mvd_bdst) {
20860 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
20861 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
20862 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
20864 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
20865 + a->mvd_errno = EAU_MVDOWN_UPPER;
20866 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
20867 + a->mvd_bdst, a->bfound);
20871 + err = 0; /* success */
20878 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
20883 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
20884 + && a->bfound == a->mvd_bdst)
20890 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
20893 + struct au_branch *br;
20896 + if (unlikely(S_ISDIR(a->inode->i_mode)))
20900 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
20901 + a->mvd_bsrc = au_ibstart(a->inode);
20903 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
20904 + if (unlikely(a->mvd_bsrc < 0
20905 + || (a->mvd_bsrc < au_dbstart(a->dentry)
20906 + || au_dbend(a->dentry) < a->mvd_bsrc
20907 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
20908 + || (a->mvd_bsrc < au_ibstart(a->inode)
20909 + || au_ibend(a->inode) < a->mvd_bsrc
20910 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
20911 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
20912 + AU_MVD_PR(dmsg, "no upper\n");
20916 + if (unlikely(a->mvd_bsrc == au_sbend(a->sb))) {
20917 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
20918 + AU_MVD_PR(dmsg, "on the bottom\n");
20921 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
20922 + br = au_sbr(a->sb, a->mvd_bsrc);
20923 + err = au_br_rdonly(br);
20924 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
20925 + if (unlikely(err))
20927 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
20928 + || IS_APPEND(a->mvd_h_src_inode))) {
20930 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
20936 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
20937 + a->mvd_bdst = find_lower_writable(a);
20938 + if (unlikely(a->mvd_bdst < 0)) {
20939 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
20940 + AU_MVD_PR(dmsg, "no writable lower branch\n");
20944 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
20945 + if (unlikely(a->mvd_bdst < 0
20946 + || au_sbend(a->sb) < a->mvd_bdst)) {
20947 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
20948 + AU_MVD_PR(dmsg, "no lower brid\n");
20953 + err = au_mvd_args_busy(dmsg, a);
20955 + err = au_mvd_args_parent(dmsg, a);
20957 + err = au_mvd_args_intermediate(dmsg, a);
20959 + err = au_mvd_args_exist(dmsg, a);
20961 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
20968 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
20971 + unsigned char dmsg;
20972 + struct au_mvd_args *args;
20975 + if (unlikely(!capable(CAP_SYS_ADMIN)))
20978 + WARN_ONCE(1, "move-down is still testing...\n");
20981 + args = kmalloc(sizeof(*args), GFP_NOFS);
20982 + if (unlikely(!args))
20985 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
20987 + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
20988 + if (unlikely(err)) {
20993 + AuDbg("flags 0x%x\n", args->mvdown.flags);
20994 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
20995 + args->mvdown.au_errno = 0;
20996 + args->dentry = dentry;
20997 + args->inode = dentry->d_inode;
20998 + args->sb = dentry->d_sb;
21001 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
21002 + args->parent = dget_parent(dentry);
21003 + args->dir = args->parent->d_inode;
21004 + mutex_lock_nested(&args->dir->i_mutex, I_MUTEX_PARENT);
21005 + dput(args->parent);
21006 + if (unlikely(args->parent != dentry->d_parent)) {
21007 + AU_MVD_PR(dmsg, "parent dir is moved\n");
21011 + mutex_lock_nested(&args->inode->i_mutex, I_MUTEX_CHILD);
21012 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH);
21013 + if (unlikely(err))
21016 + di_write_lock_parent(args->parent);
21017 + err = au_mvd_args(dmsg, args);
21018 + if (unlikely(err))
21021 + AuDbgDentry(dentry);
21022 + AuDbgInode(args->inode);
21023 + err = au_do_mvdown(dmsg, args);
21024 + if (unlikely(err))
21026 + AuDbgDentry(dentry);
21027 + AuDbgInode(args->inode);
21029 + au_cpup_attr_timesizes(args->dir);
21030 + au_cpup_attr_timesizes(args->inode);
21031 + au_cpup_igen(args->inode, au_h_iptr(args->inode, args->mvd_bdst));
21032 + /* au_digen_dec(dentry); */
21035 + di_write_unlock(args->parent);
21036 + aufs_read_unlock(dentry, AuLock_DW);
21038 + mutex_unlock(&args->inode->i_mutex);
21040 + mutex_unlock(&args->dir->i_mutex);
21042 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
21050 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
21051 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
21052 +++ linux/fs/aufs/opts.c 2014-04-24 22:11:10.855269116 +0200
21055 + * Copyright (C) 2005-2014 Junjiro R. Okajima
21057 + * This program, aufs is free software; you can redistribute it and/or modify
21058 + * it under the terms of the GNU General Public License as published by
21059 + * the Free Software Foundation; either version 2 of the License, or
21060 + * (at your option) any later version.
21062 + * This program is distributed in the hope that it will be useful,
21063 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21064 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21065 + * GNU General Public License for more details.
21067 + * You should have received a copy of the GNU General Public License
21068 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21072 + * mount options/flags
21075 +#include <linux/namei.h>
21076 +#include <linux/types.h> /* a distribution requires */
21077 +#include <linux/parser.h>
21080 +/* ---------------------------------------------------------------------- */
21084 + Opt_add, Opt_del, Opt_mod, Opt_reorder, Opt_append, Opt_prepend,
21085 + Opt_idel, Opt_imod, Opt_ireorder,
21086 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash, Opt_rendir,
21087 + Opt_rdblk_def, Opt_rdhash_def,
21088 + Opt_xino, Opt_zxino, Opt_noxino,
21089 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
21090 + Opt_trunc_xino_path, Opt_itrunc_xino,
21091 + Opt_trunc_xib, Opt_notrunc_xib,
21092 + Opt_shwh, Opt_noshwh,
21093 + Opt_plink, Opt_noplink, Opt_list_plink,
21095 + Opt_dio, Opt_nodio,
21096 + /* Opt_lock, Opt_unlock, */
21097 + Opt_cmd, Opt_cmd_args,
21098 + Opt_diropq_a, Opt_diropq_w,
21099 + Opt_warn_perm, Opt_nowarn_perm,
21100 + Opt_wbr_copyup, Opt_wbr_create,
21101 + Opt_refrof, Opt_norefrof,
21102 + Opt_verbose, Opt_noverbose,
21103 + Opt_sum, Opt_nosum, Opt_wsum,
21104 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
21107 +static match_table_t options = {
21108 + {Opt_br, "br=%s"},
21109 + {Opt_br, "br:%s"},
21111 + {Opt_add, "add=%d:%s"},
21112 + {Opt_add, "add:%d:%s"},
21113 + {Opt_add, "ins=%d:%s"},
21114 + {Opt_add, "ins:%d:%s"},
21115 + {Opt_append, "append=%s"},
21116 + {Opt_append, "append:%s"},
21117 + {Opt_prepend, "prepend=%s"},
21118 + {Opt_prepend, "prepend:%s"},
21120 + {Opt_del, "del=%s"},
21121 + {Opt_del, "del:%s"},
21122 + /* {Opt_idel, "idel:%d"}, */
21123 + {Opt_mod, "mod=%s"},
21124 + {Opt_mod, "mod:%s"},
21125 + /* {Opt_imod, "imod:%d:%s"}, */
21127 + {Opt_dirwh, "dirwh=%d"},
21129 + {Opt_xino, "xino=%s"},
21130 + {Opt_noxino, "noxino"},
21131 + {Opt_trunc_xino, "trunc_xino"},
21132 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
21133 + {Opt_notrunc_xino, "notrunc_xino"},
21134 + {Opt_trunc_xino_path, "trunc_xino=%s"},
21135 + {Opt_itrunc_xino, "itrunc_xino=%d"},
21136 + /* {Opt_zxino, "zxino=%s"}, */
21137 + {Opt_trunc_xib, "trunc_xib"},
21138 + {Opt_notrunc_xib, "notrunc_xib"},
21140 +#ifdef CONFIG_PROC_FS
21141 + {Opt_plink, "plink"},
21143 + {Opt_ignore_silent, "plink"},
21146 + {Opt_noplink, "noplink"},
21148 +#ifdef CONFIG_AUFS_DEBUG
21149 + {Opt_list_plink, "list_plink"},
21152 + {Opt_udba, "udba=%s"},
21154 + {Opt_dio, "dio"},
21155 + {Opt_nodio, "nodio"},
21157 + {Opt_diropq_a, "diropq=always"},
21158 + {Opt_diropq_a, "diropq=a"},
21159 + {Opt_diropq_w, "diropq=whiteouted"},
21160 + {Opt_diropq_w, "diropq=w"},
21162 + {Opt_warn_perm, "warn_perm"},
21163 + {Opt_nowarn_perm, "nowarn_perm"},
21165 + /* keep them temporary */
21166 + {Opt_ignore_silent, "coo=%s"},
21167 + {Opt_ignore_silent, "nodlgt"},
21168 + {Opt_ignore_silent, "nodirperm1"},
21169 + {Opt_ignore_silent, "clean_plink"},
21171 +#ifdef CONFIG_AUFS_SHWH
21172 + {Opt_shwh, "shwh"},
21174 + {Opt_noshwh, "noshwh"},
21176 + {Opt_rendir, "rendir=%d"},
21178 + {Opt_refrof, "refrof"},
21179 + {Opt_norefrof, "norefrof"},
21181 + {Opt_verbose, "verbose"},
21182 + {Opt_verbose, "v"},
21183 + {Opt_noverbose, "noverbose"},
21184 + {Opt_noverbose, "quiet"},
21185 + {Opt_noverbose, "q"},
21186 + {Opt_noverbose, "silent"},
21188 + {Opt_sum, "sum"},
21189 + {Opt_nosum, "nosum"},
21190 + {Opt_wsum, "wsum"},
21192 + {Opt_rdcache, "rdcache=%d"},
21193 + {Opt_rdblk, "rdblk=%d"},
21194 + {Opt_rdblk_def, "rdblk=def"},
21195 + {Opt_rdhash, "rdhash=%d"},
21196 + {Opt_rdhash_def, "rdhash=def"},
21198 + {Opt_wbr_create, "create=%s"},
21199 + {Opt_wbr_create, "create_policy=%s"},
21200 + {Opt_wbr_copyup, "cpup=%s"},
21201 + {Opt_wbr_copyup, "copyup=%s"},
21202 + {Opt_wbr_copyup, "copyup_policy=%s"},
21204 + /* internal use for the scripts */
21205 + {Opt_ignore_silent, "si=%s"},
21207 + {Opt_br, "dirs=%s"},
21208 + {Opt_ignore, "debug=%d"},
21209 + {Opt_ignore, "delete=whiteout"},
21210 + {Opt_ignore, "delete=all"},
21211 + {Opt_ignore, "imap=%s"},
21213 + /* temporary workaround, due to old mount(8)? */
21214 + {Opt_ignore_silent, "relatime"},
21219 +/* ---------------------------------------------------------------------- */
21221 +static const char *au_parser_pattern(int val, struct match_token *token)
21223 + while (token->pattern) {
21224 + if (token->token == val)
21225 + return token->pattern;
21232 +/* ---------------------------------------------------------------------- */
21234 +static match_table_t brperm = {
21235 + {AuBrPerm_RO, AUFS_BRPERM_RO},
21236 + {AuBrPerm_RR, AUFS_BRPERM_RR},
21237 + {AuBrPerm_RW, AUFS_BRPERM_RW},
21241 +static match_table_t brattr = {
21242 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
21243 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
21244 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
21248 +#define AuBrStr_LONGEST AUFS_BRPERM_RW \
21249 + "+" AUFS_BRATTR_UNPIN \
21250 + "+" AUFS_BRWATTR_NLWH
21252 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
21259 + p = strchr(str, '+');
21262 + v = match_token(str, table, args);
21268 + pr_warn("ignored branch attribute %s\n", str);
21278 +static int noinline_for_stack br_perm_val(char *perm)
21282 + substring_t args[MAX_OPT_ARGS];
21284 + p = strchr(perm, '+');
21287 + val = match_token(perm, brperm, args);
21291 + pr_warn("ignored branch permission %s\n", perm);
21292 + val = AuBrPerm_RO;
21300 + q = strchr(p, '+');
21303 + val |= br_attr_val(p, brattr, args);
21310 + switch (val & AuBrPerm_Mask) {
21311 + case AuBrPerm_RO:
21312 + case AuBrPerm_RR:
21313 + if (unlikely(val & AuBrWAttr_NoLinkWH)) {
21314 + pr_warn("ignored branch attribute %s\n",
21315 + AUFS_BRWATTR_NLWH);
21316 + val &= ~AuBrWAttr_NoLinkWH;
21319 + case AuBrPerm_RW:
21320 + if (unlikely(val & AuBrRAttr_WH)) {
21321 + pr_warn("ignored branch attribute %s\n",
21322 + AUFS_BRRATTR_WH);
21323 + val &= ~AuBrRAttr_WH;
21332 +/* Caller should free the return value */
21333 +char *au_optstr_br_perm(int brperm)
21335 + char *p, a[sizeof(AuBrStr_LONGEST)];
21338 +#define SetPerm(str) do { \
21339 + sz = sizeof(str); \
21340 + memcpy(a, str, sz); \
21341 + p = a + sz - 1; \
21344 +#define AppendAttr(flag, str) do { \
21345 + if (brperm & flag) { \
21346 + sz = sizeof(str); \
21348 + memcpy(p, str, sz); \
21353 + switch (brperm & AuBrPerm_Mask) {
21354 + case AuBrPerm_RO:
21355 + SetPerm(AUFS_BRPERM_RO);
21357 + case AuBrPerm_RR:
21358 + SetPerm(AUFS_BRPERM_RR);
21360 + case AuBrPerm_RW:
21361 + SetPerm(AUFS_BRPERM_RW);
21367 + AppendAttr(AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN);
21368 + AppendAttr(AuBrRAttr_WH, AUFS_BRRATTR_WH);
21369 + AppendAttr(AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH);
21371 + AuDebugOn(strlen(a) >= sizeof(a));
21372 + return kstrdup(a, GFP_NOFS);
21377 +/* ---------------------------------------------------------------------- */
21379 +static match_table_t udbalevel = {
21380 + {AuOpt_UDBA_REVAL, "reval"},
21381 + {AuOpt_UDBA_NONE, "none"},
21382 +#ifdef CONFIG_AUFS_HNOTIFY
21383 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
21384 +#ifdef CONFIG_AUFS_HFSNOTIFY
21385 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
21391 +static int noinline_for_stack udba_val(char *str)
21393 + substring_t args[MAX_OPT_ARGS];
21395 + return match_token(str, udbalevel, args);
21398 +const char *au_optstr_udba(int udba)
21400 + return au_parser_pattern(udba, (void *)udbalevel);
21403 +/* ---------------------------------------------------------------------- */
21405 +static match_table_t au_wbr_create_policy = {
21406 + {AuWbrCreate_TDP, "tdp"},
21407 + {AuWbrCreate_TDP, "top-down-parent"},
21408 + {AuWbrCreate_RR, "rr"},
21409 + {AuWbrCreate_RR, "round-robin"},
21410 + {AuWbrCreate_MFS, "mfs"},
21411 + {AuWbrCreate_MFS, "most-free-space"},
21412 + {AuWbrCreate_MFSV, "mfs:%d"},
21413 + {AuWbrCreate_MFSV, "most-free-space:%d"},
21415 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
21416 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
21417 + {AuWbrCreate_PMFS, "pmfs"},
21418 + {AuWbrCreate_PMFSV, "pmfs:%d"},
21419 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
21420 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
21426 + * cf. linux/lib/parser.c and cmdline.c
21427 + * gave up calling memparse() since it uses simple_strtoull() instead of
21430 +static int noinline_for_stack
21431 +au_match_ull(substring_t *s, unsigned long long *result)
21434 + unsigned int len;
21438 + len = s->to - s->from;
21439 + if (len + 1 <= sizeof(a)) {
21440 + memcpy(a, s->from, len);
21442 + err = kstrtoull(a, 0, result);
21447 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
21448 + struct au_opt_wbr_create *create)
21451 + unsigned long long ull;
21454 + if (!au_match_ull(arg, &ull))
21455 + create->mfsrr_watermark = ull;
21457 + pr_err("bad integer in %s\n", str);
21464 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
21465 + struct au_opt_wbr_create *create)
21470 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
21471 + create->mfs_second = n;
21473 + pr_err("bad integer in %s\n", str);
21480 +static int noinline_for_stack
21481 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
21484 + substring_t args[MAX_OPT_ARGS];
21486 + err = match_token(str, au_wbr_create_policy, args);
21487 + create->wbr_create = err;
21489 + case AuWbrCreate_MFSRRV:
21490 + case AuWbrCreate_PMFSRRV:
21491 + e = au_wbr_mfs_wmark(&args[0], str, create);
21493 + e = au_wbr_mfs_sec(&args[1], str, create);
21497 + case AuWbrCreate_MFSRR:
21498 + case AuWbrCreate_PMFSRR:
21499 + e = au_wbr_mfs_wmark(&args[0], str, create);
21500 + if (unlikely(e)) {
21505 + case AuWbrCreate_MFS:
21506 + case AuWbrCreate_PMFS:
21507 + create->mfs_second = AUFS_MFS_DEF_SEC;
21509 + case AuWbrCreate_MFSV:
21510 + case AuWbrCreate_PMFSV:
21511 + e = au_wbr_mfs_sec(&args[0], str, create);
21520 +const char *au_optstr_wbr_create(int wbr_create)
21522 + return au_parser_pattern(wbr_create, (void *)au_wbr_create_policy);
21525 +static match_table_t au_wbr_copyup_policy = {
21526 + {AuWbrCopyup_TDP, "tdp"},
21527 + {AuWbrCopyup_TDP, "top-down-parent"},
21528 + {AuWbrCopyup_BUP, "bup"},
21529 + {AuWbrCopyup_BUP, "bottom-up-parent"},
21530 + {AuWbrCopyup_BU, "bu"},
21531 + {AuWbrCopyup_BU, "bottom-up"},
21535 +static int noinline_for_stack au_wbr_copyup_val(char *str)
21537 + substring_t args[MAX_OPT_ARGS];
21539 + return match_token(str, au_wbr_copyup_policy, args);
21542 +const char *au_optstr_wbr_copyup(int wbr_copyup)
21544 + return au_parser_pattern(wbr_copyup, (void *)au_wbr_copyup_policy);
21547 +/* ---------------------------------------------------------------------- */
21549 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
21551 +static void dump_opts(struct au_opts *opts)
21553 +#ifdef CONFIG_AUFS_DEBUG
21554 + /* reduce stack space */
21556 + struct au_opt_add *add;
21557 + struct au_opt_del *del;
21558 + struct au_opt_mod *mod;
21559 + struct au_opt_xino *xino;
21560 + struct au_opt_xino_itrunc *xino_itrunc;
21561 + struct au_opt_wbr_create *create;
21563 + struct au_opt *opt;
21566 + while (opt->type != Opt_tail) {
21567 + switch (opt->type) {
21569 + u.add = &opt->add;
21570 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
21571 + u.add->bindex, u.add->pathname, u.add->perm,
21572 + u.add->path.dentry);
21576 + u.del = &opt->del;
21577 + AuDbg("del {%s, %p}\n",
21578 + u.del->pathname, u.del->h_path.dentry);
21582 + u.mod = &opt->mod;
21583 + AuDbg("mod {%s, 0x%x, %p}\n",
21584 + u.mod->path, u.mod->perm, u.mod->h_root);
21587 + u.add = &opt->add;
21588 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
21589 + u.add->bindex, u.add->pathname, u.add->perm,
21590 + u.add->path.dentry);
21592 + case Opt_prepend:
21593 + u.add = &opt->add;
21594 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
21595 + u.add->bindex, u.add->pathname, u.add->perm,
21596 + u.add->path.dentry);
21599 + AuDbg("dirwh %d\n", opt->dirwh);
21601 + case Opt_rdcache:
21602 + AuDbg("rdcache %d\n", opt->rdcache);
21605 + AuDbg("rdblk %u\n", opt->rdblk);
21607 + case Opt_rdblk_def:
21608 + AuDbg("rdblk_def\n");
21611 + AuDbg("rdhash %u\n", opt->rdhash);
21613 + case Opt_rdhash_def:
21614 + AuDbg("rdhash_def\n");
21617 + u.xino = &opt->xino;
21618 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
21620 + case Opt_trunc_xino:
21621 + AuLabel(trunc_xino);
21623 + case Opt_notrunc_xino:
21624 + AuLabel(notrunc_xino);
21626 + case Opt_trunc_xino_path:
21627 + case Opt_itrunc_xino:
21628 + u.xino_itrunc = &opt->xino_itrunc;
21629 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
21635 + case Opt_trunc_xib:
21636 + AuLabel(trunc_xib);
21638 + case Opt_notrunc_xib:
21639 + AuLabel(notrunc_xib);
21650 + case Opt_noplink:
21651 + AuLabel(noplink);
21653 + case Opt_list_plink:
21654 + AuLabel(list_plink);
21657 + AuDbg("udba %d, %s\n",
21658 + opt->udba, au_optstr_udba(opt->udba));
21666 + case Opt_diropq_a:
21667 + AuLabel(diropq_a);
21669 + case Opt_diropq_w:
21670 + AuLabel(diropq_w);
21672 + case Opt_warn_perm:
21673 + AuLabel(warn_perm);
21675 + case Opt_nowarn_perm:
21676 + AuLabel(nowarn_perm);
21681 + case Opt_norefrof:
21682 + AuLabel(norefrof);
21684 + case Opt_verbose:
21685 + AuLabel(verbose);
21687 + case Opt_noverbose:
21688 + AuLabel(noverbose);
21699 + case Opt_wbr_create:
21700 + u.create = &opt->wbr_create;
21701 + AuDbg("create %d, %s\n", u.create->wbr_create,
21702 + au_optstr_wbr_create(u.create->wbr_create));
21703 + switch (u.create->wbr_create) {
21704 + case AuWbrCreate_MFSV:
21705 + case AuWbrCreate_PMFSV:
21706 + AuDbg("%d sec\n", u.create->mfs_second);
21708 + case AuWbrCreate_MFSRR:
21709 + AuDbg("%llu watermark\n",
21710 + u.create->mfsrr_watermark);
21712 + case AuWbrCreate_MFSRRV:
21713 + case AuWbrCreate_PMFSRRV:
21714 + AuDbg("%llu watermark, %d sec\n",
21715 + u.create->mfsrr_watermark,
21716 + u.create->mfs_second);
21720 + case Opt_wbr_copyup:
21721 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
21722 + au_optstr_wbr_copyup(opt->wbr_copyup));
21732 +void au_opts_free(struct au_opts *opts)
21734 + struct au_opt *opt;
21737 + while (opt->type != Opt_tail) {
21738 + switch (opt->type) {
21741 + case Opt_prepend:
21742 + path_put(&opt->add.path);
21746 + path_put(&opt->del.h_path);
21750 + dput(opt->mod.h_root);
21753 + fput(opt->xino.file);
21760 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
21761 + aufs_bindex_t bindex)
21764 + struct au_opt_add *add = &opt->add;
21767 + add->bindex = bindex;
21768 + add->perm = AuBrPerm_RO;
21769 + add->pathname = opt_str;
21770 + p = strchr(opt_str, '=');
21774 + add->perm = br_perm_val(p);
21777 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
21780 + add->perm = AuBrPerm_RO;
21781 + if (au_test_fs_rr(add->path.dentry->d_sb))
21782 + add->perm = AuBrPerm_RR;
21783 + else if (!bindex && !(sb_flags & MS_RDONLY))
21784 + add->perm = AuBrPerm_RW;
21786 + opt->type = Opt_add;
21789 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
21796 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
21800 + del->pathname = args[0].from;
21801 + AuDbg("del path %s\n", del->pathname);
21803 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
21804 + if (unlikely(err))
21805 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
21810 +#if 0 /* reserved for future use */
21811 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
21812 + struct au_opt_del *del, substring_t args[])
21815 + struct dentry *root;
21818 + root = sb->s_root;
21819 + aufs_read_lock(root, AuLock_FLUSH);
21820 + if (bindex < 0 || au_sbend(sb) < bindex) {
21821 + pr_err("out of bounds, %d\n", bindex);
21826 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
21827 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
21830 + aufs_read_unlock(root, !AuLock_IR);
21835 +static int noinline_for_stack
21836 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
21839 + struct path path;
21843 + mod->path = args[0].from;
21844 + p = strchr(mod->path, '=');
21845 + if (unlikely(!p)) {
21846 + pr_err("no permssion %s\n", args[0].from);
21851 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
21852 + if (unlikely(err)) {
21853 + pr_err("lookup failed %s (%d)\n", mod->path, err);
21857 + mod->perm = br_perm_val(p);
21858 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
21859 + mod->h_root = dget(path.dentry);
21866 +#if 0 /* reserved for future use */
21867 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
21868 + struct au_opt_mod *mod, substring_t args[])
21871 + struct dentry *root;
21874 + root = sb->s_root;
21875 + aufs_read_lock(root, AuLock_FLUSH);
21876 + if (bindex < 0 || au_sbend(sb) < bindex) {
21877 + pr_err("out of bounds, %d\n", bindex);
21882 + mod->perm = br_perm_val(args[1].from);
21883 + AuDbg("mod path %s, perm 0x%x, %s\n",
21884 + mod->path, mod->perm, args[1].from);
21885 + mod->h_root = dget(au_h_dptr(root, bindex));
21888 + aufs_read_unlock(root, !AuLock_IR);
21893 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
21894 + substring_t args[])
21897 + struct file *file;
21899 + file = au_xino_create(sb, args[0].from, /*silent*/0);
21900 + err = PTR_ERR(file);
21901 + if (IS_ERR(file))
21905 + if (unlikely(file->f_dentry->d_sb == sb)) {
21907 + pr_err("%s must be outside\n", args[0].from);
21912 + xino->file = file;
21913 + xino->path = args[0].from;
21919 +static int noinline_for_stack
21920 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
21921 + struct au_opt_xino_itrunc *xino_itrunc,
21922 + substring_t args[])
21925 + aufs_bindex_t bend, bindex;
21926 + struct path path;
21927 + struct dentry *root;
21929 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
21930 + if (unlikely(err)) {
21931 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
21935 + xino_itrunc->bindex = -1;
21936 + root = sb->s_root;
21937 + aufs_read_lock(root, AuLock_FLUSH);
21938 + bend = au_sbend(sb);
21939 + for (bindex = 0; bindex <= bend; bindex++) {
21940 + if (au_h_dptr(root, bindex) == path.dentry) {
21941 + xino_itrunc->bindex = bindex;
21945 + aufs_read_unlock(root, !AuLock_IR);
21948 + if (unlikely(xino_itrunc->bindex < 0)) {
21949 + pr_err("no such branch %s\n", args[0].from);
21957 +/* called without aufs lock */
21958 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
21960 + int err, n, token;
21961 + aufs_bindex_t bindex;
21962 + unsigned char skipped;
21963 + struct dentry *root;
21964 + struct au_opt *opt, *opt_tail;
21966 + /* reduce the stack space */
21968 + struct au_opt_xino_itrunc *xino_itrunc;
21969 + struct au_opt_wbr_create *create;
21972 + substring_t args[MAX_OPT_ARGS];
21976 + a = kmalloc(sizeof(*a), GFP_NOFS);
21977 + if (unlikely(!a))
21980 + root = sb->s_root;
21984 + opt_tail = opt + opts->max_opt - 1;
21985 + opt->type = Opt_tail;
21986 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
21989 + token = match_token(opt_str, options, a->args);
21993 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
21995 + err = opt_add(opt, opt_str, opts->sb_flags,
21997 + if (unlikely(!err && ++opt > opt_tail)) {
22001 + opt->type = Opt_tail;
22006 + if (unlikely(match_int(&a->args[0], &n))) {
22007 + pr_err("bad integer in %s\n", opt_str);
22011 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
22014 + opt->type = token;
22017 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
22018 + /*dummy bindex*/1);
22020 + opt->type = token;
22022 + case Opt_prepend:
22023 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
22026 + opt->type = token;
22029 + err = au_opts_parse_del(&opt->del, a->args);
22031 + opt->type = token;
22033 +#if 0 /* reserved for future use */
22035 + del->pathname = "(indexed)";
22036 + if (unlikely(match_int(&args[0], &n))) {
22037 + pr_err("bad integer in %s\n", opt_str);
22040 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
22042 + opt->type = token;
22046 + err = au_opts_parse_mod(&opt->mod, a->args);
22048 + opt->type = token;
22050 +#ifdef IMOD /* reserved for future use */
22052 + u.mod->path = "(indexed)";
22053 + if (unlikely(match_int(&a->args[0], &n))) {
22054 + pr_err("bad integer in %s\n", opt_str);
22057 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
22059 + opt->type = token;
22063 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
22065 + opt->type = token;
22068 + case Opt_trunc_xino_path:
22069 + err = au_opts_parse_xino_itrunc_path
22070 + (sb, &opt->xino_itrunc, a->args);
22072 + opt->type = token;
22075 + case Opt_itrunc_xino:
22076 + u.xino_itrunc = &opt->xino_itrunc;
22077 + if (unlikely(match_int(&a->args[0], &n))) {
22078 + pr_err("bad integer in %s\n", opt_str);
22081 + u.xino_itrunc->bindex = n;
22082 + aufs_read_lock(root, AuLock_FLUSH);
22083 + if (n < 0 || au_sbend(sb) < n) {
22084 + pr_err("out of bounds, %d\n", n);
22085 + aufs_read_unlock(root, !AuLock_IR);
22088 + aufs_read_unlock(root, !AuLock_IR);
22090 + opt->type = token;
22094 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
22097 + opt->type = token;
22100 + case Opt_rdcache:
22101 + if (unlikely(match_int(&a->args[0], &n))) {
22102 + pr_err("bad integer in %s\n", opt_str);
22105 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
22106 + pr_err("rdcache must be smaller than %d\n",
22107 + AUFS_RDCACHE_MAX);
22110 + opt->rdcache = n;
22112 + opt->type = token;
22115 + if (unlikely(match_int(&a->args[0], &n)
22117 + || n > KMALLOC_MAX_SIZE)) {
22118 + pr_err("bad integer in %s\n", opt_str);
22121 + if (unlikely(n && n < NAME_MAX)) {
22122 + pr_err("rdblk must be larger than %d\n",
22128 + opt->type = token;
22131 + if (unlikely(match_int(&a->args[0], &n)
22133 + || n * sizeof(struct hlist_head)
22134 + > KMALLOC_MAX_SIZE)) {
22135 + pr_err("bad integer in %s\n", opt_str);
22140 + opt->type = token;
22143 + case Opt_trunc_xino:
22144 + case Opt_notrunc_xino:
22146 + case Opt_trunc_xib:
22147 + case Opt_notrunc_xib:
22151 + case Opt_noplink:
22152 + case Opt_list_plink:
22155 + case Opt_diropq_a:
22156 + case Opt_diropq_w:
22157 + case Opt_warn_perm:
22158 + case Opt_nowarn_perm:
22160 + case Opt_norefrof:
22161 + case Opt_verbose:
22162 + case Opt_noverbose:
22166 + case Opt_rdblk_def:
22167 + case Opt_rdhash_def:
22169 + opt->type = token;
22173 + opt->udba = udba_val(a->args[0].from);
22174 + if (opt->udba >= 0) {
22176 + opt->type = token;
22178 + pr_err("wrong value, %s\n", opt_str);
22181 + case Opt_wbr_create:
22182 + u.create = &opt->wbr_create;
22183 + u.create->wbr_create
22184 + = au_wbr_create_val(a->args[0].from, u.create);
22185 + if (u.create->wbr_create >= 0) {
22187 + opt->type = token;
22189 + pr_err("wrong value, %s\n", opt_str);
22191 + case Opt_wbr_copyup:
22192 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
22193 + if (opt->wbr_copyup >= 0) {
22195 + opt->type = token;
22197 + pr_err("wrong value, %s\n", opt_str);
22201 + pr_warn("ignored %s\n", opt_str);
22203 + case Opt_ignore_silent:
22208 + pr_err("unknown option %s\n", opt_str);
22212 + if (!err && !skipped) {
22213 + if (unlikely(++opt > opt_tail)) {
22216 + opt->type = Opt_tail;
22219 + opt->type = Opt_tail;
22225 + if (unlikely(err))
22226 + au_opts_free(opts);
22232 +static int au_opt_wbr_create(struct super_block *sb,
22233 + struct au_opt_wbr_create *create)
22236 + struct au_sbinfo *sbinfo;
22238 + SiMustWriteLock(sb);
22240 + err = 1; /* handled */
22241 + sbinfo = au_sbi(sb);
22242 + if (sbinfo->si_wbr_create_ops->fin) {
22243 + err = sbinfo->si_wbr_create_ops->fin(sb);
22248 + sbinfo->si_wbr_create = create->wbr_create;
22249 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
22250 + switch (create->wbr_create) {
22251 + case AuWbrCreate_MFSRRV:
22252 + case AuWbrCreate_MFSRR:
22253 + case AuWbrCreate_PMFSRR:
22254 + case AuWbrCreate_PMFSRRV:
22255 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
22257 + case AuWbrCreate_MFS:
22258 + case AuWbrCreate_MFSV:
22259 + case AuWbrCreate_PMFS:
22260 + case AuWbrCreate_PMFSV:
22261 + sbinfo->si_wbr_mfs.mfs_expire
22262 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
22266 + if (sbinfo->si_wbr_create_ops->init)
22267 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
22274 + * plus: processed without an error
22275 + * zero: unprocessed
22277 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
22278 + struct au_opts *opts)
22281 + struct au_sbinfo *sbinfo;
22283 + SiMustWriteLock(sb);
22285 + err = 1; /* handled */
22286 + sbinfo = au_sbi(sb);
22287 + switch (opt->type) {
22289 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
22290 + sbinfo->si_mntflags |= opt->udba;
22291 + opts->given_udba |= opt->udba;
22295 + au_opt_set(sbinfo->si_mntflags, PLINK);
22297 + case Opt_noplink:
22298 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
22299 + au_plink_put(sb, /*verbose*/1);
22300 + au_opt_clr(sbinfo->si_mntflags, PLINK);
22302 + case Opt_list_plink:
22303 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
22304 + au_plink_list(sb);
22308 + au_opt_set(sbinfo->si_mntflags, DIO);
22309 + au_fset_opts(opts->flags, REFRESH_DYAOP);
22312 + au_opt_clr(sbinfo->si_mntflags, DIO);
22313 + au_fset_opts(opts->flags, REFRESH_DYAOP);
22316 + case Opt_diropq_a:
22317 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
22319 + case Opt_diropq_w:
22320 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
22323 + case Opt_warn_perm:
22324 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
22326 + case Opt_nowarn_perm:
22327 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
22331 + au_opt_set(sbinfo->si_mntflags, REFROF);
22333 + case Opt_norefrof:
22334 + au_opt_clr(sbinfo->si_mntflags, REFROF);
22337 + case Opt_verbose:
22338 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
22340 + case Opt_noverbose:
22341 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
22345 + au_opt_set(sbinfo->si_mntflags, SUM);
22348 + au_opt_clr(sbinfo->si_mntflags, SUM);
22349 + au_opt_set(sbinfo->si_mntflags, SUM_W);
22351 + au_opt_clr(sbinfo->si_mntflags, SUM);
22352 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
22355 + case Opt_wbr_create:
22356 + err = au_opt_wbr_create(sb, &opt->wbr_create);
22358 + case Opt_wbr_copyup:
22359 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
22360 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
22364 + sbinfo->si_dirwh = opt->dirwh;
22367 + case Opt_rdcache:
22368 + sbinfo->si_rdcache
22369 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
22372 + sbinfo->si_rdblk = opt->rdblk;
22374 + case Opt_rdblk_def:
22375 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
22378 + sbinfo->si_rdhash = opt->rdhash;
22380 + case Opt_rdhash_def:
22381 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
22385 + au_opt_set(sbinfo->si_mntflags, SHWH);
22388 + au_opt_clr(sbinfo->si_mntflags, SHWH);
22391 + case Opt_trunc_xino:
22392 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
22394 + case Opt_notrunc_xino:
22395 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
22398 + case Opt_trunc_xino_path:
22399 + case Opt_itrunc_xino:
22400 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
22405 + case Opt_trunc_xib:
22406 + au_fset_opts(opts->flags, TRUNC_XIB);
22408 + case Opt_notrunc_xib:
22409 + au_fclr_opts(opts->flags, TRUNC_XIB);
22421 + * returns tri-state.
22422 + * plus: processed without an error
22423 + * zero: unprocessed
22426 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
22427 + struct au_opts *opts)
22429 + int err, do_refresh;
22432 + switch (opt->type) {
22434 + opt->add.bindex = au_sbend(sb) + 1;
22435 + if (opt->add.bindex < 0)
22436 + opt->add.bindex = 0;
22438 + case Opt_prepend:
22439 + opt->add.bindex = 0;
22440 + add: /* indented label */
22442 + err = au_br_add(sb, &opt->add,
22443 + au_ftest_opts(opts->flags, REMOUNT));
22446 + au_fset_opts(opts->flags, REFRESH);
22452 + err = au_br_del(sb, &opt->del,
22453 + au_ftest_opts(opts->flags, REMOUNT));
22456 + au_fset_opts(opts->flags, TRUNC_XIB);
22457 + au_fset_opts(opts->flags, REFRESH);
22463 + err = au_br_mod(sb, &opt->mod,
22464 + au_ftest_opts(opts->flags, REMOUNT),
22469 + au_fset_opts(opts->flags, REFRESH);
22477 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
22478 + struct au_opt_xino **opt_xino,
22479 + struct au_opts *opts)
22482 + aufs_bindex_t bend, bindex;
22483 + struct dentry *root, *parent, *h_root;
22486 + switch (opt->type) {
22488 + err = au_xino_set(sb, &opt->xino,
22489 + !!au_ftest_opts(opts->flags, REMOUNT));
22490 + if (unlikely(err))
22493 + *opt_xino = &opt->xino;
22494 + au_xino_brid_set(sb, -1);
22496 + /* safe d_parent access */
22497 + parent = opt->xino.file->f_dentry->d_parent;
22498 + root = sb->s_root;
22499 + bend = au_sbend(sb);
22500 + for (bindex = 0; bindex <= bend; bindex++) {
22501 + h_root = au_h_dptr(root, bindex);
22502 + if (h_root == parent) {
22503 + au_xino_brid_set(sb, au_sbr_id(sb, bindex));
22511 + au_xino_brid_set(sb, -1);
22512 + *opt_xino = (void *)-1;
22519 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
22520 + unsigned int pending)
22523 + aufs_bindex_t bindex, bend;
22524 + unsigned char do_plink, skip, do_free;
22525 + struct au_branch *br;
22526 + struct au_wbr *wbr;
22527 + struct dentry *root;
22528 + struct inode *dir, *h_dir;
22529 + struct au_sbinfo *sbinfo;
22530 + struct au_hinode *hdir;
22532 + SiMustAnyLock(sb);
22534 + sbinfo = au_sbi(sb);
22535 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
22537 + if (!(sb_flags & MS_RDONLY)) {
22538 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
22539 + pr_warn("first branch should be rw\n");
22540 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
22541 + pr_warn("shwh should be used with ro\n");
22544 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
22545 + && !au_opt_test(sbinfo->si_mntflags, XINO))
22546 + pr_warn("udba=*notify requires xino\n");
22549 + root = sb->s_root;
22550 + dir = root->d_inode;
22551 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
22552 + bend = au_sbend(sb);
22553 + for (bindex = 0; !err && bindex <= bend; bindex++) {
22555 + h_dir = au_h_iptr(dir, bindex);
22556 + br = au_sbr(sb, bindex);
22559 + wbr = br->br_wbr;
22561 + wbr_wh_read_lock(wbr);
22563 + if (!au_br_writable(br->br_perm)) {
22566 + || (!wbr->wbr_whbase
22567 + && !wbr->wbr_plink
22568 + && !wbr->wbr_orph));
22569 + } else if (!au_br_wh_linkable(br->br_perm)) {
22570 + /* skip = (!br->br_whbase && !br->br_orph); */
22571 + skip = (!wbr || !wbr->wbr_whbase);
22572 + if (skip && wbr) {
22574 + skip = !!wbr->wbr_plink;
22576 + skip = !wbr->wbr_plink;
22579 + /* skip = (br->br_whbase && br->br_ohph); */
22580 + skip = (wbr && wbr->wbr_whbase);
22583 + skip = !!wbr->wbr_plink;
22585 + skip = !wbr->wbr_plink;
22589 + wbr_wh_read_unlock(wbr);
22594 + hdir = au_hi(dir, bindex);
22595 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
22597 + wbr_wh_write_lock(wbr);
22598 + err = au_wh_init(br, sb);
22600 + wbr_wh_write_unlock(wbr);
22601 + au_hn_imtx_unlock(hdir);
22603 + if (!err && do_free) {
22605 + br->br_wbr = NULL;
22612 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
22615 + unsigned int tmp;
22616 + aufs_bindex_t bindex, bend;
22617 + struct au_opt *opt;
22618 + struct au_opt_xino *opt_xino, xino;
22619 + struct au_sbinfo *sbinfo;
22620 + struct au_branch *br;
22622 + SiMustWriteLock(sb);
22627 + while (err >= 0 && opt->type != Opt_tail)
22628 + err = au_opt_simple(sb, opt++, opts);
22631 + else if (unlikely(err < 0))
22634 + /* disable xino and udba temporary */
22635 + sbinfo = au_sbi(sb);
22636 + tmp = sbinfo->si_mntflags;
22637 + au_opt_clr(sbinfo->si_mntflags, XINO);
22638 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
22641 + while (err >= 0 && opt->type != Opt_tail)
22642 + err = au_opt_br(sb, opt++, opts);
22645 + else if (unlikely(err < 0))
22648 + bend = au_sbend(sb);
22649 + if (unlikely(bend < 0)) {
22651 + pr_err("no branches\n");
22655 + if (au_opt_test(tmp, XINO))
22656 + au_opt_set(sbinfo->si_mntflags, XINO);
22658 + while (!err && opt->type != Opt_tail)
22659 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
22660 + if (unlikely(err))
22663 + err = au_opts_verify(sb, sb->s_flags, tmp);
22664 + if (unlikely(err))
22667 + /* restore xino */
22668 + if (au_opt_test(tmp, XINO) && !opt_xino) {
22669 + xino.file = au_xino_def(sb);
22670 + err = PTR_ERR(xino.file);
22671 + if (IS_ERR(xino.file))
22674 + err = au_xino_set(sb, &xino, /*remount*/0);
22676 + if (unlikely(err))
22680 + /* restore udba */
22681 + tmp &= AuOptMask_UDBA;
22682 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
22683 + sbinfo->si_mntflags |= tmp;
22684 + bend = au_sbend(sb);
22685 + for (bindex = 0; bindex <= bend; bindex++) {
22686 + br = au_sbr(sb, bindex);
22687 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
22688 + if (unlikely(err))
22689 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
22691 + /* go on even if err */
22693 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
22694 + struct inode *dir = sb->s_root->d_inode;
22695 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
22702 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
22705 + struct inode *dir;
22706 + struct au_opt_xino *opt_xino;
22707 + struct au_opt *opt;
22708 + struct au_sbinfo *sbinfo;
22710 + SiMustWriteLock(sb);
22712 + dir = sb->s_root->d_inode;
22713 + sbinfo = au_sbi(sb);
22717 + while (err >= 0 && opt->type != Opt_tail) {
22718 + err = au_opt_simple(sb, opt, opts);
22720 + err = au_opt_br(sb, opt, opts);
22722 + err = au_opt_xino(sb, opt, &opt_xino, opts);
22728 + /* go on even err */
22730 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
22731 + if (unlikely(rerr && !err))
22734 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
22735 + rerr = au_xib_trunc(sb);
22736 + if (unlikely(rerr && !err))
22740 + /* will be handled by the caller */
22741 + if (!au_ftest_opts(opts->flags, REFRESH)
22742 + && (opts->given_udba || au_opt_test(sbinfo->si_mntflags, XINO)))
22743 + au_fset_opts(opts->flags, REFRESH);
22745 + AuDbg("status 0x%x\n", opts->flags);
22749 +/* ---------------------------------------------------------------------- */
22751 +unsigned int au_opt_udba(struct super_block *sb)
22753 + return au_mntflags(sb) & AuOptMask_UDBA;
22755 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
22756 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
22757 +++ linux/fs/aufs/opts.h 2014-04-24 22:11:10.855269116 +0200
22760 + * Copyright (C) 2005-2014 Junjiro R. Okajima
22762 + * This program, aufs is free software; you can redistribute it and/or modify
22763 + * it under the terms of the GNU General Public License as published by
22764 + * the Free Software Foundation; either version 2 of the License, or
22765 + * (at your option) any later version.
22767 + * This program is distributed in the hope that it will be useful,
22768 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22769 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22770 + * GNU General Public License for more details.
22772 + * You should have received a copy of the GNU General Public License
22773 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22777 + * mount options/flags
22780 +#ifndef __AUFS_OPTS_H__
22781 +#define __AUFS_OPTS_H__
22785 +#include <linux/path.h>
22788 +struct super_block;
22790 +/* ---------------------------------------------------------------------- */
22793 +#define AuOpt_XINO 1 /* external inode number bitmap
22794 + and translation table */
22795 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
22796 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
22797 +#define AuOpt_UDBA_REVAL (1 << 3)
22798 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
22799 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
22800 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
22801 +#define AuOpt_DIRPERM1 (1 << 7) /* unimplemented */
22802 +#define AuOpt_REFROF (1 << 8) /* unimplemented */
22803 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
22804 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
22805 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
22806 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
22807 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
22808 +#define AuOpt_DIO (1 << 14) /* direct io */
22810 +#ifndef CONFIG_AUFS_HNOTIFY
22811 +#undef AuOpt_UDBA_HNOTIFY
22812 +#define AuOpt_UDBA_HNOTIFY 0
22814 +#ifndef CONFIG_AUFS_SHWH
22816 +#define AuOpt_SHWH 0
22819 +#define AuOpt_Def (AuOpt_XINO \
22820 + | AuOpt_UDBA_REVAL \
22822 + /* | AuOpt_DIRPERM1 */ \
22823 + | AuOpt_WARN_PERM)
22824 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
22825 + | AuOpt_UDBA_REVAL \
22826 + | AuOpt_UDBA_HNOTIFY)
22828 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
22829 +#define au_opt_set(flags, name) do { \
22830 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
22831 + ((flags) |= AuOpt_##name); \
22833 +#define au_opt_set_udba(flags, name) do { \
22834 + (flags) &= ~AuOptMask_UDBA; \
22835 + ((flags) |= AuOpt_##name); \
22837 +#define au_opt_clr(flags, name) do { \
22838 + ((flags) &= ~AuOpt_##name); \
22841 +static inline unsigned int au_opts_plink(unsigned int mntflags)
22843 +#ifdef CONFIG_PROC_FS
22846 + return mntflags & ~AuOpt_PLINK;
22850 +/* ---------------------------------------------------------------------- */
22852 +/* policies to select one among multiple writable branches */
22854 + AuWbrCreate_TDP, /* top down parent */
22855 + AuWbrCreate_RR, /* round robin */
22856 + AuWbrCreate_MFS, /* most free space */
22857 + AuWbrCreate_MFSV, /* mfs with seconds */
22858 + AuWbrCreate_MFSRR, /* mfs then rr */
22859 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
22860 + AuWbrCreate_PMFS, /* parent and mfs */
22861 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
22862 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
22863 + AuWbrCreate_PMFSRRV, /* plus seconds */
22865 + AuWbrCreate_Def = AuWbrCreate_TDP
22869 + AuWbrCopyup_TDP, /* top down parent */
22870 + AuWbrCopyup_BUP, /* bottom up parent */
22871 + AuWbrCopyup_BU, /* bottom up */
22873 + AuWbrCopyup_Def = AuWbrCopyup_TDP
22876 +/* ---------------------------------------------------------------------- */
22878 +struct au_opt_add {
22879 + aufs_bindex_t bindex;
22882 + struct path path;
22885 +struct au_opt_del {
22887 + struct path h_path;
22890 +struct au_opt_mod {
22893 + struct dentry *h_root;
22896 +struct au_opt_xino {
22898 + struct file *file;
22901 +struct au_opt_xino_itrunc {
22902 + aufs_bindex_t bindex;
22905 +struct au_opt_wbr_create {
22908 + unsigned long long mfsrr_watermark;
22914 + struct au_opt_xino xino;
22915 + struct au_opt_xino_itrunc xino_itrunc;
22916 + struct au_opt_add add;
22917 + struct au_opt_del del;
22918 + struct au_opt_mod mod;
22921 + unsigned int rdblk;
22922 + unsigned int rdhash;
22924 + struct au_opt_wbr_create wbr_create;
22930 +#define AuOpts_REMOUNT 1
22931 +#define AuOpts_REFRESH (1 << 1)
22932 +#define AuOpts_TRUNC_XIB (1 << 2)
22933 +#define AuOpts_REFRESH_DYAOP (1 << 3)
22934 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
22935 +#define au_fset_opts(flags, name) \
22936 + do { (flags) |= AuOpts_##name; } while (0)
22937 +#define au_fclr_opts(flags, name) \
22938 + do { (flags) &= ~AuOpts_##name; } while (0)
22941 + struct au_opt *opt;
22944 + unsigned int given_udba;
22945 + unsigned int flags;
22946 + unsigned long sb_flags;
22949 +/* ---------------------------------------------------------------------- */
22951 +char *au_optstr_br_perm(int brperm);
22952 +const char *au_optstr_udba(int udba);
22953 +const char *au_optstr_wbr_copyup(int wbr_copyup);
22954 +const char *au_optstr_wbr_create(int wbr_create);
22956 +void au_opts_free(struct au_opts *opts);
22957 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
22958 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
22959 + unsigned int pending);
22960 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
22961 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
22963 +unsigned int au_opt_udba(struct super_block *sb);
22965 +/* ---------------------------------------------------------------------- */
22967 +#endif /* __KERNEL__ */
22968 +#endif /* __AUFS_OPTS_H__ */
22969 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
22970 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
22971 +++ linux/fs/aufs/plink.c 2014-04-24 22:11:10.855269116 +0200
22974 + * Copyright (C) 2005-2014 Junjiro R. Okajima
22976 + * This program, aufs is free software; you can redistribute it and/or modify
22977 + * it under the terms of the GNU General Public License as published by
22978 + * the Free Software Foundation; either version 2 of the License, or
22979 + * (at your option) any later version.
22981 + * This program is distributed in the hope that it will be useful,
22982 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22983 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22984 + * GNU General Public License for more details.
22986 + * You should have received a copy of the GNU General Public License
22987 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22997 + * the pseudo-link maintenance mode.
22998 + * during a user process maintains the pseudo-links,
22999 + * prohibit adding a new plink and branch manipulation.
23003 + * For entry functions which will handle plink, and i_mutex is already held
23005 + * They cannot wait and should return an error at once.
23006 + * Callers has to check the error.
23008 + * For entry functions which will handle plink, but i_mutex is not held
23010 + * They can wait the plink maintenance mode to finish.
23012 + * They behave like F_SETLK and F_SETLKW.
23013 + * If the caller never handle plink, then both flags are unnecessary.
23016 +int au_plink_maint(struct super_block *sb, int flags)
23020 + struct au_sbinfo *sbi;
23022 + SiMustAnyLock(sb);
23025 + if (!au_opt_test(au_mntflags(sb), PLINK))
23028 + sbi = au_sbi(sb);
23029 + pid = sbi->si_plink_maint_pid;
23030 + if (!pid || pid == current->pid)
23033 + /* todo: it highly depends upon /sbin/mount.aufs */
23035 + ppid = task_pid_vnr(rcu_dereference(current->real_parent));
23036 + rcu_read_unlock();
23040 + if (au_ftest_lock(flags, NOPLMW)) {
23041 + /* if there is no i_mutex lock in VFS, we don't need to wait */
23042 + /* AuDebugOn(!lockdep_depth(current)); */
23043 + while (sbi->si_plink_maint_pid) {
23044 + si_read_unlock(sb);
23045 + /* gave up wake_up_bit() */
23046 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
23048 + if (au_ftest_lock(flags, FLUSH))
23049 + au_nwt_flush(&sbi->si_nowait);
23050 + si_noflush_read_lock(sb);
23052 + } else if (au_ftest_lock(flags, NOPLM)) {
23053 + AuDbg("ppid %d, pid %d\n", ppid, pid);
23061 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
23063 + spin_lock(&sbinfo->si_plink_maint_lock);
23064 + sbinfo->si_plink_maint_pid = 0;
23065 + spin_unlock(&sbinfo->si_plink_maint_lock);
23066 + wake_up_all(&sbinfo->si_plink_wq);
23069 +int au_plink_maint_enter(struct super_block *sb)
23072 + struct au_sbinfo *sbinfo;
23075 + sbinfo = au_sbi(sb);
23076 + /* make sure i am the only one in this fs */
23077 + si_write_lock(sb, AuLock_FLUSH);
23078 + if (au_opt_test(au_mntflags(sb), PLINK)) {
23079 + spin_lock(&sbinfo->si_plink_maint_lock);
23080 + if (!sbinfo->si_plink_maint_pid)
23081 + sbinfo->si_plink_maint_pid = current->pid;
23084 + spin_unlock(&sbinfo->si_plink_maint_lock);
23086 + si_write_unlock(sb);
23091 +/* ---------------------------------------------------------------------- */
23093 +#ifdef CONFIG_AUFS_DEBUG
23094 +void au_plink_list(struct super_block *sb)
23097 + struct au_sbinfo *sbinfo;
23098 + struct hlist_head *plink_hlist;
23099 + struct pseudo_link *plink;
23101 + SiMustAnyLock(sb);
23103 + sbinfo = au_sbi(sb);
23104 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
23105 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
23107 + for (i = 0; i < AuPlink_NHASH; i++) {
23108 + plink_hlist = &sbinfo->si_plink[i].head;
23110 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
23111 + AuDbg("%lu\n", plink->inode->i_ino);
23112 + rcu_read_unlock();
23117 +/* is the inode pseudo-linked? */
23118 +int au_plink_test(struct inode *inode)
23121 + struct au_sbinfo *sbinfo;
23122 + struct hlist_head *plink_hlist;
23123 + struct pseudo_link *plink;
23125 + sbinfo = au_sbi(inode->i_sb);
23126 + AuRwMustAnyLock(&sbinfo->si_rwsem);
23127 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
23128 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
23131 + i = au_plink_hash(inode->i_ino);
23132 + plink_hlist = &sbinfo->si_plink[i].head;
23134 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
23135 + if (plink->inode == inode) {
23139 + rcu_read_unlock();
23143 +/* ---------------------------------------------------------------------- */
23146 + * generate a name for plink.
23147 + * the file will be stored under AUFS_WH_PLINKDIR.
23149 +/* 20 is max digits length of ulong 64 */
23150 +#define PLINK_NAME_LEN ((20 + 1) * 2)
23152 +static int plink_name(char *name, int len, struct inode *inode,
23153 + aufs_bindex_t bindex)
23156 + struct inode *h_inode;
23158 + h_inode = au_h_iptr(inode, bindex);
23159 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
23163 +struct au_do_plink_lkup_args {
23164 + struct dentry **errp;
23165 + struct qstr *tgtname;
23166 + struct dentry *h_parent;
23167 + struct au_branch *br;
23170 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
23171 + struct dentry *h_parent,
23172 + struct au_branch *br)
23174 + struct dentry *h_dentry;
23175 + struct mutex *h_mtx;
23177 + h_mtx = &h_parent->d_inode->i_mutex;
23178 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
23179 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
23180 + mutex_unlock(h_mtx);
23184 +static void au_call_do_plink_lkup(void *args)
23186 + struct au_do_plink_lkup_args *a = args;
23187 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
23190 +/* lookup the plink-ed @inode under the branch at @bindex */
23191 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
23193 + struct dentry *h_dentry, *h_parent;
23194 + struct au_branch *br;
23195 + struct inode *h_dir;
23197 + char a[PLINK_NAME_LEN];
23198 + struct qstr tgtname = QSTR_INIT(a, 0);
23200 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
23202 + br = au_sbr(inode->i_sb, bindex);
23203 + h_parent = br->br_wbr->wbr_plink;
23204 + h_dir = h_parent->d_inode;
23205 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
23207 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
23208 + struct au_do_plink_lkup_args args = {
23209 + .errp = &h_dentry,
23210 + .tgtname = &tgtname,
23211 + .h_parent = h_parent,
23215 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
23216 + if (unlikely(wkq_err))
23217 + h_dentry = ERR_PTR(wkq_err);
23219 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
23224 +/* create a pseudo-link */
23225 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
23226 + struct dentry *h_dentry, struct au_branch *br)
23229 + struct path h_path = {
23230 + .mnt = au_br_mnt(br)
23232 + struct inode *h_dir, *delegated;
23234 + h_dir = h_parent->d_inode;
23235 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_CHILD2);
23237 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
23238 + err = PTR_ERR(h_path.dentry);
23239 + if (IS_ERR(h_path.dentry))
23243 + /* wh.plink dir is not monitored */
23244 + /* todo: is it really safe? */
23245 + if (h_path.dentry->d_inode
23246 + && h_path.dentry->d_inode != h_dentry->d_inode) {
23247 + delegated = NULL;
23248 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
23249 + if (unlikely(err == -EWOULDBLOCK)) {
23250 + pr_warn("cannot retry for NFSv4 delegation"
23251 + " for an internal unlink\n");
23254 + dput(h_path.dentry);
23255 + h_path.dentry = NULL;
23259 + if (!err && !h_path.dentry->d_inode) {
23260 + delegated = NULL;
23261 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
23262 + if (unlikely(err == -EWOULDBLOCK)) {
23263 + pr_warn("cannot retry for NFSv4 delegation"
23264 + " for an internal link\n");
23268 + dput(h_path.dentry);
23271 + mutex_unlock(&h_dir->i_mutex);
23275 +struct do_whplink_args {
23277 + struct qstr *tgt;
23278 + struct dentry *h_parent;
23279 + struct dentry *h_dentry;
23280 + struct au_branch *br;
23283 +static void call_do_whplink(void *args)
23285 + struct do_whplink_args *a = args;
23286 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
23289 +static int whplink(struct dentry *h_dentry, struct inode *inode,
23290 + aufs_bindex_t bindex, struct au_branch *br)
23292 + int err, wkq_err;
23293 + struct au_wbr *wbr;
23294 + struct dentry *h_parent;
23295 + struct inode *h_dir;
23296 + char a[PLINK_NAME_LEN];
23297 + struct qstr tgtname = QSTR_INIT(a, 0);
23299 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
23300 + h_parent = wbr->wbr_plink;
23301 + h_dir = h_parent->d_inode;
23302 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
23304 + /* always superio. */
23305 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
23306 + struct do_whplink_args args = {
23309 + .h_parent = h_parent,
23310 + .h_dentry = h_dentry,
23313 + wkq_err = au_wkq_wait(call_do_whplink, &args);
23314 + if (unlikely(wkq_err))
23317 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
23322 +/* free a single plink */
23323 +static void do_put_plink(struct pseudo_link *plink, int do_del)
23326 + hlist_del(&plink->hlist);
23327 + iput(plink->inode);
23331 +static void do_put_plink_rcu(struct rcu_head *rcu)
23333 + struct pseudo_link *plink;
23335 + plink = container_of(rcu, struct pseudo_link, rcu);
23336 + iput(plink->inode);
23341 + * create a new pseudo-link for @h_dentry on @bindex.
23342 + * the linked inode is held in aufs @inode.
23344 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
23345 + struct dentry *h_dentry)
23347 + struct super_block *sb;
23348 + struct au_sbinfo *sbinfo;
23349 + struct hlist_head *plink_hlist;
23350 + struct pseudo_link *plink, *tmp;
23351 + struct au_sphlhead *sphl;
23352 + int found, err, cnt, i;
23354 + sb = inode->i_sb;
23355 + sbinfo = au_sbi(sb);
23356 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
23357 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
23359 + found = au_plink_test(inode);
23363 + i = au_plink_hash(inode->i_ino);
23364 + sphl = sbinfo->si_plink + i;
23365 + plink_hlist = &sphl->head;
23366 + tmp = kmalloc(sizeof(*plink), GFP_NOFS);
23368 + tmp->inode = au_igrab(inode);
23374 + spin_lock(&sphl->spin);
23375 + hlist_for_each_entry(plink, plink_hlist, hlist) {
23376 + if (plink->inode == inode) {
23382 + hlist_add_head_rcu(&tmp->hlist, plink_hlist);
23383 + spin_unlock(&sphl->spin);
23385 + cnt = au_sphl_count(sphl);
23386 +#define msg "unexpectedly unblanced or too many pseudo-links"
23387 + if (cnt > AUFS_PLINK_WARN)
23388 + AuWarn1(msg ", %d\n", cnt);
23390 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
23392 + do_put_plink(tmp, 0);
23397 + if (unlikely(err)) {
23398 + pr_warn("err %d, damaged pseudo link.\n", err);
23400 + au_sphl_del_rcu(&tmp->hlist, sphl);
23401 + call_rcu(&tmp->rcu, do_put_plink_rcu);
23406 +/* free all plinks */
23407 +void au_plink_put(struct super_block *sb, int verbose)
23410 + struct au_sbinfo *sbinfo;
23411 + struct hlist_head *plink_hlist;
23412 + struct hlist_node *tmp;
23413 + struct pseudo_link *plink;
23415 + SiMustWriteLock(sb);
23417 + sbinfo = au_sbi(sb);
23418 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
23419 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
23421 + /* no spin_lock since sbinfo is write-locked */
23423 + for (i = 0; i < AuPlink_NHASH; i++) {
23424 + plink_hlist = &sbinfo->si_plink[i].head;
23425 + if (!warned && verbose && !hlist_empty(plink_hlist)) {
23426 + pr_warn("pseudo-link is not flushed");
23429 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist)
23430 + do_put_plink(plink, 0);
23431 + INIT_HLIST_HEAD(plink_hlist);
23435 +void au_plink_clean(struct super_block *sb, int verbose)
23437 + struct dentry *root;
23439 + root = sb->s_root;
23440 + aufs_write_lock(root);
23441 + if (au_opt_test(au_mntflags(sb), PLINK))
23442 + au_plink_put(sb, verbose);
23443 + aufs_write_unlock(root);
23446 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
23449 + aufs_bindex_t bstart, bend, bindex;
23452 + bstart = au_ibstart(inode);
23453 + bend = au_ibend(inode);
23454 + if (bstart >= 0) {
23455 + for (bindex = bstart; bindex <= bend; bindex++) {
23456 + if (!au_h_iptr(inode, bindex)
23457 + || au_ii_br_id(inode, bindex) != br_id)
23459 + au_set_h_iptr(inode, bindex, NULL, 0);
23464 + for (bindex = bstart; bindex <= bend; bindex++)
23465 + if (au_h_iptr(inode, bindex)) {
23475 +/* free the plinks on a branch specified by @br_id */
23476 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
23478 + struct au_sbinfo *sbinfo;
23479 + struct hlist_head *plink_hlist;
23480 + struct hlist_node *tmp;
23481 + struct pseudo_link *plink;
23482 + struct inode *inode;
23485 + SiMustWriteLock(sb);
23487 + sbinfo = au_sbi(sb);
23488 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
23489 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
23491 + /* no spin_lock since sbinfo is write-locked */
23492 + for (i = 0; i < AuPlink_NHASH; i++) {
23493 + plink_hlist = &sbinfo->si_plink[i].head;
23494 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist) {
23495 + inode = au_igrab(plink->inode);
23496 + ii_write_lock_child(inode);
23497 + do_put = au_plink_do_half_refresh(inode, br_id);
23499 + do_put_plink(plink, 1);
23500 + ii_write_unlock(inode);
23505 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
23506 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
23507 +++ linux/fs/aufs/poll.c 2014-04-24 22:11:10.855269116 +0200
23510 + * Copyright (C) 2005-2014 Junjiro R. Okajima
23512 + * This program, aufs is free software; you can redistribute it and/or modify
23513 + * it under the terms of the GNU General Public License as published by
23514 + * the Free Software Foundation; either version 2 of the License, or
23515 + * (at your option) any later version.
23517 + * This program is distributed in the hope that it will be useful,
23518 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23519 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23520 + * GNU General Public License for more details.
23522 + * You should have received a copy of the GNU General Public License
23523 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23528 + * There is only one filesystem which implements ->poll operation, currently.
23533 +unsigned int aufs_poll(struct file *file, poll_table *wait)
23535 + unsigned int mask;
23537 + struct file *h_file;
23538 + struct dentry *dentry;
23539 + struct super_block *sb;
23541 + /* We should pretend an error happened. */
23542 + mask = POLLERR /* | POLLIN | POLLOUT */;
23543 + dentry = file->f_dentry;
23544 + sb = dentry->d_sb;
23545 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
23546 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
23547 + if (unlikely(err))
23550 + /* it is not an error if h_file has no operation */
23551 + mask = DEFAULT_POLLMASK;
23552 + h_file = au_hf_top(file);
23553 + if (h_file->f_op->poll)
23554 + mask = h_file->f_op->poll(h_file, wait);
23556 + di_read_unlock(dentry, AuLock_IR);
23557 + fi_read_unlock(file);
23560 + si_read_unlock(sb);
23561 + AuTraceErr((int)mask);
23564 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
23565 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
23566 +++ linux/fs/aufs/procfs.c 2014-04-24 22:11:10.855269116 +0200
23569 + * Copyright (C) 2010-2014 Junjiro R. Okajima
23571 + * This program, aufs is free software; you can redistribute it and/or modify
23572 + * it under the terms of the GNU General Public License as published by
23573 + * the Free Software Foundation; either version 2 of the License, or
23574 + * (at your option) any later version.
23576 + * This program is distributed in the hope that it will be useful,
23577 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23578 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23579 + * GNU General Public License for more details.
23581 + * You should have received a copy of the GNU General Public License
23582 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23586 + * procfs interfaces
23589 +#include <linux/proc_fs.h>
23592 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
23594 + struct au_sbinfo *sbinfo;
23596 + sbinfo = file->private_data;
23598 + au_plink_maint_leave(sbinfo);
23599 + kobject_put(&sbinfo->si_kobj);
23605 +static void au_procfs_plm_write_clean(struct file *file)
23607 + struct au_sbinfo *sbinfo;
23609 + sbinfo = file->private_data;
23611 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
23614 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
23617 + struct super_block *sb;
23618 + struct au_sbinfo *sbinfo;
23621 + if (unlikely(file->private_data))
23625 + /* don't use au_sbilist_lock() here */
23626 + spin_lock(&au_sbilist.spin);
23627 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
23628 + if (id == sysaufs_si_id(sbinfo)) {
23629 + kobject_get(&sbinfo->si_kobj);
23630 + sb = sbinfo->si_sb;
23633 + spin_unlock(&au_sbilist.spin);
23636 + if (unlikely(!sb))
23639 + err = au_plink_maint_enter(sb);
23641 + /* keep kobject_get() */
23642 + file->private_data = sbinfo;
23644 + kobject_put(&sbinfo->si_kobj);
23650 + * Accept a valid "si=xxxx" only.
23651 + * Once it is accepted successfully, accept "clean" too.
23653 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
23654 + size_t count, loff_t *ppos)
23657 + unsigned long id;
23658 + /* last newline is allowed */
23659 + char buf[3 + sizeof(unsigned long) * 2 + 1];
23662 + if (unlikely(!capable(CAP_SYS_ADMIN)))
23666 + if (unlikely(count > sizeof(buf)))
23669 + err = copy_from_user(buf, ubuf, count);
23670 + if (unlikely(err)) {
23677 + if (!strcmp("clean", buf)) {
23678 + au_procfs_plm_write_clean(file);
23679 + goto out_success;
23680 + } else if (unlikely(strncmp("si=", buf, 3)))
23683 + err = kstrtoul(buf + 3, 16, &id);
23684 + if (unlikely(err))
23687 + err = au_procfs_plm_write_si(file, id);
23688 + if (unlikely(err))
23692 + err = count; /* success */
23697 +static const struct file_operations au_procfs_plm_fop = {
23698 + .write = au_procfs_plm_write,
23699 + .release = au_procfs_plm_release,
23700 + .owner = THIS_MODULE
23703 +/* ---------------------------------------------------------------------- */
23705 +static struct proc_dir_entry *au_procfs_dir;
23707 +void au_procfs_fin(void)
23709 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
23710 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
23713 +int __init au_procfs_init(void)
23716 + struct proc_dir_entry *entry;
23719 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
23720 + if (unlikely(!au_procfs_dir))
23723 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR,
23724 + au_procfs_dir, &au_procfs_plm_fop);
23725 + if (unlikely(!entry))
23729 + goto out; /* success */
23733 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
23737 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
23738 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
23739 +++ linux/fs/aufs/rdu.c 2014-04-24 22:11:10.858602483 +0200
23742 + * Copyright (C) 2005-2014 Junjiro R. Okajima
23744 + * This program, aufs is free software; you can redistribute it and/or modify
23745 + * it under the terms of the GNU General Public License as published by
23746 + * the Free Software Foundation; either version 2 of the License, or
23747 + * (at your option) any later version.
23749 + * This program is distributed in the hope that it will be useful,
23750 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23751 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23752 + * GNU General Public License for more details.
23754 + * You should have received a copy of the GNU General Public License
23755 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23759 + * readdir in userspace.
23762 +#include <linux/compat.h>
23763 +#include <linux/fs_stack.h>
23764 +#include <linux/security.h>
23767 +/* bits for struct aufs_rdu.flags */
23768 +#define AuRdu_CALLED 1
23769 +#define AuRdu_CONT (1 << 1)
23770 +#define AuRdu_FULL (1 << 2)
23771 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
23772 +#define au_fset_rdu(flags, name) \
23773 + do { (flags) |= AuRdu_##name; } while (0)
23774 +#define au_fclr_rdu(flags, name) \
23775 + do { (flags) &= ~AuRdu_##name; } while (0)
23777 +struct au_rdu_arg {
23778 + struct dir_context ctx;
23779 + struct aufs_rdu *rdu;
23780 + union au_rdu_ent_ul ent;
23781 + unsigned long end;
23783 + struct super_block *sb;
23787 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
23788 + loff_t offset, u64 h_ino, unsigned int d_type)
23791 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
23792 + struct aufs_rdu *rdu = arg->rdu;
23793 + struct au_rdu_ent ent;
23797 + au_fset_rdu(rdu->cookie.flags, CALLED);
23798 + len = au_rdu_len(nlen);
23799 + if (arg->ent.ul + len < arg->end) {
23801 + ent.bindex = rdu->cookie.bindex;
23802 + ent.type = d_type;
23804 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
23805 + ent.type = DT_UNKNOWN;
23807 + /* unnecessary to support mmap_sem since this is a dir */
23809 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
23811 + if (copy_to_user(arg->ent.e->name, name, nlen))
23813 + /* the terminating NULL */
23814 + if (__put_user(0, arg->ent.e->name + nlen))
23817 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
23818 + arg->ent.ul += len;
23822 + au_fset_rdu(rdu->cookie.flags, FULL);
23824 + rdu->tail = arg->ent;
23828 + /* AuTraceErr(err); */
23832 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
23836 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
23838 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
23839 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
23841 + if (unlikely(offset != cookie->h_pos))
23847 + au_fclr_rdu(cookie->flags, CALLED);
23849 + err = vfsub_iterate_dir(h_file, &arg->ctx);
23853 + && au_ftest_rdu(cookie->flags, CALLED)
23854 + && !au_ftest_rdu(cookie->flags, FULL));
23855 + cookie->h_pos = h_file->f_pos;
23862 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
23865 + aufs_bindex_t bend;
23866 + struct au_rdu_arg arg = {
23868 + .actor = au_diractor(au_rdu_fill)
23871 + struct dentry *dentry;
23872 + struct inode *inode;
23873 + struct file *h_file;
23874 + struct au_rdu_cookie *cookie = &rdu->cookie;
23876 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
23877 + if (unlikely(err)) {
23883 + rdu->tail = rdu->ent;
23886 + arg.ent = rdu->ent;
23887 + arg.end = arg.ent.ul;
23888 + arg.end += rdu->sz;
23891 + if (unlikely(!file->f_op->iterate))
23894 + err = security_file_permission(file, MAY_READ);
23896 + if (unlikely(err))
23899 + dentry = file->f_dentry;
23900 + inode = dentry->d_inode;
23902 + mutex_lock(&inode->i_mutex);
23904 + err = mutex_lock_killable(&inode->i_mutex);
23906 + if (unlikely(err))
23910 + arg.sb = inode->i_sb;
23911 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
23912 + if (unlikely(err))
23914 + err = au_alive_dir(dentry);
23915 + if (unlikely(err))
23917 + /* todo: reval? */
23918 + fi_read_lock(file);
23921 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
23922 + && cookie->generation != au_figen(file)))
23927 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
23929 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
23931 + bend = au_fbstart(file);
23932 + if (cookie->bindex < bend)
23933 + cookie->bindex = bend;
23934 + bend = au_fbend_dir(file);
23935 + /* AuDbg("b%d, b%d\n", cookie->bindex, bend); */
23936 + for (; !err && cookie->bindex <= bend;
23937 + cookie->bindex++, cookie->h_pos = 0) {
23938 + h_file = au_hf_dir(file, cookie->bindex);
23942 + au_fclr_rdu(cookie->flags, FULL);
23943 + err = au_rdu_do(h_file, &arg);
23945 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
23948 + AuDbg("rent %llu\n", rdu->rent);
23950 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
23951 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
23952 + au_fset_rdu(cookie->flags, CONT);
23953 + cookie->generation = au_figen(file);
23956 + ii_read_lock_child(inode);
23957 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibstart(inode)));
23958 + ii_read_unlock(inode);
23961 + fi_read_unlock(file);
23963 + si_read_unlock(arg.sb);
23965 + mutex_unlock(&inode->i_mutex);
23971 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
23975 + unsigned long long nent;
23976 + union au_rdu_ent_ul *u;
23977 + struct au_rdu_ent ent;
23978 + struct super_block *sb;
23981 + nent = rdu->nent;
23983 + sb = file->f_dentry->d_sb;
23984 + si_read_lock(sb, AuLock_FLUSH);
23985 + while (nent-- > 0) {
23986 + /* unnecessary to support mmap_sem since this is a dir */
23987 + err = copy_from_user(&ent, u->e, sizeof(ent));
23989 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
23990 + if (unlikely(err)) {
23996 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
23998 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
24000 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
24002 + if (unlikely(err)) {
24007 + err = __put_user(ino, &u->e->ino);
24008 + if (unlikely(err)) {
24013 + u->ul += au_rdu_len(ent.nlen);
24015 + si_read_unlock(sb);
24020 +/* ---------------------------------------------------------------------- */
24022 +static int au_rdu_verify(struct aufs_rdu *rdu)
24024 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
24025 + "%llu, b%d, 0x%x, g%u}\n",
24026 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
24028 + rdu->rent, rdu->shwh, rdu->full,
24029 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
24030 + rdu->cookie.generation);
24032 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
24036 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
24040 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
24043 + struct aufs_rdu rdu;
24044 + void __user *p = (void __user *)arg;
24046 + err = copy_from_user(&rdu, p, sizeof(rdu));
24047 + if (unlikely(err)) {
24052 + err = au_rdu_verify(&rdu);
24053 + if (unlikely(err))
24057 + case AUFS_CTL_RDU:
24058 + err = au_rdu(file, &rdu);
24059 + if (unlikely(err))
24062 + e = copy_to_user(p, &rdu, sizeof(rdu));
24063 + if (unlikely(e)) {
24068 + case AUFS_CTL_RDU_INO:
24069 + err = au_rdu_ino(file, &rdu);
24073 + /* err = -ENOTTY; */
24082 +#ifdef CONFIG_COMPAT
24083 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
24086 + struct aufs_rdu rdu;
24087 + void __user *p = compat_ptr(arg);
24089 + /* todo: get_user()? */
24090 + err = copy_from_user(&rdu, p, sizeof(rdu));
24091 + if (unlikely(err)) {
24096 + rdu.ent.e = compat_ptr(rdu.ent.ul);
24097 + err = au_rdu_verify(&rdu);
24098 + if (unlikely(err))
24102 + case AUFS_CTL_RDU:
24103 + err = au_rdu(file, &rdu);
24104 + if (unlikely(err))
24107 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
24108 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
24109 + e = copy_to_user(p, &rdu, sizeof(rdu));
24110 + if (unlikely(e)) {
24115 + case AUFS_CTL_RDU_INO:
24116 + err = au_rdu_ino(file, &rdu);
24120 + /* err = -ENOTTY; */
24129 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
24130 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
24131 +++ linux/fs/aufs/rwsem.h 2014-04-24 22:11:10.858602483 +0200
24134 + * Copyright (C) 2005-2014 Junjiro R. Okajima
24136 + * This program, aufs is free software; you can redistribute it and/or modify
24137 + * it under the terms of the GNU General Public License as published by
24138 + * the Free Software Foundation; either version 2 of the License, or
24139 + * (at your option) any later version.
24141 + * This program is distributed in the hope that it will be useful,
24142 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24143 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24144 + * GNU General Public License for more details.
24146 + * You should have received a copy of the GNU General Public License
24147 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24151 + * simple read-write semaphore wrappers
24154 +#ifndef __AUFS_RWSEM_H__
24155 +#define __AUFS_RWSEM_H__
24159 +#include "debug.h"
24162 + struct rw_semaphore rwsem;
24163 +#ifdef CONFIG_AUFS_DEBUG
24164 + /* just for debugging, not almighty counter */
24165 + atomic_t rcnt, wcnt;
24169 +#ifdef CONFIG_AUFS_DEBUG
24170 +#define AuDbgCntInit(rw) do { \
24171 + atomic_set(&(rw)->rcnt, 0); \
24172 + atomic_set(&(rw)->wcnt, 0); \
24173 + smp_mb(); /* atomic set */ \
24176 +#define AuDbgRcntInc(rw) atomic_inc(&(rw)->rcnt)
24177 +#define AuDbgRcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->rcnt) < 0)
24178 +#define AuDbgWcntInc(rw) atomic_inc(&(rw)->wcnt)
24179 +#define AuDbgWcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->wcnt) < 0)
24181 +#define AuDbgCntInit(rw) do {} while (0)
24182 +#define AuDbgRcntInc(rw) do {} while (0)
24183 +#define AuDbgRcntDec(rw) do {} while (0)
24184 +#define AuDbgWcntInc(rw) do {} while (0)
24185 +#define AuDbgWcntDec(rw) do {} while (0)
24186 +#endif /* CONFIG_AUFS_DEBUG */
24188 +/* to debug easier, do not make them inlined functions */
24189 +#define AuRwMustNoWaiters(rw) AuDebugOn(!list_empty(&(rw)->rwsem.wait_list))
24190 +/* rwsem_is_locked() is unusable */
24191 +#define AuRwMustReadLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0)
24192 +#define AuRwMustWriteLock(rw) AuDebugOn(atomic_read(&(rw)->wcnt) <= 0)
24193 +#define AuRwMustAnyLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0 \
24194 + && atomic_read(&(rw)->wcnt) <= 0)
24195 +#define AuRwDestroy(rw) AuDebugOn(atomic_read(&(rw)->rcnt) \
24196 + || atomic_read(&(rw)->wcnt))
24198 +#define au_rw_class(rw, key) lockdep_set_class(&(rw)->rwsem, key)
24200 +static inline void au_rw_init(struct au_rwsem *rw)
24202 + AuDbgCntInit(rw);
24203 + init_rwsem(&rw->rwsem);
24206 +static inline void au_rw_init_wlock(struct au_rwsem *rw)
24209 + down_write(&rw->rwsem);
24210 + AuDbgWcntInc(rw);
24213 +static inline void au_rw_init_wlock_nested(struct au_rwsem *rw,
24214 + unsigned int lsc)
24217 + down_write_nested(&rw->rwsem, lsc);
24218 + AuDbgWcntInc(rw);
24221 +static inline void au_rw_read_lock(struct au_rwsem *rw)
24223 + down_read(&rw->rwsem);
24224 + AuDbgRcntInc(rw);
24227 +static inline void au_rw_read_lock_nested(struct au_rwsem *rw, unsigned int lsc)
24229 + down_read_nested(&rw->rwsem, lsc);
24230 + AuDbgRcntInc(rw);
24233 +static inline void au_rw_read_unlock(struct au_rwsem *rw)
24235 + AuRwMustReadLock(rw);
24236 + AuDbgRcntDec(rw);
24237 + up_read(&rw->rwsem);
24240 +static inline void au_rw_dgrade_lock(struct au_rwsem *rw)
24242 + AuRwMustWriteLock(rw);
24243 + AuDbgRcntInc(rw);
24244 + AuDbgWcntDec(rw);
24245 + downgrade_write(&rw->rwsem);
24248 +static inline void au_rw_write_lock(struct au_rwsem *rw)
24250 + down_write(&rw->rwsem);
24251 + AuDbgWcntInc(rw);
24254 +static inline void au_rw_write_lock_nested(struct au_rwsem *rw,
24255 + unsigned int lsc)
24257 + down_write_nested(&rw->rwsem, lsc);
24258 + AuDbgWcntInc(rw);
24261 +static inline void au_rw_write_unlock(struct au_rwsem *rw)
24263 + AuRwMustWriteLock(rw);
24264 + AuDbgWcntDec(rw);
24265 + up_write(&rw->rwsem);
24268 +/* why is not _nested version defined */
24269 +static inline int au_rw_read_trylock(struct au_rwsem *rw)
24271 + int ret = down_read_trylock(&rw->rwsem);
24273 + AuDbgRcntInc(rw);
24277 +static inline int au_rw_write_trylock(struct au_rwsem *rw)
24279 + int ret = down_write_trylock(&rw->rwsem);
24281 + AuDbgWcntInc(rw);
24285 +#undef AuDbgCntInit
24286 +#undef AuDbgRcntInc
24287 +#undef AuDbgRcntDec
24288 +#undef AuDbgWcntInc
24289 +#undef AuDbgWcntDec
24291 +#define AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
24292 +static inline void prefix##_read_lock(param) \
24293 +{ au_rw_read_lock(rwsem); } \
24294 +static inline void prefix##_write_lock(param) \
24295 +{ au_rw_write_lock(rwsem); } \
24296 +static inline int prefix##_read_trylock(param) \
24297 +{ return au_rw_read_trylock(rwsem); } \
24298 +static inline int prefix##_write_trylock(param) \
24299 +{ return au_rw_write_trylock(rwsem); }
24300 +/* why is not _nested version defined */
24301 +/* static inline void prefix##_read_trylock_nested(param, lsc)
24302 +{ au_rw_read_trylock_nested(rwsem, lsc)); }
24303 +static inline void prefix##_write_trylock_nestd(param, lsc)
24304 +{ au_rw_write_trylock_nested(rwsem, lsc); } */
24306 +#define AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) \
24307 +static inline void prefix##_read_unlock(param) \
24308 +{ au_rw_read_unlock(rwsem); } \
24309 +static inline void prefix##_write_unlock(param) \
24310 +{ au_rw_write_unlock(rwsem); } \
24311 +static inline void prefix##_downgrade_lock(param) \
24312 +{ au_rw_dgrade_lock(rwsem); }
24314 +#define AuSimpleRwsemFuncs(prefix, param, rwsem) \
24315 + AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
24316 + AuSimpleUnlockRwsemFuncs(prefix, param, rwsem)
24318 +#endif /* __KERNEL__ */
24319 +#endif /* __AUFS_RWSEM_H__ */
24320 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
24321 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
24322 +++ linux/fs/aufs/sbinfo.c 2014-04-24 22:11:10.858602483 +0200
24325 + * Copyright (C) 2005-2014 Junjiro R. Okajima
24327 + * This program, aufs is free software; you can redistribute it and/or modify
24328 + * it under the terms of the GNU General Public License as published by
24329 + * the Free Software Foundation; either version 2 of the License, or
24330 + * (at your option) any later version.
24332 + * This program is distributed in the hope that it will be useful,
24333 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24334 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24335 + * GNU General Public License for more details.
24337 + * You should have received a copy of the GNU General Public License
24338 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24342 + * superblock private data
24348 + * they are necessary regardless sysfs is disabled.
24350 +void au_si_free(struct kobject *kobj)
24353 + struct au_sbinfo *sbinfo;
24354 + char *locked __maybe_unused; /* debug only */
24356 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
24357 + for (i = 0; i < AuPlink_NHASH; i++)
24358 + AuDebugOn(!hlist_empty(&sbinfo->si_plink[i].head));
24359 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
24361 + au_rw_write_lock(&sbinfo->si_rwsem);
24362 + au_br_free(sbinfo);
24363 + au_rw_write_unlock(&sbinfo->si_rwsem);
24365 + AuDebugOn(radix_tree_gang_lookup
24366 + (&sbinfo->au_si_pid.tree, (void **)&locked,
24367 + /*first_index*/PID_MAX_DEFAULT - 1,
24368 + /*max_items*/sizeof(locked)/sizeof(*locked)));
24370 + kfree(sbinfo->si_branch);
24371 + kfree(sbinfo->au_si_pid.bitmap);
24372 + mutex_destroy(&sbinfo->si_xib_mtx);
24373 + AuRwDestroy(&sbinfo->si_rwsem);
24378 +int au_si_alloc(struct super_block *sb)
24381 + struct au_sbinfo *sbinfo;
24382 + static struct lock_class_key aufs_si;
24385 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
24386 + if (unlikely(!sbinfo))
24389 + BUILD_BUG_ON(sizeof(unsigned long) !=
24390 + sizeof(*sbinfo->au_si_pid.bitmap));
24391 + sbinfo->au_si_pid.bitmap = kcalloc(BITS_TO_LONGS(PID_MAX_DEFAULT),
24392 + sizeof(*sbinfo->au_si_pid.bitmap),
24394 + if (unlikely(!sbinfo->au_si_pid.bitmap))
24397 + /* will be reallocated separately */
24398 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
24399 + if (unlikely(!sbinfo->si_branch))
24402 + err = sysaufs_si_init(sbinfo);
24403 + if (unlikely(err))
24406 + au_nwt_init(&sbinfo->si_nowait);
24407 + au_rw_init_wlock(&sbinfo->si_rwsem);
24408 + au_rw_class(&sbinfo->si_rwsem, &aufs_si);
24409 + spin_lock_init(&sbinfo->au_si_pid.tree_lock);
24410 + INIT_RADIX_TREE(&sbinfo->au_si_pid.tree, GFP_ATOMIC | __GFP_NOFAIL);
24412 + atomic_long_set(&sbinfo->si_ninodes, 0);
24413 + atomic_long_set(&sbinfo->si_nfiles, 0);
24415 + sbinfo->si_bend = -1;
24416 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
24418 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
24419 + sbinfo->si_wbr_create = AuWbrCreate_Def;
24420 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
24421 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
24423 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
24425 + sbinfo->si_xino_jiffy = jiffies;
24426 + sbinfo->si_xino_expire
24427 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
24428 + mutex_init(&sbinfo->si_xib_mtx);
24429 + sbinfo->si_xino_brid = -1;
24430 + /* leave si_xib_last_pindex and si_xib_next_bit */
24432 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
24433 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
24434 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
24435 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
24437 + for (i = 0; i < AuPlink_NHASH; i++)
24438 + au_sphl_init(sbinfo->si_plink + i);
24439 + init_waitqueue_head(&sbinfo->si_plink_wq);
24440 + spin_lock_init(&sbinfo->si_plink_maint_lock);
24442 + au_sphl_init(&sbinfo->si_files);
24444 + /* leave other members for sysaufs and si_mnt. */
24445 + sbinfo->si_sb = sb;
24446 + sb->s_fs_info = sbinfo;
24448 + au_debug_sbinfo_init(sbinfo);
24449 + return 0; /* success */
24452 + kfree(sbinfo->si_branch);
24454 + kfree(sbinfo->au_si_pid.bitmap);
24461 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr)
24464 + struct au_branch **brp;
24466 + AuRwMustWriteLock(&sbinfo->si_rwsem);
24469 + sz = sizeof(*brp) * (sbinfo->si_bend + 1);
24470 + if (unlikely(!sz))
24471 + sz = sizeof(*brp);
24472 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS);
24474 + sbinfo->si_branch = brp;
24481 +/* ---------------------------------------------------------------------- */
24483 +unsigned int au_sigen_inc(struct super_block *sb)
24485 + unsigned int gen;
24487 + SiMustWriteLock(sb);
24489 + gen = ++au_sbi(sb)->si_generation;
24490 + au_update_digen(sb->s_root);
24491 + au_update_iigen(sb->s_root->d_inode, /*half*/0);
24492 + sb->s_root->d_inode->i_version++;
24496 +aufs_bindex_t au_new_br_id(struct super_block *sb)
24498 + aufs_bindex_t br_id;
24500 + struct au_sbinfo *sbinfo;
24502 + SiMustWriteLock(sb);
24504 + sbinfo = au_sbi(sb);
24505 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
24506 + br_id = ++sbinfo->si_last_br_id;
24507 + AuDebugOn(br_id < 0);
24508 + if (br_id && au_br_index(sb, br_id) < 0)
24515 +/* ---------------------------------------------------------------------- */
24517 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
24518 +int si_read_lock(struct super_block *sb, int flags)
24523 + if (au_ftest_lock(flags, FLUSH))
24524 + au_nwt_flush(&au_sbi(sb)->si_nowait);
24526 + si_noflush_read_lock(sb);
24527 + err = au_plink_maint(sb, flags);
24528 + if (unlikely(err))
24529 + si_read_unlock(sb);
24534 +int si_write_lock(struct super_block *sb, int flags)
24538 + if (au_ftest_lock(flags, FLUSH))
24539 + au_nwt_flush(&au_sbi(sb)->si_nowait);
24541 + si_noflush_write_lock(sb);
24542 + err = au_plink_maint(sb, flags);
24543 + if (unlikely(err))
24544 + si_write_unlock(sb);
24549 +/* dentry and super_block lock. call at entry point */
24550 +int aufs_read_lock(struct dentry *dentry, int flags)
24553 + struct super_block *sb;
24555 + sb = dentry->d_sb;
24556 + err = si_read_lock(sb, flags);
24557 + if (unlikely(err))
24560 + if (au_ftest_lock(flags, DW))
24561 + di_write_lock_child(dentry);
24563 + di_read_lock_child(dentry, flags);
24565 + if (au_ftest_lock(flags, GEN)) {
24566 + err = au_digen_test(dentry, au_sigen(sb));
24567 + AuDebugOn(!err && au_dbrange_test(dentry));
24568 + if (unlikely(err))
24569 + aufs_read_unlock(dentry, flags);
24576 +void aufs_read_unlock(struct dentry *dentry, int flags)
24578 + if (au_ftest_lock(flags, DW))
24579 + di_write_unlock(dentry);
24581 + di_read_unlock(dentry, flags);
24582 + si_read_unlock(dentry->d_sb);
24585 +void aufs_write_lock(struct dentry *dentry)
24587 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
24588 + di_write_lock_child(dentry);
24591 +void aufs_write_unlock(struct dentry *dentry)
24593 + di_write_unlock(dentry);
24594 + si_write_unlock(dentry->d_sb);
24597 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
24600 + unsigned int sigen;
24601 + struct super_block *sb;
24604 + err = si_read_lock(sb, flags);
24605 + if (unlikely(err))
24608 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIR));
24610 + if (au_ftest_lock(flags, GEN)) {
24611 + sigen = au_sigen(sb);
24612 + err = au_digen_test(d1, sigen);
24613 + AuDebugOn(!err && au_dbrange_test(d1));
24615 + err = au_digen_test(d2, sigen);
24616 + AuDebugOn(!err && au_dbrange_test(d2));
24618 + if (unlikely(err))
24619 + aufs_read_and_write_unlock2(d1, d2);
24626 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
24628 + di_write_unlock2(d1, d2);
24629 + si_read_unlock(d1->d_sb);
24632 +/* ---------------------------------------------------------------------- */
24634 +int si_pid_test_slow(struct super_block *sb)
24639 + p = radix_tree_lookup(&au_sbi(sb)->au_si_pid.tree, current->pid);
24640 + rcu_read_unlock();
24642 + return (long)!!p;
24645 +void si_pid_set_slow(struct super_block *sb)
24648 + struct au_sbinfo *sbinfo;
24650 + AuDebugOn(si_pid_test_slow(sb));
24652 + sbinfo = au_sbi(sb);
24653 + err = radix_tree_preload(GFP_NOFS | __GFP_NOFAIL);
24655 + spin_lock(&sbinfo->au_si_pid.tree_lock);
24656 + err = radix_tree_insert(&sbinfo->au_si_pid.tree, current->pid,
24657 + /*any valid ptr*/sb);
24658 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
24660 + radix_tree_preload_end();
24663 +void si_pid_clr_slow(struct super_block *sb)
24666 + struct au_sbinfo *sbinfo;
24668 + AuDebugOn(!si_pid_test_slow(sb));
24670 + sbinfo = au_sbi(sb);
24671 + spin_lock(&sbinfo->au_si_pid.tree_lock);
24672 + p = radix_tree_delete(&sbinfo->au_si_pid.tree, current->pid);
24673 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
24675 diff -urN /usr/share/empty/fs/aufs/spl.h linux/fs/aufs/spl.h
24676 --- /usr/share/empty/fs/aufs/spl.h 1970-01-01 01:00:00.000000000 +0100
24677 +++ linux/fs/aufs/spl.h 2014-04-24 22:11:10.858602483 +0200
24680 + * Copyright (C) 2005-2014 Junjiro R. Okajima
24682 + * This program, aufs is free software; you can redistribute it and/or modify
24683 + * it under the terms of the GNU General Public License as published by
24684 + * the Free Software Foundation; either version 2 of the License, or
24685 + * (at your option) any later version.
24687 + * This program is distributed in the hope that it will be useful,
24688 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24689 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24690 + * GNU General Public License for more details.
24692 + * You should have received a copy of the GNU General Public License
24693 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24697 + * simple list protected by a spinlock
24700 +#ifndef __AUFS_SPL_H__
24701 +#define __AUFS_SPL_H__
24705 +struct au_splhead {
24707 + struct list_head head;
24710 +static inline void au_spl_init(struct au_splhead *spl)
24712 + spin_lock_init(&spl->spin);
24713 + INIT_LIST_HEAD(&spl->head);
24716 +static inline void au_spl_add(struct list_head *list, struct au_splhead *spl)
24718 + spin_lock(&spl->spin);
24719 + list_add(list, &spl->head);
24720 + spin_unlock(&spl->spin);
24723 +static inline void au_spl_del(struct list_head *list, struct au_splhead *spl)
24725 + spin_lock(&spl->spin);
24727 + spin_unlock(&spl->spin);
24730 +static inline void au_spl_del_rcu(struct list_head *list,
24731 + struct au_splhead *spl)
24733 + spin_lock(&spl->spin);
24734 + list_del_rcu(list);
24735 + spin_unlock(&spl->spin);
24738 +/* ---------------------------------------------------------------------- */
24740 +struct au_sphlhead {
24742 + struct hlist_head head;
24745 +static inline void au_sphl_init(struct au_sphlhead *sphl)
24747 + spin_lock_init(&sphl->spin);
24748 + INIT_HLIST_HEAD(&sphl->head);
24751 +static inline void au_sphl_add(struct hlist_node *hlist,
24752 + struct au_sphlhead *sphl)
24754 + spin_lock(&sphl->spin);
24755 + hlist_add_head(hlist, &sphl->head);
24756 + spin_unlock(&sphl->spin);
24759 +static inline void au_sphl_del(struct hlist_node *hlist,
24760 + struct au_sphlhead *sphl)
24762 + spin_lock(&sphl->spin);
24763 + hlist_del(hlist);
24764 + spin_unlock(&sphl->spin);
24767 +static inline void au_sphl_del_rcu(struct hlist_node *hlist,
24768 + struct au_sphlhead *sphl)
24770 + spin_lock(&sphl->spin);
24771 + hlist_del_rcu(hlist);
24772 + spin_unlock(&sphl->spin);
24775 +static inline unsigned long au_sphl_count(struct au_sphlhead *sphl)
24777 + unsigned long cnt;
24778 + struct hlist_node *pos;
24781 + spin_lock(&sphl->spin);
24782 + hlist_for_each(pos, &sphl->head)
24784 + spin_unlock(&sphl->spin);
24788 +#endif /* __KERNEL__ */
24789 +#endif /* __AUFS_SPL_H__ */
24790 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
24791 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
24792 +++ linux/fs/aufs/super.c 2014-04-24 22:11:10.858602483 +0200
24795 + * Copyright (C) 2005-2014 Junjiro R. Okajima
24797 + * This program, aufs is free software; you can redistribute it and/or modify
24798 + * it under the terms of the GNU General Public License as published by
24799 + * the Free Software Foundation; either version 2 of the License, or
24800 + * (at your option) any later version.
24802 + * This program is distributed in the hope that it will be useful,
24803 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24804 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24805 + * GNU General Public License for more details.
24807 + * You should have received a copy of the GNU General Public License
24808 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24812 + * mount and super_block operations
24815 +#include <linux/mm.h>
24816 +#include <linux/module.h>
24817 +#include <linux/seq_file.h>
24818 +#include <linux/statfs.h>
24819 +#include <linux/vmalloc.h>
24820 +#include <linux/writeback.h>
24824 + * super_operations
24826 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
24828 + struct au_icntnr *c;
24830 + c = au_cache_alloc_icntnr();
24832 + au_icntnr_init(c);
24833 + c->vfs_inode.i_version = 1; /* sigen(sb); */
24834 + c->iinfo.ii_hinode = NULL;
24835 + return &c->vfs_inode;
24840 +static void aufs_destroy_inode_cb(struct rcu_head *head)
24842 + struct inode *inode = container_of(head, struct inode, i_rcu);
24844 + INIT_HLIST_HEAD(&inode->i_dentry);
24845 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
24848 +static void aufs_destroy_inode(struct inode *inode)
24850 + au_iinfo_fin(inode);
24851 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
24854 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
24856 + struct inode *inode;
24859 + inode = iget_locked(sb, ino);
24860 + if (unlikely(!inode)) {
24861 + inode = ERR_PTR(-ENOMEM);
24864 + if (!(inode->i_state & I_NEW))
24867 + err = au_xigen_new(inode);
24869 + err = au_iinfo_init(inode);
24871 + inode->i_version++;
24873 + iget_failed(inode);
24874 + inode = ERR_PTR(err);
24878 + /* never return NULL */
24879 + AuDebugOn(!inode);
24880 + AuTraceErrPtr(inode);
24884 +/* lock free root dinfo */
24885 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
24888 + aufs_bindex_t bindex, bend;
24889 + struct path path;
24890 + struct au_hdentry *hdp;
24891 + struct au_branch *br;
24895 + bend = au_sbend(sb);
24896 + hdp = au_di(sb->s_root)->di_hdentry;
24897 + for (bindex = 0; !err && bindex <= bend; bindex++) {
24898 + br = au_sbr(sb, bindex);
24899 + path.mnt = au_br_mnt(br);
24900 + path.dentry = hdp[bindex].hd_dentry;
24901 + err = au_seq_path(seq, &path);
24903 + perm = au_optstr_br_perm(br->br_perm);
24905 + err = seq_printf(seq, "=%s", perm);
24912 + if (!err && bindex != bend)
24913 + err = seq_putc(seq, ':');
24919 +static void au_show_wbr_create(struct seq_file *m, int v,
24920 + struct au_sbinfo *sbinfo)
24924 + AuRwMustAnyLock(&sbinfo->si_rwsem);
24926 + seq_puts(m, ",create=");
24927 + pat = au_optstr_wbr_create(v);
24929 + case AuWbrCreate_TDP:
24930 + case AuWbrCreate_RR:
24931 + case AuWbrCreate_MFS:
24932 + case AuWbrCreate_PMFS:
24933 + seq_puts(m, pat);
24935 + case AuWbrCreate_MFSV:
24936 + seq_printf(m, /*pat*/"mfs:%lu",
24937 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
24940 + case AuWbrCreate_PMFSV:
24941 + seq_printf(m, /*pat*/"pmfs:%lu",
24942 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
24945 + case AuWbrCreate_MFSRR:
24946 + seq_printf(m, /*pat*/"mfsrr:%llu",
24947 + sbinfo->si_wbr_mfs.mfsrr_watermark);
24949 + case AuWbrCreate_MFSRRV:
24950 + seq_printf(m, /*pat*/"mfsrr:%llu:%lu",
24951 + sbinfo->si_wbr_mfs.mfsrr_watermark,
24952 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
24955 + case AuWbrCreate_PMFSRR:
24956 + seq_printf(m, /*pat*/"pmfsrr:%llu",
24957 + sbinfo->si_wbr_mfs.mfsrr_watermark);
24959 + case AuWbrCreate_PMFSRRV:
24960 + seq_printf(m, /*pat*/"pmfsrr:%llu:%lu",
24961 + sbinfo->si_wbr_mfs.mfsrr_watermark,
24962 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
24968 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
24970 +#ifdef CONFIG_SYSFS
24974 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
24975 + aufs_bindex_t bindex, brid;
24976 + struct qstr *name;
24978 + struct dentry *d, *h_root;
24979 + struct au_hdentry *hdp;
24981 + AuRwMustAnyLock(&sbinfo->si_rwsem);
24984 + f = au_sbi(sb)->si_xib;
24988 + /* stop printing the default xino path on the first writable branch */
24990 + brid = au_xino_brid(sb);
24992 + bindex = au_br_index(sb, brid);
24993 + hdp = au_di(sb->s_root)->di_hdentry;
24994 + h_root = hdp[0 + bindex].hd_dentry;
24997 + name = &d->d_name;
24998 + /* safe ->d_parent because the file is unlinked */
24999 + if (d->d_parent == h_root
25000 + && name->len == len
25001 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
25004 + seq_puts(seq, ",xino=");
25005 + err = au_xino_path(seq, f);
25012 +/* seq_file will re-call me in case of too long string */
25013 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
25016 + unsigned int mnt_flags, v;
25017 + struct super_block *sb;
25018 + struct au_sbinfo *sbinfo;
25020 +#define AuBool(name, str) do { \
25021 + v = au_opt_test(mnt_flags, name); \
25022 + if (v != au_opt_test(AuOpt_Def, name)) \
25023 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
25026 +#define AuStr(name, str) do { \
25027 + v = mnt_flags & AuOptMask_##name; \
25028 + if (v != (AuOpt_Def & AuOptMask_##name)) \
25029 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
25032 +#define AuUInt(name, str, val) do { \
25033 + if (val != AUFS_##name##_DEF) \
25034 + seq_printf(m, "," #str "=%u", val); \
25037 + /* lock free root dinfo */
25038 + sb = dentry->d_sb;
25039 + si_noflush_read_lock(sb);
25040 + sbinfo = au_sbi(sb);
25041 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
25043 + mnt_flags = au_mntflags(sb);
25044 + if (au_opt_test(mnt_flags, XINO)) {
25045 + err = au_show_xino(m, sb);
25046 + if (unlikely(err))
25049 + seq_puts(m, ",noxino");
25051 + AuBool(TRUNC_XINO, trunc_xino);
25052 + AuStr(UDBA, udba);
25053 + AuBool(SHWH, shwh);
25054 + AuBool(PLINK, plink);
25055 + AuBool(DIO, dio);
25056 + /* AuBool(DIRPERM1, dirperm1); */
25057 + /* AuBool(REFROF, refrof); */
25059 + v = sbinfo->si_wbr_create;
25060 + if (v != AuWbrCreate_Def)
25061 + au_show_wbr_create(m, v, sbinfo);
25063 + v = sbinfo->si_wbr_copyup;
25064 + if (v != AuWbrCopyup_Def)
25065 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
25067 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
25068 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
25069 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
25071 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
25073 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
25074 + AuUInt(RDCACHE, rdcache, v);
25076 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
25077 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
25079 + AuBool(SUM, sum);
25080 + /* AuBool(SUM_W, wsum); */
25081 + AuBool(WARN_PERM, warn_perm);
25082 + AuBool(VERBOSE, verbose);
25085 + /* be sure to print "br:" last */
25086 + if (!sysaufs_brs) {
25087 + seq_puts(m, ",br:");
25088 + au_show_brs(m, sb);
25090 + si_read_unlock(sb);
25098 +/* ---------------------------------------------------------------------- */
25100 +/* sum mode which returns the summation for statfs(2) */
25102 +static u64 au_add_till_max(u64 a, u64 b)
25110 + return ULLONG_MAX;
25113 +static u64 au_mul_till_max(u64 a, long mul)
25121 + return ULLONG_MAX;
25124 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
25127 + long bsize, factor;
25128 + u64 blocks, bfree, bavail, files, ffree;
25129 + aufs_bindex_t bend, bindex, i;
25130 + unsigned char shared;
25131 + struct path h_path;
25132 + struct super_block *h_sb;
25135 + bsize = LONG_MAX;
25141 + bend = au_sbend(sb);
25142 + for (bindex = 0; bindex <= bend; bindex++) {
25143 + h_path.mnt = au_sbr_mnt(sb, bindex);
25144 + h_sb = h_path.mnt->mnt_sb;
25146 + for (i = 0; !shared && i < bindex; i++)
25147 + shared = (au_sbr_sb(sb, i) == h_sb);
25151 + /* sb->s_root for NFS is unreliable */
25152 + h_path.dentry = h_path.mnt->mnt_root;
25153 + err = vfs_statfs(&h_path, buf);
25154 + if (unlikely(err))
25157 + if (bsize > buf->f_bsize) {
25159 + * we will reduce bsize, so we have to expand blocks
25160 + * etc. to match them again
25162 + factor = (bsize / buf->f_bsize);
25163 + blocks = au_mul_till_max(blocks, factor);
25164 + bfree = au_mul_till_max(bfree, factor);
25165 + bavail = au_mul_till_max(bavail, factor);
25166 + bsize = buf->f_bsize;
25169 + factor = (buf->f_bsize / bsize);
25170 + blocks = au_add_till_max(blocks,
25171 + au_mul_till_max(buf->f_blocks, factor));
25172 + bfree = au_add_till_max(bfree,
25173 + au_mul_till_max(buf->f_bfree, factor));
25174 + bavail = au_add_till_max(bavail,
25175 + au_mul_till_max(buf->f_bavail, factor));
25176 + files = au_add_till_max(files, buf->f_files);
25177 + ffree = au_add_till_max(ffree, buf->f_ffree);
25180 + buf->f_bsize = bsize;
25181 + buf->f_blocks = blocks;
25182 + buf->f_bfree = bfree;
25183 + buf->f_bavail = bavail;
25184 + buf->f_files = files;
25185 + buf->f_ffree = ffree;
25186 + buf->f_frsize = 0;
25192 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
25195 + struct path h_path;
25196 + struct super_block *sb;
25198 + /* lock free root dinfo */
25199 + sb = dentry->d_sb;
25200 + si_noflush_read_lock(sb);
25201 + if (!au_opt_test(au_mntflags(sb), SUM)) {
25202 + /* sb->s_root for NFS is unreliable */
25203 + h_path.mnt = au_sbr_mnt(sb, 0);
25204 + h_path.dentry = h_path.mnt->mnt_root;
25205 + err = vfs_statfs(&h_path, buf);
25207 + err = au_statfs_sum(sb, buf);
25208 + si_read_unlock(sb);
25211 + buf->f_type = AUFS_SUPER_MAGIC;
25212 + buf->f_namelen = AUFS_MAX_NAMELEN;
25213 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
25215 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
25220 +/* ---------------------------------------------------------------------- */
25222 +static int aufs_sync_fs(struct super_block *sb, int wait)
25225 + aufs_bindex_t bend, bindex;
25226 + struct au_branch *br;
25227 + struct super_block *h_sb;
25230 + si_noflush_read_lock(sb);
25231 + bend = au_sbend(sb);
25232 + for (bindex = 0; bindex <= bend; bindex++) {
25233 + br = au_sbr(sb, bindex);
25234 + if (!au_br_writable(br->br_perm))
25237 + h_sb = au_sbr_sb(sb, bindex);
25238 + if (h_sb->s_op->sync_fs) {
25239 + e = h_sb->s_op->sync_fs(h_sb, wait);
25240 + if (unlikely(e && !err))
25242 + /* go on even if an error happens */
25245 + si_read_unlock(sb);
25250 +/* ---------------------------------------------------------------------- */
25252 +/* final actions when unmounting a file system */
25253 +static void aufs_put_super(struct super_block *sb)
25255 + struct au_sbinfo *sbinfo;
25257 + sbinfo = au_sbi(sb);
25261 + dbgaufs_si_fin(sbinfo);
25262 + kobject_put(&sbinfo->si_kobj);
25265 +/* ---------------------------------------------------------------------- */
25267 +void au_array_free(void *array)
25270 + if (!is_vmalloc_addr(array))
25277 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg)
25280 + unsigned long long n;
25287 + if (*hint > ULLONG_MAX / sizeof(array)) {
25288 + array = ERR_PTR(-EMFILE);
25289 + pr_err("hint %llu\n", *hint);
25293 + array = kmalloc(sizeof(array) * *hint, GFP_NOFS);
25294 + if (unlikely(!array))
25295 + array = vmalloc(sizeof(array) * *hint);
25296 + if (unlikely(!array)) {
25297 + array = ERR_PTR(-ENOMEM);
25301 + n = cb(array, *hint, arg);
25302 + AuDebugOn(n > *hint);
25309 +static unsigned long long au_iarray_cb(void *a,
25310 + unsigned long long max __maybe_unused,
25313 + unsigned long long n;
25314 + struct inode **p, *inode;
25315 + struct list_head *head;
25320 + spin_lock(&inode_sb_list_lock);
25321 + list_for_each_entry(inode, head, i_sb_list) {
25322 + if (!is_bad_inode(inode)
25323 + && au_ii(inode)->ii_bstart >= 0) {
25324 + spin_lock(&inode->i_lock);
25325 + if (atomic_read(&inode->i_count)) {
25329 + AuDebugOn(n > max);
25331 + spin_unlock(&inode->i_lock);
25334 + spin_unlock(&inode_sb_list_lock);
25339 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
25341 + *max = atomic_long_read(&au_sbi(sb)->si_ninodes);
25342 + return au_array_alloc(max, au_iarray_cb, &sb->s_inodes);
25345 +void au_iarray_free(struct inode **a, unsigned long long max)
25347 + unsigned long long ull;
25349 + for (ull = 0; ull < max; ull++)
25351 + au_array_free(a);
25354 +/* ---------------------------------------------------------------------- */
25357 + * refresh dentry and inode at remount time.
25359 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
25360 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
25361 + struct dentry *parent)
25365 + di_write_lock_child(dentry);
25366 + di_read_lock_parent(parent, AuLock_IR);
25367 + err = au_refresh_dentry(dentry, parent);
25368 + if (!err && dir_flags)
25369 + au_hn_reset(dentry->d_inode, dir_flags);
25370 + di_read_unlock(parent, AuLock_IR);
25371 + di_write_unlock(dentry);
25376 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
25377 + struct au_sbinfo *sbinfo,
25378 + const unsigned int dir_flags)
25381 + struct dentry *parent;
25382 + struct inode *inode;
25385 + parent = dget_parent(dentry);
25386 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
25387 + inode = dentry->d_inode;
25389 + if (!S_ISDIR(inode->i_mode))
25390 + err = au_do_refresh(dentry, /*dir_flags*/0,
25393 + err = au_do_refresh(dentry, dir_flags, parent);
25394 + if (unlikely(err))
25395 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
25398 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
25399 + AuDbgDentry(dentry);
25407 +static int au_refresh_d(struct super_block *sb)
25409 + int err, i, j, ndentry, e;
25410 + unsigned int sigen;
25411 + struct au_dcsub_pages dpages;
25412 + struct au_dpage *dpage;
25413 + struct dentry **dentries, *d;
25414 + struct au_sbinfo *sbinfo;
25415 + struct dentry *root = sb->s_root;
25416 + const unsigned int dir_flags = au_hi_flags(root->d_inode, /*isdir*/1);
25418 + err = au_dpages_init(&dpages, GFP_NOFS);
25419 + if (unlikely(err))
25421 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
25422 + if (unlikely(err))
25425 + sigen = au_sigen(sb);
25426 + sbinfo = au_sbi(sb);
25427 + for (i = 0; i < dpages.ndpage; i++) {
25428 + dpage = dpages.dpages + i;
25429 + dentries = dpage->dentries;
25430 + ndentry = dpage->ndentry;
25431 + for (j = 0; j < ndentry; j++) {
25433 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags);
25434 + if (unlikely(e && !err))
25436 + /* go on even err */
25441 + au_dpages_free(&dpages);
25446 +static int au_refresh_i(struct super_block *sb)
25449 + unsigned int sigen;
25450 + unsigned long long max, ull;
25451 + struct inode *inode, **array;
25453 + array = au_iarray_alloc(sb, &max);
25454 + err = PTR_ERR(array);
25455 + if (IS_ERR(array))
25459 + sigen = au_sigen(sb);
25460 + for (ull = 0; ull < max; ull++) {
25461 + inode = array[ull];
25462 + if (au_iigen(inode, NULL) != sigen) {
25463 + ii_write_lock_child(inode);
25464 + e = au_refresh_hinode_self(inode);
25465 + ii_write_unlock(inode);
25466 + if (unlikely(e)) {
25467 + pr_err("error %d, i%lu\n", e, inode->i_ino);
25470 + /* go on even if err */
25475 + au_iarray_free(array, max);
25481 +static void au_remount_refresh(struct super_block *sb)
25484 + unsigned int udba;
25485 + aufs_bindex_t bindex, bend;
25486 + struct dentry *root;
25487 + struct inode *inode;
25488 + struct au_branch *br;
25490 + au_sigen_inc(sb);
25491 + au_fclr_si(au_sbi(sb), FAILED_REFRESH_DIR);
25493 + root = sb->s_root;
25494 + DiMustNoWaiters(root);
25495 + inode = root->d_inode;
25496 + IiMustNoWaiters(inode);
25498 + udba = au_opt_udba(sb);
25499 + bend = au_sbend(sb);
25500 + for (bindex = 0; bindex <= bend; bindex++) {
25501 + br = au_sbr(sb, bindex);
25502 + err = au_hnotify_reset_br(udba, br, br->br_perm);
25503 + if (unlikely(err))
25504 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
25506 + /* go on even if err */
25508 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
25510 + di_write_unlock(root);
25511 + err = au_refresh_d(sb);
25512 + e = au_refresh_i(sb);
25513 + if (unlikely(e && !err))
25515 + /* aufs_write_lock() calls ..._child() */
25516 + di_write_lock_child(root);
25518 + au_cpup_attr_all(inode, /*force*/1);
25520 + if (unlikely(err))
25521 + AuIOErr("refresh failed, ignored, %d\n", err);
25524 +/* stop extra interpretation of errno in mount(8), and strange error messages */
25525 +static int cvt_err(int err)
25539 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
25542 + unsigned int mntflags;
25543 + struct au_opts opts;
25544 + struct dentry *root;
25545 + struct inode *inode;
25546 + struct au_sbinfo *sbinfo;
25549 + root = sb->s_root;
25550 + if (!data || !*data) {
25551 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
25553 + di_write_lock_child(root);
25554 + err = au_opts_verify(sb, *flags, /*pending*/0);
25555 + aufs_write_unlock(root);
25561 + memset(&opts, 0, sizeof(opts));
25562 + opts.opt = (void *)__get_free_page(GFP_NOFS);
25563 + if (unlikely(!opts.opt))
25565 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
25566 + opts.flags = AuOpts_REMOUNT;
25567 + opts.sb_flags = *flags;
25569 + /* parse it before aufs lock */
25570 + err = au_opts_parse(sb, data, &opts);
25571 + if (unlikely(err))
25574 + sbinfo = au_sbi(sb);
25575 + inode = root->d_inode;
25576 + mutex_lock(&inode->i_mutex);
25577 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
25578 + if (unlikely(err))
25580 + di_write_lock_child(root);
25582 + /* au_opts_remount() may return an error */
25583 + err = au_opts_remount(sb, &opts);
25584 + au_opts_free(&opts);
25586 + if (au_ftest_opts(opts.flags, REFRESH))
25587 + au_remount_refresh(sb);
25589 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
25590 + mntflags = au_mntflags(sb);
25591 + do_dx = !!au_opt_test(mntflags, DIO);
25592 + au_dy_arefresh(do_dx);
25595 + aufs_write_unlock(root);
25598 + mutex_unlock(&inode->i_mutex);
25600 + free_page((unsigned long)opts.opt);
25602 + err = cvt_err(err);
25607 +static const struct super_operations aufs_sop = {
25608 + .alloc_inode = aufs_alloc_inode,
25609 + .destroy_inode = aufs_destroy_inode,
25610 + /* always deleting, no clearing */
25611 + .drop_inode = generic_delete_inode,
25612 + .show_options = aufs_show_options,
25613 + .statfs = aufs_statfs,
25614 + .put_super = aufs_put_super,
25615 + .sync_fs = aufs_sync_fs,
25616 + .remount_fs = aufs_remount_fs
25619 +/* ---------------------------------------------------------------------- */
25621 +static int alloc_root(struct super_block *sb)
25624 + struct inode *inode;
25625 + struct dentry *root;
25628 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
25629 + err = PTR_ERR(inode);
25630 + if (IS_ERR(inode))
25633 + inode->i_op = &aufs_dir_iop;
25634 + inode->i_fop = &aufs_dir_fop;
25635 + inode->i_mode = S_IFDIR;
25636 + set_nlink(inode, 2);
25637 + unlock_new_inode(inode);
25639 + root = d_make_root(inode);
25640 + if (unlikely(!root))
25642 + err = PTR_ERR(root);
25643 + if (IS_ERR(root))
25646 + err = au_di_init(root);
25648 + sb->s_root = root;
25649 + return 0; /* success */
25657 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
25658 + int silent __maybe_unused)
25661 + struct au_opts opts;
25662 + struct dentry *root;
25663 + struct inode *inode;
25664 + char *arg = raw_data;
25666 + if (unlikely(!arg || !*arg)) {
25668 + pr_err("no arg\n");
25673 + memset(&opts, 0, sizeof(opts));
25674 + opts.opt = (void *)__get_free_page(GFP_NOFS);
25675 + if (unlikely(!opts.opt))
25677 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
25678 + opts.sb_flags = sb->s_flags;
25680 + err = au_si_alloc(sb);
25681 + if (unlikely(err))
25684 + /* all timestamps always follow the ones on the branch */
25685 + sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
25686 + sb->s_op = &aufs_sop;
25687 + sb->s_d_op = &aufs_dop;
25688 + sb->s_magic = AUFS_SUPER_MAGIC;
25689 + sb->s_maxbytes = 0;
25690 + au_export_init(sb);
25692 + err = alloc_root(sb);
25693 + if (unlikely(err)) {
25694 + si_write_unlock(sb);
25697 + root = sb->s_root;
25698 + inode = root->d_inode;
25701 + * actually we can parse options regardless aufs lock here.
25702 + * but at remount time, parsing must be done before aufs lock.
25703 + * so we follow the same rule.
25705 + ii_write_lock_parent(inode);
25706 + aufs_write_unlock(root);
25707 + err = au_opts_parse(sb, arg, &opts);
25708 + if (unlikely(err))
25711 + /* lock vfs_inode first, then aufs. */
25712 + mutex_lock(&inode->i_mutex);
25713 + aufs_write_lock(root);
25714 + err = au_opts_mount(sb, &opts);
25715 + au_opts_free(&opts);
25716 + aufs_write_unlock(root);
25717 + mutex_unlock(&inode->i_mutex);
25719 + goto out_opts; /* success */
25723 + sb->s_root = NULL;
25725 + dbgaufs_si_fin(au_sbi(sb));
25726 + kobject_put(&au_sbi(sb)->si_kobj);
25727 + sb->s_fs_info = NULL;
25729 + free_page((unsigned long)opts.opt);
25732 + err = cvt_err(err);
25737 +/* ---------------------------------------------------------------------- */
25739 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
25740 + const char *dev_name __maybe_unused,
25743 + struct dentry *root;
25744 + struct super_block *sb;
25746 + /* all timestamps always follow the ones on the branch */
25747 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
25748 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
25749 + if (IS_ERR(root))
25753 + si_write_lock(sb, !AuLock_FLUSH);
25754 + sysaufs_brs_add(sb, 0);
25755 + si_write_unlock(sb);
25756 + au_sbilist_add(sb);
25762 +static void aufs_kill_sb(struct super_block *sb)
25764 + struct au_sbinfo *sbinfo;
25766 + sbinfo = au_sbi(sb);
25768 + au_sbilist_del(sb);
25769 + aufs_write_lock(sb->s_root);
25770 + if (sbinfo->si_wbr_create_ops->fin)
25771 + sbinfo->si_wbr_create_ops->fin(sb);
25772 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
25773 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
25774 + au_remount_refresh(sb);
25776 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
25777 + au_plink_put(sb, /*verbose*/1);
25779 + sbinfo->si_sb = NULL;
25780 + aufs_write_unlock(sb->s_root);
25781 + au_nwt_flush(&sbinfo->si_nowait);
25783 + kill_anon_super(sb);
25786 +struct file_system_type aufs_fs_type = {
25787 + .name = AUFS_FSTYPE,
25788 + /* a race between rename and others */
25789 + .fs_flags = FS_RENAME_DOES_D_MOVE,
25790 + .mount = aufs_mount,
25791 + .kill_sb = aufs_kill_sb,
25792 + /* no need to __module_get() and module_put(). */
25793 + .owner = THIS_MODULE,
25795 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
25796 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
25797 +++ linux/fs/aufs/super.h 2014-04-24 22:11:10.858602483 +0200
25800 + * Copyright (C) 2005-2014 Junjiro R. Okajima
25802 + * This program, aufs is free software; you can redistribute it and/or modify
25803 + * it under the terms of the GNU General Public License as published by
25804 + * the Free Software Foundation; either version 2 of the License, or
25805 + * (at your option) any later version.
25807 + * This program is distributed in the hope that it will be useful,
25808 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25809 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25810 + * GNU General Public License for more details.
25812 + * You should have received a copy of the GNU General Public License
25813 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25817 + * super_block operations
25820 +#ifndef __AUFS_SUPER_H__
25821 +#define __AUFS_SUPER_H__
25825 +#include <linux/fs.h>
25826 +#include "rwsem.h"
25830 +typedef ssize_t (*au_readf_t)(struct file *, char __user *, size_t, loff_t *);
25831 +typedef ssize_t (*au_writef_t)(struct file *, const char __user *, size_t,
25834 +/* policies to select one among multiple writable branches */
25835 +struct au_wbr_copyup_operations {
25836 + int (*copyup)(struct dentry *dentry);
25839 +#define AuWbr_DIR 1 /* target is a dir */
25840 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
25842 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
25843 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
25844 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
25846 +struct au_wbr_create_operations {
25847 + int (*create)(struct dentry *dentry, unsigned int flags);
25848 + int (*init)(struct super_block *sb);
25849 + int (*fin)(struct super_block *sb);
25852 +struct au_wbr_mfs {
25853 + struct mutex mfs_lock; /* protect this structure */
25854 + unsigned long mfs_jiffy;
25855 + unsigned long mfs_expire;
25856 + aufs_bindex_t mfs_bindex;
25858 + unsigned long long mfsrr_bytes;
25859 + unsigned long long mfsrr_watermark;
25862 +struct pseudo_link {
25864 + struct hlist_node hlist;
25865 + struct rcu_head rcu;
25867 + struct inode *inode;
25870 +#define AuPlink_NHASH 100
25871 +static inline int au_plink_hash(ino_t ino)
25873 + return ino % AuPlink_NHASH;
25877 +struct au_sbinfo {
25878 + /* nowait tasks in the system-wide workqueue */
25879 + struct au_nowait_tasks si_nowait;
25882 + * tried sb->s_umount, but failed due to the dependecy between i_mutex.
25883 + * rwsem for au_sbinfo is necessary.
25885 + struct au_rwsem si_rwsem;
25887 + /* prevent recursive locking in deleting inode */
25889 + unsigned long *bitmap;
25890 + spinlock_t tree_lock;
25891 + struct radix_tree_root tree;
25895 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
25898 + atomic_long_t si_ninodes, si_nfiles;
25900 + /* branch management */
25901 + unsigned int si_generation;
25903 + /* see above flags */
25904 + unsigned char au_si_status;
25906 + aufs_bindex_t si_bend;
25908 + /* dirty trick to keep br_id plus */
25909 + unsigned int si_last_br_id :
25910 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
25911 + struct au_branch **si_branch;
25913 + /* policy to select a writable branch */
25914 + unsigned char si_wbr_copyup;
25915 + unsigned char si_wbr_create;
25916 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
25917 + struct au_wbr_create_operations *si_wbr_create_ops;
25919 + /* round robin */
25920 + atomic_t si_wbr_rr_next;
25922 + /* most free space */
25923 + struct au_wbr_mfs si_wbr_mfs;
25925 + /* mount flags */
25926 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
25927 + unsigned int si_mntflags;
25929 + /* external inode number (bitmap and translation table) */
25930 + au_readf_t si_xread;
25931 + au_writef_t si_xwrite;
25932 + struct file *si_xib;
25933 + struct mutex si_xib_mtx; /* protect xib members */
25934 + unsigned long *si_xib_buf;
25935 + unsigned long si_xib_last_pindex;
25936 + int si_xib_next_bit;
25937 + aufs_bindex_t si_xino_brid;
25938 + unsigned long si_xino_jiffy;
25939 + unsigned long si_xino_expire;
25940 + /* reserved for future use */
25941 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
25943 +#ifdef CONFIG_AUFS_EXPORT
25944 + /* i_generation */
25945 + struct file *si_xigen;
25946 + atomic_t si_xigen_next;
25949 + /* vdir parameters */
25950 + unsigned long si_rdcache; /* max cache time in jiffies */
25951 + unsigned int si_rdblk; /* deblk size */
25952 + unsigned int si_rdhash; /* hash size */
25955 + * If the number of whiteouts are larger than si_dirwh, leave all of
25956 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
25957 + * future fsck.aufs or kernel thread will remove them later.
25958 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
25960 + unsigned int si_dirwh;
25963 + * rename(2) a directory with all children.
25965 + /* reserved for future use */
25966 + /* int si_rendir; */
25968 + /* pseudo_link list */
25969 + struct au_sphlhead si_plink[AuPlink_NHASH];
25970 + wait_queue_head_t si_plink_wq;
25971 + spinlock_t si_plink_maint_lock;
25972 + pid_t si_plink_maint_pid;
25975 + struct au_sphlhead si_files;
25978 + * sysfs and lifetime management.
25979 + * this is not a small structure and it may be a waste of memory in case
25980 + * of sysfs is disabled, particulary when many aufs-es are mounted.
25981 + * but using sysfs is majority.
25983 + struct kobject si_kobj;
25984 +#ifdef CONFIG_DEBUG_FS
25985 + struct dentry *si_dbgaufs;
25986 + struct dentry *si_dbgaufs_plink;
25987 + struct dentry *si_dbgaufs_xib;
25988 +#ifdef CONFIG_AUFS_EXPORT
25989 + struct dentry *si_dbgaufs_xigen;
25993 +#ifdef CONFIG_AUFS_SBILIST
25994 + struct list_head si_list;
25997 + /* dirty, necessary for unmounting, sysfs and sysrq */
25998 + struct super_block *si_sb;
26001 +/* sbinfo status flags */
26003 + * set true when refresh_dirs() failed at remount time.
26004 + * then try refreshing dirs at access time again.
26005 + * if it is false, refreshing dirs at access time is unnecesary
26007 +#define AuSi_FAILED_REFRESH_DIR 1
26008 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
26009 + unsigned int flag)
26011 + AuRwMustAnyLock(&sbi->si_rwsem);
26012 + return sbi->au_si_status & flag;
26014 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
26015 +#define au_fset_si(sbinfo, name) do { \
26016 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
26017 + (sbinfo)->au_si_status |= AuSi_##name; \
26019 +#define au_fclr_si(sbinfo, name) do { \
26020 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
26021 + (sbinfo)->au_si_status &= ~AuSi_##name; \
26024 +/* ---------------------------------------------------------------------- */
26026 +/* policy to select one among writable branches */
26027 +#define AuWbrCopyup(sbinfo, ...) \
26028 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
26029 +#define AuWbrCreate(sbinfo, ...) \
26030 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
26032 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
26033 +#define AuLock_DW 1 /* write-lock dentry */
26034 +#define AuLock_IR (1 << 1) /* read-lock inode */
26035 +#define AuLock_IW (1 << 2) /* write-lock inode */
26036 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
26037 +#define AuLock_DIR (1 << 4) /* target is a dir */
26038 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
26039 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
26040 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
26041 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
26042 +#define au_fset_lock(flags, name) \
26043 + do { (flags) |= AuLock_##name; } while (0)
26044 +#define au_fclr_lock(flags, name) \
26045 + do { (flags) &= ~AuLock_##name; } while (0)
26047 +/* ---------------------------------------------------------------------- */
26050 +extern struct file_system_type aufs_fs_type;
26051 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
26052 +typedef unsigned long long (*au_arraycb_t)(void *array, unsigned long long max,
26054 +void au_array_free(void *array);
26055 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg);
26056 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
26057 +void au_iarray_free(struct inode **a, unsigned long long max);
26060 +void au_si_free(struct kobject *kobj);
26061 +int au_si_alloc(struct super_block *sb);
26062 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr);
26064 +unsigned int au_sigen_inc(struct super_block *sb);
26065 +aufs_bindex_t au_new_br_id(struct super_block *sb);
26067 +int si_read_lock(struct super_block *sb, int flags);
26068 +int si_write_lock(struct super_block *sb, int flags);
26069 +int aufs_read_lock(struct dentry *dentry, int flags);
26070 +void aufs_read_unlock(struct dentry *dentry, int flags);
26071 +void aufs_write_lock(struct dentry *dentry);
26072 +void aufs_write_unlock(struct dentry *dentry);
26073 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
26074 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
26076 +int si_pid_test_slow(struct super_block *sb);
26077 +void si_pid_set_slow(struct super_block *sb);
26078 +void si_pid_clr_slow(struct super_block *sb);
26080 +/* wbr_policy.c */
26081 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
26082 +extern struct au_wbr_create_operations au_wbr_create_ops[];
26083 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
26084 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
26087 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
26089 +/* ---------------------------------------------------------------------- */
26091 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
26093 + return sb->s_fs_info;
26096 +/* ---------------------------------------------------------------------- */
26098 +#ifdef CONFIG_AUFS_EXPORT
26099 +int au_test_nfsd(void);
26100 +void au_export_init(struct super_block *sb);
26101 +void au_xigen_inc(struct inode *inode);
26102 +int au_xigen_new(struct inode *inode);
26103 +int au_xigen_set(struct super_block *sb, struct file *base);
26104 +void au_xigen_clr(struct super_block *sb);
26106 +static inline int au_busy_or_stale(void)
26108 + if (!au_test_nfsd())
26113 +AuStubInt0(au_test_nfsd, void)
26114 +AuStubVoid(au_export_init, struct super_block *sb)
26115 +AuStubVoid(au_xigen_inc, struct inode *inode)
26116 +AuStubInt0(au_xigen_new, struct inode *inode)
26117 +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base)
26118 +AuStubVoid(au_xigen_clr, struct super_block *sb)
26119 +static inline int au_busy_or_stale(void)
26123 +#endif /* CONFIG_AUFS_EXPORT */
26125 +/* ---------------------------------------------------------------------- */
26127 +#ifdef CONFIG_AUFS_SBILIST
26129 +extern struct au_splhead au_sbilist;
26131 +static inline void au_sbilist_init(void)
26133 + au_spl_init(&au_sbilist);
26136 +static inline void au_sbilist_add(struct super_block *sb)
26138 + au_spl_add(&au_sbi(sb)->si_list, &au_sbilist);
26141 +static inline void au_sbilist_del(struct super_block *sb)
26143 + au_spl_del(&au_sbi(sb)->si_list, &au_sbilist);
26146 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
26147 +static inline void au_sbilist_lock(void)
26149 + spin_lock(&au_sbilist.spin);
26152 +static inline void au_sbilist_unlock(void)
26154 + spin_unlock(&au_sbilist.spin);
26156 +#define AuGFP_SBILIST GFP_ATOMIC
26158 +AuStubVoid(au_sbilist_lock, void)
26159 +AuStubVoid(au_sbilist_unlock, void)
26160 +#define AuGFP_SBILIST GFP_NOFS
26161 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
26163 +AuStubVoid(au_sbilist_init, void)
26164 +AuStubVoid(au_sbilist_add, struct super_block*)
26165 +AuStubVoid(au_sbilist_del, struct super_block*)
26166 +AuStubVoid(au_sbilist_lock, void)
26167 +AuStubVoid(au_sbilist_unlock, void)
26168 +#define AuGFP_SBILIST GFP_NOFS
26171 +/* ---------------------------------------------------------------------- */
26173 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
26176 + * This function is a dynamic '__init' fucntion actually,
26177 + * so the tiny check for si_rwsem is unnecessary.
26179 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
26180 +#ifdef CONFIG_DEBUG_FS
26181 + sbinfo->si_dbgaufs = NULL;
26182 + sbinfo->si_dbgaufs_plink = NULL;
26183 + sbinfo->si_dbgaufs_xib = NULL;
26184 +#ifdef CONFIG_AUFS_EXPORT
26185 + sbinfo->si_dbgaufs_xigen = NULL;
26190 +/* ---------------------------------------------------------------------- */
26192 +static inline pid_t si_pid_bit(void)
26194 + /* the origin of pid is 1, but the bitmap's is 0 */
26195 + return current->pid - 1;
26198 +static inline int si_pid_test(struct super_block *sb)
26200 + pid_t bit = si_pid_bit();
26201 + if (bit < PID_MAX_DEFAULT)
26202 + return test_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
26204 + return si_pid_test_slow(sb);
26207 +static inline void si_pid_set(struct super_block *sb)
26209 + pid_t bit = si_pid_bit();
26210 + if (bit < PID_MAX_DEFAULT) {
26211 + AuDebugOn(test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
26212 + set_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
26215 + si_pid_set_slow(sb);
26218 +static inline void si_pid_clr(struct super_block *sb)
26220 + pid_t bit = si_pid_bit();
26221 + if (bit < PID_MAX_DEFAULT) {
26222 + AuDebugOn(!test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
26223 + clear_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
26226 + si_pid_clr_slow(sb);
26229 +/* ---------------------------------------------------------------------- */
26231 +/* lock superblock. mainly for entry point functions */
26233 + * __si_read_lock, __si_write_lock,
26234 + * __si_read_unlock, __si_write_unlock, __si_downgrade_lock
26236 +AuSimpleRwsemFuncs(__si, struct super_block *sb, &au_sbi(sb)->si_rwsem);
26238 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
26239 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
26240 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
26242 +static inline void si_noflush_read_lock(struct super_block *sb)
26244 + __si_read_lock(sb);
26248 +static inline int si_noflush_read_trylock(struct super_block *sb)
26250 + int locked = __si_read_trylock(sb);
26256 +static inline void si_noflush_write_lock(struct super_block *sb)
26258 + __si_write_lock(sb);
26262 +static inline int si_noflush_write_trylock(struct super_block *sb)
26264 + int locked = __si_write_trylock(sb);
26270 +#if 0 /* unused */
26271 +static inline int si_read_trylock(struct super_block *sb, int flags)
26273 + if (au_ftest_lock(flags, FLUSH))
26274 + au_nwt_flush(&au_sbi(sb)->si_nowait);
26275 + return si_noflush_read_trylock(sb);
26279 +static inline void si_read_unlock(struct super_block *sb)
26282 + __si_read_unlock(sb);
26285 +#if 0 /* unused */
26286 +static inline int si_write_trylock(struct super_block *sb, int flags)
26288 + if (au_ftest_lock(flags, FLUSH))
26289 + au_nwt_flush(&au_sbi(sb)->si_nowait);
26290 + return si_noflush_write_trylock(sb);
26294 +static inline void si_write_unlock(struct super_block *sb)
26297 + __si_write_unlock(sb);
26300 +#if 0 /* unused */
26301 +static inline void si_downgrade_lock(struct super_block *sb)
26303 + __si_downgrade_lock(sb);
26307 +/* ---------------------------------------------------------------------- */
26309 +static inline aufs_bindex_t au_sbend(struct super_block *sb)
26311 + SiMustAnyLock(sb);
26312 + return au_sbi(sb)->si_bend;
26315 +static inline unsigned int au_mntflags(struct super_block *sb)
26317 + SiMustAnyLock(sb);
26318 + return au_sbi(sb)->si_mntflags;
26321 +static inline unsigned int au_sigen(struct super_block *sb)
26323 + SiMustAnyLock(sb);
26324 + return au_sbi(sb)->si_generation;
26327 +static inline void au_ninodes_inc(struct super_block *sb)
26329 + atomic_long_inc(&au_sbi(sb)->si_ninodes);
26332 +static inline void au_ninodes_dec(struct super_block *sb)
26334 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_ninodes));
26335 + atomic_long_dec(&au_sbi(sb)->si_ninodes);
26338 +static inline void au_nfiles_inc(struct super_block *sb)
26340 + atomic_long_inc(&au_sbi(sb)->si_nfiles);
26343 +static inline void au_nfiles_dec(struct super_block *sb)
26345 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_nfiles));
26346 + atomic_long_dec(&au_sbi(sb)->si_nfiles);
26349 +static inline struct au_branch *au_sbr(struct super_block *sb,
26350 + aufs_bindex_t bindex)
26352 + SiMustAnyLock(sb);
26353 + return au_sbi(sb)->si_branch[0 + bindex];
26356 +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid)
26358 + SiMustWriteLock(sb);
26359 + au_sbi(sb)->si_xino_brid = brid;
26362 +static inline aufs_bindex_t au_xino_brid(struct super_block *sb)
26364 + SiMustAnyLock(sb);
26365 + return au_sbi(sb)->si_xino_brid;
26368 +#endif /* __KERNEL__ */
26369 +#endif /* __AUFS_SUPER_H__ */
26370 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
26371 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
26372 +++ linux/fs/aufs/sysaufs.c 2014-04-24 22:11:10.858602483 +0200
26375 + * Copyright (C) 2005-2014 Junjiro R. Okajima
26377 + * This program, aufs is free software; you can redistribute it and/or modify
26378 + * it under the terms of the GNU General Public License as published by
26379 + * the Free Software Foundation; either version 2 of the License, or
26380 + * (at your option) any later version.
26382 + * This program is distributed in the hope that it will be useful,
26383 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26384 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26385 + * GNU General Public License for more details.
26387 + * You should have received a copy of the GNU General Public License
26388 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26392 + * sysfs interface and lifetime management
26393 + * they are necessary regardless sysfs is disabled.
26396 +#include <linux/random.h>
26399 +unsigned long sysaufs_si_mask;
26400 +struct kset *sysaufs_kset;
26402 +#define AuSiAttr(_name) { \
26403 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
26404 + .show = sysaufs_si_##_name, \
26407 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
26408 +struct attribute *sysaufs_si_attrs[] = {
26409 + &sysaufs_si_attr_xi_path.attr,
26413 +static const struct sysfs_ops au_sbi_ops = {
26414 + .show = sysaufs_si_show
26417 +static struct kobj_type au_sbi_ktype = {
26418 + .release = au_si_free,
26419 + .sysfs_ops = &au_sbi_ops,
26420 + .default_attrs = sysaufs_si_attrs
26423 +/* ---------------------------------------------------------------------- */
26425 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
26429 + sbinfo->si_kobj.kset = sysaufs_kset;
26430 + /* cf. sysaufs_name() */
26431 + err = kobject_init_and_add
26432 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
26433 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
26435 + dbgaufs_si_null(sbinfo);
26437 + err = dbgaufs_si_init(sbinfo);
26438 + if (unlikely(err))
26439 + kobject_put(&sbinfo->si_kobj);
26444 +void sysaufs_fin(void)
26447 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
26448 + kset_unregister(sysaufs_kset);
26451 +int __init sysaufs_init(void)
26456 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
26457 + } while (!sysaufs_si_mask);
26460 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
26461 + if (unlikely(!sysaufs_kset))
26463 + err = PTR_ERR(sysaufs_kset);
26464 + if (IS_ERR(sysaufs_kset))
26466 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
26467 + if (unlikely(err)) {
26468 + kset_unregister(sysaufs_kset);
26472 + err = dbgaufs_init();
26473 + if (unlikely(err))
26478 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
26479 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
26480 +++ linux/fs/aufs/sysaufs.h 2014-04-24 22:11:10.858602483 +0200
26483 + * Copyright (C) 2005-2014 Junjiro R. Okajima
26485 + * This program, aufs is free software; you can redistribute it and/or modify
26486 + * it under the terms of the GNU General Public License as published by
26487 + * the Free Software Foundation; either version 2 of the License, or
26488 + * (at your option) any later version.
26490 + * This program is distributed in the hope that it will be useful,
26491 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26492 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26493 + * GNU General Public License for more details.
26495 + * You should have received a copy of the GNU General Public License
26496 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26500 + * sysfs interface and mount lifetime management
26503 +#ifndef __SYSAUFS_H__
26504 +#define __SYSAUFS_H__
26508 +#include <linux/sysfs.h>
26509 +#include "module.h"
26511 +struct super_block;
26514 +struct sysaufs_si_attr {
26515 + struct attribute attr;
26516 + int (*show)(struct seq_file *seq, struct super_block *sb);
26519 +/* ---------------------------------------------------------------------- */
26522 +extern unsigned long sysaufs_si_mask;
26523 +extern struct kset *sysaufs_kset;
26524 +extern struct attribute *sysaufs_si_attrs[];
26525 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
26526 +int __init sysaufs_init(void);
26527 +void sysaufs_fin(void);
26529 +/* ---------------------------------------------------------------------- */
26531 +/* some people doesn't like to show a pointer in kernel */
26532 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
26534 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
26537 +#define SysaufsSiNamePrefix "si_"
26538 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
26539 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
26541 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
26542 + sysaufs_si_id(sbinfo));
26546 +#ifdef CONFIG_SYSFS
26548 +extern struct attribute_group *sysaufs_attr_group;
26550 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
26551 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
26554 +void sysaufs_br_init(struct au_branch *br);
26555 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
26556 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
26558 +#define sysaufs_brs_init() do {} while (0)
26561 +#define sysaufs_attr_group NULL
26563 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
26566 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
26572 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
26573 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
26574 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
26576 +static inline void sysaufs_brs_init(void)
26581 +#endif /* CONFIG_SYSFS */
26583 +#endif /* __KERNEL__ */
26584 +#endif /* __SYSAUFS_H__ */
26585 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
26586 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
26587 +++ linux/fs/aufs/sysfs.c 2014-04-24 22:11:10.858602483 +0200
26590 + * Copyright (C) 2005-2014 Junjiro R. Okajima
26592 + * This program, aufs is free software; you can redistribute it and/or modify
26593 + * it under the terms of the GNU General Public License as published by
26594 + * the Free Software Foundation; either version 2 of the License, or
26595 + * (at your option) any later version.
26597 + * This program is distributed in the hope that it will be useful,
26598 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26599 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26600 + * GNU General Public License for more details.
26602 + * You should have received a copy of the GNU General Public License
26603 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26607 + * sysfs interface
26610 +#include <linux/seq_file.h>
26613 +#ifdef CONFIG_AUFS_FS_MODULE
26614 +/* this entry violates the "one line per file" policy of sysfs */
26615 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
26619 + static char *conf =
26620 +/* this file is generated at compiling */
26621 +#include "conf.str"
26624 + err = snprintf(buf, PAGE_SIZE, conf);
26625 + if (unlikely(err >= PAGE_SIZE))
26630 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
26633 +static struct attribute *au_attr[] = {
26634 +#ifdef CONFIG_AUFS_FS_MODULE
26635 + &au_config_attr.attr,
26637 + NULL, /* need to NULL terminate the list of attributes */
26640 +static struct attribute_group sysaufs_attr_group_body = {
26644 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
26646 +/* ---------------------------------------------------------------------- */
26648 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
26652 + SiMustAnyLock(sb);
26655 + if (au_opt_test(au_mntflags(sb), XINO)) {
26656 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
26657 + seq_putc(seq, '\n');
26663 + * the lifetime of branch is independent from the entry under sysfs.
26664 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
26667 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
26668 + aufs_bindex_t bindex, int idx)
26671 + struct path path;
26672 + struct dentry *root;
26673 + struct au_branch *br;
26676 + AuDbg("b%d\n", bindex);
26679 + root = sb->s_root;
26680 + di_read_lock_parent(root, !AuLock_IR);
26681 + br = au_sbr(sb, bindex);
26684 + case AuBrSysfs_BR:
26685 + path.mnt = au_br_mnt(br);
26686 + path.dentry = au_h_dptr(root, bindex);
26687 + au_seq_path(seq, &path);
26688 + di_read_unlock(root, !AuLock_IR);
26689 + perm = au_optstr_br_perm(br->br_perm);
26691 + err = seq_printf(seq, "=%s\n", perm);
26698 + case AuBrSysfs_BRID:
26699 + err = seq_printf(seq, "%d\n", br->br_id);
26700 + di_read_unlock(root, !AuLock_IR);
26709 +/* ---------------------------------------------------------------------- */
26711 +static struct seq_file *au_seq(char *p, ssize_t len)
26713 + struct seq_file *seq;
26715 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
26717 + /* mutex_init(&seq.lock); */
26720 + return seq; /* success */
26723 + seq = ERR_PTR(-ENOMEM);
26727 +#define SysaufsBr_PREFIX "br"
26728 +#define SysaufsBrid_PREFIX "brid"
26730 +/* todo: file size may exceed PAGE_SIZE */
26731 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
26737 + aufs_bindex_t bend;
26738 + struct au_sbinfo *sbinfo;
26739 + struct super_block *sb;
26740 + struct seq_file *seq;
26742 + struct attribute **cattr;
26744 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
26745 + sb = sbinfo->si_sb;
26748 + * prevent a race condition between sysfs and aufs.
26749 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
26750 + * prohibits maintaining the sysfs entries.
26751 + * hew we acquire read lock after sysfs_get_active_two().
26752 + * on the other hand, the remount process may maintain the sysfs/aufs
26753 + * entries after acquiring write lock.
26754 + * it can cause a deadlock.
26755 + * simply we gave up processing read here.
26758 + if (unlikely(!si_noflush_read_trylock(sb)))
26761 + seq = au_seq(buf, PAGE_SIZE);
26762 + err = PTR_ERR(seq);
26766 + name = (void *)attr->name;
26767 + cattr = sysaufs_si_attrs;
26769 + if (!strcmp(name, (*cattr)->name)) {
26770 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
26777 + if (!strncmp(name, SysaufsBrid_PREFIX,
26778 + sizeof(SysaufsBrid_PREFIX) - 1)) {
26779 + idx = AuBrSysfs_BRID;
26780 + name += sizeof(SysaufsBrid_PREFIX) - 1;
26781 + } else if (!strncmp(name, SysaufsBr_PREFIX,
26782 + sizeof(SysaufsBr_PREFIX) - 1)) {
26783 + idx = AuBrSysfs_BR;
26784 + name += sizeof(SysaufsBr_PREFIX) - 1;
26788 + err = kstrtol(name, 10, &l);
26790 + bend = au_sbend(sb);
26792 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
26799 + err = seq->count;
26800 + /* sysfs limit */
26801 + if (unlikely(err == PAGE_SIZE))
26806 + si_read_unlock(sb);
26811 +/* ---------------------------------------------------------------------- */
26813 +void sysaufs_br_init(struct au_branch *br)
26816 + struct au_brsysfs *br_sysfs;
26817 + struct attribute *attr;
26819 + br_sysfs = br->br_sysfs;
26820 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
26821 + attr = &br_sysfs->attr;
26822 + sysfs_attr_init(attr);
26823 + attr->name = br_sysfs->name;
26824 + attr->mode = S_IRUGO;
26829 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
26831 + struct au_branch *br;
26832 + struct kobject *kobj;
26833 + struct au_brsysfs *br_sysfs;
26835 + aufs_bindex_t bend;
26837 + dbgaufs_brs_del(sb, bindex);
26839 + if (!sysaufs_brs)
26842 + kobj = &au_sbi(sb)->si_kobj;
26843 + bend = au_sbend(sb);
26844 + for (; bindex <= bend; bindex++) {
26845 + br = au_sbr(sb, bindex);
26846 + br_sysfs = br->br_sysfs;
26847 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
26848 + sysfs_remove_file(kobj, &br_sysfs->attr);
26854 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
26857 + aufs_bindex_t bend;
26858 + struct kobject *kobj;
26859 + struct au_branch *br;
26860 + struct au_brsysfs *br_sysfs;
26862 + dbgaufs_brs_add(sb, bindex);
26864 + if (!sysaufs_brs)
26867 + kobj = &au_sbi(sb)->si_kobj;
26868 + bend = au_sbend(sb);
26869 + for (; bindex <= bend; bindex++) {
26870 + br = au_sbr(sb, bindex);
26871 + br_sysfs = br->br_sysfs;
26872 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
26873 + SysaufsBr_PREFIX "%d", bindex);
26874 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
26875 + SysaufsBrid_PREFIX "%d", bindex);
26876 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
26877 + err = sysfs_create_file(kobj, &br_sysfs->attr);
26878 + if (unlikely(err))
26879 + pr_warn("failed %s under sysfs(%d)\n",
26880 + br_sysfs->name, err);
26885 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
26886 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
26887 +++ linux/fs/aufs/sysrq.c 2014-04-24 22:11:10.858602483 +0200
26890 + * Copyright (C) 2005-2014 Junjiro R. Okajima
26892 + * This program, aufs is free software; you can redistribute it and/or modify
26893 + * it under the terms of the GNU General Public License as published by
26894 + * the Free Software Foundation; either version 2 of the License, or
26895 + * (at your option) any later version.
26897 + * This program is distributed in the hope that it will be useful,
26898 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26899 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26900 + * GNU General Public License for more details.
26902 + * You should have received a copy of the GNU General Public License
26903 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26907 + * magic sysrq hanlder
26910 +/* #include <linux/sysrq.h> */
26911 +#include <linux/writeback.h>
26914 +/* ---------------------------------------------------------------------- */
26916 +static void sysrq_sb(struct super_block *sb)
26919 + struct au_sbinfo *sbinfo;
26920 + struct file *file;
26921 + struct au_sphlhead *files;
26922 + struct au_finfo *finfo;
26924 + plevel = au_plevel;
26925 + au_plevel = KERN_WARNING;
26927 + /* since we define pr_fmt, call printk directly */
26928 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
26930 + sbinfo = au_sbi(sb);
26931 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
26932 + pr("superblock\n");
26936 + pr("root dentry\n");
26937 + au_dpri_dentry(sb->s_root);
26938 + pr("root inode\n");
26939 + au_dpri_inode(sb->s_root->d_inode);
26944 + int err, i, j, ndentry;
26945 + struct au_dcsub_pages dpages;
26946 + struct au_dpage *dpage;
26948 + err = au_dpages_init(&dpages, GFP_ATOMIC);
26949 + if (unlikely(err))
26951 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
26953 + for (i = 0; i < dpages.ndpage; i++) {
26954 + dpage = dpages.dpages + i;
26955 + ndentry = dpage->ndentry;
26956 + for (j = 0; j < ndentry; j++)
26957 + au_dpri_dentry(dpage->dentries[j]);
26959 + au_dpages_free(&dpages);
26966 + pr("isolated inode\n");
26967 + spin_lock(&inode_sb_list_lock);
26968 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
26969 + spin_lock(&i->i_lock);
26970 + if (1 || hlist_empty(&i->i_dentry))
26971 + au_dpri_inode(i);
26972 + spin_unlock(&i->i_lock);
26974 + spin_unlock(&inode_sb_list_lock);
26978 + files = &au_sbi(sb)->si_files;
26979 + spin_lock(&files->spin);
26980 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
26982 + file = finfo->fi_file;
26983 + mode = file_inode(file)->i_mode;
26984 + if (!special_file(mode) || au_special_file(mode))
26985 + au_dpri_file(file);
26987 + spin_unlock(&files->spin);
26991 + au_plevel = plevel;
26994 +/* ---------------------------------------------------------------------- */
26996 +/* module parameter */
26997 +static char *aufs_sysrq_key = "a";
26998 +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO);
26999 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
27001 +static void au_sysrq(int key __maybe_unused)
27003 + struct au_sbinfo *sbinfo;
27006 + au_sbilist_lock();
27007 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
27008 + sysrq_sb(sbinfo->si_sb);
27009 + au_sbilist_unlock();
27013 +static struct sysrq_key_op au_sysrq_op = {
27014 + .handler = au_sysrq,
27015 + .help_msg = "Aufs",
27016 + .action_msg = "Aufs",
27017 + .enable_mask = SYSRQ_ENABLE_DUMP
27020 +/* ---------------------------------------------------------------------- */
27022 +int __init au_sysrq_init(void)
27028 + key = *aufs_sysrq_key;
27029 + if ('a' <= key && key <= 'z')
27030 + err = register_sysrq_key(key, &au_sysrq_op);
27031 + if (unlikely(err))
27032 + pr_err("err %d, sysrq=%c\n", err, key);
27036 +void au_sysrq_fin(void)
27039 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
27040 + if (unlikely(err))
27041 + pr_err("err %d (ignored)\n", err);
27043 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
27044 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
27045 +++ linux/fs/aufs/vdir.c 2014-04-24 22:11:10.858602483 +0200
27048 + * Copyright (C) 2005-2014 Junjiro R. Okajima
27050 + * This program, aufs is free software; you can redistribute it and/or modify
27051 + * it under the terms of the GNU General Public License as published by
27052 + * the Free Software Foundation; either version 2 of the License, or
27053 + * (at your option) any later version.
27055 + * This program is distributed in the hope that it will be useful,
27056 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27057 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27058 + * GNU General Public License for more details.
27060 + * You should have received a copy of the GNU General Public License
27061 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27065 + * virtual or vertical directory
27070 +static unsigned int calc_size(int nlen)
27072 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
27075 +static int set_deblk_end(union au_vdir_deblk_p *p,
27076 + union au_vdir_deblk_p *deblk_end)
27078 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
27079 + p->de->de_str.len = 0;
27083 + return -1; /* error */
27086 +/* returns true or false */
27087 +static int is_deblk_end(union au_vdir_deblk_p *p,
27088 + union au_vdir_deblk_p *deblk_end)
27090 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
27091 + return !p->de->de_str.len;
27095 +static unsigned char *last_deblk(struct au_vdir *vdir)
27097 + return vdir->vd_deblk[vdir->vd_nblk - 1];
27100 +/* ---------------------------------------------------------------------- */
27102 +/* estimate the apropriate size for name hash table */
27103 +unsigned int au_rdhash_est(loff_t sz)
27111 + if (sz < AUFS_RDHASH_DEF)
27112 + n = AUFS_RDHASH_DEF;
27113 + /* pr_info("n %u\n", n); */
27118 + * the allocated memory has to be freed by
27119 + * au_nhash_wh_free() or au_nhash_de_free().
27121 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
27123 + struct hlist_head *head;
27126 + head = kmalloc(sizeof(*nhash->nh_head) * num_hash, gfp);
27128 + nhash->nh_num = num_hash;
27129 + nhash->nh_head = head;
27130 + for (u = 0; u < num_hash; u++)
27131 + INIT_HLIST_HEAD(head++);
27132 + return 0; /* success */
27138 +static void nhash_count(struct hlist_head *head)
27142 + struct hlist_node *pos;
27145 + hlist_for_each(pos, head)
27147 + pr_info("%lu\n", n);
27151 +static void au_nhash_wh_do_free(struct hlist_head *head)
27153 + struct au_vdir_wh *pos;
27154 + struct hlist_node *node;
27156 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
27160 +static void au_nhash_de_do_free(struct hlist_head *head)
27162 + struct au_vdir_dehstr *pos;
27163 + struct hlist_node *node;
27165 + hlist_for_each_entry_safe(pos, node, head, hash)
27166 + au_cache_free_vdir_dehstr(pos);
27169 +static void au_nhash_do_free(struct au_nhash *nhash,
27170 + void (*free)(struct hlist_head *head))
27173 + struct hlist_head *head;
27175 + n = nhash->nh_num;
27179 + head = nhash->nh_head;
27180 + while (n-- > 0) {
27181 + nhash_count(head);
27184 + kfree(nhash->nh_head);
27187 +void au_nhash_wh_free(struct au_nhash *whlist)
27189 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
27192 +static void au_nhash_de_free(struct au_nhash *delist)
27194 + au_nhash_do_free(delist, au_nhash_de_do_free);
27197 +/* ---------------------------------------------------------------------- */
27199 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
27203 + unsigned int u, n;
27204 + struct hlist_head *head;
27205 + struct au_vdir_wh *pos;
27208 + n = whlist->nh_num;
27209 + head = whlist->nh_head;
27210 + for (u = 0; u < n; u++, head++)
27211 + hlist_for_each_entry(pos, head, wh_hash)
27212 + if (pos->wh_bindex == btgt && ++num > limit)
27217 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
27218 + unsigned char *name,
27219 + unsigned int len)
27222 + /* const unsigned int magic_bit = 12; */
27224 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
27229 + /* v = hash_long(v, magic_bit); */
27230 + v %= nhash->nh_num;
27231 + return nhash->nh_head + v;
27234 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
27237 + return str->len == nlen && !memcmp(str->name, name, nlen);
27240 +/* returns found or not */
27241 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
27243 + struct hlist_head *head;
27244 + struct au_vdir_wh *pos;
27245 + struct au_vdir_destr *str;
27247 + head = au_name_hash(whlist, name, nlen);
27248 + hlist_for_each_entry(pos, head, wh_hash) {
27249 + str = &pos->wh_str;
27250 + AuDbg("%.*s\n", str->len, str->name);
27251 + if (au_nhash_test_name(str, name, nlen))
27257 +/* returns found(true) or not */
27258 +static int test_known(struct au_nhash *delist, char *name, int nlen)
27260 + struct hlist_head *head;
27261 + struct au_vdir_dehstr *pos;
27262 + struct au_vdir_destr *str;
27264 + head = au_name_hash(delist, name, nlen);
27265 + hlist_for_each_entry(pos, head, hash) {
27267 + AuDbg("%.*s\n", str->len, str->name);
27268 + if (au_nhash_test_name(str, name, nlen))
27274 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
27275 + unsigned char d_type)
27277 +#ifdef CONFIG_AUFS_SHWH
27278 + wh->wh_ino = ino;
27279 + wh->wh_type = d_type;
27283 +/* ---------------------------------------------------------------------- */
27285 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
27286 + unsigned int d_type, aufs_bindex_t bindex,
27287 + unsigned char shwh)
27290 + struct au_vdir_destr *str;
27291 + struct au_vdir_wh *wh;
27293 + AuDbg("%.*s\n", nlen, name);
27294 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
27297 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
27298 + if (unlikely(!wh))
27302 + wh->wh_bindex = bindex;
27304 + au_shwh_init_wh(wh, ino, d_type);
27305 + str = &wh->wh_str;
27307 + memcpy(str->name, name, nlen);
27308 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
27315 +static int append_deblk(struct au_vdir *vdir)
27318 + unsigned long ul;
27319 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
27320 + union au_vdir_deblk_p p, deblk_end;
27321 + unsigned char **o;
27324 + o = krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
27326 + if (unlikely(!o))
27329 + vdir->vd_deblk = o;
27330 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
27332 + ul = vdir->vd_nblk++;
27333 + vdir->vd_deblk[ul] = p.deblk;
27334 + vdir->vd_last.ul = ul;
27335 + vdir->vd_last.p.deblk = p.deblk;
27336 + deblk_end.deblk = p.deblk + deblk_sz;
27337 + err = set_deblk_end(&p, &deblk_end);
27344 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
27345 + unsigned int d_type, struct au_nhash *delist)
27349 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
27350 + union au_vdir_deblk_p p, *room, deblk_end;
27351 + struct au_vdir_dehstr *dehstr;
27353 + p.deblk = last_deblk(vdir);
27354 + deblk_end.deblk = p.deblk + deblk_sz;
27355 + room = &vdir->vd_last.p;
27356 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
27357 + || !is_deblk_end(room, &deblk_end));
27359 + sz = calc_size(nlen);
27360 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
27361 + err = append_deblk(vdir);
27362 + if (unlikely(err))
27365 + p.deblk = last_deblk(vdir);
27366 + deblk_end.deblk = p.deblk + deblk_sz;
27368 + AuDebugOn(room->deblk != p.deblk);
27372 + dehstr = au_cache_alloc_vdir_dehstr();
27373 + if (unlikely(!dehstr))
27376 + dehstr->str = &room->de->de_str;
27377 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
27378 + room->de->de_ino = ino;
27379 + room->de->de_type = d_type;
27380 + room->de->de_str.len = nlen;
27381 + memcpy(room->de->de_str.name, name, nlen);
27384 + room->deblk += sz;
27385 + if (unlikely(set_deblk_end(room, &deblk_end)))
27386 + err = append_deblk(vdir);
27393 +/* ---------------------------------------------------------------------- */
27395 +void au_vdir_free(struct au_vdir *vdir)
27397 + unsigned char **deblk;
27399 + deblk = vdir->vd_deblk;
27400 + while (vdir->vd_nblk--)
27402 + kfree(vdir->vd_deblk);
27403 + au_cache_free_vdir(vdir);
27406 +static struct au_vdir *alloc_vdir(struct file *file)
27408 + struct au_vdir *vdir;
27409 + struct super_block *sb;
27412 + sb = file->f_dentry->d_sb;
27413 + SiMustAnyLock(sb);
27416 + vdir = au_cache_alloc_vdir();
27417 + if (unlikely(!vdir))
27420 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
27421 + if (unlikely(!vdir->vd_deblk))
27424 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
27425 + if (!vdir->vd_deblk_sz) {
27426 + /* estimate the apropriate size for deblk */
27427 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
27428 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
27430 + vdir->vd_nblk = 0;
27431 + vdir->vd_version = 0;
27432 + vdir->vd_jiffy = 0;
27433 + err = append_deblk(vdir);
27435 + return vdir; /* success */
27437 + kfree(vdir->vd_deblk);
27440 + au_cache_free_vdir(vdir);
27442 + vdir = ERR_PTR(err);
27446 +static int reinit_vdir(struct au_vdir *vdir)
27449 + union au_vdir_deblk_p p, deblk_end;
27451 + while (vdir->vd_nblk > 1) {
27452 + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
27453 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
27456 + p.deblk = vdir->vd_deblk[0];
27457 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
27458 + err = set_deblk_end(&p, &deblk_end);
27459 + /* keep vd_dblk_sz */
27460 + vdir->vd_last.ul = 0;
27461 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
27462 + vdir->vd_version = 0;
27463 + vdir->vd_jiffy = 0;
27468 +/* ---------------------------------------------------------------------- */
27470 +#define AuFillVdir_CALLED 1
27471 +#define AuFillVdir_WHABLE (1 << 1)
27472 +#define AuFillVdir_SHWH (1 << 2)
27473 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
27474 +#define au_fset_fillvdir(flags, name) \
27475 + do { (flags) |= AuFillVdir_##name; } while (0)
27476 +#define au_fclr_fillvdir(flags, name) \
27477 + do { (flags) &= ~AuFillVdir_##name; } while (0)
27479 +#ifndef CONFIG_AUFS_SHWH
27480 +#undef AuFillVdir_SHWH
27481 +#define AuFillVdir_SHWH 0
27484 +struct fillvdir_arg {
27485 + struct dir_context ctx;
27486 + struct file *file;
27487 + struct au_vdir *vdir;
27488 + struct au_nhash delist;
27489 + struct au_nhash whlist;
27490 + aufs_bindex_t bindex;
27491 + unsigned int flags;
27495 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
27496 + loff_t offset __maybe_unused, u64 h_ino,
27497 + unsigned int d_type)
27499 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
27500 + char *name = (void *)__name;
27501 + struct super_block *sb;
27503 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
27506 + sb = arg->file->f_dentry->d_sb;
27507 + au_fset_fillvdir(arg->flags, CALLED);
27509 + if (nlen <= AUFS_WH_PFX_LEN
27510 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
27511 + if (test_known(&arg->delist, name, nlen)
27512 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
27513 + goto out; /* already exists or whiteouted */
27515 + sb = arg->file->f_dentry->d_sb;
27516 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
27518 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
27519 + d_type = DT_UNKNOWN;
27520 + arg->err = append_de(arg->vdir, name, nlen, ino,
27521 + d_type, &arg->delist);
27523 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
27524 + name += AUFS_WH_PFX_LEN;
27525 + nlen -= AUFS_WH_PFX_LEN;
27526 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
27527 + goto out; /* already whiteouted */
27530 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
27533 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
27534 + d_type = DT_UNKNOWN;
27535 + arg->err = au_nhash_append_wh
27536 + (&arg->whlist, name, nlen, ino, d_type,
27537 + arg->bindex, shwh);
27543 + arg->vdir->vd_jiffy = jiffies;
27545 + AuTraceErr(arg->err);
27549 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
27550 + struct au_nhash *whlist, struct au_nhash *delist)
27552 +#ifdef CONFIG_AUFS_SHWH
27554 + unsigned int nh, u;
27555 + struct hlist_head *head;
27556 + struct au_vdir_wh *pos;
27557 + struct hlist_node *n;
27559 + struct au_vdir_destr *destr;
27561 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
27564 + o = p = (void *)__get_free_page(GFP_NOFS);
27565 + if (unlikely(!p))
27569 + nh = whlist->nh_num;
27570 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
27571 + p += AUFS_WH_PFX_LEN;
27572 + for (u = 0; u < nh; u++) {
27573 + head = whlist->nh_head + u;
27574 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
27575 + destr = &pos->wh_str;
27576 + memcpy(p, destr->name, destr->len);
27577 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
27578 + pos->wh_ino, pos->wh_type, delist);
27579 + if (unlikely(err))
27584 + free_page((unsigned long)o);
27594 +static int au_do_read_vdir(struct fillvdir_arg *arg)
27597 + unsigned int rdhash;
27599 + aufs_bindex_t bend, bindex, bstart;
27600 + unsigned char shwh;
27601 + struct file *hf, *file;
27602 + struct super_block *sb;
27604 + file = arg->file;
27605 + sb = file->f_dentry->d_sb;
27606 + SiMustAnyLock(sb);
27608 + rdhash = au_sbi(sb)->si_rdhash;
27610 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
27611 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
27612 + if (unlikely(err))
27614 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
27615 + if (unlikely(err))
27621 + if (au_opt_test(au_mntflags(sb), SHWH)) {
27623 + au_fset_fillvdir(arg->flags, SHWH);
27625 + bstart = au_fbstart(file);
27626 + bend = au_fbend_dir(file);
27627 + for (bindex = bstart; !err && bindex <= bend; bindex++) {
27628 + hf = au_hf_dir(file, bindex);
27632 + offset = vfsub_llseek(hf, 0, SEEK_SET);
27634 + if (unlikely(offset))
27637 + arg->bindex = bindex;
27638 + au_fclr_fillvdir(arg->flags, WHABLE);
27640 + || (bindex != bend
27641 + && au_br_whable(au_sbr_perm(sb, bindex))))
27642 + au_fset_fillvdir(arg->flags, WHABLE);
27645 + au_fclr_fillvdir(arg->flags, CALLED);
27647 + err = vfsub_iterate_dir(hf, &arg->ctx);
27650 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
27653 + * dir_relax() may be good for concurrency, but aufs should not
27654 + * use it since it will cause a lockdep problem.
27658 + if (!err && shwh)
27659 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
27661 + au_nhash_wh_free(&arg->whlist);
27664 + au_nhash_de_free(&arg->delist);
27669 +static int read_vdir(struct file *file, int may_read)
27672 + unsigned long expire;
27673 + unsigned char do_read;
27674 + struct fillvdir_arg arg = {
27676 + .actor = au_diractor(fillvdir)
27679 + struct inode *inode;
27680 + struct au_vdir *vdir, *allocated;
27683 + inode = file_inode(file);
27684 + IMustLock(inode);
27685 + SiMustAnyLock(inode->i_sb);
27687 + allocated = NULL;
27689 + expire = au_sbi(inode->i_sb)->si_rdcache;
27690 + vdir = au_ivdir(inode);
27693 + vdir = alloc_vdir(file);
27694 + err = PTR_ERR(vdir);
27695 + if (IS_ERR(vdir))
27698 + allocated = vdir;
27699 + } else if (may_read
27700 + && (inode->i_version != vdir->vd_version
27701 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
27703 + err = reinit_vdir(vdir);
27704 + if (unlikely(err))
27709 + return 0; /* success */
27713 + err = au_do_read_vdir(&arg);
27715 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
27716 + vdir->vd_version = inode->i_version;
27717 + vdir->vd_last.ul = 0;
27718 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
27720 + au_set_ivdir(inode, allocated);
27721 + } else if (allocated)
27722 + au_vdir_free(allocated);
27728 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
27731 + unsigned long ul, n;
27732 + const unsigned int deblk_sz = src->vd_deblk_sz;
27734 + AuDebugOn(tgt->vd_nblk != 1);
27737 + if (tgt->vd_nblk < src->vd_nblk) {
27738 + unsigned char **p;
27740 + p = krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
27742 + if (unlikely(!p))
27744 + tgt->vd_deblk = p;
27747 + if (tgt->vd_deblk_sz != deblk_sz) {
27748 + unsigned char *p;
27750 + tgt->vd_deblk_sz = deblk_sz;
27751 + p = krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS);
27752 + if (unlikely(!p))
27754 + tgt->vd_deblk[0] = p;
27756 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
27757 + tgt->vd_version = src->vd_version;
27758 + tgt->vd_jiffy = src->vd_jiffy;
27760 + n = src->vd_nblk;
27761 + for (ul = 1; ul < n; ul++) {
27762 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
27764 + if (unlikely(!tgt->vd_deblk[ul]))
27768 + tgt->vd_nblk = n;
27769 + tgt->vd_last.ul = tgt->vd_last.ul;
27770 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
27771 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
27772 + - src->vd_deblk[src->vd_last.ul];
27774 + return 0; /* success */
27777 + rerr = reinit_vdir(tgt);
27782 +int au_vdir_init(struct file *file)
27785 + struct inode *inode;
27786 + struct au_vdir *vdir_cache, *allocated;
27788 + /* test file->f_pos here instead of ctx->pos */
27789 + err = read_vdir(file, !file->f_pos);
27790 + if (unlikely(err))
27793 + allocated = NULL;
27794 + vdir_cache = au_fvdir_cache(file);
27795 + if (!vdir_cache) {
27796 + vdir_cache = alloc_vdir(file);
27797 + err = PTR_ERR(vdir_cache);
27798 + if (IS_ERR(vdir_cache))
27800 + allocated = vdir_cache;
27801 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
27802 + /* test file->f_pos here instead of ctx->pos */
27803 + err = reinit_vdir(vdir_cache);
27804 + if (unlikely(err))
27807 + return 0; /* success */
27809 + inode = file_inode(file);
27810 + err = copy_vdir(vdir_cache, au_ivdir(inode));
27812 + file->f_version = inode->i_version;
27814 + au_set_fvdir_cache(file, allocated);
27815 + } else if (allocated)
27816 + au_vdir_free(allocated);
27822 +static loff_t calc_offset(struct au_vdir *vdir)
27825 + union au_vdir_deblk_p p;
27827 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
27828 + offset = vdir->vd_last.p.deblk - p.deblk;
27829 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
27833 +/* returns true or false */
27834 +static int seek_vdir(struct file *file, struct dir_context *ctx)
27837 + unsigned int deblk_sz;
27838 + unsigned long ul, n;
27840 + union au_vdir_deblk_p p, deblk_end;
27841 + struct au_vdir *vdir_cache;
27844 + vdir_cache = au_fvdir_cache(file);
27845 + offset = calc_offset(vdir_cache);
27846 + AuDbg("offset %lld\n", offset);
27847 + if (ctx->pos == offset)
27850 + vdir_cache->vd_last.ul = 0;
27851 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
27856 + deblk_sz = vdir_cache->vd_deblk_sz;
27857 + ul = div64_u64(ctx->pos, deblk_sz);
27858 + AuDbg("ul %lu\n", ul);
27859 + if (ul >= vdir_cache->vd_nblk)
27862 + n = vdir_cache->vd_nblk;
27863 + for (; ul < n; ul++) {
27864 + p.deblk = vdir_cache->vd_deblk[ul];
27865 + deblk_end.deblk = p.deblk + deblk_sz;
27867 + offset *= deblk_sz;
27868 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
27871 + l = calc_size(p.de->de_str.len);
27875 + if (!is_deblk_end(&p, &deblk_end)) {
27877 + vdir_cache->vd_last.ul = ul;
27878 + vdir_cache->vd_last.p = p;
27885 + AuTraceErr(!valid);
27889 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
27891 + unsigned int l, deblk_sz;
27892 + union au_vdir_deblk_p deblk_end;
27893 + struct au_vdir *vdir_cache;
27894 + struct au_vdir_de *de;
27896 + vdir_cache = au_fvdir_cache(file);
27897 + if (!seek_vdir(file, ctx))
27900 + deblk_sz = vdir_cache->vd_deblk_sz;
27902 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
27903 + deblk_end.deblk += deblk_sz;
27904 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
27905 + de = vdir_cache->vd_last.p.de;
27906 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
27907 + de->de_str.len, de->de_str.name, ctx->pos,
27908 + (unsigned long)de->de_ino, de->de_type);
27909 + if (unlikely(!dir_emit(ctx, de->de_str.name,
27910 + de->de_str.len, de->de_ino,
27912 + /* todo: ignore the error caused by udba? */
27913 + /* return err; */
27917 + l = calc_size(de->de_str.len);
27918 + vdir_cache->vd_last.p.deblk += l;
27921 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
27922 + vdir_cache->vd_last.ul++;
27923 + vdir_cache->vd_last.p.deblk
27924 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
27925 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
27934 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
27935 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
27936 +++ linux/fs/aufs/vfsub.c 2014-04-24 22:11:10.861935852 +0200
27939 + * Copyright (C) 2005-2014 Junjiro R. Okajima
27941 + * This program, aufs is free software; you can redistribute it and/or modify
27942 + * it under the terms of the GNU General Public License as published by
27943 + * the Free Software Foundation; either version 2 of the License, or
27944 + * (at your option) any later version.
27946 + * This program is distributed in the hope that it will be useful,
27947 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27948 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27949 + * GNU General Public License for more details.
27951 + * You should have received a copy of the GNU General Public License
27952 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27956 + * sub-routines for VFS
27959 +#include <linux/ima.h>
27960 +#include <linux/namei.h>
27961 +#include <linux/security.h>
27962 +#include <linux/splice.h>
27965 +int vfsub_update_h_iattr(struct path *h_path, int *did)
27969 + struct super_block *h_sb;
27971 + /* for remote fs, leave work for its getattr or d_revalidate */
27972 + /* for bad i_attr fs, handle them in aufs_getattr() */
27973 + /* still some fs may acquire i_mutex. we need to skip them */
27977 + h_sb = h_path->dentry->d_sb;
27978 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
27980 + err = vfs_getattr(h_path, &st);
27985 +/* ---------------------------------------------------------------------- */
27987 +struct file *vfsub_dentry_open(struct path *path, int flags)
27989 + struct file *file;
27991 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
27993 + if (!IS_ERR_OR_NULL(file)
27994 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
27995 + i_readcount_inc(path->dentry->d_inode);
28000 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
28002 + struct file *file;
28005 + file = filp_open(path,
28006 + oflags /* | __FMODE_NONOTIFY */,
28009 + if (IS_ERR(file))
28011 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
28017 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
28021 + err = kern_path(name, flags, path);
28022 + if (!err && path->dentry->d_inode)
28023 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
28027 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
28030 + struct path path = {
28034 + /* VFS checks it too, but by WARN_ON_ONCE() */
28035 + IMustLock(parent->d_inode);
28037 + path.dentry = lookup_one_len(name, parent, len);
28038 + if (IS_ERR(path.dentry))
28040 + if (path.dentry->d_inode)
28041 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
28044 + AuTraceErrPtr(path.dentry);
28045 + return path.dentry;
28048 +void vfsub_call_lkup_one(void *args)
28050 + struct vfsub_lkup_one_args *a = args;
28051 + *a->errp = vfsub_lkup_one(a->name, a->parent);
28054 +/* ---------------------------------------------------------------------- */
28056 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
28057 + struct dentry *d2, struct au_hinode *hdir2)
28059 + struct dentry *d;
28062 + d = lock_rename(d1, d2);
28064 + au_hn_suspend(hdir1);
28065 + if (hdir1 != hdir2)
28066 + au_hn_suspend(hdir2);
28071 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
28072 + struct dentry *d2, struct au_hinode *hdir2)
28074 + au_hn_resume(hdir1);
28075 + if (hdir1 != hdir2)
28076 + au_hn_resume(hdir2);
28078 + unlock_rename(d1, d2);
28082 +/* ---------------------------------------------------------------------- */
28084 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
28087 + struct dentry *d;
28091 + d = path->dentry;
28092 + path->dentry = d->d_parent;
28093 + err = security_path_mknod(path, d, mode, 0);
28094 + path->dentry = d;
28095 + if (unlikely(err))
28098 + err = vfs_create(dir, path->dentry, mode, want_excl);
28100 + struct path tmp = *path;
28103 + vfsub_update_h_iattr(&tmp, &did);
28105 + tmp.dentry = path->dentry->d_parent;
28106 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
28115 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
28118 + struct dentry *d;
28122 + d = path->dentry;
28123 + path->dentry = d->d_parent;
28124 + err = security_path_symlink(path, d, symname);
28125 + path->dentry = d;
28126 + if (unlikely(err))
28129 + err = vfs_symlink(dir, path->dentry, symname);
28131 + struct path tmp = *path;
28134 + vfsub_update_h_iattr(&tmp, &did);
28136 + tmp.dentry = path->dentry->d_parent;
28137 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
28146 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
28149 + struct dentry *d;
28153 + d = path->dentry;
28154 + path->dentry = d->d_parent;
28155 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
28156 + path->dentry = d;
28157 + if (unlikely(err))
28160 + err = vfs_mknod(dir, path->dentry, mode, dev);
28162 + struct path tmp = *path;
28165 + vfsub_update_h_iattr(&tmp, &did);
28167 + tmp.dentry = path->dentry->d_parent;
28168 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
28177 +static int au_test_nlink(struct inode *inode)
28179 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
28181 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
28182 + || inode->i_nlink < link_max)
28187 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
28188 + struct inode **delegated_inode)
28191 + struct dentry *d;
28195 + err = au_test_nlink(src_dentry->d_inode);
28196 + if (unlikely(err))
28199 + /* we don't call may_linkat() */
28200 + d = path->dentry;
28201 + path->dentry = d->d_parent;
28202 + err = security_path_link(src_dentry, path, d);
28203 + path->dentry = d;
28204 + if (unlikely(err))
28208 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
28211 + struct path tmp = *path;
28214 + /* fuse has different memory inode for the same inumber */
28215 + vfsub_update_h_iattr(&tmp, &did);
28217 + tmp.dentry = path->dentry->d_parent;
28218 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
28219 + tmp.dentry = src_dentry;
28220 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
28229 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
28230 + struct inode *dir, struct path *path,
28231 + struct inode **delegated_inode)
28234 + struct path tmp = {
28237 + struct dentry *d;
28240 + IMustLock(src_dir);
28242 + d = path->dentry;
28243 + path->dentry = d->d_parent;
28244 + tmp.dentry = src_dentry->d_parent;
28245 + err = security_path_rename(&tmp, src_dentry, path, d);
28246 + path->dentry = d;
28247 + if (unlikely(err))
28251 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
28252 + delegated_inode);
28257 + tmp.dentry = d->d_parent;
28258 + vfsub_update_h_iattr(&tmp, &did);
28260 + tmp.dentry = src_dentry;
28261 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
28262 + tmp.dentry = src_dentry->d_parent;
28263 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
28272 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
28275 + struct dentry *d;
28279 + d = path->dentry;
28280 + path->dentry = d->d_parent;
28281 + err = security_path_mkdir(path, d, mode);
28282 + path->dentry = d;
28283 + if (unlikely(err))
28286 + err = vfs_mkdir(dir, path->dentry, mode);
28288 + struct path tmp = *path;
28291 + vfsub_update_h_iattr(&tmp, &did);
28293 + tmp.dentry = path->dentry->d_parent;
28294 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
28303 +int vfsub_rmdir(struct inode *dir, struct path *path)
28306 + struct dentry *d;
28310 + d = path->dentry;
28311 + path->dentry = d->d_parent;
28312 + err = security_path_rmdir(path, d);
28313 + path->dentry = d;
28314 + if (unlikely(err))
28318 + err = vfs_rmdir(dir, path->dentry);
28321 + struct path tmp = {
28322 + .dentry = path->dentry->d_parent,
28326 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
28333 +/* ---------------------------------------------------------------------- */
28335 +/* todo: support mmap_sem? */
28336 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
28342 + err = vfs_read(file, ubuf, count, ppos);
28345 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
28349 +/* todo: kernel_read()? */
28350 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
28354 + mm_segment_t oldfs;
28361 + oldfs = get_fs();
28362 + set_fs(KERNEL_DS);
28363 + err = vfsub_read_u(file, buf.u, count, ppos);
28368 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
28374 + err = vfs_write(file, ubuf, count, ppos);
28377 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
28381 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
28384 + mm_segment_t oldfs;
28387 + const char __user *u;
28391 + oldfs = get_fs();
28392 + set_fs(KERNEL_DS);
28393 + err = vfsub_write_u(file, buf.u, count, ppos);
28398 +int vfsub_flush(struct file *file, fl_owner_t id)
28403 + if (file->f_op->flush) {
28404 + if (!au_test_nfs(file->f_dentry->d_sb))
28405 + err = file->f_op->flush(file, id);
28408 + err = file->f_op->flush(file, id);
28412 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
28418 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
28422 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
28425 + err = iterate_dir(file, ctx);
28428 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
28432 +long vfsub_splice_to(struct file *in, loff_t *ppos,
28433 + struct pipe_inode_info *pipe, size_t len,
28434 + unsigned int flags)
28439 + err = do_splice_to(in, ppos, pipe, len, flags);
28441 + file_accessed(in);
28443 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
28447 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
28448 + loff_t *ppos, size_t len, unsigned int flags)
28453 + err = do_splice_from(pipe, out, ppos, len, flags);
28456 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
28460 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
28464 + /* file can be NULL */
28466 + err = vfs_fsync(file, datasync);
28470 + AuDebugOn(!file);
28471 + path = &file->f_path;
28473 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
28478 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
28479 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
28480 + struct file *h_file)
28483 + struct inode *h_inode;
28484 + struct super_block *h_sb;
28487 + err = vfsub_truncate(h_path, length);
28491 + h_inode = h_path->dentry->d_inode;
28492 + h_sb = h_inode->i_sb;
28494 + sb_start_write(h_sb);
28496 + err = locks_verify_truncate(h_inode, h_file, length);
28498 + err = security_path_truncate(h_path);
28501 + err = do_truncate(h_path->dentry, length, attr, h_file);
28505 + sb_end_write(h_sb);
28512 +/* ---------------------------------------------------------------------- */
28514 +struct au_vfsub_mkdir_args {
28516 + struct inode *dir;
28517 + struct path *path;
28521 +static void au_call_vfsub_mkdir(void *args)
28523 + struct au_vfsub_mkdir_args *a = args;
28524 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
28527 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
28529 + int err, do_sio, wkq_err;
28531 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
28533 + err = vfsub_mkdir(dir, path, mode);
28535 + struct au_vfsub_mkdir_args args = {
28541 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
28542 + if (unlikely(wkq_err))
28549 +struct au_vfsub_rmdir_args {
28551 + struct inode *dir;
28552 + struct path *path;
28555 +static void au_call_vfsub_rmdir(void *args)
28557 + struct au_vfsub_rmdir_args *a = args;
28558 + *a->errp = vfsub_rmdir(a->dir, a->path);
28561 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
28563 + int err, do_sio, wkq_err;
28565 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
28567 + err = vfsub_rmdir(dir, path);
28569 + struct au_vfsub_rmdir_args args = {
28574 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
28575 + if (unlikely(wkq_err))
28582 +/* ---------------------------------------------------------------------- */
28584 +struct notify_change_args {
28586 + struct path *path;
28587 + struct iattr *ia;
28588 + struct inode **delegated_inode;
28591 +static void call_notify_change(void *args)
28593 + struct notify_change_args *a = args;
28594 + struct inode *h_inode;
28596 + h_inode = a->path->dentry->d_inode;
28597 + IMustLock(h_inode);
28599 + *a->errp = -EPERM;
28600 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
28601 + *a->errp = notify_change(a->path->dentry, a->ia,
28602 + a->delegated_inode);
28604 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
28606 + AuTraceErr(*a->errp);
28609 +int vfsub_notify_change(struct path *path, struct iattr *ia,
28610 + struct inode **delegated_inode)
28613 + struct notify_change_args args = {
28617 + .delegated_inode = delegated_inode
28620 + call_notify_change(&args);
28625 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
28626 + struct inode **delegated_inode)
28628 + int err, wkq_err;
28629 + struct notify_change_args args = {
28633 + .delegated_inode = delegated_inode
28636 + wkq_err = au_wkq_wait(call_notify_change, &args);
28637 + if (unlikely(wkq_err))
28643 +/* ---------------------------------------------------------------------- */
28645 +struct unlink_args {
28647 + struct inode *dir;
28648 + struct path *path;
28649 + struct inode **delegated_inode;
28652 +static void call_unlink(void *args)
28654 + struct unlink_args *a = args;
28655 + struct dentry *d = a->path->dentry;
28656 + struct inode *h_inode;
28657 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
28658 + && d_count(d) == 1);
28660 + IMustLock(a->dir);
28662 + a->path->dentry = d->d_parent;
28663 + *a->errp = security_path_unlink(a->path, d);
28664 + a->path->dentry = d;
28665 + if (unlikely(*a->errp))
28668 + if (!stop_sillyrename)
28670 + h_inode = d->d_inode;
28675 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
28678 + struct path tmp = {
28679 + .dentry = d->d_parent,
28680 + .mnt = a->path->mnt
28682 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
28685 + if (!stop_sillyrename)
28690 + AuTraceErr(*a->errp);
28694 + * @dir: must be locked.
28695 + * @dentry: target dentry.
28697 +int vfsub_unlink(struct inode *dir, struct path *path,
28698 + struct inode **delegated_inode, int force)
28701 + struct unlink_args args = {
28705 + .delegated_inode = delegated_inode
28709 + call_unlink(&args);
28713 + wkq_err = au_wkq_wait(call_unlink, &args);
28714 + if (unlikely(wkq_err))
28720 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
28721 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
28722 +++ linux/fs/aufs/vfsub.h 2014-04-24 22:11:10.861935852 +0200
28725 + * Copyright (C) 2005-2014 Junjiro R. Okajima
28727 + * This program, aufs is free software; you can redistribute it and/or modify
28728 + * it under the terms of the GNU General Public License as published by
28729 + * the Free Software Foundation; either version 2 of the License, or
28730 + * (at your option) any later version.
28732 + * This program is distributed in the hope that it will be useful,
28733 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28734 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28735 + * GNU General Public License for more details.
28737 + * You should have received a copy of the GNU General Public License
28738 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28742 + * sub-routines for VFS
28745 +#ifndef __AUFS_VFSUB_H__
28746 +#define __AUFS_VFSUB_H__
28750 +#include <linux/fs.h>
28751 +#include <linux/lglock.h>
28752 +#include <linux/mount.h>
28753 +#include "debug.h"
28755 +/* copied from linux/fs/internal.h */
28756 +/* todo: BAD approach!! */
28757 +extern void __mnt_drop_write(struct vfsmount *);
28758 +extern spinlock_t inode_sb_list_lock;
28760 +/* ---------------------------------------------------------------------- */
28762 +/* lock subclass for lower inode */
28763 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
28764 +/* reduce? gave up. */
28766 + AuLsc_I_Begin = I_MUTEX_NONDIR2, /* 4 */
28767 + AuLsc_I_PARENT, /* lower inode, parent first */
28768 + AuLsc_I_PARENT2, /* copyup dirs */
28769 + AuLsc_I_PARENT3, /* copyup wh */
28775 +/* to debug easier, do not make them inlined functions */
28776 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
28777 +#define IMustLock(i) MtxMustLock(&(i)->i_mutex)
28779 +/* ---------------------------------------------------------------------- */
28781 +static inline void vfsub_drop_nlink(struct inode *inode)
28783 + AuDebugOn(!inode->i_nlink);
28784 + drop_nlink(inode);
28787 +static inline void vfsub_dead_dir(struct inode *inode)
28789 + AuDebugOn(!S_ISDIR(inode->i_mode));
28790 + inode->i_flags |= S_DEAD;
28791 + clear_nlink(inode);
28794 +static inline int vfsub_native_ro(struct inode *inode)
28796 + return (inode->i_sb->s_flags & MS_RDONLY)
28797 + || IS_RDONLY(inode)
28798 + /* || IS_APPEND(inode) */
28799 + || IS_IMMUTABLE(inode);
28802 +/* ---------------------------------------------------------------------- */
28804 +int vfsub_update_h_iattr(struct path *h_path, int *did);
28805 +struct file *vfsub_dentry_open(struct path *path, int flags);
28806 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
28807 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
28809 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
28812 +struct vfsub_lkup_one_args {
28813 + struct dentry **errp;
28814 + struct qstr *name;
28815 + struct dentry *parent;
28818 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
28819 + struct dentry *parent)
28821 + return vfsub_lookup_one_len(name->name, parent, name->len);
28824 +void vfsub_call_lkup_one(void *args);
28826 +/* ---------------------------------------------------------------------- */
28828 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
28832 + err = mnt_want_write(mnt);
28837 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
28840 + mnt_drop_write(mnt);
28844 +static inline void vfsub_mnt_drop_write_file(struct file *file)
28847 + mnt_drop_write_file(file);
28851 +/* ---------------------------------------------------------------------- */
28854 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
28855 + struct dentry *d2, struct au_hinode *hdir2);
28856 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
28857 + struct dentry *d2, struct au_hinode *hdir2);
28859 +int vfsub_create(struct inode *dir, struct path *path, int mode,
28861 +int vfsub_symlink(struct inode *dir, struct path *path,
28862 + const char *symname);
28863 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
28864 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
28865 + struct path *path, struct inode **delegated_inode);
28866 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
28867 + struct inode *hdir, struct path *path,
28868 + struct inode **delegated_inode);
28869 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
28870 +int vfsub_rmdir(struct inode *dir, struct path *path);
28872 +/* ---------------------------------------------------------------------- */
28874 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
28876 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
28878 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
28880 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
28882 +int vfsub_flush(struct file *file, fl_owner_t id);
28883 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
28885 +/* just for type-check */
28886 +static inline filldir_t au_diractor(int (*func)(struct dir_context *,
28887 + const char *, int, loff_t, u64,
28890 + return (filldir_t)func;
28894 +static inline loff_t vfsub_f_size_read(struct file *file)
28896 + return i_size_read(file_inode(file));
28899 +static inline unsigned int vfsub_file_flags(struct file *file)
28901 + unsigned int flags;
28903 + spin_lock(&file->f_lock);
28904 + flags = file->f_flags;
28905 + spin_unlock(&file->f_lock);
28910 +static inline void vfsub_file_accessed(struct file *h_file)
28912 + file_accessed(h_file);
28913 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
28916 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
28917 + struct dentry *h_dentry)
28919 + struct path h_path = {
28920 + .dentry = h_dentry,
28923 + touch_atime(&h_path);
28924 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
28927 +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts,
28930 + return update_time(h_inode, ts, flags);
28931 + /* no vfsub_update_h_iattr() since we don't have struct path */
28934 +long vfsub_splice_to(struct file *in, loff_t *ppos,
28935 + struct pipe_inode_info *pipe, size_t len,
28936 + unsigned int flags);
28937 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
28938 + loff_t *ppos, size_t len, unsigned int flags);
28940 +static inline long vfsub_truncate(struct path *path, loff_t length)
28944 + err = vfs_truncate(path, length);
28949 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
28950 + struct file *h_file);
28951 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
28953 +/* ---------------------------------------------------------------------- */
28955 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
28960 + err = vfs_llseek(file, offset, origin);
28965 +/* ---------------------------------------------------------------------- */
28967 +/* dirty workaround for strict type of fmode_t */
28973 +static inline unsigned int vfsub_fmode_to_uint(fmode_t fm)
28975 + union vfsub_fmu u = {
28979 + BUILD_BUG_ON(sizeof(u.fm) != sizeof(u.ui));
28984 +static inline fmode_t vfsub_uint_to_fmode(unsigned int ui)
28986 + union vfsub_fmu u = {
28993 +/* ---------------------------------------------------------------------- */
28995 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
28996 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
28997 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
28998 + struct inode **delegated_inode);
28999 +int vfsub_notify_change(struct path *path, struct iattr *ia,
29000 + struct inode **delegated_inode);
29001 +int vfsub_unlink(struct inode *dir, struct path *path,
29002 + struct inode **delegated_inode, int force);
29004 +#endif /* __KERNEL__ */
29005 +#endif /* __AUFS_VFSUB_H__ */
29006 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
29007 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
29008 +++ linux/fs/aufs/wbr_policy.c 2014-04-24 22:11:10.861935852 +0200
29011 + * Copyright (C) 2005-2014 Junjiro R. Okajima
29013 + * This program, aufs is free software; you can redistribute it and/or modify
29014 + * it under the terms of the GNU General Public License as published by
29015 + * the Free Software Foundation; either version 2 of the License, or
29016 + * (at your option) any later version.
29018 + * This program is distributed in the hope that it will be useful,
29019 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29020 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29021 + * GNU General Public License for more details.
29023 + * You should have received a copy of the GNU General Public License
29024 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29028 + * policies for selecting one among multiple writable branches
29031 +#include <linux/statfs.h>
29034 +/* subset of cpup_attr() */
29035 +static noinline_for_stack
29036 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
29040 + struct inode *h_isrc;
29042 + h_isrc = h_src->d_inode;
29043 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
29044 + ia.ia_mode = h_isrc->i_mode;
29045 + ia.ia_uid = h_isrc->i_uid;
29046 + ia.ia_gid = h_isrc->i_gid;
29047 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
29048 + au_cpup_attr_flags(h_path->dentry->d_inode, h_isrc->i_flags);
29049 + /* no delegation since it is just created */
29050 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
29052 + /* is this nfs only? */
29053 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
29054 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
29055 + ia.ia_mode = h_isrc->i_mode;
29056 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
29062 +#define AuCpdown_PARENT_OPQ 1
29063 +#define AuCpdown_WHED (1 << 1)
29064 +#define AuCpdown_MADE_DIR (1 << 2)
29065 +#define AuCpdown_DIROPQ (1 << 3)
29066 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
29067 +#define au_fset_cpdown(flags, name) \
29068 + do { (flags) |= AuCpdown_##name; } while (0)
29069 +#define au_fclr_cpdown(flags, name) \
29070 + do { (flags) &= ~AuCpdown_##name; } while (0)
29072 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
29073 + unsigned int *flags)
29076 + struct dentry *opq_dentry;
29078 + opq_dentry = au_diropq_create(dentry, bdst);
29079 + err = PTR_ERR(opq_dentry);
29080 + if (IS_ERR(opq_dentry))
29082 + dput(opq_dentry);
29083 + au_fset_cpdown(*flags, DIROPQ);
29089 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
29090 + struct inode *dir, aufs_bindex_t bdst)
29093 + struct path h_path;
29094 + struct au_branch *br;
29096 + br = au_sbr(dentry->d_sb, bdst);
29097 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
29098 + err = PTR_ERR(h_path.dentry);
29099 + if (IS_ERR(h_path.dentry))
29103 + if (h_path.dentry->d_inode) {
29104 + h_path.mnt = au_br_mnt(br);
29105 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
29108 + dput(h_path.dentry);
29114 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
29115 + struct au_pin *pin,
29116 + struct dentry *h_parent, void *arg)
29119 + aufs_bindex_t bopq, bstart;
29120 + struct path h_path;
29121 + struct dentry *parent;
29122 + struct inode *h_dir, *h_inode, *inode, *dir;
29123 + unsigned int *flags = arg;
29125 + bstart = au_dbstart(dentry);
29126 + /* dentry is di-locked */
29127 + parent = dget_parent(dentry);
29128 + dir = parent->d_inode;
29129 + h_dir = h_parent->d_inode;
29130 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
29131 + IMustLock(h_dir);
29133 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
29134 + if (unlikely(err < 0))
29136 + h_path.dentry = au_h_dptr(dentry, bdst);
29137 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
29138 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path,
29139 + S_IRWXU | S_IRUGO | S_IXUGO);
29140 + if (unlikely(err))
29142 + au_fset_cpdown(*flags, MADE_DIR);
29144 + bopq = au_dbdiropq(dentry);
29145 + au_fclr_cpdown(*flags, WHED);
29146 + au_fclr_cpdown(*flags, DIROPQ);
29147 + if (au_dbwh(dentry) == bdst)
29148 + au_fset_cpdown(*flags, WHED);
29149 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
29150 + au_fset_cpdown(*flags, PARENT_OPQ);
29151 + h_inode = h_path.dentry->d_inode;
29152 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
29153 + if (au_ftest_cpdown(*flags, WHED)) {
29154 + err = au_cpdown_dir_opq(dentry, bdst, flags);
29155 + if (unlikely(err)) {
29156 + mutex_unlock(&h_inode->i_mutex);
29161 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, bstart));
29162 + mutex_unlock(&h_inode->i_mutex);
29163 + if (unlikely(err))
29166 + if (au_ftest_cpdown(*flags, WHED)) {
29167 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
29168 + if (unlikely(err))
29172 + inode = dentry->d_inode;
29173 + if (au_ibend(inode) < bdst)
29174 + au_set_ibend(inode, bdst);
29175 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
29176 + au_hi_flags(inode, /*isdir*/1));
29177 + goto out; /* success */
29181 + if (au_ftest_cpdown(*flags, DIROPQ)) {
29182 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
29183 + rerr = au_diropq_remove(dentry, bdst);
29184 + mutex_unlock(&h_inode->i_mutex);
29185 + if (unlikely(rerr)) {
29186 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
29187 + dentry, bdst, rerr);
29193 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
29194 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
29195 + if (unlikely(rerr)) {
29196 + AuIOErr("failed removing %pd b%d (%d)\n",
29197 + dentry, bdst, rerr);
29202 + au_set_h_dptr(dentry, bdst, NULL);
29203 + if (au_dbend(dentry) == bdst)
29204 + au_update_dbend(dentry);
29210 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
29213 + unsigned int flags;
29216 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
29221 +/* ---------------------------------------------------------------------- */
29223 +/* policies for create */
29225 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
29227 + int err, i, j, ndentry;
29228 + aufs_bindex_t bopq;
29229 + struct au_dcsub_pages dpages;
29230 + struct au_dpage *dpage;
29231 + struct dentry **dentries, *parent, *d;
29233 + err = au_dpages_init(&dpages, GFP_NOFS);
29234 + if (unlikely(err))
29236 + parent = dget_parent(dentry);
29237 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
29238 + if (unlikely(err))
29242 + for (i = 0; i < dpages.ndpage; i++) {
29243 + dpage = dpages.dpages + i;
29244 + dentries = dpage->dentries;
29245 + ndentry = dpage->ndentry;
29246 + for (j = 0; j < ndentry; j++) {
29248 + di_read_lock_parent2(d, !AuLock_IR);
29249 + bopq = au_dbdiropq(d);
29250 + di_read_unlock(d, !AuLock_IR);
29251 + if (bopq >= 0 && bopq < err)
29258 + au_dpages_free(&dpages);
29263 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
29265 + for (; bindex >= 0; bindex--)
29266 + if (!au_br_rdonly(au_sbr(sb, bindex)))
29271 +/* top down parent */
29272 +static int au_wbr_create_tdp(struct dentry *dentry,
29273 + unsigned int flags __maybe_unused)
29276 + aufs_bindex_t bstart, bindex;
29277 + struct super_block *sb;
29278 + struct dentry *parent, *h_parent;
29280 + sb = dentry->d_sb;
29281 + bstart = au_dbstart(dentry);
29283 + if (!au_br_rdonly(au_sbr(sb, bstart)))
29287 + parent = dget_parent(dentry);
29288 + for (bindex = au_dbstart(parent); bindex < bstart; bindex++) {
29289 + h_parent = au_h_dptr(parent, bindex);
29290 + if (!h_parent || !h_parent->d_inode)
29293 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
29300 + /* bottom up here */
29301 + if (unlikely(err < 0)) {
29302 + err = au_wbr_bu(sb, bstart - 1);
29304 + err = au_wbr_nonopq(dentry, err);
29308 + AuDbg("b%d\n", err);
29312 +/* ---------------------------------------------------------------------- */
29314 +/* an exception for the policy other than tdp */
29315 +static int au_wbr_create_exp(struct dentry *dentry)
29318 + aufs_bindex_t bwh, bdiropq;
29319 + struct dentry *parent;
29322 + bwh = au_dbwh(dentry);
29323 + parent = dget_parent(dentry);
29324 + bdiropq = au_dbdiropq(parent);
29326 + if (bdiropq >= 0)
29327 + err = min(bdiropq, bwh);
29330 + AuDbg("%d\n", err);
29331 + } else if (bdiropq >= 0) {
29333 + AuDbg("%d\n", err);
29338 + err = au_wbr_nonopq(dentry, err);
29340 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
29343 + AuDbg("%d\n", err);
29347 +/* ---------------------------------------------------------------------- */
29350 +static int au_wbr_create_init_rr(struct super_block *sb)
29354 + err = au_wbr_bu(sb, au_sbend(sb));
29355 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
29358 + AuDbg("b%d\n", err);
29362 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
29366 + aufs_bindex_t bindex, bend;
29367 + struct super_block *sb;
29370 + err = au_wbr_create_exp(dentry);
29374 + sb = dentry->d_sb;
29375 + next = &au_sbi(sb)->si_wbr_rr_next;
29376 + bend = au_sbend(sb);
29378 + for (bindex = 0; bindex <= bend; bindex++) {
29379 + if (!au_ftest_wbr(flags, DIR)) {
29380 + err = atomic_dec_return(next) + 1;
29381 + /* modulo for 0 is meaningless */
29382 + if (unlikely(!err))
29383 + err = atomic_dec_return(next) + 1;
29385 + err = atomic_read(next);
29386 + AuDbg("%d\n", err);
29389 + AuDbg("%d\n", err);
29390 + if (!au_br_rdonly(au_sbr(sb, err)))
29396 + err = au_wbr_nonopq(dentry, err);
29399 + AuDbg("%d\n", err);
29403 +/* ---------------------------------------------------------------------- */
29405 +/* most free space */
29406 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
29408 + struct super_block *sb;
29409 + struct au_branch *br;
29410 + struct au_wbr_mfs *mfs;
29411 + struct dentry *h_parent;
29412 + aufs_bindex_t bindex, bend;
29414 + unsigned long long b, bavail;
29415 + struct path h_path;
29416 + /* reduce the stack usage */
29417 + struct kstatfs *st;
29419 + st = kmalloc(sizeof(*st), GFP_NOFS);
29420 + if (unlikely(!st)) {
29421 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
29426 + sb = dentry->d_sb;
29427 + mfs = &au_sbi(sb)->si_wbr_mfs;
29428 + MtxMustLock(&mfs->mfs_lock);
29429 + mfs->mfs_bindex = -EROFS;
29430 + mfs->mfsrr_bytes = 0;
29433 + bend = au_sbend(sb);
29435 + bindex = au_dbstart(parent);
29436 + bend = au_dbtaildir(parent);
29439 + for (; bindex <= bend; bindex++) {
29441 + h_parent = au_h_dptr(parent, bindex);
29442 + if (!h_parent || !h_parent->d_inode)
29445 + br = au_sbr(sb, bindex);
29446 + if (au_br_rdonly(br))
29449 + /* sb->s_root for NFS is unreliable */
29450 + h_path.mnt = au_br_mnt(br);
29451 + h_path.dentry = h_path.mnt->mnt_root;
29452 + err = vfs_statfs(&h_path, st);
29453 + if (unlikely(err)) {
29454 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
29458 + /* when the available size is equal, select the lower one */
29459 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
29460 + || sizeof(b) < sizeof(st->f_bsize));
29461 + b = st->f_bavail * st->f_bsize;
29462 + br->br_wbr->wbr_bytes = b;
29463 + if (b >= bavail) {
29465 + mfs->mfs_bindex = bindex;
29466 + mfs->mfs_jiffy = jiffies;
29470 + mfs->mfsrr_bytes = bavail;
29471 + AuDbg("b%d\n", mfs->mfs_bindex);
29475 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
29478 + struct dentry *parent;
29479 + struct super_block *sb;
29480 + struct au_wbr_mfs *mfs;
29482 + err = au_wbr_create_exp(dentry);
29486 + sb = dentry->d_sb;
29488 + if (au_ftest_wbr(flags, PARENT))
29489 + parent = dget_parent(dentry);
29490 + mfs = &au_sbi(sb)->si_wbr_mfs;
29491 + mutex_lock(&mfs->mfs_lock);
29492 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
29493 + || mfs->mfs_bindex < 0
29494 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
29495 + au_mfs(dentry, parent);
29496 + mutex_unlock(&mfs->mfs_lock);
29497 + err = mfs->mfs_bindex;
29501 + err = au_wbr_nonopq(dentry, err);
29504 + AuDbg("b%d\n", err);
29508 +static int au_wbr_create_init_mfs(struct super_block *sb)
29510 + struct au_wbr_mfs *mfs;
29512 + mfs = &au_sbi(sb)->si_wbr_mfs;
29513 + mutex_init(&mfs->mfs_lock);
29514 + mfs->mfs_jiffy = 0;
29515 + mfs->mfs_bindex = -EROFS;
29520 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
29522 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
29526 +/* ---------------------------------------------------------------------- */
29528 +/* most free space and then round robin */
29529 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
29532 + struct au_wbr_mfs *mfs;
29534 + err = au_wbr_create_mfs(dentry, flags);
29536 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
29537 + mutex_lock(&mfs->mfs_lock);
29538 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
29539 + err = au_wbr_create_rr(dentry, flags);
29540 + mutex_unlock(&mfs->mfs_lock);
29543 + AuDbg("b%d\n", err);
29547 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
29551 + au_wbr_create_init_mfs(sb); /* ignore */
29552 + err = au_wbr_create_init_rr(sb);
29557 +/* ---------------------------------------------------------------------- */
29559 +/* top down parent and most free space */
29560 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
29563 + unsigned long long b;
29564 + aufs_bindex_t bindex, bstart, bend;
29565 + struct super_block *sb;
29566 + struct dentry *parent, *h_parent;
29567 + struct au_branch *br;
29569 + err = au_wbr_create_tdp(dentry, flags);
29570 + if (unlikely(err < 0))
29572 + parent = dget_parent(dentry);
29573 + bstart = au_dbstart(parent);
29574 + bend = au_dbtaildir(parent);
29575 + if (bstart == bend)
29576 + goto out_parent; /* success */
29578 + e2 = au_wbr_create_mfs(dentry, flags);
29580 + goto out_parent; /* success */
29582 + /* when the available size is equal, select upper one */
29583 + sb = dentry->d_sb;
29584 + br = au_sbr(sb, err);
29585 + b = br->br_wbr->wbr_bytes;
29586 + AuDbg("b%d, %llu\n", err, b);
29588 + for (bindex = bstart; bindex <= bend; bindex++) {
29589 + h_parent = au_h_dptr(parent, bindex);
29590 + if (!h_parent || !h_parent->d_inode)
29593 + br = au_sbr(sb, bindex);
29594 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
29595 + b = br->br_wbr->wbr_bytes;
29597 + AuDbg("b%d, %llu\n", err, b);
29602 + err = au_wbr_nonopq(dentry, err);
29607 + AuDbg("b%d\n", err);
29611 +/* ---------------------------------------------------------------------- */
29614 + * - top down parent
29615 + * - most free space with parent
29616 + * - most free space round-robin regardless parent
29618 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
29621 + unsigned long long watermark;
29622 + struct super_block *sb;
29623 + struct au_branch *br;
29624 + struct au_wbr_mfs *mfs;
29626 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
29627 + if (unlikely(err < 0))
29630 + sb = dentry->d_sb;
29631 + br = au_sbr(sb, err);
29632 + mfs = &au_sbi(sb)->si_wbr_mfs;
29633 + mutex_lock(&mfs->mfs_lock);
29634 + watermark = mfs->mfsrr_watermark;
29635 + mutex_unlock(&mfs->mfs_lock);
29636 + if (br->br_wbr->wbr_bytes < watermark)
29637 + /* regardless the parent dir */
29638 + err = au_wbr_create_mfsrr(dentry, flags);
29641 + AuDbg("b%d\n", err);
29645 +/* ---------------------------------------------------------------------- */
29647 +/* policies for copyup */
29649 +/* top down parent */
29650 +static int au_wbr_copyup_tdp(struct dentry *dentry)
29652 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
29655 +/* bottom up parent */
29656 +static int au_wbr_copyup_bup(struct dentry *dentry)
29659 + aufs_bindex_t bindex, bstart;
29660 + struct dentry *parent, *h_parent;
29661 + struct super_block *sb;
29664 + sb = dentry->d_sb;
29665 + parent = dget_parent(dentry);
29666 + bstart = au_dbstart(parent);
29667 + for (bindex = au_dbstart(dentry); bindex >= bstart; bindex--) {
29668 + h_parent = au_h_dptr(parent, bindex);
29669 + if (!h_parent || !h_parent->d_inode)
29672 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
29679 + /* bottom up here */
29680 + if (unlikely(err < 0))
29681 + err = au_wbr_bu(sb, bstart - 1);
29683 + AuDbg("b%d\n", err);
29688 +static int au_wbr_copyup_bu(struct dentry *dentry)
29691 + aufs_bindex_t bstart;
29693 + bstart = au_dbstart(dentry);
29694 + err = au_wbr_bu(dentry->d_sb, bstart);
29695 + AuDbg("b%d\n", err);
29696 + if (err > bstart)
29697 + err = au_wbr_nonopq(dentry, err);
29699 + AuDbg("b%d\n", err);
29703 +/* ---------------------------------------------------------------------- */
29705 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
29706 + [AuWbrCopyup_TDP] = {
29707 + .copyup = au_wbr_copyup_tdp
29709 + [AuWbrCopyup_BUP] = {
29710 + .copyup = au_wbr_copyup_bup
29712 + [AuWbrCopyup_BU] = {
29713 + .copyup = au_wbr_copyup_bu
29717 +struct au_wbr_create_operations au_wbr_create_ops[] = {
29718 + [AuWbrCreate_TDP] = {
29719 + .create = au_wbr_create_tdp
29721 + [AuWbrCreate_RR] = {
29722 + .create = au_wbr_create_rr,
29723 + .init = au_wbr_create_init_rr
29725 + [AuWbrCreate_MFS] = {
29726 + .create = au_wbr_create_mfs,
29727 + .init = au_wbr_create_init_mfs,
29728 + .fin = au_wbr_create_fin_mfs
29730 + [AuWbrCreate_MFSV] = {
29731 + .create = au_wbr_create_mfs,
29732 + .init = au_wbr_create_init_mfs,
29733 + .fin = au_wbr_create_fin_mfs
29735 + [AuWbrCreate_MFSRR] = {
29736 + .create = au_wbr_create_mfsrr,
29737 + .init = au_wbr_create_init_mfsrr,
29738 + .fin = au_wbr_create_fin_mfs
29740 + [AuWbrCreate_MFSRRV] = {
29741 + .create = au_wbr_create_mfsrr,
29742 + .init = au_wbr_create_init_mfsrr,
29743 + .fin = au_wbr_create_fin_mfs
29745 + [AuWbrCreate_PMFS] = {
29746 + .create = au_wbr_create_pmfs,
29747 + .init = au_wbr_create_init_mfs,
29748 + .fin = au_wbr_create_fin_mfs
29750 + [AuWbrCreate_PMFSV] = {
29751 + .create = au_wbr_create_pmfs,
29752 + .init = au_wbr_create_init_mfs,
29753 + .fin = au_wbr_create_fin_mfs
29755 + [AuWbrCreate_PMFSRR] = {
29756 + .create = au_wbr_create_pmfsrr,
29757 + .init = au_wbr_create_init_mfsrr,
29758 + .fin = au_wbr_create_fin_mfs
29760 + [AuWbrCreate_PMFSRRV] = {
29761 + .create = au_wbr_create_pmfsrr,
29762 + .init = au_wbr_create_init_mfsrr,
29763 + .fin = au_wbr_create_fin_mfs
29766 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
29767 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
29768 +++ linux/fs/aufs/whout.c 2014-04-24 22:11:10.861935852 +0200
29771 + * Copyright (C) 2005-2014 Junjiro R. Okajima
29773 + * This program, aufs is free software; you can redistribute it and/or modify
29774 + * it under the terms of the GNU General Public License as published by
29775 + * the Free Software Foundation; either version 2 of the License, or
29776 + * (at your option) any later version.
29778 + * This program is distributed in the hope that it will be useful,
29779 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29780 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29781 + * GNU General Public License for more details.
29783 + * You should have received a copy of the GNU General Public License
29784 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29788 + * whiteout for logical deletion and opaque directory
29793 +#define WH_MASK S_IRUGO
29796 + * If a directory contains this file, then it is opaque. We start with the
29797 + * .wh. flag so that it is blocked by lookup.
29799 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
29800 + sizeof(AUFS_WH_DIROPQ) - 1);
29803 + * generate whiteout name, which is NOT terminated by NULL.
29804 + * @name: original d_name.name
29805 + * @len: original d_name.len
29806 + * @wh: whiteout qstr
29807 + * returns zero when succeeds, otherwise error.
29808 + * succeeded value as wh->name should be freed by kfree().
29810 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
29814 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
29815 + return -ENAMETOOLONG;
29817 + wh->len = name->len + AUFS_WH_PFX_LEN;
29818 + p = kmalloc(wh->len, GFP_NOFS);
29821 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
29822 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
29829 +/* ---------------------------------------------------------------------- */
29832 + * test if the @wh_name exists under @h_parent.
29833 + * @try_sio specifies the necessary of super-io.
29835 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name,
29836 + struct au_branch *br, int try_sio)
29839 + struct dentry *wh_dentry;
29842 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
29844 + wh_dentry = au_sio_lkup_one(wh_name, h_parent, br);
29845 + err = PTR_ERR(wh_dentry);
29846 + if (IS_ERR(wh_dentry))
29850 + if (!wh_dentry->d_inode)
29851 + goto out_wh; /* success */
29854 + if (S_ISREG(wh_dentry->d_inode->i_mode))
29855 + goto out_wh; /* success */
29858 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
29859 + wh_dentry, wh_dentry->d_inode->i_mode);
29868 + * test if the @h_dentry sets opaque or not.
29870 +int au_diropq_test(struct dentry *h_dentry, struct au_branch *br)
29873 + struct inode *h_dir;
29875 + h_dir = h_dentry->d_inode;
29876 + err = au_wh_test(h_dentry, &diropq_name, br,
29877 + au_test_h_perm_sio(h_dir, MAY_EXEC));
29882 + * returns a negative dentry whose name is unique and temporary.
29884 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
29885 + struct qstr *prefix)
29887 + struct dentry *dentry;
29889 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
29891 + /* strict atomic_t is unnecessary here */
29892 + static unsigned short cnt;
29895 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
29898 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
29899 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
29900 + dentry = ERR_PTR(-ENAMETOOLONG);
29901 + if (unlikely(qs.len > NAME_MAX))
29903 + dentry = ERR_PTR(-ENOMEM);
29904 + name = kmalloc(qs.len + 1, GFP_NOFS);
29905 + if (unlikely(!name))
29909 + /* doubly whiteout-ed */
29910 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
29911 + p = name + AUFS_WH_PFX_LEN * 2;
29912 + memcpy(p, prefix->name, prefix->len);
29913 + p += prefix->len;
29915 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
29918 + for (i = 0; i < 3; i++) {
29919 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
29920 + dentry = au_sio_lkup_one(&qs, h_parent, br);
29921 + if (IS_ERR(dentry) || !dentry->d_inode)
29925 + /* pr_warn("could not get random name\n"); */
29926 + dentry = ERR_PTR(-EEXIST);
29927 + AuDbg("%.*s\n", AuLNPair(&qs));
29931 + if (name != defname)
29934 + AuTraceErrPtr(dentry);
29939 + * rename the @h_dentry on @br to the whiteouted temporary name.
29941 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
29944 + struct path h_path = {
29945 + .mnt = au_br_mnt(br)
29947 + struct inode *h_dir, *delegated;
29948 + struct dentry *h_parent;
29950 + h_parent = h_dentry->d_parent; /* dir inode is locked */
29951 + h_dir = h_parent->d_inode;
29952 + IMustLock(h_dir);
29954 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
29955 + err = PTR_ERR(h_path.dentry);
29956 + if (IS_ERR(h_path.dentry))
29959 + /* under the same dir, no need to lock_rename() */
29960 + delegated = NULL;
29961 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated);
29963 + if (unlikely(err == -EWOULDBLOCK)) {
29964 + pr_warn("cannot retry for NFSv4 delegation"
29965 + " for an internal rename\n");
29968 + dput(h_path.dentry);
29975 +/* ---------------------------------------------------------------------- */
29977 + * functions for removing a whiteout
29980 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
29983 + struct inode *delegated;
29986 + * forces superio when the dir has a sticky bit.
29987 + * this may be a violation of unix fs semantics.
29989 + force = (h_dir->i_mode & S_ISVTX)
29990 + && !uid_eq(current_fsuid(), h_path->dentry->d_inode->i_uid);
29991 + delegated = NULL;
29992 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
29993 + if (unlikely(err == -EWOULDBLOCK)) {
29994 + pr_warn("cannot retry for NFSv4 delegation"
29995 + " for an internal unlink\n");
30001 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
30002 + struct dentry *dentry)
30006 + err = do_unlink_wh(h_dir, h_path);
30007 + if (!err && dentry)
30008 + au_set_dbwh(dentry, -1);
30013 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
30014 + struct au_branch *br)
30017 + struct path h_path = {
30018 + .mnt = au_br_mnt(br)
30022 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
30023 + if (IS_ERR(h_path.dentry))
30024 + err = PTR_ERR(h_path.dentry);
30026 + if (h_path.dentry->d_inode
30027 + && S_ISREG(h_path.dentry->d_inode->i_mode))
30028 + err = do_unlink_wh(h_parent->d_inode, &h_path);
30029 + dput(h_path.dentry);
30035 +/* ---------------------------------------------------------------------- */
30037 + * initialize/clean whiteout for a branch
30040 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
30044 + struct inode *delegated;
30046 + if (!whpath->dentry->d_inode)
30050 + err = vfsub_rmdir(h_dir, whpath);
30052 + delegated = NULL;
30053 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
30054 + if (unlikely(err == -EWOULDBLOCK)) {
30055 + pr_warn("cannot retry for NFSv4 delegation"
30056 + " for an internal unlink\n");
30060 + if (unlikely(err))
30061 + pr_warn("failed removing %pd (%d), ignored.\n",
30062 + whpath->dentry, err);
30065 +static int test_linkable(struct dentry *h_root)
30067 + struct inode *h_dir = h_root->d_inode;
30069 + if (h_dir->i_op->link)
30072 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
30073 + h_root, au_sbtype(h_root->d_sb));
30077 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
30078 +static int au_whdir(struct inode *h_dir, struct path *path)
30083 + if (!path->dentry->d_inode) {
30084 + int mode = S_IRWXU;
30086 + if (au_test_nfs(path->dentry->d_sb))
30088 + err = vfsub_mkdir(h_dir, path, mode);
30089 + } else if (S_ISDIR(path->dentry->d_inode->i_mode))
30092 + pr_err("unknown %pd exists\n", path->dentry);
30097 +struct au_wh_base {
30098 + const struct qstr *name;
30099 + struct dentry *dentry;
30102 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
30103 + struct path *h_path)
30105 + h_path->dentry = base[AuBrWh_BASE].dentry;
30106 + au_wh_clean(h_dir, h_path, /*isdir*/0);
30107 + h_path->dentry = base[AuBrWh_PLINK].dentry;
30108 + au_wh_clean(h_dir, h_path, /*isdir*/1);
30109 + h_path->dentry = base[AuBrWh_ORPH].dentry;
30110 + au_wh_clean(h_dir, h_path, /*isdir*/1);
30114 + * returns tri-state,
30115 + * minus: error, caller should print the mesage
30117 + * plus: error, caller should NOT print the mesage
30119 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
30120 + int do_plink, struct au_wh_base base[],
30121 + struct path *h_path)
30124 + struct inode *h_dir;
30126 + h_dir = h_root->d_inode;
30127 + h_path->dentry = base[AuBrWh_BASE].dentry;
30128 + au_wh_clean(h_dir, h_path, /*isdir*/0);
30129 + h_path->dentry = base[AuBrWh_PLINK].dentry;
30131 + err = test_linkable(h_root);
30132 + if (unlikely(err)) {
30137 + err = au_whdir(h_dir, h_path);
30138 + if (unlikely(err))
30140 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
30142 + au_wh_clean(h_dir, h_path, /*isdir*/1);
30143 + h_path->dentry = base[AuBrWh_ORPH].dentry;
30144 + err = au_whdir(h_dir, h_path);
30145 + if (unlikely(err))
30147 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
30154 + * for the moment, aufs supports the branch filesystem which does not support
30155 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
30156 + * copyup failed. finally, such filesystem will not be used as the writable
30159 + * returns tri-state, see above.
30161 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
30162 + int do_plink, struct au_wh_base base[],
30163 + struct path *h_path)
30166 + struct inode *h_dir;
30168 + WbrWhMustWriteLock(wbr);
30170 + err = test_linkable(h_root);
30171 + if (unlikely(err)) {
30177 + * todo: should this create be done in /sbin/mount.aufs helper?
30180 + h_dir = h_root->d_inode;
30181 + if (!base[AuBrWh_BASE].dentry->d_inode) {
30182 + h_path->dentry = base[AuBrWh_BASE].dentry;
30183 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
30184 + } else if (S_ISREG(base[AuBrWh_BASE].dentry->d_inode->i_mode))
30187 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
30188 + if (unlikely(err))
30191 + h_path->dentry = base[AuBrWh_PLINK].dentry;
30193 + err = au_whdir(h_dir, h_path);
30194 + if (unlikely(err))
30196 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
30198 + au_wh_clean(h_dir, h_path, /*isdir*/1);
30199 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
30201 + h_path->dentry = base[AuBrWh_ORPH].dentry;
30202 + err = au_whdir(h_dir, h_path);
30203 + if (unlikely(err))
30205 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
30212 + * initialize the whiteout base file/dir for @br.
30214 +int au_wh_init(struct au_branch *br, struct super_block *sb)
30217 + const unsigned char do_plink
30218 + = !!au_opt_test(au_mntflags(sb), PLINK);
30219 + struct inode *h_dir;
30220 + struct path path = br->br_path;
30221 + struct dentry *h_root = path.dentry;
30222 + struct au_wbr *wbr = br->br_wbr;
30223 + static const struct qstr base_name[] = {
30224 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
30225 + sizeof(AUFS_BASE_NAME) - 1),
30226 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
30227 + sizeof(AUFS_PLINKDIR_NAME) - 1),
30228 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
30229 + sizeof(AUFS_ORPHDIR_NAME) - 1)
30231 + struct au_wh_base base[] = {
30232 + [AuBrWh_BASE] = {
30233 + .name = base_name + AuBrWh_BASE,
30236 + [AuBrWh_PLINK] = {
30237 + .name = base_name + AuBrWh_PLINK,
30240 + [AuBrWh_ORPH] = {
30241 + .name = base_name + AuBrWh_ORPH,
30247 + WbrWhMustWriteLock(wbr);
30249 + for (i = 0; i < AuBrWh_Last; i++) {
30250 + /* doubly whiteouted */
30251 + struct dentry *d;
30253 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
30254 + err = PTR_ERR(d);
30258 + base[i].dentry = d;
30260 + && wbr->wbr_wh[i]
30261 + && wbr->wbr_wh[i] != base[i].dentry);
30265 + for (i = 0; i < AuBrWh_Last; i++) {
30266 + dput(wbr->wbr_wh[i]);
30267 + wbr->wbr_wh[i] = NULL;
30271 + if (!au_br_writable(br->br_perm)) {
30272 + h_dir = h_root->d_inode;
30273 + au_wh_init_ro(h_dir, base, &path);
30274 + } else if (!au_br_wh_linkable(br->br_perm)) {
30275 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
30281 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
30287 + goto out; /* success */
30290 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
30291 + err, h_root, au_sbtype(h_root->d_sb));
30293 + for (i = 0; i < AuBrWh_Last; i++)
30294 + dput(base[i].dentry);
30298 +/* ---------------------------------------------------------------------- */
30300 + * whiteouts are all hard-linked usually.
30301 + * when its link count reaches a ceiling, we create a new whiteout base
30302 + * asynchronously.
30305 +struct reinit_br_wh {
30306 + struct super_block *sb;
30307 + struct au_branch *br;
30310 +static void reinit_br_wh(void *arg)
30313 + aufs_bindex_t bindex;
30314 + struct path h_path;
30315 + struct reinit_br_wh *a = arg;
30316 + struct au_wbr *wbr;
30317 + struct inode *dir, *delegated;
30318 + struct dentry *h_root;
30319 + struct au_hinode *hdir;
30322 + wbr = a->br->br_wbr;
30323 + /* big aufs lock */
30324 + si_noflush_write_lock(a->sb);
30325 + if (!au_br_writable(a->br->br_perm))
30327 + bindex = au_br_index(a->sb, a->br->br_id);
30328 + if (unlikely(bindex < 0))
30331 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
30332 + dir = a->sb->s_root->d_inode;
30333 + hdir = au_hi(dir, bindex);
30334 + h_root = au_h_dptr(a->sb->s_root, bindex);
30335 + AuDebugOn(h_root != au_br_dentry(a->br));
30337 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
30338 + wbr_wh_write_lock(wbr);
30339 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
30342 + h_path.dentry = wbr->wbr_whbase;
30343 + h_path.mnt = au_br_mnt(a->br);
30344 + delegated = NULL;
30345 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
30347 + if (unlikely(err == -EWOULDBLOCK)) {
30348 + pr_warn("cannot retry for NFSv4 delegation"
30349 + " for an internal unlink\n");
30353 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
30356 + dput(wbr->wbr_whbase);
30357 + wbr->wbr_whbase = NULL;
30359 + err = au_wh_init(a->br, a->sb);
30360 + wbr_wh_write_unlock(wbr);
30361 + au_hn_imtx_unlock(hdir);
30362 + di_read_unlock(a->sb->s_root, AuLock_IR);
30366 + atomic_dec(&wbr->wbr_wh_running);
30367 + atomic_dec(&a->br->br_count);
30368 + si_write_unlock(a->sb);
30369 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
30371 + if (unlikely(err))
30372 + AuIOErr("err %d\n", err);
30375 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
30377 + int do_dec, wkq_err;
30378 + struct reinit_br_wh *arg;
30381 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
30384 + /* ignore ENOMEM */
30385 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
30388 + * dec(wh_running), kfree(arg) and dec(br_count)
30389 + * in reinit function
30393 + atomic_inc(&br->br_count);
30394 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
30395 + if (unlikely(wkq_err)) {
30396 + atomic_dec(&br->br_wbr->wbr_wh_running);
30397 + atomic_dec(&br->br_count);
30405 + atomic_dec(&br->br_wbr->wbr_wh_running);
30408 +/* ---------------------------------------------------------------------- */
30411 + * create the whiteout @wh.
30413 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
30414 + struct dentry *wh)
30417 + struct path h_path = {
30420 + struct au_branch *br;
30421 + struct au_wbr *wbr;
30422 + struct dentry *h_parent;
30423 + struct inode *h_dir, *delegated;
30425 + h_parent = wh->d_parent; /* dir inode is locked */
30426 + h_dir = h_parent->d_inode;
30427 + IMustLock(h_dir);
30429 + br = au_sbr(sb, bindex);
30430 + h_path.mnt = au_br_mnt(br);
30431 + wbr = br->br_wbr;
30432 + wbr_wh_read_lock(wbr);
30433 + if (wbr->wbr_whbase) {
30434 + delegated = NULL;
30435 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
30436 + if (unlikely(err == -EWOULDBLOCK)) {
30437 + pr_warn("cannot retry for NFSv4 delegation"
30438 + " for an internal link\n");
30441 + if (!err || err != -EMLINK)
30444 + /* link count full. re-initialize br_whbase. */
30445 + kick_reinit_br_wh(sb, br);
30448 + /* return this error in this context */
30449 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
30452 + wbr_wh_read_unlock(wbr);
30456 +/* ---------------------------------------------------------------------- */
30459 + * create or remove the diropq.
30461 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
30462 + unsigned int flags)
30464 + struct dentry *opq_dentry, *h_dentry;
30465 + struct super_block *sb;
30466 + struct au_branch *br;
30469 + sb = dentry->d_sb;
30470 + br = au_sbr(sb, bindex);
30471 + h_dentry = au_h_dptr(dentry, bindex);
30472 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
30473 + if (IS_ERR(opq_dentry))
30476 + if (au_ftest_diropq(flags, CREATE)) {
30477 + err = link_or_create_wh(sb, bindex, opq_dentry);
30479 + au_set_dbdiropq(dentry, bindex);
30480 + goto out; /* success */
30483 + struct path tmp = {
30484 + .dentry = opq_dentry,
30485 + .mnt = au_br_mnt(br)
30487 + err = do_unlink_wh(au_h_iptr(dentry->d_inode, bindex), &tmp);
30489 + au_set_dbdiropq(dentry, -1);
30491 + dput(opq_dentry);
30492 + opq_dentry = ERR_PTR(err);
30495 + return opq_dentry;
30498 +struct do_diropq_args {
30499 + struct dentry **errp;
30500 + struct dentry *dentry;
30501 + aufs_bindex_t bindex;
30502 + unsigned int flags;
30505 +static void call_do_diropq(void *args)
30507 + struct do_diropq_args *a = args;
30508 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
30511 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
30512 + unsigned int flags)
30514 + struct dentry *diropq, *h_dentry;
30516 + h_dentry = au_h_dptr(dentry, bindex);
30517 + if (!au_test_h_perm_sio(h_dentry->d_inode, MAY_EXEC | MAY_WRITE))
30518 + diropq = do_diropq(dentry, bindex, flags);
30521 + struct do_diropq_args args = {
30523 + .dentry = dentry,
30524 + .bindex = bindex,
30528 + wkq_err = au_wkq_wait(call_do_diropq, &args);
30529 + if (unlikely(wkq_err))
30530 + diropq = ERR_PTR(wkq_err);
30536 +/* ---------------------------------------------------------------------- */
30539 + * lookup whiteout dentry.
30540 + * @h_parent: lower parent dentry which must exist and be locked
30541 + * @base_name: name of dentry which will be whiteouted
30542 + * returns dentry for whiteout.
30544 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
30545 + struct au_branch *br)
30548 + struct qstr wh_name;
30549 + struct dentry *wh_dentry;
30551 + err = au_wh_name_alloc(&wh_name, base_name);
30552 + wh_dentry = ERR_PTR(err);
30554 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
30555 + kfree(wh_name.name);
30557 + return wh_dentry;
30561 + * link/create a whiteout for @dentry on @bindex.
30563 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
30564 + struct dentry *h_parent)
30566 + struct dentry *wh_dentry;
30567 + struct super_block *sb;
30570 + sb = dentry->d_sb;
30571 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
30572 + if (!IS_ERR(wh_dentry) && !wh_dentry->d_inode) {
30573 + err = link_or_create_wh(sb, bindex, wh_dentry);
30575 + au_set_dbwh(dentry, bindex);
30578 + wh_dentry = ERR_PTR(err);
30582 + return wh_dentry;
30585 +/* ---------------------------------------------------------------------- */
30587 +/* Delete all whiteouts in this directory on branch bindex. */
30588 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
30589 + aufs_bindex_t bindex, struct au_branch *br)
30592 + unsigned long ul, n;
30593 + struct qstr wh_name;
30595 + struct hlist_head *head;
30596 + struct au_vdir_wh *pos;
30597 + struct au_vdir_destr *str;
30600 + p = (void *)__get_free_page(GFP_NOFS);
30601 + wh_name.name = p;
30602 + if (unlikely(!wh_name.name))
30606 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
30607 + p += AUFS_WH_PFX_LEN;
30608 + n = whlist->nh_num;
30609 + head = whlist->nh_head;
30610 + for (ul = 0; !err && ul < n; ul++, head++) {
30611 + hlist_for_each_entry(pos, head, wh_hash) {
30612 + if (pos->wh_bindex != bindex)
30615 + str = &pos->wh_str;
30616 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
30617 + memcpy(p, str->name, str->len);
30618 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
30619 + err = unlink_wh_name(h_dentry, &wh_name, br);
30624 + AuIOErr("whiteout name too long %.*s\n",
30625 + str->len, str->name);
30630 + free_page((unsigned long)wh_name.name);
30636 +struct del_wh_children_args {
30638 + struct dentry *h_dentry;
30639 + struct au_nhash *whlist;
30640 + aufs_bindex_t bindex;
30641 + struct au_branch *br;
30644 +static void call_del_wh_children(void *args)
30646 + struct del_wh_children_args *a = args;
30647 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
30650 +/* ---------------------------------------------------------------------- */
30652 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
30654 + struct au_whtmp_rmdir *whtmp;
30656 + unsigned int rdhash;
30658 + SiMustAnyLock(sb);
30660 + whtmp = kmalloc(sizeof(*whtmp), gfp);
30661 + if (unlikely(!whtmp)) {
30662 + whtmp = ERR_PTR(-ENOMEM);
30666 + whtmp->dir = NULL;
30667 + whtmp->br = NULL;
30668 + whtmp->wh_dentry = NULL;
30669 + /* no estimation for dir size */
30670 + rdhash = au_sbi(sb)->si_rdhash;
30672 + rdhash = AUFS_RDHASH_DEF;
30673 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
30674 + if (unlikely(err)) {
30676 + whtmp = ERR_PTR(err);
30683 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
30686 + atomic_dec(&whtmp->br->br_count);
30687 + dput(whtmp->wh_dentry);
30688 + iput(whtmp->dir);
30689 + au_nhash_wh_free(&whtmp->whlist);
30694 + * rmdir the whiteouted temporary named dir @h_dentry.
30695 + * @whlist: whiteouted children.
30697 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
30698 + struct dentry *wh_dentry, struct au_nhash *whlist)
30701 + struct path h_tmp;
30702 + struct inode *wh_inode, *h_dir;
30703 + struct au_branch *br;
30705 + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
30706 + IMustLock(h_dir);
30708 + br = au_sbr(dir->i_sb, bindex);
30709 + wh_inode = wh_dentry->d_inode;
30710 + mutex_lock_nested(&wh_inode->i_mutex, AuLsc_I_CHILD);
30713 + * someone else might change some whiteouts while we were sleeping.
30714 + * it means this whlist may have an obsoleted entry.
30716 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
30717 + err = del_wh_children(wh_dentry, whlist, bindex, br);
30720 + struct del_wh_children_args args = {
30722 + .h_dentry = wh_dentry,
30723 + .whlist = whlist,
30724 + .bindex = bindex,
30728 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
30729 + if (unlikely(wkq_err))
30732 + mutex_unlock(&wh_inode->i_mutex);
30735 + h_tmp.dentry = wh_dentry;
30736 + h_tmp.mnt = au_br_mnt(br);
30737 + err = vfsub_rmdir(h_dir, &h_tmp);
30741 + if (au_ibstart(dir) == bindex) {
30742 + /* todo: dir->i_mutex is necessary */
30743 + au_cpup_attr_timesizes(dir);
30744 + vfsub_drop_nlink(dir);
30746 + return 0; /* success */
30749 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
30753 +static void call_rmdir_whtmp(void *args)
30756 + aufs_bindex_t bindex;
30757 + struct au_whtmp_rmdir *a = args;
30758 + struct super_block *sb;
30759 + struct dentry *h_parent;
30760 + struct inode *h_dir;
30761 + struct au_hinode *hdir;
30763 + /* rmdir by nfsd may cause deadlock with this i_mutex */
30764 + /* mutex_lock(&a->dir->i_mutex); */
30766 + sb = a->dir->i_sb;
30767 + si_read_lock(sb, !AuLock_FLUSH);
30768 + if (!au_br_writable(a->br->br_perm))
30770 + bindex = au_br_index(sb, a->br->br_id);
30771 + if (unlikely(bindex < 0))
30775 + ii_write_lock_parent(a->dir);
30776 + h_parent = dget_parent(a->wh_dentry);
30777 + h_dir = h_parent->d_inode;
30778 + hdir = au_hi(a->dir, bindex);
30779 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
30780 + if (unlikely(err))
30782 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
30783 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
30786 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
30787 + au_hn_imtx_unlock(hdir);
30788 + vfsub_mnt_drop_write(au_br_mnt(a->br));
30792 + ii_write_unlock(a->dir);
30794 + /* mutex_unlock(&a->dir->i_mutex); */
30795 + au_whtmp_rmdir_free(a);
30796 + si_read_unlock(sb);
30797 + au_nwt_done(&au_sbi(sb)->si_nowait);
30798 + if (unlikely(err))
30799 + AuIOErr("err %d\n", err);
30802 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
30803 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
30806 + struct super_block *sb;
30810 + /* all post-process will be done in do_rmdir_whtmp(). */
30812 + args->dir = au_igrab(dir);
30813 + args->br = au_sbr(sb, bindex);
30814 + atomic_inc(&args->br->br_count);
30815 + args->wh_dentry = dget(wh_dentry);
30816 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
30817 + if (unlikely(wkq_err)) {
30818 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
30819 + au_whtmp_rmdir_free(args);
30822 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
30823 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
30824 +++ linux/fs/aufs/whout.h 2014-04-24 22:11:10.861935852 +0200
30827 + * Copyright (C) 2005-2014 Junjiro R. Okajima
30829 + * This program, aufs is free software; you can redistribute it and/or modify
30830 + * it under the terms of the GNU General Public License as published by
30831 + * the Free Software Foundation; either version 2 of the License, or
30832 + * (at your option) any later version.
30834 + * This program is distributed in the hope that it will be useful,
30835 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30836 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30837 + * GNU General Public License for more details.
30839 + * You should have received a copy of the GNU General Public License
30840 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30844 + * whiteout for logical deletion and opaque directory
30847 +#ifndef __AUFS_WHOUT_H__
30848 +#define __AUFS_WHOUT_H__
30855 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
30857 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name,
30858 + struct au_branch *br, int try_sio);
30859 +int au_diropq_test(struct dentry *h_dentry, struct au_branch *br);
30860 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
30861 + struct qstr *prefix);
30862 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
30863 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
30864 + struct dentry *dentry);
30865 +int au_wh_init(struct au_branch *br, struct super_block *sb);
30867 +/* diropq flags */
30868 +#define AuDiropq_CREATE 1
30869 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
30870 +#define au_fset_diropq(flags, name) \
30871 + do { (flags) |= AuDiropq_##name; } while (0)
30872 +#define au_fclr_diropq(flags, name) \
30873 + do { (flags) &= ~AuDiropq_##name; } while (0)
30875 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
30876 + unsigned int flags);
30877 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
30878 + struct au_branch *br);
30879 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
30880 + struct dentry *h_parent);
30882 +/* real rmdir for the whiteout-ed dir */
30883 +struct au_whtmp_rmdir {
30884 + struct inode *dir;
30885 + struct au_branch *br;
30886 + struct dentry *wh_dentry;
30887 + struct au_nhash whlist;
30890 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
30891 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
30892 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
30893 + struct dentry *wh_dentry, struct au_nhash *whlist);
30894 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
30895 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
30897 +/* ---------------------------------------------------------------------- */
30899 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
30900 + aufs_bindex_t bindex)
30902 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
30905 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
30907 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
30910 +#endif /* __KERNEL__ */
30911 +#endif /* __AUFS_WHOUT_H__ */
30912 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
30913 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
30914 +++ linux/fs/aufs/wkq.c 2014-04-24 22:11:10.861935852 +0200
30917 + * Copyright (C) 2005-2014 Junjiro R. Okajima
30919 + * This program, aufs is free software; you can redistribute it and/or modify
30920 + * it under the terms of the GNU General Public License as published by
30921 + * the Free Software Foundation; either version 2 of the License, or
30922 + * (at your option) any later version.
30924 + * This program is distributed in the hope that it will be useful,
30925 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30926 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30927 + * GNU General Public License for more details.
30929 + * You should have received a copy of the GNU General Public License
30930 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30934 + * workqueue for asynchronous/super-io operations
30935 + * todo: try new dredential scheme
30938 +#include <linux/module.h>
30941 +/* internal workqueue named AUFS_WKQ_NAME */
30943 +static struct workqueue_struct *au_wkq;
30945 +struct au_wkinfo {
30946 + struct work_struct wk;
30947 + struct kobject *kobj;
30949 + unsigned int flags; /* see wkq.h */
30951 + au_wkq_func_t func;
30954 + struct completion *comp;
30957 +/* ---------------------------------------------------------------------- */
30959 +static void wkq_func(struct work_struct *wk)
30961 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
30963 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
30964 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
30966 + wkinfo->func(wkinfo->args);
30967 + if (au_ftest_wkq(wkinfo->flags, WAIT))
30968 + complete(wkinfo->comp);
30970 + kobject_put(wkinfo->kobj);
30971 + module_put(THIS_MODULE); /* todo: ?? */
30977 + * Since struct completion is large, try allocating it dynamically.
30979 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
30980 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
30982 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
30984 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
30986 + init_completion(*comp);
30987 + wkinfo->comp = *comp;
30993 +static void au_wkq_comp_free(struct completion *comp)
31001 +#define AuWkqCompDeclare(name) \
31002 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
31003 + struct completion *comp = &_ ## name
31005 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
31007 + wkinfo->comp = *comp;
31011 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
31015 +#endif /* 4KSTACKS */
31017 +static void au_wkq_run(struct au_wkinfo *wkinfo)
31019 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
31020 + if (au_wkq_test()) {
31021 + AuWarn1("wkq from wkq, due to a dead dir by UDBA?\n");
31022 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
31025 + au_dbg_verify_kthread();
31027 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
31028 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
31029 + queue_work(au_wkq, &wkinfo->wk);
31031 + INIT_WORK(&wkinfo->wk, wkq_func);
31032 + schedule_work(&wkinfo->wk);
31037 + * Be careful. It is easy to make deadlock happen.
31038 + * processA: lock, wkq and wait
31039 + * processB: wkq and wait, lock in wkq
31042 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
31045 + AuWkqCompDeclare(comp);
31046 + struct au_wkinfo wkinfo = {
31052 + err = au_wkq_comp_alloc(&wkinfo, &comp);
31054 + au_wkq_run(&wkinfo);
31055 + /* no timeout, no interrupt */
31056 + wait_for_completion(wkinfo.comp);
31057 + au_wkq_comp_free(comp);
31058 + destroy_work_on_stack(&wkinfo.wk);
31066 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
31067 + * problem in a concurrent umounting.
31069 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
31070 + unsigned int flags)
31073 + struct au_wkinfo *wkinfo;
31075 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
31078 + * wkq_func() must free this wkinfo.
31079 + * it highly depends upon the implementation of workqueue.
31082 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
31084 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
31085 + wkinfo->flags = flags & ~AuWkq_WAIT;
31086 + wkinfo->func = func;
31087 + wkinfo->args = args;
31088 + wkinfo->comp = NULL;
31089 + kobject_get(wkinfo->kobj);
31090 + __module_get(THIS_MODULE); /* todo: ?? */
31092 + au_wkq_run(wkinfo);
31095 + au_nwt_done(&au_sbi(sb)->si_nowait);
31101 +/* ---------------------------------------------------------------------- */
31103 +void au_nwt_init(struct au_nowait_tasks *nwt)
31105 + atomic_set(&nwt->nw_len, 0);
31106 + /* smp_mb(); */ /* atomic_set */
31107 + init_waitqueue_head(&nwt->nw_wq);
31110 +void au_wkq_fin(void)
31112 + destroy_workqueue(au_wkq);
31115 +int __init au_wkq_init(void)
31120 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
31121 + if (IS_ERR(au_wkq))
31122 + err = PTR_ERR(au_wkq);
31123 + else if (!au_wkq)
31128 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
31129 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
31130 +++ linux/fs/aufs/wkq.h 2014-04-24 22:11:10.861935852 +0200
31133 + * Copyright (C) 2005-2014 Junjiro R. Okajima
31135 + * This program, aufs is free software; you can redistribute it and/or modify
31136 + * it under the terms of the GNU General Public License as published by
31137 + * the Free Software Foundation; either version 2 of the License, or
31138 + * (at your option) any later version.
31140 + * This program is distributed in the hope that it will be useful,
31141 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31142 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31143 + * GNU General Public License for more details.
31145 + * You should have received a copy of the GNU General Public License
31146 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31150 + * workqueue for asynchronous/super-io operations
31151 + * todo: try new credentials management scheme
31154 +#ifndef __AUFS_WKQ_H__
31155 +#define __AUFS_WKQ_H__
31159 +struct super_block;
31161 +/* ---------------------------------------------------------------------- */
31164 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
31166 +struct au_nowait_tasks {
31168 + wait_queue_head_t nw_wq;
31171 +/* ---------------------------------------------------------------------- */
31173 +typedef void (*au_wkq_func_t)(void *args);
31176 +#define AuWkq_WAIT 1
31177 +#define AuWkq_NEST (1 << 1)
31178 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
31179 +#define au_fset_wkq(flags, name) \
31180 + do { (flags) |= AuWkq_##name; } while (0)
31181 +#define au_fclr_wkq(flags, name) \
31182 + do { (flags) &= ~AuWkq_##name; } while (0)
31184 +#ifndef CONFIG_AUFS_HNOTIFY
31186 +#define AuWkq_NEST 0
31190 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
31191 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
31192 + unsigned int flags);
31193 +void au_nwt_init(struct au_nowait_tasks *nwt);
31194 +int __init au_wkq_init(void);
31195 +void au_wkq_fin(void);
31197 +/* ---------------------------------------------------------------------- */
31199 +static inline int au_wkq_test(void)
31201 + return current->flags & PF_WQ_WORKER;
31204 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
31206 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
31209 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
31211 + if (atomic_dec_and_test(&nwt->nw_len))
31212 + wake_up_all(&nwt->nw_wq);
31215 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
31217 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
31221 +#endif /* __KERNEL__ */
31222 +#endif /* __AUFS_WKQ_H__ */
31223 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
31224 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
31225 +++ linux/fs/aufs/xino.c 2014-04-24 22:11:10.861935852 +0200
31228 + * Copyright (C) 2005-2014 Junjiro R. Okajima
31230 + * This program, aufs is free software; you can redistribute it and/or modify
31231 + * it under the terms of the GNU General Public License as published by
31232 + * the Free Software Foundation; either version 2 of the License, or
31233 + * (at your option) any later version.
31235 + * This program is distributed in the hope that it will be useful,
31236 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31237 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31238 + * GNU General Public License for more details.
31240 + * You should have received a copy of the GNU General Public License
31241 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31245 + * external inode number translation table and bitmap
31248 +#include <linux/seq_file.h>
31249 +#include <linux/statfs.h>
31252 +/* todo: unnecessary to support mmap_sem since kernel-space? */
31253 +ssize_t xino_fread(au_readf_t func, struct file *file, void *kbuf, size_t size,
31257 + mm_segment_t oldfs;
31264 + oldfs = get_fs();
31265 + set_fs(KERNEL_DS);
31267 + /* todo: signal_pending? */
31268 + err = func(file, buf.u, size, pos);
31269 + } while (err == -EAGAIN || err == -EINTR);
31272 +#if 0 /* reserved for future use */
31274 + fsnotify_access(file->f_dentry);
31280 +/* ---------------------------------------------------------------------- */
31282 +static ssize_t do_xino_fwrite(au_writef_t func, struct file *file, void *kbuf,
31283 + size_t size, loff_t *pos)
31286 + mm_segment_t oldfs;
31289 + const char __user *u;
31293 + oldfs = get_fs();
31294 + set_fs(KERNEL_DS);
31296 + /* todo: signal_pending? */
31297 + err = func(file, buf.u, size, pos);
31298 + } while (err == -EAGAIN || err == -EINTR);
31301 +#if 0 /* reserved for future use */
31303 + fsnotify_modify(file->f_dentry);
31309 +struct do_xino_fwrite_args {
31311 + au_writef_t func;
31312 + struct file *file;
31318 +static void call_do_xino_fwrite(void *args)
31320 + struct do_xino_fwrite_args *a = args;
31321 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
31324 +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size,
31329 + /* todo: signal block and no wkq? */
31330 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
31332 + err = do_xino_fwrite(func, file, buf, size, pos);
31336 + * it breaks RLIMIT_FSIZE and normal user's limit,
31337 + * users should care about quota and real 'filesystem full.'
31340 + struct do_xino_fwrite_args args = {
31349 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
31350 + if (unlikely(wkq_err))
31357 +/* ---------------------------------------------------------------------- */
31360 + * create a new xinofile at the same place/path as @base_file.
31362 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src)
31364 + struct file *file;
31365 + struct dentry *base, *parent;
31366 + struct inode *dir, *delegated;
31367 + struct qstr *name;
31368 + struct path path;
31371 + base = base_file->f_dentry;
31372 + parent = base->d_parent; /* dir inode is locked */
31373 + dir = parent->d_inode;
31376 + file = ERR_PTR(-EINVAL);
31377 + name = &base->d_name;
31378 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
31379 + if (IS_ERR(path.dentry)) {
31380 + file = (void *)path.dentry;
31381 + pr_err("%pd lookup err %ld\n",
31382 + base, PTR_ERR(path.dentry));
31386 + /* no need to mnt_want_write() since we call dentry_open() later */
31387 + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL);
31388 + if (unlikely(err)) {
31389 + file = ERR_PTR(err);
31390 + pr_err("%pd create err %d\n", base, err);
31394 + path.mnt = base_file->f_path.mnt;
31395 + file = vfsub_dentry_open(&path,
31396 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
31397 + /* | __FMODE_NONOTIFY */);
31398 + if (IS_ERR(file)) {
31399 + pr_err("%pd open err %ld\n", base, PTR_ERR(file));
31403 + delegated = NULL;
31404 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
31405 + if (unlikely(err == -EWOULDBLOCK)) {
31406 + pr_warn("cannot retry for NFSv4 delegation"
31407 + " for an internal unlink\n");
31410 + if (unlikely(err)) {
31411 + pr_err("%pd unlink err %d\n", base, err);
31416 + /* no one can touch copy_src xino */
31417 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
31418 + if (unlikely(err)) {
31419 + pr_err("%pd copy err %d\n", base, err);
31423 + goto out_dput; /* success */
31427 + file = ERR_PTR(err);
31429 + dput(path.dentry);
31434 +struct au_xino_lock_dir {
31435 + struct au_hinode *hdir;
31436 + struct dentry *parent;
31437 + struct mutex *mtx;
31440 +static void au_xino_lock_dir(struct super_block *sb, struct file *xino,
31441 + struct au_xino_lock_dir *ldir)
31443 + aufs_bindex_t brid, bindex;
31445 + ldir->hdir = NULL;
31447 + brid = au_xino_brid(sb);
31449 + bindex = au_br_index(sb, brid);
31450 + if (bindex >= 0) {
31451 + ldir->hdir = au_hi(sb->s_root->d_inode, bindex);
31452 + au_hn_imtx_lock_nested(ldir->hdir, AuLsc_I_PARENT);
31454 + ldir->parent = dget_parent(xino->f_dentry);
31455 + ldir->mtx = &ldir->parent->d_inode->i_mutex;
31456 + mutex_lock_nested(ldir->mtx, AuLsc_I_PARENT);
31460 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
31463 + au_hn_imtx_unlock(ldir->hdir);
31465 + mutex_unlock(ldir->mtx);
31466 + dput(ldir->parent);
31470 +/* ---------------------------------------------------------------------- */
31472 +/* trucate xino files asynchronously */
31474 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
31477 + unsigned long jiffy;
31479 + aufs_bindex_t bi, bend;
31480 + struct kstatfs *st;
31481 + struct au_branch *br;
31482 + struct file *new_xino, *file;
31483 + struct super_block *h_sb;
31484 + struct au_xino_lock_dir ldir;
31487 + st = kzalloc(sizeof(*st), GFP_NOFS);
31488 + if (unlikely(!st))
31492 + bend = au_sbend(sb);
31493 + if (unlikely(bindex < 0 || bend < bindex))
31495 + br = au_sbr(sb, bindex);
31496 + file = br->br_xino.xi_file;
31500 + err = vfs_statfs(&file->f_path, st);
31501 + if (unlikely(err))
31502 + AuErr1("statfs err %d, ignored\n", err);
31504 + blocks = file_inode(file)->i_blocks;
31505 + pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
31506 + bindex, (u64)blocks, st->f_bfree, st->f_blocks);
31508 + au_xino_lock_dir(sb, file, &ldir);
31509 + /* mnt_want_write() is unnecessary here */
31510 + new_xino = au_xino_create2(file, file);
31511 + au_xino_unlock_dir(&ldir);
31512 + err = PTR_ERR(new_xino);
31513 + if (IS_ERR(new_xino)) {
31514 + pr_err("err %d, ignored\n", err);
31519 + br->br_xino.xi_file = new_xino;
31521 + h_sb = au_br_sb(br);
31522 + for (bi = 0; bi <= bend; bi++) {
31523 + if (unlikely(bi == bindex))
31525 + br = au_sbr(sb, bi);
31526 + if (au_br_sb(br) != h_sb)
31529 + fput(br->br_xino.xi_file);
31530 + br->br_xino.xi_file = new_xino;
31531 + get_file(new_xino);
31534 + err = vfs_statfs(&new_xino->f_path, st);
31536 + pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
31537 + bindex, (u64)file_inode(new_xino)->i_blocks,
31538 + st->f_bfree, st->f_blocks);
31539 + if (file_inode(new_xino)->i_blocks < blocks)
31540 + au_sbi(sb)->si_xino_jiffy = jiffy;
31542 + AuErr1("statfs err %d, ignored\n", err);
31550 +struct xino_do_trunc_args {
31551 + struct super_block *sb;
31552 + struct au_branch *br;
31555 +static void xino_do_trunc(void *_args)
31557 + struct xino_do_trunc_args *args = _args;
31558 + struct super_block *sb;
31559 + struct au_branch *br;
31560 + struct inode *dir;
31562 + aufs_bindex_t bindex;
31566 + dir = sb->s_root->d_inode;
31569 + si_noflush_write_lock(sb);
31570 + ii_read_lock_parent(dir);
31571 + bindex = au_br_index(sb, br->br_id);
31572 + err = au_xino_trunc(sb, bindex);
31573 + ii_read_unlock(dir);
31574 + if (unlikely(err))
31575 + pr_warn("err b%d, (%d)\n", bindex, err);
31576 + atomic_dec(&br->br_xino_running);
31577 + atomic_dec(&br->br_count);
31578 + si_write_unlock(sb);
31579 + au_nwt_done(&au_sbi(sb)->si_nowait);
31583 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
31586 + struct kstatfs st;
31587 + struct au_sbinfo *sbinfo;
31589 + /* todo: si_xino_expire and the ratio should be customizable */
31590 + sbinfo = au_sbi(sb);
31591 + if (time_before(jiffies,
31592 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
31595 + /* truncation border */
31596 + err = vfs_statfs(&br->br_xino.xi_file->f_path, &st);
31597 + if (unlikely(err)) {
31598 + AuErr1("statfs err %d, ignored\n", err);
31601 + if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC)
31607 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
31609 + struct xino_do_trunc_args *args;
31612 + if (!xino_trunc_test(sb, br))
31615 + if (atomic_inc_return(&br->br_xino_running) > 1)
31618 + /* lock and kfree() will be called in trunc_xino() */
31619 + args = kmalloc(sizeof(*args), GFP_NOFS);
31620 + if (unlikely(!args)) {
31621 + AuErr1("no memory\n");
31625 + atomic_inc(&br->br_count);
31628 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
31630 + return; /* success */
31632 + pr_err("wkq %d\n", wkq_err);
31633 + atomic_dec(&br->br_count);
31638 + atomic_dec(&br->br_xino_running);
31641 +/* ---------------------------------------------------------------------- */
31643 +static int au_xino_do_write(au_writef_t write, struct file *file,
31644 + ino_t h_ino, ino_t ino)
31650 + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) {
31651 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
31654 + pos *= sizeof(ino);
31655 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos);
31656 + if (sz == sizeof(ino))
31657 + return 0; /* success */
31659 + AuIOErr("write failed (%zd)\n", sz);
31664 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
31665 + * at the position of @h_ino.
31666 + * even if @ino is zero, it is written to the xinofile and means no entry.
31667 + * if the size of the xino file on a specific filesystem exceeds the watermark,
31668 + * try truncating it.
31670 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
31674 + unsigned int mnt_flags;
31675 + struct au_branch *br;
31677 + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max)
31678 + || ((loff_t)-1) > 0);
31679 + SiMustAnyLock(sb);
31681 + mnt_flags = au_mntflags(sb);
31682 + if (!au_opt_test(mnt_flags, XINO))
31685 + br = au_sbr(sb, bindex);
31686 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
31689 + if (au_opt_test(mnt_flags, TRUNC_XINO)
31690 + && au_test_fs_trunc_xino(au_br_sb(br)))
31691 + xino_try_trunc(sb, br);
31692 + return 0; /* success */
31695 + AuIOErr("write failed (%d)\n", err);
31699 +/* ---------------------------------------------------------------------- */
31701 +/* aufs inode number bitmap */
31703 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
31704 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
31708 + AuDebugOn(bit < 0 || page_bits <= bit);
31709 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
31713 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
31715 + AuDebugOn(ino < AUFS_FIRST_INO);
31716 + ino -= AUFS_FIRST_INO;
31717 + *pindex = ino / page_bits;
31718 + *bit = ino % page_bits;
31721 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
31726 + struct au_sbinfo *sbinfo;
31727 + struct file *xib;
31728 + unsigned long *p;
31730 + sbinfo = au_sbi(sb);
31731 + MtxMustLock(&sbinfo->si_xib_mtx);
31732 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
31733 + || !au_opt_test(sbinfo->si_mntflags, XINO));
31735 + if (pindex == sbinfo->si_xib_last_pindex)
31738 + xib = sbinfo->si_xib;
31739 + p = sbinfo->si_xib_buf;
31740 + pos = sbinfo->si_xib_last_pindex;
31741 + pos *= PAGE_SIZE;
31742 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
31743 + if (unlikely(sz != PAGE_SIZE))
31747 + pos *= PAGE_SIZE;
31748 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
31749 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
31751 + memset(p, 0, PAGE_SIZE);
31752 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
31754 + if (sz == PAGE_SIZE) {
31755 + sbinfo->si_xib_last_pindex = pindex;
31756 + return 0; /* success */
31760 + AuIOErr1("write failed (%zd)\n", sz);
31767 +/* ---------------------------------------------------------------------- */
31769 +static void au_xib_clear_bit(struct inode *inode)
31772 + unsigned long pindex;
31773 + struct super_block *sb;
31774 + struct au_sbinfo *sbinfo;
31776 + AuDebugOn(inode->i_nlink);
31778 + sb = inode->i_sb;
31779 + xib_calc_bit(inode->i_ino, &pindex, &bit);
31780 + AuDebugOn(page_bits <= bit);
31781 + sbinfo = au_sbi(sb);
31782 + mutex_lock(&sbinfo->si_xib_mtx);
31783 + err = xib_pindex(sb, pindex);
31785 + clear_bit(bit, sbinfo->si_xib_buf);
31786 + sbinfo->si_xib_next_bit = bit;
31788 + mutex_unlock(&sbinfo->si_xib_mtx);
31791 +/* for s_op->delete_inode() */
31792 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
31795 + unsigned int mnt_flags;
31796 + aufs_bindex_t bindex, bend, bi;
31797 + unsigned char try_trunc;
31798 + struct au_iinfo *iinfo;
31799 + struct super_block *sb;
31800 + struct au_hinode *hi;
31801 + struct inode *h_inode;
31802 + struct au_branch *br;
31803 + au_writef_t xwrite;
31805 + sb = inode->i_sb;
31806 + mnt_flags = au_mntflags(sb);
31807 + if (!au_opt_test(mnt_flags, XINO)
31808 + || inode->i_ino == AUFS_ROOT_INO)
31812 + au_xigen_inc(inode);
31813 + au_xib_clear_bit(inode);
31816 + iinfo = au_ii(inode);
31820 + bindex = iinfo->ii_bstart;
31824 + xwrite = au_sbi(sb)->si_xwrite;
31825 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
31826 + hi = iinfo->ii_hinode + bindex;
31827 + bend = iinfo->ii_bend;
31828 + for (; bindex <= bend; bindex++, hi++) {
31829 + h_inode = hi->hi_inode;
31831 + || (!unlinked && h_inode->i_nlink))
31834 + /* inode may not be revalidated */
31835 + bi = au_br_index(sb, hi->hi_id);
31839 + br = au_sbr(sb, bi);
31840 + err = au_xino_do_write(xwrite, br->br_xino.xi_file,
31841 + h_inode->i_ino, /*ino*/0);
31842 + if (!err && try_trunc
31843 + && au_test_fs_trunc_xino(au_br_sb(br)))
31844 + xino_try_trunc(sb, br);
31848 +/* get an unused inode number from bitmap */
31849 +ino_t au_xino_new_ino(struct super_block *sb)
31852 + unsigned long *p, pindex, ul, pend;
31853 + struct au_sbinfo *sbinfo;
31854 + struct file *file;
31855 + int free_bit, err;
31857 + if (!au_opt_test(au_mntflags(sb), XINO))
31858 + return iunique(sb, AUFS_FIRST_INO);
31860 + sbinfo = au_sbi(sb);
31861 + mutex_lock(&sbinfo->si_xib_mtx);
31862 + p = sbinfo->si_xib_buf;
31863 + free_bit = sbinfo->si_xib_next_bit;
31864 + if (free_bit < page_bits && !test_bit(free_bit, p))
31865 + goto out; /* success */
31866 + free_bit = find_first_zero_bit(p, page_bits);
31867 + if (free_bit < page_bits)
31868 + goto out; /* success */
31870 + pindex = sbinfo->si_xib_last_pindex;
31871 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
31872 + err = xib_pindex(sb, ul);
31873 + if (unlikely(err))
31875 + free_bit = find_first_zero_bit(p, page_bits);
31876 + if (free_bit < page_bits)
31877 + goto out; /* success */
31880 + file = sbinfo->si_xib;
31881 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
31882 + for (ul = pindex + 1; ul <= pend; ul++) {
31883 + err = xib_pindex(sb, ul);
31884 + if (unlikely(err))
31886 + free_bit = find_first_zero_bit(p, page_bits);
31887 + if (free_bit < page_bits)
31888 + goto out; /* success */
31893 + set_bit(free_bit, p);
31894 + sbinfo->si_xib_next_bit = free_bit + 1;
31895 + pindex = sbinfo->si_xib_last_pindex;
31896 + mutex_unlock(&sbinfo->si_xib_mtx);
31897 + ino = xib_calc_ino(pindex, free_bit);
31898 + AuDbg("i%lu\n", (unsigned long)ino);
31901 + mutex_unlock(&sbinfo->si_xib_mtx);
31907 + * read @ino from xinofile for the specified branch{@sb, @bindex}
31908 + * at the position of @h_ino.
31909 + * if @ino does not exist and @do_new is true, get new one.
31911 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
31917 + struct file *file;
31918 + struct au_sbinfo *sbinfo;
31921 + if (!au_opt_test(au_mntflags(sb), XINO))
31922 + return 0; /* no xino */
31925 + sbinfo = au_sbi(sb);
31927 + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) {
31928 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
31931 + pos *= sizeof(*ino);
31933 + file = au_sbr(sb, bindex)->br_xino.xi_file;
31934 + if (vfsub_f_size_read(file) < pos + sizeof(*ino))
31935 + return 0; /* no ino */
31937 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
31938 + if (sz == sizeof(*ino))
31939 + return 0; /* success */
31942 + if (unlikely(sz >= 0)) {
31944 + AuIOErr("xino read error (%zd)\n", sz);
31950 +/* ---------------------------------------------------------------------- */
31952 +/* create and set a new xino file */
31954 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent)
31956 + struct file *file;
31957 + struct dentry *h_parent, *d;
31958 + struct inode *h_dir;
31962 + * at mount-time, and the xino file is the default path,
31963 + * hnotify is disabled so we have no notify events to ignore.
31964 + * when a user specified the xino, we cannot get au_hdir to be ignored.
31966 + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
31967 + /* | __FMODE_NONOTIFY */,
31968 + S_IRUGO | S_IWUGO);
31969 + if (IS_ERR(file)) {
31971 + pr_err("open %s(%ld)\n", fname, PTR_ERR(file));
31975 + /* keep file count */
31976 + h_parent = dget_parent(file->f_dentry);
31977 + h_dir = h_parent->d_inode;
31978 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
31979 + /* mnt_want_write() is unnecessary here */
31980 + /* no delegation since it is just created */
31981 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL, /*force*/0);
31982 + mutex_unlock(&h_dir->i_mutex);
31984 + if (unlikely(err)) {
31986 + pr_err("unlink %s(%d)\n", fname, err);
31991 + d = file->f_dentry;
31992 + if (unlikely(sb == d->d_sb)) {
31994 + pr_err("%s must be outside\n", fname);
31997 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
31999 + pr_err("xino doesn't support %s(%s)\n",
32000 + fname, au_sbtype(d->d_sb));
32003 + return file; /* success */
32007 + file = ERR_PTR(err);
32012 + * find another branch who is on the same filesystem of the specified
32013 + * branch{@btgt}. search until @bend.
32015 +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
32016 + aufs_bindex_t bend)
32018 + aufs_bindex_t bindex;
32019 + struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
32021 + for (bindex = 0; bindex < btgt; bindex++)
32022 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
32024 + for (bindex++; bindex <= bend; bindex++)
32025 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
32030 +/* ---------------------------------------------------------------------- */
32033 + * initialize the xinofile for the specified branch @br
32034 + * at the place/path where @base_file indicates.
32035 + * test whether another branch is on the same filesystem or not,
32036 + * if @do_test is true.
32038 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
32039 + struct file *base_file, int do_test)
32043 + aufs_bindex_t bend, bindex;
32044 + struct au_branch *shared_br, *b;
32045 + struct file *file;
32046 + struct super_block *tgt_sb;
32048 + shared_br = NULL;
32049 + bend = au_sbend(sb);
32051 + tgt_sb = au_br_sb(br);
32052 + for (bindex = 0; bindex <= bend; bindex++) {
32053 + b = au_sbr(sb, bindex);
32054 + if (tgt_sb == au_br_sb(b)) {
32061 + if (!shared_br || !shared_br->br_xino.xi_file) {
32062 + struct au_xino_lock_dir ldir;
32064 + au_xino_lock_dir(sb, base_file, &ldir);
32065 + /* mnt_want_write() is unnecessary here */
32066 + file = au_xino_create2(base_file, NULL);
32067 + au_xino_unlock_dir(&ldir);
32068 + err = PTR_ERR(file);
32069 + if (IS_ERR(file))
32071 + br->br_xino.xi_file = file;
32073 + br->br_xino.xi_file = shared_br->br_xino.xi_file;
32074 + get_file(br->br_xino.xi_file);
32077 + ino = AUFS_ROOT_INO;
32078 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
32080 + if (unlikely(err)) {
32081 + fput(br->br_xino.xi_file);
32082 + br->br_xino.xi_file = NULL;
32089 +/* ---------------------------------------------------------------------- */
32091 +/* trucate a xino bitmap file */
32094 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
32098 + unsigned long pindex;
32099 + loff_t pos, pend;
32100 + struct au_sbinfo *sbinfo;
32103 + unsigned long *p;
32106 + sbinfo = au_sbi(sb);
32107 + MtxMustLock(&sbinfo->si_xib_mtx);
32108 + p = sbinfo->si_xib_buf;
32109 + func = sbinfo->si_xread;
32110 + pend = vfsub_f_size_read(file);
32112 + while (pos < pend) {
32113 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
32115 + if (unlikely(sz <= 0))
32119 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
32120 + if (unlikely(*ino < AUFS_FIRST_INO))
32123 + xib_calc_bit(*ino, &pindex, &bit);
32124 + AuDebugOn(page_bits <= bit);
32125 + err = xib_pindex(sb, pindex);
32137 +static int xib_restore(struct super_block *sb)
32140 + aufs_bindex_t bindex, bend;
32144 + page = (void *)__get_free_page(GFP_NOFS);
32145 + if (unlikely(!page))
32149 + bend = au_sbend(sb);
32150 + for (bindex = 0; !err && bindex <= bend; bindex++)
32151 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
32152 + err = do_xib_restore
32153 + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page);
32155 + AuDbg("b%d\n", bindex);
32156 + free_page((unsigned long)page);
32162 +int au_xib_trunc(struct super_block *sb)
32167 + struct au_xino_lock_dir ldir;
32168 + struct au_sbinfo *sbinfo;
32169 + unsigned long *p;
32170 + struct file *file;
32172 + SiMustWriteLock(sb);
32175 + sbinfo = au_sbi(sb);
32176 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
32179 + file = sbinfo->si_xib;
32180 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
32183 + au_xino_lock_dir(sb, file, &ldir);
32184 + /* mnt_want_write() is unnecessary here */
32185 + file = au_xino_create2(sbinfo->si_xib, NULL);
32186 + au_xino_unlock_dir(&ldir);
32187 + err = PTR_ERR(file);
32188 + if (IS_ERR(file))
32190 + fput(sbinfo->si_xib);
32191 + sbinfo->si_xib = file;
32193 + p = sbinfo->si_xib_buf;
32194 + memset(p, 0, PAGE_SIZE);
32196 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
32197 + if (unlikely(sz != PAGE_SIZE)) {
32199 + AuIOErr("err %d\n", err);
32205 + mutex_lock(&sbinfo->si_xib_mtx);
32206 + /* mnt_want_write() is unnecessary here */
32207 + err = xib_restore(sb);
32208 + mutex_unlock(&sbinfo->si_xib_mtx);
32214 +/* ---------------------------------------------------------------------- */
32217 + * xino mount option handlers
32219 +static au_readf_t find_readf(struct file *h_file)
32221 + const struct file_operations *fop = h_file->f_op;
32224 + return fop->read;
32225 + if (fop->aio_read)
32226 + return do_sync_read;
32227 + return ERR_PTR(-ENOSYS);
32230 +static au_writef_t find_writef(struct file *h_file)
32232 + const struct file_operations *fop = h_file->f_op;
32235 + return fop->write;
32236 + if (fop->aio_write)
32237 + return do_sync_write;
32238 + return ERR_PTR(-ENOSYS);
32242 +static void xino_clear_xib(struct super_block *sb)
32244 + struct au_sbinfo *sbinfo;
32246 + SiMustWriteLock(sb);
32248 + sbinfo = au_sbi(sb);
32249 + sbinfo->si_xread = NULL;
32250 + sbinfo->si_xwrite = NULL;
32251 + if (sbinfo->si_xib)
32252 + fput(sbinfo->si_xib);
32253 + sbinfo->si_xib = NULL;
32254 + free_page((unsigned long)sbinfo->si_xib_buf);
32255 + sbinfo->si_xib_buf = NULL;
32258 +static int au_xino_set_xib(struct super_block *sb, struct file *base)
32262 + struct au_sbinfo *sbinfo;
32263 + struct file *file;
32265 + SiMustWriteLock(sb);
32267 + sbinfo = au_sbi(sb);
32268 + file = au_xino_create2(base, sbinfo->si_xib);
32269 + err = PTR_ERR(file);
32270 + if (IS_ERR(file))
32272 + if (sbinfo->si_xib)
32273 + fput(sbinfo->si_xib);
32274 + sbinfo->si_xib = file;
32275 + sbinfo->si_xread = find_readf(file);
32276 + sbinfo->si_xwrite = find_writef(file);
32279 + if (!sbinfo->si_xib_buf)
32280 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
32281 + if (unlikely(!sbinfo->si_xib_buf))
32284 + sbinfo->si_xib_last_pindex = 0;
32285 + sbinfo->si_xib_next_bit = 0;
32286 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
32288 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
32289 + PAGE_SIZE, &pos);
32290 + if (unlikely(err != PAGE_SIZE))
32294 + goto out; /* success */
32297 + free_page((unsigned long)sbinfo->si_xib_buf);
32298 + sbinfo->si_xib_buf = NULL;
32302 + fput(sbinfo->si_xib);
32303 + sbinfo->si_xib = NULL;
32304 + sbinfo->si_xread = NULL;
32305 + sbinfo->si_xwrite = NULL;
32310 +/* xino for each branch */
32311 +static void xino_clear_br(struct super_block *sb)
32313 + aufs_bindex_t bindex, bend;
32314 + struct au_branch *br;
32316 + bend = au_sbend(sb);
32317 + for (bindex = 0; bindex <= bend; bindex++) {
32318 + br = au_sbr(sb, bindex);
32319 + if (!br || !br->br_xino.xi_file)
32322 + fput(br->br_xino.xi_file);
32323 + br->br_xino.xi_file = NULL;
32327 +static int au_xino_set_br(struct super_block *sb, struct file *base)
32331 + aufs_bindex_t bindex, bend, bshared;
32333 + struct file *old, *new;
32335 + struct au_branch *br;
32336 + struct inode *inode;
32337 + au_writef_t writef;
32339 + SiMustWriteLock(sb);
32342 + bend = au_sbend(sb);
32343 + fpair = kcalloc(bend + 1, sizeof(*fpair), GFP_NOFS);
32344 + if (unlikely(!fpair))
32347 + inode = sb->s_root->d_inode;
32348 + ino = AUFS_ROOT_INO;
32349 + writef = au_sbi(sb)->si_xwrite;
32350 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
32351 + br = au_sbr(sb, bindex);
32352 + bshared = is_sb_shared(sb, bindex, bindex - 1);
32353 + if (bshared >= 0) {
32354 + /* shared xino */
32355 + *p = fpair[bshared];
32356 + get_file(p->new);
32361 + p->old = br->br_xino.xi_file;
32362 + p->new = au_xino_create2(base, br->br_xino.xi_file);
32363 + err = PTR_ERR(p->new);
32364 + if (IS_ERR(p->new)) {
32370 + err = au_xino_do_write(writef, p->new,
32371 + au_h_iptr(inode, bindex)->i_ino, ino);
32372 + if (unlikely(err))
32376 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
32377 + br = au_sbr(sb, bindex);
32378 + if (br->br_xino.xi_file)
32379 + fput(br->br_xino.xi_file);
32380 + get_file(p->new);
32381 + br->br_xino.xi_file = p->new;
32385 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++)
32395 +void au_xino_clr(struct super_block *sb)
32397 + struct au_sbinfo *sbinfo;
32399 + au_xigen_clr(sb);
32400 + xino_clear_xib(sb);
32401 + xino_clear_br(sb);
32402 + sbinfo = au_sbi(sb);
32403 + /* lvalue, do not call au_mntflags() */
32404 + au_opt_clr(sbinfo->si_mntflags, XINO);
32407 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
32410 + struct dentry *parent, *cur_parent;
32411 + struct qstr *dname, *cur_name;
32412 + struct file *cur_xino;
32413 + struct inode *dir;
32414 + struct au_sbinfo *sbinfo;
32416 + SiMustWriteLock(sb);
32419 + sbinfo = au_sbi(sb);
32420 + parent = dget_parent(xino->file->f_dentry);
32423 + dname = &xino->file->f_dentry->d_name;
32424 + cur_xino = sbinfo->si_xib;
32426 + cur_parent = dget_parent(cur_xino->f_dentry);
32427 + cur_name = &cur_xino->f_dentry->d_name;
32428 + skip = (cur_parent == parent
32429 + && dname->len == cur_name->len
32430 + && !memcmp(dname->name, cur_name->name,
32432 + dput(cur_parent);
32438 + au_opt_set(sbinfo->si_mntflags, XINO);
32439 + dir = parent->d_inode;
32440 + mutex_lock_nested(&dir->i_mutex, AuLsc_I_PARENT);
32441 + /* mnt_want_write() is unnecessary here */
32442 + err = au_xino_set_xib(sb, xino->file);
32444 + err = au_xigen_set(sb, xino->file);
32446 + err = au_xino_set_br(sb, xino->file);
32447 + mutex_unlock(&dir->i_mutex);
32449 + goto out; /* success */
32452 + AuIOErr("failed creating xino(%d).\n", err);
32459 +/* ---------------------------------------------------------------------- */
32462 + * create a xinofile at the default place/path.
32464 +struct file *au_xino_def(struct super_block *sb)
32466 + struct file *file;
32468 + struct au_branch *br;
32469 + struct super_block *h_sb;
32470 + struct path path;
32471 + aufs_bindex_t bend, bindex, bwr;
32474 + bend = au_sbend(sb);
32476 + for (bindex = 0; bindex <= bend; bindex++) {
32477 + br = au_sbr(sb, bindex);
32478 + if (au_br_writable(br->br_perm)
32479 + && !au_test_fs_bad_xino(au_br_sb(br))) {
32486 + file = ERR_PTR(-ENOMEM);
32487 + page = (void *)__get_free_page(GFP_NOFS);
32488 + if (unlikely(!page))
32490 + path.mnt = au_br_mnt(br);
32491 + path.dentry = au_h_dptr(sb->s_root, bwr);
32492 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
32493 + file = (void *)p;
32494 + if (!IS_ERR(p)) {
32495 + strcat(p, "/" AUFS_XINO_FNAME);
32496 + AuDbg("%s\n", p);
32497 + file = au_xino_create(sb, p, /*silent*/0);
32498 + if (!IS_ERR(file))
32499 + au_xino_brid_set(sb, br->br_id);
32501 + free_page((unsigned long)page);
32503 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
32504 + if (IS_ERR(file))
32506 + h_sb = file->f_dentry->d_sb;
32507 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
32508 + pr_err("xino doesn't support %s(%s)\n",
32509 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
32511 + file = ERR_PTR(-EINVAL);
32513 + if (!IS_ERR(file))
32514 + au_xino_brid_set(sb, -1);
32521 +/* ---------------------------------------------------------------------- */
32523 +int au_xino_path(struct seq_file *seq, struct file *file)
32527 + err = au_seq_path(seq, &file->f_path);
32528 + if (unlikely(err < 0))
32532 +#define Deleted "\\040(deleted)"
32533 + seq->count -= sizeof(Deleted) - 1;
32534 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
32535 + sizeof(Deleted) - 1));
32541 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
32542 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
32543 +++ linux/include/uapi/linux/aufs_type.h 2014-04-24 22:11:10.935269950 +0200
32546 + * Copyright (C) 2005-2014 Junjiro R. Okajima
32548 + * This program, aufs is free software; you can redistribute it and/or modify
32549 + * it under the terms of the GNU General Public License as published by
32550 + * the Free Software Foundation; either version 2 of the License, or
32551 + * (at your option) any later version.
32553 + * This program is distributed in the hope that it will be useful,
32554 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32555 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32556 + * GNU General Public License for more details.
32558 + * You should have received a copy of the GNU General Public License
32559 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32562 +#ifndef __AUFS_TYPE_H__
32563 +#define __AUFS_TYPE_H__
32565 +#define AUFS_NAME "aufs"
32569 + * define it before including all other headers.
32570 + * sched.h may use pr_* macros before defining "current", so define the
32571 + * no-current version first, and re-define later.
32573 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
32574 +#include <linux/sched.h>
32576 +#define pr_fmt(fmt) \
32577 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
32578 + (int)sizeof(current->comm), current->comm, current->pid
32580 +#include <stdint.h>
32581 +#include <sys/types.h>
32582 +#endif /* __KERNEL__ */
32584 +#include <linux/limits.h>
32586 +#define AUFS_VERSION "3.14-20140407"
32588 +/* todo? move this to linux-2.6.19/include/magic.h */
32589 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
32591 +/* ---------------------------------------------------------------------- */
32593 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
32594 +typedef int8_t aufs_bindex_t;
32595 +#define AUFS_BRANCH_MAX 127
32597 +typedef int16_t aufs_bindex_t;
32598 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
32599 +#define AUFS_BRANCH_MAX 511
32600 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
32601 +#define AUFS_BRANCH_MAX 1023
32602 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
32603 +#define AUFS_BRANCH_MAX 32767
32608 +#ifndef AUFS_BRANCH_MAX
32609 +#error unknown CONFIG_AUFS_BRANCH_MAX value
32611 +#endif /* __KERNEL__ */
32613 +/* ---------------------------------------------------------------------- */
32615 +#define AUFS_FSTYPE AUFS_NAME
32617 +#define AUFS_ROOT_INO 2
32618 +#define AUFS_FIRST_INO 11
32620 +#define AUFS_WH_PFX ".wh."
32621 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
32622 +#define AUFS_WH_TMP_LEN 4
32623 +/* a limit for rmdir/rename a dir and copyup */
32624 +#define AUFS_MAX_NAMELEN (NAME_MAX \
32625 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
32627 + - AUFS_WH_TMP_LEN) /* hex */
32628 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
32629 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
32630 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
32631 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
32632 +#define AUFS_DIRWH_DEF 3
32633 +#define AUFS_RDCACHE_DEF 10 /* seconds */
32634 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
32635 +#define AUFS_RDBLK_DEF 512 /* bytes */
32636 +#define AUFS_RDHASH_DEF 32
32637 +#define AUFS_WKQ_NAME AUFS_NAME "d"
32638 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
32639 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
32640 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
32642 +/* pseudo-link maintenace under /proc */
32643 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
32644 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
32645 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
32647 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
32648 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
32650 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
32651 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
32652 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
32654 +/* doubly whiteouted */
32655 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
32656 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
32657 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
32659 +/* branch permissions and attributes */
32660 +#define AUFS_BRPERM_RW "rw"
32661 +#define AUFS_BRPERM_RO "ro"
32662 +#define AUFS_BRPERM_RR "rr"
32663 +#define AUFS_BRRATTR_WH "wh"
32664 +#define AUFS_BRWATTR_NLWH "nolwh"
32665 +#define AUFS_BRATTR_UNPIN "unpin"
32667 +/* ---------------------------------------------------------------------- */
32671 + /* readdir in userspace */
32675 + /* pathconf wrapper */
32685 +/* borrowed from linux/include/linux/kernel.h */
32687 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
32688 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
32691 +/* borrowed from linux/include/linux/compiler-gcc3.h */
32693 +#define __aligned(x) __attribute__((aligned(x)))
32698 +#define __packed __attribute__((packed))
32702 +struct au_rdu_cookie {
32707 + uint32_t generation;
32710 +struct au_rdu_ent {
32719 +static inline int au_rdu_len(int nlen)
32721 + /* include the terminating NULL */
32722 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
32723 + sizeof(uint64_t));
32726 +union au_rdu_ent_ul {
32727 + struct au_rdu_ent __user *e;
32739 + uint64_t sz; /* AuCtl_RDU */
32740 + uint64_t nent; /* AuCtl_RDU_INO */
32742 + union au_rdu_ent_ul ent;
32743 + uint16_t verify[AufsCtlRduV_End];
32745 + /* input/output */
32749 + union au_rdu_ent_ul tail;
32750 + /* number of entries which were added in a single call */
32755 + struct au_rdu_cookie cookie;
32758 +/* ---------------------------------------------------------------------- */
32760 +struct aufs_wbr_fd {
32765 +/* ---------------------------------------------------------------------- */
32767 +struct aufs_ibusy {
32768 + uint64_t ino, h_ino;
32772 +/* ---------------------------------------------------------------------- */
32774 +/* error code for move-down */
32775 +/* the actual message strings are implemented in aufs-util.git */
32777 + EAU_MVDOWN_OPAQUE = 1,
32778 + EAU_MVDOWN_WHITEOUT,
32779 + EAU_MVDOWN_UPPER,
32780 + EAU_MVDOWN_BOTTOM,
32781 + EAU_MVDOWN_NOUPPER,
32782 + EAU_MVDOWN_NOLOWERBR,
32786 +/* flags for move-down */
32787 +#define AUFS_MVDOWN_DMSG 1
32788 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
32789 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
32790 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
32791 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
32792 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
32793 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
32794 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
32795 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
32796 +/* will be added more */
32799 + AUFS_MVDOWN_UPPER,
32800 + AUFS_MVDOWN_LOWER,
32801 + AUFS_MVDOWN_NARRAY
32804 +struct aufs_mvdown {
32809 + } a[AUFS_MVDOWN_NARRAY];
32811 + /* will be added more */
32814 +/* ---------------------------------------------------------------------- */
32816 +#define AuCtlType 'A'
32817 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
32818 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
32819 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
32820 + struct aufs_wbr_fd)
32821 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
32822 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
32823 + struct aufs_mvdown)
32825 +#endif /* __AUFS_TYPE_H__ */
32826 aufs3.14 loopback patch
32828 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
32829 index ec278ac..1894990 100644
32830 --- a/drivers/block/loop.c
32831 +++ b/drivers/block/loop.c
32832 @@ -514,7 +514,7 @@ out:
32835 struct switch_request {
32836 - struct file *file;
32837 + struct file *file, *virt_file;
32838 struct completion wait;
32841 @@ -576,7 +576,8 @@ static int loop_thread(void *data)
32842 * First it needs to flush existing IO, it does this by sending a magic
32843 * BIO down the pipe. The completion of this BIO does the actual switch.
32845 -static int loop_switch(struct loop_device *lo, struct file *file)
32846 +static int loop_switch(struct loop_device *lo, struct file *file,
32847 + struct file *virt_file)
32849 struct switch_request w;
32850 struct bio *bio = bio_alloc(GFP_KERNEL, 0);
32851 @@ -584,6 +585,7 @@ static int loop_switch(struct loop_device *lo, struct file *file)
32853 init_completion(&w.wait);
32855 + w.virt_file = virt_file;
32856 bio->bi_private = &w;
32857 bio->bi_bdev = NULL;
32858 loop_make_request(lo->lo_queue, bio);
32859 @@ -600,7 +602,7 @@ static int loop_flush(struct loop_device *lo)
32860 if (!lo->lo_thread)
32863 - return loop_switch(lo, NULL);
32864 + return loop_switch(lo, NULL, NULL);
32868 @@ -619,6 +621,7 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
32869 mapping = file->f_mapping;
32870 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
32871 lo->lo_backing_file = file;
32872 + lo->lo_backing_virt_file = p->virt_file;
32873 lo->lo_blocksize = S_ISBLK(mapping->host->i_mode) ?
32874 mapping->host->i_bdev->bd_block_size : PAGE_SIZE;
32875 lo->old_gfp_mask = mapping_gfp_mask(mapping);
32876 @@ -627,6 +630,13 @@ out:
32877 complete(&p->wait);
32880 +static struct file *loop_real_file(struct file *file)
32882 + struct file *f = NULL;
32883 + if (file->f_dentry->d_sb->s_op->real_loop)
32884 + f = file->f_dentry->d_sb->s_op->real_loop(file);
32889 * loop_change_fd switched the backing store of a loopback device to
32890 @@ -640,6 +650,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
32893 struct file *file, *old_file;
32894 + struct file *f, *virt_file = NULL, *old_virt_file;
32895 struct inode *inode;
32898 @@ -656,9 +667,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
32902 + f = loop_real_file(file);
32904 + virt_file = file;
32909 inode = file->f_mapping->host;
32910 old_file = lo->lo_backing_file;
32911 + old_virt_file = lo->lo_backing_virt_file;
32915 @@ -670,17 +688,21 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
32918 /* and ... switch */
32919 - error = loop_switch(lo, file);
32920 + error = loop_switch(lo, file, virt_file);
32925 + if (old_virt_file)
32926 + fput(old_virt_file);
32927 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
32928 ioctl_by_bdev(bdev, BLKRRPART, 0);
32938 @@ -841,7 +863,7 @@ static void loop_config_discard(struct loop_device *lo)
32939 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
32940 struct block_device *bdev, unsigned int arg)
32942 - struct file *file, *f;
32943 + struct file *file, *f, *virt_file = NULL;
32944 struct inode *inode;
32945 struct address_space *mapping;
32946 unsigned lo_blocksize;
32947 @@ -856,6 +878,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
32951 + f = loop_real_file(file);
32953 + virt_file = file;
32959 if (lo->lo_state != Lo_unbound)
32960 @@ -904,6 +932,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
32961 lo->lo_device = bdev;
32962 lo->lo_flags = lo_flags;
32963 lo->lo_backing_file = file;
32964 + lo->lo_backing_virt_file = virt_file;
32965 lo->transfer = transfer_none;
32967 lo->lo_sizelimit = 0;
32968 @@ -948,6 +977,7 @@ out_clr:
32969 lo->lo_thread = NULL;
32970 lo->lo_device = NULL;
32971 lo->lo_backing_file = NULL;
32972 + lo->lo_backing_virt_file = NULL;
32974 set_capacity(lo->lo_disk, 0);
32975 invalidate_bdev(bdev);
32976 @@ -957,6 +987,8 @@ out_clr:
32977 lo->lo_state = Lo_unbound;
32983 /* This is safe: open() is still holding a reference. */
32984 module_put(THIS_MODULE);
32985 @@ -1003,6 +1035,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
32986 static int loop_clr_fd(struct loop_device *lo)
32988 struct file *filp = lo->lo_backing_file;
32989 + struct file *virt_filp = lo->lo_backing_virt_file;
32990 gfp_t gfp = lo->old_gfp_mask;
32991 struct block_device *bdev = lo->lo_device;
32993 @@ -1036,6 +1069,7 @@ static int loop_clr_fd(struct loop_device *lo)
32995 spin_lock_irq(&lo->lo_lock);
32996 lo->lo_backing_file = NULL;
32997 + lo->lo_backing_virt_file = NULL;
32998 spin_unlock_irq(&lo->lo_lock);
33000 loop_release_xfer(lo);
33001 @@ -1078,6 +1112,8 @@ static int loop_clr_fd(struct loop_device *lo)
33002 * bd_mutex which is usually taken before lo_ctl_mutex.
33010 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
33011 index 90df5d6..cb91822 100644
33012 --- a/drivers/block/loop.h
33013 +++ b/drivers/block/loop.h
33014 @@ -44,7 +44,7 @@ struct loop_device {
33015 int (*ioctl)(struct loop_device *, int cmd,
33016 unsigned long arg);
33018 - struct file * lo_backing_file;
33019 + struct file * lo_backing_file, *lo_backing_virt_file;
33020 struct block_device *lo_device;
33021 unsigned lo_blocksize;
33023 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
33024 index 2e0302d..b35af58 100644
33025 --- a/fs/aufs/f_op.c
33026 +++ b/fs/aufs/f_op.c
33027 @@ -337,7 +337,7 @@ static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
33029 h_file = au_hf_top(file);
33031 - if (au_test_loopback_kthread()) {
33032 + if (0 && au_test_loopback_kthread()) {
33033 au_warn_loopback(h_file->f_dentry->d_sb);
33034 if (file->f_mapping != h_file->f_mapping) {
33035 file->f_mapping = h_file->f_mapping;
33036 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
33037 index 3b03b52..4ab749d 100644
33038 --- a/fs/aufs/loop.c
33039 +++ b/fs/aufs/loop.c
33040 @@ -130,3 +130,19 @@ void au_loopback_fin(void)
33041 symbol_put(loop_backing_file);
33042 kfree(au_warn_loopback_array);
33045 +/* ---------------------------------------------------------------------- */
33047 +/* support the loopback block device insude aufs */
33049 +struct file *aufs_real_loop(struct file *file)
33053 + BUG_ON(!au_test_aufs(file->f_dentry->d_sb));
33054 + fi_read_lock(file);
33055 + f = au_hf_top(file);
33056 + fi_read_unlock(file);
33060 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
33061 index da8b756..28cb7ea 100644
33062 --- a/fs/aufs/loop.h
33063 +++ b/fs/aufs/loop.h
33064 @@ -25,7 +25,11 @@ void au_warn_loopback(struct super_block *h_sb);
33066 int au_loopback_init(void);
33067 void au_loopback_fin(void);
33069 +struct file *aufs_real_loop(struct file *file);
33071 +AuStub(struct file *, loop_backing_file, return NULL)
33073 AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
33074 struct dentry *h_adding)
33075 AuStubInt0(au_test_loopback_kthread, void)
33076 @@ -33,6 +37,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
33078 AuStubInt0(au_loopback_init, void)
33079 AuStubVoid(au_loopback_fin, void)
33081 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
33082 #endif /* BLK_DEV_LOOP */
33084 #endif /* __KERNEL__ */
33085 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
33086 index b609e5a..e3909ed 100644
33087 --- a/fs/aufs/super.c
33088 +++ b/fs/aufs/super.c
33089 @@ -807,7 +807,10 @@ static const struct super_operations aufs_sop = {
33090 .statfs = aufs_statfs,
33091 .put_super = aufs_put_super,
33092 .sync_fs = aufs_sync_fs,
33093 - .remount_fs = aufs_remount_fs
33094 + .remount_fs = aufs_remount_fs,
33095 +#ifdef CONFIG_AUFS_BDEV_LOOP
33096 + .real_loop = aufs_real_loop
33100 /* ---------------------------------------------------------------------- */
33101 diff --git a/include/linux/fs.h b/include/linux/fs.h
33102 index f3f635c..c4308ca 100644
33103 --- a/include/linux/fs.h
33104 +++ b/include/linux/fs.h
33105 @@ -1626,6 +1626,10 @@ struct super_operations {
33106 int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
33107 long (*nr_cached_objects)(struct super_block *, int);
33108 long (*free_cached_objects)(struct super_block *, long, int);
33109 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
33111 + struct file *(*real_loop)(struct file *);