3 diff --git a/fs/Kconfig b/fs/Kconfig
4 index 312393f..78632ed 100644
7 @@ -209,6 +209,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 f9cb987..a0c580f 100644
19 @@ -126,3 +126,4 @@ obj-y += exofs/ # Multiple modules
20 obj-$(CONFIG_CEPH_FS) += ceph/
21 obj-$(CONFIG_PSTORE) += pstore/
22 obj-$(CONFIG_EFIVAR_FS) += efivarfs/
23 +obj-$(CONFIG_AUFS_FS) += aufs/
24 diff --git a/include/uapi/linux/Kbuild b/include/uapi/linux/Kbuild
25 index 6929571..351ca48 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 f70a230..138104b 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 f96d2a6..2d72083 100644
71 @@ -1496,7 +1496,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 e246954..4797013 100644
84 @@ -1103,8 +1103,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 @@ -1120,9 +1120,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 8780312..3ff3e89 100644
110 --- a/include/linux/fs.h
111 +++ b/include/linux/fs.h
112 @@ -2606,6 +2606,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 9ddb9fc..1059a0b 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 c4b2646..dc3c0dc 100644
167 --- a/fs/proc/task_mmu.c
168 +++ b/fs/proc/task_mmu.c
169 @@ -265,7 +265,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 @@ -1408,6 +1410,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 d677706..192e7ac4 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 @@ -1173,6 +1176,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 8967e20..a57b589 100644
307 --- a/include/linux/mm_types.h
308 +++ b/include/linux/mm_types.h
309 @@ -232,6 +232,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 @@ -300,6 +301,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 54a8d26..dcf08b6 100644
329 @@ -416,7 +416,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 088358c..138a88c 100644
342 @@ -2091,7 +2091,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..8d6c451 100644
355 @@ -223,16 +223,27 @@ get_write_lock:
357 if (mapping_cap_account_dirty(mapping)) {
359 - struct file *file = get_file(vma->vm_file);
360 + struct file *file = vma->vm_file,
361 + *prfile = vma->vm_prfile;
363 /* mmap_region may free vma; grab the info now */
364 vm_flags = vma->vm_flags;
367 addr = mmap_region(file, start, size, vm_flags, pgoff);
370 if (IS_ERR_VALUE(addr)) {
373 BUG_ON(addr != start);
375 + struct vm_area_struct *new_vma;
376 + new_vma = find_vma(mm, addr);
377 + if (!new_vma->vm_prfile)
378 + new_vma->vm_prfile = prfile;
379 + if (new_vma != vma)
385 diff --git a/mm/madvise.c b/mm/madvise.c
386 index a402f8f..134e15d 100644
389 @@ -327,12 +327,12 @@ static long madvise_remove(struct vm_area_struct *vma,
390 * vma's reference to the file) can go away as soon as we drop
395 up_read(¤t->mm->mmap_sem);
396 error = do_fallocate(f,
397 FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
398 offset, end - start);
401 down_read(¤t->mm->mmap_sem);
404 diff --git a/mm/memory.c b/mm/memory.c
405 index 037b812..6e7d241 100644
408 @@ -2805,7 +2805,7 @@ reuse:
409 set_page_dirty_balance(dirty_page);
410 /* file_update_time outside page_lock */
412 - file_update_time(vma->vm_file);
413 + vma_file_update_time(vma);
415 put_page(dirty_page);
417 diff --git a/mm/mmap.c b/mm/mmap.c
418 index b1202cf..40dd067 100644
421 @@ -250,7 +250,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
422 if (vma->vm_ops && vma->vm_ops->close)
423 vma->vm_ops->close(vma);
425 - fput(vma->vm_file);
427 mpol_put(vma_policy(vma));
428 kmem_cache_free(vm_area_cachep, vma);
430 @@ -861,7 +861,7 @@ again: remove_next = 1 + (end > next->vm_end);
433 uprobe_munmap(next, next->vm_start, next->vm_end);
438 anon_vma_merge(vma, next);
439 @@ -1641,8 +1641,8 @@ out:
441 if (vm_flags & VM_DENYWRITE)
442 allow_write_access(file);
447 /* Undo any partial mapping done by a device driver. */
448 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
449 @@ -2432,7 +2432,7 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
453 - get_file(new->vm_file);
456 if (new->vm_ops && new->vm_ops->open)
457 new->vm_ops->open(new);
458 @@ -2451,7 +2451,7 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
459 if (new->vm_ops && new->vm_ops->close)
460 new->vm_ops->close(new);
462 - fput(new->vm_file);
464 unlink_anon_vmas(new);
466 mpol_put(vma_policy(new));
467 @@ -2840,7 +2840,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
468 if (anon_vma_clone(new_vma, vma))
469 goto out_free_mempol;
470 if (new_vma->vm_file)
471 - get_file(new_vma->vm_file);
472 + vma_get_file(new_vma);
473 if (new_vma->vm_ops && new_vma->vm_ops->open)
474 new_vma->vm_ops->open(new_vma);
475 vma_link(mm, new_vma, prev, rb_link, rb_parent);
476 diff --git a/mm/msync.c b/mm/msync.c
477 index 632df45..02d770e 100644
480 @@ -80,10 +80,10 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags)
482 if ((flags & MS_SYNC) && file &&
483 (vma->vm_flags & VM_SHARED)) {
486 up_read(&mm->mmap_sem);
487 error = vfs_fsync(file, 0);
490 if (error || start >= end)
492 down_read(&mm->mmap_sem);
493 diff --git a/mm/nommu.c b/mm/nommu.c
494 index 85f8d66..9f471fa 100644
497 @@ -655,7 +655,7 @@ static void __put_nommu_region(struct vm_region *region)
498 up_write(&nommu_region_sem);
501 - fput(region->vm_file);
504 /* IO memory and memory shared directly out of the pagecache
505 * from ramfs/tmpfs mustn't be released here */
506 @@ -820,7 +820,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
507 if (vma->vm_ops && vma->vm_ops->close)
508 vma->vm_ops->close(vma);
510 - fput(vma->vm_file);
512 put_nommu_region(vma->vm_region);
513 kmem_cache_free(vm_area_cachep, vma);
515 @@ -1382,7 +1382,7 @@ unsigned long do_mmap_pgoff(struct file *file,
516 goto error_just_free;
519 - fput(region->vm_file);
521 kmem_cache_free(vm_region_jar, region);
524 @@ -1458,10 +1458,10 @@ error_just_free:
525 up_write(&nommu_region_sem);
528 - fput(region->vm_file);
530 kmem_cache_free(vm_region_jar, region);
532 - fput(vma->vm_file);
534 kmem_cache_free(vm_area_cachep, vma);
535 kleave(" = %d", ret);
537 aufs3.15 standalone patch
539 diff --git a/fs/inode.c b/fs/inode.c
540 index 2d72083..30b69da 100644
543 @@ -57,6 +57,7 @@ static struct hlist_head *inode_hashtable __read_mostly;
544 static __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_hash_lock);
546 __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_sb_list_lock);
547 +EXPORT_SYMBOL(inode_sb_list_lock);
550 * Empty aops. Can be used for the cases where the user does not
551 @@ -1512,6 +1513,7 @@ int update_time(struct inode *inode, struct timespec *time, int flags)
552 mark_inode_dirty_sync(inode);
555 +EXPORT_SYMBOL(update_time);
558 * touch_atime - update the access time
559 diff --git a/fs/namespace.c b/fs/namespace.c
560 index 182bc41..c88e101 100644
563 @@ -453,6 +453,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
564 mnt_dec_writers(real_mount(mnt));
567 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
570 * mnt_drop_write - give up write access to a mount
571 @@ -1564,6 +1565,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
575 +EXPORT_SYMBOL(iterate_mounts);
577 static void cleanup_group_ids(struct mount *mnt, struct mount *end)
579 diff --git a/fs/notify/group.c b/fs/notify/group.c
580 index ad19959..adf290d 100644
581 --- a/fs/notify/group.c
582 +++ b/fs/notify/group.c
584 #include <linux/srcu.h>
585 #include <linux/rculist.h>
586 #include <linux/wait.h>
587 +#include <linux/module.h>
589 #include <linux/fsnotify_backend.h>
590 #include "fsnotify.h"
591 @@ -72,6 +73,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
593 atomic_inc(&group->refcnt);
595 +EXPORT_SYMBOL(fsnotify_get_group);
598 * Drop a reference to a group. Free it if it's through.
599 @@ -81,6 +83,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
600 if (atomic_dec_and_test(&group->refcnt))
601 fsnotify_final_destroy_group(group);
603 +EXPORT_SYMBOL(fsnotify_put_group);
606 * Create a new fsnotify_group and hold a reference for the group returned.
607 @@ -109,6 +112,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
611 +EXPORT_SYMBOL(fsnotify_alloc_group);
613 int fsnotify_fasync(int fd, struct file *file, int on)
615 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
616 index 923fe4a..176b435 100644
617 --- a/fs/notify/mark.c
618 +++ b/fs/notify/mark.c
619 @@ -109,6 +109,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
620 mark->free_mark(mark);
623 +EXPORT_SYMBOL(fsnotify_put_mark);
626 * Any time a mark is getting freed we end up here.
627 @@ -191,6 +192,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
628 fsnotify_destroy_mark_locked(mark, group);
629 mutex_unlock(&group->mark_mutex);
631 +EXPORT_SYMBOL(fsnotify_destroy_mark);
633 void fsnotify_set_mark_mask_locked(struct fsnotify_mark *mark, __u32 mask)
635 @@ -275,6 +277,7 @@ err:
639 +EXPORT_SYMBOL(fsnotify_add_mark);
641 int fsnotify_add_mark(struct fsnotify_mark *mark, struct fsnotify_group *group,
642 struct inode *inode, struct vfsmount *mnt, int allow_dups)
643 @@ -336,6 +339,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
644 atomic_set(&mark->refcnt, 1);
645 mark->free_mark = free_mark;
647 +EXPORT_SYMBOL(fsnotify_init_mark);
649 static int fsnotify_mark_destroy(void *ignored)
651 diff --git a/fs/open.c b/fs/open.c
652 index 9d64679..1aa876a 100644
655 @@ -62,6 +62,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
656 mutex_unlock(&dentry->d_inode->i_mutex);
659 +EXPORT_SYMBOL(do_truncate);
661 long vfs_truncate(struct path *path, loff_t length)
663 @@ -299,6 +300,7 @@ int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
664 sb_end_write(inode->i_sb);
667 +EXPORT_SYMBOL(do_fallocate);
669 SYSCALL_DEFINE4(fallocate, int, fd, int, mode, loff_t, offset, loff_t, len)
671 diff --git a/fs/splice.c b/fs/splice.c
672 index 4797013..44b603a 100644
675 @@ -1116,6 +1116,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
677 return splice_write(pipe, out, ppos, len, flags);
679 +EXPORT_SYMBOL(do_splice_from);
682 * Attempt to initiate a splice from a file to a pipe.
683 @@ -1142,6 +1143,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
685 return splice_read(in, ppos, pipe, len, flags);
687 +EXPORT_SYMBOL(do_splice_to);
690 * splice_direct_to_actor - splices data directly between two non-pipes
691 diff --git a/security/commoncap.c b/security/commoncap.c
692 index b9d613e..ba3b618 100644
693 --- a/security/commoncap.c
694 +++ b/security/commoncap.c
695 @@ -988,9 +988,11 @@ int cap_mmap_addr(unsigned long addr)
699 +EXPORT_SYMBOL(cap_mmap_addr);
701 int cap_mmap_file(struct file *file, unsigned long reqprot,
702 unsigned long prot, unsigned long flags)
706 +EXPORT_SYMBOL(cap_mmap_file);
707 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
708 index 9134dbf..4d4217a 100644
709 --- a/security/device_cgroup.c
710 +++ b/security/device_cgroup.c
712 #include <linux/device_cgroup.h>
713 #include <linux/cgroup.h>
714 #include <linux/ctype.h>
715 +#include <linux/export.h>
716 #include <linux/list.h>
717 #include <linux/uaccess.h>
718 #include <linux/seq_file.h>
719 @@ -856,6 +857,7 @@ int __devcgroup_inode_permission(struct inode *inode, int mask)
720 return __devcgroup_check_permission(type, imajor(inode), iminor(inode),
723 +EXPORT_SYMBOL(__devcgroup_inode_permission);
725 int devcgroup_inode_mknod(int mode, dev_t dev)
727 diff --git a/security/security.c b/security/security.c
728 index 8b774f3..e3190b9 100644
729 --- a/security/security.c
730 +++ b/security/security.c
731 @@ -407,6 +407,7 @@ int security_path_rmdir(struct path *dir, struct dentry *dentry)
733 return security_ops->path_rmdir(dir, dentry);
735 +EXPORT_SYMBOL(security_path_rmdir);
737 int security_path_unlink(struct path *dir, struct dentry *dentry)
739 @@ -423,6 +424,7 @@ int security_path_symlink(struct path *dir, struct dentry *dentry,
741 return security_ops->path_symlink(dir, dentry, old_name);
743 +EXPORT_SYMBOL(security_path_symlink);
745 int security_path_link(struct dentry *old_dentry, struct path *new_dir,
746 struct dentry *new_dentry)
747 @@ -431,6 +433,7 @@ int security_path_link(struct dentry *old_dentry, struct path *new_dir,
749 return security_ops->path_link(old_dentry, new_dir, new_dentry);
751 +EXPORT_SYMBOL(security_path_link);
753 int security_path_rename(struct path *old_dir, struct dentry *old_dentry,
754 struct path *new_dir, struct dentry *new_dentry,
755 @@ -458,6 +461,7 @@ int security_path_truncate(struct path *path)
757 return security_ops->path_truncate(path);
759 +EXPORT_SYMBOL(security_path_truncate);
761 int security_path_chmod(struct path *path, umode_t mode)
763 @@ -465,6 +469,7 @@ int security_path_chmod(struct path *path, umode_t mode)
765 return security_ops->path_chmod(path, mode);
767 +EXPORT_SYMBOL(security_path_chmod);
769 int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
771 @@ -472,6 +477,7 @@ int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
773 return security_ops->path_chown(path, uid, gid);
775 +EXPORT_SYMBOL(security_path_chown);
777 int security_path_chroot(struct path *path)
779 @@ -557,6 +563,7 @@ int security_inode_readlink(struct dentry *dentry)
781 return security_ops->inode_readlink(dentry);
783 +EXPORT_SYMBOL(security_inode_readlink);
785 int security_inode_follow_link(struct dentry *dentry, struct nameidata *nd)
787 @@ -571,6 +578,7 @@ int security_inode_permission(struct inode *inode, int mask)
789 return security_ops->inode_permission(inode, mask);
791 +EXPORT_SYMBOL(security_inode_permission);
793 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
795 @@ -693,6 +701,7 @@ int security_file_permission(struct file *file, int mask)
797 return fsnotify_perm(file, mask);
799 +EXPORT_SYMBOL(security_file_permission);
801 int security_file_alloc(struct file *file)
803 @@ -753,6 +762,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
805 return ima_file_mmap(file, prot);
807 +EXPORT_SYMBOL(security_mmap_file);
809 int security_mmap_addr(unsigned long addr)
811 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
812 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
813 +++ linux/Documentation/ABI/testing/debugfs-aufs 2014-06-24 00:14:06.769385243 +0200
815 +What: /debug/aufs/si_<id>/
817 +Contact: J. R. Okajima <hooanon05g@gmail.com>
819 + Under /debug/aufs, a directory named si_<id> is created
820 + per aufs mount, where <id> is a unique id generated
823 +What: /debug/aufs/si_<id>/plink
825 +Contact: J. R. Okajima <hooanon05g@gmail.com>
827 + It has three lines and shows the information about the
828 + pseudo-link. The first line is a single number
829 + representing a number of buckets. The second line is a
830 + number of pseudo-links per buckets (separated by a
831 + blank). The last line is a single number representing a
832 + total number of psedo-links.
833 + When the aufs mount option 'noplink' is specified, it
834 + will show "1\n0\n0\n".
836 +What: /debug/aufs/si_<id>/xib
838 +Contact: J. R. Okajima <hooanon05g@gmail.com>
840 + It shows the consumed blocks by xib (External Inode Number
841 + Bitmap), its block size and file size.
842 + When the aufs mount option 'noxino' is specified, it
843 + will be empty. About XINO files, see the aufs manual.
845 +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN
847 +Contact: J. R. Okajima <hooanon05g@gmail.com>
849 + It shows the consumed blocks by xino (External Inode Number
850 + Translation Table), its link count, block size and file
852 + When the aufs mount option 'noxino' is specified, it
853 + will be empty. About XINO files, see the aufs manual.
855 +What: /debug/aufs/si_<id>/xigen
857 +Contact: J. R. Okajima <hooanon05g@gmail.com>
859 + It shows the consumed blocks by xigen (External Inode
860 + Generation Table), its block size and file size.
861 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
863 + When the aufs mount option 'noxino' is specified, it
864 + will be empty. About XINO files, see the aufs manual.
865 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
866 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
867 +++ linux/Documentation/ABI/testing/sysfs-aufs 2014-06-24 00:14:06.769385243 +0200
869 +What: /sys/fs/aufs/si_<id>/
871 +Contact: J. R. Okajima <hooanon05g@gmail.com>
873 + Under /sys/fs/aufs, a directory named si_<id> is created
874 + per aufs mount, where <id> is a unique id generated
877 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
879 +Contact: J. R. Okajima <hooanon05g@gmail.com>
881 + It shows the abolute path of a member directory (which
882 + is called branch) in aufs, and its permission.
884 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
886 +Contact: J. R. Okajima <hooanon05g@gmail.com>
888 + It shows the id of a member directory (which is called
891 +What: /sys/fs/aufs/si_<id>/xi_path
893 +Contact: J. R. Okajima <hooanon05g@gmail.com>
895 + It shows the abolute path of XINO (External Inode Number
896 + Bitmap, Translation Table and Generation Table) file
897 + even if it is the default path.
898 + When the aufs mount option 'noxino' is specified, it
899 + will be empty. About XINO files, see the aufs manual.
900 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
901 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
902 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2014-06-24 00:14:06.772718759 +0200
905 +# Copyright (C) 2005-2014 Junjiro R. Okajima
907 +# This program is free software; you can redistribute it and/or modify
908 +# it under the terms of the GNU General Public License as published by
909 +# the Free Software Foundation; either version 2 of the License, or
910 +# (at your option) any later version.
912 +# This program is distributed in the hope that it will be useful,
913 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
914 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
915 +# GNU General Public License for more details.
917 +# You should have received a copy of the GNU General Public License
918 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
921 +----------------------------------------
923 +aufs [ei ju: ef es] | [a u f s]
924 +1. abbrev. for "advanced multi-layered unification filesystem".
925 +2. abbrev. for "another unionfs".
926 +3. abbrev. for "auf das" in German which means "on the" in English.
927 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
928 + But "Filesystem aufs Filesystem" is hard to understand.
930 +AUFS is a filesystem with features:
931 +- multi layered stackable unification filesystem, the member directory
932 + is called as a branch.
933 +- branch permission and attribute, 'readonly', 'real-readonly',
934 + 'readwrite', 'whiteout-able', 'link-able whiteout' and their
936 +- internal "file copy-on-write".
937 +- logical deletion, whiteout.
938 +- dynamic branch manipulation, adding, deleting and changing permission.
939 +- allow bypassing aufs, user's direct branch access.
940 +- external inode number translation table and bitmap which maintains the
941 + persistent aufs inode number.
942 +- seekable directory, including NFS readdir.
943 +- file mapping, mmap and sharing pages.
944 +- pseudo-link, hardlink over branches.
945 +- loopback mounted filesystem as a branch.
946 +- several policies to select one among multiple writable branches.
947 +- revert a single systemcall when an error occurs in aufs.
951 +Multi Layered Stackable Unification Filesystem
952 +----------------------------------------------------------------------
953 +Most people already knows what it is.
954 +It is a filesystem which unifies several directories and provides a
955 +merged single directory. When users access a file, the access will be
956 +passed/re-directed/converted (sorry, I am not sure which English word is
957 +correct) to the real file on the member filesystem. The member
958 +filesystem is called 'lower filesystem' or 'branch' and has a mode
959 +'readonly' and 'readwrite.' And the deletion for a file on the lower
960 +readonly branch is handled by creating 'whiteout' on the upper writable
963 +On LKML, there have been discussions about UnionMount (Jan Blunck,
964 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
965 +different approaches to implement the merged-view.
966 +The former tries putting it into VFS, and the latter implements as a
967 +separate filesystem.
968 +(If I misunderstand about these implementations, please let me know and
969 +I shall correct it. Because it is a long time ago when I read their
970 +source files last time).
972 +UnionMount's approach will be able to small, but may be hard to share
973 +branches between several UnionMount since the whiteout in it is
974 +implemented in the inode on branch filesystem and always
975 +shared. According to Bharata's post, readdir does not seems to be
977 +There are several missing features known in this implementations such as
978 +- for users, the inode number may change silently. eg. copy-up.
979 +- link(2) may break by copy-up.
980 +- read(2) may get an obsoleted filedata (fstat(2) too).
981 +- fcntl(F_SETLK) may be broken by copy-up.
982 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
985 +Unionfs has a longer history. When I started implementing a stacking filesystem
986 +(Aug 2005), it already existed. It has virtual super_block, inode,
987 +dentry and file objects and they have an array pointing lower same kind
988 +objects. After contributing many patches for Unionfs, I re-started my
989 +project AUFS (Jun 2006).
991 +In AUFS, the structure of filesystem resembles to Unionfs, but I
992 +implemented my own ideas, approaches and enhancements and it became
993 +totally different one.
995 +Comparing DM snapshot and fs based implementation
996 +- the number of bytes to be copied between devices is much smaller.
997 +- the type of filesystem must be one and only.
998 +- the fs must be writable, no readonly fs, even for the lower original
999 + device. so the compression fs will not be usable. but if we use
1000 + loopback mount, we may address this issue.
1002 + mount /cdrom/squashfs.img /sq
1003 + losetup /sq/ext2.img
1004 + losetup /somewhere/cow
1005 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1006 +- it will be difficult (or needs more operations) to extract the
1007 + difference between the original device and COW.
1008 +- DM snapshot-merge may help a lot when users try merging. in the
1009 + fs-layer union, users will use rsync(1).
1012 +Several characters/aspects of aufs
1013 +----------------------------------------------------------------------
1015 +Aufs has several characters or aspects.
1016 +1. a filesystem, callee of VFS helper
1017 +2. sub-VFS, caller of VFS helper for branches
1018 +3. a virtual filesystem which maintains persistent inode number
1019 +4. reader/writer of files on branches such like an application
1021 +1. Callee of VFS Helper
1022 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1023 +unlink(2) from an application reaches sys_unlink() kernel function and
1024 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1025 +calls filesystem specific unlink operation. Actually aufs implements the
1026 +unlink operation but it behaves like a redirector.
1028 +2. Caller of VFS Helper for Branches
1029 +aufs_unlink() passes the unlink request to the branch filesystem as if
1030 +it were called from VFS. So the called unlink operation of the branch
1031 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1032 +every necessary pre/post operation for the branch filesystem.
1033 +- acquire the lock for the parent dir on a branch
1034 +- lookup in a branch
1035 +- revalidate dentry on a branch
1036 +- mnt_want_write() for a branch
1037 +- vfs_unlink() for a branch
1038 +- mnt_drop_write() for a branch
1039 +- release the lock on a branch
1041 +3. Persistent Inode Number
1042 +One of the most important issue for a filesystem is to maintain inode
1043 +numbers. This is particularly important to support exporting a
1044 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1045 +backend block device for its own. But some storage is necessary to
1046 +maintain inode number. It may be a large space and may not suit to keep
1047 +in memory. Aufs rents some space from its first writable branch
1048 +filesystem (by default) and creates file(s) on it. These files are
1049 +created by aufs internally and removed soon (currently) keeping opened.
1050 +Note: Because these files are removed, they are totally gone after
1051 + unmounting aufs. It means the inode numbers are not persistent
1052 + across unmount or reboot. I have a plan to make them really
1053 + persistent which will be important for aufs on NFS server.
1055 +4. Read/Write Files Internally (copy-on-write)
1056 +Because a branch can be readonly, when you write a file on it, aufs will
1057 +"copy-up" it to the upper writable branch internally. And then write the
1058 +originally requested thing to the file. Generally kernel doesn't
1059 +open/read/write file actively. In aufs, even a single write may cause a
1060 +internal "file copy". This behaviour is very similar to cp(1) command.
1062 +Some people may think it is better to pass such work to user space
1063 +helper, instead of doing in kernel space. Actually I am still thinking
1064 +about it. But currently I have implemented it in kernel space.
1065 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1066 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1067 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2014-06-24 00:14:06.772718759 +0200
1070 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1072 +# This program is free software; you can redistribute it and/or modify
1073 +# it under the terms of the GNU General Public License as published by
1074 +# the Free Software Foundation; either version 2 of the License, or
1075 +# (at your option) any later version.
1077 +# This program is distributed in the hope that it will be useful,
1078 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1079 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1080 +# GNU General Public License for more details.
1082 +# You should have received a copy of the GNU General Public License
1083 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1085 +Basic Aufs Internal Structure
1087 +Superblock/Inode/Dentry/File Objects
1088 +----------------------------------------------------------------------
1089 +As like an ordinary filesystem, aufs has its own
1090 +superblock/inode/dentry/file objects. All these objects have a
1091 +dynamically allocated array and store the same kind of pointers to the
1092 +lower filesystem, branch.
1093 +For example, when you build a union with one readwrite branch and one
1094 +readonly, mounted /au, /rw and /ro respectively.
1096 +- /ro/fileA exists but /rw/fileA
1098 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1099 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1103 +This style of an array is essentially same to the aufs
1104 +superblock/inode/dentry/file objects.
1106 +Because aufs supports manipulating branches, ie. add/delete/change
1107 +dynamically, these objects has its own generation. When branches are
1108 +changed, the generation in aufs superblock is incremented. And a
1109 +generation in other object are compared when it is accessed.
1110 +When a generation in other objects are obsoleted, aufs refreshes the
1115 +----------------------------------------------------------------------
1116 +Additionally aufs superblock has some data for policies to select one
1117 +among multiple writable branches, XIB files, pseudo-links and kobject.
1118 +See below in detail.
1119 +About the policies which supports copy-down a directory, see policy.txt
1123 +Branch and XINO(External Inode Number Translation Table)
1124 +----------------------------------------------------------------------
1125 +Every branch has its own xino (external inode number translation table)
1126 +file. The xino file is created and unlinked by aufs internally. When two
1127 +members of a union exist on the same filesystem, they share the single
1129 +The struct of a xino file is simple, just a sequence of aufs inode
1130 +numbers which is indexed by the lower inode number.
1131 +In the above sample, assume the inode number of /ro/fileA is i111 and
1132 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1133 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1135 +When the inode numbers are not contiguous, the xino file will be sparse
1136 +which has a hole in it and doesn't consume as much disk space as it
1137 +might appear. If your branch filesystem consumes disk space for such
1138 +holes, then you should specify 'xino=' option at mounting aufs.
1140 +Also a writable branch has three kinds of "whiteout bases". All these
1141 +are existed when the branch is joined to aufs and the names are
1142 +whiteout-ed doubly, so that users will never see their names in aufs
1144 +1. a regular file which will be linked to all whiteouts.
1145 +2. a directory to store a pseudo-link.
1146 +3. a directory to store an "orphan-ed" file temporary.
1149 + When you remove a file on a readonly branch, aufs handles it as a
1150 + logical deletion and creates a whiteout on the upper writable branch
1151 + as a hardlink of this file in order not to consume inode on the
1154 + See below, Pseudo-link.
1156 + When "fileC" exists on the lower readonly branch only and it is
1157 + opened and removed with its parent dir, and then user writes
1158 + something into it, then aufs copies-up fileC to this
1159 + directory. Because there is no other dir to store fileC. After
1160 + creating a file under this dir, the file is unlinked.
1162 +Because aufs supports manipulating branches, ie. add/delete/change
1163 +dynamically, a branch has its own id. When the branch order changes, aufs
1164 +finds the new index by searching the branch id.
1168 +----------------------------------------------------------------------
1169 +Assume "fileA" exists on the lower readonly branch only and it is
1170 +hardlinked to "fileB" on the branch. When you write something to fileA,
1171 +aufs copies-up it to the upper writable branch. Additionally aufs
1172 +creates a hardlink under the Pseudo-link Directory of the writable
1173 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1174 +simple list. If fileB is read after unlinking fileA, aufs returns
1175 +filedata from the pseudo-link instead of the lower readonly
1176 +branch. Because the pseudo-link is based upon the inode, to keep the
1177 +inode number by xino (see above) is important.
1179 +All the hardlinks under the Pseudo-link Directory of the writable branch
1180 +should be restored in a proper location later. Aufs provides a utility
1181 +to do this. The userspace helpers executed at remounting and unmounting
1183 +During this utility is running, it puts aufs into the pseudo-link
1184 +maintenance mode. In this mode, only the process which began the
1185 +maintenance mode (and its child processes) is allowed to operate in
1186 +aufs. Some other processes which are not related to the pseudo-link will
1187 +be allowed to run too, but the rest have to return an error or wait
1188 +until the maintenance mode ends. If a process already acquires an inode
1189 +mutex (in VFS), it has to return an error.
1192 +XIB(external inode number bitmap)
1193 +----------------------------------------------------------------------
1194 +Addition to the xino file per a branch, aufs has an external inode number
1195 +bitmap in a superblock object. It is also a file such like a xino file.
1196 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1198 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1200 +Aufs implements a feature to truncate/refresh both of xino and xib to
1201 +reduce the number of consumed disk blocks for these files.
1204 +Virtual or Vertical Dir, and Readdir in Userspace
1205 +----------------------------------------------------------------------
1206 +In order to support multiple layers (branches), aufs readdir operation
1207 +constructs a virtual dir block on memory. For readdir, aufs calls
1208 +vfs_readdir() internally for each dir on branches, merges their entries
1209 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1210 +object. So the file object has its entry list until it is closed. The
1211 +entry list will be updated when the file position is zero and becomes
1212 +old. This decision is made in aufs automatically.
1214 +The dynamically allocated memory block for the name of entries has a
1215 +unit of 512 bytes (by default) and stores the names contiguously (no
1216 +padding). Another block for each entry is handled by kmem_cache too.
1217 +During building dir blocks, aufs creates hash list and judging whether
1218 +the entry is whiteouted by its upper branch or already listed.
1219 +The merged result is cached in the corresponding inode object and
1220 +maintained by a customizable life-time option.
1222 +Some people may call it can be a security hole or invite DoS attack
1223 +since the opened and once readdir-ed dir (file object) holds its entry
1224 +list and becomes a pressure for system memory. But I'd say it is similar
1225 +to files under /proc or /sys. The virtual files in them also holds a
1226 +memory page (generally) while they are opened. When an idea to reduce
1227 +memory for them is introduced, it will be applied to aufs too.
1228 +For those who really hate this situation, I've developed readdir(3)
1229 +library which operates this merging in userspace. You just need to set
1230 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1231 +kernel space for readdir(3).
1235 +----------------------------------------------------------------------
1236 +Aufs sometimes requires privilege access to a branch. For instance,
1237 +in copy-up/down operation. When a user process is going to make changes
1238 +to a file which exists in the lower readonly branch only, and the mode
1239 +of one of ancestor directories may not be writable by a user
1240 +process. Here aufs copy-up the file with its ancestors and they may
1241 +require privilege to set its owner/group/mode/etc.
1242 +This is a typical case of a application character of aufs (see
1245 +Aufs uses workqueue synchronously for this case. It creates its own
1246 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1247 +passes the request to call mkdir or write (for example), and wait for
1248 +its completion. This approach solves a problem of a signal handler
1250 +If aufs didn't adopt the workqueue and changed the privilege of the
1251 +process, and if the mkdir/write call arises SIGXFSZ or other signal,
1252 +then the user process might gain a privilege or the generated core file
1253 +was owned by a superuser.
1255 +Also aufs uses the system global workqueue ("events" kernel thread) too
1256 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1257 +whiteout base and etc. This is unrelated to a privilege.
1258 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1259 +superblock at the beginning, at the same time waits for the completion
1260 +of all queued asynchronous tasks.
1264 +----------------------------------------------------------------------
1265 +The whiteout in aufs is very similar to Unionfs's. That is represented
1266 +by its filename. UnionMount takes an approach of a file mode, but I am
1267 +afraid several utilities (find(1) or something) will have to support it.
1269 +Basically the whiteout represents "logical deletion" which stops aufs to
1270 +lookup further, but also it represents "dir is opaque" which also stop
1273 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1274 +In order to make several functions in a single systemcall to be
1275 +revertible, aufs adopts an approach to rename a directory to a temporary
1276 +unique whiteouted name.
1277 +For example, in rename(2) dir where the target dir already existed, aufs
1278 +renames the target dir to a temporary unique whiteouted name before the
1279 +actual rename on a branch and then handles other actions (make it opaque,
1280 +update the attributes, etc). If an error happens in these actions, aufs
1281 +simply renames the whiteouted name back and returns an error. If all are
1282 +succeeded, aufs registers a function to remove the whiteouted unique
1283 +temporary name completely and asynchronously to the system global
1288 +----------------------------------------------------------------------
1289 +It is a well-known feature or concept.
1290 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1291 +internally and makes change to the new file on the upper writable branch.
1292 +When the trigger systemcall does not update the timestamps of the parent
1293 +dir, aufs reverts it after copy-up.
1296 +Move-down (aufs3.9 and later)
1297 +----------------------------------------------------------------------
1298 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1299 +the lower readonly branch to the upper writable branch when a user
1300 +changes something about the file.
1301 +"Move-down" is an opposite action of copy-up. Basically this action is
1302 +ran manually instead of automatically and internally.
1304 +Sometimes users want to move-down a file from the upper writable branch
1305 +to the lower readonly or writable branch. For instance,
1306 +- the free space of the upper writable branch is going to run out.
1307 +- create a new intermediate branch between the upper and lower branch.
1310 +For this purpose, use "aumvdown" command in aufs-util.git.
1311 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1312 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1313 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2014-06-24 00:14:06.772718759 +0200
1316 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1318 +# This program is free software; you can redistribute it and/or modify
1319 +# it under the terms of the GNU General Public License as published by
1320 +# the Free Software Foundation; either version 2 of the License, or
1321 +# (at your option) any later version.
1323 +# This program is distributed in the hope that it will be useful,
1324 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1325 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1326 +# GNU General Public License for more details.
1328 +# You should have received a copy of the GNU General Public License
1329 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1332 +----------------------------------------------------------------------
1333 +Since aufs has a character of sub-VFS (see Introduction), it operates
1334 +lookup for branches as VFS does. It may be a heavy work. Generally
1335 +speaking struct nameidata is a bigger structure and includes many
1336 +information. But almost all lookup operation in aufs is the simplest
1337 +case, ie. lookup only an entry directly connected to its parent. Digging
1338 +down the directory hierarchy is unnecessary.
1340 +VFS has a function lookup_one_len() for that use, but it is not usable
1341 +for a branch filesystem which requires struct nameidata. So aufs
1342 +implements a simple lookup wrapper function. When a branch filesystem
1343 +allows NULL as nameidata, it calls lookup_one_len(). Otherwise it builds
1344 +a simplest nameidata and calls lookup_hash().
1345 +Here aufs applies "a principle in NFSD", ie. if the filesystem supports
1346 +NFS-export, then it has to support NULL as a nameidata parameter for
1347 +->create(), ->lookup() and ->d_revalidate(). So the lookup wrapper in
1348 +aufs tests if ->s_export_op in the branch is NULL or not.
1350 +When a branch is a remote filesystem, aufs basically trusts its
1351 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1353 +For d_revalidate, aufs implements three levels of revalidate tests. See
1354 +"Revalidate Dentry and UDBA" in detail.
1358 +----------------------------------------------------------------------
1359 +Basically aufs supports any type of filesystem and block device for a
1360 +branch (actually there are some exceptions). But it is prohibited to add
1361 +a loopback mounted one whose backend file exists in a filesystem which is
1362 +already added to aufs. The reason is to protect aufs from a recursive
1363 +lookup. If it was allowed, the aufs lookup operation might re-enter a
1364 +lookup for the loopback mounted branch in the same context, and will
1368 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1369 +----------------------------------------------------------------------
1370 +Generally VFS helpers re-validate a dentry as a part of lookup.
1371 +0. digging down the directory hierarchy.
1372 +1. lock the parent dir by its i_mutex.
1373 +2. lookup the final (child) entry.
1375 +4. call the actual operation (create, unlink, etc.)
1376 +5. unlock the parent dir
1378 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1379 +called. Actually aufs implements it and checks the dentry on a branch is
1381 +But it is not enough. Because aufs has to release the lock for the
1382 +parent dir on a branch at the end of ->lookup() (step 2) and
1383 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1385 +If the file on a branch is changed directly, eg. bypassing aufs, after
1386 +aufs released the lock, then the subsequent operation may cause
1387 +something unpleasant result.
1389 +This situation is a result of VFS architecture, ->lookup() and
1390 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1391 +design from VFS's point of view. It is just not suitable for sub-VFS
1394 +Aufs supports such case by three level of revalidation which is
1395 +selectable by user.
1396 +1. Simple Revalidate
1397 + Addition to the native flow in VFS's, confirm the child-parent
1398 + relationship on the branch just after locking the parent dir on the
1399 + branch in the "actual operation" (step 4). When this validation
1400 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1401 + checks the validation of the dentry on branches.
1402 +2. Monitor Changes Internally by Inotify/Fsnotify
1403 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1404 + the dentry on the branch, and returns EBUSY if it finds different
1406 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1407 + during it is in cache. When the event is notified, aufs registers a
1408 + function to kernel 'events' thread by schedule_work(). And the
1409 + function sets some special status to the cached aufs dentry and inode
1410 + private data. If they are not cached, then aufs has nothing to
1411 + do. When the same file is accessed through aufs (step 0-3) later,
1412 + aufs will detect the status and refresh all necessary data.
1413 + In this mode, aufs has to ignore the event which is fired by aufs
1415 +3. No Extra Validation
1416 + This is the simplest test and doesn't add any additional revalidation
1417 + test, and skip therevalidatin in step 4. It is useful and improves
1418 + aufs performance when system surely hide the aufs branches from user,
1419 + by over-mounting something (or another method).
1420 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1421 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1422 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2014-06-24 00:14:06.772718759 +0200
1425 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1427 +# This program is free software; you can redistribute it and/or modify
1428 +# it under the terms of the GNU General Public License as published by
1429 +# the Free Software Foundation; either version 2 of the License, or
1430 +# (at your option) any later version.
1432 +# This program is distributed in the hope that it will be useful,
1433 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1434 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1435 +# GNU General Public License for more details.
1437 +# You should have received a copy of the GNU General Public License
1438 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1440 +Branch Manipulation
1442 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1443 +and changing its permission/attribute, there are a lot of works to do.
1447 +----------------------------------------------------------------------
1448 +o Confirm the adding dir exists outside of aufs, including loopback
1450 +- and other various attributes...
1451 +o Initialize the xino file and whiteout bases if necessary.
1454 +o Check the owner/group/mode of the directory
1455 + When the owner/group/mode of the adding directory differs from the
1456 + existing branch, aufs issues a warning because it may impose a
1458 + For example, when a upper writable branch has a world writable empty
1459 + top directory, a malicious user can create any files on the writable
1460 + branch directly, like copy-up and modify manually. If something like
1461 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1462 + writable branch, and the writable branch is world-writable, then a
1463 + malicious guy may create /etc/passwd on the writable branch directly
1464 + and the infected file will be valid in aufs.
1465 + I am afraid it can be a security issue, but nothing to do except
1466 + producing a warning.
1470 +----------------------------------------------------------------------
1471 +o Confirm the deleting branch is not busy
1472 + To be general, there is one merit to adopt "remount" interface to
1473 + manipulate branches. It is to discard caches. At deleting a branch,
1474 + aufs checks the still cached (and connected) dentries and inodes. If
1475 + there are any, then they are all in-use. An inode without its
1476 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1478 + For the cached one, aufs checks whether the same named entry exists on
1480 + If the cached one is a directory, because aufs provides a merged view
1481 + to users, as long as one dir is left on any branch aufs can show the
1482 + dir to users. In this case, the branch can be removed from aufs.
1483 + Otherwise aufs rejects deleting the branch.
1485 + If any file on the deleting branch is opened by aufs, then aufs
1489 +Modify the Permission of a Branch
1490 +----------------------------------------------------------------------
1491 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1494 +o rw --> ro: Confirm the modifying branch is not busy
1495 + Aufs rejects the request if any of these conditions are true.
1496 + - a file on the branch is mmap-ed.
1497 + - a regular file on the branch is opened for write and there is no
1498 + same named entry on the upper branch.
1499 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1500 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1501 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2014-06-24 00:14:06.772718759 +0200
1504 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1506 +# This program is free software; you can redistribute it and/or modify
1507 +# it under the terms of the GNU General Public License as published by
1508 +# the Free Software Foundation; either version 2 of the License, or
1509 +# (at your option) any later version.
1511 +# This program is distributed in the hope that it will be useful,
1512 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1513 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1514 +# GNU General Public License for more details.
1516 +# You should have received a copy of the GNU General Public License
1517 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1519 +Policies to Select One among Multiple Writable Branches
1520 +----------------------------------------------------------------------
1521 +When the number of writable branch is more than one, aufs has to decide
1522 +the target branch for file creation or copy-up. By default, the highest
1523 +writable branch which has the parent (or ancestor) dir of the target
1524 +file is chosen (top-down-parent policy).
1525 +By user's request, aufs implements some other policies to select the
1526 +writable branch, for file creation two policies, round-robin and
1527 +most-free-space policies. For copy-up three policies, top-down-parent,
1528 +bottom-up-parent and bottom-up policies.
1530 +As expected, the round-robin policy selects the branch in circular. When
1531 +you have two writable branches and creates 10 new files, 5 files will be
1532 +created for each branch. mkdir(2) systemcall is an exception. When you
1533 +create 10 new directories, all will be created on the same branch.
1534 +And the most-free-space policy selects the one which has most free
1535 +space among the writable branches. The amount of free space will be
1536 +checked by aufs internally, and users can specify its time interval.
1538 +The policies for copy-up is more simple,
1539 +top-down-parent is equivalent to the same named on in create policy,
1540 +bottom-up-parent selects the writable branch where the parent dir
1541 +exists and the nearest upper one from the copyup-source,
1542 +bottom-up selects the nearest upper writable branch from the
1543 +copyup-source, regardless the existence of the parent dir.
1545 +There are some rules or exceptions to apply these policies.
1546 +- If there is a readonly branch above the policy-selected branch and
1547 + the parent dir is marked as opaque (a variation of whiteout), or the
1548 + target (creating) file is whiteout-ed on the upper readonly branch,
1549 + then the result of the policy is ignored and the target file will be
1550 + created on the nearest upper writable branch than the readonly branch.
1551 +- If there is a writable branch above the policy-selected branch and
1552 + the parent dir is marked as opaque or the target file is whiteouted
1553 + on the branch, then the result of the policy is ignored and the target
1554 + file will be created on the highest one among the upper writable
1555 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1557 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1558 + They try selecting the branch where the source exists as possible
1559 + since copyup a large file will take long time. If it can't be,
1560 + ie. the branch where the source exists is readonly, then they will
1561 + follow the copyup policy.
1562 +- There is an exception for rename(2) when the target exists.
1563 + If the rename target exists, aufs compares the index of the branches
1564 + where the source and the target exists and selects the higher
1565 + one. If the selected branch is readonly, then aufs follows the
1567 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
1568 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
1569 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2014-06-24 00:14:06.772718759 +0200
1572 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1574 +# This program is free software; you can redistribute it and/or modify
1575 +# it under the terms of the GNU General Public License as published by
1576 +# the Free Software Foundation; either version 2 of the License, or
1577 +# (at your option) any later version.
1579 +# This program is distributed in the hope that it will be useful,
1580 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1581 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1582 +# GNU General Public License for more details.
1584 +# You should have received a copy of the GNU General Public License
1585 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1587 +mmap(2) -- File Memory Mapping
1588 +----------------------------------------------------------------------
1589 +In aufs, the file-mapped pages are handled by a branch fs directly, no
1590 +interaction with aufs. It means aufs_mmap() calls the branch fs's
1592 +This approach is simple and good, but there is one problem.
1593 +Under /proc, several entries show the mmap-ped files by its path (with
1594 +device and inode number), and the printed path will be the path on the
1595 +branch fs's instead of virtual aufs's.
1596 +This is not a problem in most cases, but some utilities lsof(1) (and its
1597 +user) may expect the path on aufs.
1599 +To address this issue, aufs adds a new member called vm_prfile in struct
1600 +vm_area_struct (and struct vm_region). The original vm_file points to
1601 +the file on the branch fs in order to handle everything correctly as
1602 +usual. The new vm_prfile points to a virtual file in aufs, and the
1603 +show-functions in procfs refers to vm_prfile if it is set.
1604 +Also we need to maintain several other places where touching vm_file
1606 +- fork()/clone() copies vma and the reference count of vm_file is
1608 +- merging vma maintains the ref count too.
1610 +This is not a good approach. It just faking the printed path. But it
1611 +leaves all behaviour around f_mapping unchanged. This is surely an
1613 +Actually aufs had adopted another complicated approach which calls
1614 +generic_file_mmap() and handles struct vm_operations_struct. In this
1615 +approach, aufs met a hard problem and I could not solve it without
1616 +switching the approach.
1617 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
1618 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
1619 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2014-06-24 00:14:06.772718759 +0200
1622 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1624 +# This program is free software; you can redistribute it and/or modify
1625 +# it under the terms of the GNU General Public License as published by
1626 +# the Free Software Foundation; either version 2 of the License, or
1627 +# (at your option) any later version.
1629 +# This program is distributed in the hope that it will be useful,
1630 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1631 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1632 +# GNU General Public License for more details.
1634 +# You should have received a copy of the GNU General Public License
1635 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1637 +Export Aufs via NFS
1638 +----------------------------------------------------------------------
1639 +Here is an approach.
1640 +- like xino/xib, add a new file 'xigen' which stores aufs inode
1642 +- iget_locked(): initialize aufs inode generation for a new inode, and
1643 + store it in xigen file.
1644 +- destroy_inode(): increment aufs inode generation and store it in xigen
1645 + file. it is necessary even if it is not unlinked, because any data of
1646 + inode may be changed by UDBA.
1647 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
1648 + build file handle by
1649 + + branch id (4 bytes)
1650 + + superblock generation (4 bytes)
1651 + + inode number (4 or 8 bytes)
1652 + + parent dir inode number (4 or 8 bytes)
1653 + + inode generation (4 bytes))
1654 + + return value of exportfs_encode_fh() for the parent on a branch (4
1656 + + file handle for a branch (by exportfs_encode_fh())
1658 + + find the index of a branch from its id in handle, and check it is
1659 + still exist in aufs.
1660 + + 1st level: get the inode number from handle and search it in cache.
1661 + + 2nd level: if not found, get the parent inode number from handle and
1662 + search it in cache. and then open the parent dir, find the matching
1663 + inode number by vfs_readdir() and get its name, and call
1664 + lookup_one_len() for the target dentry.
1665 + + 3rd level: if the parent dir is not cached, call
1666 + exportfs_decode_fh() for a branch and get the parent on a branch,
1667 + build a pathname of it, convert it a pathname in aufs, call
1668 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
1670 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
1671 + for every branch, but not itself. to get this, (currently) aufs
1672 + searches in current->nsproxy->mnt_ns list. it may not be a good
1673 + idea, but I didn't get other approach.
1674 + + test the generation of the gotten inode.
1675 +- every inode operation: they may get EBUSY due to UDBA. in this case,
1676 + convert it into ESTALE for NFSD.
1677 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
1678 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
1679 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
1680 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
1681 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2014-06-24 00:14:06.772718759 +0200
1684 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1686 +# This program is free software; you can redistribute it and/or modify
1687 +# it under the terms of the GNU General Public License as published by
1688 +# the Free Software Foundation; either version 2 of the License, or
1689 +# (at your option) any later version.
1691 +# This program is distributed in the hope that it will be useful,
1692 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1693 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1694 +# GNU General Public License for more details.
1696 +# You should have received a copy of the GNU General Public License
1697 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1699 +Show Whiteout Mode (shwh)
1700 +----------------------------------------------------------------------
1701 +Generally aufs hides the name of whiteouts. But in some cases, to show
1702 +them is very useful for users. For instance, creating a new middle layer
1703 +(branch) by merging existing layers.
1705 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
1706 +When you have three branches,
1707 +- Bottom: 'system', squashfs (underlying base system), read-only
1708 +- Middle: 'mods', squashfs, read-only
1709 +- Top: 'overlay', ram (tmpfs), read-write
1711 +The top layer is loaded at boot time and saved at shutdown, to preserve
1712 +the changes made to the system during the session.
1713 +When larger changes have been made, or smaller changes have accumulated,
1714 +the size of the saved top layer data grows. At this point, it would be
1715 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
1716 +and rewrite the 'mods' squashfs, clearing the top layer and thus
1717 +restoring save and load speed.
1719 +This merging is simplified by the use of another aufs mount, of just the
1720 +two overlay branches using the 'shwh' option.
1721 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
1722 + aufs /livesys/merge_union
1724 +A merged view of these two branches is then available at
1725 +/livesys/merge_union, and the new feature is that the whiteouts are
1727 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
1728 +writing to all branches. Also the default mode for all branches is 'ro'.
1729 +It is now possible to save the combined contents of the two overlay
1730 +branches to a new squashfs, e.g.:
1731 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
1733 +This new squashfs archive can be stored on the boot device and the
1734 +initramfs will use it to replace the old one at the next boot.
1735 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
1736 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
1737 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2014-06-24 00:14:06.772718759 +0200
1740 +# Copyright (C) 2010-2014 Junjiro R. Okajima
1742 +# This program is free software; you can redistribute it and/or modify
1743 +# it under the terms of the GNU General Public License as published by
1744 +# the Free Software Foundation; either version 2 of the License, or
1745 +# (at your option) any later version.
1747 +# This program is distributed in the hope that it will be useful,
1748 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1749 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1750 +# GNU General Public License for more details.
1752 +# You should have received a copy of the GNU General Public License
1753 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1755 +Dynamically customizable FS operations
1756 +----------------------------------------------------------------------
1757 +Generally FS operations (struct inode_operations, struct
1758 +address_space_operations, struct file_operations, etc.) are defined as
1759 +"static const", but it never means that FS have only one set of
1760 +operation. Some FS have multiple sets of them. For instance, ext2 has
1761 +three sets, one for XIP, for NOBH, and for normal.
1762 +Since aufs overrides and redirects these operations, sometimes aufs has
1763 +to change its behaviour according to the branch FS type. More imporantly
1764 +VFS acts differently if a function (member in the struct) is set or
1765 +not. It means aufs should have several sets of operations and select one
1766 +among them according to the branch FS definition.
1768 +In order to solve this problem and not to affect the behavour of VFS,
1769 +aufs defines these operations dynamically. For instance, aufs defines
1770 +aio_read function for struct file_operations, but it may not be set to
1771 +the file_operations. When the branch FS doesn't have it, aufs doesn't
1772 +set it to its file_operations while the function definition itself is
1773 +still alive. So the behaviour of io_submit(2) will not change, and it
1774 +will return an error when aio_read is not defined.
1776 +The lifetime of these dynamically generated operation object is
1777 +maintained by aufs branch object. When the branch is removed from aufs,
1778 +the reference counter of the object is decremented. When it reaches
1779 +zero, the dynamically generated operation object will be freed.
1781 +This approach is designed to support AIO (io_submit), Direcit I/O and
1783 +Currently this approach is applied to file_operations and
1784 +vm_operations_struct for regular files only.
1785 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt linux/Documentation/filesystems/aufs/design/99plan.txt
1786 --- /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt 1970-01-01 01:00:00.000000000 +0100
1787 +++ linux/Documentation/filesystems/aufs/design/99plan.txt 2014-06-24 00:14:06.772718759 +0200
1790 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1792 +# This program is free software; you can redistribute it and/or modify
1793 +# it under the terms of the GNU General Public License as published by
1794 +# the Free Software Foundation; either version 2 of the License, or
1795 +# (at your option) any later version.
1797 +# This program is distributed in the hope that it will be useful,
1798 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1799 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1800 +# GNU General Public License for more details.
1802 +# You should have received a copy of the GNU General Public License
1803 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1807 +Restoring some features which was implemented in aufs1.
1808 +They were dropped in aufs2 in order to make source files simpler and
1809 +easier to be reviewed.
1812 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1813 +----------------------------------------------------------------------
1814 +Let's try case study.
1815 +- aufs has two branches, upper readwrite and lower readonly.
1817 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1818 +- user invoked "chmod a+rx /au/dirA"
1819 +- then "dirA" becomes world readable?
1821 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1822 +or it may be a natively readonly filesystem. If aufs respects the lower
1823 +branch, it should not respond readdir request from other users. But user
1824 +allowed it by chmod. Should really aufs rejects showing the entries
1827 +To be honest, I don't have a best solution for this case. So I
1828 +implemented 'dirperm1' and 'nodirperm1' option in aufs1, and leave it to
1830 +When dirperm1 is specified, aufs checks only the highest one for the
1831 +directory permission, and shows the entries. Otherwise, as usual, checks
1832 +every dir existing on all branches and rejects the request.
1834 +As a side effect, dirperm1 option improves the performance of aufs
1835 +because the number of permission check is reduced.
1838 +Being Another Aufs's Readonly Branch (robr)
1839 +----------------------------------------------------------------------
1840 +Aufs1 allows aufs to be another aufs's readonly branch.
1841 +This feature was developed by a user's request. But it may not be used
1845 +Copy-up on Open (coo=)
1846 +----------------------------------------------------------------------
1847 +By default the internal copy-up is executed when it is really necessary.
1848 +It is not done when a file is opened for writing, but when write(2) is
1849 +done. Users who have many (over 100) branches want to know and analyse
1850 +when and what file is copied-up. To insert a new upper branch which
1851 +contains such files only may improve the performance of aufs.
1853 +Aufs1 implemented "coo=none | leaf | all" option.
1856 +Refresh the Opened File (refrof)
1857 +----------------------------------------------------------------------
1858 +This option is implemented in aufs1 but incomplete.
1860 +When user reads from a file, he expects to get its latest filedata
1861 +generally. If the file is removed and a new same named file is created,
1862 +the content he gets is unchanged, ie. the unlinked filedata.
1864 +Let's try case study again.
1865 +- aufs has two branches.
1867 +- "fileA" exists under /ro, but /rw.
1868 +- user opened "/au/fileA".
1869 +- he or someone else inserts a branch (/new) between /rw and /ro.
1870 + /au = /rw + /new + /ro
1871 +- the new branch has "fileA".
1872 +- user reads from the opened "fileA"
1873 +- which filedata should aufs return, from /ro or /new?
1875 +Some people says it has to be "from /ro" and it is a semantics of Unix.
1876 +The others say it should be "from /new" because the file is not removed
1877 +and it is equivalent to the case of someone else modifies the file.
1879 +Here again I don't have a best and final answer. I got an idea to
1880 +implement 'refrof' and 'norefrof' option. When 'refrof' (REFResh the
1881 +Opened File) is specified (by default), aufs returns the filedata from
1883 +Otherwise from /new.
1884 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
1885 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
1886 +++ linux/Documentation/filesystems/aufs/README 2014-06-24 00:14:06.769385243 +0200
1889 +Aufs3 -- advanced multi layered unification filesystem version 3.x
1895 +----------------------------------------
1896 +In the early days, aufs was entirely re-designed and re-implemented
1897 +Unionfs Version 1.x series. After many original ideas, approaches,
1898 +improvements and implementations, it becomes totally different from
1899 +Unionfs while keeping the basic features.
1900 +Recently, Unionfs Version 2.x series begin taking some of the same
1901 +approaches to aufs1's.
1902 +Unionfs is being developed by Professor Erez Zadok at Stony Brook
1903 +University and his team.
1905 +Aufs3 supports linux-3.0 and later.
1906 +If you want older kernel version support, try aufs2-2.6.git or
1907 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
1909 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
1910 + According to Christoph Hellwig, linux rejects all union-type
1911 + filesystems but UnionMount.
1912 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
1914 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
1915 + UnionMount, and he pointed out an issue around a directory mutex
1916 + lock and aufs addressed it. But it is still unsure whether aufs will
1917 + be merged (or any other union solution).
1918 +<http://lkml.org/lkml/2013/3/12/637>
1922 +----------------------------------------
1923 +- unite several directories into a single virtual filesystem. The member
1924 + directory is called as a branch.
1925 +- you can specify the permission flags to the branch, which are 'readonly',
1926 + 'readwrite' and 'whiteout-able.'
1927 +- by upper writable branch, internal copyup and whiteout, files/dirs on
1928 + readonly branch are modifiable logically.
1929 +- dynamic branch manipulation, add, del.
1932 +Also there are many enhancements in aufs1, such as:
1933 +- readdir(3) in userspace.
1934 +- keep inode number by external inode number table
1935 +- keep the timestamps of file/dir in internal copyup operation
1936 +- seekable directory, supporting NFS readdir.
1937 +- whiteout is hardlinked in order to reduce the consumption of inodes
1939 +- do not copyup, nor create a whiteout when it is unnecessary
1940 +- revert a single systemcall when an error occurs in aufs
1941 +- remount interface instead of ioctl
1942 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
1943 +- loopback mounted filesystem as a branch
1944 +- kernel thread for removing the dir who has a plenty of whiteouts
1945 +- support copyup sparse file (a file which has a 'hole' in it)
1946 +- default permission flags for branches
1947 +- selectable permission flags for ro branch, whether whiteout can
1950 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
1951 +- support multiple writable branches, some policies to select one
1952 + among multiple writable branches.
1953 +- a new semantics for link(2) and rename(2) to support multiple
1954 + writable branches.
1955 +- no glibc changes are required.
1956 +- pseudo hardlink (hardlink over branches)
1957 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
1958 + including NFS or remote filesystem branch.
1959 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
1962 +Currently these features are dropped temporary from aufs3.
1963 +See design/08plan.txt in detail.
1964 +- test only the highest one for the directory permission (dirperm1)
1965 +- copyup on open (coo=)
1966 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
1968 +- statistics of aufs thread (/sys/fs/aufs/stat)
1969 +- delegation mode (dlgt)
1970 + a delegation of the internal branch access to support task I/O
1971 + accounting, which also supports Linux Security Modules (LSM) mainly
1972 + for Suse AppArmor.
1973 +- intent.open/create (file open in a single lookup)
1975 +Features or just an idea in the future (see also design/*.txt),
1976 +- reorder the branch index without del/re-add.
1977 +- permanent xino files for NFSD
1978 +- an option for refreshing the opened files after add/del branches
1979 +- 'move' policy for copy-up between two writable branches, after
1980 + checking free space.
1981 +- light version, without branch manipulation. (unnecessary?)
1982 +- copyup in userspace
1983 +- inotify in userspace
1989 +----------------------------------------
1990 +There were three GIT trees for aufs3, aufs3-linux.git,
1991 +aufs3-standalone.git, and aufs-util.git. Note that there is no "3" in
1993 +While the aufs-util is always necessary, you need either of aufs3-linux
1994 +or aufs3-standalone.
1996 +The aufs3-linux tree includes the whole linux mainline GIT tree,
1997 +git://git.kernel.org/.../torvalds/linux.git.
1998 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
1999 +build aufs3 as an external kernel module.
2001 +On the other hand, the aufs3-standalone tree has only aufs source files
2002 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2004 +You will find GIT branches whose name is in form of "aufs3.x" where "x"
2005 +represents the linux kernel version, "linux-3.x". For instance,
2006 +"aufs3.0" is for linux-3.0. For latest "linux-3.x-rcN", use
2007 +"aufs3.x-rcN" branch.
2010 +$ git clone --reference /your/linux/git/tree \
2011 + git://git.code.sf.net/p/aufs/aufs3-linux aufs-aufs3-linux \
2013 +- if you don't have linux GIT tree, then remove "--reference ..."
2014 +$ cd aufs3-linux.git
2015 +$ git checkout origin/aufs3.0
2017 +o aufs3-standalone tree
2018 +$ git clone git://git.code.sf.net/p/aufs/aufs3-standalone \
2019 + aufs3-standalone.git
2020 +$ cd aufs3-standalone.git
2021 +$ git checkout origin/aufs3.0
2024 +$ git clone git://git.code.sf.net/p/aufs/aufs-util \
2027 +$ git checkout origin/aufs3.0
2029 +Note: The 3.x-rcN branch is to be used with `rc' kernel versions ONLY.
2030 +The minor version number, 'x' in '3.x', of aufs may not always
2031 +follow the minor version number of the kernel.
2032 +Because changes in the kernel that cause the use of a new
2033 +minor version number do not always require changes to aufs-util.
2035 +Since aufs-util has its own minor version number, you may not be
2036 +able to find a GIT branch in aufs-util for your kernel's
2037 +exact minor version number.
2038 +In this case, you should git-checkout the branch for the
2039 +nearest lower number.
2041 +For (an unreleased) example:
2042 +If you are using "linux-3.10" and the "aufs3.10" branch
2043 +does not exist in aufs-util repository, then "aufs3.9", "aufs3.8"
2044 +or something numerically smaller is the branch for your kernel.
2046 +Also you can view all branches by
2050 +3. Configuration and Compilation
2051 +----------------------------------------
2052 +Make sure you have git-checkout'ed the correct branch.
2054 +For aufs3-linux tree,
2055 +- enable CONFIG_AUFS_FS.
2056 +- set other aufs configurations if necessary.
2058 +For aufs3-standalone tree,
2059 +There are several ways to build.
2062 +- apply ./aufs3-kbuild.patch to your kernel source files.
2063 +- apply ./aufs3-base.patch too.
2064 +- apply ./aufs3-mmap.patch too.
2065 +- apply ./aufs3-standalone.patch too, if you have a plan to set
2066 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs3-standalone.patch.
2067 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2068 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2069 +- enable CONFIG_AUFS_FS, you can select either
2071 +- and build your kernel as usual.
2072 +- install the built kernel.
2073 + Note: Since linux-3.9, every filesystem module requires an alias
2074 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2075 + modules.aliases file if you set CONFIG_AUFS_FS=m.
2076 +- install the header files too by "make headers_install" to the
2077 + directory where you specify. By default, it is $PWD/usr.
2078 + "make help" shows a brief note for headers_install.
2079 +- and reboot your system.
2082 +- module only (CONFIG_AUFS_FS=m).
2083 +- apply ./aufs3-base.patch to your kernel source files.
2084 +- apply ./aufs3-mmap.patch too.
2085 +- apply ./aufs3-standalone.patch too.
2086 +- build your kernel, don't forget "make headers_install", and reboot.
2087 +- edit ./config.mk and set other aufs configurations if necessary.
2088 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2089 + every aufs configurations.
2090 +- build the module by simple "make".
2091 + Note: Since linux-3.9, every filesystem module requires an alias
2092 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2093 + modules.aliases file.
2094 +- you can specify ${KDIR} make variable which points to your kernel
2096 +- install the files
2097 + + run "make install" to install the aufs module, or copy the built
2098 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2099 + + run "make install_headers" (instead of headers_install) to install
2100 + the modified aufs header file (you can specify DESTDIR which is
2101 + available in aufs standalone version's Makefile only), or copy
2102 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2103 + you like manually. By default, the target directory is $PWD/usr.
2104 +- no need to apply aufs3-kbuild.patch, nor copying source files to your
2105 + kernel source tree.
2107 +Note: The header file aufs_type.h is necessary to build aufs-util
2108 + as well as "make headers_install" in the kernel source tree.
2109 + headers_install is subject to be forgotten, but it is essentially
2110 + necessary, not only for building aufs-util.
2111 + You may not meet problems without headers_install in some older
2115 +- read README in aufs-util, build and install it
2116 +- note that your distribution may contain an obsoleted version of
2117 + aufs_type.h in /usr/include/linux or something. When you build aufs
2118 + utilities, make sure that your compiler refers the correct aufs header
2119 + file which is built by "make headers_install."
2120 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2121 + then run "make install_ulib" too. And refer to the aufs manual in
2124 +There several other patches in aufs3-standalone.git. They are all
2125 +optional. When you meet some problems, they will help you.
2126 +- aufs3-loopback.patch
2127 + Supports a nested loopback mount in a branch-fs. This patch is
2128 + unnecessary until aufs produces a message like "you may want to try
2129 + another patch for loopback file".
2131 + Modifies a system global kernel internal function get_next_ino() in
2132 + order to stop assigning 0 for an inode-number. Not directly related to
2133 + aufs, but recommended generally.
2135 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2136 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2137 + duplication of inode number, which is important for backup tools and
2138 + other utilities. When you find aufs XINO files for tmpfs branch
2139 + growing too much, try this patch.
2143 +----------------------------------------
2144 +At first, make sure aufs-util are installed, and please read the aufs
2145 +manual, aufs.5 in aufs-util.git tree.
2149 +$ mkdir /tmp/rw /tmp/aufs
2150 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2152 +Here is another example. The result is equivalent.
2153 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2155 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2156 +# mount -o remount,append:${HOME} /tmp/aufs
2158 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2159 +you modify a file under /tmp/aufs, the one on your home directory is
2160 +not affected, instead the same named file will be newly created under
2161 +/tmp/rw. And all of your modification to a file will be applied to
2162 +the one under /tmp/rw. This is called the file based Copy on Write
2164 +Aufs mount options are described in aufs.5.
2165 +If you run chroot or something and make your aufs as a root directory,
2166 +then you need to customize the shutdown script. See the aufs manual in
2169 +Additionally, there are some sample usages of aufs which are a
2170 +diskless system with network booting, and LiveCD over NFS.
2171 +See sample dir in CVS tree on SourceForge.
2175 +----------------------------------------
2176 +When you have any problems or strange behaviour in aufs, please let me
2178 +- /proc/mounts (instead of the output of mount(8))
2179 +- /sys/module/aufs/*
2180 +- /sys/fs/aufs/* (if you have them)
2181 +- /debug/aufs/* (if you have them)
2182 +- linux kernel version
2183 + if your kernel is not plain, for example modified by distributor,
2184 + the url where i can download its source is necessary too.
2185 +- aufs version which was printed at loading the module or booting the
2186 + system, instead of the date you downloaded.
2187 +- configuration (define/undefine CONFIG_AUFS_xxx)
2188 +- kernel configuration or /proc/config.gz (if you have it)
2189 +- behaviour which you think to be incorrect
2190 +- actual operation, reproducible one is better
2191 +- mailto: aufs-users at lists.sourceforge.net
2193 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2194 +and Feature Requests) on SourceForge. Please join and write to
2198 +6. Acknowledgements
2199 +----------------------------------------
2200 +Thanks to everyone who have tried and are using aufs, whoever
2201 +have reported a bug or any feedback.
2203 +Especially donators:
2204 +Tomas Matejicek(slax.org) made a donation (much more than once).
2205 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2206 + scripts) is making "doubling" donations.
2207 + Unfortunately I cannot list all of the donators, but I really
2209 + It ends Aug 2010, but the ordinary donation URL is still available.
2210 + <http://sourceforge.net/donate/index.php?group_id=167503>
2211 +Dai Itasaka made a donation (2007/8).
2212 +Chuck Smith made a donation (2008/4, 10 and 12).
2213 +Henk Schoneveld made a donation (2008/9).
2214 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2215 +Francois Dupoux made a donation (2008/11).
2216 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2217 + aufs2 GIT tree (2009/2).
2218 +William Grant made a donation (2009/3).
2219 +Patrick Lane made a donation (2009/4).
2220 +The Mail Archive (mail-archive.com) made donations (2009/5).
2221 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2222 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2223 +Pavel Pronskiy made a donation (2011/2).
2224 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2225 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2226 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2228 +Sam Liddicott made a donation (2011/9).
2229 +Era Scarecrow made a donation (2013/4).
2230 +Bor Ratajc made a donation (2013/4).
2231 +Alessandro Gorreta made a donation (2013/4).
2232 +POIRETTE Marc made a donation (2013/4).
2233 +Alessandro Gorreta made a donation (2013/4).
2234 +lauri kasvandik made a donation (2013/5).
2235 +"pemasu from Finland" made a donation (2013/7).
2236 +The Parted Magic Project made a donation (2013/9 and 11).
2237 +Pavel Barta made a donation (2013/10).
2238 +Nikolay Pertsev made a donation (2014/5).
2240 +Thank you very much.
2241 +Donations are always, including future donations, very important and
2242 +helpful for me to keep on developing aufs.
2246 +----------------------------------------
2247 +If you are an experienced user, no explanation is needed. Aufs is
2248 +just a linux filesystem.
2253 +# Local variables: ;
2256 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2257 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2258 +++ linux/fs/aufs/aufs.h 2014-06-24 00:14:06.776052275 +0200
2261 + * Copyright (C) 2005-2014 Junjiro R. Okajima
2263 + * This program, aufs is free software; you can redistribute it and/or modify
2264 + * it under the terms of the GNU General Public License as published by
2265 + * the Free Software Foundation; either version 2 of the License, or
2266 + * (at your option) any later version.
2268 + * This program is distributed in the hope that it will be useful,
2269 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2270 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2271 + * GNU General Public License for more details.
2273 + * You should have received a copy of the GNU General Public License
2274 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2278 + * all header files
2286 +#define AuStub(type, name, body, ...) \
2287 + static inline type name(__VA_ARGS__) { body; }
2289 +#define AuStubVoid(name, ...) \
2290 + AuStub(void, name, , __VA_ARGS__)
2291 +#define AuStubInt0(name, ...) \
2292 + AuStub(int, name, return 0, __VA_ARGS__)
2296 +#include "branch.h"
2299 +#include "dbgaufs.h"
2300 +#include "dentry.h"
2304 +#include "fstype.h"
2307 +#include "module.h"
2312 +#include "sysaufs.h"
2317 +#endif /* __KERNEL__ */
2318 +#endif /* __AUFS_H__ */
2319 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2320 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2321 +++ linux/fs/aufs/branch.c 2014-06-24 00:14:06.776052275 +0200
2324 + * Copyright (C) 2005-2014 Junjiro R. Okajima
2326 + * This program, aufs is free software; you can redistribute it and/or modify
2327 + * it under the terms of the GNU General Public License as published by
2328 + * the Free Software Foundation; either version 2 of the License, or
2329 + * (at your option) any later version.
2331 + * This program is distributed in the hope that it will be useful,
2332 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2333 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2334 + * GNU General Public License for more details.
2336 + * You should have received a copy of the GNU General Public License
2337 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2341 + * branch management
2344 +#include <linux/compat.h>
2345 +#include <linux/statfs.h>
2349 + * free a single branch
2352 +/* prohibit rmdir to the root of the branch */
2353 +/* todo: another new flag? */
2354 +static void au_br_dflags_force(struct au_branch *br)
2356 + struct dentry *h_dentry;
2358 + h_dentry = au_br_dentry(br);
2359 + spin_lock(&h_dentry->d_lock);
2360 + br->br_dflags = h_dentry->d_flags & DCACHE_MOUNTED;
2361 + h_dentry->d_flags |= DCACHE_MOUNTED;
2362 + spin_unlock(&h_dentry->d_lock);
2365 +/* restore its d_flags */
2366 +static void au_br_dflags_restore(struct au_branch *br)
2368 + struct dentry *h_dentry;
2370 + if (br->br_dflags)
2373 + h_dentry = au_br_dentry(br);
2374 + spin_lock(&h_dentry->d_lock);
2375 + h_dentry->d_flags &= ~DCACHE_MOUNTED;
2376 + spin_unlock(&h_dentry->d_lock);
2379 +static void au_br_do_free(struct au_branch *br)
2382 + struct au_wbr *wbr;
2383 + struct au_dykey **key;
2385 + au_hnotify_fin_br(br);
2387 + if (br->br_xino.xi_file)
2388 + fput(br->br_xino.xi_file);
2389 + mutex_destroy(&br->br_xino.xi_nondir_mtx);
2391 + AuDebugOn(atomic_read(&br->br_count));
2395 + for (i = 0; i < AuBrWh_Last; i++)
2396 + dput(wbr->wbr_wh[i]);
2397 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2398 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2401 + key = br->br_dykey;
2402 + for (i = 0; i < AuBrDynOp; i++, key++)
2408 + au_br_dflags_restore(br);
2410 + /* recursive lock, s_umount of branch's */
2412 + path_put(&br->br_path);
2419 + * frees all branches
2421 +void au_br_free(struct au_sbinfo *sbinfo)
2423 + aufs_bindex_t bmax;
2424 + struct au_branch **br;
2426 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2428 + bmax = sbinfo->si_bend + 1;
2429 + br = sbinfo->si_branch;
2431 + au_br_do_free(*br++);
2435 + * find the index of a branch which is specified by @br_id.
2437 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
2439 + aufs_bindex_t bindex, bend;
2441 + bend = au_sbend(sb);
2442 + for (bindex = 0; bindex <= bend; bindex++)
2443 + if (au_sbr_id(sb, bindex) == br_id)
2448 +/* ---------------------------------------------------------------------- */
2454 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
2455 + struct dentry *h_root)
2457 + if (unlikely(h_adding == h_root
2458 + || au_test_loopback_overlap(sb, h_adding)))
2460 + if (h_adding->d_sb != h_root->d_sb)
2462 + return au_test_subdir(h_adding, h_root)
2463 + || au_test_subdir(h_root, h_adding);
2467 + * returns a newly allocated branch. @new_nbranch is a number of branches
2468 + * after adding a branch.
2470 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
2473 + struct au_branch *add_branch;
2474 + struct dentry *root;
2478 + root = sb->s_root;
2479 + add_branch = kmalloc(sizeof(*add_branch), GFP_NOFS);
2480 + if (unlikely(!add_branch))
2483 + err = au_hnotify_init_br(add_branch, perm);
2484 + if (unlikely(err))
2487 + add_branch->br_wbr = NULL;
2488 + if (au_br_writable(perm)) {
2489 + /* may be freed separately at changing the branch permission */
2490 + add_branch->br_wbr = kmalloc(sizeof(*add_branch->br_wbr),
2492 + if (unlikely(!add_branch->br_wbr))
2496 + err = au_sbr_realloc(au_sbi(sb), new_nbranch);
2498 + err = au_di_realloc(au_di(root), new_nbranch);
2500 + err = au_ii_realloc(au_ii(root->d_inode), new_nbranch);
2502 + return add_branch; /* success */
2504 + kfree(add_branch->br_wbr);
2507 + au_hnotify_fin_br(add_branch);
2509 + kfree(add_branch);
2511 + return ERR_PTR(err);
2515 + * test if the branch permission is legal or not.
2517 +static int test_br(struct inode *inode, int brperm, char *path)
2521 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
2526 + pr_err("write permission for readonly mount or inode, %s\n", path);
2534 + * 0: success, the caller will add it
2535 + * plus: success, it is already unified, the caller should ignore it
2538 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
2541 + aufs_bindex_t bend, bindex;
2542 + struct dentry *root;
2543 + struct inode *inode, *h_inode;
2545 + root = sb->s_root;
2546 + bend = au_sbend(sb);
2547 + if (unlikely(bend >= 0
2548 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
2552 + pr_err("%s duplicated\n", add->pathname);
2557 + err = -ENOSPC; /* -E2BIG; */
2558 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
2559 + || AUFS_BRANCH_MAX - 1 <= bend)) {
2560 + pr_err("number of branches exceeded %s\n", add->pathname);
2565 + if (unlikely(add->bindex < 0 || bend + 1 < add->bindex)) {
2566 + pr_err("bad index %d\n", add->bindex);
2570 + inode = add->path.dentry->d_inode;
2572 + if (unlikely(!inode->i_nlink)) {
2573 + pr_err("no existence %s\n", add->pathname);
2578 + if (unlikely(inode->i_sb == sb)) {
2579 + pr_err("%s must be outside\n", add->pathname);
2583 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
2584 + pr_err("unsupported filesystem, %s (%s)\n",
2585 + add->pathname, au_sbtype(inode->i_sb));
2589 + err = test_br(add->path.dentry->d_inode, add->perm, add->pathname);
2590 + if (unlikely(err))
2594 + return 0; /* success */
2597 + for (bindex = 0; bindex <= bend; bindex++)
2598 + if (unlikely(test_overlap(sb, add->path.dentry,
2599 + au_h_dptr(root, bindex)))) {
2600 + pr_err("%s is overlapped\n", add->pathname);
2605 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
2606 + h_inode = au_h_dptr(root, 0)->d_inode;
2607 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
2608 + || !uid_eq(h_inode->i_uid, inode->i_uid)
2609 + || !gid_eq(h_inode->i_gid, inode->i_gid))
2610 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
2612 + i_uid_read(inode), i_gid_read(inode),
2613 + (inode->i_mode & S_IALLUGO),
2614 + i_uid_read(h_inode), i_gid_read(h_inode),
2615 + (h_inode->i_mode & S_IALLUGO));
2623 + * initialize or clean the whiteouts for an adding branch
2625 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
2628 + int err, old_perm;
2629 + aufs_bindex_t bindex;
2630 + struct mutex *h_mtx;
2631 + struct au_wbr *wbr;
2632 + struct au_hinode *hdir;
2634 + err = vfsub_mnt_want_write(au_br_mnt(br));
2635 + if (unlikely(err))
2639 + old_perm = br->br_perm;
2640 + br->br_perm = new_perm;
2643 + bindex = au_br_index(sb, br->br_id);
2644 + if (0 <= bindex) {
2645 + hdir = au_hi(sb->s_root->d_inode, bindex);
2646 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
2648 + h_mtx = &au_br_dentry(br)->d_inode->i_mutex;
2649 + mutex_lock_nested(h_mtx, AuLsc_I_PARENT);
2652 + err = au_wh_init(br, sb);
2654 + wbr_wh_write_lock(wbr);
2655 + err = au_wh_init(br, sb);
2656 + wbr_wh_write_unlock(wbr);
2659 + au_hn_imtx_unlock(hdir);
2661 + mutex_unlock(h_mtx);
2662 + vfsub_mnt_drop_write(au_br_mnt(br));
2663 + br->br_perm = old_perm;
2665 + if (!err && wbr && !au_br_writable(new_perm)) {
2667 + br->br_wbr = NULL;
2674 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
2678 + struct kstatfs kst;
2679 + struct au_wbr *wbr;
2682 + au_rw_init(&wbr->wbr_wh_rwsem);
2683 + memset(wbr->wbr_wh, 0, sizeof(wbr->wbr_wh));
2684 + atomic_set(&wbr->wbr_wh_running, 0);
2685 + wbr->wbr_bytes = 0;
2688 + * a limit for rmdir/rename a dir
2689 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
2691 + err = vfs_statfs(&br->br_path, &kst);
2692 + if (unlikely(err))
2695 + if (kst.f_namelen >= NAME_MAX)
2696 + err = au_br_init_wh(sb, br, perm);
2698 + pr_err("%pd(%s), unsupported namelen %ld\n",
2700 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
2706 +/* intialize a new branch */
2707 +static int au_br_init(struct au_branch *br, struct super_block *sb,
2708 + struct au_opt_add *add)
2713 + memset(&br->br_xino, 0, sizeof(br->br_xino));
2714 + mutex_init(&br->br_xino.xi_nondir_mtx);
2715 + br->br_perm = add->perm;
2716 + BUILD_BUG_ON(sizeof(br->br_dflags)
2717 + != sizeof(br->br_path.dentry->d_flags));
2718 + br->br_dflags = DCACHE_MOUNTED;
2719 + br->br_path = add->path; /* set first, path_get() later */
2720 + spin_lock_init(&br->br_dykey_lock);
2721 + memset(br->br_dykey, 0, sizeof(br->br_dykey));
2722 + atomic_set(&br->br_count, 0);
2723 + atomic_set(&br->br_xino_running, 0);
2724 + br->br_id = au_new_br_id(sb);
2725 + AuDebugOn(br->br_id < 0);
2727 + if (au_br_writable(add->perm)) {
2728 + err = au_wbr_init(br, sb, add->perm);
2729 + if (unlikely(err))
2733 + if (au_opt_test(au_mntflags(sb), XINO)) {
2734 + err = au_xino_br(sb, br, add->path.dentry->d_inode->i_ino,
2735 + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1);
2736 + if (unlikely(err)) {
2737 + AuDebugOn(br->br_xino.xi_file);
2742 + sysaufs_br_init(br);
2743 + path_get(&br->br_path);
2744 + goto out; /* success */
2747 + memset(&br->br_path, 0, sizeof(br->br_path));
2752 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
2753 + struct au_branch *br, aufs_bindex_t bend,
2754 + aufs_bindex_t amount)
2756 + struct au_branch **brp;
2758 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2760 + brp = sbinfo->si_branch + bindex;
2761 + memmove(brp + 1, brp, sizeof(*brp) * amount);
2763 + sbinfo->si_bend++;
2764 + if (unlikely(bend < 0))
2765 + sbinfo->si_bend = 0;
2768 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
2769 + aufs_bindex_t bend, aufs_bindex_t amount)
2771 + struct au_hdentry *hdp;
2773 + AuRwMustWriteLock(&dinfo->di_rwsem);
2775 + hdp = dinfo->di_hdentry + bindex;
2776 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
2777 + au_h_dentry_init(hdp);
2779 + if (unlikely(bend < 0))
2780 + dinfo->di_bstart = 0;
2783 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
2784 + aufs_bindex_t bend, aufs_bindex_t amount)
2786 + struct au_hinode *hip;
2788 + AuRwMustWriteLock(&iinfo->ii_rwsem);
2790 + hip = iinfo->ii_hinode + bindex;
2791 + memmove(hip + 1, hip, sizeof(*hip) * amount);
2792 + hip->hi_inode = NULL;
2795 + if (unlikely(bend < 0))
2796 + iinfo->ii_bstart = 0;
2799 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
2800 + aufs_bindex_t bindex)
2802 + struct dentry *root, *h_dentry;
2803 + struct inode *root_inode;
2804 + aufs_bindex_t bend, amount;
2806 + au_br_dflags_force(br);
2808 + root = sb->s_root;
2809 + root_inode = root->d_inode;
2810 + bend = au_sbend(sb);
2811 + amount = bend + 1 - bindex;
2812 + h_dentry = au_br_dentry(br);
2813 + au_sbilist_lock();
2814 + au_br_do_add_brp(au_sbi(sb), bindex, br, bend, amount);
2815 + au_br_do_add_hdp(au_di(root), bindex, bend, amount);
2816 + au_br_do_add_hip(au_ii(root_inode), bindex, bend, amount);
2817 + au_set_h_dptr(root, bindex, dget(h_dentry));
2818 + au_set_h_iptr(root_inode, bindex, au_igrab(h_dentry->d_inode),
2820 + au_sbilist_unlock();
2823 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
2826 + aufs_bindex_t bend, add_bindex;
2827 + struct dentry *root, *h_dentry;
2828 + struct inode *root_inode;
2829 + struct au_branch *add_branch;
2831 + root = sb->s_root;
2832 + root_inode = root->d_inode;
2833 + IMustLock(root_inode);
2834 + err = test_add(sb, add, remount);
2835 + if (unlikely(err < 0))
2839 + goto out; /* success */
2842 + bend = au_sbend(sb);
2843 + add_branch = au_br_alloc(sb, bend + 2, add->perm);
2844 + err = PTR_ERR(add_branch);
2845 + if (IS_ERR(add_branch))
2848 + err = au_br_init(add_branch, sb, add);
2849 + if (unlikely(err)) {
2850 + au_br_do_free(add_branch);
2854 + add_bindex = add->bindex;
2856 + au_br_do_add(sb, add_branch, add_bindex);
2858 + sysaufs_brs_del(sb, add_bindex);
2859 + au_br_do_add(sb, add_branch, add_bindex);
2860 + sysaufs_brs_add(sb, add_bindex);
2863 + h_dentry = add->path.dentry;
2864 + if (!add_bindex) {
2865 + au_cpup_attr_all(root_inode, /*force*/1);
2866 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
2868 + au_add_nlink(root_inode, h_dentry->d_inode);
2871 + * this test/set prevents aufs from handling unnecesary notify events
2872 + * of xino files, in case of re-adding a writable branch which was
2873 + * once detached from aufs.
2875 + if (au_xino_brid(sb) < 0
2876 + && au_br_writable(add_branch->br_perm)
2877 + && !au_test_fs_bad_xino(h_dentry->d_sb)
2878 + && add_branch->br_xino.xi_file
2879 + && add_branch->br_xino.xi_file->f_dentry->d_parent == h_dentry)
2880 + au_xino_brid_set(sb, add_branch->br_id);
2886 +/* ---------------------------------------------------------------------- */
2892 +/* to show the line number, do not make it inlined function */
2893 +#define AuVerbose(do_info, fmt, ...) do { \
2895 + pr_info(fmt, ##__VA_ARGS__); \
2898 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t bstart,
2899 + aufs_bindex_t bend)
2901 + return (inode && !S_ISDIR(inode->i_mode)) || bstart == bend;
2904 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t bstart,
2905 + aufs_bindex_t bend)
2907 + return au_test_ibusy(dentry->d_inode, bstart, bend);
2911 + * test if the branch is deletable or not.
2913 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
2914 + unsigned int sigen, const unsigned int verbose)
2916 + int err, i, j, ndentry;
2917 + aufs_bindex_t bstart, bend;
2918 + struct au_dcsub_pages dpages;
2919 + struct au_dpage *dpage;
2922 + err = au_dpages_init(&dpages, GFP_NOFS);
2923 + if (unlikely(err))
2925 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
2926 + if (unlikely(err))
2929 + for (i = 0; !err && i < dpages.ndpage; i++) {
2930 + dpage = dpages.dpages + i;
2931 + ndentry = dpage->ndentry;
2932 + for (j = 0; !err && j < ndentry; j++) {
2933 + d = dpage->dentries[j];
2934 + AuDebugOn(!d_count(d));
2935 + if (!au_digen_test(d, sigen)) {
2936 + di_read_lock_child(d, AuLock_IR);
2937 + if (unlikely(au_dbrange_test(d))) {
2938 + di_read_unlock(d, AuLock_IR);
2942 + di_write_lock_child(d);
2943 + if (unlikely(au_dbrange_test(d))) {
2944 + di_write_unlock(d);
2947 + err = au_reval_dpath(d, sigen);
2949 + di_downgrade_lock(d, AuLock_IR);
2951 + di_write_unlock(d);
2956 + /* AuDbgDentry(d); */
2957 + bstart = au_dbstart(d);
2958 + bend = au_dbend(d);
2959 + if (bstart <= bindex
2961 + && au_h_dptr(d, bindex)
2962 + && au_test_dbusy(d, bstart, bend)) {
2964 + AuVerbose(verbose, "busy %pd\n", d);
2967 + di_read_unlock(d, AuLock_IR);
2972 + au_dpages_free(&dpages);
2977 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
2978 + unsigned int sigen, const unsigned int verbose)
2981 + unsigned long long max, ull;
2982 + struct inode *i, **array;
2983 + aufs_bindex_t bstart, bend;
2985 + array = au_iarray_alloc(sb, &max);
2986 + err = PTR_ERR(array);
2987 + if (IS_ERR(array))
2991 + AuDbg("b%d\n", bindex);
2992 + for (ull = 0; !err && ull < max; ull++) {
2994 + if (i->i_ino == AUFS_ROOT_INO)
2997 + /* AuDbgInode(i); */
2998 + if (au_iigen(i, NULL) == sigen)
2999 + ii_read_lock_child(i);
3001 + ii_write_lock_child(i);
3002 + err = au_refresh_hinode_self(i);
3005 + ii_downgrade_lock(i);
3007 + ii_write_unlock(i);
3012 + bstart = au_ibstart(i);
3013 + bend = au_ibend(i);
3014 + if (bstart <= bindex
3016 + && au_h_iptr(i, bindex)
3017 + && au_test_ibusy(i, bstart, bend)) {
3019 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3022 + ii_read_unlock(i);
3024 + au_iarray_free(array, max);
3030 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3031 + const unsigned int verbose)
3034 + unsigned int sigen;
3036 + sigen = au_sigen(root->d_sb);
3037 + DiMustNoWaiters(root);
3038 + IiMustNoWaiters(root->d_inode);
3039 + di_write_unlock(root);
3040 + err = test_dentry_busy(root, bindex, sigen, verbose);
3042 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3043 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3048 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3049 + const aufs_bindex_t bindex,
3050 + const aufs_bindex_t bend)
3052 + struct au_branch **brp, **p;
3054 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3056 + brp = sbinfo->si_branch + bindex;
3057 + if (bindex < bend)
3058 + memmove(brp, brp + 1, sizeof(*brp) * (bend - bindex));
3059 + sbinfo->si_branch[0 + bend] = NULL;
3060 + sbinfo->si_bend--;
3062 + p = krealloc(sbinfo->si_branch, sizeof(*p) * bend, AuGFP_SBILIST);
3064 + sbinfo->si_branch = p;
3065 + /* harmless error */
3068 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3069 + const aufs_bindex_t bend)
3071 + struct au_hdentry *hdp, *p;
3073 + AuRwMustWriteLock(&dinfo->di_rwsem);
3075 + hdp = dinfo->di_hdentry;
3076 + if (bindex < bend)
3077 + memmove(hdp + bindex, hdp + bindex + 1,
3078 + sizeof(*hdp) * (bend - bindex));
3079 + hdp[0 + bend].hd_dentry = NULL;
3082 + p = krealloc(hdp, sizeof(*p) * bend, AuGFP_SBILIST);
3084 + dinfo->di_hdentry = p;
3085 + /* harmless error */
3088 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3089 + const aufs_bindex_t bend)
3091 + struct au_hinode *hip, *p;
3093 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3095 + hip = iinfo->ii_hinode + bindex;
3096 + if (bindex < bend)
3097 + memmove(hip, hip + 1, sizeof(*hip) * (bend - bindex));
3098 + iinfo->ii_hinode[0 + bend].hi_inode = NULL;
3099 + au_hn_init(iinfo->ii_hinode + bend);
3102 + p = krealloc(iinfo->ii_hinode, sizeof(*p) * bend, AuGFP_SBILIST);
3104 + iinfo->ii_hinode = p;
3105 + /* harmless error */
3108 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3109 + struct au_branch *br)
3111 + aufs_bindex_t bend;
3112 + struct au_sbinfo *sbinfo;
3113 + struct dentry *root, *h_root;
3114 + struct inode *inode, *h_inode;
3115 + struct au_hinode *hinode;
3117 + SiMustWriteLock(sb);
3119 + root = sb->s_root;
3120 + inode = root->d_inode;
3121 + sbinfo = au_sbi(sb);
3122 + bend = sbinfo->si_bend;
3124 + h_root = au_h_dptr(root, bindex);
3125 + hinode = au_hi(inode, bindex);
3126 + h_inode = au_igrab(hinode->hi_inode);
3129 + au_sbilist_lock();
3130 + au_br_do_del_brp(sbinfo, bindex, bend);
3131 + au_br_do_del_hdp(au_di(root), bindex, bend);
3132 + au_br_do_del_hip(au_ii(inode), bindex, bend);
3133 + au_sbilist_unlock();
3137 + au_br_do_free(br);
3140 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3143 + unsigned int mnt_flags;
3144 + aufs_bindex_t bindex, bend, br_id;
3145 + unsigned char do_wh, verbose;
3146 + struct au_branch *br;
3147 + struct au_wbr *wbr;
3150 + bindex = au_find_dbindex(sb->s_root, del->h_path.dentry);
3153 + goto out; /* success */
3155 + pr_err("%s no such branch\n", del->pathname);
3158 + AuDbg("bindex b%d\n", bindex);
3161 + mnt_flags = au_mntflags(sb);
3162 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3163 + bend = au_sbend(sb);
3164 + if (unlikely(!bend)) {
3165 + AuVerbose(verbose, "no more branches left\n");
3168 + br = au_sbr(sb, bindex);
3169 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3170 + i = atomic_read(&br->br_count);
3171 + if (unlikely(i)) {
3172 + AuVerbose(verbose, "%d file(s) opened\n", i);
3177 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3179 + /* instead of WbrWhMustWriteLock(wbr) */
3180 + SiMustWriteLock(sb);
3181 + for (i = 0; i < AuBrWh_Last; i++) {
3182 + dput(wbr->wbr_wh[i]);
3183 + wbr->wbr_wh[i] = NULL;
3187 + err = test_children_busy(sb->s_root, bindex, verbose);
3188 + if (unlikely(err)) {
3195 + br_id = br->br_id;
3197 + au_br_do_del(sb, bindex, br);
3199 + sysaufs_brs_del(sb, bindex);
3200 + au_br_do_del(sb, bindex, br);
3201 + sysaufs_brs_add(sb, bindex);
3205 + au_cpup_attr_all(sb->s_root->d_inode, /*force*/1);
3206 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
3208 + au_sub_nlink(sb->s_root->d_inode, del->h_path.dentry->d_inode);
3209 + if (au_opt_test(mnt_flags, PLINK))
3210 + au_plink_half_refresh(sb, br_id);
3212 + if (au_xino_brid(sb) == br_id)
3213 + au_xino_brid_set(sb, -1);
3214 + goto out; /* success */
3218 + rerr = au_br_init_wh(sb, br, br->br_perm);
3220 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
3221 + del->pathname, rerr);
3226 +/* ---------------------------------------------------------------------- */
3228 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
3231 + aufs_bindex_t bstart, bend;
3232 + struct aufs_ibusy ibusy;
3233 + struct inode *inode, *h_inode;
3236 + if (unlikely(!capable(CAP_SYS_ADMIN)))
3239 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
3241 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
3242 + if (unlikely(err)) {
3249 + si_read_lock(sb, AuLock_FLUSH);
3250 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbend(sb)))
3254 + ibusy.h_ino = 0; /* invalid */
3255 + inode = ilookup(sb, ibusy.ino);
3257 + || inode->i_ino == AUFS_ROOT_INO
3258 + || is_bad_inode(inode))
3261 + ii_read_lock_child(inode);
3262 + bstart = au_ibstart(inode);
3263 + bend = au_ibend(inode);
3264 + if (bstart <= ibusy.bindex && ibusy.bindex <= bend) {
3265 + h_inode = au_h_iptr(inode, ibusy.bindex);
3266 + if (h_inode && au_test_ibusy(inode, bstart, bend))
3267 + ibusy.h_ino = h_inode->i_ino;
3269 + ii_read_unlock(inode);
3273 + si_read_unlock(sb);
3275 + err = __put_user(ibusy.h_ino, &arg->h_ino);
3276 + if (unlikely(err)) {
3285 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
3287 + return au_ibusy(file->f_dentry->d_sb, (void __user *)arg);
3290 +#ifdef CONFIG_COMPAT
3291 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
3293 + return au_ibusy(file->f_dentry->d_sb, compat_ptr(arg));
3297 +/* ---------------------------------------------------------------------- */
3300 + * change a branch permission
3303 +static void au_warn_ima(void)
3306 + /* since it doesn't support mark_files_ro() */
3307 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
3311 +static int do_need_sigen_inc(int a, int b)
3313 + return au_br_whable(a) && !au_br_whable(b);
3316 +static int need_sigen_inc(int old, int new)
3318 + return do_need_sigen_inc(old, new)
3319 + || do_need_sigen_inc(new, old);
3322 +static unsigned long long au_farray_cb(void *a,
3323 + unsigned long long max __maybe_unused,
3326 + unsigned long long n;
3327 + struct file **p, *f;
3328 + struct au_sphlhead *files;
3329 + struct au_finfo *finfo;
3330 + struct super_block *sb = arg;
3334 + files = &au_sbi(sb)->si_files;
3335 + spin_lock(&files->spin);
3336 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
3337 + f = finfo->fi_file;
3339 + && !special_file(file_inode(f)->i_mode)) {
3343 + AuDebugOn(n > max);
3346 + spin_unlock(&files->spin);
3351 +static struct file **au_farray_alloc(struct super_block *sb,
3352 + unsigned long long *max)
3354 + *max = atomic_long_read(&au_sbi(sb)->si_nfiles);
3355 + return au_array_alloc(max, au_farray_cb, sb);
3358 +static void au_farray_free(struct file **a, unsigned long long max)
3360 + unsigned long long ull;
3362 + for (ull = 0; ull < max; ull++)
3368 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
3371 + unsigned int mnt_flags;
3372 + unsigned long long ull, max;
3373 + aufs_bindex_t br_id;
3374 + unsigned char verbose, writer;
3375 + struct file *file, *hf, **array;
3376 + struct inode *inode;
3377 + struct au_hfile *hfile;
3379 + mnt_flags = au_mntflags(sb);
3380 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3382 + array = au_farray_alloc(sb, &max);
3383 + err = PTR_ERR(array);
3384 + if (IS_ERR(array))
3388 + br_id = au_sbr_id(sb, bindex);
3389 + for (ull = 0; ull < max; ull++) {
3390 + file = array[ull];
3392 + /* AuDbg("%pD\n", file); */
3393 + fi_read_lock(file);
3394 + if (unlikely(au_test_mmapped(file))) {
3396 + AuVerbose(verbose, "mmapped %pD\n", file);
3398 + FiMustNoWaiters(file);
3399 + fi_read_unlock(file);
3403 + inode = file_inode(file);
3404 + hfile = &au_fi(file)->fi_htop;
3405 + hf = hfile->hf_file;
3406 + if (!S_ISREG(inode->i_mode)
3407 + || !(file->f_mode & FMODE_WRITE)
3408 + || hfile->hf_br->br_id != br_id
3409 + || !(hf->f_mode & FMODE_WRITE))
3410 + array[ull] = NULL;
3416 + FiMustNoWaiters(file);
3417 + fi_read_unlock(file);
3425 + for (ull = 0; ull < max; ull++) {
3426 + file = array[ull];
3430 + /* todo: already flushed? */
3432 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
3433 + * approach which resets f_mode and calls mnt_drop_write() and
3434 + * file_release_write() for each file, because the branch
3435 + * attribute in aufs world is totally different from the native
3438 + /* fi_read_lock(file); */
3439 + hfile = &au_fi(file)->fi_htop;
3440 + hf = hfile->hf_file;
3441 + /* fi_read_unlock(file); */
3442 + spin_lock(&hf->f_lock);
3443 + writer = !!(hf->f_mode & FMODE_WRITER);
3444 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
3445 + spin_unlock(&hf->f_lock);
3447 + put_write_access(file_inode(hf));
3448 + __mnt_drop_write(hf->f_path.mnt);
3453 + au_farray_free(array, max);
3459 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
3463 + aufs_bindex_t bindex;
3464 + struct dentry *root;
3465 + struct au_branch *br;
3467 + root = sb->s_root;
3468 + bindex = au_find_dbindex(root, mod->h_root);
3471 + return 0; /* success */
3473 + pr_err("%s no such branch\n", mod->path);
3476 + AuDbg("bindex b%d\n", bindex);
3478 + err = test_br(mod->h_root->d_inode, mod->perm, mod->path);
3479 + if (unlikely(err))
3482 + br = au_sbr(sb, bindex);
3483 + AuDebugOn(mod->h_root != au_br_dentry(br));
3484 + if (br->br_perm == mod->perm)
3485 + return 0; /* success */
3487 + if (au_br_writable(br->br_perm)) {
3488 + /* remove whiteout base */
3489 + err = au_br_init_wh(sb, br, mod->perm);
3490 + if (unlikely(err))
3493 + if (!au_br_writable(mod->perm)) {
3494 + /* rw --> ro, file might be mmapped */
3495 + DiMustNoWaiters(root);
3496 + IiMustNoWaiters(root->d_inode);
3497 + di_write_unlock(root);
3498 + err = au_br_mod_files_ro(sb, bindex);
3499 + /* aufs_write_lock() calls ..._child() */
3500 + di_write_lock_child(root);
3502 + if (unlikely(err)) {
3504 + br->br_wbr = kmalloc(sizeof(*br->br_wbr),
3507 + rerr = au_wbr_init(br, sb, br->br_perm);
3508 + if (unlikely(rerr)) {
3509 + AuIOErr("nested error %d (%d)\n",
3511 + br->br_perm = mod->perm;
3515 + } else if (au_br_writable(mod->perm)) {
3518 + br->br_wbr = kmalloc(sizeof(*br->br_wbr), GFP_NOFS);
3520 + err = au_wbr_init(br, sb, mod->perm);
3521 + if (unlikely(err)) {
3522 + kfree(br->br_wbr);
3523 + br->br_wbr = NULL;
3529 + if ((br->br_perm & AuBrAttr_UNPIN)
3530 + && !(mod->perm & AuBrAttr_UNPIN))
3531 + au_br_dflags_force(br);
3532 + else if (!(br->br_perm & AuBrAttr_UNPIN)
3533 + && (mod->perm & AuBrAttr_UNPIN))
3534 + au_br_dflags_restore(br);
3535 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
3536 + br->br_perm = mod->perm;
3543 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
3544 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
3545 +++ linux/fs/aufs/branch.h 2014-06-24 00:14:06.776052275 +0200
3548 + * Copyright (C) 2005-2014 Junjiro R. Okajima
3550 + * This program, aufs is free software; you can redistribute it and/or modify
3551 + * it under the terms of the GNU General Public License as published by
3552 + * the Free Software Foundation; either version 2 of the License, or
3553 + * (at your option) any later version.
3555 + * This program is distributed in the hope that it will be useful,
3556 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3557 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3558 + * GNU General Public License for more details.
3560 + * You should have received a copy of the GNU General Public License
3561 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3565 + * branch filesystems and xino for them
3568 +#ifndef __AUFS_BRANCH_H__
3569 +#define __AUFS_BRANCH_H__
3573 +#include <linux/mount.h>
3578 +/* ---------------------------------------------------------------------- */
3581 +struct au_xino_file {
3582 + struct file *xi_file;
3583 + struct mutex xi_nondir_mtx;
3585 + /* todo: make xino files an array to support huge inode number */
3587 +#ifdef CONFIG_DEBUG_FS
3588 + struct dentry *xi_dbgaufs;
3592 +/* members for writable branch only */
3593 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
3595 + struct au_rwsem wbr_wh_rwsem;
3596 + struct dentry *wbr_wh[AuBrWh_Last];
3597 + atomic_t wbr_wh_running;
3598 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
3599 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
3600 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
3603 + unsigned long long wbr_bytes;
3606 +/* ext2 has 3 types of operations at least, ext3 has 4 */
3607 +#define AuBrDynOp (AuDyLast * 4)
3609 +#ifdef CONFIG_AUFS_HFSNOTIFY
3610 +/* support for asynchronous destruction */
3611 +struct au_br_hfsnotify {
3612 + struct fsnotify_group *hfsn_group;
3616 +/* sysfs entries */
3617 +struct au_brsysfs {
3619 + struct attribute attr;
3628 +/* protected by superblock rwsem */
3630 + struct au_xino_file br_xino;
3632 + aufs_bindex_t br_id;
3635 + unsigned int br_dflags;
3636 + struct path br_path;
3637 + spinlock_t br_dykey_lock;
3638 + struct au_dykey *br_dykey[AuBrDynOp];
3639 + atomic_t br_count;
3641 + struct au_wbr *br_wbr;
3643 + /* xino truncation */
3644 + atomic_t br_xino_running;
3646 +#ifdef CONFIG_AUFS_HFSNOTIFY
3647 + struct au_br_hfsnotify *br_hfsn;
3650 +#ifdef CONFIG_SYSFS
3651 + /* entries under sysfs per mount-point */
3652 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
3656 +/* ---------------------------------------------------------------------- */
3658 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
3660 + return br->br_path.mnt;
3663 +static inline struct dentry *au_br_dentry(struct au_branch *br)
3665 + return br->br_path.dentry;
3668 +static inline struct super_block *au_br_sb(struct au_branch *br)
3670 + return au_br_mnt(br)->mnt_sb;
3673 +/* branch permissions and attributes */
3674 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
3675 +#define AuBrPerm_RO (1 << 1) /* readonly */
3676 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
3677 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
3679 +#define AuBrRAttr_WH (1 << 3) /* whiteout-able */
3681 +#define AuBrWAttr_NoLinkWH (1 << 4) /* un-hardlinkable whiteouts */
3683 +#define AuBrAttr_UNPIN (1 << 5) /* rename-able top dir of
3686 +static inline int au_br_writable(int brperm)
3688 + return brperm & AuBrPerm_RW;
3691 +static inline int au_br_whable(int brperm)
3693 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
3696 +static inline int au_br_wh_linkable(int brperm)
3698 + return !(brperm & AuBrWAttr_NoLinkWH);
3701 +static inline int au_br_rdonly(struct au_branch *br)
3703 + return ((au_br_sb(br)->s_flags & MS_RDONLY)
3704 + || !au_br_writable(br->br_perm))
3708 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
3710 +#ifdef CONFIG_AUFS_HNOTIFY
3711 + return !(brperm & AuBrPerm_RR);
3717 +/* ---------------------------------------------------------------------- */
3721 +void au_br_free(struct au_sbinfo *sinfo);
3722 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
3724 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
3726 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
3727 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
3728 +#ifdef CONFIG_COMPAT
3729 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
3732 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
3736 +static const loff_t au_loff_max = LLONG_MAX;
3738 +int au_xib_trunc(struct super_block *sb);
3739 +ssize_t xino_fread(au_readf_t func, struct file *file, void *buf, size_t size,
3741 +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size,
3743 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src);
3744 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent);
3745 +ino_t au_xino_new_ino(struct super_block *sb);
3746 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
3747 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
3749 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
3751 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino,
3752 + struct file *base_file, int do_test);
3753 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex);
3755 +struct au_opt_xino;
3756 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount);
3757 +void au_xino_clr(struct super_block *sb);
3758 +struct file *au_xino_def(struct super_block *sb);
3759 +int au_xino_path(struct seq_file *seq, struct file *file);
3761 +/* ---------------------------------------------------------------------- */
3763 +/* Superblock to branch */
3765 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
3767 + return au_sbr(sb, bindex)->br_id;
3771 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
3773 + return au_br_mnt(au_sbr(sb, bindex));
3777 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
3779 + return au_br_sb(au_sbr(sb, bindex));
3782 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
3784 + atomic_dec(&au_sbr(sb, bindex)->br_count);
3787 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
3789 + return au_sbr(sb, bindex)->br_perm;
3792 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
3794 + return au_br_whable(au_sbr_perm(sb, bindex));
3797 +/* ---------------------------------------------------------------------- */
3800 + * wbr_wh_read_lock, wbr_wh_write_lock
3801 + * wbr_wh_read_unlock, wbr_wh_write_unlock, wbr_wh_downgrade_lock
3803 +AuSimpleRwsemFuncs(wbr_wh, struct au_wbr *wbr, &wbr->wbr_wh_rwsem);
3805 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&wbr->wbr_wh_rwsem)
3806 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&wbr->wbr_wh_rwsem)
3807 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&wbr->wbr_wh_rwsem)
3809 +#endif /* __KERNEL__ */
3810 +#endif /* __AUFS_BRANCH_H__ */
3811 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
3812 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
3813 +++ linux/fs/aufs/conf.mk 2014-06-24 00:14:06.776052275 +0200
3816 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
3820 +AuConfStr += ${1}=${${1}}
3824 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
3826 + HNOTIFY HFSNOTIFY \
3835 +$(foreach i, ${AuConfAll}, \
3836 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
3838 +AuConfName = ${obj}/conf.str
3839 +${AuConfName}.tmp: FORCE
3840 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
3841 +${AuConfName}: ${AuConfName}.tmp
3842 + @diff -q $< $@ > /dev/null 2>&1 || { \
3843 + echo ' GEN ' $@; \
3847 +clean-files += ${AuConfName} ${AuConfName}.tmp
3848 +${obj}/sysfs.o: ${AuConfName}
3850 +-include ${srctree}/${src}/conf_priv.mk
3851 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
3852 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
3853 +++ linux/fs/aufs/cpup.c 2014-06-24 00:14:06.779385790 +0200
3856 + * Copyright (C) 2005-2014 Junjiro R. Okajima
3858 + * This program, aufs is free software; you can redistribute it and/or modify
3859 + * it under the terms of the GNU General Public License as published by
3860 + * the Free Software Foundation; either version 2 of the License, or
3861 + * (at your option) any later version.
3863 + * This program is distributed in the hope that it will be useful,
3864 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3865 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3866 + * GNU General Public License for more details.
3868 + * You should have received a copy of the GNU General Public License
3869 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3873 + * copy-up functions, see wbr_policy.c for copy-down
3876 +#include <linux/fs_stack.h>
3877 +#include <linux/mm.h>
3880 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
3882 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
3883 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
3885 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
3887 + dst->i_flags |= iflags & ~mask;
3888 + if (au_test_fs_notime(dst->i_sb))
3889 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
3892 +void au_cpup_attr_timesizes(struct inode *inode)
3894 + struct inode *h_inode;
3896 + h_inode = au_h_iptr(inode, au_ibstart(inode));
3897 + fsstack_copy_attr_times(inode, h_inode);
3898 + fsstack_copy_inode_size(inode, h_inode);
3901 +void au_cpup_attr_nlink(struct inode *inode, int force)
3903 + struct inode *h_inode;
3904 + struct super_block *sb;
3905 + aufs_bindex_t bindex, bend;
3908 + bindex = au_ibstart(inode);
3909 + h_inode = au_h_iptr(inode, bindex);
3911 + && !S_ISDIR(h_inode->i_mode)
3912 + && au_opt_test(au_mntflags(sb), PLINK)
3913 + && au_plink_test(inode))
3917 + * 0 can happen in revalidating.
3918 + * h_inode->i_mutex may not be held here, but it is harmless since once
3919 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
3921 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
3922 + * the incorrect link count.
3924 + set_nlink(inode, h_inode->i_nlink);
3927 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
3928 + * it may includes whplink directory.
3930 + if (S_ISDIR(h_inode->i_mode)) {
3931 + bend = au_ibend(inode);
3932 + for (bindex++; bindex <= bend; bindex++) {
3933 + h_inode = au_h_iptr(inode, bindex);
3935 + au_add_nlink(inode, h_inode);
3940 +void au_cpup_attr_changeable(struct inode *inode)
3942 + struct inode *h_inode;
3944 + h_inode = au_h_iptr(inode, au_ibstart(inode));
3945 + inode->i_mode = h_inode->i_mode;
3946 + inode->i_uid = h_inode->i_uid;
3947 + inode->i_gid = h_inode->i_gid;
3948 + au_cpup_attr_timesizes(inode);
3949 + au_cpup_attr_flags(inode, h_inode->i_flags);
3952 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
3954 + struct au_iinfo *iinfo = au_ii(inode);
3956 + IiMustWriteLock(inode);
3958 + iinfo->ii_higen = h_inode->i_generation;
3959 + iinfo->ii_hsb1 = h_inode->i_sb;
3962 +void au_cpup_attr_all(struct inode *inode, int force)
3964 + struct inode *h_inode;
3966 + h_inode = au_h_iptr(inode, au_ibstart(inode));
3967 + au_cpup_attr_changeable(inode);
3968 + if (inode->i_nlink > 0)
3969 + au_cpup_attr_nlink(inode, force);
3970 + inode->i_rdev = h_inode->i_rdev;
3971 + inode->i_blkbits = h_inode->i_blkbits;
3972 + au_cpup_igen(inode, h_inode);
3975 +/* ---------------------------------------------------------------------- */
3977 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
3979 +/* keep the timestamps of the parent dir when cpup */
3980 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
3981 + struct path *h_path)
3983 + struct inode *h_inode;
3985 + dt->dt_dentry = dentry;
3986 + dt->dt_h_path = *h_path;
3987 + h_inode = h_path->dentry->d_inode;
3988 + dt->dt_atime = h_inode->i_atime;
3989 + dt->dt_mtime = h_inode->i_mtime;
3993 +void au_dtime_revert(struct au_dtime *dt)
3995 + struct iattr attr;
3998 + attr.ia_atime = dt->dt_atime;
3999 + attr.ia_mtime = dt->dt_mtime;
4000 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4001 + | ATTR_ATIME | ATTR_ATIME_SET;
4003 + /* no delegation since this is a directory */
4004 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4005 + if (unlikely(err))
4006 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4009 +/* ---------------------------------------------------------------------- */
4011 +/* internal use only */
4012 +struct au_cpup_reg_attr {
4015 + unsigned int iflags; /* inode->i_flags */
4018 +static noinline_for_stack
4019 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
4020 + struct au_cpup_reg_attr *h_src_attr)
4024 + struct path h_path;
4025 + struct inode *h_isrc, *h_idst;
4026 + struct kstat *h_st;
4028 + h_path.dentry = au_h_dptr(dst, bindex);
4029 + h_idst = h_path.dentry->d_inode;
4030 + h_path.mnt = au_sbr_mnt(dst->d_sb, bindex);
4031 + h_isrc = h_src->d_inode;
4032 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4033 + | ATTR_ATIME | ATTR_MTIME
4034 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4035 + if (h_src_attr && h_src_attr->valid) {
4036 + h_st = &h_src_attr->st;
4037 + ia.ia_uid = h_st->uid;
4038 + ia.ia_gid = h_st->gid;
4039 + ia.ia_atime = h_st->atime;
4040 + ia.ia_mtime = h_st->mtime;
4041 + if (h_idst->i_mode != h_st->mode
4042 + && !S_ISLNK(h_idst->i_mode)) {
4043 + ia.ia_valid |= ATTR_MODE;
4044 + ia.ia_mode = h_st->mode;
4046 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4047 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4049 + ia.ia_uid = h_isrc->i_uid;
4050 + ia.ia_gid = h_isrc->i_gid;
4051 + ia.ia_atime = h_isrc->i_atime;
4052 + ia.ia_mtime = h_isrc->i_mtime;
4053 + if (h_idst->i_mode != h_isrc->i_mode
4054 + && !S_ISLNK(h_idst->i_mode)) {
4055 + ia.ia_valid |= ATTR_MODE;
4056 + ia.ia_mode = h_isrc->i_mode;
4058 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4059 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4061 + /* no delegation since it is just created */
4062 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4064 + /* is this nfs only? */
4065 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
4066 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
4067 + ia.ia_mode = h_isrc->i_mode;
4068 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4074 +/* ---------------------------------------------------------------------- */
4076 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
4077 + char *buf, unsigned long blksize)
4080 + size_t sz, rbytes, wbytes;
4081 + unsigned char all_zero;
4083 + struct mutex *h_mtx;
4084 + /* reduce stack usage */
4087 + zp = page_address(ZERO_PAGE(0));
4088 + if (unlikely(!zp))
4089 + return -ENOMEM; /* possible? */
4094 + AuDbg("len %lld\n", len);
4096 + if (len < blksize)
4100 + /* todo: signal_pending? */
4101 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
4102 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
4105 + if (unlikely(err < 0))
4109 + if (len >= rbytes && rbytes == blksize)
4110 + all_zero = !memcmp(buf, zp, rbytes);
4117 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
4119 + /* todo: signal_pending? */
4120 + if (unlikely(err == -EAGAIN || err == -EINTR))
4122 + if (unlikely(err < 0))
4127 + if (unlikely(err < 0))
4133 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
4135 + if (unlikely(res < 0))
4142 + /* the last block may be a hole */
4143 + if (!err && all_zero) {
4144 + AuLabel(last hole);
4147 + if (au_test_nfs(dst->f_dentry->d_sb)) {
4148 + /* nfs requires this step to make last hole */
4149 + /* is this only nfs? */
4151 + /* todo: signal_pending? */
4152 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
4153 + } while (err == -EAGAIN || err == -EINTR);
4160 + ia->ia_size = dst->f_pos;
4161 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
4162 + ia->ia_file = dst;
4163 + h_mtx = &file_inode(dst)->i_mutex;
4164 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
4165 + /* no delegation since it is just created */
4166 + err = vfsub_notify_change(&dst->f_path, ia,
4167 + /*delegated*/NULL);
4168 + mutex_unlock(h_mtx);
4175 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
4178 + unsigned long blksize;
4179 + unsigned char do_kfree;
4183 + blksize = dst->f_dentry->d_sb->s_blocksize;
4184 + if (!blksize || PAGE_SIZE < blksize)
4185 + blksize = PAGE_SIZE;
4186 + AuDbg("blksize %lu\n", blksize);
4187 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
4189 + buf = kmalloc(blksize, GFP_NOFS);
4191 + buf = (void *)__get_free_page(GFP_NOFS);
4192 + if (unlikely(!buf))
4195 + if (len > (1 << 22))
4196 + AuDbg("copying a large file %lld\n", (long long)len);
4200 + err = au_do_copy_file(dst, src, len, buf, blksize);
4204 + free_page((unsigned long)buf);
4211 + * to support a sparse file which is opened with O_APPEND,
4212 + * we need to close the file.
4214 +static int au_cp_regular(struct au_cp_generic *cpg)
4217 + enum { SRC, DST };
4219 + aufs_bindex_t bindex;
4220 + unsigned int flags;
4221 + struct dentry *dentry;
4223 + struct file *file;
4227 + .bindex = cpg->bsrc,
4228 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
4232 + .bindex = cpg->bdst,
4233 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
4234 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
4235 + .label = &&out_src
4238 + struct super_block *sb;
4240 + /* bsrc branch can be ro/rw. */
4241 + sb = cpg->dentry->d_sb;
4243 + for (i = 0; i < 2; i++, f++) {
4244 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
4245 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
4246 + /*file*/NULL, f->force_wr);
4247 + err = PTR_ERR(f->file);
4248 + if (IS_ERR(f->file))
4252 + /* try stopping to update while we copyup */
4253 + IMustLock(file[SRC].dentry->d_inode);
4254 + err = au_copy_file(file[DST].file, file[SRC].file, cpg->len);
4256 + fput(file[DST].file);
4257 + au_sbr_put(sb, file[DST].bindex);
4260 + fput(file[SRC].file);
4261 + au_sbr_put(sb, file[SRC].bindex);
4266 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
4267 + struct au_cpup_reg_attr *h_src_attr)
4271 + struct path h_path;
4272 + struct inode *h_src_inode, *h_dst_inode;
4275 + h_src_inode = au_h_iptr(cpg->dentry->d_inode, cpg->bsrc);
4276 + l = i_size_read(h_src_inode);
4277 + if (cpg->len == -1 || l < cpg->len)
4280 + /* try stopping to update while we are referencing */
4281 + mutex_lock_nested(&h_src_inode->i_mutex, AuLsc_I_CHILD);
4282 + au_pin_hdir_unlock(cpg->pin);
4284 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
4285 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
4286 + h_src_attr->iflags = h_src_inode->i_flags;
4287 + err = vfs_getattr(&h_path, &h_src_attr->st);
4288 + if (unlikely(err)) {
4289 + mutex_unlock(&h_src_inode->i_mutex);
4292 + h_src_attr->valid = 1;
4293 + err = au_cp_regular(cpg);
4294 + mutex_unlock(&h_src_inode->i_mutex);
4295 + rerr = au_pin_hdir_relock(cpg->pin);
4299 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
4300 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
4301 + h_dst_inode = h_path.dentry->d_inode;
4302 + spin_lock(&h_dst_inode->i_lock);
4303 + h_dst_inode->i_state |= I_LINKABLE;
4304 + spin_unlock(&h_dst_inode->i_lock);
4311 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
4312 + struct inode *h_dir)
4315 + mm_segment_t old_fs;
4322 + if (unlikely(!h_src->d_inode->i_op->readlink))
4326 + sym.k = (void *)__get_free_page(GFP_NOFS);
4327 + if (unlikely(!sym.k))
4330 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
4331 + old_fs = get_fs();
4332 + set_fs(KERNEL_DS);
4333 + symlen = h_src->d_inode->i_op->readlink(h_src, sym.u, PATH_MAX);
4338 + sym.k[symlen] = 0;
4339 + err = vfsub_symlink(h_dir, h_path, sym.k);
4341 + free_page((unsigned long)sym.k);
4347 +static noinline_for_stack
4348 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
4349 + struct au_cpup_reg_attr *h_src_attr)
4353 + unsigned int mnt_flags;
4354 + unsigned char isdir;
4355 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
4356 + struct au_dtime dt;
4357 + struct path h_path;
4358 + struct dentry *h_src, *h_dst, *h_parent;
4359 + struct inode *h_inode, *h_dir;
4360 + struct super_block *sb;
4362 + /* bsrc branch can be ro/rw. */
4363 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
4364 + h_inode = h_src->d_inode;
4365 + AuDebugOn(h_inode != au_h_iptr(cpg->dentry->d_inode, cpg->bsrc));
4367 + /* try stopping to be referenced while we are creating */
4368 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
4369 + if (au_ftest_cpup(cpg->flags, RENAME))
4370 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
4371 + AUFS_WH_PFX_LEN));
4372 + h_parent = h_dst->d_parent; /* dir inode is locked */
4373 + h_dir = h_parent->d_inode;
4375 + AuDebugOn(h_parent != h_dst->d_parent);
4377 + sb = cpg->dentry->d_sb;
4378 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
4380 + h_path.dentry = h_parent;
4381 + au_dtime_store(&dt, dst_parent, &h_path);
4383 + h_path.dentry = h_dst;
4386 + mode = h_inode->i_mode;
4387 + switch (mode & S_IFMT) {
4389 + err = vfsub_create(h_dir, &h_path, mode | S_IWUSR,
4390 + /*want_excl*/true);
4392 + err = au_do_cpup_regular(cpg, h_src_attr);
4396 + err = vfsub_mkdir(h_dir, &h_path, mode);
4399 + * strange behaviour from the users view,
4400 + * particularry setattr case
4402 + if (au_ibstart(dst_parent->d_inode) == cpg->bdst)
4403 + au_cpup_attr_nlink(dst_parent->d_inode,
4405 + au_cpup_attr_nlink(cpg->dentry->d_inode, /*force*/1);
4409 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
4413 + AuDebugOn(!capable(CAP_MKNOD));
4417 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
4420 + AuIOErr("Unknown inode type 0%o\n", mode);
4424 + mnt_flags = au_mntflags(sb);
4425 + if (!au_opt_test(mnt_flags, UDBA_NONE)
4427 + && au_opt_test(mnt_flags, XINO)
4428 + && (h_inode->i_nlink == 1
4429 + || (h_inode->i_state & I_LINKABLE))
4430 + /* todo: unnecessary? */
4431 + /* && cpg->dentry->d_inode->i_nlink == 1 */
4432 + && cpg->bdst < cpg->bsrc
4433 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
4434 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
4435 + /* ignore this error */
4438 + au_dtime_revert(&dt);
4442 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
4445 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
4446 + struct inode *h_dir;
4447 + aufs_bindex_t bdst;
4449 + dentry = cpg->dentry;
4451 + h_dentry = au_h_dptr(dentry, bdst);
4452 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
4454 + au_set_h_dptr(dentry, bdst, NULL);
4455 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
4457 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
4458 + au_set_h_dptr(dentry, bdst, h_dentry);
4461 + parent = dget_parent(dentry);
4462 + h_parent = au_h_dptr(parent, bdst);
4464 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
4465 + if (IS_ERR(h_path->dentry))
4466 + err = PTR_ERR(h_path->dentry);
4468 + if (unlikely(err))
4471 + h_parent = h_dentry->d_parent; /* dir inode is locked */
4472 + h_dir = h_parent->d_inode;
4474 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
4475 + /* no delegation since it is just created */
4476 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL);
4477 + dput(h_path->dentry);
4484 + * copyup the @dentry from @bsrc to @bdst.
4485 + * the caller must set the both of lower dentries.
4486 + * @len is for truncating when it is -1 copyup the entire file.
4487 + * in link/rename cases, @dst_parent may be different from the real one.
4488 + * basic->bsrc can be larger than basic->bdst.
4490 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
4493 + aufs_bindex_t old_ibstart;
4494 + unsigned char isdir, plink;
4495 + struct dentry *h_src, *h_dst, *h_parent;
4496 + struct inode *dst_inode, *h_dir, *inode, *delegated;
4497 + struct super_block *sb;
4498 + struct au_branch *br;
4499 + /* to reuduce stack size */
4501 + struct au_dtime dt;
4502 + struct path h_path;
4503 + struct au_cpup_reg_attr h_src_attr;
4507 + a = kmalloc(sizeof(*a), GFP_NOFS);
4510 + a->h_src_attr.valid = 0;
4512 + sb = cpg->dentry->d_sb;
4513 + br = au_sbr(sb, cpg->bdst);
4514 + a->h_path.mnt = au_br_mnt(br);
4515 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
4516 + h_parent = h_dst->d_parent; /* dir inode is locked */
4517 + h_dir = h_parent->d_inode;
4520 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
4521 + inode = cpg->dentry->d_inode;
4524 + dst_parent = dget_parent(cpg->dentry);
4528 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
4529 + dst_inode = au_h_iptr(inode, cpg->bdst);
4531 + if (unlikely(!plink)) {
4533 + AuIOErr("hi%lu(i%lu) exists on b%d "
4534 + "but plink is disabled\n",
4535 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
4539 + if (dst_inode->i_nlink) {
4540 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
4542 + h_src = au_plink_lkup(inode, cpg->bdst);
4543 + err = PTR_ERR(h_src);
4544 + if (IS_ERR(h_src))
4546 + if (unlikely(!h_src->d_inode)) {
4548 + AuIOErr("i%lu exists on a upper branch "
4549 + "but not pseudo-linked\n",
4556 + a->h_path.dentry = h_parent;
4557 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
4560 + a->h_path.dentry = h_dst;
4562 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
4563 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
4564 + err = au_do_ren_after_cpup(cpg, &a->h_path);
4566 + au_dtime_revert(&a->dt);
4567 + if (unlikely(err == -EWOULDBLOCK)) {
4568 + pr_warn("cannot retry for NFSv4 delegation"
4569 + " for an internal link\n");
4575 + /* todo: cpup_wh_file? */
4577 + au_update_ibrange(inode, /*do_put_zero*/1);
4580 + isdir = S_ISDIR(inode->i_mode);
4581 + old_ibstart = au_ibstart(inode);
4582 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
4583 + if (unlikely(err))
4585 + dst_inode = h_dst->d_inode;
4586 + mutex_lock_nested(&dst_inode->i_mutex, AuLsc_I_CHILD2);
4587 + /* todo: necessary? */
4588 + /* au_pin_hdir_unlock(cpg->pin); */
4590 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
4591 + if (unlikely(err)) {
4592 + /* todo: necessary? */
4593 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
4594 + mutex_unlock(&dst_inode->i_mutex);
4598 + if (cpg->bdst < old_ibstart) {
4599 + if (S_ISREG(inode->i_mode)) {
4600 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
4601 + if (unlikely(err)) {
4602 + /* ignore an error */
4603 + /* au_pin_hdir_relock(cpg->pin); */
4604 + mutex_unlock(&dst_inode->i_mutex);
4608 + au_set_ibstart(inode, cpg->bdst);
4610 + au_set_ibend(inode, cpg->bdst);
4611 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
4612 + au_hi_flags(inode, isdir));
4614 + /* todo: necessary? */
4615 + /* err = au_pin_hdir_relock(cpg->pin); */
4616 + mutex_unlock(&dst_inode->i_mutex);
4617 + if (unlikely(err))
4621 + && (h_src->d_inode->i_nlink > 1
4622 + || h_src->d_inode->i_state & I_LINKABLE)
4624 + au_plink_append(inode, cpg->bdst, h_dst);
4626 + if (au_ftest_cpup(cpg->flags, RENAME)) {
4627 + a->h_path.dentry = h_dst;
4628 + err = au_do_ren_after_cpup(cpg, &a->h_path);
4631 + goto out_parent; /* success */
4635 + a->h_path.dentry = h_parent;
4636 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
4637 + a->h_path.dentry = h_dst;
4639 + if (h_dst->d_inode) {
4641 + /* no delegation since it is just created */
4642 + rerr = vfsub_unlink(h_dir, &a->h_path,
4643 + /*delegated*/NULL, /*force*/0);
4645 + rerr = vfsub_rmdir(h_dir, &a->h_path);
4647 + au_dtime_revert(&a->dt);
4649 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
4660 +struct au_cpup_single_args {
4662 + struct au_cp_generic *cpg;
4663 + struct dentry *dst_parent;
4666 +static void au_call_cpup_single(void *args)
4668 + struct au_cpup_single_args *a = args;
4670 + au_pin_hdir_acquire_nest(a->cpg->pin);
4671 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
4672 + au_pin_hdir_release(a->cpg->pin);
4677 + * prevent SIGXFSZ in copy-up.
4678 + * testing CAP_MKNOD is for generic fs,
4679 + * but CAP_FSETID is for xfs only, currently.
4681 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
4684 + struct super_block *sb;
4685 + struct inode *h_dir;
4688 + sb = au_pinned_parent(pin)->d_sb;
4689 + if (!au_wkq_test()
4690 + && (!au_sbi(sb)->si_plink_maint_pid
4691 + || au_plink_maint(sb, AuLock_NOPLM))) {
4692 + switch (mode & S_IFMT) {
4694 + /* no condition about RLIMIT_FSIZE and the file size */
4699 + do_sio = !capable(CAP_MKNOD);
4703 + do_sio = ((mode & (S_ISUID | S_ISGID))
4704 + && !capable(CAP_FSETID));
4705 + /* this workaround may be removed in the future */
4707 + h_dir = au_pinned_h_dir(pin);
4708 + do_sio = h_dir->i_mode & S_ISVTX;
4716 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
4719 + struct dentry *h_dentry;
4721 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
4722 + if (!au_cpup_sio_test(pin, h_dentry->d_inode->i_mode))
4723 + err = au_cpup_single(cpg, dst_parent);
4725 + struct au_cpup_single_args args = {
4728 + .dst_parent = dst_parent
4730 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
4731 + if (unlikely(wkq_err))
4740 + * copyup the @dentry from the first active lower branch to @bdst,
4741 + * using au_cpup_single().
4743 +static int au_cpup_simple(struct au_cp_generic *cpg)
4746 + unsigned int flags_orig;
4747 + struct dentry *dentry;
4749 + AuDebugOn(cpg->bsrc < 0);
4751 + dentry = cpg->dentry;
4752 + DiMustWriteLock(dentry);
4754 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
4756 + flags_orig = cpg->flags;
4757 + au_fset_cpup(cpg->flags, RENAME);
4758 + err = au_cpup_single(cpg, NULL);
4759 + cpg->flags = flags_orig;
4761 + return 0; /* success */
4764 + au_set_h_dptr(dentry, cpg->bdst, NULL);
4765 + au_set_dbstart(dentry, cpg->bsrc);
4771 +struct au_cpup_simple_args {
4773 + struct au_cp_generic *cpg;
4776 +static void au_call_cpup_simple(void *args)
4778 + struct au_cpup_simple_args *a = args;
4780 + au_pin_hdir_acquire_nest(a->cpg->pin);
4781 + *a->errp = au_cpup_simple(a->cpg);
4782 + au_pin_hdir_release(a->cpg->pin);
4785 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
4788 + struct dentry *dentry, *parent;
4789 + struct file *h_file;
4790 + struct inode *h_dir;
4792 + dentry = cpg->dentry;
4794 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
4795 + AuDebugOn(cpg->bsrc < 0);
4796 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
4797 + err = PTR_ERR(h_file);
4798 + if (IS_ERR(h_file))
4802 + parent = dget_parent(dentry);
4803 + h_dir = au_h_iptr(parent->d_inode, cpg->bdst);
4804 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
4805 + && !au_cpup_sio_test(cpg->pin, dentry->d_inode->i_mode))
4806 + err = au_cpup_simple(cpg);
4808 + struct au_cpup_simple_args args = {
4812 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
4813 + if (unlikely(wkq_err))
4819 + au_h_open_post(dentry, cpg->bsrc, h_file);
4825 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
4827 + aufs_bindex_t bsrc, bend;
4828 + struct dentry *dentry, *h_dentry;
4830 + if (cpg->bsrc < 0) {
4831 + dentry = cpg->dentry;
4832 + bend = au_dbend(dentry);
4833 + for (bsrc = cpg->bdst + 1; bsrc <= bend; bsrc++) {
4834 + h_dentry = au_h_dptr(dentry, bsrc);
4836 + AuDebugOn(!h_dentry->d_inode);
4840 + AuDebugOn(bsrc > bend);
4843 + AuDebugOn(cpg->bsrc <= cpg->bdst);
4844 + return au_do_sio_cpup_simple(cpg);
4847 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
4849 + AuDebugOn(cpg->bdst <= cpg->bsrc);
4850 + return au_do_sio_cpup_simple(cpg);
4853 +/* ---------------------------------------------------------------------- */
4856 + * copyup the deleted file for writing.
4858 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
4859 + struct file *file)
4862 + unsigned int flags_orig;
4863 + aufs_bindex_t bsrc_orig;
4864 + struct dentry *h_d_dst, *h_d_start;
4865 + struct au_dinfo *dinfo;
4866 + struct au_hdentry *hdp;
4868 + dinfo = au_di(cpg->dentry);
4869 + AuRwMustWriteLock(&dinfo->di_rwsem);
4871 + bsrc_orig = cpg->bsrc;
4872 + cpg->bsrc = dinfo->di_bstart;
4873 + hdp = dinfo->di_hdentry;
4874 + h_d_dst = hdp[0 + cpg->bdst].hd_dentry;
4875 + dinfo->di_bstart = cpg->bdst;
4876 + hdp[0 + cpg->bdst].hd_dentry = wh_dentry;
4879 + h_d_start = hdp[0 + cpg->bsrc].hd_dentry;
4880 + hdp[0 + cpg->bsrc].hd_dentry = au_hf_top(file)->f_dentry;
4882 + flags_orig = cpg->flags;
4883 + cpg->flags = !AuCpup_DTIME;
4884 + err = au_cpup_single(cpg, /*h_parent*/NULL);
4885 + cpg->flags = flags_orig;
4888 + err = au_reopen_nondir(file);
4889 + hdp[0 + cpg->bsrc].hd_dentry = h_d_start;
4891 + hdp[0 + cpg->bdst].hd_dentry = h_d_dst;
4892 + dinfo->di_bstart = cpg->bsrc;
4893 + cpg->bsrc = bsrc_orig;
4898 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
4901 + aufs_bindex_t bdst;
4902 + struct au_dtime dt;
4903 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
4904 + struct au_branch *br;
4905 + struct path h_path;
4907 + dentry = cpg->dentry;
4909 + br = au_sbr(dentry->d_sb, bdst);
4910 + parent = dget_parent(dentry);
4911 + h_parent = au_h_dptr(parent, bdst);
4912 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
4913 + err = PTR_ERR(wh_dentry);
4914 + if (IS_ERR(wh_dentry))
4917 + h_path.dentry = h_parent;
4918 + h_path.mnt = au_br_mnt(br);
4919 + au_dtime_store(&dt, parent, &h_path);
4920 + err = au_do_cpup_wh(cpg, wh_dentry, file);
4921 + if (unlikely(err))
4925 + h_path.dentry = wh_dentry;
4926 + if (!S_ISDIR(wh_dentry->d_inode->i_mode)) {
4927 + /* no delegation since it is just created */
4928 + err = vfsub_unlink(h_parent->d_inode, &h_path,
4929 + /*delegated*/NULL, /*force*/0);
4931 + err = vfsub_rmdir(h_parent->d_inode, &h_path);
4932 + if (unlikely(err)) {
4933 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
4937 + au_dtime_revert(&dt);
4938 + au_set_hi_wh(dentry->d_inode, bdst, wh_dentry);
4947 +struct au_cpup_wh_args {
4949 + struct au_cp_generic *cpg;
4950 + struct file *file;
4953 +static void au_call_cpup_wh(void *args)
4955 + struct au_cpup_wh_args *a = args;
4957 + au_pin_hdir_acquire_nest(a->cpg->pin);
4958 + *a->errp = au_cpup_wh(a->cpg, a->file);
4959 + au_pin_hdir_release(a->cpg->pin);
4962 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
4965 + aufs_bindex_t bdst;
4966 + struct dentry *dentry, *parent, *h_orph, *h_parent, *h_dentry;
4967 + struct inode *dir, *h_dir, *h_tmpdir;
4968 + struct au_wbr *wbr;
4969 + struct au_pin wh_pin, *pin_orig;
4971 + dentry = cpg->dentry;
4973 + parent = dget_parent(dentry);
4974 + dir = parent->d_inode;
4977 + h_dir = au_igrab(au_h_iptr(dir, bdst));
4980 + if (!h_dir->i_nlink) {
4981 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
4982 + h_orph = wbr->wbr_orph;
4984 + h_parent = dget(au_h_dptr(parent, bdst));
4985 + au_set_h_dptr(parent, bdst, dget(h_orph));
4986 + h_tmpdir = h_orph->d_inode;
4987 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
4990 + h_dentry = au_hf_top(file)->f_dentry;
4992 + h_dentry = au_h_dptr(dentry, au_dbstart(dentry));
4993 + mutex_lock_nested(&h_tmpdir->i_mutex, AuLsc_I_PARENT3);
4994 + /* todo: au_h_open_pre()? */
4996 + pin_orig = cpg->pin;
4997 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
4998 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
4999 + cpg->pin = &wh_pin;
5002 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
5003 + && !au_cpup_sio_test(cpg->pin, dentry->d_inode->i_mode))
5004 + err = au_cpup_wh(cpg, file);
5006 + struct au_cpup_wh_args args = {
5011 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
5012 + if (unlikely(wkq_err))
5017 + mutex_unlock(&h_tmpdir->i_mutex);
5018 + /* todo: au_h_open_post()? */
5019 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
5020 + au_set_h_dptr(parent, bdst, h_parent);
5021 + AuDebugOn(!pin_orig);
5022 + cpg->pin = pin_orig;
5030 +/* ---------------------------------------------------------------------- */
5033 + * generic routine for both of copy-up and copy-down.
5035 +/* cf. revalidate function in file.c */
5036 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
5037 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
5038 + struct au_pin *pin,
5039 + struct dentry *h_parent, void *arg),
5043 + struct au_pin pin;
5044 + struct dentry *d, *parent, *h_parent, *real_parent;
5047 + parent = dget_parent(dentry);
5048 + if (IS_ROOT(parent))
5051 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
5052 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
5054 + /* do not use au_dpage */
5055 + real_parent = parent;
5058 + parent = dget_parent(dentry);
5059 + h_parent = au_h_dptr(parent, bdst);
5061 + goto out; /* success */
5063 + /* find top dir which is necessary to cpup */
5067 + parent = dget_parent(d);
5068 + di_read_lock_parent3(parent, !AuLock_IR);
5069 + h_parent = au_h_dptr(parent, bdst);
5070 + di_read_unlock(parent, !AuLock_IR);
5071 + } while (!h_parent);
5073 + if (d != real_parent)
5074 + di_write_lock_child3(d);
5076 + /* somebody else might create while we were sleeping */
5077 + if (!au_h_dptr(d, bdst) || !au_h_dptr(d, bdst)->d_inode) {
5078 + if (au_h_dptr(d, bdst))
5079 + au_update_dbstart(d);
5081 + au_pin_set_dentry(&pin, d);
5082 + err = au_do_pin(&pin);
5084 + err = cp(d, bdst, &pin, h_parent, arg);
5089 + if (d != real_parent)
5090 + di_write_unlock(d);
5091 + if (unlikely(err))
5100 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
5101 + struct au_pin *pin,
5102 + struct dentry *h_parent __maybe_unused ,
5103 + void *arg __maybe_unused)
5105 + struct au_cp_generic cpg = {
5111 + .flags = AuCpup_DTIME
5113 + return au_sio_cpup_simple(&cpg);
5116 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
5118 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
5121 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
5124 + struct dentry *parent;
5125 + struct inode *dir;
5127 + parent = dget_parent(dentry);
5128 + dir = parent->d_inode;
5130 + if (au_h_iptr(dir, bdst))
5133 + di_read_unlock(parent, AuLock_IR);
5134 + di_write_lock_parent(parent);
5135 + /* someone else might change our inode while we were sleeping */
5136 + if (!au_h_iptr(dir, bdst))
5137 + err = au_cpup_dirs(dentry, bdst);
5138 + di_downgrade_lock(parent, AuLock_IR);
5144 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
5145 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
5146 +++ linux/fs/aufs/cpup.h 2014-06-24 00:14:06.779385790 +0200
5149 + * Copyright (C) 2005-2014 Junjiro R. Okajima
5151 + * This program, aufs is free software; you can redistribute it and/or modify
5152 + * it under the terms of the GNU General Public License as published by
5153 + * the Free Software Foundation; either version 2 of the License, or
5154 + * (at your option) any later version.
5156 + * This program is distributed in the hope that it will be useful,
5157 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5158 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5159 + * GNU General Public License for more details.
5161 + * You should have received a copy of the GNU General Public License
5162 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5166 + * copy-up/down functions
5169 +#ifndef __AUFS_CPUP_H__
5170 +#define __AUFS_CPUP_H__
5174 +#include <linux/path.h>
5180 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
5181 +void au_cpup_attr_timesizes(struct inode *inode);
5182 +void au_cpup_attr_nlink(struct inode *inode, int force);
5183 +void au_cpup_attr_changeable(struct inode *inode);
5184 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
5185 +void au_cpup_attr_all(struct inode *inode, int force);
5187 +/* ---------------------------------------------------------------------- */
5189 +struct au_cp_generic {
5190 + struct dentry *dentry;
5191 + aufs_bindex_t bdst, bsrc;
5193 + struct au_pin *pin;
5194 + unsigned int flags;
5198 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
5199 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
5201 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
5202 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
5204 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
5206 +#define AuCpup_RWDST (1 << 5) /* force write target even if
5207 + the branch is marked as RO */
5209 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
5210 +#define au_fset_cpup(flags, name) \
5211 + do { (flags) |= AuCpup_##name; } while (0)
5212 +#define au_fclr_cpup(flags, name) \
5213 + do { (flags) &= ~AuCpup_##name; } while (0)
5215 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
5216 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
5217 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
5218 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
5220 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
5221 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
5222 + struct au_pin *pin,
5223 + struct dentry *h_parent, void *arg),
5225 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
5226 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
5228 +/* ---------------------------------------------------------------------- */
5230 +/* keep timestamps when copyup */
5232 + struct dentry *dt_dentry;
5233 + struct path dt_h_path;
5234 + struct timespec dt_atime, dt_mtime;
5236 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
5237 + struct path *h_path);
5238 +void au_dtime_revert(struct au_dtime *dt);
5240 +#endif /* __KERNEL__ */
5241 +#endif /* __AUFS_CPUP_H__ */
5242 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
5243 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
5244 +++ linux/fs/aufs/dbgaufs.c 2014-06-24 00:14:06.779385790 +0200
5247 + * Copyright (C) 2005-2014 Junjiro R. Okajima
5249 + * This program, aufs is free software; you can redistribute it and/or modify
5250 + * it under the terms of the GNU General Public License as published by
5251 + * the Free Software Foundation; either version 2 of the License, or
5252 + * (at your option) any later version.
5254 + * This program is distributed in the hope that it will be useful,
5255 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5256 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5257 + * GNU General Public License for more details.
5259 + * You should have received a copy of the GNU General Public License
5260 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5264 + * debugfs interface
5267 +#include <linux/debugfs.h>
5270 +#ifndef CONFIG_SYSFS
5271 +#error DEBUG_FS depends upon SYSFS
5274 +static struct dentry *dbgaufs;
5275 +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH;
5277 +/* 20 is max digits length of ulong 64 */
5278 +struct dbgaufs_arg {
5284 + * common function for all XINO files
5286 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
5287 + struct file *file)
5289 + kfree(file->private_data);
5293 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt)
5297 + struct dbgaufs_arg *p;
5300 + p = kmalloc(sizeof(*p), GFP_NOFS);
5306 + file->private_data = p;
5310 + err = vfs_getattr(&xf->f_path, &st);
5314 + (p->a, sizeof(p->a), "%ld, %llux%lu %lld\n",
5315 + (long)file_count(xf), st.blocks, st.blksize,
5316 + (long long)st.size);
5318 + p->n = snprintf(p->a, sizeof(p->a), "%llux%lu %lld\n",
5319 + st.blocks, st.blksize,
5320 + (long long)st.size);
5321 + AuDebugOn(p->n >= sizeof(p->a));
5323 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
5332 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
5333 + size_t count, loff_t *ppos)
5335 + struct dbgaufs_arg *p;
5337 + p = file->private_data;
5338 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
5341 +/* ---------------------------------------------------------------------- */
5343 +struct dbgaufs_plink_arg {
5348 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
5349 + struct file *file)
5351 + free_page((unsigned long)file->private_data);
5355 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
5357 + int err, i, limit;
5358 + unsigned long n, sum;
5359 + struct dbgaufs_plink_arg *p;
5360 + struct au_sbinfo *sbinfo;
5361 + struct super_block *sb;
5362 + struct au_sphlhead *sphl;
5365 + p = (void *)get_zeroed_page(GFP_NOFS);
5370 + sbinfo = inode->i_private;
5371 + sb = sbinfo->si_sb;
5372 + si_noflush_read_lock(sb);
5373 + if (au_opt_test(au_mntflags(sb), PLINK)) {
5374 + limit = PAGE_SIZE - sizeof(p->n);
5376 + /* the number of buckets */
5377 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
5382 + for (i = 0, sphl = sbinfo->si_plink;
5383 + i < AuPlink_NHASH;
5385 + n = au_sphl_count(sphl);
5388 + n = snprintf(p->a + p->n, limit, "%lu ", n);
5391 + if (unlikely(limit <= 0))
5394 + p->a[p->n - 1] = '\n';
5396 + /* the sum of plinks */
5397 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
5400 + if (unlikely(limit <= 0))
5403 +#define str "1\n0\n0\n"
5404 + p->n = sizeof(str) - 1;
5405 + strcpy(p->a, str);
5408 + si_read_unlock(sb);
5411 + file->private_data = p;
5412 + goto out; /* success */
5415 + free_page((unsigned long)p);
5420 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
5421 + size_t count, loff_t *ppos)
5423 + struct dbgaufs_plink_arg *p;
5425 + p = file->private_data;
5426 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
5429 +static const struct file_operations dbgaufs_plink_fop = {
5430 + .owner = THIS_MODULE,
5431 + .open = dbgaufs_plink_open,
5432 + .release = dbgaufs_plink_release,
5433 + .read = dbgaufs_plink_read
5436 +/* ---------------------------------------------------------------------- */
5438 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
5441 + struct au_sbinfo *sbinfo;
5442 + struct super_block *sb;
5444 + sbinfo = inode->i_private;
5445 + sb = sbinfo->si_sb;
5446 + si_noflush_read_lock(sb);
5447 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
5448 + si_read_unlock(sb);
5452 +static const struct file_operations dbgaufs_xib_fop = {
5453 + .owner = THIS_MODULE,
5454 + .open = dbgaufs_xib_open,
5455 + .release = dbgaufs_xi_release,
5456 + .read = dbgaufs_xi_read
5459 +/* ---------------------------------------------------------------------- */
5461 +#define DbgaufsXi_PREFIX "xi"
5463 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
5467 + struct au_sbinfo *sbinfo;
5468 + struct super_block *sb;
5470 + struct qstr *name;
5474 + name = &file->f_dentry->d_name;
5475 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
5476 + || memcmp(name->name, DbgaufsXi_PREFIX,
5477 + sizeof(DbgaufsXi_PREFIX) - 1)))
5479 + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
5480 + if (unlikely(err))
5483 + sbinfo = inode->i_private;
5484 + sb = sbinfo->si_sb;
5485 + si_noflush_read_lock(sb);
5486 + if (l <= au_sbend(sb)) {
5487 + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file;
5488 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1);
5491 + si_read_unlock(sb);
5497 +static const struct file_operations dbgaufs_xino_fop = {
5498 + .owner = THIS_MODULE,
5499 + .open = dbgaufs_xino_open,
5500 + .release = dbgaufs_xi_release,
5501 + .read = dbgaufs_xi_read
5504 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
5506 + aufs_bindex_t bend;
5507 + struct au_branch *br;
5508 + struct au_xino_file *xi;
5510 + if (!au_sbi(sb)->si_dbgaufs)
5513 + bend = au_sbend(sb);
5514 + for (; bindex <= bend; bindex++) {
5515 + br = au_sbr(sb, bindex);
5516 + xi = &br->br_xino;
5517 + debugfs_remove(xi->xi_dbgaufs);
5518 + xi->xi_dbgaufs = NULL;
5522 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
5524 + struct au_sbinfo *sbinfo;
5525 + struct dentry *parent;
5526 + struct au_branch *br;
5527 + struct au_xino_file *xi;
5528 + aufs_bindex_t bend;
5529 + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
5531 + sbinfo = au_sbi(sb);
5532 + parent = sbinfo->si_dbgaufs;
5536 + bend = au_sbend(sb);
5537 + for (; bindex <= bend; bindex++) {
5538 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
5539 + br = au_sbr(sb, bindex);
5540 + xi = &br->br_xino;
5541 + AuDebugOn(xi->xi_dbgaufs);
5542 + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
5543 + sbinfo, &dbgaufs_xino_fop);
5544 + /* ignore an error */
5545 + if (unlikely(!xi->xi_dbgaufs))
5546 + AuWarn1("failed %s under debugfs\n", name);
5550 +/* ---------------------------------------------------------------------- */
5552 +#ifdef CONFIG_AUFS_EXPORT
5553 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
5556 + struct au_sbinfo *sbinfo;
5557 + struct super_block *sb;
5559 + sbinfo = inode->i_private;
5560 + sb = sbinfo->si_sb;
5561 + si_noflush_read_lock(sb);
5562 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0);
5563 + si_read_unlock(sb);
5567 +static const struct file_operations dbgaufs_xigen_fop = {
5568 + .owner = THIS_MODULE,
5569 + .open = dbgaufs_xigen_open,
5570 + .release = dbgaufs_xi_release,
5571 + .read = dbgaufs_xi_read
5574 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
5579 + * This function is a dynamic '__init' fucntion actually,
5580 + * so the tiny check for si_rwsem is unnecessary.
5582 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
5585 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
5586 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
5587 + &dbgaufs_xigen_fop);
5588 + if (sbinfo->si_dbgaufs_xigen)
5594 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
5598 +#endif /* CONFIG_AUFS_EXPORT */
5600 +/* ---------------------------------------------------------------------- */
5602 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
5605 + * This function is a dynamic '__init' fucntion actually,
5606 + * so the tiny check for si_rwsem is unnecessary.
5608 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
5610 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
5611 + sbinfo->si_dbgaufs = NULL;
5612 + kobject_put(&sbinfo->si_kobj);
5615 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
5618 + char name[SysaufsSiNameLen];
5621 + * This function is a dynamic '__init' fucntion actually,
5622 + * so the tiny check for si_rwsem is unnecessary.
5624 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
5628 + AuErr1("/debug/aufs is uninitialized\n");
5633 + sysaufs_name(sbinfo, name);
5634 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
5635 + if (unlikely(!sbinfo->si_dbgaufs))
5637 + kobject_get(&sbinfo->si_kobj);
5639 + sbinfo->si_dbgaufs_xib = debugfs_create_file
5640 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
5641 + &dbgaufs_xib_fop);
5642 + if (unlikely(!sbinfo->si_dbgaufs_xib))
5645 + sbinfo->si_dbgaufs_plink = debugfs_create_file
5646 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
5647 + &dbgaufs_plink_fop);
5648 + if (unlikely(!sbinfo->si_dbgaufs_plink))
5651 + err = dbgaufs_xigen_init(sbinfo);
5653 + goto out; /* success */
5656 + dbgaufs_si_fin(sbinfo);
5661 +/* ---------------------------------------------------------------------- */
5663 +void dbgaufs_fin(void)
5665 + debugfs_remove(dbgaufs);
5668 +int __init dbgaufs_init(void)
5673 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
5678 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
5679 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
5680 +++ linux/fs/aufs/dbgaufs.h 2014-06-24 00:14:06.779385790 +0200
5683 + * Copyright (C) 2005-2014 Junjiro R. Okajima
5685 + * This program, aufs is free software; you can redistribute it and/or modify
5686 + * it under the terms of the GNU General Public License as published by
5687 + * the Free Software Foundation; either version 2 of the License, or
5688 + * (at your option) any later version.
5690 + * This program is distributed in the hope that it will be useful,
5691 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5692 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5693 + * GNU General Public License for more details.
5695 + * You should have received a copy of the GNU General Public License
5696 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5700 + * debugfs interface
5703 +#ifndef __DBGAUFS_H__
5704 +#define __DBGAUFS_H__
5708 +struct super_block;
5711 +#ifdef CONFIG_DEBUG_FS
5713 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
5714 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
5715 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
5716 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
5717 +void dbgaufs_fin(void);
5718 +int __init dbgaufs_init(void);
5720 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
5721 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
5722 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
5723 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
5724 +AuStubVoid(dbgaufs_fin, void)
5725 +AuStubInt0(__init dbgaufs_init, void)
5726 +#endif /* CONFIG_DEBUG_FS */
5728 +#endif /* __KERNEL__ */
5729 +#endif /* __DBGAUFS_H__ */
5730 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
5731 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
5732 +++ linux/fs/aufs/dcsub.c 2014-06-24 00:14:06.779385790 +0200
5735 + * Copyright (C) 2005-2014 Junjiro R. Okajima
5737 + * This program, aufs is free software; you can redistribute it and/or modify
5738 + * it under the terms of the GNU General Public License as published by
5739 + * the Free Software Foundation; either version 2 of the License, or
5740 + * (at your option) any later version.
5742 + * This program is distributed in the hope that it will be useful,
5743 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5744 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5745 + * GNU General Public License for more details.
5747 + * You should have received a copy of the GNU General Public License
5748 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5752 + * sub-routines for dentry cache
5757 +static void au_dpage_free(struct au_dpage *dpage)
5760 + struct dentry **p;
5762 + p = dpage->dentries;
5763 + for (i = 0; i < dpage->ndentry; i++)
5765 + free_page((unsigned long)dpage->dentries);
5768 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
5774 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
5775 + if (unlikely(!dpages->dpages))
5778 + p = (void *)__get_free_page(gfp);
5782 + dpages->dpages[0].ndentry = 0;
5783 + dpages->dpages[0].dentries = p;
5784 + dpages->ndpage = 1;
5785 + return 0; /* success */
5788 + kfree(dpages->dpages);
5793 +void au_dpages_free(struct au_dcsub_pages *dpages)
5796 + struct au_dpage *p;
5798 + p = dpages->dpages;
5799 + for (i = 0; i < dpages->ndpage; i++)
5800 + au_dpage_free(p++);
5801 + kfree(dpages->dpages);
5804 +static int au_dpages_append(struct au_dcsub_pages *dpages,
5805 + struct dentry *dentry, gfp_t gfp)
5808 + struct au_dpage *dpage;
5811 + dpage = dpages->dpages + dpages->ndpage - 1;
5812 + sz = PAGE_SIZE / sizeof(dentry);
5813 + if (unlikely(dpage->ndentry >= sz)) {
5814 + AuLabel(new dpage);
5816 + sz = dpages->ndpage * sizeof(*dpages->dpages);
5817 + p = au_kzrealloc(dpages->dpages, sz,
5818 + sz + sizeof(*dpages->dpages), gfp);
5822 + dpages->dpages = p;
5823 + dpage = dpages->dpages + dpages->ndpage;
5824 + p = (void *)__get_free_page(gfp);
5828 + dpage->ndentry = 0;
5829 + dpage->dentries = p;
5833 + AuDebugOn(!d_count(dentry));
5834 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
5835 + return 0; /* success */
5841 +/* try d_walk() in linux/fs/dcache.c */
5842 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
5843 + au_dpages_test test, void *arg)
5846 + struct dentry *this_parent;
5847 + struct list_head *next;
5848 + struct super_block *sb = root->d_sb;
5851 + write_seqlock(&rename_lock);
5852 + this_parent = root;
5853 + spin_lock(&this_parent->d_lock);
5855 + next = this_parent->d_subdirs.next;
5857 + if (this_parent->d_sb == sb
5858 + && !IS_ROOT(this_parent)
5859 + && au_di(this_parent)
5860 + && d_count(this_parent)
5861 + && (!test || test(this_parent, arg))) {
5862 + err = au_dpages_append(dpages, this_parent, GFP_ATOMIC);
5863 + if (unlikely(err))
5867 + while (next != &this_parent->d_subdirs) {
5868 + struct list_head *tmp = next;
5869 + struct dentry *dentry = list_entry(tmp, struct dentry,
5873 + spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED);
5874 + if (d_count(dentry)) {
5875 + if (!list_empty(&dentry->d_subdirs)) {
5876 + spin_unlock(&this_parent->d_lock);
5877 + spin_release(&dentry->d_lock.dep_map, 1,
5879 + this_parent = dentry;
5880 + spin_acquire(&this_parent->d_lock.dep_map, 0, 1,
5884 + if (dentry->d_sb == sb
5886 + && (!test || test(dentry, arg)))
5887 + err = au_dpages_append(dpages, dentry,
5890 + spin_unlock(&dentry->d_lock);
5891 + if (unlikely(err))
5895 + if (this_parent != root) {
5896 + struct dentry *tmp;
5897 + struct dentry *child;
5899 + tmp = this_parent->d_parent;
5901 + spin_unlock(&this_parent->d_lock);
5902 + child = this_parent;
5903 + this_parent = tmp;
5904 + spin_lock(&this_parent->d_lock);
5905 + rcu_read_unlock();
5906 + next = child->d_u.d_child.next;
5911 + spin_unlock(&this_parent->d_lock);
5912 + write_sequnlock(&rename_lock);
5916 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
5917 + int do_include, au_dpages_test test, void *arg)
5922 + write_seqlock(&rename_lock);
5923 + spin_lock(&dentry->d_lock);
5925 + && d_count(dentry)
5926 + && (!test || test(dentry, arg)))
5927 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
5928 + spin_unlock(&dentry->d_lock);
5929 + if (unlikely(err))
5933 + * RCU for vfsmount is unnecessary since this is a traverse in a single
5936 + while (!IS_ROOT(dentry)) {
5937 + dentry = dentry->d_parent; /* rename_lock is locked */
5938 + spin_lock(&dentry->d_lock);
5939 + if (d_count(dentry)
5940 + && (!test || test(dentry, arg)))
5941 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
5942 + spin_unlock(&dentry->d_lock);
5943 + if (unlikely(err))
5948 + write_sequnlock(&rename_lock);
5952 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
5954 + return au_di(dentry) && dentry->d_sb == arg;
5957 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
5958 + struct dentry *dentry, int do_include)
5960 + return au_dcsub_pages_rev(dpages, dentry, do_include,
5961 + au_dcsub_dpages_aufs, dentry->d_sb);
5964 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
5966 + struct path path[2] = {
5975 + return path_is_under(path + 0, path + 1);
5977 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
5978 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
5979 +++ linux/fs/aufs/dcsub.h 2014-06-24 00:14:06.779385790 +0200
5982 + * Copyright (C) 2005-2014 Junjiro R. Okajima
5984 + * This program, aufs is free software; you can redistribute it and/or modify
5985 + * it under the terms of the GNU General Public License as published by
5986 + * the Free Software Foundation; either version 2 of the License, or
5987 + * (at your option) any later version.
5989 + * This program is distributed in the hope that it will be useful,
5990 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5991 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5992 + * GNU General Public License for more details.
5994 + * You should have received a copy of the GNU General Public License
5995 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5999 + * sub-routines for dentry cache
6002 +#ifndef __AUFS_DCSUB_H__
6003 +#define __AUFS_DCSUB_H__
6007 +#include <linux/dcache.h>
6008 +#include <linux/fs.h>
6014 + struct dentry **dentries;
6017 +struct au_dcsub_pages {
6019 + struct au_dpage *dpages;
6022 +/* ---------------------------------------------------------------------- */
6025 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
6026 +void au_dpages_free(struct au_dcsub_pages *dpages);
6027 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
6028 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6029 + au_dpages_test test, void *arg);
6030 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6031 + int do_include, au_dpages_test test, void *arg);
6032 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6033 + struct dentry *dentry, int do_include);
6034 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
6036 +/* ---------------------------------------------------------------------- */
6039 + * todo: in linux-3.13, several similar (but faster) helpers are added to
6040 + * include/linux/dcache.h. Try them (in the future).
6043 +static inline int au_d_hashed_positive(struct dentry *d)
6046 + struct inode *inode = d->d_inode;
6048 + if (unlikely(d_unhashed(d) || !inode || !inode->i_nlink))
6053 +static inline int au_d_linkable(struct dentry *d)
6056 + struct inode *inode = d->d_inode;
6057 + err = au_d_hashed_positive(d);
6060 + && (inode->i_state & I_LINKABLE))
6065 +static inline int au_d_alive(struct dentry *d)
6068 + struct inode *inode;
6071 + err = au_d_hashed_positive(d);
6073 + inode = d->d_inode;
6074 + if (unlikely(d_unlinked(d) || !inode || !inode->i_nlink))
6080 +static inline int au_alive_dir(struct dentry *d)
6083 + err = au_d_alive(d);
6084 + if (unlikely(err || IS_DEADDIR(d->d_inode)))
6089 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
6091 + return a->len == b->len
6092 + && !memcmp(a->name, b->name, a->len);
6095 +#endif /* __KERNEL__ */
6096 +#endif /* __AUFS_DCSUB_H__ */
6097 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
6098 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
6099 +++ linux/fs/aufs/debug.c 2014-06-24 00:14:06.779385790 +0200
6102 + * Copyright (C) 2005-2014 Junjiro R. Okajima
6104 + * This program, aufs is free software; you can redistribute it and/or modify
6105 + * it under the terms of the GNU General Public License as published by
6106 + * the Free Software Foundation; either version 2 of the License, or
6107 + * (at your option) any later version.
6109 + * This program is distributed in the hope that it will be useful,
6110 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6111 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6112 + * GNU General Public License for more details.
6114 + * You should have received a copy of the GNU General Public License
6115 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6119 + * debug print functions
6122 +#include <linux/vt_kern.h>
6125 +/* Returns 0, or -errno. arg is in kp->arg. */
6126 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
6130 + err = kstrtoint(val, 0, &n);
6140 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
6141 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
6146 + return sprintf(buffer, "%d", atomic_read(a));
6149 +static struct kernel_param_ops param_ops_atomic_t = {
6150 + .set = param_atomic_t_set,
6151 + .get = param_atomic_t_get
6152 + /* void (*free)(void *arg) */
6155 +atomic_t aufs_debug = ATOMIC_INIT(0);
6156 +MODULE_PARM_DESC(debug, "debug print");
6157 +module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP);
6159 +char *au_plevel = KERN_DEBUG;
6160 +#define dpri(fmt, ...) do { \
6162 + && strcmp(au_plevel, KERN_DEBUG)) \
6163 + || au_debug_test()) \
6164 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
6167 +/* ---------------------------------------------------------------------- */
6169 +void au_dpri_whlist(struct au_nhash *whlist)
6171 + unsigned long ul, n;
6172 + struct hlist_head *head;
6173 + struct au_vdir_wh *pos;
6175 + n = whlist->nh_num;
6176 + head = whlist->nh_head;
6177 + for (ul = 0; ul < n; ul++) {
6178 + hlist_for_each_entry(pos, head, wh_hash)
6179 + dpri("b%d, %.*s, %d\n",
6181 + pos->wh_str.len, pos->wh_str.name,
6187 +void au_dpri_vdir(struct au_vdir *vdir)
6190 + union au_vdir_deblk_p p;
6193 + if (!vdir || IS_ERR(vdir)) {
6194 + dpri("err %ld\n", PTR_ERR(vdir));
6198 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n",
6199 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
6200 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
6201 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
6202 + p.deblk = vdir->vd_deblk[ul];
6204 + dpri("[%lu]: %p\n", ul, o);
6208 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
6209 + struct dentry *wh)
6214 + if (!inode || IS_ERR(inode)) {
6215 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
6219 + /* the type of i_blocks depends upon CONFIG_LBDAF */
6220 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
6221 + && sizeof(inode->i_blocks) != sizeof(u64));
6223 + n = (void *)wh->d_name.name;
6224 + l = wh->d_name.len;
6227 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
6228 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
6230 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
6231 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
6232 + i_size_read(inode), (unsigned long long)inode->i_blocks,
6233 + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
6234 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
6235 + inode->i_state, inode->i_flags, inode->i_version,
6236 + inode->i_generation,
6237 + l ? ", wh " : "", l, n);
6241 +void au_dpri_inode(struct inode *inode)
6243 + struct au_iinfo *iinfo;
6244 + aufs_bindex_t bindex;
6247 + err = do_pri_inode(-1, inode, -1, NULL);
6248 + if (err || !au_test_aufs(inode->i_sb))
6251 + iinfo = au_ii(inode);
6254 + dpri("i-1: bstart %d, bend %d, gen %d\n",
6255 + iinfo->ii_bstart, iinfo->ii_bend, au_iigen(inode, NULL));
6256 + if (iinfo->ii_bstart < 0)
6259 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend; bindex++) {
6260 + hn = !!au_hn(iinfo->ii_hinode + bindex);
6261 + do_pri_inode(bindex, iinfo->ii_hinode[0 + bindex].hi_inode, hn,
6262 + iinfo->ii_hinode[0 + bindex].hi_whdentry);
6266 +void au_dpri_dalias(struct inode *inode)
6270 + spin_lock(&inode->i_lock);
6271 + hlist_for_each_entry(d, &inode->i_dentry, d_alias)
6272 + au_dpri_dentry(d);
6273 + spin_unlock(&inode->i_lock);
6276 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
6278 + struct dentry *wh = NULL;
6281 + if (!dentry || IS_ERR(dentry)) {
6282 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
6285 + /* do not call dget_parent() here */
6286 + /* note: access d_xxx without d_lock */
6287 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
6288 + bindex, dentry, dentry,
6289 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
6290 + d_count(dentry), dentry->d_flags,
6291 + d_unhashed(dentry) ? "un" : "");
6293 + if (bindex >= 0 && dentry->d_inode && au_test_aufs(dentry->d_sb)) {
6294 + struct au_iinfo *iinfo = au_ii(dentry->d_inode);
6296 + hn = !!au_hn(iinfo->ii_hinode + bindex);
6297 + wh = iinfo->ii_hinode[0 + bindex].hi_whdentry;
6300 + do_pri_inode(bindex, dentry->d_inode, hn, wh);
6304 +void au_dpri_dentry(struct dentry *dentry)
6306 + struct au_dinfo *dinfo;
6307 + aufs_bindex_t bindex;
6309 + struct au_hdentry *hdp;
6311 + err = do_pri_dentry(-1, dentry);
6312 + if (err || !au_test_aufs(dentry->d_sb))
6315 + dinfo = au_di(dentry);
6318 + dpri("d-1: bstart %d, bend %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
6319 + dinfo->di_bstart, dinfo->di_bend,
6320 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
6321 + dinfo->di_tmpfile);
6322 + if (dinfo->di_bstart < 0)
6324 + hdp = dinfo->di_hdentry;
6325 + for (bindex = dinfo->di_bstart; bindex <= dinfo->di_bend; bindex++)
6326 + do_pri_dentry(bindex, hdp[0 + bindex].hd_dentry);
6329 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
6333 + if (!file || IS_ERR(file)) {
6334 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
6340 + && au_test_aufs(file->f_dentry->d_sb)
6342 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
6343 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
6344 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
6345 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
6346 + file->f_version, file->f_pos, a);
6347 + if (file->f_dentry)
6348 + do_pri_dentry(bindex, file->f_dentry);
6352 +void au_dpri_file(struct file *file)
6354 + struct au_finfo *finfo;
6355 + struct au_fidir *fidir;
6356 + struct au_hfile *hfile;
6357 + aufs_bindex_t bindex;
6360 + err = do_pri_file(-1, file);
6361 + if (err || !file->f_dentry || !au_test_aufs(file->f_dentry->d_sb))
6364 + finfo = au_fi(file);
6367 + if (finfo->fi_btop < 0)
6369 + fidir = finfo->fi_hdir;
6371 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
6373 + for (bindex = finfo->fi_btop;
6374 + bindex >= 0 && bindex <= fidir->fd_bbot;
6376 + hfile = fidir->fd_hfile + bindex;
6377 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
6381 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
6383 + struct vfsmount *mnt;
6384 + struct super_block *sb;
6386 + if (!br || IS_ERR(br))
6388 + mnt = au_br_mnt(br);
6389 + if (!mnt || IS_ERR(mnt))
6392 + if (!sb || IS_ERR(sb))
6395 + dpri("s%d: {perm 0x%x, id %d, cnt %d, wbr %p}, "
6396 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
6398 + bindex, br->br_perm, br->br_id, atomic_read(&br->br_count),
6399 + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
6400 + sb->s_flags, sb->s_count,
6401 + atomic_read(&sb->s_active), !!br->br_xino.xi_file);
6405 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
6409 +void au_dpri_sb(struct super_block *sb)
6411 + struct au_sbinfo *sbinfo;
6412 + aufs_bindex_t bindex;
6414 + /* to reuduce stack size */
6416 + struct vfsmount mnt;
6417 + struct au_branch fake;
6420 + /* this function can be called from magic sysrq */
6421 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
6422 + if (unlikely(!a)) {
6423 + dpri("no memory\n");
6427 + a->mnt.mnt_sb = sb;
6428 + a->fake.br_perm = 0;
6429 + a->fake.br_path.mnt = &a->mnt;
6430 + a->fake.br_xino.xi_file = NULL;
6431 + atomic_set(&a->fake.br_count, 0);
6432 + smp_mb(); /* atomic_set */
6433 + err = do_pri_br(-1, &a->fake);
6435 + dpri("dev 0x%x\n", sb->s_dev);
6436 + if (err || !au_test_aufs(sb))
6439 + sbinfo = au_sbi(sb);
6442 + dpri("nw %d, gen %u, kobj %d\n",
6443 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
6444 + atomic_read(&sbinfo->si_kobj.kref.refcount));
6445 + for (bindex = 0; bindex <= sbinfo->si_bend; bindex++)
6446 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
6449 +/* ---------------------------------------------------------------------- */
6451 +void au_dbg_sleep_jiffy(int jiffy)
6454 + jiffy = schedule_timeout_uninterruptible(jiffy);
6457 +void au_dbg_iattr(struct iattr *ia)
6459 +#define AuBit(name) \
6461 + if (ia->ia_valid & ATTR_ ## name) \
6462 + dpri(#name "\n"); \
6482 + dpri("ia_file %p\n", ia->ia_file);
6485 +/* ---------------------------------------------------------------------- */
6487 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
6489 + struct inode *h_inode, *inode = dentry->d_inode;
6490 + struct dentry *h_dentry;
6491 + aufs_bindex_t bindex, bend, bi;
6493 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
6496 + bend = au_dbend(dentry);
6497 + bi = au_ibend(inode);
6500 + bindex = au_dbstart(dentry);
6501 + bi = au_ibstart(inode);
6505 + for (; bindex <= bend; bindex++) {
6506 + h_dentry = au_h_dptr(dentry, bindex);
6509 + h_inode = au_h_iptr(inode, bindex);
6510 + if (unlikely(h_inode != h_dentry->d_inode)) {
6512 + AuDbg("b%d, %s:%d\n", bindex, func, line);
6513 + AuDbgDentry(dentry);
6514 + AuDbgInode(inode);
6521 +void au_dbg_verify_dir_parent(struct dentry *dentry, unsigned int sigen)
6523 + struct dentry *parent;
6525 + parent = dget_parent(dentry);
6526 + AuDebugOn(!S_ISDIR(dentry->d_inode->i_mode));
6527 + AuDebugOn(IS_ROOT(dentry));
6528 + AuDebugOn(au_digen_test(parent, sigen));
6532 +void au_dbg_verify_nondir_parent(struct dentry *dentry, unsigned int sigen)
6534 + struct dentry *parent;
6535 + struct inode *inode;
6537 + parent = dget_parent(dentry);
6538 + inode = dentry->d_inode;
6539 + AuDebugOn(inode && S_ISDIR(dentry->d_inode->i_mode));
6540 + AuDebugOn(au_digen_test(parent, sigen));
6544 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
6547 + struct au_dcsub_pages dpages;
6548 + struct au_dpage *dpage;
6549 + struct dentry **dentries;
6551 + err = au_dpages_init(&dpages, GFP_NOFS);
6553 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
6555 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
6556 + dpage = dpages.dpages + i;
6557 + dentries = dpage->dentries;
6558 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
6559 + AuDebugOn(au_digen_test(dentries[j], sigen));
6561 + au_dpages_free(&dpages);
6564 +void au_dbg_verify_kthread(void)
6566 + if (au_wkq_test()) {
6569 + * It may be recursive, but udba=notify between two aufs mounts,
6570 + * where a single ro branch is shared, is not a problem.
6576 +/* ---------------------------------------------------------------------- */
6578 +void au_debug_sbinfo_init(struct au_sbinfo *sbinfo __maybe_unused)
6580 +#ifdef AuForceNoPlink
6581 + au_opt_clr(sbinfo->si_mntflags, PLINK);
6583 +#ifdef AuForceNoXino
6584 + au_opt_clr(sbinfo->si_mntflags, XINO);
6586 +#ifdef AuForceNoRefrof
6587 + au_opt_clr(sbinfo->si_mntflags, REFROF);
6589 +#ifdef AuForceHnotify
6590 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_HNOTIFY);
6593 + sbinfo->si_rdblk = 0;
6594 + sbinfo->si_rdhash = 0;
6598 +int __init au_debug_init(void)
6600 + aufs_bindex_t bindex;
6601 + struct au_vdir_destr destr;
6604 + AuDebugOn(bindex >= 0);
6607 + AuDebugOn(destr.len < NAME_MAX);
6609 +#ifdef CONFIG_4KSTACKS
6610 + pr_warn("CONFIG_4KSTACKS is defined.\n");
6613 +#ifdef AuForceNoBrs
6619 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
6620 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
6621 +++ linux/fs/aufs/debug.h 2014-06-24 00:14:06.779385790 +0200
6624 + * Copyright (C) 2005-2014 Junjiro R. Okajima
6626 + * This program, aufs is free software; you can redistribute it and/or modify
6627 + * it under the terms of the GNU General Public License as published by
6628 + * the Free Software Foundation; either version 2 of the License, or
6629 + * (at your option) any later version.
6631 + * This program is distributed in the hope that it will be useful,
6632 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6633 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6634 + * GNU General Public License for more details.
6636 + * You should have received a copy of the GNU General Public License
6637 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6641 + * debug print functions
6644 +#ifndef __AUFS_DEBUG_H__
6645 +#define __AUFS_DEBUG_H__
6649 +#include <linux/atomic.h>
6650 +#include <linux/module.h>
6651 +#include <linux/kallsyms.h>
6652 +#include <linux/sysrq.h>
6654 +#ifdef CONFIG_AUFS_DEBUG
6655 +#define AuDebugOn(a) BUG_ON(a)
6657 +/* module parameter */
6658 +extern atomic_t aufs_debug;
6659 +static inline void au_debug_on(void)
6661 + atomic_inc(&aufs_debug);
6663 +static inline void au_debug_off(void)
6665 + atomic_dec_if_positive(&aufs_debug);
6668 +static inline int au_debug_test(void)
6670 + return atomic_read(&aufs_debug) > 0;
6673 +#define AuDebugOn(a) do {} while (0)
6674 +AuStubVoid(au_debug_on, void)
6675 +AuStubVoid(au_debug_off, void)
6676 +AuStubInt0(au_debug_test, void)
6677 +#endif /* CONFIG_AUFS_DEBUG */
6679 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
6681 +/* ---------------------------------------------------------------------- */
6685 +#define AuDbg(fmt, ...) do { \
6686 + if (au_debug_test()) \
6687 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
6689 +#define AuLabel(l) AuDbg(#l "\n")
6690 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
6691 +#define AuWarn1(fmt, ...) do { \
6692 + static unsigned char _c; \
6694 + pr_warn(fmt, ##__VA_ARGS__); \
6697 +#define AuErr1(fmt, ...) do { \
6698 + static unsigned char _c; \
6700 + pr_err(fmt, ##__VA_ARGS__); \
6703 +#define AuIOErr1(fmt, ...) do { \
6704 + static unsigned char _c; \
6706 + AuIOErr(fmt, ##__VA_ARGS__); \
6709 +#define AuUnsupportMsg "This operation is not supported." \
6710 + " Please report this application to aufs-users ML."
6711 +#define AuUnsupport(fmt, ...) do { \
6712 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
6716 +#define AuTraceErr(e) do { \
6717 + if (unlikely((e) < 0)) \
6718 + AuDbg("err %d\n", (int)(e)); \
6721 +#define AuTraceErrPtr(p) do { \
6723 + AuDbg("err %ld\n", PTR_ERR(p)); \
6726 +/* dirty macros for debug print, use with "%.*s" and caution */
6727 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
6729 +/* ---------------------------------------------------------------------- */
6734 +#ifdef CONFIG_AUFS_DEBUG
6735 +extern char *au_plevel;
6737 +void au_dpri_whlist(struct au_nhash *whlist);
6739 +void au_dpri_vdir(struct au_vdir *vdir);
6741 +void au_dpri_inode(struct inode *inode);
6742 +void au_dpri_dalias(struct inode *inode);
6743 +void au_dpri_dentry(struct dentry *dentry);
6745 +void au_dpri_file(struct file *filp);
6746 +struct super_block;
6747 +void au_dpri_sb(struct super_block *sb);
6749 +void au_dbg_sleep_jiffy(int jiffy);
6751 +void au_dbg_iattr(struct iattr *ia);
6753 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
6754 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
6755 +void au_dbg_verify_dir_parent(struct dentry *dentry, unsigned int sigen);
6756 +void au_dbg_verify_nondir_parent(struct dentry *dentry, unsigned int sigen);
6757 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
6758 +void au_dbg_verify_kthread(void);
6760 +int __init au_debug_init(void);
6761 +void au_debug_sbinfo_init(struct au_sbinfo *sbinfo);
6762 +#define AuDbgWhlist(w) do { \
6764 + au_dpri_whlist(w); \
6767 +#define AuDbgVdir(v) do { \
6769 + au_dpri_vdir(v); \
6772 +#define AuDbgInode(i) do { \
6774 + au_dpri_inode(i); \
6777 +#define AuDbgDAlias(i) do { \
6779 + au_dpri_dalias(i); \
6782 +#define AuDbgDentry(d) do { \
6784 + au_dpri_dentry(d); \
6787 +#define AuDbgFile(f) do { \
6789 + au_dpri_file(f); \
6792 +#define AuDbgSb(sb) do { \
6793 + AuDbg(#sb "\n"); \
6797 +#define AuDbgSleep(sec) do { \
6798 + AuDbg("sleep %d sec\n", sec); \
6802 +#define AuDbgSleepJiffy(jiffy) do { \
6803 + AuDbg("sleep %d jiffies\n", jiffy); \
6804 + au_dbg_sleep_jiffy(jiffy); \
6807 +#define AuDbgIAttr(ia) do { \
6808 + AuDbg("ia_valid 0x%x\n", (ia)->ia_valid); \
6809 + au_dbg_iattr(ia); \
6812 +#define AuDbgSym(addr) do { \
6813 + char sym[KSYM_SYMBOL_LEN]; \
6814 + sprint_symbol(sym, (unsigned long)addr); \
6815 + AuDbg("%s\n", sym); \
6818 +#define AuInfoSym(addr) do { \
6819 + char sym[KSYM_SYMBOL_LEN]; \
6820 + sprint_symbol(sym, (unsigned long)addr); \
6821 + AuInfo("%s\n", sym); \
6824 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
6825 +AuStubVoid(au_dbg_verify_dir_parent, struct dentry *dentry, unsigned int sigen)
6826 +AuStubVoid(au_dbg_verify_nondir_parent, struct dentry *dentry,
6827 + unsigned int sigen)
6828 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
6829 +AuStubVoid(au_dbg_verify_kthread, void)
6830 +AuStubInt0(__init au_debug_init, void)
6831 +AuStubVoid(au_debug_sbinfo_init, struct au_sbinfo *sbinfo)
6833 +#define AuDbgWhlist(w) do {} while (0)
6834 +#define AuDbgVdir(v) do {} while (0)
6835 +#define AuDbgInode(i) do {} while (0)
6836 +#define AuDbgDAlias(i) do {} while (0)
6837 +#define AuDbgDentry(d) do {} while (0)
6838 +#define AuDbgFile(f) do {} while (0)
6839 +#define AuDbgSb(sb) do {} while (0)
6840 +#define AuDbgSleep(sec) do {} while (0)
6841 +#define AuDbgSleepJiffy(jiffy) do {} while (0)
6842 +#define AuDbgIAttr(ia) do {} while (0)
6843 +#define AuDbgSym(addr) do {} while (0)
6844 +#define AuInfoSym(addr) do {} while (0)
6845 +#endif /* CONFIG_AUFS_DEBUG */
6847 +/* ---------------------------------------------------------------------- */
6849 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
6850 +int __init au_sysrq_init(void);
6851 +void au_sysrq_fin(void);
6853 +#ifdef CONFIG_HW_CONSOLE
6854 +#define au_dbg_blocked() do { \
6856 + handle_sysrq('w'); \
6859 +AuStubVoid(au_dbg_blocked, void)
6863 +AuStubInt0(__init au_sysrq_init, void)
6864 +AuStubVoid(au_sysrq_fin, void)
6865 +AuStubVoid(au_dbg_blocked, void)
6866 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
6868 +#endif /* __KERNEL__ */
6869 +#endif /* __AUFS_DEBUG_H__ */
6870 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
6871 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
6872 +++ linux/fs/aufs/dentry.c 2014-06-24 00:14:06.779385790 +0200
6875 + * Copyright (C) 2005-2014 Junjiro R. Okajima
6877 + * This program, aufs is free software; you can redistribute it and/or modify
6878 + * it under the terms of the GNU General Public License as published by
6879 + * the Free Software Foundation; either version 2 of the License, or
6880 + * (at your option) any later version.
6882 + * This program is distributed in the hope that it will be useful,
6883 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6884 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6885 + * GNU General Public License for more details.
6887 + * You should have received a copy of the GNU General Public License
6888 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6892 + * lookup and dentry operations
6895 +#include <linux/namei.h>
6898 +#define AuLkup_ALLOW_NEG 1
6899 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
6900 +#define au_fset_lkup(flags, name) \
6901 + do { (flags) |= AuLkup_##name; } while (0)
6902 +#define au_fclr_lkup(flags, name) \
6903 + do { (flags) &= ~AuLkup_##name; } while (0)
6905 +struct au_do_lookup_args {
6906 + unsigned int flags;
6911 + * returns positive/negative dentry, NULL or an error.
6912 + * NULL means whiteout-ed or not-found.
6914 +static struct dentry*
6915 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
6916 + aufs_bindex_t bindex, struct qstr *wh_name,
6917 + struct au_do_lookup_args *args)
6919 + struct dentry *h_dentry;
6920 + struct inode *h_inode, *inode;
6921 + struct au_branch *br;
6922 + int wh_found, opq;
6923 + unsigned char wh_able;
6924 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
6927 + br = au_sbr(dentry->d_sb, bindex);
6928 + wh_able = !!au_br_whable(br->br_perm);
6930 + wh_found = au_wh_test(h_parent, wh_name, br, /*try_sio*/0);
6931 + h_dentry = ERR_PTR(wh_found);
6934 + if (unlikely(wh_found < 0))
6937 + /* We found a whiteout */
6938 + /* au_set_dbend(dentry, bindex); */
6939 + au_set_dbwh(dentry, bindex);
6941 + return NULL; /* success */
6944 + h_dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
6945 + if (IS_ERR(h_dentry))
6948 + h_inode = h_dentry->d_inode;
6952 + } else if (wh_found
6953 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
6956 + if (au_dbend(dentry) <= bindex)
6957 + au_set_dbend(dentry, bindex);
6958 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
6959 + au_set_dbstart(dentry, bindex);
6960 + au_set_h_dptr(dentry, bindex, h_dentry);
6962 + inode = dentry->d_inode;
6963 + if (!h_inode || !S_ISDIR(h_inode->i_mode) || !wh_able
6964 + || (inode && !S_ISDIR(inode->i_mode)))
6965 + goto out; /* success */
6967 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
6968 + opq = au_diropq_test(h_dentry, br);
6969 + mutex_unlock(&h_inode->i_mutex);
6971 + au_set_dbdiropq(dentry, bindex);
6972 + else if (unlikely(opq < 0)) {
6973 + au_set_h_dptr(dentry, bindex, NULL);
6974 + h_dentry = ERR_PTR(opq);
6985 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
6987 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
6988 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
6994 + * returns the number of lower positive dentries,
6995 + * otherwise an error.
6996 + * can be called at unlinking with @type is zero.
6998 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type)
7000 + int npositive, err;
7001 + aufs_bindex_t bindex, btail, bdiropq;
7002 + unsigned char isdir;
7003 + struct qstr whname;
7004 + struct au_do_lookup_args args = {
7008 + const struct qstr *name = &dentry->d_name;
7009 + struct dentry *parent;
7010 + struct inode *inode;
7012 + err = au_test_shwh(dentry->d_sb, name);
7013 + if (unlikely(err))
7016 + err = au_wh_name_alloc(&whname, name);
7017 + if (unlikely(err))
7020 + inode = dentry->d_inode;
7021 + isdir = !!(inode && S_ISDIR(inode->i_mode));
7023 + au_fset_lkup(args.flags, ALLOW_NEG);
7026 + parent = dget_parent(dentry);
7027 + btail = au_dbtaildir(parent);
7028 + for (bindex = bstart; bindex <= btail; bindex++) {
7029 + struct dentry *h_parent, *h_dentry;
7030 + struct inode *h_inode, *h_dir;
7032 + h_dentry = au_h_dptr(dentry, bindex);
7034 + if (h_dentry->d_inode)
7036 + if (type != S_IFDIR)
7040 + h_parent = au_h_dptr(parent, bindex);
7043 + h_dir = h_parent->d_inode;
7044 + if (!h_dir || !S_ISDIR(h_dir->i_mode))
7047 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
7048 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname,
7050 + mutex_unlock(&h_dir->i_mutex);
7051 + err = PTR_ERR(h_dentry);
7052 + if (IS_ERR(h_dentry))
7054 + au_fclr_lkup(args.flags, ALLOW_NEG);
7056 + if (au_dbwh(dentry) >= 0)
7060 + h_inode = h_dentry->d_inode;
7065 + args.type = h_inode->i_mode & S_IFMT;
7066 + if (args.type != S_IFDIR)
7069 + /* the type of lower may be different */
7070 + bdiropq = au_dbdiropq(dentry);
7071 + if (bdiropq >= 0 && bdiropq <= bindex)
7077 + AuLabel(positive);
7078 + au_update_dbstart(dentry);
7081 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
7082 + && au_dbstart(dentry) < 0)) {
7084 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
7090 + kfree(whname.name);
7095 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent,
7096 + struct au_branch *br)
7098 + struct dentry *dentry;
7101 + if (!au_test_h_perm_sio(parent->d_inode, MAY_EXEC))
7102 + dentry = vfsub_lkup_one(name, parent);
7104 + struct vfsub_lkup_one_args args = {
7110 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
7111 + if (unlikely(wkq_err))
7112 + dentry = ERR_PTR(wkq_err);
7119 + * lookup @dentry on @bindex which should be negative.
7121 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
7124 + struct dentry *parent, *h_parent, *h_dentry;
7125 + struct au_branch *br;
7127 + parent = dget_parent(dentry);
7128 + h_parent = au_h_dptr(parent, bindex);
7129 + br = au_sbr(dentry->d_sb, bindex);
7131 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
7133 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent, br);
7134 + err = PTR_ERR(h_dentry);
7135 + if (IS_ERR(h_dentry))
7137 + if (unlikely(h_dentry->d_inode)) {
7139 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
7145 + if (bindex < au_dbstart(dentry))
7146 + au_set_dbstart(dentry, bindex);
7147 + if (au_dbend(dentry) < bindex)
7148 + au_set_dbend(dentry, bindex);
7149 + au_set_h_dptr(dentry, bindex, h_dentry);
7156 +/* ---------------------------------------------------------------------- */
7158 +/* subset of struct inode */
7160 + unsigned long i_ino;
7161 + /* unsigned int i_nlink; */
7167 + blkcnt_t i_blocks;
7172 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
7174 + ia->i_ino = h_inode->i_ino;
7175 + /* ia->i_nlink = h_inode->i_nlink; */
7176 + ia->i_uid = h_inode->i_uid;
7177 + ia->i_gid = h_inode->i_gid;
7178 + ia->i_version = h_inode->i_version;
7180 + ia->i_size = h_inode->i_size;
7181 + ia->i_blocks = h_inode->i_blocks;
7183 + ia->i_mode = (h_inode->i_mode & S_IFMT);
7186 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
7188 + return ia->i_ino != h_inode->i_ino
7189 + /* || ia->i_nlink != h_inode->i_nlink */
7190 + || !uid_eq(ia->i_uid, h_inode->i_uid)
7191 + || !gid_eq(ia->i_gid, h_inode->i_gid)
7192 + || ia->i_version != h_inode->i_version
7194 + || ia->i_size != h_inode->i_size
7195 + || ia->i_blocks != h_inode->i_blocks
7197 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
7200 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
7201 + struct au_branch *br)
7204 + struct au_iattr ia;
7205 + struct inode *h_inode;
7206 + struct dentry *h_d;
7207 + struct super_block *h_sb;
7210 + memset(&ia, -1, sizeof(ia));
7211 + h_sb = h_dentry->d_sb;
7212 + h_inode = h_dentry->d_inode;
7214 + au_iattr_save(&ia, h_inode);
7215 + else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
7216 + /* nfs d_revalidate may return 0 for negative dentry */
7217 + /* fuse d_revalidate always return 0 for negative dentry */
7220 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
7221 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
7222 + err = PTR_ERR(h_d);
7227 + if (unlikely(h_d != h_dentry
7228 + || h_d->d_inode != h_inode
7229 + || (h_inode && au_iattr_test(&ia, h_inode))))
7230 + err = au_busy_or_stale();
7238 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
7239 + struct dentry *h_parent, struct au_branch *br)
7244 + if (udba == AuOpt_UDBA_REVAL
7245 + && !au_test_fs_remote(h_dentry->d_sb)) {
7247 + err = (h_dentry->d_parent->d_inode != h_dir);
7248 + } else if (udba != AuOpt_UDBA_NONE)
7249 + err = au_h_verify_dentry(h_dentry, h_parent, br);
7254 +/* ---------------------------------------------------------------------- */
7256 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
7259 + aufs_bindex_t new_bindex, bindex, bend, bwh, bdiropq;
7260 + struct au_hdentry tmp, *p, *q;
7261 + struct au_dinfo *dinfo;
7262 + struct super_block *sb;
7264 + DiMustWriteLock(dentry);
7266 + sb = dentry->d_sb;
7267 + dinfo = au_di(dentry);
7268 + bend = dinfo->di_bend;
7269 + bwh = dinfo->di_bwh;
7270 + bdiropq = dinfo->di_bdiropq;
7271 + p = dinfo->di_hdentry + dinfo->di_bstart;
7272 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++, p++) {
7273 + if (!p->hd_dentry)
7276 + new_bindex = au_br_index(sb, p->hd_id);
7277 + if (new_bindex == bindex)
7280 + if (dinfo->di_bwh == bindex)
7282 + if (dinfo->di_bdiropq == bindex)
7283 + bdiropq = new_bindex;
7284 + if (new_bindex < 0) {
7286 + p->hd_dentry = NULL;
7290 + /* swap two lower dentries, and loop again */
7291 + q = dinfo->di_hdentry + new_bindex;
7295 + if (tmp.hd_dentry) {
7301 + dinfo->di_bwh = -1;
7302 + if (bwh >= 0 && bwh <= au_sbend(sb) && au_sbr_whable(sb, bwh))
7303 + dinfo->di_bwh = bwh;
7305 + dinfo->di_bdiropq = -1;
7307 + && bdiropq <= au_sbend(sb)
7308 + && au_sbr_whable(sb, bdiropq))
7309 + dinfo->di_bdiropq = bdiropq;
7312 + dinfo->di_bstart = -1;
7313 + dinfo->di_bend = -1;
7314 + bend = au_dbend(parent);
7315 + p = dinfo->di_hdentry;
7316 + for (bindex = 0; bindex <= bend; bindex++, p++)
7317 + if (p->hd_dentry) {
7318 + dinfo->di_bstart = bindex;
7322 + if (dinfo->di_bstart >= 0) {
7323 + p = dinfo->di_hdentry + bend;
7324 + for (bindex = bend; bindex >= 0; bindex--, p--)
7325 + if (p->hd_dentry) {
7326 + dinfo->di_bend = bindex;
7335 +static void au_do_hide(struct dentry *dentry)
7337 + struct inode *inode;
7339 + inode = dentry->d_inode;
7341 + if (!S_ISDIR(inode->i_mode)) {
7342 + if (inode->i_nlink && !d_unhashed(dentry))
7343 + drop_nlink(inode);
7345 + clear_nlink(inode);
7346 + /* stop next lookup */
7347 + inode->i_flags |= S_DEAD;
7349 + smp_mb(); /* necessary? */
7354 +static int au_hide_children(struct dentry *parent)
7356 + int err, i, j, ndentry;
7357 + struct au_dcsub_pages dpages;
7358 + struct au_dpage *dpage;
7359 + struct dentry *dentry;
7361 + err = au_dpages_init(&dpages, GFP_NOFS);
7362 + if (unlikely(err))
7364 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
7365 + if (unlikely(err))
7368 + /* in reverse order */
7369 + for (i = dpages.ndpage - 1; i >= 0; i--) {
7370 + dpage = dpages.dpages + i;
7371 + ndentry = dpage->ndentry;
7372 + for (j = ndentry - 1; j >= 0; j--) {
7373 + dentry = dpage->dentries[j];
7374 + if (dentry != parent)
7375 + au_do_hide(dentry);
7380 + au_dpages_free(&dpages);
7385 +static void au_hide(struct dentry *dentry)
7388 + struct inode *inode;
7390 + AuDbgDentry(dentry);
7391 + inode = dentry->d_inode;
7392 + if (inode && S_ISDIR(inode->i_mode)) {
7393 + /* shrink_dcache_parent(dentry); */
7394 + err = au_hide_children(dentry);
7395 + if (unlikely(err))
7396 + AuIOErr("%pd, failed hiding children, ignored %d\n",
7399 + au_do_hide(dentry);
7403 + * By adding a dirty branch, a cached dentry may be affected in various ways.
7405 + * a dirty branch is added
7406 + * - on the top of layers
7407 + * - in the middle of layers
7408 + * - to the bottom of layers
7410 + * on the added branch there exists
7413 + * - a same named entry
7415 + * * negative --> positive
7416 + * * positive --> positive
7417 + * - type is unchanged
7418 + * - type is changed
7420 + * * negative --> negative
7421 + * * positive --> negative (rejected by au_br_del() for non-dir case)
7424 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
7425 + struct au_dinfo *tmp)
7428 + aufs_bindex_t bindex, bend;
7430 + struct dentry *dentry;
7431 + struct inode *inode;
7434 + struct au_hdentry *hd;
7435 + struct inode *inode, *h_inode;
7436 + struct dentry *h_dentry;
7439 + AuDebugOn(dinfo->di_bstart < 0);
7440 + orig_h.dentry = dinfo->di_hdentry[dinfo->di_bstart].hd_dentry;
7441 + orig_h.inode = orig_h.dentry->d_inode;
7444 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
7445 + memset(&tmp_h, 0, sizeof(tmp_h));
7446 + if (tmp->di_bstart >= 0) {
7447 + tmp_h.dentry = tmp->di_hdentry[tmp->di_bstart].hd_dentry;
7448 + tmp_h.inode = tmp_h.dentry->d_inode;
7450 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
7453 + inode = dentry->d_inode;
7454 + if (!orig_h.inode) {
7455 + AuDbg("nagative originally\n");
7461 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
7462 + AuDebugOn(dinfo->di_bdiropq != -1);
7464 + if (!tmp_h.inode) {
7465 + AuDbg("negative --> negative\n");
7466 + /* should have only one negative lower */
7467 + if (tmp->di_bstart >= 0
7468 + && tmp->di_bstart < dinfo->di_bstart) {
7469 + AuDebugOn(tmp->di_bstart != tmp->di_bend);
7470 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
7471 + au_set_h_dptr(dentry, dinfo->di_bstart, NULL);
7472 + au_di_cp(dinfo, tmp);
7473 + hd = tmp->di_hdentry + tmp->di_bstart;
7474 + au_set_h_dptr(dentry, tmp->di_bstart,
7475 + dget(hd->hd_dentry));
7477 + au_dbg_verify_dinode(dentry);
7479 + AuDbg("negative --> positive\n");
7481 + * similar to the behaviour of creating with bypassing
7483 + * unhash it in order to force an error in the
7484 + * succeeding create operation.
7485 + * we should not set S_DEAD here.
7488 + /* au_di_swap(tmp, dinfo); */
7489 + au_dbg_verify_dinode(dentry);
7492 + AuDbg("positive originally\n");
7493 + /* inode may be NULL */
7494 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
7495 + if (!tmp_h.inode) {
7496 + AuDbg("positive --> negative\n");
7497 + /* or bypassing aufs */
7499 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_bstart)
7500 + dinfo->di_bwh = tmp->di_bwh;
7502 + err = au_refresh_hinode_self(inode);
7503 + au_dbg_verify_dinode(dentry);
7504 + } else if (orig_h.mode == tmp_h.mode) {
7505 + AuDbg("positive --> positive, same type\n");
7506 + if (!S_ISDIR(orig_h.mode)
7507 + && dinfo->di_bstart > tmp->di_bstart) {
7509 + * similar to the behaviour of removing and
7514 + err = au_refresh_hinode_self(inode);
7515 + au_dbg_verify_dinode(dentry);
7517 + /* fill empty slots */
7518 + if (dinfo->di_bstart > tmp->di_bstart)
7519 + dinfo->di_bstart = tmp->di_bstart;
7520 + if (dinfo->di_bend < tmp->di_bend)
7521 + dinfo->di_bend = tmp->di_bend;
7522 + dinfo->di_bwh = tmp->di_bwh;
7523 + dinfo->di_bdiropq = tmp->di_bdiropq;
7524 + hd = tmp->di_hdentry;
7525 + bend = dinfo->di_bend;
7526 + for (bindex = tmp->di_bstart; bindex <= bend;
7528 + if (au_h_dptr(dentry, bindex))
7530 + h_dentry = hd[bindex].hd_dentry;
7533 + h_inode = h_dentry->d_inode;
7534 + AuDebugOn(!h_inode);
7535 + AuDebugOn(orig_h.mode
7536 + != (h_inode->i_mode
7538 + au_set_h_dptr(dentry, bindex,
7541 + err = au_refresh_hinode(inode, dentry);
7542 + au_dbg_verify_dinode(dentry);
7545 + AuDbg("positive --> positive, different type\n");
7546 + /* similar to the behaviour of removing and creating */
7549 + err = au_refresh_hinode_self(inode);
7550 + au_dbg_verify_dinode(dentry);
7558 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
7561 + unsigned int sigen;
7562 + struct au_dinfo *dinfo, *tmp;
7563 + struct super_block *sb;
7564 + struct inode *inode;
7566 + DiMustWriteLock(dentry);
7567 + AuDebugOn(IS_ROOT(dentry));
7568 + AuDebugOn(!parent->d_inode);
7570 + sb = dentry->d_sb;
7571 + inode = dentry->d_inode;
7572 + sigen = au_sigen(sb);
7573 + err = au_digen_test(parent, sigen);
7574 + if (unlikely(err))
7577 + dinfo = au_di(dentry);
7578 + err = au_di_realloc(dinfo, au_sbend(sb) + 1);
7579 + if (unlikely(err))
7581 + ebrange = au_dbrange_test(dentry);
7583 + ebrange = au_do_refresh_hdentry(dentry, parent);
7585 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
7586 + AuDebugOn(au_dbstart(dentry) < 0 && au_dbend(dentry) >= 0);
7588 + err = au_refresh_hinode_self(inode);
7589 + au_dbg_verify_dinode(dentry);
7591 + goto out_dgen; /* success */
7595 + /* temporary dinfo */
7596 + AuDbgDentry(dentry);
7598 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
7599 + if (unlikely(!tmp))
7601 + au_di_swap(tmp, dinfo);
7602 + /* returns the number of positive dentries */
7604 + * if current working dir is removed, it returns an error.
7605 + * but the dentry is legal.
7607 + err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0);
7608 + AuDbgDentry(dentry);
7609 + au_di_swap(tmp, dinfo);
7610 + if (err == -ENOENT)
7613 + /* compare/refresh by dinfo */
7614 + AuDbgDentry(dentry);
7615 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
7616 + au_dbg_verify_dinode(dentry);
7619 + au_rw_write_unlock(&tmp->di_rwsem);
7621 + if (unlikely(err))
7625 + au_update_digen(dentry);
7627 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
7628 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
7629 + AuDbgDentry(dentry);
7635 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
7636 + struct dentry *dentry, aufs_bindex_t bindex)
7641 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
7644 + AuDbg("b%d\n", bindex);
7646 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
7647 + * due to whiteout and branch permission.
7649 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
7650 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
7651 + /* it may return tri-state */
7652 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
7654 + if (unlikely(valid < 0))
7664 +/* todo: remove this */
7665 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
7666 + unsigned int flags, int do_udba)
7669 + umode_t mode, h_mode;
7670 + aufs_bindex_t bindex, btail, bstart, ibs, ibe;
7671 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
7672 + struct inode *h_inode, *h_cached_inode;
7673 + struct dentry *h_dentry;
7674 + struct qstr *name, *h_name;
7681 + unhashed = !!d_unhashed(dentry);
7682 + is_root = !!IS_ROOT(dentry);
7683 + name = &dentry->d_name;
7684 + tmpfile = au_di(dentry)->di_tmpfile;
7687 + * Theoretically, REVAL test should be unnecessary in case of
7689 + * But {fs,i}notify doesn't fire some necessary events,
7690 + * IN_ATTRIB for atime/nlink/pageio
7691 + * Let's do REVAL test too.
7693 + if (do_udba && inode) {
7694 + mode = (inode->i_mode & S_IFMT);
7695 + plus = (inode->i_nlink > 0);
7696 + ibs = au_ibstart(inode);
7697 + ibe = au_ibend(inode);
7700 + bstart = au_dbstart(dentry);
7702 + if (inode && S_ISDIR(inode->i_mode))
7703 + btail = au_dbtaildir(dentry);
7704 + for (bindex = bstart; bindex <= btail; bindex++) {
7705 + h_dentry = au_h_dptr(dentry, bindex);
7709 + AuDbg("b%d, %pd\n", bindex, h_dentry);
7710 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
7711 + spin_lock(&h_dentry->d_lock);
7712 + h_name = &h_dentry->d_name;
7713 + if (unlikely(do_udba
7716 + && (unhashed != !!d_unhashed(h_dentry)
7718 + && !au_qstreq(name, h_name))
7721 + && !(flags & LOOKUP_OPEN)
7722 + && (h_dentry->d_flags
7723 + & DCACHE_NFSFS_RENAMED)))
7727 + h_unhashed = d_unhashed(h_dentry);
7728 + spin_unlock(&h_dentry->d_lock);
7729 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
7730 + unhashed, h_unhashed, dentry, h_dentry);
7733 + spin_unlock(&h_dentry->d_lock);
7735 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
7736 + if (unlikely(err))
7737 + /* do not goto err, to keep the errno */
7740 + /* todo: plink too? */
7745 + h_inode = h_dentry->d_inode;
7746 + if (unlikely(!!inode != !!h_inode))
7751 + h_cached_inode = h_inode;
7753 + h_mode = (h_inode->i_mode & S_IFMT);
7754 + h_plus = (h_inode->i_nlink > 0);
7756 + if (inode && ibs <= bindex && bindex <= ibe)
7757 + h_cached_inode = au_h_iptr(inode, bindex);
7760 + if (unlikely(plus != h_plus && !tmpfile))
7763 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
7765 + && !IS_ROOT(h_dentry)
7766 + && unhashed != d_unhashed(h_dentry)))
7769 + if (unlikely(mode != h_mode
7770 + || h_cached_inode != h_inode))
7783 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
7784 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
7787 + struct dentry *parent;
7789 + if (!au_digen_test(dentry, sigen))
7792 + parent = dget_parent(dentry);
7793 + di_read_lock_parent(parent, AuLock_IR);
7794 + AuDebugOn(au_digen_test(parent, sigen));
7795 + au_dbg_verify_gen(parent, sigen);
7796 + err = au_refresh_dentry(dentry, parent);
7797 + di_read_unlock(parent, AuLock_IR);
7803 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
7806 + struct dentry *d, *parent;
7807 + struct inode *inode;
7809 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
7810 + return simple_reval_dpath(dentry, sigen);
7812 + /* slow loop, keep it simple and stupid */
7813 + /* cf: au_cpup_dirs() */
7816 + while (au_digen_test(dentry, sigen)) {
7820 + parent = dget_parent(d);
7821 + if (!au_digen_test(parent, sigen))
7826 + inode = d->d_inode;
7828 + di_write_lock_child2(d);
7830 + /* someone might update our dentry while we were sleeping */
7831 + if (au_digen_test(d, sigen)) {
7833 + * todo: consolidate with simple_reval_dpath(),
7834 + * do_refresh() and au_reval_for_attr().
7836 + di_read_lock_parent(parent, AuLock_IR);
7837 + err = au_refresh_dentry(d, parent);
7838 + di_read_unlock(parent, AuLock_IR);
7842 + di_write_unlock(d);
7844 + if (unlikely(err))
7852 + * if valid returns 1, otherwise 0.
7854 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
7857 + unsigned int sigen;
7858 + unsigned char do_udba;
7859 + struct super_block *sb;
7860 + struct inode *inode;
7862 + /* todo: support rcu-walk? */
7863 + if (flags & LOOKUP_RCU)
7867 + if (unlikely(!au_di(dentry)))
7870 + inode = dentry->d_inode;
7871 + if (inode && is_bad_inode(inode))
7875 + sb = dentry->d_sb;
7878 + * i_mutex of parent dir may be held,
7879 + * but we should not return 'invalid' due to busy.
7881 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
7882 + if (unlikely(err)) {
7887 + if (unlikely(au_dbrange_test(dentry))) {
7893 + sigen = au_sigen(sb);
7894 + if (au_digen_test(dentry, sigen)) {
7895 + AuDebugOn(IS_ROOT(dentry));
7896 + err = au_reval_dpath(dentry, sigen);
7897 + if (unlikely(err)) {
7902 + di_downgrade_lock(dentry, AuLock_IR);
7905 + if (!(flags & LOOKUP_OPEN)
7907 + && !(inode->i_state && I_LINKABLE)
7908 + && (IS_DEADDIR(inode) || !inode->i_nlink))
7911 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
7912 + if (do_udba && inode) {
7913 + aufs_bindex_t bstart = au_ibstart(inode);
7914 + struct inode *h_inode;
7916 + if (bstart >= 0) {
7917 + h_inode = au_h_iptr(inode, bstart);
7918 + if (h_inode && au_test_higen(inode, h_inode))
7923 + err = h_d_revalidate(dentry, inode, flags, do_udba);
7924 + if (unlikely(!err && do_udba && au_dbstart(dentry) < 0)) {
7926 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
7932 + di_downgrade_lock(dentry, AuLock_IR);
7934 + aufs_read_unlock(dentry, AuLock_IR);
7939 + AuDbg("%pd invalid, %d\n", dentry, valid);
7945 +static void aufs_d_release(struct dentry *dentry)
7947 + if (au_di(dentry)) {
7948 + au_di_fin(dentry);
7949 + au_hn_di_reinit(dentry);
7953 +const struct dentry_operations aufs_dop = {
7954 + .d_revalidate = aufs_d_revalidate,
7955 + .d_weak_revalidate = aufs_d_revalidate,
7956 + .d_release = aufs_d_release
7958 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
7959 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
7960 +++ linux/fs/aufs/dentry.h 2014-06-24 00:14:06.779385790 +0200
7963 + * Copyright (C) 2005-2014 Junjiro R. Okajima
7965 + * This program, aufs is free software; you can redistribute it and/or modify
7966 + * it under the terms of the GNU General Public License as published by
7967 + * the Free Software Foundation; either version 2 of the License, or
7968 + * (at your option) any later version.
7970 + * This program is distributed in the hope that it will be useful,
7971 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7972 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7973 + * GNU General Public License for more details.
7975 + * You should have received a copy of the GNU General Public License
7976 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7980 + * lookup and dentry operations
7983 +#ifndef __AUFS_DENTRY_H__
7984 +#define __AUFS_DENTRY_H__
7988 +#include <linux/dcache.h>
7991 +struct au_hdentry {
7992 + struct dentry *hd_dentry;
7993 + aufs_bindex_t hd_id;
7997 + atomic_t di_generation;
7999 + struct au_rwsem di_rwsem;
8000 + aufs_bindex_t di_bstart, di_bend, di_bwh, di_bdiropq;
8001 + unsigned char di_tmpfile; /* to allow the different name */
8002 + struct au_hdentry *di_hdentry;
8003 +} ____cacheline_aligned_in_smp;
8005 +/* ---------------------------------------------------------------------- */
8008 +extern const struct dentry_operations aufs_dop;
8010 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent,
8011 + struct au_branch *br);
8012 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8013 + struct dentry *h_parent, struct au_branch *br);
8015 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type);
8016 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
8017 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
8018 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
8021 +void au_di_init_once(void *_di);
8022 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
8023 +void au_di_free(struct au_dinfo *dinfo);
8024 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
8025 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
8026 +int au_di_init(struct dentry *dentry);
8027 +void au_di_fin(struct dentry *dentry);
8028 +int au_di_realloc(struct au_dinfo *dinfo, int nbr);
8030 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
8031 +void di_read_unlock(struct dentry *d, int flags);
8032 +void di_downgrade_lock(struct dentry *d, int flags);
8033 +void di_write_lock(struct dentry *d, unsigned int lsc);
8034 +void di_write_unlock(struct dentry *d);
8035 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
8036 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
8037 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
8039 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
8040 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
8041 +aufs_bindex_t au_dbtail(struct dentry *dentry);
8042 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
8044 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
8045 + struct dentry *h_dentry);
8046 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
8047 +int au_dbrange_test(struct dentry *dentry);
8048 +void au_update_digen(struct dentry *dentry);
8049 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
8050 +void au_update_dbstart(struct dentry *dentry);
8051 +void au_update_dbend(struct dentry *dentry);
8052 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
8054 +/* ---------------------------------------------------------------------- */
8056 +static inline struct au_dinfo *au_di(struct dentry *dentry)
8058 + return dentry->d_fsdata;
8061 +/* ---------------------------------------------------------------------- */
8063 +/* lock subclass for dinfo */
8065 + AuLsc_DI_CHILD, /* child first */
8066 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
8067 + AuLsc_DI_CHILD3, /* copyup dirs */
8071 + AuLsc_DI_TMP /* temp for replacing dinfo */
8075 + * di_read_lock_child, di_write_lock_child,
8076 + * di_read_lock_child2, di_write_lock_child2,
8077 + * di_read_lock_child3, di_write_lock_child3,
8078 + * di_read_lock_parent, di_write_lock_parent,
8079 + * di_read_lock_parent2, di_write_lock_parent2,
8080 + * di_read_lock_parent3, di_write_lock_parent3,
8082 +#define AuReadLockFunc(name, lsc) \
8083 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
8084 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
8086 +#define AuWriteLockFunc(name, lsc) \
8087 +static inline void di_write_lock_##name(struct dentry *d) \
8088 +{ di_write_lock(d, AuLsc_DI_##lsc); }
8090 +#define AuRWLockFuncs(name, lsc) \
8091 + AuReadLockFunc(name, lsc) \
8092 + AuWriteLockFunc(name, lsc)
8094 +AuRWLockFuncs(child, CHILD);
8095 +AuRWLockFuncs(child2, CHILD2);
8096 +AuRWLockFuncs(child3, CHILD3);
8097 +AuRWLockFuncs(parent, PARENT);
8098 +AuRWLockFuncs(parent2, PARENT2);
8099 +AuRWLockFuncs(parent3, PARENT3);
8101 +#undef AuReadLockFunc
8102 +#undef AuWriteLockFunc
8103 +#undef AuRWLockFuncs
8105 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
8106 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
8107 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
8109 +/* ---------------------------------------------------------------------- */
8111 +/* todo: memory barrier? */
8112 +static inline unsigned int au_digen(struct dentry *d)
8114 + return atomic_read(&au_di(d)->di_generation);
8117 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
8119 + hdentry->hd_dentry = NULL;
8122 +static inline void au_hdput(struct au_hdentry *hd)
8125 + dput(hd->hd_dentry);
8128 +static inline aufs_bindex_t au_dbstart(struct dentry *dentry)
8130 + DiMustAnyLock(dentry);
8131 + return au_di(dentry)->di_bstart;
8134 +static inline aufs_bindex_t au_dbend(struct dentry *dentry)
8136 + DiMustAnyLock(dentry);
8137 + return au_di(dentry)->di_bend;
8140 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
8142 + DiMustAnyLock(dentry);
8143 + return au_di(dentry)->di_bwh;
8146 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
8148 + DiMustAnyLock(dentry);
8149 + return au_di(dentry)->di_bdiropq;
8152 +/* todo: hard/soft set? */
8153 +static inline void au_set_dbstart(struct dentry *dentry, aufs_bindex_t bindex)
8155 + DiMustWriteLock(dentry);
8156 + au_di(dentry)->di_bstart = bindex;
8159 +static inline void au_set_dbend(struct dentry *dentry, aufs_bindex_t bindex)
8161 + DiMustWriteLock(dentry);
8162 + au_di(dentry)->di_bend = bindex;
8165 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
8167 + DiMustWriteLock(dentry);
8168 + /* dbwh can be outside of bstart - bend range */
8169 + au_di(dentry)->di_bwh = bindex;
8172 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
8174 + DiMustWriteLock(dentry);
8175 + au_di(dentry)->di_bdiropq = bindex;
8178 +/* ---------------------------------------------------------------------- */
8180 +#ifdef CONFIG_AUFS_HNOTIFY
8181 +static inline void au_digen_dec(struct dentry *d)
8183 + atomic_dec(&au_di(d)->di_generation);
8186 +static inline void au_hn_di_reinit(struct dentry *dentry)
8188 + dentry->d_fsdata = NULL;
8191 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
8192 +#endif /* CONFIG_AUFS_HNOTIFY */
8194 +#endif /* __KERNEL__ */
8195 +#endif /* __AUFS_DENTRY_H__ */
8196 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
8197 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
8198 +++ linux/fs/aufs/dinfo.c 2014-06-24 00:14:06.779385790 +0200
8201 + * Copyright (C) 2005-2014 Junjiro R. Okajima
8203 + * This program, aufs is free software; you can redistribute it and/or modify
8204 + * it under the terms of the GNU General Public License as published by
8205 + * the Free Software Foundation; either version 2 of the License, or
8206 + * (at your option) any later version.
8208 + * This program is distributed in the hope that it will be useful,
8209 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8210 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8211 + * GNU General Public License for more details.
8213 + * You should have received a copy of the GNU General Public License
8214 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8218 + * dentry private data
8223 +void au_di_init_once(void *_dinfo)
8225 + struct au_dinfo *dinfo = _dinfo;
8226 + static struct lock_class_key aufs_di;
8228 + au_rw_init(&dinfo->di_rwsem);
8229 + au_rw_class(&dinfo->di_rwsem, &aufs_di);
8232 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
8234 + struct au_dinfo *dinfo;
8237 + dinfo = au_cache_alloc_dinfo();
8238 + if (unlikely(!dinfo))
8241 + nbr = au_sbend(sb) + 1;
8244 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
8245 + if (dinfo->di_hdentry) {
8246 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
8247 + dinfo->di_bstart = -1;
8248 + dinfo->di_bend = -1;
8249 + dinfo->di_bwh = -1;
8250 + dinfo->di_bdiropq = -1;
8251 + dinfo->di_tmpfile = 0;
8252 + for (i = 0; i < nbr; i++)
8253 + dinfo->di_hdentry[i].hd_id = -1;
8257 + au_cache_free_dinfo(dinfo);
8264 +void au_di_free(struct au_dinfo *dinfo)
8266 + struct au_hdentry *p;
8267 + aufs_bindex_t bend, bindex;
8269 + /* dentry may not be revalidated */
8270 + bindex = dinfo->di_bstart;
8271 + if (bindex >= 0) {
8272 + bend = dinfo->di_bend;
8273 + p = dinfo->di_hdentry + bindex;
8274 + while (bindex++ <= bend)
8277 + kfree(dinfo->di_hdentry);
8278 + au_cache_free_dinfo(dinfo);
8281 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
8283 + struct au_hdentry *p;
8286 + AuRwMustWriteLock(&a->di_rwsem);
8287 + AuRwMustWriteLock(&b->di_rwsem);
8289 +#define DiSwap(v, name) \
8291 + v = a->di_##name; \
8292 + a->di_##name = b->di_##name; \
8293 + b->di_##name = v; \
8296 + DiSwap(p, hdentry);
8297 + DiSwap(bi, bstart);
8300 + DiSwap(bi, bdiropq);
8306 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
8308 + AuRwMustWriteLock(&dst->di_rwsem);
8309 + AuRwMustWriteLock(&src->di_rwsem);
8311 + dst->di_bstart = src->di_bstart;
8312 + dst->di_bend = src->di_bend;
8313 + dst->di_bwh = src->di_bwh;
8314 + dst->di_bdiropq = src->di_bdiropq;
8318 +int au_di_init(struct dentry *dentry)
8321 + struct super_block *sb;
8322 + struct au_dinfo *dinfo;
8325 + sb = dentry->d_sb;
8326 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
8328 + atomic_set(&dinfo->di_generation, au_sigen(sb));
8329 + /* smp_mb(); */ /* atomic_set */
8330 + dentry->d_fsdata = dinfo;
8337 +void au_di_fin(struct dentry *dentry)
8339 + struct au_dinfo *dinfo;
8341 + dinfo = au_di(dentry);
8342 + AuRwDestroy(&dinfo->di_rwsem);
8343 + au_di_free(dinfo);
8346 +int au_di_realloc(struct au_dinfo *dinfo, int nbr)
8349 + struct au_hdentry *hdp;
8351 + AuRwMustWriteLock(&dinfo->di_rwsem);
8354 + sz = sizeof(*hdp) * (dinfo->di_bend + 1);
8356 + sz = sizeof(*hdp);
8357 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS);
8359 + dinfo->di_hdentry = hdp;
8366 +/* ---------------------------------------------------------------------- */
8368 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
8371 + case AuLsc_DI_CHILD:
8372 + ii_write_lock_child(inode);
8374 + case AuLsc_DI_CHILD2:
8375 + ii_write_lock_child2(inode);
8377 + case AuLsc_DI_CHILD3:
8378 + ii_write_lock_child3(inode);
8380 + case AuLsc_DI_PARENT:
8381 + ii_write_lock_parent(inode);
8383 + case AuLsc_DI_PARENT2:
8384 + ii_write_lock_parent2(inode);
8386 + case AuLsc_DI_PARENT3:
8387 + ii_write_lock_parent3(inode);
8394 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
8397 + case AuLsc_DI_CHILD:
8398 + ii_read_lock_child(inode);
8400 + case AuLsc_DI_CHILD2:
8401 + ii_read_lock_child2(inode);
8403 + case AuLsc_DI_CHILD3:
8404 + ii_read_lock_child3(inode);
8406 + case AuLsc_DI_PARENT:
8407 + ii_read_lock_parent(inode);
8409 + case AuLsc_DI_PARENT2:
8410 + ii_read_lock_parent2(inode);
8412 + case AuLsc_DI_PARENT3:
8413 + ii_read_lock_parent3(inode);
8420 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
8422 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
8424 + if (au_ftest_lock(flags, IW))
8425 + do_ii_write_lock(d->d_inode, lsc);
8426 + else if (au_ftest_lock(flags, IR))
8427 + do_ii_read_lock(d->d_inode, lsc);
8431 +void di_read_unlock(struct dentry *d, int flags)
8434 + if (au_ftest_lock(flags, IW)) {
8435 + au_dbg_verify_dinode(d);
8436 + ii_write_unlock(d->d_inode);
8437 + } else if (au_ftest_lock(flags, IR)) {
8438 + au_dbg_verify_dinode(d);
8439 + ii_read_unlock(d->d_inode);
8442 + au_rw_read_unlock(&au_di(d)->di_rwsem);
8445 +void di_downgrade_lock(struct dentry *d, int flags)
8447 + if (d->d_inode && au_ftest_lock(flags, IR))
8448 + ii_downgrade_lock(d->d_inode);
8449 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
8452 +void di_write_lock(struct dentry *d, unsigned int lsc)
8454 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
8456 + do_ii_write_lock(d->d_inode, lsc);
8459 +void di_write_unlock(struct dentry *d)
8461 + au_dbg_verify_dinode(d);
8463 + ii_write_unlock(d->d_inode);
8464 + au_rw_write_unlock(&au_di(d)->di_rwsem);
8467 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
8469 + AuDebugOn(d1 == d2
8470 + || d1->d_inode == d2->d_inode
8471 + || d1->d_sb != d2->d_sb);
8473 + if (isdir && au_test_subdir(d1, d2)) {
8474 + di_write_lock_child(d1);
8475 + di_write_lock_child2(d2);
8477 + /* there should be no races */
8478 + di_write_lock_child(d2);
8479 + di_write_lock_child2(d1);
8483 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
8485 + AuDebugOn(d1 == d2
8486 + || d1->d_inode == d2->d_inode
8487 + || d1->d_sb != d2->d_sb);
8489 + if (isdir && au_test_subdir(d1, d2)) {
8490 + di_write_lock_parent(d1);
8491 + di_write_lock_parent2(d2);
8493 + /* there should be no races */
8494 + di_write_lock_parent(d2);
8495 + di_write_lock_parent2(d1);
8499 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
8501 + di_write_unlock(d1);
8502 + if (d1->d_inode == d2->d_inode)
8503 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
8505 + di_write_unlock(d2);
8508 +/* ---------------------------------------------------------------------- */
8510 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
8514 + DiMustAnyLock(dentry);
8516 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
8518 + AuDebugOn(bindex < 0);
8519 + d = au_di(dentry)->di_hdentry[0 + bindex].hd_dentry;
8520 + AuDebugOn(d && d_count(d) <= 0);
8525 + * extended version of au_h_dptr().
8526 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
8529 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
8531 + struct dentry *h_dentry;
8532 + struct inode *inode, *h_inode;
8534 + inode = dentry->d_inode;
8535 + AuDebugOn(!inode);
8538 + if (au_dbstart(dentry) <= bindex
8539 + && bindex <= au_dbend(dentry))
8540 + h_dentry = au_h_dptr(dentry, bindex);
8541 + if (h_dentry && !au_d_linkable(h_dentry)) {
8543 + goto out; /* success */
8546 + AuDebugOn(bindex < au_ibstart(inode));
8547 + AuDebugOn(au_ibend(inode) < bindex);
8548 + h_inode = au_h_iptr(inode, bindex);
8549 + h_dentry = d_find_alias(h_inode);
8551 + if (!IS_ERR(h_dentry)) {
8552 + if (!au_d_linkable(h_dentry))
8553 + goto out; /* success */
8559 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
8560 + h_dentry = au_plink_lkup(inode, bindex);
8561 + AuDebugOn(!h_dentry);
8562 + if (!IS_ERR(h_dentry)) {
8563 + if (!au_d_hashed_positive(h_dentry))
8564 + goto out; /* success */
8571 + AuDbgDentry(h_dentry);
8575 +aufs_bindex_t au_dbtail(struct dentry *dentry)
8577 + aufs_bindex_t bend, bwh;
8579 + bend = au_dbend(dentry);
8581 + bwh = au_dbwh(dentry);
8584 + if (0 < bwh && bwh < bend)
8590 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
8592 + aufs_bindex_t bend, bopq;
8594 + bend = au_dbtail(dentry);
8596 + bopq = au_dbdiropq(dentry);
8597 + if (0 <= bopq && bopq < bend)
8603 +/* ---------------------------------------------------------------------- */
8605 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
8606 + struct dentry *h_dentry)
8608 + struct au_hdentry *hd = au_di(dentry)->di_hdentry + bindex;
8609 + struct au_branch *br;
8611 + DiMustWriteLock(dentry);
8614 + hd->hd_dentry = h_dentry;
8616 + br = au_sbr(dentry->d_sb, bindex);
8617 + hd->hd_id = br->br_id;
8621 +int au_dbrange_test(struct dentry *dentry)
8624 + aufs_bindex_t bstart, bend;
8627 + bstart = au_dbstart(dentry);
8628 + bend = au_dbend(dentry);
8630 + AuDebugOn(bend < 0 && bstart > bend);
8633 + AuDebugOn(bend >= 0);
8639 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
8644 + if (unlikely(au_digen(dentry) != sigen
8645 + || au_iigen_test(dentry->d_inode, sigen)))
8651 +void au_update_digen(struct dentry *dentry)
8653 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
8654 + /* smp_mb(); */ /* atomic_set */
8657 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
8659 + struct au_dinfo *dinfo;
8660 + struct dentry *h_d;
8661 + struct au_hdentry *hdp;
8663 + DiMustWriteLock(dentry);
8665 + dinfo = au_di(dentry);
8666 + if (!dinfo || dinfo->di_bstart < 0)
8669 + hdp = dinfo->di_hdentry;
8670 + if (do_put_zero) {
8671 + aufs_bindex_t bindex, bend;
8673 + bend = dinfo->di_bend;
8674 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++) {
8675 + h_d = hdp[0 + bindex].hd_dentry;
8676 + if (h_d && !h_d->d_inode)
8677 + au_set_h_dptr(dentry, bindex, NULL);
8681 + dinfo->di_bstart = -1;
8682 + while (++dinfo->di_bstart <= dinfo->di_bend)
8683 + if (hdp[0 + dinfo->di_bstart].hd_dentry)
8685 + if (dinfo->di_bstart > dinfo->di_bend) {
8686 + dinfo->di_bstart = -1;
8687 + dinfo->di_bend = -1;
8692 + while (0 <= --dinfo->di_bend)
8693 + if (hdp[0 + dinfo->di_bend].hd_dentry)
8695 + AuDebugOn(dinfo->di_bstart > dinfo->di_bend || dinfo->di_bend < 0);
8698 +void au_update_dbstart(struct dentry *dentry)
8700 + aufs_bindex_t bindex, bend;
8701 + struct dentry *h_dentry;
8703 + bend = au_dbend(dentry);
8704 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
8705 + h_dentry = au_h_dptr(dentry, bindex);
8708 + if (h_dentry->d_inode) {
8709 + au_set_dbstart(dentry, bindex);
8712 + au_set_h_dptr(dentry, bindex, NULL);
8716 +void au_update_dbend(struct dentry *dentry)
8718 + aufs_bindex_t bindex, bstart;
8719 + struct dentry *h_dentry;
8721 + bstart = au_dbstart(dentry);
8722 + for (bindex = au_dbend(dentry); bindex >= bstart; bindex--) {
8723 + h_dentry = au_h_dptr(dentry, bindex);
8726 + if (h_dentry->d_inode) {
8727 + au_set_dbend(dentry, bindex);
8730 + au_set_h_dptr(dentry, bindex, NULL);
8734 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
8736 + aufs_bindex_t bindex, bend;
8738 + bend = au_dbend(dentry);
8739 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++)
8740 + if (au_h_dptr(dentry, bindex) == h_dentry)
8744 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
8745 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
8746 +++ linux/fs/aufs/dir.c 2014-06-24 00:14:06.779385790 +0200
8749 + * Copyright (C) 2005-2014 Junjiro R. Okajima
8751 + * This program, aufs is free software; you can redistribute it and/or modify
8752 + * it under the terms of the GNU General Public License as published by
8753 + * the Free Software Foundation; either version 2 of the License, or
8754 + * (at your option) any later version.
8756 + * This program is distributed in the hope that it will be useful,
8757 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8758 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8759 + * GNU General Public License for more details.
8761 + * You should have received a copy of the GNU General Public License
8762 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8766 + * directory operations
8769 +#include <linux/fs_stack.h>
8772 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
8774 + unsigned int nlink;
8776 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
8778 + nlink = dir->i_nlink;
8779 + nlink += h_dir->i_nlink - 2;
8780 + if (h_dir->i_nlink < 2)
8782 + smp_mb(); /* for i_nlink */
8783 + /* 0 can happen in revaliding */
8784 + set_nlink(dir, nlink);
8787 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
8789 + unsigned int nlink;
8791 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
8793 + nlink = dir->i_nlink;
8794 + nlink -= h_dir->i_nlink - 2;
8795 + if (h_dir->i_nlink < 2)
8797 + smp_mb(); /* for i_nlink */
8798 + /* nlink == 0 means the branch-fs is broken */
8799 + set_nlink(dir, nlink);
8802 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
8805 + aufs_bindex_t bindex, bend;
8806 + struct file *h_file;
8807 + struct dentry *h_dentry;
8811 + AuDebugOn(!file_inode(file));
8812 + AuDebugOn(!S_ISDIR(file_inode(file)->i_mode));
8814 + bend = au_fbend_dir(file);
8815 + for (bindex = au_fbstart(file);
8816 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
8818 + h_file = au_hf_dir(file, bindex);
8819 + if (h_file && file_inode(h_file))
8820 + sz += vfsub_f_size_read(h_file);
8823 + AuDebugOn(!dentry);
8824 + AuDebugOn(!dentry->d_inode);
8825 + AuDebugOn(!S_ISDIR(dentry->d_inode->i_mode));
8827 + bend = au_dbtaildir(dentry);
8828 + for (bindex = au_dbstart(dentry);
8829 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
8831 + h_dentry = au_h_dptr(dentry, bindex);
8832 + if (h_dentry && h_dentry->d_inode)
8833 + sz += i_size_read(h_dentry->d_inode);
8836 + if (sz < KMALLOC_MAX_SIZE)
8837 + sz = roundup_pow_of_two(sz);
8838 + if (sz > KMALLOC_MAX_SIZE)
8839 + sz = KMALLOC_MAX_SIZE;
8840 + else if (sz < NAME_MAX) {
8841 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
8842 + sz = AUFS_RDBLK_DEF;
8847 +/* ---------------------------------------------------------------------- */
8849 +static int reopen_dir(struct file *file)
8852 + unsigned int flags;
8853 + aufs_bindex_t bindex, btail, bstart;
8854 + struct dentry *dentry, *h_dentry;
8855 + struct file *h_file;
8857 + /* open all lower dirs */
8858 + dentry = file->f_dentry;
8859 + bstart = au_dbstart(dentry);
8860 + for (bindex = au_fbstart(file); bindex < bstart; bindex++)
8861 + au_set_h_fptr(file, bindex, NULL);
8862 + au_set_fbstart(file, bstart);
8864 + btail = au_dbtaildir(dentry);
8865 + for (bindex = au_fbend_dir(file); btail < bindex; bindex--)
8866 + au_set_h_fptr(file, bindex, NULL);
8867 + au_set_fbend_dir(file, btail);
8869 + flags = vfsub_file_flags(file);
8870 + for (bindex = bstart; bindex <= btail; bindex++) {
8871 + h_dentry = au_h_dptr(dentry, bindex);
8874 + h_file = au_hf_dir(file, bindex);
8878 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
8879 + err = PTR_ERR(h_file);
8880 + if (IS_ERR(h_file))
8881 + goto out; /* close all? */
8882 + au_set_h_fptr(file, bindex, h_file);
8884 + au_update_figen(file);
8885 + /* todo: necessary? */
8886 + /* file->f_ra = h_file->f_ra; */
8893 +static int do_open_dir(struct file *file, int flags)
8896 + aufs_bindex_t bindex, btail;
8897 + struct dentry *dentry, *h_dentry;
8898 + struct file *h_file;
8900 + FiMustWriteLock(file);
8903 + dentry = file->f_dentry;
8904 + file->f_version = dentry->d_inode->i_version;
8905 + bindex = au_dbstart(dentry);
8906 + au_set_fbstart(file, bindex);
8907 + btail = au_dbtaildir(dentry);
8908 + au_set_fbend_dir(file, btail);
8909 + for (; !err && bindex <= btail; bindex++) {
8910 + h_dentry = au_h_dptr(dentry, bindex);
8914 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
8915 + if (IS_ERR(h_file)) {
8916 + err = PTR_ERR(h_file);
8919 + au_set_h_fptr(file, bindex, h_file);
8921 + au_update_figen(file);
8922 + /* todo: necessary? */
8923 + /* file->f_ra = h_file->f_ra; */
8925 + return 0; /* success */
8928 + for (bindex = au_fbstart(file); bindex <= btail; bindex++)
8929 + au_set_h_fptr(file, bindex, NULL);
8930 + au_set_fbstart(file, -1);
8931 + au_set_fbend_dir(file, -1);
8936 +static int aufs_open_dir(struct inode *inode __maybe_unused,
8937 + struct file *file)
8940 + struct super_block *sb;
8941 + struct au_fidir *fidir;
8944 + sb = file->f_dentry->d_sb;
8945 + si_read_lock(sb, AuLock_FLUSH);
8946 + fidir = au_fidir_alloc(sb);
8948 + err = au_do_open(file, do_open_dir, fidir);
8949 + if (unlikely(err))
8952 + si_read_unlock(sb);
8956 +static int aufs_release_dir(struct inode *inode __maybe_unused,
8957 + struct file *file)
8959 + struct au_vdir *vdir_cache;
8960 + struct au_finfo *finfo;
8961 + struct au_fidir *fidir;
8962 + aufs_bindex_t bindex, bend;
8964 + finfo = au_fi(file);
8965 + fidir = finfo->fi_hdir;
8967 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
8969 + au_vdir_free(vdir_cache);
8971 + bindex = finfo->fi_btop;
8972 + if (bindex >= 0) {
8974 + * calls fput() instead of filp_close(),
8975 + * since no dnotify or lock for the lower file.
8977 + bend = fidir->fd_bbot;
8978 + for (; bindex <= bend; bindex++)
8979 + au_set_h_fptr(file, bindex, NULL);
8982 + finfo->fi_hdir = NULL;
8984 + au_finfo_fin(file);
8988 +/* ---------------------------------------------------------------------- */
8990 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
8993 + aufs_bindex_t bindex, bend;
8994 + struct file *h_file;
8997 + bend = au_fbend_dir(file);
8998 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
8999 + h_file = au_hf_dir(file, bindex);
9001 + err = vfsub_flush(h_file, id);
9006 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
9008 + return au_do_flush(file, id, au_do_flush_dir);
9011 +/* ---------------------------------------------------------------------- */
9013 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
9016 + aufs_bindex_t bend, bindex;
9017 + struct inode *inode;
9018 + struct super_block *sb;
9021 + sb = dentry->d_sb;
9022 + inode = dentry->d_inode;
9024 + bend = au_dbend(dentry);
9025 + for (bindex = au_dbstart(dentry); !err && bindex <= bend; bindex++) {
9026 + struct path h_path;
9028 + if (au_test_ro(sb, bindex, inode))
9030 + h_path.dentry = au_h_dptr(dentry, bindex);
9031 + if (!h_path.dentry)
9034 + h_path.mnt = au_sbr_mnt(sb, bindex);
9035 + err = vfsub_fsync(NULL, &h_path, datasync);
9041 +static int au_do_fsync_dir(struct file *file, int datasync)
9044 + aufs_bindex_t bend, bindex;
9045 + struct file *h_file;
9046 + struct super_block *sb;
9047 + struct inode *inode;
9049 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
9050 + if (unlikely(err))
9053 + sb = file->f_dentry->d_sb;
9054 + inode = file_inode(file);
9055 + bend = au_fbend_dir(file);
9056 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
9057 + h_file = au_hf_dir(file, bindex);
9058 + if (!h_file || au_test_ro(sb, bindex, inode))
9061 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
9069 + * @file may be NULL
9071 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
9075 + struct dentry *dentry;
9076 + struct super_block *sb;
9077 + struct mutex *mtx;
9080 + dentry = file->f_dentry;
9081 + mtx = &dentry->d_inode->i_mutex;
9083 + sb = dentry->d_sb;
9084 + si_noflush_read_lock(sb);
9086 + err = au_do_fsync_dir(file, datasync);
9088 + di_write_lock_child(dentry);
9089 + err = au_do_fsync_dir_no_file(dentry, datasync);
9091 + au_cpup_attr_timesizes(dentry->d_inode);
9092 + di_write_unlock(dentry);
9094 + fi_write_unlock(file);
9096 + si_read_unlock(sb);
9097 + mutex_unlock(mtx);
9101 +/* ---------------------------------------------------------------------- */
9103 +static int aufs_iterate(struct file *file, struct dir_context *ctx)
9106 + struct dentry *dentry;
9107 + struct inode *inode, *h_inode;
9108 + struct super_block *sb;
9110 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
9112 + dentry = file->f_dentry;
9113 + inode = dentry->d_inode;
9116 + sb = dentry->d_sb;
9117 + si_read_lock(sb, AuLock_FLUSH);
9118 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
9119 + if (unlikely(err))
9121 + err = au_alive_dir(dentry);
9123 + err = au_vdir_init(file);
9124 + di_downgrade_lock(dentry, AuLock_IR);
9125 + if (unlikely(err))
9128 + h_inode = au_h_iptr(inode, au_ibstart(inode));
9129 + if (!au_test_nfsd()) {
9130 + err = au_vdir_fill_de(file, ctx);
9131 + fsstack_copy_attr_atime(inode, h_inode);
9134 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
9135 + * encode_fh() and others.
9137 + atomic_inc(&h_inode->i_count);
9138 + di_read_unlock(dentry, AuLock_IR);
9139 + si_read_unlock(sb);
9140 + err = au_vdir_fill_de(file, ctx);
9141 + fsstack_copy_attr_atime(inode, h_inode);
9142 + fi_write_unlock(file);
9150 + di_read_unlock(dentry, AuLock_IR);
9151 + fi_write_unlock(file);
9153 + si_read_unlock(sb);
9157 +/* ---------------------------------------------------------------------- */
9159 +#define AuTestEmpty_WHONLY 1
9160 +#define AuTestEmpty_CALLED (1 << 1)
9161 +#define AuTestEmpty_SHWH (1 << 2)
9162 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
9163 +#define au_fset_testempty(flags, name) \
9164 + do { (flags) |= AuTestEmpty_##name; } while (0)
9165 +#define au_fclr_testempty(flags, name) \
9166 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
9168 +#ifndef CONFIG_AUFS_SHWH
9169 +#undef AuTestEmpty_SHWH
9170 +#define AuTestEmpty_SHWH 0
9173 +struct test_empty_arg {
9174 + struct dir_context ctx;
9175 + struct au_nhash *whlist;
9176 + unsigned int flags;
9178 + aufs_bindex_t bindex;
9181 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
9182 + int namelen, loff_t offset __maybe_unused, u64 ino,
9183 + unsigned int d_type)
9185 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
9187 + char *name = (void *)__name;
9190 + au_fset_testempty(arg->flags, CALLED);
9192 + if (name[0] == '.'
9193 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
9194 + goto out; /* success */
9196 + if (namelen <= AUFS_WH_PFX_LEN
9197 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
9198 + if (au_ftest_testempty(arg->flags, WHONLY)
9199 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
9200 + arg->err = -ENOTEMPTY;
9204 + name += AUFS_WH_PFX_LEN;
9205 + namelen -= AUFS_WH_PFX_LEN;
9206 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
9207 + arg->err = au_nhash_append_wh
9208 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
9209 + au_ftest_testempty(arg->flags, SHWH));
9213 + AuTraceErr(arg->err);
9217 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
9220 + struct file *h_file;
9222 + h_file = au_h_open(dentry, arg->bindex,
9223 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
9224 + /*file*/NULL, /*force_wr*/0);
9225 + err = PTR_ERR(h_file);
9226 + if (IS_ERR(h_file))
9230 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
9231 + && !file_inode(h_file)->i_nlink)
9236 + au_fclr_testempty(arg->flags, CALLED);
9238 + err = vfsub_iterate_dir(h_file, &arg->ctx);
9241 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
9245 + au_sbr_put(dentry->d_sb, arg->bindex);
9250 +struct do_test_empty_args {
9252 + struct dentry *dentry;
9253 + struct test_empty_arg *arg;
9256 +static void call_do_test_empty(void *args)
9258 + struct do_test_empty_args *a = args;
9259 + *a->errp = do_test_empty(a->dentry, a->arg);
9262 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
9265 + struct dentry *h_dentry;
9266 + struct inode *h_inode;
9268 + h_dentry = au_h_dptr(dentry, arg->bindex);
9269 + h_inode = h_dentry->d_inode;
9270 + /* todo: i_mode changes anytime? */
9271 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
9272 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
9273 + mutex_unlock(&h_inode->i_mutex);
9275 + err = do_test_empty(dentry, arg);
9277 + struct do_test_empty_args args = {
9282 + unsigned int flags = arg->flags;
9284 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
9285 + if (unlikely(wkq_err))
9287 + arg->flags = flags;
9293 +int au_test_empty_lower(struct dentry *dentry)
9296 + unsigned int rdhash;
9297 + aufs_bindex_t bindex, bstart, btail;
9298 + struct au_nhash whlist;
9299 + struct test_empty_arg arg = {
9301 + .actor = au_diractor(test_empty_cb)
9305 + SiMustAnyLock(dentry->d_sb);
9307 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
9309 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
9310 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
9311 + if (unlikely(err))
9315 + arg.whlist = &whlist;
9316 + bstart = au_dbstart(dentry);
9317 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
9318 + au_fset_testempty(arg.flags, SHWH);
9319 + arg.bindex = bstart;
9320 + err = do_test_empty(dentry, &arg);
9321 + if (unlikely(err))
9324 + au_fset_testempty(arg.flags, WHONLY);
9325 + btail = au_dbtaildir(dentry);
9326 + for (bindex = bstart + 1; !err && bindex <= btail; bindex++) {
9327 + struct dentry *h_dentry;
9329 + h_dentry = au_h_dptr(dentry, bindex);
9330 + if (h_dentry && h_dentry->d_inode) {
9331 + arg.bindex = bindex;
9332 + err = do_test_empty(dentry, &arg);
9337 + au_nhash_wh_free(&whlist);
9342 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
9345 + struct test_empty_arg arg = {
9347 + .actor = au_diractor(test_empty_cb)
9350 + aufs_bindex_t bindex, btail;
9353 + arg.whlist = whlist;
9354 + arg.flags = AuTestEmpty_WHONLY;
9355 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
9356 + au_fset_testempty(arg.flags, SHWH);
9357 + btail = au_dbtaildir(dentry);
9358 + for (bindex = au_dbstart(dentry); !err && bindex <= btail; bindex++) {
9359 + struct dentry *h_dentry;
9361 + h_dentry = au_h_dptr(dentry, bindex);
9362 + if (h_dentry && h_dentry->d_inode) {
9363 + arg.bindex = bindex;
9364 + err = sio_test_empty(dentry, &arg);
9371 +/* ---------------------------------------------------------------------- */
9373 +const struct file_operations aufs_dir_fop = {
9374 + .owner = THIS_MODULE,
9375 + .llseek = default_llseek,
9376 + .read = generic_read_dir,
9377 + .iterate = aufs_iterate,
9378 + .unlocked_ioctl = aufs_ioctl_dir,
9379 +#ifdef CONFIG_COMPAT
9380 + .compat_ioctl = aufs_compat_ioctl_dir,
9382 + .open = aufs_open_dir,
9383 + .release = aufs_release_dir,
9384 + .flush = aufs_flush_dir,
9385 + .fsync = aufs_fsync_dir
9387 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
9388 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
9389 +++ linux/fs/aufs/dir.h 2014-06-24 00:14:06.779385790 +0200
9392 + * Copyright (C) 2005-2014 Junjiro R. Okajima
9394 + * This program, aufs is free software; you can redistribute it and/or modify
9395 + * it under the terms of the GNU General Public License as published by
9396 + * the Free Software Foundation; either version 2 of the License, or
9397 + * (at your option) any later version.
9399 + * This program is distributed in the hope that it will be useful,
9400 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9401 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9402 + * GNU General Public License for more details.
9404 + * You should have received a copy of the GNU General Public License
9405 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9409 + * directory operations
9412 +#ifndef __AUFS_DIR_H__
9413 +#define __AUFS_DIR_H__
9417 +#include <linux/fs.h>
9419 +/* ---------------------------------------------------------------------- */
9421 +/* need to be faster and smaller */
9424 + unsigned int nh_num;
9425 + struct hlist_head *nh_head;
9428 +struct au_vdir_destr {
9429 + unsigned char len;
9430 + unsigned char name[0];
9433 +struct au_vdir_dehstr {
9434 + struct hlist_node hash;
9435 + struct au_vdir_destr *str;
9436 +} ____cacheline_aligned_in_smp;
9438 +struct au_vdir_de {
9440 + unsigned char de_type;
9441 + /* caution: packed */
9442 + struct au_vdir_destr de_str;
9445 +struct au_vdir_wh {
9446 + struct hlist_node wh_hash;
9447 +#ifdef CONFIG_AUFS_SHWH
9449 + aufs_bindex_t wh_bindex;
9450 + unsigned char wh_type;
9452 + aufs_bindex_t wh_bindex;
9454 + /* caution: packed */
9455 + struct au_vdir_destr wh_str;
9458 +union au_vdir_deblk_p {
9459 + unsigned char *deblk;
9460 + struct au_vdir_de *de;
9464 + unsigned char **vd_deblk;
9465 + unsigned long vd_nblk;
9468 + union au_vdir_deblk_p p;
9471 + unsigned long vd_version;
9472 + unsigned int vd_deblk_sz;
9473 + unsigned long vd_jiffy;
9474 +} ____cacheline_aligned_in_smp;
9476 +/* ---------------------------------------------------------------------- */
9479 +extern const struct file_operations aufs_dir_fop;
9480 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
9481 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
9482 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
9483 +int au_test_empty_lower(struct dentry *dentry);
9484 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
9487 +unsigned int au_rdhash_est(loff_t sz);
9488 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
9489 +void au_nhash_wh_free(struct au_nhash *whlist);
9490 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
9492 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
9493 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
9494 + unsigned int d_type, aufs_bindex_t bindex,
9495 + unsigned char shwh);
9496 +void au_vdir_free(struct au_vdir *vdir);
9497 +int au_vdir_init(struct file *file);
9498 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
9501 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
9503 +#ifdef CONFIG_AUFS_RDU
9505 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
9506 +#ifdef CONFIG_COMPAT
9507 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
9508 + unsigned long arg);
9511 +static inline long au_rdu_ioctl(struct file *file, unsigned int cmd,
9512 + unsigned long arg)
9516 +#ifdef CONFIG_COMPAT
9517 +static inline long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
9518 + unsigned long arg)
9525 +#endif /* __KERNEL__ */
9526 +#endif /* __AUFS_DIR_H__ */
9527 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
9528 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
9529 +++ linux/fs/aufs/dynop.c 2014-06-24 00:14:06.782719306 +0200
9532 + * Copyright (C) 2010-2014 Junjiro R. Okajima
9534 + * This program, aufs is free software; you can redistribute it and/or modify
9535 + * it under the terms of the GNU General Public License as published by
9536 + * the Free Software Foundation; either version 2 of the License, or
9537 + * (at your option) any later version.
9539 + * This program is distributed in the hope that it will be useful,
9540 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9541 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9542 + * GNU General Public License for more details.
9544 + * You should have received a copy of the GNU General Public License
9545 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9549 + * dynamically customizable operations for regular files
9554 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
9557 + * How large will these lists be?
9558 + * Usually just a few elements, 20-30 at most for each, I guess.
9560 +static struct au_splhead dynop[AuDyLast];
9562 +static struct au_dykey *dy_gfind_get(struct au_splhead *spl, const void *h_op)
9564 + struct au_dykey *key, *tmp;
9565 + struct list_head *head;
9568 + head = &spl->head;
9570 + list_for_each_entry_rcu(tmp, head, dk_list)
9571 + if (tmp->dk_op.dy_hop == h_op) {
9573 + kref_get(&key->dk_kref);
9576 + rcu_read_unlock();
9581 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
9583 + struct au_dykey **k, *found;
9584 + const void *h_op = key->dk_op.dy_hop;
9589 + for (i = 0; i < AuBrDynOp; i++)
9591 + if (k[i]->dk_op.dy_hop == h_op) {
9598 + spin_lock(&br->br_dykey_lock);
9599 + for (; i < AuBrDynOp; i++)
9601 + if (k[i]->dk_op.dy_hop == h_op) {
9609 + spin_unlock(&br->br_dykey_lock);
9610 + BUG_ON(i == AuBrDynOp); /* expand the array */
9616 +/* kref_get() if @key is already added */
9617 +static struct au_dykey *dy_gadd(struct au_splhead *spl, struct au_dykey *key)
9619 + struct au_dykey *tmp, *found;
9620 + struct list_head *head;
9621 + const void *h_op = key->dk_op.dy_hop;
9624 + head = &spl->head;
9625 + spin_lock(&spl->spin);
9626 + list_for_each_entry(tmp, head, dk_list)
9627 + if (tmp->dk_op.dy_hop == h_op) {
9628 + kref_get(&tmp->dk_kref);
9633 + list_add_rcu(&key->dk_list, head);
9634 + spin_unlock(&spl->spin);
9641 +static void dy_free_rcu(struct rcu_head *rcu)
9643 + struct au_dykey *key;
9645 + key = container_of(rcu, struct au_dykey, dk_rcu);
9650 +static void dy_free(struct kref *kref)
9652 + struct au_dykey *key;
9653 + struct au_splhead *spl;
9655 + key = container_of(kref, struct au_dykey, dk_kref);
9656 + spl = dynop + key->dk_op.dy_type;
9657 + au_spl_del_rcu(&key->dk_list, spl);
9658 + call_rcu(&key->dk_rcu, dy_free_rcu);
9661 +void au_dy_put(struct au_dykey *key)
9663 + kref_put(&key->dk_kref, dy_free);
9666 +/* ---------------------------------------------------------------------- */
9668 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
9670 +#ifdef CONFIG_AUFS_DEBUG
9671 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
9672 +#define DyDbgInc(cnt) do { cnt++; } while (0)
9674 +#define DyDbgDeclare(cnt) do {} while (0)
9675 +#define DyDbgInc(cnt) do {} while (0)
9678 +#define DySet(func, dst, src, h_op, h_sb) do { \
9680 + if (h_op->func) { \
9682 + dst.func = src.func; \
9684 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
9688 +#define DySetForce(func, dst, src) do { \
9689 + AuDebugOn(!src.func); \
9691 + dst.func = src.func; \
9694 +#define DySetAop(func) \
9695 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
9696 +#define DySetAopForce(func) \
9697 + DySetForce(func, dyaop->da_op, aufs_aop)
9699 +static void dy_aop(struct au_dykey *key, const void *h_op,
9700 + struct super_block *h_sb __maybe_unused)
9702 + struct au_dyaop *dyaop = (void *)key;
9703 + const struct address_space_operations *h_aop = h_op;
9704 + DyDbgDeclare(cnt);
9706 + AuDbg("%s\n", au_sbtype(h_sb));
9708 + DySetAop(writepage);
9709 + DySetAopForce(readpage); /* force */
9710 + DySetAop(writepages);
9711 + DySetAop(set_page_dirty);
9712 + DySetAop(readpages);
9713 + DySetAop(write_begin);
9714 + DySetAop(write_end);
9716 + DySetAop(invalidatepage);
9717 + DySetAop(releasepage);
9718 + DySetAop(freepage);
9719 + /* these two will be changed according to an aufs mount option */
9720 + DySetAop(direct_IO);
9721 + DySetAop(get_xip_mem);
9722 + DySetAop(migratepage);
9723 + DySetAop(launder_page);
9724 + DySetAop(is_partially_uptodate);
9725 + DySetAop(is_dirty_writeback);
9726 + DySetAop(error_remove_page);
9727 + DySetAop(swap_activate);
9728 + DySetAop(swap_deactivate);
9730 + DyDbgSize(cnt, *h_aop);
9731 + dyaop->da_get_xip_mem = h_aop->get_xip_mem;
9734 +/* ---------------------------------------------------------------------- */
9736 +static void dy_bug(struct kref *kref)
9741 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
9743 + struct au_dykey *key, *old;
9744 + struct au_splhead *spl;
9747 + void (*set)(struct au_dykey *key, const void *h_op,
9748 + struct super_block *h_sb __maybe_unused);
9750 + static const struct op a[] = {
9752 + .sz = sizeof(struct au_dyaop),
9756 + const struct op *p;
9758 + spl = dynop + op->dy_type;
9759 + key = dy_gfind_get(spl, op->dy_hop);
9761 + goto out_add; /* success */
9763 + p = a + op->dy_type;
9764 + key = kzalloc(p->sz, GFP_NOFS);
9765 + if (unlikely(!key)) {
9766 + key = ERR_PTR(-ENOMEM);
9770 + key->dk_op.dy_hop = op->dy_hop;
9771 + kref_init(&key->dk_kref);
9772 + p->set(key, op->dy_hop, au_br_sb(br));
9773 + old = dy_gadd(spl, key);
9780 + old = dy_bradd(br, key);
9782 + /* its ref-count should never be zero here */
9783 + kref_put(&key->dk_kref, dy_bug);
9788 +/* ---------------------------------------------------------------------- */
9790 + * Aufs prohibits O_DIRECT by defaut even if the branch supports it.
9791 + * This behaviour is neccessary to return an error from open(O_DIRECT) instead
9792 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
9793 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
9794 + * See the aufs manual in detail.
9796 + * To keep this behaviour, aufs has to set NULL to ->get_xip_mem too, and the
9797 + * performance of fadvise() and madvise() may be affected.
9799 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
9802 + dyaop->da_op.direct_IO = NULL;
9803 + dyaop->da_op.get_xip_mem = NULL;
9805 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
9806 + dyaop->da_op.get_xip_mem = aufs_aop.get_xip_mem;
9807 + if (!dyaop->da_get_xip_mem)
9808 + dyaop->da_op.get_xip_mem = NULL;
9812 +static struct au_dyaop *dy_aget(struct au_branch *br,
9813 + const struct address_space_operations *h_aop,
9816 + struct au_dyaop *dyaop;
9817 + struct au_dynop op;
9819 + op.dy_type = AuDy_AOP;
9820 + op.dy_haop = h_aop;
9821 + dyaop = (void *)dy_get(&op, br);
9822 + if (IS_ERR(dyaop))
9824 + dy_adx(dyaop, do_dx);
9830 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
9831 + struct inode *h_inode)
9834 + struct super_block *sb;
9835 + struct au_branch *br;
9836 + struct au_dyaop *dyaop;
9838 + AuDebugOn(!S_ISREG(h_inode->i_mode));
9839 + IiMustWriteLock(inode);
9842 + br = au_sbr(sb, bindex);
9843 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
9844 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
9845 + err = PTR_ERR(dyaop);
9846 + if (IS_ERR(dyaop))
9847 + /* unnecessary to call dy_fput() */
9851 + inode->i_mapping->a_ops = &dyaop->da_op;
9858 + * Is it safe to replace a_ops during the inode/file is in operation?
9861 +int au_dy_irefresh(struct inode *inode)
9864 + aufs_bindex_t bstart;
9865 + struct inode *h_inode;
9868 + if (S_ISREG(inode->i_mode)) {
9869 + bstart = au_ibstart(inode);
9870 + h_inode = au_h_iptr(inode, bstart);
9871 + err = au_dy_iaop(inode, bstart, h_inode);
9876 +void au_dy_arefresh(int do_dx)
9878 + struct au_splhead *spl;
9879 + struct list_head *head;
9880 + struct au_dykey *key;
9882 + spl = dynop + AuDy_AOP;
9883 + head = &spl->head;
9884 + spin_lock(&spl->spin);
9885 + list_for_each_entry(key, head, dk_list)
9886 + dy_adx((void *)key, do_dx);
9887 + spin_unlock(&spl->spin);
9890 +/* ---------------------------------------------------------------------- */
9892 +void __init au_dy_init(void)
9896 + /* make sure that 'struct au_dykey *' can be any type */
9897 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
9899 + for (i = 0; i < AuDyLast; i++)
9900 + au_spl_init(dynop + i);
9903 +void au_dy_fin(void)
9907 + for (i = 0; i < AuDyLast; i++)
9908 + WARN_ON(!list_empty(&dynop[i].head));
9910 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
9911 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
9912 +++ linux/fs/aufs/dynop.h 2014-06-24 00:14:06.782719306 +0200
9915 + * Copyright (C) 2010-2014 Junjiro R. Okajima
9917 + * This program, aufs is free software; you can redistribute it and/or modify
9918 + * it under the terms of the GNU General Public License as published by
9919 + * the Free Software Foundation; either version 2 of the License, or
9920 + * (at your option) any later version.
9922 + * This program is distributed in the hope that it will be useful,
9923 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9924 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9925 + * GNU General Public License for more details.
9927 + * You should have received a copy of the GNU General Public License
9928 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9932 + * dynamically customizable operations (for regular files only)
9935 +#ifndef __AUFS_DYNOP_H__
9936 +#define __AUFS_DYNOP_H__
9942 +enum {AuDy_AOP, AuDyLast};
9947 + const void *dy_hop;
9948 + const struct address_space_operations *dy_haop;
9954 + struct list_head dk_list;
9955 + struct rcu_head dk_rcu;
9957 + struct au_dynop dk_op;
9960 + * during I am in the branch local array, kref is gotten. when the
9961 + * branch is removed, kref is put.
9963 + struct kref dk_kref;
9966 +/* stop unioning since their sizes are very different from each other */
9968 + struct au_dykey da_key;
9969 + struct address_space_operations da_op; /* not const */
9970 + int (*da_get_xip_mem)(struct address_space *, pgoff_t, int,
9971 + void **, unsigned long *);
9974 +/* ---------------------------------------------------------------------- */
9978 +void au_dy_put(struct au_dykey *key);
9979 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
9980 + struct inode *h_inode);
9981 +int au_dy_irefresh(struct inode *inode);
9982 +void au_dy_arefresh(int do_dio);
9984 +void __init au_dy_init(void);
9985 +void au_dy_fin(void);
9987 +#endif /* __KERNEL__ */
9988 +#endif /* __AUFS_DYNOP_H__ */
9989 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
9990 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
9991 +++ linux/fs/aufs/export.c 2014-06-24 00:14:06.782719306 +0200
9994 + * Copyright (C) 2005-2014 Junjiro R. Okajima
9996 + * This program, aufs is free software; you can redistribute it and/or modify
9997 + * it under the terms of the GNU General Public License as published by
9998 + * the Free Software Foundation; either version 2 of the License, or
9999 + * (at your option) any later version.
10001 + * This program is distributed in the hope that it will be useful,
10002 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10003 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10004 + * GNU General Public License for more details.
10006 + * You should have received a copy of the GNU General Public License
10007 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10014 +#include <linux/exportfs.h>
10015 +#include <linux/fs_struct.h>
10016 +#include <linux/namei.h>
10017 +#include <linux/nsproxy.h>
10018 +#include <linux/random.h>
10019 +#include <linux/writeback.h>
10020 +#include "../fs/mount.h"
10024 +#ifdef CONFIG_AUFS_INO_T_64
10032 +static ino_t decode_ino(__u32 *a)
10036 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
10038 +#ifdef CONFIG_AUFS_INO_T_64
10044 +static void encode_ino(__u32 *a, ino_t ino)
10050 +#ifdef CONFIG_AUFS_INO_T_64
10055 +/* NFS file handle */
10059 +#ifdef CONFIG_AUFS_INO_T_64
10060 + /* support 64bit inode number */
10073 + Fh_ino = Fh_ino1,
10074 + Fh_dir_ino = Fh_dir_ino1
10077 +static int au_test_anon(struct dentry *dentry)
10079 + /* note: read d_flags without d_lock */
10080 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
10083 +int au_test_nfsd(void)
10086 + struct task_struct *tsk = current;
10087 + char comm[sizeof(tsk->comm)];
10090 + if (tsk->flags & PF_KTHREAD) {
10091 + get_task_comm(comm, tsk);
10092 + ret = !strcmp(comm, "nfsd");
10098 +/* ---------------------------------------------------------------------- */
10099 +/* inode generation external table */
10101 +void au_xigen_inc(struct inode *inode)
10106 + struct super_block *sb;
10107 + struct au_sbinfo *sbinfo;
10109 + sb = inode->i_sb;
10110 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
10112 + sbinfo = au_sbi(sb);
10113 + pos = inode->i_ino;
10114 + pos *= sizeof(igen);
10115 + igen = inode->i_generation + 1;
10116 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
10117 + sizeof(igen), &pos);
10118 + if (sz == sizeof(igen))
10119 + return; /* success */
10121 + if (unlikely(sz >= 0))
10122 + AuIOErr("xigen error (%zd)\n", sz);
10125 +int au_xigen_new(struct inode *inode)
10130 + struct super_block *sb;
10131 + struct au_sbinfo *sbinfo;
10132 + struct file *file;
10135 + /* todo: dirty, at mount time */
10136 + if (inode->i_ino == AUFS_ROOT_INO)
10138 + sb = inode->i_sb;
10139 + SiMustAnyLock(sb);
10140 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
10144 + pos = inode->i_ino;
10145 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
10146 + AuIOErr1("too large i%lld\n", pos);
10149 + pos *= sizeof(inode->i_generation);
10152 + sbinfo = au_sbi(sb);
10153 + file = sbinfo->si_xigen;
10156 + if (vfsub_f_size_read(file)
10157 + < pos + sizeof(inode->i_generation)) {
10158 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
10159 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
10160 + sizeof(inode->i_generation), &pos);
10162 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
10163 + sizeof(inode->i_generation), &pos);
10164 + if (sz == sizeof(inode->i_generation))
10165 + goto out; /* success */
10168 + if (unlikely(sz >= 0)) {
10170 + AuIOErr("xigen error (%zd)\n", sz);
10177 +int au_xigen_set(struct super_block *sb, struct file *base)
10180 + struct au_sbinfo *sbinfo;
10181 + struct file *file;
10183 + SiMustWriteLock(sb);
10185 + sbinfo = au_sbi(sb);
10186 + file = au_xino_create2(base, sbinfo->si_xigen);
10187 + err = PTR_ERR(file);
10188 + if (IS_ERR(file))
10191 + if (sbinfo->si_xigen)
10192 + fput(sbinfo->si_xigen);
10193 + sbinfo->si_xigen = file;
10199 +void au_xigen_clr(struct super_block *sb)
10201 + struct au_sbinfo *sbinfo;
10203 + SiMustWriteLock(sb);
10205 + sbinfo = au_sbi(sb);
10206 + if (sbinfo->si_xigen) {
10207 + fput(sbinfo->si_xigen);
10208 + sbinfo->si_xigen = NULL;
10212 +/* ---------------------------------------------------------------------- */
10214 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
10217 + struct dentry *dentry, *d;
10218 + struct inode *inode;
10219 + unsigned int sigen;
10222 + inode = ilookup(sb, ino);
10226 + dentry = ERR_PTR(-ESTALE);
10227 + sigen = au_sigen(sb);
10228 + if (unlikely(is_bad_inode(inode)
10229 + || IS_DEADDIR(inode)
10230 + || sigen != au_iigen(inode, NULL)))
10234 + if (!dir_ino || S_ISDIR(inode->i_mode))
10235 + dentry = d_find_alias(inode);
10237 + spin_lock(&inode->i_lock);
10238 + hlist_for_each_entry(d, &inode->i_dentry, d_alias) {
10239 + spin_lock(&d->d_lock);
10240 + if (!au_test_anon(d)
10241 + && d->d_parent->d_inode->i_ino == dir_ino) {
10242 + dentry = dget_dlock(d);
10243 + spin_unlock(&d->d_lock);
10246 + spin_unlock(&d->d_lock);
10248 + spin_unlock(&inode->i_lock);
10250 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
10251 + /* need to refresh */
10259 + AuTraceErrPtr(dentry);
10263 +/* ---------------------------------------------------------------------- */
10265 +/* todo: dirty? */
10266 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
10268 +struct au_compare_mnt_args {
10270 + struct super_block *sb;
10273 + struct vfsmount *mnt;
10276 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
10278 + struct au_compare_mnt_args *a = arg;
10280 + if (mnt->mnt_sb != a->sb)
10282 + a->mnt = mntget(mnt);
10286 +static struct vfsmount *au_mnt_get(struct super_block *sb)
10289 + struct path root;
10290 + struct au_compare_mnt_args args = {
10294 + get_fs_root(current->fs, &root);
10296 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
10297 + rcu_read_unlock();
10300 + AuDebugOn(!args.mnt);
10304 +struct au_nfsd_si_lock {
10305 + unsigned int sigen;
10306 + aufs_bindex_t bindex, br_id;
10307 + unsigned char force_lock;
10310 +static int si_nfsd_read_lock(struct super_block *sb,
10311 + struct au_nfsd_si_lock *nsi_lock)
10314 + aufs_bindex_t bindex;
10316 + si_read_lock(sb, AuLock_FLUSH);
10318 + /* branch id may be wrapped around */
10320 + bindex = au_br_index(sb, nsi_lock->br_id);
10321 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
10322 + goto out; /* success */
10326 + if (!nsi_lock->force_lock)
10327 + si_read_unlock(sb);
10330 + nsi_lock->bindex = bindex;
10334 +struct find_name_by_ino {
10335 + struct dir_context ctx;
10336 + int called, found;
10343 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
10344 + loff_t offset, u64 ino, unsigned int d_type)
10346 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
10350 + if (a->ino != ino)
10353 + memcpy(a->name, name, namelen);
10354 + a->namelen = namelen;
10359 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
10360 + struct au_nfsd_si_lock *nsi_lock)
10362 + struct dentry *dentry, *parent;
10363 + struct file *file;
10364 + struct inode *dir;
10365 + struct find_name_by_ino arg = {
10367 + .actor = au_diractor(find_name_by_ino)
10372 + parent = path->dentry;
10374 + si_read_unlock(parent->d_sb);
10375 + file = vfsub_dentry_open(path, au_dir_roflags);
10376 + dentry = (void *)file;
10377 + if (IS_ERR(file))
10380 + dentry = ERR_PTR(-ENOMEM);
10381 + arg.name = (void *)__get_free_page(GFP_NOFS);
10382 + if (unlikely(!arg.name))
10389 + err = vfsub_iterate_dir(file, &arg.ctx);
10390 + } while (!err && !arg.found && arg.called);
10391 + dentry = ERR_PTR(err);
10392 + if (unlikely(err))
10394 + /* instead of ENOENT */
10395 + dentry = ERR_PTR(-ESTALE);
10399 + /* do not call vfsub_lkup_one() */
10400 + dir = parent->d_inode;
10401 + mutex_lock(&dir->i_mutex);
10402 + dentry = vfsub_lookup_one_len(arg.name, parent, arg.namelen);
10403 + mutex_unlock(&dir->i_mutex);
10404 + AuTraceErrPtr(dentry);
10405 + if (IS_ERR(dentry))
10407 + AuDebugOn(au_test_anon(dentry));
10408 + if (unlikely(!dentry->d_inode)) {
10410 + dentry = ERR_PTR(-ENOENT);
10414 + free_page((unsigned long)arg.name);
10418 + if (unlikely(nsi_lock
10419 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
10420 + if (!IS_ERR(dentry)) {
10422 + dentry = ERR_PTR(-ESTALE);
10424 + AuTraceErrPtr(dentry);
10428 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
10430 + struct au_nfsd_si_lock *nsi_lock)
10432 + struct dentry *dentry;
10433 + struct path path;
10435 + if (dir_ino != AUFS_ROOT_INO) {
10436 + path.dentry = decode_by_ino(sb, dir_ino, 0);
10437 + dentry = path.dentry;
10438 + if (!path.dentry || IS_ERR(path.dentry))
10440 + AuDebugOn(au_test_anon(path.dentry));
10442 + path.dentry = dget(sb->s_root);
10444 + path.mnt = au_mnt_get(sb);
10445 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
10449 + AuTraceErrPtr(dentry);
10453 +/* ---------------------------------------------------------------------- */
10455 +static int h_acceptable(void *expv, struct dentry *dentry)
10460 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
10461 + char *buf, int len, struct super_block *sb)
10465 + struct path path;
10467 + p = d_path(h_rootpath, buf, len);
10472 + path.mnt = h_rootpath->mnt;
10473 + path.dentry = h_parent;
10474 + p = d_path(&path, buf, len);
10480 + path.mnt = au_mnt_get(sb);
10481 + path.dentry = sb->s_root;
10482 + p = d_path(&path, buf, len - strlen(p));
10483 + mntput(path.mnt);
10487 + p[strlen(p)] = '/';
10490 + AuTraceErrPtr(p);
10495 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
10496 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
10498 + struct dentry *dentry, *h_parent, *root;
10499 + struct super_block *h_sb;
10500 + char *pathname, *p;
10501 + struct vfsmount *h_mnt;
10502 + struct au_branch *br;
10504 + struct path path;
10506 + br = au_sbr(sb, nsi_lock->bindex);
10507 + h_mnt = au_br_mnt(br);
10508 + h_sb = h_mnt->mnt_sb;
10509 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
10510 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
10511 + fh_len - Fh_tail, fh[Fh_h_type],
10512 + h_acceptable, /*context*/NULL);
10513 + dentry = h_parent;
10514 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
10515 + AuWarn1("%s decode_fh failed, %ld\n",
10516 + au_sbtype(h_sb), PTR_ERR(h_parent));
10520 + if (unlikely(au_test_anon(h_parent))) {
10521 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
10522 + au_sbtype(h_sb));
10523 + goto out_h_parent;
10526 + dentry = ERR_PTR(-ENOMEM);
10527 + pathname = (void *)__get_free_page(GFP_NOFS);
10528 + if (unlikely(!pathname))
10529 + goto out_h_parent;
10531 + root = sb->s_root;
10532 + path.mnt = h_mnt;
10533 + di_read_lock_parent(root, !AuLock_IR);
10534 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
10535 + di_read_unlock(root, !AuLock_IR);
10536 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
10537 + dentry = (void *)p;
10539 + goto out_pathname;
10541 + si_read_unlock(sb);
10542 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
10543 + dentry = ERR_PTR(err);
10544 + if (unlikely(err))
10547 + dentry = ERR_PTR(-ENOENT);
10548 + AuDebugOn(au_test_anon(path.dentry));
10549 + if (unlikely(!path.dentry->d_inode))
10552 + if (ino != path.dentry->d_inode->i_ino)
10553 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
10555 + dentry = dget(path.dentry);
10560 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
10561 + if (!IS_ERR(dentry)) {
10563 + dentry = ERR_PTR(-ESTALE);
10566 + free_page((unsigned long)pathname);
10570 + AuTraceErrPtr(dentry);
10574 +/* ---------------------------------------------------------------------- */
10576 +static struct dentry *
10577 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
10580 + struct dentry *dentry;
10581 + __u32 *fh = fid->raw;
10582 + struct au_branch *br;
10583 + ino_t ino, dir_ino;
10584 + struct au_nfsd_si_lock nsi_lock = {
10588 + dentry = ERR_PTR(-ESTALE);
10589 + /* it should never happen, but the file handle is unreliable */
10590 + if (unlikely(fh_len < Fh_tail))
10592 + nsi_lock.sigen = fh[Fh_sigen];
10593 + nsi_lock.br_id = fh[Fh_br_id];
10595 + /* branch id may be wrapped around */
10597 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
10599 + nsi_lock.force_lock = 1;
10601 + /* is this inode still cached? */
10602 + ino = decode_ino(fh + Fh_ino);
10603 + /* it should never happen */
10604 + if (unlikely(ino == AUFS_ROOT_INO))
10607 + dir_ino = decode_ino(fh + Fh_dir_ino);
10608 + dentry = decode_by_ino(sb, ino, dir_ino);
10609 + if (IS_ERR(dentry))
10614 + /* is the parent dir cached? */
10615 + br = au_sbr(sb, nsi_lock.bindex);
10616 + atomic_inc(&br->br_count);
10617 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
10618 + if (IS_ERR(dentry))
10623 + /* lookup path */
10624 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
10625 + if (IS_ERR(dentry))
10627 + if (unlikely(!dentry))
10628 + /* todo?: make it ESTALE */
10632 + if (!au_digen_test(dentry, au_sigen(sb))
10633 + && dentry->d_inode->i_generation == fh[Fh_igen])
10634 + goto out_unlock; /* success */
10637 + dentry = ERR_PTR(-ESTALE);
10640 + atomic_dec(&br->br_count);
10641 + si_read_unlock(sb);
10643 + AuTraceErrPtr(dentry);
10647 +#if 0 /* reserved for future use */
10648 +/* support subtreecheck option */
10649 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
10650 + int fh_len, int fh_type)
10652 + struct dentry *parent;
10653 + __u32 *fh = fid->raw;
10656 + dir_ino = decode_ino(fh + Fh_dir_ino);
10657 + parent = decode_by_ino(sb, dir_ino, 0);
10658 + if (IS_ERR(parent))
10661 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
10662 + dir_ino, fh, fh_len);
10665 + AuTraceErrPtr(parent);
10670 +/* ---------------------------------------------------------------------- */
10672 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
10673 + struct inode *dir)
10676 + aufs_bindex_t bindex;
10677 + struct super_block *sb, *h_sb;
10678 + struct dentry *dentry, *parent, *h_parent;
10679 + struct inode *h_dir;
10680 + struct au_branch *br;
10683 + if (unlikely(*max_len <= Fh_tail)) {
10684 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
10688 + err = FILEID_ROOT;
10689 + if (inode->i_ino == AUFS_ROOT_INO) {
10690 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
10695 + sb = inode->i_sb;
10696 + err = si_read_lock(sb, AuLock_FLUSH);
10697 + if (unlikely(err))
10700 +#ifdef CONFIG_AUFS_DEBUG
10701 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
10702 + AuWarn1("NFS-exporting requires xino\n");
10706 + ii_read_lock_child(inode);
10707 + bindex = au_ibstart(inode);
10709 + dentry = d_find_alias(inode);
10710 + if (unlikely(!dentry))
10712 + AuDebugOn(au_test_anon(dentry));
10713 + parent = dget_parent(dentry);
10715 + if (unlikely(!parent))
10717 + dir = parent->d_inode;
10720 + ii_read_lock_parent(dir);
10721 + h_dir = au_h_iptr(dir, bindex);
10722 + ii_read_unlock(dir);
10723 + if (unlikely(!h_dir))
10725 + h_parent = d_find_alias(h_dir);
10726 + if (unlikely(!h_parent))
10727 + goto out_hparent;
10730 + br = au_sbr(sb, bindex);
10731 + h_sb = au_br_sb(br);
10732 + if (unlikely(!h_sb->s_export_op)) {
10733 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
10734 + goto out_hparent;
10737 + fh[Fh_br_id] = br->br_id;
10738 + fh[Fh_sigen] = au_sigen(sb);
10739 + encode_ino(fh + Fh_ino, inode->i_ino);
10740 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
10741 + fh[Fh_igen] = inode->i_generation;
10743 + *max_len -= Fh_tail;
10744 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
10746 + /*connectable or subtreecheck*/0);
10747 + err = fh[Fh_h_type];
10748 + *max_len += Fh_tail;
10749 + /* todo: macros? */
10750 + if (err != FILEID_INVALID)
10753 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
10760 + ii_read_unlock(inode);
10761 + si_read_unlock(sb);
10763 + if (unlikely(err < 0))
10764 + err = FILEID_INVALID;
10768 +/* ---------------------------------------------------------------------- */
10770 +static int aufs_commit_metadata(struct inode *inode)
10773 + aufs_bindex_t bindex;
10774 + struct super_block *sb;
10775 + struct inode *h_inode;
10776 + int (*f)(struct inode *inode);
10778 + sb = inode->i_sb;
10779 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
10780 + ii_write_lock_child(inode);
10781 + bindex = au_ibstart(inode);
10782 + AuDebugOn(bindex < 0);
10783 + h_inode = au_h_iptr(inode, bindex);
10785 + f = h_inode->i_sb->s_export_op->commit_metadata;
10787 + err = f(h_inode);
10789 + struct writeback_control wbc = {
10790 + .sync_mode = WB_SYNC_ALL,
10791 + .nr_to_write = 0 /* metadata only */
10794 + err = sync_inode(h_inode, &wbc);
10797 + au_cpup_attr_timesizes(inode);
10798 + ii_write_unlock(inode);
10799 + si_read_unlock(sb);
10803 +/* ---------------------------------------------------------------------- */
10805 +static struct export_operations aufs_export_op = {
10806 + .fh_to_dentry = aufs_fh_to_dentry,
10807 + /* .fh_to_parent = aufs_fh_to_parent, */
10808 + .encode_fh = aufs_encode_fh,
10809 + .commit_metadata = aufs_commit_metadata
10812 +void au_export_init(struct super_block *sb)
10814 + struct au_sbinfo *sbinfo;
10817 + sb->s_export_op = &aufs_export_op;
10818 + sbinfo = au_sbi(sb);
10819 + sbinfo->si_xigen = NULL;
10820 + get_random_bytes(&u, sizeof(u));
10821 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
10822 + atomic_set(&sbinfo->si_xigen_next, u);
10824 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
10825 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
10826 +++ linux/fs/aufs/file.c 2014-06-24 00:14:06.782719306 +0200
10829 + * Copyright (C) 2005-2014 Junjiro R. Okajima
10831 + * This program, aufs is free software; you can redistribute it and/or modify
10832 + * it under the terms of the GNU General Public License as published by
10833 + * the Free Software Foundation; either version 2 of the License, or
10834 + * (at your option) any later version.
10836 + * This program is distributed in the hope that it will be useful,
10837 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10838 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10839 + * GNU General Public License for more details.
10841 + * You should have received a copy of the GNU General Public License
10842 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10846 + * handling file/dir, and address_space operation
10849 +#ifdef CONFIG_AUFS_DEBUG
10850 +#include <linux/migrate.h>
10852 +#include <linux/pagemap.h>
10855 +/* drop flags for writing */
10856 +unsigned int au_file_roflags(unsigned int flags)
10858 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
10859 + flags |= O_RDONLY | O_NOATIME;
10863 +/* common functions to regular file and dir */
10864 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
10865 + struct file *file, int force_wr)
10867 + struct file *h_file;
10868 + struct dentry *h_dentry;
10869 + struct inode *h_inode;
10870 + struct super_block *sb;
10871 + struct au_branch *br;
10872 + struct path h_path;
10873 + int err, exec_flag;
10875 + /* a race condition can happen between open and unlink/rmdir */
10876 + h_file = ERR_PTR(-ENOENT);
10877 + h_dentry = au_h_dptr(dentry, bindex);
10878 + if (au_test_nfsd() && !h_dentry)
10880 + h_inode = h_dentry->d_inode;
10881 + if (au_test_nfsd() && !h_inode)
10883 + spin_lock(&h_dentry->d_lock);
10884 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
10886 + /* || !dentry->d_inode->i_nlink */
10888 + spin_unlock(&h_dentry->d_lock);
10889 + if (unlikely(err))
10892 + sb = dentry->d_sb;
10893 + br = au_sbr(sb, bindex);
10894 + h_file = ERR_PTR(-EACCES);
10895 + exec_flag = flags & __FMODE_EXEC;
10896 + if (exec_flag && (au_br_mnt(br)->mnt_flags & MNT_NOEXEC))
10899 + /* drop flags for writing */
10900 + if (au_test_ro(sb, bindex, dentry->d_inode)) {
10901 + if (force_wr && !(flags & O_WRONLY))
10903 + flags = au_file_roflags(flags);
10905 + h_file = ERR_PTR(-EROFS);
10906 + flags = au_file_roflags(flags);
10907 + if (unlikely(vfsub_native_ro(h_inode)
10908 + || IS_APPEND(h_inode)))
10910 + flags &= ~O_ACCMODE;
10911 + flags |= O_WRONLY;
10914 + flags &= ~O_CREAT;
10915 + atomic_inc(&br->br_count);
10916 + h_path.dentry = h_dentry;
10917 + h_path.mnt = au_br_mnt(br);
10918 + h_file = vfsub_dentry_open(&h_path, flags);
10919 + if (IS_ERR(h_file))
10923 + err = deny_write_access(h_file);
10924 + if (unlikely(err)) {
10926 + h_file = ERR_PTR(err);
10930 + fsnotify_open(h_file);
10931 + goto out; /* success */
10934 + atomic_dec(&br->br_count);
10939 +int au_do_open(struct file *file, int (*open)(struct file *file, int flags),
10940 + struct au_fidir *fidir)
10943 + struct dentry *dentry;
10945 + err = au_finfo_init(file, fidir);
10946 + if (unlikely(err))
10949 + dentry = file->f_dentry;
10950 + di_read_lock_child(dentry, AuLock_IR);
10951 + err = open(file, vfsub_file_flags(file));
10952 + di_read_unlock(dentry, AuLock_IR);
10954 + fi_write_unlock(file);
10955 + if (unlikely(err)) {
10956 + au_fi(file)->fi_hdir = NULL;
10957 + au_finfo_fin(file);
10964 +int au_reopen_nondir(struct file *file)
10967 + aufs_bindex_t bstart;
10968 + struct dentry *dentry;
10969 + struct file *h_file, *h_file_tmp;
10971 + dentry = file->f_dentry;
10972 + bstart = au_dbstart(dentry);
10973 + h_file_tmp = NULL;
10974 + if (au_fbstart(file) == bstart) {
10975 + h_file = au_hf_top(file);
10976 + if (file->f_mode == h_file->f_mode)
10977 + return 0; /* success */
10978 + h_file_tmp = h_file;
10979 + get_file(h_file_tmp);
10980 + au_set_h_fptr(file, bstart, NULL);
10982 + AuDebugOn(au_fi(file)->fi_hdir);
10985 + * file exists on both of rw and ro
10986 + * open --> dbstart and fbstart are both 0
10987 + * prepend a branch as rw, "rw" become ro
10989 + * delete the top branch, "rw" becomes rw again
10990 + * --> dbstart is 1, fbstart is still 0
10991 + * write --> fbstart is 0 but dbstart is 1
10993 + /* AuDebugOn(au_fbstart(file) < bstart); */
10995 + h_file = au_h_open(dentry, bstart, vfsub_file_flags(file) & ~O_TRUNC,
10996 + file, /*force_wr*/0);
10997 + err = PTR_ERR(h_file);
10998 + if (IS_ERR(h_file)) {
10999 + if (h_file_tmp) {
11000 + atomic_inc(&au_sbr(dentry->d_sb, bstart)->br_count);
11001 + au_set_h_fptr(file, bstart, h_file_tmp);
11002 + h_file_tmp = NULL;
11004 + goto out; /* todo: close all? */
11008 + au_set_fbstart(file, bstart);
11009 + au_set_h_fptr(file, bstart, h_file);
11010 + au_update_figen(file);
11011 + /* todo: necessary? */
11012 + /* file->f_ra = h_file->f_ra; */
11016 + fput(h_file_tmp);
11020 +/* ---------------------------------------------------------------------- */
11022 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
11023 + struct dentry *hi_wh)
11026 + aufs_bindex_t bstart;
11027 + struct au_dinfo *dinfo;
11028 + struct dentry *h_dentry;
11029 + struct au_hdentry *hdp;
11031 + dinfo = au_di(file->f_dentry);
11032 + AuRwMustWriteLock(&dinfo->di_rwsem);
11034 + bstart = dinfo->di_bstart;
11035 + dinfo->di_bstart = btgt;
11036 + hdp = dinfo->di_hdentry;
11037 + h_dentry = hdp[0 + btgt].hd_dentry;
11038 + hdp[0 + btgt].hd_dentry = hi_wh;
11039 + err = au_reopen_nondir(file);
11040 + hdp[0 + btgt].hd_dentry = h_dentry;
11041 + dinfo->di_bstart = bstart;
11046 +static int au_ready_to_write_wh(struct file *file, loff_t len,
11047 + aufs_bindex_t bcpup, struct au_pin *pin)
11050 + struct inode *inode, *h_inode;
11051 + struct dentry *h_dentry, *hi_wh;
11052 + struct au_cp_generic cpg = {
11053 + .dentry = file->f_dentry,
11060 + au_update_dbstart(cpg.dentry);
11061 + inode = cpg.dentry->d_inode;
11063 + if (au_dbstart(cpg.dentry) <= bcpup
11064 + && au_dbend(cpg.dentry) >= bcpup) {
11065 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
11067 + h_inode = h_dentry->d_inode;
11069 + hi_wh = au_hi_wh(inode, bcpup);
11070 + if (!hi_wh && !h_inode)
11071 + err = au_sio_cpup_wh(&cpg, file);
11073 + /* already copied-up after unlink */
11074 + err = au_reopen_wh(file, bcpup, hi_wh);
11077 + && (inode->i_nlink > 1
11078 + || (inode->i_state & I_LINKABLE))
11079 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
11080 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
11086 + * prepare the @file for writing.
11088 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
11091 + aufs_bindex_t dbstart;
11092 + struct dentry *parent, *h_dentry;
11093 + struct inode *inode;
11094 + struct super_block *sb;
11095 + struct file *h_file;
11096 + struct au_cp_generic cpg = {
11097 + .dentry = file->f_dentry,
11102 + .flags = AuCpup_DTIME
11105 + sb = cpg.dentry->d_sb;
11106 + inode = cpg.dentry->d_inode;
11107 + cpg.bsrc = au_fbstart(file);
11108 + err = au_test_ro(sb, cpg.bsrc, inode);
11109 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
11110 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
11115 + /* need to cpup or reopen */
11116 + parent = dget_parent(cpg.dentry);
11117 + di_write_lock_parent(parent);
11118 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
11120 + if (unlikely(err < 0))
11124 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
11125 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
11126 + if (unlikely(err))
11130 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
11131 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
11132 + if (unlikely(err))
11135 + h_dentry = au_hf_top(file)->f_dentry;
11136 + dbstart = au_dbstart(cpg.dentry);
11137 + if (dbstart <= cpg.bdst) {
11138 + h_dentry = au_h_dptr(cpg.dentry, cpg.bdst);
11139 + AuDebugOn(!h_dentry);
11140 + cpg.bsrc = cpg.bdst;
11143 + if (dbstart <= cpg.bdst /* just reopen */
11144 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
11146 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
11147 + if (IS_ERR(h_file))
11148 + err = PTR_ERR(h_file);
11150 + di_downgrade_lock(parent, AuLock_IR);
11151 + if (dbstart > cpg.bdst)
11152 + err = au_sio_cpup_simple(&cpg);
11154 + err = au_reopen_nondir(file);
11155 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
11157 + } else { /* copyup as wh and reopen */
11159 + * since writable hfsplus branch is not supported,
11160 + * h_open_pre/post() are unnecessary.
11162 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
11163 + di_downgrade_lock(parent, AuLock_IR);
11167 + au_pin_set_parent_lflag(pin, /*lflag*/0);
11168 + goto out_dput; /* success */
11174 + di_downgrade_lock(parent, AuLock_IR);
11176 + di_read_unlock(parent, AuLock_IR);
11183 +/* ---------------------------------------------------------------------- */
11185 +int au_do_flush(struct file *file, fl_owner_t id,
11186 + int (*flush)(struct file *file, fl_owner_t id))
11189 + struct super_block *sb;
11190 + struct inode *inode;
11192 + inode = file_inode(file);
11193 + sb = inode->i_sb;
11194 + si_noflush_read_lock(sb);
11195 + fi_read_lock(file);
11196 + ii_read_lock_child(inode);
11198 + err = flush(file, id);
11199 + au_cpup_attr_timesizes(inode);
11201 + ii_read_unlock(inode);
11202 + fi_read_unlock(file);
11203 + si_read_unlock(sb);
11207 +/* ---------------------------------------------------------------------- */
11209 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
11212 + struct au_pin pin;
11213 + struct au_finfo *finfo;
11214 + struct dentry *parent, *hi_wh;
11215 + struct inode *inode;
11216 + struct super_block *sb;
11217 + struct au_cp_generic cpg = {
11218 + .dentry = file->f_dentry,
11223 + .flags = AuCpup_DTIME
11226 + FiMustWriteLock(file);
11229 + finfo = au_fi(file);
11230 + sb = cpg.dentry->d_sb;
11231 + inode = cpg.dentry->d_inode;
11232 + cpg.bdst = au_ibstart(inode);
11233 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
11236 + parent = dget_parent(cpg.dentry);
11237 + if (au_test_ro(sb, cpg.bdst, inode)) {
11238 + di_read_lock_parent(parent, !AuLock_IR);
11239 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
11241 + di_read_unlock(parent, !AuLock_IR);
11242 + if (unlikely(err < 0))
11247 + di_read_lock_parent(parent, AuLock_IR);
11248 + hi_wh = au_hi_wh(inode, cpg.bdst);
11249 + if (!S_ISDIR(inode->i_mode)
11250 + && au_opt_test(au_mntflags(sb), PLINK)
11251 + && au_plink_test(inode)
11252 + && !d_unhashed(cpg.dentry)
11253 + && cpg.bdst < au_dbstart(cpg.dentry)) {
11254 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
11255 + if (unlikely(err))
11258 + /* always superio. */
11259 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
11260 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
11262 + err = au_sio_cpup_simple(&cpg);
11265 + } else if (hi_wh) {
11266 + /* already copied-up after unlink */
11267 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
11268 + *need_reopen = 0;
11272 + di_read_unlock(parent, AuLock_IR);
11279 +static void au_do_refresh_dir(struct file *file)
11281 + aufs_bindex_t bindex, bend, new_bindex, brid;
11282 + struct au_hfile *p, tmp, *q;
11283 + struct au_finfo *finfo;
11284 + struct super_block *sb;
11285 + struct au_fidir *fidir;
11287 + FiMustWriteLock(file);
11289 + sb = file->f_dentry->d_sb;
11290 + finfo = au_fi(file);
11291 + fidir = finfo->fi_hdir;
11292 + AuDebugOn(!fidir);
11293 + p = fidir->fd_hfile + finfo->fi_btop;
11294 + brid = p->hf_br->br_id;
11295 + bend = fidir->fd_bbot;
11296 + for (bindex = finfo->fi_btop; bindex <= bend; bindex++, p++) {
11300 + new_bindex = au_br_index(sb, p->hf_br->br_id);
11301 + if (new_bindex == bindex)
11303 + if (new_bindex < 0) {
11304 + au_set_h_fptr(file, bindex, NULL);
11308 + /* swap two lower inode, and loop again */
11309 + q = fidir->fd_hfile + new_bindex;
11313 + if (tmp.hf_file) {
11319 + p = fidir->fd_hfile;
11320 + if (!au_test_mmapped(file) && !d_unlinked(file->f_dentry)) {
11321 + bend = au_sbend(sb);
11322 + for (finfo->fi_btop = 0; finfo->fi_btop <= bend;
11323 + finfo->fi_btop++, p++)
11324 + if (p->hf_file) {
11325 + if (file_inode(p->hf_file))
11328 + au_hfput(p, file);
11331 + bend = au_br_index(sb, brid);
11332 + for (finfo->fi_btop = 0; finfo->fi_btop < bend;
11333 + finfo->fi_btop++, p++)
11335 + au_hfput(p, file);
11336 + bend = au_sbend(sb);
11339 + p = fidir->fd_hfile + bend;
11340 + for (fidir->fd_bbot = bend; fidir->fd_bbot >= finfo->fi_btop;
11341 + fidir->fd_bbot--, p--)
11342 + if (p->hf_file) {
11343 + if (file_inode(p->hf_file))
11346 + au_hfput(p, file);
11348 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
11352 + * after branch manipulating, refresh the file.
11354 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
11356 + int err, need_reopen;
11357 + aufs_bindex_t bend, bindex;
11358 + struct dentry *dentry;
11359 + struct au_finfo *finfo;
11360 + struct au_hfile *hfile;
11362 + dentry = file->f_dentry;
11363 + finfo = au_fi(file);
11364 + if (!finfo->fi_hdir) {
11365 + hfile = &finfo->fi_htop;
11366 + AuDebugOn(!hfile->hf_file);
11367 + bindex = au_br_index(dentry->d_sb, hfile->hf_br->br_id);
11368 + AuDebugOn(bindex < 0);
11369 + if (bindex != finfo->fi_btop)
11370 + au_set_fbstart(file, bindex);
11372 + err = au_fidir_realloc(finfo, au_sbend(dentry->d_sb) + 1);
11373 + if (unlikely(err))
11375 + au_do_refresh_dir(file);
11380 + if (!au_test_mmapped(file))
11381 + err = au_file_refresh_by_inode(file, &need_reopen);
11382 + if (!err && need_reopen && !d_unlinked(dentry))
11383 + err = reopen(file);
11385 + au_update_figen(file);
11386 + goto out; /* success */
11389 + /* error, close all lower files */
11390 + if (finfo->fi_hdir) {
11391 + bend = au_fbend_dir(file);
11392 + for (bindex = au_fbstart(file); bindex <= bend; bindex++)
11393 + au_set_h_fptr(file, bindex, NULL);
11400 +/* common function to regular file and dir */
11401 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
11405 + unsigned int sigen, figen;
11406 + aufs_bindex_t bstart;
11407 + unsigned char pseudo_link;
11408 + struct dentry *dentry;
11409 + struct inode *inode;
11412 + dentry = file->f_dentry;
11413 + inode = dentry->d_inode;
11414 + sigen = au_sigen(dentry->d_sb);
11415 + fi_write_lock(file);
11416 + figen = au_figen(file);
11417 + di_write_lock_child(dentry);
11418 + bstart = au_dbstart(dentry);
11419 + pseudo_link = (bstart != au_ibstart(inode));
11420 + if (sigen == figen && !pseudo_link && au_fbstart(file) == bstart) {
11422 + di_downgrade_lock(dentry, AuLock_IR);
11423 + fi_downgrade_lock(file);
11425 + goto out; /* success */
11428 + AuDbg("sigen %d, figen %d\n", sigen, figen);
11429 + if (au_digen_test(dentry, sigen)) {
11430 + err = au_reval_dpath(dentry, sigen);
11431 + AuDebugOn(!err && au_digen_test(dentry, sigen));
11435 + err = refresh_file(file, reopen);
11438 + di_downgrade_lock(dentry, AuLock_IR);
11439 + fi_downgrade_lock(file);
11442 + di_write_unlock(dentry);
11443 + fi_write_unlock(file);
11450 +/* ---------------------------------------------------------------------- */
11452 +/* cf. aufs_nopage() */
11453 +/* for madvise(2) */
11454 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
11456 + unlock_page(page);
11460 +/* it will never be called, but necessary to support O_DIRECT */
11461 +static ssize_t aufs_direct_IO(int rw, struct kiocb *iocb,
11462 + const struct iovec *iov, loff_t offset,
11463 + unsigned long nr_segs)
11464 +{ BUG(); return 0; }
11467 + * it will never be called, but madvise and fadvise behaves differently
11468 + * when get_xip_mem is defined
11470 +static int aufs_get_xip_mem(struct address_space *mapping, pgoff_t pgoff,
11471 + int create, void **kmem, unsigned long *pfn)
11472 +{ BUG(); return 0; }
11474 +/* they will never be called. */
11475 +#ifdef CONFIG_AUFS_DEBUG
11476 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
11477 + loff_t pos, unsigned len, unsigned flags,
11478 + struct page **pagep, void **fsdata)
11479 +{ AuUnsupport(); return 0; }
11480 +static int aufs_write_end(struct file *file, struct address_space *mapping,
11481 + loff_t pos, unsigned len, unsigned copied,
11482 + struct page *page, void *fsdata)
11483 +{ AuUnsupport(); return 0; }
11484 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
11485 +{ AuUnsupport(); return 0; }
11487 +static int aufs_set_page_dirty(struct page *page)
11488 +{ AuUnsupport(); return 0; }
11489 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
11490 + unsigned int length)
11491 +{ AuUnsupport(); }
11492 +static int aufs_releasepage(struct page *page, gfp_t gfp)
11493 +{ AuUnsupport(); return 0; }
11494 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
11495 + struct page *page, enum migrate_mode mode)
11496 +{ AuUnsupport(); return 0; }
11497 +static int aufs_launder_page(struct page *page)
11498 +{ AuUnsupport(); return 0; }
11499 +static int aufs_is_partially_uptodate(struct page *page,
11500 + unsigned long from,
11501 + unsigned long count)
11502 +{ AuUnsupport(); return 0; }
11503 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
11505 +{ AuUnsupport(); }
11506 +static int aufs_error_remove_page(struct address_space *mapping,
11507 + struct page *page)
11508 +{ AuUnsupport(); return 0; }
11509 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
11511 +{ AuUnsupport(); return 0; }
11512 +static void aufs_swap_deactivate(struct file *file)
11513 +{ AuUnsupport(); }
11514 +#endif /* CONFIG_AUFS_DEBUG */
11516 +const struct address_space_operations aufs_aop = {
11517 + .readpage = aufs_readpage,
11518 + .direct_IO = aufs_direct_IO,
11519 + .get_xip_mem = aufs_get_xip_mem,
11520 +#ifdef CONFIG_AUFS_DEBUG
11521 + .writepage = aufs_writepage,
11522 + /* no writepages, because of writepage */
11523 + .set_page_dirty = aufs_set_page_dirty,
11524 + /* no readpages, because of readpage */
11525 + .write_begin = aufs_write_begin,
11526 + .write_end = aufs_write_end,
11527 + /* no bmap, no block device */
11528 + .invalidatepage = aufs_invalidatepage,
11529 + .releasepage = aufs_releasepage,
11530 + .migratepage = aufs_migratepage,
11531 + .launder_page = aufs_launder_page,
11532 + .is_partially_uptodate = aufs_is_partially_uptodate,
11533 + .is_dirty_writeback = aufs_is_dirty_writeback,
11534 + .error_remove_page = aufs_error_remove_page,
11535 + .swap_activate = aufs_swap_activate,
11536 + .swap_deactivate = aufs_swap_deactivate
11537 +#endif /* CONFIG_AUFS_DEBUG */
11539 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
11540 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
11541 +++ linux/fs/aufs/file.h 2014-06-24 00:14:06.782719306 +0200
11544 + * Copyright (C) 2005-2014 Junjiro R. Okajima
11546 + * This program, aufs is free software; you can redistribute it and/or modify
11547 + * it under the terms of the GNU General Public License as published by
11548 + * the Free Software Foundation; either version 2 of the License, or
11549 + * (at your option) any later version.
11551 + * This program is distributed in the hope that it will be useful,
11552 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11553 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11554 + * GNU General Public License for more details.
11556 + * You should have received a copy of the GNU General Public License
11557 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11561 + * file operations
11564 +#ifndef __AUFS_FILE_H__
11565 +#define __AUFS_FILE_H__
11569 +#include <linux/file.h>
11570 +#include <linux/fs.h>
11571 +#include <linux/poll.h>
11572 +#include "rwsem.h"
11576 + struct file *hf_file;
11577 + struct au_branch *hf_br;
11582 + aufs_bindex_t fd_bbot;
11583 + aufs_bindex_t fd_nent;
11584 + struct au_vdir *fd_vdir_cache;
11585 + struct au_hfile fd_hfile[];
11588 +static inline int au_fidir_sz(int nent)
11590 + AuDebugOn(nent < 0);
11591 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
11595 + atomic_t fi_generation;
11597 + struct au_rwsem fi_rwsem;
11598 + aufs_bindex_t fi_btop;
11600 + /* do not union them */
11601 + struct { /* for non-dir */
11602 + struct au_hfile fi_htop;
11603 + atomic_t fi_mmapped;
11605 + struct au_fidir *fi_hdir; /* for dir only */
11607 + struct hlist_node fi_hlist;
11608 + struct file *fi_file; /* very ugly */
11609 +} ____cacheline_aligned_in_smp;
11611 +/* ---------------------------------------------------------------------- */
11614 +extern const struct address_space_operations aufs_aop;
11615 +unsigned int au_file_roflags(unsigned int flags);
11616 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
11617 + struct file *file, int force_wr);
11618 +int au_do_open(struct file *file, int (*open)(struct file *file, int flags),
11619 + struct au_fidir *fidir);
11620 +int au_reopen_nondir(struct file *file);
11622 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
11623 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
11625 +int au_do_flush(struct file *file, fl_owner_t id,
11626 + int (*flush)(struct file *file, fl_owner_t id));
11629 +#ifdef CONFIG_AUFS_POLL
11630 +unsigned int aufs_poll(struct file *file, poll_table *wait);
11633 +#ifdef CONFIG_AUFS_BR_HFSPLUS
11635 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
11637 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
11638 + struct file *h_file);
11641 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
11647 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
11648 + struct file *h_file);
11652 +extern const struct file_operations aufs_file_fop;
11653 +int au_do_open_nondir(struct file *file, int flags);
11654 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
11657 +void au_hfput(struct au_hfile *hf, struct file *file);
11658 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
11659 + struct file *h_file);
11661 +void au_update_figen(struct file *file);
11662 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
11663 +int au_fidir_realloc(struct au_finfo *finfo, int nbr);
11665 +void au_fi_init_once(void *_fi);
11666 +void au_finfo_fin(struct file *file);
11667 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
11670 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
11671 +#ifdef CONFIG_COMPAT
11672 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
11673 + unsigned long arg);
11674 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
11675 + unsigned long arg);
11678 +/* ---------------------------------------------------------------------- */
11680 +static inline struct au_finfo *au_fi(struct file *file)
11682 + return file->private_data;
11685 +/* ---------------------------------------------------------------------- */
11688 + * fi_read_lock, fi_write_lock,
11689 + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock
11691 +AuSimpleRwsemFuncs(fi, struct file *f, &au_fi(f)->fi_rwsem);
11693 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
11694 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
11695 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
11697 +/* ---------------------------------------------------------------------- */
11699 +/* todo: hard/soft set? */
11700 +static inline aufs_bindex_t au_fbstart(struct file *file)
11702 + FiMustAnyLock(file);
11703 + return au_fi(file)->fi_btop;
11706 +static inline aufs_bindex_t au_fbend_dir(struct file *file)
11708 + FiMustAnyLock(file);
11709 + AuDebugOn(!au_fi(file)->fi_hdir);
11710 + return au_fi(file)->fi_hdir->fd_bbot;
11713 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
11715 + FiMustAnyLock(file);
11716 + AuDebugOn(!au_fi(file)->fi_hdir);
11717 + return au_fi(file)->fi_hdir->fd_vdir_cache;
11720 +static inline void au_set_fbstart(struct file *file, aufs_bindex_t bindex)
11722 + FiMustWriteLock(file);
11723 + au_fi(file)->fi_btop = bindex;
11726 +static inline void au_set_fbend_dir(struct file *file, aufs_bindex_t bindex)
11728 + FiMustWriteLock(file);
11729 + AuDebugOn(!au_fi(file)->fi_hdir);
11730 + au_fi(file)->fi_hdir->fd_bbot = bindex;
11733 +static inline void au_set_fvdir_cache(struct file *file,
11734 + struct au_vdir *vdir_cache)
11736 + FiMustWriteLock(file);
11737 + AuDebugOn(!au_fi(file)->fi_hdir);
11738 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
11741 +static inline struct file *au_hf_top(struct file *file)
11743 + FiMustAnyLock(file);
11744 + AuDebugOn(au_fi(file)->fi_hdir);
11745 + return au_fi(file)->fi_htop.hf_file;
11748 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
11750 + FiMustAnyLock(file);
11751 + AuDebugOn(!au_fi(file)->fi_hdir);
11752 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
11755 +/* todo: memory barrier? */
11756 +static inline unsigned int au_figen(struct file *f)
11758 + return atomic_read(&au_fi(f)->fi_generation);
11761 +static inline void au_set_mmapped(struct file *f)
11763 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
11765 + pr_warn("fi_mmapped wrapped around\n");
11766 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
11770 +static inline void au_unset_mmapped(struct file *f)
11772 + atomic_dec(&au_fi(f)->fi_mmapped);
11775 +static inline int au_test_mmapped(struct file *f)
11777 + return atomic_read(&au_fi(f)->fi_mmapped);
11780 +/* customize vma->vm_file */
11782 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
11783 + struct file *file)
11787 + f = vma->vm_file;
11789 + vma->vm_file = file;
11794 +#define AuDbgVmRegion(file, vma) do {} while (0)
11796 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
11797 + struct file *file)
11799 + au_do_vm_file_reset(vma, file);
11802 +#define AuDbgVmRegion(file, vma) \
11803 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
11805 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
11806 + struct file *file)
11810 + au_do_vm_file_reset(vma, file);
11811 + f = vma->vm_region->vm_file;
11813 + vma->vm_region->vm_file = file;
11816 +#endif /* CONFIG_MMU */
11818 +/* handle vma->vm_prfile */
11819 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
11820 + struct file *file)
11823 + vma->vm_prfile = file;
11824 +#ifndef CONFIG_MMU
11826 + vma->vm_region->vm_prfile = file;
11830 +#endif /* __KERNEL__ */
11831 +#endif /* __AUFS_FILE_H__ */
11832 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
11833 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
11834 +++ linux/fs/aufs/finfo.c 2014-06-24 00:14:06.782719306 +0200
11837 + * Copyright (C) 2005-2014 Junjiro R. Okajima
11839 + * This program, aufs is free software; you can redistribute it and/or modify
11840 + * it under the terms of the GNU General Public License as published by
11841 + * the Free Software Foundation; either version 2 of the License, or
11842 + * (at your option) any later version.
11844 + * This program is distributed in the hope that it will be useful,
11845 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11846 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11847 + * GNU General Public License for more details.
11849 + * You should have received a copy of the GNU General Public License
11850 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11854 + * file private data
11859 +void au_hfput(struct au_hfile *hf, struct file *file)
11861 + /* todo: direct access f_flags */
11862 + if (vfsub_file_flags(file) & __FMODE_EXEC)
11863 + allow_write_access(hf->hf_file);
11864 + fput(hf->hf_file);
11865 + hf->hf_file = NULL;
11866 + atomic_dec(&hf->hf_br->br_count);
11867 + hf->hf_br = NULL;
11870 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
11872 + struct au_finfo *finfo = au_fi(file);
11873 + struct au_hfile *hf;
11874 + struct au_fidir *fidir;
11876 + fidir = finfo->fi_hdir;
11878 + AuDebugOn(finfo->fi_btop != bindex);
11879 + hf = &finfo->fi_htop;
11881 + hf = fidir->fd_hfile + bindex;
11883 + if (hf && hf->hf_file)
11884 + au_hfput(hf, file);
11886 + FiMustWriteLock(file);
11887 + hf->hf_file = val;
11888 + hf->hf_br = au_sbr(file->f_dentry->d_sb, bindex);
11892 +void au_update_figen(struct file *file)
11894 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_dentry));
11895 + /* smp_mb(); */ /* atomic_set */
11898 +/* ---------------------------------------------------------------------- */
11900 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
11902 + struct au_fidir *fidir;
11905 + nbr = au_sbend(sb) + 1;
11907 + nbr = 2; /* initial allocate for 2 branches */
11908 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
11910 + fidir->fd_bbot = -1;
11911 + fidir->fd_nent = nbr;
11912 + fidir->fd_vdir_cache = NULL;
11918 +int au_fidir_realloc(struct au_finfo *finfo, int nbr)
11921 + struct au_fidir *fidir, *p;
11923 + AuRwMustWriteLock(&finfo->fi_rwsem);
11924 + fidir = finfo->fi_hdir;
11925 + AuDebugOn(!fidir);
11928 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
11931 + p->fd_nent = nbr;
11932 + finfo->fi_hdir = p;
11939 +/* ---------------------------------------------------------------------- */
11941 +void au_finfo_fin(struct file *file)
11943 + struct au_finfo *finfo;
11945 + au_nfiles_dec(file->f_dentry->d_sb);
11947 + finfo = au_fi(file);
11948 + AuDebugOn(finfo->fi_hdir);
11949 + AuRwDestroy(&finfo->fi_rwsem);
11950 + au_cache_free_finfo(finfo);
11953 +void au_fi_init_once(void *_finfo)
11955 + struct au_finfo *finfo = _finfo;
11956 + static struct lock_class_key aufs_fi;
11958 + au_rw_init(&finfo->fi_rwsem);
11959 + au_rw_class(&finfo->fi_rwsem, &aufs_fi);
11962 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
11965 + struct au_finfo *finfo;
11966 + struct dentry *dentry;
11969 + dentry = file->f_dentry;
11970 + finfo = au_cache_alloc_finfo();
11971 + if (unlikely(!finfo))
11975 + au_nfiles_inc(dentry->d_sb);
11976 + /* verbose coding for lock class name */
11978 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcNonDir_FIINFO);
11980 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcDir_FIINFO);
11981 + au_rw_write_lock(&finfo->fi_rwsem);
11982 + finfo->fi_btop = -1;
11983 + finfo->fi_hdir = fidir;
11984 + atomic_set(&finfo->fi_generation, au_digen(dentry));
11985 + /* smp_mb(); */ /* atomic_set */
11987 + file->private_data = finfo;
11992 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
11993 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
11994 +++ linux/fs/aufs/f_op.c 2014-06-24 00:14:06.782719306 +0200
11997 + * Copyright (C) 2005-2014 Junjiro R. Okajima
11999 + * This program, aufs is free software; you can redistribute it and/or modify
12000 + * it under the terms of the GNU General Public License as published by
12001 + * the Free Software Foundation; either version 2 of the License, or
12002 + * (at your option) any later version.
12004 + * This program is distributed in the hope that it will be useful,
12005 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12006 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12007 + * GNU General Public License for more details.
12009 + * You should have received a copy of the GNU General Public License
12010 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12014 + * file and vm operations
12017 +#include <linux/aio.h>
12018 +#include <linux/fs_stack.h>
12019 +#include <linux/mman.h>
12020 +#include <linux/security.h>
12023 +int au_do_open_nondir(struct file *file, int flags)
12026 + aufs_bindex_t bindex;
12027 + struct file *h_file;
12028 + struct dentry *dentry;
12029 + struct au_finfo *finfo;
12030 + struct inode *h_inode;
12032 + FiMustWriteLock(file);
12035 + dentry = file->f_dentry;
12036 + finfo = au_fi(file);
12037 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
12038 + atomic_set(&finfo->fi_mmapped, 0);
12039 + bindex = au_dbstart(dentry);
12040 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
12041 + if (IS_ERR(h_file))
12042 + err = PTR_ERR(h_file);
12044 + if ((flags & __O_TMPFILE)
12045 + && !(flags & O_EXCL)) {
12046 + h_inode = file_inode(h_file);
12047 + spin_lock(&h_inode->i_lock);
12048 + h_inode->i_state |= I_LINKABLE;
12049 + spin_unlock(&h_inode->i_lock);
12051 + au_set_fbstart(file, bindex);
12052 + au_set_h_fptr(file, bindex, h_file);
12053 + au_update_figen(file);
12054 + finfo->fi_file = file;
12055 + au_sphl_add(&finfo->fi_hlist, &au_sbi(dentry->d_sb)->si_files);
12056 + /* todo: necessary? */
12057 + /* file->f_ra = h_file->f_ra; */
12063 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
12064 + struct file *file)
12067 + struct super_block *sb;
12069 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
12070 + file, vfsub_file_flags(file), file->f_mode);
12072 + sb = file->f_dentry->d_sb;
12073 + si_read_lock(sb, AuLock_FLUSH);
12074 + err = au_do_open(file, au_do_open_nondir, /*fidir*/NULL);
12075 + si_read_unlock(sb);
12079 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
12081 + struct au_finfo *finfo;
12082 + aufs_bindex_t bindex;
12084 + finfo = au_fi(file);
12085 + au_sphl_del(&finfo->fi_hlist, &au_sbi(file->f_dentry->d_sb)->si_files);
12086 + bindex = finfo->fi_btop;
12088 + au_set_h_fptr(file, bindex, NULL);
12090 + au_finfo_fin(file);
12094 +/* ---------------------------------------------------------------------- */
12096 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
12099 + struct file *h_file;
12102 + h_file = au_hf_top(file);
12104 + err = vfsub_flush(h_file, id);
12108 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
12110 + return au_do_flush(file, id, au_do_flush_nondir);
12113 +/* ---------------------------------------------------------------------- */
12115 + * read and write functions acquire [fdi]_rwsem once, but release before
12116 + * mmap_sem. This is because to stop a race condition between mmap(2).
12117 + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping
12118 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
12119 + * read functions after [fdi]_rwsem are released, but it should be harmless.
12122 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
12126 + struct dentry *dentry;
12127 + struct file *h_file;
12128 + struct super_block *sb;
12130 + dentry = file->f_dentry;
12131 + sb = dentry->d_sb;
12132 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
12133 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
12134 + if (unlikely(err))
12137 + h_file = au_hf_top(file);
12138 + get_file(h_file);
12139 + di_read_unlock(dentry, AuLock_IR);
12140 + fi_read_unlock(file);
12142 + /* filedata may be obsoleted by concurrent copyup, but no problem */
12143 + err = vfsub_read_u(h_file, buf, count, ppos);
12144 + /* todo: necessary? */
12145 + /* file->f_ra = h_file->f_ra; */
12146 + /* update without lock, I don't think it a problem */
12147 + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
12151 + si_read_unlock(sb);
12156 + * todo: very ugly
12157 + * it locks both of i_mutex and si_rwsem for read in safe.
12158 + * if the plink maintenance mode continues forever (that is the problem),
12159 + * may loop forever.
12161 +static void au_mtx_and_read_lock(struct inode *inode)
12164 + struct super_block *sb = inode->i_sb;
12167 + mutex_lock(&inode->i_mutex);
12168 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
12171 + mutex_unlock(&inode->i_mutex);
12172 + si_read_lock(sb, AuLock_NOPLMW);
12173 + si_read_unlock(sb);
12177 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
12178 + size_t count, loff_t *ppos)
12181 + struct au_pin pin;
12182 + struct dentry *dentry;
12183 + struct super_block *sb;
12184 + struct inode *inode;
12185 + struct file *h_file;
12186 + char __user *buf = (char __user *)ubuf;
12188 + dentry = file->f_dentry;
12189 + sb = dentry->d_sb;
12190 + inode = dentry->d_inode;
12191 + au_mtx_and_read_lock(inode);
12193 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
12194 + if (unlikely(err))
12197 + err = au_ready_to_write(file, -1, &pin);
12198 + di_downgrade_lock(dentry, AuLock_IR);
12199 + if (unlikely(err)) {
12200 + di_read_unlock(dentry, AuLock_IR);
12201 + fi_write_unlock(file);
12205 + h_file = au_hf_top(file);
12206 + get_file(h_file);
12208 + di_read_unlock(dentry, AuLock_IR);
12209 + fi_write_unlock(file);
12211 + err = vfsub_write_u(h_file, buf, count, ppos);
12212 + ii_write_lock_child(inode);
12213 + au_cpup_attr_timesizes(inode);
12214 + inode->i_mode = file_inode(h_file)->i_mode;
12215 + ii_write_unlock(inode);
12219 + si_read_unlock(sb);
12220 + mutex_unlock(&inode->i_mutex);
12224 +static ssize_t au_do_aio(struct file *h_file, int rw, struct kiocb *kio,
12225 + const struct iovec *iov, unsigned long nv, loff_t pos)
12228 + struct file *file;
12229 + ssize_t (*func)(struct kiocb *, const struct iovec *, unsigned long,
12232 + err = security_file_permission(h_file, rw);
12233 + if (unlikely(err))
12238 + if (rw == MAY_READ)
12239 + func = h_file->f_op->aio_read;
12240 + else if (rw == MAY_WRITE)
12241 + func = h_file->f_op->aio_write;
12243 + file = kio->ki_filp;
12244 + kio->ki_filp = h_file;
12246 + err = func(kio, iov, nv, pos);
12248 + kio->ki_filp = file;
12250 + /* currently there is no such fs */
12257 +static ssize_t aufs_aio_read(struct kiocb *kio, const struct iovec *iov,
12258 + unsigned long nv, loff_t pos)
12261 + struct file *file, *h_file;
12262 + struct dentry *dentry;
12263 + struct super_block *sb;
12265 + file = kio->ki_filp;
12266 + dentry = file->f_dentry;
12267 + sb = dentry->d_sb;
12268 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
12269 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
12270 + if (unlikely(err))
12273 + h_file = au_hf_top(file);
12274 + get_file(h_file);
12275 + di_read_unlock(dentry, AuLock_IR);
12276 + fi_read_unlock(file);
12278 + err = au_do_aio(h_file, MAY_READ, kio, iov, nv, pos);
12279 + /* todo: necessary? */
12280 + /* file->f_ra = h_file->f_ra; */
12281 + /* update without lock, I don't think it a problem */
12282 + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
12286 + si_read_unlock(sb);
12290 +static ssize_t aufs_aio_write(struct kiocb *kio, const struct iovec *iov,
12291 + unsigned long nv, loff_t pos)
12294 + struct au_pin pin;
12295 + struct dentry *dentry;
12296 + struct inode *inode;
12297 + struct file *file, *h_file;
12298 + struct super_block *sb;
12300 + file = kio->ki_filp;
12301 + dentry = file->f_dentry;
12302 + sb = dentry->d_sb;
12303 + inode = dentry->d_inode;
12304 + au_mtx_and_read_lock(inode);
12306 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
12307 + if (unlikely(err))
12310 + err = au_ready_to_write(file, -1, &pin);
12311 + di_downgrade_lock(dentry, AuLock_IR);
12312 + if (unlikely(err)) {
12313 + di_read_unlock(dentry, AuLock_IR);
12314 + fi_write_unlock(file);
12318 + h_file = au_hf_top(file);
12319 + get_file(h_file);
12321 + di_read_unlock(dentry, AuLock_IR);
12322 + fi_write_unlock(file);
12324 + err = au_do_aio(h_file, MAY_WRITE, kio, iov, nv, pos);
12325 + ii_write_lock_child(inode);
12326 + au_cpup_attr_timesizes(inode);
12327 + inode->i_mode = file_inode(h_file)->i_mode;
12328 + ii_write_unlock(inode);
12332 + si_read_unlock(sb);
12333 + mutex_unlock(&inode->i_mutex);
12337 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
12338 + struct pipe_inode_info *pipe, size_t len,
12339 + unsigned int flags)
12342 + struct file *h_file;
12343 + struct dentry *dentry;
12344 + struct super_block *sb;
12346 + dentry = file->f_dentry;
12347 + sb = dentry->d_sb;
12348 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
12349 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
12350 + if (unlikely(err))
12354 + h_file = au_hf_top(file);
12355 + get_file(h_file);
12356 + if (au_test_loopback_kthread()) {
12357 + au_warn_loopback(h_file->f_dentry->d_sb);
12358 + if (file->f_mapping != h_file->f_mapping) {
12359 + file->f_mapping = h_file->f_mapping;
12360 + smp_mb(); /* unnecessary? */
12363 + di_read_unlock(dentry, AuLock_IR);
12364 + fi_read_unlock(file);
12366 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
12367 + /* todo: necessasry? */
12368 + /* file->f_ra = h_file->f_ra; */
12369 + /* update without lock, I don't think it a problem */
12370 + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
12374 + si_read_unlock(sb);
12379 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
12380 + size_t len, unsigned int flags)
12383 + struct au_pin pin;
12384 + struct dentry *dentry;
12385 + struct inode *inode;
12386 + struct file *h_file;
12387 + struct super_block *sb;
12389 + dentry = file->f_dentry;
12390 + sb = dentry->d_sb;
12391 + inode = dentry->d_inode;
12392 + au_mtx_and_read_lock(inode);
12394 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
12395 + if (unlikely(err))
12398 + err = au_ready_to_write(file, -1, &pin);
12399 + di_downgrade_lock(dentry, AuLock_IR);
12400 + if (unlikely(err)) {
12401 + di_read_unlock(dentry, AuLock_IR);
12402 + fi_write_unlock(file);
12406 + h_file = au_hf_top(file);
12407 + get_file(h_file);
12409 + di_read_unlock(dentry, AuLock_IR);
12410 + fi_write_unlock(file);
12412 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
12413 + ii_write_lock_child(inode);
12414 + au_cpup_attr_timesizes(inode);
12415 + inode->i_mode = file_inode(h_file)->i_mode;
12416 + ii_write_unlock(inode);
12420 + si_read_unlock(sb);
12421 + mutex_unlock(&inode->i_mutex);
12425 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
12429 + struct au_pin pin;
12430 + struct dentry *dentry;
12431 + struct super_block *sb;
12432 + struct inode *inode;
12433 + struct file *h_file;
12435 + dentry = file->f_dentry;
12436 + sb = dentry->d_sb;
12437 + inode = dentry->d_inode;
12438 + au_mtx_and_read_lock(inode);
12440 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
12441 + if (unlikely(err))
12444 + err = au_ready_to_write(file, -1, &pin);
12445 + di_downgrade_lock(dentry, AuLock_IR);
12446 + if (unlikely(err)) {
12447 + di_read_unlock(dentry, AuLock_IR);
12448 + fi_write_unlock(file);
12452 + h_file = au_hf_top(file);
12453 + get_file(h_file);
12455 + di_read_unlock(dentry, AuLock_IR);
12456 + fi_write_unlock(file);
12459 + err = do_fallocate(h_file, mode, offset, len);
12461 + ii_write_lock_child(inode);
12462 + au_cpup_attr_timesizes(inode);
12463 + inode->i_mode = file_inode(h_file)->i_mode;
12464 + ii_write_unlock(inode);
12468 + si_read_unlock(sb);
12469 + mutex_unlock(&inode->i_mutex);
12473 +/* ---------------------------------------------------------------------- */
12476 + * The locking order around current->mmap_sem.
12477 + * - in most and regular cases
12478 + * file I/O syscall -- aufs_read() or something
12479 + * -- si_rwsem for read -- mmap_sem
12480 + * (Note that [fdi]i_rwsem are released before mmap_sem).
12482 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
12483 + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
12484 + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
12485 + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
12486 + * It means that when aufs acquires si_rwsem for write, the process should never
12487 + * acquire mmap_sem.
12489 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
12490 + * problem either since any directory is not able to be mmap-ed.
12491 + * The similar scenario is applied to aufs_readlink() too.
12494 +#if 0 /* stop calling security_file_mmap() */
12495 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
12496 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
12498 +static unsigned long au_arch_prot_conv(unsigned long flags)
12500 + /* currently ppc64 only */
12501 +#ifdef CONFIG_PPC64
12502 + /* cf. linux/arch/powerpc/include/asm/mman.h */
12503 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
12504 + return AuConv_VM_PROT(flags, SAO);
12506 + AuDebugOn(arch_calc_vm_prot_bits(-1));
12511 +static unsigned long au_prot_conv(unsigned long flags)
12513 + return AuConv_VM_PROT(flags, READ)
12514 + | AuConv_VM_PROT(flags, WRITE)
12515 + | AuConv_VM_PROT(flags, EXEC)
12516 + | au_arch_prot_conv(flags);
12519 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
12520 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
12522 +static unsigned long au_flag_conv(unsigned long flags)
12524 + return AuConv_VM_MAP(flags, GROWSDOWN)
12525 + | AuConv_VM_MAP(flags, DENYWRITE)
12526 + | AuConv_VM_MAP(flags, LOCKED);
12530 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
12533 + aufs_bindex_t bstart;
12534 + const unsigned char wlock
12535 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
12536 + struct dentry *dentry;
12537 + struct super_block *sb;
12538 + struct file *h_file;
12539 + struct au_branch *br;
12540 + struct au_pin pin;
12542 + AuDbgVmRegion(file, vma);
12544 + dentry = file->f_dentry;
12545 + sb = dentry->d_sb;
12547 + si_read_lock(sb, AuLock_NOPLMW);
12548 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
12549 + if (unlikely(err))
12553 + err = au_ready_to_write(file, -1, &pin);
12554 + di_write_unlock(dentry);
12555 + if (unlikely(err)) {
12556 + fi_write_unlock(file);
12561 + di_write_unlock(dentry);
12563 + bstart = au_fbstart(file);
12564 + br = au_sbr(sb, bstart);
12565 + h_file = au_hf_top(file);
12566 + get_file(h_file);
12567 + au_set_mmapped(file);
12568 + fi_write_unlock(file);
12571 + au_vm_file_reset(vma, h_file);
12573 + * we cannot call security_mmap_file() here since it may acquire
12574 + * mmap_sem or i_mutex.
12576 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
12577 + * au_flag_conv(vma->vm_flags));
12580 + err = h_file->f_op->mmap(h_file, vma);
12581 + if (unlikely(err))
12584 + au_vm_prfile_set(vma, file);
12585 + /* update without lock, I don't think it a problem */
12586 + fsstack_copy_attr_atime(file_inode(file), file_inode(h_file));
12587 + goto out_fput; /* success */
12590 + au_unset_mmapped(file);
12591 + au_vm_file_reset(vma, file);
12596 + si_read_unlock(sb);
12602 +/* ---------------------------------------------------------------------- */
12604 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
12608 + struct au_pin pin;
12609 + struct dentry *dentry;
12610 + struct inode *inode;
12611 + struct file *h_file;
12612 + struct super_block *sb;
12614 + dentry = file->f_dentry;
12615 + inode = dentry->d_inode;
12616 + sb = dentry->d_sb;
12617 + mutex_lock(&inode->i_mutex);
12618 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
12619 + if (unlikely(err))
12622 + err = 0; /* -EBADF; */ /* posix? */
12623 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
12625 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
12626 + if (unlikely(err))
12629 + err = au_ready_to_write(file, -1, &pin);
12630 + di_downgrade_lock(dentry, AuLock_IR);
12631 + if (unlikely(err))
12636 + h_file = au_hf_top(file);
12637 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
12638 + au_cpup_attr_timesizes(inode);
12641 + di_read_unlock(dentry, AuLock_IR);
12642 + fi_write_unlock(file);
12644 + si_read_unlock(sb);
12646 + mutex_unlock(&inode->i_mutex);
12650 +/* no one supports this operation, currently */
12652 +static int aufs_aio_fsync_nondir(struct kiocb *kio, int datasync)
12655 + struct au_pin pin;
12656 + struct dentry *dentry;
12657 + struct inode *inode;
12658 + struct file *file, *h_file;
12660 + file = kio->ki_filp;
12661 + dentry = file->f_dentry;
12662 + inode = dentry->d_inode;
12663 + au_mtx_and_read_lock(inode);
12665 + err = 0; /* -EBADF; */ /* posix? */
12666 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
12668 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
12669 + if (unlikely(err))
12672 + err = au_ready_to_write(file, -1, &pin);
12673 + di_downgrade_lock(dentry, AuLock_IR);
12674 + if (unlikely(err))
12679 + h_file = au_hf_top(file);
12680 + if (h_file->f_op->aio_fsync) {
12681 + struct mutex *h_mtx;
12683 + h_mtx = &file_inode(h_file)->i_mutex;
12684 + if (!is_sync_kiocb(kio)) {
12685 + get_file(h_file);
12688 + kio->ki_filp = h_file;
12689 + err = h_file->f_op->aio_fsync(kio, datasync);
12690 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
12692 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL);
12694 + au_cpup_attr_timesizes(inode);
12695 + mutex_unlock(h_mtx);
12699 + di_read_unlock(dentry, AuLock_IR);
12700 + fi_write_unlock(file);
12702 + si_read_unlock(inode->sb);
12703 + mutex_unlock(&inode->i_mutex);
12708 +static int aufs_fasync(int fd, struct file *file, int flag)
12711 + struct file *h_file;
12712 + struct dentry *dentry;
12713 + struct super_block *sb;
12715 + dentry = file->f_dentry;
12716 + sb = dentry->d_sb;
12717 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
12718 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
12719 + if (unlikely(err))
12722 + h_file = au_hf_top(file);
12723 + if (h_file->f_op->fasync)
12724 + err = h_file->f_op->fasync(fd, h_file, flag);
12726 + di_read_unlock(dentry, AuLock_IR);
12727 + fi_read_unlock(file);
12730 + si_read_unlock(sb);
12734 +/* ---------------------------------------------------------------------- */
12736 +/* no one supports this operation, currently */
12738 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
12739 + size_t len, loff_t *pos , int more)
12744 +/* ---------------------------------------------------------------------- */
12746 +const struct file_operations aufs_file_fop = {
12747 + .owner = THIS_MODULE,
12749 + .llseek = default_llseek,
12751 + .read = aufs_read,
12752 + .write = aufs_write,
12753 + .aio_read = aufs_aio_read,
12754 + .aio_write = aufs_aio_write,
12755 +#ifdef CONFIG_AUFS_POLL
12756 + .poll = aufs_poll,
12758 + .unlocked_ioctl = aufs_ioctl_nondir,
12759 +#ifdef CONFIG_COMPAT
12760 + .compat_ioctl = aufs_compat_ioctl_nondir,
12762 + .mmap = aufs_mmap,
12763 + .open = aufs_open_nondir,
12764 + .flush = aufs_flush_nondir,
12765 + .release = aufs_release_nondir,
12766 + .fsync = aufs_fsync_nondir,
12767 + /* .aio_fsync = aufs_aio_fsync_nondir, */
12768 + .fasync = aufs_fasync,
12769 + /* .sendpage = aufs_sendpage, */
12770 + .splice_write = aufs_splice_write,
12771 + .splice_read = aufs_splice_read,
12773 + .aio_splice_write = aufs_aio_splice_write,
12774 + .aio_splice_read = aufs_aio_splice_read,
12776 + .fallocate = aufs_fallocate
12778 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
12779 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
12780 +++ linux/fs/aufs/fstype.h 2014-06-24 00:14:06.782719306 +0200
12783 + * Copyright (C) 2005-2014 Junjiro R. Okajima
12785 + * This program, aufs is free software; you can redistribute it and/or modify
12786 + * it under the terms of the GNU General Public License as published by
12787 + * the Free Software Foundation; either version 2 of the License, or
12788 + * (at your option) any later version.
12790 + * This program is distributed in the hope that it will be useful,
12791 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12792 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12793 + * GNU General Public License for more details.
12795 + * You should have received a copy of the GNU General Public License
12796 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12800 + * judging filesystem type
12803 +#ifndef __AUFS_FSTYPE_H__
12804 +#define __AUFS_FSTYPE_H__
12808 +#include <linux/fs.h>
12809 +#include <linux/magic.h>
12810 +#include <linux/romfs_fs.h>
12812 +static inline int au_test_aufs(struct super_block *sb)
12814 + return sb->s_magic == AUFS_SUPER_MAGIC;
12817 +static inline const char *au_sbtype(struct super_block *sb)
12819 + return sb->s_type->name;
12822 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
12824 +#if defined(CONFIG_ROMFS_FS) || defined(CONFIG_ROMFS_FS_MODULE)
12825 + return sb->s_magic == ROMFS_MAGIC;
12831 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
12833 +#if defined(CONFIG_ISO9660_FS) || defined(CONFIG_ISO9660_FS_MODULE)
12834 + return sb->s_magic == ISOFS_SUPER_MAGIC;
12840 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
12842 +#if defined(CONFIG_CRAMFS) || defined(CONFIG_CRAMFS_MODULE)
12843 + return sb->s_magic == CRAMFS_MAGIC;
12848 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
12850 +#if defined(CONFIG_NFS_FS) || defined(CONFIG_NFS_FS_MODULE)
12851 + return sb->s_magic == NFS_SUPER_MAGIC;
12857 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
12859 +#if defined(CONFIG_FUSE_FS) || defined(CONFIG_FUSE_FS_MODULE)
12860 + return sb->s_magic == FUSE_SUPER_MAGIC;
12866 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
12868 +#if defined(CONFIG_XFS_FS) || defined(CONFIG_XFS_FS_MODULE)
12869 + return sb->s_magic == XFS_SB_MAGIC;
12875 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
12877 +#ifdef CONFIG_TMPFS
12878 + return sb->s_magic == TMPFS_MAGIC;
12884 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
12886 +#if defined(CONFIG_ECRYPT_FS) || defined(CONFIG_ECRYPT_FS_MODULE)
12887 + return !strcmp(au_sbtype(sb), "ecryptfs");
12893 +static inline int au_test_ocfs2(struct super_block *sb __maybe_unused)
12895 +#if defined(CONFIG_OCFS2_FS) || defined(CONFIG_OCFS2_FS_MODULE)
12896 + return sb->s_magic == OCFS2_SUPER_MAGIC;
12902 +static inline int au_test_ocfs2_dlmfs(struct super_block *sb __maybe_unused)
12904 +#if defined(CONFIG_OCFS2_FS_O2CB) || defined(CONFIG_OCFS2_FS_O2CB_MODULE)
12905 + return sb->s_magic == DLMFS_MAGIC;
12911 +static inline int au_test_coda(struct super_block *sb __maybe_unused)
12913 +#if defined(CONFIG_CODA_FS) || defined(CONFIG_CODA_FS_MODULE)
12914 + return sb->s_magic == CODA_SUPER_MAGIC;
12920 +static inline int au_test_v9fs(struct super_block *sb __maybe_unused)
12922 +#if defined(CONFIG_9P_FS) || defined(CONFIG_9P_FS_MODULE)
12923 + return sb->s_magic == V9FS_MAGIC;
12929 +static inline int au_test_ext4(struct super_block *sb __maybe_unused)
12931 +#if defined(CONFIG_EXT4_FS) || defined(CONFIG_EXT4_FS_MODULE)
12932 + return sb->s_magic == EXT4_SUPER_MAGIC;
12938 +static inline int au_test_sysv(struct super_block *sb __maybe_unused)
12940 +#if defined(CONFIG_SYSV_FS) || defined(CONFIG_SYSV_FS_MODULE)
12941 + return !strcmp(au_sbtype(sb), "sysv");
12947 +static inline int au_test_ramfs(struct super_block *sb)
12949 + return sb->s_magic == RAMFS_MAGIC;
12952 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
12954 +#if defined(CONFIG_UBIFS_FS) || defined(CONFIG_UBIFS_FS_MODULE)
12955 + return sb->s_magic == UBIFS_SUPER_MAGIC;
12961 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
12963 +#ifdef CONFIG_PROC_FS
12964 + return sb->s_magic == PROC_SUPER_MAGIC;
12970 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
12972 +#ifdef CONFIG_SYSFS
12973 + return sb->s_magic == SYSFS_MAGIC;
12979 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
12981 +#if defined(CONFIG_CONFIGFS_FS) || defined(CONFIG_CONFIGFS_FS_MODULE)
12982 + return sb->s_magic == CONFIGFS_MAGIC;
12988 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
12990 +#if defined(CONFIG_MINIX_FS) || defined(CONFIG_MINIX_FS_MODULE)
12991 + return sb->s_magic == MINIX3_SUPER_MAGIC
12992 + || sb->s_magic == MINIX2_SUPER_MAGIC
12993 + || sb->s_magic == MINIX2_SUPER_MAGIC2
12994 + || sb->s_magic == MINIX_SUPER_MAGIC
12995 + || sb->s_magic == MINIX_SUPER_MAGIC2;
13001 +static inline int au_test_cifs(struct super_block *sb __maybe_unused)
13003 +#if defined(CONFIG_CIFS_FS) || defined(CONFIGCIFS_FS_MODULE)
13004 + return sb->s_magic == CIFS_MAGIC_NUMBER;
13010 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
13012 +#if defined(CONFIG_FAT_FS) || defined(CONFIG_FAT_FS_MODULE)
13013 + return sb->s_magic == MSDOS_SUPER_MAGIC;
13019 +static inline int au_test_msdos(struct super_block *sb)
13021 + return au_test_fat(sb);
13024 +static inline int au_test_vfat(struct super_block *sb)
13026 + return au_test_fat(sb);
13029 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
13031 +#ifdef CONFIG_SECURITYFS
13032 + return sb->s_magic == SECURITYFS_MAGIC;
13038 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
13040 +#if defined(CONFIG_SQUASHFS) || defined(CONFIG_SQUASHFS_MODULE)
13041 + return sb->s_magic == SQUASHFS_MAGIC;
13047 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
13049 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
13050 + return sb->s_magic == BTRFS_SUPER_MAGIC;
13056 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
13058 +#if defined(CONFIG_XENFS) || defined(CONFIG_XENFS_MODULE)
13059 + return sb->s_magic == XENFS_SUPER_MAGIC;
13065 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
13067 +#ifdef CONFIG_DEBUG_FS
13068 + return sb->s_magic == DEBUGFS_MAGIC;
13074 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
13076 +#if defined(CONFIG_NILFS) || defined(CONFIG_NILFS_MODULE)
13077 + return sb->s_magic == NILFS_SUPER_MAGIC;
13083 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
13085 +#if defined(CONFIG_HFSPLUS_FS) || defined(CONFIG_HFSPLUS_FS_MODULE)
13086 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
13092 +/* ---------------------------------------------------------------------- */
13094 + * they can't be an aufs branch.
13096 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
13099 +#ifndef CONFIG_AUFS_BR_RAMFS
13100 + au_test_ramfs(sb) ||
13102 + au_test_procfs(sb)
13103 + || au_test_sysfs(sb)
13104 + || au_test_configfs(sb)
13105 + || au_test_debugfs(sb)
13106 + || au_test_securityfs(sb)
13107 + || au_test_xenfs(sb)
13108 + || au_test_ecryptfs(sb)
13109 + /* || !strcmp(au_sbtype(sb), "unionfs") */
13110 + || au_test_aufs(sb); /* will be supported in next version */
13113 +static inline int au_test_fs_remote(struct super_block *sb)
13115 + return !au_test_tmpfs(sb)
13116 +#ifdef CONFIG_AUFS_BR_RAMFS
13117 + && !au_test_ramfs(sb)
13119 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
13122 +/* ---------------------------------------------------------------------- */
13125 + * Note: these functions (below) are created after reading ->getattr() in all
13126 + * filesystems under linux/fs. it means we have to do so in every update...
13130 + * some filesystems require getattr to refresh the inode attributes before
13132 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
13133 + * and leave the work for d_revalidate()
13135 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
13137 + return au_test_nfs(sb)
13138 + || au_test_fuse(sb)
13139 + /* || au_test_ocfs2(sb) */ /* untested */
13140 + /* || au_test_btrfs(sb) */ /* untested */
13141 + /* || au_test_coda(sb) */ /* untested */
13142 + /* || au_test_v9fs(sb) */ /* untested */
13147 + * filesystems which don't maintain i_size or i_blocks.
13149 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
13151 + return au_test_xfs(sb)
13152 + || au_test_btrfs(sb)
13153 + || au_test_ubifs(sb)
13154 + || au_test_hfsplus(sb) /* maintained, but incorrect */
13155 + /* || au_test_ext4(sb) */ /* untested */
13156 + /* || au_test_ocfs2(sb) */ /* untested */
13157 + /* || au_test_ocfs2_dlmfs(sb) */ /* untested */
13158 + /* || au_test_sysv(sb) */ /* untested */
13159 + /* || au_test_minix(sb) */ /* untested */
13164 + * filesystems which don't store the correct value in some of their inode
13167 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
13169 + return au_test_fs_bad_iattr_size(sb)
13170 + /* || au_test_cifs(sb) */ /* untested */
13171 + || au_test_fat(sb)
13172 + || au_test_msdos(sb)
13173 + || au_test_vfat(sb);
13176 +/* they don't check i_nlink in link(2) */
13177 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
13179 + return au_test_tmpfs(sb)
13180 +#ifdef CONFIG_AUFS_BR_RAMFS
13181 + || au_test_ramfs(sb)
13183 + || au_test_ubifs(sb)
13184 + || au_test_hfsplus(sb);
13188 + * filesystems which sets S_NOATIME and S_NOCMTIME.
13190 +static inline int au_test_fs_notime(struct super_block *sb)
13192 + return au_test_nfs(sb)
13193 + || au_test_fuse(sb)
13194 + || au_test_ubifs(sb)
13195 + /* || au_test_cifs(sb) */ /* untested */
13200 + * filesystems which requires replacing i_mapping.
13202 +static inline int au_test_fs_bad_mapping(struct super_block *sb)
13204 + return au_test_fuse(sb)
13205 + || au_test_ubifs(sb);
13208 +/* temporary support for i#1 in cramfs */
13209 +static inline int au_test_fs_unique_ino(struct inode *inode)
13211 + if (au_test_cramfs(inode->i_sb))
13212 + return inode->i_ino != 1;
13216 +/* ---------------------------------------------------------------------- */
13219 + * the filesystem where the xino files placed must support i/o after unlink and
13220 + * maintain i_size and i_blocks.
13222 +static inline int au_test_fs_bad_xino(struct super_block *sb)
13224 + return au_test_fs_remote(sb)
13225 + || au_test_fs_bad_iattr_size(sb)
13226 + /* don't want unnecessary work for xino */
13227 + || au_test_aufs(sb)
13228 + || au_test_ecryptfs(sb)
13229 + || au_test_nilfs(sb);
13232 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
13234 + return au_test_tmpfs(sb)
13235 + || au_test_ramfs(sb);
13239 + * test if the @sb is real-readonly.
13241 +static inline int au_test_fs_rr(struct super_block *sb)
13243 + return au_test_squashfs(sb)
13244 + || au_test_iso9660(sb)
13245 + || au_test_cramfs(sb)
13246 + || au_test_romfs(sb);
13249 +#endif /* __KERNEL__ */
13250 +#endif /* __AUFS_FSTYPE_H__ */
13251 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
13252 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
13253 +++ linux/fs/aufs/hfsnotify.c 2014-06-24 00:14:06.782719306 +0200
13256 + * Copyright (C) 2005-2014 Junjiro R. Okajima
13258 + * This program, aufs is free software; you can redistribute it and/or modify
13259 + * it under the terms of the GNU General Public License as published by
13260 + * the Free Software Foundation; either version 2 of the License, or
13261 + * (at your option) any later version.
13263 + * This program is distributed in the hope that it will be useful,
13264 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13265 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13266 + * GNU General Public License for more details.
13268 + * You should have received a copy of the GNU General Public License
13269 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13273 + * fsnotify for the lower directories
13278 +/* FS_IN_IGNORED is unnecessary */
13279 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
13280 + | FS_CREATE | FS_EVENT_ON_CHILD);
13281 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
13282 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
13284 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
13286 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
13289 + au_cache_free_hnotify(hn);
13290 + smp_mb__before_atomic_dec();
13291 + if (atomic64_dec_and_test(&au_hfsn_ifree))
13292 + wake_up(&au_hfsn_wq);
13295 +static int au_hfsn_alloc(struct au_hinode *hinode)
13298 + struct au_hnotify *hn;
13299 + struct super_block *sb;
13300 + struct au_branch *br;
13301 + struct fsnotify_mark *mark;
13302 + aufs_bindex_t bindex;
13304 + hn = hinode->hi_notify;
13305 + sb = hn->hn_aufs_inode->i_sb;
13306 + bindex = au_br_index(sb, hinode->hi_id);
13307 + br = au_sbr(sb, bindex);
13308 + AuDebugOn(!br->br_hfsn);
13310 + mark = &hn->hn_mark;
13311 + fsnotify_init_mark(mark, au_hfsn_free_mark);
13312 + mark->mask = AuHfsnMask;
13314 + * by udba rename or rmdir, aufs assign a new inode to the known
13315 + * h_inode, so specify 1 to allow dups.
13317 + err = fsnotify_add_mark(mark, br->br_hfsn->hfsn_group, hinode->hi_inode,
13318 + /*mnt*/NULL, /*allow_dups*/1);
13319 + /* even if err */
13320 + fsnotify_put_mark(mark);
13325 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
13327 + struct fsnotify_mark *mark;
13328 + unsigned long long ull;
13329 + struct fsnotify_group *group;
13331 + ull = atomic64_inc_return(&au_hfsn_ifree);
13334 + mark = &hn->hn_mark;
13335 + spin_lock(&mark->lock);
13336 + group = mark->group;
13337 + fsnotify_get_group(group);
13338 + spin_unlock(&mark->lock);
13339 + fsnotify_destroy_mark(mark, group);
13340 + fsnotify_put_group(group);
13342 + /* free hn by myself */
13346 +/* ---------------------------------------------------------------------- */
13348 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
13350 + struct fsnotify_mark *mark;
13352 + mark = &hinode->hi_notify->hn_mark;
13353 + spin_lock(&mark->lock);
13355 + AuDebugOn(mark->mask & AuHfsnMask);
13356 + mark->mask |= AuHfsnMask;
13358 + AuDebugOn(!(mark->mask & AuHfsnMask));
13359 + mark->mask &= ~AuHfsnMask;
13361 + spin_unlock(&mark->lock);
13362 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
13365 +/* ---------------------------------------------------------------------- */
13367 +/* #define AuDbgHnotify */
13368 +#ifdef AuDbgHnotify
13369 +static char *au_hfsn_name(u32 mask)
13371 +#ifdef CONFIG_AUFS_DEBUG
13372 +#define test_ret(flag) \
13374 + if (mask & flag) \
13377 + test_ret(FS_ACCESS);
13378 + test_ret(FS_MODIFY);
13379 + test_ret(FS_ATTRIB);
13380 + test_ret(FS_CLOSE_WRITE);
13381 + test_ret(FS_CLOSE_NOWRITE);
13382 + test_ret(FS_OPEN);
13383 + test_ret(FS_MOVED_FROM);
13384 + test_ret(FS_MOVED_TO);
13385 + test_ret(FS_CREATE);
13386 + test_ret(FS_DELETE);
13387 + test_ret(FS_DELETE_SELF);
13388 + test_ret(FS_MOVE_SELF);
13389 + test_ret(FS_UNMOUNT);
13390 + test_ret(FS_Q_OVERFLOW);
13391 + test_ret(FS_IN_IGNORED);
13392 + test_ret(FS_IN_ISDIR);
13393 + test_ret(FS_IN_ONESHOT);
13394 + test_ret(FS_EVENT_ON_CHILD);
13403 +/* ---------------------------------------------------------------------- */
13405 +static void au_hfsn_free_group(struct fsnotify_group *group)
13407 + struct au_br_hfsnotify *hfsn = group->private;
13413 +static int au_hfsn_handle_event(struct fsnotify_group *group,
13414 + struct inode *inode,
13415 + struct fsnotify_mark *inode_mark,
13416 + struct fsnotify_mark *vfsmount_mark,
13417 + u32 mask, void *data, int data_type,
13418 + const unsigned char *file_name, u32 cookie)
13421 + struct au_hnotify *hnotify;
13422 + struct inode *h_dir, *h_inode;
13423 + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
13425 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
13428 + /* if FS_UNMOUNT happens, there must be another bug */
13429 + AuDebugOn(mask & FS_UNMOUNT);
13430 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
13435 +#ifdef AuDbgHnotify
13437 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
13438 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
13439 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
13440 + h_dir->i_ino, mask, au_hfsn_name(mask),
13441 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
13442 + /* WARN_ON(1); */
13447 + AuDebugOn(!inode_mark);
13448 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
13449 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
13455 +static struct fsnotify_ops au_hfsn_ops = {
13456 + .handle_event = au_hfsn_handle_event,
13457 + .free_group_priv = au_hfsn_free_group
13460 +/* ---------------------------------------------------------------------- */
13462 +static void au_hfsn_fin_br(struct au_branch *br)
13464 + struct au_br_hfsnotify *hfsn;
13466 + hfsn = br->br_hfsn;
13468 + fsnotify_put_group(hfsn->hfsn_group);
13471 +static int au_hfsn_init_br(struct au_branch *br, int perm)
13474 + struct fsnotify_group *group;
13475 + struct au_br_hfsnotify *hfsn;
13478 + br->br_hfsn = NULL;
13479 + if (!au_br_hnotifyable(perm))
13483 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
13484 + if (unlikely(!hfsn))
13488 + group = fsnotify_alloc_group(&au_hfsn_ops);
13489 + if (IS_ERR(group)) {
13490 + err = PTR_ERR(group);
13491 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
13495 + group->private = hfsn;
13496 + hfsn->hfsn_group = group;
13497 + br->br_hfsn = hfsn;
13498 + goto out; /* success */
13506 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
13511 + if (!br->br_hfsn)
13512 + err = au_hfsn_init_br(br, perm);
13517 +/* ---------------------------------------------------------------------- */
13519 +static void au_hfsn_fin(void)
13521 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
13522 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
13525 +const struct au_hnotify_op au_hnotify_op = {
13526 + .ctl = au_hfsn_ctl,
13527 + .alloc = au_hfsn_alloc,
13528 + .free = au_hfsn_free,
13530 + .fin = au_hfsn_fin,
13532 + .reset_br = au_hfsn_reset_br,
13533 + .fin_br = au_hfsn_fin_br,
13534 + .init_br = au_hfsn_init_br
13536 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
13537 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
13538 +++ linux/fs/aufs/hfsplus.c 2014-06-24 00:14:06.782719306 +0200
13541 + * Copyright (C) 2010-2014 Junjiro R. Okajima
13543 + * This program, aufs is free software; you can redistribute it and/or modify
13544 + * it under the terms of the GNU General Public License as published by
13545 + * the Free Software Foundation; either version 2 of the License, or
13546 + * (at your option) any later version.
13548 + * This program is distributed in the hope that it will be useful,
13549 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13550 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13551 + * GNU General Public License for more details.
13553 + * You should have received a copy of the GNU General Public License
13554 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13558 + * special support for filesystems which aqucires an inode mutex
13559 + * at final closing a file, eg, hfsplus.
13561 + * This trick is very simple and stupid, just to open the file before really
13562 + * neceeary open to tell hfsplus that this is not the final closing.
13563 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
13564 + * and au_h_open_post() after releasing it.
13569 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
13572 + struct file *h_file;
13573 + struct dentry *h_dentry;
13575 + h_dentry = au_h_dptr(dentry, bindex);
13576 + AuDebugOn(!h_dentry);
13577 + AuDebugOn(!h_dentry->d_inode);
13580 + if (au_test_hfsplus(h_dentry->d_sb)
13581 + && S_ISREG(h_dentry->d_inode->i_mode))
13582 + h_file = au_h_open(dentry, bindex,
13583 + O_RDONLY | O_NOATIME | O_LARGEFILE,
13584 + /*file*/NULL, force_wr);
13588 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
13589 + struct file *h_file)
13593 + au_sbr_put(dentry->d_sb, bindex);
13596 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
13597 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
13598 +++ linux/fs/aufs/hnotify.c 2014-06-24 00:14:06.782719306 +0200
13601 + * Copyright (C) 2005-2014 Junjiro R. Okajima
13603 + * This program, aufs is free software; you can redistribute it and/or modify
13604 + * it under the terms of the GNU General Public License as published by
13605 + * the Free Software Foundation; either version 2 of the License, or
13606 + * (at your option) any later version.
13608 + * This program is distributed in the hope that it will be useful,
13609 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13610 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13611 + * GNU General Public License for more details.
13613 + * You should have received a copy of the GNU General Public License
13614 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13618 + * abstraction to notify the direct changes on lower directories
13623 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
13626 + struct au_hnotify *hn;
13629 + hn = au_cache_alloc_hnotify();
13631 + hn->hn_aufs_inode = inode;
13632 + hinode->hi_notify = hn;
13633 + err = au_hnotify_op.alloc(hinode);
13635 + if (unlikely(err)) {
13636 + hinode->hi_notify = NULL;
13637 + au_cache_free_hnotify(hn);
13639 + * The upper dir was removed by udba, but the same named
13640 + * dir left. In this case, aufs assignes a new inode
13641 + * number and set the monitor again.
13642 + * For the lower dir, the old monitnor is still left.
13644 + if (err == -EEXIST)
13653 +void au_hn_free(struct au_hinode *hinode)
13655 + struct au_hnotify *hn;
13657 + hn = hinode->hi_notify;
13659 + hinode->hi_notify = NULL;
13660 + if (au_hnotify_op.free(hinode, hn))
13661 + au_cache_free_hnotify(hn);
13665 +/* ---------------------------------------------------------------------- */
13667 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
13669 + if (hinode->hi_notify)
13670 + au_hnotify_op.ctl(hinode, do_set);
13673 +void au_hn_reset(struct inode *inode, unsigned int flags)
13675 + aufs_bindex_t bindex, bend;
13676 + struct inode *hi;
13677 + struct dentry *iwhdentry;
13679 + bend = au_ibend(inode);
13680 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
13681 + hi = au_h_iptr(inode, bindex);
13685 + /* mutex_lock_nested(&hi->i_mutex, AuLsc_I_CHILD); */
13686 + iwhdentry = au_hi_wh(inode, bindex);
13690 + au_set_h_iptr(inode, bindex, NULL, 0);
13691 + au_set_h_iptr(inode, bindex, au_igrab(hi),
13692 + flags & ~AuHi_XINO);
13695 + /* mutex_unlock(&hi->i_mutex); */
13699 +/* ---------------------------------------------------------------------- */
13701 +static int hn_xino(struct inode *inode, struct inode *h_inode)
13704 + aufs_bindex_t bindex, bend, bfound, bstart;
13705 + struct inode *h_i;
13708 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
13709 + pr_warn("branch root dir was changed\n");
13714 + bend = au_ibend(inode);
13715 + bstart = au_ibstart(inode);
13716 +#if 0 /* reserved for future use */
13717 + if (bindex == bend) {
13718 + /* keep this ino in rename case */
13722 + for (bindex = bstart; bindex <= bend; bindex++)
13723 + if (au_h_iptr(inode, bindex) == h_inode) {
13730 + for (bindex = bstart; bindex <= bend; bindex++) {
13731 + h_i = au_h_iptr(inode, bindex);
13735 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
13736 + /* ignore this error */
13737 + /* bad action? */
13740 + /* children inode number will be broken */
13747 +static int hn_gen_tree(struct dentry *dentry)
13749 + int err, i, j, ndentry;
13750 + struct au_dcsub_pages dpages;
13751 + struct au_dpage *dpage;
13752 + struct dentry **dentries;
13754 + err = au_dpages_init(&dpages, GFP_NOFS);
13755 + if (unlikely(err))
13757 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
13758 + if (unlikely(err))
13761 + for (i = 0; i < dpages.ndpage; i++) {
13762 + dpage = dpages.dpages + i;
13763 + dentries = dpage->dentries;
13764 + ndentry = dpage->ndentry;
13765 + for (j = 0; j < ndentry; j++) {
13766 + struct dentry *d;
13774 + /* todo: reset children xino?
13775 + cached children only? */
13776 + au_iigen_dec(d->d_inode);
13781 + au_dpages_free(&dpages);
13784 + /* discard children */
13785 + dentry_unhash(dentry);
13793 + * return 0 if processed.
13795 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
13796 + const unsigned int isdir)
13799 + struct dentry *d;
13800 + struct qstr *dname;
13803 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
13804 + pr_warn("branch root dir was changed\n");
13810 + AuDebugOn(!name);
13811 + au_iigen_dec(inode);
13812 + spin_lock(&inode->i_lock);
13813 + hlist_for_each_entry(d, &inode->i_dentry, d_alias) {
13814 + spin_lock(&d->d_lock);
13815 + dname = &d->d_name;
13816 + if (dname->len != nlen
13817 + && memcmp(dname->name, name, nlen)) {
13818 + spin_unlock(&d->d_lock);
13823 + spin_unlock(&d->d_lock);
13826 + spin_unlock(&inode->i_lock);
13828 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
13829 + d = d_find_alias(inode);
13831 + au_iigen_dec(inode);
13835 + spin_lock(&d->d_lock);
13836 + dname = &d->d_name;
13837 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
13838 + spin_unlock(&d->d_lock);
13839 + err = hn_gen_tree(d);
13840 + spin_lock(&d->d_lock);
13842 + spin_unlock(&d->d_lock);
13851 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
13854 + struct inode *inode;
13856 + inode = dentry->d_inode;
13857 + if (IS_ROOT(dentry)
13858 + /* || (inode && inode->i_ino == AUFS_ROOT_INO) */
13860 + pr_warn("branch root dir was changed\n");
13866 + au_digen_dec(dentry);
13868 + au_iigen_dec(inode);
13870 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
13872 + err = hn_gen_tree(dentry);
13879 +/* ---------------------------------------------------------------------- */
13881 +/* hnotify job flags */
13882 +#define AuHnJob_XINO0 1
13883 +#define AuHnJob_GEN (1 << 1)
13884 +#define AuHnJob_DIRENT (1 << 2)
13885 +#define AuHnJob_ISDIR (1 << 3)
13886 +#define AuHnJob_TRYXINO0 (1 << 4)
13887 +#define AuHnJob_MNTPNT (1 << 5)
13888 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
13889 +#define au_fset_hnjob(flags, name) \
13890 + do { (flags) |= AuHnJob_##name; } while (0)
13891 +#define au_fclr_hnjob(flags, name) \
13892 + do { (flags) &= ~AuHnJob_##name; } while (0)
13900 +struct au_hnotify_args {
13901 + struct inode *h_dir, *dir, *h_child_inode;
13903 + unsigned int flags[AuHnLast];
13904 + unsigned int h_child_nlen;
13905 + char h_child_name[];
13908 +struct hn_job_args {
13909 + unsigned int flags;
13910 + struct inode *inode, *h_inode, *dir, *h_dir;
13911 + struct dentry *dentry;
13916 +static int hn_job(struct hn_job_args *a)
13918 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
13921 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
13922 + hn_xino(a->inode, a->h_inode); /* ignore this error */
13924 + if (au_ftest_hnjob(a->flags, TRYXINO0)
13927 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
13928 + if (!a->h_inode->i_nlink
13929 + && !(a->h_inode->i_state & I_LINKABLE))
13930 + hn_xino(a->inode, a->h_inode); /* ignore this error */
13931 + mutex_unlock(&a->h_inode->i_mutex);
13934 + /* make the generation obsolete */
13935 + if (au_ftest_hnjob(a->flags, GEN)) {
13938 + err = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
13940 + if (err && a->dentry)
13941 + hn_gen_by_name(a->dentry, isdir);
13942 + /* ignore this error */
13945 + /* make dir entries obsolete */
13946 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
13947 + struct au_vdir *vdir;
13949 + vdir = au_ivdir(a->inode);
13951 + vdir->vd_jiffy = 0;
13952 + /* IMustLock(a->inode); */
13953 + /* a->inode->i_version++; */
13956 + /* can do nothing but warn */
13957 + if (au_ftest_hnjob(a->flags, MNTPNT)
13959 + && d_mountpoint(a->dentry))
13960 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
13965 +/* ---------------------------------------------------------------------- */
13967 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
13968 + struct inode *dir)
13970 + struct dentry *dentry, *d, *parent;
13971 + struct qstr *dname;
13973 + parent = d_find_alias(dir);
13978 + spin_lock(&parent->d_lock);
13979 + list_for_each_entry(d, &parent->d_subdirs, d_u.d_child) {
13980 + /* AuDbg("%pd\n", d); */
13981 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
13982 + dname = &d->d_name;
13983 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
13984 + goto cont_unlock;
13988 + goto cont_unlock;
13989 + if (d_count(d)) {
13990 + dentry = dget_dlock(d);
13991 + spin_unlock(&d->d_lock);
13996 + spin_unlock(&d->d_lock);
13998 + spin_unlock(&parent->d_lock);
14002 + di_write_lock_child(dentry);
14007 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
14008 + aufs_bindex_t bindex, ino_t h_ino)
14010 + struct inode *inode;
14015 + err = au_xino_read(sb, bindex, h_ino, &ino);
14017 + inode = ilookup(sb, ino);
14021 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
14022 + pr_warn("wrong root branch\n");
14028 + ii_write_lock_child(inode);
14034 +static void au_hn_bh(void *_args)
14036 + struct au_hnotify_args *a = _args;
14037 + struct super_block *sb;
14038 + aufs_bindex_t bindex, bend, bfound;
14039 + unsigned char xino, try_iput;
14041 + struct inode *inode;
14043 + struct hn_job_args args;
14044 + struct dentry *dentry;
14045 + struct au_sbinfo *sbinfo;
14047 + AuDebugOn(!_args);
14048 + AuDebugOn(!a->h_dir);
14049 + AuDebugOn(!a->dir);
14050 + AuDebugOn(!a->mask);
14051 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
14052 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
14053 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
14058 + * do not lock a->dir->i_mutex here
14059 + * because of d_revalidate() may cause a deadlock.
14061 + sb = a->dir->i_sb;
14063 + sbinfo = au_sbi(sb);
14064 + AuDebugOn(!sbinfo);
14065 + si_write_lock(sb, AuLock_NOPLMW);
14067 + ii_read_lock_parent(a->dir);
14069 + bend = au_ibend(a->dir);
14070 + for (bindex = au_ibstart(a->dir); bindex <= bend; bindex++)
14071 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
14075 + ii_read_unlock(a->dir);
14076 + if (unlikely(bfound < 0))
14079 + xino = !!au_opt_test(au_mntflags(sb), XINO);
14081 + if (a->h_child_inode)
14082 + h_ino = a->h_child_inode->i_ino;
14084 + if (a->h_child_nlen
14085 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
14086 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
14087 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
14091 + inode = dentry->d_inode;
14092 + if (xino && !inode && h_ino
14093 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
14094 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
14095 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
14096 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
14100 + args.flags = a->flags[AuHn_CHILD];
14101 + args.dentry = dentry;
14102 + args.inode = inode;
14103 + args.h_inode = a->h_child_inode;
14104 + args.dir = a->dir;
14105 + args.h_dir = a->h_dir;
14106 + args.h_name = a->h_child_name;
14107 + args.h_nlen = a->h_child_nlen;
14108 + err = hn_job(&args);
14110 + if (au_di(dentry))
14111 + di_write_unlock(dentry);
14114 + if (inode && try_iput) {
14115 + ii_write_unlock(inode);
14119 + ii_write_lock_parent(a->dir);
14120 + args.flags = a->flags[AuHn_PARENT];
14121 + args.dentry = NULL;
14122 + args.inode = a->dir;
14123 + args.h_inode = a->h_dir;
14125 + args.h_dir = NULL;
14126 + args.h_name = NULL;
14128 + err = hn_job(&args);
14129 + ii_write_unlock(a->dir);
14132 + iput(a->h_child_inode);
14135 + si_write_unlock(sb);
14136 + au_nwt_done(&sbinfo->si_nowait);
14140 +/* ---------------------------------------------------------------------- */
14142 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
14143 + struct qstr *h_child_qstr, struct inode *h_child_inode)
14146 + unsigned int flags[AuHnLast], f;
14147 + unsigned char isdir, isroot, wh;
14148 + struct inode *dir;
14149 + struct au_hnotify_args *args;
14150 + char *p, *h_child_name;
14153 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
14154 + dir = igrab(hnotify->hn_aufs_inode);
14158 + isroot = (dir->i_ino == AUFS_ROOT_INO);
14160 + h_child_name = (void *)h_child_qstr->name;
14161 + len = h_child_qstr->len;
14162 + if (h_child_name) {
14163 + if (len > AUFS_WH_PFX_LEN
14164 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
14165 + h_child_name += AUFS_WH_PFX_LEN;
14166 + len -= AUFS_WH_PFX_LEN;
14172 + if (h_child_inode)
14173 + isdir = !!S_ISDIR(h_child_inode->i_mode);
14174 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
14175 + flags[AuHn_CHILD] = 0;
14177 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
14178 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
14179 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
14180 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
14181 + case FS_MOVED_FROM:
14182 + case FS_MOVED_TO:
14183 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
14184 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
14187 + AuDebugOn(!h_child_name);
14192 + * aufs never be able to get this child inode.
14193 + * revalidation should be in d_revalidate()
14194 + * by checking i_nlink, i_generation or d_unhashed().
14196 + AuDebugOn(!h_child_name);
14197 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
14198 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
14206 + h_child_inode = NULL;
14209 + /* iput() and kfree() will be called in au_hnotify() */
14210 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
14211 + if (unlikely(!args)) {
14212 + AuErr1("no memory\n");
14216 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
14217 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
14218 + args->mask = mask;
14220 + args->h_dir = igrab(h_dir);
14221 + if (h_child_inode)
14222 + h_child_inode = igrab(h_child_inode); /* can be NULL */
14223 + args->h_child_inode = h_child_inode;
14224 + args->h_child_nlen = len;
14226 + p = (void *)args;
14227 + p += sizeof(*args);
14228 + memcpy(p, h_child_name, len);
14232 + /* NFS fires the event for silly-renamed one from kworker */
14234 + if (!dir->i_nlink
14235 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
14237 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
14238 + if (unlikely(err)) {
14239 + pr_err("wkq %d\n", err);
14240 + iput(args->h_child_inode);
14241 + iput(args->h_dir);
14250 +/* ---------------------------------------------------------------------- */
14252 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
14256 + AuDebugOn(!(udba & AuOptMask_UDBA));
14259 + if (au_hnotify_op.reset_br)
14260 + err = au_hnotify_op.reset_br(udba, br, perm);
14265 +int au_hnotify_init_br(struct au_branch *br, int perm)
14270 + if (au_hnotify_op.init_br)
14271 + err = au_hnotify_op.init_br(br, perm);
14276 +void au_hnotify_fin_br(struct au_branch *br)
14278 + if (au_hnotify_op.fin_br)
14279 + au_hnotify_op.fin_br(br);
14282 +static void au_hn_destroy_cache(void)
14284 + kmem_cache_destroy(au_cachep[AuCache_HNOTIFY]);
14285 + au_cachep[AuCache_HNOTIFY] = NULL;
14288 +int __init au_hnotify_init(void)
14293 + au_cachep[AuCache_HNOTIFY] = AuCache(au_hnotify);
14294 + if (au_cachep[AuCache_HNOTIFY]) {
14296 + if (au_hnotify_op.init)
14297 + err = au_hnotify_op.init();
14298 + if (unlikely(err))
14299 + au_hn_destroy_cache();
14305 +void au_hnotify_fin(void)
14307 + if (au_hnotify_op.fin)
14308 + au_hnotify_op.fin();
14309 + /* cf. au_cache_fin() */
14310 + if (au_cachep[AuCache_HNOTIFY])
14311 + au_hn_destroy_cache();
14313 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
14314 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
14315 +++ linux/fs/aufs/iinfo.c 2014-06-24 00:14:06.786052822 +0200
14318 + * Copyright (C) 2005-2014 Junjiro R. Okajima
14320 + * This program, aufs is free software; you can redistribute it and/or modify
14321 + * it under the terms of the GNU General Public License as published by
14322 + * the Free Software Foundation; either version 2 of the License, or
14323 + * (at your option) any later version.
14325 + * This program is distributed in the hope that it will be useful,
14326 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14327 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14328 + * GNU General Public License for more details.
14330 + * You should have received a copy of the GNU General Public License
14331 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14335 + * inode private data
14340 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
14342 + struct inode *h_inode;
14344 + IiMustAnyLock(inode);
14346 + h_inode = au_ii(inode)->ii_hinode[0 + bindex].hi_inode;
14347 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
14351 +/* todo: hard/soft set? */
14352 +void au_hiput(struct au_hinode *hinode)
14354 + au_hn_free(hinode);
14355 + dput(hinode->hi_whdentry);
14356 + iput(hinode->hi_inode);
14359 +unsigned int au_hi_flags(struct inode *inode, int isdir)
14361 + unsigned int flags;
14362 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
14365 + if (au_opt_test(mnt_flags, XINO))
14366 + au_fset_hi(flags, XINO);
14367 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
14368 + au_fset_hi(flags, HNOTIFY);
14372 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
14373 + struct inode *h_inode, unsigned int flags)
14375 + struct au_hinode *hinode;
14376 + struct inode *hi;
14377 + struct au_iinfo *iinfo = au_ii(inode);
14379 + IiMustWriteLock(inode);
14381 + hinode = iinfo->ii_hinode + bindex;
14382 + hi = hinode->hi_inode;
14383 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
14386 + au_hiput(hinode);
14387 + hinode->hi_inode = h_inode;
14390 + struct super_block *sb = inode->i_sb;
14391 + struct au_branch *br;
14393 + AuDebugOn(inode->i_mode
14394 + && (h_inode->i_mode & S_IFMT)
14395 + != (inode->i_mode & S_IFMT));
14396 + if (bindex == iinfo->ii_bstart)
14397 + au_cpup_igen(inode, h_inode);
14398 + br = au_sbr(sb, bindex);
14399 + hinode->hi_id = br->br_id;
14400 + if (au_ftest_hi(flags, XINO)) {
14401 + err = au_xino_write(sb, bindex, h_inode->i_ino,
14403 + if (unlikely(err))
14404 + AuIOErr1("failed au_xino_write() %d\n", err);
14407 + if (au_ftest_hi(flags, HNOTIFY)
14408 + && au_br_hnotifyable(br->br_perm)) {
14409 + err = au_hn_alloc(hinode, inode);
14410 + if (unlikely(err))
14411 + AuIOErr1("au_hn_alloc() %d\n", err);
14416 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
14417 + struct dentry *h_wh)
14419 + struct au_hinode *hinode;
14421 + IiMustWriteLock(inode);
14423 + hinode = au_ii(inode)->ii_hinode + bindex;
14424 + AuDebugOn(hinode->hi_whdentry);
14425 + hinode->hi_whdentry = h_wh;
14428 +void au_update_iigen(struct inode *inode, int half)
14430 + struct au_iinfo *iinfo;
14431 + struct au_iigen *iigen;
14432 + unsigned int sigen;
14434 + sigen = au_sigen(inode->i_sb);
14435 + iinfo = au_ii(inode);
14436 + iigen = &iinfo->ii_generation;
14437 + spin_lock(&iinfo->ii_genspin);
14438 + iigen->ig_generation = sigen;
14440 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
14442 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
14443 + spin_unlock(&iinfo->ii_genspin);
14446 +/* it may be called at remount time, too */
14447 +void au_update_ibrange(struct inode *inode, int do_put_zero)
14449 + struct au_iinfo *iinfo;
14450 + aufs_bindex_t bindex, bend;
14452 + iinfo = au_ii(inode);
14456 + IiMustWriteLock(inode);
14458 + if (do_put_zero && iinfo->ii_bstart >= 0) {
14459 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
14461 + struct inode *h_i;
14463 + h_i = iinfo->ii_hinode[0 + bindex].hi_inode;
14466 + && !(h_i->i_state & I_LINKABLE))
14467 + au_set_h_iptr(inode, bindex, NULL, 0);
14471 + iinfo->ii_bstart = -1;
14472 + iinfo->ii_bend = -1;
14473 + bend = au_sbend(inode->i_sb);
14474 + for (bindex = 0; bindex <= bend; bindex++)
14475 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
14476 + iinfo->ii_bstart = bindex;
14479 + if (iinfo->ii_bstart >= 0)
14480 + for (bindex = bend; bindex >= iinfo->ii_bstart; bindex--)
14481 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
14482 + iinfo->ii_bend = bindex;
14485 + AuDebugOn(iinfo->ii_bstart > iinfo->ii_bend);
14488 +/* ---------------------------------------------------------------------- */
14490 +void au_icntnr_init_once(void *_c)
14492 + struct au_icntnr *c = _c;
14493 + struct au_iinfo *iinfo = &c->iinfo;
14494 + static struct lock_class_key aufs_ii;
14496 + spin_lock_init(&iinfo->ii_genspin);
14497 + au_rw_init(&iinfo->ii_rwsem);
14498 + au_rw_class(&iinfo->ii_rwsem, &aufs_ii);
14499 + inode_init_once(&c->vfs_inode);
14502 +int au_iinfo_init(struct inode *inode)
14504 + struct au_iinfo *iinfo;
14505 + struct super_block *sb;
14508 + sb = inode->i_sb;
14509 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
14510 + nbr = au_sbend(sb) + 1;
14511 + if (unlikely(nbr <= 0))
14513 + iinfo->ii_hinode = kcalloc(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
14514 + if (iinfo->ii_hinode) {
14515 + au_ninodes_inc(sb);
14516 + for (i = 0; i < nbr; i++)
14517 + iinfo->ii_hinode[i].hi_id = -1;
14519 + iinfo->ii_generation.ig_generation = au_sigen(sb);
14520 + iinfo->ii_bstart = -1;
14521 + iinfo->ii_bend = -1;
14522 + iinfo->ii_vdir = NULL;
14528 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr)
14531 + struct au_hinode *hip;
14533 + AuRwMustWriteLock(&iinfo->ii_rwsem);
14536 + sz = sizeof(*hip) * (iinfo->ii_bend + 1);
14538 + sz = sizeof(*hip);
14539 + hip = au_kzrealloc(iinfo->ii_hinode, sz, sizeof(*hip) * nbr, GFP_NOFS);
14541 + iinfo->ii_hinode = hip;
14548 +void au_iinfo_fin(struct inode *inode)
14550 + struct au_iinfo *iinfo;
14551 + struct au_hinode *hi;
14552 + struct super_block *sb;
14553 + aufs_bindex_t bindex, bend;
14554 + const unsigned char unlinked = !inode->i_nlink;
14556 + iinfo = au_ii(inode);
14557 + /* bad_inode case */
14561 + sb = inode->i_sb;
14562 + au_ninodes_dec(sb);
14563 + if (si_pid_test(sb))
14564 + au_xino_delete_inode(inode, unlinked);
14567 + * it is safe to hide the dependency between sbinfo and
14571 + si_noflush_read_lock(sb);
14572 + au_xino_delete_inode(inode, unlinked);
14573 + si_read_unlock(sb);
14577 + if (iinfo->ii_vdir)
14578 + au_vdir_free(iinfo->ii_vdir);
14580 + bindex = iinfo->ii_bstart;
14581 + if (bindex >= 0) {
14582 + hi = iinfo->ii_hinode + bindex;
14583 + bend = iinfo->ii_bend;
14584 + while (bindex++ <= bend) {
14585 + if (hi->hi_inode)
14590 + kfree(iinfo->ii_hinode);
14591 + iinfo->ii_hinode = NULL;
14592 + AuRwDestroy(&iinfo->ii_rwsem);
14594 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
14595 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
14596 +++ linux/fs/aufs/inode.c 2014-06-24 00:14:06.786052822 +0200
14599 + * Copyright (C) 2005-2014 Junjiro R. Okajima
14601 + * This program, aufs is free software; you can redistribute it and/or modify
14602 + * it under the terms of the GNU General Public License as published by
14603 + * the Free Software Foundation; either version 2 of the License, or
14604 + * (at your option) any later version.
14606 + * This program is distributed in the hope that it will be useful,
14607 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14608 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14609 + * GNU General Public License for more details.
14611 + * You should have received a copy of the GNU General Public License
14612 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14616 + * inode functions
14621 +struct inode *au_igrab(struct inode *inode)
14624 + AuDebugOn(!atomic_read(&inode->i_count));
14630 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
14632 + au_cpup_attr_all(inode, /*force*/0);
14633 + au_update_iigen(inode, /*half*/1);
14635 + inode->i_version++;
14638 +static int au_ii_refresh(struct inode *inode, int *update)
14642 + aufs_bindex_t bindex, new_bindex;
14643 + struct super_block *sb;
14644 + struct au_iinfo *iinfo;
14645 + struct au_hinode *p, *q, tmp;
14647 + IiMustWriteLock(inode);
14650 + sb = inode->i_sb;
14651 + type = inode->i_mode & S_IFMT;
14652 + iinfo = au_ii(inode);
14653 + err = au_ii_realloc(iinfo, au_sbend(sb) + 1);
14654 + if (unlikely(err))
14657 + AuDebugOn(iinfo->ii_bstart < 0);
14658 + p = iinfo->ii_hinode + iinfo->ii_bstart;
14659 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
14661 + if (!p->hi_inode)
14664 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
14665 + new_bindex = au_br_index(sb, p->hi_id);
14666 + if (new_bindex == bindex)
14669 + if (new_bindex < 0) {
14672 + p->hi_inode = NULL;
14676 + if (new_bindex < iinfo->ii_bstart)
14677 + iinfo->ii_bstart = new_bindex;
14678 + if (iinfo->ii_bend < new_bindex)
14679 + iinfo->ii_bend = new_bindex;
14680 + /* swap two lower inode, and loop again */
14681 + q = iinfo->ii_hinode + new_bindex;
14685 + if (tmp.hi_inode) {
14690 + au_update_ibrange(inode, /*do_put_zero*/0);
14691 + e = au_dy_irefresh(inode);
14692 + if (unlikely(e && !err))
14700 +int au_refresh_hinode_self(struct inode *inode)
14704 + err = au_ii_refresh(inode, &update);
14706 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
14712 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
14714 + int err, e, update;
14715 + unsigned int flags;
14717 + aufs_bindex_t bindex, bend;
14718 + unsigned char isdir;
14719 + struct au_hinode *p;
14720 + struct au_iinfo *iinfo;
14722 + err = au_ii_refresh(inode, &update);
14723 + if (unlikely(err))
14727 + iinfo = au_ii(inode);
14728 + p = iinfo->ii_hinode + iinfo->ii_bstart;
14729 + mode = (inode->i_mode & S_IFMT);
14730 + isdir = S_ISDIR(mode);
14731 + flags = au_hi_flags(inode, isdir);
14732 + bend = au_dbend(dentry);
14733 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
14734 + struct inode *h_i;
14735 + struct dentry *h_d;
14737 + h_d = au_h_dptr(dentry, bindex);
14738 + if (!h_d || !h_d->d_inode)
14741 + AuDebugOn(mode != (h_d->d_inode->i_mode & S_IFMT));
14742 + if (iinfo->ii_bstart <= bindex && bindex <= iinfo->ii_bend) {
14743 + h_i = au_h_iptr(inode, bindex);
14745 + if (h_i == h_d->d_inode)
14751 + if (bindex < iinfo->ii_bstart)
14752 + iinfo->ii_bstart = bindex;
14753 + if (iinfo->ii_bend < bindex)
14754 + iinfo->ii_bend = bindex;
14755 + au_set_h_iptr(inode, bindex, au_igrab(h_d->d_inode), flags);
14758 + au_update_ibrange(inode, /*do_put_zero*/0);
14759 + e = au_dy_irefresh(inode);
14760 + if (unlikely(e && !err))
14763 + au_refresh_hinode_attr(inode, update && isdir);
14770 +static int set_inode(struct inode *inode, struct dentry *dentry)
14773 + unsigned int flags;
14775 + aufs_bindex_t bindex, bstart, btail;
14776 + unsigned char isdir;
14777 + struct dentry *h_dentry;
14778 + struct inode *h_inode;
14779 + struct au_iinfo *iinfo;
14781 + IiMustWriteLock(inode);
14785 + bstart = au_dbstart(dentry);
14786 + h_inode = au_h_dptr(dentry, bstart)->d_inode;
14787 + mode = h_inode->i_mode;
14788 + switch (mode & S_IFMT) {
14790 + btail = au_dbtail(dentry);
14791 + inode->i_op = &aufs_iop;
14792 + inode->i_fop = &aufs_file_fop;
14793 + err = au_dy_iaop(inode, bstart, h_inode);
14794 + if (unlikely(err))
14799 + btail = au_dbtaildir(dentry);
14800 + inode->i_op = &aufs_dir_iop;
14801 + inode->i_fop = &aufs_dir_fop;
14804 + btail = au_dbtail(dentry);
14805 + inode->i_op = &aufs_symlink_iop;
14811 + btail = au_dbtail(dentry);
14812 + inode->i_op = &aufs_iop;
14813 + init_special_inode(inode, mode, h_inode->i_rdev);
14816 + AuIOErr("Unknown file type 0%o\n", mode);
14821 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
14822 + flags = au_hi_flags(inode, isdir);
14823 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
14824 + && au_ftest_hi(flags, HNOTIFY)
14825 + && dentry->d_name.len > AUFS_WH_PFX_LEN
14826 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
14827 + au_fclr_hi(flags, HNOTIFY);
14828 + iinfo = au_ii(inode);
14829 + iinfo->ii_bstart = bstart;
14830 + iinfo->ii_bend = btail;
14831 + for (bindex = bstart; bindex <= btail; bindex++) {
14832 + h_dentry = au_h_dptr(dentry, bindex);
14834 + au_set_h_iptr(inode, bindex,
14835 + au_igrab(h_dentry->d_inode), flags);
14837 + au_cpup_attr_all(inode, /*force*/1);
14844 + * successful returns with iinfo write_locked
14846 + * zero: success, matched
14847 + * plus: no error, but unmatched
14849 +static int reval_inode(struct inode *inode, struct dentry *dentry)
14852 + unsigned int gen;
14853 + struct au_iigen iigen;
14854 + aufs_bindex_t bindex, bend;
14855 + struct inode *h_inode, *h_dinode;
14858 + * before this function, if aufs got any iinfo lock, it must be only
14859 + * one, the parent dir.
14860 + * it can happen by UDBA and the obsoleted inode number.
14863 + if (unlikely(inode->i_ino == parent_ino(dentry)))
14867 + ii_write_lock_new_child(inode);
14868 + h_dinode = au_h_dptr(dentry, au_dbstart(dentry))->d_inode;
14869 + bend = au_ibend(inode);
14870 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
14871 + h_inode = au_h_iptr(inode, bindex);
14872 + if (!h_inode || h_inode != h_dinode)
14876 + gen = au_iigen(inode, &iigen);
14877 + if (gen == au_digen(dentry)
14878 + && !au_ig_ftest(iigen.ig_flags, HALF_REFRESHED))
14881 + /* fully refresh inode using dentry */
14882 + err = au_refresh_hinode(inode, dentry);
14884 + au_update_iigen(inode, /*half*/0);
14888 + if (unlikely(err))
14889 + ii_write_unlock(inode);
14894 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
14895 + unsigned int d_type, ino_t *ino)
14898 + struct mutex *mtx;
14900 + /* prevent hardlinked inode number from race condition */
14902 + if (d_type != DT_DIR) {
14903 + mtx = &au_sbr(sb, bindex)->br_xino.xi_nondir_mtx;
14906 + err = au_xino_read(sb, bindex, h_ino, ino);
14907 + if (unlikely(err))
14912 + *ino = au_xino_new_ino(sb);
14913 + if (unlikely(!*ino))
14915 + err = au_xino_write(sb, bindex, h_ino, *ino);
14916 + if (unlikely(err))
14922 + mutex_unlock(mtx);
14926 +/* successful returns with iinfo write_locked */
14927 +/* todo: return with unlocked? */
14928 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
14930 + struct inode *inode, *h_inode;
14931 + struct dentry *h_dentry;
14932 + struct super_block *sb;
14933 + struct mutex *mtx;
14934 + ino_t h_ino, ino;
14936 + aufs_bindex_t bstart;
14938 + sb = dentry->d_sb;
14939 + bstart = au_dbstart(dentry);
14940 + h_dentry = au_h_dptr(dentry, bstart);
14941 + h_inode = h_dentry->d_inode;
14942 + h_ino = h_inode->i_ino;
14945 + * stop 'race'-ing between hardlinks under different
14949 + if (!S_ISDIR(h_inode->i_mode))
14950 + mtx = &au_sbr(sb, bstart)->br_xino.xi_nondir_mtx;
14955 + err = au_xino_read(sb, bstart, h_ino, &ino);
14956 + inode = ERR_PTR(err);
14957 + if (unlikely(err))
14961 + ino = au_xino_new_ino(sb);
14962 + if (unlikely(!ino)) {
14963 + inode = ERR_PTR(-EIO);
14968 + AuDbg("i%lu\n", (unsigned long)ino);
14969 + inode = au_iget_locked(sb, ino);
14970 + err = PTR_ERR(inode);
14971 + if (IS_ERR(inode))
14974 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
14975 + if (inode->i_state & I_NEW) {
14976 + /* verbose coding for lock class name */
14977 + if (unlikely(S_ISLNK(h_inode->i_mode)))
14978 + au_rw_class(&au_ii(inode)->ii_rwsem,
14979 + au_lc_key + AuLcSymlink_IIINFO);
14980 + else if (unlikely(S_ISDIR(h_inode->i_mode)))
14981 + au_rw_class(&au_ii(inode)->ii_rwsem,
14982 + au_lc_key + AuLcDir_IIINFO);
14983 + else /* likely */
14984 + au_rw_class(&au_ii(inode)->ii_rwsem,
14985 + au_lc_key + AuLcNonDir_IIINFO);
14987 + ii_write_lock_new_child(inode);
14988 + err = set_inode(inode, dentry);
14990 + unlock_new_inode(inode);
14991 + goto out; /* success */
14995 + * iget_failed() calls iput(), but we need to call
14996 + * ii_write_unlock() after iget_failed(). so dirty hack for
14999 + atomic_inc(&inode->i_count);
15000 + iget_failed(inode);
15001 + ii_write_unlock(inode);
15002 + au_xino_write(sb, bstart, h_ino, /*ino*/0);
15003 + /* ignore this error */
15005 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
15007 + * horrible race condition between lookup, readdir and copyup
15008 + * (or something).
15011 + mutex_unlock(mtx);
15012 + err = reval_inode(inode, dentry);
15013 + if (unlikely(err < 0)) {
15020 + goto out; /* success */
15025 + if (unlikely(au_test_fs_unique_ino(h_dentry->d_inode)))
15026 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
15027 + " b%d, %s, %pd, hi%lu, i%lu.\n",
15028 + bstart, au_sbtype(h_dentry->d_sb), dentry,
15029 + (unsigned long)h_ino, (unsigned long)ino);
15031 + err = au_xino_write(sb, bstart, h_ino, /*ino*/0);
15035 + mutex_unlock(mtx);
15041 + inode = ERR_PTR(err);
15044 + mutex_unlock(mtx);
15048 +/* ---------------------------------------------------------------------- */
15050 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
15051 + struct inode *inode)
15055 + err = au_br_rdonly(au_sbr(sb, bindex));
15057 + /* pseudo-link after flushed may happen out of bounds */
15060 + && au_ibstart(inode) <= bindex
15061 + && bindex <= au_ibend(inode)) {
15063 + * permission check is unnecessary since vfsub routine
15064 + * will be called later
15066 + struct inode *hi = au_h_iptr(inode, bindex);
15068 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
15074 +int au_test_h_perm(struct inode *h_inode, int mask)
15076 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
15078 + return inode_permission(h_inode, mask);
15081 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
15083 + if (au_test_nfs(h_inode->i_sb)
15084 + && (mask & MAY_WRITE)
15085 + && S_ISDIR(h_inode->i_mode))
15086 + mask |= MAY_READ; /* force permission check */
15087 + return au_test_h_perm(h_inode, mask);
15089 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
15090 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
15091 +++ linux/fs/aufs/inode.h 2014-06-24 00:14:06.786052822 +0200
15094 + * Copyright (C) 2005-2014 Junjiro R. Okajima
15096 + * This program, aufs is free software; you can redistribute it and/or modify
15097 + * it under the terms of the GNU General Public License as published by
15098 + * the Free Software Foundation; either version 2 of the License, or
15099 + * (at your option) any later version.
15101 + * This program is distributed in the hope that it will be useful,
15102 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15103 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15104 + * GNU General Public License for more details.
15106 + * You should have received a copy of the GNU General Public License
15107 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15111 + * inode operations
15114 +#ifndef __AUFS_INODE_H__
15115 +#define __AUFS_INODE_H__
15119 +#include <linux/fsnotify.h>
15120 +#include "rwsem.h"
15124 +struct au_hnotify {
15125 +#ifdef CONFIG_AUFS_HNOTIFY
15126 +#ifdef CONFIG_AUFS_HFSNOTIFY
15127 + /* never use fsnotify_add_vfsmount_mark() */
15128 + struct fsnotify_mark hn_mark;
15130 + struct inode *hn_aufs_inode; /* no get/put */
15132 +} ____cacheline_aligned_in_smp;
15134 +struct au_hinode {
15135 + struct inode *hi_inode;
15136 + aufs_bindex_t hi_id;
15137 +#ifdef CONFIG_AUFS_HNOTIFY
15138 + struct au_hnotify *hi_notify;
15141 + /* reference to the copied-up whiteout with get/put */
15142 + struct dentry *hi_whdentry;
15146 +#define AuIG_HALF_REFRESHED 1
15147 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
15148 +#define au_ig_fset(flags, name) \
15149 + do { (flags) |= AuIG_##name; } while (0)
15150 +#define au_ig_fclr(flags, name) \
15151 + do { (flags) &= ~AuIG_##name; } while (0)
15154 + __u32 ig_generation, ig_flags;
15159 + spinlock_t ii_genspin;
15160 + struct au_iigen ii_generation;
15161 + struct super_block *ii_hsb1; /* no get/put */
15163 + struct au_rwsem ii_rwsem;
15164 + aufs_bindex_t ii_bstart, ii_bend;
15166 + struct au_hinode *ii_hinode;
15167 + struct au_vdir *ii_vdir;
15170 +struct au_icntnr {
15171 + struct au_iinfo iinfo;
15172 + struct inode vfs_inode;
15173 +} ____cacheline_aligned_in_smp;
15175 +/* au_pin flags */
15176 +#define AuPin_DI_LOCKED 1
15177 +#define AuPin_MNT_WRITE (1 << 1)
15178 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
15179 +#define au_fset_pin(flags, name) \
15180 + do { (flags) |= AuPin_##name; } while (0)
15181 +#define au_fclr_pin(flags, name) \
15182 + do { (flags) &= ~AuPin_##name; } while (0)
15186 + struct dentry *dentry;
15187 + unsigned int udba;
15188 + unsigned char lsc_di, lsc_hi, flags;
15189 + aufs_bindex_t bindex;
15192 + struct dentry *parent;
15193 + struct au_hinode *hdir;
15194 + struct vfsmount *h_mnt;
15196 + /* temporary unlock/relock for copyup */
15197 + struct dentry *h_dentry, *h_parent;
15198 + struct au_branch *br;
15199 + struct task_struct *task;
15202 +void au_pin_hdir_unlock(struct au_pin *p);
15203 +int au_pin_hdir_relock(struct au_pin *p);
15204 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task);
15205 +void au_pin_hdir_acquire_nest(struct au_pin *p);
15206 +void au_pin_hdir_release(struct au_pin *p);
15208 +/* ---------------------------------------------------------------------- */
15210 +static inline struct au_iinfo *au_ii(struct inode *inode)
15212 + struct au_iinfo *iinfo;
15214 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
15215 + if (iinfo->ii_hinode)
15217 + return NULL; /* debugging bad_inode case */
15220 +/* ---------------------------------------------------------------------- */
15223 +struct inode *au_igrab(struct inode *inode);
15224 +int au_refresh_hinode_self(struct inode *inode);
15225 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
15226 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
15227 + unsigned int d_type, ino_t *ino);
15228 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
15229 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
15230 + struct inode *inode);
15231 +int au_test_h_perm(struct inode *h_inode, int mask);
15232 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
15234 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
15235 + ino_t h_ino, unsigned int d_type, ino_t *ino)
15237 +#ifdef CONFIG_AUFS_SHWH
15238 + return au_ino(sb, bindex, h_ino, d_type, ino);
15245 +extern struct inode_operations aufs_iop, aufs_symlink_iop, aufs_dir_iop;
15247 +/* au_wr_dir flags */
15248 +#define AuWrDir_ADD_ENTRY 1
15249 +#define AuWrDir_TMP_WHENTRY (1 << 1)
15250 +#define AuWrDir_ISDIR (1 << 2)
15251 +#define AuWrDir_TMPFILE (1 << 3)
15252 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
15253 +#define au_fset_wrdir(flags, name) \
15254 + do { (flags) |= AuWrDir_##name; } while (0)
15255 +#define au_fclr_wrdir(flags, name) \
15256 + do { (flags) &= ~AuWrDir_##name; } while (0)
15258 +struct au_wr_dir_args {
15259 + aufs_bindex_t force_btgt;
15260 + unsigned char flags;
15262 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
15263 + struct au_wr_dir_args *args);
15265 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
15266 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
15267 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
15268 + unsigned int udba, unsigned char flags);
15269 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
15270 + unsigned int udba, unsigned char flags) __must_check;
15271 +int au_do_pin(struct au_pin *pin) __must_check;
15272 +void au_unpin(struct au_pin *pin);
15275 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
15276 + struct dentry *h_parent, int isdir);
15277 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
15279 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
15280 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
15282 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
15283 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
15284 + struct dentry *dentry);
15285 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
15288 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
15289 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
15290 + struct dentry *h_parent, int isdir);
15291 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
15292 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
15295 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
15296 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
15297 + struct inode *dir, struct dentry *dentry);
15300 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
15301 +void au_hiput(struct au_hinode *hinode);
15302 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
15303 + struct dentry *h_wh);
15304 +unsigned int au_hi_flags(struct inode *inode, int isdir);
15306 +/* hinode flags */
15307 +#define AuHi_XINO 1
15308 +#define AuHi_HNOTIFY (1 << 1)
15309 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
15310 +#define au_fset_hi(flags, name) \
15311 + do { (flags) |= AuHi_##name; } while (0)
15312 +#define au_fclr_hi(flags, name) \
15313 + do { (flags) &= ~AuHi_##name; } while (0)
15315 +#ifndef CONFIG_AUFS_HNOTIFY
15316 +#undef AuHi_HNOTIFY
15317 +#define AuHi_HNOTIFY 0
15320 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
15321 + struct inode *h_inode, unsigned int flags);
15323 +void au_update_iigen(struct inode *inode, int half);
15324 +void au_update_ibrange(struct inode *inode, int do_put_zero);
15326 +void au_icntnr_init_once(void *_c);
15327 +int au_iinfo_init(struct inode *inode);
15328 +void au_iinfo_fin(struct inode *inode);
15329 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr);
15331 +#ifdef CONFIG_PROC_FS
15333 +int au_plink_maint(struct super_block *sb, int flags);
15334 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
15335 +int au_plink_maint_enter(struct super_block *sb);
15336 +#ifdef CONFIG_AUFS_DEBUG
15337 +void au_plink_list(struct super_block *sb);
15339 +AuStubVoid(au_plink_list, struct super_block *sb)
15341 +int au_plink_test(struct inode *inode);
15342 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
15343 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
15344 + struct dentry *h_dentry);
15345 +void au_plink_put(struct super_block *sb, int verbose);
15346 +void au_plink_clean(struct super_block *sb, int verbose);
15347 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
15349 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
15350 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
15351 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
15352 +AuStubVoid(au_plink_list, struct super_block *sb);
15353 +AuStubInt0(au_plink_test, struct inode *inode);
15354 +AuStub(struct dentry *, au_plink_lkup, return NULL,
15355 + struct inode *inode, aufs_bindex_t bindex);
15356 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
15357 + struct dentry *h_dentry);
15358 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
15359 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
15360 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
15361 +#endif /* CONFIG_PROC_FS */
15363 +/* ---------------------------------------------------------------------- */
15365 +/* lock subclass for iinfo */
15367 + AuLsc_II_CHILD, /* child first */
15368 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
15369 + AuLsc_II_CHILD3, /* copyup dirs */
15370 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
15371 + AuLsc_II_PARENT2,
15372 + AuLsc_II_PARENT3, /* copyup dirs */
15373 + AuLsc_II_NEW_CHILD
15377 + * ii_read_lock_child, ii_write_lock_child,
15378 + * ii_read_lock_child2, ii_write_lock_child2,
15379 + * ii_read_lock_child3, ii_write_lock_child3,
15380 + * ii_read_lock_parent, ii_write_lock_parent,
15381 + * ii_read_lock_parent2, ii_write_lock_parent2,
15382 + * ii_read_lock_parent3, ii_write_lock_parent3,
15383 + * ii_read_lock_new_child, ii_write_lock_new_child,
15385 +#define AuReadLockFunc(name, lsc) \
15386 +static inline void ii_read_lock_##name(struct inode *i) \
15388 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
15391 +#define AuWriteLockFunc(name, lsc) \
15392 +static inline void ii_write_lock_##name(struct inode *i) \
15394 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
15397 +#define AuRWLockFuncs(name, lsc) \
15398 + AuReadLockFunc(name, lsc) \
15399 + AuWriteLockFunc(name, lsc)
15401 +AuRWLockFuncs(child, CHILD);
15402 +AuRWLockFuncs(child2, CHILD2);
15403 +AuRWLockFuncs(child3, CHILD3);
15404 +AuRWLockFuncs(parent, PARENT);
15405 +AuRWLockFuncs(parent2, PARENT2);
15406 +AuRWLockFuncs(parent3, PARENT3);
15407 +AuRWLockFuncs(new_child, NEW_CHILD);
15409 +#undef AuReadLockFunc
15410 +#undef AuWriteLockFunc
15411 +#undef AuRWLockFuncs
15414 + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock
15416 +AuSimpleUnlockRwsemFuncs(ii, struct inode *i, &au_ii(i)->ii_rwsem);
15418 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
15419 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
15420 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
15422 +/* ---------------------------------------------------------------------- */
15424 +static inline void au_icntnr_init(struct au_icntnr *c)
15426 +#ifdef CONFIG_AUFS_DEBUG
15427 + c->vfs_inode.i_mode = 0;
15431 +static inline unsigned int au_iigen(struct inode *inode, struct au_iigen *iigen)
15433 + unsigned int gen;
15434 + struct au_iinfo *iinfo;
15436 + iinfo = au_ii(inode);
15437 + spin_lock(&iinfo->ii_genspin);
15439 + *iigen = iinfo->ii_generation;
15440 + gen = iinfo->ii_generation.ig_generation;
15441 + spin_unlock(&iinfo->ii_genspin);
15446 +/* tiny test for inode number */
15447 +/* tmpfs generation is too rough */
15448 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
15450 + struct au_iinfo *iinfo;
15452 + iinfo = au_ii(inode);
15453 + AuRwMustAnyLock(&iinfo->ii_rwsem);
15454 + return !(iinfo->ii_hsb1 == h_inode->i_sb
15455 + && iinfo->ii_higen == h_inode->i_generation);
15458 +static inline void au_iigen_dec(struct inode *inode)
15460 + struct au_iinfo *iinfo;
15462 + iinfo = au_ii(inode);
15463 + spin_lock(&iinfo->ii_genspin);
15464 + iinfo->ii_generation.ig_generation--;
15465 + spin_unlock(&iinfo->ii_genspin);
15468 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
15473 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
15479 +/* ---------------------------------------------------------------------- */
15481 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
15482 + aufs_bindex_t bindex)
15484 + IiMustAnyLock(inode);
15485 + return au_ii(inode)->ii_hinode[0 + bindex].hi_id;
15488 +static inline aufs_bindex_t au_ibstart(struct inode *inode)
15490 + IiMustAnyLock(inode);
15491 + return au_ii(inode)->ii_bstart;
15494 +static inline aufs_bindex_t au_ibend(struct inode *inode)
15496 + IiMustAnyLock(inode);
15497 + return au_ii(inode)->ii_bend;
15500 +static inline struct au_vdir *au_ivdir(struct inode *inode)
15502 + IiMustAnyLock(inode);
15503 + return au_ii(inode)->ii_vdir;
15506 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
15508 + IiMustAnyLock(inode);
15509 + return au_ii(inode)->ii_hinode[0 + bindex].hi_whdentry;
15512 +static inline void au_set_ibstart(struct inode *inode, aufs_bindex_t bindex)
15514 + IiMustWriteLock(inode);
15515 + au_ii(inode)->ii_bstart = bindex;
15518 +static inline void au_set_ibend(struct inode *inode, aufs_bindex_t bindex)
15520 + IiMustWriteLock(inode);
15521 + au_ii(inode)->ii_bend = bindex;
15524 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
15526 + IiMustWriteLock(inode);
15527 + au_ii(inode)->ii_vdir = vdir;
15530 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
15532 + IiMustAnyLock(inode);
15533 + return au_ii(inode)->ii_hinode + bindex;
15536 +/* ---------------------------------------------------------------------- */
15538 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
15541 + return pin->parent;
15545 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
15547 + if (pin && pin->hdir)
15548 + return pin->hdir->hi_inode;
15552 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
15555 + return pin->hdir;
15559 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
15562 + pin->dentry = dentry;
15565 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
15566 + unsigned char lflag)
15570 + au_fset_pin(pin->flags, DI_LOCKED);
15572 + au_fclr_pin(pin->flags, DI_LOCKED);
15576 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
15579 + dput(pin->parent);
15580 + pin->parent = dget(parent);
15584 +/* ---------------------------------------------------------------------- */
15587 +#ifdef CONFIG_AUFS_HNOTIFY
15588 +struct au_hnotify_op {
15589 + void (*ctl)(struct au_hinode *hinode, int do_set);
15590 + int (*alloc)(struct au_hinode *hinode);
15593 + * if it returns true, the the caller should free hinode->hi_notify,
15594 + * otherwise ->free() frees it.
15596 + int (*free)(struct au_hinode *hinode,
15597 + struct au_hnotify *hn) __must_check;
15599 + void (*fin)(void);
15600 + int (*init)(void);
15602 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
15603 + void (*fin_br)(struct au_branch *br);
15604 + int (*init_br)(struct au_branch *br, int perm);
15608 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
15609 +void au_hn_free(struct au_hinode *hinode);
15610 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
15611 +void au_hn_reset(struct inode *inode, unsigned int flags);
15612 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
15613 + struct qstr *h_child_qstr, struct inode *h_child_inode);
15614 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
15615 +int au_hnotify_init_br(struct au_branch *br, int perm);
15616 +void au_hnotify_fin_br(struct au_branch *br);
15617 +int __init au_hnotify_init(void);
15618 +void au_hnotify_fin(void);
15621 +extern const struct au_hnotify_op au_hnotify_op;
15624 +void au_hn_init(struct au_hinode *hinode)
15626 + hinode->hi_notify = NULL;
15629 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
15631 + return hinode->hi_notify;
15636 +int au_hn_alloc(struct au_hinode *hinode __maybe_unused,
15637 + struct inode *inode __maybe_unused)
15639 + return -EOPNOTSUPP;
15642 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
15647 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
15648 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
15649 + int do_set __maybe_unused)
15650 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
15651 + unsigned int flags __maybe_unused)
15652 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
15653 + struct au_branch *br __maybe_unused,
15654 + int perm __maybe_unused)
15655 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
15656 + int perm __maybe_unused)
15657 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
15658 +AuStubInt0(__init au_hnotify_init, void)
15659 +AuStubVoid(au_hnotify_fin, void)
15660 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
15661 +#endif /* CONFIG_AUFS_HNOTIFY */
15663 +static inline void au_hn_suspend(struct au_hinode *hdir)
15665 + au_hn_ctl(hdir, /*do_set*/0);
15668 +static inline void au_hn_resume(struct au_hinode *hdir)
15670 + au_hn_ctl(hdir, /*do_set*/1);
15673 +static inline void au_hn_imtx_lock(struct au_hinode *hdir)
15675 + mutex_lock(&hdir->hi_inode->i_mutex);
15676 + au_hn_suspend(hdir);
15679 +static inline void au_hn_imtx_lock_nested(struct au_hinode *hdir,
15680 + unsigned int sc __maybe_unused)
15682 + mutex_lock_nested(&hdir->hi_inode->i_mutex, sc);
15683 + au_hn_suspend(hdir);
15686 +static inline void au_hn_imtx_unlock(struct au_hinode *hdir)
15688 + au_hn_resume(hdir);
15689 + mutex_unlock(&hdir->hi_inode->i_mutex);
15692 +#endif /* __KERNEL__ */
15693 +#endif /* __AUFS_INODE_H__ */
15694 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
15695 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
15696 +++ linux/fs/aufs/ioctl.c 2014-06-24 00:14:06.786052822 +0200
15699 + * Copyright (C) 2005-2014 Junjiro R. Okajima
15701 + * This program, aufs is free software; you can redistribute it and/or modify
15702 + * it under the terms of the GNU General Public License as published by
15703 + * the Free Software Foundation; either version 2 of the License, or
15704 + * (at your option) any later version.
15706 + * This program is distributed in the hope that it will be useful,
15707 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15708 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15709 + * GNU General Public License for more details.
15711 + * You should have received a copy of the GNU General Public License
15712 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15717 + * plink-management and readdir in userspace.
15718 + * assist the pathconf(3) wrapper library.
15722 +#include <linux/compat.h>
15723 +#include <linux/file.h>
15726 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
15729 + aufs_bindex_t wbi, bindex, bend;
15730 + struct file *h_file;
15731 + struct super_block *sb;
15732 + struct dentry *root;
15733 + struct au_branch *br;
15734 + struct aufs_wbr_fd wbrfd = {
15735 + .oflags = au_dir_roflags,
15738 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
15739 + | O_NOATIME | O_CLOEXEC;
15741 + AuDebugOn(wbrfd.oflags & ~valid);
15744 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
15745 + if (unlikely(err)) {
15751 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
15752 + wbrfd.oflags |= au_dir_roflags;
15753 + AuDbg("0%o\n", wbrfd.oflags);
15754 + if (unlikely(wbrfd.oflags & ~valid))
15758 + fd = get_unused_fd();
15760 + if (unlikely(fd < 0))
15763 + h_file = ERR_PTR(-EINVAL);
15766 + sb = path->dentry->d_sb;
15767 + root = sb->s_root;
15768 + aufs_read_lock(root, AuLock_IR);
15769 + bend = au_sbend(sb);
15770 + if (wbrfd.brid >= 0) {
15771 + wbi = au_br_index(sb, wbrfd.brid);
15772 + if (unlikely(wbi < 0 || wbi > bend))
15776 + h_file = ERR_PTR(-ENOENT);
15777 + br = au_sbr(sb, wbi);
15778 + if (!au_br_writable(br->br_perm)) {
15782 + bindex = wbi + 1;
15784 + for (; bindex <= bend; bindex++) {
15785 + br = au_sbr(sb, bindex);
15786 + if (au_br_writable(br->br_perm)) {
15788 + br = au_sbr(sb, wbi);
15793 + AuDbg("wbi %d\n", wbi);
15795 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
15799 + aufs_read_unlock(root, AuLock_IR);
15800 + err = PTR_ERR(h_file);
15801 + if (IS_ERR(h_file))
15804 + atomic_dec(&br->br_count); /* cf. au_h_open() */
15805 + fd_install(fd, h_file);
15807 + goto out; /* success */
15810 + put_unused_fd(fd);
15816 +/* ---------------------------------------------------------------------- */
15818 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
15823 + case AUFS_CTL_RDU:
15824 + case AUFS_CTL_RDU_INO:
15825 + err = au_rdu_ioctl(file, cmd, arg);
15828 + case AUFS_CTL_WBR_FD:
15829 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
15832 + case AUFS_CTL_IBUSY:
15833 + err = au_ibusy_ioctl(file, arg);
15837 + /* do not call the lower */
15838 + AuDbg("0x%x\n", cmd);
15846 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
15851 + case AUFS_CTL_MVDOWN:
15852 + err = au_mvdown(file->f_dentry, (void __user *)arg);
15855 + case AUFS_CTL_WBR_FD:
15856 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
15860 + /* do not call the lower */
15861 + AuDbg("0x%x\n", cmd);
15869 +#ifdef CONFIG_COMPAT
15870 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15871 + unsigned long arg)
15876 + case AUFS_CTL_RDU:
15877 + case AUFS_CTL_RDU_INO:
15878 + err = au_rdu_compat_ioctl(file, cmd, arg);
15881 + case AUFS_CTL_IBUSY:
15882 + err = au_ibusy_compat_ioctl(file, arg);
15886 + err = aufs_ioctl_dir(file, cmd, arg);
15893 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15894 + unsigned long arg)
15896 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
15899 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
15900 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
15901 +++ linux/fs/aufs/i_op_add.c 2014-06-24 00:14:06.782719306 +0200
15904 + * Copyright (C) 2005-2014 Junjiro R. Okajima
15906 + * This program, aufs is free software; you can redistribute it and/or modify
15907 + * it under the terms of the GNU General Public License as published by
15908 + * the Free Software Foundation; either version 2 of the License, or
15909 + * (at your option) any later version.
15911 + * This program is distributed in the hope that it will be useful,
15912 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15913 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15914 + * GNU General Public License for more details.
15916 + * You should have received a copy of the GNU General Public License
15917 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15921 + * inode operations (add entry)
15927 + * final procedure of adding a new entry, except link(2).
15928 + * remove whiteout, instantiate, copyup the parent dir's times and size
15929 + * and update version.
15930 + * if it failed, re-create the removed whiteout.
15932 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
15933 + struct dentry *wh_dentry, struct dentry *dentry)
15936 + aufs_bindex_t bwh;
15937 + struct path h_path;
15938 + struct inode *inode, *h_dir;
15939 + struct dentry *wh;
15943 + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
15944 + IMustLock(h_dir);
15945 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
15946 + bwh = au_dbwh(dentry);
15947 + h_path.dentry = wh_dentry;
15948 + h_path.mnt = au_sbr_mnt(dir->i_sb, bindex);
15949 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
15951 + if (unlikely(err))
15955 + inode = au_new_inode(dentry, /*must_new*/1);
15956 + if (!IS_ERR(inode)) {
15957 + d_instantiate(dentry, inode);
15958 + dir = dentry->d_parent->d_inode; /* dir inode is locked */
15960 + if (au_ibstart(dir) == au_dbstart(dentry))
15961 + au_cpup_attr_timesizes(dir);
15962 + dir->i_version++;
15963 + return 0; /* success */
15966 + err = PTR_ERR(inode);
15971 + /* dir inode is locked */
15972 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
15973 + rerr = PTR_ERR(wh);
15974 + if (IS_ERR(wh)) {
15975 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
15976 + dentry, err, rerr);
15985 +static int au_d_may_add(struct dentry *dentry)
15990 + if (unlikely(d_unhashed(dentry)))
15992 + if (unlikely(dentry->d_inode))
15998 + * simple tests for the adding inode operations.
15999 + * following the checks in vfs, plus the parent-child relationship.
16001 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
16002 + struct dentry *h_parent, int isdir)
16006 + struct dentry *h_dentry;
16007 + struct inode *h_inode;
16009 + err = -ENAMETOOLONG;
16010 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
16013 + h_dentry = au_h_dptr(dentry, bindex);
16014 + h_inode = h_dentry->d_inode;
16015 + if (!dentry->d_inode) {
16017 + if (unlikely(h_inode))
16020 + /* rename(2) case */
16022 + if (unlikely(!h_inode || !h_inode->i_nlink))
16025 + h_mode = h_inode->i_mode;
16028 + if (unlikely(S_ISDIR(h_mode)))
16030 + } else if (unlikely(!S_ISDIR(h_mode))) {
16037 + /* expected parent dir is locked */
16038 + if (unlikely(h_parent != h_dentry->d_parent))
16047 + * initial procedure of adding a new entry.
16048 + * prepare writable branch and the parent dir, lock it,
16049 + * and lookup whiteout for the new entry.
16051 +static struct dentry*
16052 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
16053 + struct dentry *src_dentry, struct au_pin *pin,
16054 + struct au_wr_dir_args *wr_dir_args)
16056 + struct dentry *wh_dentry, *h_parent;
16057 + struct super_block *sb;
16058 + struct au_branch *br;
16060 + unsigned int udba;
16061 + aufs_bindex_t bcpup;
16063 + AuDbg("%pd\n", dentry);
16065 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
16067 + wh_dentry = ERR_PTR(err);
16068 + if (unlikely(err < 0))
16071 + sb = dentry->d_sb;
16072 + udba = au_opt_udba(sb);
16073 + err = au_pin(pin, dentry, bcpup, udba,
16074 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
16075 + wh_dentry = ERR_PTR(err);
16076 + if (unlikely(err))
16079 + h_parent = au_pinned_h_parent(pin);
16080 + if (udba != AuOpt_UDBA_NONE
16081 + && au_dbstart(dentry) == bcpup)
16082 + err = au_may_add(dentry, bcpup, h_parent,
16083 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
16084 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
16085 + err = -ENAMETOOLONG;
16086 + wh_dentry = ERR_PTR(err);
16087 + if (unlikely(err))
16090 + br = au_sbr(sb, bcpup);
16092 + struct path tmp = {
16093 + .dentry = h_parent,
16094 + .mnt = au_br_mnt(br)
16096 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
16099 + wh_dentry = NULL;
16100 + if (bcpup != au_dbwh(dentry))
16101 + goto out; /* success */
16103 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
16106 + if (IS_ERR(wh_dentry))
16109 + return wh_dentry;
16112 +/* ---------------------------------------------------------------------- */
16114 +enum { Mknod, Symlink, Creat };
16115 +struct simple_arg {
16123 + const char *symname;
16132 +static int add_simple(struct inode *dir, struct dentry *dentry,
16133 + struct simple_arg *arg)
16136 + aufs_bindex_t bstart;
16137 + unsigned char created;
16138 + struct dentry *wh_dentry, *parent;
16139 + struct inode *h_dir;
16140 + /* to reuduce stack size */
16142 + struct au_dtime dt;
16143 + struct au_pin pin;
16144 + struct path h_path;
16145 + struct au_wr_dir_args wr_dir_args;
16148 + AuDbg("%pd\n", dentry);
16152 + a = kmalloc(sizeof(*a), GFP_NOFS);
16153 + if (unlikely(!a))
16155 + a->wr_dir_args.force_btgt = -1;
16156 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
16158 + parent = dentry->d_parent; /* dir inode is locked */
16159 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
16160 + if (unlikely(err))
16162 + err = au_d_may_add(dentry);
16163 + if (unlikely(err))
16165 + di_write_lock_parent(parent);
16166 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
16167 + &a->pin, &a->wr_dir_args);
16168 + err = PTR_ERR(wh_dentry);
16169 + if (IS_ERR(wh_dentry))
16172 + bstart = au_dbstart(dentry);
16173 + a->h_path.dentry = au_h_dptr(dentry, bstart);
16174 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
16175 + h_dir = au_pinned_h_dir(&a->pin);
16176 + switch (arg->type) {
16178 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
16179 + arg->u.c.want_excl);
16182 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
16185 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
16193 + err = epilog(dir, bstart, wh_dentry, dentry);
16196 + if (unlikely(created && err && a->h_path.dentry->d_inode)) {
16198 + /* no delegation since it is just created */
16199 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
16202 + AuIOErr("%pd revert failure(%d, %d)\n",
16203 + dentry, err, rerr);
16206 + au_dtime_revert(&a->dt);
16209 + au_unpin(&a->pin);
16213 + di_write_unlock(parent);
16215 + if (unlikely(err)) {
16216 + au_update_dbstart(dentry);
16219 + aufs_read_unlock(dentry, AuLock_DW);
16226 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
16229 + struct simple_arg arg = {
16236 + return add_simple(dir, dentry, &arg);
16239 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
16241 + struct simple_arg arg = {
16243 + .u.s.symname = symname
16245 + return add_simple(dir, dentry, &arg);
16248 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
16251 + struct simple_arg arg = {
16255 + .want_excl = want_excl
16258 + return add_simple(dir, dentry, &arg);
16261 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
16264 + aufs_bindex_t bindex;
16265 + struct super_block *sb;
16266 + struct dentry *parent, *h_parent, *h_dentry;
16267 + struct inode *h_dir, *inode;
16268 + struct vfsmount *h_mnt;
16269 + struct au_wr_dir_args wr_dir_args = {
16270 + .force_btgt = -1,
16271 + .flags = AuWrDir_TMPFILE
16274 + /* copy-up may happen */
16275 + mutex_lock(&dir->i_mutex);
16278 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16279 + if (unlikely(err))
16282 + err = au_di_init(dentry);
16283 + if (unlikely(err))
16287 + parent = d_find_any_alias(dir);
16288 + AuDebugOn(!parent);
16289 + di_write_lock_parent(parent);
16290 + if (unlikely(parent->d_inode != dir))
16293 + err = au_digen_test(parent, au_sigen(sb));
16294 + if (unlikely(err))
16297 + bindex = au_dbstart(parent);
16298 + au_set_dbstart(dentry, bindex);
16299 + au_set_dbend(dentry, bindex);
16300 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
16302 + if (unlikely(err < 0))
16305 + err = -EOPNOTSUPP;
16306 + h_dir = au_h_iptr(dir, bindex);
16307 + if (unlikely(!h_dir->i_op->tmpfile))
16310 + h_mnt = au_sbr_mnt(sb, bindex);
16311 + err = vfsub_mnt_want_write(h_mnt);
16312 + if (unlikely(err))
16315 + h_parent = au_h_dptr(parent, bindex);
16316 + err = inode_permission(h_parent->d_inode, MAY_WRITE | MAY_EXEC);
16317 + if (unlikely(err))
16321 + h_dentry = d_alloc(h_parent, &dentry->d_name);
16322 + if (unlikely(!h_dentry))
16325 + err = h_dir->i_op->tmpfile(h_dir, h_dentry, mode);
16326 + if (unlikely(err))
16329 + au_set_dbstart(dentry, bindex);
16330 + au_set_dbend(dentry, bindex);
16331 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
16332 + inode = au_new_inode(dentry, /*must_new*/1);
16333 + if (IS_ERR(inode)) {
16334 + err = PTR_ERR(inode);
16335 + au_set_h_dptr(dentry, bindex, NULL);
16336 + au_set_dbstart(dentry, -1);
16337 + au_set_dbend(dentry, -1);
16339 + if (!inode->i_nlink)
16340 + set_nlink(inode, 1);
16341 + d_tmpfile(dentry, inode);
16342 + au_di(dentry)->di_tmpfile = 1;
16344 + /* update without i_mutex */
16345 + if (au_ibstart(dir) == au_dbstart(dentry))
16346 + au_cpup_attr_timesizes(dir);
16352 + vfsub_mnt_drop_write(h_mnt);
16354 + di_write_unlock(parent);
16356 + di_write_unlock(dentry);
16359 + /* verbose coding for lock class name */
16360 + au_rw_class(&au_di(dentry)->di_rwsem,
16361 + au_lc_key + AuLcNonDir_DIINFO);
16366 + au_di_fin(dentry);
16367 + dentry->d_fsdata = NULL;
16370 + si_read_unlock(sb);
16372 + mutex_unlock(&dir->i_mutex);
16376 +/* ---------------------------------------------------------------------- */
16378 +struct au_link_args {
16379 + aufs_bindex_t bdst, bsrc;
16380 + struct au_pin pin;
16381 + struct path h_path;
16382 + struct dentry *src_parent, *parent;
16385 +static int au_cpup_before_link(struct dentry *src_dentry,
16386 + struct au_link_args *a)
16389 + struct dentry *h_src_dentry;
16390 + struct au_cp_generic cpg = {
16391 + .dentry = src_dentry,
16396 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
16399 + di_read_lock_parent(a->src_parent, AuLock_IR);
16400 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
16401 + if (unlikely(err))
16404 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
16405 + err = au_pin(&a->pin, src_dentry, a->bdst,
16406 + au_opt_udba(src_dentry->d_sb),
16407 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
16408 + if (unlikely(err))
16411 + err = au_sio_cpup_simple(&cpg);
16412 + au_unpin(&a->pin);
16415 + di_read_unlock(a->src_parent, AuLock_IR);
16419 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
16420 + struct au_link_args *a)
16423 + unsigned char plink;
16424 + aufs_bindex_t bend;
16425 + struct dentry *h_src_dentry;
16426 + struct inode *h_inode, *inode, *delegated;
16427 + struct super_block *sb;
16428 + struct file *h_file;
16432 + sb = src_dentry->d_sb;
16433 + inode = src_dentry->d_inode;
16434 + if (au_ibstart(inode) <= a->bdst)
16435 + h_inode = au_h_iptr(inode, a->bdst);
16436 + if (!h_inode || !h_inode->i_nlink) {
16437 + /* copyup src_dentry as the name of dentry. */
16438 + bend = au_dbend(dentry);
16439 + if (bend < a->bsrc)
16440 + au_set_dbend(dentry, a->bsrc);
16441 + au_set_h_dptr(dentry, a->bsrc,
16442 + dget(au_h_dptr(src_dentry, a->bsrc)));
16443 + dget(a->h_path.dentry);
16444 + au_set_h_dptr(dentry, a->bdst, NULL);
16445 + dentry->d_inode = src_dentry->d_inode; /* tmp */
16446 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
16447 + if (IS_ERR(h_file))
16448 + err = PTR_ERR(h_file);
16450 + struct au_cp_generic cpg = {
16451 + .dentry = dentry,
16456 + .flags = AuCpup_KEEPLINO
16458 + err = au_sio_cpup_simple(&cpg);
16459 + au_h_open_post(dentry, a->bsrc, h_file);
16461 + dput(a->h_path.dentry);
16462 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
16464 + au_set_h_dptr(dentry, a->bdst,
16465 + a->h_path.dentry);
16467 + dentry->d_inode = NULL; /* restore */
16468 + au_set_h_dptr(dentry, a->bsrc, NULL);
16469 + au_set_dbend(dentry, bend);
16471 + /* the inode of src_dentry already exists on a.bdst branch */
16472 + h_src_dentry = d_find_alias(h_inode);
16473 + if (!h_src_dentry && au_plink_test(inode)) {
16475 + h_src_dentry = au_plink_lkup(inode, a->bdst);
16476 + err = PTR_ERR(h_src_dentry);
16477 + if (IS_ERR(h_src_dentry))
16480 + if (unlikely(!h_src_dentry->d_inode)) {
16481 + dput(h_src_dentry);
16482 + h_src_dentry = NULL;
16486 + if (h_src_dentry) {
16487 + delegated = NULL;
16488 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
16489 + &a->h_path, &delegated);
16490 + if (unlikely(err == -EWOULDBLOCK)) {
16491 + pr_warn("cannot retry for NFSv4 delegation"
16492 + " for an internal link\n");
16495 + dput(h_src_dentry);
16497 + AuIOErr("no dentry found for hi%lu on b%d\n",
16498 + h_inode->i_ino, a->bdst);
16503 + if (!err && !plink)
16504 + au_plink_append(inode, a->bdst, a->h_path.dentry);
16511 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
16512 + struct dentry *dentry)
16515 + struct au_dtime dt;
16516 + struct au_link_args *a;
16517 + struct dentry *wh_dentry, *h_src_dentry;
16518 + struct inode *inode, *delegated;
16519 + struct super_block *sb;
16520 + struct au_wr_dir_args wr_dir_args = {
16521 + /* .force_btgt = -1, */
16522 + .flags = AuWrDir_ADD_ENTRY
16526 + inode = src_dentry->d_inode;
16527 + IMustLock(inode);
16530 + a = kzalloc(sizeof(*a), GFP_NOFS);
16531 + if (unlikely(!a))
16534 + a->parent = dentry->d_parent; /* dir inode is locked */
16535 + err = aufs_read_and_write_lock2(dentry, src_dentry,
16536 + AuLock_NOPLM | AuLock_GEN);
16537 + if (unlikely(err))
16539 + err = au_d_linkable(src_dentry);
16540 + if (unlikely(err))
16542 + err = au_d_may_add(dentry);
16543 + if (unlikely(err))
16546 + a->src_parent = dget_parent(src_dentry);
16547 + wr_dir_args.force_btgt = au_ibstart(inode);
16549 + di_write_lock_parent(a->parent);
16550 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
16551 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
16553 + err = PTR_ERR(wh_dentry);
16554 + if (IS_ERR(wh_dentry))
16558 + sb = dentry->d_sb;
16559 + a->bdst = au_dbstart(dentry);
16560 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
16561 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
16562 + a->bsrc = au_ibstart(inode);
16563 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
16564 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
16565 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
16566 + if (!h_src_dentry) {
16567 + a->bsrc = au_dbstart(src_dentry);
16568 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
16569 + AuDebugOn(!h_src_dentry);
16570 + } else if (IS_ERR(h_src_dentry)) {
16571 + err = PTR_ERR(h_src_dentry);
16575 + if (au_opt_test(au_mntflags(sb), PLINK)) {
16576 + if (a->bdst < a->bsrc
16577 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
16578 + err = au_cpup_or_link(src_dentry, dentry, a);
16580 + delegated = NULL;
16581 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
16582 + &a->h_path, &delegated);
16583 + if (unlikely(err == -EWOULDBLOCK)) {
16584 + pr_warn("cannot retry for NFSv4 delegation"
16585 + " for an internal link\n");
16589 + dput(h_src_dentry);
16592 + * copyup src_dentry to the branch we process,
16593 + * and then link(2) to it.
16595 + dput(h_src_dentry);
16596 + if (a->bdst < a->bsrc
16597 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
16598 + au_unpin(&a->pin);
16599 + di_write_unlock(a->parent);
16600 + err = au_cpup_before_link(src_dentry, a);
16601 + di_write_lock_parent(a->parent);
16603 + err = au_pin(&a->pin, dentry, a->bdst,
16605 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
16606 + if (unlikely(err))
16610 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
16612 + if (h_src_dentry && h_src_dentry->d_inode) {
16613 + delegated = NULL;
16614 + err = vfsub_link(h_src_dentry,
16615 + au_pinned_h_dir(&a->pin),
16616 + &a->h_path, &delegated);
16617 + if (unlikely(err == -EWOULDBLOCK)) {
16618 + pr_warn("cannot retry"
16619 + " for NFSv4 delegation"
16620 + " for an internal link\n");
16626 + if (unlikely(err))
16630 + a->h_path.dentry = wh_dentry;
16631 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
16633 + if (unlikely(err))
16637 + dir->i_version++;
16638 + if (au_ibstart(dir) == au_dbstart(dentry))
16639 + au_cpup_attr_timesizes(dir);
16640 + inc_nlink(inode);
16641 + inode->i_ctime = dir->i_ctime;
16642 + d_instantiate(dentry, au_igrab(inode));
16643 + if (d_unhashed(a->h_path.dentry))
16644 + /* some filesystem calls d_drop() */
16646 + goto out_unpin; /* success */
16649 + /* no delegation since it is just created */
16650 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
16651 + /*delegated*/NULL, /*force*/0);
16652 + if (unlikely(rerr)) {
16653 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
16656 + au_dtime_revert(&dt);
16658 + au_unpin(&a->pin);
16662 + di_write_unlock(a->parent);
16663 + dput(a->src_parent);
16665 + if (unlikely(err)) {
16666 + au_update_dbstart(dentry);
16669 + aufs_read_and_write_unlock2(dentry, src_dentry);
16677 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
16680 + aufs_bindex_t bindex;
16681 + unsigned char diropq;
16682 + struct path h_path;
16683 + struct dentry *wh_dentry, *parent, *opq_dentry;
16684 + struct mutex *h_mtx;
16685 + struct super_block *sb;
16687 + struct au_pin pin;
16688 + struct au_dtime dt;
16689 + } *a; /* reduce the stack usage */
16690 + struct au_wr_dir_args wr_dir_args = {
16691 + .force_btgt = -1,
16692 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
16698 + a = kmalloc(sizeof(*a), GFP_NOFS);
16699 + if (unlikely(!a))
16702 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
16703 + if (unlikely(err))
16705 + err = au_d_may_add(dentry);
16706 + if (unlikely(err))
16709 + parent = dentry->d_parent; /* dir inode is locked */
16710 + di_write_lock_parent(parent);
16711 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
16712 + &a->pin, &wr_dir_args);
16713 + err = PTR_ERR(wh_dentry);
16714 + if (IS_ERR(wh_dentry))
16717 + sb = dentry->d_sb;
16718 + bindex = au_dbstart(dentry);
16719 + h_path.dentry = au_h_dptr(dentry, bindex);
16720 + h_path.mnt = au_sbr_mnt(sb, bindex);
16721 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
16722 + if (unlikely(err))
16725 + /* make the dir opaque */
16727 + h_mtx = &h_path.dentry->d_inode->i_mutex;
16729 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
16730 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
16731 + opq_dentry = au_diropq_create(dentry, bindex);
16732 + mutex_unlock(h_mtx);
16733 + err = PTR_ERR(opq_dentry);
16734 + if (IS_ERR(opq_dentry))
16736 + dput(opq_dentry);
16740 + err = epilog(dir, bindex, wh_dentry, dentry);
16743 + goto out_unpin; /* success */
16748 + AuLabel(revert opq);
16749 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
16750 + rerr = au_diropq_remove(dentry, bindex);
16751 + mutex_unlock(h_mtx);
16753 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
16754 + dentry, err, rerr);
16760 + AuLabel(revert dir);
16761 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
16763 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
16764 + dentry, err, rerr);
16767 + au_dtime_revert(&a->dt);
16769 + au_unpin(&a->pin);
16772 + di_write_unlock(parent);
16774 + if (unlikely(err)) {
16775 + au_update_dbstart(dentry);
16778 + aufs_read_unlock(dentry, AuLock_DW);
16784 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
16785 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
16786 +++ linux/fs/aufs/i_op.c 2014-06-24 00:14:06.782719306 +0200
16789 + * Copyright (C) 2005-2014 Junjiro R. Okajima
16791 + * This program, aufs is free software; you can redistribute it and/or modify
16792 + * it under the terms of the GNU General Public License as published by
16793 + * the Free Software Foundation; either version 2 of the License, or
16794 + * (at your option) any later version.
16796 + * This program is distributed in the hope that it will be useful,
16797 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16798 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16799 + * GNU General Public License for more details.
16801 + * You should have received a copy of the GNU General Public License
16802 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16806 + * inode operations (except add/del/rename)
16809 +#include <linux/device_cgroup.h>
16810 +#include <linux/fs_stack.h>
16811 +#include <linux/mm.h>
16812 +#include <linux/namei.h>
16813 +#include <linux/security.h>
16816 +static int h_permission(struct inode *h_inode, int mask,
16817 + struct vfsmount *h_mnt, int brperm)
16820 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
16823 + if ((write_mask && IS_IMMUTABLE(h_inode))
16824 + || ((mask & MAY_EXEC)
16825 + && S_ISREG(h_inode->i_mode)
16826 + && ((h_mnt->mnt_flags & MNT_NOEXEC)
16827 + || !(h_inode->i_mode & S_IXUGO))))
16831 + * - skip the lower fs test in the case of write to ro branch.
16832 + * - nfs dir permission write check is optimized, but a policy for
16833 + * link/rename requires a real check.
16835 + if ((write_mask && !au_br_writable(brperm))
16836 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
16837 + && write_mask && !(mask & MAY_READ))
16838 + || !h_inode->i_op->permission) {
16839 + /* AuLabel(generic_permission); */
16840 + err = generic_permission(h_inode, mask);
16842 + /* AuLabel(h_inode->permission); */
16843 + err = h_inode->i_op->permission(h_inode, mask);
16848 + err = devcgroup_inode_permission(h_inode, mask);
16850 + err = security_inode_permission(h_inode, mask);
16854 + /* todo: do we need to call ima_path_check()? */
16855 + struct path h_path = {
16859 + err = ima_path_check(&h_path,
16860 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
16861 + IMA_COUNT_LEAVE);
16869 +static int aufs_permission(struct inode *inode, int mask)
16872 + aufs_bindex_t bindex, bend;
16873 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
16874 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
16875 + struct inode *h_inode;
16876 + struct super_block *sb;
16877 + struct au_branch *br;
16879 + /* todo: support rcu-walk? */
16880 + if (mask & MAY_NOT_BLOCK)
16883 + sb = inode->i_sb;
16884 + si_read_lock(sb, AuLock_FLUSH);
16885 + ii_read_lock_child(inode);
16887 + err = au_iigen_test(inode, au_sigen(sb));
16888 + if (unlikely(err))
16892 + if (!isdir || write_mask) {
16893 + err = au_busy_or_stale();
16894 + h_inode = au_h_iptr(inode, au_ibstart(inode));
16895 + if (unlikely(!h_inode
16896 + || (h_inode->i_mode & S_IFMT)
16897 + != (inode->i_mode & S_IFMT)))
16901 + bindex = au_ibstart(inode);
16902 + br = au_sbr(sb, bindex);
16903 + err = h_permission(h_inode, mask, au_br_mnt(br), br->br_perm);
16906 + && !special_file(h_inode->i_mode)) {
16907 + /* test whether the upper writable branch exists */
16909 + for (; bindex >= 0; bindex--)
16910 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
16918 + /* non-write to dir */
16920 + bend = au_ibend(inode);
16921 + for (bindex = au_ibstart(inode); !err && bindex <= bend; bindex++) {
16922 + h_inode = au_h_iptr(inode, bindex);
16924 + err = au_busy_or_stale();
16925 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
16928 + br = au_sbr(sb, bindex);
16929 + err = h_permission(h_inode, mask, au_br_mnt(br),
16935 + ii_read_unlock(inode);
16936 + si_read_unlock(sb);
16940 +/* ---------------------------------------------------------------------- */
16942 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
16943 + unsigned int flags)
16945 + struct dentry *ret, *parent;
16946 + struct inode *inode;
16947 + struct super_block *sb;
16948 + int err, npositive;
16952 + /* todo: support rcu-walk? */
16953 + ret = ERR_PTR(-ECHILD);
16954 + if (flags & LOOKUP_RCU)
16957 + ret = ERR_PTR(-ENAMETOOLONG);
16958 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
16962 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16963 + ret = ERR_PTR(err);
16964 + if (unlikely(err))
16967 + err = au_di_init(dentry);
16968 + ret = ERR_PTR(err);
16969 + if (unlikely(err))
16973 + npositive = 0; /* suppress a warning */
16974 + parent = dentry->d_parent; /* dir inode is locked */
16975 + di_read_lock_parent(parent, AuLock_IR);
16976 + err = au_alive_dir(parent);
16978 + err = au_digen_test(parent, au_sigen(sb));
16980 + npositive = au_lkup_dentry(dentry, au_dbstart(parent),
16984 + di_read_unlock(parent, AuLock_IR);
16985 + ret = ERR_PTR(err);
16986 + if (unlikely(err < 0))
16990 + inode = au_new_inode(dentry, /*must_new*/0);
16991 + ret = (void *)inode;
16993 + if (IS_ERR(inode)) {
16998 + ret = d_splice_alias(inode, dentry);
17000 + if (unlikely(d_need_lookup(dentry))) {
17001 + spin_lock(&dentry->d_lock);
17002 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
17003 + spin_unlock(&dentry->d_lock);
17006 + if (unlikely(IS_ERR(ret) && inode)) {
17007 + ii_write_unlock(inode);
17013 + di_write_unlock(dentry);
17015 + /* verbose coding for lock class name */
17016 + if (unlikely(S_ISLNK(inode->i_mode)))
17017 + au_rw_class(&au_di(dentry)->di_rwsem,
17018 + au_lc_key + AuLcSymlink_DIINFO);
17019 + else if (unlikely(S_ISDIR(inode->i_mode)))
17020 + au_rw_class(&au_di(dentry)->di_rwsem,
17021 + au_lc_key + AuLcDir_DIINFO);
17022 + else /* likely */
17023 + au_rw_class(&au_di(dentry)->di_rwsem,
17024 + au_lc_key + AuLcNonDir_DIINFO);
17027 + si_read_unlock(sb);
17032 +/* ---------------------------------------------------------------------- */
17034 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
17035 + const unsigned char add_entry, aufs_bindex_t bcpup,
17036 + aufs_bindex_t bstart)
17039 + struct dentry *h_parent;
17040 + struct inode *h_dir;
17043 + IMustLock(parent->d_inode);
17045 + di_write_lock_parent(parent);
17048 + if (!au_h_dptr(parent, bcpup)) {
17049 + if (bstart > bcpup)
17050 + err = au_cpup_dirs(dentry, bcpup);
17051 + else if (bstart < bcpup)
17052 + err = au_cpdown_dirs(dentry, bcpup);
17056 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
17057 + h_parent = au_h_dptr(parent, bcpup);
17058 + h_dir = h_parent->d_inode;
17059 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
17060 + err = au_lkup_neg(dentry, bcpup,
17061 + au_ftest_wrdir(add_entry, TMP_WHENTRY));
17062 + /* todo: no unlock here */
17063 + mutex_unlock(&h_dir->i_mutex);
17065 + AuDbg("bcpup %d\n", bcpup);
17067 + if (!dentry->d_inode)
17068 + au_set_h_dptr(dentry, bstart, NULL);
17069 + au_update_dbrange(dentry, /*do_put_zero*/0);
17074 + di_write_unlock(parent);
17076 + err = bcpup; /* success */
17083 + * decide the branch and the parent dir where we will create a new entry.
17084 + * returns new bindex or an error.
17085 + * copyup the parent dir if needed.
17087 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
17088 + struct au_wr_dir_args *args)
17091 + unsigned int flags;
17092 + aufs_bindex_t bcpup, bstart, src_bstart;
17093 + const unsigned char add_entry
17094 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
17095 + | au_ftest_wrdir(args->flags, TMP_WHENTRY)
17096 + | au_ftest_wrdir(args->flags, TMPFILE);
17097 + struct super_block *sb;
17098 + struct dentry *parent;
17099 + struct au_sbinfo *sbinfo;
17101 + sb = dentry->d_sb;
17102 + sbinfo = au_sbi(sb);
17103 + parent = dget_parent(dentry);
17104 + bstart = au_dbstart(dentry);
17106 + if (args->force_btgt < 0) {
17107 + if (src_dentry) {
17108 + src_bstart = au_dbstart(src_dentry);
17109 + if (src_bstart < bstart)
17110 + bcpup = src_bstart;
17111 + } else if (add_entry) {
17113 + if (au_ftest_wrdir(args->flags, ISDIR))
17114 + au_fset_wbr(flags, DIR);
17115 + err = AuWbrCreate(sbinfo, dentry, flags);
17119 + if (bcpup < 0 || au_test_ro(sb, bcpup, dentry->d_inode)) {
17121 + err = AuWbrCopyup(sbinfo, dentry);
17123 + if (!IS_ROOT(dentry)) {
17124 + di_read_lock_parent(parent, !AuLock_IR);
17125 + err = AuWbrCopyup(sbinfo, dentry);
17126 + di_read_unlock(parent, !AuLock_IR);
17128 + err = AuWbrCopyup(sbinfo, dentry);
17131 + if (unlikely(err < 0))
17135 + bcpup = args->force_btgt;
17136 + AuDebugOn(au_test_ro(sb, bcpup, dentry->d_inode));
17139 + AuDbg("bstart %d, bcpup %d\n", bstart, bcpup);
17141 + if (bcpup == bstart)
17142 + goto out; /* success */
17144 + /* copyup the new parent into the branch we process */
17145 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, bstart);
17147 + if (!dentry->d_inode) {
17148 + au_set_h_dptr(dentry, bstart, NULL);
17149 + au_set_dbstart(dentry, bcpup);
17150 + au_set_dbend(dentry, bcpup);
17152 + AuDebugOn(add_entry
17153 + && !au_ftest_wrdir(args->flags, TMPFILE)
17154 + && !au_h_dptr(dentry, bcpup));
17162 +/* ---------------------------------------------------------------------- */
17164 +void au_pin_hdir_unlock(struct au_pin *p)
17167 + au_hn_imtx_unlock(p->hdir);
17170 +static int au_pin_hdir_lock(struct au_pin *p)
17178 + /* even if an error happens later, keep this lock */
17179 + au_hn_imtx_lock_nested(p->hdir, p->lsc_hi);
17182 + if (unlikely(p->hdir->hi_inode != p->h_parent->d_inode))
17187 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
17188 + p->h_parent, p->br);
17194 +int au_pin_hdir_relock(struct au_pin *p)
17197 + struct inode *h_i;
17198 + struct dentry *h_d[] = {
17203 + err = au_pin_hdir_lock(p);
17204 + if (unlikely(err))
17207 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
17210 + h_i = h_d[i]->d_inode;
17212 + err = !h_i->i_nlink;
17219 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
17221 +#if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
17222 + p->hdir->hi_inode->i_mutex.owner = task;
17226 +void au_pin_hdir_acquire_nest(struct au_pin *p)
17229 + mutex_acquire_nest(&p->hdir->hi_inode->i_mutex.dep_map,
17230 + p->lsc_hi, 0, NULL, _RET_IP_);
17231 + au_pin_hdir_set_owner(p, current);
17235 +void au_pin_hdir_release(struct au_pin *p)
17238 + au_pin_hdir_set_owner(p, p->task);
17239 + mutex_release(&p->hdir->hi_inode->i_mutex.dep_map, 1, _RET_IP_);
17243 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
17245 + if (pin && pin->parent)
17246 + return au_h_dptr(pin->parent, pin->bindex);
17250 +void au_unpin(struct au_pin *p)
17253 + au_pin_hdir_unlock(p);
17254 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
17255 + vfsub_mnt_drop_write(p->h_mnt);
17259 + if (!au_ftest_pin(p->flags, DI_LOCKED))
17260 + di_read_unlock(p->parent, AuLock_IR);
17261 + iput(p->hdir->hi_inode);
17263 + p->parent = NULL;
17266 + /* do not clear p->task */
17269 +int au_do_pin(struct au_pin *p)
17272 + struct super_block *sb;
17273 + struct inode *h_dir;
17276 + sb = p->dentry->d_sb;
17277 + p->br = au_sbr(sb, p->bindex);
17278 + if (IS_ROOT(p->dentry)) {
17279 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
17280 + p->h_mnt = au_br_mnt(p->br);
17281 + err = vfsub_mnt_want_write(p->h_mnt);
17282 + if (unlikely(err)) {
17283 + au_fclr_pin(p->flags, MNT_WRITE);
17290 + p->h_dentry = NULL;
17291 + if (p->bindex <= au_dbend(p->dentry))
17292 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
17294 + p->parent = dget_parent(p->dentry);
17295 + if (!au_ftest_pin(p->flags, DI_LOCKED))
17296 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
17299 + p->h_parent = au_h_dptr(p->parent, p->bindex);
17300 + p->hdir = au_hi(p->parent->d_inode, p->bindex);
17302 + h_dir = p->hdir->hi_inode;
17306 + * if DI_LOCKED is not set, then p->parent may be different
17307 + * and h_parent can be NULL.
17309 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
17311 + if (!au_ftest_pin(p->flags, DI_LOCKED))
17312 + di_read_unlock(p->parent, AuLock_IR);
17314 + p->parent = NULL;
17318 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
17319 + p->h_mnt = au_br_mnt(p->br);
17320 + err = vfsub_mnt_want_write(p->h_mnt);
17321 + if (unlikely(err)) {
17322 + au_fclr_pin(p->flags, MNT_WRITE);
17323 + if (!au_ftest_pin(p->flags, DI_LOCKED))
17324 + di_read_unlock(p->parent, AuLock_IR);
17326 + p->parent = NULL;
17332 + err = au_pin_hdir_lock(p);
17334 + goto out; /* success */
17337 + pr_err("err %d\n", err);
17338 + err = au_busy_or_stale();
17343 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
17344 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
17345 + unsigned int udba, unsigned char flags)
17347 + p->dentry = dentry;
17349 + p->lsc_di = lsc_di;
17350 + p->lsc_hi = lsc_hi;
17351 + p->flags = flags;
17352 + p->bindex = bindex;
17354 + p->parent = NULL;
17358 + p->h_dentry = NULL;
17359 + p->h_parent = NULL;
17361 + p->task = current;
17364 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
17365 + unsigned int udba, unsigned char flags)
17367 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
17369 + return au_do_pin(pin);
17372 +/* ---------------------------------------------------------------------- */
17375 + * ->setattr() and ->getattr() are called in various cases.
17376 + * chmod, stat: dentry is revalidated.
17377 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
17379 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
17381 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
17382 +static int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
17385 + struct inode *inode;
17386 + struct dentry *parent;
17389 + inode = dentry->d_inode;
17390 + if (au_digen_test(dentry, sigen)) {
17391 + parent = dget_parent(dentry);
17392 + di_read_lock_parent(parent, AuLock_IR);
17393 + err = au_refresh_dentry(dentry, parent);
17394 + di_read_unlock(parent, AuLock_IR);
17402 +#define AuIcpup_DID_CPUP 1
17403 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
17404 +#define au_fset_icpup(flags, name) \
17405 + do { (flags) |= AuIcpup_##name; } while (0)
17406 +#define au_fclr_icpup(flags, name) \
17407 + do { (flags) &= ~AuIcpup_##name; } while (0)
17409 +struct au_icpup_args {
17410 + unsigned char flags;
17411 + unsigned char pin_flags;
17412 + aufs_bindex_t btgt;
17413 + unsigned int udba;
17414 + struct au_pin pin;
17415 + struct path h_path;
17416 + struct inode *h_inode;
17419 +static int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
17420 + struct au_icpup_args *a)
17424 + aufs_bindex_t bstart, ibstart;
17425 + struct dentry *hi_wh, *parent;
17426 + struct inode *inode;
17427 + struct au_wr_dir_args wr_dir_args = {
17428 + .force_btgt = -1,
17432 + bstart = au_dbstart(dentry);
17433 + inode = dentry->d_inode;
17434 + if (S_ISDIR(inode->i_mode))
17435 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
17436 + /* plink or hi_wh() case */
17437 + ibstart = au_ibstart(inode);
17438 + if (bstart != ibstart && !au_test_ro(inode->i_sb, ibstart, inode))
17439 + wr_dir_args.force_btgt = ibstart;
17440 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
17441 + if (unlikely(err < 0))
17444 + if (err != bstart)
17445 + au_fset_icpup(a->flags, DID_CPUP);
17448 + a->pin_flags = AuPin_MNT_WRITE;
17450 + if (!IS_ROOT(dentry)) {
17451 + au_fset_pin(a->pin_flags, DI_LOCKED);
17452 + parent = dget_parent(dentry);
17453 + di_write_lock_parent(parent);
17456 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
17457 + if (unlikely(err))
17460 + a->h_path.dentry = au_h_dptr(dentry, bstart);
17461 + a->h_inode = a->h_path.dentry->d_inode;
17462 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
17464 + if ((ia->ia_valid & ATTR_SIZE) && ia->ia_size < i_size_read(a->h_inode))
17465 + sz = ia->ia_size;
17466 + mutex_unlock(&a->h_inode->i_mutex);
17469 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
17470 + hi_wh = au_hi_wh(inode, a->btgt);
17472 + struct au_cp_generic cpg = {
17473 + .dentry = dentry,
17479 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
17480 + if (unlikely(err))
17482 + hi_wh = au_hi_wh(inode, a->btgt);
17483 + /* todo: revalidate hi_wh? */
17488 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
17489 + di_downgrade_lock(parent, AuLock_IR);
17493 + if (!au_ftest_icpup(a->flags, DID_CPUP))
17494 + goto out; /* success */
17496 + if (!d_unhashed(dentry)) {
17497 + struct au_cp_generic cpg = {
17498 + .dentry = dentry,
17503 + .flags = AuCpup_DTIME | AuCpup_HOPEN
17505 + err = au_sio_cpup_simple(&cpg);
17507 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
17508 + } else if (!hi_wh)
17509 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
17511 + a->h_path.dentry = hi_wh; /* do not dget here */
17514 + a->h_inode = a->h_path.dentry->d_inode;
17516 + goto out; /* success */
17517 + au_unpin(&a->pin);
17520 + di_write_unlock(parent);
17525 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
17529 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
17532 + struct inode *inode, *delegated;
17533 + struct super_block *sb;
17534 + struct file *file;
17535 + struct au_icpup_args *a;
17537 + inode = dentry->d_inode;
17538 + IMustLock(inode);
17541 + a = kzalloc(sizeof(*a), GFP_NOFS);
17542 + if (unlikely(!a))
17545 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
17546 + ia->ia_valid &= ~ATTR_MODE;
17549 + sb = dentry->d_sb;
17550 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
17551 + if (unlikely(err))
17554 + if (ia->ia_valid & ATTR_FILE) {
17555 + /* currently ftruncate(2) only */
17556 + AuDebugOn(!S_ISREG(inode->i_mode));
17557 + file = ia->ia_file;
17558 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
17559 + if (unlikely(err))
17561 + ia->ia_file = au_hf_top(file);
17562 + a->udba = AuOpt_UDBA_NONE;
17564 + /* fchmod() doesn't pass ia_file */
17565 + a->udba = au_opt_udba(sb);
17566 + di_write_lock_child(dentry);
17567 + /* no d_unlinked(), to set UDBA_NONE for root */
17568 + if (d_unhashed(dentry))
17569 + a->udba = AuOpt_UDBA_NONE;
17570 + if (a->udba != AuOpt_UDBA_NONE) {
17571 + AuDebugOn(IS_ROOT(dentry));
17572 + err = au_reval_for_attr(dentry, au_sigen(sb));
17573 + if (unlikely(err))
17578 + err = au_pin_and_icpup(dentry, ia, a);
17579 + if (unlikely(err < 0))
17581 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
17582 + ia->ia_file = NULL;
17583 + ia->ia_valid &= ~ATTR_FILE;
17586 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
17587 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
17588 + == (ATTR_MODE | ATTR_CTIME)) {
17589 + err = security_path_chmod(&a->h_path, ia->ia_mode);
17590 + if (unlikely(err))
17592 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
17593 + && (ia->ia_valid & ATTR_CTIME)) {
17594 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
17595 + if (unlikely(err))
17599 + if (ia->ia_valid & ATTR_SIZE) {
17602 + if (ia->ia_size < i_size_read(inode))
17604 + truncate_setsize(inode, ia->ia_size);
17607 + if (ia->ia_valid & ATTR_FILE)
17609 + mutex_unlock(&a->h_inode->i_mutex);
17610 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
17611 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
17613 + delegated = NULL;
17615 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
17617 + err = break_deleg_wait(&delegated);
17625 + au_cpup_attr_changeable(inode);
17628 + mutex_unlock(&a->h_inode->i_mutex);
17629 + au_unpin(&a->pin);
17630 + if (unlikely(err))
17631 + au_update_dbstart(dentry);
17633 + di_write_unlock(dentry);
17635 + fi_write_unlock(file);
17636 + ia->ia_file = file;
17637 + ia->ia_valid |= ATTR_FILE;
17640 + si_read_unlock(sb);
17648 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
17649 + unsigned int nlink)
17653 + inode->i_mode = st->mode;
17654 + /* don't i_[ug]id_write() here */
17655 + inode->i_uid = st->uid;
17656 + inode->i_gid = st->gid;
17657 + inode->i_atime = st->atime;
17658 + inode->i_mtime = st->mtime;
17659 + inode->i_ctime = st->ctime;
17661 + au_cpup_attr_nlink(inode, /*force*/0);
17662 + if (S_ISDIR(inode->i_mode)) {
17663 + n = inode->i_nlink;
17666 + smp_mb(); /* for i_nlink */
17667 + /* 0 can happen */
17668 + set_nlink(inode, n);
17671 + spin_lock(&inode->i_lock);
17672 + inode->i_blocks = st->blocks;
17673 + i_size_write(inode, st->size);
17674 + spin_unlock(&inode->i_lock);
17677 +static int aufs_getattr(struct vfsmount *mnt __maybe_unused,
17678 + struct dentry *dentry, struct kstat *st)
17681 + unsigned int mnt_flags;
17682 + aufs_bindex_t bindex;
17683 + unsigned char udba_none, positive;
17684 + struct super_block *sb, *h_sb;
17685 + struct inode *inode;
17686 + struct path h_path;
17688 + sb = dentry->d_sb;
17689 + inode = dentry->d_inode;
17690 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
17691 + if (unlikely(err))
17693 + mnt_flags = au_mntflags(sb);
17694 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
17696 + /* support fstat(2) */
17697 + if (!d_unlinked(dentry) && !udba_none) {
17698 + unsigned int sigen = au_sigen(sb);
17699 + err = au_digen_test(dentry, sigen);
17701 + di_read_lock_child(dentry, AuLock_IR);
17702 + err = au_dbrange_test(dentry);
17703 + if (unlikely(err))
17706 + AuDebugOn(IS_ROOT(dentry));
17707 + di_write_lock_child(dentry);
17708 + err = au_dbrange_test(dentry);
17710 + err = au_reval_for_attr(dentry, sigen);
17711 + di_downgrade_lock(dentry, AuLock_IR);
17712 + if (unlikely(err))
17716 + di_read_lock_child(dentry, AuLock_IR);
17718 + bindex = au_ibstart(inode);
17719 + h_path.mnt = au_sbr_mnt(sb, bindex);
17720 + h_sb = h_path.mnt->mnt_sb;
17721 + if (!au_test_fs_bad_iattr(h_sb) && udba_none)
17722 + goto out_fill; /* success */
17724 + h_path.dentry = NULL;
17725 + if (au_dbstart(dentry) == bindex)
17726 + h_path.dentry = dget(au_h_dptr(dentry, bindex));
17727 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
17728 + h_path.dentry = au_plink_lkup(inode, bindex);
17729 + if (IS_ERR(h_path.dentry))
17730 + goto out_fill; /* pretending success */
17732 + /* illegally overlapped or something */
17733 + if (unlikely(!h_path.dentry))
17734 + goto out_fill; /* pretending success */
17736 + positive = !!h_path.dentry->d_inode;
17738 + err = vfs_getattr(&h_path, st);
17739 + dput(h_path.dentry);
17742 + au_refresh_iattr(inode, st,
17743 + h_path.dentry->d_inode->i_nlink);
17744 + goto out_fill; /* success */
17750 + generic_fillattr(inode, st);
17752 + di_read_unlock(dentry, AuLock_IR);
17753 + si_read_unlock(sb);
17759 +/* ---------------------------------------------------------------------- */
17761 +static int h_readlink(struct dentry *dentry, int bindex, char __user *buf,
17765 + struct super_block *sb;
17766 + struct dentry *h_dentry;
17769 + h_dentry = au_h_dptr(dentry, bindex);
17770 + if (unlikely(!h_dentry->d_inode->i_op->readlink))
17773 + err = security_inode_readlink(h_dentry);
17774 + if (unlikely(err))
17777 + sb = dentry->d_sb;
17778 + if (!au_test_ro(sb, bindex, dentry->d_inode)) {
17779 + vfsub_touch_atime(au_sbr_mnt(sb, bindex), h_dentry);
17780 + fsstack_copy_attr_atime(dentry->d_inode, h_dentry->d_inode);
17782 + err = h_dentry->d_inode->i_op->readlink(h_dentry, buf, bufsiz);
17788 +static int aufs_readlink(struct dentry *dentry, char __user *buf, int bufsiz)
17792 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
17793 + if (unlikely(err))
17795 + err = au_d_hashed_positive(dentry);
17797 + err = h_readlink(dentry, au_dbstart(dentry), buf, bufsiz);
17798 + aufs_read_unlock(dentry, AuLock_IR);
17804 +static void *aufs_follow_link(struct dentry *dentry, struct nameidata *nd)
17807 + mm_segment_t old_fs;
17814 + buf.k = (void *)__get_free_page(GFP_NOFS);
17815 + if (unlikely(!buf.k))
17818 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
17819 + if (unlikely(err))
17822 + err = au_d_hashed_positive(dentry);
17824 + old_fs = get_fs();
17825 + set_fs(KERNEL_DS);
17826 + err = h_readlink(dentry, au_dbstart(dentry), buf.u, PATH_MAX);
17829 + aufs_read_unlock(dentry, AuLock_IR);
17833 + /* will be freed by put_link */
17834 + nd_set_link(nd, buf.k);
17835 + return NULL; /* success */
17839 + free_page((unsigned long)buf.k);
17842 + return ERR_PTR(err);
17845 +static void aufs_put_link(struct dentry *dentry __maybe_unused,
17846 + struct nameidata *nd, void *cookie __maybe_unused)
17850 + p = nd_get_link(nd);
17851 + if (!IS_ERR_OR_NULL(p))
17852 + free_page((unsigned long)p);
17855 +/* ---------------------------------------------------------------------- */
17857 +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags)
17860 + struct super_block *sb;
17861 + struct inode *h_inode;
17863 + sb = inode->i_sb;
17864 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
17866 + si_read_lock(sb, AuLock_FLUSH);
17867 + ii_write_lock_child(inode);
17869 + h_inode = au_h_iptr(inode, au_ibstart(inode));
17870 + err = vfsub_update_time(h_inode, ts, flags);
17873 + au_cpup_attr_timesizes(inode);
17874 + ii_write_unlock(inode);
17875 + si_read_unlock(sb);
17878 + if (!err && (flags & S_VERSION))
17879 + inode_inc_iversion(inode);
17884 +/* ---------------------------------------------------------------------- */
17886 +struct inode_operations aufs_symlink_iop = {
17887 + .permission = aufs_permission,
17888 + .setattr = aufs_setattr,
17889 + .getattr = aufs_getattr,
17891 + .readlink = aufs_readlink,
17892 + .follow_link = aufs_follow_link,
17893 + .put_link = aufs_put_link,
17895 + /* .update_time = aufs_update_time */
17898 +struct inode_operations aufs_dir_iop = {
17899 + .create = aufs_create,
17900 + .lookup = aufs_lookup,
17901 + .link = aufs_link,
17902 + .unlink = aufs_unlink,
17903 + .symlink = aufs_symlink,
17904 + .mkdir = aufs_mkdir,
17905 + .rmdir = aufs_rmdir,
17906 + .mknod = aufs_mknod,
17907 + .rename = aufs_rename,
17909 + .permission = aufs_permission,
17910 + .setattr = aufs_setattr,
17911 + .getattr = aufs_getattr,
17913 + .update_time = aufs_update_time,
17914 + /* no support for atomic_open() */
17916 + .tmpfile = aufs_tmpfile
17919 +struct inode_operations aufs_iop = {
17920 + .permission = aufs_permission,
17921 + .setattr = aufs_setattr,
17922 + .getattr = aufs_getattr,
17924 + .update_time = aufs_update_time
17926 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
17927 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
17928 +++ linux/fs/aufs/i_op_del.c 2014-06-24 00:14:06.782719306 +0200
17931 + * Copyright (C) 2005-2014 Junjiro R. Okajima
17933 + * This program, aufs is free software; you can redistribute it and/or modify
17934 + * it under the terms of the GNU General Public License as published by
17935 + * the Free Software Foundation; either version 2 of the License, or
17936 + * (at your option) any later version.
17938 + * This program is distributed in the hope that it will be useful,
17939 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17940 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17941 + * GNU General Public License for more details.
17943 + * You should have received a copy of the GNU General Public License
17944 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17948 + * inode operations (del entry)
17954 + * decide if a new whiteout for @dentry is necessary or not.
17955 + * when it is necessary, prepare the parent dir for the upper branch whose
17956 + * branch index is @bcpup for creation. the actual creation of the whiteout will
17957 + * be done by caller.
17959 + * 0: wh is unnecessary
17960 + * plus: wh is necessary
17963 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
17965 + int need_wh, err;
17966 + aufs_bindex_t bstart;
17967 + struct super_block *sb;
17969 + sb = dentry->d_sb;
17970 + bstart = au_dbstart(dentry);
17971 + if (*bcpup < 0) {
17973 + if (au_test_ro(sb, bstart, dentry->d_inode)) {
17974 + err = AuWbrCopyup(au_sbi(sb), dentry);
17976 + if (unlikely(err < 0))
17980 + AuDebugOn(bstart < *bcpup
17981 + || au_test_ro(sb, *bcpup, dentry->d_inode));
17982 + AuDbg("bcpup %d, bstart %d\n", *bcpup, bstart);
17984 + if (*bcpup != bstart) {
17985 + err = au_cpup_dirs(dentry, *bcpup);
17986 + if (unlikely(err))
17990 + struct au_dinfo *dinfo, *tmp;
17992 + need_wh = -ENOMEM;
17993 + dinfo = au_di(dentry);
17994 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
17996 + au_di_cp(tmp, dinfo);
17997 + au_di_swap(tmp, dinfo);
17998 + /* returns the number of positive dentries */
17999 + need_wh = au_lkup_dentry(dentry, bstart + 1, /*type*/0);
18000 + au_di_swap(tmp, dinfo);
18001 + au_rw_write_unlock(&tmp->di_rwsem);
18005 + AuDbg("need_wh %d\n", need_wh);
18013 + * simple tests for the del-entry operations.
18014 + * following the checks in vfs, plus the parent-child relationship.
18016 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
18017 + struct dentry *h_parent, int isdir)
18021 + struct dentry *h_dentry, *h_latest;
18022 + struct inode *h_inode;
18024 + h_dentry = au_h_dptr(dentry, bindex);
18025 + h_inode = h_dentry->d_inode;
18026 + if (dentry->d_inode) {
18028 + if (unlikely(!h_inode || !h_inode->i_nlink))
18031 + h_mode = h_inode->i_mode;
18034 + if (unlikely(S_ISDIR(h_mode)))
18036 + } else if (unlikely(!S_ISDIR(h_mode))) {
18041 + /* rename(2) case */
18043 + if (unlikely(h_inode))
18048 + /* expected parent dir is locked */
18049 + if (unlikely(h_parent != h_dentry->d_parent))
18054 + * rmdir a dir may break the consistency on some filesystem.
18055 + * let's try heavy test.
18058 + if (unlikely(au_test_h_perm(h_parent->d_inode, MAY_EXEC | MAY_WRITE)))
18061 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent,
18062 + au_sbr(dentry->d_sb, bindex));
18064 + if (IS_ERR(h_latest))
18066 + if (h_latest == h_dentry)
18075 + * decide the branch where we operate for @dentry. the branch index will be set
18076 + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent
18077 + * dir for reverting.
18078 + * when a new whiteout is necessary, create it.
18080 +static struct dentry*
18081 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
18082 + struct au_dtime *dt, struct au_pin *pin)
18084 + struct dentry *wh_dentry;
18085 + struct super_block *sb;
18086 + struct path h_path;
18087 + int err, need_wh;
18088 + unsigned int udba;
18089 + aufs_bindex_t bcpup;
18091 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
18092 + wh_dentry = ERR_PTR(need_wh);
18093 + if (unlikely(need_wh < 0))
18096 + sb = dentry->d_sb;
18097 + udba = au_opt_udba(sb);
18099 + err = au_pin(pin, dentry, bcpup, udba,
18100 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
18101 + wh_dentry = ERR_PTR(err);
18102 + if (unlikely(err))
18105 + h_path.dentry = au_pinned_h_parent(pin);
18106 + if (udba != AuOpt_UDBA_NONE
18107 + && au_dbstart(dentry) == bcpup) {
18108 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
18109 + wh_dentry = ERR_PTR(err);
18110 + if (unlikely(err))
18114 + h_path.mnt = au_sbr_mnt(sb, bcpup);
18115 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
18116 + wh_dentry = NULL;
18118 + goto out; /* success, no need to create whiteout */
18120 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
18121 + if (IS_ERR(wh_dentry))
18124 + /* returns with the parent is locked and wh_dentry is dget-ed */
18125 + goto out; /* success */
18130 + return wh_dentry;
18134 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
18135 + * in order to be revertible and save time for removing many child whiteouts
18137 + * returns 1 when there are too many child whiteout and caller should remove
18138 + * them asynchronously. returns 0 when the number of children is enough small to
18139 + * remove now or the branch fs is a remote fs.
18140 + * otherwise return an error.
18142 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
18143 + struct au_nhash *whlist, struct inode *dir)
18145 + int rmdir_later, err, dirwh;
18146 + struct dentry *h_dentry;
18147 + struct super_block *sb;
18149 + sb = dentry->d_sb;
18150 + SiMustAnyLock(sb);
18151 + h_dentry = au_h_dptr(dentry, bindex);
18152 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
18153 + if (unlikely(err))
18156 + /* stop monitoring */
18157 + au_hn_free(au_hi(dentry->d_inode, bindex));
18159 + if (!au_test_fs_remote(h_dentry->d_sb)) {
18160 + dirwh = au_sbi(sb)->si_dirwh;
18161 + rmdir_later = (dirwh <= 1);
18162 + if (!rmdir_later)
18163 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
18166 + return rmdir_later;
18169 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
18170 + if (unlikely(err)) {
18171 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
18172 + h_dentry, bindex, err);
18182 + * final procedure for deleting a entry.
18183 + * maintain dentry and iattr.
18185 +static void epilog(struct inode *dir, struct dentry *dentry,
18186 + aufs_bindex_t bindex)
18188 + struct inode *inode;
18190 + inode = dentry->d_inode;
18192 + inode->i_ctime = dir->i_ctime;
18194 + if (au_ibstart(dir) == bindex)
18195 + au_cpup_attr_timesizes(dir);
18196 + dir->i_version++;
18200 + * when an error happened, remove the created whiteout and revert everything.
18202 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
18203 + aufs_bindex_t bwh, struct dentry *wh_dentry,
18204 + struct dentry *dentry, struct au_dtime *dt)
18207 + struct path h_path = {
18208 + .dentry = wh_dentry,
18209 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
18212 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
18214 + au_set_dbwh(dentry, bwh);
18215 + au_dtime_revert(dt);
18219 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
18223 +/* ---------------------------------------------------------------------- */
18225 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
18228 + aufs_bindex_t bwh, bindex, bstart;
18229 + struct inode *inode, *h_dir, *delegated;
18230 + struct dentry *parent, *wh_dentry;
18231 + /* to reuduce stack size */
18233 + struct au_dtime dt;
18234 + struct au_pin pin;
18235 + struct path h_path;
18241 + a = kmalloc(sizeof(*a), GFP_NOFS);
18242 + if (unlikely(!a))
18245 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
18246 + if (unlikely(err))
18248 + err = au_d_hashed_positive(dentry);
18249 + if (unlikely(err))
18251 + inode = dentry->d_inode;
18252 + IMustLock(inode);
18254 + if (unlikely(S_ISDIR(inode->i_mode)))
18255 + goto out_unlock; /* possible? */
18257 + bstart = au_dbstart(dentry);
18258 + bwh = au_dbwh(dentry);
18260 + parent = dentry->d_parent; /* dir inode is locked */
18261 + di_write_lock_parent(parent);
18262 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
18264 + err = PTR_ERR(wh_dentry);
18265 + if (IS_ERR(wh_dentry))
18268 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
18269 + a->h_path.dentry = au_h_dptr(dentry, bstart);
18270 + dget(a->h_path.dentry);
18271 + if (bindex == bstart) {
18272 + h_dir = au_pinned_h_dir(&a->pin);
18273 + delegated = NULL;
18274 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
18275 + if (unlikely(err == -EWOULDBLOCK)) {
18276 + pr_warn("cannot retry for NFSv4 delegation"
18277 + " for an internal unlink\n");
18281 + /* dir inode is locked */
18282 + h_dir = wh_dentry->d_parent->d_inode;
18283 + IMustLock(h_dir);
18288 + vfsub_drop_nlink(inode);
18289 + epilog(dir, dentry, bindex);
18291 + /* update target timestamps */
18292 + if (bindex == bstart) {
18293 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
18295 + inode->i_ctime = a->h_path.dentry->d_inode->i_ctime;
18297 + /* todo: this timestamp may be reverted later */
18298 + inode->i_ctime = h_dir->i_ctime;
18299 + goto out_unpin; /* success */
18306 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
18313 + au_unpin(&a->pin);
18315 + dput(a->h_path.dentry);
18317 + di_write_unlock(parent);
18319 + aufs_read_unlock(dentry, AuLock_DW);
18326 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
18328 + int err, rmdir_later;
18329 + aufs_bindex_t bwh, bindex, bstart;
18330 + struct inode *inode;
18331 + struct dentry *parent, *wh_dentry, *h_dentry;
18332 + struct au_whtmp_rmdir *args;
18333 + /* to reuduce stack size */
18335 + struct au_dtime dt;
18336 + struct au_pin pin;
18342 + a = kmalloc(sizeof(*a), GFP_NOFS);
18343 + if (unlikely(!a))
18346 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
18347 + if (unlikely(err))
18349 + err = au_alive_dir(dentry);
18350 + if (unlikely(err))
18352 + inode = dentry->d_inode;
18353 + IMustLock(inode);
18355 + if (unlikely(!S_ISDIR(inode->i_mode)))
18356 + goto out_unlock; /* possible? */
18359 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
18360 + if (unlikely(!args))
18363 + parent = dentry->d_parent; /* dir inode is locked */
18364 + di_write_lock_parent(parent);
18365 + err = au_test_empty(dentry, &args->whlist);
18366 + if (unlikely(err))
18369 + bstart = au_dbstart(dentry);
18370 + bwh = au_dbwh(dentry);
18372 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
18374 + err = PTR_ERR(wh_dentry);
18375 + if (IS_ERR(wh_dentry))
18378 + h_dentry = au_h_dptr(dentry, bstart);
18381 + if (bindex == bstart) {
18382 + err = renwh_and_rmdir(dentry, bstart, &args->whlist, dir);
18384 + rmdir_later = err;
18388 + /* stop monitoring */
18389 + au_hn_free(au_hi(inode, bstart));
18391 + /* dir inode is locked */
18392 + IMustLock(wh_dentry->d_parent->d_inode);
18397 + vfsub_dead_dir(inode);
18398 + au_set_dbdiropq(dentry, -1);
18399 + epilog(dir, dentry, bindex);
18401 + if (rmdir_later) {
18402 + au_whtmp_kick_rmdir(dir, bstart, h_dentry, args);
18406 + goto out_unpin; /* success */
18414 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
18421 + au_unpin(&a->pin);
18425 + di_write_unlock(parent);
18427 + au_whtmp_rmdir_free(args);
18429 + aufs_read_unlock(dentry, AuLock_DW);
18436 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
18437 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
18438 +++ linux/fs/aufs/i_op_ren.c 2014-06-24 00:14:06.786052822 +0200
18441 + * Copyright (C) 2005-2014 Junjiro R. Okajima
18443 + * This program, aufs is free software; you can redistribute it and/or modify
18444 + * it under the terms of the GNU General Public License as published by
18445 + * the Free Software Foundation; either version 2 of the License, or
18446 + * (at your option) any later version.
18448 + * This program is distributed in the hope that it will be useful,
18449 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18450 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18451 + * GNU General Public License for more details.
18453 + * You should have received a copy of the GNU General Public License
18454 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18458 + * inode operation (rename entry)
18459 + * todo: this is crazy monster
18464 +enum { AuSRC, AuDST, AuSrcDst };
18465 +enum { AuPARENT, AuCHILD, AuParentChild };
18467 +#define AuRen_ISDIR 1
18468 +#define AuRen_ISSAMEDIR (1 << 1)
18469 +#define AuRen_WHSRC (1 << 2)
18470 +#define AuRen_WHDST (1 << 3)
18471 +#define AuRen_MNT_WRITE (1 << 4)
18472 +#define AuRen_DT_DSTDIR (1 << 5)
18473 +#define AuRen_DIROPQ (1 << 6)
18474 +#define AuRen_CPUP (1 << 7)
18475 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
18476 +#define au_fset_ren(flags, name) \
18477 + do { (flags) |= AuRen_##name; } while (0)
18478 +#define au_fclr_ren(flags, name) \
18479 + do { (flags) &= ~AuRen_##name; } while (0)
18481 +struct au_ren_args {
18483 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
18485 + struct inode *dir, *inode;
18486 + struct au_hinode *hdir;
18487 + struct au_dtime dt[AuParentChild];
18488 + aufs_bindex_t bstart;
18491 +#define src_dentry sd[AuSRC].dentry
18492 +#define src_dir sd[AuSRC].dir
18493 +#define src_inode sd[AuSRC].inode
18494 +#define src_h_dentry sd[AuSRC].h_dentry
18495 +#define src_parent sd[AuSRC].parent
18496 +#define src_h_parent sd[AuSRC].h_parent
18497 +#define src_wh_dentry sd[AuSRC].wh_dentry
18498 +#define src_hdir sd[AuSRC].hdir
18499 +#define src_h_dir sd[AuSRC].hdir->hi_inode
18500 +#define src_dt sd[AuSRC].dt
18501 +#define src_bstart sd[AuSRC].bstart
18503 +#define dst_dentry sd[AuDST].dentry
18504 +#define dst_dir sd[AuDST].dir
18505 +#define dst_inode sd[AuDST].inode
18506 +#define dst_h_dentry sd[AuDST].h_dentry
18507 +#define dst_parent sd[AuDST].parent
18508 +#define dst_h_parent sd[AuDST].h_parent
18509 +#define dst_wh_dentry sd[AuDST].wh_dentry
18510 +#define dst_hdir sd[AuDST].hdir
18511 +#define dst_h_dir sd[AuDST].hdir->hi_inode
18512 +#define dst_dt sd[AuDST].dt
18513 +#define dst_bstart sd[AuDST].bstart
18515 + struct dentry *h_trap;
18516 + struct au_branch *br;
18517 + struct au_hinode *src_hinode;
18518 + struct path h_path;
18519 + struct au_nhash whlist;
18520 + aufs_bindex_t btgt, src_bwh, src_bdiropq;
18522 + unsigned int flags;
18524 + struct au_whtmp_rmdir *thargs;
18525 + struct dentry *h_dst;
18528 +/* ---------------------------------------------------------------------- */
18531 + * functions for reverting.
18532 + * when an error happened in a single rename systemcall, we should revert
18533 + * everything as if nothing happend.
18534 + * we don't need to revert the copied-up/down the parent dir since they are
18538 +#define RevertFailure(fmt, ...) do { \
18539 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
18540 + ##__VA_ARGS__, err, rerr); \
18544 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
18548 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
18549 + rerr = au_diropq_remove(a->src_dentry, a->btgt);
18550 + au_hn_imtx_unlock(a->src_hinode);
18551 + au_set_dbdiropq(a->src_dentry, a->src_bdiropq);
18553 + RevertFailure("remove diropq %pd", a->src_dentry);
18556 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
18559 + struct inode *delegated;
18561 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
18562 + a->src_h_parent);
18563 + rerr = PTR_ERR(a->h_path.dentry);
18564 + if (IS_ERR(a->h_path.dentry)) {
18565 + RevertFailure("lkup one %pd", a->src_dentry);
18569 + delegated = NULL;
18570 + rerr = vfsub_rename(a->dst_h_dir,
18571 + au_h_dptr(a->src_dentry, a->btgt),
18572 + a->src_h_dir, &a->h_path, &delegated);
18573 + if (unlikely(rerr == -EWOULDBLOCK)) {
18574 + pr_warn("cannot retry for NFSv4 delegation"
18575 + " for an internal rename\n");
18578 + d_drop(a->h_path.dentry);
18579 + dput(a->h_path.dentry);
18580 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
18582 + RevertFailure("rename %pd", a->src_dentry);
18585 +static void au_ren_rev_cpup(int err, struct au_ren_args *a)
18589 + a->h_path.dentry = a->dst_h_dentry;
18590 + /* no delegation since it is just created */
18591 + rerr = vfsub_unlink(a->dst_h_dir, &a->h_path, /*delegated*/NULL,
18593 + au_set_h_dptr(a->src_dentry, a->btgt, NULL);
18594 + au_set_dbstart(a->src_dentry, a->src_bstart);
18596 + RevertFailure("unlink %pd", a->dst_h_dentry);
18599 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
18602 + struct inode *delegated;
18604 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
18605 + a->dst_h_parent);
18606 + rerr = PTR_ERR(a->h_path.dentry);
18607 + if (IS_ERR(a->h_path.dentry)) {
18608 + RevertFailure("lkup one %pd", a->dst_dentry);
18611 + if (a->h_path.dentry->d_inode) {
18612 + d_drop(a->h_path.dentry);
18613 + dput(a->h_path.dentry);
18617 + delegated = NULL;
18618 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
18620 + if (unlikely(rerr == -EWOULDBLOCK)) {
18621 + pr_warn("cannot retry for NFSv4 delegation"
18622 + " for an internal rename\n");
18625 + d_drop(a->h_path.dentry);
18626 + dput(a->h_path.dentry);
18628 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
18630 + RevertFailure("rename %pd", a->h_dst);
18633 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
18637 + a->h_path.dentry = a->src_wh_dentry;
18638 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
18639 + au_set_dbwh(a->src_dentry, a->src_bwh);
18641 + RevertFailure("unlink %pd", a->src_wh_dentry);
18643 +#undef RevertFailure
18645 +/* ---------------------------------------------------------------------- */
18648 + * when we have to copyup the renaming entry, do it with the rename-target name
18649 + * in order to minimize the cost (the later actual rename is unnecessary).
18650 + * otherwise rename it on the target branch.
18652 +static int au_ren_or_cpup(struct au_ren_args *a)
18655 + struct dentry *d;
18656 + struct inode *delegated;
18658 + d = a->src_dentry;
18659 + if (au_dbstart(d) == a->btgt) {
18660 + a->h_path.dentry = a->dst_h_dentry;
18661 + if (au_ftest_ren(a->flags, DIROPQ)
18662 + && au_dbdiropq(d) == a->btgt)
18663 + au_fclr_ren(a->flags, DIROPQ);
18664 + AuDebugOn(au_dbstart(d) != a->btgt);
18665 + delegated = NULL;
18666 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
18667 + a->dst_h_dir, &a->h_path, &delegated);
18668 + if (unlikely(err == -EWOULDBLOCK)) {
18669 + pr_warn("cannot retry for NFSv4 delegation"
18670 + " for an internal rename\n");
18676 + if (!err && a->h_dst)
18677 + /* it will be set to dinfo later */
18683 +/* cf. aufs_rmdir() */
18684 +static int au_ren_del_whtmp(struct au_ren_args *a)
18687 + struct inode *dir;
18689 + dir = a->dst_dir;
18690 + SiMustAnyLock(dir->i_sb);
18691 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
18692 + au_sbi(dir->i_sb)->si_dirwh)
18693 + || au_test_fs_remote(a->h_dst->d_sb)) {
18694 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
18695 + if (unlikely(err))
18696 + pr_warn("failed removing whtmp dir %pd (%d), "
18697 + "ignored.\n", a->h_dst, err);
18699 + au_nhash_wh_free(&a->thargs->whlist);
18700 + a->thargs->whlist = a->whlist;
18701 + a->whlist.nh_num = 0;
18702 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
18704 + a->thargs = NULL;
18710 +/* make it 'opaque' dir. */
18711 +static int au_ren_diropq(struct au_ren_args *a)
18714 + struct dentry *diropq;
18717 + a->src_bdiropq = au_dbdiropq(a->src_dentry);
18718 + a->src_hinode = au_hi(a->src_inode, a->btgt);
18719 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
18720 + diropq = au_diropq_create(a->src_dentry, a->btgt);
18721 + au_hn_imtx_unlock(a->src_hinode);
18722 + if (IS_ERR(diropq))
18723 + err = PTR_ERR(diropq);
18729 +static int do_rename(struct au_ren_args *a)
18732 + struct dentry *d, *h_d;
18734 + /* prepare workqueue args for asynchronous rmdir */
18735 + h_d = a->dst_h_dentry;
18736 + if (au_ftest_ren(a->flags, ISDIR) && h_d->d_inode) {
18738 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb, GFP_NOFS);
18739 + if (unlikely(!a->thargs))
18741 + a->h_dst = dget(h_d);
18744 + /* create whiteout for src_dentry */
18745 + if (au_ftest_ren(a->flags, WHSRC)) {
18746 + a->src_bwh = au_dbwh(a->src_dentry);
18747 + AuDebugOn(a->src_bwh >= 0);
18749 + = au_wh_create(a->src_dentry, a->btgt, a->src_h_parent);
18750 + err = PTR_ERR(a->src_wh_dentry);
18751 + if (IS_ERR(a->src_wh_dentry))
18755 + /* lookup whiteout for dentry */
18756 + if (au_ftest_ren(a->flags, WHDST)) {
18757 + h_d = au_wh_lkup(a->dst_h_parent, &a->dst_dentry->d_name,
18759 + err = PTR_ERR(h_d);
18762 + if (!h_d->d_inode)
18765 + a->dst_wh_dentry = h_d;
18768 + /* rename dentry to tmpwh */
18770 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
18771 + if (unlikely(err))
18774 + d = a->dst_dentry;
18775 + au_set_h_dptr(d, a->btgt, NULL);
18776 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
18777 + if (unlikely(err))
18779 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
18782 + BUG_ON(a->dst_h_dentry->d_inode && a->src_bstart != a->btgt);
18784 + /* rename by vfs_rename or cpup */
18785 + d = a->dst_dentry;
18786 + if (au_ftest_ren(a->flags, ISDIR)
18787 + && (a->dst_wh_dentry
18788 + || au_dbdiropq(d) == a->btgt
18789 + /* hide the lower to keep xino */
18790 + || a->btgt < au_dbend(d)
18791 + || au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ)))
18792 + au_fset_ren(a->flags, DIROPQ);
18793 + err = au_ren_or_cpup(a);
18794 + if (unlikely(err))
18795 + /* leave the copied-up one */
18798 + /* make dir opaque */
18799 + if (au_ftest_ren(a->flags, DIROPQ)) {
18800 + err = au_ren_diropq(a);
18801 + if (unlikely(err))
18805 + /* update target timestamps */
18806 + AuDebugOn(au_dbstart(a->src_dentry) != a->btgt);
18807 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
18808 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
18809 + a->src_inode->i_ctime = a->h_path.dentry->d_inode->i_ctime;
18811 + /* remove whiteout for dentry */
18812 + if (a->dst_wh_dentry) {
18813 + a->h_path.dentry = a->dst_wh_dentry;
18814 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
18816 + if (unlikely(err))
18820 + /* remove whtmp */
18822 + au_ren_del_whtmp(a); /* ignore this error */
18825 + goto out_success;
18828 + if (au_ftest_ren(a->flags, DIROPQ))
18829 + au_ren_rev_diropq(err, a);
18831 + if (!au_ftest_ren(a->flags, CPUP))
18832 + au_ren_rev_rename(err, a);
18834 + au_ren_rev_cpup(err, a);
18838 + au_ren_rev_whtmp(err, a);
18840 + dput(a->dst_wh_dentry);
18841 + a->dst_wh_dentry = NULL;
18843 + if (a->src_wh_dentry)
18844 + au_ren_rev_whsrc(err, a);
18846 + dput(a->src_wh_dentry);
18847 + dput(a->dst_wh_dentry);
18851 + au_whtmp_rmdir_free(a->thargs);
18852 + a->thargs = NULL;
18858 +/* ---------------------------------------------------------------------- */
18861 + * test if @dentry dir can be rename destination or not.
18862 + * success means, it is a logically empty dir.
18864 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
18866 + return au_test_empty(dentry, whlist);
18870 + * test if @dentry dir can be rename source or not.
18871 + * if it can, return 0 and @children is filled.
18873 + * - it is a logically empty dir.
18874 + * - or, it exists on writable branch and has no children including whiteouts
18875 + * on the lower branch.
18877 +static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt)
18880 + unsigned int rdhash;
18881 + aufs_bindex_t bstart;
18883 + bstart = au_dbstart(dentry);
18884 + if (bstart != btgt) {
18885 + struct au_nhash whlist;
18887 + SiMustAnyLock(dentry->d_sb);
18888 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
18890 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
18892 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
18893 + if (unlikely(err))
18895 + err = au_test_empty(dentry, &whlist);
18896 + au_nhash_wh_free(&whlist);
18900 + if (bstart == au_dbtaildir(dentry))
18901 + return 0; /* success */
18903 + err = au_test_empty_lower(dentry);
18906 + if (err == -ENOTEMPTY) {
18907 + AuWarn1("renaming dir who has child(ren) on multiple branches,"
18908 + " is not supported\n");
18914 +/* side effect: sets whlist and h_dentry */
18915 +static int au_ren_may_dir(struct au_ren_args *a)
18918 + unsigned int rdhash;
18919 + struct dentry *d;
18921 + d = a->dst_dentry;
18922 + SiMustAnyLock(d->d_sb);
18925 + if (au_ftest_ren(a->flags, ISDIR) && a->dst_inode) {
18926 + rdhash = au_sbi(d->d_sb)->si_rdhash;
18928 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
18929 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
18930 + if (unlikely(err))
18933 + au_set_dbstart(d, a->dst_bstart);
18934 + err = may_rename_dstdir(d, &a->whlist);
18935 + au_set_dbstart(d, a->btgt);
18937 + a->dst_h_dentry = au_h_dptr(d, au_dbstart(d));
18938 + if (unlikely(err))
18941 + d = a->src_dentry;
18942 + a->src_h_dentry = au_h_dptr(d, au_dbstart(d));
18943 + if (au_ftest_ren(a->flags, ISDIR)) {
18944 + err = may_rename_srcdir(d, a->btgt);
18945 + if (unlikely(err)) {
18946 + au_nhash_wh_free(&a->whlist);
18947 + a->whlist.nh_num = 0;
18954 +/* ---------------------------------------------------------------------- */
18957 + * simple tests for rename.
18958 + * following the checks in vfs, plus the parent-child relationship.
18960 +static int au_may_ren(struct au_ren_args *a)
18963 + struct inode *h_inode;
18965 + if (a->src_bstart == a->btgt) {
18966 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
18967 + au_ftest_ren(a->flags, ISDIR));
18968 + if (unlikely(err))
18971 + if (unlikely(a->src_h_dentry == a->h_trap))
18976 + if (a->dst_bstart != a->btgt)
18979 + err = -ENOTEMPTY;
18980 + if (unlikely(a->dst_h_dentry == a->h_trap))
18984 + h_inode = a->dst_h_dentry->d_inode;
18985 + isdir = !!au_ftest_ren(a->flags, ISDIR);
18986 + if (!a->dst_dentry->d_inode) {
18987 + if (unlikely(h_inode))
18989 + err = au_may_add(a->dst_dentry, a->btgt, a->dst_h_parent,
18992 + if (unlikely(!h_inode || !h_inode->i_nlink))
18994 + err = au_may_del(a->dst_dentry, a->btgt, a->dst_h_parent,
18996 + if (unlikely(err))
19001 + if (unlikely(err == -ENOENT || err == -EEXIST))
19007 +/* ---------------------------------------------------------------------- */
19012 + * - src_dir and dir by lock_rename()
19013 + * - inode if exitsts
19016 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
19018 + * + di_write_lock2_child()
19019 + * + di_write_lock_child()
19020 + * + ii_write_lock_child()
19021 + * + di_write_lock_child2()
19022 + * + ii_write_lock_child2()
19023 + * + src_parent and parent
19024 + * + di_write_lock_parent()
19025 + * + ii_write_lock_parent()
19026 + * + di_write_lock_parent2()
19027 + * + ii_write_lock_parent2()
19028 + * + lower src_dir and dir by vfsub_lock_rename()
19029 + * + verify the every relationships between child and parent. if any
19030 + * of them failed, unlock all and return -EBUSY.
19032 +static void au_ren_unlock(struct au_ren_args *a)
19034 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
19035 + a->dst_h_parent, a->dst_hdir);
19036 + if (au_ftest_ren(a->flags, MNT_WRITE))
19037 + vfsub_mnt_drop_write(au_br_mnt(a->br));
19040 +static int au_ren_lock(struct au_ren_args *a)
19043 + unsigned int udba;
19046 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
19047 + a->src_hdir = au_hi(a->src_dir, a->btgt);
19048 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
19049 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
19051 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
19052 + if (unlikely(err))
19054 + au_fset_ren(a->flags, MNT_WRITE);
19055 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
19056 + a->dst_h_parent, a->dst_hdir);
19057 + udba = au_opt_udba(a->src_dentry->d_sb);
19058 + if (unlikely(a->src_hdir->hi_inode != a->src_h_parent->d_inode
19059 + || a->dst_hdir->hi_inode != a->dst_h_parent->d_inode))
19060 + err = au_busy_or_stale();
19061 + if (!err && au_dbstart(a->src_dentry) == a->btgt)
19062 + err = au_h_verify(a->src_h_dentry, udba,
19063 + a->src_h_parent->d_inode, a->src_h_parent,
19065 + if (!err && au_dbstart(a->dst_dentry) == a->btgt)
19066 + err = au_h_verify(a->dst_h_dentry, udba,
19067 + a->dst_h_parent->d_inode, a->dst_h_parent,
19070 + goto out; /* success */
19072 + err = au_busy_or_stale();
19073 + au_ren_unlock(a);
19079 +/* ---------------------------------------------------------------------- */
19081 +static void au_ren_refresh_dir(struct au_ren_args *a)
19083 + struct inode *dir;
19085 + dir = a->dst_dir;
19086 + dir->i_version++;
19087 + if (au_ftest_ren(a->flags, ISDIR)) {
19088 + /* is this updating defined in POSIX? */
19089 + au_cpup_attr_timesizes(a->src_inode);
19090 + au_cpup_attr_nlink(dir, /*force*/1);
19093 + if (au_ibstart(dir) == a->btgt)
19094 + au_cpup_attr_timesizes(dir);
19096 + if (au_ftest_ren(a->flags, ISSAMEDIR))
19099 + dir = a->src_dir;
19100 + dir->i_version++;
19101 + if (au_ftest_ren(a->flags, ISDIR))
19102 + au_cpup_attr_nlink(dir, /*force*/1);
19103 + if (au_ibstart(dir) == a->btgt)
19104 + au_cpup_attr_timesizes(dir);
19107 +static void au_ren_refresh(struct au_ren_args *a)
19109 + aufs_bindex_t bend, bindex;
19110 + struct dentry *d, *h_d;
19111 + struct inode *i, *h_i;
19112 + struct super_block *sb;
19114 + d = a->dst_dentry;
19117 + /* already dget-ed by au_ren_or_cpup() */
19118 + au_set_h_dptr(d, a->btgt, a->h_dst);
19120 + i = a->dst_inode;
19122 + if (!au_ftest_ren(a->flags, ISDIR))
19123 + vfsub_drop_nlink(i);
19125 + vfsub_dead_dir(i);
19126 + au_cpup_attr_timesizes(i);
19128 + au_update_dbrange(d, /*do_put_zero*/1);
19131 + for (bindex = au_dbstart(d); bindex < bend; bindex++)
19132 + au_set_h_dptr(d, bindex, NULL);
19133 + bend = au_dbend(d);
19134 + for (bindex = a->btgt + 1; bindex <= bend; bindex++)
19135 + au_set_h_dptr(d, bindex, NULL);
19136 + au_update_dbrange(d, /*do_put_zero*/0);
19139 + d = a->src_dentry;
19140 + au_set_dbwh(d, -1);
19141 + bend = au_dbend(d);
19142 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
19143 + h_d = au_h_dptr(d, bindex);
19145 + au_set_h_dptr(d, bindex, NULL);
19147 + au_set_dbend(d, a->btgt);
19150 + i = a->src_inode;
19151 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
19152 + return; /* success */
19154 + bend = au_ibend(i);
19155 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
19156 + h_i = au_h_iptr(i, bindex);
19158 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
19159 + /* ignore this error */
19160 + au_set_h_iptr(i, bindex, NULL, 0);
19163 + au_set_ibend(i, a->btgt);
19166 +/* ---------------------------------------------------------------------- */
19168 +/* mainly for link(2) and rename(2) */
19169 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
19171 + aufs_bindex_t bdiropq, bwh;
19172 + struct dentry *parent;
19173 + struct au_branch *br;
19175 + parent = dentry->d_parent;
19176 + IMustLock(parent->d_inode); /* dir is locked */
19178 + bdiropq = au_dbdiropq(parent);
19179 + bwh = au_dbwh(dentry);
19180 + br = au_sbr(dentry->d_sb, btgt);
19181 + if (au_br_rdonly(br)
19182 + || (0 <= bdiropq && bdiropq < btgt)
19183 + || (0 <= bwh && bwh < btgt))
19186 + AuDbg("btgt %d\n", btgt);
19190 +/* sets src_bstart, dst_bstart and btgt */
19191 +static int au_ren_wbr(struct au_ren_args *a)
19194 + struct au_wr_dir_args wr_dir_args = {
19195 + /* .force_btgt = -1, */
19196 + .flags = AuWrDir_ADD_ENTRY
19199 + a->src_bstart = au_dbstart(a->src_dentry);
19200 + a->dst_bstart = au_dbstart(a->dst_dentry);
19201 + if (au_ftest_ren(a->flags, ISDIR))
19202 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
19203 + wr_dir_args.force_btgt = a->src_bstart;
19204 + if (a->dst_inode && a->dst_bstart < a->src_bstart)
19205 + wr_dir_args.force_btgt = a->dst_bstart;
19206 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
19207 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
19213 +static void au_ren_dt(struct au_ren_args *a)
19215 + a->h_path.dentry = a->src_h_parent;
19216 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
19217 + if (!au_ftest_ren(a->flags, ISSAMEDIR)) {
19218 + a->h_path.dentry = a->dst_h_parent;
19219 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
19222 + au_fclr_ren(a->flags, DT_DSTDIR);
19223 + if (!au_ftest_ren(a->flags, ISDIR))
19226 + a->h_path.dentry = a->src_h_dentry;
19227 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
19228 + if (a->dst_h_dentry->d_inode) {
19229 + au_fset_ren(a->flags, DT_DSTDIR);
19230 + a->h_path.dentry = a->dst_h_dentry;
19231 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
19235 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
19237 + struct dentry *h_d;
19238 + struct mutex *h_mtx;
19240 + au_dtime_revert(a->src_dt + AuPARENT);
19241 + if (!au_ftest_ren(a->flags, ISSAMEDIR))
19242 + au_dtime_revert(a->dst_dt + AuPARENT);
19244 + if (au_ftest_ren(a->flags, ISDIR) && err != -EIO) {
19245 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
19246 + h_mtx = &h_d->d_inode->i_mutex;
19247 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
19248 + au_dtime_revert(a->src_dt + AuCHILD);
19249 + mutex_unlock(h_mtx);
19251 + if (au_ftest_ren(a->flags, DT_DSTDIR)) {
19252 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
19253 + h_mtx = &h_d->d_inode->i_mutex;
19254 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
19255 + au_dtime_revert(a->dst_dt + AuCHILD);
19256 + mutex_unlock(h_mtx);
19261 +/* ---------------------------------------------------------------------- */
19263 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
19264 + struct inode *_dst_dir, struct dentry *_dst_dentry)
19267 + /* reduce stack space */
19268 + struct au_ren_args *a;
19270 + AuDbg("%pd, %pd\n", _src_dentry, _dst_dentry);
19271 + IMustLock(_src_dir);
19272 + IMustLock(_dst_dir);
19275 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
19276 + a = kzalloc(sizeof(*a), GFP_NOFS);
19277 + if (unlikely(!a))
19280 + a->src_dir = _src_dir;
19281 + a->src_dentry = _src_dentry;
19282 + a->src_inode = a->src_dentry->d_inode;
19283 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
19284 + a->dst_dir = _dst_dir;
19285 + a->dst_dentry = _dst_dentry;
19286 + a->dst_inode = a->dst_dentry->d_inode;
19287 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
19288 + if (a->dst_inode) {
19289 + IMustLock(a->dst_inode);
19290 + au_igrab(a->dst_inode);
19294 + flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
19295 + if (S_ISDIR(a->src_inode->i_mode)) {
19296 + au_fset_ren(a->flags, ISDIR);
19297 + if (unlikely(a->dst_inode && !S_ISDIR(a->dst_inode->i_mode)))
19299 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
19300 + AuLock_DIR | flags);
19302 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
19304 + if (unlikely(err))
19307 + err = au_d_hashed_positive(a->src_dentry);
19308 + if (unlikely(err))
19311 + if (a->dst_inode) {
19313 + * If it is a dir, VFS unhash dst_dentry before this
19314 + * function. It means we cannot rely upon d_unhashed().
19316 + if (unlikely(!a->dst_inode->i_nlink))
19318 + if (!S_ISDIR(a->dst_inode->i_mode)) {
19319 + err = au_d_hashed_positive(a->dst_dentry);
19320 + if (unlikely(err))
19322 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
19324 + } else if (unlikely(d_unhashed(a->dst_dentry)))
19328 + * is it possible?
19329 + * yes, it happend (in linux-3.3-rcN) but I don't know why.
19330 + * there may exist a problem somewhere else.
19333 + if (unlikely(a->dst_parent->d_inode == a->src_dentry->d_inode))
19336 + au_fset_ren(a->flags, ISSAMEDIR); /* temporary */
19337 + di_write_lock_parent(a->dst_parent);
19339 + /* which branch we process */
19340 + err = au_ren_wbr(a);
19341 + if (unlikely(err < 0))
19343 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
19344 + a->h_path.mnt = au_br_mnt(a->br);
19346 + /* are they available to be renamed */
19347 + err = au_ren_may_dir(a);
19348 + if (unlikely(err))
19349 + goto out_children;
19351 + /* prepare the writable parent dir on the same branch */
19352 + if (a->dst_bstart == a->btgt) {
19353 + au_fset_ren(a->flags, WHDST);
19355 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
19356 + if (unlikely(err))
19357 + goto out_children;
19360 + if (a->src_dir != a->dst_dir) {
19362 + * this temporary unlock is safe,
19363 + * because both dir->i_mutex are locked.
19365 + di_write_unlock(a->dst_parent);
19366 + di_write_lock_parent(a->src_parent);
19367 + err = au_wr_dir_need_wh(a->src_dentry,
19368 + au_ftest_ren(a->flags, ISDIR),
19370 + di_write_unlock(a->src_parent);
19371 + di_write_lock2_parent(a->src_parent, a->dst_parent, /*isdir*/1);
19372 + au_fclr_ren(a->flags, ISSAMEDIR);
19374 + err = au_wr_dir_need_wh(a->src_dentry,
19375 + au_ftest_ren(a->flags, ISDIR),
19377 + if (unlikely(err < 0))
19378 + goto out_children;
19380 + au_fset_ren(a->flags, WHSRC);
19383 + if (a->src_bstart != a->btgt) {
19384 + struct au_pin pin;
19386 + err = au_pin(&pin, a->src_dentry, a->btgt,
19387 + au_opt_udba(a->src_dentry->d_sb),
19388 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19390 + struct au_cp_generic cpg = {
19391 + .dentry = a->src_dentry,
19393 + .bsrc = a->src_bstart,
19396 + .flags = AuCpup_DTIME | AuCpup_HOPEN
19398 + AuDebugOn(au_dbstart(a->src_dentry) != a->src_bstart);
19399 + err = au_sio_cpup_simple(&cpg);
19402 + if (unlikely(err))
19403 + goto out_children;
19404 + a->src_bstart = a->btgt;
19405 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
19406 + au_fset_ren(a->flags, WHSRC);
19409 + /* lock them all */
19410 + err = au_ren_lock(a);
19411 + if (unlikely(err))
19412 + /* leave the copied-up one */
19413 + goto out_children;
19415 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
19416 + err = au_may_ren(a);
19417 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
19418 + err = -ENAMETOOLONG;
19419 + if (unlikely(err))
19422 + /* store timestamps to be revertible */
19426 + err = do_rename(a);
19427 + if (unlikely(err))
19430 + /* update dir attributes */
19431 + au_ren_refresh_dir(a);
19433 + /* dput/iput all lower dentries */
19434 + au_ren_refresh(a);
19436 + goto out_hdir; /* success */
19439 + au_ren_rev_dt(err, a);
19441 + au_ren_unlock(a);
19443 + au_nhash_wh_free(&a->whlist);
19444 + if (err && a->dst_inode && a->dst_bstart != a->btgt) {
19445 + AuDbg("bstart %d, btgt %d\n", a->dst_bstart, a->btgt);
19446 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
19447 + au_set_dbstart(a->dst_dentry, a->dst_bstart);
19451 + d_move(a->src_dentry, a->dst_dentry);
19453 + au_update_dbstart(a->dst_dentry);
19454 + if (!a->dst_inode)
19455 + d_drop(a->dst_dentry);
19457 + if (au_ftest_ren(a->flags, ISSAMEDIR))
19458 + di_write_unlock(a->dst_parent);
19460 + di_write_unlock2(a->src_parent, a->dst_parent);
19462 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
19464 + iput(a->dst_inode);
19466 + au_whtmp_rmdir_free(a->thargs);
19472 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
19473 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
19474 +++ linux/fs/aufs/Kconfig 2014-06-24 00:14:06.776052275 +0200
19477 + tristate "Aufs (Advanced multi layered unification filesystem) support"
19479 + Aufs is a stackable unification filesystem such as Unionfs,
19480 + which unifies several directories and provides a merged single
19482 + In the early days, aufs was entirely re-designed and
19483 + re-implemented Unionfs Version 1.x series. Introducing many
19484 + original ideas, approaches and improvements, it becomes totally
19485 + different from Unionfs while keeping the basic features.
19489 + prompt "Maximum number of branches"
19490 + default AUFS_BRANCH_MAX_127
19492 + Specifies the maximum number of branches (or member directories)
19493 + in a single aufs. The larger value consumes more system
19494 + resources and has a minor impact to performance.
19495 +config AUFS_BRANCH_MAX_127
19498 + Specifies the maximum number of branches (or member directories)
19499 + in a single aufs. The larger value consumes more system
19500 + resources and has a minor impact to performance.
19501 +config AUFS_BRANCH_MAX_511
19504 + Specifies the maximum number of branches (or member directories)
19505 + in a single aufs. The larger value consumes more system
19506 + resources and has a minor impact to performance.
19507 +config AUFS_BRANCH_MAX_1023
19510 + Specifies the maximum number of branches (or member directories)
19511 + in a single aufs. The larger value consumes more system
19512 + resources and has a minor impact to performance.
19513 +config AUFS_BRANCH_MAX_32767
19516 + Specifies the maximum number of branches (or member directories)
19517 + in a single aufs. The larger value consumes more system
19518 + resources and has a minor impact to performance.
19521 +config AUFS_SBILIST
19523 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
19526 + Automatic configuration for internal use.
19527 + When aufs supports Magic SysRq or /proc, enabled automatically.
19529 +config AUFS_HNOTIFY
19530 + bool "Detect direct branch access (bypassing aufs)"
19532 + If you want to modify files on branches directly, eg. bypassing aufs,
19533 + and want aufs to detect the changes of them fully, then enable this
19534 + option and use 'udba=notify' mount option.
19535 + Currently there is only one available configuration, "fsnotify".
19536 + It will have a negative impact to the performance.
19537 + See detail in aufs.5.
19540 + prompt "method" if AUFS_HNOTIFY
19541 + default AUFS_HFSNOTIFY
19542 +config AUFS_HFSNOTIFY
19547 +config AUFS_EXPORT
19548 + bool "NFS-exportable aufs"
19549 + depends on EXPORTFS
19551 + If you want to export your mounted aufs via NFS, then enable this
19552 + option. There are several requirements for this configuration.
19553 + See detail in aufs.5.
19555 +config AUFS_INO_T_64
19557 + depends on AUFS_EXPORT
19558 + depends on 64BIT && !(ALPHA || S390)
19561 + Automatic configuration for internal use.
19562 + /* typedef unsigned long/int __kernel_ino_t */
19563 + /* alpha and s390x are int */
19566 + bool "Readdir in userspace"
19568 + Aufs has two methods to provide a merged view for a directory,
19569 + by a user-space library and by kernel-space natively. The latter
19570 + is always enabled but sometimes large and slow.
19571 + If you enable this option, install the library in aufs2-util
19572 + package, and set some environment variables for your readdir(3),
19573 + then the work will be handled in user-space which generally
19574 + shows better performance in most cases.
19575 + See detail in aufs.5.
19578 + bool "Show whiteouts"
19580 + If you want to make the whiteouts in aufs visible, then enable
19581 + this option and specify 'shwh' mount option. Although it may
19582 + sounds like philosophy or something, but in technically it
19583 + simply shows the name of whiteout with keeping its behaviour.
19585 +config AUFS_BR_RAMFS
19586 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
19588 + If you want to use ramfs as an aufs branch fs, then enable this
19589 + option. Generally tmpfs is recommended.
19590 + Aufs prohibited them to be a branch fs by default, because
19591 + initramfs becomes unusable after switch_root or something
19592 + generally. If you sets initramfs as an aufs branch and boot your
19593 + system by switch_root, you will meet a problem easily since the
19594 + files in initramfs may be inaccessible.
19595 + Unless you are going to use ramfs as an aufs branch fs without
19596 + switch_root or something, leave it N.
19598 +config AUFS_BR_FUSE
19599 + bool "Fuse fs as an aufs branch"
19600 + depends on FUSE_FS
19603 + If you want to use fuse-based userspace filesystem as an aufs
19604 + branch fs, then enable this option.
19605 + It implements the internal poll(2) operation which is
19606 + implemented by fuse only (curretnly).
19611 + Automatic configuration for internal use.
19613 +config AUFS_BR_HFSPLUS
19614 + bool "Hfsplus as an aufs branch"
19615 + depends on HFSPLUS_FS
19618 + If you want to use hfsplus fs as an aufs branch fs, then enable
19619 + this option. This option introduces a small overhead at
19620 + copying-up a file on hfsplus.
19622 +config AUFS_BDEV_LOOP
19624 + depends on BLK_DEV_LOOP
19627 + Automatic configuration for internal use.
19628 + Convert =[ym] into =y.
19631 + bool "Debug aufs"
19633 + Enable this to compile aufs internal debug code.
19634 + It will have a negative impact to the performance.
19636 +config AUFS_MAGIC_SYSRQ
19638 + depends on AUFS_DEBUG && MAGIC_SYSRQ
19641 + Automatic configuration for internal use.
19642 + When aufs supports Magic SysRq, enabled automatically.
19644 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
19645 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
19646 +++ linux/fs/aufs/loop.c 2014-06-24 00:14:06.786052822 +0200
19649 + * Copyright (C) 2005-2014 Junjiro R. Okajima
19651 + * This program, aufs is free software; you can redistribute it and/or modify
19652 + * it under the terms of the GNU General Public License as published by
19653 + * the Free Software Foundation; either version 2 of the License, or
19654 + * (at your option) any later version.
19656 + * This program is distributed in the hope that it will be useful,
19657 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19658 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19659 + * GNU General Public License for more details.
19661 + * You should have received a copy of the GNU General Public License
19662 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19666 + * support for loopback block device as a branch
19671 +/* added into drivers/block/loop.c */
19672 +static struct file *(*backing_file_func)(struct super_block *sb);
19675 + * test if two lower dentries have overlapping branches.
19677 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
19679 + struct super_block *h_sb;
19680 + struct file *backing_file;
19682 + if (unlikely(!backing_file_func)) {
19683 + /* don't load "loop" module here */
19684 + backing_file_func = symbol_get(loop_backing_file);
19685 + if (unlikely(!backing_file_func))
19686 + /* "loop" module is not loaded */
19690 + h_sb = h_adding->d_sb;
19691 + backing_file = backing_file_func(h_sb);
19692 + if (!backing_file)
19695 + h_adding = backing_file->f_dentry;
19697 + * h_adding can be local NFS.
19698 + * in this case aufs cannot detect the loop.
19700 + if (unlikely(h_adding->d_sb == sb))
19702 + return !!au_test_subdir(h_adding, sb->s_root);
19705 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
19706 +int au_test_loopback_kthread(void)
19709 + struct task_struct *tsk = current;
19710 + char c, comm[sizeof(tsk->comm)];
19713 + if (tsk->flags & PF_KTHREAD) {
19714 + get_task_comm(comm, tsk);
19716 + ret = ('0' <= c && c <= '9'
19717 + && !strncmp(comm, "loop", 4));
19723 +/* ---------------------------------------------------------------------- */
19725 +#define au_warn_loopback_step 16
19726 +static int au_warn_loopback_nelem = au_warn_loopback_step;
19727 +static unsigned long *au_warn_loopback_array;
19729 +void au_warn_loopback(struct super_block *h_sb)
19731 + int i, new_nelem;
19732 + unsigned long *a, magic;
19733 + static DEFINE_SPINLOCK(spin);
19735 + magic = h_sb->s_magic;
19736 + spin_lock(&spin);
19737 + a = au_warn_loopback_array;
19738 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
19739 + if (a[i] == magic) {
19740 + spin_unlock(&spin);
19744 + /* h_sb is new to us, print it */
19745 + if (i < au_warn_loopback_nelem) {
19750 + /* expand the array */
19751 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
19752 + a = au_kzrealloc(au_warn_loopback_array,
19753 + au_warn_loopback_nelem * sizeof(unsigned long),
19754 + new_nelem * sizeof(unsigned long), GFP_ATOMIC);
19756 + au_warn_loopback_nelem = new_nelem;
19757 + au_warn_loopback_array = a;
19762 + spin_unlock(&spin);
19763 + AuWarn1("realloc failed, ignored\n");
19767 + spin_unlock(&spin);
19768 + pr_warn("you may want to try another patch for loopback file "
19769 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
19772 +int au_loopback_init(void)
19775 + struct super_block *sb __maybe_unused;
19777 + AuDebugOn(sizeof(sb->s_magic) != sizeof(unsigned long));
19780 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
19781 + sizeof(unsigned long), GFP_NOFS);
19782 + if (unlikely(!au_warn_loopback_array))
19788 +void au_loopback_fin(void)
19790 + symbol_put(loop_backing_file);
19791 + kfree(au_warn_loopback_array);
19793 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
19794 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
19795 +++ linux/fs/aufs/loop.h 2014-06-24 00:14:06.786052822 +0200
19798 + * Copyright (C) 2005-2014 Junjiro R. Okajima
19800 + * This program, aufs is free software; you can redistribute it and/or modify
19801 + * it under the terms of the GNU General Public License as published by
19802 + * the Free Software Foundation; either version 2 of the License, or
19803 + * (at your option) any later version.
19805 + * This program is distributed in the hope that it will be useful,
19806 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19807 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19808 + * GNU General Public License for more details.
19810 + * You should have received a copy of the GNU General Public License
19811 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19815 + * support for loopback mount as a branch
19818 +#ifndef __AUFS_LOOP_H__
19819 +#define __AUFS_LOOP_H__
19824 +struct super_block;
19826 +#ifdef CONFIG_AUFS_BDEV_LOOP
19827 +/* drivers/block/loop.c */
19828 +struct file *loop_backing_file(struct super_block *sb);
19831 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
19832 +int au_test_loopback_kthread(void);
19833 +void au_warn_loopback(struct super_block *h_sb);
19835 +int au_loopback_init(void);
19836 +void au_loopback_fin(void);
19838 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
19839 + struct dentry *h_adding)
19840 +AuStubInt0(au_test_loopback_kthread, void)
19841 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
19843 +AuStubInt0(au_loopback_init, void)
19844 +AuStubVoid(au_loopback_fin, void)
19845 +#endif /* BLK_DEV_LOOP */
19847 +#endif /* __KERNEL__ */
19848 +#endif /* __AUFS_LOOP_H__ */
19849 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
19850 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
19851 +++ linux/fs/aufs/magic.mk 2014-06-24 00:14:06.786052822 +0200
19854 +# defined in ${srctree}/fs/fuse/inode.c
19856 +ifdef CONFIG_FUSE_FS
19857 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
19860 +# defined in ${srctree}/fs/ocfs2/ocfs2_fs.h
19862 +ifdef CONFIG_OCFS2_FS
19863 +ccflags-y += -DOCFS2_SUPER_MAGIC=0x7461636f
19866 +# defined in ${srctree}/fs/ocfs2/dlm/userdlm.h
19868 +ifdef CONFIG_OCFS2_FS_O2CB
19869 +ccflags-y += -DDLMFS_MAGIC=0x76a9f425
19872 +# defined in ${srctree}/fs/cifs/cifsfs.c
19874 +ifdef CONFIG_CIFS_FS
19875 +ccflags-y += -DCIFS_MAGIC_NUMBER=0xFF534D42
19878 +# defined in ${srctree}/fs/xfs/xfs_sb.h
19880 +ifdef CONFIG_XFS_FS
19881 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
19884 +# defined in ${srctree}/fs/configfs/mount.c
19886 +ifdef CONFIG_CONFIGFS_FS
19887 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
19890 +# defined in ${srctree}/fs/9p/v9fs.h
19892 +ifdef CONFIG_9P_FS
19893 +ccflags-y += -DV9FS_MAGIC=0x01021997
19896 +# defined in ${srctree}/fs/ubifs/ubifs.h
19898 +ifdef CONFIG_UBIFS_FS
19899 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
19902 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
19904 +ifdef CONFIG_HFSPLUS_FS
19905 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
19907 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
19908 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
19909 +++ linux/fs/aufs/Makefile 2014-06-24 00:14:06.776052275 +0200
19912 +include ${src}/magic.mk
19913 +ifeq (${CONFIG_AUFS_FS},m)
19914 +include ${src}/conf.mk
19916 +-include ${src}/priv_def.mk
19918 +# cf. include/linux/kernel.h
19920 +ccflags-y += -DDEBUG
19921 +# sparse requires the full pathname
19923 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
19925 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
19928 +obj-$(CONFIG_AUFS_FS) += aufs.o
19929 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
19930 + wkq.o vfsub.o dcsub.o \
19931 + cpup.o whout.o wbr_policy.o \
19932 + dinfo.o dentry.o \
19934 + finfo.o file.o f_op.o \
19936 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
19940 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
19941 +aufs-$(CONFIG_SYSFS) += sysfs.o
19942 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
19943 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
19944 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
19945 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
19946 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
19947 +aufs-$(CONFIG_AUFS_POLL) += poll.o
19948 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
19949 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
19950 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
19951 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
19952 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
19953 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
19954 +++ linux/fs/aufs/module.c 2014-06-24 00:14:06.786052822 +0200
19957 + * Copyright (C) 2005-2014 Junjiro R. Okajima
19959 + * This program, aufs is free software; you can redistribute it and/or modify
19960 + * it under the terms of the GNU General Public License as published by
19961 + * the Free Software Foundation; either version 2 of the License, or
19962 + * (at your option) any later version.
19964 + * This program is distributed in the hope that it will be useful,
19965 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19966 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19967 + * GNU General Public License for more details.
19969 + * You should have received a copy of the GNU General Public License
19970 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19974 + * module global variables and operations
19977 +#include <linux/module.h>
19978 +#include <linux/seq_file.h>
19981 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp)
19983 + if (new_sz <= nused)
19986 + p = krealloc(p, new_sz, gfp);
19988 + memset(p + nused, 0, new_sz - nused);
19992 +/* ---------------------------------------------------------------------- */
19997 +struct kmem_cache *au_cachep[AuCache_Last];
19998 +static int __init au_cache_init(void)
20000 + au_cachep[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
20001 + if (au_cachep[AuCache_DINFO])
20002 + /* SLAB_DESTROY_BY_RCU */
20003 + au_cachep[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
20004 + au_icntnr_init_once);
20005 + if (au_cachep[AuCache_ICNTNR])
20006 + au_cachep[AuCache_FINFO] = AuCacheCtor(au_finfo,
20007 + au_fi_init_once);
20008 + if (au_cachep[AuCache_FINFO])
20009 + au_cachep[AuCache_VDIR] = AuCache(au_vdir);
20010 + if (au_cachep[AuCache_VDIR])
20011 + au_cachep[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
20012 + if (au_cachep[AuCache_DEHSTR])
20018 +static void au_cache_fin(void)
20023 + * Make sure all delayed rcu free inodes are flushed before we
20028 + /* excluding AuCache_HNOTIFY */
20029 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
20030 + for (i = 0; i < AuCache_HNOTIFY; i++)
20031 + if (au_cachep[i]) {
20032 + kmem_cache_destroy(au_cachep[i]);
20033 + au_cachep[i] = NULL;
20037 +/* ---------------------------------------------------------------------- */
20039 +int au_dir_roflags;
20041 +#ifdef CONFIG_AUFS_SBILIST
20043 + * iterate_supers_type() doesn't protect us from
20044 + * remounting (branch management)
20046 +struct au_splhead au_sbilist;
20049 +struct lock_class_key au_lc_key[AuLcKey_Last];
20052 + * functions for module interface.
20054 +MODULE_LICENSE("GPL");
20055 +/* MODULE_LICENSE("GPL v2"); */
20056 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
20057 +MODULE_DESCRIPTION(AUFS_NAME
20058 + " -- Advanced multi layered unification filesystem");
20059 +MODULE_VERSION(AUFS_VERSION);
20060 +MODULE_ALIAS_FS(AUFS_NAME);
20062 +/* this module parameter has no meaning when SYSFS is disabled */
20063 +int sysaufs_brs = 1;
20064 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
20065 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
20067 +/* ---------------------------------------------------------------------- */
20069 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
20071 +int au_seq_path(struct seq_file *seq, struct path *path)
20073 + return seq_path(seq, path, au_esc_chars);
20076 +/* ---------------------------------------------------------------------- */
20078 +static int __init aufs_init(void)
20083 + p = au_esc_chars;
20084 + for (i = 1; i <= ' '; i++)
20090 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
20092 + au_sbilist_init();
20093 + sysaufs_brs_init();
20096 + err = sysaufs_init();
20097 + if (unlikely(err))
20099 + err = au_procfs_init();
20100 + if (unlikely(err))
20101 + goto out_sysaufs;
20102 + err = au_wkq_init();
20103 + if (unlikely(err))
20105 + err = au_loopback_init();
20106 + if (unlikely(err))
20108 + err = au_hnotify_init();
20109 + if (unlikely(err))
20110 + goto out_loopback;
20111 + err = au_sysrq_init();
20112 + if (unlikely(err))
20114 + err = au_cache_init();
20115 + if (unlikely(err))
20117 + err = register_filesystem(&aufs_fs_type);
20118 + if (unlikely(err))
20120 + /* since we define pr_fmt, call printk directly */
20121 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
20122 + goto out; /* success */
20129 + au_hnotify_fin();
20131 + au_loopback_fin();
20143 +static void __exit aufs_exit(void)
20145 + unregister_filesystem(&aufs_fs_type);
20148 + au_hnotify_fin();
20149 + au_loopback_fin();
20156 +module_init(aufs_init);
20157 +module_exit(aufs_exit);
20158 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
20159 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
20160 +++ linux/fs/aufs/module.h 2014-06-24 00:14:06.786052822 +0200
20163 + * Copyright (C) 2005-2014 Junjiro R. Okajima
20165 + * This program, aufs is free software; you can redistribute it and/or modify
20166 + * it under the terms of the GNU General Public License as published by
20167 + * the Free Software Foundation; either version 2 of the License, or
20168 + * (at your option) any later version.
20170 + * This program is distributed in the hope that it will be useful,
20171 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20172 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20173 + * GNU General Public License for more details.
20175 + * You should have received a copy of the GNU General Public License
20176 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20180 + * module initialization and module-global
20183 +#ifndef __AUFS_MODULE_H__
20184 +#define __AUFS_MODULE_H__
20188 +#include <linux/slab.h>
20193 +/* module parameters */
20194 +extern int sysaufs_brs;
20196 +/* ---------------------------------------------------------------------- */
20198 +extern int au_dir_roflags;
20201 + AuLcNonDir_FIINFO,
20202 + AuLcNonDir_DIINFO,
20203 + AuLcNonDir_IIINFO,
20209 + AuLcSymlink_DIINFO,
20210 + AuLcSymlink_IIINFO,
20214 +extern struct lock_class_key au_lc_key[AuLcKey_Last];
20216 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp);
20217 +int au_seq_path(struct seq_file *seq, struct path *path);
20219 +#ifdef CONFIG_PROC_FS
20221 +int __init au_procfs_init(void);
20222 +void au_procfs_fin(void);
20224 +AuStubInt0(au_procfs_init, void);
20225 +AuStubVoid(au_procfs_fin, void);
20228 +/* ---------------------------------------------------------------------- */
20237 + AuCache_HNOTIFY, /* must be last */
20241 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
20242 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
20243 +#define AuCacheCtor(type, ctor) \
20244 + kmem_cache_create(#type, sizeof(struct type), \
20245 + __alignof__(struct type), AuCacheFlags, ctor)
20247 +extern struct kmem_cache *au_cachep[];
20249 +#define AuCacheFuncs(name, index) \
20250 +static inline struct au_##name *au_cache_alloc_##name(void) \
20251 +{ return kmem_cache_alloc(au_cachep[AuCache_##index], GFP_NOFS); } \
20252 +static inline void au_cache_free_##name(struct au_##name *p) \
20253 +{ kmem_cache_free(au_cachep[AuCache_##index], p); }
20255 +AuCacheFuncs(dinfo, DINFO);
20256 +AuCacheFuncs(icntnr, ICNTNR);
20257 +AuCacheFuncs(finfo, FINFO);
20258 +AuCacheFuncs(vdir, VDIR);
20259 +AuCacheFuncs(vdir_dehstr, DEHSTR);
20260 +#ifdef CONFIG_AUFS_HNOTIFY
20261 +AuCacheFuncs(hnotify, HNOTIFY);
20264 +#endif /* __KERNEL__ */
20265 +#endif /* __AUFS_MODULE_H__ */
20266 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
20267 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
20268 +++ linux/fs/aufs/mvdown.c 2014-06-24 00:14:06.786052822 +0200
20271 + * Copyright (C) 2011-2014 Junjiro R. Okajima
20273 + * This program, aufs is free software; you can redistribute it and/or modify
20274 + * it under the terms of the GNU General Public License as published by
20275 + * the Free Software Foundation; either version 2 of the License, or
20276 + * (at your option) any later version.
20278 + * This program is distributed in the hope that it will be useful,
20279 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20280 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20281 + * GNU General Public License for more details.
20283 + * You should have received a copy of the GNU General Public License
20284 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20288 + * move-down, opposite of copy-up
20293 +struct au_mvd_args {
20295 + struct super_block *h_sb;
20296 + struct dentry *h_parent;
20297 + struct au_hinode *hdir;
20298 + struct inode *h_dir, *h_inode;
20299 + } info[AUFS_MVDOWN_NARRAY];
20301 + struct aufs_mvdown mvdown;
20302 + struct dentry *dentry, *parent;
20303 + struct inode *inode, *dir;
20304 + struct super_block *sb;
20305 + aufs_bindex_t bopq, bwh, bfound;
20306 + unsigned char rename_lock;
20307 + struct au_pin pin;
20310 +#define mvd_errno mvdown.au_errno
20311 +#define mvd_bsrc mvdown.a[AUFS_MVDOWN_UPPER].bindex
20312 +#define mvd_src_brid mvdown.a[AUFS_MVDOWN_UPPER].brid
20313 +#define mvd_bdst mvdown.a[AUFS_MVDOWN_LOWER].bindex
20314 +#define mvd_dst_brid mvdown.a[AUFS_MVDOWN_LOWER].brid
20316 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
20317 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
20318 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
20319 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
20320 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
20322 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
20323 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
20324 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
20325 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
20326 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
20328 +#define AU_MVD_PR(flag, ...) do { \
20330 + pr_err(__VA_ARGS__); \
20333 +/* make the parent dir on bdst */
20334 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
20339 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
20340 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
20341 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
20342 + a->mvd_h_dst_parent = NULL;
20343 + if (au_dbend(a->parent) >= a->mvd_bdst)
20344 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
20345 + if (!a->mvd_h_dst_parent) {
20346 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
20347 + if (unlikely(err)) {
20348 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
20351 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
20359 +/* lock them all */
20360 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
20363 + struct dentry *h_trap;
20365 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
20366 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
20367 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
20368 + a->rename_lock = 0;
20369 + err = au_pin(&a->pin, a->dentry, a->mvd_bdst,
20370 + au_opt_udba(a->sb),
20371 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
20373 + a->mvd_h_src_dir = a->mvd_h_src_parent->d_inode;
20374 + mutex_lock_nested(&a->mvd_h_src_dir->i_mutex,
20375 + AuLsc_I_PARENT3);
20377 + AU_MVD_PR(dmsg, "pin failed\n");
20382 + a->rename_lock = 1;
20383 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
20384 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
20386 + err = (h_trap != a->mvd_h_src_parent);
20388 + err = (h_trap != a->mvd_h_dst_parent);
20390 + BUG_ON(err); /* it should never happen */
20397 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
20399 + if (!a->rename_lock) {
20400 + mutex_unlock(&a->mvd_h_src_dir->i_mutex);
20401 + au_unpin(&a->pin);
20403 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
20404 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
20407 +/* copy-down the file */
20408 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
20411 + struct au_cp_generic cpg = {
20412 + .dentry = a->dentry,
20413 + .bdst = a->mvd_bdst,
20414 + .bsrc = a->mvd_bsrc,
20417 + .flags = AuCpup_DTIME | AuCpup_HOPEN
20420 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
20421 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
20422 + au_fset_cpup(cpg.flags, OVERWRITE);
20423 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
20424 + au_fset_cpup(cpg.flags, RWDST);
20425 + err = au_sio_cpdown_simple(&cpg);
20426 + if (unlikely(err))
20427 + AU_MVD_PR(dmsg, "cpdown failed\n");
20434 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
20437 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
20440 + struct path h_path;
20441 + struct au_branch *br;
20442 + struct inode *delegated;
20444 + br = au_sbr(a->sb, a->mvd_bdst);
20445 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
20446 + err = PTR_ERR(h_path.dentry);
20447 + if (IS_ERR(h_path.dentry)) {
20448 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
20453 + if (h_path.dentry->d_inode) {
20454 + h_path.mnt = au_br_mnt(br);
20455 + delegated = NULL;
20456 + err = vfsub_unlink(a->mvd_h_dst_parent->d_inode, &h_path,
20457 + &delegated, /*force*/0);
20458 + if (unlikely(err == -EWOULDBLOCK)) {
20459 + pr_warn("cannot retry for NFSv4 delegation"
20460 + " for an internal unlink\n");
20463 + if (unlikely(err))
20464 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
20466 + dput(h_path.dentry);
20474 + * unlink the topmost h_dentry
20475 + * Note: the target file MAY be modified by UDBA between this mutex_unlock() and
20476 + * mutex_lock() in vfs_unlink(). in this case, such changes may be lost.
20478 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
20481 + struct path h_path;
20482 + struct inode *delegated;
20484 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
20485 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
20486 + delegated = NULL;
20487 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
20488 + if (unlikely(err == -EWOULDBLOCK)) {
20489 + pr_warn("cannot retry for NFSv4 delegation"
20490 + " for an internal unlink\n");
20493 + if (unlikely(err))
20494 + AU_MVD_PR(dmsg, "unlink failed\n");
20501 + * copy-down the file and unlink the bsrc file.
20502 + * - unlink the bdst whout if exist
20503 + * - copy-down the file (with whtmp name and rename)
20504 + * - unlink the bsrc file
20506 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
20510 + err = au_do_mkdir(dmsg, a);
20512 + err = au_do_lock(dmsg, a);
20513 + if (unlikely(err))
20517 + * do not revert the activities we made on bdst since they should be
20518 + * harmless in aufs.
20521 + err = au_do_cpdown(dmsg, a);
20523 + err = au_do_unlink_wh(dmsg, a);
20524 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
20525 + err = au_do_unlink(dmsg, a);
20526 + if (unlikely(err))
20529 + /* maintain internal array */
20530 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
20531 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
20532 + au_set_dbstart(a->dentry, a->mvd_bdst);
20533 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
20534 + au_set_ibstart(a->inode, a->mvd_bdst);
20536 + if (au_dbend(a->dentry) < a->mvd_bdst)
20537 + au_set_dbend(a->dentry, a->mvd_bdst);
20538 + if (au_ibend(a->inode) < a->mvd_bdst)
20539 + au_set_ibend(a->inode, a->mvd_bdst);
20542 + au_do_unlock(dmsg, a);
20548 +/* ---------------------------------------------------------------------- */
20550 +static int find_lower_writable(struct au_mvd_args *a)
20552 + struct super_block *sb;
20553 + aufs_bindex_t bindex, bend;
20554 + struct au_branch *br;
20557 + bindex = a->mvd_bsrc;
20558 + bend = au_sbend(sb);
20559 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER)) {
20560 + for (bindex++; bindex <= bend; bindex++) {
20561 + br = au_sbr(sb, bindex);
20562 + if (!au_br_rdonly(br))
20566 + for (bindex++; bindex <= bend; bindex++) {
20567 + br = au_sbr(sb, bindex);
20568 + if (!(au_br_sb(br)->s_flags & MS_RDONLY)) {
20569 + if (au_br_rdonly(br))
20571 + |= AUFS_MVDOWN_ROLOWER_R;
20580 +/* make sure the file is idle */
20581 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
20583 + int err, plinked;
20586 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
20587 + if (au_dbstart(a->dentry) == a->mvd_bsrc
20588 + && d_count(a->dentry) == 1
20589 + && atomic_read(&a->inode->i_count) == 1
20590 + /* && a->mvd_h_src_inode->i_nlink == 1 */
20591 + && (!plinked || !au_plink_test(a->inode))
20592 + && a->inode->i_nlink == 1)
20597 + "b%d, d{b%d, c%u?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
20598 + a->mvd_bsrc, au_dbstart(a->dentry), d_count(a->dentry),
20599 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
20600 + a->mvd_h_src_inode->i_nlink,
20601 + plinked, plinked ? au_plink_test(a->inode) : 0);
20608 +/* make sure the parent dir is fine */
20609 +static int au_mvd_args_parent(const unsigned char dmsg,
20610 + struct au_mvd_args *a)
20613 + aufs_bindex_t bindex;
20616 + if (unlikely(au_alive_dir(a->parent))) {
20618 + AU_MVD_PR(dmsg, "parent dir is dead\n");
20622 + a->bopq = au_dbdiropq(a->parent);
20623 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
20624 + AuDbg("b%d\n", bindex);
20625 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
20626 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
20628 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
20629 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
20630 + a->bopq, a->mvd_bdst);
20638 +static int au_mvd_args_intermediate(const unsigned char dmsg,
20639 + struct au_mvd_args *a)
20642 + struct au_dinfo *dinfo, *tmp;
20644 + /* lookup the next lower positive entry */
20646 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
20647 + if (unlikely(!tmp))
20652 + dinfo = au_di(a->dentry);
20653 + au_di_cp(tmp, dinfo);
20654 + au_di_swap(tmp, dinfo);
20656 + /* returns the number of positive dentries */
20657 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1, /*type*/0);
20659 + a->bwh = au_dbwh(a->dentry);
20660 + else if (err > 0)
20661 + a->bfound = au_dbstart(a->dentry);
20663 + au_di_swap(tmp, dinfo);
20664 + au_rw_write_unlock(&tmp->di_rwsem);
20666 + if (unlikely(err < 0))
20667 + AU_MVD_PR(dmsg, "failed look-up lower\n");
20670 + * here, we have these cases.
20672 + * no positive dentry under bsrc. there are more sub-cases.
20674 + * there no whiteout, we can safely move-down.
20677 + * bsrc < bwh && bwh < bdst
20678 + * there is a whiteout on RO branch. cannot proceed.
20680 + * there is a whiteout on the RW target branch. it should
20683 + * there is a whiteout somewhere unrelated branch.
20684 + * -1 < bfound && bfound <= bsrc
20687 + * found, but it is on RO branch between bsrc and bdst. cannot
20690 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
20693 + * found, after we create the file on bdst, it will be hidden.
20696 + AuDebugOn(a->bfound == -1
20698 + && a->bwh <= a->mvd_bsrc);
20699 + AuDebugOn(-1 < a->bfound
20700 + && a->bfound <= a->mvd_bsrc);
20703 + if (a->bfound == -1
20704 + && a->mvd_bsrc < a->bwh
20706 + && a->bwh < a->mvd_bdst) {
20707 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
20708 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
20709 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
20711 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
20712 + a->mvd_errno = EAU_MVDOWN_UPPER;
20713 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
20714 + a->mvd_bdst, a->bfound);
20718 + err = 0; /* success */
20725 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
20730 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
20731 + && a->bfound == a->mvd_bdst)
20737 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
20740 + struct au_branch *br;
20743 + if (unlikely(S_ISDIR(a->inode->i_mode)))
20747 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
20748 + a->mvd_bsrc = au_ibstart(a->inode);
20750 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
20751 + if (unlikely(a->mvd_bsrc < 0
20752 + || (a->mvd_bsrc < au_dbstart(a->dentry)
20753 + || au_dbend(a->dentry) < a->mvd_bsrc
20754 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
20755 + || (a->mvd_bsrc < au_ibstart(a->inode)
20756 + || au_ibend(a->inode) < a->mvd_bsrc
20757 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
20758 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
20759 + AU_MVD_PR(dmsg, "no upper\n");
20763 + if (unlikely(a->mvd_bsrc == au_sbend(a->sb))) {
20764 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
20765 + AU_MVD_PR(dmsg, "on the bottom\n");
20768 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
20769 + br = au_sbr(a->sb, a->mvd_bsrc);
20770 + err = au_br_rdonly(br);
20771 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
20772 + if (unlikely(err))
20774 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
20775 + || IS_APPEND(a->mvd_h_src_inode))) {
20777 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
20783 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
20784 + a->mvd_bdst = find_lower_writable(a);
20785 + if (unlikely(a->mvd_bdst < 0)) {
20786 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
20787 + AU_MVD_PR(dmsg, "no writable lower branch\n");
20791 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
20792 + if (unlikely(a->mvd_bdst < 0
20793 + || au_sbend(a->sb) < a->mvd_bdst)) {
20794 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
20795 + AU_MVD_PR(dmsg, "no lower brid\n");
20800 + err = au_mvd_args_busy(dmsg, a);
20802 + err = au_mvd_args_parent(dmsg, a);
20804 + err = au_mvd_args_intermediate(dmsg, a);
20806 + err = au_mvd_args_exist(dmsg, a);
20808 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
20815 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
20818 + unsigned char dmsg;
20819 + struct au_mvd_args *args;
20822 + if (unlikely(!capable(CAP_SYS_ADMIN)))
20825 + WARN_ONCE(1, "move-down is still testing...\n");
20828 + args = kmalloc(sizeof(*args), GFP_NOFS);
20829 + if (unlikely(!args))
20832 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
20834 + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
20835 + if (unlikely(err)) {
20840 + AuDbg("flags 0x%x\n", args->mvdown.flags);
20841 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
20842 + args->mvdown.au_errno = 0;
20843 + args->dentry = dentry;
20844 + args->inode = dentry->d_inode;
20845 + args->sb = dentry->d_sb;
20848 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
20849 + args->parent = dget_parent(dentry);
20850 + args->dir = args->parent->d_inode;
20851 + mutex_lock_nested(&args->dir->i_mutex, I_MUTEX_PARENT);
20852 + dput(args->parent);
20853 + if (unlikely(args->parent != dentry->d_parent)) {
20854 + AU_MVD_PR(dmsg, "parent dir is moved\n");
20858 + mutex_lock_nested(&args->inode->i_mutex, I_MUTEX_CHILD);
20859 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH);
20860 + if (unlikely(err))
20863 + di_write_lock_parent(args->parent);
20864 + err = au_mvd_args(dmsg, args);
20865 + if (unlikely(err))
20868 + AuDbgDentry(dentry);
20869 + AuDbgInode(args->inode);
20870 + err = au_do_mvdown(dmsg, args);
20871 + if (unlikely(err))
20873 + AuDbgDentry(dentry);
20874 + AuDbgInode(args->inode);
20876 + au_cpup_attr_timesizes(args->dir);
20877 + au_cpup_attr_timesizes(args->inode);
20878 + au_cpup_igen(args->inode, au_h_iptr(args->inode, args->mvd_bdst));
20879 + /* au_digen_dec(dentry); */
20882 + di_write_unlock(args->parent);
20883 + aufs_read_unlock(dentry, AuLock_DW);
20885 + mutex_unlock(&args->inode->i_mutex);
20887 + mutex_unlock(&args->dir->i_mutex);
20889 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
20897 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
20898 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
20899 +++ linux/fs/aufs/opts.c 2014-06-24 00:14:06.786052822 +0200
20902 + * Copyright (C) 2005-2014 Junjiro R. Okajima
20904 + * This program, aufs is free software; you can redistribute it and/or modify
20905 + * it under the terms of the GNU General Public License as published by
20906 + * the Free Software Foundation; either version 2 of the License, or
20907 + * (at your option) any later version.
20909 + * This program is distributed in the hope that it will be useful,
20910 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20911 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20912 + * GNU General Public License for more details.
20914 + * You should have received a copy of the GNU General Public License
20915 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20919 + * mount options/flags
20922 +#include <linux/namei.h>
20923 +#include <linux/types.h> /* a distribution requires */
20924 +#include <linux/parser.h>
20927 +/* ---------------------------------------------------------------------- */
20931 + Opt_add, Opt_del, Opt_mod, Opt_reorder, Opt_append, Opt_prepend,
20932 + Opt_idel, Opt_imod, Opt_ireorder,
20933 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash, Opt_rendir,
20934 + Opt_rdblk_def, Opt_rdhash_def,
20935 + Opt_xino, Opt_zxino, Opt_noxino,
20936 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
20937 + Opt_trunc_xino_path, Opt_itrunc_xino,
20938 + Opt_trunc_xib, Opt_notrunc_xib,
20939 + Opt_shwh, Opt_noshwh,
20940 + Opt_plink, Opt_noplink, Opt_list_plink,
20942 + Opt_dio, Opt_nodio,
20943 + /* Opt_lock, Opt_unlock, */
20944 + Opt_cmd, Opt_cmd_args,
20945 + Opt_diropq_a, Opt_diropq_w,
20946 + Opt_warn_perm, Opt_nowarn_perm,
20947 + Opt_wbr_copyup, Opt_wbr_create,
20948 + Opt_refrof, Opt_norefrof,
20949 + Opt_verbose, Opt_noverbose,
20950 + Opt_sum, Opt_nosum, Opt_wsum,
20951 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
20954 +static match_table_t options = {
20955 + {Opt_br, "br=%s"},
20956 + {Opt_br, "br:%s"},
20958 + {Opt_add, "add=%d:%s"},
20959 + {Opt_add, "add:%d:%s"},
20960 + {Opt_add, "ins=%d:%s"},
20961 + {Opt_add, "ins:%d:%s"},
20962 + {Opt_append, "append=%s"},
20963 + {Opt_append, "append:%s"},
20964 + {Opt_prepend, "prepend=%s"},
20965 + {Opt_prepend, "prepend:%s"},
20967 + {Opt_del, "del=%s"},
20968 + {Opt_del, "del:%s"},
20969 + /* {Opt_idel, "idel:%d"}, */
20970 + {Opt_mod, "mod=%s"},
20971 + {Opt_mod, "mod:%s"},
20972 + /* {Opt_imod, "imod:%d:%s"}, */
20974 + {Opt_dirwh, "dirwh=%d"},
20976 + {Opt_xino, "xino=%s"},
20977 + {Opt_noxino, "noxino"},
20978 + {Opt_trunc_xino, "trunc_xino"},
20979 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
20980 + {Opt_notrunc_xino, "notrunc_xino"},
20981 + {Opt_trunc_xino_path, "trunc_xino=%s"},
20982 + {Opt_itrunc_xino, "itrunc_xino=%d"},
20983 + /* {Opt_zxino, "zxino=%s"}, */
20984 + {Opt_trunc_xib, "trunc_xib"},
20985 + {Opt_notrunc_xib, "notrunc_xib"},
20987 +#ifdef CONFIG_PROC_FS
20988 + {Opt_plink, "plink"},
20990 + {Opt_ignore_silent, "plink"},
20993 + {Opt_noplink, "noplink"},
20995 +#ifdef CONFIG_AUFS_DEBUG
20996 + {Opt_list_plink, "list_plink"},
20999 + {Opt_udba, "udba=%s"},
21001 + {Opt_dio, "dio"},
21002 + {Opt_nodio, "nodio"},
21004 + {Opt_diropq_a, "diropq=always"},
21005 + {Opt_diropq_a, "diropq=a"},
21006 + {Opt_diropq_w, "diropq=whiteouted"},
21007 + {Opt_diropq_w, "diropq=w"},
21009 + {Opt_warn_perm, "warn_perm"},
21010 + {Opt_nowarn_perm, "nowarn_perm"},
21012 + /* keep them temporary */
21013 + {Opt_ignore_silent, "coo=%s"},
21014 + {Opt_ignore_silent, "nodlgt"},
21015 + {Opt_ignore_silent, "nodirperm1"},
21016 + {Opt_ignore_silent, "clean_plink"},
21018 +#ifdef CONFIG_AUFS_SHWH
21019 + {Opt_shwh, "shwh"},
21021 + {Opt_noshwh, "noshwh"},
21023 + {Opt_rendir, "rendir=%d"},
21025 + {Opt_refrof, "refrof"},
21026 + {Opt_norefrof, "norefrof"},
21028 + {Opt_verbose, "verbose"},
21029 + {Opt_verbose, "v"},
21030 + {Opt_noverbose, "noverbose"},
21031 + {Opt_noverbose, "quiet"},
21032 + {Opt_noverbose, "q"},
21033 + {Opt_noverbose, "silent"},
21035 + {Opt_sum, "sum"},
21036 + {Opt_nosum, "nosum"},
21037 + {Opt_wsum, "wsum"},
21039 + {Opt_rdcache, "rdcache=%d"},
21040 + {Opt_rdblk, "rdblk=%d"},
21041 + {Opt_rdblk_def, "rdblk=def"},
21042 + {Opt_rdhash, "rdhash=%d"},
21043 + {Opt_rdhash_def, "rdhash=def"},
21045 + {Opt_wbr_create, "create=%s"},
21046 + {Opt_wbr_create, "create_policy=%s"},
21047 + {Opt_wbr_copyup, "cpup=%s"},
21048 + {Opt_wbr_copyup, "copyup=%s"},
21049 + {Opt_wbr_copyup, "copyup_policy=%s"},
21051 + /* internal use for the scripts */
21052 + {Opt_ignore_silent, "si=%s"},
21054 + {Opt_br, "dirs=%s"},
21055 + {Opt_ignore, "debug=%d"},
21056 + {Opt_ignore, "delete=whiteout"},
21057 + {Opt_ignore, "delete=all"},
21058 + {Opt_ignore, "imap=%s"},
21060 + /* temporary workaround, due to old mount(8)? */
21061 + {Opt_ignore_silent, "relatime"},
21066 +/* ---------------------------------------------------------------------- */
21068 +static const char *au_parser_pattern(int val, struct match_token *token)
21070 + while (token->pattern) {
21071 + if (token->token == val)
21072 + return token->pattern;
21079 +/* ---------------------------------------------------------------------- */
21081 +static match_table_t brperm = {
21082 + {AuBrPerm_RO, AUFS_BRPERM_RO},
21083 + {AuBrPerm_RR, AUFS_BRPERM_RR},
21084 + {AuBrPerm_RW, AUFS_BRPERM_RW},
21088 +static match_table_t brattr = {
21089 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
21090 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
21091 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
21095 +#define AuBrStr_LONGEST AUFS_BRPERM_RW \
21096 + "+" AUFS_BRATTR_UNPIN \
21097 + "+" AUFS_BRWATTR_NLWH
21099 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
21106 + p = strchr(str, '+');
21109 + v = match_token(str, table, args);
21115 + pr_warn("ignored branch attribute %s\n", str);
21125 +static int noinline_for_stack br_perm_val(char *perm)
21129 + substring_t args[MAX_OPT_ARGS];
21131 + p = strchr(perm, '+');
21134 + val = match_token(perm, brperm, args);
21138 + pr_warn("ignored branch permission %s\n", perm);
21139 + val = AuBrPerm_RO;
21147 + q = strchr(p, '+');
21150 + val |= br_attr_val(p, brattr, args);
21157 + switch (val & AuBrPerm_Mask) {
21158 + case AuBrPerm_RO:
21159 + case AuBrPerm_RR:
21160 + if (unlikely(val & AuBrWAttr_NoLinkWH)) {
21161 + pr_warn("ignored branch attribute %s\n",
21162 + AUFS_BRWATTR_NLWH);
21163 + val &= ~AuBrWAttr_NoLinkWH;
21166 + case AuBrPerm_RW:
21167 + if (unlikely(val & AuBrRAttr_WH)) {
21168 + pr_warn("ignored branch attribute %s\n",
21169 + AUFS_BRRATTR_WH);
21170 + val &= ~AuBrRAttr_WH;
21179 +/* Caller should free the return value */
21180 +char *au_optstr_br_perm(int brperm)
21182 + char *p, a[sizeof(AuBrStr_LONGEST)];
21185 +#define SetPerm(str) do { \
21186 + sz = sizeof(str); \
21187 + memcpy(a, str, sz); \
21188 + p = a + sz - 1; \
21191 +#define AppendAttr(flag, str) do { \
21192 + if (brperm & flag) { \
21193 + sz = sizeof(str); \
21195 + memcpy(p, str, sz); \
21200 + switch (brperm & AuBrPerm_Mask) {
21201 + case AuBrPerm_RO:
21202 + SetPerm(AUFS_BRPERM_RO);
21204 + case AuBrPerm_RR:
21205 + SetPerm(AUFS_BRPERM_RR);
21207 + case AuBrPerm_RW:
21208 + SetPerm(AUFS_BRPERM_RW);
21214 + AppendAttr(AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN);
21215 + AppendAttr(AuBrRAttr_WH, AUFS_BRRATTR_WH);
21216 + AppendAttr(AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH);
21218 + AuDebugOn(strlen(a) >= sizeof(a));
21219 + return kstrdup(a, GFP_NOFS);
21224 +/* ---------------------------------------------------------------------- */
21226 +static match_table_t udbalevel = {
21227 + {AuOpt_UDBA_REVAL, "reval"},
21228 + {AuOpt_UDBA_NONE, "none"},
21229 +#ifdef CONFIG_AUFS_HNOTIFY
21230 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
21231 +#ifdef CONFIG_AUFS_HFSNOTIFY
21232 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
21238 +static int noinline_for_stack udba_val(char *str)
21240 + substring_t args[MAX_OPT_ARGS];
21242 + return match_token(str, udbalevel, args);
21245 +const char *au_optstr_udba(int udba)
21247 + return au_parser_pattern(udba, (void *)udbalevel);
21250 +/* ---------------------------------------------------------------------- */
21252 +static match_table_t au_wbr_create_policy = {
21253 + {AuWbrCreate_TDP, "tdp"},
21254 + {AuWbrCreate_TDP, "top-down-parent"},
21255 + {AuWbrCreate_RR, "rr"},
21256 + {AuWbrCreate_RR, "round-robin"},
21257 + {AuWbrCreate_MFS, "mfs"},
21258 + {AuWbrCreate_MFS, "most-free-space"},
21259 + {AuWbrCreate_MFSV, "mfs:%d"},
21260 + {AuWbrCreate_MFSV, "most-free-space:%d"},
21262 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
21263 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
21264 + {AuWbrCreate_PMFS, "pmfs"},
21265 + {AuWbrCreate_PMFSV, "pmfs:%d"},
21266 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
21267 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
21273 + * cf. linux/lib/parser.c and cmdline.c
21274 + * gave up calling memparse() since it uses simple_strtoull() instead of
21277 +static int noinline_for_stack
21278 +au_match_ull(substring_t *s, unsigned long long *result)
21281 + unsigned int len;
21285 + len = s->to - s->from;
21286 + if (len + 1 <= sizeof(a)) {
21287 + memcpy(a, s->from, len);
21289 + err = kstrtoull(a, 0, result);
21294 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
21295 + struct au_opt_wbr_create *create)
21298 + unsigned long long ull;
21301 + if (!au_match_ull(arg, &ull))
21302 + create->mfsrr_watermark = ull;
21304 + pr_err("bad integer in %s\n", str);
21311 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
21312 + struct au_opt_wbr_create *create)
21317 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
21318 + create->mfs_second = n;
21320 + pr_err("bad integer in %s\n", str);
21327 +static int noinline_for_stack
21328 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
21331 + substring_t args[MAX_OPT_ARGS];
21333 + err = match_token(str, au_wbr_create_policy, args);
21334 + create->wbr_create = err;
21336 + case AuWbrCreate_MFSRRV:
21337 + case AuWbrCreate_PMFSRRV:
21338 + e = au_wbr_mfs_wmark(&args[0], str, create);
21340 + e = au_wbr_mfs_sec(&args[1], str, create);
21344 + case AuWbrCreate_MFSRR:
21345 + case AuWbrCreate_PMFSRR:
21346 + e = au_wbr_mfs_wmark(&args[0], str, create);
21347 + if (unlikely(e)) {
21352 + case AuWbrCreate_MFS:
21353 + case AuWbrCreate_PMFS:
21354 + create->mfs_second = AUFS_MFS_DEF_SEC;
21356 + case AuWbrCreate_MFSV:
21357 + case AuWbrCreate_PMFSV:
21358 + e = au_wbr_mfs_sec(&args[0], str, create);
21367 +const char *au_optstr_wbr_create(int wbr_create)
21369 + return au_parser_pattern(wbr_create, (void *)au_wbr_create_policy);
21372 +static match_table_t au_wbr_copyup_policy = {
21373 + {AuWbrCopyup_TDP, "tdp"},
21374 + {AuWbrCopyup_TDP, "top-down-parent"},
21375 + {AuWbrCopyup_BUP, "bup"},
21376 + {AuWbrCopyup_BUP, "bottom-up-parent"},
21377 + {AuWbrCopyup_BU, "bu"},
21378 + {AuWbrCopyup_BU, "bottom-up"},
21382 +static int noinline_for_stack au_wbr_copyup_val(char *str)
21384 + substring_t args[MAX_OPT_ARGS];
21386 + return match_token(str, au_wbr_copyup_policy, args);
21389 +const char *au_optstr_wbr_copyup(int wbr_copyup)
21391 + return au_parser_pattern(wbr_copyup, (void *)au_wbr_copyup_policy);
21394 +/* ---------------------------------------------------------------------- */
21396 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
21398 +static void dump_opts(struct au_opts *opts)
21400 +#ifdef CONFIG_AUFS_DEBUG
21401 + /* reduce stack space */
21403 + struct au_opt_add *add;
21404 + struct au_opt_del *del;
21405 + struct au_opt_mod *mod;
21406 + struct au_opt_xino *xino;
21407 + struct au_opt_xino_itrunc *xino_itrunc;
21408 + struct au_opt_wbr_create *create;
21410 + struct au_opt *opt;
21413 + while (opt->type != Opt_tail) {
21414 + switch (opt->type) {
21416 + u.add = &opt->add;
21417 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
21418 + u.add->bindex, u.add->pathname, u.add->perm,
21419 + u.add->path.dentry);
21423 + u.del = &opt->del;
21424 + AuDbg("del {%s, %p}\n",
21425 + u.del->pathname, u.del->h_path.dentry);
21429 + u.mod = &opt->mod;
21430 + AuDbg("mod {%s, 0x%x, %p}\n",
21431 + u.mod->path, u.mod->perm, u.mod->h_root);
21434 + u.add = &opt->add;
21435 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
21436 + u.add->bindex, u.add->pathname, u.add->perm,
21437 + u.add->path.dentry);
21439 + case Opt_prepend:
21440 + u.add = &opt->add;
21441 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
21442 + u.add->bindex, u.add->pathname, u.add->perm,
21443 + u.add->path.dentry);
21446 + AuDbg("dirwh %d\n", opt->dirwh);
21448 + case Opt_rdcache:
21449 + AuDbg("rdcache %d\n", opt->rdcache);
21452 + AuDbg("rdblk %u\n", opt->rdblk);
21454 + case Opt_rdblk_def:
21455 + AuDbg("rdblk_def\n");
21458 + AuDbg("rdhash %u\n", opt->rdhash);
21460 + case Opt_rdhash_def:
21461 + AuDbg("rdhash_def\n");
21464 + u.xino = &opt->xino;
21465 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
21467 + case Opt_trunc_xino:
21468 + AuLabel(trunc_xino);
21470 + case Opt_notrunc_xino:
21471 + AuLabel(notrunc_xino);
21473 + case Opt_trunc_xino_path:
21474 + case Opt_itrunc_xino:
21475 + u.xino_itrunc = &opt->xino_itrunc;
21476 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
21482 + case Opt_trunc_xib:
21483 + AuLabel(trunc_xib);
21485 + case Opt_notrunc_xib:
21486 + AuLabel(notrunc_xib);
21497 + case Opt_noplink:
21498 + AuLabel(noplink);
21500 + case Opt_list_plink:
21501 + AuLabel(list_plink);
21504 + AuDbg("udba %d, %s\n",
21505 + opt->udba, au_optstr_udba(opt->udba));
21513 + case Opt_diropq_a:
21514 + AuLabel(diropq_a);
21516 + case Opt_diropq_w:
21517 + AuLabel(diropq_w);
21519 + case Opt_warn_perm:
21520 + AuLabel(warn_perm);
21522 + case Opt_nowarn_perm:
21523 + AuLabel(nowarn_perm);
21528 + case Opt_norefrof:
21529 + AuLabel(norefrof);
21531 + case Opt_verbose:
21532 + AuLabel(verbose);
21534 + case Opt_noverbose:
21535 + AuLabel(noverbose);
21546 + case Opt_wbr_create:
21547 + u.create = &opt->wbr_create;
21548 + AuDbg("create %d, %s\n", u.create->wbr_create,
21549 + au_optstr_wbr_create(u.create->wbr_create));
21550 + switch (u.create->wbr_create) {
21551 + case AuWbrCreate_MFSV:
21552 + case AuWbrCreate_PMFSV:
21553 + AuDbg("%d sec\n", u.create->mfs_second);
21555 + case AuWbrCreate_MFSRR:
21556 + AuDbg("%llu watermark\n",
21557 + u.create->mfsrr_watermark);
21559 + case AuWbrCreate_MFSRRV:
21560 + case AuWbrCreate_PMFSRRV:
21561 + AuDbg("%llu watermark, %d sec\n",
21562 + u.create->mfsrr_watermark,
21563 + u.create->mfs_second);
21567 + case Opt_wbr_copyup:
21568 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
21569 + au_optstr_wbr_copyup(opt->wbr_copyup));
21579 +void au_opts_free(struct au_opts *opts)
21581 + struct au_opt *opt;
21584 + while (opt->type != Opt_tail) {
21585 + switch (opt->type) {
21588 + case Opt_prepend:
21589 + path_put(&opt->add.path);
21593 + path_put(&opt->del.h_path);
21597 + dput(opt->mod.h_root);
21600 + fput(opt->xino.file);
21607 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
21608 + aufs_bindex_t bindex)
21611 + struct au_opt_add *add = &opt->add;
21614 + add->bindex = bindex;
21615 + add->perm = AuBrPerm_RO;
21616 + add->pathname = opt_str;
21617 + p = strchr(opt_str, '=');
21621 + add->perm = br_perm_val(p);
21624 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
21627 + add->perm = AuBrPerm_RO;
21628 + if (au_test_fs_rr(add->path.dentry->d_sb))
21629 + add->perm = AuBrPerm_RR;
21630 + else if (!bindex && !(sb_flags & MS_RDONLY))
21631 + add->perm = AuBrPerm_RW;
21633 + opt->type = Opt_add;
21636 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
21643 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
21647 + del->pathname = args[0].from;
21648 + AuDbg("del path %s\n", del->pathname);
21650 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
21651 + if (unlikely(err))
21652 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
21657 +#if 0 /* reserved for future use */
21658 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
21659 + struct au_opt_del *del, substring_t args[])
21662 + struct dentry *root;
21665 + root = sb->s_root;
21666 + aufs_read_lock(root, AuLock_FLUSH);
21667 + if (bindex < 0 || au_sbend(sb) < bindex) {
21668 + pr_err("out of bounds, %d\n", bindex);
21673 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
21674 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
21677 + aufs_read_unlock(root, !AuLock_IR);
21682 +static int noinline_for_stack
21683 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
21686 + struct path path;
21690 + mod->path = args[0].from;
21691 + p = strchr(mod->path, '=');
21692 + if (unlikely(!p)) {
21693 + pr_err("no permssion %s\n", args[0].from);
21698 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
21699 + if (unlikely(err)) {
21700 + pr_err("lookup failed %s (%d)\n", mod->path, err);
21704 + mod->perm = br_perm_val(p);
21705 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
21706 + mod->h_root = dget(path.dentry);
21713 +#if 0 /* reserved for future use */
21714 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
21715 + struct au_opt_mod *mod, substring_t args[])
21718 + struct dentry *root;
21721 + root = sb->s_root;
21722 + aufs_read_lock(root, AuLock_FLUSH);
21723 + if (bindex < 0 || au_sbend(sb) < bindex) {
21724 + pr_err("out of bounds, %d\n", bindex);
21729 + mod->perm = br_perm_val(args[1].from);
21730 + AuDbg("mod path %s, perm 0x%x, %s\n",
21731 + mod->path, mod->perm, args[1].from);
21732 + mod->h_root = dget(au_h_dptr(root, bindex));
21735 + aufs_read_unlock(root, !AuLock_IR);
21740 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
21741 + substring_t args[])
21744 + struct file *file;
21746 + file = au_xino_create(sb, args[0].from, /*silent*/0);
21747 + err = PTR_ERR(file);
21748 + if (IS_ERR(file))
21752 + if (unlikely(file->f_dentry->d_sb == sb)) {
21754 + pr_err("%s must be outside\n", args[0].from);
21759 + xino->file = file;
21760 + xino->path = args[0].from;
21766 +static int noinline_for_stack
21767 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
21768 + struct au_opt_xino_itrunc *xino_itrunc,
21769 + substring_t args[])
21772 + aufs_bindex_t bend, bindex;
21773 + struct path path;
21774 + struct dentry *root;
21776 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
21777 + if (unlikely(err)) {
21778 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
21782 + xino_itrunc->bindex = -1;
21783 + root = sb->s_root;
21784 + aufs_read_lock(root, AuLock_FLUSH);
21785 + bend = au_sbend(sb);
21786 + for (bindex = 0; bindex <= bend; bindex++) {
21787 + if (au_h_dptr(root, bindex) == path.dentry) {
21788 + xino_itrunc->bindex = bindex;
21792 + aufs_read_unlock(root, !AuLock_IR);
21795 + if (unlikely(xino_itrunc->bindex < 0)) {
21796 + pr_err("no such branch %s\n", args[0].from);
21804 +/* called without aufs lock */
21805 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
21807 + int err, n, token;
21808 + aufs_bindex_t bindex;
21809 + unsigned char skipped;
21810 + struct dentry *root;
21811 + struct au_opt *opt, *opt_tail;
21813 + /* reduce the stack space */
21815 + struct au_opt_xino_itrunc *xino_itrunc;
21816 + struct au_opt_wbr_create *create;
21819 + substring_t args[MAX_OPT_ARGS];
21823 + a = kmalloc(sizeof(*a), GFP_NOFS);
21824 + if (unlikely(!a))
21827 + root = sb->s_root;
21831 + opt_tail = opt + opts->max_opt - 1;
21832 + opt->type = Opt_tail;
21833 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
21836 + token = match_token(opt_str, options, a->args);
21840 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
21842 + err = opt_add(opt, opt_str, opts->sb_flags,
21844 + if (unlikely(!err && ++opt > opt_tail)) {
21848 + opt->type = Opt_tail;
21853 + if (unlikely(match_int(&a->args[0], &n))) {
21854 + pr_err("bad integer in %s\n", opt_str);
21858 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
21861 + opt->type = token;
21864 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
21865 + /*dummy bindex*/1);
21867 + opt->type = token;
21869 + case Opt_prepend:
21870 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
21873 + opt->type = token;
21876 + err = au_opts_parse_del(&opt->del, a->args);
21878 + opt->type = token;
21880 +#if 0 /* reserved for future use */
21882 + del->pathname = "(indexed)";
21883 + if (unlikely(match_int(&args[0], &n))) {
21884 + pr_err("bad integer in %s\n", opt_str);
21887 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
21889 + opt->type = token;
21893 + err = au_opts_parse_mod(&opt->mod, a->args);
21895 + opt->type = token;
21897 +#ifdef IMOD /* reserved for future use */
21899 + u.mod->path = "(indexed)";
21900 + if (unlikely(match_int(&a->args[0], &n))) {
21901 + pr_err("bad integer in %s\n", opt_str);
21904 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
21906 + opt->type = token;
21910 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
21912 + opt->type = token;
21915 + case Opt_trunc_xino_path:
21916 + err = au_opts_parse_xino_itrunc_path
21917 + (sb, &opt->xino_itrunc, a->args);
21919 + opt->type = token;
21922 + case Opt_itrunc_xino:
21923 + u.xino_itrunc = &opt->xino_itrunc;
21924 + if (unlikely(match_int(&a->args[0], &n))) {
21925 + pr_err("bad integer in %s\n", opt_str);
21928 + u.xino_itrunc->bindex = n;
21929 + aufs_read_lock(root, AuLock_FLUSH);
21930 + if (n < 0 || au_sbend(sb) < n) {
21931 + pr_err("out of bounds, %d\n", n);
21932 + aufs_read_unlock(root, !AuLock_IR);
21935 + aufs_read_unlock(root, !AuLock_IR);
21937 + opt->type = token;
21941 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
21944 + opt->type = token;
21947 + case Opt_rdcache:
21948 + if (unlikely(match_int(&a->args[0], &n))) {
21949 + pr_err("bad integer in %s\n", opt_str);
21952 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
21953 + pr_err("rdcache must be smaller than %d\n",
21954 + AUFS_RDCACHE_MAX);
21957 + opt->rdcache = n;
21959 + opt->type = token;
21962 + if (unlikely(match_int(&a->args[0], &n)
21964 + || n > KMALLOC_MAX_SIZE)) {
21965 + pr_err("bad integer in %s\n", opt_str);
21968 + if (unlikely(n && n < NAME_MAX)) {
21969 + pr_err("rdblk must be larger than %d\n",
21975 + opt->type = token;
21978 + if (unlikely(match_int(&a->args[0], &n)
21980 + || n * sizeof(struct hlist_head)
21981 + > KMALLOC_MAX_SIZE)) {
21982 + pr_err("bad integer in %s\n", opt_str);
21987 + opt->type = token;
21990 + case Opt_trunc_xino:
21991 + case Opt_notrunc_xino:
21993 + case Opt_trunc_xib:
21994 + case Opt_notrunc_xib:
21998 + case Opt_noplink:
21999 + case Opt_list_plink:
22002 + case Opt_diropq_a:
22003 + case Opt_diropq_w:
22004 + case Opt_warn_perm:
22005 + case Opt_nowarn_perm:
22007 + case Opt_norefrof:
22008 + case Opt_verbose:
22009 + case Opt_noverbose:
22013 + case Opt_rdblk_def:
22014 + case Opt_rdhash_def:
22016 + opt->type = token;
22020 + opt->udba = udba_val(a->args[0].from);
22021 + if (opt->udba >= 0) {
22023 + opt->type = token;
22025 + pr_err("wrong value, %s\n", opt_str);
22028 + case Opt_wbr_create:
22029 + u.create = &opt->wbr_create;
22030 + u.create->wbr_create
22031 + = au_wbr_create_val(a->args[0].from, u.create);
22032 + if (u.create->wbr_create >= 0) {
22034 + opt->type = token;
22036 + pr_err("wrong value, %s\n", opt_str);
22038 + case Opt_wbr_copyup:
22039 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
22040 + if (opt->wbr_copyup >= 0) {
22042 + opt->type = token;
22044 + pr_err("wrong value, %s\n", opt_str);
22048 + pr_warn("ignored %s\n", opt_str);
22050 + case Opt_ignore_silent:
22055 + pr_err("unknown option %s\n", opt_str);
22059 + if (!err && !skipped) {
22060 + if (unlikely(++opt > opt_tail)) {
22063 + opt->type = Opt_tail;
22066 + opt->type = Opt_tail;
22072 + if (unlikely(err))
22073 + au_opts_free(opts);
22079 +static int au_opt_wbr_create(struct super_block *sb,
22080 + struct au_opt_wbr_create *create)
22083 + struct au_sbinfo *sbinfo;
22085 + SiMustWriteLock(sb);
22087 + err = 1; /* handled */
22088 + sbinfo = au_sbi(sb);
22089 + if (sbinfo->si_wbr_create_ops->fin) {
22090 + err = sbinfo->si_wbr_create_ops->fin(sb);
22095 + sbinfo->si_wbr_create = create->wbr_create;
22096 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
22097 + switch (create->wbr_create) {
22098 + case AuWbrCreate_MFSRRV:
22099 + case AuWbrCreate_MFSRR:
22100 + case AuWbrCreate_PMFSRR:
22101 + case AuWbrCreate_PMFSRRV:
22102 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
22104 + case AuWbrCreate_MFS:
22105 + case AuWbrCreate_MFSV:
22106 + case AuWbrCreate_PMFS:
22107 + case AuWbrCreate_PMFSV:
22108 + sbinfo->si_wbr_mfs.mfs_expire
22109 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
22113 + if (sbinfo->si_wbr_create_ops->init)
22114 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
22121 + * plus: processed without an error
22122 + * zero: unprocessed
22124 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
22125 + struct au_opts *opts)
22128 + struct au_sbinfo *sbinfo;
22130 + SiMustWriteLock(sb);
22132 + err = 1; /* handled */
22133 + sbinfo = au_sbi(sb);
22134 + switch (opt->type) {
22136 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
22137 + sbinfo->si_mntflags |= opt->udba;
22138 + opts->given_udba |= opt->udba;
22142 + au_opt_set(sbinfo->si_mntflags, PLINK);
22144 + case Opt_noplink:
22145 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
22146 + au_plink_put(sb, /*verbose*/1);
22147 + au_opt_clr(sbinfo->si_mntflags, PLINK);
22149 + case Opt_list_plink:
22150 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
22151 + au_plink_list(sb);
22155 + au_opt_set(sbinfo->si_mntflags, DIO);
22156 + au_fset_opts(opts->flags, REFRESH_DYAOP);
22159 + au_opt_clr(sbinfo->si_mntflags, DIO);
22160 + au_fset_opts(opts->flags, REFRESH_DYAOP);
22163 + case Opt_diropq_a:
22164 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
22166 + case Opt_diropq_w:
22167 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
22170 + case Opt_warn_perm:
22171 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
22173 + case Opt_nowarn_perm:
22174 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
22178 + au_opt_set(sbinfo->si_mntflags, REFROF);
22180 + case Opt_norefrof:
22181 + au_opt_clr(sbinfo->si_mntflags, REFROF);
22184 + case Opt_verbose:
22185 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
22187 + case Opt_noverbose:
22188 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
22192 + au_opt_set(sbinfo->si_mntflags, SUM);
22195 + au_opt_clr(sbinfo->si_mntflags, SUM);
22196 + au_opt_set(sbinfo->si_mntflags, SUM_W);
22198 + au_opt_clr(sbinfo->si_mntflags, SUM);
22199 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
22202 + case Opt_wbr_create:
22203 + err = au_opt_wbr_create(sb, &opt->wbr_create);
22205 + case Opt_wbr_copyup:
22206 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
22207 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
22211 + sbinfo->si_dirwh = opt->dirwh;
22214 + case Opt_rdcache:
22215 + sbinfo->si_rdcache
22216 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
22219 + sbinfo->si_rdblk = opt->rdblk;
22221 + case Opt_rdblk_def:
22222 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
22225 + sbinfo->si_rdhash = opt->rdhash;
22227 + case Opt_rdhash_def:
22228 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
22232 + au_opt_set(sbinfo->si_mntflags, SHWH);
22235 + au_opt_clr(sbinfo->si_mntflags, SHWH);
22238 + case Opt_trunc_xino:
22239 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
22241 + case Opt_notrunc_xino:
22242 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
22245 + case Opt_trunc_xino_path:
22246 + case Opt_itrunc_xino:
22247 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
22252 + case Opt_trunc_xib:
22253 + au_fset_opts(opts->flags, TRUNC_XIB);
22255 + case Opt_notrunc_xib:
22256 + au_fclr_opts(opts->flags, TRUNC_XIB);
22268 + * returns tri-state.
22269 + * plus: processed without an error
22270 + * zero: unprocessed
22273 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
22274 + struct au_opts *opts)
22276 + int err, do_refresh;
22279 + switch (opt->type) {
22281 + opt->add.bindex = au_sbend(sb) + 1;
22282 + if (opt->add.bindex < 0)
22283 + opt->add.bindex = 0;
22285 + case Opt_prepend:
22286 + opt->add.bindex = 0;
22287 + add: /* indented label */
22289 + err = au_br_add(sb, &opt->add,
22290 + au_ftest_opts(opts->flags, REMOUNT));
22293 + au_fset_opts(opts->flags, REFRESH);
22299 + err = au_br_del(sb, &opt->del,
22300 + au_ftest_opts(opts->flags, REMOUNT));
22303 + au_fset_opts(opts->flags, TRUNC_XIB);
22304 + au_fset_opts(opts->flags, REFRESH);
22310 + err = au_br_mod(sb, &opt->mod,
22311 + au_ftest_opts(opts->flags, REMOUNT),
22316 + au_fset_opts(opts->flags, REFRESH);
22324 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
22325 + struct au_opt_xino **opt_xino,
22326 + struct au_opts *opts)
22329 + aufs_bindex_t bend, bindex;
22330 + struct dentry *root, *parent, *h_root;
22333 + switch (opt->type) {
22335 + err = au_xino_set(sb, &opt->xino,
22336 + !!au_ftest_opts(opts->flags, REMOUNT));
22337 + if (unlikely(err))
22340 + *opt_xino = &opt->xino;
22341 + au_xino_brid_set(sb, -1);
22343 + /* safe d_parent access */
22344 + parent = opt->xino.file->f_dentry->d_parent;
22345 + root = sb->s_root;
22346 + bend = au_sbend(sb);
22347 + for (bindex = 0; bindex <= bend; bindex++) {
22348 + h_root = au_h_dptr(root, bindex);
22349 + if (h_root == parent) {
22350 + au_xino_brid_set(sb, au_sbr_id(sb, bindex));
22358 + au_xino_brid_set(sb, -1);
22359 + *opt_xino = (void *)-1;
22366 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
22367 + unsigned int pending)
22370 + aufs_bindex_t bindex, bend;
22371 + unsigned char do_plink, skip, do_free;
22372 + struct au_branch *br;
22373 + struct au_wbr *wbr;
22374 + struct dentry *root;
22375 + struct inode *dir, *h_dir;
22376 + struct au_sbinfo *sbinfo;
22377 + struct au_hinode *hdir;
22379 + SiMustAnyLock(sb);
22381 + sbinfo = au_sbi(sb);
22382 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
22384 + if (!(sb_flags & MS_RDONLY)) {
22385 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
22386 + pr_warn("first branch should be rw\n");
22387 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
22388 + pr_warn("shwh should be used with ro\n");
22391 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
22392 + && !au_opt_test(sbinfo->si_mntflags, XINO))
22393 + pr_warn("udba=*notify requires xino\n");
22396 + root = sb->s_root;
22397 + dir = root->d_inode;
22398 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
22399 + bend = au_sbend(sb);
22400 + for (bindex = 0; !err && bindex <= bend; bindex++) {
22402 + h_dir = au_h_iptr(dir, bindex);
22403 + br = au_sbr(sb, bindex);
22406 + wbr = br->br_wbr;
22408 + wbr_wh_read_lock(wbr);
22410 + if (!au_br_writable(br->br_perm)) {
22413 + || (!wbr->wbr_whbase
22414 + && !wbr->wbr_plink
22415 + && !wbr->wbr_orph));
22416 + } else if (!au_br_wh_linkable(br->br_perm)) {
22417 + /* skip = (!br->br_whbase && !br->br_orph); */
22418 + skip = (!wbr || !wbr->wbr_whbase);
22419 + if (skip && wbr) {
22421 + skip = !!wbr->wbr_plink;
22423 + skip = !wbr->wbr_plink;
22426 + /* skip = (br->br_whbase && br->br_ohph); */
22427 + skip = (wbr && wbr->wbr_whbase);
22430 + skip = !!wbr->wbr_plink;
22432 + skip = !wbr->wbr_plink;
22436 + wbr_wh_read_unlock(wbr);
22441 + hdir = au_hi(dir, bindex);
22442 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
22444 + wbr_wh_write_lock(wbr);
22445 + err = au_wh_init(br, sb);
22447 + wbr_wh_write_unlock(wbr);
22448 + au_hn_imtx_unlock(hdir);
22450 + if (!err && do_free) {
22452 + br->br_wbr = NULL;
22459 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
22462 + unsigned int tmp;
22463 + aufs_bindex_t bindex, bend;
22464 + struct au_opt *opt;
22465 + struct au_opt_xino *opt_xino, xino;
22466 + struct au_sbinfo *sbinfo;
22467 + struct au_branch *br;
22469 + SiMustWriteLock(sb);
22474 + while (err >= 0 && opt->type != Opt_tail)
22475 + err = au_opt_simple(sb, opt++, opts);
22478 + else if (unlikely(err < 0))
22481 + /* disable xino and udba temporary */
22482 + sbinfo = au_sbi(sb);
22483 + tmp = sbinfo->si_mntflags;
22484 + au_opt_clr(sbinfo->si_mntflags, XINO);
22485 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
22488 + while (err >= 0 && opt->type != Opt_tail)
22489 + err = au_opt_br(sb, opt++, opts);
22492 + else if (unlikely(err < 0))
22495 + bend = au_sbend(sb);
22496 + if (unlikely(bend < 0)) {
22498 + pr_err("no branches\n");
22502 + if (au_opt_test(tmp, XINO))
22503 + au_opt_set(sbinfo->si_mntflags, XINO);
22505 + while (!err && opt->type != Opt_tail)
22506 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
22507 + if (unlikely(err))
22510 + err = au_opts_verify(sb, sb->s_flags, tmp);
22511 + if (unlikely(err))
22514 + /* restore xino */
22515 + if (au_opt_test(tmp, XINO) && !opt_xino) {
22516 + xino.file = au_xino_def(sb);
22517 + err = PTR_ERR(xino.file);
22518 + if (IS_ERR(xino.file))
22521 + err = au_xino_set(sb, &xino, /*remount*/0);
22523 + if (unlikely(err))
22527 + /* restore udba */
22528 + tmp &= AuOptMask_UDBA;
22529 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
22530 + sbinfo->si_mntflags |= tmp;
22531 + bend = au_sbend(sb);
22532 + for (bindex = 0; bindex <= bend; bindex++) {
22533 + br = au_sbr(sb, bindex);
22534 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
22535 + if (unlikely(err))
22536 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
22538 + /* go on even if err */
22540 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
22541 + struct inode *dir = sb->s_root->d_inode;
22542 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
22549 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
22552 + struct inode *dir;
22553 + struct au_opt_xino *opt_xino;
22554 + struct au_opt *opt;
22555 + struct au_sbinfo *sbinfo;
22557 + SiMustWriteLock(sb);
22559 + dir = sb->s_root->d_inode;
22560 + sbinfo = au_sbi(sb);
22564 + while (err >= 0 && opt->type != Opt_tail) {
22565 + err = au_opt_simple(sb, opt, opts);
22567 + err = au_opt_br(sb, opt, opts);
22569 + err = au_opt_xino(sb, opt, &opt_xino, opts);
22575 + /* go on even err */
22577 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
22578 + if (unlikely(rerr && !err))
22581 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
22582 + rerr = au_xib_trunc(sb);
22583 + if (unlikely(rerr && !err))
22587 + /* will be handled by the caller */
22588 + if (!au_ftest_opts(opts->flags, REFRESH)
22589 + && (opts->given_udba || au_opt_test(sbinfo->si_mntflags, XINO)))
22590 + au_fset_opts(opts->flags, REFRESH);
22592 + AuDbg("status 0x%x\n", opts->flags);
22596 +/* ---------------------------------------------------------------------- */
22598 +unsigned int au_opt_udba(struct super_block *sb)
22600 + return au_mntflags(sb) & AuOptMask_UDBA;
22602 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
22603 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
22604 +++ linux/fs/aufs/opts.h 2014-06-24 00:14:06.786052822 +0200
22607 + * Copyright (C) 2005-2014 Junjiro R. Okajima
22609 + * This program, aufs is free software; you can redistribute it and/or modify
22610 + * it under the terms of the GNU General Public License as published by
22611 + * the Free Software Foundation; either version 2 of the License, or
22612 + * (at your option) any later version.
22614 + * This program is distributed in the hope that it will be useful,
22615 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22616 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22617 + * GNU General Public License for more details.
22619 + * You should have received a copy of the GNU General Public License
22620 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22624 + * mount options/flags
22627 +#ifndef __AUFS_OPTS_H__
22628 +#define __AUFS_OPTS_H__
22632 +#include <linux/path.h>
22635 +struct super_block;
22637 +/* ---------------------------------------------------------------------- */
22640 +#define AuOpt_XINO 1 /* external inode number bitmap
22641 + and translation table */
22642 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
22643 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
22644 +#define AuOpt_UDBA_REVAL (1 << 3)
22645 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
22646 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
22647 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
22648 +#define AuOpt_DIRPERM1 (1 << 7) /* unimplemented */
22649 +#define AuOpt_REFROF (1 << 8) /* unimplemented */
22650 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
22651 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
22652 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
22653 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
22654 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
22655 +#define AuOpt_DIO (1 << 14) /* direct io */
22657 +#ifndef CONFIG_AUFS_HNOTIFY
22658 +#undef AuOpt_UDBA_HNOTIFY
22659 +#define AuOpt_UDBA_HNOTIFY 0
22661 +#ifndef CONFIG_AUFS_SHWH
22663 +#define AuOpt_SHWH 0
22666 +#define AuOpt_Def (AuOpt_XINO \
22667 + | AuOpt_UDBA_REVAL \
22669 + /* | AuOpt_DIRPERM1 */ \
22670 + | AuOpt_WARN_PERM)
22671 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
22672 + | AuOpt_UDBA_REVAL \
22673 + | AuOpt_UDBA_HNOTIFY)
22675 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
22676 +#define au_opt_set(flags, name) do { \
22677 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
22678 + ((flags) |= AuOpt_##name); \
22680 +#define au_opt_set_udba(flags, name) do { \
22681 + (flags) &= ~AuOptMask_UDBA; \
22682 + ((flags) |= AuOpt_##name); \
22684 +#define au_opt_clr(flags, name) do { \
22685 + ((flags) &= ~AuOpt_##name); \
22688 +static inline unsigned int au_opts_plink(unsigned int mntflags)
22690 +#ifdef CONFIG_PROC_FS
22693 + return mntflags & ~AuOpt_PLINK;
22697 +/* ---------------------------------------------------------------------- */
22699 +/* policies to select one among multiple writable branches */
22701 + AuWbrCreate_TDP, /* top down parent */
22702 + AuWbrCreate_RR, /* round robin */
22703 + AuWbrCreate_MFS, /* most free space */
22704 + AuWbrCreate_MFSV, /* mfs with seconds */
22705 + AuWbrCreate_MFSRR, /* mfs then rr */
22706 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
22707 + AuWbrCreate_PMFS, /* parent and mfs */
22708 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
22709 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
22710 + AuWbrCreate_PMFSRRV, /* plus seconds */
22712 + AuWbrCreate_Def = AuWbrCreate_TDP
22716 + AuWbrCopyup_TDP, /* top down parent */
22717 + AuWbrCopyup_BUP, /* bottom up parent */
22718 + AuWbrCopyup_BU, /* bottom up */
22720 + AuWbrCopyup_Def = AuWbrCopyup_TDP
22723 +/* ---------------------------------------------------------------------- */
22725 +struct au_opt_add {
22726 + aufs_bindex_t bindex;
22729 + struct path path;
22732 +struct au_opt_del {
22734 + struct path h_path;
22737 +struct au_opt_mod {
22740 + struct dentry *h_root;
22743 +struct au_opt_xino {
22745 + struct file *file;
22748 +struct au_opt_xino_itrunc {
22749 + aufs_bindex_t bindex;
22752 +struct au_opt_wbr_create {
22755 + unsigned long long mfsrr_watermark;
22761 + struct au_opt_xino xino;
22762 + struct au_opt_xino_itrunc xino_itrunc;
22763 + struct au_opt_add add;
22764 + struct au_opt_del del;
22765 + struct au_opt_mod mod;
22768 + unsigned int rdblk;
22769 + unsigned int rdhash;
22771 + struct au_opt_wbr_create wbr_create;
22777 +#define AuOpts_REMOUNT 1
22778 +#define AuOpts_REFRESH (1 << 1)
22779 +#define AuOpts_TRUNC_XIB (1 << 2)
22780 +#define AuOpts_REFRESH_DYAOP (1 << 3)
22781 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
22782 +#define au_fset_opts(flags, name) \
22783 + do { (flags) |= AuOpts_##name; } while (0)
22784 +#define au_fclr_opts(flags, name) \
22785 + do { (flags) &= ~AuOpts_##name; } while (0)
22788 + struct au_opt *opt;
22791 + unsigned int given_udba;
22792 + unsigned int flags;
22793 + unsigned long sb_flags;
22796 +/* ---------------------------------------------------------------------- */
22798 +char *au_optstr_br_perm(int brperm);
22799 +const char *au_optstr_udba(int udba);
22800 +const char *au_optstr_wbr_copyup(int wbr_copyup);
22801 +const char *au_optstr_wbr_create(int wbr_create);
22803 +void au_opts_free(struct au_opts *opts);
22804 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
22805 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
22806 + unsigned int pending);
22807 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
22808 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
22810 +unsigned int au_opt_udba(struct super_block *sb);
22812 +/* ---------------------------------------------------------------------- */
22814 +#endif /* __KERNEL__ */
22815 +#endif /* __AUFS_OPTS_H__ */
22816 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
22817 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
22818 +++ linux/fs/aufs/plink.c 2014-06-24 00:14:06.786052822 +0200
22821 + * Copyright (C) 2005-2014 Junjiro R. Okajima
22823 + * This program, aufs is free software; you can redistribute it and/or modify
22824 + * it under the terms of the GNU General Public License as published by
22825 + * the Free Software Foundation; either version 2 of the License, or
22826 + * (at your option) any later version.
22828 + * This program is distributed in the hope that it will be useful,
22829 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22830 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22831 + * GNU General Public License for more details.
22833 + * You should have received a copy of the GNU General Public License
22834 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22844 + * the pseudo-link maintenance mode.
22845 + * during a user process maintains the pseudo-links,
22846 + * prohibit adding a new plink and branch manipulation.
22850 + * For entry functions which will handle plink, and i_mutex is already held
22852 + * They cannot wait and should return an error at once.
22853 + * Callers has to check the error.
22855 + * For entry functions which will handle plink, but i_mutex is not held
22857 + * They can wait the plink maintenance mode to finish.
22859 + * They behave like F_SETLK and F_SETLKW.
22860 + * If the caller never handle plink, then both flags are unnecessary.
22863 +int au_plink_maint(struct super_block *sb, int flags)
22867 + struct au_sbinfo *sbi;
22869 + SiMustAnyLock(sb);
22872 + if (!au_opt_test(au_mntflags(sb), PLINK))
22875 + sbi = au_sbi(sb);
22876 + pid = sbi->si_plink_maint_pid;
22877 + if (!pid || pid == current->pid)
22880 + /* todo: it highly depends upon /sbin/mount.aufs */
22882 + ppid = task_pid_vnr(rcu_dereference(current->real_parent));
22883 + rcu_read_unlock();
22887 + if (au_ftest_lock(flags, NOPLMW)) {
22888 + /* if there is no i_mutex lock in VFS, we don't need to wait */
22889 + /* AuDebugOn(!lockdep_depth(current)); */
22890 + while (sbi->si_plink_maint_pid) {
22891 + si_read_unlock(sb);
22892 + /* gave up wake_up_bit() */
22893 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
22895 + if (au_ftest_lock(flags, FLUSH))
22896 + au_nwt_flush(&sbi->si_nowait);
22897 + si_noflush_read_lock(sb);
22899 + } else if (au_ftest_lock(flags, NOPLM)) {
22900 + AuDbg("ppid %d, pid %d\n", ppid, pid);
22908 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
22910 + spin_lock(&sbinfo->si_plink_maint_lock);
22911 + sbinfo->si_plink_maint_pid = 0;
22912 + spin_unlock(&sbinfo->si_plink_maint_lock);
22913 + wake_up_all(&sbinfo->si_plink_wq);
22916 +int au_plink_maint_enter(struct super_block *sb)
22919 + struct au_sbinfo *sbinfo;
22922 + sbinfo = au_sbi(sb);
22923 + /* make sure i am the only one in this fs */
22924 + si_write_lock(sb, AuLock_FLUSH);
22925 + if (au_opt_test(au_mntflags(sb), PLINK)) {
22926 + spin_lock(&sbinfo->si_plink_maint_lock);
22927 + if (!sbinfo->si_plink_maint_pid)
22928 + sbinfo->si_plink_maint_pid = current->pid;
22931 + spin_unlock(&sbinfo->si_plink_maint_lock);
22933 + si_write_unlock(sb);
22938 +/* ---------------------------------------------------------------------- */
22940 +#ifdef CONFIG_AUFS_DEBUG
22941 +void au_plink_list(struct super_block *sb)
22944 + struct au_sbinfo *sbinfo;
22945 + struct hlist_head *plink_hlist;
22946 + struct pseudo_link *plink;
22948 + SiMustAnyLock(sb);
22950 + sbinfo = au_sbi(sb);
22951 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
22952 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
22954 + for (i = 0; i < AuPlink_NHASH; i++) {
22955 + plink_hlist = &sbinfo->si_plink[i].head;
22957 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
22958 + AuDbg("%lu\n", plink->inode->i_ino);
22959 + rcu_read_unlock();
22964 +/* is the inode pseudo-linked? */
22965 +int au_plink_test(struct inode *inode)
22968 + struct au_sbinfo *sbinfo;
22969 + struct hlist_head *plink_hlist;
22970 + struct pseudo_link *plink;
22972 + sbinfo = au_sbi(inode->i_sb);
22973 + AuRwMustAnyLock(&sbinfo->si_rwsem);
22974 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
22975 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
22978 + i = au_plink_hash(inode->i_ino);
22979 + plink_hlist = &sbinfo->si_plink[i].head;
22981 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
22982 + if (plink->inode == inode) {
22986 + rcu_read_unlock();
22990 +/* ---------------------------------------------------------------------- */
22993 + * generate a name for plink.
22994 + * the file will be stored under AUFS_WH_PLINKDIR.
22996 +/* 20 is max digits length of ulong 64 */
22997 +#define PLINK_NAME_LEN ((20 + 1) * 2)
22999 +static int plink_name(char *name, int len, struct inode *inode,
23000 + aufs_bindex_t bindex)
23003 + struct inode *h_inode;
23005 + h_inode = au_h_iptr(inode, bindex);
23006 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
23010 +struct au_do_plink_lkup_args {
23011 + struct dentry **errp;
23012 + struct qstr *tgtname;
23013 + struct dentry *h_parent;
23014 + struct au_branch *br;
23017 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
23018 + struct dentry *h_parent,
23019 + struct au_branch *br)
23021 + struct dentry *h_dentry;
23022 + struct mutex *h_mtx;
23024 + h_mtx = &h_parent->d_inode->i_mutex;
23025 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
23026 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
23027 + mutex_unlock(h_mtx);
23031 +static void au_call_do_plink_lkup(void *args)
23033 + struct au_do_plink_lkup_args *a = args;
23034 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
23037 +/* lookup the plink-ed @inode under the branch at @bindex */
23038 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
23040 + struct dentry *h_dentry, *h_parent;
23041 + struct au_branch *br;
23042 + struct inode *h_dir;
23044 + char a[PLINK_NAME_LEN];
23045 + struct qstr tgtname = QSTR_INIT(a, 0);
23047 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
23049 + br = au_sbr(inode->i_sb, bindex);
23050 + h_parent = br->br_wbr->wbr_plink;
23051 + h_dir = h_parent->d_inode;
23052 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
23054 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
23055 + struct au_do_plink_lkup_args args = {
23056 + .errp = &h_dentry,
23057 + .tgtname = &tgtname,
23058 + .h_parent = h_parent,
23062 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
23063 + if (unlikely(wkq_err))
23064 + h_dentry = ERR_PTR(wkq_err);
23066 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
23071 +/* create a pseudo-link */
23072 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
23073 + struct dentry *h_dentry, struct au_branch *br)
23076 + struct path h_path = {
23077 + .mnt = au_br_mnt(br)
23079 + struct inode *h_dir, *delegated;
23081 + h_dir = h_parent->d_inode;
23082 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_CHILD2);
23084 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
23085 + err = PTR_ERR(h_path.dentry);
23086 + if (IS_ERR(h_path.dentry))
23090 + /* wh.plink dir is not monitored */
23091 + /* todo: is it really safe? */
23092 + if (h_path.dentry->d_inode
23093 + && h_path.dentry->d_inode != h_dentry->d_inode) {
23094 + delegated = NULL;
23095 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
23096 + if (unlikely(err == -EWOULDBLOCK)) {
23097 + pr_warn("cannot retry for NFSv4 delegation"
23098 + " for an internal unlink\n");
23101 + dput(h_path.dentry);
23102 + h_path.dentry = NULL;
23106 + if (!err && !h_path.dentry->d_inode) {
23107 + delegated = NULL;
23108 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
23109 + if (unlikely(err == -EWOULDBLOCK)) {
23110 + pr_warn("cannot retry for NFSv4 delegation"
23111 + " for an internal link\n");
23115 + dput(h_path.dentry);
23118 + mutex_unlock(&h_dir->i_mutex);
23122 +struct do_whplink_args {
23124 + struct qstr *tgt;
23125 + struct dentry *h_parent;
23126 + struct dentry *h_dentry;
23127 + struct au_branch *br;
23130 +static void call_do_whplink(void *args)
23132 + struct do_whplink_args *a = args;
23133 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
23136 +static int whplink(struct dentry *h_dentry, struct inode *inode,
23137 + aufs_bindex_t bindex, struct au_branch *br)
23139 + int err, wkq_err;
23140 + struct au_wbr *wbr;
23141 + struct dentry *h_parent;
23142 + struct inode *h_dir;
23143 + char a[PLINK_NAME_LEN];
23144 + struct qstr tgtname = QSTR_INIT(a, 0);
23146 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
23147 + h_parent = wbr->wbr_plink;
23148 + h_dir = h_parent->d_inode;
23149 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
23151 + /* always superio. */
23152 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
23153 + struct do_whplink_args args = {
23156 + .h_parent = h_parent,
23157 + .h_dentry = h_dentry,
23160 + wkq_err = au_wkq_wait(call_do_whplink, &args);
23161 + if (unlikely(wkq_err))
23164 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
23169 +/* free a single plink */
23170 +static void do_put_plink(struct pseudo_link *plink, int do_del)
23173 + hlist_del(&plink->hlist);
23174 + iput(plink->inode);
23178 +static void do_put_plink_rcu(struct rcu_head *rcu)
23180 + struct pseudo_link *plink;
23182 + plink = container_of(rcu, struct pseudo_link, rcu);
23183 + iput(plink->inode);
23188 + * create a new pseudo-link for @h_dentry on @bindex.
23189 + * the linked inode is held in aufs @inode.
23191 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
23192 + struct dentry *h_dentry)
23194 + struct super_block *sb;
23195 + struct au_sbinfo *sbinfo;
23196 + struct hlist_head *plink_hlist;
23197 + struct pseudo_link *plink, *tmp;
23198 + struct au_sphlhead *sphl;
23199 + int found, err, cnt, i;
23201 + sb = inode->i_sb;
23202 + sbinfo = au_sbi(sb);
23203 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
23204 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
23206 + found = au_plink_test(inode);
23210 + i = au_plink_hash(inode->i_ino);
23211 + sphl = sbinfo->si_plink + i;
23212 + plink_hlist = &sphl->head;
23213 + tmp = kmalloc(sizeof(*plink), GFP_NOFS);
23215 + tmp->inode = au_igrab(inode);
23221 + spin_lock(&sphl->spin);
23222 + hlist_for_each_entry(plink, plink_hlist, hlist) {
23223 + if (plink->inode == inode) {
23229 + hlist_add_head_rcu(&tmp->hlist, plink_hlist);
23230 + spin_unlock(&sphl->spin);
23232 + cnt = au_sphl_count(sphl);
23233 +#define msg "unexpectedly unblanced or too many pseudo-links"
23234 + if (cnt > AUFS_PLINK_WARN)
23235 + AuWarn1(msg ", %d\n", cnt);
23237 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
23239 + do_put_plink(tmp, 0);
23244 + if (unlikely(err)) {
23245 + pr_warn("err %d, damaged pseudo link.\n", err);
23247 + au_sphl_del_rcu(&tmp->hlist, sphl);
23248 + call_rcu(&tmp->rcu, do_put_plink_rcu);
23253 +/* free all plinks */
23254 +void au_plink_put(struct super_block *sb, int verbose)
23257 + struct au_sbinfo *sbinfo;
23258 + struct hlist_head *plink_hlist;
23259 + struct hlist_node *tmp;
23260 + struct pseudo_link *plink;
23262 + SiMustWriteLock(sb);
23264 + sbinfo = au_sbi(sb);
23265 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
23266 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
23268 + /* no spin_lock since sbinfo is write-locked */
23270 + for (i = 0; i < AuPlink_NHASH; i++) {
23271 + plink_hlist = &sbinfo->si_plink[i].head;
23272 + if (!warned && verbose && !hlist_empty(plink_hlist)) {
23273 + pr_warn("pseudo-link is not flushed");
23276 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist)
23277 + do_put_plink(plink, 0);
23278 + INIT_HLIST_HEAD(plink_hlist);
23282 +void au_plink_clean(struct super_block *sb, int verbose)
23284 + struct dentry *root;
23286 + root = sb->s_root;
23287 + aufs_write_lock(root);
23288 + if (au_opt_test(au_mntflags(sb), PLINK))
23289 + au_plink_put(sb, verbose);
23290 + aufs_write_unlock(root);
23293 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
23296 + aufs_bindex_t bstart, bend, bindex;
23299 + bstart = au_ibstart(inode);
23300 + bend = au_ibend(inode);
23301 + if (bstart >= 0) {
23302 + for (bindex = bstart; bindex <= bend; bindex++) {
23303 + if (!au_h_iptr(inode, bindex)
23304 + || au_ii_br_id(inode, bindex) != br_id)
23306 + au_set_h_iptr(inode, bindex, NULL, 0);
23311 + for (bindex = bstart; bindex <= bend; bindex++)
23312 + if (au_h_iptr(inode, bindex)) {
23322 +/* free the plinks on a branch specified by @br_id */
23323 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
23325 + struct au_sbinfo *sbinfo;
23326 + struct hlist_head *plink_hlist;
23327 + struct hlist_node *tmp;
23328 + struct pseudo_link *plink;
23329 + struct inode *inode;
23332 + SiMustWriteLock(sb);
23334 + sbinfo = au_sbi(sb);
23335 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
23336 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
23338 + /* no spin_lock since sbinfo is write-locked */
23339 + for (i = 0; i < AuPlink_NHASH; i++) {
23340 + plink_hlist = &sbinfo->si_plink[i].head;
23341 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist) {
23342 + inode = au_igrab(plink->inode);
23343 + ii_write_lock_child(inode);
23344 + do_put = au_plink_do_half_refresh(inode, br_id);
23346 + do_put_plink(plink, 1);
23347 + ii_write_unlock(inode);
23352 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
23353 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
23354 +++ linux/fs/aufs/poll.c 2014-06-24 00:14:06.786052822 +0200
23357 + * Copyright (C) 2005-2014 Junjiro R. Okajima
23359 + * This program, aufs is free software; you can redistribute it and/or modify
23360 + * it under the terms of the GNU General Public License as published by
23361 + * the Free Software Foundation; either version 2 of the License, or
23362 + * (at your option) any later version.
23364 + * This program is distributed in the hope that it will be useful,
23365 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23366 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23367 + * GNU General Public License for more details.
23369 + * You should have received a copy of the GNU General Public License
23370 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23375 + * There is only one filesystem which implements ->poll operation, currently.
23380 +unsigned int aufs_poll(struct file *file, poll_table *wait)
23382 + unsigned int mask;
23384 + struct file *h_file;
23385 + struct dentry *dentry;
23386 + struct super_block *sb;
23388 + /* We should pretend an error happened. */
23389 + mask = POLLERR /* | POLLIN | POLLOUT */;
23390 + dentry = file->f_dentry;
23391 + sb = dentry->d_sb;
23392 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
23393 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
23394 + if (unlikely(err))
23397 + /* it is not an error if h_file has no operation */
23398 + mask = DEFAULT_POLLMASK;
23399 + h_file = au_hf_top(file);
23400 + if (h_file->f_op->poll)
23401 + mask = h_file->f_op->poll(h_file, wait);
23403 + di_read_unlock(dentry, AuLock_IR);
23404 + fi_read_unlock(file);
23407 + si_read_unlock(sb);
23408 + AuTraceErr((int)mask);
23411 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
23412 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
23413 +++ linux/fs/aufs/procfs.c 2014-06-24 00:14:06.786052822 +0200
23416 + * Copyright (C) 2010-2014 Junjiro R. Okajima
23418 + * This program, aufs is free software; you can redistribute it and/or modify
23419 + * it under the terms of the GNU General Public License as published by
23420 + * the Free Software Foundation; either version 2 of the License, or
23421 + * (at your option) any later version.
23423 + * This program is distributed in the hope that it will be useful,
23424 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23425 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23426 + * GNU General Public License for more details.
23428 + * You should have received a copy of the GNU General Public License
23429 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23433 + * procfs interfaces
23436 +#include <linux/proc_fs.h>
23439 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
23441 + struct au_sbinfo *sbinfo;
23443 + sbinfo = file->private_data;
23445 + au_plink_maint_leave(sbinfo);
23446 + kobject_put(&sbinfo->si_kobj);
23452 +static void au_procfs_plm_write_clean(struct file *file)
23454 + struct au_sbinfo *sbinfo;
23456 + sbinfo = file->private_data;
23458 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
23461 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
23464 + struct super_block *sb;
23465 + struct au_sbinfo *sbinfo;
23468 + if (unlikely(file->private_data))
23472 + /* don't use au_sbilist_lock() here */
23473 + spin_lock(&au_sbilist.spin);
23474 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
23475 + if (id == sysaufs_si_id(sbinfo)) {
23476 + kobject_get(&sbinfo->si_kobj);
23477 + sb = sbinfo->si_sb;
23480 + spin_unlock(&au_sbilist.spin);
23483 + if (unlikely(!sb))
23486 + err = au_plink_maint_enter(sb);
23488 + /* keep kobject_get() */
23489 + file->private_data = sbinfo;
23491 + kobject_put(&sbinfo->si_kobj);
23497 + * Accept a valid "si=xxxx" only.
23498 + * Once it is accepted successfully, accept "clean" too.
23500 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
23501 + size_t count, loff_t *ppos)
23504 + unsigned long id;
23505 + /* last newline is allowed */
23506 + char buf[3 + sizeof(unsigned long) * 2 + 1];
23509 + if (unlikely(!capable(CAP_SYS_ADMIN)))
23513 + if (unlikely(count > sizeof(buf)))
23516 + err = copy_from_user(buf, ubuf, count);
23517 + if (unlikely(err)) {
23524 + if (!strcmp("clean", buf)) {
23525 + au_procfs_plm_write_clean(file);
23526 + goto out_success;
23527 + } else if (unlikely(strncmp("si=", buf, 3)))
23530 + err = kstrtoul(buf + 3, 16, &id);
23531 + if (unlikely(err))
23534 + err = au_procfs_plm_write_si(file, id);
23535 + if (unlikely(err))
23539 + err = count; /* success */
23544 +static const struct file_operations au_procfs_plm_fop = {
23545 + .write = au_procfs_plm_write,
23546 + .release = au_procfs_plm_release,
23547 + .owner = THIS_MODULE
23550 +/* ---------------------------------------------------------------------- */
23552 +static struct proc_dir_entry *au_procfs_dir;
23554 +void au_procfs_fin(void)
23556 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
23557 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
23560 +int __init au_procfs_init(void)
23563 + struct proc_dir_entry *entry;
23566 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
23567 + if (unlikely(!au_procfs_dir))
23570 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR,
23571 + au_procfs_dir, &au_procfs_plm_fop);
23572 + if (unlikely(!entry))
23576 + goto out; /* success */
23580 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
23584 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
23585 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
23586 +++ linux/fs/aufs/rdu.c 2014-06-24 00:14:06.786052822 +0200
23589 + * Copyright (C) 2005-2014 Junjiro R. Okajima
23591 + * This program, aufs is free software; you can redistribute it and/or modify
23592 + * it under the terms of the GNU General Public License as published by
23593 + * the Free Software Foundation; either version 2 of the License, or
23594 + * (at your option) any later version.
23596 + * This program is distributed in the hope that it will be useful,
23597 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23598 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23599 + * GNU General Public License for more details.
23601 + * You should have received a copy of the GNU General Public License
23602 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23606 + * readdir in userspace.
23609 +#include <linux/compat.h>
23610 +#include <linux/fs_stack.h>
23611 +#include <linux/security.h>
23614 +/* bits for struct aufs_rdu.flags */
23615 +#define AuRdu_CALLED 1
23616 +#define AuRdu_CONT (1 << 1)
23617 +#define AuRdu_FULL (1 << 2)
23618 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
23619 +#define au_fset_rdu(flags, name) \
23620 + do { (flags) |= AuRdu_##name; } while (0)
23621 +#define au_fclr_rdu(flags, name) \
23622 + do { (flags) &= ~AuRdu_##name; } while (0)
23624 +struct au_rdu_arg {
23625 + struct dir_context ctx;
23626 + struct aufs_rdu *rdu;
23627 + union au_rdu_ent_ul ent;
23628 + unsigned long end;
23630 + struct super_block *sb;
23634 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
23635 + loff_t offset, u64 h_ino, unsigned int d_type)
23638 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
23639 + struct aufs_rdu *rdu = arg->rdu;
23640 + struct au_rdu_ent ent;
23644 + au_fset_rdu(rdu->cookie.flags, CALLED);
23645 + len = au_rdu_len(nlen);
23646 + if (arg->ent.ul + len < arg->end) {
23648 + ent.bindex = rdu->cookie.bindex;
23649 + ent.type = d_type;
23651 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
23652 + ent.type = DT_UNKNOWN;
23654 + /* unnecessary to support mmap_sem since this is a dir */
23656 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
23658 + if (copy_to_user(arg->ent.e->name, name, nlen))
23660 + /* the terminating NULL */
23661 + if (__put_user(0, arg->ent.e->name + nlen))
23664 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
23665 + arg->ent.ul += len;
23669 + au_fset_rdu(rdu->cookie.flags, FULL);
23671 + rdu->tail = arg->ent;
23675 + /* AuTraceErr(err); */
23679 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
23683 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
23685 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
23686 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
23688 + if (unlikely(offset != cookie->h_pos))
23694 + au_fclr_rdu(cookie->flags, CALLED);
23696 + err = vfsub_iterate_dir(h_file, &arg->ctx);
23700 + && au_ftest_rdu(cookie->flags, CALLED)
23701 + && !au_ftest_rdu(cookie->flags, FULL));
23702 + cookie->h_pos = h_file->f_pos;
23709 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
23712 + aufs_bindex_t bend;
23713 + struct au_rdu_arg arg = {
23715 + .actor = au_diractor(au_rdu_fill)
23718 + struct dentry *dentry;
23719 + struct inode *inode;
23720 + struct file *h_file;
23721 + struct au_rdu_cookie *cookie = &rdu->cookie;
23723 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
23724 + if (unlikely(err)) {
23730 + rdu->tail = rdu->ent;
23733 + arg.ent = rdu->ent;
23734 + arg.end = arg.ent.ul;
23735 + arg.end += rdu->sz;
23738 + if (unlikely(!file->f_op->iterate))
23741 + err = security_file_permission(file, MAY_READ);
23743 + if (unlikely(err))
23746 + dentry = file->f_dentry;
23747 + inode = dentry->d_inode;
23749 + mutex_lock(&inode->i_mutex);
23751 + err = mutex_lock_killable(&inode->i_mutex);
23753 + if (unlikely(err))
23757 + arg.sb = inode->i_sb;
23758 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
23759 + if (unlikely(err))
23761 + err = au_alive_dir(dentry);
23762 + if (unlikely(err))
23764 + /* todo: reval? */
23765 + fi_read_lock(file);
23768 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
23769 + && cookie->generation != au_figen(file)))
23774 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
23776 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
23778 + bend = au_fbstart(file);
23779 + if (cookie->bindex < bend)
23780 + cookie->bindex = bend;
23781 + bend = au_fbend_dir(file);
23782 + /* AuDbg("b%d, b%d\n", cookie->bindex, bend); */
23783 + for (; !err && cookie->bindex <= bend;
23784 + cookie->bindex++, cookie->h_pos = 0) {
23785 + h_file = au_hf_dir(file, cookie->bindex);
23789 + au_fclr_rdu(cookie->flags, FULL);
23790 + err = au_rdu_do(h_file, &arg);
23792 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
23795 + AuDbg("rent %llu\n", rdu->rent);
23797 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
23798 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
23799 + au_fset_rdu(cookie->flags, CONT);
23800 + cookie->generation = au_figen(file);
23803 + ii_read_lock_child(inode);
23804 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibstart(inode)));
23805 + ii_read_unlock(inode);
23808 + fi_read_unlock(file);
23810 + si_read_unlock(arg.sb);
23812 + mutex_unlock(&inode->i_mutex);
23818 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
23822 + unsigned long long nent;
23823 + union au_rdu_ent_ul *u;
23824 + struct au_rdu_ent ent;
23825 + struct super_block *sb;
23828 + nent = rdu->nent;
23830 + sb = file->f_dentry->d_sb;
23831 + si_read_lock(sb, AuLock_FLUSH);
23832 + while (nent-- > 0) {
23833 + /* unnecessary to support mmap_sem since this is a dir */
23834 + err = copy_from_user(&ent, u->e, sizeof(ent));
23836 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
23837 + if (unlikely(err)) {
23843 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
23845 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
23847 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
23849 + if (unlikely(err)) {
23854 + err = __put_user(ino, &u->e->ino);
23855 + if (unlikely(err)) {
23860 + u->ul += au_rdu_len(ent.nlen);
23862 + si_read_unlock(sb);
23867 +/* ---------------------------------------------------------------------- */
23869 +static int au_rdu_verify(struct aufs_rdu *rdu)
23871 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
23872 + "%llu, b%d, 0x%x, g%u}\n",
23873 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
23875 + rdu->rent, rdu->shwh, rdu->full,
23876 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
23877 + rdu->cookie.generation);
23879 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
23883 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
23887 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
23890 + struct aufs_rdu rdu;
23891 + void __user *p = (void __user *)arg;
23893 + err = copy_from_user(&rdu, p, sizeof(rdu));
23894 + if (unlikely(err)) {
23899 + err = au_rdu_verify(&rdu);
23900 + if (unlikely(err))
23904 + case AUFS_CTL_RDU:
23905 + err = au_rdu(file, &rdu);
23906 + if (unlikely(err))
23909 + e = copy_to_user(p, &rdu, sizeof(rdu));
23910 + if (unlikely(e)) {
23915 + case AUFS_CTL_RDU_INO:
23916 + err = au_rdu_ino(file, &rdu);
23920 + /* err = -ENOTTY; */
23929 +#ifdef CONFIG_COMPAT
23930 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
23933 + struct aufs_rdu rdu;
23934 + void __user *p = compat_ptr(arg);
23936 + /* todo: get_user()? */
23937 + err = copy_from_user(&rdu, p, sizeof(rdu));
23938 + if (unlikely(err)) {
23943 + rdu.ent.e = compat_ptr(rdu.ent.ul);
23944 + err = au_rdu_verify(&rdu);
23945 + if (unlikely(err))
23949 + case AUFS_CTL_RDU:
23950 + err = au_rdu(file, &rdu);
23951 + if (unlikely(err))
23954 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
23955 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
23956 + e = copy_to_user(p, &rdu, sizeof(rdu));
23957 + if (unlikely(e)) {
23962 + case AUFS_CTL_RDU_INO:
23963 + err = au_rdu_ino(file, &rdu);
23967 + /* err = -ENOTTY; */
23976 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
23977 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
23978 +++ linux/fs/aufs/rwsem.h 2014-06-24 00:14:06.789386337 +0200
23981 + * Copyright (C) 2005-2014 Junjiro R. Okajima
23983 + * This program, aufs is free software; you can redistribute it and/or modify
23984 + * it under the terms of the GNU General Public License as published by
23985 + * the Free Software Foundation; either version 2 of the License, or
23986 + * (at your option) any later version.
23988 + * This program is distributed in the hope that it will be useful,
23989 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23990 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23991 + * GNU General Public License for more details.
23993 + * You should have received a copy of the GNU General Public License
23994 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23998 + * simple read-write semaphore wrappers
24001 +#ifndef __AUFS_RWSEM_H__
24002 +#define __AUFS_RWSEM_H__
24006 +#include "debug.h"
24009 + struct rw_semaphore rwsem;
24010 +#ifdef CONFIG_AUFS_DEBUG
24011 + /* just for debugging, not almighty counter */
24012 + atomic_t rcnt, wcnt;
24016 +#ifdef CONFIG_AUFS_DEBUG
24017 +#define AuDbgCntInit(rw) do { \
24018 + atomic_set(&(rw)->rcnt, 0); \
24019 + atomic_set(&(rw)->wcnt, 0); \
24020 + smp_mb(); /* atomic set */ \
24023 +#define AuDbgRcntInc(rw) atomic_inc(&(rw)->rcnt)
24024 +#define AuDbgRcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->rcnt) < 0)
24025 +#define AuDbgWcntInc(rw) atomic_inc(&(rw)->wcnt)
24026 +#define AuDbgWcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->wcnt) < 0)
24028 +#define AuDbgCntInit(rw) do {} while (0)
24029 +#define AuDbgRcntInc(rw) do {} while (0)
24030 +#define AuDbgRcntDec(rw) do {} while (0)
24031 +#define AuDbgWcntInc(rw) do {} while (0)
24032 +#define AuDbgWcntDec(rw) do {} while (0)
24033 +#endif /* CONFIG_AUFS_DEBUG */
24035 +/* to debug easier, do not make them inlined functions */
24036 +#define AuRwMustNoWaiters(rw) AuDebugOn(!list_empty(&(rw)->rwsem.wait_list))
24037 +/* rwsem_is_locked() is unusable */
24038 +#define AuRwMustReadLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0)
24039 +#define AuRwMustWriteLock(rw) AuDebugOn(atomic_read(&(rw)->wcnt) <= 0)
24040 +#define AuRwMustAnyLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0 \
24041 + && atomic_read(&(rw)->wcnt) <= 0)
24042 +#define AuRwDestroy(rw) AuDebugOn(atomic_read(&(rw)->rcnt) \
24043 + || atomic_read(&(rw)->wcnt))
24045 +#define au_rw_class(rw, key) lockdep_set_class(&(rw)->rwsem, key)
24047 +static inline void au_rw_init(struct au_rwsem *rw)
24049 + AuDbgCntInit(rw);
24050 + init_rwsem(&rw->rwsem);
24053 +static inline void au_rw_init_wlock(struct au_rwsem *rw)
24056 + down_write(&rw->rwsem);
24057 + AuDbgWcntInc(rw);
24060 +static inline void au_rw_init_wlock_nested(struct au_rwsem *rw,
24061 + unsigned int lsc)
24064 + down_write_nested(&rw->rwsem, lsc);
24065 + AuDbgWcntInc(rw);
24068 +static inline void au_rw_read_lock(struct au_rwsem *rw)
24070 + down_read(&rw->rwsem);
24071 + AuDbgRcntInc(rw);
24074 +static inline void au_rw_read_lock_nested(struct au_rwsem *rw, unsigned int lsc)
24076 + down_read_nested(&rw->rwsem, lsc);
24077 + AuDbgRcntInc(rw);
24080 +static inline void au_rw_read_unlock(struct au_rwsem *rw)
24082 + AuRwMustReadLock(rw);
24083 + AuDbgRcntDec(rw);
24084 + up_read(&rw->rwsem);
24087 +static inline void au_rw_dgrade_lock(struct au_rwsem *rw)
24089 + AuRwMustWriteLock(rw);
24090 + AuDbgRcntInc(rw);
24091 + AuDbgWcntDec(rw);
24092 + downgrade_write(&rw->rwsem);
24095 +static inline void au_rw_write_lock(struct au_rwsem *rw)
24097 + down_write(&rw->rwsem);
24098 + AuDbgWcntInc(rw);
24101 +static inline void au_rw_write_lock_nested(struct au_rwsem *rw,
24102 + unsigned int lsc)
24104 + down_write_nested(&rw->rwsem, lsc);
24105 + AuDbgWcntInc(rw);
24108 +static inline void au_rw_write_unlock(struct au_rwsem *rw)
24110 + AuRwMustWriteLock(rw);
24111 + AuDbgWcntDec(rw);
24112 + up_write(&rw->rwsem);
24115 +/* why is not _nested version defined */
24116 +static inline int au_rw_read_trylock(struct au_rwsem *rw)
24118 + int ret = down_read_trylock(&rw->rwsem);
24120 + AuDbgRcntInc(rw);
24124 +static inline int au_rw_write_trylock(struct au_rwsem *rw)
24126 + int ret = down_write_trylock(&rw->rwsem);
24128 + AuDbgWcntInc(rw);
24132 +#undef AuDbgCntInit
24133 +#undef AuDbgRcntInc
24134 +#undef AuDbgRcntDec
24135 +#undef AuDbgWcntInc
24136 +#undef AuDbgWcntDec
24138 +#define AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
24139 +static inline void prefix##_read_lock(param) \
24140 +{ au_rw_read_lock(rwsem); } \
24141 +static inline void prefix##_write_lock(param) \
24142 +{ au_rw_write_lock(rwsem); } \
24143 +static inline int prefix##_read_trylock(param) \
24144 +{ return au_rw_read_trylock(rwsem); } \
24145 +static inline int prefix##_write_trylock(param) \
24146 +{ return au_rw_write_trylock(rwsem); }
24147 +/* why is not _nested version defined */
24148 +/* static inline void prefix##_read_trylock_nested(param, lsc)
24149 +{ au_rw_read_trylock_nested(rwsem, lsc)); }
24150 +static inline void prefix##_write_trylock_nestd(param, lsc)
24151 +{ au_rw_write_trylock_nested(rwsem, lsc); } */
24153 +#define AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) \
24154 +static inline void prefix##_read_unlock(param) \
24155 +{ au_rw_read_unlock(rwsem); } \
24156 +static inline void prefix##_write_unlock(param) \
24157 +{ au_rw_write_unlock(rwsem); } \
24158 +static inline void prefix##_downgrade_lock(param) \
24159 +{ au_rw_dgrade_lock(rwsem); }
24161 +#define AuSimpleRwsemFuncs(prefix, param, rwsem) \
24162 + AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
24163 + AuSimpleUnlockRwsemFuncs(prefix, param, rwsem)
24165 +#endif /* __KERNEL__ */
24166 +#endif /* __AUFS_RWSEM_H__ */
24167 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
24168 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
24169 +++ linux/fs/aufs/sbinfo.c 2014-06-24 00:14:06.789386337 +0200
24172 + * Copyright (C) 2005-2014 Junjiro R. Okajima
24174 + * This program, aufs is free software; you can redistribute it and/or modify
24175 + * it under the terms of the GNU General Public License as published by
24176 + * the Free Software Foundation; either version 2 of the License, or
24177 + * (at your option) any later version.
24179 + * This program is distributed in the hope that it will be useful,
24180 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24181 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24182 + * GNU General Public License for more details.
24184 + * You should have received a copy of the GNU General Public License
24185 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24189 + * superblock private data
24195 + * they are necessary regardless sysfs is disabled.
24197 +void au_si_free(struct kobject *kobj)
24200 + struct au_sbinfo *sbinfo;
24201 + char *locked __maybe_unused; /* debug only */
24203 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
24204 + for (i = 0; i < AuPlink_NHASH; i++)
24205 + AuDebugOn(!hlist_empty(&sbinfo->si_plink[i].head));
24206 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
24208 + au_rw_write_lock(&sbinfo->si_rwsem);
24209 + au_br_free(sbinfo);
24210 + au_rw_write_unlock(&sbinfo->si_rwsem);
24212 + AuDebugOn(radix_tree_gang_lookup
24213 + (&sbinfo->au_si_pid.tree, (void **)&locked,
24214 + /*first_index*/PID_MAX_DEFAULT - 1,
24215 + /*max_items*/sizeof(locked)/sizeof(*locked)));
24217 + kfree(sbinfo->si_branch);
24218 + kfree(sbinfo->au_si_pid.bitmap);
24219 + mutex_destroy(&sbinfo->si_xib_mtx);
24220 + AuRwDestroy(&sbinfo->si_rwsem);
24225 +int au_si_alloc(struct super_block *sb)
24228 + struct au_sbinfo *sbinfo;
24229 + static struct lock_class_key aufs_si;
24232 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
24233 + if (unlikely(!sbinfo))
24236 + BUILD_BUG_ON(sizeof(unsigned long) !=
24237 + sizeof(*sbinfo->au_si_pid.bitmap));
24238 + sbinfo->au_si_pid.bitmap = kcalloc(BITS_TO_LONGS(PID_MAX_DEFAULT),
24239 + sizeof(*sbinfo->au_si_pid.bitmap),
24241 + if (unlikely(!sbinfo->au_si_pid.bitmap))
24244 + /* will be reallocated separately */
24245 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
24246 + if (unlikely(!sbinfo->si_branch))
24249 + err = sysaufs_si_init(sbinfo);
24250 + if (unlikely(err))
24253 + au_nwt_init(&sbinfo->si_nowait);
24254 + au_rw_init_wlock(&sbinfo->si_rwsem);
24255 + au_rw_class(&sbinfo->si_rwsem, &aufs_si);
24256 + spin_lock_init(&sbinfo->au_si_pid.tree_lock);
24257 + INIT_RADIX_TREE(&sbinfo->au_si_pid.tree, GFP_ATOMIC | __GFP_NOFAIL);
24259 + atomic_long_set(&sbinfo->si_ninodes, 0);
24260 + atomic_long_set(&sbinfo->si_nfiles, 0);
24262 + sbinfo->si_bend = -1;
24263 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
24265 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
24266 + sbinfo->si_wbr_create = AuWbrCreate_Def;
24267 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
24268 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
24270 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
24272 + sbinfo->si_xino_jiffy = jiffies;
24273 + sbinfo->si_xino_expire
24274 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
24275 + mutex_init(&sbinfo->si_xib_mtx);
24276 + sbinfo->si_xino_brid = -1;
24277 + /* leave si_xib_last_pindex and si_xib_next_bit */
24279 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
24280 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
24281 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
24282 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
24284 + for (i = 0; i < AuPlink_NHASH; i++)
24285 + au_sphl_init(sbinfo->si_plink + i);
24286 + init_waitqueue_head(&sbinfo->si_plink_wq);
24287 + spin_lock_init(&sbinfo->si_plink_maint_lock);
24289 + au_sphl_init(&sbinfo->si_files);
24291 + /* leave other members for sysaufs and si_mnt. */
24292 + sbinfo->si_sb = sb;
24293 + sb->s_fs_info = sbinfo;
24295 + au_debug_sbinfo_init(sbinfo);
24296 + return 0; /* success */
24299 + kfree(sbinfo->si_branch);
24301 + kfree(sbinfo->au_si_pid.bitmap);
24308 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr)
24311 + struct au_branch **brp;
24313 + AuRwMustWriteLock(&sbinfo->si_rwsem);
24316 + sz = sizeof(*brp) * (sbinfo->si_bend + 1);
24317 + if (unlikely(!sz))
24318 + sz = sizeof(*brp);
24319 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS);
24321 + sbinfo->si_branch = brp;
24328 +/* ---------------------------------------------------------------------- */
24330 +unsigned int au_sigen_inc(struct super_block *sb)
24332 + unsigned int gen;
24334 + SiMustWriteLock(sb);
24336 + gen = ++au_sbi(sb)->si_generation;
24337 + au_update_digen(sb->s_root);
24338 + au_update_iigen(sb->s_root->d_inode, /*half*/0);
24339 + sb->s_root->d_inode->i_version++;
24343 +aufs_bindex_t au_new_br_id(struct super_block *sb)
24345 + aufs_bindex_t br_id;
24347 + struct au_sbinfo *sbinfo;
24349 + SiMustWriteLock(sb);
24351 + sbinfo = au_sbi(sb);
24352 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
24353 + br_id = ++sbinfo->si_last_br_id;
24354 + AuDebugOn(br_id < 0);
24355 + if (br_id && au_br_index(sb, br_id) < 0)
24362 +/* ---------------------------------------------------------------------- */
24364 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
24365 +int si_read_lock(struct super_block *sb, int flags)
24370 + if (au_ftest_lock(flags, FLUSH))
24371 + au_nwt_flush(&au_sbi(sb)->si_nowait);
24373 + si_noflush_read_lock(sb);
24374 + err = au_plink_maint(sb, flags);
24375 + if (unlikely(err))
24376 + si_read_unlock(sb);
24381 +int si_write_lock(struct super_block *sb, int flags)
24385 + if (au_ftest_lock(flags, FLUSH))
24386 + au_nwt_flush(&au_sbi(sb)->si_nowait);
24388 + si_noflush_write_lock(sb);
24389 + err = au_plink_maint(sb, flags);
24390 + if (unlikely(err))
24391 + si_write_unlock(sb);
24396 +/* dentry and super_block lock. call at entry point */
24397 +int aufs_read_lock(struct dentry *dentry, int flags)
24400 + struct super_block *sb;
24402 + sb = dentry->d_sb;
24403 + err = si_read_lock(sb, flags);
24404 + if (unlikely(err))
24407 + if (au_ftest_lock(flags, DW))
24408 + di_write_lock_child(dentry);
24410 + di_read_lock_child(dentry, flags);
24412 + if (au_ftest_lock(flags, GEN)) {
24413 + err = au_digen_test(dentry, au_sigen(sb));
24414 + AuDebugOn(!err && au_dbrange_test(dentry));
24415 + if (unlikely(err))
24416 + aufs_read_unlock(dentry, flags);
24423 +void aufs_read_unlock(struct dentry *dentry, int flags)
24425 + if (au_ftest_lock(flags, DW))
24426 + di_write_unlock(dentry);
24428 + di_read_unlock(dentry, flags);
24429 + si_read_unlock(dentry->d_sb);
24432 +void aufs_write_lock(struct dentry *dentry)
24434 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
24435 + di_write_lock_child(dentry);
24438 +void aufs_write_unlock(struct dentry *dentry)
24440 + di_write_unlock(dentry);
24441 + si_write_unlock(dentry->d_sb);
24444 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
24447 + unsigned int sigen;
24448 + struct super_block *sb;
24451 + err = si_read_lock(sb, flags);
24452 + if (unlikely(err))
24455 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIR));
24457 + if (au_ftest_lock(flags, GEN)) {
24458 + sigen = au_sigen(sb);
24459 + err = au_digen_test(d1, sigen);
24460 + AuDebugOn(!err && au_dbrange_test(d1));
24462 + err = au_digen_test(d2, sigen);
24463 + AuDebugOn(!err && au_dbrange_test(d2));
24465 + if (unlikely(err))
24466 + aufs_read_and_write_unlock2(d1, d2);
24473 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
24475 + di_write_unlock2(d1, d2);
24476 + si_read_unlock(d1->d_sb);
24479 +/* ---------------------------------------------------------------------- */
24481 +int si_pid_test_slow(struct super_block *sb)
24486 + p = radix_tree_lookup(&au_sbi(sb)->au_si_pid.tree, current->pid);
24487 + rcu_read_unlock();
24489 + return (long)!!p;
24492 +void si_pid_set_slow(struct super_block *sb)
24495 + struct au_sbinfo *sbinfo;
24497 + AuDebugOn(si_pid_test_slow(sb));
24499 + sbinfo = au_sbi(sb);
24500 + err = radix_tree_preload(GFP_NOFS | __GFP_NOFAIL);
24502 + spin_lock(&sbinfo->au_si_pid.tree_lock);
24503 + err = radix_tree_insert(&sbinfo->au_si_pid.tree, current->pid,
24504 + /*any valid ptr*/sb);
24505 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
24507 + radix_tree_preload_end();
24510 +void si_pid_clr_slow(struct super_block *sb)
24513 + struct au_sbinfo *sbinfo;
24515 + AuDebugOn(!si_pid_test_slow(sb));
24517 + sbinfo = au_sbi(sb);
24518 + spin_lock(&sbinfo->au_si_pid.tree_lock);
24519 + p = radix_tree_delete(&sbinfo->au_si_pid.tree, current->pid);
24520 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
24522 diff -urN /usr/share/empty/fs/aufs/spl.h linux/fs/aufs/spl.h
24523 --- /usr/share/empty/fs/aufs/spl.h 1970-01-01 01:00:00.000000000 +0100
24524 +++ linux/fs/aufs/spl.h 2014-06-24 00:14:06.789386337 +0200
24527 + * Copyright (C) 2005-2014 Junjiro R. Okajima
24529 + * This program, aufs is free software; you can redistribute it and/or modify
24530 + * it under the terms of the GNU General Public License as published by
24531 + * the Free Software Foundation; either version 2 of the License, or
24532 + * (at your option) any later version.
24534 + * This program is distributed in the hope that it will be useful,
24535 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24536 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24537 + * GNU General Public License for more details.
24539 + * You should have received a copy of the GNU General Public License
24540 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24544 + * simple list protected by a spinlock
24547 +#ifndef __AUFS_SPL_H__
24548 +#define __AUFS_SPL_H__
24552 +struct au_splhead {
24554 + struct list_head head;
24557 +static inline void au_spl_init(struct au_splhead *spl)
24559 + spin_lock_init(&spl->spin);
24560 + INIT_LIST_HEAD(&spl->head);
24563 +static inline void au_spl_add(struct list_head *list, struct au_splhead *spl)
24565 + spin_lock(&spl->spin);
24566 + list_add(list, &spl->head);
24567 + spin_unlock(&spl->spin);
24570 +static inline void au_spl_del(struct list_head *list, struct au_splhead *spl)
24572 + spin_lock(&spl->spin);
24574 + spin_unlock(&spl->spin);
24577 +static inline void au_spl_del_rcu(struct list_head *list,
24578 + struct au_splhead *spl)
24580 + spin_lock(&spl->spin);
24581 + list_del_rcu(list);
24582 + spin_unlock(&spl->spin);
24585 +/* ---------------------------------------------------------------------- */
24587 +struct au_sphlhead {
24589 + struct hlist_head head;
24592 +static inline void au_sphl_init(struct au_sphlhead *sphl)
24594 + spin_lock_init(&sphl->spin);
24595 + INIT_HLIST_HEAD(&sphl->head);
24598 +static inline void au_sphl_add(struct hlist_node *hlist,
24599 + struct au_sphlhead *sphl)
24601 + spin_lock(&sphl->spin);
24602 + hlist_add_head(hlist, &sphl->head);
24603 + spin_unlock(&sphl->spin);
24606 +static inline void au_sphl_del(struct hlist_node *hlist,
24607 + struct au_sphlhead *sphl)
24609 + spin_lock(&sphl->spin);
24610 + hlist_del(hlist);
24611 + spin_unlock(&sphl->spin);
24614 +static inline void au_sphl_del_rcu(struct hlist_node *hlist,
24615 + struct au_sphlhead *sphl)
24617 + spin_lock(&sphl->spin);
24618 + hlist_del_rcu(hlist);
24619 + spin_unlock(&sphl->spin);
24622 +static inline unsigned long au_sphl_count(struct au_sphlhead *sphl)
24624 + unsigned long cnt;
24625 + struct hlist_node *pos;
24628 + spin_lock(&sphl->spin);
24629 + hlist_for_each(pos, &sphl->head)
24631 + spin_unlock(&sphl->spin);
24635 +#endif /* __KERNEL__ */
24636 +#endif /* __AUFS_SPL_H__ */
24637 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
24638 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
24639 +++ linux/fs/aufs/super.c 2014-06-24 00:14:06.789386337 +0200
24642 + * Copyright (C) 2005-2014 Junjiro R. Okajima
24644 + * This program, aufs is free software; you can redistribute it and/or modify
24645 + * it under the terms of the GNU General Public License as published by
24646 + * the Free Software Foundation; either version 2 of the License, or
24647 + * (at your option) any later version.
24649 + * This program is distributed in the hope that it will be useful,
24650 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24651 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24652 + * GNU General Public License for more details.
24654 + * You should have received a copy of the GNU General Public License
24655 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24659 + * mount and super_block operations
24662 +#include <linux/mm.h>
24663 +#include <linux/module.h>
24664 +#include <linux/seq_file.h>
24665 +#include <linux/statfs.h>
24666 +#include <linux/vmalloc.h>
24667 +#include <linux/writeback.h>
24671 + * super_operations
24673 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
24675 + struct au_icntnr *c;
24677 + c = au_cache_alloc_icntnr();
24679 + au_icntnr_init(c);
24680 + c->vfs_inode.i_version = 1; /* sigen(sb); */
24681 + c->iinfo.ii_hinode = NULL;
24682 + return &c->vfs_inode;
24687 +static void aufs_destroy_inode_cb(struct rcu_head *head)
24689 + struct inode *inode = container_of(head, struct inode, i_rcu);
24691 + INIT_HLIST_HEAD(&inode->i_dentry);
24692 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
24695 +static void aufs_destroy_inode(struct inode *inode)
24697 + au_iinfo_fin(inode);
24698 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
24701 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
24703 + struct inode *inode;
24706 + inode = iget_locked(sb, ino);
24707 + if (unlikely(!inode)) {
24708 + inode = ERR_PTR(-ENOMEM);
24711 + if (!(inode->i_state & I_NEW))
24714 + err = au_xigen_new(inode);
24716 + err = au_iinfo_init(inode);
24718 + inode->i_version++;
24720 + iget_failed(inode);
24721 + inode = ERR_PTR(err);
24725 + /* never return NULL */
24726 + AuDebugOn(!inode);
24727 + AuTraceErrPtr(inode);
24731 +/* lock free root dinfo */
24732 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
24735 + aufs_bindex_t bindex, bend;
24736 + struct path path;
24737 + struct au_hdentry *hdp;
24738 + struct au_branch *br;
24742 + bend = au_sbend(sb);
24743 + hdp = au_di(sb->s_root)->di_hdentry;
24744 + for (bindex = 0; !err && bindex <= bend; bindex++) {
24745 + br = au_sbr(sb, bindex);
24746 + path.mnt = au_br_mnt(br);
24747 + path.dentry = hdp[bindex].hd_dentry;
24748 + err = au_seq_path(seq, &path);
24750 + perm = au_optstr_br_perm(br->br_perm);
24752 + err = seq_printf(seq, "=%s", perm);
24759 + if (!err && bindex != bend)
24760 + err = seq_putc(seq, ':');
24766 +static void au_show_wbr_create(struct seq_file *m, int v,
24767 + struct au_sbinfo *sbinfo)
24771 + AuRwMustAnyLock(&sbinfo->si_rwsem);
24773 + seq_puts(m, ",create=");
24774 + pat = au_optstr_wbr_create(v);
24776 + case AuWbrCreate_TDP:
24777 + case AuWbrCreate_RR:
24778 + case AuWbrCreate_MFS:
24779 + case AuWbrCreate_PMFS:
24780 + seq_puts(m, pat);
24782 + case AuWbrCreate_MFSV:
24783 + seq_printf(m, /*pat*/"mfs:%lu",
24784 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
24787 + case AuWbrCreate_PMFSV:
24788 + seq_printf(m, /*pat*/"pmfs:%lu",
24789 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
24792 + case AuWbrCreate_MFSRR:
24793 + seq_printf(m, /*pat*/"mfsrr:%llu",
24794 + sbinfo->si_wbr_mfs.mfsrr_watermark);
24796 + case AuWbrCreate_MFSRRV:
24797 + seq_printf(m, /*pat*/"mfsrr:%llu:%lu",
24798 + sbinfo->si_wbr_mfs.mfsrr_watermark,
24799 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
24802 + case AuWbrCreate_PMFSRR:
24803 + seq_printf(m, /*pat*/"pmfsrr:%llu",
24804 + sbinfo->si_wbr_mfs.mfsrr_watermark);
24806 + case AuWbrCreate_PMFSRRV:
24807 + seq_printf(m, /*pat*/"pmfsrr:%llu:%lu",
24808 + sbinfo->si_wbr_mfs.mfsrr_watermark,
24809 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
24815 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
24817 +#ifdef CONFIG_SYSFS
24821 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
24822 + aufs_bindex_t bindex, brid;
24823 + struct qstr *name;
24825 + struct dentry *d, *h_root;
24826 + struct au_hdentry *hdp;
24828 + AuRwMustAnyLock(&sbinfo->si_rwsem);
24831 + f = au_sbi(sb)->si_xib;
24835 + /* stop printing the default xino path on the first writable branch */
24837 + brid = au_xino_brid(sb);
24839 + bindex = au_br_index(sb, brid);
24840 + hdp = au_di(sb->s_root)->di_hdentry;
24841 + h_root = hdp[0 + bindex].hd_dentry;
24844 + name = &d->d_name;
24845 + /* safe ->d_parent because the file is unlinked */
24846 + if (d->d_parent == h_root
24847 + && name->len == len
24848 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
24851 + seq_puts(seq, ",xino=");
24852 + err = au_xino_path(seq, f);
24859 +/* seq_file will re-call me in case of too long string */
24860 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
24863 + unsigned int mnt_flags, v;
24864 + struct super_block *sb;
24865 + struct au_sbinfo *sbinfo;
24867 +#define AuBool(name, str) do { \
24868 + v = au_opt_test(mnt_flags, name); \
24869 + if (v != au_opt_test(AuOpt_Def, name)) \
24870 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
24873 +#define AuStr(name, str) do { \
24874 + v = mnt_flags & AuOptMask_##name; \
24875 + if (v != (AuOpt_Def & AuOptMask_##name)) \
24876 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
24879 +#define AuUInt(name, str, val) do { \
24880 + if (val != AUFS_##name##_DEF) \
24881 + seq_printf(m, "," #str "=%u", val); \
24884 + /* lock free root dinfo */
24885 + sb = dentry->d_sb;
24886 + si_noflush_read_lock(sb);
24887 + sbinfo = au_sbi(sb);
24888 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
24890 + mnt_flags = au_mntflags(sb);
24891 + if (au_opt_test(mnt_flags, XINO)) {
24892 + err = au_show_xino(m, sb);
24893 + if (unlikely(err))
24896 + seq_puts(m, ",noxino");
24898 + AuBool(TRUNC_XINO, trunc_xino);
24899 + AuStr(UDBA, udba);
24900 + AuBool(SHWH, shwh);
24901 + AuBool(PLINK, plink);
24902 + AuBool(DIO, dio);
24903 + /* AuBool(DIRPERM1, dirperm1); */
24904 + /* AuBool(REFROF, refrof); */
24906 + v = sbinfo->si_wbr_create;
24907 + if (v != AuWbrCreate_Def)
24908 + au_show_wbr_create(m, v, sbinfo);
24910 + v = sbinfo->si_wbr_copyup;
24911 + if (v != AuWbrCopyup_Def)
24912 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
24914 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
24915 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
24916 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
24918 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
24920 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
24921 + AuUInt(RDCACHE, rdcache, v);
24923 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
24924 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
24926 + AuBool(SUM, sum);
24927 + /* AuBool(SUM_W, wsum); */
24928 + AuBool(WARN_PERM, warn_perm);
24929 + AuBool(VERBOSE, verbose);
24932 + /* be sure to print "br:" last */
24933 + if (!sysaufs_brs) {
24934 + seq_puts(m, ",br:");
24935 + au_show_brs(m, sb);
24937 + si_read_unlock(sb);
24945 +/* ---------------------------------------------------------------------- */
24947 +/* sum mode which returns the summation for statfs(2) */
24949 +static u64 au_add_till_max(u64 a, u64 b)
24957 + return ULLONG_MAX;
24960 +static u64 au_mul_till_max(u64 a, long mul)
24968 + return ULLONG_MAX;
24971 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
24974 + long bsize, factor;
24975 + u64 blocks, bfree, bavail, files, ffree;
24976 + aufs_bindex_t bend, bindex, i;
24977 + unsigned char shared;
24978 + struct path h_path;
24979 + struct super_block *h_sb;
24982 + bsize = LONG_MAX;
24988 + bend = au_sbend(sb);
24989 + for (bindex = 0; bindex <= bend; bindex++) {
24990 + h_path.mnt = au_sbr_mnt(sb, bindex);
24991 + h_sb = h_path.mnt->mnt_sb;
24993 + for (i = 0; !shared && i < bindex; i++)
24994 + shared = (au_sbr_sb(sb, i) == h_sb);
24998 + /* sb->s_root for NFS is unreliable */
24999 + h_path.dentry = h_path.mnt->mnt_root;
25000 + err = vfs_statfs(&h_path, buf);
25001 + if (unlikely(err))
25004 + if (bsize > buf->f_bsize) {
25006 + * we will reduce bsize, so we have to expand blocks
25007 + * etc. to match them again
25009 + factor = (bsize / buf->f_bsize);
25010 + blocks = au_mul_till_max(blocks, factor);
25011 + bfree = au_mul_till_max(bfree, factor);
25012 + bavail = au_mul_till_max(bavail, factor);
25013 + bsize = buf->f_bsize;
25016 + factor = (buf->f_bsize / bsize);
25017 + blocks = au_add_till_max(blocks,
25018 + au_mul_till_max(buf->f_blocks, factor));
25019 + bfree = au_add_till_max(bfree,
25020 + au_mul_till_max(buf->f_bfree, factor));
25021 + bavail = au_add_till_max(bavail,
25022 + au_mul_till_max(buf->f_bavail, factor));
25023 + files = au_add_till_max(files, buf->f_files);
25024 + ffree = au_add_till_max(ffree, buf->f_ffree);
25027 + buf->f_bsize = bsize;
25028 + buf->f_blocks = blocks;
25029 + buf->f_bfree = bfree;
25030 + buf->f_bavail = bavail;
25031 + buf->f_files = files;
25032 + buf->f_ffree = ffree;
25033 + buf->f_frsize = 0;
25039 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
25042 + struct path h_path;
25043 + struct super_block *sb;
25045 + /* lock free root dinfo */
25046 + sb = dentry->d_sb;
25047 + si_noflush_read_lock(sb);
25048 + if (!au_opt_test(au_mntflags(sb), SUM)) {
25049 + /* sb->s_root for NFS is unreliable */
25050 + h_path.mnt = au_sbr_mnt(sb, 0);
25051 + h_path.dentry = h_path.mnt->mnt_root;
25052 + err = vfs_statfs(&h_path, buf);
25054 + err = au_statfs_sum(sb, buf);
25055 + si_read_unlock(sb);
25058 + buf->f_type = AUFS_SUPER_MAGIC;
25059 + buf->f_namelen = AUFS_MAX_NAMELEN;
25060 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
25062 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
25067 +/* ---------------------------------------------------------------------- */
25069 +static int aufs_sync_fs(struct super_block *sb, int wait)
25072 + aufs_bindex_t bend, bindex;
25073 + struct au_branch *br;
25074 + struct super_block *h_sb;
25077 + si_noflush_read_lock(sb);
25078 + bend = au_sbend(sb);
25079 + for (bindex = 0; bindex <= bend; bindex++) {
25080 + br = au_sbr(sb, bindex);
25081 + if (!au_br_writable(br->br_perm))
25084 + h_sb = au_sbr_sb(sb, bindex);
25085 + if (h_sb->s_op->sync_fs) {
25086 + e = h_sb->s_op->sync_fs(h_sb, wait);
25087 + if (unlikely(e && !err))
25089 + /* go on even if an error happens */
25092 + si_read_unlock(sb);
25097 +/* ---------------------------------------------------------------------- */
25099 +/* final actions when unmounting a file system */
25100 +static void aufs_put_super(struct super_block *sb)
25102 + struct au_sbinfo *sbinfo;
25104 + sbinfo = au_sbi(sb);
25108 + dbgaufs_si_fin(sbinfo);
25109 + kobject_put(&sbinfo->si_kobj);
25112 +/* ---------------------------------------------------------------------- */
25114 +void au_array_free(void *array)
25117 + if (!is_vmalloc_addr(array))
25124 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg)
25127 + unsigned long long n;
25134 + if (*hint > ULLONG_MAX / sizeof(array)) {
25135 + array = ERR_PTR(-EMFILE);
25136 + pr_err("hint %llu\n", *hint);
25140 + array = kmalloc(sizeof(array) * *hint, GFP_NOFS);
25141 + if (unlikely(!array))
25142 + array = vmalloc(sizeof(array) * *hint);
25143 + if (unlikely(!array)) {
25144 + array = ERR_PTR(-ENOMEM);
25148 + n = cb(array, *hint, arg);
25149 + AuDebugOn(n > *hint);
25156 +static unsigned long long au_iarray_cb(void *a,
25157 + unsigned long long max __maybe_unused,
25160 + unsigned long long n;
25161 + struct inode **p, *inode;
25162 + struct list_head *head;
25167 + spin_lock(&inode_sb_list_lock);
25168 + list_for_each_entry(inode, head, i_sb_list) {
25169 + if (!is_bad_inode(inode)
25170 + && au_ii(inode)->ii_bstart >= 0) {
25171 + spin_lock(&inode->i_lock);
25172 + if (atomic_read(&inode->i_count)) {
25176 + AuDebugOn(n > max);
25178 + spin_unlock(&inode->i_lock);
25181 + spin_unlock(&inode_sb_list_lock);
25186 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
25188 + *max = atomic_long_read(&au_sbi(sb)->si_ninodes);
25189 + return au_array_alloc(max, au_iarray_cb, &sb->s_inodes);
25192 +void au_iarray_free(struct inode **a, unsigned long long max)
25194 + unsigned long long ull;
25196 + for (ull = 0; ull < max; ull++)
25198 + au_array_free(a);
25201 +/* ---------------------------------------------------------------------- */
25204 + * refresh dentry and inode at remount time.
25206 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
25207 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
25208 + struct dentry *parent)
25212 + di_write_lock_child(dentry);
25213 + di_read_lock_parent(parent, AuLock_IR);
25214 + err = au_refresh_dentry(dentry, parent);
25215 + if (!err && dir_flags)
25216 + au_hn_reset(dentry->d_inode, dir_flags);
25217 + di_read_unlock(parent, AuLock_IR);
25218 + di_write_unlock(dentry);
25223 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
25224 + struct au_sbinfo *sbinfo,
25225 + const unsigned int dir_flags)
25228 + struct dentry *parent;
25229 + struct inode *inode;
25232 + parent = dget_parent(dentry);
25233 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
25234 + inode = dentry->d_inode;
25236 + if (!S_ISDIR(inode->i_mode))
25237 + err = au_do_refresh(dentry, /*dir_flags*/0,
25240 + err = au_do_refresh(dentry, dir_flags, parent);
25241 + if (unlikely(err))
25242 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
25245 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
25246 + AuDbgDentry(dentry);
25254 +static int au_refresh_d(struct super_block *sb)
25256 + int err, i, j, ndentry, e;
25257 + unsigned int sigen;
25258 + struct au_dcsub_pages dpages;
25259 + struct au_dpage *dpage;
25260 + struct dentry **dentries, *d;
25261 + struct au_sbinfo *sbinfo;
25262 + struct dentry *root = sb->s_root;
25263 + const unsigned int dir_flags = au_hi_flags(root->d_inode, /*isdir*/1);
25265 + err = au_dpages_init(&dpages, GFP_NOFS);
25266 + if (unlikely(err))
25268 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
25269 + if (unlikely(err))
25272 + sigen = au_sigen(sb);
25273 + sbinfo = au_sbi(sb);
25274 + for (i = 0; i < dpages.ndpage; i++) {
25275 + dpage = dpages.dpages + i;
25276 + dentries = dpage->dentries;
25277 + ndentry = dpage->ndentry;
25278 + for (j = 0; j < ndentry; j++) {
25280 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags);
25281 + if (unlikely(e && !err))
25283 + /* go on even err */
25288 + au_dpages_free(&dpages);
25293 +static int au_refresh_i(struct super_block *sb)
25296 + unsigned int sigen;
25297 + unsigned long long max, ull;
25298 + struct inode *inode, **array;
25300 + array = au_iarray_alloc(sb, &max);
25301 + err = PTR_ERR(array);
25302 + if (IS_ERR(array))
25306 + sigen = au_sigen(sb);
25307 + for (ull = 0; ull < max; ull++) {
25308 + inode = array[ull];
25309 + if (au_iigen(inode, NULL) != sigen) {
25310 + ii_write_lock_child(inode);
25311 + e = au_refresh_hinode_self(inode);
25312 + ii_write_unlock(inode);
25313 + if (unlikely(e)) {
25314 + pr_err("error %d, i%lu\n", e, inode->i_ino);
25317 + /* go on even if err */
25322 + au_iarray_free(array, max);
25328 +static void au_remount_refresh(struct super_block *sb)
25331 + unsigned int udba;
25332 + aufs_bindex_t bindex, bend;
25333 + struct dentry *root;
25334 + struct inode *inode;
25335 + struct au_branch *br;
25337 + au_sigen_inc(sb);
25338 + au_fclr_si(au_sbi(sb), FAILED_REFRESH_DIR);
25340 + root = sb->s_root;
25341 + DiMustNoWaiters(root);
25342 + inode = root->d_inode;
25343 + IiMustNoWaiters(inode);
25345 + udba = au_opt_udba(sb);
25346 + bend = au_sbend(sb);
25347 + for (bindex = 0; bindex <= bend; bindex++) {
25348 + br = au_sbr(sb, bindex);
25349 + err = au_hnotify_reset_br(udba, br, br->br_perm);
25350 + if (unlikely(err))
25351 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
25353 + /* go on even if err */
25355 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
25357 + di_write_unlock(root);
25358 + err = au_refresh_d(sb);
25359 + e = au_refresh_i(sb);
25360 + if (unlikely(e && !err))
25362 + /* aufs_write_lock() calls ..._child() */
25363 + di_write_lock_child(root);
25365 + au_cpup_attr_all(inode, /*force*/1);
25367 + if (unlikely(err))
25368 + AuIOErr("refresh failed, ignored, %d\n", err);
25371 +/* stop extra interpretation of errno in mount(8), and strange error messages */
25372 +static int cvt_err(int err)
25386 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
25389 + unsigned int mntflags;
25390 + struct au_opts opts;
25391 + struct dentry *root;
25392 + struct inode *inode;
25393 + struct au_sbinfo *sbinfo;
25396 + root = sb->s_root;
25397 + if (!data || !*data) {
25398 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
25400 + di_write_lock_child(root);
25401 + err = au_opts_verify(sb, *flags, /*pending*/0);
25402 + aufs_write_unlock(root);
25408 + memset(&opts, 0, sizeof(opts));
25409 + opts.opt = (void *)__get_free_page(GFP_NOFS);
25410 + if (unlikely(!opts.opt))
25412 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
25413 + opts.flags = AuOpts_REMOUNT;
25414 + opts.sb_flags = *flags;
25416 + /* parse it before aufs lock */
25417 + err = au_opts_parse(sb, data, &opts);
25418 + if (unlikely(err))
25421 + sbinfo = au_sbi(sb);
25422 + inode = root->d_inode;
25423 + mutex_lock(&inode->i_mutex);
25424 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
25425 + if (unlikely(err))
25427 + di_write_lock_child(root);
25429 + /* au_opts_remount() may return an error */
25430 + err = au_opts_remount(sb, &opts);
25431 + au_opts_free(&opts);
25433 + if (au_ftest_opts(opts.flags, REFRESH))
25434 + au_remount_refresh(sb);
25436 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
25437 + mntflags = au_mntflags(sb);
25438 + do_dx = !!au_opt_test(mntflags, DIO);
25439 + au_dy_arefresh(do_dx);
25442 + aufs_write_unlock(root);
25445 + mutex_unlock(&inode->i_mutex);
25447 + free_page((unsigned long)opts.opt);
25449 + err = cvt_err(err);
25454 +static const struct super_operations aufs_sop = {
25455 + .alloc_inode = aufs_alloc_inode,
25456 + .destroy_inode = aufs_destroy_inode,
25457 + /* always deleting, no clearing */
25458 + .drop_inode = generic_delete_inode,
25459 + .show_options = aufs_show_options,
25460 + .statfs = aufs_statfs,
25461 + .put_super = aufs_put_super,
25462 + .sync_fs = aufs_sync_fs,
25463 + .remount_fs = aufs_remount_fs
25466 +/* ---------------------------------------------------------------------- */
25468 +static int alloc_root(struct super_block *sb)
25471 + struct inode *inode;
25472 + struct dentry *root;
25475 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
25476 + err = PTR_ERR(inode);
25477 + if (IS_ERR(inode))
25480 + inode->i_op = &aufs_dir_iop;
25481 + inode->i_fop = &aufs_dir_fop;
25482 + inode->i_mode = S_IFDIR;
25483 + set_nlink(inode, 2);
25484 + unlock_new_inode(inode);
25486 + root = d_make_root(inode);
25487 + if (unlikely(!root))
25489 + err = PTR_ERR(root);
25490 + if (IS_ERR(root))
25493 + err = au_di_init(root);
25495 + sb->s_root = root;
25496 + return 0; /* success */
25504 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
25505 + int silent __maybe_unused)
25508 + struct au_opts opts;
25509 + struct dentry *root;
25510 + struct inode *inode;
25511 + char *arg = raw_data;
25513 + if (unlikely(!arg || !*arg)) {
25515 + pr_err("no arg\n");
25520 + memset(&opts, 0, sizeof(opts));
25521 + opts.opt = (void *)__get_free_page(GFP_NOFS);
25522 + if (unlikely(!opts.opt))
25524 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
25525 + opts.sb_flags = sb->s_flags;
25527 + err = au_si_alloc(sb);
25528 + if (unlikely(err))
25531 + /* all timestamps always follow the ones on the branch */
25532 + sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
25533 + sb->s_op = &aufs_sop;
25534 + sb->s_d_op = &aufs_dop;
25535 + sb->s_magic = AUFS_SUPER_MAGIC;
25536 + sb->s_maxbytes = 0;
25537 + au_export_init(sb);
25539 + err = alloc_root(sb);
25540 + if (unlikely(err)) {
25541 + si_write_unlock(sb);
25544 + root = sb->s_root;
25545 + inode = root->d_inode;
25548 + * actually we can parse options regardless aufs lock here.
25549 + * but at remount time, parsing must be done before aufs lock.
25550 + * so we follow the same rule.
25552 + ii_write_lock_parent(inode);
25553 + aufs_write_unlock(root);
25554 + err = au_opts_parse(sb, arg, &opts);
25555 + if (unlikely(err))
25558 + /* lock vfs_inode first, then aufs. */
25559 + mutex_lock(&inode->i_mutex);
25560 + aufs_write_lock(root);
25561 + err = au_opts_mount(sb, &opts);
25562 + au_opts_free(&opts);
25563 + aufs_write_unlock(root);
25564 + mutex_unlock(&inode->i_mutex);
25566 + goto out_opts; /* success */
25570 + sb->s_root = NULL;
25572 + dbgaufs_si_fin(au_sbi(sb));
25573 + kobject_put(&au_sbi(sb)->si_kobj);
25574 + sb->s_fs_info = NULL;
25576 + free_page((unsigned long)opts.opt);
25579 + err = cvt_err(err);
25584 +/* ---------------------------------------------------------------------- */
25586 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
25587 + const char *dev_name __maybe_unused,
25590 + struct dentry *root;
25591 + struct super_block *sb;
25593 + /* all timestamps always follow the ones on the branch */
25594 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
25595 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
25596 + if (IS_ERR(root))
25600 + si_write_lock(sb, !AuLock_FLUSH);
25601 + sysaufs_brs_add(sb, 0);
25602 + si_write_unlock(sb);
25603 + au_sbilist_add(sb);
25609 +static void aufs_kill_sb(struct super_block *sb)
25611 + struct au_sbinfo *sbinfo;
25613 + sbinfo = au_sbi(sb);
25615 + au_sbilist_del(sb);
25616 + aufs_write_lock(sb->s_root);
25617 + if (sbinfo->si_wbr_create_ops->fin)
25618 + sbinfo->si_wbr_create_ops->fin(sb);
25619 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
25620 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
25621 + au_remount_refresh(sb);
25623 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
25624 + au_plink_put(sb, /*verbose*/1);
25626 + sbinfo->si_sb = NULL;
25627 + aufs_write_unlock(sb->s_root);
25628 + au_nwt_flush(&sbinfo->si_nowait);
25630 + kill_anon_super(sb);
25633 +struct file_system_type aufs_fs_type = {
25634 + .name = AUFS_FSTYPE,
25635 + /* a race between rename and others */
25636 + .fs_flags = FS_RENAME_DOES_D_MOVE,
25637 + .mount = aufs_mount,
25638 + .kill_sb = aufs_kill_sb,
25639 + /* no need to __module_get() and module_put(). */
25640 + .owner = THIS_MODULE,
25642 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
25643 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
25644 +++ linux/fs/aufs/super.h 2014-06-24 00:14:06.789386337 +0200
25647 + * Copyright (C) 2005-2014 Junjiro R. Okajima
25649 + * This program, aufs is free software; you can redistribute it and/or modify
25650 + * it under the terms of the GNU General Public License as published by
25651 + * the Free Software Foundation; either version 2 of the License, or
25652 + * (at your option) any later version.
25654 + * This program is distributed in the hope that it will be useful,
25655 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25656 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25657 + * GNU General Public License for more details.
25659 + * You should have received a copy of the GNU General Public License
25660 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25664 + * super_block operations
25667 +#ifndef __AUFS_SUPER_H__
25668 +#define __AUFS_SUPER_H__
25672 +#include <linux/fs.h>
25673 +#include "rwsem.h"
25677 +typedef ssize_t (*au_readf_t)(struct file *, char __user *, size_t, loff_t *);
25678 +typedef ssize_t (*au_writef_t)(struct file *, const char __user *, size_t,
25681 +/* policies to select one among multiple writable branches */
25682 +struct au_wbr_copyup_operations {
25683 + int (*copyup)(struct dentry *dentry);
25686 +#define AuWbr_DIR 1 /* target is a dir */
25687 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
25689 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
25690 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
25691 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
25693 +struct au_wbr_create_operations {
25694 + int (*create)(struct dentry *dentry, unsigned int flags);
25695 + int (*init)(struct super_block *sb);
25696 + int (*fin)(struct super_block *sb);
25699 +struct au_wbr_mfs {
25700 + struct mutex mfs_lock; /* protect this structure */
25701 + unsigned long mfs_jiffy;
25702 + unsigned long mfs_expire;
25703 + aufs_bindex_t mfs_bindex;
25705 + unsigned long long mfsrr_bytes;
25706 + unsigned long long mfsrr_watermark;
25709 +struct pseudo_link {
25711 + struct hlist_node hlist;
25712 + struct rcu_head rcu;
25714 + struct inode *inode;
25717 +#define AuPlink_NHASH 100
25718 +static inline int au_plink_hash(ino_t ino)
25720 + return ino % AuPlink_NHASH;
25724 +struct au_sbinfo {
25725 + /* nowait tasks in the system-wide workqueue */
25726 + struct au_nowait_tasks si_nowait;
25729 + * tried sb->s_umount, but failed due to the dependecy between i_mutex.
25730 + * rwsem for au_sbinfo is necessary.
25732 + struct au_rwsem si_rwsem;
25734 + /* prevent recursive locking in deleting inode */
25736 + unsigned long *bitmap;
25737 + spinlock_t tree_lock;
25738 + struct radix_tree_root tree;
25742 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
25745 + atomic_long_t si_ninodes, si_nfiles;
25747 + /* branch management */
25748 + unsigned int si_generation;
25750 + /* see above flags */
25751 + unsigned char au_si_status;
25753 + aufs_bindex_t si_bend;
25755 + /* dirty trick to keep br_id plus */
25756 + unsigned int si_last_br_id :
25757 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
25758 + struct au_branch **si_branch;
25760 + /* policy to select a writable branch */
25761 + unsigned char si_wbr_copyup;
25762 + unsigned char si_wbr_create;
25763 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
25764 + struct au_wbr_create_operations *si_wbr_create_ops;
25766 + /* round robin */
25767 + atomic_t si_wbr_rr_next;
25769 + /* most free space */
25770 + struct au_wbr_mfs si_wbr_mfs;
25772 + /* mount flags */
25773 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
25774 + unsigned int si_mntflags;
25776 + /* external inode number (bitmap and translation table) */
25777 + au_readf_t si_xread;
25778 + au_writef_t si_xwrite;
25779 + struct file *si_xib;
25780 + struct mutex si_xib_mtx; /* protect xib members */
25781 + unsigned long *si_xib_buf;
25782 + unsigned long si_xib_last_pindex;
25783 + int si_xib_next_bit;
25784 + aufs_bindex_t si_xino_brid;
25785 + unsigned long si_xino_jiffy;
25786 + unsigned long si_xino_expire;
25787 + /* reserved for future use */
25788 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
25790 +#ifdef CONFIG_AUFS_EXPORT
25791 + /* i_generation */
25792 + struct file *si_xigen;
25793 + atomic_t si_xigen_next;
25796 + /* vdir parameters */
25797 + unsigned long si_rdcache; /* max cache time in jiffies */
25798 + unsigned int si_rdblk; /* deblk size */
25799 + unsigned int si_rdhash; /* hash size */
25802 + * If the number of whiteouts are larger than si_dirwh, leave all of
25803 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
25804 + * future fsck.aufs or kernel thread will remove them later.
25805 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
25807 + unsigned int si_dirwh;
25810 + * rename(2) a directory with all children.
25812 + /* reserved for future use */
25813 + /* int si_rendir; */
25815 + /* pseudo_link list */
25816 + struct au_sphlhead si_plink[AuPlink_NHASH];
25817 + wait_queue_head_t si_plink_wq;
25818 + spinlock_t si_plink_maint_lock;
25819 + pid_t si_plink_maint_pid;
25822 + struct au_sphlhead si_files;
25825 + * sysfs and lifetime management.
25826 + * this is not a small structure and it may be a waste of memory in case
25827 + * of sysfs is disabled, particulary when many aufs-es are mounted.
25828 + * but using sysfs is majority.
25830 + struct kobject si_kobj;
25831 +#ifdef CONFIG_DEBUG_FS
25832 + struct dentry *si_dbgaufs;
25833 + struct dentry *si_dbgaufs_plink;
25834 + struct dentry *si_dbgaufs_xib;
25835 +#ifdef CONFIG_AUFS_EXPORT
25836 + struct dentry *si_dbgaufs_xigen;
25840 +#ifdef CONFIG_AUFS_SBILIST
25841 + struct list_head si_list;
25844 + /* dirty, necessary for unmounting, sysfs and sysrq */
25845 + struct super_block *si_sb;
25848 +/* sbinfo status flags */
25850 + * set true when refresh_dirs() failed at remount time.
25851 + * then try refreshing dirs at access time again.
25852 + * if it is false, refreshing dirs at access time is unnecesary
25854 +#define AuSi_FAILED_REFRESH_DIR 1
25855 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
25856 + unsigned int flag)
25858 + AuRwMustAnyLock(&sbi->si_rwsem);
25859 + return sbi->au_si_status & flag;
25861 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
25862 +#define au_fset_si(sbinfo, name) do { \
25863 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
25864 + (sbinfo)->au_si_status |= AuSi_##name; \
25866 +#define au_fclr_si(sbinfo, name) do { \
25867 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
25868 + (sbinfo)->au_si_status &= ~AuSi_##name; \
25871 +/* ---------------------------------------------------------------------- */
25873 +/* policy to select one among writable branches */
25874 +#define AuWbrCopyup(sbinfo, ...) \
25875 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
25876 +#define AuWbrCreate(sbinfo, ...) \
25877 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
25879 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
25880 +#define AuLock_DW 1 /* write-lock dentry */
25881 +#define AuLock_IR (1 << 1) /* read-lock inode */
25882 +#define AuLock_IW (1 << 2) /* write-lock inode */
25883 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
25884 +#define AuLock_DIR (1 << 4) /* target is a dir */
25885 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
25886 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
25887 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
25888 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
25889 +#define au_fset_lock(flags, name) \
25890 + do { (flags) |= AuLock_##name; } while (0)
25891 +#define au_fclr_lock(flags, name) \
25892 + do { (flags) &= ~AuLock_##name; } while (0)
25894 +/* ---------------------------------------------------------------------- */
25897 +extern struct file_system_type aufs_fs_type;
25898 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
25899 +typedef unsigned long long (*au_arraycb_t)(void *array, unsigned long long max,
25901 +void au_array_free(void *array);
25902 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg);
25903 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
25904 +void au_iarray_free(struct inode **a, unsigned long long max);
25907 +void au_si_free(struct kobject *kobj);
25908 +int au_si_alloc(struct super_block *sb);
25909 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr);
25911 +unsigned int au_sigen_inc(struct super_block *sb);
25912 +aufs_bindex_t au_new_br_id(struct super_block *sb);
25914 +int si_read_lock(struct super_block *sb, int flags);
25915 +int si_write_lock(struct super_block *sb, int flags);
25916 +int aufs_read_lock(struct dentry *dentry, int flags);
25917 +void aufs_read_unlock(struct dentry *dentry, int flags);
25918 +void aufs_write_lock(struct dentry *dentry);
25919 +void aufs_write_unlock(struct dentry *dentry);
25920 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
25921 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
25923 +int si_pid_test_slow(struct super_block *sb);
25924 +void si_pid_set_slow(struct super_block *sb);
25925 +void si_pid_clr_slow(struct super_block *sb);
25927 +/* wbr_policy.c */
25928 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
25929 +extern struct au_wbr_create_operations au_wbr_create_ops[];
25930 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
25931 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
25934 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
25936 +/* ---------------------------------------------------------------------- */
25938 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
25940 + return sb->s_fs_info;
25943 +/* ---------------------------------------------------------------------- */
25945 +#ifdef CONFIG_AUFS_EXPORT
25946 +int au_test_nfsd(void);
25947 +void au_export_init(struct super_block *sb);
25948 +void au_xigen_inc(struct inode *inode);
25949 +int au_xigen_new(struct inode *inode);
25950 +int au_xigen_set(struct super_block *sb, struct file *base);
25951 +void au_xigen_clr(struct super_block *sb);
25953 +static inline int au_busy_or_stale(void)
25955 + if (!au_test_nfsd())
25960 +AuStubInt0(au_test_nfsd, void)
25961 +AuStubVoid(au_export_init, struct super_block *sb)
25962 +AuStubVoid(au_xigen_inc, struct inode *inode)
25963 +AuStubInt0(au_xigen_new, struct inode *inode)
25964 +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base)
25965 +AuStubVoid(au_xigen_clr, struct super_block *sb)
25966 +static inline int au_busy_or_stale(void)
25970 +#endif /* CONFIG_AUFS_EXPORT */
25972 +/* ---------------------------------------------------------------------- */
25974 +#ifdef CONFIG_AUFS_SBILIST
25976 +extern struct au_splhead au_sbilist;
25978 +static inline void au_sbilist_init(void)
25980 + au_spl_init(&au_sbilist);
25983 +static inline void au_sbilist_add(struct super_block *sb)
25985 + au_spl_add(&au_sbi(sb)->si_list, &au_sbilist);
25988 +static inline void au_sbilist_del(struct super_block *sb)
25990 + au_spl_del(&au_sbi(sb)->si_list, &au_sbilist);
25993 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
25994 +static inline void au_sbilist_lock(void)
25996 + spin_lock(&au_sbilist.spin);
25999 +static inline void au_sbilist_unlock(void)
26001 + spin_unlock(&au_sbilist.spin);
26003 +#define AuGFP_SBILIST GFP_ATOMIC
26005 +AuStubVoid(au_sbilist_lock, void)
26006 +AuStubVoid(au_sbilist_unlock, void)
26007 +#define AuGFP_SBILIST GFP_NOFS
26008 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
26010 +AuStubVoid(au_sbilist_init, void)
26011 +AuStubVoid(au_sbilist_add, struct super_block*)
26012 +AuStubVoid(au_sbilist_del, struct super_block*)
26013 +AuStubVoid(au_sbilist_lock, void)
26014 +AuStubVoid(au_sbilist_unlock, void)
26015 +#define AuGFP_SBILIST GFP_NOFS
26018 +/* ---------------------------------------------------------------------- */
26020 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
26023 + * This function is a dynamic '__init' fucntion actually,
26024 + * so the tiny check for si_rwsem is unnecessary.
26026 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
26027 +#ifdef CONFIG_DEBUG_FS
26028 + sbinfo->si_dbgaufs = NULL;
26029 + sbinfo->si_dbgaufs_plink = NULL;
26030 + sbinfo->si_dbgaufs_xib = NULL;
26031 +#ifdef CONFIG_AUFS_EXPORT
26032 + sbinfo->si_dbgaufs_xigen = NULL;
26037 +/* ---------------------------------------------------------------------- */
26039 +static inline pid_t si_pid_bit(void)
26041 + /* the origin of pid is 1, but the bitmap's is 0 */
26042 + return current->pid - 1;
26045 +static inline int si_pid_test(struct super_block *sb)
26047 + pid_t bit = si_pid_bit();
26048 + if (bit < PID_MAX_DEFAULT)
26049 + return test_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
26051 + return si_pid_test_slow(sb);
26054 +static inline void si_pid_set(struct super_block *sb)
26056 + pid_t bit = si_pid_bit();
26057 + if (bit < PID_MAX_DEFAULT) {
26058 + AuDebugOn(test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
26059 + set_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
26062 + si_pid_set_slow(sb);
26065 +static inline void si_pid_clr(struct super_block *sb)
26067 + pid_t bit = si_pid_bit();
26068 + if (bit < PID_MAX_DEFAULT) {
26069 + AuDebugOn(!test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
26070 + clear_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
26073 + si_pid_clr_slow(sb);
26076 +/* ---------------------------------------------------------------------- */
26078 +/* lock superblock. mainly for entry point functions */
26080 + * __si_read_lock, __si_write_lock,
26081 + * __si_read_unlock, __si_write_unlock, __si_downgrade_lock
26083 +AuSimpleRwsemFuncs(__si, struct super_block *sb, &au_sbi(sb)->si_rwsem);
26085 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
26086 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
26087 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
26089 +static inline void si_noflush_read_lock(struct super_block *sb)
26091 + __si_read_lock(sb);
26095 +static inline int si_noflush_read_trylock(struct super_block *sb)
26097 + int locked = __si_read_trylock(sb);
26103 +static inline void si_noflush_write_lock(struct super_block *sb)
26105 + __si_write_lock(sb);
26109 +static inline int si_noflush_write_trylock(struct super_block *sb)
26111 + int locked = __si_write_trylock(sb);
26117 +#if 0 /* unused */
26118 +static inline int si_read_trylock(struct super_block *sb, int flags)
26120 + if (au_ftest_lock(flags, FLUSH))
26121 + au_nwt_flush(&au_sbi(sb)->si_nowait);
26122 + return si_noflush_read_trylock(sb);
26126 +static inline void si_read_unlock(struct super_block *sb)
26129 + __si_read_unlock(sb);
26132 +#if 0 /* unused */
26133 +static inline int si_write_trylock(struct super_block *sb, int flags)
26135 + if (au_ftest_lock(flags, FLUSH))
26136 + au_nwt_flush(&au_sbi(sb)->si_nowait);
26137 + return si_noflush_write_trylock(sb);
26141 +static inline void si_write_unlock(struct super_block *sb)
26144 + __si_write_unlock(sb);
26147 +#if 0 /* unused */
26148 +static inline void si_downgrade_lock(struct super_block *sb)
26150 + __si_downgrade_lock(sb);
26154 +/* ---------------------------------------------------------------------- */
26156 +static inline aufs_bindex_t au_sbend(struct super_block *sb)
26158 + SiMustAnyLock(sb);
26159 + return au_sbi(sb)->si_bend;
26162 +static inline unsigned int au_mntflags(struct super_block *sb)
26164 + SiMustAnyLock(sb);
26165 + return au_sbi(sb)->si_mntflags;
26168 +static inline unsigned int au_sigen(struct super_block *sb)
26170 + SiMustAnyLock(sb);
26171 + return au_sbi(sb)->si_generation;
26174 +static inline void au_ninodes_inc(struct super_block *sb)
26176 + atomic_long_inc(&au_sbi(sb)->si_ninodes);
26179 +static inline void au_ninodes_dec(struct super_block *sb)
26181 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_ninodes));
26182 + atomic_long_dec(&au_sbi(sb)->si_ninodes);
26185 +static inline void au_nfiles_inc(struct super_block *sb)
26187 + atomic_long_inc(&au_sbi(sb)->si_nfiles);
26190 +static inline void au_nfiles_dec(struct super_block *sb)
26192 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_nfiles));
26193 + atomic_long_dec(&au_sbi(sb)->si_nfiles);
26196 +static inline struct au_branch *au_sbr(struct super_block *sb,
26197 + aufs_bindex_t bindex)
26199 + SiMustAnyLock(sb);
26200 + return au_sbi(sb)->si_branch[0 + bindex];
26203 +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid)
26205 + SiMustWriteLock(sb);
26206 + au_sbi(sb)->si_xino_brid = brid;
26209 +static inline aufs_bindex_t au_xino_brid(struct super_block *sb)
26211 + SiMustAnyLock(sb);
26212 + return au_sbi(sb)->si_xino_brid;
26215 +#endif /* __KERNEL__ */
26216 +#endif /* __AUFS_SUPER_H__ */
26217 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
26218 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
26219 +++ linux/fs/aufs/sysaufs.c 2014-06-24 00:14:06.789386337 +0200
26222 + * Copyright (C) 2005-2014 Junjiro R. Okajima
26224 + * This program, aufs is free software; you can redistribute it and/or modify
26225 + * it under the terms of the GNU General Public License as published by
26226 + * the Free Software Foundation; either version 2 of the License, or
26227 + * (at your option) any later version.
26229 + * This program is distributed in the hope that it will be useful,
26230 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26231 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26232 + * GNU General Public License for more details.
26234 + * You should have received a copy of the GNU General Public License
26235 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26239 + * sysfs interface and lifetime management
26240 + * they are necessary regardless sysfs is disabled.
26243 +#include <linux/random.h>
26246 +unsigned long sysaufs_si_mask;
26247 +struct kset *sysaufs_kset;
26249 +#define AuSiAttr(_name) { \
26250 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
26251 + .show = sysaufs_si_##_name, \
26254 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
26255 +struct attribute *sysaufs_si_attrs[] = {
26256 + &sysaufs_si_attr_xi_path.attr,
26260 +static const struct sysfs_ops au_sbi_ops = {
26261 + .show = sysaufs_si_show
26264 +static struct kobj_type au_sbi_ktype = {
26265 + .release = au_si_free,
26266 + .sysfs_ops = &au_sbi_ops,
26267 + .default_attrs = sysaufs_si_attrs
26270 +/* ---------------------------------------------------------------------- */
26272 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
26276 + sbinfo->si_kobj.kset = sysaufs_kset;
26277 + /* cf. sysaufs_name() */
26278 + err = kobject_init_and_add
26279 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
26280 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
26282 + dbgaufs_si_null(sbinfo);
26284 + err = dbgaufs_si_init(sbinfo);
26285 + if (unlikely(err))
26286 + kobject_put(&sbinfo->si_kobj);
26291 +void sysaufs_fin(void)
26294 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
26295 + kset_unregister(sysaufs_kset);
26298 +int __init sysaufs_init(void)
26303 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
26304 + } while (!sysaufs_si_mask);
26307 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
26308 + if (unlikely(!sysaufs_kset))
26310 + err = PTR_ERR(sysaufs_kset);
26311 + if (IS_ERR(sysaufs_kset))
26313 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
26314 + if (unlikely(err)) {
26315 + kset_unregister(sysaufs_kset);
26319 + err = dbgaufs_init();
26320 + if (unlikely(err))
26325 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
26326 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
26327 +++ linux/fs/aufs/sysaufs.h 2014-06-24 00:14:06.789386337 +0200
26330 + * Copyright (C) 2005-2014 Junjiro R. Okajima
26332 + * This program, aufs is free software; you can redistribute it and/or modify
26333 + * it under the terms of the GNU General Public License as published by
26334 + * the Free Software Foundation; either version 2 of the License, or
26335 + * (at your option) any later version.
26337 + * This program is distributed in the hope that it will be useful,
26338 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26339 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26340 + * GNU General Public License for more details.
26342 + * You should have received a copy of the GNU General Public License
26343 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26347 + * sysfs interface and mount lifetime management
26350 +#ifndef __SYSAUFS_H__
26351 +#define __SYSAUFS_H__
26355 +#include <linux/sysfs.h>
26356 +#include "module.h"
26358 +struct super_block;
26361 +struct sysaufs_si_attr {
26362 + struct attribute attr;
26363 + int (*show)(struct seq_file *seq, struct super_block *sb);
26366 +/* ---------------------------------------------------------------------- */
26369 +extern unsigned long sysaufs_si_mask;
26370 +extern struct kset *sysaufs_kset;
26371 +extern struct attribute *sysaufs_si_attrs[];
26372 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
26373 +int __init sysaufs_init(void);
26374 +void sysaufs_fin(void);
26376 +/* ---------------------------------------------------------------------- */
26378 +/* some people doesn't like to show a pointer in kernel */
26379 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
26381 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
26384 +#define SysaufsSiNamePrefix "si_"
26385 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
26386 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
26388 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
26389 + sysaufs_si_id(sbinfo));
26393 +#ifdef CONFIG_SYSFS
26395 +extern struct attribute_group *sysaufs_attr_group;
26397 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
26398 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
26401 +void sysaufs_br_init(struct au_branch *br);
26402 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
26403 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
26405 +#define sysaufs_brs_init() do {} while (0)
26408 +#define sysaufs_attr_group NULL
26410 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
26413 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
26419 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
26420 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
26421 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
26423 +static inline void sysaufs_brs_init(void)
26428 +#endif /* CONFIG_SYSFS */
26430 +#endif /* __KERNEL__ */
26431 +#endif /* __SYSAUFS_H__ */
26432 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
26433 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
26434 +++ linux/fs/aufs/sysfs.c 2014-06-24 00:14:06.789386337 +0200
26437 + * Copyright (C) 2005-2014 Junjiro R. Okajima
26439 + * This program, aufs is free software; you can redistribute it and/or modify
26440 + * it under the terms of the GNU General Public License as published by
26441 + * the Free Software Foundation; either version 2 of the License, or
26442 + * (at your option) any later version.
26444 + * This program is distributed in the hope that it will be useful,
26445 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26446 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26447 + * GNU General Public License for more details.
26449 + * You should have received a copy of the GNU General Public License
26450 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26454 + * sysfs interface
26457 +#include <linux/seq_file.h>
26460 +#ifdef CONFIG_AUFS_FS_MODULE
26461 +/* this entry violates the "one line per file" policy of sysfs */
26462 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
26466 + static char *conf =
26467 +/* this file is generated at compiling */
26468 +#include "conf.str"
26471 + err = snprintf(buf, PAGE_SIZE, conf);
26472 + if (unlikely(err >= PAGE_SIZE))
26477 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
26480 +static struct attribute *au_attr[] = {
26481 +#ifdef CONFIG_AUFS_FS_MODULE
26482 + &au_config_attr.attr,
26484 + NULL, /* need to NULL terminate the list of attributes */
26487 +static struct attribute_group sysaufs_attr_group_body = {
26491 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
26493 +/* ---------------------------------------------------------------------- */
26495 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
26499 + SiMustAnyLock(sb);
26502 + if (au_opt_test(au_mntflags(sb), XINO)) {
26503 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
26504 + seq_putc(seq, '\n');
26510 + * the lifetime of branch is independent from the entry under sysfs.
26511 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
26514 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
26515 + aufs_bindex_t bindex, int idx)
26518 + struct path path;
26519 + struct dentry *root;
26520 + struct au_branch *br;
26523 + AuDbg("b%d\n", bindex);
26526 + root = sb->s_root;
26527 + di_read_lock_parent(root, !AuLock_IR);
26528 + br = au_sbr(sb, bindex);
26531 + case AuBrSysfs_BR:
26532 + path.mnt = au_br_mnt(br);
26533 + path.dentry = au_h_dptr(root, bindex);
26534 + au_seq_path(seq, &path);
26535 + di_read_unlock(root, !AuLock_IR);
26536 + perm = au_optstr_br_perm(br->br_perm);
26538 + err = seq_printf(seq, "=%s\n", perm);
26545 + case AuBrSysfs_BRID:
26546 + err = seq_printf(seq, "%d\n", br->br_id);
26547 + di_read_unlock(root, !AuLock_IR);
26556 +/* ---------------------------------------------------------------------- */
26558 +static struct seq_file *au_seq(char *p, ssize_t len)
26560 + struct seq_file *seq;
26562 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
26564 + /* mutex_init(&seq.lock); */
26567 + return seq; /* success */
26570 + seq = ERR_PTR(-ENOMEM);
26574 +#define SysaufsBr_PREFIX "br"
26575 +#define SysaufsBrid_PREFIX "brid"
26577 +/* todo: file size may exceed PAGE_SIZE */
26578 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
26584 + aufs_bindex_t bend;
26585 + struct au_sbinfo *sbinfo;
26586 + struct super_block *sb;
26587 + struct seq_file *seq;
26589 + struct attribute **cattr;
26591 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
26592 + sb = sbinfo->si_sb;
26595 + * prevent a race condition between sysfs and aufs.
26596 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
26597 + * prohibits maintaining the sysfs entries.
26598 + * hew we acquire read lock after sysfs_get_active_two().
26599 + * on the other hand, the remount process may maintain the sysfs/aufs
26600 + * entries after acquiring write lock.
26601 + * it can cause a deadlock.
26602 + * simply we gave up processing read here.
26605 + if (unlikely(!si_noflush_read_trylock(sb)))
26608 + seq = au_seq(buf, PAGE_SIZE);
26609 + err = PTR_ERR(seq);
26613 + name = (void *)attr->name;
26614 + cattr = sysaufs_si_attrs;
26616 + if (!strcmp(name, (*cattr)->name)) {
26617 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
26624 + if (!strncmp(name, SysaufsBrid_PREFIX,
26625 + sizeof(SysaufsBrid_PREFIX) - 1)) {
26626 + idx = AuBrSysfs_BRID;
26627 + name += sizeof(SysaufsBrid_PREFIX) - 1;
26628 + } else if (!strncmp(name, SysaufsBr_PREFIX,
26629 + sizeof(SysaufsBr_PREFIX) - 1)) {
26630 + idx = AuBrSysfs_BR;
26631 + name += sizeof(SysaufsBr_PREFIX) - 1;
26635 + err = kstrtol(name, 10, &l);
26637 + bend = au_sbend(sb);
26639 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
26646 + err = seq->count;
26647 + /* sysfs limit */
26648 + if (unlikely(err == PAGE_SIZE))
26653 + si_read_unlock(sb);
26658 +/* ---------------------------------------------------------------------- */
26660 +void sysaufs_br_init(struct au_branch *br)
26663 + struct au_brsysfs *br_sysfs;
26664 + struct attribute *attr;
26666 + br_sysfs = br->br_sysfs;
26667 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
26668 + attr = &br_sysfs->attr;
26669 + sysfs_attr_init(attr);
26670 + attr->name = br_sysfs->name;
26671 + attr->mode = S_IRUGO;
26676 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
26678 + struct au_branch *br;
26679 + struct kobject *kobj;
26680 + struct au_brsysfs *br_sysfs;
26682 + aufs_bindex_t bend;
26684 + dbgaufs_brs_del(sb, bindex);
26686 + if (!sysaufs_brs)
26689 + kobj = &au_sbi(sb)->si_kobj;
26690 + bend = au_sbend(sb);
26691 + for (; bindex <= bend; bindex++) {
26692 + br = au_sbr(sb, bindex);
26693 + br_sysfs = br->br_sysfs;
26694 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
26695 + sysfs_remove_file(kobj, &br_sysfs->attr);
26701 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
26704 + aufs_bindex_t bend;
26705 + struct kobject *kobj;
26706 + struct au_branch *br;
26707 + struct au_brsysfs *br_sysfs;
26709 + dbgaufs_brs_add(sb, bindex);
26711 + if (!sysaufs_brs)
26714 + kobj = &au_sbi(sb)->si_kobj;
26715 + bend = au_sbend(sb);
26716 + for (; bindex <= bend; bindex++) {
26717 + br = au_sbr(sb, bindex);
26718 + br_sysfs = br->br_sysfs;
26719 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
26720 + SysaufsBr_PREFIX "%d", bindex);
26721 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
26722 + SysaufsBrid_PREFIX "%d", bindex);
26723 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
26724 + err = sysfs_create_file(kobj, &br_sysfs->attr);
26725 + if (unlikely(err))
26726 + pr_warn("failed %s under sysfs(%d)\n",
26727 + br_sysfs->name, err);
26732 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
26733 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
26734 +++ linux/fs/aufs/sysrq.c 2014-06-24 00:14:06.789386337 +0200
26737 + * Copyright (C) 2005-2014 Junjiro R. Okajima
26739 + * This program, aufs is free software; you can redistribute it and/or modify
26740 + * it under the terms of the GNU General Public License as published by
26741 + * the Free Software Foundation; either version 2 of the License, or
26742 + * (at your option) any later version.
26744 + * This program is distributed in the hope that it will be useful,
26745 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26746 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26747 + * GNU General Public License for more details.
26749 + * You should have received a copy of the GNU General Public License
26750 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26754 + * magic sysrq hanlder
26757 +/* #include <linux/sysrq.h> */
26758 +#include <linux/writeback.h>
26761 +/* ---------------------------------------------------------------------- */
26763 +static void sysrq_sb(struct super_block *sb)
26766 + struct au_sbinfo *sbinfo;
26767 + struct file *file;
26768 + struct au_sphlhead *files;
26769 + struct au_finfo *finfo;
26771 + plevel = au_plevel;
26772 + au_plevel = KERN_WARNING;
26774 + /* since we define pr_fmt, call printk directly */
26775 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
26777 + sbinfo = au_sbi(sb);
26778 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
26779 + pr("superblock\n");
26783 + pr("root dentry\n");
26784 + au_dpri_dentry(sb->s_root);
26785 + pr("root inode\n");
26786 + au_dpri_inode(sb->s_root->d_inode);
26791 + int err, i, j, ndentry;
26792 + struct au_dcsub_pages dpages;
26793 + struct au_dpage *dpage;
26795 + err = au_dpages_init(&dpages, GFP_ATOMIC);
26796 + if (unlikely(err))
26798 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
26800 + for (i = 0; i < dpages.ndpage; i++) {
26801 + dpage = dpages.dpages + i;
26802 + ndentry = dpage->ndentry;
26803 + for (j = 0; j < ndentry; j++)
26804 + au_dpri_dentry(dpage->dentries[j]);
26806 + au_dpages_free(&dpages);
26813 + pr("isolated inode\n");
26814 + spin_lock(&inode_sb_list_lock);
26815 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
26816 + spin_lock(&i->i_lock);
26817 + if (1 || hlist_empty(&i->i_dentry))
26818 + au_dpri_inode(i);
26819 + spin_unlock(&i->i_lock);
26821 + spin_unlock(&inode_sb_list_lock);
26825 + files = &au_sbi(sb)->si_files;
26826 + spin_lock(&files->spin);
26827 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
26829 + file = finfo->fi_file;
26830 + mode = file_inode(file)->i_mode;
26831 + if (!special_file(mode))
26832 + au_dpri_file(file);
26834 + spin_unlock(&files->spin);
26838 + au_plevel = plevel;
26841 +/* ---------------------------------------------------------------------- */
26843 +/* module parameter */
26844 +static char *aufs_sysrq_key = "a";
26845 +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO);
26846 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
26848 +static void au_sysrq(int key __maybe_unused)
26850 + struct au_sbinfo *sbinfo;
26853 + au_sbilist_lock();
26854 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
26855 + sysrq_sb(sbinfo->si_sb);
26856 + au_sbilist_unlock();
26860 +static struct sysrq_key_op au_sysrq_op = {
26861 + .handler = au_sysrq,
26862 + .help_msg = "Aufs",
26863 + .action_msg = "Aufs",
26864 + .enable_mask = SYSRQ_ENABLE_DUMP
26867 +/* ---------------------------------------------------------------------- */
26869 +int __init au_sysrq_init(void)
26875 + key = *aufs_sysrq_key;
26876 + if ('a' <= key && key <= 'z')
26877 + err = register_sysrq_key(key, &au_sysrq_op);
26878 + if (unlikely(err))
26879 + pr_err("err %d, sysrq=%c\n", err, key);
26883 +void au_sysrq_fin(void)
26886 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
26887 + if (unlikely(err))
26888 + pr_err("err %d (ignored)\n", err);
26890 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
26891 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
26892 +++ linux/fs/aufs/vdir.c 2014-06-24 00:14:06.789386337 +0200
26895 + * Copyright (C) 2005-2014 Junjiro R. Okajima
26897 + * This program, aufs is free software; you can redistribute it and/or modify
26898 + * it under the terms of the GNU General Public License as published by
26899 + * the Free Software Foundation; either version 2 of the License, or
26900 + * (at your option) any later version.
26902 + * This program is distributed in the hope that it will be useful,
26903 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26904 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26905 + * GNU General Public License for more details.
26907 + * You should have received a copy of the GNU General Public License
26908 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26912 + * virtual or vertical directory
26917 +static unsigned int calc_size(int nlen)
26919 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
26922 +static int set_deblk_end(union au_vdir_deblk_p *p,
26923 + union au_vdir_deblk_p *deblk_end)
26925 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
26926 + p->de->de_str.len = 0;
26930 + return -1; /* error */
26933 +/* returns true or false */
26934 +static int is_deblk_end(union au_vdir_deblk_p *p,
26935 + union au_vdir_deblk_p *deblk_end)
26937 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
26938 + return !p->de->de_str.len;
26942 +static unsigned char *last_deblk(struct au_vdir *vdir)
26944 + return vdir->vd_deblk[vdir->vd_nblk - 1];
26947 +/* ---------------------------------------------------------------------- */
26949 +/* estimate the apropriate size for name hash table */
26950 +unsigned int au_rdhash_est(loff_t sz)
26958 + if (sz < AUFS_RDHASH_DEF)
26959 + n = AUFS_RDHASH_DEF;
26960 + /* pr_info("n %u\n", n); */
26965 + * the allocated memory has to be freed by
26966 + * au_nhash_wh_free() or au_nhash_de_free().
26968 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
26970 + struct hlist_head *head;
26973 + head = kmalloc(sizeof(*nhash->nh_head) * num_hash, gfp);
26975 + nhash->nh_num = num_hash;
26976 + nhash->nh_head = head;
26977 + for (u = 0; u < num_hash; u++)
26978 + INIT_HLIST_HEAD(head++);
26979 + return 0; /* success */
26985 +static void nhash_count(struct hlist_head *head)
26989 + struct hlist_node *pos;
26992 + hlist_for_each(pos, head)
26994 + pr_info("%lu\n", n);
26998 +static void au_nhash_wh_do_free(struct hlist_head *head)
27000 + struct au_vdir_wh *pos;
27001 + struct hlist_node *node;
27003 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
27007 +static void au_nhash_de_do_free(struct hlist_head *head)
27009 + struct au_vdir_dehstr *pos;
27010 + struct hlist_node *node;
27012 + hlist_for_each_entry_safe(pos, node, head, hash)
27013 + au_cache_free_vdir_dehstr(pos);
27016 +static void au_nhash_do_free(struct au_nhash *nhash,
27017 + void (*free)(struct hlist_head *head))
27020 + struct hlist_head *head;
27022 + n = nhash->nh_num;
27026 + head = nhash->nh_head;
27027 + while (n-- > 0) {
27028 + nhash_count(head);
27031 + kfree(nhash->nh_head);
27034 +void au_nhash_wh_free(struct au_nhash *whlist)
27036 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
27039 +static void au_nhash_de_free(struct au_nhash *delist)
27041 + au_nhash_do_free(delist, au_nhash_de_do_free);
27044 +/* ---------------------------------------------------------------------- */
27046 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
27050 + unsigned int u, n;
27051 + struct hlist_head *head;
27052 + struct au_vdir_wh *pos;
27055 + n = whlist->nh_num;
27056 + head = whlist->nh_head;
27057 + for (u = 0; u < n; u++, head++)
27058 + hlist_for_each_entry(pos, head, wh_hash)
27059 + if (pos->wh_bindex == btgt && ++num > limit)
27064 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
27065 + unsigned char *name,
27066 + unsigned int len)
27069 + /* const unsigned int magic_bit = 12; */
27071 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
27076 + /* v = hash_long(v, magic_bit); */
27077 + v %= nhash->nh_num;
27078 + return nhash->nh_head + v;
27081 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
27084 + return str->len == nlen && !memcmp(str->name, name, nlen);
27087 +/* returns found or not */
27088 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
27090 + struct hlist_head *head;
27091 + struct au_vdir_wh *pos;
27092 + struct au_vdir_destr *str;
27094 + head = au_name_hash(whlist, name, nlen);
27095 + hlist_for_each_entry(pos, head, wh_hash) {
27096 + str = &pos->wh_str;
27097 + AuDbg("%.*s\n", str->len, str->name);
27098 + if (au_nhash_test_name(str, name, nlen))
27104 +/* returns found(true) or not */
27105 +static int test_known(struct au_nhash *delist, char *name, int nlen)
27107 + struct hlist_head *head;
27108 + struct au_vdir_dehstr *pos;
27109 + struct au_vdir_destr *str;
27111 + head = au_name_hash(delist, name, nlen);
27112 + hlist_for_each_entry(pos, head, hash) {
27114 + AuDbg("%.*s\n", str->len, str->name);
27115 + if (au_nhash_test_name(str, name, nlen))
27121 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
27122 + unsigned char d_type)
27124 +#ifdef CONFIG_AUFS_SHWH
27125 + wh->wh_ino = ino;
27126 + wh->wh_type = d_type;
27130 +/* ---------------------------------------------------------------------- */
27132 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
27133 + unsigned int d_type, aufs_bindex_t bindex,
27134 + unsigned char shwh)
27137 + struct au_vdir_destr *str;
27138 + struct au_vdir_wh *wh;
27140 + AuDbg("%.*s\n", nlen, name);
27141 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
27144 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
27145 + if (unlikely(!wh))
27149 + wh->wh_bindex = bindex;
27151 + au_shwh_init_wh(wh, ino, d_type);
27152 + str = &wh->wh_str;
27154 + memcpy(str->name, name, nlen);
27155 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
27162 +static int append_deblk(struct au_vdir *vdir)
27165 + unsigned long ul;
27166 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
27167 + union au_vdir_deblk_p p, deblk_end;
27168 + unsigned char **o;
27171 + o = krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
27173 + if (unlikely(!o))
27176 + vdir->vd_deblk = o;
27177 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
27179 + ul = vdir->vd_nblk++;
27180 + vdir->vd_deblk[ul] = p.deblk;
27181 + vdir->vd_last.ul = ul;
27182 + vdir->vd_last.p.deblk = p.deblk;
27183 + deblk_end.deblk = p.deblk + deblk_sz;
27184 + err = set_deblk_end(&p, &deblk_end);
27191 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
27192 + unsigned int d_type, struct au_nhash *delist)
27196 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
27197 + union au_vdir_deblk_p p, *room, deblk_end;
27198 + struct au_vdir_dehstr *dehstr;
27200 + p.deblk = last_deblk(vdir);
27201 + deblk_end.deblk = p.deblk + deblk_sz;
27202 + room = &vdir->vd_last.p;
27203 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
27204 + || !is_deblk_end(room, &deblk_end));
27206 + sz = calc_size(nlen);
27207 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
27208 + err = append_deblk(vdir);
27209 + if (unlikely(err))
27212 + p.deblk = last_deblk(vdir);
27213 + deblk_end.deblk = p.deblk + deblk_sz;
27215 + AuDebugOn(room->deblk != p.deblk);
27219 + dehstr = au_cache_alloc_vdir_dehstr();
27220 + if (unlikely(!dehstr))
27223 + dehstr->str = &room->de->de_str;
27224 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
27225 + room->de->de_ino = ino;
27226 + room->de->de_type = d_type;
27227 + room->de->de_str.len = nlen;
27228 + memcpy(room->de->de_str.name, name, nlen);
27231 + room->deblk += sz;
27232 + if (unlikely(set_deblk_end(room, &deblk_end)))
27233 + err = append_deblk(vdir);
27240 +/* ---------------------------------------------------------------------- */
27242 +void au_vdir_free(struct au_vdir *vdir)
27244 + unsigned char **deblk;
27246 + deblk = vdir->vd_deblk;
27247 + while (vdir->vd_nblk--)
27249 + kfree(vdir->vd_deblk);
27250 + au_cache_free_vdir(vdir);
27253 +static struct au_vdir *alloc_vdir(struct file *file)
27255 + struct au_vdir *vdir;
27256 + struct super_block *sb;
27259 + sb = file->f_dentry->d_sb;
27260 + SiMustAnyLock(sb);
27263 + vdir = au_cache_alloc_vdir();
27264 + if (unlikely(!vdir))
27267 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
27268 + if (unlikely(!vdir->vd_deblk))
27271 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
27272 + if (!vdir->vd_deblk_sz) {
27273 + /* estimate the apropriate size for deblk */
27274 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
27275 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
27277 + vdir->vd_nblk = 0;
27278 + vdir->vd_version = 0;
27279 + vdir->vd_jiffy = 0;
27280 + err = append_deblk(vdir);
27282 + return vdir; /* success */
27284 + kfree(vdir->vd_deblk);
27287 + au_cache_free_vdir(vdir);
27289 + vdir = ERR_PTR(err);
27293 +static int reinit_vdir(struct au_vdir *vdir)
27296 + union au_vdir_deblk_p p, deblk_end;
27298 + while (vdir->vd_nblk > 1) {
27299 + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
27300 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
27303 + p.deblk = vdir->vd_deblk[0];
27304 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
27305 + err = set_deblk_end(&p, &deblk_end);
27306 + /* keep vd_dblk_sz */
27307 + vdir->vd_last.ul = 0;
27308 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
27309 + vdir->vd_version = 0;
27310 + vdir->vd_jiffy = 0;
27315 +/* ---------------------------------------------------------------------- */
27317 +#define AuFillVdir_CALLED 1
27318 +#define AuFillVdir_WHABLE (1 << 1)
27319 +#define AuFillVdir_SHWH (1 << 2)
27320 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
27321 +#define au_fset_fillvdir(flags, name) \
27322 + do { (flags) |= AuFillVdir_##name; } while (0)
27323 +#define au_fclr_fillvdir(flags, name) \
27324 + do { (flags) &= ~AuFillVdir_##name; } while (0)
27326 +#ifndef CONFIG_AUFS_SHWH
27327 +#undef AuFillVdir_SHWH
27328 +#define AuFillVdir_SHWH 0
27331 +struct fillvdir_arg {
27332 + struct dir_context ctx;
27333 + struct file *file;
27334 + struct au_vdir *vdir;
27335 + struct au_nhash delist;
27336 + struct au_nhash whlist;
27337 + aufs_bindex_t bindex;
27338 + unsigned int flags;
27342 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
27343 + loff_t offset __maybe_unused, u64 h_ino,
27344 + unsigned int d_type)
27346 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
27347 + char *name = (void *)__name;
27348 + struct super_block *sb;
27350 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
27353 + sb = arg->file->f_dentry->d_sb;
27354 + au_fset_fillvdir(arg->flags, CALLED);
27356 + if (nlen <= AUFS_WH_PFX_LEN
27357 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
27358 + if (test_known(&arg->delist, name, nlen)
27359 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
27360 + goto out; /* already exists or whiteouted */
27362 + sb = arg->file->f_dentry->d_sb;
27363 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
27365 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
27366 + d_type = DT_UNKNOWN;
27367 + arg->err = append_de(arg->vdir, name, nlen, ino,
27368 + d_type, &arg->delist);
27370 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
27371 + name += AUFS_WH_PFX_LEN;
27372 + nlen -= AUFS_WH_PFX_LEN;
27373 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
27374 + goto out; /* already whiteouted */
27377 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
27380 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
27381 + d_type = DT_UNKNOWN;
27382 + arg->err = au_nhash_append_wh
27383 + (&arg->whlist, name, nlen, ino, d_type,
27384 + arg->bindex, shwh);
27390 + arg->vdir->vd_jiffy = jiffies;
27392 + AuTraceErr(arg->err);
27396 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
27397 + struct au_nhash *whlist, struct au_nhash *delist)
27399 +#ifdef CONFIG_AUFS_SHWH
27401 + unsigned int nh, u;
27402 + struct hlist_head *head;
27403 + struct au_vdir_wh *pos;
27404 + struct hlist_node *n;
27406 + struct au_vdir_destr *destr;
27408 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
27411 + o = p = (void *)__get_free_page(GFP_NOFS);
27412 + if (unlikely(!p))
27416 + nh = whlist->nh_num;
27417 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
27418 + p += AUFS_WH_PFX_LEN;
27419 + for (u = 0; u < nh; u++) {
27420 + head = whlist->nh_head + u;
27421 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
27422 + destr = &pos->wh_str;
27423 + memcpy(p, destr->name, destr->len);
27424 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
27425 + pos->wh_ino, pos->wh_type, delist);
27426 + if (unlikely(err))
27431 + free_page((unsigned long)o);
27441 +static int au_do_read_vdir(struct fillvdir_arg *arg)
27444 + unsigned int rdhash;
27446 + aufs_bindex_t bend, bindex, bstart;
27447 + unsigned char shwh;
27448 + struct file *hf, *file;
27449 + struct super_block *sb;
27451 + file = arg->file;
27452 + sb = file->f_dentry->d_sb;
27453 + SiMustAnyLock(sb);
27455 + rdhash = au_sbi(sb)->si_rdhash;
27457 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
27458 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
27459 + if (unlikely(err))
27461 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
27462 + if (unlikely(err))
27468 + if (au_opt_test(au_mntflags(sb), SHWH)) {
27470 + au_fset_fillvdir(arg->flags, SHWH);
27472 + bstart = au_fbstart(file);
27473 + bend = au_fbend_dir(file);
27474 + for (bindex = bstart; !err && bindex <= bend; bindex++) {
27475 + hf = au_hf_dir(file, bindex);
27479 + offset = vfsub_llseek(hf, 0, SEEK_SET);
27481 + if (unlikely(offset))
27484 + arg->bindex = bindex;
27485 + au_fclr_fillvdir(arg->flags, WHABLE);
27487 + || (bindex != bend
27488 + && au_br_whable(au_sbr_perm(sb, bindex))))
27489 + au_fset_fillvdir(arg->flags, WHABLE);
27492 + au_fclr_fillvdir(arg->flags, CALLED);
27494 + err = vfsub_iterate_dir(hf, &arg->ctx);
27497 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
27500 + * dir_relax() may be good for concurrency, but aufs should not
27501 + * use it since it will cause a lockdep problem.
27505 + if (!err && shwh)
27506 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
27508 + au_nhash_wh_free(&arg->whlist);
27511 + au_nhash_de_free(&arg->delist);
27516 +static int read_vdir(struct file *file, int may_read)
27519 + unsigned long expire;
27520 + unsigned char do_read;
27521 + struct fillvdir_arg arg = {
27523 + .actor = au_diractor(fillvdir)
27526 + struct inode *inode;
27527 + struct au_vdir *vdir, *allocated;
27530 + inode = file_inode(file);
27531 + IMustLock(inode);
27532 + SiMustAnyLock(inode->i_sb);
27534 + allocated = NULL;
27536 + expire = au_sbi(inode->i_sb)->si_rdcache;
27537 + vdir = au_ivdir(inode);
27540 + vdir = alloc_vdir(file);
27541 + err = PTR_ERR(vdir);
27542 + if (IS_ERR(vdir))
27545 + allocated = vdir;
27546 + } else if (may_read
27547 + && (inode->i_version != vdir->vd_version
27548 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
27550 + err = reinit_vdir(vdir);
27551 + if (unlikely(err))
27556 + return 0; /* success */
27560 + err = au_do_read_vdir(&arg);
27562 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
27563 + vdir->vd_version = inode->i_version;
27564 + vdir->vd_last.ul = 0;
27565 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
27567 + au_set_ivdir(inode, allocated);
27568 + } else if (allocated)
27569 + au_vdir_free(allocated);
27575 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
27578 + unsigned long ul, n;
27579 + const unsigned int deblk_sz = src->vd_deblk_sz;
27581 + AuDebugOn(tgt->vd_nblk != 1);
27584 + if (tgt->vd_nblk < src->vd_nblk) {
27585 + unsigned char **p;
27587 + p = krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
27589 + if (unlikely(!p))
27591 + tgt->vd_deblk = p;
27594 + if (tgt->vd_deblk_sz != deblk_sz) {
27595 + unsigned char *p;
27597 + tgt->vd_deblk_sz = deblk_sz;
27598 + p = krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS);
27599 + if (unlikely(!p))
27601 + tgt->vd_deblk[0] = p;
27603 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
27604 + tgt->vd_version = src->vd_version;
27605 + tgt->vd_jiffy = src->vd_jiffy;
27607 + n = src->vd_nblk;
27608 + for (ul = 1; ul < n; ul++) {
27609 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
27611 + if (unlikely(!tgt->vd_deblk[ul]))
27615 + tgt->vd_nblk = n;
27616 + tgt->vd_last.ul = tgt->vd_last.ul;
27617 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
27618 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
27619 + - src->vd_deblk[src->vd_last.ul];
27621 + return 0; /* success */
27624 + rerr = reinit_vdir(tgt);
27629 +int au_vdir_init(struct file *file)
27632 + struct inode *inode;
27633 + struct au_vdir *vdir_cache, *allocated;
27635 + /* test file->f_pos here instead of ctx->pos */
27636 + err = read_vdir(file, !file->f_pos);
27637 + if (unlikely(err))
27640 + allocated = NULL;
27641 + vdir_cache = au_fvdir_cache(file);
27642 + if (!vdir_cache) {
27643 + vdir_cache = alloc_vdir(file);
27644 + err = PTR_ERR(vdir_cache);
27645 + if (IS_ERR(vdir_cache))
27647 + allocated = vdir_cache;
27648 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
27649 + /* test file->f_pos here instead of ctx->pos */
27650 + err = reinit_vdir(vdir_cache);
27651 + if (unlikely(err))
27654 + return 0; /* success */
27656 + inode = file_inode(file);
27657 + err = copy_vdir(vdir_cache, au_ivdir(inode));
27659 + file->f_version = inode->i_version;
27661 + au_set_fvdir_cache(file, allocated);
27662 + } else if (allocated)
27663 + au_vdir_free(allocated);
27669 +static loff_t calc_offset(struct au_vdir *vdir)
27672 + union au_vdir_deblk_p p;
27674 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
27675 + offset = vdir->vd_last.p.deblk - p.deblk;
27676 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
27680 +/* returns true or false */
27681 +static int seek_vdir(struct file *file, struct dir_context *ctx)
27684 + unsigned int deblk_sz;
27685 + unsigned long ul, n;
27687 + union au_vdir_deblk_p p, deblk_end;
27688 + struct au_vdir *vdir_cache;
27691 + vdir_cache = au_fvdir_cache(file);
27692 + offset = calc_offset(vdir_cache);
27693 + AuDbg("offset %lld\n", offset);
27694 + if (ctx->pos == offset)
27697 + vdir_cache->vd_last.ul = 0;
27698 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
27703 + deblk_sz = vdir_cache->vd_deblk_sz;
27704 + ul = div64_u64(ctx->pos, deblk_sz);
27705 + AuDbg("ul %lu\n", ul);
27706 + if (ul >= vdir_cache->vd_nblk)
27709 + n = vdir_cache->vd_nblk;
27710 + for (; ul < n; ul++) {
27711 + p.deblk = vdir_cache->vd_deblk[ul];
27712 + deblk_end.deblk = p.deblk + deblk_sz;
27714 + offset *= deblk_sz;
27715 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
27718 + l = calc_size(p.de->de_str.len);
27722 + if (!is_deblk_end(&p, &deblk_end)) {
27724 + vdir_cache->vd_last.ul = ul;
27725 + vdir_cache->vd_last.p = p;
27732 + AuTraceErr(!valid);
27736 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
27738 + unsigned int l, deblk_sz;
27739 + union au_vdir_deblk_p deblk_end;
27740 + struct au_vdir *vdir_cache;
27741 + struct au_vdir_de *de;
27743 + vdir_cache = au_fvdir_cache(file);
27744 + if (!seek_vdir(file, ctx))
27747 + deblk_sz = vdir_cache->vd_deblk_sz;
27749 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
27750 + deblk_end.deblk += deblk_sz;
27751 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
27752 + de = vdir_cache->vd_last.p.de;
27753 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
27754 + de->de_str.len, de->de_str.name, ctx->pos,
27755 + (unsigned long)de->de_ino, de->de_type);
27756 + if (unlikely(!dir_emit(ctx, de->de_str.name,
27757 + de->de_str.len, de->de_ino,
27759 + /* todo: ignore the error caused by udba? */
27760 + /* return err; */
27764 + l = calc_size(de->de_str.len);
27765 + vdir_cache->vd_last.p.deblk += l;
27768 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
27769 + vdir_cache->vd_last.ul++;
27770 + vdir_cache->vd_last.p.deblk
27771 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
27772 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
27781 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
27782 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
27783 +++ linux/fs/aufs/vfsub.c 2014-06-24 00:14:06.789386337 +0200
27786 + * Copyright (C) 2005-2014 Junjiro R. Okajima
27788 + * This program, aufs is free software; you can redistribute it and/or modify
27789 + * it under the terms of the GNU General Public License as published by
27790 + * the Free Software Foundation; either version 2 of the License, or
27791 + * (at your option) any later version.
27793 + * This program is distributed in the hope that it will be useful,
27794 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27795 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27796 + * GNU General Public License for more details.
27798 + * You should have received a copy of the GNU General Public License
27799 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27803 + * sub-routines for VFS
27806 +#include <linux/ima.h>
27807 +#include <linux/namei.h>
27808 +#include <linux/security.h>
27809 +#include <linux/splice.h>
27812 +int vfsub_update_h_iattr(struct path *h_path, int *did)
27816 + struct super_block *h_sb;
27818 + /* for remote fs, leave work for its getattr or d_revalidate */
27819 + /* for bad i_attr fs, handle them in aufs_getattr() */
27820 + /* still some fs may acquire i_mutex. we need to skip them */
27824 + h_sb = h_path->dentry->d_sb;
27825 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
27827 + err = vfs_getattr(h_path, &st);
27832 +/* ---------------------------------------------------------------------- */
27834 +struct file *vfsub_dentry_open(struct path *path, int flags)
27836 + struct file *file;
27838 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
27840 + if (!IS_ERR_OR_NULL(file)
27841 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
27842 + i_readcount_inc(path->dentry->d_inode);
27847 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
27849 + struct file *file;
27852 + file = filp_open(path,
27853 + oflags /* | __FMODE_NONOTIFY */,
27856 + if (IS_ERR(file))
27858 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
27864 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
27868 + err = kern_path(name, flags, path);
27869 + if (!err && path->dentry->d_inode)
27870 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
27874 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
27877 + struct path path = {
27881 + /* VFS checks it too, but by WARN_ON_ONCE() */
27882 + IMustLock(parent->d_inode);
27884 + path.dentry = lookup_one_len(name, parent, len);
27885 + if (IS_ERR(path.dentry))
27887 + if (path.dentry->d_inode)
27888 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
27891 + AuTraceErrPtr(path.dentry);
27892 + return path.dentry;
27895 +void vfsub_call_lkup_one(void *args)
27897 + struct vfsub_lkup_one_args *a = args;
27898 + *a->errp = vfsub_lkup_one(a->name, a->parent);
27901 +/* ---------------------------------------------------------------------- */
27903 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
27904 + struct dentry *d2, struct au_hinode *hdir2)
27906 + struct dentry *d;
27909 + d = lock_rename(d1, d2);
27911 + au_hn_suspend(hdir1);
27912 + if (hdir1 != hdir2)
27913 + au_hn_suspend(hdir2);
27918 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
27919 + struct dentry *d2, struct au_hinode *hdir2)
27921 + au_hn_resume(hdir1);
27922 + if (hdir1 != hdir2)
27923 + au_hn_resume(hdir2);
27925 + unlock_rename(d1, d2);
27929 +/* ---------------------------------------------------------------------- */
27931 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
27934 + struct dentry *d;
27938 + d = path->dentry;
27939 + path->dentry = d->d_parent;
27940 + err = security_path_mknod(path, d, mode, 0);
27941 + path->dentry = d;
27942 + if (unlikely(err))
27945 + err = vfs_create(dir, path->dentry, mode, want_excl);
27947 + struct path tmp = *path;
27950 + vfsub_update_h_iattr(&tmp, &did);
27952 + tmp.dentry = path->dentry->d_parent;
27953 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27962 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
27965 + struct dentry *d;
27969 + d = path->dentry;
27970 + path->dentry = d->d_parent;
27971 + err = security_path_symlink(path, d, symname);
27972 + path->dentry = d;
27973 + if (unlikely(err))
27976 + err = vfs_symlink(dir, path->dentry, symname);
27978 + struct path tmp = *path;
27981 + vfsub_update_h_iattr(&tmp, &did);
27983 + tmp.dentry = path->dentry->d_parent;
27984 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
27993 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
27996 + struct dentry *d;
28000 + d = path->dentry;
28001 + path->dentry = d->d_parent;
28002 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
28003 + path->dentry = d;
28004 + if (unlikely(err))
28007 + err = vfs_mknod(dir, path->dentry, mode, dev);
28009 + struct path tmp = *path;
28012 + vfsub_update_h_iattr(&tmp, &did);
28014 + tmp.dentry = path->dentry->d_parent;
28015 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
28024 +static int au_test_nlink(struct inode *inode)
28026 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
28028 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
28029 + || inode->i_nlink < link_max)
28034 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
28035 + struct inode **delegated_inode)
28038 + struct dentry *d;
28042 + err = au_test_nlink(src_dentry->d_inode);
28043 + if (unlikely(err))
28046 + /* we don't call may_linkat() */
28047 + d = path->dentry;
28048 + path->dentry = d->d_parent;
28049 + err = security_path_link(src_dentry, path, d);
28050 + path->dentry = d;
28051 + if (unlikely(err))
28055 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
28058 + struct path tmp = *path;
28061 + /* fuse has different memory inode for the same inumber */
28062 + vfsub_update_h_iattr(&tmp, &did);
28064 + tmp.dentry = path->dentry->d_parent;
28065 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
28066 + tmp.dentry = src_dentry;
28067 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
28076 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
28077 + struct inode *dir, struct path *path,
28078 + struct inode **delegated_inode)
28081 + struct path tmp = {
28084 + struct dentry *d;
28087 + IMustLock(src_dir);
28089 + d = path->dentry;
28090 + path->dentry = d->d_parent;
28091 + tmp.dentry = src_dentry->d_parent;
28092 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
28093 + path->dentry = d;
28094 + if (unlikely(err))
28098 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
28099 + delegated_inode, /*flags*/0);
28104 + tmp.dentry = d->d_parent;
28105 + vfsub_update_h_iattr(&tmp, &did);
28107 + tmp.dentry = src_dentry;
28108 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
28109 + tmp.dentry = src_dentry->d_parent;
28110 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
28119 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
28122 + struct dentry *d;
28126 + d = path->dentry;
28127 + path->dentry = d->d_parent;
28128 + err = security_path_mkdir(path, d, mode);
28129 + path->dentry = d;
28130 + if (unlikely(err))
28133 + err = vfs_mkdir(dir, path->dentry, mode);
28135 + struct path tmp = *path;
28138 + vfsub_update_h_iattr(&tmp, &did);
28140 + tmp.dentry = path->dentry->d_parent;
28141 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
28150 +int vfsub_rmdir(struct inode *dir, struct path *path)
28153 + struct dentry *d;
28157 + d = path->dentry;
28158 + path->dentry = d->d_parent;
28159 + err = security_path_rmdir(path, d);
28160 + path->dentry = d;
28161 + if (unlikely(err))
28165 + err = vfs_rmdir(dir, path->dentry);
28168 + struct path tmp = {
28169 + .dentry = path->dentry->d_parent,
28173 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
28180 +/* ---------------------------------------------------------------------- */
28182 +/* todo: support mmap_sem? */
28183 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
28189 + err = vfs_read(file, ubuf, count, ppos);
28192 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
28196 +/* todo: kernel_read()? */
28197 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
28201 + mm_segment_t oldfs;
28208 + oldfs = get_fs();
28209 + set_fs(KERNEL_DS);
28210 + err = vfsub_read_u(file, buf.u, count, ppos);
28215 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
28221 + err = vfs_write(file, ubuf, count, ppos);
28224 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
28228 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
28231 + mm_segment_t oldfs;
28234 + const char __user *u;
28238 + oldfs = get_fs();
28239 + set_fs(KERNEL_DS);
28240 + err = vfsub_write_u(file, buf.u, count, ppos);
28245 +int vfsub_flush(struct file *file, fl_owner_t id)
28250 + if (file->f_op->flush) {
28251 + if (!au_test_nfs(file->f_dentry->d_sb))
28252 + err = file->f_op->flush(file, id);
28255 + err = file->f_op->flush(file, id);
28259 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
28265 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
28269 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
28272 + err = iterate_dir(file, ctx);
28275 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
28279 +long vfsub_splice_to(struct file *in, loff_t *ppos,
28280 + struct pipe_inode_info *pipe, size_t len,
28281 + unsigned int flags)
28286 + err = do_splice_to(in, ppos, pipe, len, flags);
28288 + file_accessed(in);
28290 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
28294 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
28295 + loff_t *ppos, size_t len, unsigned int flags)
28300 + err = do_splice_from(pipe, out, ppos, len, flags);
28303 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
28307 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
28311 + /* file can be NULL */
28313 + err = vfs_fsync(file, datasync);
28317 + AuDebugOn(!file);
28318 + path = &file->f_path;
28320 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
28325 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
28326 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
28327 + struct file *h_file)
28330 + struct inode *h_inode;
28331 + struct super_block *h_sb;
28334 + err = vfsub_truncate(h_path, length);
28338 + h_inode = h_path->dentry->d_inode;
28339 + h_sb = h_inode->i_sb;
28341 + sb_start_write(h_sb);
28343 + err = locks_verify_truncate(h_inode, h_file, length);
28345 + err = security_path_truncate(h_path);
28348 + err = do_truncate(h_path->dentry, length, attr, h_file);
28352 + sb_end_write(h_sb);
28359 +/* ---------------------------------------------------------------------- */
28361 +struct au_vfsub_mkdir_args {
28363 + struct inode *dir;
28364 + struct path *path;
28368 +static void au_call_vfsub_mkdir(void *args)
28370 + struct au_vfsub_mkdir_args *a = args;
28371 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
28374 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
28376 + int err, do_sio, wkq_err;
28378 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
28380 + err = vfsub_mkdir(dir, path, mode);
28382 + struct au_vfsub_mkdir_args args = {
28388 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
28389 + if (unlikely(wkq_err))
28396 +struct au_vfsub_rmdir_args {
28398 + struct inode *dir;
28399 + struct path *path;
28402 +static void au_call_vfsub_rmdir(void *args)
28404 + struct au_vfsub_rmdir_args *a = args;
28405 + *a->errp = vfsub_rmdir(a->dir, a->path);
28408 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
28410 + int err, do_sio, wkq_err;
28412 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
28414 + err = vfsub_rmdir(dir, path);
28416 + struct au_vfsub_rmdir_args args = {
28421 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
28422 + if (unlikely(wkq_err))
28429 +/* ---------------------------------------------------------------------- */
28431 +struct notify_change_args {
28433 + struct path *path;
28434 + struct iattr *ia;
28435 + struct inode **delegated_inode;
28438 +static void call_notify_change(void *args)
28440 + struct notify_change_args *a = args;
28441 + struct inode *h_inode;
28443 + h_inode = a->path->dentry->d_inode;
28444 + IMustLock(h_inode);
28446 + *a->errp = -EPERM;
28447 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
28448 + *a->errp = notify_change(a->path->dentry, a->ia,
28449 + a->delegated_inode);
28451 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
28453 + AuTraceErr(*a->errp);
28456 +int vfsub_notify_change(struct path *path, struct iattr *ia,
28457 + struct inode **delegated_inode)
28460 + struct notify_change_args args = {
28464 + .delegated_inode = delegated_inode
28467 + call_notify_change(&args);
28472 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
28473 + struct inode **delegated_inode)
28475 + int err, wkq_err;
28476 + struct notify_change_args args = {
28480 + .delegated_inode = delegated_inode
28483 + wkq_err = au_wkq_wait(call_notify_change, &args);
28484 + if (unlikely(wkq_err))
28490 +/* ---------------------------------------------------------------------- */
28492 +struct unlink_args {
28494 + struct inode *dir;
28495 + struct path *path;
28496 + struct inode **delegated_inode;
28499 +static void call_unlink(void *args)
28501 + struct unlink_args *a = args;
28502 + struct dentry *d = a->path->dentry;
28503 + struct inode *h_inode;
28504 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
28505 + && d_count(d) == 1);
28507 + IMustLock(a->dir);
28509 + a->path->dentry = d->d_parent;
28510 + *a->errp = security_path_unlink(a->path, d);
28511 + a->path->dentry = d;
28512 + if (unlikely(*a->errp))
28515 + if (!stop_sillyrename)
28517 + h_inode = d->d_inode;
28522 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
28525 + struct path tmp = {
28526 + .dentry = d->d_parent,
28527 + .mnt = a->path->mnt
28529 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
28532 + if (!stop_sillyrename)
28537 + AuTraceErr(*a->errp);
28541 + * @dir: must be locked.
28542 + * @dentry: target dentry.
28544 +int vfsub_unlink(struct inode *dir, struct path *path,
28545 + struct inode **delegated_inode, int force)
28548 + struct unlink_args args = {
28552 + .delegated_inode = delegated_inode
28556 + call_unlink(&args);
28560 + wkq_err = au_wkq_wait(call_unlink, &args);
28561 + if (unlikely(wkq_err))
28567 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
28568 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
28569 +++ linux/fs/aufs/vfsub.h 2014-06-24 00:14:06.789386337 +0200
28572 + * Copyright (C) 2005-2014 Junjiro R. Okajima
28574 + * This program, aufs is free software; you can redistribute it and/or modify
28575 + * it under the terms of the GNU General Public License as published by
28576 + * the Free Software Foundation; either version 2 of the License, or
28577 + * (at your option) any later version.
28579 + * This program is distributed in the hope that it will be useful,
28580 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28581 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28582 + * GNU General Public License for more details.
28584 + * You should have received a copy of the GNU General Public License
28585 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28589 + * sub-routines for VFS
28592 +#ifndef __AUFS_VFSUB_H__
28593 +#define __AUFS_VFSUB_H__
28597 +#include <linux/fs.h>
28598 +#include <linux/lglock.h>
28599 +#include <linux/mount.h>
28600 +#include "debug.h"
28602 +/* copied from linux/fs/internal.h */
28603 +/* todo: BAD approach!! */
28604 +extern void __mnt_drop_write(struct vfsmount *);
28605 +extern spinlock_t inode_sb_list_lock;
28607 +/* ---------------------------------------------------------------------- */
28609 +/* lock subclass for lower inode */
28610 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
28611 +/* reduce? gave up. */
28613 + AuLsc_I_Begin = I_MUTEX_NONDIR2, /* 4 */
28614 + AuLsc_I_PARENT, /* lower inode, parent first */
28615 + AuLsc_I_PARENT2, /* copyup dirs */
28616 + AuLsc_I_PARENT3, /* copyup wh */
28622 +/* to debug easier, do not make them inlined functions */
28623 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
28624 +#define IMustLock(i) MtxMustLock(&(i)->i_mutex)
28626 +/* ---------------------------------------------------------------------- */
28628 +static inline void vfsub_drop_nlink(struct inode *inode)
28630 + AuDebugOn(!inode->i_nlink);
28631 + drop_nlink(inode);
28634 +static inline void vfsub_dead_dir(struct inode *inode)
28636 + AuDebugOn(!S_ISDIR(inode->i_mode));
28637 + inode->i_flags |= S_DEAD;
28638 + clear_nlink(inode);
28641 +static inline int vfsub_native_ro(struct inode *inode)
28643 + return (inode->i_sb->s_flags & MS_RDONLY)
28644 + || IS_RDONLY(inode)
28645 + /* || IS_APPEND(inode) */
28646 + || IS_IMMUTABLE(inode);
28649 +/* ---------------------------------------------------------------------- */
28651 +int vfsub_update_h_iattr(struct path *h_path, int *did);
28652 +struct file *vfsub_dentry_open(struct path *path, int flags);
28653 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
28654 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
28656 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
28659 +struct vfsub_lkup_one_args {
28660 + struct dentry **errp;
28661 + struct qstr *name;
28662 + struct dentry *parent;
28665 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
28666 + struct dentry *parent)
28668 + return vfsub_lookup_one_len(name->name, parent, name->len);
28671 +void vfsub_call_lkup_one(void *args);
28673 +/* ---------------------------------------------------------------------- */
28675 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
28679 + err = mnt_want_write(mnt);
28684 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
28687 + mnt_drop_write(mnt);
28691 +static inline void vfsub_mnt_drop_write_file(struct file *file)
28694 + mnt_drop_write_file(file);
28698 +/* ---------------------------------------------------------------------- */
28701 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
28702 + struct dentry *d2, struct au_hinode *hdir2);
28703 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
28704 + struct dentry *d2, struct au_hinode *hdir2);
28706 +int vfsub_create(struct inode *dir, struct path *path, int mode,
28708 +int vfsub_symlink(struct inode *dir, struct path *path,
28709 + const char *symname);
28710 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
28711 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
28712 + struct path *path, struct inode **delegated_inode);
28713 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
28714 + struct inode *hdir, struct path *path,
28715 + struct inode **delegated_inode);
28716 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
28717 +int vfsub_rmdir(struct inode *dir, struct path *path);
28719 +/* ---------------------------------------------------------------------- */
28721 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
28723 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
28725 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
28727 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
28729 +int vfsub_flush(struct file *file, fl_owner_t id);
28730 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
28732 +/* just for type-check */
28733 +static inline filldir_t au_diractor(int (*func)(struct dir_context *,
28734 + const char *, int, loff_t, u64,
28737 + return (filldir_t)func;
28741 +static inline loff_t vfsub_f_size_read(struct file *file)
28743 + return i_size_read(file_inode(file));
28746 +static inline unsigned int vfsub_file_flags(struct file *file)
28748 + unsigned int flags;
28750 + spin_lock(&file->f_lock);
28751 + flags = file->f_flags;
28752 + spin_unlock(&file->f_lock);
28757 +static inline void vfsub_file_accessed(struct file *h_file)
28759 + file_accessed(h_file);
28760 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
28763 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
28764 + struct dentry *h_dentry)
28766 + struct path h_path = {
28767 + .dentry = h_dentry,
28770 + touch_atime(&h_path);
28771 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
28774 +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts,
28777 + return update_time(h_inode, ts, flags);
28778 + /* no vfsub_update_h_iattr() since we don't have struct path */
28781 +long vfsub_splice_to(struct file *in, loff_t *ppos,
28782 + struct pipe_inode_info *pipe, size_t len,
28783 + unsigned int flags);
28784 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
28785 + loff_t *ppos, size_t len, unsigned int flags);
28787 +static inline long vfsub_truncate(struct path *path, loff_t length)
28791 + err = vfs_truncate(path, length);
28796 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
28797 + struct file *h_file);
28798 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
28800 +/* ---------------------------------------------------------------------- */
28802 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
28807 + err = vfs_llseek(file, offset, origin);
28812 +/* ---------------------------------------------------------------------- */
28814 +/* dirty workaround for strict type of fmode_t */
28820 +static inline unsigned int vfsub_fmode_to_uint(fmode_t fm)
28822 + union vfsub_fmu u = {
28826 + BUILD_BUG_ON(sizeof(u.fm) != sizeof(u.ui));
28831 +static inline fmode_t vfsub_uint_to_fmode(unsigned int ui)
28833 + union vfsub_fmu u = {
28840 +/* ---------------------------------------------------------------------- */
28842 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
28843 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
28844 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
28845 + struct inode **delegated_inode);
28846 +int vfsub_notify_change(struct path *path, struct iattr *ia,
28847 + struct inode **delegated_inode);
28848 +int vfsub_unlink(struct inode *dir, struct path *path,
28849 + struct inode **delegated_inode, int force);
28851 +#endif /* __KERNEL__ */
28852 +#endif /* __AUFS_VFSUB_H__ */
28853 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
28854 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
28855 +++ linux/fs/aufs/wbr_policy.c 2014-06-24 00:14:06.789386337 +0200
28858 + * Copyright (C) 2005-2014 Junjiro R. Okajima
28860 + * This program, aufs is free software; you can redistribute it and/or modify
28861 + * it under the terms of the GNU General Public License as published by
28862 + * the Free Software Foundation; either version 2 of the License, or
28863 + * (at your option) any later version.
28865 + * This program is distributed in the hope that it will be useful,
28866 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28867 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28868 + * GNU General Public License for more details.
28870 + * You should have received a copy of the GNU General Public License
28871 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28875 + * policies for selecting one among multiple writable branches
28878 +#include <linux/statfs.h>
28881 +/* subset of cpup_attr() */
28882 +static noinline_for_stack
28883 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
28887 + struct inode *h_isrc;
28889 + h_isrc = h_src->d_inode;
28890 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
28891 + ia.ia_mode = h_isrc->i_mode;
28892 + ia.ia_uid = h_isrc->i_uid;
28893 + ia.ia_gid = h_isrc->i_gid;
28894 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
28895 + au_cpup_attr_flags(h_path->dentry->d_inode, h_isrc->i_flags);
28896 + /* no delegation since it is just created */
28897 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
28899 + /* is this nfs only? */
28900 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
28901 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
28902 + ia.ia_mode = h_isrc->i_mode;
28903 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
28909 +#define AuCpdown_PARENT_OPQ 1
28910 +#define AuCpdown_WHED (1 << 1)
28911 +#define AuCpdown_MADE_DIR (1 << 2)
28912 +#define AuCpdown_DIROPQ (1 << 3)
28913 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
28914 +#define au_fset_cpdown(flags, name) \
28915 + do { (flags) |= AuCpdown_##name; } while (0)
28916 +#define au_fclr_cpdown(flags, name) \
28917 + do { (flags) &= ~AuCpdown_##name; } while (0)
28919 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
28920 + unsigned int *flags)
28923 + struct dentry *opq_dentry;
28925 + opq_dentry = au_diropq_create(dentry, bdst);
28926 + err = PTR_ERR(opq_dentry);
28927 + if (IS_ERR(opq_dentry))
28929 + dput(opq_dentry);
28930 + au_fset_cpdown(*flags, DIROPQ);
28936 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
28937 + struct inode *dir, aufs_bindex_t bdst)
28940 + struct path h_path;
28941 + struct au_branch *br;
28943 + br = au_sbr(dentry->d_sb, bdst);
28944 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
28945 + err = PTR_ERR(h_path.dentry);
28946 + if (IS_ERR(h_path.dentry))
28950 + if (h_path.dentry->d_inode) {
28951 + h_path.mnt = au_br_mnt(br);
28952 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
28955 + dput(h_path.dentry);
28961 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
28962 + struct au_pin *pin,
28963 + struct dentry *h_parent, void *arg)
28966 + aufs_bindex_t bopq, bstart;
28967 + struct path h_path;
28968 + struct dentry *parent;
28969 + struct inode *h_dir, *h_inode, *inode, *dir;
28970 + unsigned int *flags = arg;
28972 + bstart = au_dbstart(dentry);
28973 + /* dentry is di-locked */
28974 + parent = dget_parent(dentry);
28975 + dir = parent->d_inode;
28976 + h_dir = h_parent->d_inode;
28977 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
28978 + IMustLock(h_dir);
28980 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
28981 + if (unlikely(err < 0))
28983 + h_path.dentry = au_h_dptr(dentry, bdst);
28984 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
28985 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path,
28986 + S_IRWXU | S_IRUGO | S_IXUGO);
28987 + if (unlikely(err))
28989 + au_fset_cpdown(*flags, MADE_DIR);
28991 + bopq = au_dbdiropq(dentry);
28992 + au_fclr_cpdown(*flags, WHED);
28993 + au_fclr_cpdown(*flags, DIROPQ);
28994 + if (au_dbwh(dentry) == bdst)
28995 + au_fset_cpdown(*flags, WHED);
28996 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
28997 + au_fset_cpdown(*flags, PARENT_OPQ);
28998 + h_inode = h_path.dentry->d_inode;
28999 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
29000 + if (au_ftest_cpdown(*flags, WHED)) {
29001 + err = au_cpdown_dir_opq(dentry, bdst, flags);
29002 + if (unlikely(err)) {
29003 + mutex_unlock(&h_inode->i_mutex);
29008 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, bstart));
29009 + mutex_unlock(&h_inode->i_mutex);
29010 + if (unlikely(err))
29013 + if (au_ftest_cpdown(*flags, WHED)) {
29014 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
29015 + if (unlikely(err))
29019 + inode = dentry->d_inode;
29020 + if (au_ibend(inode) < bdst)
29021 + au_set_ibend(inode, bdst);
29022 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
29023 + au_hi_flags(inode, /*isdir*/1));
29024 + goto out; /* success */
29028 + if (au_ftest_cpdown(*flags, DIROPQ)) {
29029 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
29030 + rerr = au_diropq_remove(dentry, bdst);
29031 + mutex_unlock(&h_inode->i_mutex);
29032 + if (unlikely(rerr)) {
29033 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
29034 + dentry, bdst, rerr);
29040 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
29041 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
29042 + if (unlikely(rerr)) {
29043 + AuIOErr("failed removing %pd b%d (%d)\n",
29044 + dentry, bdst, rerr);
29049 + au_set_h_dptr(dentry, bdst, NULL);
29050 + if (au_dbend(dentry) == bdst)
29051 + au_update_dbend(dentry);
29057 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
29060 + unsigned int flags;
29063 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
29068 +/* ---------------------------------------------------------------------- */
29070 +/* policies for create */
29072 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
29074 + int err, i, j, ndentry;
29075 + aufs_bindex_t bopq;
29076 + struct au_dcsub_pages dpages;
29077 + struct au_dpage *dpage;
29078 + struct dentry **dentries, *parent, *d;
29080 + err = au_dpages_init(&dpages, GFP_NOFS);
29081 + if (unlikely(err))
29083 + parent = dget_parent(dentry);
29084 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
29085 + if (unlikely(err))
29089 + for (i = 0; i < dpages.ndpage; i++) {
29090 + dpage = dpages.dpages + i;
29091 + dentries = dpage->dentries;
29092 + ndentry = dpage->ndentry;
29093 + for (j = 0; j < ndentry; j++) {
29095 + di_read_lock_parent2(d, !AuLock_IR);
29096 + bopq = au_dbdiropq(d);
29097 + di_read_unlock(d, !AuLock_IR);
29098 + if (bopq >= 0 && bopq < err)
29105 + au_dpages_free(&dpages);
29110 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
29112 + for (; bindex >= 0; bindex--)
29113 + if (!au_br_rdonly(au_sbr(sb, bindex)))
29118 +/* top down parent */
29119 +static int au_wbr_create_tdp(struct dentry *dentry,
29120 + unsigned int flags __maybe_unused)
29123 + aufs_bindex_t bstart, bindex;
29124 + struct super_block *sb;
29125 + struct dentry *parent, *h_parent;
29127 + sb = dentry->d_sb;
29128 + bstart = au_dbstart(dentry);
29130 + if (!au_br_rdonly(au_sbr(sb, bstart)))
29134 + parent = dget_parent(dentry);
29135 + for (bindex = au_dbstart(parent); bindex < bstart; bindex++) {
29136 + h_parent = au_h_dptr(parent, bindex);
29137 + if (!h_parent || !h_parent->d_inode)
29140 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
29147 + /* bottom up here */
29148 + if (unlikely(err < 0)) {
29149 + err = au_wbr_bu(sb, bstart - 1);
29151 + err = au_wbr_nonopq(dentry, err);
29155 + AuDbg("b%d\n", err);
29159 +/* ---------------------------------------------------------------------- */
29161 +/* an exception for the policy other than tdp */
29162 +static int au_wbr_create_exp(struct dentry *dentry)
29165 + aufs_bindex_t bwh, bdiropq;
29166 + struct dentry *parent;
29169 + bwh = au_dbwh(dentry);
29170 + parent = dget_parent(dentry);
29171 + bdiropq = au_dbdiropq(parent);
29173 + if (bdiropq >= 0)
29174 + err = min(bdiropq, bwh);
29177 + AuDbg("%d\n", err);
29178 + } else if (bdiropq >= 0) {
29180 + AuDbg("%d\n", err);
29185 + err = au_wbr_nonopq(dentry, err);
29187 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
29190 + AuDbg("%d\n", err);
29194 +/* ---------------------------------------------------------------------- */
29197 +static int au_wbr_create_init_rr(struct super_block *sb)
29201 + err = au_wbr_bu(sb, au_sbend(sb));
29202 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
29205 + AuDbg("b%d\n", err);
29209 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
29213 + aufs_bindex_t bindex, bend;
29214 + struct super_block *sb;
29217 + err = au_wbr_create_exp(dentry);
29221 + sb = dentry->d_sb;
29222 + next = &au_sbi(sb)->si_wbr_rr_next;
29223 + bend = au_sbend(sb);
29225 + for (bindex = 0; bindex <= bend; bindex++) {
29226 + if (!au_ftest_wbr(flags, DIR)) {
29227 + err = atomic_dec_return(next) + 1;
29228 + /* modulo for 0 is meaningless */
29229 + if (unlikely(!err))
29230 + err = atomic_dec_return(next) + 1;
29232 + err = atomic_read(next);
29233 + AuDbg("%d\n", err);
29236 + AuDbg("%d\n", err);
29237 + if (!au_br_rdonly(au_sbr(sb, err)))
29243 + err = au_wbr_nonopq(dentry, err);
29246 + AuDbg("%d\n", err);
29250 +/* ---------------------------------------------------------------------- */
29252 +/* most free space */
29253 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
29255 + struct super_block *sb;
29256 + struct au_branch *br;
29257 + struct au_wbr_mfs *mfs;
29258 + struct dentry *h_parent;
29259 + aufs_bindex_t bindex, bend;
29261 + unsigned long long b, bavail;
29262 + struct path h_path;
29263 + /* reduce the stack usage */
29264 + struct kstatfs *st;
29266 + st = kmalloc(sizeof(*st), GFP_NOFS);
29267 + if (unlikely(!st)) {
29268 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
29273 + sb = dentry->d_sb;
29274 + mfs = &au_sbi(sb)->si_wbr_mfs;
29275 + MtxMustLock(&mfs->mfs_lock);
29276 + mfs->mfs_bindex = -EROFS;
29277 + mfs->mfsrr_bytes = 0;
29280 + bend = au_sbend(sb);
29282 + bindex = au_dbstart(parent);
29283 + bend = au_dbtaildir(parent);
29286 + for (; bindex <= bend; bindex++) {
29288 + h_parent = au_h_dptr(parent, bindex);
29289 + if (!h_parent || !h_parent->d_inode)
29292 + br = au_sbr(sb, bindex);
29293 + if (au_br_rdonly(br))
29296 + /* sb->s_root for NFS is unreliable */
29297 + h_path.mnt = au_br_mnt(br);
29298 + h_path.dentry = h_path.mnt->mnt_root;
29299 + err = vfs_statfs(&h_path, st);
29300 + if (unlikely(err)) {
29301 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
29305 + /* when the available size is equal, select the lower one */
29306 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
29307 + || sizeof(b) < sizeof(st->f_bsize));
29308 + b = st->f_bavail * st->f_bsize;
29309 + br->br_wbr->wbr_bytes = b;
29310 + if (b >= bavail) {
29312 + mfs->mfs_bindex = bindex;
29313 + mfs->mfs_jiffy = jiffies;
29317 + mfs->mfsrr_bytes = bavail;
29318 + AuDbg("b%d\n", mfs->mfs_bindex);
29322 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
29325 + struct dentry *parent;
29326 + struct super_block *sb;
29327 + struct au_wbr_mfs *mfs;
29329 + err = au_wbr_create_exp(dentry);
29333 + sb = dentry->d_sb;
29335 + if (au_ftest_wbr(flags, PARENT))
29336 + parent = dget_parent(dentry);
29337 + mfs = &au_sbi(sb)->si_wbr_mfs;
29338 + mutex_lock(&mfs->mfs_lock);
29339 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
29340 + || mfs->mfs_bindex < 0
29341 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
29342 + au_mfs(dentry, parent);
29343 + mutex_unlock(&mfs->mfs_lock);
29344 + err = mfs->mfs_bindex;
29348 + err = au_wbr_nonopq(dentry, err);
29351 + AuDbg("b%d\n", err);
29355 +static int au_wbr_create_init_mfs(struct super_block *sb)
29357 + struct au_wbr_mfs *mfs;
29359 + mfs = &au_sbi(sb)->si_wbr_mfs;
29360 + mutex_init(&mfs->mfs_lock);
29361 + mfs->mfs_jiffy = 0;
29362 + mfs->mfs_bindex = -EROFS;
29367 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
29369 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
29373 +/* ---------------------------------------------------------------------- */
29375 +/* most free space and then round robin */
29376 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
29379 + struct au_wbr_mfs *mfs;
29381 + err = au_wbr_create_mfs(dentry, flags);
29383 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
29384 + mutex_lock(&mfs->mfs_lock);
29385 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
29386 + err = au_wbr_create_rr(dentry, flags);
29387 + mutex_unlock(&mfs->mfs_lock);
29390 + AuDbg("b%d\n", err);
29394 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
29398 + au_wbr_create_init_mfs(sb); /* ignore */
29399 + err = au_wbr_create_init_rr(sb);
29404 +/* ---------------------------------------------------------------------- */
29406 +/* top down parent and most free space */
29407 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
29410 + unsigned long long b;
29411 + aufs_bindex_t bindex, bstart, bend;
29412 + struct super_block *sb;
29413 + struct dentry *parent, *h_parent;
29414 + struct au_branch *br;
29416 + err = au_wbr_create_tdp(dentry, flags);
29417 + if (unlikely(err < 0))
29419 + parent = dget_parent(dentry);
29420 + bstart = au_dbstart(parent);
29421 + bend = au_dbtaildir(parent);
29422 + if (bstart == bend)
29423 + goto out_parent; /* success */
29425 + e2 = au_wbr_create_mfs(dentry, flags);
29427 + goto out_parent; /* success */
29429 + /* when the available size is equal, select upper one */
29430 + sb = dentry->d_sb;
29431 + br = au_sbr(sb, err);
29432 + b = br->br_wbr->wbr_bytes;
29433 + AuDbg("b%d, %llu\n", err, b);
29435 + for (bindex = bstart; bindex <= bend; bindex++) {
29436 + h_parent = au_h_dptr(parent, bindex);
29437 + if (!h_parent || !h_parent->d_inode)
29440 + br = au_sbr(sb, bindex);
29441 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
29442 + b = br->br_wbr->wbr_bytes;
29444 + AuDbg("b%d, %llu\n", err, b);
29449 + err = au_wbr_nonopq(dentry, err);
29454 + AuDbg("b%d\n", err);
29458 +/* ---------------------------------------------------------------------- */
29461 + * - top down parent
29462 + * - most free space with parent
29463 + * - most free space round-robin regardless parent
29465 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
29468 + unsigned long long watermark;
29469 + struct super_block *sb;
29470 + struct au_branch *br;
29471 + struct au_wbr_mfs *mfs;
29473 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
29474 + if (unlikely(err < 0))
29477 + sb = dentry->d_sb;
29478 + br = au_sbr(sb, err);
29479 + mfs = &au_sbi(sb)->si_wbr_mfs;
29480 + mutex_lock(&mfs->mfs_lock);
29481 + watermark = mfs->mfsrr_watermark;
29482 + mutex_unlock(&mfs->mfs_lock);
29483 + if (br->br_wbr->wbr_bytes < watermark)
29484 + /* regardless the parent dir */
29485 + err = au_wbr_create_mfsrr(dentry, flags);
29488 + AuDbg("b%d\n", err);
29492 +/* ---------------------------------------------------------------------- */
29494 +/* policies for copyup */
29496 +/* top down parent */
29497 +static int au_wbr_copyup_tdp(struct dentry *dentry)
29499 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
29502 +/* bottom up parent */
29503 +static int au_wbr_copyup_bup(struct dentry *dentry)
29506 + aufs_bindex_t bindex, bstart;
29507 + struct dentry *parent, *h_parent;
29508 + struct super_block *sb;
29511 + sb = dentry->d_sb;
29512 + parent = dget_parent(dentry);
29513 + bstart = au_dbstart(parent);
29514 + for (bindex = au_dbstart(dentry); bindex >= bstart; bindex--) {
29515 + h_parent = au_h_dptr(parent, bindex);
29516 + if (!h_parent || !h_parent->d_inode)
29519 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
29526 + /* bottom up here */
29527 + if (unlikely(err < 0))
29528 + err = au_wbr_bu(sb, bstart - 1);
29530 + AuDbg("b%d\n", err);
29535 +static int au_wbr_copyup_bu(struct dentry *dentry)
29538 + aufs_bindex_t bstart;
29540 + bstart = au_dbstart(dentry);
29541 + err = au_wbr_bu(dentry->d_sb, bstart);
29542 + AuDbg("b%d\n", err);
29543 + if (err > bstart)
29544 + err = au_wbr_nonopq(dentry, err);
29546 + AuDbg("b%d\n", err);
29550 +/* ---------------------------------------------------------------------- */
29552 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
29553 + [AuWbrCopyup_TDP] = {
29554 + .copyup = au_wbr_copyup_tdp
29556 + [AuWbrCopyup_BUP] = {
29557 + .copyup = au_wbr_copyup_bup
29559 + [AuWbrCopyup_BU] = {
29560 + .copyup = au_wbr_copyup_bu
29564 +struct au_wbr_create_operations au_wbr_create_ops[] = {
29565 + [AuWbrCreate_TDP] = {
29566 + .create = au_wbr_create_tdp
29568 + [AuWbrCreate_RR] = {
29569 + .create = au_wbr_create_rr,
29570 + .init = au_wbr_create_init_rr
29572 + [AuWbrCreate_MFS] = {
29573 + .create = au_wbr_create_mfs,
29574 + .init = au_wbr_create_init_mfs,
29575 + .fin = au_wbr_create_fin_mfs
29577 + [AuWbrCreate_MFSV] = {
29578 + .create = au_wbr_create_mfs,
29579 + .init = au_wbr_create_init_mfs,
29580 + .fin = au_wbr_create_fin_mfs
29582 + [AuWbrCreate_MFSRR] = {
29583 + .create = au_wbr_create_mfsrr,
29584 + .init = au_wbr_create_init_mfsrr,
29585 + .fin = au_wbr_create_fin_mfs
29587 + [AuWbrCreate_MFSRRV] = {
29588 + .create = au_wbr_create_mfsrr,
29589 + .init = au_wbr_create_init_mfsrr,
29590 + .fin = au_wbr_create_fin_mfs
29592 + [AuWbrCreate_PMFS] = {
29593 + .create = au_wbr_create_pmfs,
29594 + .init = au_wbr_create_init_mfs,
29595 + .fin = au_wbr_create_fin_mfs
29597 + [AuWbrCreate_PMFSV] = {
29598 + .create = au_wbr_create_pmfs,
29599 + .init = au_wbr_create_init_mfs,
29600 + .fin = au_wbr_create_fin_mfs
29602 + [AuWbrCreate_PMFSRR] = {
29603 + .create = au_wbr_create_pmfsrr,
29604 + .init = au_wbr_create_init_mfsrr,
29605 + .fin = au_wbr_create_fin_mfs
29607 + [AuWbrCreate_PMFSRRV] = {
29608 + .create = au_wbr_create_pmfsrr,
29609 + .init = au_wbr_create_init_mfsrr,
29610 + .fin = au_wbr_create_fin_mfs
29613 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
29614 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
29615 +++ linux/fs/aufs/whout.c 2014-06-24 00:14:06.789386337 +0200
29618 + * Copyright (C) 2005-2014 Junjiro R. Okajima
29620 + * This program, aufs is free software; you can redistribute it and/or modify
29621 + * it under the terms of the GNU General Public License as published by
29622 + * the Free Software Foundation; either version 2 of the License, or
29623 + * (at your option) any later version.
29625 + * This program is distributed in the hope that it will be useful,
29626 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29627 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29628 + * GNU General Public License for more details.
29630 + * You should have received a copy of the GNU General Public License
29631 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29635 + * whiteout for logical deletion and opaque directory
29640 +#define WH_MASK S_IRUGO
29643 + * If a directory contains this file, then it is opaque. We start with the
29644 + * .wh. flag so that it is blocked by lookup.
29646 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
29647 + sizeof(AUFS_WH_DIROPQ) - 1);
29650 + * generate whiteout name, which is NOT terminated by NULL.
29651 + * @name: original d_name.name
29652 + * @len: original d_name.len
29653 + * @wh: whiteout qstr
29654 + * returns zero when succeeds, otherwise error.
29655 + * succeeded value as wh->name should be freed by kfree().
29657 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
29661 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
29662 + return -ENAMETOOLONG;
29664 + wh->len = name->len + AUFS_WH_PFX_LEN;
29665 + p = kmalloc(wh->len, GFP_NOFS);
29668 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
29669 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
29676 +/* ---------------------------------------------------------------------- */
29679 + * test if the @wh_name exists under @h_parent.
29680 + * @try_sio specifies the necessary of super-io.
29682 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name,
29683 + struct au_branch *br, int try_sio)
29686 + struct dentry *wh_dentry;
29689 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
29691 + wh_dentry = au_sio_lkup_one(wh_name, h_parent, br);
29692 + err = PTR_ERR(wh_dentry);
29693 + if (IS_ERR(wh_dentry))
29697 + if (!wh_dentry->d_inode)
29698 + goto out_wh; /* success */
29701 + if (S_ISREG(wh_dentry->d_inode->i_mode))
29702 + goto out_wh; /* success */
29705 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
29706 + wh_dentry, wh_dentry->d_inode->i_mode);
29715 + * test if the @h_dentry sets opaque or not.
29717 +int au_diropq_test(struct dentry *h_dentry, struct au_branch *br)
29720 + struct inode *h_dir;
29722 + h_dir = h_dentry->d_inode;
29723 + err = au_wh_test(h_dentry, &diropq_name, br,
29724 + au_test_h_perm_sio(h_dir, MAY_EXEC));
29729 + * returns a negative dentry whose name is unique and temporary.
29731 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
29732 + struct qstr *prefix)
29734 + struct dentry *dentry;
29736 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
29738 + /* strict atomic_t is unnecessary here */
29739 + static unsigned short cnt;
29742 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
29745 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
29746 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
29747 + dentry = ERR_PTR(-ENAMETOOLONG);
29748 + if (unlikely(qs.len > NAME_MAX))
29750 + dentry = ERR_PTR(-ENOMEM);
29751 + name = kmalloc(qs.len + 1, GFP_NOFS);
29752 + if (unlikely(!name))
29756 + /* doubly whiteout-ed */
29757 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
29758 + p = name + AUFS_WH_PFX_LEN * 2;
29759 + memcpy(p, prefix->name, prefix->len);
29760 + p += prefix->len;
29762 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
29765 + for (i = 0; i < 3; i++) {
29766 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
29767 + dentry = au_sio_lkup_one(&qs, h_parent, br);
29768 + if (IS_ERR(dentry) || !dentry->d_inode)
29772 + /* pr_warn("could not get random name\n"); */
29773 + dentry = ERR_PTR(-EEXIST);
29774 + AuDbg("%.*s\n", AuLNPair(&qs));
29778 + if (name != defname)
29781 + AuTraceErrPtr(dentry);
29786 + * rename the @h_dentry on @br to the whiteouted temporary name.
29788 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
29791 + struct path h_path = {
29792 + .mnt = au_br_mnt(br)
29794 + struct inode *h_dir, *delegated;
29795 + struct dentry *h_parent;
29797 + h_parent = h_dentry->d_parent; /* dir inode is locked */
29798 + h_dir = h_parent->d_inode;
29799 + IMustLock(h_dir);
29801 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
29802 + err = PTR_ERR(h_path.dentry);
29803 + if (IS_ERR(h_path.dentry))
29806 + /* under the same dir, no need to lock_rename() */
29807 + delegated = NULL;
29808 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated);
29810 + if (unlikely(err == -EWOULDBLOCK)) {
29811 + pr_warn("cannot retry for NFSv4 delegation"
29812 + " for an internal rename\n");
29815 + dput(h_path.dentry);
29822 +/* ---------------------------------------------------------------------- */
29824 + * functions for removing a whiteout
29827 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
29830 + struct inode *delegated;
29833 + * forces superio when the dir has a sticky bit.
29834 + * this may be a violation of unix fs semantics.
29836 + force = (h_dir->i_mode & S_ISVTX)
29837 + && !uid_eq(current_fsuid(), h_path->dentry->d_inode->i_uid);
29838 + delegated = NULL;
29839 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
29840 + if (unlikely(err == -EWOULDBLOCK)) {
29841 + pr_warn("cannot retry for NFSv4 delegation"
29842 + " for an internal unlink\n");
29848 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
29849 + struct dentry *dentry)
29853 + err = do_unlink_wh(h_dir, h_path);
29854 + if (!err && dentry)
29855 + au_set_dbwh(dentry, -1);
29860 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
29861 + struct au_branch *br)
29864 + struct path h_path = {
29865 + .mnt = au_br_mnt(br)
29869 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
29870 + if (IS_ERR(h_path.dentry))
29871 + err = PTR_ERR(h_path.dentry);
29873 + if (h_path.dentry->d_inode
29874 + && S_ISREG(h_path.dentry->d_inode->i_mode))
29875 + err = do_unlink_wh(h_parent->d_inode, &h_path);
29876 + dput(h_path.dentry);
29882 +/* ---------------------------------------------------------------------- */
29884 + * initialize/clean whiteout for a branch
29887 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
29891 + struct inode *delegated;
29893 + if (!whpath->dentry->d_inode)
29897 + err = vfsub_rmdir(h_dir, whpath);
29899 + delegated = NULL;
29900 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
29901 + if (unlikely(err == -EWOULDBLOCK)) {
29902 + pr_warn("cannot retry for NFSv4 delegation"
29903 + " for an internal unlink\n");
29907 + if (unlikely(err))
29908 + pr_warn("failed removing %pd (%d), ignored.\n",
29909 + whpath->dentry, err);
29912 +static int test_linkable(struct dentry *h_root)
29914 + struct inode *h_dir = h_root->d_inode;
29916 + if (h_dir->i_op->link)
29919 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
29920 + h_root, au_sbtype(h_root->d_sb));
29924 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
29925 +static int au_whdir(struct inode *h_dir, struct path *path)
29930 + if (!path->dentry->d_inode) {
29931 + int mode = S_IRWXU;
29933 + if (au_test_nfs(path->dentry->d_sb))
29935 + err = vfsub_mkdir(h_dir, path, mode);
29936 + } else if (S_ISDIR(path->dentry->d_inode->i_mode))
29939 + pr_err("unknown %pd exists\n", path->dentry);
29944 +struct au_wh_base {
29945 + const struct qstr *name;
29946 + struct dentry *dentry;
29949 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
29950 + struct path *h_path)
29952 + h_path->dentry = base[AuBrWh_BASE].dentry;
29953 + au_wh_clean(h_dir, h_path, /*isdir*/0);
29954 + h_path->dentry = base[AuBrWh_PLINK].dentry;
29955 + au_wh_clean(h_dir, h_path, /*isdir*/1);
29956 + h_path->dentry = base[AuBrWh_ORPH].dentry;
29957 + au_wh_clean(h_dir, h_path, /*isdir*/1);
29961 + * returns tri-state,
29962 + * minus: error, caller should print the mesage
29964 + * plus: error, caller should NOT print the mesage
29966 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
29967 + int do_plink, struct au_wh_base base[],
29968 + struct path *h_path)
29971 + struct inode *h_dir;
29973 + h_dir = h_root->d_inode;
29974 + h_path->dentry = base[AuBrWh_BASE].dentry;
29975 + au_wh_clean(h_dir, h_path, /*isdir*/0);
29976 + h_path->dentry = base[AuBrWh_PLINK].dentry;
29978 + err = test_linkable(h_root);
29979 + if (unlikely(err)) {
29984 + err = au_whdir(h_dir, h_path);
29985 + if (unlikely(err))
29987 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
29989 + au_wh_clean(h_dir, h_path, /*isdir*/1);
29990 + h_path->dentry = base[AuBrWh_ORPH].dentry;
29991 + err = au_whdir(h_dir, h_path);
29992 + if (unlikely(err))
29994 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
30001 + * for the moment, aufs supports the branch filesystem which does not support
30002 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
30003 + * copyup failed. finally, such filesystem will not be used as the writable
30006 + * returns tri-state, see above.
30008 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
30009 + int do_plink, struct au_wh_base base[],
30010 + struct path *h_path)
30013 + struct inode *h_dir;
30015 + WbrWhMustWriteLock(wbr);
30017 + err = test_linkable(h_root);
30018 + if (unlikely(err)) {
30024 + * todo: should this create be done in /sbin/mount.aufs helper?
30027 + h_dir = h_root->d_inode;
30028 + if (!base[AuBrWh_BASE].dentry->d_inode) {
30029 + h_path->dentry = base[AuBrWh_BASE].dentry;
30030 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
30031 + } else if (S_ISREG(base[AuBrWh_BASE].dentry->d_inode->i_mode))
30034 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
30035 + if (unlikely(err))
30038 + h_path->dentry = base[AuBrWh_PLINK].dentry;
30040 + err = au_whdir(h_dir, h_path);
30041 + if (unlikely(err))
30043 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
30045 + au_wh_clean(h_dir, h_path, /*isdir*/1);
30046 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
30048 + h_path->dentry = base[AuBrWh_ORPH].dentry;
30049 + err = au_whdir(h_dir, h_path);
30050 + if (unlikely(err))
30052 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
30059 + * initialize the whiteout base file/dir for @br.
30061 +int au_wh_init(struct au_branch *br, struct super_block *sb)
30064 + const unsigned char do_plink
30065 + = !!au_opt_test(au_mntflags(sb), PLINK);
30066 + struct inode *h_dir;
30067 + struct path path = br->br_path;
30068 + struct dentry *h_root = path.dentry;
30069 + struct au_wbr *wbr = br->br_wbr;
30070 + static const struct qstr base_name[] = {
30071 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
30072 + sizeof(AUFS_BASE_NAME) - 1),
30073 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
30074 + sizeof(AUFS_PLINKDIR_NAME) - 1),
30075 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
30076 + sizeof(AUFS_ORPHDIR_NAME) - 1)
30078 + struct au_wh_base base[] = {
30079 + [AuBrWh_BASE] = {
30080 + .name = base_name + AuBrWh_BASE,
30083 + [AuBrWh_PLINK] = {
30084 + .name = base_name + AuBrWh_PLINK,
30087 + [AuBrWh_ORPH] = {
30088 + .name = base_name + AuBrWh_ORPH,
30094 + WbrWhMustWriteLock(wbr);
30096 + for (i = 0; i < AuBrWh_Last; i++) {
30097 + /* doubly whiteouted */
30098 + struct dentry *d;
30100 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
30101 + err = PTR_ERR(d);
30105 + base[i].dentry = d;
30107 + && wbr->wbr_wh[i]
30108 + && wbr->wbr_wh[i] != base[i].dentry);
30112 + for (i = 0; i < AuBrWh_Last; i++) {
30113 + dput(wbr->wbr_wh[i]);
30114 + wbr->wbr_wh[i] = NULL;
30118 + if (!au_br_writable(br->br_perm)) {
30119 + h_dir = h_root->d_inode;
30120 + au_wh_init_ro(h_dir, base, &path);
30121 + } else if (!au_br_wh_linkable(br->br_perm)) {
30122 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
30128 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
30134 + goto out; /* success */
30137 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
30138 + err, h_root, au_sbtype(h_root->d_sb));
30140 + for (i = 0; i < AuBrWh_Last; i++)
30141 + dput(base[i].dentry);
30145 +/* ---------------------------------------------------------------------- */
30147 + * whiteouts are all hard-linked usually.
30148 + * when its link count reaches a ceiling, we create a new whiteout base
30149 + * asynchronously.
30152 +struct reinit_br_wh {
30153 + struct super_block *sb;
30154 + struct au_branch *br;
30157 +static void reinit_br_wh(void *arg)
30160 + aufs_bindex_t bindex;
30161 + struct path h_path;
30162 + struct reinit_br_wh *a = arg;
30163 + struct au_wbr *wbr;
30164 + struct inode *dir, *delegated;
30165 + struct dentry *h_root;
30166 + struct au_hinode *hdir;
30169 + wbr = a->br->br_wbr;
30170 + /* big aufs lock */
30171 + si_noflush_write_lock(a->sb);
30172 + if (!au_br_writable(a->br->br_perm))
30174 + bindex = au_br_index(a->sb, a->br->br_id);
30175 + if (unlikely(bindex < 0))
30178 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
30179 + dir = a->sb->s_root->d_inode;
30180 + hdir = au_hi(dir, bindex);
30181 + h_root = au_h_dptr(a->sb->s_root, bindex);
30182 + AuDebugOn(h_root != au_br_dentry(a->br));
30184 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
30185 + wbr_wh_write_lock(wbr);
30186 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
30189 + h_path.dentry = wbr->wbr_whbase;
30190 + h_path.mnt = au_br_mnt(a->br);
30191 + delegated = NULL;
30192 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
30194 + if (unlikely(err == -EWOULDBLOCK)) {
30195 + pr_warn("cannot retry for NFSv4 delegation"
30196 + " for an internal unlink\n");
30200 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
30203 + dput(wbr->wbr_whbase);
30204 + wbr->wbr_whbase = NULL;
30206 + err = au_wh_init(a->br, a->sb);
30207 + wbr_wh_write_unlock(wbr);
30208 + au_hn_imtx_unlock(hdir);
30209 + di_read_unlock(a->sb->s_root, AuLock_IR);
30213 + atomic_dec(&wbr->wbr_wh_running);
30214 + atomic_dec(&a->br->br_count);
30215 + si_write_unlock(a->sb);
30216 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
30218 + if (unlikely(err))
30219 + AuIOErr("err %d\n", err);
30222 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
30224 + int do_dec, wkq_err;
30225 + struct reinit_br_wh *arg;
30228 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
30231 + /* ignore ENOMEM */
30232 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
30235 + * dec(wh_running), kfree(arg) and dec(br_count)
30236 + * in reinit function
30240 + atomic_inc(&br->br_count);
30241 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
30242 + if (unlikely(wkq_err)) {
30243 + atomic_dec(&br->br_wbr->wbr_wh_running);
30244 + atomic_dec(&br->br_count);
30252 + atomic_dec(&br->br_wbr->wbr_wh_running);
30255 +/* ---------------------------------------------------------------------- */
30258 + * create the whiteout @wh.
30260 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
30261 + struct dentry *wh)
30264 + struct path h_path = {
30267 + struct au_branch *br;
30268 + struct au_wbr *wbr;
30269 + struct dentry *h_parent;
30270 + struct inode *h_dir, *delegated;
30272 + h_parent = wh->d_parent; /* dir inode is locked */
30273 + h_dir = h_parent->d_inode;
30274 + IMustLock(h_dir);
30276 + br = au_sbr(sb, bindex);
30277 + h_path.mnt = au_br_mnt(br);
30278 + wbr = br->br_wbr;
30279 + wbr_wh_read_lock(wbr);
30280 + if (wbr->wbr_whbase) {
30281 + delegated = NULL;
30282 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
30283 + if (unlikely(err == -EWOULDBLOCK)) {
30284 + pr_warn("cannot retry for NFSv4 delegation"
30285 + " for an internal link\n");
30288 + if (!err || err != -EMLINK)
30291 + /* link count full. re-initialize br_whbase. */
30292 + kick_reinit_br_wh(sb, br);
30295 + /* return this error in this context */
30296 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
30299 + wbr_wh_read_unlock(wbr);
30303 +/* ---------------------------------------------------------------------- */
30306 + * create or remove the diropq.
30308 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
30309 + unsigned int flags)
30311 + struct dentry *opq_dentry, *h_dentry;
30312 + struct super_block *sb;
30313 + struct au_branch *br;
30316 + sb = dentry->d_sb;
30317 + br = au_sbr(sb, bindex);
30318 + h_dentry = au_h_dptr(dentry, bindex);
30319 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
30320 + if (IS_ERR(opq_dentry))
30323 + if (au_ftest_diropq(flags, CREATE)) {
30324 + err = link_or_create_wh(sb, bindex, opq_dentry);
30326 + au_set_dbdiropq(dentry, bindex);
30327 + goto out; /* success */
30330 + struct path tmp = {
30331 + .dentry = opq_dentry,
30332 + .mnt = au_br_mnt(br)
30334 + err = do_unlink_wh(au_h_iptr(dentry->d_inode, bindex), &tmp);
30336 + au_set_dbdiropq(dentry, -1);
30338 + dput(opq_dentry);
30339 + opq_dentry = ERR_PTR(err);
30342 + return opq_dentry;
30345 +struct do_diropq_args {
30346 + struct dentry **errp;
30347 + struct dentry *dentry;
30348 + aufs_bindex_t bindex;
30349 + unsigned int flags;
30352 +static void call_do_diropq(void *args)
30354 + struct do_diropq_args *a = args;
30355 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
30358 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
30359 + unsigned int flags)
30361 + struct dentry *diropq, *h_dentry;
30363 + h_dentry = au_h_dptr(dentry, bindex);
30364 + if (!au_test_h_perm_sio(h_dentry->d_inode, MAY_EXEC | MAY_WRITE))
30365 + diropq = do_diropq(dentry, bindex, flags);
30368 + struct do_diropq_args args = {
30370 + .dentry = dentry,
30371 + .bindex = bindex,
30375 + wkq_err = au_wkq_wait(call_do_diropq, &args);
30376 + if (unlikely(wkq_err))
30377 + diropq = ERR_PTR(wkq_err);
30383 +/* ---------------------------------------------------------------------- */
30386 + * lookup whiteout dentry.
30387 + * @h_parent: lower parent dentry which must exist and be locked
30388 + * @base_name: name of dentry which will be whiteouted
30389 + * returns dentry for whiteout.
30391 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
30392 + struct au_branch *br)
30395 + struct qstr wh_name;
30396 + struct dentry *wh_dentry;
30398 + err = au_wh_name_alloc(&wh_name, base_name);
30399 + wh_dentry = ERR_PTR(err);
30401 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
30402 + kfree(wh_name.name);
30404 + return wh_dentry;
30408 + * link/create a whiteout for @dentry on @bindex.
30410 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
30411 + struct dentry *h_parent)
30413 + struct dentry *wh_dentry;
30414 + struct super_block *sb;
30417 + sb = dentry->d_sb;
30418 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
30419 + if (!IS_ERR(wh_dentry) && !wh_dentry->d_inode) {
30420 + err = link_or_create_wh(sb, bindex, wh_dentry);
30422 + au_set_dbwh(dentry, bindex);
30425 + wh_dentry = ERR_PTR(err);
30429 + return wh_dentry;
30432 +/* ---------------------------------------------------------------------- */
30434 +/* Delete all whiteouts in this directory on branch bindex. */
30435 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
30436 + aufs_bindex_t bindex, struct au_branch *br)
30439 + unsigned long ul, n;
30440 + struct qstr wh_name;
30442 + struct hlist_head *head;
30443 + struct au_vdir_wh *pos;
30444 + struct au_vdir_destr *str;
30447 + p = (void *)__get_free_page(GFP_NOFS);
30448 + wh_name.name = p;
30449 + if (unlikely(!wh_name.name))
30453 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
30454 + p += AUFS_WH_PFX_LEN;
30455 + n = whlist->nh_num;
30456 + head = whlist->nh_head;
30457 + for (ul = 0; !err && ul < n; ul++, head++) {
30458 + hlist_for_each_entry(pos, head, wh_hash) {
30459 + if (pos->wh_bindex != bindex)
30462 + str = &pos->wh_str;
30463 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
30464 + memcpy(p, str->name, str->len);
30465 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
30466 + err = unlink_wh_name(h_dentry, &wh_name, br);
30471 + AuIOErr("whiteout name too long %.*s\n",
30472 + str->len, str->name);
30477 + free_page((unsigned long)wh_name.name);
30483 +struct del_wh_children_args {
30485 + struct dentry *h_dentry;
30486 + struct au_nhash *whlist;
30487 + aufs_bindex_t bindex;
30488 + struct au_branch *br;
30491 +static void call_del_wh_children(void *args)
30493 + struct del_wh_children_args *a = args;
30494 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
30497 +/* ---------------------------------------------------------------------- */
30499 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
30501 + struct au_whtmp_rmdir *whtmp;
30503 + unsigned int rdhash;
30505 + SiMustAnyLock(sb);
30507 + whtmp = kmalloc(sizeof(*whtmp), gfp);
30508 + if (unlikely(!whtmp)) {
30509 + whtmp = ERR_PTR(-ENOMEM);
30513 + whtmp->dir = NULL;
30514 + whtmp->br = NULL;
30515 + whtmp->wh_dentry = NULL;
30516 + /* no estimation for dir size */
30517 + rdhash = au_sbi(sb)->si_rdhash;
30519 + rdhash = AUFS_RDHASH_DEF;
30520 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
30521 + if (unlikely(err)) {
30523 + whtmp = ERR_PTR(err);
30530 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
30533 + atomic_dec(&whtmp->br->br_count);
30534 + dput(whtmp->wh_dentry);
30535 + iput(whtmp->dir);
30536 + au_nhash_wh_free(&whtmp->whlist);
30541 + * rmdir the whiteouted temporary named dir @h_dentry.
30542 + * @whlist: whiteouted children.
30544 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
30545 + struct dentry *wh_dentry, struct au_nhash *whlist)
30548 + struct path h_tmp;
30549 + struct inode *wh_inode, *h_dir;
30550 + struct au_branch *br;
30552 + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
30553 + IMustLock(h_dir);
30555 + br = au_sbr(dir->i_sb, bindex);
30556 + wh_inode = wh_dentry->d_inode;
30557 + mutex_lock_nested(&wh_inode->i_mutex, AuLsc_I_CHILD);
30560 + * someone else might change some whiteouts while we were sleeping.
30561 + * it means this whlist may have an obsoleted entry.
30563 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
30564 + err = del_wh_children(wh_dentry, whlist, bindex, br);
30567 + struct del_wh_children_args args = {
30569 + .h_dentry = wh_dentry,
30570 + .whlist = whlist,
30571 + .bindex = bindex,
30575 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
30576 + if (unlikely(wkq_err))
30579 + mutex_unlock(&wh_inode->i_mutex);
30582 + h_tmp.dentry = wh_dentry;
30583 + h_tmp.mnt = au_br_mnt(br);
30584 + err = vfsub_rmdir(h_dir, &h_tmp);
30588 + if (au_ibstart(dir) == bindex) {
30589 + /* todo: dir->i_mutex is necessary */
30590 + au_cpup_attr_timesizes(dir);
30591 + vfsub_drop_nlink(dir);
30593 + return 0; /* success */
30596 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
30600 +static void call_rmdir_whtmp(void *args)
30603 + aufs_bindex_t bindex;
30604 + struct au_whtmp_rmdir *a = args;
30605 + struct super_block *sb;
30606 + struct dentry *h_parent;
30607 + struct inode *h_dir;
30608 + struct au_hinode *hdir;
30610 + /* rmdir by nfsd may cause deadlock with this i_mutex */
30611 + /* mutex_lock(&a->dir->i_mutex); */
30613 + sb = a->dir->i_sb;
30614 + si_read_lock(sb, !AuLock_FLUSH);
30615 + if (!au_br_writable(a->br->br_perm))
30617 + bindex = au_br_index(sb, a->br->br_id);
30618 + if (unlikely(bindex < 0))
30622 + ii_write_lock_parent(a->dir);
30623 + h_parent = dget_parent(a->wh_dentry);
30624 + h_dir = h_parent->d_inode;
30625 + hdir = au_hi(a->dir, bindex);
30626 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
30627 + if (unlikely(err))
30629 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
30630 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
30633 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
30634 + au_hn_imtx_unlock(hdir);
30635 + vfsub_mnt_drop_write(au_br_mnt(a->br));
30639 + ii_write_unlock(a->dir);
30641 + /* mutex_unlock(&a->dir->i_mutex); */
30642 + au_whtmp_rmdir_free(a);
30643 + si_read_unlock(sb);
30644 + au_nwt_done(&au_sbi(sb)->si_nowait);
30645 + if (unlikely(err))
30646 + AuIOErr("err %d\n", err);
30649 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
30650 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
30653 + struct super_block *sb;
30657 + /* all post-process will be done in do_rmdir_whtmp(). */
30659 + args->dir = au_igrab(dir);
30660 + args->br = au_sbr(sb, bindex);
30661 + atomic_inc(&args->br->br_count);
30662 + args->wh_dentry = dget(wh_dentry);
30663 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
30664 + if (unlikely(wkq_err)) {
30665 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
30666 + au_whtmp_rmdir_free(args);
30669 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
30670 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
30671 +++ linux/fs/aufs/whout.h 2014-06-24 00:14:06.789386337 +0200
30674 + * Copyright (C) 2005-2014 Junjiro R. Okajima
30676 + * This program, aufs is free software; you can redistribute it and/or modify
30677 + * it under the terms of the GNU General Public License as published by
30678 + * the Free Software Foundation; either version 2 of the License, or
30679 + * (at your option) any later version.
30681 + * This program is distributed in the hope that it will be useful,
30682 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30683 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30684 + * GNU General Public License for more details.
30686 + * You should have received a copy of the GNU General Public License
30687 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30691 + * whiteout for logical deletion and opaque directory
30694 +#ifndef __AUFS_WHOUT_H__
30695 +#define __AUFS_WHOUT_H__
30702 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
30704 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name,
30705 + struct au_branch *br, int try_sio);
30706 +int au_diropq_test(struct dentry *h_dentry, struct au_branch *br);
30707 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
30708 + struct qstr *prefix);
30709 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
30710 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
30711 + struct dentry *dentry);
30712 +int au_wh_init(struct au_branch *br, struct super_block *sb);
30714 +/* diropq flags */
30715 +#define AuDiropq_CREATE 1
30716 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
30717 +#define au_fset_diropq(flags, name) \
30718 + do { (flags) |= AuDiropq_##name; } while (0)
30719 +#define au_fclr_diropq(flags, name) \
30720 + do { (flags) &= ~AuDiropq_##name; } while (0)
30722 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
30723 + unsigned int flags);
30724 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
30725 + struct au_branch *br);
30726 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
30727 + struct dentry *h_parent);
30729 +/* real rmdir for the whiteout-ed dir */
30730 +struct au_whtmp_rmdir {
30731 + struct inode *dir;
30732 + struct au_branch *br;
30733 + struct dentry *wh_dentry;
30734 + struct au_nhash whlist;
30737 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
30738 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
30739 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
30740 + struct dentry *wh_dentry, struct au_nhash *whlist);
30741 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
30742 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
30744 +/* ---------------------------------------------------------------------- */
30746 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
30747 + aufs_bindex_t bindex)
30749 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
30752 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
30754 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
30757 +#endif /* __KERNEL__ */
30758 +#endif /* __AUFS_WHOUT_H__ */
30759 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
30760 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
30761 +++ linux/fs/aufs/wkq.c 2014-06-24 00:14:06.789386337 +0200
30764 + * Copyright (C) 2005-2014 Junjiro R. Okajima
30766 + * This program, aufs is free software; you can redistribute it and/or modify
30767 + * it under the terms of the GNU General Public License as published by
30768 + * the Free Software Foundation; either version 2 of the License, or
30769 + * (at your option) any later version.
30771 + * This program is distributed in the hope that it will be useful,
30772 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30773 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30774 + * GNU General Public License for more details.
30776 + * You should have received a copy of the GNU General Public License
30777 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30781 + * workqueue for asynchronous/super-io operations
30782 + * todo: try new dredential scheme
30785 +#include <linux/module.h>
30788 +/* internal workqueue named AUFS_WKQ_NAME */
30790 +static struct workqueue_struct *au_wkq;
30792 +struct au_wkinfo {
30793 + struct work_struct wk;
30794 + struct kobject *kobj;
30796 + unsigned int flags; /* see wkq.h */
30798 + au_wkq_func_t func;
30801 + struct completion *comp;
30804 +/* ---------------------------------------------------------------------- */
30806 +static void wkq_func(struct work_struct *wk)
30808 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
30810 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
30811 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
30813 + wkinfo->func(wkinfo->args);
30814 + if (au_ftest_wkq(wkinfo->flags, WAIT))
30815 + complete(wkinfo->comp);
30817 + kobject_put(wkinfo->kobj);
30818 + module_put(THIS_MODULE); /* todo: ?? */
30824 + * Since struct completion is large, try allocating it dynamically.
30826 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
30827 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
30829 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
30831 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
30833 + init_completion(*comp);
30834 + wkinfo->comp = *comp;
30840 +static void au_wkq_comp_free(struct completion *comp)
30848 +#define AuWkqCompDeclare(name) \
30849 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
30850 + struct completion *comp = &_ ## name
30852 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
30854 + wkinfo->comp = *comp;
30858 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
30862 +#endif /* 4KSTACKS */
30864 +static void au_wkq_run(struct au_wkinfo *wkinfo)
30866 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
30867 + if (au_wkq_test()) {
30868 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
30869 + " due to a dead dir by UDBA?\n");
30870 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
30873 + au_dbg_verify_kthread();
30875 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
30876 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
30877 + queue_work(au_wkq, &wkinfo->wk);
30879 + INIT_WORK(&wkinfo->wk, wkq_func);
30880 + schedule_work(&wkinfo->wk);
30885 + * Be careful. It is easy to make deadlock happen.
30886 + * processA: lock, wkq and wait
30887 + * processB: wkq and wait, lock in wkq
30890 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
30893 + AuWkqCompDeclare(comp);
30894 + struct au_wkinfo wkinfo = {
30900 + err = au_wkq_comp_alloc(&wkinfo, &comp);
30902 + au_wkq_run(&wkinfo);
30903 + /* no timeout, no interrupt */
30904 + wait_for_completion(wkinfo.comp);
30905 + au_wkq_comp_free(comp);
30906 + destroy_work_on_stack(&wkinfo.wk);
30914 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
30915 + * problem in a concurrent umounting.
30917 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
30918 + unsigned int flags)
30921 + struct au_wkinfo *wkinfo;
30923 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
30926 + * wkq_func() must free this wkinfo.
30927 + * it highly depends upon the implementation of workqueue.
30930 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
30932 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
30933 + wkinfo->flags = flags & ~AuWkq_WAIT;
30934 + wkinfo->func = func;
30935 + wkinfo->args = args;
30936 + wkinfo->comp = NULL;
30937 + kobject_get(wkinfo->kobj);
30938 + __module_get(THIS_MODULE); /* todo: ?? */
30940 + au_wkq_run(wkinfo);
30943 + au_nwt_done(&au_sbi(sb)->si_nowait);
30949 +/* ---------------------------------------------------------------------- */
30951 +void au_nwt_init(struct au_nowait_tasks *nwt)
30953 + atomic_set(&nwt->nw_len, 0);
30954 + /* smp_mb(); */ /* atomic_set */
30955 + init_waitqueue_head(&nwt->nw_wq);
30958 +void au_wkq_fin(void)
30960 + destroy_workqueue(au_wkq);
30963 +int __init au_wkq_init(void)
30968 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
30969 + if (IS_ERR(au_wkq))
30970 + err = PTR_ERR(au_wkq);
30971 + else if (!au_wkq)
30976 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
30977 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
30978 +++ linux/fs/aufs/wkq.h 2014-06-24 00:14:06.789386337 +0200
30981 + * Copyright (C) 2005-2014 Junjiro R. Okajima
30983 + * This program, aufs is free software; you can redistribute it and/or modify
30984 + * it under the terms of the GNU General Public License as published by
30985 + * the Free Software Foundation; either version 2 of the License, or
30986 + * (at your option) any later version.
30988 + * This program is distributed in the hope that it will be useful,
30989 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30990 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30991 + * GNU General Public License for more details.
30993 + * You should have received a copy of the GNU General Public License
30994 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30998 + * workqueue for asynchronous/super-io operations
30999 + * todo: try new credentials management scheme
31002 +#ifndef __AUFS_WKQ_H__
31003 +#define __AUFS_WKQ_H__
31007 +struct super_block;
31009 +/* ---------------------------------------------------------------------- */
31012 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
31014 +struct au_nowait_tasks {
31016 + wait_queue_head_t nw_wq;
31019 +/* ---------------------------------------------------------------------- */
31021 +typedef void (*au_wkq_func_t)(void *args);
31024 +#define AuWkq_WAIT 1
31025 +#define AuWkq_NEST (1 << 1)
31026 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
31027 +#define au_fset_wkq(flags, name) \
31028 + do { (flags) |= AuWkq_##name; } while (0)
31029 +#define au_fclr_wkq(flags, name) \
31030 + do { (flags) &= ~AuWkq_##name; } while (0)
31032 +#ifndef CONFIG_AUFS_HNOTIFY
31034 +#define AuWkq_NEST 0
31038 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
31039 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
31040 + unsigned int flags);
31041 +void au_nwt_init(struct au_nowait_tasks *nwt);
31042 +int __init au_wkq_init(void);
31043 +void au_wkq_fin(void);
31045 +/* ---------------------------------------------------------------------- */
31047 +static inline int au_wkq_test(void)
31049 + return current->flags & PF_WQ_WORKER;
31052 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
31054 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
31057 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
31059 + if (atomic_dec_and_test(&nwt->nw_len))
31060 + wake_up_all(&nwt->nw_wq);
31063 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
31065 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
31069 +#endif /* __KERNEL__ */
31070 +#endif /* __AUFS_WKQ_H__ */
31071 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
31072 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
31073 +++ linux/fs/aufs/xino.c 2014-06-24 00:14:06.792719853 +0200
31076 + * Copyright (C) 2005-2014 Junjiro R. Okajima
31078 + * This program, aufs is free software; you can redistribute it and/or modify
31079 + * it under the terms of the GNU General Public License as published by
31080 + * the Free Software Foundation; either version 2 of the License, or
31081 + * (at your option) any later version.
31083 + * This program is distributed in the hope that it will be useful,
31084 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31085 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31086 + * GNU General Public License for more details.
31088 + * You should have received a copy of the GNU General Public License
31089 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31093 + * external inode number translation table and bitmap
31096 +#include <linux/seq_file.h>
31097 +#include <linux/statfs.h>
31100 +/* todo: unnecessary to support mmap_sem since kernel-space? */
31101 +ssize_t xino_fread(au_readf_t func, struct file *file, void *kbuf, size_t size,
31105 + mm_segment_t oldfs;
31112 + oldfs = get_fs();
31113 + set_fs(KERNEL_DS);
31115 + /* todo: signal_pending? */
31116 + err = func(file, buf.u, size, pos);
31117 + } while (err == -EAGAIN || err == -EINTR);
31120 +#if 0 /* reserved for future use */
31122 + fsnotify_access(file->f_dentry);
31128 +/* ---------------------------------------------------------------------- */
31130 +static ssize_t do_xino_fwrite(au_writef_t func, struct file *file, void *kbuf,
31131 + size_t size, loff_t *pos)
31134 + mm_segment_t oldfs;
31137 + const char __user *u;
31141 + oldfs = get_fs();
31142 + set_fs(KERNEL_DS);
31144 + /* todo: signal_pending? */
31145 + err = func(file, buf.u, size, pos);
31146 + } while (err == -EAGAIN || err == -EINTR);
31149 +#if 0 /* reserved for future use */
31151 + fsnotify_modify(file->f_dentry);
31157 +struct do_xino_fwrite_args {
31159 + au_writef_t func;
31160 + struct file *file;
31166 +static void call_do_xino_fwrite(void *args)
31168 + struct do_xino_fwrite_args *a = args;
31169 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
31172 +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size,
31177 + /* todo: signal block and no wkq? */
31178 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
31180 + err = do_xino_fwrite(func, file, buf, size, pos);
31184 + * it breaks RLIMIT_FSIZE and normal user's limit,
31185 + * users should care about quota and real 'filesystem full.'
31188 + struct do_xino_fwrite_args args = {
31197 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
31198 + if (unlikely(wkq_err))
31205 +/* ---------------------------------------------------------------------- */
31208 + * create a new xinofile at the same place/path as @base_file.
31210 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src)
31212 + struct file *file;
31213 + struct dentry *base, *parent;
31214 + struct inode *dir, *delegated;
31215 + struct qstr *name;
31216 + struct path path;
31219 + base = base_file->f_dentry;
31220 + parent = base->d_parent; /* dir inode is locked */
31221 + dir = parent->d_inode;
31224 + file = ERR_PTR(-EINVAL);
31225 + name = &base->d_name;
31226 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
31227 + if (IS_ERR(path.dentry)) {
31228 + file = (void *)path.dentry;
31229 + pr_err("%pd lookup err %ld\n",
31230 + base, PTR_ERR(path.dentry));
31234 + /* no need to mnt_want_write() since we call dentry_open() later */
31235 + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL);
31236 + if (unlikely(err)) {
31237 + file = ERR_PTR(err);
31238 + pr_err("%pd create err %d\n", base, err);
31242 + path.mnt = base_file->f_path.mnt;
31243 + file = vfsub_dentry_open(&path,
31244 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
31245 + /* | __FMODE_NONOTIFY */);
31246 + if (IS_ERR(file)) {
31247 + pr_err("%pd open err %ld\n", base, PTR_ERR(file));
31251 + delegated = NULL;
31252 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
31253 + if (unlikely(err == -EWOULDBLOCK)) {
31254 + pr_warn("cannot retry for NFSv4 delegation"
31255 + " for an internal unlink\n");
31258 + if (unlikely(err)) {
31259 + pr_err("%pd unlink err %d\n", base, err);
31264 + /* no one can touch copy_src xino */
31265 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
31266 + if (unlikely(err)) {
31267 + pr_err("%pd copy err %d\n", base, err);
31271 + goto out_dput; /* success */
31275 + file = ERR_PTR(err);
31277 + dput(path.dentry);
31282 +struct au_xino_lock_dir {
31283 + struct au_hinode *hdir;
31284 + struct dentry *parent;
31285 + struct mutex *mtx;
31288 +static void au_xino_lock_dir(struct super_block *sb, struct file *xino,
31289 + struct au_xino_lock_dir *ldir)
31291 + aufs_bindex_t brid, bindex;
31293 + ldir->hdir = NULL;
31295 + brid = au_xino_brid(sb);
31297 + bindex = au_br_index(sb, brid);
31298 + if (bindex >= 0) {
31299 + ldir->hdir = au_hi(sb->s_root->d_inode, bindex);
31300 + au_hn_imtx_lock_nested(ldir->hdir, AuLsc_I_PARENT);
31302 + ldir->parent = dget_parent(xino->f_dentry);
31303 + ldir->mtx = &ldir->parent->d_inode->i_mutex;
31304 + mutex_lock_nested(ldir->mtx, AuLsc_I_PARENT);
31308 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
31311 + au_hn_imtx_unlock(ldir->hdir);
31313 + mutex_unlock(ldir->mtx);
31314 + dput(ldir->parent);
31318 +/* ---------------------------------------------------------------------- */
31320 +/* trucate xino files asynchronously */
31322 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
31325 + unsigned long jiffy;
31327 + aufs_bindex_t bi, bend;
31328 + struct kstatfs *st;
31329 + struct au_branch *br;
31330 + struct file *new_xino, *file;
31331 + struct super_block *h_sb;
31332 + struct au_xino_lock_dir ldir;
31335 + st = kzalloc(sizeof(*st), GFP_NOFS);
31336 + if (unlikely(!st))
31340 + bend = au_sbend(sb);
31341 + if (unlikely(bindex < 0 || bend < bindex))
31343 + br = au_sbr(sb, bindex);
31344 + file = br->br_xino.xi_file;
31348 + err = vfs_statfs(&file->f_path, st);
31349 + if (unlikely(err))
31350 + AuErr1("statfs err %d, ignored\n", err);
31352 + blocks = file_inode(file)->i_blocks;
31353 + pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
31354 + bindex, (u64)blocks, st->f_bfree, st->f_blocks);
31356 + au_xino_lock_dir(sb, file, &ldir);
31357 + /* mnt_want_write() is unnecessary here */
31358 + new_xino = au_xino_create2(file, file);
31359 + au_xino_unlock_dir(&ldir);
31360 + err = PTR_ERR(new_xino);
31361 + if (IS_ERR(new_xino)) {
31362 + pr_err("err %d, ignored\n", err);
31367 + br->br_xino.xi_file = new_xino;
31369 + h_sb = au_br_sb(br);
31370 + for (bi = 0; bi <= bend; bi++) {
31371 + if (unlikely(bi == bindex))
31373 + br = au_sbr(sb, bi);
31374 + if (au_br_sb(br) != h_sb)
31377 + fput(br->br_xino.xi_file);
31378 + br->br_xino.xi_file = new_xino;
31379 + get_file(new_xino);
31382 + err = vfs_statfs(&new_xino->f_path, st);
31384 + pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
31385 + bindex, (u64)file_inode(new_xino)->i_blocks,
31386 + st->f_bfree, st->f_blocks);
31387 + if (file_inode(new_xino)->i_blocks < blocks)
31388 + au_sbi(sb)->si_xino_jiffy = jiffy;
31390 + AuErr1("statfs err %d, ignored\n", err);
31398 +struct xino_do_trunc_args {
31399 + struct super_block *sb;
31400 + struct au_branch *br;
31403 +static void xino_do_trunc(void *_args)
31405 + struct xino_do_trunc_args *args = _args;
31406 + struct super_block *sb;
31407 + struct au_branch *br;
31408 + struct inode *dir;
31410 + aufs_bindex_t bindex;
31414 + dir = sb->s_root->d_inode;
31417 + si_noflush_write_lock(sb);
31418 + ii_read_lock_parent(dir);
31419 + bindex = au_br_index(sb, br->br_id);
31420 + err = au_xino_trunc(sb, bindex);
31421 + ii_read_unlock(dir);
31422 + if (unlikely(err))
31423 + pr_warn("err b%d, (%d)\n", bindex, err);
31424 + atomic_dec(&br->br_xino_running);
31425 + atomic_dec(&br->br_count);
31426 + si_write_unlock(sb);
31427 + au_nwt_done(&au_sbi(sb)->si_nowait);
31431 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
31434 + struct kstatfs st;
31435 + struct au_sbinfo *sbinfo;
31437 + /* todo: si_xino_expire and the ratio should be customizable */
31438 + sbinfo = au_sbi(sb);
31439 + if (time_before(jiffies,
31440 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
31443 + /* truncation border */
31444 + err = vfs_statfs(&br->br_xino.xi_file->f_path, &st);
31445 + if (unlikely(err)) {
31446 + AuErr1("statfs err %d, ignored\n", err);
31449 + if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC)
31455 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
31457 + struct xino_do_trunc_args *args;
31460 + if (!xino_trunc_test(sb, br))
31463 + if (atomic_inc_return(&br->br_xino_running) > 1)
31466 + /* lock and kfree() will be called in trunc_xino() */
31467 + args = kmalloc(sizeof(*args), GFP_NOFS);
31468 + if (unlikely(!args)) {
31469 + AuErr1("no memory\n");
31473 + atomic_inc(&br->br_count);
31476 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
31478 + return; /* success */
31480 + pr_err("wkq %d\n", wkq_err);
31481 + atomic_dec(&br->br_count);
31486 + atomic_dec(&br->br_xino_running);
31489 +/* ---------------------------------------------------------------------- */
31491 +static int au_xino_do_write(au_writef_t write, struct file *file,
31492 + ino_t h_ino, ino_t ino)
31498 + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) {
31499 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
31502 + pos *= sizeof(ino);
31503 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos);
31504 + if (sz == sizeof(ino))
31505 + return 0; /* success */
31507 + AuIOErr("write failed (%zd)\n", sz);
31512 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
31513 + * at the position of @h_ino.
31514 + * even if @ino is zero, it is written to the xinofile and means no entry.
31515 + * if the size of the xino file on a specific filesystem exceeds the watermark,
31516 + * try truncating it.
31518 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
31522 + unsigned int mnt_flags;
31523 + struct au_branch *br;
31525 + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max)
31526 + || ((loff_t)-1) > 0);
31527 + SiMustAnyLock(sb);
31529 + mnt_flags = au_mntflags(sb);
31530 + if (!au_opt_test(mnt_flags, XINO))
31533 + br = au_sbr(sb, bindex);
31534 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
31537 + if (au_opt_test(mnt_flags, TRUNC_XINO)
31538 + && au_test_fs_trunc_xino(au_br_sb(br)))
31539 + xino_try_trunc(sb, br);
31540 + return 0; /* success */
31543 + AuIOErr("write failed (%d)\n", err);
31547 +/* ---------------------------------------------------------------------- */
31549 +/* aufs inode number bitmap */
31551 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
31552 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
31556 + AuDebugOn(bit < 0 || page_bits <= bit);
31557 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
31561 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
31563 + AuDebugOn(ino < AUFS_FIRST_INO);
31564 + ino -= AUFS_FIRST_INO;
31565 + *pindex = ino / page_bits;
31566 + *bit = ino % page_bits;
31569 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
31574 + struct au_sbinfo *sbinfo;
31575 + struct file *xib;
31576 + unsigned long *p;
31578 + sbinfo = au_sbi(sb);
31579 + MtxMustLock(&sbinfo->si_xib_mtx);
31580 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
31581 + || !au_opt_test(sbinfo->si_mntflags, XINO));
31583 + if (pindex == sbinfo->si_xib_last_pindex)
31586 + xib = sbinfo->si_xib;
31587 + p = sbinfo->si_xib_buf;
31588 + pos = sbinfo->si_xib_last_pindex;
31589 + pos *= PAGE_SIZE;
31590 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
31591 + if (unlikely(sz != PAGE_SIZE))
31595 + pos *= PAGE_SIZE;
31596 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
31597 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
31599 + memset(p, 0, PAGE_SIZE);
31600 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
31602 + if (sz == PAGE_SIZE) {
31603 + sbinfo->si_xib_last_pindex = pindex;
31604 + return 0; /* success */
31608 + AuIOErr1("write failed (%zd)\n", sz);
31615 +/* ---------------------------------------------------------------------- */
31617 +static void au_xib_clear_bit(struct inode *inode)
31620 + unsigned long pindex;
31621 + struct super_block *sb;
31622 + struct au_sbinfo *sbinfo;
31624 + AuDebugOn(inode->i_nlink);
31626 + sb = inode->i_sb;
31627 + xib_calc_bit(inode->i_ino, &pindex, &bit);
31628 + AuDebugOn(page_bits <= bit);
31629 + sbinfo = au_sbi(sb);
31630 + mutex_lock(&sbinfo->si_xib_mtx);
31631 + err = xib_pindex(sb, pindex);
31633 + clear_bit(bit, sbinfo->si_xib_buf);
31634 + sbinfo->si_xib_next_bit = bit;
31636 + mutex_unlock(&sbinfo->si_xib_mtx);
31639 +/* for s_op->delete_inode() */
31640 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
31643 + unsigned int mnt_flags;
31644 + aufs_bindex_t bindex, bend, bi;
31645 + unsigned char try_trunc;
31646 + struct au_iinfo *iinfo;
31647 + struct super_block *sb;
31648 + struct au_hinode *hi;
31649 + struct inode *h_inode;
31650 + struct au_branch *br;
31651 + au_writef_t xwrite;
31653 + sb = inode->i_sb;
31654 + mnt_flags = au_mntflags(sb);
31655 + if (!au_opt_test(mnt_flags, XINO)
31656 + || inode->i_ino == AUFS_ROOT_INO)
31660 + au_xigen_inc(inode);
31661 + au_xib_clear_bit(inode);
31664 + iinfo = au_ii(inode);
31668 + bindex = iinfo->ii_bstart;
31672 + xwrite = au_sbi(sb)->si_xwrite;
31673 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
31674 + hi = iinfo->ii_hinode + bindex;
31675 + bend = iinfo->ii_bend;
31676 + for (; bindex <= bend; bindex++, hi++) {
31677 + h_inode = hi->hi_inode;
31679 + || (!unlinked && h_inode->i_nlink))
31682 + /* inode may not be revalidated */
31683 + bi = au_br_index(sb, hi->hi_id);
31687 + br = au_sbr(sb, bi);
31688 + err = au_xino_do_write(xwrite, br->br_xino.xi_file,
31689 + h_inode->i_ino, /*ino*/0);
31690 + if (!err && try_trunc
31691 + && au_test_fs_trunc_xino(au_br_sb(br)))
31692 + xino_try_trunc(sb, br);
31696 +/* get an unused inode number from bitmap */
31697 +ino_t au_xino_new_ino(struct super_block *sb)
31700 + unsigned long *p, pindex, ul, pend;
31701 + struct au_sbinfo *sbinfo;
31702 + struct file *file;
31703 + int free_bit, err;
31705 + if (!au_opt_test(au_mntflags(sb), XINO))
31706 + return iunique(sb, AUFS_FIRST_INO);
31708 + sbinfo = au_sbi(sb);
31709 + mutex_lock(&sbinfo->si_xib_mtx);
31710 + p = sbinfo->si_xib_buf;
31711 + free_bit = sbinfo->si_xib_next_bit;
31712 + if (free_bit < page_bits && !test_bit(free_bit, p))
31713 + goto out; /* success */
31714 + free_bit = find_first_zero_bit(p, page_bits);
31715 + if (free_bit < page_bits)
31716 + goto out; /* success */
31718 + pindex = sbinfo->si_xib_last_pindex;
31719 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
31720 + err = xib_pindex(sb, ul);
31721 + if (unlikely(err))
31723 + free_bit = find_first_zero_bit(p, page_bits);
31724 + if (free_bit < page_bits)
31725 + goto out; /* success */
31728 + file = sbinfo->si_xib;
31729 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
31730 + for (ul = pindex + 1; ul <= pend; ul++) {
31731 + err = xib_pindex(sb, ul);
31732 + if (unlikely(err))
31734 + free_bit = find_first_zero_bit(p, page_bits);
31735 + if (free_bit < page_bits)
31736 + goto out; /* success */
31741 + set_bit(free_bit, p);
31742 + sbinfo->si_xib_next_bit = free_bit + 1;
31743 + pindex = sbinfo->si_xib_last_pindex;
31744 + mutex_unlock(&sbinfo->si_xib_mtx);
31745 + ino = xib_calc_ino(pindex, free_bit);
31746 + AuDbg("i%lu\n", (unsigned long)ino);
31749 + mutex_unlock(&sbinfo->si_xib_mtx);
31755 + * read @ino from xinofile for the specified branch{@sb, @bindex}
31756 + * at the position of @h_ino.
31757 + * if @ino does not exist and @do_new is true, get new one.
31759 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
31765 + struct file *file;
31766 + struct au_sbinfo *sbinfo;
31769 + if (!au_opt_test(au_mntflags(sb), XINO))
31770 + return 0; /* no xino */
31773 + sbinfo = au_sbi(sb);
31775 + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) {
31776 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
31779 + pos *= sizeof(*ino);
31781 + file = au_sbr(sb, bindex)->br_xino.xi_file;
31782 + if (vfsub_f_size_read(file) < pos + sizeof(*ino))
31783 + return 0; /* no ino */
31785 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
31786 + if (sz == sizeof(*ino))
31787 + return 0; /* success */
31790 + if (unlikely(sz >= 0)) {
31792 + AuIOErr("xino read error (%zd)\n", sz);
31798 +/* ---------------------------------------------------------------------- */
31800 +/* create and set a new xino file */
31802 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent)
31804 + struct file *file;
31805 + struct dentry *h_parent, *d;
31806 + struct inode *h_dir;
31810 + * at mount-time, and the xino file is the default path,
31811 + * hnotify is disabled so we have no notify events to ignore.
31812 + * when a user specified the xino, we cannot get au_hdir to be ignored.
31814 + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
31815 + /* | __FMODE_NONOTIFY */,
31816 + S_IRUGO | S_IWUGO);
31817 + if (IS_ERR(file)) {
31819 + pr_err("open %s(%ld)\n", fname, PTR_ERR(file));
31823 + /* keep file count */
31824 + h_parent = dget_parent(file->f_dentry);
31825 + h_dir = h_parent->d_inode;
31826 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
31827 + /* mnt_want_write() is unnecessary here */
31828 + /* no delegation since it is just created */
31829 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL, /*force*/0);
31830 + mutex_unlock(&h_dir->i_mutex);
31832 + if (unlikely(err)) {
31834 + pr_err("unlink %s(%d)\n", fname, err);
31839 + d = file->f_dentry;
31840 + if (unlikely(sb == d->d_sb)) {
31842 + pr_err("%s must be outside\n", fname);
31845 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
31847 + pr_err("xino doesn't support %s(%s)\n",
31848 + fname, au_sbtype(d->d_sb));
31851 + return file; /* success */
31855 + file = ERR_PTR(err);
31860 + * find another branch who is on the same filesystem of the specified
31861 + * branch{@btgt}. search until @bend.
31863 +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
31864 + aufs_bindex_t bend)
31866 + aufs_bindex_t bindex;
31867 + struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
31869 + for (bindex = 0; bindex < btgt; bindex++)
31870 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
31872 + for (bindex++; bindex <= bend; bindex++)
31873 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
31878 +/* ---------------------------------------------------------------------- */
31881 + * initialize the xinofile for the specified branch @br
31882 + * at the place/path where @base_file indicates.
31883 + * test whether another branch is on the same filesystem or not,
31884 + * if @do_test is true.
31886 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
31887 + struct file *base_file, int do_test)
31891 + aufs_bindex_t bend, bindex;
31892 + struct au_branch *shared_br, *b;
31893 + struct file *file;
31894 + struct super_block *tgt_sb;
31896 + shared_br = NULL;
31897 + bend = au_sbend(sb);
31899 + tgt_sb = au_br_sb(br);
31900 + for (bindex = 0; bindex <= bend; bindex++) {
31901 + b = au_sbr(sb, bindex);
31902 + if (tgt_sb == au_br_sb(b)) {
31909 + if (!shared_br || !shared_br->br_xino.xi_file) {
31910 + struct au_xino_lock_dir ldir;
31912 + au_xino_lock_dir(sb, base_file, &ldir);
31913 + /* mnt_want_write() is unnecessary here */
31914 + file = au_xino_create2(base_file, NULL);
31915 + au_xino_unlock_dir(&ldir);
31916 + err = PTR_ERR(file);
31917 + if (IS_ERR(file))
31919 + br->br_xino.xi_file = file;
31921 + br->br_xino.xi_file = shared_br->br_xino.xi_file;
31922 + get_file(br->br_xino.xi_file);
31925 + ino = AUFS_ROOT_INO;
31926 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
31928 + if (unlikely(err)) {
31929 + fput(br->br_xino.xi_file);
31930 + br->br_xino.xi_file = NULL;
31937 +/* ---------------------------------------------------------------------- */
31939 +/* trucate a xino bitmap file */
31942 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
31946 + unsigned long pindex;
31947 + loff_t pos, pend;
31948 + struct au_sbinfo *sbinfo;
31951 + unsigned long *p;
31954 + sbinfo = au_sbi(sb);
31955 + MtxMustLock(&sbinfo->si_xib_mtx);
31956 + p = sbinfo->si_xib_buf;
31957 + func = sbinfo->si_xread;
31958 + pend = vfsub_f_size_read(file);
31960 + while (pos < pend) {
31961 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
31963 + if (unlikely(sz <= 0))
31967 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
31968 + if (unlikely(*ino < AUFS_FIRST_INO))
31971 + xib_calc_bit(*ino, &pindex, &bit);
31972 + AuDebugOn(page_bits <= bit);
31973 + err = xib_pindex(sb, pindex);
31985 +static int xib_restore(struct super_block *sb)
31988 + aufs_bindex_t bindex, bend;
31992 + page = (void *)__get_free_page(GFP_NOFS);
31993 + if (unlikely(!page))
31997 + bend = au_sbend(sb);
31998 + for (bindex = 0; !err && bindex <= bend; bindex++)
31999 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
32000 + err = do_xib_restore
32001 + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page);
32003 + AuDbg("b%d\n", bindex);
32004 + free_page((unsigned long)page);
32010 +int au_xib_trunc(struct super_block *sb)
32015 + struct au_xino_lock_dir ldir;
32016 + struct au_sbinfo *sbinfo;
32017 + unsigned long *p;
32018 + struct file *file;
32020 + SiMustWriteLock(sb);
32023 + sbinfo = au_sbi(sb);
32024 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
32027 + file = sbinfo->si_xib;
32028 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
32031 + au_xino_lock_dir(sb, file, &ldir);
32032 + /* mnt_want_write() is unnecessary here */
32033 + file = au_xino_create2(sbinfo->si_xib, NULL);
32034 + au_xino_unlock_dir(&ldir);
32035 + err = PTR_ERR(file);
32036 + if (IS_ERR(file))
32038 + fput(sbinfo->si_xib);
32039 + sbinfo->si_xib = file;
32041 + p = sbinfo->si_xib_buf;
32042 + memset(p, 0, PAGE_SIZE);
32044 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
32045 + if (unlikely(sz != PAGE_SIZE)) {
32047 + AuIOErr("err %d\n", err);
32053 + mutex_lock(&sbinfo->si_xib_mtx);
32054 + /* mnt_want_write() is unnecessary here */
32055 + err = xib_restore(sb);
32056 + mutex_unlock(&sbinfo->si_xib_mtx);
32062 +/* ---------------------------------------------------------------------- */
32065 + * xino mount option handlers
32067 +static au_readf_t find_readf(struct file *h_file)
32069 + const struct file_operations *fop = h_file->f_op;
32072 + return fop->read;
32073 + if (fop->aio_read)
32074 + return do_sync_read;
32075 + return ERR_PTR(-ENOSYS);
32078 +static au_writef_t find_writef(struct file *h_file)
32080 + const struct file_operations *fop = h_file->f_op;
32083 + return fop->write;
32084 + if (fop->aio_write)
32085 + return do_sync_write;
32086 + return ERR_PTR(-ENOSYS);
32090 +static void xino_clear_xib(struct super_block *sb)
32092 + struct au_sbinfo *sbinfo;
32094 + SiMustWriteLock(sb);
32096 + sbinfo = au_sbi(sb);
32097 + sbinfo->si_xread = NULL;
32098 + sbinfo->si_xwrite = NULL;
32099 + if (sbinfo->si_xib)
32100 + fput(sbinfo->si_xib);
32101 + sbinfo->si_xib = NULL;
32102 + free_page((unsigned long)sbinfo->si_xib_buf);
32103 + sbinfo->si_xib_buf = NULL;
32106 +static int au_xino_set_xib(struct super_block *sb, struct file *base)
32110 + struct au_sbinfo *sbinfo;
32111 + struct file *file;
32113 + SiMustWriteLock(sb);
32115 + sbinfo = au_sbi(sb);
32116 + file = au_xino_create2(base, sbinfo->si_xib);
32117 + err = PTR_ERR(file);
32118 + if (IS_ERR(file))
32120 + if (sbinfo->si_xib)
32121 + fput(sbinfo->si_xib);
32122 + sbinfo->si_xib = file;
32123 + sbinfo->si_xread = find_readf(file);
32124 + sbinfo->si_xwrite = find_writef(file);
32127 + if (!sbinfo->si_xib_buf)
32128 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
32129 + if (unlikely(!sbinfo->si_xib_buf))
32132 + sbinfo->si_xib_last_pindex = 0;
32133 + sbinfo->si_xib_next_bit = 0;
32134 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
32136 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
32137 + PAGE_SIZE, &pos);
32138 + if (unlikely(err != PAGE_SIZE))
32142 + goto out; /* success */
32145 + free_page((unsigned long)sbinfo->si_xib_buf);
32146 + sbinfo->si_xib_buf = NULL;
32150 + fput(sbinfo->si_xib);
32151 + sbinfo->si_xib = NULL;
32152 + sbinfo->si_xread = NULL;
32153 + sbinfo->si_xwrite = NULL;
32158 +/* xino for each branch */
32159 +static void xino_clear_br(struct super_block *sb)
32161 + aufs_bindex_t bindex, bend;
32162 + struct au_branch *br;
32164 + bend = au_sbend(sb);
32165 + for (bindex = 0; bindex <= bend; bindex++) {
32166 + br = au_sbr(sb, bindex);
32167 + if (!br || !br->br_xino.xi_file)
32170 + fput(br->br_xino.xi_file);
32171 + br->br_xino.xi_file = NULL;
32175 +static int au_xino_set_br(struct super_block *sb, struct file *base)
32179 + aufs_bindex_t bindex, bend, bshared;
32181 + struct file *old, *new;
32183 + struct au_branch *br;
32184 + struct inode *inode;
32185 + au_writef_t writef;
32187 + SiMustWriteLock(sb);
32190 + bend = au_sbend(sb);
32191 + fpair = kcalloc(bend + 1, sizeof(*fpair), GFP_NOFS);
32192 + if (unlikely(!fpair))
32195 + inode = sb->s_root->d_inode;
32196 + ino = AUFS_ROOT_INO;
32197 + writef = au_sbi(sb)->si_xwrite;
32198 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
32199 + br = au_sbr(sb, bindex);
32200 + bshared = is_sb_shared(sb, bindex, bindex - 1);
32201 + if (bshared >= 0) {
32202 + /* shared xino */
32203 + *p = fpair[bshared];
32204 + get_file(p->new);
32209 + p->old = br->br_xino.xi_file;
32210 + p->new = au_xino_create2(base, br->br_xino.xi_file);
32211 + err = PTR_ERR(p->new);
32212 + if (IS_ERR(p->new)) {
32218 + err = au_xino_do_write(writef, p->new,
32219 + au_h_iptr(inode, bindex)->i_ino, ino);
32220 + if (unlikely(err))
32224 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
32225 + br = au_sbr(sb, bindex);
32226 + if (br->br_xino.xi_file)
32227 + fput(br->br_xino.xi_file);
32228 + get_file(p->new);
32229 + br->br_xino.xi_file = p->new;
32233 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++)
32243 +void au_xino_clr(struct super_block *sb)
32245 + struct au_sbinfo *sbinfo;
32247 + au_xigen_clr(sb);
32248 + xino_clear_xib(sb);
32249 + xino_clear_br(sb);
32250 + sbinfo = au_sbi(sb);
32251 + /* lvalue, do not call au_mntflags() */
32252 + au_opt_clr(sbinfo->si_mntflags, XINO);
32255 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
32258 + struct dentry *parent, *cur_parent;
32259 + struct qstr *dname, *cur_name;
32260 + struct file *cur_xino;
32261 + struct inode *dir;
32262 + struct au_sbinfo *sbinfo;
32264 + SiMustWriteLock(sb);
32267 + sbinfo = au_sbi(sb);
32268 + parent = dget_parent(xino->file->f_dentry);
32271 + dname = &xino->file->f_dentry->d_name;
32272 + cur_xino = sbinfo->si_xib;
32274 + cur_parent = dget_parent(cur_xino->f_dentry);
32275 + cur_name = &cur_xino->f_dentry->d_name;
32276 + skip = (cur_parent == parent
32277 + && au_qstreq(dname, cur_name));
32278 + dput(cur_parent);
32284 + au_opt_set(sbinfo->si_mntflags, XINO);
32285 + dir = parent->d_inode;
32286 + mutex_lock_nested(&dir->i_mutex, AuLsc_I_PARENT);
32287 + /* mnt_want_write() is unnecessary here */
32288 + err = au_xino_set_xib(sb, xino->file);
32290 + err = au_xigen_set(sb, xino->file);
32292 + err = au_xino_set_br(sb, xino->file);
32293 + mutex_unlock(&dir->i_mutex);
32295 + goto out; /* success */
32298 + AuIOErr("failed creating xino(%d).\n", err);
32305 +/* ---------------------------------------------------------------------- */
32308 + * create a xinofile at the default place/path.
32310 +struct file *au_xino_def(struct super_block *sb)
32312 + struct file *file;
32314 + struct au_branch *br;
32315 + struct super_block *h_sb;
32316 + struct path path;
32317 + aufs_bindex_t bend, bindex, bwr;
32320 + bend = au_sbend(sb);
32322 + for (bindex = 0; bindex <= bend; bindex++) {
32323 + br = au_sbr(sb, bindex);
32324 + if (au_br_writable(br->br_perm)
32325 + && !au_test_fs_bad_xino(au_br_sb(br))) {
32332 + file = ERR_PTR(-ENOMEM);
32333 + page = (void *)__get_free_page(GFP_NOFS);
32334 + if (unlikely(!page))
32336 + path.mnt = au_br_mnt(br);
32337 + path.dentry = au_h_dptr(sb->s_root, bwr);
32338 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
32339 + file = (void *)p;
32340 + if (!IS_ERR(p)) {
32341 + strcat(p, "/" AUFS_XINO_FNAME);
32342 + AuDbg("%s\n", p);
32343 + file = au_xino_create(sb, p, /*silent*/0);
32344 + if (!IS_ERR(file))
32345 + au_xino_brid_set(sb, br->br_id);
32347 + free_page((unsigned long)page);
32349 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
32350 + if (IS_ERR(file))
32352 + h_sb = file->f_dentry->d_sb;
32353 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
32354 + pr_err("xino doesn't support %s(%s)\n",
32355 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
32357 + file = ERR_PTR(-EINVAL);
32359 + if (!IS_ERR(file))
32360 + au_xino_brid_set(sb, -1);
32367 +/* ---------------------------------------------------------------------- */
32369 +int au_xino_path(struct seq_file *seq, struct file *file)
32373 + err = au_seq_path(seq, &file->f_path);
32374 + if (unlikely(err < 0))
32378 +#define Deleted "\\040(deleted)"
32379 + seq->count -= sizeof(Deleted) - 1;
32380 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
32381 + sizeof(Deleted) - 1));
32387 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
32388 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
32389 +++ linux/include/uapi/linux/aufs_type.h 2014-06-24 00:14:06.792719853 +0200
32392 + * Copyright (C) 2005-2014 Junjiro R. Okajima
32394 + * This program, aufs is free software; you can redistribute it and/or modify
32395 + * it under the terms of the GNU General Public License as published by
32396 + * the Free Software Foundation; either version 2 of the License, or
32397 + * (at your option) any later version.
32399 + * This program is distributed in the hope that it will be useful,
32400 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32401 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32402 + * GNU General Public License for more details.
32404 + * You should have received a copy of the GNU General Public License
32405 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32408 +#ifndef __AUFS_TYPE_H__
32409 +#define __AUFS_TYPE_H__
32411 +#define AUFS_NAME "aufs"
32415 + * define it before including all other headers.
32416 + * sched.h may use pr_* macros before defining "current", so define the
32417 + * no-current version first, and re-define later.
32419 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
32420 +#include <linux/sched.h>
32422 +#define pr_fmt(fmt) \
32423 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
32424 + (int)sizeof(current->comm), current->comm, current->pid
32426 +#include <stdint.h>
32427 +#include <sys/types.h>
32428 +#endif /* __KERNEL__ */
32430 +#include <linux/limits.h>
32432 +#define AUFS_VERSION "3.15-20140623"
32434 +/* todo? move this to linux-2.6.19/include/magic.h */
32435 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
32437 +/* ---------------------------------------------------------------------- */
32439 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
32440 +typedef int8_t aufs_bindex_t;
32441 +#define AUFS_BRANCH_MAX 127
32443 +typedef int16_t aufs_bindex_t;
32444 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
32445 +#define AUFS_BRANCH_MAX 511
32446 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
32447 +#define AUFS_BRANCH_MAX 1023
32448 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
32449 +#define AUFS_BRANCH_MAX 32767
32454 +#ifndef AUFS_BRANCH_MAX
32455 +#error unknown CONFIG_AUFS_BRANCH_MAX value
32457 +#endif /* __KERNEL__ */
32459 +/* ---------------------------------------------------------------------- */
32461 +#define AUFS_FSTYPE AUFS_NAME
32463 +#define AUFS_ROOT_INO 2
32464 +#define AUFS_FIRST_INO 11
32466 +#define AUFS_WH_PFX ".wh."
32467 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
32468 +#define AUFS_WH_TMP_LEN 4
32469 +/* a limit for rmdir/rename a dir and copyup */
32470 +#define AUFS_MAX_NAMELEN (NAME_MAX \
32471 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
32473 + - AUFS_WH_TMP_LEN) /* hex */
32474 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
32475 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
32476 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
32477 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
32478 +#define AUFS_DIRWH_DEF 3
32479 +#define AUFS_RDCACHE_DEF 10 /* seconds */
32480 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
32481 +#define AUFS_RDBLK_DEF 512 /* bytes */
32482 +#define AUFS_RDHASH_DEF 32
32483 +#define AUFS_WKQ_NAME AUFS_NAME "d"
32484 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
32485 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
32486 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
32488 +/* pseudo-link maintenace under /proc */
32489 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
32490 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
32491 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
32493 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
32494 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
32496 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
32497 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
32498 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
32500 +/* doubly whiteouted */
32501 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
32502 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
32503 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
32505 +/* branch permissions and attributes */
32506 +#define AUFS_BRPERM_RW "rw"
32507 +#define AUFS_BRPERM_RO "ro"
32508 +#define AUFS_BRPERM_RR "rr"
32509 +#define AUFS_BRRATTR_WH "wh"
32510 +#define AUFS_BRWATTR_NLWH "nolwh"
32511 +#define AUFS_BRATTR_UNPIN "unpin"
32513 +/* ---------------------------------------------------------------------- */
32517 + /* readdir in userspace */
32521 + /* pathconf wrapper */
32531 +/* borrowed from linux/include/linux/kernel.h */
32533 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
32534 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
32537 +/* borrowed from linux/include/linux/compiler-gcc3.h */
32539 +#define __aligned(x) __attribute__((aligned(x)))
32544 +#define __packed __attribute__((packed))
32548 +struct au_rdu_cookie {
32553 + uint32_t generation;
32556 +struct au_rdu_ent {
32565 +static inline int au_rdu_len(int nlen)
32567 + /* include the terminating NULL */
32568 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
32569 + sizeof(uint64_t));
32572 +union au_rdu_ent_ul {
32573 + struct au_rdu_ent __user *e;
32585 + uint64_t sz; /* AuCtl_RDU */
32586 + uint64_t nent; /* AuCtl_RDU_INO */
32588 + union au_rdu_ent_ul ent;
32589 + uint16_t verify[AufsCtlRduV_End];
32591 + /* input/output */
32595 + union au_rdu_ent_ul tail;
32596 + /* number of entries which were added in a single call */
32601 + struct au_rdu_cookie cookie;
32604 +/* ---------------------------------------------------------------------- */
32606 +struct aufs_wbr_fd {
32611 +/* ---------------------------------------------------------------------- */
32613 +struct aufs_ibusy {
32614 + uint64_t ino, h_ino;
32618 +/* ---------------------------------------------------------------------- */
32620 +/* error code for move-down */
32621 +/* the actual message strings are implemented in aufs-util.git */
32623 + EAU_MVDOWN_OPAQUE = 1,
32624 + EAU_MVDOWN_WHITEOUT,
32625 + EAU_MVDOWN_UPPER,
32626 + EAU_MVDOWN_BOTTOM,
32627 + EAU_MVDOWN_NOUPPER,
32628 + EAU_MVDOWN_NOLOWERBR,
32632 +/* flags for move-down */
32633 +#define AUFS_MVDOWN_DMSG 1
32634 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
32635 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
32636 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
32637 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
32638 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
32639 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
32640 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
32641 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
32642 +/* will be added more */
32645 + AUFS_MVDOWN_UPPER,
32646 + AUFS_MVDOWN_LOWER,
32647 + AUFS_MVDOWN_NARRAY
32650 +struct aufs_mvdown {
32655 + } a[AUFS_MVDOWN_NARRAY];
32657 + /* will be added more */
32660 +/* ---------------------------------------------------------------------- */
32662 +#define AuCtlType 'A'
32663 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
32664 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
32665 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
32666 + struct aufs_wbr_fd)
32667 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
32668 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
32669 + struct aufs_mvdown)
32671 +#endif /* __AUFS_TYPE_H__ */
32672 aufs3.15 loopback patch
32674 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
32675 index 138104b..227f7fa 100644
32676 --- a/drivers/block/loop.c
32677 +++ b/drivers/block/loop.c
32678 @@ -514,7 +514,7 @@ out:
32681 struct switch_request {
32682 - struct file *file;
32683 + struct file *file, *virt_file;
32684 struct completion wait;
32687 @@ -576,7 +576,8 @@ static int loop_thread(void *data)
32688 * First it needs to flush existing IO, it does this by sending a magic
32689 * BIO down the pipe. The completion of this BIO does the actual switch.
32691 -static int loop_switch(struct loop_device *lo, struct file *file)
32692 +static int loop_switch(struct loop_device *lo, struct file *file,
32693 + struct file *virt_file)
32695 struct switch_request w;
32696 struct bio *bio = bio_alloc(GFP_KERNEL, 0);
32697 @@ -584,6 +585,7 @@ static int loop_switch(struct loop_device *lo, struct file *file)
32699 init_completion(&w.wait);
32701 + w.virt_file = virt_file;
32702 bio->bi_private = &w;
32703 bio->bi_bdev = NULL;
32704 loop_make_request(lo->lo_queue, bio);
32705 @@ -600,7 +602,7 @@ static int loop_flush(struct loop_device *lo)
32706 if (!lo->lo_thread)
32709 - return loop_switch(lo, NULL);
32710 + return loop_switch(lo, NULL, NULL);
32714 @@ -619,6 +621,7 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
32715 mapping = file->f_mapping;
32716 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
32717 lo->lo_backing_file = file;
32718 + lo->lo_backing_virt_file = p->virt_file;
32719 lo->lo_blocksize = S_ISBLK(mapping->host->i_mode) ?
32720 mapping->host->i_bdev->bd_block_size : PAGE_SIZE;
32721 lo->old_gfp_mask = mapping_gfp_mask(mapping);
32722 @@ -627,6 +630,13 @@ out:
32723 complete(&p->wait);
32726 +static struct file *loop_real_file(struct file *file)
32728 + struct file *f = NULL;
32729 + if (file->f_dentry->d_sb->s_op->real_loop)
32730 + f = file->f_dentry->d_sb->s_op->real_loop(file);
32735 * loop_change_fd switched the backing store of a loopback device to
32736 @@ -640,6 +650,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
32739 struct file *file, *old_file;
32740 + struct file *f, *virt_file = NULL, *old_virt_file;
32741 struct inode *inode;
32744 @@ -656,9 +667,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
32748 + f = loop_real_file(file);
32750 + virt_file = file;
32755 inode = file->f_mapping->host;
32756 old_file = lo->lo_backing_file;
32757 + old_virt_file = lo->lo_backing_virt_file;
32761 @@ -670,17 +688,21 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
32764 /* and ... switch */
32765 - error = loop_switch(lo, file);
32766 + error = loop_switch(lo, file, virt_file);
32771 + if (old_virt_file)
32772 + fput(old_virt_file);
32773 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
32774 ioctl_by_bdev(bdev, BLKRRPART, 0);
32784 @@ -841,7 +863,7 @@ static void loop_config_discard(struct loop_device *lo)
32785 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
32786 struct block_device *bdev, unsigned int arg)
32788 - struct file *file, *f;
32789 + struct file *file, *f, *virt_file = NULL;
32790 struct inode *inode;
32791 struct address_space *mapping;
32792 unsigned lo_blocksize;
32793 @@ -856,6 +878,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
32797 + f = loop_real_file(file);
32799 + virt_file = file;
32805 if (lo->lo_state != Lo_unbound)
32806 @@ -904,6 +932,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
32807 lo->lo_device = bdev;
32808 lo->lo_flags = lo_flags;
32809 lo->lo_backing_file = file;
32810 + lo->lo_backing_virt_file = virt_file;
32811 lo->transfer = transfer_none;
32813 lo->lo_sizelimit = 0;
32814 @@ -948,6 +977,7 @@ out_clr:
32815 lo->lo_thread = NULL;
32816 lo->lo_device = NULL;
32817 lo->lo_backing_file = NULL;
32818 + lo->lo_backing_virt_file = NULL;
32820 set_capacity(lo->lo_disk, 0);
32821 invalidate_bdev(bdev);
32822 @@ -957,6 +987,8 @@ out_clr:
32823 lo->lo_state = Lo_unbound;
32829 /* This is safe: open() is still holding a reference. */
32830 module_put(THIS_MODULE);
32831 @@ -1003,6 +1035,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
32832 static int loop_clr_fd(struct loop_device *lo)
32834 struct file *filp = lo->lo_backing_file;
32835 + struct file *virt_filp = lo->lo_backing_virt_file;
32836 gfp_t gfp = lo->old_gfp_mask;
32837 struct block_device *bdev = lo->lo_device;
32839 @@ -1036,6 +1069,7 @@ static int loop_clr_fd(struct loop_device *lo)
32841 spin_lock_irq(&lo->lo_lock);
32842 lo->lo_backing_file = NULL;
32843 + lo->lo_backing_virt_file = NULL;
32844 spin_unlock_irq(&lo->lo_lock);
32846 loop_release_xfer(lo);
32847 @@ -1078,6 +1112,8 @@ static int loop_clr_fd(struct loop_device *lo)
32848 * bd_mutex which is usually taken before lo_ctl_mutex.
32856 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
32857 index 90df5d6..cb91822 100644
32858 --- a/drivers/block/loop.h
32859 +++ b/drivers/block/loop.h
32860 @@ -44,7 +44,7 @@ struct loop_device {
32861 int (*ioctl)(struct loop_device *, int cmd,
32862 unsigned long arg);
32864 - struct file * lo_backing_file;
32865 + struct file * lo_backing_file, *lo_backing_virt_file;
32866 struct block_device *lo_device;
32867 unsigned lo_blocksize;
32869 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
32870 index 510919e..f9317c9 100644
32871 --- a/fs/aufs/f_op.c
32872 +++ b/fs/aufs/f_op.c
32873 @@ -345,7 +345,7 @@ static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
32875 h_file = au_hf_top(file);
32877 - if (au_test_loopback_kthread()) {
32878 + if (0 && au_test_loopback_kthread()) {
32879 au_warn_loopback(h_file->f_dentry->d_sb);
32880 if (file->f_mapping != h_file->f_mapping) {
32881 file->f_mapping = h_file->f_mapping;
32882 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
32883 index 3b03b52..4ab749d 100644
32884 --- a/fs/aufs/loop.c
32885 +++ b/fs/aufs/loop.c
32886 @@ -130,3 +130,19 @@ void au_loopback_fin(void)
32887 symbol_put(loop_backing_file);
32888 kfree(au_warn_loopback_array);
32891 +/* ---------------------------------------------------------------------- */
32893 +/* support the loopback block device insude aufs */
32895 +struct file *aufs_real_loop(struct file *file)
32899 + BUG_ON(!au_test_aufs(file->f_dentry->d_sb));
32900 + fi_read_lock(file);
32901 + f = au_hf_top(file);
32902 + fi_read_unlock(file);
32906 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
32907 index da8b756..28cb7ea 100644
32908 --- a/fs/aufs/loop.h
32909 +++ b/fs/aufs/loop.h
32910 @@ -25,7 +25,11 @@ void au_warn_loopback(struct super_block *h_sb);
32912 int au_loopback_init(void);
32913 void au_loopback_fin(void);
32915 +struct file *aufs_real_loop(struct file *file);
32917 +AuStub(struct file *, loop_backing_file, return NULL)
32919 AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
32920 struct dentry *h_adding)
32921 AuStubInt0(au_test_loopback_kthread, void)
32922 @@ -33,6 +37,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
32924 AuStubInt0(au_loopback_init, void)
32925 AuStubVoid(au_loopback_fin, void)
32927 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
32928 #endif /* BLK_DEV_LOOP */
32930 #endif /* __KERNEL__ */
32931 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
32932 index b609e5a..e3909ed 100644
32933 --- a/fs/aufs/super.c
32934 +++ b/fs/aufs/super.c
32935 @@ -807,7 +807,10 @@ static const struct super_operations aufs_sop = {
32936 .statfs = aufs_statfs,
32937 .put_super = aufs_put_super,
32938 .sync_fs = aufs_sync_fs,
32939 - .remount_fs = aufs_remount_fs
32940 + .remount_fs = aufs_remount_fs,
32941 +#ifdef CONFIG_AUFS_BDEV_LOOP
32942 + .real_loop = aufs_real_loop
32946 /* ---------------------------------------------------------------------- */
32947 diff --git a/include/linux/fs.h b/include/linux/fs.h
32948 index 3ff3e89..13017e6 100644
32949 --- a/include/linux/fs.h
32950 +++ b/include/linux/fs.h
32951 @@ -1554,6 +1554,10 @@ struct super_operations {
32952 int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
32953 long (*nr_cached_objects)(struct super_block *, int);
32954 long (*free_cached_objects)(struct super_block *, long, int);
32955 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
32957 + struct file *(*real_loop)(struct file *);